{"record":{"id":"938528492eff7eca","repo":"stride3d/stride","slug":"the-depth-stencil-format-viewformat-is-not-supported","errorCode":null,"errorMessage":"The Depth-Stencil format [{ViewFormat}] is not supported","messagePattern":"The Depth-Stencil format \\[(.+?)\\] is not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Direct3D11/Texture.Direct3D11.cs","lineNumber":787,"sourceCode":"        ///   Gets a specific <see cref=\"ID3D11DepthStencilView\"/> from the Texture.\n        /// </summary>\n        /// <param name=\"hasStencil\">\n        ///   When the method returns, contains a value indicating if the <see cref=\"ViewFormat\"/> is a Depth format\n        ///   that also contains Stencil data.\n        /// </param>\n        /// <returns>An <see cref=\"ID3D11DepthStencilView\"/> for the Texture.</returns>\n        /// <exception cref=\"NotSupportedException\">The Depth-Stencil format specified is not supported.</exception>\n        /// <exception cref=\"NotSupportedException\">Cannot create a read-only Depth-Stencil View because the device does not support it.</exception>\n        private ComPtr<ID3D11DepthStencilView> GetDepthStencilView(out bool hasStencil)\n        {\n            hasStencil = false;\n\n            if (!IsDepthStencil)\n                return null;\n\n            // Check that the format is supported\n            if (ComputeShaderResourceFormatFromDepthFormat(ViewFormat) == PixelFormat.None)\n                throw new NotSupportedException($\"The Depth-Stencil format [{ViewFormat}] is not supported\");\n\n            // Setup the HasStencil flag\n            hasStencil = IsStencilFormat(ViewFormat);\n\n            // Create a Depth-Stencil View\n            var dsvDescription = new DepthStencilViewDesc\n            {\n                Format = ComputeDepthViewFormatFromTextureFormat(ViewFormat),\n                Flags = 0\n            };\n\n            if (ArraySize > 1)\n            {\n                dsvDescription.ViewDimension = DsvDimension.Texture2Darray;\n                dsvDescription.Texture2DArray.ArraySize = (uint) ArraySize;\n                dsvDescription.Texture2DArray.FirstArraySlice = 0;\n                dsvDescription.Texture2DArray.MipSlice = 0;\n            }","sourceCodeStart":769,"sourceCodeEnd":805,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Direct3D11/Texture.Direct3D11.cs#L769-L805","documentation":"When creating a depth-stencil view, Stride validates the depth format by mapping it to a shader-resource pixel format; if ComputeShaderResourceFormatFromDepthFormat returns PixelFormat.None, the format is not a usable depth-stencil format on this backend and the view cannot be built. The NotSupportedException names the offending ViewFormat.","triggerScenarios":"Creating a texture with TextureFlags.DepthStencil and a ViewFormat that is not a recognized depth format (e.g., a plain color format like R8G8B8A8_UNorm, or an exotic/unsupported depth format) — checked at the top of GetDepthStencilView during InitializeFromImpl.","commonSituations":"Passing a color PixelFormat to a depth texture constructor; loading a texture asset whose format was converted to a non-depth format; typos in format selection (R32_Float instead of D32_Float); platforms where the chosen depth format has no shader-resource mapping.","solutions":["Use a proper depth format such as PixelFormat.D32_Float, D24_UNorm_S8_UInt, D16_UNorm, or D32_Float_S8X24_UInt for depth-stencil textures.","Verify the ViewFormat on the TextureDescription before flagging it DepthStencil.","If the depth texture comes from an asset, check that the importer/serialization did not change its PixelFormat."],"exampleFix":"// before\nvar depth = Texture.New2D(GraphicsDevice, 1024, 1024, PixelFormat.R32_Float,\n    TextureFlags.DepthStencil);\n// after\nvar depth = Texture.New2D(GraphicsDevice, 1024, 1024, PixelFormat.D32_Float,\n    TextureFlags.DepthStencil);","handlingStrategy":"validation","validationCode":"static readonly HashSet<PixelFormat> DepthFormats = new()\n    { PixelFormat.D16_UNorm, PixelFormat.D32_Float, PixelFormat.D24_UNorm_S8_UInt, PixelFormat.D32_Float_S8X24_UInt };\nif ((desc.Flags & TextureFlags.DepthStencil) != 0 && !DepthFormats.Contains(desc.Format))\n    throw new InvalidOperationException($\"{desc.Format} is not a depth format\");","typeGuard":"bool IsDepthFormat(PixelFormat f) => f is PixelFormat.D16_UNorm or PixelFormat.D32_Float\n    or PixelFormat.D24_UNorm_S8_UInt or PixelFormat.D32_Float_S8X24_UInt;","tryCatchPattern":"try { var tex = Texture.New2D(gd, w, h, fmt, TextureFlags.DepthStencil); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"Depth-Stencil format\"))\n{\n    // recreate with PixelFormat.D32_Float or D24_UNorm_S8_UInt\n}","preventionTips":["Only pass D* PixelFormats to depth-stencil texture creation.","Validate asset-declared depth formats at load time."],"tags":["direct3d11","depth-stencil","pixel-format"],"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"}