{"record":{"id":"91eb7d9543b86e86","repo":"stride3d/stride","slug":"expecting-texture-supporting-uav","errorCode":null,"errorMessage":"Expecting texture supporting UAV","messagePattern":"Expecting texture supporting UAV","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Direct3D12/CommandList.Direct3D12.cs","lineNumber":1300,"sourceCode":"\n            currentCommandList.NativeCommandList.ClearUnorderedAccessViewUint(gpuHandle, cpuHandle, buffer.NativeResource,\n                                                                              ref clearValue, NumRects: 0, in nullRect);\n            RecordDebugCounter(DebugCounterKind.Clear);\n        }\n\n        /// <summary>\n        ///   Clears a Read-Write Texture.\n        /// </summary>\n        /// <param name=\"texture\">The Texture to clear. It must have been created with read-write / unordered access flags.</param>\n        /// <param name=\"value\">The value to use to clear the Texture.</param>\n        /// <exception cref=\"ArgumentNullException\"><paramref name=\"texture\"/> is <see langword=\"null\"/>.</exception>\n        /// <exception cref=\"ArgumentException\"><paramref name=\"texture\"/> must support Unordered Access.</exception>\n        public void ClearReadWrite(Texture texture, Vector4 value)\n        {\n            ArgumentNullException.ThrowIfNull(texture);\n\n            if (texture.NativeUnorderedAccessView.Ptr == 0)\n                throw new ArgumentException(\"Expecting texture supporting UAV\", nameof(texture));\n\n            ResourceBarrierTransition(texture, BarrierLayout.UnorderedAccess);\n            FlushResourceBarriers();\n\n            var cpuHandle = texture.NativeUnorderedAccessView;\n            var gpuHandle = GetGpuDescriptorHandle(cpuHandle);\n\n            scoped ref SilkBox2I nullRect = ref NullRef<SilkBox2I>();\n            scoped ref var clearValue = ref value.AsSpan<Vector4, float>()[0];\n\n            currentCommandList.NativeCommandList.ClearUnorderedAccessViewFloat(gpuHandle, cpuHandle, texture.NativeResource,\n                                                                               ref clearValue, NumRects: 0, in nullRect);\n            RecordDebugCounter(DebugCounterKind.Clear);\n        }\n\n        /// <summary>\n        ///   Clears a Read-Write Texture.\n        /// </summary>","sourceCodeStart":1282,"sourceCodeEnd":1318,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Direct3D12/CommandList.Direct3D12.cs#L1282-L1318","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nvar tex = Texture.New2D(device, 512, 512, PixelFormat.R32G32B32A32_Float, TextureFlags.ShaderResource);\ncommandList.ClearReadWrite(tex, Vector4.Zero); // throws\n\n// after\nvar tex = Texture.New2D(device, 512, 512, PixelFormat.R32G32B32A32_Float, TextureFlags.ShaderResource | TextureFlags.UnorderedAccess);\ncommandList.ClearReadWrite(tex, Vector4.Zero);","handlingStrategy":"validation","validationCode":"if (texture == null) throw new ArgumentNullException(nameof(texture));\nif (texture.NativeUnorderedAccessView.Ptr == 0)\n    throw new InvalidOperationException(\"Texture must be created with TextureFlags.UnorderedAccess before ClearReadWrite\");","typeGuard":"bool SupportsTextureUav(Texture t) => t != null && t.NativeUnorderedAccessView.Ptr != 0;","tryCatchPattern":"try\n{\n    commandList.ClearReadWrite(texture, value);\n}\ncatch (ArgumentException ex) when (ex.ParamName == nameof(texture))\n{\n    // recreate texture with TextureFlags.UnorderedAccess or fall back to Clear\n}","preventionTips":["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."],"tags":["direct3d12","graphics","uav","texture"],"backgroundTag":"invalid-argument-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"}