From 64328b7388dfc27664ef2d4b2bdd14b13f414cc2 Mon Sep 17 00:00:00 2001 From: Jeremy Nelson Date: Mon, 9 Jun 2025 14:48:53 -0700 Subject: [PATCH] pass through defaultDepthStencilFormat --- filament/backend/src/webgpu/WebGPUDriver.cpp | 3 ++ .../backend/src/webgpu/WebGPURenderTarget.cpp | 33 ++++++++++++------- .../backend/src/webgpu/WebGPURenderTarget.h | 1 + 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/filament/backend/src/webgpu/WebGPUDriver.cpp b/filament/backend/src/webgpu/WebGPUDriver.cpp index aec36799c4..063f78d667 100644 --- a/filament/backend/src/webgpu/WebGPUDriver.cpp +++ b/filament/backend/src/webgpu/WebGPUDriver.cpp @@ -807,6 +807,7 @@ void WebGPUDriver::beginRenderPass(Handle renderTargetHandle, wgpu::TextureView defaultColorView = nullptr; wgpu::TextureView defaultDepthStencilView = nullptr; + wgpu::TextureFormat defaultDepthStencilFormat = wgpu::TextureFormat::Undefined; std::array customColorViews{}; uint32_t customColorViewCount = 0; @@ -820,6 +821,7 @@ void WebGPUDriver::beginRenderPass(Handle renderTargetHandle, assert_invariant(mSwapChain && mTextureView); defaultColorView = mTextureView; defaultDepthStencilView = mSwapChain->getDepthTextureView(); + defaultDepthStencilFormat = mSwapChain->getDepthFormat(); } else { // Resolve views for custom render target const auto& colorInfos = renderTarget->getColorAttachmentInfos(); @@ -877,6 +879,7 @@ void WebGPUDriver::beginRenderPass(Handle renderTargetHandle, params, defaultColorView, defaultDepthStencilView, + defaultDepthStencilFormat, customColorViews.data(), customColorViewCount, customDepthView, diff --git a/filament/backend/src/webgpu/WebGPURenderTarget.cpp b/filament/backend/src/webgpu/WebGPURenderTarget.cpp index 6582a6861f..9e68311def 100644 --- a/filament/backend/src/webgpu/WebGPURenderTarget.cpp +++ b/filament/backend/src/webgpu/WebGPURenderTarget.cpp @@ -73,6 +73,7 @@ wgpu::StoreOp WebGPURenderTarget::getStoreOperation(RenderPassParams const& para void WebGPURenderTarget::setUpRenderPassAttachments(wgpu::RenderPassDescriptor& outDescriptor, RenderPassParams const& params, wgpu::TextureView const& defaultColorTextureView, wgpu::TextureView const& defaultDepthStencilTextureView, + wgpu::TextureFormat const& defaultDepthStencilFormat, wgpu::TextureView const* customColorTextureViews, uint32_t customColorTextureViewCount, wgpu::TextureView const& customDepthTextureView, wgpu::TextureView const& customStencilTextureView, @@ -93,30 +94,38 @@ void WebGPURenderTarget::setUpRenderPassAttachments(wgpu::RenderPassDescriptor& if (defaultDepthStencilTextureView) { mDepthStencilAttachmentDescriptor = { .view = defaultDepthStencilTextureView, - .depthLoadOp = WebGPURenderTarget::getLoadOperation(params, TargetBufferFlags::DEPTH), + .depthLoadOp = + WebGPURenderTarget::getLoadOperation(params, TargetBufferFlags::DEPTH), .depthStoreOp = WebGPURenderTarget::getStoreOperation(params, TargetBufferFlags::DEPTH), .depthClearValue = static_cast(params.clearDepth), .depthReadOnly = (params.readOnlyDepthStencil & RenderPassParams::READONLY_DEPTH) > 0, - .stencilLoadOp = - WebGPURenderTarget::getLoadOperation(params, TargetBufferFlags::STENCIL), - .stencilStoreOp = - WebGPURenderTarget::getStoreOperation(params, TargetBufferFlags::STENCIL), - .stencilClearValue = params.clearStencil, - .stencilReadOnly = - (params.readOnlyDepthStencil & RenderPassParams::READONLY_STENCIL) > 0, }; + if (defaultDepthStencilFormat == wgpu::TextureFormat::Depth24PlusStencil8 || + defaultDepthStencilFormat == wgpu::TextureFormat::Depth32FloatStencil8) { + mDepthStencilAttachmentDescriptor.stencilLoadOp = + WebGPURenderTarget::getLoadOperation(params, TargetBufferFlags::STENCIL); + mDepthStencilAttachmentDescriptor.stencilStoreOp = + WebGPURenderTarget::getStoreOperation(params, TargetBufferFlags::STENCIL); + } else { + mDepthStencilAttachmentDescriptor.stencilLoadOp = wgpu::LoadOp::Undefined; + mDepthStencilAttachmentDescriptor.stencilStoreOp = wgpu::StoreOp::Undefined; + } + mDepthStencilAttachmentDescriptor.stencilClearValue = params.clearStencil; + mDepthStencilAttachmentDescriptor.stencilReadOnly = + (params.readOnlyDepthStencil & RenderPassParams::READONLY_STENCIL) > 0; mHasDepthStencilAttachment = true; } - } else {// Custom Render Target + } else { // Custom Render Target for (uint32_t i = 0; i < customColorTextureViewCount; ++i) { if (customColorTextureViews[i]) { mColorAttachmentDescriptors.push_back({ .view = customColorTextureViews[i], // .resolveTarget = nullptr; // TODO: MSAA resolve for custom RT - .loadOp = WebGPURenderTarget::getLoadOperation(params, getTargetBufferFlagsAt(i)), - .storeOp = - WebGPURenderTarget::getStoreOperation(params, getTargetBufferFlagsAt(i)), + .loadOp = + WebGPURenderTarget::getLoadOperation(params, getTargetBufferFlagsAt(i)), + .storeOp = WebGPURenderTarget::getStoreOperation(params, + getTargetBufferFlagsAt(i)), .clearValue = { .r = params.clearColor.r, .g = params.clearColor.g, .b = params.clearColor.b, diff --git a/filament/backend/src/webgpu/WebGPURenderTarget.h b/filament/backend/src/webgpu/WebGPURenderTarget.h index f351026ef9..073357806e 100644 --- a/filament/backend/src/webgpu/WebGPURenderTarget.h +++ b/filament/backend/src/webgpu/WebGPURenderTarget.h @@ -46,6 +46,7 @@ public: // For default render target: wgpu::TextureView const& defaultColorTextureView, wgpu::TextureView const& defaultDepthStencilTextureView, + wgpu::TextureFormat const& defaultDepthStencilFormat, // For custom render targets: wgpu::TextureView const* customColorTextureViews, // Array of views uint32_t customColorTextureViewCount,