diff --git a/filament/backend/src/webgpu/WebGPUDriver.cpp b/filament/backend/src/webgpu/WebGPUDriver.cpp index 22606eb506..ca174465bb 100644 --- a/filament/backend/src/webgpu/WebGPUDriver.cpp +++ b/filament/backend/src/webgpu/WebGPUDriver.cpp @@ -431,18 +431,6 @@ void WebGPUDriver::createDefaultRenderTargetR(Handle rth, int) { void WebGPUDriver::createRenderTargetR(Handle rth, TargetBufferFlags targets, uint32_t width, uint32_t height, uint8_t samples, uint8_t layerCount, MRT color, TargetBufferInfo depth, TargetBufferInfo stencil) { - // The `targets` flags indicate which of the `color`, `depth`, `stencil` TargetBufferInfo - // are actually active for this render target. - // We'll pass all TargetBufferInfo to WGPURenderTarget; it will use them if their handles are valid. - - // Ensure that textures intended for use as attachments were created with - // wgpu::TextureUsage::RenderAttachment. This check should ideally be in createTextureR - // or validated here if possible. - - // The `layerCount` parameter might be for creating array textures that this RT targets. - // Individual attachments (color[i].layer, depth.layer, stencil.layer) specify which layer - // of an array texture to bind. For now, we assume textures are pre-configured. - constructHandle(rth, width, height, samples, layerCount, color, depth, stencil); } diff --git a/filament/backend/src/webgpu/WebGPUHandles.cpp b/filament/backend/src/webgpu/WebGPUHandles.cpp index 401cab219b..a3cbbc2fec 100644 --- a/filament/backend/src/webgpu/WebGPUHandles.cpp +++ b/filament/backend/src/webgpu/WebGPUHandles.cpp @@ -638,7 +638,8 @@ WGPUTexture::WGPUTexture(SamplerType samplerType, uint8_t levels, TextureFormat FILAMENT_CHECK_POSTCONDITION(mTexture) << "Failed to create texture for " << textureDescriptor.label; - mDefaultTextureView = makeTextureView(0, levels, 0, mArrayLayerCount, samplerType); + mDefaultTextureView = makeTextureView(mDefaultMipLevel, levels, mDefaultBaseArrayLayer, + mArrayLayerCount, samplerType); } WGPUTexture::WGPUTexture(WGPUTexture* src, uint8_t baseLevel, uint8_t levelCount) noexcept @@ -977,7 +978,10 @@ wgpu::TextureAspect WGPUTexture::fToWGPUTextureViewAspect(TextureUsage const& fU } wgpu::TextureView WGPUTexture::getOrMakeTextureView(uint8_t mipLevel, uint32_t arrayLayer) const { -// TODO: just return mTextureView if redundant + //TODO: there's an optimization to be made here to return mDefaultTextureView. + // Problem: mDefaultTextureView is a view of the entire texture, + // but this function (and its callers) expects a single-slice view. + // Returning the whole texture view for a single-slice request seems wrong. return makeTextureView(mipLevel, 1, arrayLayer, 1, mSamplerType); } diff --git a/filament/backend/src/webgpu/WebGPUHandles.h b/filament/backend/src/webgpu/WebGPUHandles.h index 53f0482c82..c8b5aeba59 100644 --- a/filament/backend/src/webgpu/WebGPUHandles.h +++ b/filament/backend/src/webgpu/WebGPUHandles.h @@ -208,7 +208,8 @@ private: size_t mBlockHeight; SamplerType mSamplerType; wgpu::TextureView mDefaultTextureView = nullptr; - + uint32_t mDefaultMipLevel = 0; + uint32_t mDefaultBaseArrayLayer = 0; [[nodiscard]] wgpu::TextureUsage fToWGPUTextureUsage( filament::backend::TextureUsage const& fUsage);