mirror of
https://github.com/Kbz-8/Pulse.git
synced 2026-01-11 15:33:34 +00:00
adding compute pass
This commit is contained in:
@@ -33,7 +33,14 @@ const char* hlsl_source = HLSL_SOURCE(
|
||||
|
||||
int main(void)
|
||||
{
|
||||
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_D3D11, PULSE_SHADER_FORMAT_HLSL_BIT, PULSE_HIGH_DEBUG);
|
||||
PulseFlags shader_format;
|
||||
#ifdef PULSE_D3D11_COMPILER_UNAVAILABLE
|
||||
shader_format = PULSE_SHADER_FORMAT_DXBC_BIT;
|
||||
#else
|
||||
shader_format = PULSE_SHADER_FORMAT_HLSL_BIT;
|
||||
#endif
|
||||
|
||||
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_D3D11, shader_format, PULSE_HIGH_DEBUG);
|
||||
PulseSetDebugCallback(backend, DebugCallBack);
|
||||
PulseDevice device = PulseCreateDevice(backend, NULL, 0);
|
||||
|
||||
@@ -45,16 +52,30 @@ int main(void)
|
||||
// GPU computations
|
||||
{
|
||||
PulseComputePipelineCreateInfo info = { 0 };
|
||||
info.code_size = strlen(hlsl_source);
|
||||
info.code = (const uint8_t*)hlsl_source;
|
||||
#ifdef PULSE_D3D11_COMPILER_UNAVAILABLE
|
||||
const uint8_t shader_bytecode[] = {
|
||||
#include "shader.cso.h"
|
||||
};
|
||||
info.code_size = sizeof(shader_bytecode);
|
||||
info.code = shader_bytecode;
|
||||
#else
|
||||
info.code_size = strlen(hlsl_source);
|
||||
info.code = (const uint8_t*)hlsl_source;
|
||||
#endif
|
||||
info.entrypoint = "CSMain";
|
||||
info.format = PULSE_SHADER_FORMAT_HLSL_BIT;
|
||||
info.format = shader_format;
|
||||
info.num_readwrite_storage_buffers = 1;
|
||||
PulseComputePipeline pipeline = PulseCreateComputePipeline(device, &info);
|
||||
|
||||
PulseFence fence = PulseCreateFence(device);
|
||||
PulseCommandList cmd = PulseRequestCommandList(device, PULSE_COMMAND_LIST_GENERAL);
|
||||
|
||||
PulseComputePass pass = PulseBeginComputePass(cmd);
|
||||
PulseBindStorageBuffers(pass, &buffer, 1);
|
||||
PulseBindComputePipeline(pass, pipeline);
|
||||
PulseDispatchComputations(pass, 16, 1, 1);
|
||||
PulseEndComputePass(pass);
|
||||
|
||||
PulseSubmitCommandList(device, cmd, fence);
|
||||
PulseWaitForFences(device, &fence, 1, true);
|
||||
|
||||
@@ -63,6 +84,42 @@ int main(void)
|
||||
PulseDestroyComputePipeline(device, pipeline);
|
||||
}
|
||||
|
||||
// Get result and read it on CPU
|
||||
{
|
||||
PulseBufferCreateInfo staging_buffer_create_info = { 0 };
|
||||
staging_buffer_create_info.size = BUFFER_SIZE;
|
||||
staging_buffer_create_info.usage = PULSE_BUFFER_USAGE_TRANSFER_UPLOAD | PULSE_BUFFER_USAGE_TRANSFER_DOWNLOAD;
|
||||
PulseBuffer staging_buffer = PulseCreateBuffer(device, &staging_buffer_create_info);
|
||||
|
||||
PulseFence fence = PulseCreateFence(device);
|
||||
PulseCommandList cmd = PulseRequestCommandList(device, PULSE_COMMAND_LIST_TRANSFER_ONLY);
|
||||
|
||||
PulseBufferRegion src_region = { 0 };
|
||||
src_region.buffer = buffer;
|
||||
src_region.size = BUFFER_SIZE;
|
||||
|
||||
PulseBufferRegion dst_region = { 0 };
|
||||
dst_region.buffer = staging_buffer;
|
||||
dst_region.size = BUFFER_SIZE;
|
||||
|
||||
PulseCopyBufferToBuffer(cmd, &src_region, &dst_region);
|
||||
|
||||
PulseSubmitCommandList(device, cmd, fence);
|
||||
PulseWaitForFences(device, &fence, 1, true);
|
||||
|
||||
void* ptr;
|
||||
PulseMapBuffer(staging_buffer, PULSE_MAP_READ, &ptr);
|
||||
for(uint32_t i = 0; i < BUFFER_SIZE / sizeof(uint32_t); i++)
|
||||
printf("%d, ", ((int32_t*)ptr)[i]);
|
||||
puts("");
|
||||
PulseUnmapBuffer(staging_buffer);
|
||||
|
||||
PulseDestroyBuffer(device, staging_buffer);
|
||||
|
||||
PulseReleaseCommandList(device, cmd);
|
||||
PulseDestroyFence(device, fence);
|
||||
}
|
||||
|
||||
PulseDestroyBuffer(device, buffer);
|
||||
|
||||
PulseDestroyDevice(device);
|
||||
|
||||
44
Examples/D3D11/shader.cso.h
git.filemode.normal_file
44
Examples/D3D11/shader.cso.h
git.filemode.normal_file
@@ -0,0 +1,44 @@
|
||||
0x44, 0x58, 0x42, 0x43, 0x73, 0x34, 0xc8, 0x1f, 0xdb, 0x93, 0x0e, 0xcb,
|
||||
0x41, 0xcd, 0x2e, 0x23, 0xde, 0x7c, 0x23, 0x9b, 0x01, 0x00, 0x00, 0x00,
|
||||
0x08, 0x02, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x34, 0x00, 0x00, 0x00,
|
||||
0xd0, 0x00, 0x00, 0x00, 0xe0, 0x00, 0x00, 0x00, 0xf0, 0x00, 0x00, 0x00,
|
||||
0x6c, 0x01, 0x00, 0x00, 0x52, 0x44, 0x45, 0x46, 0x94, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x3c, 0x00, 0x00, 0x00, 0x00, 0x05, 0x53, 0x43, 0x00, 0x01, 0x00, 0x00,
|
||||
0x61, 0x00, 0x00, 0x00, 0x52, 0x44, 0x31, 0x31, 0x3c, 0x00, 0x00, 0x00,
|
||||
0x18, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00,
|
||||
0x24, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x5c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x73, 0x73, 0x62, 0x6f,
|
||||
0x00, 0x4d, 0x69, 0x63, 0x72, 0x6f, 0x73, 0x6f, 0x66, 0x74, 0x20, 0x28,
|
||||
0x52, 0x29, 0x20, 0x48, 0x4c, 0x53, 0x4c, 0x20, 0x53, 0x68, 0x61, 0x64,
|
||||
0x65, 0x72, 0x20, 0x43, 0x6f, 0x6d, 0x70, 0x69, 0x6c, 0x65, 0x72, 0x20,
|
||||
0x39, 0x2e, 0x32, 0x39, 0x2e, 0x39, 0x35, 0x32, 0x2e, 0x33, 0x31, 0x31,
|
||||
0x31, 0x00, 0xab, 0xab, 0x49, 0x53, 0x47, 0x4e, 0x08, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x4f, 0x53, 0x47, 0x4e,
|
||||
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00,
|
||||
0x53, 0x48, 0x45, 0x58, 0x74, 0x00, 0x00, 0x00, 0x50, 0x00, 0x05, 0x00,
|
||||
0x1d, 0x00, 0x00, 0x00, 0x6a, 0x08, 0x00, 0x01, 0x9c, 0x08, 0x00, 0x04,
|
||||
0x00, 0xe0, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x00, 0x00,
|
||||
0x5f, 0x00, 0x00, 0x02, 0x32, 0x00, 0x02, 0x00, 0x68, 0x00, 0x00, 0x02,
|
||||
0x01, 0x00, 0x00, 0x00, 0x9b, 0x00, 0x00, 0x04, 0x10, 0x00, 0x00, 0x00,
|
||||
0x10, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x26, 0x00, 0x00, 0x06,
|
||||
0x00, 0xd0, 0x00, 0x00, 0x12, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0a, 0x00, 0x02, 0x00, 0x1a, 0x00, 0x02, 0x00, 0xa4, 0x00, 0x00, 0x07,
|
||||
0xf2, 0xe0, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x10, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x3e, 0x00, 0x00, 0x01, 0x53, 0x54, 0x41, 0x54, 0x94, 0x00, 0x00, 0x00,
|
||||
0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00
|
||||
@@ -2,6 +2,7 @@ target("D3D11Example")
|
||||
add_deps("pulse_gpu")
|
||||
if is_plat("linux") then
|
||||
set_extension(".x86_64")
|
||||
add_defines("PULSE_D3D11_COMPILER_UNAVAILABLE")
|
||||
end
|
||||
add_files("*.c")
|
||||
target_end()
|
||||
|
||||
Reference in New Issue
Block a user