@@ -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
5353private:
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+
114139private:
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
0 commit comments