Skip to content

Commit 0f6c295

Browse files
WebGPU: Added support for formats without storage flag in mip generator (close #590)
1 parent 4b3ad5d commit 0f6c295

File tree

8 files changed

+517
-204
lines changed

8 files changed

+517
-204
lines changed

Graphics/GraphicsEngineWebGPU/include/DeviceContextWebGPUImpl.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,7 @@ class DeviceContextWebGPUImpl final : public DeviceContextBase<EngineWebGPUImplT
382382

383383
private:
384384
friend class QueryManagerWebGPU;
385+
friend class GenerateMipsHelperWebGPU;
385386

386387
struct WebGPUEncoderState
387388
{

Graphics/GraphicsEngineWebGPU/include/GenerateMipsHelperWebGPU.hpp

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,34 @@ class GenerateMipsHelperWebGPU
4848
GenerateMipsHelperWebGPU& operator = ( GenerateMipsHelperWebGPU&&) = delete;
4949
// clang-format on
5050

51-
void GenerateMips(WGPUComputePassEncoder wgpuCmdEncoder, DeviceContextWebGPUImpl* pDeviceContext, TextureViewWebGPUImpl* pTexView);
51+
void GenerateMips(DeviceContextWebGPUImpl* pDeviceContext, TextureViewWebGPUImpl* pTexView);
5252

5353
private:
5454
using UAVFormats = std::array<TEXTURE_FORMAT, 4>;
5555

56+
struct ShaderModuleCacheKey
57+
{
58+
struct Hasher
59+
{
60+
size_t operator()(const ShaderModuleCacheKey& Key) const;
61+
};
62+
63+
ShaderModuleCacheKey(const UAVFormats& _Formats, SHADER_TYPE _ShaderType) :
64+
Formats{_Formats},
65+
ShaderType{_ShaderType}
66+
{}
67+
68+
bool operator==(const ShaderModuleCacheKey& rhs) const;
69+
70+
size_t GetHash() const;
71+
72+
UAVFormats Formats = {};
73+
SHADER_TYPE ShaderType = {};
74+
75+
private:
76+
mutable size_t Hash = 0;
77+
};
78+
5679
struct ComputePipelineHashKey
5780
{
5881
struct Hasher
@@ -76,41 +99,43 @@ class GenerateMipsHelperWebGPU
7699
mutable size_t Hash = 0;
77100
};
78101

79-
struct ShaderModuleCacheKey
102+
struct RenderPipelineHashKey
80103
{
81104
struct Hasher
82105
{
83-
size_t operator()(const ShaderModuleCacheKey& Key) const;
106+
size_t operator()(const RenderPipelineHashKey& Key) const;
84107
};
85108

86-
ShaderModuleCacheKey(const UAVFormats& Formats) :
87-
Formats{Formats}
88-
{}
109+
RenderPipelineHashKey(TEXTURE_FORMAT _Format) :
110+
Format{_Format} {};
89111

90-
bool operator==(const ShaderModuleCacheKey& rhs) const;
112+
bool operator==(const RenderPipelineHashKey& rhs) const;
91113

92-
size_t GetHash() const;
93-
94-
UAVFormats Formats = {};
95-
96-
private:
97-
mutable size_t Hash = 0;
114+
TEXTURE_FORMAT Format = {};
98115
};
99116

100117
using ComputePipelineGroupLayout = std::pair<WebGPUComputePipelineWrapper, WebGPUBindGroupLayoutWrapper>;
101-
using ComputePipelineCache = std::unordered_map<ComputePipelineHashKey, ComputePipelineGroupLayout, ComputePipelineHashKey::Hasher>;
118+
using RenderPipelineGroupLayout = std::pair<WebGPURenderPipelineWrapper, WebGPUBindGroupLayoutWrapper>;
102119
using ShaderModuleCache = std::unordered_map<ShaderModuleCacheKey, WebGPUShaderModuleWrapper, ShaderModuleCacheKey::Hasher>;
120+
using ComputePipelineCache = std::unordered_map<ComputePipelineHashKey, ComputePipelineGroupLayout, ComputePipelineHashKey::Hasher>;
121+
using RenderPipelineCache = std::unordered_map<RenderPipelineHashKey, RenderPipelineGroupLayout, RenderPipelineHashKey::Hasher>;
103122

104123
void InitializeConstantBuffer();
105124

106125
void InitializeSampler();
107126

108127
void InitializePlaceholderTextures();
109128

110-
WebGPUShaderModuleWrapper& GetShaderModule(const UAVFormats& Formats);
129+
WebGPUShaderModuleWrapper& GetShaderModule(const UAVFormats& Formats, SHADER_TYPE ShaderType);
111130

112131
ComputePipelineGroupLayout& GetComputePipelineAndGroupLayout(const UAVFormats& Formats, Uint32 PowerOfTwo);
113132

133+
RenderPipelineGroupLayout& GetRenderPipelineAndGroupLayout(TEXTURE_FORMAT Format);
134+
135+
void GenerateMips(WGPUComputePassEncoder wgpuCmdEncoder, DeviceContextWebGPUImpl* pDeviceContext, TextureViewWebGPUImpl* pTexView);
136+
137+
void GenerateMips(WGPUCommandEncoder wgpuCmdEncoder, DeviceContextWebGPUImpl* pDeviceContext, TextureViewWebGPUImpl* pTexView);
138+
114139
private:
115140
static constexpr TEXTURE_FORMAT PlaceholderTextureFormat = TEX_FORMAT_RGBA8_UNORM;
116141
static constexpr Uint32 SizeofUniformBuffer = 16u;
@@ -121,10 +146,9 @@ class GenerateMipsHelperWebGPU
121146
RefCntAutoPtr<IBuffer> m_pBuffer;
122147
std::vector<RefCntAutoPtr<ITextureView>> m_PlaceholderTextureViews;
123148

124-
ComputePipelineCache m_PipelineLayoutCache;
149+
ComputePipelineCache m_ComputePipelineLayoutCache;
150+
RenderPipelineCache m_RenderPipelineLayoutCache;
125151
ShaderModuleCache m_ShaderModuleCache;
126-
127-
bool m_IsInitializedResources = false;
128152
};
129153

130154
} // namespace Diligent

Graphics/GraphicsEngineWebGPU/include/TextureViewWebGPUImpl.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ class TextureViewWebGPUImpl final : public TextureViewBase<EngineWebGPUImplTrait
6161

6262
WGPUTextureView GetMipLevelSRV(Uint32 Mip);
6363

64+
WGPUTextureView GetMipLevelRTV(Uint32 Slice, Uint32 Mip);
65+
66+
WGPUTextureView GetMipLevelSRV(Uint32 Slice, Uint32 Mip);
67+
6468
private:
6569
WebGPUTextureViewWrapper m_wgpuTextureView;
6670
std::vector<WebGPUTextureViewWrapper> m_wgpuTextureMipSRVs;

Graphics/GraphicsEngineWebGPU/src/DeviceContextWebGPUImpl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,8 +1577,7 @@ void DeviceContextWebGPUImpl::GenerateMips(ITextureView* pTexView)
15771577
}
15781578

15791579
GenerateMipsHelperWebGPU& MipGenerator = m_pDevice->GetMipsGenerator();
1580-
WGPUComputePassEncoder CmdEncoder = GetComputePassCommandEncoder();
1581-
MipGenerator.GenerateMips(CmdEncoder, this, ClassPtrCast<TextureViewWebGPUImpl>(pTexView));
1580+
MipGenerator.GenerateMips(this, ClassPtrCast<TextureViewWebGPUImpl>(pTexView));
15821581
}
15831582

15841583
void DeviceContextWebGPUImpl::FinishFrame()

0 commit comments

Comments
 (0)