From bdc371fd0e2ff1f9233697f8193482941aeb965e Mon Sep 17 00:00:00 2001 From: Johann Muszynski Date: Thu, 28 Mar 2024 09:00:36 +0200 Subject: [PATCH] Expose sampler and sampling types in binding layout explicitly --- src/pt/hybrid_renderer.cpp | 11 ++++++++--- src/pt/texture_blit_renderer.cpp | 3 ++- src/pt/webgpu_utils.hpp | 12 ++++++++---- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/pt/hybrid_renderer.cpp b/src/pt/hybrid_renderer.cpp index 7cb8736..e9a0677 100644 --- a/src/pt/hybrid_renderer.cpp +++ b/src/pt/hybrid_renderer.cpp @@ -135,7 +135,8 @@ HybridRenderer::HybridRenderer( gpuContext.device, "Gbuffer bind group layout", std::array{ - textureBindGroupLayoutEntry(0), textureBindGroupLayoutEntry(1)}}; + textureBindGroupLayoutEntry(0, WGPUTextureSampleType_UnfilterableFloat), + textureBindGroupLayoutEntry(1, WGPUTextureSampleType_UnfilterableFloat)}}; mGbufferBindGroup = GpuBindGroup{ gpuContext.device, @@ -458,7 +459,9 @@ HybridRenderer::GbufferPass::GbufferPass( } const GpuBindGroupLayout samplerBindGroupLayout{ - gpuContext.device, "Sampler bind group layout", samplerBindGroupLayoutEntry(0)}; + gpuContext.device, + "Sampler bind group layout", + samplerBindGroupLayoutEntry(0, WGPUSamplerBindingType_Filtering)}; mSamplerBindGroup = GpuBindGroup{ gpuContext.device, @@ -467,7 +470,9 @@ HybridRenderer::GbufferPass::GbufferPass( samplerBindGroupEntry(0, mBaseColorSampler)}; const GpuBindGroupLayout textureBindGroupLayout{ - gpuContext.device, "Texture bind group layout", textureBindGroupLayoutEntry(0)}; + gpuContext.device, + "Texture bind group layout", + textureBindGroupLayoutEntry(0, WGPUTextureSampleType_Float)}; std::transform( mBaseColorTextures.begin(), diff --git a/src/pt/texture_blit_renderer.cpp b/src/pt/texture_blit_renderer.cpp index 59b4408..593bcab 100644 --- a/src/pt/texture_blit_renderer.cpp +++ b/src/pt/texture_blit_renderer.cpp @@ -96,7 +96,8 @@ TextureBlitRenderer::TextureBlitRenderer( // texture bind group { std::array textureBindGroupLayoutEntries{ - textureBindGroupLayoutEntry(0), samplerBindGroupLayoutEntry(1)}; + textureBindGroupLayoutEntry(0, WGPUTextureSampleType_Float), + samplerBindGroupLayoutEntry(1, WGPUSamplerBindingType_Filtering)}; mTextureBindGroupLayout = GpuBindGroupLayout{ gpuContext.device, "Texture bind group layout", textureBindGroupLayoutEntries}; diff --git a/src/pt/webgpu_utils.hpp b/src/pt/webgpu_utils.hpp index 938aa16..5e9c8b3 100644 --- a/src/pt/webgpu_utils.hpp +++ b/src/pt/webgpu_utils.hpp @@ -142,7 +142,9 @@ inline WGPUBindGroupEntry bufferBindGroupEntry( }; } -inline WGPUBindGroupLayoutEntry textureBindGroupLayoutEntry(const std::uint32_t bindingIdx) +inline WGPUBindGroupLayoutEntry textureBindGroupLayoutEntry( + const std::uint32_t bindingIdx, + const WGPUTextureSampleType sampleType) { return WGPUBindGroupLayoutEntry{ .nextInChain = nullptr, @@ -153,7 +155,7 @@ inline WGPUBindGroupLayoutEntry textureBindGroupLayoutEntry(const std::uint32_t .texture = WGPUTextureBindingLayout{ .nextInChain = nullptr, - .sampleType = WGPUTextureSampleType_Float, + .sampleType = sampleType, .viewDimension = WGPUTextureViewDimension_2D, .multisampled = false, }, @@ -176,7 +178,9 @@ inline WGPUBindGroupEntry textureBindGroupEntry( }; } -inline WGPUBindGroupLayoutEntry samplerBindGroupLayoutEntry(const std::uint32_t bindingIdx) +inline WGPUBindGroupLayoutEntry samplerBindGroupLayoutEntry( + const std::uint32_t bindingIdx, + const WGPUSamplerBindingType samplerType) { return WGPUBindGroupLayoutEntry{ .nextInChain = nullptr, @@ -186,7 +190,7 @@ inline WGPUBindGroupLayoutEntry samplerBindGroupLayoutEntry(const std::uint32_t .sampler = WGPUSamplerBindingLayout{ .nextInChain = nullptr, - .type = WGPUSamplerBindingType_Filtering, + .type = samplerType, }, .texture = DEFAULT_TEXTURE_BINDING_LAYOUT, .storageTexture = DEFAULT_STORAGE_TEXTURE_BINDING_LAYOUT,