stride3d/stride · error · ArgumentException
Expecting texture supporting UAV
Error message
Expecting texture supporting UAV
What it means
CommandList.ClearReadWrite(Texture, Vector4) clears a texture as a float4 via its Unordered Access View. The throw fires when the Texture has no UAV (NativeUnorderedAccessView.Ptr == 0), i.e. it was not created with GraphicsResourceUsage or texture flags that enable UnorderedAccess. D3D12 cannot clear through a nonexistent descriptor.
Solutions
- Recreate the Texture with TextureFlags.UnorderedAccess (e.g. Texture.New2D(..., TextureFlags.UnorderedAccess)).
- If the texture is both rendered to and compute-written, request Render | UnorderedAccess flags together.
- Skip/guard the clear when texture.NativeUnorderedAccessView.Ptr == 0.
Example fix
// before var tex = Texture.New2D(device, 512, 512, PixelFormat.R32G32B32A32_Float, TextureFlags.ShaderResource); commandList.ClearReadWrite(tex, Vector4.Zero); // throws // after var tex = Texture.New2D(device, 512, 512, PixelFormat.R32G32B32A32_Float, TextureFlags.ShaderResource | TextureFlags.UnorderedAccess); commandList.ClearReadWrite(tex, Vector4.Zero);
Defensive patterns
Strategy: validation
Validate before calling
if (texture == null) throw new ArgumentNullException(nameof(texture));
if (texture.NativeUnorderedAccessView.Ptr == 0)
throw new InvalidOperationException("Texture must be created with TextureFlags.UnorderedAccess before ClearReadWrite"); Type guard
bool SupportsTextureUav(Texture t) => t != null && t.NativeUnorderedAccessView.Ptr != 0;
Try / catch
try
{
commandList.ClearReadWrite(texture, value);
}
catch (ArgumentException ex) when (ex.ParamName == nameof(texture))
{
// recreate texture with TextureFlags.UnorderedAccess or fall back to Clear
} Prevention
- Pass TextureFlags.UnorderedAccess for any texture cleared or written by compute shaders.
- Check format supports UAV use (typed UAV load/clear formats) at creation time.
- Combine Render | UnorderedAccess flags for dual-use post-process textures.
When it happens
Trigger: Calling CommandList.ClearReadWrite(texture, Vector4 value) on a texture created without UnorderedAccess support — e.g. a plain render target or sampled texture without TextureFlags.UnorderedAccess.
Common situations: Post-processing passes clearing a compute-writable texture that was allocated as a render target only; textures created via Texture.New2D default flags; D3D11 code that relied on implicit UAV capability.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Expecting a Texture supporting UAV
- Expecting a Buffer supporting UAV
- Source Texture is not a MSAA Texture
- The Graphics Resource is a Texture, but its dimension is…
- Resource ' ' has missing Unordered Access View.
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/91eb7d9543b86e86.
Report an issue: GitHub.
Appendix: source
Thrown at sources/engine/Stride.Graphics/Direct3D12/CommandList.Direct3D12.cs:1300
currentCommandList.NativeCommandList.ClearUnorderedAccessViewUint(gpuHandle, cpuHandle, buffer.NativeResource,
ref clearValue, NumRects: 0, in nullRect);
RecordDebugCounter(DebugCounterKind.Clear);
}
/// <summary>
/// Clears a Read-Write Texture.
/// </summary>
/// <param name="texture">The Texture to clear. It must have been created with read-write / unordered access flags.</param>
/// <param name="value">The value to use to clear the Texture.</param>
/// <exception cref="ArgumentNullException"><paramref name="texture"/> is <see langword="null"/>.</exception>
/// <exception cref="ArgumentException"><paramref name="texture"/> must support Unordered Access.</exception>
public void ClearReadWrite(Texture texture, Vector4 value)
{
ArgumentNullException.ThrowIfNull(texture);
if (texture.NativeUnorderedAccessView.Ptr == 0)
throw new ArgumentException("Expecting texture supporting UAV", nameof(texture));
ResourceBarrierTransition(texture, BarrierLayout.UnorderedAccess);
FlushResourceBarriers();
var cpuHandle = texture.NativeUnorderedAccessView;
var gpuHandle = GetGpuDescriptorHandle(cpuHandle);
scoped ref SilkBox2I nullRect = ref NullRef<SilkBox2I>();
scoped ref var clearValue = ref value.AsSpan<Vector4, float>()[0];
currentCommandList.NativeCommandList.ClearUnorderedAccessViewFloat(gpuHandle, cpuHandle, texture.NativeResource,
ref clearValue, NumRects: 0, in nullRect);
RecordDebugCounter(DebugCounterKind.Clear);
}
/// <summary>
/// Clears a Read-Write Texture.
/// </summary>View on GitHub (pinned to 96fad776d2)