adding pipeline unit tests

This commit is contained in:
2025-02-21 22:41:22 +01:00
parent 2de2e1f381
commit b5abfe1589
14 changed files with 497 additions and 7 deletions

View File

@@ -325,6 +325,75 @@ void TestBufferComputeWrite()
CleanupPulse(backend);
}
void TestBufferComputeCopy()
{
PulseBackend backend;
SetupPulse(&backend);
PulseDevice device;
SetupDevice(backend, &device);
const uint8_t shader_bytecode[] = {
#include "Shaders/BufferCopy.spv.h"
};
uint32_t data[256];
memset(data, 0xFF, 256 * sizeof(uint32_t));
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_TRANSFER_UPLOAD;
PulseBuffer read_buffer = PulseCreateBuffer(device, &buffer_create_info);
TEST_ASSERT_NOT_EQUAL_MESSAGE(read_buffer, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
{
void* ptr;
TEST_ASSERT_NOT_EQUAL_MESSAGE(PulseMapBuffer(read_buffer, &ptr), false, PulseVerbaliseErrorType(PulseGetLastErrorType()));
TEST_ASSERT_NOT_NULL(ptr);
memcpy(ptr, data, 256 * sizeof(uint32_t));
PulseUnmapBuffer(read_buffer);
}
buffer_create_info.usage = PULSE_BUFFER_USAGE_STORAGE_WRITE | PULSE_BUFFER_USAGE_TRANSFER_DOWNLOAD;
PulseBuffer write_buffer = PulseCreateBuffer(device, &buffer_create_info);
TEST_ASSERT_NOT_EQUAL_MESSAGE(write_buffer, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
PulseComputePipeline pipeline;
LoadComputePipeline(device, &pipeline, shader_bytecode, sizeof(shader_bytecode), 0, 1, 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, &read_buffer, 1);
PulseBindStorageBuffers(pass, 0, &write_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;
TEST_ASSERT_NOT_EQUAL_MESSAGE(PulseMapBuffer(write_buffer, &ptr), false, PulseVerbaliseErrorType(PulseGetLastErrorType()));
TEST_ASSERT_NOT_NULL(ptr);
TEST_ASSERT_EQUAL(memcmp(ptr, data, 256 * sizeof(uint32_t)), 0);
PulseUnmapBuffer(write_buffer);
}
PulseReleaseCommandList(device, cmd);
PulseDestroyFence(device, fence);
PulseDestroyBuffer(device, read_buffer);
PulseDestroyBuffer(device, write_buffer);
CleanupPipeline(device, pipeline);
CleanupDevice(device);
CleanupPulse(backend);
}
void TestBufferDestruction()
{
PulseBackend backend;
@@ -365,5 +434,6 @@ void TestBuffer()
RUN_TEST(TestBufferCopy);
RUN_TEST(TestBufferCopyImage);
RUN_TEST(TestBufferComputeWrite);
RUN_TEST(TestBufferComputeCopy);
RUN_TEST(TestBufferDestruction);
}

View File

@@ -10,6 +10,211 @@ void TestPipelineSetup()
PulseDevice device;
SetupDevice(backend, &device);
const uint8_t shader_bytecode[] = {
#include "Shaders/Simple.spv.h"
};
PulseComputePipeline pipeline;
LoadComputePipeline(device, &pipeline, shader_bytecode, sizeof(shader_bytecode), 0, 0, 0, 0, 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()));
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()));
PulseReleaseCommandList(device, cmd);
PulseDestroyFence(device, fence);
CleanupPipeline(device, pipeline);
CleanupDevice(device);
CleanupPulse(backend);
}
void TestPipelineReadOnlyBindings()
{
PulseBackend backend;
SetupPulse(&backend);
PulseDevice device;
SetupDevice(backend, &device);
const uint8_t shader_bytecode[] = {
#include "Shaders/ReadOnlyBindings.spv.h"
};
PulseBufferCreateInfo buffer_create_info = { 0 };
buffer_create_info.size = 256 * sizeof(int32_t);
buffer_create_info.usage = PULSE_BUFFER_USAGE_STORAGE_READ;
PulseBuffer buffer = PulseCreateBuffer(device, &buffer_create_info);
TEST_ASSERT_NOT_EQUAL_MESSAGE(buffer, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
PulseImageCreateInfo image_create_info = { 0 };
image_create_info.type = PULSE_IMAGE_TYPE_2D;
image_create_info.format = PULSE_IMAGE_FORMAT_R8G8B8A8_UNORM;
image_create_info.usage = PULSE_IMAGE_USAGE_STORAGE_READ;
image_create_info.width = 256;
image_create_info.height = 256;
image_create_info.layer_count_or_depth = 1;
PulseImage image = PulseCreateImage(device, &image_create_info);
TEST_ASSERT_NOT_EQUAL_MESSAGE(image, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
PulseComputePipeline pipeline;
LoadComputePipeline(device, &pipeline, shader_bytecode, sizeof(shader_bytecode), 1, 1, 0, 0, 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);
PulseBindStorageImages(pass, 1, &image, 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()));
PulseReleaseCommandList(device, cmd);
PulseDestroyFence(device, fence);
PulseDestroyBuffer(device, buffer);
PulseDestroyImage(device, image);
CleanupPipeline(device, pipeline);
CleanupDevice(device);
CleanupPulse(backend);
}
void TestPipelineWriteOnlyBindings()
{
PulseBackend backend;
SetupPulse(&backend);
PulseDevice device;
SetupDevice(backend, &device);
const uint8_t shader_bytecode[] = {
#include "Shaders/ReadOnlyBindings.spv.h"
};
PulseBufferCreateInfo buffer_create_info = { 0 };
buffer_create_info.size = 256 * sizeof(int32_t);
buffer_create_info.usage = PULSE_BUFFER_USAGE_STORAGE_WRITE;
PulseBuffer buffer = PulseCreateBuffer(device, &buffer_create_info);
TEST_ASSERT_NOT_EQUAL_MESSAGE(buffer, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
PulseImageCreateInfo image_create_info = { 0 };
image_create_info.type = PULSE_IMAGE_TYPE_2D;
image_create_info.format = PULSE_IMAGE_FORMAT_R8G8B8A8_UNORM;
image_create_info.usage = PULSE_IMAGE_USAGE_STORAGE_WRITE;
image_create_info.width = 256;
image_create_info.height = 256;
image_create_info.layer_count_or_depth = 1;
PulseImage image = PulseCreateImage(device, &image_create_info);
TEST_ASSERT_NOT_EQUAL_MESSAGE(image, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
PulseComputePipeline pipeline;
LoadComputePipeline(device, &pipeline, shader_bytecode, sizeof(shader_bytecode), 0, 0, 1, 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);
PulseBindStorageImages(pass, 1, &image, 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()));
PulseReleaseCommandList(device, cmd);
PulseDestroyFence(device, fence);
PulseDestroyBuffer(device, buffer);
PulseDestroyImage(device, image);
CleanupPipeline(device, pipeline);
CleanupDevice(device);
CleanupPulse(backend);
}
void TestPipelineReadWriteBindings()
{
PulseBackend backend;
SetupPulse(&backend);
PulseDevice device;
SetupDevice(backend, &device);
const uint8_t shader_bytecode[] = {
#include "Shaders/ReadOnlyBindings.spv.h"
};
PulseBufferCreateInfo buffer_create_info = { 0 };
buffer_create_info.size = 256 * sizeof(int32_t);
buffer_create_info.usage = PULSE_BUFFER_USAGE_STORAGE_READ;
PulseBuffer read_buffer = PulseCreateBuffer(device, &buffer_create_info);
TEST_ASSERT_NOT_EQUAL_MESSAGE(read_buffer, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
buffer_create_info.usage = PULSE_BUFFER_USAGE_STORAGE_WRITE;
PulseBuffer write_buffer = PulseCreateBuffer(device, &buffer_create_info);
TEST_ASSERT_NOT_EQUAL_MESSAGE(write_buffer, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
PulseImageCreateInfo image_create_info = { 0 };
image_create_info.type = PULSE_IMAGE_TYPE_2D;
image_create_info.format = PULSE_IMAGE_FORMAT_R8G8B8A8_UNORM;
image_create_info.usage = PULSE_IMAGE_USAGE_STORAGE_READ;
image_create_info.width = 256;
image_create_info.height = 256;
image_create_info.layer_count_or_depth = 1;
PulseImage read_image = PulseCreateImage(device, &image_create_info);
TEST_ASSERT_NOT_EQUAL_MESSAGE(read_image, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
image_create_info.usage = PULSE_IMAGE_USAGE_STORAGE_WRITE;
PulseImage write_image = PulseCreateImage(device, &image_create_info);
TEST_ASSERT_NOT_EQUAL_MESSAGE(write_image, PULSE_NULL_HANDLE, PulseVerbaliseErrorType(PulseGetLastErrorType()));
PulseComputePipeline pipeline;
LoadComputePipeline(device, &pipeline, shader_bytecode, sizeof(shader_bytecode), 1, 1, 1, 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, &read_buffer, 1);
PulseBindStorageBuffers(pass, 0, &write_buffer, 1);
PulseBindStorageImages(pass, 1, &read_image, 1);
PulseBindStorageImages(pass, 1, &write_image, 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()));
PulseReleaseCommandList(device, cmd);
PulseDestroyFence(device, fence);
PulseDestroyBuffer(device, read_buffer);
PulseDestroyBuffer(device, write_buffer);
PulseDestroyImage(device, read_image);
PulseDestroyImage(device, write_image);
CleanupPipeline(device, pipeline);
CleanupDevice(device);
CleanupPulse(backend);
}
@@ -17,4 +222,7 @@ void TestPipelineSetup()
void TestPipeline()
{
RUN_TEST(TestPipelineSetup);
RUN_TEST(TestPipelineReadOnlyBindings);
RUN_TEST(TestPipelineWriteOnlyBindings);
RUN_TEST(TestPipelineReadWriteBindings);
}

26
Tests/Vulkan/Shaders/BufferCopy.nzsl git.filemode.normal_file
View File

@@ -0,0 +1,26 @@
[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_ssbo: storage[SSBO, readonly],
[set(1), binding(0)] write_ssbo: storage[SSBO, writeonly],
}
[entry(compute)]
[workgroup(32, 32, 1)]
fn main(input: Input)
{
write_ssbo.data[input.indices.x * input.indices.y] = read_ssbo.data[input.indices.x * input.indices.y];
}

25
Tests/Vulkan/Shaders/ReadOnlyBindings.nzsl git.filemode.normal_file
View 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(0), binding(0)] read_ssbo: storage[SSBO, readonly],
[set(0), binding(1)] read_texture: texture2D[f32, readonly, rgba8],
}
[entry(compute)]
[workgroup(32, 32, 1)]
fn main(input: Input)
{
}

27
Tests/Vulkan/Shaders/ReadWriteBindings.nzsl git.filemode.normal_file
View File

@@ -0,0 +1,27 @@
[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_ssbo: storage[SSBO, readonly],
[set(0), binding(1)] read_texture: texture2D[f32, readonly, rgba8],
[set(1), binding(0)] write_ssbo: storage[SSBO, writeonly],
[set(1), binding(1)] write_texture: texture2D[f32, readonly, rgba8],
}
[entry(compute)]
[workgroup(32, 32, 1)]
fn main(input: Input)
{
}

13
Tests/Vulkan/Shaders/Simple.nzsl git.filemode.normal_file
View File

@@ -0,0 +1,13 @@
[nzsl_version("1.0")]
module;
struct Input
{
[builtin(global_invocation_indices)] indices: vec3[u32]
}
[entry(compute)]
[workgroup(32, 32, 1)]
fn main(input: Input)
{
}

25
Tests/Vulkan/Shaders/WriteOnlyBindings.nzsl git.filemode.normal_file
View 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)] write_ssbo: storage[SSBO],
[set(1), binding(1)] write_texture: texture2D[f32, readonly, rgba8],
}
[entry(compute)]
[workgroup(32, 32, 1)]
fn main(input: Input)
{
}

View File

@@ -7,6 +7,7 @@ extern void TestBackend();
extern void TestDevice();
extern void TestBuffer();
extern void TestImage();
extern void TestPipeline();
int main(void)
{
@@ -15,5 +16,6 @@ int main(void)
TestDevice();
TestBuffer();
TestImage();
TestPipeline();
return UNITY_END();
}