From a9fc952f97b7944dc71b700fc1bb2ae3b3998479 Mon Sep 17 00:00:00 2001 From: Jess-Doit Date: Wed, 25 Nov 2026 08:10:40 -0800 Subject: [PATCH] shader: preserve signed zero in floating-point min and max Both translators resolve a pair of zeros from the sign bits (maximum ANDs the signs, minimum ORs them), following the RDNA 2 V_MIN/V_MAX clauses. The startup shader cache revisions advance from 14 to 15 and 15cs. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/windows.yml | 2 + AGENTS.md | 1 + CMakeLists.txt | 8 + docs/experiments.md | 32 ++ docs/startup-runtime.md | 9 +- src/startup_stubs/d3d12_draw.inl | 6 +- tests/pixel_aot_check.py | 13 +- tests/shader_signed_zero_minmax_check.py | 276 ++++++++++++++++++ .../startup_compute_request_offline_check.py | 4 +- tests/startup_gfx2hlsl_buffer_store_check.py | 4 +- tests/startup_gfx2hlsl_f32_med3_check.py | 6 +- tests/startup_gfx2hlsl_fract_check.py | 6 +- tests/startup_gfx2hlsl_root_check.py | 8 +- tests/startup_indirect_draw_indexed.cpp | 2 +- tests/startup_resource_retire_title.cpp | 2 +- tests/startup_shader_cache_key_check.py | 6 +- tools/pixel_aot.py | 29 +- tools/shader_minmax.py | 18 ++ tools/startup/gfx2hlsl.py | 22 +- 19 files changed, 404 insertions(+), 50 deletions(-) create mode 100644 tests/shader_signed_zero_minmax_check.py create mode 100644 tools/shader_minmax.py diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index eec590bdfc..ea3515acae 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -117,6 +117,7 @@ jobs: (["tests/startup_gfx2hlsl_interp_p2_hi_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_gfx2hlsl_sgpr_spill_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_gfx2hlsl_mad_check.py", "binary", "llvm-mc-15"], {}), + (["tests/shader_signed_zero_minmax_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_gfx2hlsl_compute_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_compute_lds_b64_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_compute_lds_b128_check.py", "binary", "llvm-mc-15"], {}), @@ -283,6 +284,7 @@ jobs: tests/startup_gfx2hlsl_sgpr_spill_check.py \ tests/startup_gfx2hlsl_mad_check.py \ tests/startup_gfx2hlsl_neg_check.py \ + tests/shader_signed_zero_minmax_check.py \ tests/startup_gfx2hlsl_compute_check.py \ tests/startup_compute_lds_b64_check.py \ tests/startup_compute_lds_b128_check.py \ diff --git a/AGENTS.md b/AGENTS.md index f17a5c5dc8..568c7000f2 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -167,6 +167,7 @@ python3 -m venv out/pe-env ./out/pe-env/bin/python -B tests/startup_gfx2hlsl_mad_check.py ./out/pe-env/bin/python -B tests/startup_gfx2hlsl_neg_check.py ./out/pe-env/bin/python -B tests/startup_gfx2hlsl_interp_p2_hi_check.py +./out/pe-env/bin/python -B tests/shader_signed_zero_minmax_check.py ./out/pe-env/bin/python -B tests/startup_gfx2hlsl_compute_check.py ./out/pe-env/bin/python -B tests/startup_compute_image_store_check.py ./out/pe-env/bin/python -B tests/startup_compute_image_store_d16_check.py diff --git a/CMakeLists.txt b/CMakeLists.txt index d7c5d52dc8..bf33e1766a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3663,6 +3663,14 @@ if(EXISTS "${INTAKE_PYTHON}") endforeach() add_test(NAME startup_gfx2hlsl_mad_controls COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_mad_check.py") + add_test(NAME shader_signed_zero_minmax_controls COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/shader_signed_zero_minmax_check.py") + foreach(adapter IN ITEMS warp hardware) + add_test(NAME shader_signed_zero_minmax_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/shader_signed_zero_minmax_check.py" draw "${DXC_EXECUTABLE}" + "$" ${adapter} $<$:${STARTUP_FXC}>) + set_tests_properties(shader_signed_zero_minmax_${adapter} PROPERTIES TIMEOUT 240 SKIP_RETURN_CODE 77) + endforeach() foreach(adapter IN ITEMS warp hardware) add_test(NAME startup_gfx2hlsl_mad_dispatch_${adapter} COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_mad_check.py" dispatch "${DXC_EXECUTABLE}" diff --git a/docs/experiments.md b/docs/experiments.md index 788af30db1..11535eb843 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -7554,6 +7554,38 @@ cmake --build --preset dev --target offscreen_check ctest --preset dev --no-tests=error -R '^compute_to_pixel_(warp|hardware)$' -V ``` +## Signed zero in floating-point min and max + +The RDNA 2 ISA defines `-0 < +0` for `V_MIN_F32`, `V_MAX_F32`, `V_MIN_F16` +and `V_MAX_F16` (§12.7, pp. 132–133 and 136). Its three-input min and max +compose these operations (§12.12, p. 170), and its packed instructions apply +min or max to each half (§12.10, p. 164). The median description specifies a +median without a separate mixed-zero rule. The fixture uses the same signed-zero +ordering for the median. DXIL FMin and FMax permit either operand when their +values compare equal. [AMD RDNA 2 ISA](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content), [DXIL operation reference](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#fmax) + +Both translators now resolve a pair of zeros from the sign bits. Maximum ANDs +the signs and minimum ORs them. The startup shader cache revision advances to +`x2w-startup-shader-18`, so translations cached before the change are not reused. The pixel translator applies the same rule to +each widened half for packed binary16 min and max. It retains the packed NaN +selection and the existing output modifiers. The startup translator retains +its own median NaN behavior. Scalar binary16 min/max, three-input binary16 +forms and startup SDWA min/max remain outside the supported instruction set. + +On Windows 10 (10.0.19045.6456), the in-box WARP baseline (10.0.19041.5794) +returned `00000000` for `(-0, +0)` and `80000000` for `(+0, -0)` for both +two-input operations. Three-input and packed results also varied with operand +order. WARP differed from the reference on 50 of 252 result words. The GTX 1060 +(32.0.15.6094) already matched all 252. With the helper, both adapters matched +all words, including single quiet NaN inputs and binary16 packed results. +The draws use DXC for the offline pixel path and DXC and FXC for the startup +path. These comparisons cover desktop results. Median and packed tie behavior +on console hardware, signaling NaNs and NaN payload propagation were unmeasured. + +Run `ctest --preset dev --no-tests=error -R '^shader_signed_zero_minmax_' -V`. +The Python test pins each emitted lowering and the LLVM 15 check reassembles +the source-built instructions. + ## Offline pixel shader recompilation The 64-bit scalar set and clear forms are s_bitset0_b64 and s_bitset1_b64. diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 1353b96e3f..2b0bab7df6 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -204,10 +204,11 @@ The translation is refused when: - either header has another size; - the code reads an attribute the table does not list. -The shader cache revision is `x2w-startup-shader-17`. Earlier translations lower `v_med3_f32` through a -branchless median, which returns the smaller of the other two operands when a source is NaN. The matching -compute (`x2w-startup-shader-17cs`) and fixed slot 57 mesh (`x2w-startup-mesh-57-2`) keys advance -because those stages use the shared lowering. +The shader cache revision is `x2w-startup-shader-18`. Revision 18 preserves the sign of zero in +floating-point min, max, min3, max3 and med3. The matching compute (`x2w-startup-shader-18cs`) and fixed +slot 57 mesh (`x2w-startup-mesh-57-3`) keys advance because those stages use the shared lowering. +Revisions before 17 lower `v_med3_f32` through a branchless median, which returns the smaller of the +other two operands when a source is NaN. Revisions before 16 lower `v_fract_f32` through a bare `frac` instead of the clamped `fract32` helper. Revisions before 15 lower `v_cvt_pk_u8_f32` with a float clamp and accept `s_setreg_imm32_b32` writes of the rounding mode. diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index 16aa47bd07..9952d6cebc 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -244,7 +244,7 @@ Translation* cached_translation(const void* a, std::size_t a_bytes, const void* { // Keep pre-fix desktop bytecode and manifests out of this ABI's cache. // tools/startup/gfx2hlsl.py hashes the same bytes, without a trailing NUL. - constexpr char revision[] = "x2w-startup-shader-17"; + constexpr char revision[] = "x2w-startup-shader-18"; const u64 seed = fnv_bytes(revision, sizeof(revision) - 1); u64 key = fnv_bytes(root_blob.data(), root_blob.size(), fnv_bytes(b, b_bytes, fnv_bytes(a, a_bytes, seed))); // A stream's input layout (stream_input_layout) feeds the vertex fetch, so it is part of the key. @@ -364,7 +364,7 @@ void publish_compute_request(const void* desc) std::vector fields(sizeof(words)); words[0] = words[1] = words[3] = words[5] = words[7] = words[9] = words[10] = 0; std::memcpy(fields.data(), words, sizeof(words)); - constexpr char compute_revision[] = "x2w-startup-shader-17cs"; // tools/startup/gfx2hlsl.py compute_key + constexpr char compute_revision[] = "x2w-startup-shader-18cs"; // tools/startup/gfx2hlsl.py compute_key u64 key = fnv_bytes(compute_revision, sizeof(compute_revision) - 1); const std::vector* order[] = {&code, &data, &root_blob, &fields, &state_a, &state_b}; for (const auto* part : order) key = fnv_part(*part, key); @@ -427,7 +427,7 @@ void request_slot57_mesh(Wrapper* pipeline, const std::vector* bo return copy_title_bytes(out.data(), pointer, out.size()); }; if (!copy_stage(13, true, mesh) || !copy_stage(5, false, pixel)) return; - constexpr char revision[] = "x2w-startup-mesh-57-2"; + constexpr char revision[] = "x2w-startup-mesh-57-3"; const u64 key = fnv_part(root_blob, fnv_part(pixel, fnv_part(mesh, fnv_bytes(revision, sizeof(revision) - 1)))); static SRWLOCK request_lock = SRWLOCK_INIT; static std::unordered_set written; diff --git a/tests/pixel_aot_check.py b/tests/pixel_aot_check.py index 2c10983562..8134328498 100644 --- a/tests/pixel_aot_check.py +++ b/tests/pixel_aot_check.py @@ -8764,7 +8764,8 @@ def check_literal_fma_draw(directory, compiler, renderer, backend): def check_scalar_pair_reads() -> None: program = with_scalar_pair_reads() source = translate(program) - for field in ("(params[0].w * sample", "max(params[15].z, ", "(params[1].x + sample", "(params[1].y - sample", + for field in ("(params[0].w * sample", "minmax_zero32(params[15].z, alu22, true)", + "(params[1].x + sample", "(params[1].y - sample", "= params[1].z;", "(params[15].w * alu"): assert field in source, field @@ -9816,9 +9817,11 @@ def three_way_case(directory, low, high, cap, middle, *, name="three_way.case"): def check_three_way_templates(): """The HLSL forms must pick the expected operand for every operand order, NaN operands included.""" names = {"min": min_num, "max": max_num, "asuint": lambda x: struct.unpack(" (0x[0-9a-f]+)u \? (.+) : (.+);\n\}") + r" return top > (0x[0-9a-f]+)u\n \? (.+)\n : (.+);\n\}") for top, limit, nan_form, finite_form in re.findall(helper, pixel_aot.PREAMBLE, re.M): top = re.sub(r"(0x[0-9a-f]+)u\b", r"\1", top) names["med3_32"] = lambda a, b, c: eval( @@ -18904,9 +18907,9 @@ def _check_controls_inline(directory): must_reject(translate, [line.replace(old, new) for line in shaping()]) source = translate(three_way()) for expected in ("med3_32(params[1].z, sample16.y, sample16.x)", - "max(max(sample16.x, sample16.z), sample16.y)", + "minmax_zero32(minmax_zero32(sample16.x, sample16.z, true), sample16.y, true)", "med3_32(sample16.x, params[0].w, params[1].x)", - "min(min(abs(params[1].y), sample16.y), alu"): + "minmax_zero32(minmax_zero32(abs(params[1].y), sample16.y, false), alu22, false)"): assert expected in source, expected for old, new in (("v_med3_f32 v12, v12, s44, s45", "v_med3_f32 v12, v12, s44"), ("v_med3_f32 v15, s47", "v_med3_i32 v15, |s47|"), @@ -24162,7 +24165,7 @@ def check_three_way_draw(directory, compiler, renderer, backend): run_pixel_batch(renderer, backend, shader, cases) # Desktop min and max alone skip a NaN operand instead of taking V_MIN3_F32 of the rest. text = source.read_text(encoding="ascii") - nan_ignored = text.replace("? min(min(a, b), c) :", "? max(min(a, b), min(max(a, b), c)) :") + nan_ignored = text.replace("return top > 0x7f800000u", "return false") assert nan_ignored != text source.write_text(nan_ignored, encoding="ascii") compile_shader(compiler, source, shader) diff --git a/tests/shader_signed_zero_minmax_check.py b/tests/shader_signed_zero_minmax_check.py new file mode 100644 index 0000000000..035bc91fd5 --- /dev/null +++ b/tests/shader_signed_zero_minmax_check.py @@ -0,0 +1,276 @@ +"""Source-built gfx1013 min/max translation and pixel checks. + +No arguments checks the emitted HLSL. Binary mode verifies the encodings with +llvm-mc. The before, draw, plain and invert modes take DXC, offscreen_check, +the adapter name and optionally FXC. +""" + +import math +import re +import struct +import subprocess +import sys +import tempfile +from pathlib import Path + +from startup_gfx2hlsl_bit_alu_check import G, POST_SOURCE, POST_WORDS, PRE_SOURCE, PRE_WORDS, vs_source, vs_words +from startup_flat_param_check import assemble, compile_hlsl, draw, root_blob + +import pixel_aot + +NEG_ZERO, POS_ZERO = 0x80000000, 0 +NEG_ONE, TWO, NAN = 0xbf800000, 0x40000000, 0x7fc01234 +CASE_TEXELS = 8 * 8 +DRAW_TEXELS = 64 * 64 +OPS = { + "min": ("v_min_f32_e32", 2), "max": ("v_max_f32_e32", 2), + "min-e64": ("v_min_f32_e64", 2), "max-e64": ("v_max_f32_e64", 2), + "min3": ("v_min3_f32", 3), "max3": ("v_max3_f32", 3), "med3": ("v_med3_f32", 3), + "min-sdwa": ("v_min_f32_sdwa", 2), "max-sdwa": ("v_max_f32_sdwa", 2), + "min-dpp": ("v_min_f32_dpp", 2), "max-dpp": ("v_max_f32_dpp", 2), + "min-pack": ("v_pk_min_f16", 2), "max-pack": ("v_pk_max_f16", 2), +} +STARTUP_OPS = ("min", "max", "min-e64", "max-e64", "min3", "max3", "med3") +BODY_WORDS = { + "min": "0009181e010b1a1e020d1c1e030f1e1e", + "max": "00091820010b1a20020d1c20030f1e20", + "min-e64": "0c000fd5000902000d000fd5010b02000e000fd5020d02000f000fd5030f0200", + "max-e64": "0c0010d5000902000d0010d5010b02000e0010d5020d02000f0010d5030f0200", + "min3": "0c0051d5000922040d0051d5010b26040e0051d5020d2a040f0051d5030f2e04", + "max3": "0c0054d5000922040d0054d5010b26040e0054d5020d2a040f0054d5030f2e04", + "med3": "0c0057d5000922040d0057d5010b26040e0057d5020d2a040f0057d5030f2e04", + "min-sdwa": "f908181e00060606f90a1a1e01060606f90c1c1e02060606f90e1e1e03060606", + "max-sdwa": "f908182000060606f90a1a2001060606f90c1c2002060606f90e1e2003060606", + "min-dpp": "fa08181e00e400fffa0a1a1e01e400fffa0c1c1e02e400fffa0e1e1e03e400ff", + "max-dpp": "fa08182000e400fffa0a1a2001e400fffa0c1c2002e400fffa0e1e2003e400ff", + "min-pack": "0c4011cc000902180d4011cc010b02180e4011cc020d02180f4011cc030f0218", + "max-pack": "0c4012cc000902180d4012cc010b02180e4012cc020d02180f4012cc030f0218", +} + +PIXEL_PREFIX = """s_mov_b32 s21, 0 +s_load_dwordx4 s[44:47], s[20:21], 0x40 +s_waitcnt lgkmcnt(0) +s_buffer_load_dwordx4 s[48:51], s[44:47], 0xc +s_buffer_load_dwordx4 s[52:55], s[44:47], 0x1c +s_buffer_load_dwordx4 s[56:59], s[44:47], 0x2c +s_waitcnt lgkmcnt(0) +""" + "".join(f"v_mov_b32_e32 v{i}, s{48 + i}\n" for i in range(12)) +PIXEL_PREFIX_WORDS = ( + "800395be0a0b08f4400000fa7fc08cbf160c28f40c0000fa160d28f41c0000fa" + "160e28f42c0000fa7fc08cbf3002007e3102027e3202047e3302067e3402087e" + "35020a7e36020c7e37020e7e3802107e3902127e3a02147e3b02167e" +) + + +def body_source(op): + mnemonic, arity = OPS[op] + mods = "" + if op.endswith("-sdwa"): + mods = " dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:DWORD src1_sel:DWORD" + if op.endswith("-dpp"): + mods = " quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf" + return "".join(f"{mnemonic} v{12 + lane}, " + + ", ".join(f"v{lane + 4 * arg}" for arg in range(arity)) + mods + "\n" + for lane in range(4)) + + +def draw_cases(op): + nz, pz = NEG_ZERO, POS_ZERO + if op.endswith("-pack"): + # Each word has distinct low and high halves. The first two lanes swap the packed operands. + return (((0x00008000, 0x80000000, 0), (0x80000000, 0x00008000, 0), + (0x80000000, 0x80000000, 0), (0x00008000, 0x00008000, 0)), + ((0x7e003c00, 0x4000fe00, 0), (0x4000fe00, 0x7e003c00, 0), + (0x3c00bc00, 0x40004000, 0), (0x40004000, 0x3c00bc00, 0))) + if OPS[op][1] == 2: + return (((nz, pz, 0), (pz, nz, 0), (nz, nz, 0), (pz, pz, 0)), + ((NAN, NEG_ONE, 0), (NEG_ONE, NAN, 0), (NAN, TWO, 0), (NEG_ONE, TWO, 0))) + return (((nz, pz, NEG_ONE), (pz, nz, NEG_ONE), (nz, pz, TWO), (pz, nz, TWO)), + ((nz, nz, pz), (pz, pz, nz), (nz, pz, pz), (pz, nz, nz)), + ((NAN, NEG_ONE, TWO), (NEG_ONE, NAN, TWO), (NEG_ONE, TWO, NAN), (NEG_ONE, pz, TWO))) + + +def value(bits, size): + return struct.unpack("> shift) & 0xffff for word in words[:2]] + return reference_word(op, selected, 16, kind) + return lane(0) | (lane(16) << 16) + return reference_word(op, words[:OPS[op][1]], 32, kind) + + +def reference_word(op, words, size, kind): + numeric = [word for word in words if not math.isnan(value(word, size))] + ordered_words = sorted(numeric, key=lambda word: ordered(word, size)) + if op.startswith("min"): + return ordered_words[0] + if op.startswith("max"): + return ordered_words[-1] + # A NaN source makes V_MED3_F32 return V_MIN3_F32 of the three: the smallest number (#2095). + if len(numeric) < len(words): + return ordered_words[0] + return ordered_words[1] + + +def pixel_hlsl(op): + code = bytes.fromhex(PIXEL_PREFIX_WORDS + BODY_WORDS[op]) + POST_WORDS + asm = [line for _, _, _, line in G.decode(code)] + return pixel_aot.lower(asm, 20, 24, None, constant_descriptor=64, integer_export=True) + + +def startup_pipeline(op, rows): + ps = PRE_WORDS + bytes.fromhex(BODY_WORDS[op]) + POST_WORDS + return G.Pipeline(vs_words(rows), ps, root_blob()) + + +def check_binary(llvm_mc): + assert assemble(llvm_mc, PIXEL_PREFIX).hex() == PIXEL_PREFIX_WORDS, "pixel constant-load prologue" + for op in OPS: + assert assemble(llvm_mc, body_source(op)).hex() == BODY_WORDS[op], op + if op in STARTUP_OPS: + for rows in draw_cases(op): + assert assemble(llvm_mc, vs_source(rows)) == vs_words(rows), op + assert assemble(llvm_mc, PRE_SOURCE + body_source(op) + POST_SOURCE) == ( + PRE_WORDS + bytes.fromhex(BODY_WORDS[op]) + POST_WORDS), op + print("All signed-zero fixtures match llvm-mc") + + +def check_lowering(kind, op, source): + assert "uint a_bits = asuint(a), b_bits = asuint(b);" in source + assert "uint either = a_bits | b_bits;" in source + assert "uint zero = maximum ? (a_bits & b_bits) : either;" in source + assert "return asfloat((either & 0x7fffffffu) == 0u ? zero :" in source + body = source[source.index(" main("):] + polarity = "true" if op.startswith("max") else "false" + if op.endswith("-pack"): + assert "isnan(a) ? b : (isnan(b) ? a : minmax_zero32(a, b, maximum))" in source + assert body.count("minmax16_num(") == body.count(", " + polarity + ")") == 8, (op, body) + elif op == "med3": + name = "med3_32" + assert body.count(name + "(") == 4, (kind, body) + start = source.index("float " + name + "(") + helper = source[start:source.index("\n}", start)] + assert helper.count("minmax_zero32(") == 6, helper + else: + count = 8 if OPS[op][1] == 3 else 4 + assert body.count("minmax_zero32(") == body.count(", " + polarity + ")") == count, (op, body) + + +def mutate(source, mode): + start = source.index("float minmax_zero32(") + end = source.index("\n}", start) + helper = source[start:end] + if mode == "plain": + replacement = helper.splitlines()[0] + "\n return maximum ? max(a, b) : min(a, b);" + else: + replacement = helper.replace("maximum ? (a_bits & b_bits) : either", + "maximum ? either : (a_bits & b_bits)") + assert replacement != helper + return source[:start] + replacement + source[end:] + + +def check_translation(): + for kind, ops in (("pixel", OPS), ("startup", STARTUP_OPS)): + for op in ops: + source = pixel_hlsl(op) if kind == "pixel" else startup_pipeline(op, draw_cases(op)[0]).hlsl_ps() + check_lowering(kind, op, source) + for mode in ("plain", "invert"): + try: + check_lowering(kind, op, mutate(source, mode)) + except AssertionError: + continue + raise AssertionError(f"{kind} {op} accepted the {mode} control") + print("20 signed-zero lowering checks reject both helper mutations") + + +def pixel_readback(renderer, backend, directory, shader, rows, expect): + # Existing integer-target case format, with three runtime uint4 operands from b0. + constants = [0] * 64 + for arg in range(3): + constants[3 + 4 * arg:7 + 4 * arg] = [row[arg] for row in rows] + case, raw = (directory / name for name in ("minmax.case", "minmax.bin")) + case.write_bytes(struct.pack("<64I", *constants) + struct.pack("<4I", *expect) * CASE_TEXELS + b"\x01") + raw.unlink(missing_ok=True) + run = subprocess.run([renderer, backend, "--check-pixel-case", str(shader), str(case), str(raw)], + capture_output=True, text=True) + return run, tuple(struct.iter_unpack("<4I", raw.read_bytes())) if raw.exists() else () + + +def startup_readback(renderer, backend, vs, ps, expect): + run = draw(renderer, backend, vs, ps, ",".join(f"{word:08x}" for word in expect)) + match = re.search(r"startup_flat_param words=([0-9a-f,]+)", run.stdout) + return run, (tuple(int(word, 16) for word in match[1].split(",")),) if match else () + + +def check_draw(mode, dxc, renderer, backend, fxc=None): + renderer = str(Path(renderer).resolve()) + sites = [("pixel", dxc, "dxc", "ps_6_2"), ("startup", dxc, "dxc", "ps_6_0")] + if fxc: + sites.append(("startup", fxc, "fxc", "ps_5_1")) + out = Path(__file__).resolve().parents[1] / "out" + out.mkdir(exist_ok=True) + mismatches = total = 0 + with tempfile.TemporaryDirectory(dir=out) as tmp: + directory = Path(tmp) + for kind, compiler, tool, profile in sites: + for op in OPS if kind == "pixel" else STARTUP_OPS: + cases = draw_cases(op) + source = pixel_hlsl(op) if kind == "pixel" else startup_pipeline(op, cases[0]).hlsl_ps() + if mode in ("plain", "invert"): + source = mutate(source, mode) + if kind == "pixel": + hlsl, shader = (directory / name for name in ("pixel.hlsl", "pixel.cso")) + hlsl.write_text(source, encoding="ascii") + subprocess.run([dxc, "-Gis", "-T", profile, "-E", "main", "-Fo", str(shader), str(hlsl)], + check=True) + else: + shader = compile_hlsl(compiler, tool, source, "pixel", profile, directory) + for index, rows in enumerate(cases): + expected = tuple(reference(op, row, kind) for row in rows) + if kind == "pixel": + run, raw = pixel_readback(renderer, backend, directory, shader, rows, expected) + else: + pipeline = startup_pipeline(op, rows) + vs = compile_hlsl(compiler, tool, pipeline.hlsl_vs(), "vertex", profile.replace("ps", "vs"), directory) + run, raw = startup_readback(renderer, backend, vs, shader, expected) + if run.returncode == 77: + print(run.stdout + run.stderr) + return 77 + pixel_count = DRAW_TEXELS if kind == "pixel" else 1 + if len(raw) != pixel_count: + raise AssertionError(f"{kind} {op}: expected {pixel_count} readback pixels, got {len(raw)}\n" + f"{run.stdout}\n{run.stderr}") + if (any(row != raw[0] for row in raw) or run.returncode not in (0, 1) + or ("debug_layer=enabled" in run.stdout and "debug_errors=0 debug_warnings=0" not in run.stdout)): + raise AssertionError(f"{kind} {op}: {run.stdout}\n{run.stderr}") + got = ",".join(f"{word:08x}" for word in raw[0]) + want = ",".join(f"{word:08x}" for word in expected) + print(f"{backend} {kind} {profile} {op} row {index}: {got} (expected {want})") + if bool(run.returncode) != (raw[0] != expected): + raise AssertionError(f"{kind} {op}: {run.stdout}\n{run.stderr}") + mismatches += sum(got != want for got, want in zip(raw[0], expected)) + total += len(expected) + print(f"{backend} {mode}: {mismatches}/{total} result words differ") + if mode == "invert" and not mismatches: + raise AssertionError("The inverted sign rule escaped detection") + return int(mode != "before" and mismatches != 0) + + +if __name__ == "__main__": + if len(sys.argv) == 3 and sys.argv[1] == "binary": + check_binary(sys.argv[2]) + elif len(sys.argv) in (5, 6) and sys.argv[1] in ("before", "draw", "plain", "invert"): + sys.exit(check_draw(*sys.argv[1:])) + elif len(sys.argv) == 1: + check_translation() + else: + sys.exit(__doc__) diff --git a/tests/startup_compute_request_offline_check.py b/tests/startup_compute_request_offline_check.py index f57f4b28c1..f2f0299a82 100644 --- a/tests/startup_compute_request_offline_check.py +++ b/tests/startup_compute_request_offline_check.py @@ -25,12 +25,12 @@ DESC = struct.pack('<12Q', 0, 0, 24, 0, 20, 0, len(CODE), 0, len(DATA), 0, 0, 11) STATE_A = struct.pack('<3Q', 1, 0x2c, 0xfff0000000000003) STATE_B = struct.pack('<5I', 0x1234abcd, 0xffff0000, 0, 0, 0) -KEY = 0x8421b8080fd0a5e6 # framed key at revision 17cs +KEY = 0x375fa7c3f8f4a3dd # framed key at revision 18cs def framed_key(): h = 1469598103934665603 - for b in b'x2w-startup-shader-17cs': + for b in b'x2w-startup-shader-18cs': h = ((h ^ b) * 1099511628211) & 0xffffffffffffffff for part in (CODE, DATA, ROOT, DESC, STATE_A, STATE_B): for b in struct.pack('` of `0x7f800000u` and - `min(min(a, b), c)` for the NaN branch; no line calls a `med3(` helper; + the signed-zero `minmax_zero32` min3 chain for the NaN branch; no line calls a `med3(` helper; - the binary32 table points `v_med3_f32` at `med3_32` and the integer forms are unchanged; - every lane of the fixture lowers to `U(med3_32(F(v1), F(v2), F(v3)))` reading s44..s47, which the entry constant buffer fills at draw time; @@ -87,7 +87,9 @@ MED3_32 = ('float med3_32(float a, float b, float c) {\n' ' uint top = max(max(asuint(a) & 0x7fffffffu, asuint(b) & 0x7fffffffu), asuint(c) & 0x7fffffffu);\n' - ' return top > 0x7f800000u ? min(min(a, b), c) : max(min(a, b), min(max(a, b), c));\n' + ' return top > 0x7f800000u\n' + ' ? minmax_zero32(minmax_zero32(a, b, false), c, false)\n' + ' : minmax_zero32(minmax_zero32(a, b, false), minmax_zero32(minmax_zero32(a, b, true), c, false), true);\n' '}') BRANCHLESS = 'float med3_32(float a, float b, float c) {\n return max(min(a, b), min(max(a, b), c));\n}' OLD_ISNAN = ('float med3_32(float a, float b, float c) {\n' diff --git a/tests/startup_gfx2hlsl_fract_check.py b/tests/startup_gfx2hlsl_fract_check.py index de05a5e1f4..9c568f6b18 100644 --- a/tests/startup_gfx2hlsl_fract_check.py +++ b/tests/startup_gfx2hlsl_fract_check.py @@ -170,8 +170,8 @@ def float_capped(word): repr((seed and seed.group(1), literal and literal.group(1)))) check('the two literals are identical', seed and literal and seed.group(1) == literal.group(1), repr((seed and seed.group(1), literal and literal.group(1)))) -check('the revision is x2w-startup-shader-17, after the fix to the cap', - bool(seed and seed.group(1) == 'x2w-startup-shader-17'), repr(seed and seed.group(1))) +check('the revision is x2w-startup-shader-18, after the fix to the cap and the signed-zero min and max', + bool(seed and seed.group(1) == 'x2w-startup-shader-18'), repr(seed and seed.group(1))) def key_from_seed(word): @@ -183,7 +183,7 @@ def key_from_seed(word): check('pipeline_key hashes the seed the source spells', G.pipeline_key(b'vs', b'ps', b'root') == key_from_seed(seed.group(1)), '%016x vs %016x' % (G.pipeline_key(b'vs', b'ps', b'root'), key_from_seed(seed.group(1)))) - old, new = key_from_seed('x2w-startup-shader-16'), key_from_seed('x2w-startup-shader-17') + old, new = key_from_seed('x2w-startup-shader-16'), key_from_seed(seed.group(1)) check('the -16 seed produces a different key, so the pre-fix entries are out of the cache', old != new, '%016x vs %016x' % (old, new)) diff --git a/tests/startup_gfx2hlsl_root_check.py b/tests/startup_gfx2hlsl_root_check.py index 31413e53df..a32c5dbb19 100644 --- a/tests/startup_gfx2hlsl_root_check.py +++ b/tests/startup_gfx2hlsl_root_check.py @@ -51,7 +51,13 @@ def container(parts): def main(): table = gfx2hlsl.parse_root(TABLE_ROOT)["params"] assert table == [dict(type=1, vis=0, reg=5, space=2, count=3)], table - vs, ps = code(12), code(0) + # --pending visits requests in key order, and every key hashes the cache revision. Pick the pixel + # export target (mrt0..mrt7) so that the valid request sorts after a bad one at the current revision. + vs = code(12) + for target in range(8): + ps = code(target) + if gfx2hlsl.pipeline_key(vs, ps, VALID_ROOT) > min(gfx2hlsl.pipeline_key(vs, ps, root) for root, _ in BAD.values()): + break with tempfile.TemporaryDirectory() as tmp: directory = Path(tmp) requests = {name: root for name, (root, _) in BAD.items()} diff --git a/tests/startup_indirect_draw_indexed.cpp b/tests/startup_indirect_draw_indexed.cpp index 234eb8c3b8..a4a7f568bd 100644 --- a/tests/startup_indirect_draw_indexed.cpp +++ b/tests/startup_indirect_draw_indexed.cpp @@ -295,7 +295,7 @@ ComPtr translated_pipeline(ID3D12Device* guest, ID3D12RootSignature* r bool needs_start, bool table_buffer = false, 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-17"; + constexpr char revision[] = "x2w-startup-shader-18"; static std::uint32_t vertex_ids[]{0xe0000101, 0xe0000102, 0xe0000103}; static std::uint32_t pixel_ids[]{0xe0000202, 0xe0000203, 0xe0000204}; auto& vertex_id = vertex_ids[indexed ? 2 : needs_start]; diff --git a/tests/startup_resource_retire_title.cpp b/tests/startup_resource_retire_title.cpp index fa6fbaf4c5..05f8f0a382 100644 --- a/tests/startup_resource_retire_title.cpp +++ b/tests/startup_resource_retire_title.cpp @@ -371,7 +371,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-17"; // d3d12_draw.inl cached_translation +constexpr char draw_revision[] = "x2w-startup-shader-18"; // 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 7a7d7218a4..8de3958200 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-17 excludes NUL. Stored order is a, b, root, then optional input layout. + # Revision x2w-startup-shader-18 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) == 0xd9521cd3fde79d61 - assert gfx2hlsl.pipeline_key(*vector, b"ia\x00\xfe") == 0xbaa2837ef61006ad + assert gfx2hlsl.pipeline_key(*vector) == 0x8d1cb58fb148b30a + assert gfx2hlsl.pipeline_key(*vector, b"ia\x00\xfe") == 0xf9e74efdcb8283d2 blobs = (VERTEX, PIXEL, ROOT) canonical = gfx2hlsl.pipeline_key(*blobs) check_request(blobs, canonical) diff --git a/tools/pixel_aot.py b/tools/pixel_aot.py index 20d01a27e9..287f928147 100644 --- a/tools/pixel_aot.py +++ b/tools/pixel_aot.py @@ -13,6 +13,7 @@ import zlib from resource_inventory import parts +from shader_minmax import FLOAT_MINMAX MESH_WAVE64 = b"+wavefrontsize64,-wavefrontsize32" @@ -445,7 +446,9 @@ def comparison_resources(state): // The NaN test is on the encoding, because some desktop compilers fold float NaN tests. float med3_32(float a, float b, float c) { uint top = max(max(asuint(a) & 0x7fffffffu, asuint(b) & 0x7fffffffu), asuint(c) & 0x7fffffffu); - return top > 0x7f800000u ? min(min(a, b), c) : max(min(a, b), min(max(a, b), c)); + return top > 0x7f800000u + ? minmax_zero32(minmax_zero32(a, b, false), c, false) + : minmax_zero32(minmax_zero32(a, b, false), minmax_zero32(minmax_zero32(a, b, true), c, false), true); } // v_fract_f32: x - floor(x) clamped to 0x3f7fffff, so a tiny negative input cannot round up to 1.0. // D3D frac has no clamp and differs between adapters. NaN fails the comparison and propagates. @@ -754,7 +757,7 @@ def vgpr_span(token, count): "rndne": (1, "round({0})"), # HLSL round is DXIL Round_ne: ties to even "sin": (1, "sin32({0})"), "cos": (1, "cos32({0})"), "add": (2, "({0} + {1})"), "mul": (2, "({0} * {1})"), - "max": (2, "max({0}, {1})"), "min": (2, "min({0}, {1})"), "sub": (2, "({0} - {1})"), + "max": (2, "minmax_zero32({0}, {1}, true)"), "min": (2, "minmax_zero32({0}, {1}, false)"), "sub": (2, "({0} - {1})"), "subrev": (2, "({1} - {0})"), "mul_legacy": (2, "(({0} == 0 || {1} == 0) ? 0.0f : {0} * {1})"), # Legacy multiply, then an unfused add: 0 * x is 0 even for an infinite or NaN x. @@ -764,7 +767,8 @@ def vgpr_span(token, count): "fma": (3, "mad({0}, {1}, {2})"), "fmac": (3, "mad({0}, {1}, {2})"), "mad": (3, "mad32({0}, {1}, {2})"), "mac": (3, "mad32({0}, {1}, {2})"), # Each result is one of the operands, so finite inputs need no rounding. - "min3": (3, "min(min({0}, {1}), {2})"), "max3": (3, "max(max({0}, {1}), {2})"), + "min3": (3, "minmax_zero32(minmax_zero32({0}, {1}, false), {2}, false)"), + "max3": (3, "minmax_zero32(minmax_zero32({0}, {1}, true), {2}, true)"), "med3": (3, "med3_32({0}, {1}, {2})"), } # LLVM 15 sets HasExtDPP = 0 for v_mac_legacy_f32, and fma, mad, mad_legacy, min3, max3 and med3 are VOP3-only, so @@ -1237,14 +1241,9 @@ def check_vopc_e32_dst(enc, dst): " return (res_sign << 15u) | sig;\n" "}" ), - "min16_num": ( - "float min16_num(float a, float b) {\n" - " return isnan(a) ? b : (isnan(b) ? a : min(a, b));\n" - "}" - ), - "max16_num": ( - "float max16_num(float a, float b) {\n" - " return isnan(a) ? b : (isnan(b) ? a : max(a, b));\n" + "minmax16_num": ( + "float minmax16_num(float a, float b, bool maximum) {\n" + " return isnan(a) ? b : (isnan(b) ? a : minmax_zero32(a, b, maximum));\n" "}" ), "dot_u64_add": ( @@ -1467,8 +1466,8 @@ def check_vopc_e32_dst(enc, dst): VOP3P_F16 = { "add": (2, "({0} + {1})"), "mul": (2, "({0} * {1})"), - "min": (2, "min16_num({0}, {1})"), - "max": (2, "max16_num({0}, {1})"), + "min": (2, "minmax16_num({0}, {1}, false)"), + "max": (2, "minmax16_num({0}, {1}, true)"), "fma": (3, "mad({0}, {1}, {2})"), } INLINE_F16 = { @@ -7211,7 +7210,7 @@ def sample_coord(reg): packed_lanes.append(f"pack16_rne({lvar})") helpers.add("pack16_rne") if op in ("min", "max"): - helpers.add(f"{op}16_num") + helpers.add("minmax16_num") vector[dst] = f"alu{i}" lines.append(f" precise float alu{i} = asfloat({packed_lanes[0]} | ({packed_lanes[1]} << 16));") elif m := match(r"v_cvt_u32_f32_e32 (v\d+), ([vs]\d+|0x[0-9a-f]{1,8})"): @@ -7882,7 +7881,7 @@ def sample_coord(reg): memory = TITLE_MEMORY + (TITLE_MEMORY_X2 if title_loads_x2 else "") memory += TITLE_MEMORY_X4 if title_loads_x4 else "" lines[:0] = [lookup, memory.format(slots=TITLE_ALIAS_SLOTS, count=title_ranges, miss=TITLE_MISS)] - source = "\n".join([*lines, "}", ""]) + source = "\n".join([FLOAT_MINMAX, *lines, "}", ""]) return (source, channel_mask) if return_write_mask else source diff --git a/tools/shader_minmax.py b/tools/shader_minmax.py new file mode 100644 index 0000000000..96880b7dfa --- /dev/null +++ b/tools/shader_minmax.py @@ -0,0 +1,18 @@ +"""HLSL shared by the gfx1013 pixel and startup translators.""" + +# RDNA 2 ISA section 12.7 settles both operand orders for signed zeros: +# V_MIN_F32: S0 = +0, S1 = -0 -> S1; S0 = -0, S1 = +0 -> S0 (min returns -0 if either operand is -0) +# V_MAX_F32: S0 = +0, S1 = -0 -> S0; S0 = -0, S1 = +0 -> S1 (max returns +0 when the zeros differ) +# Equal zeros take the general branch, so max(-0, -0) stays -0. For two zeros, the OR of the bit +# patterns gives the min result and the AND gives the max result, in either order. V_MIN3_F32, +# V_MAX3_F32 and V_MED3_F32 are defined through nested V_MIN_F32/V_MAX_F32, so chaining this helper +# applies the same rule. The emitted HLSL below is unchanged by this note. +FLOAT_MINMAX = """// RDNA 2 ISA section 12.7 orders -0 below +0 for min and max. +float minmax_zero32(float a, float b, bool maximum) { + uint a_bits = asuint(a), b_bits = asuint(b); + uint either = a_bits | b_bits; + uint zero = maximum ? (a_bits & b_bits) : either; + // Keep the selection integer so the compiler cannot merge the two float zeros. + return asfloat((either & 0x7fffffffu) == 0u ? zero : asuint(maximum ? max(a, b) : min(a, b))); +} +""" diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index 9e25a50954..c3283a0fb3 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -19,6 +19,7 @@ sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)), '..')) import disasm_rdna2 as D # noqa: E402 +from shader_minmax import FLOAT_MINMAX # noqa: E402 class Unsupported(Exception): @@ -6351,7 +6352,7 @@ def declarations(self): VEC_F = { 'v_add_f32': (2, '{0} + {1}'), 'v_sub_f32': (2, '{0} - {1}'), 'v_subrev_f32': (2, '{1} - {0}'), 'v_mul_f32': (2, '{0} * {1}'), 'v_mul_legacy_f32': (2, 'mul_legacy({0}, {1})'), - 'v_min_f32': (2, 'min({0}, {1})'), 'v_max_f32': (2, 'max({0}, {1})'), + 'v_min_f32': (2, 'minmax_zero32({0}, {1}, false)'), 'v_max_f32': (2, 'minmax_zero32({0}, {1}, true)'), 'v_fmac_f32': (2, '{0} * {1} + {2}'), 'v_mac_f32': (2, 'mad32({0}, {1}, {2}, false)'), 'v_fma_f32': (3, '{0} * {1} + {2}'), 'v_mad_f32': (3, 'mad32({0}, {1}, {2}, false)'), 'v_mad_legacy_f32': (3, 'mad32({0}, {1}, {2}, true)'), @@ -6361,7 +6362,9 @@ def declarations(self): 'v_exp_f32': (1, 'exp2({0})'), 'v_log_f32': (1, 'log2({0})'), 'v_floor_f32': (1, 'floor({0})'), 'v_ceil_f32': (1, 'ceil({0})'), 'v_trunc_f32': (1, 'trunc({0})'), 'v_fract_f32': (1, 'fract32({0})'), 'v_rndne_f32': (1, 'round({0})'), 'v_sin_f32': (1, 'sin({0} * 6.283185307)'), 'v_cos_f32': (1, 'cos({0} * 6.283185307)'), - 'v_med3_f32': (3, 'med3_32({0}, {1}, {2})'), 'v_min3_f32': (3, 'min({0}, min({1}, {2}))'), 'v_max3_f32': (3, 'max({0}, max({1}, {2}))'), + 'v_med3_f32': (3, 'med3_32({0}, {1}, {2})'), + 'v_min3_f32': (3, 'minmax_zero32({0}, minmax_zero32({1}, {2}, false), false)'), + 'v_max3_f32': (3, 'minmax_zero32({0}, minmax_zero32({1}, {2}, true), true)'), } # 16-bit VALU: (sources, source kind, float or uint expression of the sources, result kind). 'h' sources are # binary16 read from the low half and computed in binary32; an 'h' result is rounded back to binary16. The @@ -6721,7 +6724,7 @@ def sampler_lines(self): def common(self): import pixel_aot - out = ['#define F(x) asfloat(x)', '#define U(x) asuint(x)', + out = ['#define F(x) asfloat(x)', '#define U(x) asuint(x)', FLOAT_MINMAX, 'float mul_legacy(float a, float b) { return (a == 0.0 || b == 0.0) ? 0.0 : a * b; }', # Match pixel_aot: round the product before adding and flush denormals to signed zero. 'float ftz32(float value) {', @@ -6748,11 +6751,14 @@ def common(self): '}', # v_med3_f32 with a NaN source is the minimum of the three (ISA "343 V_MED3_F32"), so the test is # on the encoding: a float isnan() may be folded away by the compiler. D3D min() returns the - # other operand, so min(min(a, b), c) over a NaN source is the smallest of the non-NaN ones. + # other operand, so the min3 chain over a NaN source is the smallest of the non-NaN ones. min, max + # and med3 go through minmax_zero32, which orders -0 below +0 and passes a NaN to D3D min/max. # Same body as med3_32 in tools/pixel_aot.py. 'float med3_32(float a, float b, float c) {', ' uint top = max(max(asuint(a) & 0x7fffffffu, asuint(b) & 0x7fffffffu), asuint(c) & 0x7fffffffu);', - ' return top > 0x7f800000u ? min(min(a, b), c) : max(min(a, b), min(max(a, b), c));', + ' return top > 0x7f800000u', + ' ? minmax_zero32(minmax_zero32(a, b, false), c, false)', + ' : minmax_zero32(minmax_zero32(a, b, false), minmax_zero32(minmax_zero32(a, b, true), c, false), true);', '}', # High half of an unsigned 32x32 product, by halfword products so it fits 32-bit HLSL. 'uint mul_hi_u32(uint a, uint b) { uint la = a & 0xffffu, lb = b & 0xffffu;' @@ -7198,7 +7204,7 @@ def fnv(data, h=1469598103934665603): def pipeline_key(vs_code, ps_code, root_blob, layout=b''): """Hash the startup translation revision and the three blobs in runtime order, then a stream's input layout.""" - key = fnv(root_blob, fnv(ps_code, fnv(vs_code, fnv(b'x2w-startup-shader-17')))) + key = fnv(root_blob, fnv(ps_code, fnv(vs_code, fnv(b'x2w-startup-shader-18')))) return fnv(layout, key) if layout else key @@ -7207,7 +7213,7 @@ def compute_key(cs_code, data, root_blob, desc, state_a=b'', state_b=b''): graphics revision followed by "cs", then each part preceded by its length as a little-endian u64: the code, the words 7-8 blob, the root signature, the 12 description words with their pointers zeroed and the two state blocks.""" - key = fnv(b'x2w-startup-shader-17cs') + key = fnv(b'x2w-startup-shader-18cs') for part in (cs_code, data, root_blob, desc, state_a, state_b): key = fnv(part, fnv(struct.pack('