diff --git a/CMakeLists.txt b/CMakeLists.txt index a43c3ae223..9e3f5609a8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4967,9 +4967,13 @@ if(EXISTS "${INTAKE_PYTHON}") add_test(NAME startup_compute_dispatch_${adapter} COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_check.py" "$" "${DXC_EXECUTABLE}" ${adapter}) + unset(texture_native_args) + if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + set(texture_native_args "$" "${DXC_BIN_DIR}") + endif() add_test(NAME startup_compute_dispatch_texture_${adapter} COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_texture_check.py" "$" - "${DXC_EXECUTABLE}" ${adapter}) + "${DXC_EXECUTABLE}" ${adapter} ${texture_native_args}) add_test(NAME startup_slot67_indirect_dispatch_${adapter} COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_slot67_indirect_dispatch_check.py" "$" "${DXC_EXECUTABLE}" ${adapter}) diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 95d5ffc90d..208ab499e6 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -1008,12 +1008,14 @@ against their key, translated and compiled to DXIL in the process. The compiler' `\native`. Nothing is published as `.txt`. The existing dispatch path records the result, and a program is accepted only with the bindings a -fixture has run through it: root constants, raw table buffers loaded per lane (`buffer_load_dword`) -and raw table buffers stored to, with their descriptors in 32-byte table records. A 2D texture can be +fixture has run through it: root constants, scalar buffer SRVs (`buffer_srv`), raw table buffers loaded +per lane (`buffer_load_dword`) and raw table buffers stored to, with their descriptors in 32-byte table +records. Four-channel float 1D, 2D, 2D-array and 3D texture UAVs (`texture_uav` and `half4_texture_uav`) +are bound as outputs. A 2D texture can be sampled through samplers whose four words are constants: they become static samplers with the descriptor's MIN_LOD and MAX_LOD, or comparison samplers ([fixture and results](experiments/startup-compute-native-samplers.md)). Anything else (a -scalar buffer load, a sampler read from memory, a typed or indexed view, an instruction the compiler does +sampler read from memory, a typed or indexed view, an instruction the compiler does not lower) is refused. Programs published as `.txt` also bind 1D, 2D, 2D-array and 3D texture SRVs (`srv N tex1d|tex2d|tex2da|tex3d table R B`) from the title's described view of that dimension, or are refused by name; cube texture SRVs are not published. The first 16 refusals of a process are logged as @@ -1033,6 +1035,15 @@ pick up a rebuilt output (by the code path; no test covers the reload). Compute Check with `ctest --preset dev -R '^startup_compute_dispatch_native_(warp|hardware)$' -V` ([`tests/startup_compute_dispatch_native_check.py`](../tests/startup_compute_dispatch_native_check.py); [route, controls and results](experiments/startup-compute-native-dispatch.md)). +The #2958/#2993 fixture reads back a 3D float store fed by a scalar buffer SRV and a 2D texture SRV. +The consumer creates the views with the adapter's descriptor increment and copies their tokens +into a packed guest table when the increment exceeds 32 bytes. A zero-size W range must translate +natively, be refused at Dispatch, and leave all 6,144 volume words untouched. +Targeted in-process readbacks also check a mip-one 1D float store, a 2D-array float store into +relative slice 1 (physical slice 2), and a packed D16 store into an RGBA16_FLOAT texture with +round-to-nearest-even input conversion. Each case checks every output value, including sentinels +outside the store region. On adapters without 32-lane waves the cases check the named refusal +and untouched output before the test returns 77. ### Compute pipeline requests @@ -4083,3 +4094,22 @@ before any desktop copy, leaving a sentinel-filled readback buffer unchanged. On list refuses boxes with an unaligned right or bottom edge, copies the aligned 4x4 block, and reads back all eight block bytes with the next byte unchanged. Reproduce the portable and wrapped-list checks with `ctest --preset dev --no-tests=error -R '^startup_list_copy_texture' -V`. + +### Offline compute manifests for 3D and 1D UAVs + +The runtime half of #2902 is ported to `cpp-migration`. For offline compute +requests, the C++ formatter emits `uav N tex3d float table P OFF channels 4` and +`uav N tex1d float table P OFF channels 4`. The stand-in validates UAV view +dimensions and mip levels, including the W-slice range within the selected 3D mip. + +On an NVIDIA GeForce RTX 5080 (Windows 11, DXC from the Windows SDK 10.0.26100), the 3D, 3D NSA and 1D +store cases matched their mip-one words after `compile_dxil` published the translations. The mismatched-view, +3D W-range and 1D mip controls were refused with their sentinels intact. + +If a published compute PSO fails to create, the refusal stays `pipeline creation failed`, and the stand-in adds +the adapter's 32-lane wave capability as observed: `(adapter has no 32-lane waves)`, or `(adapter wave capability +query failed)`. The manifest records no wave size, so this does not say the shader needed one. The test knows its +native modules declare `WaveSize(32)`, so the native 3D, 3D NSA and 1D cases skip on WARP only for +`pipeline creation failed (adapter has no 32-lane waves)`. Any other PSO failure fails the test. +On WARP and hardware, the `gfx2hlsl.py` translations of the same programs require successful 3D, 3D NSA and 1D +mip-one readback and check the same mismatched-view, 3D W-range and 1D mip refusals with sentinels intact. diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index b9a06c8246..3ec2177cff 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -996,9 +996,16 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh uav_lines << "uav " << b.shader_register << ' ' << dimension << " float table " << b.root_parameter << ' ' << b.byte_offset << " channels " << channels << '\n'; } else if ((b.kind == ComputeViewKind::texture_uav || b.kind == ComputeViewKind::half4_texture_uav) && - (b.image_dimension == 1 || b.image_dimension == 5 || - (b.kind == ComputeViewKind::texture_uav && b.image_dimension == 2)) && b.array_count == 1) { - uav_lines << "uav " << b.shader_register << (b.image_dimension == 5 ? " tex2da" : b.image_dimension == 2 ? " tex3d" : " tex2d") + b.array_count == 1) { + const char *tex; + switch (b.image_dimension) { + case 0: tex = "tex1d"; break; + case 1: tex = "tex2d"; break; + case 2: tex = "tex3d"; break; + case 5: tex = "tex2da"; break; + default: return refuse(view_shape("UAV", b)); + } + uav_lines << "uav " << b.shader_register << ' ' << tex << " float table " << b.root_parameter << ' ' << b.byte_offset << " channels 4\n"; } else { return refuse(view_shape("UAV", b)); diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index ddf33ff7fd..55ec6de8e9 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -106,6 +106,15 @@ std::unordered_map& compute_translations() { static std 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 +// Whether the adapter runs 32-lane waves: 1 yes, 0 no, -1 the capability query failed. +int adapter_32_lane_waves() +{ + D3D12_FEATURE_DATA_D3D12_OPTIONS1 waves{}; + if (FAILED(device_of(the_device)->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &waves, sizeof(waves)))) + return -1; + return waves.WaveOps && waves.WaveLaneCountMin <= 32 && waves.WaveLaneCountMax >= 32; +} + // The root signature and pipeline of a translation whose entry values and views are filled in. Returns why it is // unavailable, or null when it is ready. const char* create_compute_pipeline(ComputeTranslation& tr, const void* code, std::size_t bytes) @@ -276,7 +285,16 @@ const char* load_compute_translation(ComputeTranslation& tr) } x2w_startup::ComPtr code; if (!cache_path(path, L"", tr.key, L".cs.cso") || FAILED(D3DReadFileToBlob(path, &code))) return "no compiled program"; - if (const char* failure = create_compute_pipeline(tr, code->GetBufferPointer(), code->GetBufferSize())) return failure; + if (const char* failure = create_compute_pipeline(tr, code->GetBufferPointer(), code->GetBufferSize())) { + // The manifest carries no wave size, so the failure stays the reason and the adapter's 32-lane wave + // capability is only reported next to it, as observed. It does not say the shader needed that wave size. + if (!std::strcmp(failure, "pipeline creation failed")) { + const int waves = adapter_32_lane_waves(); + if (waves < 0) return "pipeline creation failed (adapter wave capability query failed)"; + if (!waves) return "pipeline creation failed (adapter has no 32-lane waves)"; + } + return failure; + } log("x2w-draw compute pipeline %016llx translated: %zu entry values, %zu inputs, %zu outputs", tr.key, tr.uds.size(), tr.srvs.size(), tr.uavs.size()); return nullptr; @@ -285,8 +303,9 @@ const char* load_compute_translation(ComputeTranslation& tr) // X2W_NATIVE_SHADERS=: the first Dispatch of a slot 67 request translates // it in this process with the C++ compiler (src/gfx1013_compute_native.cpp), before a published .txt is read // and with no offline translator running. The dispatch path below binds the result, so a program is accepted only -// with root constants, raw table buffers and exact-width typed texture outputs. The constant sampler words the -// compiler resolved become static samplers. +// with root constants, raw table buffers, 2D texture inputs, four-channel float 1D, 2D, 2D-array and 3D texture +// outputs and exact-width typed texture outputs. The constant sampler words the compiler resolved become static +// samplers. // A refusal is logged and leaves the key to the published translations. draw_lock held. Returns whether tr is ready. bool translate_compute_natively(ComputeTranslation& tr) { @@ -349,15 +368,25 @@ bool translate_compute_natively(ComputeTranslation& tr) const bool texture_input = (view.kind == x2w::ComputeViewKind::texture_srv || view.kind == x2w::ComputeViewKind::comparison_texture_srv) && view.image_dimension == 1; - const bool volume = view.kind == x2w::ComputeViewKind::texture_uav && view.image_dimension == 2; - const bool output = view.kind == x2w::ComputeViewKind::raw_buffer_uav || half_typed || volume || channels; + // Four-channel float texture outputs, as format_compute_runtime_manifest writes them. + auto float4_dimension = D3D12_UAV_DIMENSION_UNKNOWN; + if (view.kind == x2w::ComputeViewKind::texture_uav || view.kind == x2w::ComputeViewKind::half4_texture_uav) { + switch (view.image_dimension) { + case 0: float4_dimension = D3D12_UAV_DIMENSION_TEXTURE1D; break; + case 1: float4_dimension = D3D12_UAV_DIMENSION_TEXTURE2D; break; + case 2: float4_dimension = D3D12_UAV_DIMENSION_TEXTURE3D; break; + case 5: float4_dimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; break; + } + } + const bool float4_output = float4_dimension != D3D12_UAV_DIMENSION_UNKNOWN; + const bool output = view.kind == x2w::ComputeViewKind::raw_buffer_uav || half_typed || float4_output || channels; auto& slots = output ? tr.uavs : tr.srvs; if ((!output && !texture_input && view.kind != x2w::ComputeViewKind::raw_vector_srv && !x2w::accepts_cbv_window(view.kind)) || view.array_count != 1 || view.root_parameter >= 16 || view.shader_register != slots.size()) throw std::runtime_error("view kind " + std::to_string(static_cast(view.kind)) + " is not bound for a natively translated program"); - slots.push_back({static_cast(view.root_parameter), static_cast(view.byte_offset), volume || texture_input}); - if (volume) slots.back().uav_dimension = D3D12_UAV_DIMENSION_TEXTURE3D; + slots.push_back({static_cast(view.root_parameter), static_cast(view.byte_offset), float4_output || texture_input}); + if (float4_output) slots.back().uav_dimension = float4_dimension; // The dispatch path takes an input of any other dimension for a described 1D, 2D-array or 3D view. if (texture_input) slots.back().srv_dimension = D3D12_SRV_DIMENSION_TEXTURE2D; slots.back().half_typed_bytes = half_typed ? view.required_bytes : 0; @@ -385,9 +414,7 @@ bool translate_compute_natively(ComputeTranslation& tr) if (tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 8) throw std::runtime_error("more entry values, inputs or outputs than the dispatch path binds"); // A direct module declares wave size 32 (src/dxil_module.h): without it the pipeline cannot be created. - D3D12_FEATURE_DATA_D3D12_OPTIONS1 waves{}; - if (FAILED(device_of(the_device)->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS1, &waves, sizeof(waves))) || - !waves.WaveOps || waves.WaveLaneCountMin > 32 || waves.WaveLaneCountMax < 32) + if (adapter_32_lane_waves() != 1) throw std::runtime_error("the adapter has no 32-lane waves"); // Never released: a static destructor would release DXC after its module may have detached. static x2w::ShaderDxilCompiler* const compiler = diff --git a/tests/startup_compute_dispatch_native_check.py b/tests/startup_compute_dispatch_native_check.py index 19842660f1..52c660fddf 100644 --- a/tests/startup_compute_dispatch_native_check.py +++ b/tests/startup_compute_dispatch_native_check.py @@ -25,9 +25,12 @@ comparison results. Every volume word is compared with a CPU model of the sampler words. Control: with the first sampler's words loaded from memory (the table) instead, the C++ compiler refuses the program and the volume keeps its words. +6. Table views: a scalar buffer read and a 2D image load feed a 3D image store. A zero-size UAV W range leaves the + volume untouched. +7. Texture outputs: 1D float, 2D-array float, and 2D packed D16 stores match CPU references. -A direct compute module declares wave size 32. On an adapter without 32-lane waves, steps 1 and 5 instead check that -the native translation is refused by that name with the output untouched (the memory sampler control runs as +A direct compute module declares wave size 32. On an adapter without 32-lane waves, steps 1, 5, 6 and 7 instead check +that the native translation is refused by that name with the output untouched (the memory sampler control runs as written), steps 2 and 3 run as written, step 4 runs the first program through its published translation, and the check exits 77. Exit 77 also when the adapter is not available. @@ -42,6 +45,7 @@ import startup_gfx2hlsl_compute_check as C import startup_compute_dispatch_texture_check as T import startup_compute_image_store_check as A +import startup_compute_image_store_d16_check as D import startup_gfx2hlsl_image_store_3d1d_check as V from startup_compute_dispatch_check import dispatch, lines, prepare_case from startup_compute_translate_check import state_a @@ -51,6 +55,8 @@ LOADS_X4 = bytes.fromhex('050308f4' '000000fa' '050408f4' '200000fa') RECORD_LOADS = ['s_load_dwordx4 s[12:15], s[10:11], 0x0', 's_load_dwordx4 s[16:19], s[10:11], 0x20'] NO_WAVES = 'not translated natively: the adapter has no 32-lane waves' +TEXTURE_DISPATCH = 'Dispatch(2, 1, 1)' +ZERO_W_REFUSAL = 'an output 3D texture W range is outside the mip' # Step 5. Sampler words [address, LOD limits, filter, border] in register order: U address mode in bits 2:0 over # clamp V, MIN_LOD and MAX_LOD as 4.8 fixed point in bits 11:0 and 23:12 of word 1, point filters. WRAP, MIRROR, CLAMP, POINT_MIP = 0, 1, 2, 1 << 26 @@ -84,6 +90,123 @@ def mismatch(got, expected, result): wrong[0], got[wrong[0]], expected[wrong[0]], len(wrong), result.stderr[-3000:]) +def table_program(): + # Keep the volume fixture's table pointer, UAV descriptor, coordinates, and final store. + wait = bytes.fromhex('7fc08cbf') + prologue, _, tail = V.program('volume').partition(wait) + loads = bytes.fromhex( + '060808f4000000fa' # s_load_dwordx4 s[32:35], s[12:13], 0x0 + '06060cf4200000fa' # s_load_dwordx8 s[24:31], s[12:13], 0x20 + ) + values = bytes.fromhex( + '100920f4000000fa' # s_buffer_load_dword s36, s[32:35], 0x0 + ) + wait + bytes.fromhex( + '2402107e' # v_mov_b32 v8, s36 + '80020c7e' # v_mov_b32 v6, 0 + '80020e7e' # v_mov_b32 v7, 0 + ) + image = bytes.fromhex('080100f006090600') # image_load v9, v[6:7], s[24:31], dmask:1, 2D + # The new reads replace the first two literal moves (two dwords each). + return prologue + loads + wait + values + image + bytes.fromhex('700f8cbf') + tail[16:] + + +def table_views(directory, consumer, dxc_dir, adapter, no_waves): + cache, env = prepare_case(directory, adapter) + env['X2W_NATIVE_SHADERS'] = dxc_dir + root = Path(env['X2W_TEST_COMPUTE_ROOT']) + # Two SRVs in records 0 and 1, followed by one UAV in record 2. + blob = bytearray(C.root_blob(3, table_range=True)[:-24]) + blob.extend(struct.pack('<12I', 0, 2, 0, 0, 0, 0, 1, 1, 0, 0, 0, 2)) + payload = 44 # DXBC header, part offset, and RTS0 part header + struct.pack_into(' [two-mips] +usage: startup_compute_dispatch_texture_check.py [two-mips | ] Texture output: the consumer creates the image store program of startup_compute_image_store_d16_check.py as a device slot 67 pipeline, fills a 32x8 RGBA16_FLOAT texture with sentinel halves, creates an unordered access view of @@ -13,7 +13,8 @@ 4. texture-store-denied (a texture without unordered access, whose view the stand-in does not create): refused with one logged reason, every half keeps its sentinel. A fifth run binds the same program under a manifest edited to declare no entry values. -The 1D and 3D float texture cases check mip-one readback, a mismatched view, and an invalid 3D W range. +The 1D and 3D float texture cases check mip-one readback, a mismatched view, an invalid 3D W range and an invalid +1D mip. With compile_dxil, the native translations of the same programs check the same path. Texture input: case A of startup_gfx2hlsl_compute_check.py with a level-zero sample of a 2D texture XORed into the stored word (a static sampler, a texture view at table byte 64). The consumer adds a 1x1 RGBA8 texture whose red @@ -158,6 +159,11 @@ def store(directory, consumer, dxc, env): f'untouched before translation, without a Dispatch and for a refused view; debug layer: {layer}') +# The runtime reports the adapter capability next to the PSO failure; only this test knows its native +# modules declare WaveSize(32), so only here does that observation explain the failure. +NO_WAVES = 'pipeline creation failed (adapter has no 32-lane waves)' + + # A second descriptor, at table byte 128, and a different color in v14. SECOND_STORE = bytes.fromhex( '06080cf4 800000fa ' # s_load_dwordx8 s[32:39], s[12:13], 0x80 @@ -234,10 +240,15 @@ def store_two_mips(directory, consumer, dxc, env): print(f'two mip outputs: {len(got)} halves match; swapping views changes {changed} halves; debug layer: {layer}') -def store_3d1d(directory, consumer, dxc, env, form): +def store_3d1d(directory, consumer, dxc, env, adapter, form, compiler=None, sdk=None): cache, base = prepare(directory) env = dict(base, **env) - (directory / 'compute_root').write_bytes(C.root_blob(3, table_range=True)) + root = C.root_blob(3, table_range=True) + if compiler is not None: + env.pop('X2W_NATIVE_SHADERS', None) + # The helper's final RTS0 range is replaced with UAV(u0, offset=2). Each guest record is 32 bytes. + root = root[:-24] + struct.pack('<6I', 1, 1, 0, 0, 0, 2) + (directory / 'compute_root').write_bytes(root) env['X2W_TEST_COMPUTE_ROOT'] = str(directory / 'compute_root') (directory / 'program').write_bytes(V.program(form)) (directory / 'data').write_bytes(DATA) @@ -257,11 +268,24 @@ def store_3d1d(directory, consumer, dxc, env, form): got, result = run(directory, consumer, env, mode, layout) assert got == initial and len(lines(result, 'Dispatch(2, 1, 1) refused: no translation')) == 1 key = int(lines(result, 'x2w-draw compute request')[0].split()[3], 16) - translate(cache, dxc, key) + if compiler is None: + translate(cache, dxc, key) + else: + compiled = subprocess.run([compiler, sdk, directory / 'frontend', 'gfx1013-direct-cs@0', '--requests', + cache, cache], capture_output=True, text=True) + assert compiled.returncode == 0 and 'requests=1 compiled=1 refused=0' in compiled.stdout, ( + compiled.stdout, compiled.stderr) + assert (cache / f'{key:016x}.cs.cso').read_bytes().startswith(b'DXBC') manifest = (cache / f'{key:016x}.txt').read_text().splitlines() dim = '3d' if volume else '1d' assert f'uav 0 tex{dim} float table 1 64 channels 4' in manifest, manifest got, result = run(directory, consumer, env, mode, layout) + # Older WARP builds refuse the direct compiler's WaveSize(32) PSO. + if compiler is not None and adapter == 'warp' and lines(result, f'not translated: {NO_WAVES}'): + assert got == initial and len(lines(result, f'Dispatch(2, 1, 1) refused: {NO_WAVES}')) == 1, ( + result.stderr[-3000:]) + print(f'{form}: native 3D/1D dispatch cases skipped on WARP: the adapter has no 32-lane waves') + return assert len(lines(result, 'Dispatch(2, 1, 1) translated')) == 1, result.stderr[-3000:] assert got == expected, (form, sum(a != b for a, b in zip(got, expected, strict=True))) clean(result) @@ -279,7 +303,8 @@ def store_3d1d(directory, consumer, dxc, env, form): refusal = lines(result, 'Dispatch(2, 1, 1) refused:') assert len(refusal) == 1 and refusal[0].endswith(reason), result.stderr[-3000:] assert got == untouched and not lines(result, 'Dispatch(2, 1, 1) translated') - print(f'{form}: {len(expected)} mip-one words match; incompatible views refused with sentinels intact') + fixture = 'translated' if compiler is None else 'native' + print(f'{fixture} {form}: {len(expected)} mip-one words match; incompatible views refused with sentinels intact') # v_xor_b32 v5, v5, v12: the assembled `v_xor_b32 v5, v5, v6` of case A with its second source register changed @@ -554,7 +579,7 @@ def uniform_image_load_mip(directory, consumer, dxc, env): f'x=0 and mip=1 controls each differ at {written} words; debug layer: {layer}') -def main(consumer, dxc, adapter, mode=None): +def main(consumer, dxc, adapter, mode=None, compiler=None, sdk=None): env = dict(X2W_D3D12_LIST_NOOP='1', X2W_D3D12_DEBUG='1') # guest lists; debug-layer messages go to the log if adapter == 'hardware': env['X2W_TEST_DISPATCH_HARDWARE'] = '1' @@ -565,7 +590,10 @@ def main(consumer, dxc, adapter, mode=None): else: store(directory / 'store', consumer, dxc, env) for form in V.FORMS: - store_3d1d(directory / form, consumer, dxc, env, form) + store_3d1d(directory / form, consumer, dxc, env, adapter, form) + if compiler is not None: + for form in V.FORMS: + store_3d1d(directory / f'native-{form}', consumer, dxc, env, adapter, form, compiler, sdk) sample(directory / 'sample', consumer, dxc, env) filtered(directory / 'filtered', consumer, dxc, env) compared(directory / 'compared', consumer, dxc, env) @@ -574,6 +602,10 @@ def main(consumer, dxc, adapter, mode=None): if __name__ == '__main__': - if len(sys.argv) not in (4, 5) or sys.argv[3] not in ('warp', 'hardware') or sys.argv[4:] not in ([], ['two-mips']): + extra = sys.argv[4:] + if sys.argv[3:4] not in (['warp'], ['hardware']) or (extra not in ([], ['two-mips']) and len(extra) != 2): sys.exit(__doc__) - main(*sys.argv[1:]) + if len(extra) == 2: + main(*sys.argv[1:4], None, *extra) + else: + main(*sys.argv[1:]) diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index e2ee295b1e..0ac25c1aa6 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -779,7 +779,9 @@ static int texture_slot67(IDXGIAdapter* adapter, void* device, const std::string // texture-volume-native-sampled: the volume store, plus a 2x1 R32_FLOAT texture (a format a comparison sample // reads) with a 1x1 second mip, whose shader resource view token is copied to table byte 32. const bool sampled = mode == "texture-volume-native-sampled"; - const bool volume = sampled || mode == "texture-volume" || mode == "texture-volume-bad-w" || + const bool zero_w = mode == "texture-volume-native-zero-w"; + const bool native_inputs = mode == "texture-volume-native-inputs" || zero_w; + const bool volume = sampled || native_inputs || mode == "texture-volume" || mode == "texture-volume-bad-w" || mode == "texture-exact-volume"; const bool line = mode == "texture-line" || mode == "texture-line-bad-mip"; const UINT first_mip = volume || line ? 1 : 0; @@ -860,10 +862,15 @@ static int texture_slot67(IDXGIAdapter* adapter, void* device, const std::string for (UINT i = 0; i < bytes / 2; ++i) static_cast(memory)[i] = static_cast(0x5000 + i); } invoke(upload, 9, 0, 0); + constexpr StreamWord record_bytes = 32; + const StreamWord increment = invoke(device, 15, D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); + const UINT views = dual ? 5 : 4; + // On wider heaps, reserve a separate region for the shader's packed guest table. + const UINT table_slot = increment == record_bytes ? 0 : views; const struct { D3D12_DESCRIPTOR_HEAP_DESC desc; UINT64 backing, bytes; - } heap_desc{{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, dual ? 5u : 4u, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE}, 0, 0}; + } heap_desc{{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, table_slot + views, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE}, 0, 0}; void *heap = nullptr, *queue = nullptr, *allocator = nullptr, *list = nullptr, *fence = nullptr; const D3D12_COMMAND_QUEUE_DESC queue_desc{}; const UINT list_desc[]{D3D12_COMMAND_LIST_TYPE_DIRECT, 2, 1, 0}; @@ -873,12 +880,37 @@ static int texture_slot67(IDXGIAdapter* adapter, void* device, const std::string FAILED(static_cast(invoke(device, 73, word(list_desc), word(allocator), 0, word(&__uuidof(ID3D12GraphicsCommandList)), word(&list)))) || FAILED(static_cast(invoke(device, 36, 0, 0, word(&__uuidof(ID3D12Fence)), word(&fence))))) return 72; const StreamWord cpu = invoke(heap, 9), gpu = invoke(heap, 10); - if (!cpu || !gpu) return 73; + if (!cpu || !gpu || increment < record_bytes) return 73; + const StreamWord table_cpu = cpu + table_slot * increment; + const StreamWord uav_handle = cpu + 2 * increment; + void* input_texture = nullptr; + if (native_inputs) { + // A hardware buffer descriptor in record 0 and a 2D SRV token in record 1. + auto* input = static_cast(VirtualAlloc(nullptr, 0x10000, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE)); + if (!input) return 70; + input[0] = 0x3f200000u; // 0.625f, not a value the store fixture writes + void* placed = nullptr; + const D3D12_RESOURCE_DESC input_buffer{D3D12_RESOURCE_DIMENSION_BUFFER, 0, sizeof(UINT), 1, 1, 1, + DXGI_FORMAT_UNKNOWN, {1, 0}, D3D12_TEXTURE_LAYOUT_ROW_MAJOR}; + if (FAILED(static_cast(invoke(device, 133, word(input), word(&input_buffer), D3D12_RESOURCE_STATE_COMMON, + 0, word(&__uuidof(ID3D12Resource)), word(&placed))))) return 71; + const auto address = reinterpret_cast(input); + const UINT descriptor[4] = {static_cast(address), static_cast(address >> 32) | (4u << 16), 1, 0}; + std::memcpy(reinterpret_cast(table_cpu), descriptor, sizeof(descriptor)); + const D3D12_RESOURCE_DESC input_desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, 1, 1, 1, 1, format, {1, 0}}; + input_texture = make(D3D12_HEAP_TYPE_DEFAULT, input_desc, D3D12_RESOURCE_STATE_COMMON); + if (!input_texture) return 71; + D3D12_SHADER_RESOURCE_VIEW_DESC input_view{format, D3D12_SRV_DIMENSION_TEXTURE2D, + D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING}; + input_view.Texture2D.MipLevels = 1; + invoke(device, 18, word(input_texture), word(&input_view), cpu + 1 * increment); + } D3D12_UNORDERED_ACCESS_VIEW_DESC view{format, D3D12_UAV_DIMENSION_TEXTURE2D}; if (volume) { view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE3D; // At mip 1 the depth is six. The bad count fits only if the binder uses the base mip's depth. view.Texture3D = {first_mip, 1, mode == "texture-volume-bad-w" ? layers : ~0u}; + if (zero_w) view.Texture3D.WSize = 0; } else if (line) { view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE1D; view.Texture1D.MipSlice = mode == "texture-line-bad-mip" ? first_mip + 1 : first_mip; @@ -888,33 +920,44 @@ static int texture_slot67(IDXGIAdapter* adapter, void* device, const std::string } else { view.Texture2D.MipSlice = swapped ? 1 : 0; } - if (mode != "texture-store-copied") invoke(device, 19, word(texture), 0, word(&view), cpu + 64); + if (mode != "texture-store-copied") invoke(device, 19, word(texture), 0, word(&view), uav_handle); if (mode == "texture-store-copied") { // The view is created at another handle and its token copied into this slot by memcpy, as a title does; a // refused creation at this slot then keeps that copied token. invoke(device, 19, word(texture), 0, word(&view), cpu); - std::memcpy(reinterpret_cast(cpu + 64), reinterpret_cast(cpu), 32); + std::memcpy(reinterpret_cast(uav_handle), reinterpret_cast(cpu), record_bytes); D3D12_RESOURCE_DESC plain = texture_desc; plain.Flags = D3D12_RESOURCE_FLAG_NONE; void* const other = make(D3D12_HEAP_TYPE_DEFAULT, plain, D3D12_RESOURCE_STATE_COMMON); if (!other) return 79; - invoke(device, 19, word(other), 0, word(&view), cpu + 64); + invoke(device, 19, word(other), 0, word(&view), uav_handle); } else if (mode == "texture-store-occupied") { // A second creation at the same handle, over a texture without unordered access, is refused and leaves the first view. D3D12_RESOURCE_DESC plain = texture_desc; plain.Flags = D3D12_RESOURCE_FLAG_NONE; void* const other = make(D3D12_HEAP_TYPE_DEFAULT, plain, D3D12_RESOURCE_STATE_COMMON); if (!other) return 79; - invoke(device, 19, word(other), 0, word(&view), cpu + 64); + invoke(device, 19, word(other), 0, word(&view), uav_handle); } if (dual) { view.Texture2D.MipSlice = swapped ? 0 : 1; - invoke(device, 19, word(texture), 0, word(&view), cpu + 128); + invoke(device, 19, word(texture), 0, word(&view), cpu + 4 * increment); } D3D12_SHADER_RESOURCE_VIEW_DESC read{format, D3D12_SRV_DIMENSION_TEXTURE2D, D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING}; read.Texture2D.MipLevels = 1; if (mode == "texture-store-self") invoke(device, 18, word(texture), word(&read), cpu); - void* input_texture = nullptr; + if (table_slot) { + // Creation writes 32-byte tokens at the stride-aligned CPU handles. The translated + // Dispatch reads them at literal guest byte offsets 0, 32, 64 and 128 from the bound table. + const auto copy_token = [&](UINT slot) { + std::memcpy(reinterpret_cast(table_cpu + slot * record_bytes), + reinterpret_cast(cpu + slot * increment), record_bytes); + }; + if (native_inputs) copy_token(1); + if (mode == "texture-store-self") copy_token(0); + if (dual) copy_token(4); + copy_token(2); + } if (sampled) { const D3D12_RESOURCE_DESC input_desc{D3D12_RESOURCE_DIMENSION_TEXTURE2D, 0, 2, 1, 1, 2, DXGI_FORMAT_R32_FLOAT, {1, 0}}; input_texture = make(D3D12_HEAP_TYPE_DEFAULT, input_desc, D3D12_RESOURCE_STATE_COMMON); @@ -924,7 +967,7 @@ static int texture_slot67(IDXGIAdapter* adapter, void* device, const std::string input_view.Texture2D.MipLevels = 2; // Created at handle 0 and copied to table byte 32, which is not a handle where the increment is above 32. invoke(device, 18, word(input_texture), word(&input_view), cpu); - std::memcpy(reinterpret_cast(cpu + 32), reinterpret_cast(cpu), 32); + std::memcpy(reinterpret_cast(table_cpu + record_bytes), reinterpret_cast(cpu), record_bytes); } const auto transfer = [&](void* buffer, bool to_texture) { for (UINT layer = 0; layer < subresources; ++layer) @@ -939,8 +982,16 @@ static int texture_slot67(IDXGIAdapter* adapter, void* device, const std::string const UINT constants[3] = {1, 2, 3}; if (FAILED(static_cast(invoke(list, 139, word(allocator))))) return 74; invoke(list, 32, 1, word(&heap)); + if (native_inputs) { + D3D12_TEXTURE_COPY_LOCATION input_image{static_cast(input_texture), + D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX}; + D3D12_TEXTURE_COPY_LOCATION input_source{static_cast(upload), + D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT}; + input_source.PlacedFootprint = {0, {format, 1, 1, 1, pitch}}; + invoke(list, 16, word(&input_image), 0, 0, 0, word(&input_source), 0); + } // Mip 0 takes the first two sentinel words of the upload, mip 1 the word at byte 512 (word 128). - for (UINT mip = 0; input_texture && mip < 2; ++mip) { + for (UINT mip = 0; sampled && mip < 2; ++mip) { D3D12_TEXTURE_COPY_LOCATION input_image{static_cast(input_texture), D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX}; input_image.SubresourceIndex = mip; @@ -953,7 +1004,7 @@ static int texture_slot67(IDXGIAdapter* adapter, void* device, const std::string invoke(list, 25, word(slot67_pipeline)); invoke(list, 33, word(slot67_root)); invoke(list, 39, 0, 3, word(constants), 0); - invoke(list, 35, 1, gpu); + invoke(list, 35, 1, gpu + table_slot * increment); if (mode != "texture-store-none") invoke(list, 14, 2, 1, 1); transfer(readback, false); if (FAILED(static_cast(invoke(list, 9)))) return 75;