mirror of
https://github.com/Kbz-8/Pulse.git
synced 2026-01-11 07:23:35 +00:00
software
This commit is contained in:
@@ -29,6 +29,38 @@ int main(void)
|
||||
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);
|
||||
|
||||
// GPU computations
|
||||
{
|
||||
const uint8_t shader_bytecode[] = {
|
||||
#include "shader.spv.h"
|
||||
};
|
||||
|
||||
PulseComputePipelineCreateInfo info = { 0 };
|
||||
info.code_size = sizeof(shader_bytecode);
|
||||
info.code = shader_bytecode;
|
||||
info.entrypoint = "main";
|
||||
info.format = PULSE_SHADER_FORMAT_SPIRV_BIT;
|
||||
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);
|
||||
|
||||
PulseReleaseCommandList(device, cmd);
|
||||
PulseDestroyFence(device, fence);
|
||||
PulseDestroyComputePipeline(device, pipeline);
|
||||
}
|
||||
|
||||
|
||||
// Get result and read it on CPU
|
||||
{
|
||||
PulseBufferCreateInfo staging_buffer_create_info = { 0 };
|
||||
|
||||
@@ -14,12 +14,12 @@ struct SSBO
|
||||
|
||||
external
|
||||
{
|
||||
[set(1), binding(0)] ssbo: storage[SSBO],
|
||||
//[set(1), binding(0)] ssbo: storage[SSBO],
|
||||
}
|
||||
|
||||
[entry(compute)]
|
||||
[workgroup(32, 32, 1)]
|
||||
[workgroup(16, 16, 1)]
|
||||
fn main(input: Input)
|
||||
{
|
||||
ssbo.data[input.indices.x * input.indices.y] = i32(input.indices.x * input.indices.y);
|
||||
//ssbo.data[input.indices.x * input.indices.y] = i32(input.indices.x * input.indices.y);
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ int main(void)
|
||||
PulseComputePass pass = PulseBeginComputePass(cmd);
|
||||
PulseBindStorageBuffers(pass, &buffer, 1);
|
||||
PulseBindComputePipeline(pass, pipeline);
|
||||
PulseDispatchComputations(pass, 32, 32, 1);
|
||||
PulseDispatchComputations(pass, 16, 1, 1);
|
||||
PulseEndComputePass(pass);
|
||||
|
||||
PulseSubmitCommandList(device, cmd, fence);
|
||||
|
||||
@@ -18,7 +18,7 @@ external
|
||||
}
|
||||
|
||||
[entry(compute)]
|
||||
[workgroup(32, 32, 1)]
|
||||
[workgroup(16, 16, 1)]
|
||||
fn main(input: Input)
|
||||
{
|
||||
ssbo.data[input.indices.x * input.indices.y] = i32(input.indices.x * input.indices.y);
|
||||
|
||||
@@ -24,7 +24,7 @@ void DebugCallBack(PulseDebugMessageSeverity severity, const char* message)
|
||||
const char* wgsl_source = WGSL_SOURCE(
|
||||
@group(1) @binding(0) var<storage, read_write> ssbo: array<i32>;
|
||||
|
||||
@compute @workgroup_size(32, 32, 1)
|
||||
@compute @workgroup_size(16, 16, 1)
|
||||
fn main(@builtin(global_invocation_id) grid: vec3<u32>)
|
||||
{
|
||||
ssbo[grid.x * grid.y] = i32(grid.x * grid.y);
|
||||
@@ -58,7 +58,7 @@ int main(void)
|
||||
PulseComputePass pass = PulseBeginComputePass(cmd);
|
||||
PulseBindStorageBuffers(pass, &buffer, 1);
|
||||
PulseBindComputePipeline(pass, pipeline);
|
||||
PulseDispatchComputations(pass, 32, 32, 1);
|
||||
PulseDispatchComputations(pass, 16, 1, 1);
|
||||
PulseEndComputePass(pass);
|
||||
|
||||
PulseSubmitCommandList(device, cmd, fence);
|
||||
|
||||
Reference in New Issue
Block a user