diff --git a/include/raygpu.h b/include/raygpu.h index 55dd8ea76..5857d21ad 100644 --- a/include/raygpu.h +++ b/include/raygpu.h @@ -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[]; diff --git a/src/backend_wgpu.c b/src/backend_wgpu.c index b3e98ee09..3bee13325 100644 --- a/src/backend_wgpu.c +++ b/src/backend_wgpu.c @@ -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, @@ -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; } @@ -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); diff --git a/src/raygpu.c b/src/raygpu.c index 16d827e75..acd10f16f 100644 --- a/src/raygpu.c +++ b/src/raygpu.c @@ -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 @@ -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){ @@ -3530,4 +3559,4 @@ RGAPI uint32_t getNextShaderID_shc(){ -// end file src/raygpu.c \ No newline at end of file +// end file src/raygpu.c