working on d3d11 backend

This commit is contained in:
2025-09-05 00:08:58 +02:00
parent 84bb6854c1
commit aceec58473
16 changed files with 269 additions and 68 deletions

View File

@@ -2,6 +2,9 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define HLSL_SOURCE(...) #__VA_ARGS__
void DebugCallBack(PulseDebugMessageSeverity severity, const char* message)
{
@@ -18,12 +21,42 @@ void DebugCallBack(PulseDebugMessageSeverity severity, const char* message)
#define BUFFER_SIZE (256 * sizeof(uint32_t))
const char* hlsl_source = HLSL_SOURCE(
RWStructuredBuffer<int> ssbo : register(u0);
[numthreads(16, 16, 1)]
void CSMain(uint3 grid : SV_DispatchThreadID)
{
ssbo[grid.x * grid.y] = (int)(grid.x * grid.y);
}
);
int main(void)
{
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_D3D11, PULSE_SHADER_FORMAT_DXBC_BIT, PULSE_HIGH_DEBUG);
PulseBackend backend = PulseLoadBackend(PULSE_BACKEND_D3D11, PULSE_SHADER_FORMAT_HLSL_BIT, PULSE_HIGH_DEBUG);
PulseSetDebugCallback(backend, DebugCallBack);
PulseDevice device = PulseCreateDevice(backend, NULL, 0);
PulseBufferCreateInfo buffer_create_info = { 0 };
buffer_create_info.size = BUFFER_SIZE;
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
{
PulseComputePipelineCreateInfo info = { 0 };
info.code_size = strlen(hlsl_source);
info.code = (const uint8_t*)hlsl_source;
info.entrypoint = "CSMain";
info.format = PULSE_SHADER_FORMAT_HLSL_BIT;
info.num_readwrite_storage_buffers = 1;
PulseComputePipeline pipeline = PulseCreateComputePipeline(device, &info);
PulseDestroyComputePipeline(device, pipeline);
}
PulseDestroyBuffer(device, buffer);
PulseDestroyDevice(device);
PulseUnloadBackend(backend);
puts("Successfully executed Pulse example using D3D11 !");