From 89b1a3a27ef10d124ec624f6b2de875489cfe3f6 Mon Sep 17 00:00:00 2001 From: saii <120340942+Not-Saii@users.noreply.github.com> Date: Sat, 28 Nov 2026 19:47:20 +0200 Subject: [PATCH 1/3] startup: name each refused slot-19 output view interval The slot-19 output token path refused six byte-interval conditions with one message. Each now has its own reason, checked in the same order; the set of accepted views is unchanged. A source-built fixture triggers each reason through a replaced view description and checks a bound raw view reads back. Refs #3224 Co-Authored-By: Claude Opus 5.5 --- .../compute-output-buffer-reasons.md | 26 +++++ src/startup_stubs/d3d12_compute_dispatch.inl | 11 ++- .../startup_compute_token_interval.cmake | 8 ++ tests/startup_compute_token_interval_check.py | 95 +++++++++++++++++++ tests/startup_stream_consumer.cpp | 8 ++ 5 files changed, 144 insertions(+), 4 deletions(-) create mode 100644 tests/cmake/startup_compute_token_interval.cmake create mode 100644 tests/startup_compute_token_interval_check.py diff --git a/docs/experiments/compute-output-buffer-reasons.md b/docs/experiments/compute-output-buffer-reasons.md index 0ccfcba270..f2cda35884 100644 --- a/docs/experiments/compute-output-buffer-reasons.md +++ b/docs/experiments/compute-output-buffer-reasons.md @@ -68,6 +68,32 @@ 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. +Each of the six conditions then comes from one replaced view description, and each dispatch refuses with its own +reason in the log and the census and leaves every word at its sentinel. Views 1, 5 and 6 are invalid for D3D12; +the stand-in forwards them as written. + +```powershell +ctest --preset dev --no-tests=error -R "^startup_compute_token_interval_(warp|hardware)$" -V +``` + ## 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 ce571a0f8f..164cbe9d0e 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 0000000000..9d3dcdff83 --- /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 0000000000..773dc75dfa --- /dev/null +++ b/tests/startup_compute_token_interval_check.py @@ -0,0 +1,95 @@ +"""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: + +- a raw view of zero elements; +- 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; +- a raw view of 4 elements at byte 1600, past the 1280-byte buffer; +- a raw view of 320 elements at byte 16, 16 bytes past the buffer's end. + +The first, fifth and sixth views are invalid for D3D12, which the stand-in forwards as written. 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(' Date: Sat, 28 Nov 2026 19:53:57 +0200 Subject: [PATCH 2/3] tests: create the slot-19 view at a WARP descriptor and keep reachable intervals Byte 32 of the four-descriptor heap is not a descriptor on WARP, so the consumer creates the view at byte 64 and copies its token to byte 32. An empty view, or one past or across the buffer's end, is rejected by D3D12 at creation (the debug layer removes the device), so the fixture covers the three interval reasons a valid view can reach. Co-Authored-By: Claude Opus 5.5 --- docs/experiments/compute-output-buffer-reasons.md | 8 +++++--- tests/startup_compute_token_interval_check.py | 13 ++++--------- tests/startup_stream_consumer.cpp | 5 ++++- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/docs/experiments/compute-output-buffer-reasons.md b/docs/experiments/compute-output-buffer-reasons.md index f2cda35884..811facc5e8 100644 --- a/docs/experiments/compute-output-buffer-reasons.md +++ b/docs/experiments/compute-output-buffer-reasons.md @@ -86,9 +86,11 @@ 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. -Each of the six conditions then comes from one replaced view description, and each dispatch refuses with its own -reason in the log and the census and leaves every word at its sentinel. Views 1, 5 and 6 are invalid for D3D12; -the stand-in forwards them as written. +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 diff --git a/tests/startup_compute_token_interval_check.py b/tests/startup_compute_token_interval_check.py index 773dc75dfa..a83cfae4b8 100644 --- a/tests/startup_compute_token_interval_check.py +++ b/tests/startup_compute_token_interval_check.py @@ -9,15 +9,13 @@ 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: -- a raw view of zero elements; - 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; -- a raw view of 4 elements at byte 1600, past the 1280-byte buffer; -- a raw view of 320 elements at byte 16, 16 bytes past the buffer's end. +- an R32_UINT view at byte 4, inside the buffer. -The first, fifth and sixth views are invalid for D3D12, which the stand-in forwards as written. Exit 77 when the -adapter is not available. +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 @@ -40,12 +38,9 @@ def view(first, elements, fmt=RAW): CONTROLS = ( - ('raw', view(4, 0), 'an output UAV interval is empty'), ('raw', view(8, 1, R16_UINT), 'an output UAV interval is not whole dwords'), ('large', view(0, (4 << 20) + 4), 'an output UAV interval is over 16 MiB'), ('raw', view(1, 300, R32_UINT), 'an output UAV interval is not 16-byte aligned in its buffer'), - ('raw', view(400, 4), 'an output UAV interval starts past its buffer'), - ('raw', view(4, C.WORDS), 'an output UAV interval crosses the end of its buffer'), ) diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index fd6a761992..b322a48db2 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -440,7 +440,10 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin word(&__uuidof(ID3D12Resource)), word(&output))))) return 71; } if (mode == "dispatch-uav-token-copied") copied_token_output = output; - invoke(device, 19, word(output), 0, word(&view), cpu + 32); + // Byte 32 is not a descriptor of the heap on every adapter (WARP): the view is created at byte 64 and its + // token copied to byte 32, as a title copies descriptors. + invoke(device, 19, word(output), 0, word(&view), cpu + 64); + std::memcpy(reinterpret_cast(cpu + 32), reinterpret_cast(cpu + 64), 16); if (mode == "dispatch-uav-token-wrong-slot") reinterpret_cast(cpu + 32)[2] = 18; } From 61bdb4340586e84cc54a0a0269574f267011d3a1 Mon Sep 17 00:00:00 2001 From: saii <120340942+Not-Saii@users.noreply.github.com> Date: Sat, 28 Nov 2026 19:55:25 +0200 Subject: [PATCH 3/3] docs: record the slot-19 interval fixture results Co-Authored-By: Claude Opus 5.5 --- docs/experiments/compute-output-buffer-reasons.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/experiments/compute-output-buffer-reasons.md b/docs/experiments/compute-output-buffer-reasons.md index 811facc5e8..2e77df7462 100644 --- a/docs/experiments/compute-output-buffer-reasons.md +++ b/docs/experiments/compute-output-buffer-reasons.md @@ -96,6 +96,14 @@ need a view that D3D12 rejects when it is created: with the debug layer on, the 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