| 38 | } |
| 39 | |
| 40 | void GPUTextureViewWebGPU::Create(WGPUTexture texture, const WGPUTextureViewDescriptor& desc, uint16 version) |
| 41 | { |
| 42 | Ptr.ObjectVersion = version; |
| 43 | Ptr.ViewVersion++; |
| 44 | if (ViewRender && View != ViewRender) |
| 45 | wgpuTextureViewRelease(ViewRender); |
| 46 | if (View) |
| 47 | wgpuTextureViewRelease(View); |
| 48 | Texture = texture; |
| 49 | |
| 50 | auto viewDesc = desc; |
| 51 | auto renderDesc = desc; |
| 52 | auto separateViews = false; |
| 53 | |
| 54 | // Render views cannot have more than 1 mip levels count |
| 55 | if (desc.usage & WGPUTextureUsage_RenderAttachment && renderDesc.mipLevelCount > 1) |
| 56 | { |
| 57 | renderDesc.mipLevelCount = 1; |
| 58 | separateViews = true; |
| 59 | } |
| 60 | |
| 61 | // Depth-stencil textures expose depth-only when binding to shaders (unless via custom _handleStencil view) so make separate ViewRender for rendering with all components |
| 62 | if (desc.aspect == WGPUTextureAspect_All && ::HasStencil(desc.format)) |
| 63 | { |
| 64 | viewDesc.aspect = WGPUTextureAspect_DepthOnly; |
| 65 | viewDesc.format = DropStencil(viewDesc.format); |
| 66 | separateViews = true; |
| 67 | } |
| 68 | |
| 69 | // Create views |
| 70 | View = wgpuTextureCreateView(texture, &viewDesc); |
| 71 | if (!View) |
| 72 | { |
| 73 | #if GPU_ENABLE_RESOURCE_NAMING |
| 74 | LOG(Error, "Failed to create a view for texture '{}'", GetParent() ? GetParent()->GetName() : StringView::Empty); |
| 75 | #else |
| 76 | LOG(Error, "Failed to create a view for texture"); |
| 77 | #endif |
| 78 | } |
| 79 | if (separateViews) |
| 80 | ViewRender = wgpuTextureCreateView(texture, &renderDesc); |
| 81 | else |
| 82 | ViewRender = View; |
| 83 | |
| 84 | // Cache metadata |
| 85 | Format = desc.format; |
| 86 | switch (Format) |
| 87 | { |
| 88 | case WGPUTextureFormat_Depth16Unorm: |
| 89 | case WGPUTextureFormat_Depth24Plus: |
| 90 | case WGPUTextureFormat_Depth24PlusStencil8: |
| 91 | case WGPUTextureFormat_Depth32Float: |
| 92 | case WGPUTextureFormat_Depth32FloatStencil8: |
| 93 | // https://www.w3.org/TR/webgpu/#depth-formats |
| 94 | SampleType = WGPUTextureSampleType_UnfilterableFloat; |
| 95 | break; |
| 96 | case WGPUTextureFormat_Stencil8: |
| 97 | // https://www.w3.org/TR/webgpu/#depth-formats |
no test coverage detected