|
1 | 1 | /* |
2 | | - * Copyright 2023-2024 Diligent Graphics LLC |
| 2 | + * Copyright 2023-2025 Diligent Graphics LLC |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -138,6 +138,36 @@ WGPUTextureDescriptor TextureDescToWGPUTextureDescriptor(const TextureDesc& |
138 | 138 | return wgpuTextureDesc; |
139 | 139 | } |
140 | 140 |
|
| 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 | + |
141 | 171 | WGPUTextureViewDescriptor TextureViewDescToWGPUTextureViewDescriptor(const TextureDesc& TexDesc, |
142 | 172 | TextureViewDesc& ViewDesc, |
143 | 173 | const RenderDeviceWebGPUImpl* pRenderDevice) noexcept |
@@ -199,6 +229,15 @@ WGPUTextureViewDescriptor TextureViewDescToWGPUTextureViewDescriptor(const Textu |
199 | 229 | wgpuTextureViewDesc.aspect = WGPUTextureAspect_All; |
200 | 230 | } |
201 | 231 |
|
| 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 | + |
202 | 241 | return wgpuTextureViewDesc; |
203 | 242 | } |
204 | 243 |
|
|
0 commit comments