diff --git a/CMakeLists.txt b/CMakeLists.txt index 78655be663..af15d7854c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4489,9 +4489,12 @@ if(EXISTS "${INTAKE_PYTHON}") add_test(NAME startup_compute_live_retry_${adapter} COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_live_retry_check.py" "$" "${DXC_EXECUTABLE}" ${adapter}) + add_test(NAME startup_compute_dispatch_entry_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_entry_check.py" "$" + "${DXC_EXECUTABLE}" ${adapter}) set_tests_properties(startup_compute_dispatch_${adapter} startup_compute_dispatch_texture_${adapter} startup_compute_dispatch_heap_${adapter} startup_compute_dispatch_heap_word_${adapter} - startup_compute_live_retry_${adapter} + startup_compute_live_retry_${adapter} startup_compute_dispatch_entry_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) endforeach() add_test(NAME startup_stream_adapter_filter COMMAND "${INTAKE_PYTHON}" -B diff --git a/docs/experiments.md b/docs/experiments.md index 8babf8c48b..603804cacb 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -16640,7 +16640,7 @@ the field layouts rather than assembled. ## Translated compute Dispatch -With a device slot 67 placeholder bound, command-list slot 14 looks up the translation of the pipeline's published request (`.txt` with `stage cs`, and `.cs.cso`) and records it on the desktop list. It binds, from the compute descriptor tables of slot 35: raw buffers named by 16-byte hardware buffer descriptors, and 2D textures named by the token of a view the caller created (device slot 18 for an input, slot 19 for an output the program stores `float4` to). `smp` manifest lines become static samplers, and entry values come from the compute root constants of slots 37 and 39. A buffer input must resolve to a complete GPU-backed range; a buffer output must be a placed buffer that aliases the caller's memory and allows unordered access; a texture view must be 2D, created on the desktop, and for an output have a float or normalized format that is not packed, on a texture that is not also an input of the call. Any other manifest line (other texture kinds, sampler heaps, comparison samplers, root views, `stride` and `descword3` entry values) leaves the pipeline untranslated, and a Dispatch that cannot be bound completely is refused with one logged reason: no Dispatch is recorded and nothing is bound (the upload of an input texture the caller filled in memory may already be recorded; it only syncs content). No view is ever bound null. The entry values live in the compute root-constant store of #1975: a word no slot 37 or 39 call wrote since the compute root was set (slot 33 with another root, or a list reset) has no value and is refused with `an entry value was not set since the compute root`; setting the same root again keeps the words, and the graphics words of slot 40 are separate. +With a device slot 67 placeholder bound, command-list slot 14 looks up the translation of the pipeline's published request (`.txt` with `stage cs`, and `.cs.cso`) and records it on the desktop list. It binds, from the compute descriptor tables of slot 35: raw buffers named by 16-byte hardware buffer descriptors, and 2D textures named by the token of a view the caller created (device slot 18 for an input, slot 19 for an output the program stores `float4` to). `smp` manifest lines become static samplers, and entry values come from the compute root constants of slots 37 and 39. A buffer input must resolve to a complete GPU-backed range; a buffer output must be a placed buffer that aliases the caller's memory and allows unordered access; a texture view must be 2D, created on the desktop, and for an output have a float or normalized format that is not packed, on a texture that is not also an input of the call. Any other manifest line (other texture kinds, sampler heaps, comparison samplers, root views, entry values that are neither a root constant nor a buffer descriptor word) leaves the pipeline untranslated, and a Dispatch that cannot be bound completely is refused with one logged reason: no Dispatch is recorded and nothing is bound (the upload of an input texture the caller filled in memory may already be recorded; it only syncs content). No view is ever bound null. The entry values live in the compute root-constant store of #1975: a word no slot 37 or 39 call wrote since the compute root was set (slot 33 with another root, or a list reset) has no value and is refused with `an entry value was not set since the compute root`; setting the same root again keeps the words, and the graphics words of slot 40 are separate. `tests/startup_compute_dispatch_check.py` drives a source-built gfx1013 program through the stand-in's list on WARP and on a physical adapter (exit 77 without one) and reads the 320 output words back from the aliased memory. Controls in the same run: before the offline translation, without a Dispatch, and with the two descriptors exchanged, every output word must keep its sentinel. The two entry values arrive through slot 37 and slot 39, with other values written through slot 40 in between; `dispatch-same-root` must still give the expected words, and five refused modes must log their reason and keep the sentinels: a missing word, another compute root set and the first set again, a list reset, a compute root that is not the pipeline's, and one buffer named as input and output. `tests/startup_compute_dispatch_texture_check.py` does the same for a program that stores to a 32x8 RGBA16_FLOAT texture (1024 halves read back through CopyTextureRegion; controls: before translation, without a Dispatch, a texture without unordered access) and for the raw buffer program with a level-zero sample of a 1x1 texture XORed into each stored word (control: no view at the table entry). The texture output program is also bound under a manifest edited to declare no entry values. @@ -16660,6 +16660,18 @@ cmake --build --preset dev --target startup_stream_consumer ctest --preset dev --no-tests=error -R "^startup_compute_dispatch_" -V ``` +### Entry values from a buffer descriptor + +A formatted buffer load passes the input's stride and word 3 as entry values (`udsrc stride `, `udsrc descword3 `), and a formatted buffer store (`buffer_store_format_d16_x`, and `buffer_store_format_xyzw` of #2530) passes the output's word 3, the upper half of word 1 and the record count (`uav_descword3`, `uav_stride`, `uav_numrecords`). At Dispatch the stand-in takes each from the descriptor words the same call binds the view from: the stride as the draw path takes it (from the hardware descriptor, or from the title's buffer view for a token), word 3 through the draw path's formatted-buffer check (a token's word is built from its view; a FORMAT the program does not decode refuses the dispatch with `a formatted input has no word 3 the program decodes`), and the output words unmasked, since the store helper checks the swizzle bits itself. A descriptor that is not bound refuses the dispatch as before; an entry value naming a texture slot leaves the pipeline untranslated, and so does any other source. + +`tests/startup_compute_dispatch_entry_check.py` dispatches two source-built programs on WARP and on a physical adapter (exit 77 without one) and reads the 320 output words back: the formatted load of `startup_gfx2hlsl_compute_check.py` with two word-3 values on one translation, and the `buffer_store_format_d16_x` program of `startup_compute_store_d16_x_check.py` with four output descriptors (two formats, another stride and record count, and SWIZZLE_ENABLE set in word 1, for which the translated program stores nothing). A FORMAT the program does not decode is refused with every output word at its sentinel. Returning a constant output stride and record count in the runtime, or masking the stride to 14 bits as the draw path does, makes a store run fail. The record count cannot be checked apart from the bound range, which is sized from the same word. + +Measured on two synthetic programs. In a local set of 29 compute programs whose first refusal was this manifest line (about 1.4 million calls in one run), 27 now pass the manifest (about 1.39 million calls; 17 of them, about 0.6 million calls, use the store of #2530) and 2 stop at a 1D or 3D texture input. Every formatted store in the 27 passes a zero `soffset`: a nonzero one in structured mode can store past `stride * records` bytes, outside the bound range, and is not checked here. Which bind-time reason the 27 meet next has not been measured. + +```powershell +ctest --preset dev --no-tests=error -R "^startup_compute_dispatch_entry_" -V +``` + ### Static samplers with a LOD clamp The translator writes a constant sampler of `image_sample`, `_l` or `_lz` whose mip filter is not 0 as an `smpl` line (#2482): a static sampler whose MinLOD and MaxLOD come from the descriptor's word 1. The compute Dispatch now reads `smpl` lines as the draw path does, through the same `TranslatedSamplers::read_manifest_line` and `create_translated_root`; the only difference for compute is that the root signature is set with `SetComputeRootSignature`, and static samplers need nothing else. A comparison sampler (`smpc`) and the run-time sampler heap table (`smpheap`) are still refused, as "a comparison sampler" and "a sampler from the sampler heap". Binding the heap table for compute would need the draw path's sampler snapshot (`snapshot_samplers`, `create_sampler_snapshot_heap`) taken from the compute root's sampler heap pointer, the sampler heap set with `SetDescriptorHeaps` and its table set with `SetComputeRootDescriptorTable`. diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index af6daff194..367f3a926d 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -4,7 +4,9 @@ // inputs, `uav table ` outputs) named by hardware buffer descriptors, and 2D textures // (`srv tex2d table ` inputs, `uav tex2d float table channels 4` outputs) named // by the token of a view the title created (device slots 18 and 19). `smp` lines become static samplers. Entry -// values come from the compute root constants of slots 37 and 39. Any other manifest line makes the translation +// values come from the compute root constants of slots 37 and 39, or from the descriptor a buffer input or output is +// bound from: its stride and word 3 (`stride`, `descword3`), and word 3, the upper half of word 1 and the record +// count of an output (`uav_descword3`, `uav_stride`, `uav_numrecords`). Any other manifest line makes the translation // unavailable; a dispatch that cannot be bound completely is refused with one reason and records no Dispatch and // binds nothing (the upload of an input texture the title filled in memory may already be recorded: it only // syncs content). @@ -13,12 +15,14 @@ struct ComputeTranslation { // Root parameter and byte offset (views), or parameter and word (entry values). A heap view names the root // constant (parameter and word) that indexes its 32-byte record in the list's view heap, or, with word_param // set, the table buffer (word_param, word_byte) whose word at byte at + root constant (a, b) * times (a < 0: - // at alone) is the index. + // at alone) is the index. An entry value that is not a root constant names input or output a by its source. + enum Source { root_constant, input_stride, input_word3, output_word3, output_stride, output_records }; struct Slot { int a, b; bool texture, heap; int word_param = -1, word_byte = 0; std::uint32_t at = 0, times = 0; + Source source = root_constant; }; u64 key = 0; int state = 0; // 0 not loaded, 1 ready, 2 unavailable @@ -89,11 +93,22 @@ const char* load_compute_translation(ComputeTranslation& tr) } unsigned i = 0, x = 0, y = 0, z = 0, w = 0; int a = 0, b = 0, c = 0, d = 0, used = 0; + char name[16] = ""; const auto whole = [&] { return used == static_cast(line.size()); }; + // The manifest names of the Source values after root_constant, in their order. + const auto source = [&] { + static const char* const names[] = {"stride", "descword3", "uav_descword3", "uav_stride", "uav_numrecords"}; + for (int s = 0; s < 5; ++s) + if (!std::strcmp(name, names[s])) return static_cast(s + 1); + return ComputeTranslation::root_constant; + }; if (line.empty() || (std::sscanf(line.c_str(), "group %u %u %u%n", &x, &y, &z, &used) == 3 && whole())) continue; if (std::sscanf(line.c_str(), "ud %u%n", &declared_uds, &used) == 1 && whole()) continue; if (std::sscanf(line.c_str(), "udsrc %u rootconst %d %d%n", &i, &a, &b, &used) == 3 && whole() && i == tr.uds.size()) tr.uds.push_back({a, b}); + else if (std::sscanf(line.c_str(), "udsrc %u %15s %d%n", &i, name, &a, &used) == 3 && whole() && i == tr.uds.size() && + source() != ComputeTranslation::root_constant) + tr.uds.push_back({a, 0, false, false, -1, 0, 0, 0, source()}); else if (std::sscanf(line.c_str(), "srv %u buf table %d %d%n", &i, &a, &b, &used) == 3 && whole() && i == tr.srvs.size()) tr.srvs.push_back({a, b}); else if (std::sscanf(line.c_str(), "srv %u buf heap rootconst %d %d%n", &i, &a, &b, &used) == 3 && whole() && @@ -122,11 +137,17 @@ const char* load_compute_translation(ComputeTranslation& tr) tr.samplers.read_manifest_line(line.c_str()); else return line.rfind("srv", 0) == 0 ? "a resource that is not a raw table buffer or a 2D texture" : line.rfind("uav", 0) == 0 ? "an output that is not a raw table buffer or a 2D float texture" - : line.rfind("udsrc", 0) == 0 ? "an entry value that is not a root constant" + : line.rfind("udsrc", 0) == 0 ? "an entry value that is not a root constant or a buffer descriptor word" : line.rfind("smp", 0) == 0 ? "a sampler that is not a plain static one" : "an unknown manifest line"; } if (tr.uds.size() != declared_uds || tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 8) return "entry value, input or output count"; + for (const ComputeTranslation::Slot& ud : tr.uds) { + const auto& slots = ud.source >= ComputeTranslation::output_word3 ? tr.uavs : tr.srvs; + if (ud.source != ComputeTranslation::root_constant && + (ud.a < 0 || static_cast(ud.a) >= slots.size() || slots[ud.a].texture)) + return "an entry value names a descriptor that is not a buffer input or output"; + } x2w_startup::ComPtr code; if (!cache_path(path, L"", tr.key, L".cs.cso") || FAILED(D3DReadFileToBlob(path, &code))) return "no compiled program"; // Parameter 0 keeps one constant for a program without entry values: a constants parameter cannot be empty. @@ -160,6 +181,8 @@ bool dispatch_translated(Wrapper* self, UINT x, UINT y, UINT z) bool transition, texture, described; unsigned char desc[40]; // a texture view's description, as the title gave it with a desktop format Wrapper* wrapper; + std::uint32_t words[4]; // a buffer's descriptor words as it was bound from, and its stride + UINT stride; } views[40]{}; static_assert(sizeof(D3D12_SHADER_RESOURCE_VIEW_DESC) == 40 && sizeof(D3D12_UNORDERED_ACCESS_VIEW_DESC) == 40); const auto type = list->GetType(); @@ -187,7 +210,8 @@ bool dispatch_translated(Wrapper* self, UINT x, UINT y, UINT z) } // A word no slot 37 or 39 call wrote since the compute root was set has no value to pass (it is not 0). for (std::size_t i = 0; !reason && i < tr->uds.size(); ++i) - if (!pass.compute_constants.is_bound(tr->uds[i].a, tr->uds[i].b, 1)) reason = "an entry value was not set since the compute root"; + if (tr->uds[i].source == ComputeTranslation::root_constant && !pass.compute_constants.is_bound(tr->uds[i].a, tr->uds[i].b, 1)) + reason = "an entry value was not set since the compute root"; const std::size_t inputs = reason ? 0 : tr->srvs.size(), count = reason ? 0 : inputs + tr->uavs.size(); for (std::size_t i = 0; i < count && !reason; ++i) { const bool output = i >= inputs; @@ -290,6 +314,8 @@ bool dispatch_translated(Wrapper* self, UINT x, UINT y, UINT z) const IndirectBufferView view = indirect_table_buffer(self, words); if (!view.resource || view.offset % D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT) reason = "an input is not a complete GPU-backed buffer range"; views[i] = {view.resource, view.offset, view.bytes, !view.upload}; + views[i].stride = view.stride; + std::memcpy(views[i].words, words, sizeof(views[i].words)); continue; } // An output is written by the GPU: only a placed buffer that aliases the title's memory shows the result @@ -307,6 +333,29 @@ bool dispatch_translated(Wrapper* self, UINT x, UINT y, UINT z) for (std::size_t input = 0; input < inputs && !reason; ++input) if (views[input].resource == placed.alias) reason = "an output buffer is also an input"; views[i] = {placed.alias, offset, bytes, true}; + std::memcpy(views[i].words, words, sizeof(views[i].words)); + } + // An entry value from a descriptor comes from the words its view was bound from in the loop above. + std::uint32_t values[32] = {}; + for (std::size_t i = 0; !reason && i < tr->uds.size(); ++i) { + const ComputeTranslation::Slot& ud = tr->uds[i]; + const View& view = views[ud.source >= ComputeTranslation::output_word3 ? inputs + ud.a : ud.a]; + std::uint32_t format = 0, word[4]; + switch (ud.source) { + case ComputeTranslation::root_constant: values[i] = pass.compute_constants.word(ud.a, ud.b); break; + case ComputeTranslation::input_stride: values[i] = view.stride; break; + case ComputeTranslation::input_word3: + std::memcpy(word, view.words, sizeof(word)); + if (formatted_buffer_word3(word, format)) { + reason = "a formatted input has no word 3 the program decodes"; + std::memcpy(words, view.words, sizeof(view.words)); + } + values[i] = word[3]; + break; + case ComputeTranslation::output_word3: values[i] = view.words[3]; break; + case ComputeTranslation::output_stride: values[i] = view.words[1] >> 16; break; // unmasked: the program checks the swizzle bits + case ComputeTranslation::output_records: values[i] = view.words[2]; break; + } } // A texture the title filled in memory is brought up to date first. An upload recorded before a later one // fails only syncs content, as a draw sampling that texture would. @@ -363,8 +412,6 @@ bool dispatch_translated(Wrapper* self, UINT x, UINT y, UINT z) desc.Buffer.Flags = D3D12_BUFFER_UAV_FLAG_RAW; device_of(the_device)->CreateUnorderedAccessView(view.resource, nullptr, &desc, dest); } - std::uint32_t values[32] = {}; - for (std::size_t i = 0; i < tr->uds.size(); ++i) values[i] = pass.compute_constants.word(tr->uds[i].a, tr->uds[i].b); if (!pass.heap_set) { x2w_startup::bind_translated_heaps(list, draw_heap, nullptr); pass.heap_set = true; diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index 0ebeb4580c..5376570172 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -1943,6 +1943,29 @@ struct FormattedBufferDescriptor { std::uint32_t words[8] = {}; }; +// Word 3 of a buffer descriptor as a formatted load decodes it (words[3]): the title's hardware word, or for a typed +// buffer view the title created (words[0] its token) the word the driver builds from its format and component +// mapping. Returns the refusal, with an unsupported FORMAT in format. Draws and compute Dispatch share it. +const char* formatted_buffer_word3(std::uint32_t* words, std::uint32_t& format) +{ + if (words[0] == view_token_magic) { + ViewRecord record{}; + AcquireSRWLockShared(¬e_lock); + const bool known = words[1] < view_records().size(); + if (known) record = view_records()[words[1]]; + ReleaseSRWLockShared(¬e_lock); + if (!known || record.slot != 18 || record.desc_bytes < 40) return "missing hardware descriptor"; + D3D12_SHADER_RESOURCE_VIEW_DESC view; + std::memcpy(&view, record.desc, 40); + return x2w_startup::view_word3(view, words[3]); + } + if (const auto code = x2w_startup::formatted_buffer_code(words[3]); !x2w_startup::formatted_buffer_supported(code)) { + format = code; + return "unsupported FORMAT"; + } + return x2w_startup::descriptor_word3_refusal(words[3]); +} + bool formatted_buffers_ready(const Translation& tr, const Pass& pass, FormattedBufferDescriptor (&descriptors)[32]) { const auto refuse = [&](int slot, const char* reason, std::uint32_t detail = 0) { @@ -1965,25 +1988,8 @@ bool formatted_buffers_ready(const Translation& tr, const Pass& pass, FormattedB if (!entry || !x2w_local::readable(reinterpret_cast(entry), sizeof(descriptor.words))) return refuse(ud.a, "missing hardware descriptor"); std::memcpy(descriptor.words, reinterpret_cast(entry), sizeof(descriptor.words)); - if (descriptor.words[0] == view_token_magic) { - // A typed buffer view the title created: the driver builds word 3 from its format and component mapping. - ViewRecord record{}; - AcquireSRWLockShared(¬e_lock); - const bool known = descriptor.words[1] < view_records().size(); - if (known) record = view_records()[descriptor.words[1]]; - ReleaseSRWLockShared(¬e_lock); - if (!known || record.slot != 18 || record.desc_bytes < 40) - return refuse(ud.a, "missing hardware descriptor"); - D3D12_SHADER_RESOURCE_VIEW_DESC view; - std::memcpy(&view, record.desc, 40); - if (const char* reason = x2w_startup::view_word3(view, descriptor.words[3])) return refuse(ud.a, reason); - descriptor.entry = entry; - continue; - } - const auto format = x2w_startup::formatted_buffer_code(descriptor.words[3]); - if (!x2w_startup::formatted_buffer_supported(format)) - return refuse(ud.a, "unsupported FORMAT", format); - if (const char* reason = x2w_startup::descriptor_word3_refusal(descriptor.words[3])) return refuse(ud.a, reason); + std::uint32_t format = 0; + if (const char* reason = formatted_buffer_word3(descriptor.words, format)) return refuse(ud.a, reason, format); descriptor.entry = entry; } return true; diff --git a/tests/startup_compute_dispatch_entry_check.py b/tests/startup_compute_dispatch_entry_check.py new file mode 100644 index 0000000000..1098908b27 --- /dev/null +++ b/tests/startup_compute_dispatch_entry_check.py @@ -0,0 +1,130 @@ +"""Translated compute programs whose entry values are words of a bound buffer descriptor (list slot 14). + +usage: startup_compute_dispatch_entry_check.py + +The consumer records each program as startup_compute_dispatch_check.py does, with the input words and the stride, +record count and word 3 of both table descriptors set by this script (X2W_TEST_DISPATCH_IN and _FIELDS). Each +program writes the same lanes in every group, so the consumer's Dispatch(3, 2, 2) gives the result of one group. + +1. Case L-uint of startup_gfx2hlsl_compute_check.py reads its input with buffer_load_format_xyzw; the manifest + takes `stride 0` and `descword3 0` from the input's descriptor. Stride 6 and the word 3 of L-uint, then of + L-unorm on the same translation, must each give that case's 320 words. A FORMAT the program does not decode is + refused with one reason and keeps every output word at its sentinel. +2. Case F of startup_compute_store_d16_x_check.py stores with buffer_store_format_d16_x; the manifest takes + `uav_descword3 0`, `uav_stride 0` and `uav_numrecords 0` from the output's descriptor. Three descriptors give + three different expectations: 32_FLOAT with stride 8 and 12 records, 16_FLOAT with the same, and 32_FLOAT with + stride 12 and 7 records. A fourth sets SWIZZLE_ENABLE (word 1 bit 31): the dispatch is translated and the + program stores nothing, which holds only while the entry value keeps the upper bits of word 1. +Before translation each program is refused with "no translation". Exit 77 when the adapter is not available. +""" +import os +from pathlib import Path +import struct +import subprocess +import sys +import tempfile + +import startup_compute_store_d16_x_check as D +import startup_gfx2hlsl_compute_check as C +from startup_compute_dispatch_check import dispatch, lines +from startup_compute_request_check import DATA, prepare +from startup_compute_translate_check import state_a +from startup_stream_check import gfx2hlsl as G + +RAW = (4, C.WORDS, 0) # the consumer's default stride, record count and word 3 +UNDECODED = 'a formatted input has no word 3 the program decodes' + + +def store_f32(halves, stride, records): + out = bytearray(struct.pack('<%dI' % C.WORDS, *[C.SENTINEL] * C.WORDS)) + for lane in range(records): + struct.pack_into('> 12) & 127 in (1, 5, 14, 22, 23, 24, 27, 29, 56, 60, 64, 71, 74, 77) + # 20 records of 6 bytes cover the last lane's 4-byte read at byte 6 * 15 + 3. + run_program(root, 'formatted', consumer, dxc, adapter, (words_l, rsrc2_l, group_l), + 'udsrc 2 stride 0\nudsrc 3 descword3 0\nsrv 0 buf table 1 0\nuav 0 table 1 16\n', [ + ('dispatch-formatted-uint', formatted, ((6, 20, C.L_WORD3['L-uint']), RAW), C.expected('L-uint')), + ('dispatch-formatted-unorm', formatted, ((6, 20, C.L_WORD3['L-unorm']), RAW), C.expected('L-unorm')), + ('dispatch-formatted-undecoded', formatted, ((6, 20, undecoded), RAW), UNDECODED), + ]) + + _, words_f, rsrc2_f, group_f, _ = D.PROGRAMS['F'] + runs = [] + for variant, label in (('F-f32', 'f32'), ('F-f16', 'f16'), ('F-swizzle-en', 'f32-swizzle')): + _, source, constants, expected, _ = D.case_inputs(variant) + runs.append(('dispatch-store-' + label, source, (RAW, tuple(constants[3:5]) + (constants[2],)), expected)) + word3_f32, halves = D.F_VARIANTS['F-f32'][0], D.FP16_VALUES + runs.append(('dispatch-store-f32-stride12', D.poisoned_source(halves), (RAW, (12, 7, word3_f32)), store_f32(halves, 12, 7))) + assert runs[0][3] != runs[3][3] != runs[1][3] + run_program(root, 'store', consumer, dxc, adapter, (words_f, rsrc2_f, group_f), + 'udsrc 2 uav_descword3 0\nudsrc 3 uav_stride 0\nudsrc 4 uav_numrecords 0\n', runs) + print(f'startup_compute_dispatch_entry: PASS on {adapter} (6 descriptor-word dispatches match, ' + '1 refused; untouched before translation)') + + +if __name__ == '__main__': + if len(sys.argv) != 4 or sys.argv[3] not in ('warp', 'hardware'): + sys.exit(__doc__) + main(*sys.argv[1:]) diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index 1a7bf1aa0c..ae8b44e422 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -205,6 +205,9 @@ static void* make_committed(void* device, D3D12_HEAP_TYPE type, const D3D12_RESO // another compute root and the first one again after the constants, dispatch-same-root sets the same root again; // dispatch-reset closes and resets the list after the constants; dispatch-wrong-root records under the other // root; dispatch-same-buffer names the output buffer as the input too. +// For any mode, X2W_TEST_DISPATCH_IN names 1280 bytes that replace the input words, and X2W_TEST_DISPATCH_FIELDS +// names six words that replace, for the input and then the output descriptor, the stride (word 1 bits 16-31), the +// record count (word 2) and word 3, which are otherwise 4, 320 and 0. static int dispatch_slot67(void* device, const std::string& mode) { constexpr UINT words = 320; @@ -215,6 +218,16 @@ static int dispatch_slot67(void* device, const std::string& mode) buffers[0][i] = 0x8b02a7f1u + i * 0x413b1u; buffers[1][i] = 0xc5c5c5c5u; } + UINT fields[2][3] = {{4, words, 0}, {4, words, 0}}; + const auto from_file = [](const char* variable, void* data, std::streamsize bytes) { + char path[MAX_PATH]; + const DWORD n = GetEnvironmentVariableA(variable, path, MAX_PATH); + return !n || (n < MAX_PATH && std::ifstream(path, std::ios::binary).read(static_cast(data), bytes).gcount() == bytes); + }; + if (!from_file("X2W_TEST_DISPATCH_IN", buffers[0], words * sizeof(UINT)) || + !from_file("X2W_TEST_DISPATCH_FIELDS", fields, sizeof(fields))) return 2; + UINT input[words]; + std::memcpy(input, buffers[0], sizeof(input)); const auto word = [](const void* value) { return reinterpret_cast(value); }; void* placed[2]{}; UINT descriptors[2][4]{}; @@ -224,7 +237,7 @@ static int dispatch_slot67(void* device, const std::string& mode) if (FAILED(static_cast(invoke(device, 133, word(buffers[i]), word(&desc), D3D12_RESOURCE_STATE_COMMON, 0, word(&__uuidof(ID3D12Resource)), word(&placed[i]))))) return 71; const UINT64 address = reinterpret_cast(buffers[mode == "dispatch-same-buffer" ? 1 : i]); - const UINT view[4] = {static_cast(address), static_cast(address >> 32) | 4u << 16, words, 0}; + const UINT view[4] = {static_cast(address), static_cast(address >> 32) | fields[i][0] << 16, fields[i][1], fields[i][2]}; std::memcpy(descriptors[mode == "dispatch-swapped" ? 1 - i : i], view, sizeof(view)); } const struct { @@ -315,7 +328,7 @@ static int dispatch_slot67(void* device, const std::string& mode) Sleep(1); } for (UINT i = 0; i < words; ++i) - if (buffers[0][i] != 0x8b02a7f1u + i * 0x413b1u) return 79; // the input must stay as written + if (buffers[0][i] != input[i]) return 79; // the input must stay as written x2w_d3d12_compute_census(); char path[MAX_PATH]; const DWORD n = GetEnvironmentVariableA("X2W_TEST_DISPATCH_OUT", path, MAX_PATH);