diff --git a/CMakeLists.txt b/CMakeLists.txt index fef07e485..86f2cbc4c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4759,6 +4759,12 @@ 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}) + if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${DXC_BIN_DIR}/dxil.dll") + add_test(NAME startup_compute_dispatch_texture_native_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_texture_check.py" "$" + "${DXC_EXECUTABLE}" ${adapter} "$" "${DXC_BIN_DIR}") + set_tests_properties(startup_compute_dispatch_texture_native_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) + 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}) diff --git a/docs/experiments/startup-compute-native-dispatch.md b/docs/experiments/startup-compute-native-dispatch.md index bafceee39..de1c070b9 100644 --- a/docs/experiments/startup-compute-native-dispatch.md +++ b/docs/experiments/startup-compute-native-dispatch.md @@ -14,9 +14,10 @@ cache and no offline translator, and compares all 320 output words with a CPU re 3. The entry values and views fill the same `ComputeTranslation` a published `.txt` fills. The existing dispatch path then resolves the table descriptors, sets the resource states and records the Dispatch. -Accepted: root constants, a raw table buffer loaded per lane and a raw table buffer stored to. These are the -bindings the fixture runs. Refused: every other view kind (a scalar buffer load included), a sampler, more than -32 entry values or inputs or 8 outputs, an adapter without 32-lane waves, and whatever the frontend refuses. The +Accepted bindings include root constants, scalar and per-lane raw table buffer inputs, raw buffer outputs, +2D texture inputs, and four-channel float 1D, 2D, 2D array and 3D texture outputs. The stand-in refuses other +view kinds, samplers, more than 32 entry values or inputs or 8 outputs, and adapters that lack wave32 or report +a shader model below 6.6. The stand-in logs the first 16 refusals of a process with their reason. A refused key is left to a published translation. The in-process translation is tried once per key and before a published `.txt`. @@ -44,7 +45,7 @@ decoder, and the consumer's `dispatch-records32` mode writes the table with the 5. Order: the first program runs again with its published translation in the cache. The log still names the native translation, and all 320 words match. -Without 32-lane waves, step 1 instead checks that the native translation is refused by that name with every word +Without wave32 or shader model 6.6, step 1 instead checks the named capability refusal with every word untouched. Step 2 is left out, steps 3 and 4 run, step 5 runs the first program through its published translation, and the check exits 77. diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 8a953e4d8..3777692e6 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -943,20 +943,29 @@ pipelines, and the cache can start empty: the request files the stand-in wrote a against their key, translated and compiled to DXIL in the process. The compiler's own cache goes to `\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. Anything else (a -scalar buffer load, a texture, a sampler, a typed or indexed view, an instruction the compiler does -not lower) is refused. The first 16 refusals of a process are logged as +The existing dispatch path binds root constants and views in 32-byte table records. Buffer views +include scalar buffer SRVs (`buffer_srv`), per-lane raw buffer SRVs (`raw_vector_srv`), and raw buffer +UAVs. Texture views include 2D SRVs and four-channel float 1D, 2D, 2D array, and 3D UAVs +(`texture_uav` and `half4_texture_uav`). Samplers, typed or indexed buffer views, and instructions +outside the compiler's supported set are refused. The first 16 refusals of a process are logged as `compute pipeline not translated natively: `. A refused key is left to the -published translations, so `-Translate` can run beside it for those pipelines. A direct module declares -wave size 32, so an adapter without 32-lane waves refuses every program by that name. The in-process +published translations, so `-Translate` can run beside it for those pipelines. A direct module requires +shader model 6.6 and wave32. The in-process translation is tried once per key and before a published `.txt`. It covers compute only; graphics pipelines still need a published translation. 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 wave32 or shader model 6.6 the cases check the named refusal +and untouched output before the test returns 77. ### Compute pipeline requests @@ -3613,3 +3622,17 @@ 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 + +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. + +The native offline fixture compiles 1D, 3D and 3D NSA programs, checks the published DXIL and +manifest, and compares every mip-one word after Dispatch. It also checks that mismatched views, +an invalid 3D W range and an invalid 1D mip leave the output unchanged. An adapter without +wave32 or shader model 6.6 can verify the native manifests before returning a capability skip for Dispatch. +The separate texture dispatch fixture exercises the existing Python-published path. + +`ctest --preset dev --no-tests=error -R '^startup_compute_dispatch_texture_(native_)?(warp|hardware)$' -V` diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index e633a50b2..d8e3965d1 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -763,8 +763,16 @@ std::optional format_compute_runtime_manifest(const NativeComputeSh uav_lines << "uav " << b.shader_register << " table " << b.root_parameter << ' ' << b.byte_offset << '\n'; } else if ((b.kind == ComputeViewKind::texture_uav || b.kind == ComputeViewKind::half4_texture_uav) && - (b.image_dimension == 1 || b.image_dimension == 5) && b.array_count == 1) { - uav_lines << "uav " << b.shader_register << (b.image_dimension == 5 ? " tex2da" : " 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 std::nullopt; + } + uav_lines << "uav " << b.shader_register << ' ' << tex << " float table " << b.root_parameter << ' ' << b.byte_offset << " channels 4\n"; } else { return std::nullopt; diff --git a/src/startup_stubs/d3d12_compute_dispatch.inl b/src/startup_stubs/d3d12_compute_dispatch.inl index 3dfc27444..2bbf25517 100644 --- a/src/startup_stubs/d3d12_compute_dispatch.inl +++ b/src/startup_stubs/d3d12_compute_dispatch.inl @@ -77,6 +77,22 @@ bool float_output_format(DXGI_FORMAT format) 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; +// 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; +} + +bool adapter_reports_shader_model_below_6_6() +{ + D3D12_FEATURE_DATA_SHADER_MODEL model{D3D_SHADER_MODEL_6_6}; + return SUCCEEDED(device_of(the_device)->CheckFeatureSupport(D3D12_FEATURE_SHADER_MODEL, &model, sizeof(model))) && + model.HighestShaderModel < D3D_SHADER_MODEL_6_6; +} + // 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) @@ -193,7 +209,17 @@ 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 does not declare a wave size. Report the adapter capability alongside the PSO failure. + 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)"; + if (adapter_reports_shader_model_below_6_6()) + return "pipeline creation failed (adapter shader model below 6.6)"; + } + 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; @@ -201,8 +227,7 @@ 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 it loads per lane (buffer_load_dword) and raw table buffers it stores to. +// and with no offline translator running. The dispatch path below binds root constants and supported table views. // 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) { @@ -221,22 +246,40 @@ bool translate_compute_natively(ComputeTranslation& tr) std::sort(program.bindings.begin(), program.bindings.end(), [](const auto& a, const auto& b) { return a.shader_register < b.shader_register; }); for (const auto& view : program.bindings) { - // The two kinds a fixture has run through this path: a raw buffer read per lane, and one written. - const bool output = view.kind == x2w::ComputeViewKind::raw_buffer_uav; + using Kind = x2w::ComputeViewKind; + // Match the float texture and buffer slots in format_compute_runtime_manifest. + const bool texture_output = view.kind == Kind::texture_uav || view.kind == Kind::half4_texture_uav; + const bool output = texture_output || view.kind == Kind::raw_buffer_uav; + const bool texture_input = view.kind == Kind::texture_srv && view.image_dimension == 1; + auto dimension = D3D12_UAV_DIMENSION_UNKNOWN; + if (texture_output) { + switch (view.image_dimension) { + case 0: dimension = D3D12_UAV_DIMENSION_TEXTURE1D; break; + case 1: dimension = D3D12_UAV_DIMENSION_TEXTURE2D; break; + case 2: dimension = D3D12_UAV_DIMENSION_TEXTURE3D; break; + case 5: dimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; break; + } + } auto& slots = output ? tr.uavs : tr.srvs; - if ((!output && view.kind != x2w::ComputeViewKind::raw_vector_srv) || view.array_count != 1 || + const bool supported = view.kind == Kind::raw_buffer_uav || view.kind == Kind::raw_vector_srv || + view.kind == Kind::buffer_srv || texture_input || + dimension != D3D12_UAV_DIMENSION_UNKNOWN; + if (!supported || 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)}); + slots.push_back({static_cast(view.root_parameter), static_cast(view.byte_offset), + texture_input || texture_output}); + if (texture_output) + slots.back().uav_dimension = dimension; } if (!program.samplers.empty() || tr.uds.size() > 32 || tr.srvs.size() > 32 || tr.uavs.size() > 8) throw std::runtime_error("a sampler, or 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) + // Direct modules use shader model 6.6 with WaveSize(32). + if (adapter_32_lane_waves() != 1) throw std::runtime_error("the adapter has no 32-lane waves"); + if (adapter_reports_shader_model_below_6_6()) + throw std::runtime_error("the adapter reports shader model below 6.6"); // Never released: a static destructor would release DXC after its module may have detached. static x2w::ShaderDxilCompiler* const compiler = new x2w::ShaderDxilCompiler(x2w::ShaderDxilCompiler::runtime_worker(sdk)); diff --git a/tests/startup_compute_dispatch_native_check.py b/tests/startup_compute_dispatch_native_check.py index 2a0809e72..79e2b1404 100644 --- a/tests/startup_compute_dispatch_native_check.py +++ b/tests/startup_compute_dispatch_native_check.py @@ -18,26 +18,40 @@ dispatches case A through the published translation. All 320 words match. 4. Order: the first program runs again, now with a published translation in the cache. The native translation is still the one used, and all 320 words match. +5. Table views: a scalar buffer read and a 2D image load feed a 3D image store. Replacing the load with a sample + adds a sampler and must leave the volume untouched. A zero-size UAV W range also leaves it untouched. +6. 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, step 1 instead checks that the -native translation is refused by that name with the output untouched, 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. +A direct compute module requires shader model 6.6 and wave32. Without these, steps 1, 5 and 6 check that the +native translation is refused by that name with the output untouched. The sampler control and steps 2 and 3 run as +written, step 4 uses the published translation, and the check exits 77. Exit 77 also when the adapter is unavailable. """ import os from pathlib import Path +import struct import subprocess import sys import tempfile 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 from startup_stream_check import gfx2hlsl as G LOAD_X8 = bytes.fromhex('05030cf4' '000000fa') 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' +CAPABILITY_REFUSALS = ( + 'not translated natively: the adapter has no 32-lane waves', + 'not translated natively: the adapter reports shader model below 6.6', +) +SAMPLER_REFUSAL = 'not translated natively: a sampler, or more entry values, inputs or outputs than the dispatch path binds' +TEXTURE_DISPATCH = 'Dispatch(2, 1, 1)' +ZERO_W_REFUSAL = 'an output 3D texture W range is outside the mip' def mismatch(got, expected, result): @@ -46,6 +60,133 @@ def mismatch(got, expected, result): wrong[0], got[wrong[0]], expected[wrong[0]], len(wrong), result.stderr[-3000:]) +def table_program(sample): + # 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 + ) + if sample: + image = bytes.fromhex( + '8004a8be8004aabe' # s_mov_b64 s[40:41], 0; s_mov_b64 s[42:43], 0 + '08019cf006094601' # image_sample_lz v9, v[6:7], s[24:31], s[40:43], dmask:1, 2D + ) + else: + 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, capability_refusal): + 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(' +usage: startup_compute_dispatch_texture_check.py [compile_dxil SDK] 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 @@ -14,6 +14,7 @@ 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. +With compile_dxil, run only the 1D and 3D cases using native offline manifests and bytecode. 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 @@ -150,11 +151,17 @@ def store(directory, consumer, dxc, env): f'untouched before translation, without a Dispatch and for a refused view; debug layer: {layer}') -def store_3d1d(directory, consumer, dxc, env, form): +def store_3d1d(directory, consumer, dxc, env, 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)) - env['X2W_TEST_COMPUTE_ROOT'] = str(directory / 'compute_root') + env.pop('X2W_NATIVE_SHADERS', None) + root = directory / 'compute_root' + root_blob = C.root_blob(3, table_range=True) + if compiler is not None: + # Use an explicit UAV(u0) range at guest offset 2 for the native frontend. + root_blob = root_blob[:-24] + struct.pack('<6I', 1, 1, 0, 0, 0, 2) + root.write_bytes(root_blob) + env['X2W_TEST_COMPUTE_ROOT'] = str(root) (directory / 'program').write_bytes(V.program(form)) (directory / 'data').write_bytes(DATA) (directory / 'state').write_bytes(state_a(V.group(form), V.A.RSRC2)) @@ -173,11 +180,26 @@ 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) + if compiler is not None: + for capability in ('adapter has no 32-lane waves', 'adapter shader model below 6.6'): + reason = f'pipeline creation failed ({capability})' + if lines(result, f'not translated: {reason}'): + assert got == initial and len(lines(result, f'Dispatch(2, 1, 1) refused: {reason}')) == 1, ( + result.stderr[-3000:]) + print(f'{form}: native DXIL and manifest verified; dispatch skipped ({capability})') + return False 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) @@ -196,6 +218,7 @@ def store_3d1d(directory, consumer, dxc, env, form): 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') + return True # v_xor_b32 v5, v5, v12: the assembled `v_xor_b32 v5, v5, v6` of case A with its second source register changed @@ -391,11 +414,19 @@ 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): +def main(consumer, dxc, adapter, 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' with tempfile.TemporaryDirectory() as temporary: + if compiler is not None: + dispatched = [store_3d1d(Path(temporary) / form, consumer, dxc, env, form, compiler, sdk) + for form in V.FORMS] + if not any(dispatched): + return 77 + assert all(dispatched), dispatched + print(f'startup_compute_dispatch_texture: native manifests and dispatch passed on {adapter}') + return 0 store(Path(temporary) / 'store', consumer, dxc, env) for form in V.FORMS: store_3d1d(Path(temporary) / form, consumer, dxc, env, form) @@ -406,6 +437,6 @@ def main(consumer, dxc, adapter): if __name__ == '__main__': - if len(sys.argv) != 4 or sys.argv[3] not in ('warp', 'hardware'): + if len(sys.argv) not in (4, 6) or sys.argv[3] not in ('warp', 'hardware'): sys.exit(__doc__) - main(*sys.argv[1:]) + sys.exit(main(*sys.argv[1:])) diff --git a/tests/startup_stream_consumer.cpp b/tests/startup_stream_consumer.cpp index aa7fee734..83dc6a799 100644 --- a/tests/startup_stream_consumer.cpp +++ b/tests/startup_stream_consumer.cpp @@ -498,7 +498,9 @@ static int dispatch_slot67(IDXGIAdapter* adapter, void* device, const std::strin static int texture_slot67(void* device, const std::string& mode) { constexpr UINT width = 32; - const bool volume = 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 = native_inputs || mode == "texture-volume" || mode == "texture-volume-bad-w"; const bool line = mode == "texture-line" || mode == "texture-line-bad-mip"; const UINT mip = volume || line ? 1 : 0; const UINT height = line ? 1 : 8; @@ -533,10 +535,14 @@ static int texture_slot67(void* device, const std::string& mode) 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); + // On wider heaps, reserve a separate region for the shader's packed guest table. + const UINT table_slot = increment == record_bytes ? 0 : 4; const struct { D3D12_DESCRIPTOR_HEAP_DESC desc; UINT64 backing, bytes; - } heap_desc{{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, 4, D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE}, 0, 0}; + } heap_desc{{D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, table_slot + 4, 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}; @@ -546,12 +552,37 @@ static int texture_slot67(void* device, const std::string& mode) 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 = {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" ? mip + 1 : mip; // bad-mip: one past the last mip @@ -559,28 +590,39 @@ static int texture_slot67(void* device, const std::string& mode) view.ViewDimension = D3D12_UAV_DIMENSION_TEXTURE2DARRAY; view.Texture2DArray = {0, 1, 4, 0}; // four selected slices, with untouched neighbors on both sides } - 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); } 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); + 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 and 64 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); + copy_token(2); + } D3D12_TEXTURE_COPY_LOCATION image{static_cast(texture), D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX}; D3D12_TEXTURE_COPY_LOCATION source{static_cast(upload), D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT}; source.PlacedFootprint = {0, {format, width, height, volume ? layers : 1, pitch}}; @@ -589,6 +631,14 @@ static int texture_slot67(void* device, const std::string& mode) 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 (input_texture) { + 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); + } for (UINT subresource = 0; subresource < subresources; ++subresource) { image.SubresourceIndex = subresource + mip; source.PlacedFootprint.Offset = UINT64{subresource} * slice_bytes; @@ -597,7 +647,7 @@ static int texture_slot67(void* device, const std::string& mode) 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); for (UINT subresource = 0; subresource < subresources; ++subresource) { image.SubresourceIndex = subresource + mip;