Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/raygpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,7 @@ externcvar WGPUBuffer vbo_buf;
externcvar VertexArray* renderBatchVAO;
externcvar DescribedBuffer* renderBatchVBO;
externcvar PrimitiveType current_drawmode;
externcvar DescribedComputePipeline* g_activeComputePipeline;
externcvar char telegrama_render1[];
externcvar char telegrama_render2[];
externcvar char telegrama_render3[];
Expand Down
11 changes: 6 additions & 5 deletions src/backend_wgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,9 @@ inline WGPUVertexFormat f32format(uint32_t s) {
rg_unreachable();
}
void BindComputePipeline(DescribedComputePipeline *pipeline) {
g_activeComputePipeline = pipeline;
wgpuComputePassEncoderSetPipeline((WGPUComputePassEncoder)g_renderstate.computepass.cpEncoder,
(WGPUComputePipeline)pipeline->pipeline);
wgpuComputePassEncoderSetBindGroup((WGPUComputePassEncoder)g_renderstate.computepass.cpEncoder,
0,
(WGPUBindGroup)UpdateAndGetNativeBindGroup(&pipeline->bindGroup),
0,
0);
}
void CopyBufferToBuffer(DescribedBuffer *source, DescribedBuffer *dest, size_t count) {
wgpuCommandEncoderCopyBufferToBuffer((WGPUCommandEncoder)g_renderstate.computepass.cmdEncoder,
Expand Down Expand Up @@ -120,9 +116,13 @@ void CopyTextureToTexture(Texture source, Texture dest) {
}

void DispatchCompute(uint32_t x, uint32_t y, uint32_t z) {
if(g_activeComputePipeline) {
ComputePassSetBindGroup(&g_renderstate.computepass, 0, &g_activeComputePipeline->bindGroup);
}
wgpuComputePassEncoderDispatchWorkgroups((WGPUComputePassEncoder)g_renderstate.computepass.cpEncoder, x, y, z);
}
void ComputepassEndOnlyComputing(cwoid) {
g_activeComputePipeline = NULL;
wgpuComputePassEncoderEnd((WGPUComputePassEncoder)g_renderstate.computepass.cpEncoder);
g_renderstate.computepass.cpEncoder = NULL;
}
Expand Down Expand Up @@ -197,6 +197,7 @@ RGAPI Texture3D LoadTexture3DPro(
return ret;
}
void EndComputepassEx(DescribedComputepass *computePass) {
g_activeComputePipeline = NULL;
if (computePass->cpEncoder) {
wgpuComputePassEncoderEnd((WGPUComputePassEncoder)computePass->cpEncoder);
wgpuComputePassEncoderRelease((WGPUComputePassEncoder)computePass->cpEncoder);
Expand Down
47 changes: 38 additions & 9 deletions src/raygpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ WGPUBuffer vbo_buf = 0;
VertexArray* renderBatchVAO;
DescribedBuffer* renderBatchVBO;
PrimitiveType current_drawmode;
DescribedComputePipeline* g_activeComputePipeline = NULL;
//DescribedBuffer vbomap;

#if RAYGPU_NO_INLINE_FUNCTIONS == 1
Expand Down Expand Up @@ -2192,26 +2193,54 @@ Shader GetActiveShader(){
}

void SetTexture (uint32_t index, Texture tex){
SetShaderTexture(GetActiveShader(), index, tex);
if(g_activeComputePipeline){
SetBindgroupTexture(&g_activeComputePipeline->bindGroup, index, tex);
} else {
SetShaderTexture(GetActiveShader(), index, tex);
}
}
RGAPI void SetTextureView (uint32_t index, WGPUTextureView tex){
ShaderImpl* sh = allocatedShaderIDs_shc + GetActiveShader().id;
SetBindgroupTextureView(&sh->bindGroup, index, tex);
if(g_activeComputePipeline){
SetBindgroupTextureView(&g_activeComputePipeline->bindGroup, index, tex);
} else {
ShaderImpl* sh = allocatedShaderIDs_shc + GetActiveShader().id;
SetBindgroupTextureView(&sh->bindGroup, index, tex);
}
}
void SetSampler (uint32_t index, DescribedSampler sampler){
SetShaderSampler (GetActiveShader(), index, sampler);
if(g_activeComputePipeline){
SetBindgroupSampler(&g_activeComputePipeline->bindGroup, index, sampler);
} else {
SetShaderSampler (GetActiveShader(), index, sampler);
}
}
void SetUniformBuffer (uint32_t index, DescribedBuffer* buffer){
SetShaderUniformBuffer (GetActiveShader(), index, buffer);
if(g_activeComputePipeline){
SetBindgroupUniformBuffer(&g_activeComputePipeline->bindGroup, index, buffer);
} else {
SetShaderUniformBuffer (GetActiveShader(), index, buffer);
}
}
void SetStorageBuffer (uint32_t index, DescribedBuffer* buffer){
SetShaderStorageBuffer(GetActiveShader(), index, buffer);
if(g_activeComputePipeline){
SetBindgroupStorageBuffer(&g_activeComputePipeline->bindGroup, index, buffer);
} else {
SetShaderStorageBuffer(GetActiveShader(), index, buffer);
}
}
void SetUniformBufferData (uint32_t index, const void* data, size_t size){
SetShaderUniformBufferData(GetActiveShader(), index, data, size);
if(g_activeComputePipeline){
SetBindgroupUniformBufferData(&g_activeComputePipeline->bindGroup, index, data, size);
} else {
SetShaderUniformBufferData(GetActiveShader(), index, data, size);
}
}
void SetStorageBufferData (uint32_t index, const void* data, size_t size){
SetShaderStorageBufferData(GetActiveShader(), index, data, size);
if(g_activeComputePipeline){
SetBindgroupStorageBufferData(&g_activeComputePipeline->bindGroup, index, data, size);
} else {
SetShaderStorageBufferData(GetActiveShader(), index, data, size);
}
}

void SetBindgroupUniformBuffer (DescribedBindGroup* bg, uint32_t index, DescribedBuffer* buffer){
Expand Down Expand Up @@ -3530,4 +3559,4 @@ RGAPI uint32_t getNextShaderID_shc(){



// end file src/raygpu.c
// end file src/raygpu.c