Repository navigation
d3d12: validate CreateUnorderedAccessView descriptors for buffers and textures - #5327
Taffyyy-ops wants to merge 2 commits into
Conversation
|
Independent NVIDIA check of 05e7ac18 on 3faac557. Windows 11 x64 build 26300, RTX 3080 Ti / 621.35, MSVC 19.44.35230, Windows SDK 10.0.26100.0, Vulkan SDK 1.4.363.0, LLVM MC 23.1.6, RelWithDebInfo.
Both CTests passed with zero skips or Vulkan validation errors. The scratch descriptor fixture ran the cases that this revision treated as valid, using the exact PR runtime code. That included the 2D-array slice-count case that Flyander flagged and the author corrected in a later revision. Review finding · Author fix AI-assisted. |
|
The positive Repro with the synthetic resource already created in this test (4 array slices):
The D3D12 contract describes |
kacper-serewis
left a comment
There was a problem hiding this comment.
AI-assisted independent readback at 05e7ac1. On the RTX 5070 Vulkan shim (driver 616.56) and native D3D12 WARP, ArraySize=UINT_MAX cleared exactly the two remaining layers from layer 2 of a four-layer R32_UINT texture. Both UINT_MAX and an explicit count of two matched all 672 expected texels, including neighboring layers and mips. WARP’s debug info queue was empty and Vulkan validation reported zero errors. This resolves observed behavior on these backends. A portable D3D12 guarantee remains unverified.
Kam471
left a comment
There was a problem hiding this comment.
Head 05e7ac18e.
Configured b5327 with vcvars64 + Ninja, -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_TESTING=ON -DLEONIDA_BUILD_WINDOWS_RUNTIME=ON -DVulkan_INCLUDE_DIR=C:/VulkanSDK/1.4.363.0/Include -DVulkan_LIBRARY=C:/VulkanSDK/1.4.363.0/Lib/vulkan-1.lib; built d3d12_uav_validation_test. RTX 5070 Ti, driver 621.24.
ctest -R '^d3d12_uav_validation$' -> 1/1 Passed (0.44 s)
LEONIDA_VK_DEVICE='RTX 5070 Ti' LEONIDA_VK_VALIDATION=1 d3d12_uav_validation_test.exe
-> PASS (buffer & texture UAV validation + GPU clear readback), exit 0, no VUID
ctest -R '^(d3d12_vulkan_device|d3d12_uav_clear|d3d12_short_uav_clear)$' -> 3/3 Passed
git diff --check -> clean
The added rules follow D3D12 and the existing SRV checks: raw requires R32_TYPELESS and the RAW flag, non-structured requires StructureByteStride == 0, NumElements > 0, overflow-safe FirstElement/NumElements and counter ranges, and the texture side rejects MSAA, TYPELESS, sRGB, depth, block-compressed, 96-bit and B8G8R8X8 formats plus out-of-range mip/plane/array views and default 3D/1D-array dimensions. Invalid UAVs are checked for a zeroed slot and no bindless slot consumed; the UINT_MAX 2D-array positive case is clamped by image_descriptor (line 4023).
Verdict: good.
|
Thanks for catching that, @Flyander! Good call — Fixed in
Verified on Windows 11 (MSVC 19.44, Ninja
|
|
Tested d4c5854 merged onto main 3faac55 on an RTX 5090 (driver 616.92), Windows 11, MSVC 19.44, Vulkan SDK 1.4.363, RelWithDebInfo:
AI-assisted (Claude Code). |
d4c5854 to
9543b2c
Compare
|
Rebased cleanly onto Verified on Windows 11 (MSVC 19.44, Ninja
|
|
Re-tested the rebased head
AI-assisted (Claude Code). |
|
Independent Windows GPU check of 9543b2c: PASS. Windows 11 x64, NVIDIA GeForce RTX 5080, MSVC 19.44, CTest: d3d12_uav_validation passed (1/1), including buffer Vulkan validation layers off. Synthetic inputs only. |
Claimed in the coordination issue as: #5256 (comment) (new D3D item:
CreateUnorderedAccessViewdescriptor validation)What and why
Completes descriptor-creation validation for
ID3D12Device::CreateUnorderedAccessView(alongside DSV #5163, RTV #5248, SRV #5275, and CBV #5242). All checks live directly inwrite_buffer_uav,CreateUnorderedAccessView, andwrite_image_descriptorwithout modifyingimage_descriptor, so this does not conflict with #5275.Buffer UAVs (
write_buffer_uav):D3D12_BUFFER_UAV_FLAGSbits (Flags & ~D3D12_BUFFER_UAV_FLAG_RAW).D3D12_BUFFER_UAV_FLAG_RAWwithDXGI_FORMAT_UNKNOWNor any format other thanDXGI_FORMAT_R32_TYPELESS.StructureByteStrideon raw and typed buffer UAVs (D3D12 requiresStructureByteStride == 0when not structured).NumElements == 0(matchingCreateShaderResourceView).view.NumElements > max_elements - view.FirstElement,c->desc().Width - view.CounterOffsetInBytes >= 4).Texture UAVs (
CreateUnorderedAccessView&write_image_descriptor):SampleDesc.Count > 1).TYPELESSeffective formats (bothdesc == nullptron aTYPELESStexture and explicitTYPELESSdesc->Format).R8G8B8A8_UNORM_SRGB,B8G8R8A8_UNORM_SRGB,B8G8R8X8_UNORM_SRGB,BC*_UNORM_SRGB), depth-stencil, block-compressed (bf.block != 1), and 96-bit (fmt.rgb96) texture UAV formats.ViewDimensionagainstr->desc().Dimensionand reject unsupported default dimensions (TEXTURE3D,TEXTURE1Darrays) cleanly.MipSlice < MipLevels,PlaneSlice == 0, and forTEXTURE2DARRAYrejectArraySize == 0,FirstArraySlice >= DepthOrArraySize, or anyArraySize > DepthOrArraySize - FirstArraySlice(includingUINT_MAX, since D3D12 only defines-1/UINT_MAXas an "all remaining slices" sentinel forD3D12_TEX3D_UAV::WSize, notD3D12_TEX2D_ARRAY_UAV::ArraySize) instead of silently clamping. Preserves explicitTEXTURE1Dviews on 1D texture arrays (slice 0,d3d12_texture1d_test).write_image_descriptorbefore callingimage_descriptorso storage views cannot be silently clamped, returnbool(failing without writing T# words ifstate_.bind_imagefails on a bindless device for storage views), and only callstate_.context->note_storage_image(r->id())when a storage descriptor was actually written.Tests (
runtime/test/d3d12_uav_validation_test.cpp, registered asd3d12_uav_validation):R8G8B8A8_TYPELESS->R8G8B8A8_UINT, andR9G9B9E5_SHAREDEXPtexture UAVs withbindless_hash_lookup != 0).TEXTURE2DARRAYwithArraySize == UINT_MAX) zeroes a0xA5-pre-filled descriptor slot and allocates no bindless 2D image slot.Testing
RelWithDebInfo), Vulkan deviceIntel(R) RaptorLake-S Mobile Graphics Controller(note:LEONIDA_VK_DEVICE=NVIDIAdid not enumerate the laptop's NVIDIA dGPU in this Vulkan session).cmake --build runtime/build(0 errors).ctest --test-dir runtime/build -R "^(d3d12_uav_validation|d3d12_descriptor|d3d12_uav_clear|d3d12_texture1d|d3d12_r9g9b9e5_uav)$" --output-on-failure: 5/5 passed (d3d12_texture1d,d3d12_uav_clear,d3d12_uav_validation,d3d12_r9g9b9e5_uav,d3d12_descriptor).python -I scripts/check_no_game_data.py: passed (exit code 0).LEONIDA_GAME_DIRandLEONIDA_MOVIEunset).