diff --git a/docs/experiments/compute-typed-buffer-inputs.md b/docs/experiments/compute-typed-buffer-inputs.md new file mode 100644 index 000000000..aaf9d9f6b --- /dev/null +++ b/docs/experiments/compute-typed-buffer-inputs.md @@ -0,0 +1,56 @@ +# Published typed buffer inputs (`srv typed`) + +Part of #3224. The direct compiler reads `buffer_load_format_x` to `_xyzw` (MUBUF, element index only) as a +`Buffer` (`typed_buffer_srv`). `format_compute_runtime_manifest` now publishes it as +`srv typed table bytes `, where `n` is 4 bytes per component of the widest load +of that binding. + +The stand-in (`src/startup_stubs/d3d12_compute_dispatch.inl`) resolves the table entry with the existing input +range rules and binds a UINT buffer view of the title's 32-bit components: `R32_UINT` to `R32G32B32A32_UINT`. A +UINT view returns the same bits as the guest format unit only for 32-bit UINT, SINT and FLOAT components, so only +those are bound: + +- **Hardware descriptor:** FORMAT 20-22, 62-64, 72-74 or 75-77 (gfx10 `BUF_FMT_32*`), stride equal to the + element size, identity DST_SEL over the components read, unified FORMAT (RESOURCE_LEVEL 1), structured bounds + (OOB_SELECT 0), and no swizzle, index stride or ADD_TID. +- **Slot 18 view token:** a typed buffer view with 32-bit channels and the default component mapping, read through + the UINT format of the same width (`typed_dword_channels` / `typed_dword_uint_format` in + `src/startup_stubs/native_buffer_stride.h`). +- **All four words zero:** a null buffer that reads zeros, as for raw inputs. + +Each other shape is refused before a dispatch is recorded, with one of these reasons: + +- `a typed input FORMAT is not 32 bits per channel` +- `a typed input stride is not its element size` +- `a typed input DST_SEL is not the identity` +- `a typed input descriptor is swizzled or not bounds-checked by record` +- `a typed input has fewer channels than the program reads` +- `a typed input token is not a typed buffer view with 32-bit channels` +- `a typed input range does not start at a whole element` + +The range checks of raw inputs also apply. A typed input on an indirect Dispatch is refused, and the in-process +`X2W_NATIVE_SHADERS` route is unchanged. 8- and 16-bit formats, UNORM, SNORM and 16-bit FLOAT need a conversion +that a UINT view does not do. + +## Test + +`tests/startup_compute_typed_buffer_srv_check.py` publishes a source-built program for 1 to 4 components with +`compile_dxil --requests`. It then dispatches it through slot 14 with a 32-bit FLOAT descriptor of 50 elements. +The 384 lanes store what they read, so the lanes past element 49 must read zeros. The 4-component case also reads +through a slot 18 `R32G32B32A32_FLOAT` view token (consumer mode `dispatch-srv-token-typed`). Each invalid shape +above must be refused with the output untouched. Before publication the dispatch reports `no translation`. + +```powershell +ctest --preset dev --no-tests=error -R '^startup_compute_typed_buffer_srv_' -V +``` + +Measured at `d418f70e` plus this change, on Windows 11 build 26300 with the Windows SDK 10.0.26100 DXC, Debug, +with the D3D12 debug layer enabled: + +- **NVIDIA GeForce RTX 4090, driver 32.0.16.1088:** passed for 1, 2, 3 and 4 components, the token, and 4, 6, 6 + and 7 refusal controls. +- **WARP 10.0.26100.9818:** capability skip (77). WARP reports 4-lane waves and the direct module needs 32. +- **Negative control:** with the runtime's parse of the `typed` line disabled, the published manifest is not + bound and the hardware check reads the sentinel at word 0. + +Not measured: how many of the cohort's typed inputs have a 32-bit FORMAT. The census re-measure answers that. diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index 79dcc6b3c..ad604dda5 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -957,6 +957,11 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh b.kind == ComputeViewKind::byte_window_srv) { srv_lines << "srv " << b.shader_register << " buf table " << b.root_parameter << ' ' << b.byte_offset << '\n'; + } else if (b.kind == ComputeViewKind::typed_buffer_srv && b.array_count == 1 && b.required_bytes && + b.required_bytes <= 16 && b.required_bytes % 4 == 0) { + // buffer_load_format_*: read as Buffer; bytes is the widest load (4 per component). + srv_lines << "srv " << b.shader_register << " typed table " << b.root_parameter << ' ' << b.byte_offset + << " bytes " << b.required_bytes << '\n'; } else if (b.kind == ComputeViewKind::texture_srv && b.array_count == 1 && (b.image_dimension == 0 || b.image_dimension == 1 || b.image_dimension == 2 || b.image_dimension == 5)) { diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index ce571a0f8..e4de46003 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -2,7 +2,8 @@ // the key of its published request; gfx2hlsl.py --pending answers the request with .txt (`stage cs`) and // .cs.cso. Bound from the compute tables recorded by slot 35 and compute root SRVs recorded by slot 43: raw // buffers (`srv buf table ` and `srv buf root ` inputs, `uav table ` -// outputs, or `uav bufhalf table bytes ` for typed half stores) +// outputs, or `uav bufhalf table bytes ` for typed half stores; `srv typed table +// bytes ` inputs are read through a UINT view of 32-bit components) // named by hardware buffer descriptors or 64-bit root SRV addresses, and textures // (`srv tex1d|tex2d|tex2da|tex3d table ` inputs, `uav tex1d/tex2d/tex2da/tex3d float table channels ` outputs) named // by the token of a view the title created (device slots 18 and 19). `smp`, `smpl` and `smpc` lines become static samplers. Entry @@ -44,6 +45,7 @@ struct ComputeTranslation { unsigned channels = 4; D3D12_SRV_DIMENSION srv_dimension = D3D12_SRV_DIMENSION_UNKNOWN; unsigned half_buffer_bytes = 0; + unsigned typed_bytes = 0; // `srv typed`: the widest formatted load, 4 bytes per component }; u64 key = 0; int state = 0; // 0 not loaded, 1 ready, 2 unavailable @@ -101,6 +103,65 @@ bool half_buffer_descriptor_matches(const std::uint32_t* words, unsigned bytes) return (words[1] >> 16) == bytes && (words[3] & (0xfffff000u | selectors)) == (0x01000000u | (format << 12) | (0xfacu & selectors)); } +// Channels of a gfx10 unified buffer FORMAT with 32-bit components (UINT, SINT or FLOAT; tools/startup/gfx2hlsl.py +// names the codes): a UINT view of that width reads the bits buffer_load_format returns. 0 for any other FORMAT. +unsigned typed_dword_format_channels(std::uint32_t code) +{ + switch (code) { + case 20: case 21: case 22: return 1; + case 62: case 63: case 64: return 2; + case 72: case 73: case 74: return 3; + case 75: case 76: case 77: return 4; + default: return 0; + } +} + +// The view a translated buffer_load_format_* reads (`srv typed`, a Buffer): the title's descriptor +// resolved as a buffer range, retyped to the UINT format of its 32-bit components. Returns the refusal or null. +const char* typed_dword_input_view(Wrapper* self, const std::uint32_t* words, unsigned typed_bytes, + IndirectBufferView& range, D3D12_SHADER_RESOURCE_VIEW_DESC& view) +{ + UINT channels = 0; + 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); + D3D12_SHADER_RESOURCE_VIEW_DESC desc{}; + if (known && record.slot == 18 && record.desc_bytes >= ViewRecord::srv_desc_bytes) + std::memcpy(&desc, record.desc, ViewRecord::srv_desc_bytes); + if (desc.Format) desc.Format = desktop_format(desc.Format); + channels = x2w_startup::typed_dword_channels(desc); + if (!channels) return "a typed input token is not a typed buffer view with 32-bit channels"; + } else if (words[0] || words[1] || words[2] || words[3]) { + // An all-zero descriptor is a null buffer: indirect_table_buffer gives it zeros, read as the program's width. + channels = typed_dword_format_channels(x2w_startup::formatted_buffer_code(words[3])); + if (!channels) return "a typed input FORMAT is not 32 bits per channel"; + if (((words[1] >> 16) & 0x3fff) != channels * 4) return "a typed input stride is not its element size"; + for (unsigned c = 0; c < typed_bytes / 4; ++c) + if (((words[3] >> (3 * c)) & 7) != 4 + c) return "a typed input DST_SEL is not the identity"; + // Unified FORMAT (RESOURCE_LEVEL 1), structured bounds (OOB_SELECT 0), no swizzle, index stride or ADD_TID. + if ((words[1] >> 30) || (words[3] & 0xfff80000u) != 0x01000000u) + return "a typed input descriptor is swizzled or not bounds-checked by record"; + } else { + channels = 4; // the 16 zero bytes indirect_table_buffer gives a null buffer, one element + } + if (channels * 4 < typed_bytes) return "a typed input has fewer channels than the program reads"; + const char* reason = nullptr; + range = indirect_table_buffer(self, words, false, &reason, 16u << 20, 4, true); + if (reason) return reason; + const UINT element = channels * 4; + if (range.offset % element || range.bytes < element) return "a typed input range does not start at a whole element"; + view = {}; + view.Format = x2w_startup::typed_dword_uint_format(channels); + view.ViewDimension = D3D12_SRV_DIMENSION_BUFFER; + view.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING; + view.Buffer.FirstElement = range.offset / element; + view.Buffer.NumElements = static_cast(range.bytes / element); + return nullptr; +} + std::unordered_map& compute_translations() { static std::unordered_map m; return m; } LONG compute_dispatches_translated, compute_dispatches_refused, compute_dispatches_untranslated, compute_dispatches_unmodelled; LONG compute_inputs_gpu_copied, compute_inputs_snapshot, compute_inputs_snapshot_kib; // inputs by path: this list's GPU copy, a title snapshot @@ -202,6 +263,11 @@ const char* load_compute_translation(ComputeTranslation& tr) 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 typed table %d %d bytes %u%n", &i, &a, &b, &x, &used) == 4 && whole() && + i == tr.srvs.size() && x && x <= 16 && x % 4 == 0) { + tr.srvs.push_back({a, b}); + tr.srvs.back().typed_bytes = x; + } else if (std::sscanf(line.c_str(), "srv %u buf root %d%n", &i, &a, &used) == 2 && whole() && a >= 0 && i == tr.srvs.size()) { tr.srvs.push_back({a, 0}); @@ -605,7 +671,7 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& for (std::size_t i = 0; i < count && !reason; ++i) { const bool output = i >= inputs; const ComputeTranslation::Slot slot = output ? tr->uavs[i - inputs] : tr->srvs[i]; - if (dispatch.signature && (slot.heap || slot.texture || slot.root)) { + if (dispatch.signature && (slot.heap || slot.texture || slot.root || slot.typed_bytes)) { reason = "translated indirect Dispatch requires fixed-table raw buffers"; break; } @@ -772,6 +838,16 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& views[i].wrapper = wrapper; continue; } + if (!output && slot.typed_bytes) { + IndirectBufferView range{}; + D3D12_SHADER_RESOURCE_VIEW_DESC typed{}; + reason = typed_dword_input_view(self, words, slot.typed_bytes, range, typed); + views[i] = {range.resource, range.offset, range.bytes, !range.upload, false, true}; + views[i].desc.srv = typed; + views[i].stride = range.stride; + std::memcpy(views[i].words, words, sizeof(views[i].words)); + continue; + } if (!output) { // Each condition of a complete GPU-backed buffer range has its own reason. auto view = indirect_table_buffer(self, words, false, &reason, 16u << 20, D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT, true); @@ -992,6 +1068,11 @@ const char* record_translated_dispatch(Wrapper* self, const TranslatedDispatch& view.described ? &view.desc.srv : nullptr, dest); continue; } + if (i < inputs && view.described) { // a typed buffer input + if (view.transition) require_state(self, view.resource, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); + device_of(the_device)->CreateShaderResourceView(view.resource, &view.desc.srv, dest); + continue; + } if (i < inputs || i >= count) { if (view.transition) require_state(self, view.resource, D3D12_RESOURCE_STATE_NON_PIXEL_SHADER_RESOURCE); buffer_view(dest, view.resource, view.offset, static_cast(view.bytes)); diff --git a/tests/cmake/startup_compute_typed_buffer_srv.cmake b/tests/cmake/startup_compute_typed_buffer_srv.cmake new file mode 100644 index 000000000..aedb10f63 --- /dev/null +++ b/tests/cmake/startup_compute_typed_buffer_srv.cmake @@ -0,0 +1,18 @@ +# Typed buffer inputs (buffer_load_format_*) on the published compute route (#3224). +if(TARGET compile_dxil AND EXISTS "${INTAKE_PYTHON}" + AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + add_test(NAME startup_compute_typed_buffer_srv_controls COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_typed_buffer_srv_check.py" compile + "$" "${DXC_BIN_DIR}") + set_tests_properties(startup_compute_typed_buffer_srv_controls PROPERTIES TIMEOUT 60) +endif() +if(TARGET compile_dxil AND TARGET startup_stream_consumer AND TARGET offscreen_check AND EXISTS "${INTAKE_PYTHON}" + AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + foreach(adapter IN ITEMS warp hardware) + add_test(NAME startup_compute_typed_buffer_srv_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_typed_buffer_srv_check.py" + "$" "$" "$" + "${DXC_BIN_DIR}" ${adapter}) + set_tests_properties(startup_compute_typed_buffer_srv_${adapter} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77) + endforeach() +endif() diff --git a/tests/startup_compute_typed_buffer_srv_check.py b/tests/startup_compute_typed_buffer_srv_check.py new file mode 100644 index 000000000..13bbaa34c --- /dev/null +++ b/tests/startup_compute_typed_buffer_srv_check.py @@ -0,0 +1,160 @@ +"""Publish a synthetic slot 67 program with buffer_load_format_* and check its typed buffer input (#3224). + +The program reads input element `index` with buffer_load_format_ (IDXEN) from table byte 0 and stores the n +dwords raw at output byte 4 * n * index (table byte 32). compile_dxil publishes `srv 0 typed table 1 0 bytes 4n`; +the stand-in binds a UINT view of the title's 32-bit components. Fewer records than lanes checks the zeros past +the view's last element. + +usage: + startup_compute_typed_buffer_srv_check.py compile + startup_compute_typed_buffer_srv_check.py +""" + +from pathlib import Path +import struct +import subprocess +import sys +from tempfile import TemporaryDirectory + +from native_dpp_mirror_check import vop2 +from native_gather_lod_check import render +from native_scalar_lds_check import scalar, sop1 +from startup_compute_dispatch_check import dispatch, lines, prepare_case +from startup_compute_translate_check import state_a, write_request +from startup_gfx2hlsl_compute_check import SENTINEL, TGID_X, TGID_Y, TGID_Z, USER7, WORDS, root_blob + +STATE = state_a((32, 1, 1), USER7 | TGID_X | TGID_Y | TGID_Z) +FLOAT_FORMATS = {1: 22, 2: 64, 3: 74, 4: 77} # gfx10 BUF_FMT_32[_32[_32[_32]]]_FLOAT +STORES = {1: 0x1c, 2: 0x1d, 3: 0x1f, 4: 0x1e} # buffer_store_dword[x2|x3|x4] +RECORDS = 50 +INPUT = [(0x8b02a7f1 + i * 0x413b1) & 0xffffffff for i in range(WORDS)] # the consumer's input words +DXGI_R32G32B32A32_FLOAT, DXGI_R8G8B8A8_UNORM = 2, 28 + + +def program(channels): + offset = (vop2(0x0b, 9, 128 + 12, 8) if channels == 3 else # v9 = 12 * v8 + vop2(0x1a, 9, 128 + {1: 2, 2: 3, 4: 4}[channels], 8)) # v9 = v8 << log2(4n) + words = [ + sop1(3, 20, 6), sop1(3, 21, 128), + 0xf408080a, 0xfa000020, # output descriptor s[32:35], table byte 32 + 0xf408090a, 0xfa000000, # input descriptor s[36:39], table byte 0 + 0xbf8cc07f, # s_waitcnt lgkmcnt(0) + scalar(0x26, 8, 8, 131), # 3 * group.y + scalar(0x26, 9, 9, 134), # 6 * group.z + scalar(0, 11, 7, 8), scalar(0, 11, 11, 9), + scalar(0x1e, 11, 11, 133), # 32 * flat group index + vop2(0x25, 8, 11, 0), # v8 = element index + 0xe0002000 | (channels - 1) << 18, 0x80090108, # buffer_load_format_ v[1:n], v8, s[36:39] idxen + 0xbf8c3f70, # s_waitcnt vmcnt(0) + offset, + 0xe0001000 | STORES[channels] << 18, 0x80080109, # buffer_store_dword v[1:n], v9, s[32:35] offen + 0xbf810000, + ] + return struct.pack('<%dI' % len(words), *words) + + +def output_records(channels): + return WORDS // channels * channels # no store crosses the end of the output view + + +def expected(channels): + return [INPUT[k] if k < RECORDS * channels else 0 if k < output_records(channels) else SENTINEL + for k in range(WORDS)] + + +def check_words(got, want, label): + first = next(((i, a, b) for i, (a, b) in enumerate(zip(got, want)) if a != b), None) + if first is not None: + word, actual, expected_word = first + raise AssertionError(f'{label}: word {word} expected {expected_word:08x}, read {actual:08x}') + + +def publish(compile_dxil, sdk, cache, key, channels): + result = subprocess.run([compile_dxil, sdk, cache.parent / 'native', 'gfx1013-direct-cs@0', + '--requests', cache, cache], capture_output=True, text=True, timeout=60) + manifest = cache / f'{key}.txt' + assert result.returncode == 0 and manifest.is_file(), (result.stdout, result.stderr) + text = manifest.read_text().splitlines() + assert f'srv 0 typed table 1 0 bytes {4 * channels}' in text and 'uav 0 table 1 32' in text, text + + +def check_compiler(compile_dxil, sdk): + with TemporaryDirectory() as directory: + for channels in FLOAT_FORMATS: + cache = Path(directory) / str(channels) + cache.mkdir() + key = write_request(cache, program(channels), STATE, root=root_blob(table_range=True)) + publish(compile_dxil, sdk, cache, f'{key:016x}', channels) + print('compile_dxil publishes srv typed lines for 1 to 4 components') + + +def check(compile_dxil, consumer, sdk, work, adapter, channels): + cache, env = prepare_case(work, adapter) + env.pop('X2W_NATIVE_SHADERS', None) + env.pop('X2W_NATIVE_SHADERS_ONLY', None) + (work / 'program').write_bytes(program(channels)) + (work / 'state').write_bytes(STATE) + fields = work / 'fields.bin' + env['X2W_TEST_DISPATCH_FIELDS'] = str(fields) + word3 = 0x01000fac | FLOAT_FORMATS[channels] << 12 + untouched = [SENTINEL] * WORDS + + def run(stride=4 * channels, records=RECORDS, descriptor_word=word3, mode='dispatch-records32', *, probe=False): + fields.write_bytes(struct.pack('<6I', stride, records, descriptor_word, 4, output_records(channels), 0)) + return dispatch(work, consumer, env, mode, probe=probe) + + got, result = run(probe=True) + check_words(got, untouched, 'before translation') + assert lines(result, 'Dispatch(3, 2, 2) refused: no translation'), result.stderr[-3000:] + [request] = cache.glob('req_*.c67') + key = request.stem.removeprefix('req_') + publish(compile_dxil, sdk, cache, key, channels) + + def translated(label, **options): + got, result = run(**options) + check_words(got, expected(channels), label) + assert len(lines(result, 'Dispatch(3, 2, 2) translated')) == 1 and not lines(result, 'refused:'), result.stderr[-3000:] + assert not [line for line in lines(result, 'x2w-d3d12-debug ') if ' sev=0 ' in line or ' sev=1 ' in line] + return result + + result = translated(f'{channels} channels') + layers = lines(result, 'x2w-d3d12 debug layer: ') + layer = 'enabled' if layers and '0x00000000' in layers[0] else 'unavailable' + print(f'{channels} channels: {RECORDS} typed elements, then zeros, on {adapter} (debug layer {layer})') + + refusals = [ + ({'descriptor_word': 0x01038fac}, 'a typed input FORMAT is not 32 bits per channel'), # 8_8_8_8_UNORM + ({'stride': 4 * channels + 4}, 'a typed input stride is not its element size'), + ({'descriptor_word': word3 | 3 << 28}, 'a typed input descriptor is swizzled or not bounds-checked by record'), + ({'descriptor_word': word3 & ~0x01000000}, 'a typed input descriptor is swizzled or not bounds-checked by record'), + ] + if channels > 1: + refusals.append(({'descriptor_word': word3 & ~0xfff | 0xfa5}, 'a typed input DST_SEL is not the identity')) # X, Y swapped + narrow = 0x01000fac | FLOAT_FORMATS[channels - 1] << 12 + refusals.append(({'descriptor_word': narrow, 'stride': 4 * (channels - 1)}, + 'a typed input has fewer channels than the program reads')) + if channels == 4: + translated('view token', mode='dispatch-srv-token-typed', descriptor_word=DXGI_R32G32B32A32_FLOAT) + refusals.append(({'mode': 'dispatch-srv-token-typed', 'descriptor_word': DXGI_R8G8B8A8_UNORM}, + 'a typed input token is not a typed buffer view with 32-bit channels')) + print('4 channels: a slot 18 typed buffer view token reads the same elements') + for options, reason in refusals: + got, result = run(**options) + check_words(got, untouched, options) + assert len(lines(result, 'Dispatch(3, 2, 2) refused: ' + reason)) == 1, (options, result.stderr[-3000:]) + print(f'{channels} channels: {len(refusals)} invalid inputs refused and the output remained untouched') + + +def main(compile_dxil, consumer, renderer, sdk, adapter): + wave = render(renderer, adapter, '--shader-wave32') + assert wave.returncode == 0, wave.stdout + wave.stderr + with TemporaryDirectory() as directory: + for channels in FLOAT_FORMATS: + check(compile_dxil, consumer, sdk, Path(directory) / str(channels), adapter, channels) + + +if __name__ == '__main__': + if sys.argv[1] == 'compile': + check_compiler(*sys.argv[2:]) + else: + main(*sys.argv[1:]) diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index 092b6e91e..ff2202304 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -397,7 +397,8 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin std::memcpy(reinterpret_cast(cpu + 64), window, sizeof(window)); std::memcpy(reinterpret_cast(cpu + 32), descriptors[1], sizeof(descriptors[1])); } - if (mode == "dispatch-records32" || typed_output_offset || shared_uav) { // output at byte 32, none at byte 16 + if (mode == "dispatch-records32" || typed_output_offset || shared_uav || + mode == "dispatch-srv-token-typed") { // output at byte 32, none at byte 16 std::memset(reinterpret_cast(cpu + sizeof(descriptors[0])), 0, sizeof(descriptors[1])); std::memcpy(reinterpret_cast(cpu + 32), descriptors[1], sizeof(descriptors[1])); } @@ -436,6 +437,14 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin if (mode == "dispatch-uav-token-wrong-slot") reinterpret_cast(cpu + 32)[2] = 18; } + if (mode == "dispatch-srv-token-typed") { + // dispatch-srv-token-typed: the input descriptor is the token of a typed buffer view (device slot 18) of the + // input buffer; for this mode the input's word 3 field is the view's DXGI format, its records field the elements. + D3D12_SHADER_RESOURCE_VIEW_DESC view{static_cast(fields[0][2]), D3D12_SRV_DIMENSION_BUFFER, + D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING}; + view.Buffer.NumElements = fields[0][1]; + invoke(device, 18, word(placed[0]), word(&view), cpu); + } const bool heap_record = mode.rfind("dispatch-heap", 0) == 0 && !heap_waterfall; if (heap_record) for (const UINT at : {0u, 32u, 64u})