From 66a993b6d0c7a9a623c91bd9490a51984278d25e Mon Sep 17 00:00:00 2001 From: tedin7 <110300616+tedin7@users.noreply.github.com> Date: Sat, 28 Nov 2026 18:21:33 +0100 Subject: [PATCH 1/4] shader: decode buffer FORMAT 47 (10_10_10_2 SSCALED) from hardware descriptors --- CMakeLists.txt | 7 + src/startup_stubs/formatted_buffer.h | 2 +- ...startup_buffer_format_word3_table_check.py | 2 +- tests/startup_vertex_fetch_formats_check.py | 2 +- tests/startup_vertex_fetch_sscaled_check.py | 122 ++++++++++++++++++ tools/startup/gfx2hlsl.py | 9 +- 6 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 tests/startup_vertex_fetch_sscaled_check.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 252816910f..07e16e0d20 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4136,6 +4136,8 @@ if(EXISTS "${INTAKE_PYTHON}") "${CMAKE_SOURCE_DIR}/tests/startup_sampler_heap_check.py") add_test(NAME startup_vertex_fetch_formats_controls COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/startup_vertex_fetch_formats_check.py" controls) + add_test(NAME startup_vertex_fetch_sscaled_controls COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_vertex_fetch_sscaled_check.py" controls) add_test(NAME startup_buffer_address_controls COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/startup_buffer_address_check.py" controls) add_test(NAME startup_smem_address_controls COMMAND "${INTAKE_PYTHON}" -B @@ -4150,6 +4152,11 @@ if(EXISTS "${INTAKE_PYTHON}") "${CMAKE_SOURCE_DIR}/tests/startup_vertex_fetch_formats_check.py" "${DXC_EXECUTABLE}" "$" ${adapter}) set_tests_properties(startup_vertex_fetch_formats_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) + # FORMAT 47 (10_10_10_2 SSCALED), reachable only through a hardware descriptor. + add_test(NAME startup_vertex_fetch_sscaled_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_vertex_fetch_sscaled_check.py" "${DXC_EXECUTABLE}" + "$" ${adapter}) + set_tests_properties(startup_vertex_fetch_sscaled_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) add_test(NAME startup_buffer_address_${adapter} COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/startup_buffer_address_check.py" "${DXC_EXECUTABLE}" "$" ${adapter} $<$:${STARTUP_FXC}>) diff --git a/src/startup_stubs/formatted_buffer.h b/src/startup_stubs/formatted_buffer.h index 76ad650eb8..7c1656ef47 100644 --- a/src/startup_stubs/formatted_buffer.h +++ b/src/startup_stubs/formatted_buffer.h @@ -14,7 +14,7 @@ constexpr bool formatted_buffer_supported(std::uint32_t code) { switch (code) { case 1: case 5: case 14: case 22: case 23: case 24: case 27: - case 29: case 50: case 56: case 60: case 64: case 71: case 74: case 77: + case 29: case 47: case 50: case 56: case 60: case 64: case 71: case 74: case 77: return true; default: return false; diff --git a/tests/startup_buffer_format_word3_table_check.py b/tests/startup_buffer_format_word3_table_check.py index 9099c99dc4..ab0b588a90 100644 --- a/tests/startup_buffer_format_word3_table_check.py +++ b/tests/startup_buffer_format_word3_table_check.py @@ -34,7 +34,7 @@ def main(header=ROOT / 'src' / 'startup_stubs' / 'buffer_format_word3.h'): assert set(mapped) == set(EXPECTED), sorted(set(mapped) ^ set(EXPECTED)) for dxgi, code in mapped.items(): assert code == codes[EXPECTED[dxgi]], (dxgi, code, EXPECTED[dxgi]) - assert set(EXPECTED.values()) == set(codes), 'every decoded format has a DXGI view format' + assert set(EXPECTED.values()) | gfx2hlsl.DESCRIPTOR_ONLY_FORMATS == set(codes), 'every decoded format has a DXGI view format' return len(mapped) diff --git a/tests/startup_vertex_fetch_formats_check.py b/tests/startup_vertex_fetch_formats_check.py index 0dcdc6480d..85487ae0a9 100644 --- a/tests/startup_vertex_fetch_formats_check.py +++ b/tests/startup_vertex_fetch_formats_check.py @@ -364,7 +364,7 @@ def table_matches(table): assert all(words[v * 4 + 3] for v in range(16)), label # an xyz translation leaves this register 0 for op, count in ((0, 1), (1, 2), (2, 3), (3, 4)): source = pipeline_mubuf(4, op).hlsl_vs() - assert source.count('case ') == len(FORMATS), op + assert source.count('case ') == len(FORMATS) + len(gfx2hlsl.DESCRIPTOR_ONLY_FORMATS), op # An unvalidated FORMAT yields the NaN sentinel in every component, never silent zeros. assert 'default: c0 = c1 = c2 = c3 = %du;' % gfx2hlsl.DESC_FORMAT_UNKNOWN in source, op assert 'default: break' not in source, op diff --git a/tests/startup_vertex_fetch_sscaled_check.py b/tests/startup_vertex_fetch_sscaled_check.py new file mode 100644 index 0000000000..b67adf173f --- /dev/null +++ b/tests/startup_vertex_fetch_sscaled_check.py @@ -0,0 +1,122 @@ +"""buffer_load_format_xyzw of BUF_FMT_10_10_10_2_SSCALED (gfx10 FORMAT 47) from a hardware descriptor, on a device. + +usage: startup_vertex_fetch_sscaled_check.py + startup_vertex_fetch_sscaled_check.py controls + +FORMAT 47 packs four signed fields in one dword, named most significant first: x is the 2-bit field in bits 1:0, +y, z and w are 10-bit fields in bits 11:2, 21:12 and 31:22. SSCALED converts each sign-extended field to a float +without dividing (RDNA 2 ISA guide, MTBUF/MUBUF data formats and number formats; the format list is in +tools/disasm_rdna2.py MTBUF_FORMATS). No typed DXGI view has this layout, so only a hardware descriptor reaches it: +the runtime used to refuse it ("unsupported FORMAT 47"). The translated vertex body is called from a compute +wrapper; sixteen elements at an unaligned stride are read back bit for bit against a reference decoded here. +Mutations (sign extension dropped, wrong field order, the switch case removed) must fail the same reference. +""" +import struct +import subprocess +import sys +import tempfile +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import startup_vertex_fetch_formats_check as vf # noqa: E402 + +CODE, STRIDE, OFFSET = 47, 6, 2 +IDENTITY = 4 | 5 << 3 | 6 << 6 | 7 << 9 +FIELDS = ((0, 2), (2, 10), (12, 10), (22, 10)) # (low bit, width) of x, y, z, w + + +def signed(value, width): + return value - (1 << width) if value >> (width - 1) else value + + +def f32_bits(value): + return struct.unpack('> low) & ((1 << width) - 1) + values.append(f32_bits(signed(raw, width) if extend else raw)) + words[vertex * 4:vertex * 4 + 4] = [values[i] for i in order] + return words + + +WRAPPER = ''' +RWByteAddressBuffer outputWords : register(u0); +[numthreads(16, 1, 1)] +void readback(uint id : SV_GroupIndex) { + outputWords.Store4(id * 16, asuint(body(id).pos)); +} +''' + + +def translated(): + return vf.pipeline_mubuf(OFFSET, 3) + + +def run(directory, compiler, consumer, adapter, source, words, tr): + hlsl, binary = directory / 'sscaled.hlsl', directory / 'sscaled.cso' + hlsl.write_text(source + WRAPPER, encoding='ascii') + subprocess.run([compiler, '-T', 'cs_6_0', '-E', 'readback', '-Fo', binary, hlsl], check=True) + constants = [0] * 16 + constants[tr.uds.index(('stride', 0))] = STRIDE + constants[tr.uds.index(('descword3', 0))] = CODE << 12 | IDENTITY + case = directory / 'sscaled.case' + case.write_bytes(struct.pack('<337I', 1, *words, *constants)) + return subprocess.run([consumer, adapter, '--compute-store-case', binary, case], capture_output=True, text=True) + + +def controls(): + source = translated().hlsl_vs() + assert 'case %du:' % CODE in source, 'FORMAT 47 has no decoder case' + good = expected() + # The data must exercise negative fields in every channel, or sign extension would not be tested. + for channel in range(4): + assert any(good[v * 4 + channel] >> 31 for v in range(16)), channel + assert any(not good[v * 4 + channel] >> 31 for v in range(16)), channel + assert expected(extend=False) != good and expected(order=(1, 0, 2, 3)) != good + header = (Path(__file__).resolve().parents[1] / 'src' / 'startup_stubs' / 'formatted_buffer.h').read_text() + assert 'case 47:' in header, 'the runtime must accept FORMAT 47' + + +def check(directory, compiler, consumer, adapter): + tr = translated() + source = tr.hlsl_vs() + result = run(directory, compiler, consumer, adapter, source, expected(), tr) + if result.returncode == 77: + return 77 + assert result.returncode == 0, result.stdout + result.stderr + print('FORMAT 47 xyzw: 16 elements bit-exact') + lines = [i for i, line in enumerate(source.split('\n')) if line.strip().startswith('case 47u:')] + assert len(lines) == 1, lines + rows = source.split('\n') + mutants = ( + ('case removed', lambda r: r[:lines[0]] + [r[lines[0]].replace('case 47u:', 'case 255u:', 1)] + r[lines[0] + 1:]), + ('sign extension dropped', lambda r: r[:lines[0]] + [r[lines[0]].replace('float(int(', 'float(uint(')] + r[lines[0] + 1:]), + ) + for label, mutate in mutants: + mutated = '\n'.join(mutate(rows)) + assert mutated != source, label + bad = run(directory, compiler, consumer, adapter, mutated, expected(), tr) + assert bad.returncode == 1 and 'Compute readback differs' in bad.stderr, (label, bad.stdout, bad.stderr) + print('mutation %r fails' % label) + bad = run(directory, compiler, consumer, adapter, source, expected(order=(1, 0, 2, 3)), tr) + assert bad.returncode == 1 and 'Compute readback differs' in bad.stderr, 'wrong field order passed' + print('wrong field order fails') + return 0 + + +if __name__ == '__main__': + controls() + if sys.argv[1:] == ['controls']: + print('sscaled fetch controls passed') + sys.exit(0) + if len(sys.argv) != 4: + sys.exit(__doc__) + with tempfile.TemporaryDirectory() as temp: + sys.exit(check(Path(temp), *sys.argv[1:])) diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index 148e8b9e6f..013ff5c33c 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -140,6 +140,11 @@ def strip_header(code): 'BUF_FMT_8_UINT': ('{0}.Load(a & ~3u) >> ((a & 3u) * 8u)', ['w & 255u', '0u', '0u', '1u']), # Three 10-bit fields and a 2-bit one in one dword, lowest bits first: x, y, z, then w. 'BUF_FMT_2_10_10_10_UNORM': ('ldu({0}, a)', ['U((w & 1023) / 1023.0)', 'U(((w >> 10) & 1023) / 1023.0)', 'U(((w >> 20) & 1023) / 1023.0)', 'U((w >> 30) / 3.0)']), + # Fields are listed most significant first: x is the 2-bit field in bits 1:0, y, z and w are 10 bits each. + # Each field is sign-extended and converted to a float as is (no division). No DXGI typed view has this + # layout, so only a hardware descriptor reaches it (FORMAT 47, see DESC_FORMAT_CODES). + 'BUF_FMT_10_10_10_2_SSCALED': ('ldu({0}, a)', ['U(float(int(w << 30) >> 30))', 'U(float(int(w << 20) >> 22))', + 'U(float(int(w << 10) >> 22))', 'U(float(int(w) >> 22))']), 'BUF_FMT_16_16_UNORM': ('ldu({0}, a)', ['U((w & 65535) / 65535.0)', 'U((w >> 16) / 65535.0)', '0u', 'U(1.0)']), # Two unsigned 16-bit fields, x in the low half (LLVM 15: BUF_DATA_FORMAT_16_16 with BUF_NUM_FORMAT_UINT, # gfx10 unified format 27); a missing W of an integer format reads 1. @@ -165,10 +170,12 @@ def strip_header(code): # Selectors for constants still return constants, so the caller must validate FORMAT before submission. DESC_FORMAT_UNKNOWN = 0x7fc0f0f0 DESC_FORMAT_CODES = { - 'BUF_FMT_8_UNORM': 1, 'BUF_FMT_8_UINT': 5, 'BUF_FMT_8_8_UNORM': 14, 'BUF_FMT_32_FLOAT': 22, + 'BUF_FMT_8_UNORM': 1, 'BUF_FMT_8_UINT': 5, 'BUF_FMT_10_10_10_2_SSCALED': 47, 'BUF_FMT_8_8_UNORM': 14, 'BUF_FMT_32_FLOAT': 22, 'BUF_FMT_2_10_10_10_UNORM': 50, 'BUF_FMT_16_16_UNORM': 23, 'BUF_FMT_16_16_SNORM': 24, 'BUF_FMT_16_16_UINT': 27, 'BUF_FMT_16_16_FLOAT': 29, 'BUF_FMT_8_8_8_8_UNORM': 56, 'BUF_FMT_8_8_8_8_UINT': 60, 'BUF_FMT_32_32_FLOAT': 64, 'BUF_FMT_16_16_16_16_FLOAT': 71, 'BUF_FMT_32_32_32_FLOAT': 74, 'BUF_FMT_32_32_32_32_FLOAT': 77} +# Formats only a hardware descriptor reaches: no DXGI typed view has their layout. +DESCRIPTOR_ONLY_FORMATS = frozenset({'BUF_FMT_10_10_10_2_SSCALED'}) DESC_FORMAT_SHIFT, DESC_FORMAT_MASK = 12, 127 # Integer formats read a DST_SEL constant 1 as the integer 1, every other format as 1.0. DESC_ONE_INTEGER = ('BUF_FMT_8_UINT', 'BUF_FMT_16_16_UINT', 'BUF_FMT_8_8_8_8_UINT') From 025f16dd0ad9fecbe54207c93f8aaf86ddefb9b6 Mon Sep 17 00:00:00 2001 From: tedin7 <110300616+tedin7@users.noreply.github.com> Date: Sat, 28 Nov 2026 23:08:54 +0100 Subject: [PATCH 2/4] fix: bump the startup shader cache revisions to 30 so translations cached before FORMAT 47 are redone, and document FORMAT 47 --- docs/experiments.md | 6 ++++++ docs/experiments/native-compile-dxil-rekey.md | 2 +- docs/experiments/native-startup-request-cache.md | 8 ++++---- docs/experiments/patch-manifests.md | 2 +- docs/startup-runtime.md | 2 +- src/shader_compute_request.cpp | 4 ++-- src/startup_stubs/d3d12_draw.inl | 4 ++-- tests/native_compile_dxil_rekey_check.py | 2 +- tests/startup_compute_request_offline_check.py | 4 ++-- tests/startup_gfx2hlsl_buffer_store_check.py | 4 ++-- tests/startup_gfx2hlsl_fract_check.py | 4 ++-- tests/startup_indirect_draw_indexed.cpp | 2 +- tests/startup_packed_position_provenance_check.py | 2 +- tests/startup_resource_retire_title.cpp | 2 +- tests/startup_shader_cache_key_check.py | 6 +++--- tests/startup_ui_texture_bands_check.cpp | 2 +- tools/patch_manifest.py | 2 +- tools/startup/gfx2hlsl.py | 4 ++-- 18 files changed, 34 insertions(+), 28 deletions(-) diff --git a/docs/experiments.md b/docs/experiments.md index 996ed40f27..109baf58ff 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -572,6 +572,12 @@ The original ten formats matched on WARP 10.0.26100.9818 and on an AMD Radeon RX ctest --preset dev --no-tests=error -R '^startup_vertex_fetch_formats_(controls|warp|hardware)$' -V ``` +`BUF_FMT_10_10_10_2_SSCALED` (format 47) is the first descriptor-only decoded format: no DXGI typed view has this layout, so only a hardware buffer descriptor reaches it and the DXGI table (`DESC_FORMAT_CODES` against `FETCH_DXGI`) does not list it. It reads one dword as four signed fields (x is the 2-bit field in bits 1:0, y, z and w are 10-bit), each sign-extended and converted to float without division, at an unaligned stride. Accepting it changes what an existing `buffer_load_format_*` translation does for format 47, so the startup shader cache revisions are bumped to `x2w-startup-shader-30` and `x2w-startup-shader-30cs` and a cache written before this change is retranslated. Reproduction (a CPU reference compared bit for bit, with mutants for the removed case, dropped sign extension and wrong field order): + +```powershell +ctest --preset dev --no-tests=error -R '^startup_vertex_fetch_sscaled_(controls|warp|hardware)$' -V +``` + `BUF_FMT_16_16_SNORM` (format 24, DXGI `R16G16_SNORM` 37) sign-extends each half, divides by 32767 and clamps to -1.0, so -32768 and -32767 both give -1.0 (the Direct3D and Vulkan SNORM rule, as in LLVM 15 and Mesa `ac_formats`). The device run compares `round(v * 32767)` against the same byte decode, with a wrong reference that reads the halves unsigned and a mutated translation that does the same. The pattern the harness writes to t0 holds no 0x8000, so `startup_vertex_fetch_formats_controls` also evaluates the emitted expressions on 0x8000, 0x8001, 0x7fff, 0x0000, 0xffff and 0x4000 in each half, and four wrong forms (unsigned read, no clamp, divisor 32768, one half for both) must fail that check. The D3D12 draw has not been run on Linux. `BUF_FMT_2_10_10_10_UNORM` (gfx10 format 50, DXGI `R10G10B10A2_UNORM` 24) reads one dword with x, y and z as 10-bit fields in bits 9:0, 19:10 and 29:20 and w as the 2-bit field in bits 31:30, each divided by its maximum (1023, 1023, 1023, 3). This is the 10-bit-x layout that Mesa maps R10G10B10A2 to; `BUF_FMT_10_10_10_2_UNORM` (format 44) has a 2-bit x and is not added here. It is checked on Linux by the Python evaluation `startup_gfx2hlsl_tbuffer_2101010`, which also covers the DXGI table entry; the D3D12 draws `startup_vertex_fetch_formats_warp` and `startup_vertex_fetch_formats_hardware` read it back (stride 6 / offset 2 and through the descriptor path). diff --git a/docs/experiments/native-compile-dxil-rekey.md b/docs/experiments/native-compile-dxil-rekey.md index 0a886e986c..2bb475c986 100644 --- a/docs/experiments/native-compile-dxil-rekey.md +++ b/docs/experiments/native-compile-dxil-rekey.md @@ -15,7 +15,7 @@ This mode runs without `SDK_DIRECTORY` or DXC: `.m57`, `.rtv`), counts `.m86` markers, and ignores result/diagnostic files (`.txt`, `.fail`, `.cso`, `.psdep`). - Validates and recomputes keys in parallel using the current output revision - strings (`x2w-startup-shader-29`, `x2w-startup-shader-29cs`, + strings (`x2w-startup-shader-30`, `x2w-startup-shader-30cs`, `x2w-startup-mesh-57-3` via shared helpers in `src/shader_compute_request.cpp`), while the readers retain `x2w-startup-shader-28` and `x2w-startup-shader-28cs` input compatibility. diff --git a/docs/experiments/native-startup-request-cache.md b/docs/experiments/native-startup-request-cache.md index 85fe9f4c99..abbd94be7f 100644 --- a/docs/experiments/native-startup-request-cache.md +++ b/docs/experiments/native-startup-request-cache.md @@ -1,8 +1,8 @@ # Startup request consumption and runtime cache publication in `compile_dxil` (#2933) [The fixture](../../tests/native_startup_request_cache_check.py) verifies that `compile_dxil --requests` consumes -revision-29 startup graphics (`x2w-startup-shader-29`, including ASCII `req_.psin` pixel-input descriptions) -and compute (`x2w-startup-shader-29cs`, `req_.c67`) requests, publishes runtime-named stage binaries and +revision-30 startup graphics (`x2w-startup-shader-30`, including ASCII `req_.psin` pixel-input descriptions) +and compute (`x2w-startup-shader-30cs`, `req_.c67`) requests, publishes runtime-named stage binaries and manifests (`.vs.cso` / `.ps.cso` or `.cs.cso`, followed by `.txt`), and loads directly through the startup runtime cache loaders on WARP and hardware without manual renaming or conversion. @@ -47,11 +47,11 @@ ctest --preset release --no-tests=error -R '^native_compute_pack(_hardware)?$' ## Alignment between `compile_dxil --requests` and the startup cache 1. **Request keys and `.psin` stream descriptions (`src/shader_compute_request.cpp`):** - - Graphics requests validate `x2w-startup-shader-29` or the archived revision 28 over `.a`, `.b`, `.root`, and optional `.ia`. When + - Graphics requests validate `x2w-startup-shader-30` or the archived revision 28 over `.a`, `.b`, `.root`, and optional `.ia`. When `req_.psin` is present, the reader parses `psin1 ena=0x addr=0x`, checks that the embedded key matches `` and `(ena & ~addr) == 0`, and folds `b"psin1" + struct.pack(" translated_pipeline(ID3D12Device* guest, ID3D12RootSignature* r bool needs_start, TableSample sample = TableSample::texture, bool indexed = false, bool rect = false) { // The opaque guest programs identify synthetic cache entries. The actual bound shaders are source-built DXBC. - constexpr char revision[] = "x2w-startup-shader-29"; + constexpr char revision[] = "x2w-startup-shader-30"; static std::uint32_t vertex_ids[]{0xe0000101, 0xe0000102, 0xe0000103}; static std::uint32_t pixel_ids[]{0xe0000202, 0xe0000203, 0xe0000205}; static std::uint32_t indexed_pixel_id = 0xe0000204; diff --git a/tests/startup_packed_position_provenance_check.py b/tests/startup_packed_position_provenance_check.py index a06abb7b75..70f84a5138 100644 --- a/tests/startup_packed_position_provenance_check.py +++ b/tests/startup_packed_position_provenance_check.py @@ -206,7 +206,7 @@ def refused(label, cache, key, reason): cache = Path(tmp) bare = G.pipeline_key(VS_WORDS, ps_words(4), root_blob()) check('without a description the key is unchanged', - bare == G.fnv(root_blob(), G.fnv(ps_words(4), G.fnv(VS_WORDS, G.fnv(b'x2w-startup-shader-29'))))) + bare == G.fnv(root_blob(), G.fnv(ps_words(4), G.fnv(VS_WORDS, G.fnv(b'x2w-startup-shader-30'))))) keys = [put_request(cache, ps_words(4), masks) for masks in (TARGET, SAME_V4, DECOY)] check('same stages, root and layout with three mask pairs: three request identities', len(set(keys)) == 3 and bare not in keys diff --git a/tests/startup_resource_retire_title.cpp b/tests/startup_resource_retire_title.cpp index 9645bda5f5..2fd7d31520 100644 --- a/tests/startup_resource_retire_title.cpp +++ b/tests/startup_resource_retire_title.cpp @@ -411,7 +411,7 @@ constexpr UINT draw_side = 4; // 4x4 R8G8B8A8_UNORM target constexpr UINT draw_covered = 3; // scissor leaves the last row and column untouched as the sentinel constexpr int draw_seed = 77; constexpr UINT draw_clear_pixel = 0xffff00ffu; // ClearRenderTargetView({1, 0, 1, 1}) in R8G8B8A8_UNORM -constexpr char draw_revision[] = "x2w-startup-shader-29"; // d3d12_draw.inl cached_translation +constexpr char draw_revision[] = "x2w-startup-shader-30"; // d3d12_draw.inl cached_translation constexpr char draw_vertex_shader[] = R"( struct Varying { float4 position : SV_Position; }; diff --git a/tests/startup_shader_cache_key_check.py b/tests/startup_shader_cache_key_check.py index 134cfccf96..9a42afd0ab 100644 --- a/tests/startup_shader_cache_key_check.py +++ b/tests/startup_shader_cache_key_check.py @@ -49,10 +49,10 @@ def check_request(blobs, key, diagnostic=None, rtv_request=None, layout=None): def main(): # Independently executed C++ runtime fnv_bytes/cached_translation known-answer vector. - # Revision x2w-startup-shader-29 excludes NUL. Stored order is a, b, root, then optional input layout. + # Revision x2w-startup-shader-30 excludes NUL. Stored order is a, b, root, then optional input layout. vector = (b"\x00VS\xff", b"PS\x00\x80", b"RTS0\x00") - assert gfx2hlsl.pipeline_key(*vector) == 0xa837b162afd547ce - assert gfx2hlsl.pipeline_key(*vector, b"ia\x00\xfe") == 0x6d5c0b7786182e0e + assert gfx2hlsl.pipeline_key(*vector) == 0x1fe778b573d7abcc + assert gfx2hlsl.pipeline_key(*vector, b"ia\x00\xfe") == 0x83948f5054751730 blobs = (VERTEX, PIXEL, ROOT) canonical = gfx2hlsl.pipeline_key(*blobs) check_request(blobs, canonical) diff --git a/tests/startup_ui_texture_bands_check.cpp b/tests/startup_ui_texture_bands_check.cpp index 789ddc687d..34c3fabb87 100644 --- a/tests/startup_ui_texture_bands_check.cpp +++ b/tests/startup_ui_texture_bands_check.cpp @@ -84,7 +84,7 @@ std::uint64_t fnv_bytes(const void* data, std::size_t bytes, std::uint64_t hash std::uint64_t shader_key(const void* vs, std::size_t vs_bytes, const void* ps, std::size_t ps_bytes, const void* root, std::size_t root_bytes) { - constexpr char rev[] = "x2w-startup-shader-29"; + constexpr char rev[] = "x2w-startup-shader-30"; auto h = fnv_bytes(rev, sizeof(rev) - 1); h = fnv_bytes(vs, vs_bytes, h); h = fnv_bytes(ps, ps_bytes, h); diff --git a/tools/patch_manifest.py b/tools/patch_manifest.py index a9d0f07d32..22f3f4b2c5 100644 --- a/tools/patch_manifest.py +++ b/tools/patch_manifest.py @@ -21,7 +21,7 @@ remove_when = "" key = "0123456789abcdef" # the cache key, 16 lowercase hex digits pipeline = "compute" # graphics, compute or mesh86 - revision = "x2w-startup-shader-29cs" + revision = "x2w-startup-shader-30cs" files = [{ ext = ".txt", file = "s001.txt", sha256 = "" }, { ext = ".cs.cso", file = "s001.cs.cso", sha256 = "" }] diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index d9155a3a9f..69ddb3d88b 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -12970,7 +12970,7 @@ def pipeline_key(vs_code, ps_code, root_blob, layout=b'', ps_inputs=None): SPI_PS_INPUT_ENA and SPI_PS_INPUT_ADDR as little-endian u32. Two pipelines with the same stages, root signature and input layout but different masks are then two requests with their own results. Without a description the key is unchanged.""" - key = fnv(root_blob, fnv(ps_code, fnv(vs_code, fnv(b'x2w-startup-shader-29')))) + key = fnv(root_blob, fnv(ps_code, fnv(vs_code, fnv(b'x2w-startup-shader-30')))) key = fnv(layout, key) if layout else key return key if ps_inputs is None else fnv(b'psin1' + struct.pack(' Date: Mon, 30 Nov 2026 14:54:16 +0100 Subject: [PATCH 3/4] test: update slot 57 cache keys for revision 30 --- docs/experiments/patch-manifests.md | 2 +- tests/startup_gfx2hlsl_ps57in_check.py | 2 +- tests/startup_shader_cache_key_check.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/experiments/patch-manifests.md b/docs/experiments/patch-manifests.md index c57ad2cd02..4644b6a65e 100644 --- a/docs/experiments/patch-manifests.md +++ b/docs/experiments/patch-manifests.md @@ -100,7 +100,7 @@ The check builds a synthetic PE32+ at run time with `build_pe32_plus` from | Span check off by one (`>=`) | The 1-byte case at `0xffffffff` is refused. | | `load_data` compares the target with itself | The flipped image is accepted by `load_data`. | | Revision form check removed | The other-pipeline, number-less and leading-zero revision cases are accepted. | - | The runtime's graphics revision gets a suffix (`x2w-startup-shader-29b`) | The revision-form pin fails for graphics. | + | The runtime's graphics revision gets a suffix (`x2w-startup-shader-30b`) | The revision-form pin fails for graphics. | | The runtime's graphics revision is bumped (`-29` to `-30`), loader untouched | Control: the check stays green. | | Bare-name check on `file` removed | The six non-bare `file` cases are accepted. | | Check for `<>"\|?*` in `file` removed | The six cases with one of those characters are accepted. | diff --git a/tests/startup_gfx2hlsl_ps57in_check.py b/tests/startup_gfx2hlsl_ps57in_check.py index 2d2f1a03e0..c2e829429e 100644 --- a/tests/startup_gfx2hlsl_ps57in_check.py +++ b/tests/startup_gfx2hlsl_ps57in_check.py @@ -86,7 +86,7 @@ def hlsl_bytes(directory, key, stage): # The suffixed key is the plain key hashed with the entry bytes, in runtime order, and nothing else. -key_parts = G.fnv(b'x2w-startup-shader-29') +key_parts = G.fnv(b'x2w-startup-shader-30') for part in (VS, PS, ROOT_BLOB, ENTRY): key_parts = G.fnv(part, key_parts) expect('suffixed key hashes the entry after the plain key', KEY, key_parts) diff --git a/tests/startup_shader_cache_key_check.py b/tests/startup_shader_cache_key_check.py index 3bdf4b13f9..7237c14b17 100644 --- a/tests/startup_shader_cache_key_check.py +++ b/tests/startup_shader_cache_key_check.py @@ -55,8 +55,8 @@ def check_slot57_entry(vector, blobs, canonical): # built and run separately: the record's 12 bytes follow the optional .ia bytes with no tag or length, as # the runtime's cached_translation hashes them. entry = b"PSI1" + struct.pack(" Date: Mon, 30 Nov 2026 17:28:15 +0100 Subject: [PATCH 4/4] test: verify format 47 cache invalidation --- docs/experiments.md | 2 +- tests/startup_shader_cache_rekey_check.py | 27 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/docs/experiments.md b/docs/experiments.md index 08c315b3fa..f333f617f7 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -635,7 +635,7 @@ The draw is refused, not read as zeros, whenever a translated formatted load has Each refusal logs `srv : formatted buffer refused ( )` for the first 6 occurrences and counts as `formatted-load draws refused` in the `x2w-render totals` line. Because the shader reads the raw copy at `vindex * stride`, the alignment of the upload ring does not constrain 12-byte formats. -`startup_buffer_format_word3_table` checks that the DXGI table equals `DESC_FORMAT_CODES`, agrees with `FETCH_DXGI` and with `formatted_buffer_supported()`; a header that gives `R32G32B32A32_FLOAT` code 74 must fail it. `startup_buffer_format_word3` checks words and refusal reasons, and its `mapping` control, which ignores the view mapping, must fail. `startup_formatted_view_draw_{warp,hardware}` draws one source-built pixel stage through the stand-in: `buffer_load_format_xyzw` with `idxen` of element 1 into an `R32G32B32A32_FLOAT` target, compared as four 32-bit words with distinct sentinels per channel. One translation serves every view: +`startup_buffer_format_word3_table` checks that the DXGI table agrees with `FETCH_DXGI`, maps to `DESC_FORMAT_CODES` and is accepted by `formatted_buffer_supported()`; descriptor-only format 47 has no DXGI entry; a header that gives `R32G32B32A32_FLOAT` code 74 must fail it. `startup_buffer_format_word3` checks words and refusal reasons, and its `mapping` control, which ignores the view mapping, must fail. `startup_formatted_view_draw_{warp,hardware}` draws one source-built pixel stage through the stand-in: `buffer_load_format_xyzw` with `idxen` of element 1 into an `R32G32B32A32_FLOAT` target, compared as four 32-bit words with distinct sentinels per channel. One translation serves every view: - `R32G32B32A32_FLOAT` and `R16G16B16A16_FLOAT`; - `R16G16_FLOAT`, whose z and w must be the defaults 0 and 1.0; diff --git a/tests/startup_shader_cache_rekey_check.py b/tests/startup_shader_cache_rekey_check.py index 978639b909..acc770f41d 100644 --- a/tests/startup_shader_cache_rekey_check.py +++ b/tests/startup_shader_cache_rekey_check.py @@ -26,6 +26,7 @@ import subprocess import sys import tempfile +from unittest.mock import patch ROOT = Path(__file__).resolve().parents[1] STARTUP = ROOT / 'tools' / 'startup' @@ -137,7 +138,33 @@ def contents(directory): return {p.name: p.read_bytes() for p in sorted(directory.iterdir())} +def check_pre_format47_cache(): + # Revision 29 predates FORMAT 47. A completed result must not hide the same + # pipeline requested under the current graphics or compute revision. + graphics_parts = graphics(1) + old_graphics = G.fnv(graphics_parts['.root'], G.fnv(graphics_parts['.b'], + G.fnv(graphics_parts['.a'], G.fnv(b'x2w-startup-shader-29')))) + old_compute = G.fnv(b'x2w-startup-shader-29cs') + for ext in ('.c67', '.data', '.root', '.desc', '.sa', '.sb'): + part = COMPUTE[ext] + old_compute = G.fnv(part, G.fnv(struct.pack('