{"record":{"id":"45ab09be64af51e0","repo":"BabylonJS/Babylon.js","slug":"framegraphcleartexturetask-this-name-the-depth-45ab09","errorCode":null,"errorMessage":"FrameGraphClearTextureTask ${this.name}: the depth texture (${depthSamples} samples) and the target texture (${textureSamples} samples) must have the same number of samples.","messagePattern":"FrameGraphClearTextureTask (.+?): the depth texture \\((.+?) samples\\) and the target texture \\((.+?) samples\\) must have the same number of samples\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/core/src/FrameGraph/Tasks/Texture/clearTextureTask.ts","lineNumber":104,"sourceCode":"        }\r\n        if (this.depthTexture !== undefined) {\r\n            textureManager.resolveDanglingHandle(this.outputDepthTexture, this.depthTexture);\r\n        }\r\n        if (this.targetTexture !== undefined && this.depthTexture !== undefined) {\r\n            const targetDescription = textureManager.getTextureDescription(targetTextures![0]);\r\n            const depthDescription = textureManager.getTextureDescription(this.depthTexture);\r\n\r\n            if (targetDescription.size.width !== depthDescription.size.width || targetDescription.size.height !== depthDescription.size.height) {\r\n                throw new Error(\r\n                    `FrameGraphClearTextureTask ${this.name}: the depth texture (size: ${depthDescription.size.width}x${depthDescription.size.height}) and the target texture (size: ${targetDescription.size.width}x${targetDescription.size.height}) must have the same dimensions.`\r\n                );\r\n            }\r\n\r\n            const textureSamples = targetDescription.options.samples || 1;\r\n            const depthSamples = depthDescription.options.samples || 1;\r\n\r\n            if (textureSamples !== depthSamples && textureSamples !== 0 && depthSamples !== 0) {\r\n                throw new Error(\r\n                    `FrameGraphClearTextureTask ${this.name}: the depth texture (${depthSamples} samples) and the target texture (${textureSamples} samples) must have the same number of samples.`\r\n                );\r\n            }\r\n        }\r\n\r\n        const attachments = this._frameGraph.engine.buildTextureLayout(\r\n            targetTextures ? Array(targetTextures.length).fill(true) : [],\r\n            this.targetTexture === backbufferColorTextureHandle && !this._frameGraph.textureManager.backBufferTextureOverriden\r\n        );\r\n\r\n        const color = TmpColors.Color4[0];\r\n\r\n        const pass = this._frameGraph.addRenderPass(this.name);\r\n\r\n        pass.setRenderTarget(targetTextures);\r\n        pass.setRenderTargetDepth(this.depthTexture);\r\n        pass.setInitializeFunc(() => {\r\n            const renderTargetWrapper = pass.frameGraphRenderTarget.renderTargetWrapper;\r","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/core/src/FrameGraph/Tasks/Texture/clearTextureTask.ts#L86-L122","documentation":"FrameGraphClearTextureTask.record() validates that the depth texture attachment and the target (color) texture have the same sample count. In Babylon.js FrameGraph, rendering to a texture and simultaneously clearing an MSAA depth attachment requires matching samples, otherwise the GPU render pass layout is invalid. The check treats samples of 0 or 1 as equivalent non-MSAA, and throws only when both are non-zero and differ.","triggerScenarios":"Adding a FrameGraphClearTextureTask, setting both task.depthTexture and task.targetTexture (via task target/depth handle assignment), then calling frameGraph.build()/task.record() where one texture was created with options.samples > 1 (e.g. 4) and the other with samples 1/undefined.","commonSituations":"Mixing an MSAA target texture created via createTexture with samples:4 and a non-MSAA depth texture handle; wiring a depth texture from another task that has different sampling; copying pipeline configs between WebGPU (MSAA) and WebGL (non-MSAA) projects.","solutions":["Set the depth texture's options.samples to match the target texture's samples (or vice versa) when creating the texture descriptions/handles.","If you don't need depth clearing, remove the depthTexture assignment so only the color target is cleared.","If you don't need MSAA, set samples to 1 (or 0) on both textures so the check passes."],"exampleFix":"// before\nconst target = fg.createTexture({ name: 'color', options: { samples: 4 } });\nconst depth = fg.createTexture({ name: 'depth', options: {} });\nclearTask.targetTexture = target;\nclearTask.depthTexture = depth;\n// after\nconst depth = fg.createTexture({ name: 'depth', options: { samples: 4 } });","handlingStrategy":"validation","validationCode":"const tSamples = targetDesc.options.samples || 1;\nconst dSamples = depthDesc.options.samples || 1;\nif (tSamples !== dSamples) {\n  throw new Error(`Sample mismatch: target=${tSamples}, depth=${dSamples}`);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Create depth textures with the same options.samples as their paired color targets in a shared helper.","Centralize texture creation so MSAA settings come from a single config object."],"tags":["babylonjs","framegraph","msaa","texture","validation"],"backgroundTag":"msaa-sample-count-mismatch","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}