diff --git a/CMakeLists.txt b/CMakeLists.txt index b85216ccf6..16cbf609e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3520,6 +3520,21 @@ if(EXISTS "${INTAKE_PYTHON}") "$" ${adapter} $<$:${STARTUP_FXC}>) set_tests_properties(startup_gfx2hlsl_shift64_${adapter} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77) endforeach() + # gfx2hlsl v_fract_f32 goes through the clamped fract32 helper, never a bare D3D frac (#1741). + add_test(NAME startup_gfx2hlsl_fract COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_fract_check.py") + set_tests_properties(startup_gfx2hlsl_fract PROPERTIES TIMEOUT 60) + # The same cap drawn on one pixel with FXC 5_1 (where the float comparison it used to be written with + # folded away) and DXC 6_0; the uncapped pair must read 0x3f800000 on the -2^-30 lane. + add_test(NAME startup_gfx2hlsl_fract_draw_controls COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_fract_draw_check.py") + set_tests_properties(startup_gfx2hlsl_fract_draw_controls PROPERTIES TIMEOUT 60) + foreach(adapter IN ITEMS warp hardware) + add_test(NAME startup_gfx2hlsl_fract_draw_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_fract_draw_check.py" draw "${DXC_EXECUTABLE}" + "$" ${adapter} $<$:${STARTUP_FXC}>) + set_tests_properties(startup_gfx2hlsl_fract_draw_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) + endforeach() # gfx2hlsl signed 24-bit multiply/multiply-add (v_mul_i32_i24, v_mad_i32_i24): evaluator, refusals and draws. add_test(NAME startup_gfx2hlsl_mul_mad_i24_controls COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_mul_mad_i24_check.py") diff --git a/docs/experiments.md b/docs/experiments.md index f47b5d13d2..bb40fa3867 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -15073,6 +15073,28 @@ On an AMD Radeon RX 9070 XT (`1002:7550`, driver `32.0.32029.2010`) and on in-bo ```powershell cmake --build --preset dev --target offscreen_check ctest --preset dev --no-tests=error -R '^startup_range_provenance' -V + +## Startup v_fract_f32 upper bound + +`v_fract_f32` in `tools/startup/gfx2hlsl.py` now lowers through a `fract32` helper in the common preamble +instead of a bare D3D `frac`. The helper is `frac(value)` capped at `0x3f7fffff` by a comparison, +`f >= 1.0f ? asfloat(0x3f7fffffu) : f`, which is the form and the rule `tools/pixel_aot.py` has always used: +for an input such as -2^-30 (`0xb0800000`) the unclamped `x - floor(x)` rounds up to 1.0 in binary32, while the +instruction returns at most `0x3f7fffff`. The cap is not written with `min`, because D3D `min` returns its other +operand for a NaN and a NaN input has to stay a NaN. Two NVIDIA reports fail `startup_gfx2hlsl_float_round_hardware` +on that very input with `expected=...3f7fffff... actual=...3f800000...`: an RTX 3070 Ti on driver 32.0.16.2101 and +a Quadro M1000M (Maxwell) on driver 32.0.15.7371, both in #1741, while the same draw passes on WARP, on Intel HD +Graphics 530 and on the RDNA 4 card used here. That agreement is the reason the D3D `frac` was the deviating side, +not the fixture. No NVIDIA adapter is available on this machine, so the Maxwell and Turing results are **not** +reproduced here: what the change is verified against is the emitted text, the pixel_aot rule it now matches, and +the adapters that already returned `0x3f7fffff`. `tests/startup_gfx2hlsl_fract_check.py` asserts that the statement +of the `_e32` and `_e64` forms is `U(fract32(...))`, that no bare `frac(` reaches it, that the preamble clamps at +`0x3f7fffff` with the comparison form, and that the table entry is used by `v_fract_f32` alone. Two controls +rewrite the lowering to the uncapped `frac` and to a `min`-form cap and require the checks to reject both. Only +`v_fract_f32` changes in this patch. + +```powershell +ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_fract$' -V ``` ## Vulkan subnormal preservation in a pixel shader diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index d57babc3c6..0563c3aee5 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -204,10 +204,13 @@ 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-15`. Older translations evaluate `s_brev_b32` of a -constant at run time instead of folding it into a known word, which changes the emitted HLSL. +The shader cache revision is `x2w-startup-shader-16`. Earlier translations lower `v_fract_f32` +through a bare `frac` instead of the clamped `fract32` helper. The matching compute +(`x2w-startup-shader-16cs`) and fixed slot 57 mesh (`x2w-startup-mesh-57-2`) keys advance +because those stages use the shared lowering. Revisions before 15 lower `v_cvt_pk_u8_f32` with a float clamp and accept `s_setreg_imm32_b32` writes of the rounding mode. +Revisions before 14 evaluate constant `s_brev_b32` at run time instead of folding it into a known word. Revisions before 12 can overwrite the source mask when a save-EXEC instruction uses the same source and destination register. Earlier revisions can also carry a stale scalar symbol across a join, read a stale SCC after diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index 57cef51302..2eefa8e184 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-15"; + constexpr char revision[] = "x2w-startup-shader-16"; 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-15cs"; // tools/startup/gfx2hlsl.py compute_key + constexpr char compute_revision[] = "x2w-startup-shader-16cs"; // 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-1"; + constexpr char revision[] = "x2w-startup-mesh-57-2"; 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/startup_compute_request_offline_check.py b/tests/startup_compute_request_offline_check.py index 9d75bc94aa..30e6e3c372 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 = 0x9f56f9821d4b83e0 # compute_key of the parts above +KEY = 0x4db2818cb07558bf # framed key at revision 16cs def framed_key(): h = 1469598103934665603 - for b in b'x2w-startup-shader-15cs': + for b in b'x2w-startup-shader-16cs': h = ((h ^ b) * 1099511628211) & 0xffffffffffffffff for part in (CODE, DATA, ROOT, DESC, STATE_A, STATE_B): for b in struct.pack('= 1.0f ? ... : f`, did not survive FXC: it treats `frac` as strictly +below 1, folds that comparison to false and compiles the helper to a bare `frc`, so the cap disappeared on +exactly the adapters the fix was for. DXC keeps the compare and the select, which is why the pixel_aot +lowering, compiled by DXC only, never showed this. The cap is now a comparison on the BITS, +`asuint(f) == 0x3f800000u`, which FXC emits as `frc`, `ieq`, `movc`. `frac` can only reach the cap by +rounding to exactly +1.0, so the equality covers the case a `>=` comparison covered, and a NaN word misses +it and passes through. + +This check reads the emitted text only. It cannot reproduce the NVIDIA result: that needs one of those +adapters, and no such GPU is available here. What it pins is the lowering the adapters disagreed on, and +the shader cache revision that keeps the pre-fix entries out of the cache. +""" +import os +import re +import struct +import sys +from pathlib import Path + +here = os.path.dirname(os.path.abspath(__file__)) +root = Path(here).resolve().parent +sys.path.insert(0, os.path.join(here, '..', 'tools')) +sys.path.insert(0, os.path.join(here, '..', 'tools', 'startup')) +sys.path.insert(0, here) +import gfx2hlsl as G # noqa: E402 +from startup_gfx2hlsl_bit_alu_check import Probe # noqa: E402 + +BITS_FORM = 'asuint(f) == 0x3f800000u ? asfloat(0x3f7fffffu) : f' +FLOAT_FORM = 'f >= 1.0f ? asfloat(0x3f7fffffu) : f' +ONE = 0x3f800000 +CAP = 0x3f7fffff +failures = [] + + +def check(label, condition, detail=''): + print(f"{label}: {'ok' if condition else 'MISMATCH'}") + if not condition: + failures.append(label) + if detail: + print(' ' + detail) + + +def lower(line): + """The translated statement of one assembly line, as the caller sees it.""" + stage = Probe() + stage.one(line.split(' ', 1)[0], line) + return ' '.join(stage.lines) + + +HELPER = re.compile(r'float fract32\(float value\) \{.*?\}') +BARE_FRAC = re.compile(r'(?': word > ONE, '>=': word >= ONE}[test] + return CAP if fire else word + + +preamble = common() +match = HELPER.search(preamble) +check('the fract32 helper is emitted in the common preamble', match is not None, preamble[:240]) +helper = match.group(0) if match else '' +check('the helper is defined once', preamble.count('float fract32(') == 1, preamble[:240]) +source = Path(G.__file__).read_text(encoding='utf-8') +check('the helper carries the pixel_aot comment', + '# Match pixel_aot: x - floor(x) capped at 0x3f7fffff' in source) +check('the helper comment names FXC folding the float comparison', + 'FXC folds `frac(value) >= 1.0f` to false' in source) + +# 1. The table entry itself: one source, through the helper. +check('the VEC_F entry goes through fract32', G.VEC_F.get('v_fract_f32') == (1, 'fract32({0})'), + repr(G.VEC_F.get('v_fract_f32'))) +users = sorted(op for op, (_arity, text) in G.VEC_F.items() if 'fract32(' in text) +check('fract32 is used by v_fract_f32 alone and no other entry', users == ['v_fract_f32'], repr(users)) + +# 2. The emitted statement of each spelling, with the source modifiers the form accepts. +for line, expected in ( + ('v_fract_f32 v12, v0', 'v12 = U(fract32(F(v0)));'), + ('v_fract_f32 v0, v0', 'v0 = U(fract32(F(v0)));'), + ('v_fract_f32_e64 v13, |v1|', 'v13 = U(fract32(abs(F(v1))));'), + ('v_fract_f32_e64 v14, -|v2|', 'v14 = U(fract32((-abs(F(v2)))));'), +): + statement = lower(line) + found = problems(statement, helper) + check(f'{line} lowers through the clamp', not found, '%r: %s' % (statement, '; '.join(found))) + check(f'{line} emits the expected statement', statement == expected, statement) + +# 3. Negative controls: the checks above must reject the lowerings that caused the report and the ones that +# would let it come back. The same problem list is used, so the controls cannot drift from it. +uncapped = problems(lower('v_fract_f32 v12, v0').replace('fract32(', 'frac('), helper) +check('control: a bare frac is rejected', any('bare frac' in text for text in uncapped), repr(uncapped)) +capped_with_min = problems(lower('v_fract_f32 v12, v0'), helper.replace(BITS_FORM, + 'min(frac(value), asfloat(0x3f7fffffu))')) +check('control: a min-form clamp is rejected', bool(capped_with_min), repr(capped_with_min)) +raised_cap = problems(lower('v_fract_f32 v12, v0'), helper.replace('0x3f7fffffu', '0x3f800000u')) +check('control: a cap other than 0x3f7fffff is rejected', bool(raised_cap), repr(raised_cap)) +float_compare = problems(lower('v_fract_f32 v12, v0'), helper.replace(BITS_FORM, FLOAT_FORM)) +check('control: the float comparison FXC folds away is rejected', any('FXC folds' in text for text in float_compare), + repr(float_compare)) +strict = problems(lower('v_fract_f32 v12, v0'), helper.replace(BITS_FORM, BITS_FORM.replace('==', '>'))) +check('control: a strict > on the bits is rejected', bool(strict), repr(strict)) + +# What a strict > would do, evaluated on the words the helper can see. It misses the one case that occurs, +# because 1.0 is the value the cap is for, and it caps any NaN whose sign-and-exponent bits sort above 1.0. +check('the strict > misses 0x3f800000 and leaves 1.0, the word the report measured', + capped(ONE, '>') == ONE and capped(ONE, '==') == CAP, + '> reads %08x, == reads %08x' % (capped(ONE, '>'), capped(ONE, '=='))) +check('the strict > turns a NaN word above 1.0 into the cap, and the == form passes it', + capped(0x7fc00000, '>') == CAP and capped(0x7fc00000, '==') == 0x7fc00000, + '> reads %08x, == reads %08x' % (capped(0x7fc00000, '>'), capped(0x7fc00000, '=='))) +check('both comparisons leave a word below 1.0 alone', all(capped(w, t) == w for w in (0, CAP, 0x3f000000) + for t in ('==', '>'))) +def float_capped(word): + """The word the float comparison `frac(value) >= 1.0f` caps, read as a float: the rule the bits form keeps.""" + value = struct.unpack('= 1.0 else word + + +check('the bits equality caps the same words the float comparison does over the range frac returns', + all(capped(w, '==') == float_capped(w) for w in (0, 0x80000000, 0x3f000000, CAP, ONE, 0x7fc00000)), + repr([(hex(w), hex(capped(w, '==')), hex(float_capped(w))) + for w in (0, CAP, ONE, 0x7fc00000)])) +# Outside that range the bits form is narrower: it leaves 2.0 alone where the float form caps it. frac cannot +# return such a word, so this is the one place the two rules differ, and the narrower one hides nothing. +check('the bits form is narrower than the float form above 1.0, which frac cannot return', + capped(0x40000000, '==') == 0x40000000 and float_capped(0x40000000) == CAP, + 'bits %08x, float %08x' % (capped(0x40000000, '=='), float_capped(0x40000000))) + +# 4. The shader cache revision: both literals are the same word, and the old seed cannot produce the new key. +gfx_source = Path(G.__file__).read_text(encoding='utf-8') +seed = re.search(r"fnv\(b'(x2w-startup-shader-\d+)'\)", gfx_source) +stub_source = (root / 'src' / 'startup_stubs' / 'd3d12_draw.inl').read_text(encoding='utf-8') +literal = re.search(r'constexpr char revision\[\] = "(x2w-startup-shader-\d+)";', stub_source) +check('both files spell a x2w-startup-shader revision', seed is not None and literal is not None, + 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-16, after the fix to the cap', + bool(seed and seed.group(1) == 'x2w-startup-shader-16'), repr(seed and seed.group(1))) + + +def key_from_seed(word): + """pipeline_key's hash chain with one seed, over the same three blobs, without the layout.""" + return G.fnv(b'root', G.fnv(b'ps', G.fnv(b'vs', G.fnv(word.encode())))) + + +if seed: + 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-15'), key_from_seed('x2w-startup-shader-16') + check('the -15 seed produces a different key, so the pre-fix entries are out of the cache', old != new, + '%016x vs %016x' % (old, new)) + +if failures: + print('FAIL') + for text in failures: + print(' ' + text) + sys.exit(1) +print('PASS') diff --git a/tests/startup_gfx2hlsl_fract_draw_check.py b/tests/startup_gfx2hlsl_fract_draw_check.py new file mode 100644 index 0000000000..363a59df2f --- /dev/null +++ b/tests/startup_gfx2hlsl_fract_draw_check.py @@ -0,0 +1,205 @@ +"""`v_fract_f32` capped at 0x3f7fffff in a drawn pixel, with FXC and DXC (#1741). + + (no arguments) translation and arithmetic controls, pure Python + draw [fxc] + translate the fixture, compile with FXC vs_5_1/ps_5_1 (the --pending + path) when given and with DXC vs_6_0/ps_6_0, draw one pixel and compare + the four words + +The fixture is a source-built gfx1013 vertex and pixel pair. The vertex stage places a full-screen triangle +from the vertex index (v0) and exports four words to param0; the pixel stage reads them flat with +v_interp_mov_f32 p0, applies v_fract_f32 to each and exports them to mrt0. The words are 0xb0800000 +(-2^-30, the input the two NVIDIA reports fail on), 0x3fc00000 (1.5), 0x00000000 and 0xc0200000 (-2.5), +so the capped reading of the four lanes is 0x3f7fffff, 0x3f000000, 0x00000000 and 0x3f000000. Nothing here +reads game data: the words come from the vertex stage, so no compiler can fold them. + +The control that counts: the same pair with the lowering left uncapped, `U(frac(F(v)))`, must read a +different word in the first lane. For -2^-30 the unclamped x - floor(x) rounds up to exactly 1.0 in +binary32, `0x3f800000`, while the instruction returns at most `0x3f7fffff`. An adapter whose bare `frc` +already caps reads the capped word there: the test records that as a finding on that adapter instead of +failing, because on it the two forms cannot be separated by this draw. The other three lanes must read the +same word with and without the cap, which is what says the cap adds no rounding of its own. +""" +import math +import re +import struct +import subprocess +import sys +import tempfile +from pathlib import Path + +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE.parent / 'tools' / 'startup')) +sys.path.insert(0, str(HERE)) +import gfx2hlsl as G # noqa: E402 +from startup_gfx2hlsl_bit_alu_check import mov_literal # noqa: E402 +from startup_flat_param_check import VS_WORDS, compile_hlsl, draw, root_blob # noqa: E402 + +CAP = 0x3f7fffff +ONE = 0x3f800000 +INPUTS = (0xb0800000, 0x3fc00000, 0x00000000, 0xc0200000) +VS_EXPECTED = ('v_mov_b32_e32 v3, 0x40400000', 'v_mov_b32_e32 v10, 0xc0400000', + 'v_cmp_eq_u32_e32 vcc_lo, 1, v0', 'v_cndmask_b32_e32 v1, -1.0, v3, vcc_lo', + 'v_cmp_eq_u32_e32 vcc_lo, 2, v0', 'v_cndmask_b32_e32 v2, 1.0, v10, vcc_lo', + 'v_mov_b32_e32 v4, 1.0', 'v_mov_b32_e32 v5, 0', + 'v_mov_b32_e32 v6, 0xb0800000', 'v_mov_b32_e32 v7, 0x3fc00000', + 'v_mov_b32_e32 v8, 0', 'v_mov_b32_e32 v9, 0xc0200000', + 'exp pos0 v1, v2, v5, v4 done', 'exp param0 v6, v7, v8, v9', 's_endpgm') +PS_EXPECTED = ('s_mov_b32 m0, s2', + 'v_interp_mov_f32_e32 v0, p0, attr0.x', 'v_interp_mov_f32_e32 v1, p0, attr0.y', + 'v_interp_mov_f32_e32 v2, p0, attr0.z', 'v_interp_mov_f32_e32 v3, p0, attr0.w', + 'v_fract_f32_e32 v0, v0', 'v_fract_f32_e32 v1, v1', + 'v_fract_f32_e32 v2, v2', 'v_fract_f32_e32 v3, v3', + 'exp mrt0 v0, v1, v2, v3 done vm', 's_endpgm') +failures = [] + + +def check(label, condition, detail=''): + print(f"{label}: {'ok' if condition else 'MISMATCH'}") + if not condition: + failures.append(label) + if detail: + print(' ' + detail) + + +# The recorded words are built here rather than assembled: llvm-mc is not needed, and the controls read the +# decoded text back through gfx2hlsl.decode, which is the decoder the translator itself uses. +VS = (VS_WORDS[:40] # full-screen triangle, v3..v5 + + b''.join(mov_literal(6 + lane, word) for lane, word in enumerate(INPUTS)) + + bytes.fromhex('cf0800f801020504') # exp pos0 v1, v2, v5, v4 done + + struct.pack('<2I', 0xf800000f | 32 << 4, 0x09080706) # exp param0 v6, v7, v8, v9 + + bytes.fromhex('000081bf')) # s_endpgm + + +def vop1_e32(op, vdst, src0): + """VOP1 in the e32 encoding: src0 0..127 is an SGPR, 256+n is a VGPR (VGPR 0 is 0x100, not 0).""" + return struct.pack(' the cap: this adapter's own frac already stays below 1.0, so the draw cannot + # separate the two forms here. Recorded, not failed. + print(' recorded: %s %s uncapped pair reads the capped word %s, so this adapter clamps a bare ' + 'frc itself and the control cannot separate the two forms on it' % (kind, adapter, + EXPECTED_TEXT)) + else: + check('%s %s: the uncapped pair reads %s, not %s' % (kind, adapter, UNCAPPED_TEXT, EXPECTED_TEXT), + read == UNCAPPED, run.stdout + run.stderr) + + +def main(): + if len(sys.argv) == 1: + controls() + if failures: + print('FAIL') + for text in failures: + print(' ' + text) + sys.exit(1) + print('PASS') + return + mode, *args = sys.argv[1:] + if mode != 'draw': + raise SystemExit(__doc__) + controls() + check_draw(*args) + if failures: + print('FAIL') + for text in failures: + print(' ' + text) + sys.exit(1) + print('PASS') + + +if __name__ == '__main__': + main() diff --git a/tests/startup_indirect_draw_indexed.cpp b/tests/startup_indirect_draw_indexed.cpp index c0d23090cd..9fcfa7fb1e 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-15"; + constexpr char revision[] = "x2w-startup-shader-16"; 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 5270131e8a..0850645f78 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-15"; // d3d12_draw.inl cached_translation +constexpr char draw_revision[] = "x2w-startup-shader-16"; // d3d12_draw.inl cached_translation constexpr char draw_vertex_shader[] = R"( struct Varying { float4 position : SV_Position; }; diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index 74244559c5..1ab1ec6e5b 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -5435,7 +5435,7 @@ def declarations(self): 'v_madmk_f32': (3, 'mad32({0}, {1}, {2}, false)'), 'v_madak_f32': (3, 'mad32({0}, {1}, {2}, false)'), 'v_rcp_f32': (1, '1.0 / {0}'), 'v_rcp_iflag_f32': (1, '1.0 / {0}'), 'v_rsq_f32': (1, 'rsqrt({0})'), 'v_sqrt_f32': (1, 'sqrt({0})'), '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, 'frac({0})'), 'v_rndne_f32': (1, 'round({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({0}, {1}, {2})'), 'v_min3_f32': (3, 'min({0}, min({1}, {2}))'), 'v_max3_f32': (3, 'max({0}, max({1}, {2}))'), } @@ -5785,6 +5785,15 @@ def common(self): ' precise float sum = product + ftz32(c);', ' return ftz32(sum);', '}', + # Match pixel_aot: x - floor(x) capped at 0x3f7fffff, so a tiny negative input cannot round up to + # 1.0. The cap is a comparison, not min: min returns its other operand for a NaN. + # The comparison is on the bits because FXC folds `frac(value) >= 1.0f` to false and emits a bare + # frc for it, which loses the cap on an adapter whose frac returns 1.0. frac can only reach the cap + # by rounding to exactly +1.0, so the equality covers the same case, and a NaN misses it and passes. + 'float fract32(float value) {', + ' float f = frac(value);', + ' return asuint(f) == 0x3f800000u ? asfloat(0x3f7fffffu) : f;', + '}', 'float med3(float a, float b, float c) { return max(min(a, b), min(max(a, b), c)); }', # 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;' @@ -6131,7 +6140,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-15')))) + key = fnv(root_blob, fnv(ps_code, fnv(vs_code, fnv(b'x2w-startup-shader-16')))) return fnv(layout, key) if layout else key @@ -6140,7 +6149,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-15cs') + key = fnv(b'x2w-startup-shader-16cs') for part in (cs_code, data, root_blob, desc, state_a, state_b): key = fnv(part, fnv(struct.pack('