stride3d/stride · error · NotSupportedException
This Texture is not a valid Depth-Stencil Texture
Error message
This Texture is not a valid Depth-Stencil Texture
What it means
The Texture.ToDepthStencilReadOnlyTexture extension throws NotSupportedException when the source texture does not have the DepthStencil flag (texture.IsDepthStencil is false). A read-only depth-stencil view can only be created on a texture that was created as a depth-stencil resource. The library refuses rather than producing an invalid GPU view.
Solutions
- Create the source texture with TextureFlags.DepthStencil (e.g. depth buffer = Texture.New2D(..., TextureFlags.DepthStencil))
- Verify texture.IsDepthStencil before calling the extension and route color textures to a different path
- Pass the correct texture (the depth buffer of the render target, e.g. depthBuffer or RenderTarget.DepthStencilBuffer)
- Check texture creation code after resolution changes to ensure flags are preserved
Example fix
// before Texture readonlyDepth = colorTarget.ToDepthStencilReadOnlyTexture(); // throws // after var depth = Texture.New2D(device, width, height, PixelFormat.R32_Typeless, TextureFlags.DepthStencil | TextureFlags.ShaderResource); Texture readonlyDepth = depth.ToDepthStencilReadOnlyTexture();
Defensive patterns
Strategy: validation
Validate before calling
if (texture.IsDepthStencil)
var view = texture.ToDepthStencilReadOnlyTexture();
else
Log.Error("ToDepthStencilReadOnlyTexture requires a TextureFlags.DepthStencil texture"); Type guard
static bool IsDepthTexture(Texture t) => t?.IsDepthStencil == true;
Try / catch
try { view = texture.ToDepthStencilReadOnlyTexture(); }
catch (NotSupportedException) { Log.Error("Texture lacks DepthStencil flags"); } Prevention
- Create depth textures with TextureFlags.DepthStencil explicitly
- Bind RenderTarget.DepthStencilBuffer, never the color target, for depth passes
- Add debug asserts on IsDepthStencil at pass setup
When it happens
Trigger: Calling ToDepthStencilReadOnlyTexture() on a color/render-target texture, or on a plain shader-resource texture that was never created with TextureFlags.DepthStencil.
Common situations: Wiring a shadow-map or SSAO pass and accidentally passing the scene color target instead of the depth buffer; recreating the depth texture without DepthStencil flags after a resize; refactoring where the wrong Texture property is bound.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- This Depth-Stencil format is not supported
- Resizing transaction stack to a smaller size is not…
- Changing the panel from a user library type is currently…
- Grouping elements into a user library type isn't supported.
- NotSupportedException
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/67e20d6ea044511b.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Texture.Extensions.cs:45
/// <returns>A new <see cref="Texture"/> representing the Texture View bound to <paramref name="texture"/>.</returns>
public static Texture ToTextureView(this Texture texture, ViewType viewType, int arraySlice, int mipLevel)
{
var viewDescription = texture.ViewDescription;
viewDescription.Type = viewType;
viewDescription.ArraySlice = arraySlice;
viewDescription.MipLevel = mipLevel;
return texture.ToTextureView(viewDescription);
}
/// <summary>
/// Creates a Shader Resource View that is read-only on a Depth-Stencil Texture.
/// </summary>
/// <param name="texture">The Texture to create a read-only Depth-Stencil Texture View for.</param>
/// <returns>A new <see cref="Texture"/> representing the Texture View bound to <paramref name="texture"/>.</returns>
public static Texture ToDepthStencilReadOnlyTexture(this Texture texture)
{
if (!texture.IsDepthStencil)
throw new NotSupportedException("This Texture is not a valid Depth-Stencil Texture");
var viewDescription = texture.ViewDescription;
viewDescription.Flags = TextureFlags.DepthStencilReadOnly;
return texture.ToTextureView(viewDescription);
}
/// <summary>
/// Creates a Shader Resource View on a Depth-Stencil Texture.
/// </summary>
/// <param name="texture">The Texture to create a Depth-Stencil Texture View for.</param>
/// <returns>A new <see cref="Texture"/> representing the Texture View bound to <paramref name="texture"/>.</returns>
public static Texture CreateDepthTextureCompatible(this Texture texture)
{
if (!texture.IsDepthStencil)
throw new NotSupportedException("This Texture is not a valid Depth-Stencil Texture");
var description = texture.Description;
description.Format = Texture.ComputeShaderResourceFormatFromDepthFormat(description.Format); // TODO: review thisView on GitHub (pinned to 96fad776d2)