Skip to content

Commit d7c5d04

Browse files
WebGPU: set usage in texture view descriptor
1 parent 1e3e2fa commit d7c5d04

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

Graphics/GraphicsEngineWebGPU/src/TextureWebGPUImpl.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2023-2024 Diligent Graphics LLC
2+
* Copyright 2023-2025 Diligent Graphics LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -138,6 +138,36 @@ WGPUTextureDescriptor TextureDescToWGPUTextureDescriptor(const TextureDesc&
138138
return wgpuTextureDesc;
139139
}
140140

141+
#if !PLATFORM_EMSCRIPTEN
142+
static WGPUTextureUsage TextureViewTypeToWGPUTextureUsage(TEXTURE_VIEW_TYPE ViewType)
143+
{
144+
static_assert(TEXTURE_VIEW_NUM_VIEWS == 7, "Please update the switch below to handle the new view type");
145+
switch (ViewType)
146+
{
147+
case TEXTURE_VIEW_SHADER_RESOURCE:
148+
return WGPUTextureUsage_TextureBinding;
149+
150+
case TEXTURE_VIEW_RENDER_TARGET:
151+
case TEXTURE_VIEW_DEPTH_STENCIL:
152+
return WGPUTextureUsage_RenderAttachment;
153+
154+
case TEXTURE_VIEW_READ_ONLY_DEPTH_STENCIL:
155+
return WGPUTextureUsage_TextureBinding;
156+
157+
case TEXTURE_VIEW_UNORDERED_ACCESS:
158+
return WGPUTextureUsage_StorageBinding;
159+
160+
case TEXTURE_VIEW_SHADING_RATE:
161+
UNEXPECTED("Shading rate texture views are not supported in WebGPU");
162+
return WGPUTextureUsage_None;
163+
164+
default:
165+
UNEXPECTED("Unexpected view type");
166+
return WGPUTextureUsage_None;
167+
}
168+
}
169+
#endif
170+
141171
WGPUTextureViewDescriptor TextureViewDescToWGPUTextureViewDescriptor(const TextureDesc& TexDesc,
142172
TextureViewDesc& ViewDesc,
143173
const RenderDeviceWebGPUImpl* pRenderDevice) noexcept
@@ -199,6 +229,15 @@ WGPUTextureViewDescriptor TextureViewDescToWGPUTextureViewDescriptor(const Textu
199229
wgpuTextureViewDesc.aspect = WGPUTextureAspect_All;
200230
}
201231

232+
// TODO: enable this as soon as Emscripten adds the usage member to WGPUTextureViewDescriptor
233+
// https://github.com/emscripten-core/emscripten/issues/23945
234+
#if !PLATFORM_EMSCRIPTEN
235+
if (ViewDesc.Format != TexDesc.Format)
236+
{
237+
wgpuTextureViewDesc.usage = TextureViewTypeToWGPUTextureUsage(ViewDesc.ViewType);
238+
}
239+
#endif
240+
202241
return wgpuTextureViewDesc;
203242
}
204243

0 commit comments

Comments
 (0)