This commit is contained in:
2025-04-07 00:06:32 +02:00
parent 2dd7860b17
commit 9e8084fcf3
5 changed files with 132 additions and 62 deletions

View File

@@ -16,7 +16,9 @@ void TestBackendSupport()
#elif defined(WEBGPU_ENABLED) #elif defined(WEBGPU_ENABLED)
if(!PulseSupportsBackend(PULSE_BACKEND_WEBGPU, PULSE_SHADER_FORMAT_WGSL_BIT)) if(!PulseSupportsBackend(PULSE_BACKEND_WEBGPU, PULSE_SHADER_FORMAT_WGSL_BIT))
#elif defined(OPENGL_ENABLED) #elif defined(OPENGL_ENABLED)
if(!PulseSupportsBackend(PULSE_BACKEND_WEBGPU, PULSE_SHADER_FORMAT_WGSL_BIT)) if(!PulseSupportsBackend(PULSE_BACKEND_OPENGL, PULSE_SHADER_FORMAT_GLSL_BIT))
#elif defined(OPENGLES_ENABLED)
if(!PulseSupportsBackend(PULSE_BACKEND_OPENGL_ES, PULSE_SHADER_FORMAT_GLSL_BIT))
#endif #endif
{ {
TEST_MESSAGE("Backend is not supported"); TEST_MESSAGE("Backend is not supported");
@@ -30,6 +32,10 @@ void TestBackendSetup()
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_VULKAN, PULSE_SHADER_FORMAT_SPIRV_BIT, PULSE_HIGH_DEBUG); PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_VULKAN, PULSE_SHADER_FORMAT_SPIRV_BIT, PULSE_HIGH_DEBUG);
#elif defined(WEBGPU_ENABLED) #elif defined(WEBGPU_ENABLED)
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_WEBGPU, PULSE_SHADER_FORMAT_WGSL_BIT, PULSE_HIGH_DEBUG); PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_WEBGPU, PULSE_SHADER_FORMAT_WGSL_BIT, PULSE_HIGH_DEBUG);
#elif defined(OPENGL_ENABLED)
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_OPENGL, PULSE_SHADER_FORMAT_GLSL_BIT, PULSE_HIGH_DEBUG);
#elif defined(OPENGLES_ENABLED)
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_OPENGL_ES, PULSE_SHADER_FORMAT_GLSL_BIT, PULSE_HIGH_DEBUG);
#endif #endif
TEST_ASSERT_NOT_EQUAL_MESSAGE(backend, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType())); TEST_ASSERT_NOT_EQUAL_MESSAGE(backend, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
PulseSetDebugCallback(backend, DumbDebugCallBack); PulseSetDebugCallback(backend, DumbDebugCallBack);
@@ -42,12 +48,18 @@ void TestBackendAnySetup()
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_ANY, PULSE_SHADER_FORMAT_SPIRV_BIT, PULSE_HIGH_DEBUG); PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_ANY, PULSE_SHADER_FORMAT_SPIRV_BIT, PULSE_HIGH_DEBUG);
#elif defined(WEBGPU_ENABLED) #elif defined(WEBGPU_ENABLED)
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_ANY, PULSE_SHADER_FORMAT_WGSL_BIT, PULSE_HIGH_DEBUG); PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_ANY, PULSE_SHADER_FORMAT_WGSL_BIT, PULSE_HIGH_DEBUG);
#elif defined(OPENGL_ENABLED) || defined(OPENGLES_ENABLED)
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_ANY, PULSE_SHADER_FORMAT_GLSL_BIT, PULSE_HIGH_DEBUG);
#endif #endif
TEST_ASSERT_NOT_EQUAL_MESSAGE(backend, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType())); TEST_ASSERT_NOT_EQUAL_MESSAGE(backend, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
#if defined(VULKAN_ENABLED) #if defined(VULKAN_ENABLED)
TEST_ASSERT_EQUAL(PulseGetBackendType(backend), PULSE_BACKEND_VULKAN); TEST_ASSERT_EQUAL(PulseGetBackendType(backend), PULSE_BACKEND_VULKAN);
#elif defined(WEBGPU_ENABLED) #elif defined(WEBGPU_ENABLED)
TEST_ASSERT_EQUAL(PulseGetBackendType(backend), PULSE_BACKEND_WEBGPU); TEST_ASSERT_EQUAL(PulseGetBackendType(backend), PULSE_BACKEND_WEBGPU);
#elif defined(OPENGL_ENABLED) || defined(OPENGLES_ENABLED)
PulseBackendFlags backend_type = PulseGetBackendType(backend);
if(backend_type != PULSE_BACKEND_OPENGL && backend_type != PULSE_BACKEND_OPENGL_ES)
TEST_FAIL();
#endif #endif
PulseSetDebugCallback(backend, DumbDebugCallBack); PulseSetDebugCallback(backend, DumbDebugCallBack);
PulseUnloadBackend(backend); PulseUnloadBackend(backend);
@@ -59,6 +71,10 @@ void TestWrongBackendSetup()
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_VULKAN, PULSE_SHADER_FORMAT_MSL_BIT, PULSE_HIGH_DEBUG); PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_VULKAN, PULSE_SHADER_FORMAT_MSL_BIT, PULSE_HIGH_DEBUG);
#elif defined(WEBGPU_ENABLED) #elif defined(WEBGPU_ENABLED)
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_WEBGPU, PULSE_SHADER_FORMAT_MSL_BIT, PULSE_HIGH_DEBUG); PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_WEBGPU, PULSE_SHADER_FORMAT_MSL_BIT, PULSE_HIGH_DEBUG);
#elif defined(OPENGL_ENABLED)
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_OPENGL, PULSE_SHADER_FORMAT_MSL_BIT, PULSE_HIGH_DEBUG);
#elif defined(OPENGLES_ENABLED)
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_OPENGL_ES, PULSE_SHADER_FORMAT_MSL_BIT, PULSE_HIGH_DEBUG);
#endif #endif
TEST_ASSERT_EQUAL(backend, PULSE_NULL_HANDLE); TEST_ASSERT_EQUAL(backend, PULSE_NULL_HANDLE);
PulseSetDebugCallback(backend, DumbDebugCallBack); PulseSetDebugCallback(backend, DumbDebugCallBack);

View File

@@ -271,11 +271,15 @@ void TestBufferComputeWrite()
#if defined(VULKAN_ENABLED) #if defined(VULKAN_ENABLED)
const uint8_t shader_bytecode[] = { const uint8_t shader_bytecode[] = {
#include "Shaders/Vulkan/SimpleBufferWrite.spv.h" #include "Shaders/Vulkan-OpenGL/SimpleBufferWrite.spv.h"
}; };
#elif defined(WEBGPU_ENABLED) #elif defined(WEBGPU_ENABLED)
#define SHADER_NAME shader_bytecode #define SHADER_NAME shader_bytecode
#include "Shaders/WebGPU/SimpleBufferWrite.wgsl.h" #include "Shaders/WebGPU/SimpleBufferWrite.wgsl.h"
#elif defined(OPENGL_ENABLED) || defined(OPENGLES_ENABLED)
const uint8_t shader_bytecode[] = {
#include "Shaders/Vulkan-OpenGL/SimpleBufferWrite.comp.glsl.h"
};
#endif #endif
PulseBufferCreateInfo buffer_create_info = { 0 }; PulseBufferCreateInfo buffer_create_info = { 0 };
@@ -338,11 +342,15 @@ void TestBufferComputeCopy()
#if defined(VULKAN_ENABLED) #if defined(VULKAN_ENABLED)
const uint8_t shader_bytecode[] = { const uint8_t shader_bytecode[] = {
#include "Shaders/Vulkan/BufferCopy.spv.h" #include "Shaders/Vulkan-OpenGL/BufferCopy.spv.h"
}; };
#elif defined(WEBGPU_ENABLED) #elif defined(WEBGPU_ENABLED)
#define SHADER_NAME shader_bytecode #define SHADER_NAME shader_bytecode
#include "Shaders/WebGPU/BufferCopy.wgsl.h" #include "Shaders/WebGPU/BufferCopy.wgsl.h"
#elif defined(OPENGL_ENABLED) || defined(OPENGLES_ENABLED)
const uint8_t shader_bytecode[] = {
#include "Shaders/Vulkan-OpenGL/BufferCopy.comp.glsl.h"
};
#endif #endif
uint32_t data[256]; uint32_t data[256];

View File

@@ -24,6 +24,10 @@ void SetupPulse(PulseBackend* backend)
*backend = PulseLoadBackend(PULSE_BACKEND_VULKAN, PULSE_SHADER_FORMAT_SPIRV_BIT, PULSE_PARANOID_DEBUG); *backend = PulseLoadBackend(PULSE_BACKEND_VULKAN, PULSE_SHADER_FORMAT_SPIRV_BIT, PULSE_PARANOID_DEBUG);
#elif defined(WEBGPU_ENABLED) #elif defined(WEBGPU_ENABLED)
*backend = PulseLoadBackend(PULSE_BACKEND_WEBGPU, PULSE_SHADER_FORMAT_WGSL_BIT, PULSE_PARANOID_DEBUG); *backend = PulseLoadBackend(PULSE_BACKEND_WEBGPU, PULSE_SHADER_FORMAT_WGSL_BIT, PULSE_PARANOID_DEBUG);
#elif defined(OPENGL_ENABLED)
*backend = PulseLoadBackend(PULSE_BACKEND_OPENGL, PULSE_SHADER_FORMAT_GLSL_BIT, PULSE_PARANOID_DEBUG);
#elif defined(OPENGLES_ENABLED)
*backend = PulseLoadBackend(PULSE_BACKEND_OPENGL_ES, PULSE_SHADER_FORMAT_GLSL_BIT, PULSE_PARANOID_DEBUG);
#endif #endif
if(*backend == PULSE_NULL_HANDLE) if(*backend == PULSE_NULL_HANDLE)
{ {
@@ -70,6 +74,10 @@ void LoadComputePipeline(PulseDevice device, PulseComputePipeline* pipeline, con
info.format = PULSE_SHADER_FORMAT_SPIRV_BIT; info.format = PULSE_SHADER_FORMAT_SPIRV_BIT;
#elif defined(WEBGPU_ENABLED) #elif defined(WEBGPU_ENABLED)
info.format = PULSE_SHADER_FORMAT_WGSL_BIT; info.format = PULSE_SHADER_FORMAT_WGSL_BIT;
#elif defined(OPENGL_ENABLED)
info.format = PULSE_SHADER_FORMAT_GLSL_BIT;
#elif defined(OPENGLES_ENABLED)
info.format = PULSE_SHADER_FORMAT_GLSL_BIT;
#endif #endif
info.num_readonly_storage_images = num_readonly_storage_images; info.num_readonly_storage_images = num_readonly_storage_images;
info.num_readonly_storage_buffers = num_readonly_storage_buffers; info.num_readonly_storage_buffers = num_readonly_storage_buffers;

View File

@@ -12,11 +12,15 @@ void TestPipelineSetup()
#if defined(VULKAN_ENABLED) #if defined(VULKAN_ENABLED)
const uint8_t shader_bytecode[] = { const uint8_t shader_bytecode[] = {
#include "Shaders/Vulkan/Simple.spv.h" #include "Shaders/Vulkan-OpenGL/Simple.spv.h"
}; };
#elif defined(WEBGPU_ENABLED) #elif defined(WEBGPU_ENABLED)
#define SHADER_NAME shader_bytecode #define SHADER_NAME shader_bytecode
#include "Shaders/WebGPU/Simple.wgsl.h" #include "Shaders/WebGPU/Simple.wgsl.h"
#elif defined(OPENGL_ENABLED) || defined(OPENGLES_ENABLED)
const uint8_t shader_bytecode[] = {
#include "Shaders/Vulkan-OpenGL/Simple.comp.glsl.h"
};
#endif #endif
PulseComputePipeline pipeline; PulseComputePipeline pipeline;
@@ -53,11 +57,15 @@ void TestPipelineReadOnlyBindings()
#if defined(VULKAN_ENABLED) #if defined(VULKAN_ENABLED)
const uint8_t shader_bytecode[] = { const uint8_t shader_bytecode[] = {
#include "Shaders/Vulkan/ReadOnlyBindings.spv.h" #include "Shaders/Vulkan-OpenGL/ReadOnlyBindings.spv.h"
}; };
#elif defined(WEBGPU_ENABLED) #elif defined(WEBGPU_ENABLED)
#define SHADER_NAME shader_bytecode #define SHADER_NAME shader_bytecode
#include "Shaders/WebGPU/ReadOnlyBindings.wgsl.h" #include "Shaders/WebGPU/ReadOnlyBindings.wgsl.h"
#elif defined(OPENGL_ENABLED) || defined(OPENGLES_ENABLED)
const uint8_t shader_bytecode[] = {
#include "Shaders/Vulkan-OpenGL/ReadOnlyBindings.comp.glsl.h"
};
#endif #endif
PulseBufferCreateInfo buffer_create_info = { 0 }; PulseBufferCreateInfo buffer_create_info = { 0 };
@@ -114,11 +122,15 @@ void TestPipelineWriteOnlyBindings()
#if defined(VULKAN_ENABLED) #if defined(VULKAN_ENABLED)
const uint8_t shader_bytecode[] = { const uint8_t shader_bytecode[] = {
#include "Shaders/Vulkan/WriteOnlyBindings.spv.h" #include "Shaders/Vulkan-OpenGL/WriteOnlyBindings.spv.h"
}; };
#elif defined(WEBGPU_ENABLED) #elif defined(WEBGPU_ENABLED)
#define SHADER_NAME shader_bytecode #define SHADER_NAME shader_bytecode
#include "Shaders/WebGPU/WriteOnlyBindings.wgsl.h" #include "Shaders/WebGPU/WriteOnlyBindings.wgsl.h"
#elif defined(OPENGL_ENABLED) || defined(OPENGLES_ENABLED)
const uint8_t shader_bytecode[] = {
#include "Shaders/Vulkan-OpenGL/WriteOnlyBindings.comp.glsl.h"
};
#endif #endif
PulseBufferCreateInfo buffer_create_info = { 0 }; PulseBufferCreateInfo buffer_create_info = { 0 };
@@ -175,11 +187,15 @@ void TestPipelineReadWriteBindings()
#if defined(VULKAN_ENABLED) #if defined(VULKAN_ENABLED)
const uint8_t shader_bytecode[] = { const uint8_t shader_bytecode[] = {
#include "Shaders/Vulkan/ReadWriteBindings.spv.h" #include "Shaders/Vulkan-OpenGL/ReadWriteBindings.spv.h"
}; };
#elif defined(WEBGPU_ENABLED) #elif defined(WEBGPU_ENABLED)
#define SHADER_NAME shader_bytecode #define SHADER_NAME shader_bytecode
#include "Shaders/WebGPU/ReadWriteBindings.wgsl.h" #include "Shaders/WebGPU/ReadWriteBindings.wgsl.h"
#elif defined(OPENGL_ENABLED) || defined(OPENGLES_ENABLED)
const uint8_t shader_bytecode[] = {
#include "Shaders/Vulkan-OpenGL/ReadWriteBindings.comp.glsl.h"
};
#endif #endif
PulseBufferCreateInfo buffer_create_info = { 0 }; PulseBufferCreateInfo buffer_create_info = { 0 };

View File

@@ -1,58 +1,74 @@
Backend = { local Backend = {
VULKAN = 1, VULKAN = 1,
OPENGL = 2, OPENGL = 2,
OPENGL_ES = 3, OPENGL_ES = 3,
} }
local nzsl_included = false
function nzsl(backend) function nzsl(backend)
add_repositories("nazara-engine-repo https://github.com/NazaraEngine/xmake-repo") if not nzsl_included then
add_requires("nzsl >=2023.12.31", { configs = { shared = false, nzslc = true } }) add_repositories("nazara-engine-repo https://github.com/NazaraEngine/xmake-repo")
if is_cross() then add_requires("nzsl >=2023.12.31", { configs = { shared = false, nzslc = true } })
add_requires("nzsl~host", { kind = "binary", host = true }) if is_cross() then
end add_requires("nzsl~host", { kind = "binary", host = true })
-- Yoinked from NZSL xmake repo end
rule("find_nzsl") -- Yoinked from NZSL xmake repo
on_config(function(target) rule("find_nzsl")
import("core.project.project") on_config(function(target)
import("core.tool.toolchain") import("core.project.project")
import("lib.detect.find_tool") import("core.tool.toolchain")
local envs import("lib.detect.find_tool")
if is_plat("windows") then local envs
local msvc = target:toolchain("msvc") if is_plat("windows") then
if msvc and msvc:check() then local msvc = target:toolchain("msvc")
envs = msvc:runenvs() if msvc and msvc:check() then
end envs = msvc:runenvs()
elseif is_plat("mingw") then end
local mingw = target:toolchain("mingw") elseif is_plat("mingw") then
if mingw and mingw:check() then local mingw = target:toolchain("mingw")
envs = mingw:runenvs() if mingw and mingw:check() then
end envs = mingw:runenvs()
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 end
end target:data_set("nzsl_envs", envs)
local nzsla = find_tool("nzsla", { version = true, paths = nzsldir, envs = envs }) local nzsl = project.required_package("nzsl~host") or project.required_package("nzsl")
local nzslc = find_tool("nzslc", { version = true, paths = nzsldir, envs = envs }) local nzsldir
target:data_set("nzsla", nzsla) if nzsl then
target:data_set("nzslc", nzslc) nzsldir = path.join(nzsl:installdir(), "bin")
target:data_set("nzsl_runenv", envs) local osenvs = os.getenvs()
end) envs = envs or {}
rule_end() for env, values in pairs(nzsl:get("envs")) do
rule("nzsl_compile_shaders") 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()
nzsl_included = true
end
local name = ""
if backend == Backend.VULKAN then
name = "vulkan"
elseif backend == Backend.OPENGL_ES then
name = "opengl_es"
else
name = "opengl"
end
rule("nzsl_compile_shaders_" .. name)
set_extensions(".nzsl") set_extensions(".nzsl")
add_deps("find_nzsl") add_deps("find_nzsl")
before_buildcmd_file(function(target, batchcmds, shaderfile, opt) before_buildcmd_file(function(target, batchcmds, shaderfile, opt)
@@ -64,7 +80,7 @@ function nzsl(backend)
local argv = {} local argv = {}
if backend == Backend.VULKAN then if backend == Backend.VULKAN then
argv = { "--compile=spv-header", "--optimize" } argv = { "--compile=spv-header", "--optimize" }
elseif backend == Backend.OPENGL then elseif backend == Backend.OPENGL_ES then
argv = { "--compile=glsl-header", "--optimize", "--gl-version", "310", "--gl-es", "--gl-bindingmap" } argv = { "--compile=glsl-header", "--optimize", "--gl-version", "310", "--gl-es", "--gl-bindingmap" }
else else
argv = { "--compile=glsl-header", "--optimize", "--gl-version", "310", "--gl-bindingmap" } argv = { "--compile=glsl-header", "--optimize", "--gl-version", "310", "--gl-bindingmap" }
@@ -79,7 +95,13 @@ function nzsl(backend)
end end
table.insert(argv, shaderfile) table.insert(argv, shaderfile)
batchcmds:vrunv(nzslc.program, argv, { curdir = ".", envs = runenvs }) batchcmds:vrunv(nzslc.program, argv, { curdir = ".", envs = runenvs })
local outputfile = path.join(outputdir or path.directory(shaderfile), path.basename(shaderfile) .. ".spv.h") local ext = ""
if backend == Backend.VULKAN then
ext = ".spv.h"
else
ext = ".glsl.h"
end
local outputfile = path.join(outputdir or path.directory(shaderfile), path.basename(shaderfile) .. ext)
batchcmds:add_depfiles(shaderfile) batchcmds:add_depfiles(shaderfile)
batchcmds:add_depvalues(nzslc.version) batchcmds:add_depvalues(nzslc.version)
batchcmds:set_depmtime(os.mtime(outputfile)) batchcmds:set_depmtime(os.mtime(outputfile))
@@ -95,7 +117,7 @@ local tests = {
nzsl(Backend.VULKAN) nzsl(Backend.VULKAN)
end, end,
custom = function() custom = function()
add_rules("nzsl_compile_shaders") add_rules("nzsl_compile_shaders_vulkan")
add_packages("nzsl") add_packages("nzsl")
add_files("**.nzsl") add_files("**.nzsl")
end end
@@ -103,10 +125,10 @@ local tests = {
OpenGL = { OpenGL = {
option = "opengl", option = "opengl",
global_custom = function() global_custom = function()
nzsl(backend.OPENGL) nzsl(Backend.OPENGL)
end, end,
custom = function() custom = function()
add_rules("nzsl_compile_shaders") add_rules("nzsl_compile_shaders_opengl")
add_packages("nzsl") add_packages("nzsl")
add_files("**.nzsl") add_files("**.nzsl")
end end
@@ -114,10 +136,10 @@ local tests = {
OpenGLES = { OpenGLES = {
option = "opengl-es", option = "opengl-es",
global_custom = function() global_custom = function()
nzsl(Backend.OpenGLES) nzsl(Backend.OPENGL_ES)
end, end,
custom = function() custom = function()
add_rules("nzsl_compile_shaders") add_rules("nzsl_compile_shaders_opengl_es")
add_packages("nzsl") add_packages("nzsl")
add_files("**.nzsl") add_files("**.nzsl")
end end
@@ -161,7 +183,7 @@ for name, module in table.orderpairs(tests) do
end end
for name, module in pairs(tests) do for name, module in pairs(tests) do
if has_config(module.option) then if has_config(module.option .. "-tests") then
if module.global_custom then if module.global_custom then
module.global_custom() module.global_custom()
end end