{"record":{"id":"cb823892115a125e","repo":"stride3d/stride","slug":"unsupported-depth-format-format-texture-direct3d11","errorCode":null,"errorMessage":"Unsupported depth format [{format}]","messagePattern":"Unsupported depth format \\[(.+?)\\]","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Direct3D11/Texture.Direct3D11.cs","lineNumber":1077,"sourceCode":"\n        /// <summary>\n        ///   Given a pixel format, returns the corresponding Silk.NET's depth format.\n        /// </summary>\n        /// <param name=\"format\">The pixel format.</param>\n        /// <returns>The depth <see cref=\"Silk.NET.DXGI.Format\"/> corresponding to <paramref name=\"format\"/>.</returns>\n        /// <exception cref=\"NotSupportedException\">\n        ///   The <paramref name=\"format\"/> does not have a corresponding depth format.\n        /// </exception>\n        internal static Format ComputeDepthViewFormatFromTextureFormat(PixelFormat format)\n        {\n            var viewFormat = format switch\n            {\n                PixelFormat.R16_Typeless or PixelFormat.D16_UNorm => Silk.NET.DXGI.Format.FormatD16Unorm,\n                PixelFormat.R32_Typeless or PixelFormat.D32_Float => Silk.NET.DXGI.Format.FormatD32Float,\n                PixelFormat.R24G8_Typeless or PixelFormat.D24_UNorm_S8_UInt => Silk.NET.DXGI.Format.FormatD24UnormS8Uint,\n                PixelFormat.R32G8X24_Typeless or PixelFormat.D32_Float_S8X24_UInt => Silk.NET.DXGI.Format.FormatD32FloatS8X24Uint,\n\n                _ => throw new NotSupportedException($\"Unsupported depth format [{format}]\")\n            };\n            return viewFormat;\n        }\n\n        /// <summary>\n        ///   Returns a native <see cref=\"Texture3DDesc\"/> from the current <see cref=\"TextureDescription\"/>.\n        /// </summary>\n        /// <returns>A Silk.NET's <see cref=\"Texture3DDesc\"/> describing the Texture.</returns>\n        private Texture3DDesc ConvertToNativeDescription3D()\n        {\n            var desc = new Texture3DDesc\n            {\n                Width = (uint) textureDescription.Width,\n                Height = (uint) textureDescription.Height,\n                Depth = (uint) textureDescription.Depth,\n                BindFlags = (uint) GetBindFlagsFromTextureFlags(textureDescription.Flags),\n                Format = (Format) textureDescription.Format,\n                MipLevels = (uint) textureDescription.MipLevelCount,","sourceCodeStart":1059,"sourceCodeEnd":1095,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Direct3D11/Texture.Direct3D11.cs#L1059-L1095","documentation":"Thrown by ComputeDepthViewFormatFromTextureFormat when the texture's pixel format cannot be translated into a DXGI format for a Depth-Stencil View. Only the typeless/depth pairs (R16/D16, R32/D32, R24G8/D24S8, R32G8X24/D32S8X24) are valid; anything else is rejected with NotSupportedException while building the DSV description during texture initialization.","triggerScenarios":"Initializing a D3D11 texture with DepthStencil flags whose Format is a color or non-depth format (e.g. R8_UNorm, R16_Float), so the DSV format lookup in InitializeFromImpl / dsvDescription fails.","commonSituations":"Reusing a color render-target texture as a depth buffer, configuring a shadow map with a floating-point color format instead of a depth format, or a typo in the PixelFormat enum.","solutions":["Use a depth-capable PixelFormat: D16_UNorm, D32_Float, D24_UNorm_S8_UInt, D32_Float_S8X24_UInt, or their typeless forms R16_Typeless, R32_Typeless, R24G8_Typeless, R32G8X24_Typeless.","Drop the DepthStencil flag from textures that only need ShaderResource/RenderTarget flags.","If reading depth in shaders is needed, sample the typeless depth texture with a shader-resource view created from the matching depth format."],"exampleFix":"// before\nTexture.New2D(device, w, h, PixelFormat.R16_Float, TextureFlags.DepthStencil | TextureFlags.ShaderResource);\n// after\nTexture.New2D(device, w, h, PixelFormat.R32_Typeless, TextureFlags.DepthStencil | TextureFlags.ShaderResource);","handlingStrategy":"validation","validationCode":"bool ok = format is PixelFormat.R16_Typeless or PixelFormat.D16_UNorm or PixelFormat.R32_Typeless or PixelFormat.D32_Float\n                        or PixelFormat.R24G8_Typeless or PixelFormat.D24_UNorm_S8_UInt or PixelFormat.R32G8X24_Typeless or PixelFormat.D32_Float_S8X24_UInt;","typeGuard":"static bool HasDepthViewFormat(PixelFormat f) => f is PixelFormat.R16_Typeless or PixelFormat.D16_UNorm or PixelFormat.R32_Typeless or PixelFormat.D32_Float or PixelFormat.R24G8_Typeless or PixelFormat.D24_UNorm_S8_UInt or PixelFormat.R32G8X24_Typeless or PixelFormat.D32_Float_S8X24_UInt;","tryCatchPattern":"try { dsvTexture = CreateDepthTarget(device, w, h, format); }\ncatch (NotSupportedException) { dsvTexture = CreateDepthTarget(device, w, h, PixelFormat.D32_Float); }","preventionTips":["For shadow maps sample-able in shaders, use R32_Typeless / R24G8_Typeless, not R32_Float / R16_Float.","Validate every TextureFlags.DepthStencil texture against HasDepthViewFormat at startup.","Never repurpose a color render-target texture as a depth target."],"tags":["graphics","direct3d11","depth-stencil","view-format","unsupported-format"],"backgroundTag":"unsupported-enum-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"}