stride3d/stride · error · NotSupportedException
Cannot create a Texture View with flags
Error message
Cannot create a Texture View with flags [{ViewFlags}] from the parent Texture with flags [{Flags}]. The parent Texture must include all the flags defined by the Texture View What it means
When initializing a Texture View (a view onto a parent texture), Stride checks that the parent texture's Flags include every flag the view requires (after masking out DepthStencilReadOnlyFlags). NotSupportedException is thrown when the view requests flags (e.g. RenderTarget, ShaderResource, DepthStencil) the parent texture was not created with.
Solutions
- Recreate the parent texture with TextureFlags covering all ViewFlags (parent.Flags | ViewFlags).
- Reduce the view's ViewFlags to a subset of the parent texture's flags.
- Check DepthStencilReadOnlyFlags handling if the view is depth-stencil related.
Example fix
// before var parent = Texture.New2D(device, w, h, fmt, TextureFlags.ShaderResource); var view = new Texture(parent.GraphicsDevice).InitializeFrom(parent, descWithViewFlags: TextureFlags.RenderTarget); // after var parent = Texture.New2D(device, w, h, fmt, TextureFlags.ShaderResource | TextureFlags.RenderTarget); var view = new Texture(parent.GraphicsDevice).InitializeFrom(parent, descWithViewFlags: TextureFlags.RenderTarget);
Defensive patterns
Strategy: validation
Validate before calling
var filterViewFlags = (TextureFlags)((int)viewFlags & ~(int)TextureFlags.DepthStencilReadOnly);
if ((parent.Flags & filterViewFlags) != filterViewFlags)
throw new InvalidOperationException($"Parent flags {parent.Flags} do not include view flags {viewFlags}"); Type guard
static bool CanCreateView(Texture parent, TextureFlags viewFlags) => (parent.Flags & viewFlags) == viewFlags;
Try / catch
try { view = new Texture(device).InitializeFrom(parent, desc); }
catch (NotSupportedException ex)
{
logger.LogError(ex, "View flags incompatible with parent flags {Flags}", parent.Flags);
throw;
} Prevention
- Create parent textures with the union of all flags any view will need.
- Derive view flags from the parent's flags instead of hard-coding them.
- Document required flags next to view-creation call sites.
When it happens
Trigger: Calling Texture.InitializeFrom with a TextureDescription whose ViewFlags exceed the parent texture's Flags — e.g. creating a render-target view over a ShaderResource-only texture, or a depth-stencil view over a color texture.
Common situations: Creating views for MRT or shadow-map sampling when the base texture lacks matching flags; refactors where the parent texture flags were narrowed; attempting cube-face views with mismatched flags.
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
- Custom strides is not supported with packed PixelFormats
- The camera [ ] is disabled and can't be attached
- The camera [ ] is already attached
- The camera [ ] isn't attached
- Invalid Z slice index
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/2b7f3990a029675a.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Texture.cs:520
ViewWidth = Math.Max(1, Width >> MipLevel);
ViewHeight = Math.Max(1, Height >> MipLevel);
ViewDepth = Math.Max(1, Depth >> MipLevel);
if (ViewFormat == PixelFormat.None)
{
textureViewDescription.Format = deviceDescription.Format;
}
if (ViewFlags == TextureFlags.None)
{
textureViewDescription.Flags = deviceDescription.Flags;
}
// Check that the Texture View flags are compatible with the parent Texture's flags
var filterViewFlags = (TextureFlags)((int)ViewFlags & (~DepthStencilReadOnlyFlags));
if ((Flags & filterViewFlags) != filterViewFlags)
{
throw new NotSupportedException(
$"Cannot create a Texture View with flags [{ViewFlags}] from the parent Texture with flags [{Flags}]. " +
$"The parent Texture must include all the flags defined by the Texture View");
}
if (IsMultiSampled)
{
var maxCount = GraphicsDevice.Features[Format].MultisampleCountMax;
if (maxCount < MultisampleCount)
throw new NotSupportedException(
$"Cannot create a Texture with format {Format} and multi-sample level {MultisampleCount}. " +
$"The maximum supported level is {maxCount}");
}
InitializeFromImpl(textureDatas);
return this;
}
View on GitHub (pinned to 96fad776d2)