{"record":{"id":"4a513a14f542b4b2","repo":"stride3d/stride","slug":"cannot-create-a-texture-with-format-format-and-multi-sample","errorCode":null,"errorMessage":"Cannot create a Texture with format {Format} and multi-sample level {MultisampleCount}. The maximum supported level is {maxCount}","messagePattern":"Cannot create a Texture with format (.+?) and multi-sample level (.+?)\\. The maximum supported level is (.+?)","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Texture.cs","lineNumber":529,"sourceCode":"            if (ViewFlags == TextureFlags.None)\n            {\n                textureViewDescription.Flags = deviceDescription.Flags;\n            }\n\n            // Check that the Texture View flags are compatible with the parent Texture's flags\n            var filterViewFlags = (TextureFlags)((int)ViewFlags & (~DepthStencilReadOnlyFlags));\n            if ((Flags & filterViewFlags) != filterViewFlags)\n            {\n                throw new NotSupportedException(\n                    $\"Cannot create a Texture View with flags [{ViewFlags}] from the parent Texture with flags [{Flags}]. \" +\n                    $\"The parent Texture must include all the flags defined by the Texture View\");\n            }\n\n            if (IsMultiSampled)\n            {\n                var maxCount = GraphicsDevice.Features[Format].MultisampleCountMax;\n                if (maxCount < MultisampleCount)\n                    throw new NotSupportedException(\n                        $\"Cannot create a Texture with format {Format} and multi-sample level {MultisampleCount}. \" +\n                        $\"The maximum supported level is {maxCount}\");\n            }\n\n            InitializeFromImpl(textureDatas);\n\n            return this;\n        }\n\n        /// <summary>\n        ///   Initializes the Texture with no initial data.\n        /// </summary>\n        private void InitializeFromImpl() => InitializeFromImpl(dataBoxes: null);\n\n        /// <summary>\n        ///   Performs platform-dependent initialization of the Texture.\n        /// </summary>\n        /// <param name=\"dataBoxes\">","sourceCodeStart":511,"sourceCodeEnd":547,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Texture.cs#L511-L547","documentation":"Stride validates multisampled texture creation against the graphics device's capabilities: GraphicsDevice.Features[Format].MultisampleCountMax. If the requested MultisampleCount exceeds the maximum supported for the given pixel format on the current hardware, NotSupportedException is thrown.","triggerScenarios":"Creating a Texture with a MultisampleCount (e.g. 8x or 16x MSAA) greater than the device's per-format limit; running on hardware/drivers with lower MSAA support than the development machine.","commonSituations":"Hard-coded MSAA levels that work on desktop GPUs but fail on integrated/mobile GPUs; format-specific limits (some formats support fewer samples); switching between D3D11/D3D12/Vulkan backends.","solutions":["Clamp MultisampleCount to GraphicsDevice.Features[Format].MultisampleCountMax before creating the texture.","Query the device features at startup and pick the highest supported sample count.","Fall back to a lower MSAA level or non-multisampled rendering when the max is 1."],"exampleFix":"// before\nvar desc = TextureDescription.New2D(w, h, fmt, TextureFlags.RenderTarget);\ndesc.MultisampleCount = 16;\nvar tex = new Texture(device).InitializeFrom(desc);\n// after\nint max = device.Features[fmt].MultisampleCountMax;\nvar desc = TextureDescription.New2D(w, h, fmt, TextureFlags.RenderTarget);\ndesc.MultisampleCount = Math.Min(16, max);\nvar tex = new Texture(device).InitializeFrom(desc);","handlingStrategy":"validation","validationCode":"int maxMsaa = device.Features[format].MultisampleCountMax;\nif (maxMsaa < requestedCount)\n    requestedCount = maxMsaa; // clamp or refuse","typeGuard":"static bool MsaaSupported(GraphicsDevice d, PixelFormat f, int count) => d.Features[f].MultisampleCountMax >= count;","tryCatchPattern":"try { tex = new Texture(device).InitializeFrom(desc); }\ncatch (NotSupportedException)\n{\n    desc.MultisampleCount = device.Features[desc.Format].MultisampleCountMax;\n    tex = new Texture(device).InitializeFrom(desc);\n}","preventionTips":["Never hard-code MSAA levels; always query Features per format.","Test on your minimum-spec target GPU/backend.","Expose MSAA level as a setting clamped at startup."],"tags":["graphics","stride","msaa","hardware-limits"],"backgroundTag":"value-out-of-range","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"}