This commit is contained in:
2025-04-06 22:17:03 +02:00
parent 849fc458e2
commit 2dd7860b17
10 changed files with 164 additions and 107 deletions

View File

@@ -15,6 +15,8 @@ void TestBackendSupport()
if(!PulseSupportsBackend(PULSE_BACKEND_VULKAN, PULSE_SHADER_FORMAT_SPIRV_BIT))
#elif defined(WEBGPU_ENABLED)
if(!PulseSupportsBackend(PULSE_BACKEND_WEBGPU, PULSE_SHADER_FORMAT_WGSL_BIT))
#elif defined(OPENGL_ENABLED)
if(!PulseSupportsBackend(PULSE_BACKEND_WEBGPU, PULSE_SHADER_FORMAT_WGSL_BIT))
#endif
{
TEST_MESSAGE("Backend is not supported");

View File

@@ -1,2 +1,4 @@
*.spv.h
*.wgsl.h
*.json
*.glsl.h

View File

@@ -12,10 +12,16 @@ struct SSBO
data: dyn_array[u32]
}
[set(0)]
external
{
[set(0), binding(0)] read_ssbo: storage[SSBO, readonly],
[set(1), binding(0)] write_ssbo: storage[SSBO, writeonly],
[binding(0)] read_ssbo: storage[SSBO, readonly],
}
[set(1)]
external
{
[binding(0)] write_ssbo: storage[SSBO, writeonly],
}
[entry(compute)]

View File

@@ -0,0 +1,33 @@
[nzsl_version("1.0")]
module;
struct Input
{
[builtin(global_invocation_indices)] indices: vec3[u32]
}
[layout(std430)]
struct SSBO
{
data: dyn_array[u32]
}
[set(0)]
external
{
[binding(0)] read_texture: texture2D[f32, readonly, rgba8],
[binding(1)] read_ssbo: storage[SSBO, readonly],
}
[set(1)]
external
{
[binding(0)] write_texture: texture2D[f32, rgba8],
[binding(1)] write_ssbo: storage[SSBO, writeonly],
}
[entry(compute)]
[workgroup(16, 16, 1)]
fn main(input: Input)
{
}

View File

@@ -12,9 +12,10 @@ struct SSBO
data: dyn_array[u32]
}
[set(1)]
external
{
[set(1), binding(0)] ssbo: storage[SSBO],
[binding(0)] ssbo: storage[SSBO],
}
[entry(compute)]

View File

@@ -12,10 +12,11 @@ struct SSBO
data: dyn_array[u32]
}
[set(0)]
external
{
[set(1), binding(0)] write_texture: texture2D[f32, readwrite, rgba8],
[set(1), binding(1)] write_ssbo: storage[SSBO],
[binding(0)] write_texture: texture2D[f32, readwrite, rgba8],
[binding(1)] write_ssbo: storage[SSBO],
}
[entry(compute)]

View File

@@ -1,27 +0,0 @@
[nzsl_version("1.0")]
module;
struct Input
{
[builtin(global_invocation_indices)] indices: vec3[u32]
}
[layout(std430)]
struct SSBO
{
data: dyn_array[u32]
}
external
{
[set(0), binding(0)] read_texture: texture2D[f32, readonly, rgba8],
[set(0), binding(1)] read_ssbo: storage[SSBO, readonly],
[set(1), binding(0)] write_texture: texture2D[f32, readonly, rgba8],
[set(1), binding(1)] write_ssbo: storage[SSBO, writeonly],
}
[entry(compute)]
[workgroup(16, 16, 1)]
fn main(input: Input)
{
}

View File

@@ -1,85 +1,124 @@
Backend = {
VULKAN = 1,
OPENGL = 2,
OPENGL_ES = 3,
}
function nzsl(backend)
add_repositories("nazara-engine-repo https://github.com/NazaraEngine/xmake-repo")
add_requires("nzsl >=2023.12.31", { configs = { shared = false, nzslc = true } })
if is_cross() then
add_requires("nzsl~host", { kind = "binary", host = true })
end
-- Yoinked from NZSL xmake repo
rule("find_nzsl")
on_config(function(target)
import("core.project.project")
import("core.tool.toolchain")
import("lib.detect.find_tool")
local envs
if is_plat("windows") then
local msvc = target:toolchain("msvc")
if msvc and msvc:check() then
envs = msvc:runenvs()
end
elseif is_plat("mingw") then
local mingw = target:toolchain("mingw")
if mingw and mingw:check() then
envs = mingw:runenvs()
end
end
target:data_set("nzsl_envs", envs)
local nzsl = project.required_package("nzsl~host") or project.required_package("nzsl")
local nzsldir
if nzsl then
nzsldir = path.join(nzsl:installdir(), "bin")
local osenvs = os.getenvs()
envs = envs or {}
for env, values in pairs(nzsl:get("envs")) do
local flatval = path.joinenv(values)
local oldenv = envs[env] or osenvs[env]
if not oldenv or oldenv == "" then
envs[env] = flatval
elseif not oldenv:startswith(flatval) then
envs[env] = flatval .. path.envsep() .. oldenv
end
end
end
local nzsla = find_tool("nzsla", { version = true, paths = nzsldir, envs = envs })
local nzslc = find_tool("nzslc", { version = true, paths = nzsldir, envs = envs })
target:data_set("nzsla", nzsla)
target:data_set("nzslc", nzslc)
target:data_set("nzsl_runenv", envs)
end)
rule_end()
rule("nzsl_compile_shaders")
set_extensions(".nzsl")
add_deps("find_nzsl")
before_buildcmd_file(function(target, batchcmds, shaderfile, opt)
local outputdir = target:data("nzsl_includedirs")
local nzslc = target:data("nzslc")
local runenvs = target:data("nzsl_runenv")
assert(nzslc, "nzslc not found! please install nzsl package with nzslc enabled")
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.shader %s", shaderfile)
local argv = {}
if backend == Backend.VULKAN then
argv = { "--compile=spv-header", "--optimize" }
elseif backend == Backend.OPENGL then
argv = { "--compile=glsl-header", "--optimize", "--gl-version", "310", "--gl-es", "--gl-bindingmap" }
else
argv = { "--compile=glsl-header", "--optimize", "--gl-version", "310", "--gl-bindingmap" }
end
if outputdir then
batchcmds:mkdir(outputdir)
table.insert(argv, "--output=" .. outputdir)
end
local kind = target:data("plugin.project.kind") or ""
if kind:match("vs") then
table.insert(argv, "--log-format=vs")
end
table.insert(argv, shaderfile)
batchcmds:vrunv(nzslc.program, argv, { curdir = ".", envs = runenvs })
local outputfile = path.join(outputdir or path.directory(shaderfile), path.basename(shaderfile) .. ".spv.h")
batchcmds:add_depfiles(shaderfile)
batchcmds:add_depvalues(nzslc.version)
batchcmds:set_depmtime(os.mtime(outputfile))
batchcmds:set_depcache(target:dependfile(outputfile))
end)
rule_end()
end
local tests = {
Vulkan = {
option = "vulkan",
global_custom = function()
add_repositories("nazara-engine-repo https://github.com/NazaraEngine/xmake-repo")
add_requires("nzsl >=2023.12.31", { configs = { shared = false, nzslc = true } })
if is_cross() then
add_requires("nzsl~host", { kind = "binary", host = true })
end
-- Yoinked from NZSL xmake repo
rule("find_nzsl")
on_config(function(target)
import("core.project.project")
import("core.tool.toolchain")
import("lib.detect.find_tool")
local envs
if is_plat("windows") then
local msvc = target:toolchain("msvc")
if msvc and msvc:check() then
envs = msvc:runenvs()
end
elseif is_plat("mingw") then
local mingw = target:toolchain("mingw")
if mingw and mingw:check() then
envs = mingw:runenvs()
end
end
target:data_set("nzsl_envs", envs)
local nzsl = project.required_package("nzsl~host") or project.required_package("nzsl")
local nzsldir
if nzsl then
nzsldir = path.join(nzsl:installdir(), "bin")
local osenvs = os.getenvs()
envs = envs or {}
for env, values in pairs(nzsl:get("envs")) do
local flatval = path.joinenv(values)
local oldenv = envs[env] or osenvs[env]
if not oldenv or oldenv == "" then
envs[env] = flatval
elseif not oldenv:startswith(flatval) then
envs[env] = flatval .. path.envsep() .. oldenv
end
end
end
local nzsla = find_tool("nzsla", { version = true, paths = nzsldir, envs = envs })
local nzslc = find_tool("nzslc", { version = true, paths = nzsldir, envs = envs })
target:data_set("nzsla", nzsla)
target:data_set("nzslc", nzslc)
target:data_set("nzsl_runenv", envs)
end)
rule_end()
rule("nzsl_compile_shaders")
set_extensions(".nzsl")
add_deps("find_nzsl")
before_buildcmd_file(function(target, batchcmds, shaderfile, opt)
local outputdir = target:data("nzsl_includedirs")
local nzslc = target:data("nzslc")
local runenvs = target:data("nzsl_runenv")
assert(nzslc, "nzslc not found! please install nzsl package with nzslc enabled")
batchcmds:show_progress(opt.progress, "${color.build.object}compiling.shader %s", shaderfile)
local argv = { "--compile=spv-header", "--optimize" }
if outputdir then
batchcmds:mkdir(outputdir)
table.insert(argv, "--output=" .. outputdir)
end
local kind = target:data("plugin.project.kind") or ""
if kind:match("vs") then
table.insert(argv, "--log-format=vs")
end
table.insert(argv, shaderfile)
batchcmds:vrunv(nzslc.program, argv, { curdir = ".", envs = runenvs })
local outputfile = path.join(outputdir or path.directory(shaderfile), path.basename(shaderfile) .. ".spv.h")
batchcmds:add_depfiles(shaderfile)
batchcmds:add_depvalues(nzslc.version)
batchcmds:set_depmtime(os.mtime(outputfile))
batchcmds:set_depcache(target:dependfile(outputfile))
end)
rule_end()
nzsl(Backend.VULKAN)
end,
custom = function()
add_rules("nzsl_compile_shaders")
add_packages("nzs")
add_packages("nzsl")
add_files("**.nzsl")
end
},
OpenGL = {
option = "opengl",
global_custom = function()
nzsl(backend.OPENGL)
end,
custom = function()
add_rules("nzsl_compile_shaders")
add_packages("nzsl")
add_files("**.nzsl")
end
},
OpenGLES = {
option = "opengl-es",
global_custom = function()
nzsl(Backend.OpenGLES)
end,
custom = function()
add_rules("nzsl_compile_shaders")
add_packages("nzsl")
add_files("**.nzsl")
end
},