{"record":{"id":"a79d2adec327a3b5","repo":"stride3d/stride","slug":"destination-texture-is-a-msaa-texture","errorCode":null,"errorMessage":"Destination texture is a MSAA texture.","messagePattern":"Destination texture is a MSAA texture\\.","errorType":"exception","errorClass":"ArgumentOutOfRangeException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Rendering/Rendering/Compositing/MSAAResolver.cs","lineNumber":155,"sourceCode":"        protected override void InitializeCore()\n        {\n            base.InitializeCore();\n            ToLoadAndUnload(msaaResolver);\n            ToLoadAndUnload(msaaDepthResolver);\n        }\n\n        protected override void DrawCore(RenderDrawContext drawContext)\n        {\n            var input = GetInput(0);\n            var output = GetOutput(0);\n            if (input == null)\n                throw new ArgumentNullException(nameof(input));\n            if (output == null)\n                throw new ArgumentNullException(nameof(output));\n            if (!input.IsMultiSampled)\n                throw new ArgumentOutOfRangeException(nameof(input), \"Source texture is not a MSAA texture.\");\n            if (output.IsMultiSampled)\n                throw new ArgumentOutOfRangeException(nameof(input), \"Destination texture is a MSAA texture.\");\n\n            // Prepare\n            int samplesCount = (int)input.MultisampleCount;\n            var inputSize = input.Size;\n            // SvPosUnpack = float4(float2(0.5, -0.5) * TextureSize, float2(0.5, 0.5) * TextureSize))\n            // TextureSizeLess1 = TextureSize - 1\n            var svPosUnpack = new Vector4(0.5f * inputSize.Width, -0.5f * inputSize.Height, 0.5f * inputSize.Width, 0.5f * inputSize.Height);\n            var textureSizeLess1 = new Vector2(inputSize.Width - 1.0f, inputSize.Height - 1.0f);\n\n            if (input.IsDepthStencil)\n            {\n                System.Diagnostics.Debug.Assert(output.IsDepthStencil, \"input and output IsDepthStencil don't match\");\n\n                // Resolve using custom pixel shader (output depth only)\n                msaaDepthResolver.DepthStencilState = new DepthStencilStateDescription(true, true) { DepthBufferFunction = CompareFunction.Always };\n                msaaDepthResolver.Parameters.Set(MSAAResolverParams.MSAASamples, samplesCount);\n                msaaDepthResolver.Parameters.Set(MSAADepthResolverShaderKeys.SvPosUnpack, svPosUnpack);\n                msaaDepthResolver.Parameters.Set(MSAADepthResolverShaderKeys.TextureSizeLess1, textureSizeLess1);","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Rendering/Rendering/Compositing/MSAAResolver.cs#L137-L173","documentation":"DrawCore validates output.IsMultiSampled and throws ArgumentOutOfRangeException when the destination texture is itself multisampled. The resolver's job is to produce a single-sampled texture, so writing into another MSAA texture is unsupported; note the message incorrectly uses nameof(input) even though it validates the output.","triggerScenarios":"Binding an MSAA texture (IsMultiSampled == true) to MSAAResolver's output slot 0 and rendering.","commonSituations":"Reusing the same multisampled render target for input and output; creating the resolved target with the same MultisampleCount as the source by copying target-creation code; chaining two resolvers where the second one's output was accidentally created as MSAA.","solutions":["Create the destination texture with MultisampleCount = 1 (non-MSAA).","Ensure input and output are two distinct textures, not the same MSAA target.","If you need MSAA output, don't use MSAAResolver — it resolves MSAA to non-MSAA by design."],"exampleFix":"// before\nresolver.SetOutput(0, msaaTarget); // MSAA texture as destination\n// after\nvar resolved = PushRenderTexture(width, height, 0, PixelFormat.R8G8B8A8_UNorm, TextureFlags.ShaderResource | TextureFlags.RenderTarget, 1); // single-sampled\nresolver.SetOutput(0, resolved);","handlingStrategy":"validation","validationCode":"if (output.IsMultiSampled)\n    throw new InvalidOperationException(\"MSAAResolver output must NOT be an MSAA texture\");\nresolver.SetOutput(0, output);","typeGuard":"bool IsResolvedTarget(Texture t) => t != null && !t.IsMultiSampled;","tryCatchPattern":"try { resolver.SetOutput(0, texture); }\ncatch (ArgumentOutOfRangeException ex) { Log.Error(\"Destination texture must be single-sampled.\", ex); }","preventionTips":["Always create the resolved target with MultisampleCount = 1.","Never reuse the MSAA source texture as the output.","Keep separate factory helpers for MSAA vs resolved target creation to avoid flag mix-ups."],"tags":["rendering","msaa","texture","argument-out-of-range","stride"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}