mirror of
https://github.com/Kbz-8/Pulse.git
synced 2026-01-11 07:23:35 +00:00
fixing descriptor sets, adding buffer compute write test
This commit is contained in:
@@ -271,6 +271,60 @@ void TestBufferCopyImage()
|
||||
CleanupPulse(backend);
|
||||
}
|
||||
|
||||
void TestBufferComputeWrite()
|
||||
{
|
||||
PulseBackend backend;
|
||||
SetupPulse(&backend);
|
||||
PulseDevice device;
|
||||
SetupDevice(backend, &device);
|
||||
|
||||
const uint8_t shader_bytecode[] = {
|
||||
#include "Shaders/SimpleBufferWrite.spv.h"
|
||||
};
|
||||
|
||||
PulseBufferCreateInfo buffer_create_info = { 0 };
|
||||
buffer_create_info.size = 256 * sizeof(int32_t);
|
||||
buffer_create_info.usage = PULSE_BUFFER_USAGE_STORAGE_READ | PULSE_BUFFER_USAGE_STORAGE_WRITE | PULSE_BUFFER_USAGE_TRANSFER_DOWNLOAD;
|
||||
PulseBuffer buffer = PulseCreateBuffer(device, &buffer_create_info);
|
||||
TEST_ASSERT_NOT_EQUAL_MESSAGE(buffer, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
|
||||
|
||||
PulseComputePipeline pipeline;
|
||||
LoadComputePipeline(device, &pipeline, shader_bytecode, sizeof(shader_bytecode), 0, 0, 0, 1, 0);
|
||||
|
||||
PulseFence fence = PulseCreateFence(device);
|
||||
TEST_ASSERT_NOT_EQUAL_MESSAGE(fence, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
|
||||
PulseCommandList cmd = PulseRequestCommandList(device, PULSE_COMMAND_LIST_GENERAL);
|
||||
TEST_ASSERT_NOT_EQUAL_MESSAGE(cmd, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
|
||||
|
||||
PulseComputePass pass = PulseBeginComputePass(cmd);
|
||||
TEST_ASSERT_NOT_EQUAL_MESSAGE(pass, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
|
||||
PulseBindStorageBuffers(pass, 0, &buffer, 1);
|
||||
PulseBindComputePipeline(pass, pipeline);
|
||||
PulseDispatchComputations(pass, 32, 32, 1);
|
||||
PulseEndComputePass(pass);
|
||||
|
||||
TEST_ASSERT_TRUE_MESSAGE(PulseSubmitCommandList(device, cmd, fence), PulseVerbaliseErrorType(PulseGetLastErrorType()));
|
||||
TEST_ASSERT_TRUE_MESSAGE(PulseWaitForFences(device, &fence, 1, true), PulseVerbaliseErrorType(PulseGetLastErrorType()));
|
||||
|
||||
{
|
||||
void* ptr;
|
||||
uint32_t data[256];
|
||||
memset(data, 0xFF, 256 * sizeof(uint32_t));
|
||||
TEST_ASSERT_NOT_EQUAL_MESSAGE(PulseMapBuffer(buffer, &ptr), false, PulseVerbaliseErrorType(PulseGetLastErrorType()));
|
||||
TEST_ASSERT_NOT_NULL(ptr);
|
||||
TEST_ASSERT_EQUAL(memcmp(ptr, data, 256 * sizeof(uint32_t)), 0);
|
||||
PulseUnmapBuffer(buffer);
|
||||
}
|
||||
|
||||
PulseReleaseCommandList(device, cmd);
|
||||
PulseDestroyFence(device, fence);
|
||||
PulseDestroyBuffer(device, buffer);
|
||||
|
||||
CleanupPipeline(device, pipeline);
|
||||
CleanupDevice(device);
|
||||
CleanupPulse(backend);
|
||||
}
|
||||
|
||||
void TestBufferDestruction()
|
||||
{
|
||||
PulseBackend backend;
|
||||
@@ -310,5 +364,6 @@ void TestBuffer()
|
||||
RUN_TEST(TestBufferMapping);
|
||||
RUN_TEST(TestBufferCopy);
|
||||
RUN_TEST(TestBufferCopyImage);
|
||||
RUN_TEST(TestBufferComputeWrite);
|
||||
RUN_TEST(TestBufferDestruction);
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ void SetupPulse(PulseBackend* backend)
|
||||
void SetupDevice(PulseBackend backend, PulseDevice* device)
|
||||
{
|
||||
*device = PulseCreateDevice(backend, NULL, 0);
|
||||
TEST_ASSERT_NOT_EQUAL_MESSAGE(device, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
|
||||
TEST_ASSERT_NOT_EQUAL_MESSAGE(*device, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
|
||||
}
|
||||
|
||||
void CleanupDevice(PulseDevice device)
|
||||
@@ -41,3 +41,30 @@ void CleanupPulse(PulseBackend backend)
|
||||
{
|
||||
PulseUnloadBackend(backend);
|
||||
}
|
||||
|
||||
void LoadComputePipeline(PulseDevice device, PulseComputePipeline* pipeline, const uint8_t* code, uint32_t code_size,
|
||||
uint32_t num_readonly_storage_images,
|
||||
uint32_t num_readonly_storage_buffers,
|
||||
uint32_t num_readwrite_storage_images,
|
||||
uint32_t num_readwrite_storage_buffers,
|
||||
uint32_t num_uniform_buffers)
|
||||
{
|
||||
PulseComputePipelineCreateInfo info = { 0 };
|
||||
info.code_size = code_size;
|
||||
info.code = code;
|
||||
info.entrypoint = "main";
|
||||
info.format = PULSE_SHADER_FORMAT_SPIRV_BIT;
|
||||
info.num_readonly_storage_images = num_readonly_storage_images;
|
||||
info.num_readonly_storage_buffers = num_readonly_storage_buffers;
|
||||
info.num_readwrite_storage_buffers = num_readwrite_storage_buffers;
|
||||
info.num_readwrite_storage_images = num_readwrite_storage_images;
|
||||
info.num_uniform_buffers = num_uniform_buffers;
|
||||
|
||||
*pipeline = PulseCreateComputePipeline(device, &info);
|
||||
TEST_ASSERT_NOT_EQUAL_MESSAGE(*pipeline, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
|
||||
}
|
||||
|
||||
void CleanupPipeline(PulseDevice device, PulseComputePipeline pipeline)
|
||||
{
|
||||
PulseDestroyComputePipeline(device, pipeline);
|
||||
}
|
||||
|
||||
@@ -32,5 +32,12 @@ void SetupPulse(PulseBackend* backend);
|
||||
void SetupDevice(PulseBackend backend, PulseDevice* device);
|
||||
void CleanupDevice(PulseDevice device);
|
||||
void CleanupPulse(PulseBackend backend);
|
||||
void LoadComputePipeline(PulseDevice device, PulseComputePipeline* pipeline, const uint8_t* code, uint32_t code_size,
|
||||
uint32_t num_readonly_storage_images,
|
||||
uint32_t num_readonly_storage_buffers,
|
||||
uint32_t num_readwrite_storage_images,
|
||||
uint32_t num_readwrite_storage_buffers,
|
||||
uint32_t num_uniform_buffers);
|
||||
void CleanupPipeline(PulseDevice device, PulseComputePipeline pipeline);
|
||||
|
||||
#endif
|
||||
|
||||
1
Tests/Vulkan/Shaders/.gitignore
vendored
git.filemode.normal_file
1
Tests/Vulkan/Shaders/.gitignore
vendored
git.filemode.normal_file
@@ -0,0 +1 @@
|
||||
*.spv.h
|
||||
25
Tests/Vulkan/Shaders/SimpleBufferWrite.nzsl
git.filemode.normal_file
25
Tests/Vulkan/Shaders/SimpleBufferWrite.nzsl
git.filemode.normal_file
@@ -0,0 +1,25 @@
|
||||
[nzsl_version("1.0")]
|
||||
module;
|
||||
|
||||
struct Input
|
||||
{
|
||||
[builtin(global_invocation_indices)] indices: vec3[u32]
|
||||
}
|
||||
|
||||
[layout(std430)]
|
||||
struct SSBO
|
||||
{
|
||||
data: dyn_array[u32]
|
||||
}
|
||||
|
||||
external
|
||||
{
|
||||
[set(1), binding(0)] ssbo: storage[SSBO],
|
||||
}
|
||||
|
||||
[entry(compute)]
|
||||
[workgroup(32, 32, 1)]
|
||||
fn main(input: Input)
|
||||
{
|
||||
ssbo.data[input.indices.x * input.indices.y] = u32(0xFFFFFFFF);
|
||||
}
|
||||
@@ -1,5 +1,95 @@
|
||||
option("vulkan-tests", { description = "Build Vulkan tests", default = false })
|
||||
|
||||
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("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()
|
||||
|
||||
if has_config("vulkan-tests") then
|
||||
set_group("VulkanTests")
|
||||
add_requires("unity_test")
|
||||
@@ -7,7 +97,9 @@ if has_config("vulkan-tests") then
|
||||
target("VulkanUnitTests")
|
||||
set_kind("binary")
|
||||
add_deps("pulse_gpu")
|
||||
add_rules("compile_shaders")
|
||||
add_files("**.c")
|
||||
add_files("**.nzsl")
|
||||
add_packages("unity_test")
|
||||
if is_plat("linux") then
|
||||
set_extension(".x86_64")
|
||||
|
||||
Reference in New Issue
Block a user