Skip to content

Commit

Permalink
Expose sampler and sampling types in binding layout explicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
Nelarius committed Mar 28, 2024
1 parent ab0708f commit bdc371f
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
11 changes: 8 additions & 3 deletions src/pt/hybrid_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ HybridRenderer::HybridRenderer(
gpuContext.device,
"Gbuffer bind group layout",
std::array<WGPUBindGroupLayoutEntry, 2>{
textureBindGroupLayoutEntry(0), textureBindGroupLayoutEntry(1)}};
textureBindGroupLayoutEntry(0, WGPUTextureSampleType_UnfilterableFloat),
textureBindGroupLayoutEntry(1, WGPUTextureSampleType_UnfilterableFloat)}};

mGbufferBindGroup = GpuBindGroup{
gpuContext.device,
Expand Down Expand Up @@ -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,
Expand All @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion src/pt/texture_blit_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ TextureBlitRenderer::TextureBlitRenderer(
// texture bind group
{
std::array<const WGPUBindGroupLayoutEntry, 2> textureBindGroupLayoutEntries{
textureBindGroupLayoutEntry(0), samplerBindGroupLayoutEntry(1)};
textureBindGroupLayoutEntry(0, WGPUTextureSampleType_Float),
samplerBindGroupLayoutEntry(1, WGPUSamplerBindingType_Filtering)};
mTextureBindGroupLayout = GpuBindGroupLayout{
gpuContext.device, "Texture bind group layout", textureBindGroupLayoutEntries};

Expand Down
12 changes: 8 additions & 4 deletions src/pt/webgpu_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
},
Expand All @@ -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,
Expand All @@ -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,
Expand Down

0 comments on commit bdc371f

Please sign in to comment.