Skip to content

Commit

Permalink
xmake cpu backend
Browse files Browse the repository at this point in the history
  • Loading branch information
shiinamiyuki committed Jul 27, 2023
1 parent 63eb1ba commit 12e08cf
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 8 deletions.
5 changes: 5 additions & 0 deletions scripts/xmake_func.lua
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ on_buildcmd_file(function(target, batchcmds, sourcefile, opt)
-- end
sb:add("--manifest-path ")
sb:add(sourcefile):add(' ')
local features = target:get('features')
if features then
sb:add("--features ")
sb:add(features):add(' ')
end
if not is_mode("debug") then
sb:add("--release ")
end
Expand Down
2 changes: 1 addition & 1 deletion src/backends/common/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ if get_config("vk_backend") or get_config("dx_backend") then
end

if (get_config("cuda_backend") or get_config("cpu_backend")) and get_config("_lc_vk_path") then
target("lc-vk-swapchain")
target("lc-vulkan-swapchain")
_config_project({
project_kind = "shared"
})
Expand Down
69 changes: 69 additions & 0 deletions src/backends/cpu/xmake.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
target("lc-backend-cpu")
_config_project({
project_kind = "shared"
})
on_load(function(target)
local function rela(p)
return path.relative(path.absolute(p, os.scriptdir()), os.projectdir())
end
target:add("defines", "LC_IR_EXPORT_DLL")
target:add("deps", "lc-runtime", "lc-ir", "lc-ast", "lc-rust")
target:set("features", "cpu")
if is_plat("windows") then
target:add("syslinks", "Ws2_32", "Advapi32", "Bcrypt", "Userenv")
end
local function add_rs_link(str)
target:add("linkdirs", path.absolute(path.join("../../rust/target", str), os.scriptdir()), {
public = true
})
target:add("links", "luisa_compute_backend_impl.dll", {
public = true
})
end
if is_mode("debug") then
add_rs_link("debug")
else
add_rs_link("release")
end
end)
before_build(function(target)
local profile = nil
if is_mode("debug") then
profile = "debug"
else
profile = "release"
end
local lib_path = path.absolute(path.join("../../rust/target", profile), os.scriptdir())
os.setenv("EMBREE_DLL_OUT_DIR", lib_path)
end)
add_rules("build_cargo")
add_files("../../rust/luisa_compute_backend_impl/Cargo.toml")

after_build(function(target)
local dlls = {
"embree4",
"libmmd",
"tbb12",
"tbbmalloc",
"luisa_compute_backend_impl"
}
local function copy_dll(str)
local lib_path = path.absolute(path.join("../../rust/target", str), os.scriptdir())
local bin_dir = target:targetdir()
for i, v in ipairs(dlls) do
if is_plat("windows") then
os.cp(path.join(lib_path, v .. ".dll"), bin_dir)
else
os.cp(path.join(lib_path, "lib" .. v .. ".so"), bin_dir)
end
end
end
if is_mode("debug") then
copy_dll("debug")
else
copy_dll("release")
end
end)
add_files("**.cpp")
add_files("../common/rust_device_common.cpp")
target_end()
2 changes: 1 addition & 1 deletion src/backends/cuda/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ _config_project({
if get_config("_lc_vk_path") then
add_defines("LUISA_BACKEND_ENABLE_VULKAN_SWAPCHAIN")
add_rules("lc_vulkan")
add_deps("lc-vk-swapchain")
add_deps("lc-vulkan-swapchain")
end
add_deps("lc-runtime")
if get_config("enable_ir") then
Expand Down
2 changes: 1 addition & 1 deletion src/ir/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ after_build(function(target)
if is_plat("windows") then
os.cp(path.join(lib_path, "luisa_compute_ir.dll"), bin_dir)
else
os.cp(path.join(lib_path, "luisa_compute_ir.so"), bin_dir)
os.cp(path.join(lib_path, "libluisa_compute_ir.so"), bin_dir)
end
end
if is_mode("debug") then
Expand Down
4 changes: 2 additions & 2 deletions src/rust/luisa_compute_backend_impl/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,9 @@ unsafe extern "C" fn create_device(
todo!()
};
let swapchain = lib_path.join(swapchain_dll);
let swapchain = SwapChainForCpuContext::new(swapchain)
let swapchain = SwapChainForCpuContext::new(&swapchain)
.map_err(|e| {
log::warn!("failed to load swapchain: {}", e);
eprintln!("failed to load swapchain: {}, path:{}", e, swapchain.display());
e
})
.ok()
Expand Down
2 changes: 1 addition & 1 deletion src/rust/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ _config_project({
before_build(function(target)
os.setenv("LC_RS_DO_NOT_GENERATE_BINDINGS", 1)
end)

add_rules("build_cargo")
add_files("Cargo.toml")
add_files("luisa_compute_ir/Cargo.toml")
-- add_files("luisa_compute_backend/Cargo.toml")
-- add_files("luisa_compute_backend_impl/Cargo.toml")
Expand Down
10 changes: 8 additions & 2 deletions xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ set_values(true, false)
set_default(true)
set_showmenu(true)
option_end()
-- enable CPU backend
option("cpu_backend")
set_values(true, false)
set_default(true)
set_showmenu(true)
option_end()
-- enable Metal backend
option("metal_backend")
set_values(true, false)
Expand All @@ -47,7 +53,7 @@ option_end()
-- enable cpu backend
option("cpu_backend")
set_values(true, false)
set_default(false)
set_default(true)
set_showmenu(true)
option_end()
-- enable tests module
Expand All @@ -74,7 +80,7 @@ option_end()
-- enable intermediate representation module (rust required)
option("enable_ir")
set_values(true, false)
set_default(false)
set_default(true)
set_showmenu(true)
option_end()
-- enable c-language api module for cross-language bindings module
Expand Down

0 comments on commit 12e08cf

Please sign in to comment.