{"record":{"id":"af426bedf9c9f87f","repo":"stride3d/stride","slug":"this-depth-stencil-format-is-not-supported","errorCode":null,"errorMessage":"This Depth-Stencil format is not supported","messagePattern":"This Depth-Stencil format is not supported","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Texture.Extensions.cs","lineNumber":65,"sourceCode":"        var viewDescription = texture.ViewDescription;\n        viewDescription.Flags = TextureFlags.DepthStencilReadOnly;\n        return texture.ToTextureView(viewDescription);\n    }\n\n    /// <summary>\n    ///   Creates a Shader Resource View on a Depth-Stencil Texture.\n    /// </summary>\n    /// <param name=\"texture\">The Texture to create a Depth-Stencil Texture View for.</param>\n    /// <returns>A new <see cref=\"Texture\"/> representing the Texture View bound to <paramref name=\"texture\"/>.</returns>\n    public static Texture CreateDepthTextureCompatible(this Texture texture)\n    {\n        if (!texture.IsDepthStencil)\n            throw new NotSupportedException(\"This Texture is not a valid Depth-Stencil Texture\");\n\n        var description = texture.Description;\n        description.Format = Texture.ComputeShaderResourceFormatFromDepthFormat(description.Format); // TODO: review this\n        if (description.Format == PixelFormat.None)\n            throw new NotSupportedException(\"This Depth-Stencil format is not supported\");\n\n        description.Flags = TextureFlags.ShaderResource;\n        return Texture.New(texture.GraphicsDevice, description);\n    }\n\n    /// <summary>\n    ///   Verifies that a given <see cref=\"Texture\"/> is a Render Target.\n    /// </summary>\n    /// <param name=\"texture\"></param>\n    /// <returns></returns>\n    /// <exception cref=\"ArgumentException\"></exception>\n    public static Texture EnsureRenderTarget(this Texture texture)\n    {\n        if (texture is not null && !texture.IsRenderTarget)\n        {\n            throw new ArgumentException(\"The Texture must be a Render Target\", nameof(texture));\n        }\n        return texture;","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Texture.Extensions.cs#L47-L83","documentation":"Texture.CreateDepthTextureCompatible throws NotSupportedException when Texture.ComputeShaderResourceFormatFromDepthFormat returns PixelFormat.None, i.e. the texture IS depth-stencil but its depth format has no shader-resource-compatible equivalent. The library cannot create a samplable copy of that depth format and fails explicitly.","triggerScenarios":"Calling CreateDepthTextureCompatible on a depth-stencil texture using a format with no shader-resource mapping (e.g. certain stencil-containing or feature-limited depth formats on some GPU/feature levels).","commonSituations":"Running on hardware/feature levels where D24S8 or similar lacks a typed shader-resource format; switching depth formats (e.g. to D32_S8) for precision and losing sampling support; targeting mobile or older GPUs with narrower format support.","solutions":["Use a depth format with a known shader-resource mapping (e.g. R32_Typeless/R32_Float depth) when creating the texture","Check the mapped format first: PixelFormat f = Texture.ComputeShaderResourceFormatFromDepthFormat(fmt); if (f == PixelFormat.None) use an alternate technique (e.g. write depth to a color target)","Add capability checks at startup and select the depth format accordingly","Fall back to MRT depth-encoding if sampling the depth buffer directly is unsupported"],"exampleFix":"// before\nvar depth = Texture.New2D(device, w, h, PixelFormat.R24_G8_Typeless, TextureFlags.DepthStencil);\nTexture copy = depth.CreateDepthTextureCompatible(); // throws if no SRV mapping\n// after\nvar depth = Texture.New2D(device, w, h, PixelFormat.R32_Typeless, TextureFlags.DepthStencil | TextureFlags.ShaderResource);\nTexture copy = depth.CreateDepthTextureCompatible();","handlingStrategy":"validation","validationCode":"var mapped = Texture.ComputeShaderResourceFormatFromDepthFormat(depthFormat);\nif (mapped == PixelFormat.None)\n    Log.Error($\"Depth format {depthFormat} has no shader-resource mapping; pick another format\");\nelse\n    var copy = depthTexture.CreateDepthTextureCompatible();","typeGuard":"static bool DepthFormatSamplable(PixelFormat f) => Texture.ComputeShaderResourceFormatFromDepthFormat(f) != PixelFormat.None;","tryCatchPattern":"try { copy = texture.CreateDepthTextureCompatible(); }\ncatch (NotSupportedException) { /* fall back to depth encoded into a color target */ }","preventionTips":["Choose depth formats with known shader-resource mappings (R32_Typeless, R16_Typeless)","Check GPU/feature-level format support at startup and select the depth format dynamically","Avoid exotic depth-stencil formats (e.g. D32_S8) unless sampling support is verified"],"tags":["csharp","texture","depth-stencil","pixel-format","unsupported-operation"],"backgroundTag":"unsupported-operation","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"}