{"record":{"id":"a582771adc63108e","repo":"stride3d/stride","slug":"unsupported-depth-format-format-texture-direct3d12","errorCode":null,"errorMessage":"Unsupported depth format [{format}]","messagePattern":"Unsupported depth format \\[(.+?)\\]","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Direct3D12/Texture.Direct3D12.cs","lineNumber":904,"sourceCode":"                    ? (Format) ComputeShaderResourceFormatFromDepthFormat(ViewFormat)\n                    : (Format) ViewFormat;\n\n                return viewFormat;\n            }\n\n            //\n            // Given a pixel format, returns the corresponding Silk.NET's depth format.\n            //\n            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            //\n            // Determines if a format is a Depth-Stencil format that also contains Stencil data.\n            //\n            static bool IsStencilFormat(PixelFormat format)\n            {\n                return format switch\n                {\n                    PixelFormat.R24G8_Typeless or\n                    PixelFormat.D24_UNorm_S8_UInt or\n                    PixelFormat.R32G8X24_Typeless or\n                    PixelFormat.D32_Float_S8X24_UInt => true,\n\n                    _ => false\n                };","sourceCodeStart":886,"sourceCodeEnd":922,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Direct3D12/Texture.Direct3D12.cs#L886-L922","documentation":"Thrown by Texture.InitializeFromImpl on Direct3D12 when computing the DXGI view format for a texture used as a depth buffer, and the given PixelFormat is not one of the four supported depth formats (D16_UNorm, D32_Float, D24_UNorm_S8_UInt, D32_Float_S8X24_UInt) or their typeless variants. Only these formats map to a DXGI depth-stencil resource view format.","triggerScenarios":"Creating a Texture (GraphicsDevice.AllocateTexture / new Texture) with TextureDescription whose Format is a depth-ish format that is not one of R16_Typeless/R16_UNorm, R32_Typeless/D32_Float, R24G8_Typeless/D24_UNorm_S8_UInt, or R32G8X24_Typeless/D32_Float_S8X24_UInt, with DepthStencilImage flag set.","commonSituations":"Passing a color format (e.g. R16_UNorm directly, R8_UNorm) or an unusual depth format like R16_UNorm_R16_X8_Typeless as DepthBuffer; porting code from another engine that used raw DXGI formats; misconfigured render target descriptors.","solutions":["Change the texture Format to one of PixelFormat.D16_UNorm, PixelFormat.D32_Float, PixelFormat.D24_UNorm_S8_UInt, or PixelFormat.D32_Float_S8X24_UInt.","If you need the typeless forms for shader-resource binding, use R16_Typeless, R32_Typeless, R24G8_Typeless, or R32G8X24_Typeless.","Check TextureDescription.DepthFormat or the pipeline description that produced the format; do not reuse a color format for depth."],"exampleFix":"// before\nvar texture = Texture.New2D(device, 1024, 1024, PixelFormat.R16_UNorm, TextureFlags.DepthStencil);\n// after\nvar texture = Texture.New2D(device, 1024, 1024, PixelFormat.D16_UNorm, TextureFlags.DepthStencil);","handlingStrategy":"validation","validationCode":"static readonly PixelFormat[] SupportedDepthFormats =\n{\n    PixelFormat.D16_UNorm, PixelFormat.D32_Float,\n    PixelFormat.D24_UNorm_S8_UInt, PixelFormat.D32_Float_S8X24_UInt,\n    PixelFormat.R16_Typeless, PixelFormat.R32_Typeless,\n    PixelFormat.R24G8_Typeless, PixelFormat.R32G8X24_Typeless\n};\nif (Array.IndexOf(SupportedDepthFormats, desc.Format) < 0)\n    throw new ArgumentException($\"{desc.Format} is not a supported depth format\");","typeGuard":"bool IsSupportedDepthFormat(PixelFormat f) =>\n    f is PixelFormat.D16_UNorm or PixelFormat.D32_Float\n      or PixelFormat.D24_UNorm_S8_UInt or PixelFormat.D32_Float_S8X24_UInt\n      or PixelFormat.R16_Typeless or PixelFormat.R32_Typeless\n      or PixelFormat.R24G8_Typeless or PixelFormat.R32G8X24_Typeless;","tryCatchPattern":"try { var tex = Texture.New2D(device, w, h, format, TextureFlags.DepthStencil); }\ncatch (NotSupportedException ex) { log.Error(ex, \"Depth format rejected\"); useFallbackDepthFormat(); }","preventionTips":["Always use one of the four canonical depth PixelFormats for depth-stencil targets.","Use GraphicsDevice.Factory or helper overloads (Texture.New2D with PixelFormat.D32_Float) instead of raw TextureDescription edits.","Keep depth format selection centralized in one helper for the project."],"tags":["direct3d12","depth-buffer","pixel-format","texture"],"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"}