diff --git a/docs/experiments/compute-output-buffer-reasons.md b/docs/experiments/compute-output-buffer-reasons.md index 0ccfcba27..2e77df746 100644 --- a/docs/experiments/compute-output-buffer-reasons.md +++ b/docs/experiments/compute-output-buffer-reasons.md @@ -68,6 +68,42 @@ the 12 translated keys, and the first refused dispatch of each of the other 11, of a desktop resource. That run made 2,453,727 compute dispatches, so dispatch counts compare only within one run. Whether the 12 translated keys write the right values was not checked. +## Slot-19 output view intervals + +A slot-19 output token (#3094) names a buffer UAV. The byte interval of that view was refused with one message, +`an output UAV interval is unaligned, oversized or outside its buffer`. It is now split into the condition that +failed, checked in this order: + +1. `an output UAV interval is empty` +2. `an output UAV interval is not whole dwords` +3. `an output UAV interval is over 16 MiB` +4. `an output UAV interval is not 16-byte aligned in its buffer` +5. `an output UAV interval starts past its buffer` +6. `an output UAV interval crosses the end of its buffer` + +Only the reason changes. The once-per-key `x2w-draw compute UAV` line already logs the view's format, first +element, element count, stride, flags, backing width, byte offset and byte count. + +`tests/startup_compute_token_interval_check.py` publishes case A with 32-byte table records through +`gfx2hlsl.py --pending` and binds a raw slot-19 view at byte 16 of the placed output buffer. Words 4-315 match. +Conditions 2, 3 and 4 then each come from one replaced view description (an R16_UINT view of one element, a raw +view of 16 MiB + 16 bytes of a committed buffer 64 KiB over 16 MiB, an R32_UINT view at byte 4), and each dispatch +refuses with its own reason in the log and the census and leaves every word at its sentinel. Conditions 1, 5 and 6 +need a view that D3D12 rejects when it is created: with the debug layer on, the device is removed at +`CreateUnorderedAccessView`, so no fixture creates one. + +```powershell +ctest --preset dev --no-tests=error -R "^startup_compute_token_interval_(warp|hardware)$" -V +``` + +Both tests pass on WARP (10.0.26100.9818) and on an RTX 4090 (driver 32.0.16.1088), Windows 11 build 26300, +debug layer on. With only the split reverted, the bound view still matches and the three cases are still refused, +each with the old reason, so all three expectations fail. + +On WARP, byte 32 of the consumer's four-descriptor heap is not a descriptor: a view created there ends the +consumer with exit 2173. The `dispatch-uav-token-*` modes therefore create the view at byte 64 and copy its token to +byte 32, as a title copies descriptors. + ## Published half-width buffer stores A native slot 67 request with a `half_buffer_uav` now publishes diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index ce571a0f8..164cbe9d0 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -514,10 +514,13 @@ const char* compute_token_output(Wrapper* list, const std::uint32_t* words, Comp return "an output UAV has no supported byte interval"; output.offset = view.FirstElement * element; output.bytes = u64{view.NumElements} * element; - if (!output.bytes || output.bytes % 4 || output.bytes > (16u << 20) || - output.offset % D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT || output.offset > output.backing.Width || - output.bytes > output.backing.Width - output.offset) - return "an output UAV interval is unaligned, oversized or outside its buffer"; + // Each refused interval has its own reason. The width test comes first: the end test subtracts the offset. + if (!output.bytes) return "an output UAV interval is empty"; + if (output.bytes % 4) return "an output UAV interval is not whole dwords"; + if (output.bytes > (16u << 20)) return "an output UAV interval is over 16 MiB"; + if (output.offset % D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT) return "an output UAV interval is not 16-byte aligned in its buffer"; + if (output.offset > output.backing.Width) return "an output UAV interval starts past its buffer"; + if (output.bytes > output.backing.Width - output.offset) return "an output UAV interval crosses the end of its buffer"; const auto base = reinterpret_cast(owner->own().title_memory); if (base) { if (output.offset > UINT64_MAX - base) return "an output UAV placement address overflows"; diff --git a/tests/cmake/startup_compute_token_interval.cmake b/tests/cmake/startup_compute_token_interval.cmake new file mode 100644 index 000000000..9d3dcdff8 --- /dev/null +++ b/tests/cmake/startup_compute_token_interval.cmake @@ -0,0 +1,8 @@ +if(EXISTS "${INTAKE_PYTHON}" AND TARGET startup_stream_consumer) + foreach(adapter IN ITEMS warp hardware) + add_test(NAME startup_compute_token_interval_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_token_interval_check.py" "$" + "${DXC_EXECUTABLE}" ${adapter}) + set_tests_properties(startup_compute_token_interval_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) + endforeach() +endif() diff --git a/tests/startup_compute_token_interval_check.py b/tests/startup_compute_token_interval_check.py new file mode 100644 index 000000000..a83cfae4b --- /dev/null +++ b/tests/startup_compute_token_interval_check.py @@ -0,0 +1,90 @@ +"""Named reasons for a slot-19 output view whose byte interval the translated dispatch refuses. + +usage: startup_compute_token_interval_check.py + +The program is case A of startup_gfx2hlsl_compute_check.py with its two buffer descriptors loaded from 32-byte table +records, as in startup_compute_dispatch_native_check.py. The consumer's dispatch-uav-token-raw mode writes, at table +byte 32, the token of a raw slot-19 view of the 1280-byte placed output buffer: first element 4, 312 elements. After +gfx2hlsl.py --pending with DXC that view is bound and words 4-315 match the case's expectation. Then the view is +replaced through X2W_TEST_DISPATCH_UAV, one condition at a time, and each dispatch is refused with its own reason in +the log and the census and writes no output word: + +- an R16_UINT view of one element (2 bytes) at byte 16; +- a raw view of 4 Mi + 4 elements (16 MiB + 16 bytes) of a committed buffer 64 KiB over 16 MiB; +- an R32_UINT view at byte 4, inside the buffer. + +The other three reasons (an empty interval, one that starts past the buffer and one that crosses its end) need a +view that D3D12 itself rejects when it is created; with the debug layer on, that removes the device. Exit 77 when +the adapter is not available. +""" +from pathlib import Path +import os +import struct +import subprocess +import sys +import tempfile + +import startup_gfx2hlsl_compute_check as C +from startup_compute_dispatch_check import dispatch, lines, prepare_case +from startup_compute_dispatch_native_check import LOAD_X8, LOADS_X4 +from startup_stream_check import gfx2hlsl as G + +RAW, R16_UINT, R32_UINT = 39, 57, 42 # DXGI_FORMAT values + + +def view(first, elements, fmt=RAW): + """D3D12_UNORDERED_ACCESS_VIEW_DESC of a buffer: format, dimension, first, count, stride, counter, flags.""" + return struct.pack('(cpu + 32), reinterpret_cast(cpu + 64), 16); if (mode == "dispatch-uav-token-wrong-slot") reinterpret_cast(cpu + 32)[2] = 18; }