{"record":{"id":"aee3a00bdb117ea0","repo":"stride3d/stride","slug":"expecting-a-texture-supporting-uav","errorCode":null,"errorMessage":"Expecting a Texture supporting UAV","messagePattern":"Expecting a Texture supporting UAV","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Graphics/Direct3D11/CommandList.Direct3D11.cs","lineNumber":1006,"sourceCode":"                throw new ArgumentException(\"Expecting a Buffer supporting UAV\", nameof(buffer));\n\n            nativeDeviceContext->ClearUnorderedAccessViewUint(buffer.NativeUnorderedAccessView, (uint*) &value);\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 unsafe void ClearReadWrite(Texture texture, Vector4 value)\n        {\n            ArgumentNullException.ThrowIfNull(texture);\n            RecordDebugCounter(DebugCounterKind.Clear);\n\n            if (texture.NativeUnorderedAccessView.IsNull())\n                throw new ArgumentException(\"Expecting a Texture supporting UAV\", nameof(texture));\n\n            nativeDeviceContext->ClearUnorderedAccessViewFloat(texture.NativeUnorderedAccessView, (float*) &value);\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 unsafe void ClearReadWrite(Texture texture, Int4 value)\n        {\n            ArgumentNullException.ThrowIfNull(texture);\n            RecordDebugCounter(DebugCounterKind.Clear);\n\n            if (texture.NativeUnorderedAccessView.IsNull())\n                throw new ArgumentException(\"Expecting a Texture supporting UAV\", nameof(texture));","sourceCodeStart":988,"sourceCodeEnd":1024,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Graphics/Direct3D11/CommandList.Direct3D11.cs#L988-L1024","documentation":"ClearReadWrite(Texture, Vector4) clears a texture through its D3D11 UAV view via ClearUnorderedAccessViewFloat. Textures created without the UnorderedAccess flag have a null NativeUnorderedAccessView, so the method throws an ArgumentException naming 'texture'.","triggerScenarios":"Calling commandList.ClearReadWrite(texture, new Vector4(...)) on a Texture whose TextureDescription flags lack GraphicsResourceFlags.UnorderedAccess.","commonSituations":"Render-target textures created with RenderTarget flag only and later cleared as UAVs; textures loaded from assets without UAV usage; switching an algorithm from render-target blit to compute UAV without recreating the texture.","solutions":["Recreate the texture with GraphicsResourceFlags.UnorderedAccess in its flags.","Ensure mip/array slices used for clearing are created as UAV-eligible (no unsupported formats).","Pre-check the texture's UAV handle/nullability at the call site and use Clear (render target) instead for RT-only textures."],"exampleFix":"// before\nvar tex = Texture.New2D(device, w, h, PixelFormat.R32G32B32A32_Float, GraphicsResourceFlags.ShaderResource);\ncommandList.ClearReadWrite(tex, Vector4.Zero);\n// after\nvar tex = Texture.New2D(device, w, h, PixelFormat.R32G32B32A32_Float, GraphicsResourceFlags.ShaderResource | GraphicsResourceFlags.UnorderedAccess);\ncommandList.ClearReadWrite(tex, Vector4.Zero);","handlingStrategy":"validation","validationCode":"if (texture.NativeUnorderedAccessView.IsNull())\n    throw new InvalidOperationException(\"Texture must be created with GraphicsResourceFlags.UnorderedAccess\");\ncommandList.ClearReadWrite(texture, value);","typeGuard":"static bool SupportsUavClear(Texture t) => t is not null && !t.NativeUnorderedAccessView.IsNull();","tryCatchPattern":"try { commandList.ClearReadWrite(texture, Vector4.Zero); }\ncatch (ArgumentException ex) when (ex.ParamName == \"texture\") { /* recreate texture with UAV flag or clear as render target */ }","preventionTips":["Set GraphicsResourceFlags.UnorderedAccess on textures targeted by compute or UAV clears.","Ensure the pixel format is UAV-compatible when enabling the flag.","Use ClearRenderTarget for render-target-only textures instead."],"tags":["direct3d11","graphics","uav","texture","clear"],"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"}