diff options
Diffstat (limited to 'src/gpu/effects/post_process_helper.cc')
| -rw-r--r-- | src/gpu/effects/post_process_helper.cc | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/src/gpu/effects/post_process_helper.cc b/src/gpu/effects/post_process_helper.cc index 0a2ac22..4c1d3e1 100644 --- a/src/gpu/effects/post_process_helper.cc +++ b/src/gpu/effects/post_process_helper.cc @@ -18,7 +18,7 @@ WGPURenderPipeline create_post_process_pipeline(WGPUDevice device, WGPUShaderModule shader_module = wgpuDeviceCreateShaderModule(device, &shader_desc); - WGPUBindGroupLayoutEntry bgl_entries[3] = {}; + WGPUBindGroupLayoutEntry bgl_entries[4] = {}; bgl_entries[0].binding = PP_BINDING_SAMPLER; bgl_entries[0].visibility = WGPUShaderStage_Fragment; bgl_entries[0].sampler.type = WGPUSamplerBindingType_Filtering; @@ -30,8 +30,13 @@ WGPURenderPipeline create_post_process_pipeline(WGPUDevice device, bgl_entries[2].visibility = WGPUShaderStage_Vertex | WGPUShaderStage_Fragment; bgl_entries[2].buffer.type = WGPUBufferBindingType_Uniform; + // Add an entry for effect-specific parameters + bgl_entries[3].binding = PP_BINDING_EFFECT_PARAMS; + bgl_entries[3].visibility = WGPUShaderStage_Fragment; + bgl_entries[3].buffer.type = WGPUBufferBindingType_Uniform; + WGPUBindGroupLayoutDescriptor bgl_desc = {}; - bgl_desc.entryCount = 3; + bgl_desc.entryCount = 4; bgl_desc.entries = bgl_entries; WGPUBindGroupLayout bgl = wgpuDeviceCreateBindGroupLayout(device, &bgl_desc); @@ -63,9 +68,15 @@ WGPURenderPipeline create_post_process_pipeline(WGPUDevice device, } // --- PostProcess Implementation Helper --- +static GpuBuffer g_dummy_buffer = {nullptr, 0}; + void pp_update_bind_group(WGPUDevice device, WGPURenderPipeline pipeline, WGPUBindGroup* bind_group, WGPUTextureView input_view, - GpuBuffer uniforms) { + GpuBuffer uniforms, GpuBuffer effect_params) { + if (!g_dummy_buffer.buffer) { + g_dummy_buffer = gpu_create_buffer(device, 16, WGPUBufferUsage_Uniform); + } + if (*bind_group) wgpuBindGroupRelease(*bind_group); WGPUBindGroupLayout bgl = wgpuRenderPipelineGetBindGroupLayout(pipeline, 0); @@ -74,7 +85,7 @@ void pp_update_bind_group(WGPUDevice device, WGPURenderPipeline pipeline, sd.minFilter = WGPUFilterMode_Linear; sd.maxAnisotropy = 1; WGPUSampler sampler = wgpuDeviceCreateSampler(device, &sd); - WGPUBindGroupEntry bge[3] = {}; + WGPUBindGroupEntry bge[4] = {}; bge[0].binding = PP_BINDING_SAMPLER; bge[0].sampler = sampler; bge[1].binding = PP_BINDING_TEXTURE; @@ -82,7 +93,10 @@ void pp_update_bind_group(WGPUDevice device, WGPURenderPipeline pipeline, bge[2].binding = PP_BINDING_UNIFORMS; bge[2].buffer = uniforms.buffer; bge[2].size = uniforms.size; + bge[3].binding = PP_BINDING_EFFECT_PARAMS; + bge[3].buffer = effect_params.buffer ? effect_params.buffer : g_dummy_buffer.buffer; + bge[3].size = effect_params.buffer ? effect_params.size : g_dummy_buffer.size; WGPUBindGroupDescriptor bgd = { - .layout = bgl, .entryCount = 3, .entries = bge}; + .layout = bgl, .entryCount = 4, .entries = bge}; *bind_group = wgpuDeviceCreateBindGroup(device, &bgd); } |
