From f39a87dbe86277f94e7de7d1a14c26c771c14f3b Mon Sep 17 00:00:00 2001 From: Panam Date: Wed, 25 Nov 2026 01:02:18 +0100 Subject: [PATCH 1/5] startup: return the minimum of the three on v_med3_f32 with a NaN source --- CMakeLists.txt | 13 + docs/experiments.md | 62 ++++ tests/desktop_gpu.h | 3 + tests/offscreen_check.cpp | 42 +++ tests/startup_entry_words.cpp | 123 ++++++++ tests/startup_gfx2hlsl_f32_med3_check.py | 376 +++++++++++++++++++++++ tools/startup/gfx2hlsl.py | 11 +- 7 files changed, 628 insertions(+), 2 deletions(-) create mode 100644 tests/startup_entry_words.cpp create mode 100644 tests/startup_gfx2hlsl_f32_med3_check.py diff --git a/CMakeLists.txt b/CMakeLists.txt index 94a6e3fa99..f476961122 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1140,6 +1140,7 @@ foreach(mutation IN ITEMS sampler-alone bind-unrestorable) endforeach() target_sources(offscreen_check PRIVATE tests/startup_image_3d.cpp) target_sources(offscreen_check PRIVATE tests/startup_flat_param.cpp) +target_sources(offscreen_check PRIVATE tests/startup_entry_words.cpp) # The storage root handed to the executable ends in a separator and is never cut off # (src/startup_stubs/storage_root.h); the mutated run is the negative control. add_executable(startup_storage_root_check tests/startup_storage_root_check.cpp) @@ -2248,6 +2249,18 @@ if(EXISTS "${INTAKE_PYTHON}") # Startup shader translator: signed and unsigned three-source integer min, max and median. add_test(NAME startup_gfx2hlsl_int_med3_controls COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_int_med3_check.py") + # v_med3_f32 with a NaN source is the minimum of the three (ISA p. 343): the preamble's med3_32 tests the + # encoding, the integer medians are unchanged, and the old branchless helper must be rejected. + add_test(NAME startup_gfx2hlsl_f32_med3_controls COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_f32_med3_check.py") + # The same four words drawn on WARP and the card, the NaN among them from the entry constants; the + # branchless lowering must mismatch on that lane. + foreach(adapter IN ITEMS warp hardware) + add_test(NAME startup_gfx2hlsl_f32_med3_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_f32_med3_check.py" draw "${DXC_EXECUTABLE}" + "$" ${adapter} $<$:${STARTUP_FXC}>) + set_tests_properties(startup_gfx2hlsl_f32_med3_${adapter} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77) + endforeach() foreach(adapter IN ITEMS warp hardware) add_test(NAME startup_gfx2hlsl_cvt_alu_${adapter} COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_cvt_alu_check.py" draw "${DXC_EXECUTABLE}" diff --git a/docs/experiments.md b/docs/experiments.md index a285ff9067..9b99ae78fc 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -12041,4 +12041,66 @@ On Intel UHD Graphics (TGL GT1) with Mesa 26.2.7, DXC 1.10.2605.37 and SPIRV-Too python3 -B tests/pixel_denorm_vulkan_check.py /path/to/dxc tests/vk_pixel_draw.c --device Intel VK_DRIVER_FILES=/usr/share/vulkan/icd.d/lvp_icd.json \ python3 -B tests/pixel_denorm_vulkan_check.py /path/to/dxc tests/vk_pixel_draw.c --device llvmpipe +## v_med3_f32 with a NaN source + +The RDNA 2 ISA defines `V_MED3_F32` (p. "343 V_MED3_F32") as a NaN branch first: + +``` +if (isNan(S0.f) || isNan(S1.f) || isNan(S2.f)) + D.f = V_MIN3_F32(S0.f, S1.f, S2.f); +else if (V_MAX3_F32(S0.f, S1.f, S2.f) == S0.f) + D.f = V_MAX_F32(S1.f, S2.f); +... +``` + +A NaN source therefore makes the result the smallest of the three. `tools/startup/gfx2hlsl.py` lowered +`v_med3_f32` to `max(min(a, b), min(max(a, b), c))`, which returns the larger of the non-NaN sources instead. +Drawn with `med3(a, 2.0, 1.0)` on a Radeon RX 9070 XT (driver `32.0.32029.2010`): + +| `a` | emitted form | ISA rule | +|---|---|---| +| NaN (`0x7fc00000`) | 2.0 | **1.0** | +| 3.0 | 2.0 | 2.0 | +| 1.5 | 1.5 | 1.5 | +| 0.5 | 1.0 | 1.0 | + +The only divergence is the NaN source. The table now points `v_med3_f32` at `med3_32`, whose body is the one +`tools/pixel_aot.py` already uses: + +```hlsl +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)); +} +``` + +The NaN test is on the encoding rather than on `isnan()`, because some desktop compilers fold float NaN +tests, and `min(min(a, b), c)` over operands whose sources D3D's `min()` keeps gives the smallest non-NaN +source. The integer medians (`v_med3_u32`, `v_med3_i32`) are untouched: they compare words and have no NaN. + +What the measurement establishes and what it does not: the emitted form rendered 2.0 on the card for a NaN +operand, and the ISA rule is the lower of the non-NaN sources. That the hardware instruction itself computes +`V_MIN3_F32` on a NaN source is **not** established here: HLSL cannot emit `v_med3_f32` (the compiler does not +select it from the median pattern), so the fixture compares the translated text against the ISA rule, not +against the instruction. Reading the instruction directly needs a captured shader or the ISA simulator. + +`tests/startup_gfx2hlsl_f32_med3_check.py` holds the controls and the draw. The controls read the emitted +HLSL: the preamble carries `med3_32` with the `0x7f800000u` threshold and the `asuint(x) & 0x7fffffffu` test, +the binary32 table points at it, both the bare and the `_e64` spellings lower to it, and the integer medians +keep their own lowering. Four mutations are rejected: the branchless helper, a `>=` threshold, an `isnan(` +test and a table pointing back at a helper without the branch. The `decode` mode builds +`v_med3_f32 v12, v1, v2, v3` as `0c0057d501050e04` and proves it with `tools/disasm_rdna2.py`. + +The draw is a source-built gfx1013 pair whose pixel stage moves the four entry constants s8..s11 into +s44..s47 and applies `v_med3_f32 v(12+lane), v1, v2, v3` with `v2 = 2.0` and `v3 = 1.0`. The inputs arrive as +root 32-bit constants written per draw by `offscreen_check --startup-entry-words`, not as literals: a literal +would be folded at compile time and the lowering under test would never run. The four inputs are +`0x7fc00000`, `0x40400000`, `0x3fc00000` and `0x3f000000`; the expected words are `0x3f800000`, +`0x40000000`, `0x3fc00000` and `0x3f800000`. The control that counts restores the branchless helper in the +same pair and requires a mismatch on the NaN lane alone: `0x40000000` where the ISA asks `0x3f800000`, the +other three lanes unchanged. A negative control that passes is reported as a failure, not accepted. + +```powershell +cmake --build --preset dev --target offscreen_check +ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl_f32_med3' -V ``` diff --git a/tests/desktop_gpu.h b/tests/desktop_gpu.h index ec622933d3..0c7ab4fc0a 100644 --- a/tests/desktop_gpu.h +++ b/tests/desktop_gpu.h @@ -26,6 +26,9 @@ void check_startup_image_3d(ID3D12Device* device, const char* vertex_path, const bool one_dimensional = false, bool two_dimensional = false); void check_startup_flat_param(ID3D12Device* device, const char* vertex_path, const char* pixel_path, std::uint32_t* words, UINT width = 1, UINT height = 1); +void check_startup_entry_words(ID3D12Device* device, const char* vertex_path, const char* pixel_path, + const std::uint32_t* entry, UINT entry_count, std::uint32_t* words, + UINT width = 1, UINT height = 1); void dump_raw_uav(ID3D12Device* device, const char* shader_path, const char* groups, const char* bytes, const char* out_path); void check_spirv_window(ID3D12Device* device, const char* shader_path); diff --git a/tests/offscreen_check.cpp b/tests/offscreen_check.cpp index ca6ee27e4d..f2c72d7d7e 100644 --- a/tests/offscreen_check.cpp +++ b/tests/offscreen_check.cpp @@ -1307,6 +1307,47 @@ OperationResult run_startup_flat_param(const OperationContext& ctx) return {OutcomeKind::pass, nullptr}; } +// Comma-separated 8-digit hex words, in order. An empty list or any other shape returns nothing. +static std::vector parse_hex_words(std::string_view text) +{ + std::vector words; + while (!text.empty()) { + std::uint32_t value = 0; + const auto parsed = std::from_chars(text.data(), text.data() + text.size(), value, 16); + if (parsed.ec != std::errc{} || parsed.ptr == text.data()) return {}; + words.push_back(value); + text.remove_prefix(std::size_t(parsed.ptr - text.data())); + if (text.empty()) break; + if (text.front() != ',') return {}; + text.remove_prefix(1); + } + return words; +} + +// --startup-entry-words : draws one pixel with a gfx2hlsl +// vertex and pixel pair that reads its operands from the entry constant buffer (tests/startup_entry_words.cpp). +// is 1..32 comma-separated 8-digit hex words, ud0 first; the translated vertex stage reads ud0 +// as its rectangle-list switch, so a plain triangle fixture keeps it 0. is the four words the +// target must hold, compared bit for bit. +OperationResult run_startup_entry_words(const OperationContext& ctx) +{ + const auto entry = parse_hex_words(ctx.argv[5]); + const auto expected = parse_hex_words(ctx.argv[6]); + if (entry.empty() || entry.size() > 32) + return {OutcomeKind::fail, "entry constants are not 1..32 hex words"}; + if (expected.size() != 4) + return {OutcomeKind::fail, "expected value is not four hex words"}; + std::uint32_t words[4]{}; + check_startup_entry_words(ctx.device, ctx.argv[3], ctx.argv[4], entry.data(), UINT(entry.size()), words); + if (std::memcmp(words, expected.data(), sizeof(words)) != 0) { + std::fprintf(stderr, "startup_entry_words mismatch expected=%08x,%08x,%08x,%08x " + "actual=%08x,%08x,%08x,%08x\n", + expected[0], expected[1], expected[2], expected[3], words[0], words[1], words[2], words[3]); + return {OutcomeKind::fail, "entry constant readback differs"}; + } + return {OutcomeKind::pass, nullptr}; +} + constexpr CapabilityGate kNoGate{}; constexpr CapabilityGate kGateSm60BufferOps{ D3D_SHADER_MODEL_6_0, false, false, 0, @@ -1420,6 +1461,7 @@ const OperationSpec kOperations[] = { {"--startup-image-2d-array-mips", 7, 8, nullptr, kNoGate, run_startup_image_3d}, {"--startup-packed-position", 5, 5, nullptr, kNoGate, run_startup_packed_position}, {"--startup-flat-param", 6, 6, nullptr, kNoGate, run_startup_flat_param}, + {"--startup-entry-words", 7, 7, nullptr, kNoGate, run_startup_entry_words}, {"--startup-pixel-words", 8, 8, nullptr, kNoGate, run_startup_pixel_words}, // : whole raw UAV after one dispatch (#775 GVN parity). {"--raw-uav-dump", 7, 7, nullptr, kGateSm60RawUavDump, run_raw_uav_dump}, diff --git a/tests/startup_entry_words.cpp b/tests/startup_entry_words.cpp new file mode 100644 index 0000000000..229b686df0 --- /dev/null +++ b/tests/startup_entry_words.cpp @@ -0,0 +1,123 @@ +// Desktop readback with caller-supplied entry constants for tools/startup/gfx2hlsl.py (v_med3_f32, #2044). +// +// Draws one pixel with a translated vertex and pixel stage and returns the four 32-bit words of +// the colour. The entry constants (cbuffer entry : register(b0)) are visible to both stages, because +// the translated vertex stage reads ud0, the rectangle-list switch; every word comes from the caller, +// so a value under test is never a compile-time literal the shader compiler could fold. The target is +// R32G32B32A32_FLOAT, so the readback is the raw words the pixel stage exported. +#include "desktop_gpu.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +using Microsoft::WRL::ComPtr; + +namespace { + +std::vector read_blob(const char* path) +{ + std::ifstream file(path, std::ios::binary); + std::vector bytes((std::istreambuf_iterator(file)), std::istreambuf_iterator()); + if (!file.good() && !file.eof()) throw std::runtime_error(std::string("Cannot read ") + path); + if (bytes.empty()) throw std::runtime_error(std::string("Empty shader ") + path); + return bytes; +} +} // namespace + +void check_startup_entry_words(ID3D12Device* device, const char* vertex_path, const char* pixel_path, + const std::uint32_t* entry, UINT entry_count, std::uint32_t* words, + UINT width, UINT height) +{ + const auto vs = read_blob(vertex_path); + const auto ps = read_blob(pixel_path); + + D3D12_ROOT_PARAMETER param{}; + param.ParameterType = D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS; + param.Constants = {0, 0, entry_count}; + param.ShaderVisibility = D3D12_SHADER_VISIBILITY_ALL; + D3D12_ROOT_SIGNATURE_DESC rs{}; + rs.NumParameters = 1; + rs.pParameters = ¶m; + ComPtr signature, errors; + if (FAILED(D3D12SerializeRootSignature(&rs, D3D_ROOT_SIGNATURE_VERSION_1, &signature, &errors))) + throw std::runtime_error(errors ? static_cast(errors->GetBufferPointer()) + : "Serialize flat parameter root signature"); + ComPtr root; + check(device->CreateRootSignature(0, signature->GetBufferPointer(), signature->GetBufferSize(), IID_PPV_ARGS(&root)), + "Create flat parameter root signature"); + + D3D12_GRAPHICS_PIPELINE_STATE_DESC pd{}; + pd.pRootSignature = root.Get(); + pd.VS = {vs.data(), vs.size()}; + pd.PS = {ps.data(), ps.size()}; + pd.BlendState.RenderTarget[0].RenderTargetWriteMask = D3D12_COLOR_WRITE_ENABLE_ALL; + pd.SampleMask = UINT_MAX; + pd.RasterizerState.FillMode = D3D12_FILL_MODE_SOLID; + pd.RasterizerState.CullMode = D3D12_CULL_MODE_NONE; + pd.RasterizerState.DepthClipEnable = TRUE; + pd.PrimitiveTopologyType = D3D12_PRIMITIVE_TOPOLOGY_TYPE_TRIANGLE; + pd.NumRenderTargets = 1; + pd.RTVFormats[0] = DXGI_FORMAT_R32G32B32A32_FLOAT; + pd.SampleDesc.Count = 1; + ComPtr pipeline; + check(device->CreateGraphicsPipelineState(&pd, IID_PPV_ARGS(&pipeline)), "Create flat parameter PSO"); + + D3D12_RESOURCE_DESC rd{}; + rd.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D; + rd.Width = width; + rd.Height = height; + rd.DepthOrArraySize = 1; + rd.MipLevels = 1; + rd.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; + rd.SampleDesc.Count = 1; + rd.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; + const D3D12_CLEAR_VALUE clear{DXGI_FORMAT_R32G32B32A32_FLOAT, {-1.0f, -1.0f, -1.0f, -1.0f}}; + const auto target = resource(device, rd, D3D12_HEAP_TYPE_DEFAULT, D3D12_RESOURCE_STATE_RENDER_TARGET, &clear); + D3D12_PLACED_SUBRESOURCE_FOOTPRINT footprint{}; + UINT64 readback_size = 0; + device->GetCopyableFootprints(&rd, 0, 1, 0, &footprint, nullptr, nullptr, &readback_size); + const auto readback = make_buffer(device, readback_size, D3D12_HEAP_TYPE_READBACK, D3D12_RESOURCE_STATE_COPY_DEST); + + D3D12_DESCRIPTOR_HEAP_DESC hd{D3D12_DESCRIPTOR_HEAP_TYPE_RTV, 1, D3D12_DESCRIPTOR_HEAP_FLAG_NONE}; + ComPtr rtvs; + check(device->CreateDescriptorHeap(&hd, IID_PPV_ARGS(&rtvs)), "Create flat parameter RTV heap"); + const auto rtv = rtvs->GetCPUDescriptorHandleForHeapStart(); + device->CreateRenderTargetView(target.Get(), nullptr, rtv); + + ComputeCommands commands(device, pipeline.Get(), D3D12_COMMAND_LIST_TYPE_DIRECT); + auto* list = commands.list.Get(); + list->ClearRenderTargetView(rtv, clear.Color, 0, nullptr); + list->SetGraphicsRootSignature(root.Get()); + list->SetGraphicsRoot32BitConstants(0, entry_count, entry, 0); + const D3D12_VIEWPORT viewport{0, 0, static_cast(width), static_cast(height), 0, 1}; + const D3D12_RECT scissor{0, 0, static_cast(width), static_cast(height)}; + list->RSSetViewports(1, &viewport); + list->RSSetScissorRects(1, &scissor); + list->OMSetRenderTargets(1, &rtv, FALSE, nullptr); + list->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST); + list->DrawInstanced(3, 1, 0, 0); + transition(list, target.Get(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_COPY_SOURCE); + D3D12_TEXTURE_COPY_LOCATION out{readback.Get(), D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT}; + out.PlacedFootprint = footprint; + D3D12_TEXTURE_COPY_LOCATION in{target.Get(), D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX}; + list->CopyTextureRegion(&out, 0, 0, 0, &in, nullptr); + commands.submit_and_wait(device); + + void* mapped = nullptr; + const D3D12_RANGE read{0, static_cast(readback_size)}; + const D3D12_RANGE none{0, 0}; + check(readback->Map(0, &read, &mapped), "Map flat parameter readback"); + const auto* first = static_cast(mapped) + footprint.Offset; + for (UINT y = 0; y < height; ++y) { + std::memcpy(words + size_t(y) * width * 4, first + size_t(y) * footprint.Footprint.RowPitch, + size_t(width) * 4 * sizeof(*words)); + } + readback->Unmap(0, &none); + std::printf("startup_entry_words words=%08x,%08x,%08x,%08x\n", words[0], words[1], words[2], words[3]); +} diff --git a/tests/startup_gfx2hlsl_f32_med3_check.py b/tests/startup_gfx2hlsl_f32_med3_check.py new file mode 100644 index 0000000000..1cb6c9f286 --- /dev/null +++ b/tests/startup_gfx2hlsl_f32_med3_check.py @@ -0,0 +1,376 @@ +"""v_med3_f32 in tools/startup/gfx2hlsl.py: a NaN source is the minimum of the three (#2044). + + (no arguments) translation controls, pure Python + decode decode the fixture words with tools/disasm_rdna2.py and compare the text + binary reassemble the fixture sources and compare them with the words below + draw [fxc] + compile the translated pair with FXC vs_5_1/ps_5_1 when given and with DXC + vs_6_0/ps_6_0, draw one pixel and compare the four exported words; then the + branchless lowering must disagree on the NaN lane + (needs tests/offscreen_check.cpp built as offscreen_check) + +The RDNA 2 ISA defines V_MED3_F32 (\"343 V_MED3_F32\") as: + + if (isNan(S0.f) || isNan(S1.f) || isNan(S2.f)) D.f = V_MIN3_F32(S0.f, S1.f, S2.f); + else if (V_MAX3_F32(S0.f, S1.f, S2.f) == S0.f) D.f = V_MAX_F32(S1.f, S2.f); + ... + +A NaN source therefore makes the result the smallest of the three. The lowering used to emit +`max(min(a, b), min(max(a, b), c))`, which on a NaN source returns 2.0 for med3(NaN, 2.0, 1.0) where the ISA +returns 1.0: measured on an RX 9070 XT (driver 32.0.32029.2010) with a = NaN, 3.0, 1.5 and 0.5, the old form +gave 2.0, 2.0, 1.5, 1.0 and the ISA demands 1.0, 2.0, 1.5, 1.0. + +The table now points at `med3_32`, whose body is that of `tools/pixel_aot.py`: a NaN source is recognised on +the encoding (`asuint(x) & 0x7fffffffu > 0x7f800000u`) because a float `isnan()` may be folded away by the +compiler, and the result is `min(min(a, b), c)`, which D3D's min() reduces to the smallest non-NaN source. +The integer medians (`v_med3_u32`, `v_med3_i32`) are untouched: they have no NaN. + +What the measurement establishes and what it does not: the emitted text renders 2.0 on the card for a NaN +operand, and the ISA's rule is the lower of the non-NaN sources. That the hardware instruction itself +computes V_MIN3_F32 on a NaN source is **not** established by this fixture: HLSL has no way to emit +`v_med3_f32` (the compiler does not select it from the median pattern), so the draw compares the translated +text against the ISA rule, not against the instruction. This limit is recorded in docs/experiments.md. + +Controls, all on the emitted HLSL text (no compiler, no GPU): + - the preamble defines `med3_32` with the encoding test on all three sources, the `>` of `0x7f800000u` and + `min(min(a, b), c)` 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; + - four mutations must be rejected: the old branchless helper, the threshold `>=`, an `isnan(` test, and a + table that points back at a helper without the branch. + +The draw fixture is a source-built pair. The vertex stage places a full-screen triangle and exports the +position only. The pixel stage moves the four entry constants s8..s11 into s44..s47, then for each lane +`v_mov_b32 v1, s44+lane`, `v_mov_b32 v2, 2.0`, `v_mov_b32 v3, 1.0` and `v_med3_f32 v(12+lane), v1, v2, v3`, +exporting the four words to mrt0. The constants are root 32-bit constants (the form +tools/startup/gfx2hlsl.py lowers a constant buffer to), written by the renderer per draw: a literal would be +folded at compile time and the lowering under test would never run. The four inputs are 0x7fc00000 (quiet +NaN), 0x40400000 (3.0), 0x3fc00000 (1.5) and 0x3f000000 (0.5); the expected words are 0x3f800000 (1.0), +0x40000000 (2.0), 0x3fc00000 (1.5) and 0x3f800000 (1.0). + +The control that counts: the branchless helper restored in the same pair must MISMATCH on the NaN lane, with +0x40000000 where the ISA asks 0x3f800000, and match the other three lanes. A draw whose negative control +passes proves nothing; this check reports that as a failure rather than accepting it. + +The instruction words are constructed here from the field layout the checked-in decoder reads +(`tools/disasm_rdna2.py`): VOP3A w0 = 0b110101 << 26 | opcode << 16 | vdst, w1 = src0 | src1 << 9 | src2 << 18, +with the VGPR codes 256+n; v_med3_f32 is opcode 0x157, so `v_med3_f32 v12, v1, v2, v3` is +0c0057d501050e04. The decode mode proves that with the repository decoder. +""" +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')) +sys.path.insert(0, str(HERE.parent / 'tools' / 'startup')) +sys.path.insert(0, str(HERE)) +import gfx2hlsl as G # noqa: E402 +import disasm_rdna2 # noqa: E402 +from startup_flat_param_check import assemble, compile_hlsl # noqa: E402 + +SOP1_MOV_B32 = 0xbe800300 +VOP1_E32 = 0x7e000000 +VOP1_MOV_B32 = 0x01 +VGPR, LITERAL = 256, 255 +INLINE = {0x40000000: 0xf4, 0x3f800000: 0xf2} # 2.0 and 1.0, the coding llvm-mc picks for a float literal + +# The four inputs, then the four words the ISA rule gives for med3(a, 2.0, 1.0). +INPUTS = (0x7fc00000, 0x40400000, 0x3fc00000, 0x3f000000) +EXPECTED = (0x3f800000, 0x40000000, 0x3fc00000, 0x3f800000) +# The branchless lowering's NaN lane: max(min(a, b), min(max(a, b), c)) with a = NaN is 2.0. +BRANCHLESS_NAN = 0x40000000 + +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' + '}') +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' + ' return isnan(a) || isnan(b) || isnan(c) ? min(min(a, b), c)' + ' : max(min(a, b), min(max(a, b), c));\n}') + +failures = [] + + +def check(label, ok, detail=''): + print('%s: %s' % (label, 'ok' if ok else 'MISMATCH'), flush=True) + if not ok: + failures.append(label) + if detail: + print(' ' + detail) + + +# ---- the fixture ----------------------------------------------------------------------------------------------- +VS_SOURCE = ('v_mov_b32 v3, 0x40400000\n' + 'v_mov_b32 v10, 0xc0400000\n' + 'v_cmp_eq_u32 vcc_lo, 1, v0\n' + 'v_cndmask_b32 v1, -1.0, v3, vcc_lo\n' + 'v_cmp_eq_u32 vcc_lo, 2, v0\n' + 'v_cndmask_b32 v2, 1.0, v10, vcc_lo\n' + 'v_mov_b32 v4, 1.0\n' + 'v_mov_b32 v5, 0\n' + 'exp pos0 v1, v2, v5, v4 done\n' + 's_endpgm\n') +VS_WORDS = (bytes.fromhex('ff02067e00004040' 'ff02147e000040c0' '8100847d' 'f3060202' '8200847d' 'f2140402' + 'f202087e' '80020a7e') + + bytes.fromhex('cf0800f801020504' '000081bf')) +PS_EXPORT = bytes.fromhex('0f1800f80c0d0e0f000081bf') # exp mrt0 v12..v15 done vm ; s_endpgm + + +def sop1_mov_b32(sdst, ssrc0): + return struct.pack('=', lambda t: t.replace('top > 0x7f800000u', 'top >= 0x7f800000u')), + ('an isnan() test instead of the encoding test', lambda t: t.replace(MED3_32, OLD_ISNAN)), + ('the table pointing back at a helper without the branch', + lambda t: t.replace(STATEMENT % 12, 'v12 = U(med3(F(v1), F(v2), F(v3)));')), + ] + + +def check_mutations(): + hlsl = pipeline().hlsl_ps() + for label, mutate in mutations(hlsl): + changed = mutate(hlsl) + rejected = changed != hlsl + if rejected: + try: + check_text(changed) + except AssertionError: + pass + else: + rejected = False + check('%s is rejected' % label, rejected) + + +# ---- the words ------------------------------------------------------------------------------------------------ +def check_decode(): + decoded = disasm_rdna2.disassemble_binary(PS_WORDS) + assembly = [ins['assembly'] for ins in decoded] + assert assembly[0:4] == ['s_mov_b32 s%d, s%d' % (44 + lane, 8 + lane) for lane in range(4)], assembly[0:4] + for lane in range(4): + block = assembly[4 + 4 * lane:8 + 4 * lane] + assert block == ['v_mov_b32_e32 v1, s%d' % (44 + lane), 'v_mov_b32_e32 v2, 2.0', + 'v_mov_b32_e32 v3, 1.0', 'v_med3_f32 v%d, v1, v2, v3' % (12 + lane)], block + assert assembly[-2:] == ['exp mrt0 v12, v13, v14, v15 done vm', 's_endpgm'], assembly[-2:] + assert PS_WORDS[28:36].hex() == '0c0057d501050e04', PS_WORDS[28:36].hex() + print('the fixture decodes to s44..s47, v_med3_f32 on each lane and the mrt0 export') + + +def check_binary(llvm_mc): + for name, source, words in (('vertex', VS_SOURCE, VS_WORDS), ('pixel', PS_SOURCE, PS_WORDS)): + built = assemble(llvm_mc, source) + if built != words: + raise AssertionError('%s fixture: assembled %s, recorded %s' % (name, built.hex(), words.hex())) + print('fixture words match llvm-mc') + + +# ---- the draw ------------------------------------------------------------------------------------------------- +def draw(renderer, adapter, vs, ps, constants, expected): + """One pixel through offscreen_check --startup-entry-words; exit 77 (skip) propagates.""" + run = subprocess.run([renderer, adapter, '--startup-entry-words', str(vs), str(ps), constants, expected], + capture_output=True, text=True) + sys.stdout.write(run.stdout) + if run.returncode == 77: + print(run.stdout + run.stderr) + sys.exit(77) + return run + + +def actual_words(run): + """The four words the renderer reports as `actual=` in its mismatch line.""" + m = re.search(r'actual=([0-9a-f]{8}),([0-9a-f]{8}),([0-9a-f]{8}),([0-9a-f]{8})', run.stderr) + return [int(word, 16) for word in m.groups()] if m else None + + +def naive(hlsl): + """The branchless helper restored, the table still calling med3_32.""" + return hlsl.replace(MED3_32, BRANCHLESS) + + +def check_draw(dxc, renderer, adapter, fxc=None): + check_controls() + check_mutations() + check_decode() + if failures: + sys.exit(1) + # ud0 is the vertex stage's rectangle-list switch; the four inputs follow it and are what the pixel + # stage moves into s44..s47. The list is as long as the constant buffer both shaders declare. + translated = pipeline() + entry = [0] * entry_counts(translated.hlsl_vs(), translated.hlsl_ps()) + entry[1:1 + len(INPUTS)] = INPUTS + constants = words_text(entry) + expected = words_text(EXPECTED) + print('constants %s expected %s' % (constants, expected)) + compilers = ([('fxc', fxc, 'vs_5_1', 'ps_5_1')] if fxc else []) + [('dxc', dxc, 'vs_6_0', 'ps_6_0')] + with tempfile.TemporaryDirectory() as tmp: + directory = Path(tmp) + for kind, compiler, vs_profile, ps_profile in compilers: + vs = compile_hlsl(compiler, kind, pipeline().hlsl_vs(), 'vs_med3_%s' % kind, vs_profile, directory) + good = compile_hlsl(compiler, kind, pipeline().hlsl_ps(), 'ps_med3_%s' % kind, ps_profile, directory) + run = draw(renderer, adapter, vs, good, constants, expected) + if run.returncode: + raise AssertionError('%s translated pair, constants %s\n%s\n%s' + % (kind, constants, run.stdout, run.stderr)) + print('%s %s: %s' % (kind, adapter, expected), flush=True) + bad = compile_hlsl(compiler, kind, naive(pipeline().hlsl_ps()), 'ps_med3_bad_%s' % kind, + ps_profile, directory) + run = draw(renderer, adapter, vs, bad, constants, expected) + actual = actual_words(run) + label = '%s branchless lowering on %s' % (kind, adapter) + if run.returncode == 0: + check('%s was accepted: the draw does not catch the defect' % label, False) + elif actual is None: + check('%s failed without an actual= line: %s' % (label, run.stderr.strip()), False) + else: + nan_lane = actual[0] == BRANCHLESS_NAN and EXPECTED[0] != BRANCHLESS_NAN + others = actual[1:] == list(EXPECTED[1:]) + check('%s mismatched on the NaN lane (%s) and matched the other three' + % (label, words_text(actual)), nan_lane and others) + if failures: + sys.exit(1) + + +def main(): + if len(sys.argv) == 1: + check_controls() + check_mutations() + check_decode() + if failures: + sys.exit(1) + return + mode, *args = sys.argv[1:] + if mode == 'decode': + check_decode() + elif mode == 'binary': + check_binary(*args) + elif mode == 'draw': + check_draw(*args) + else: + raise SystemExit(__doc__) + + +if __name__ == '__main__': + main() diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index 067856ece0..d7148c92ac 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -1852,7 +1852,7 @@ 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, 'frac({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}))'), + '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}))'), } # Conversions whose result is binary32. The expression is the float value, so an output modifier # (clamp, mul:2, mul:4, div:2) can wrap it the way it wraps any other float result. The uint-result @@ -2076,7 +2076,14 @@ def common(self): ' precise float sum = product + ftz32(c);', ' return ftz32(sum);', '}', - 'float med3(float a, float b, float c) { return max(min(a, b), min(max(a, b), c)); }', + # 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. + # 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));', + '}', # The ten binary32 classes v_cmp_class_f32 tests, from the raw encoding (#1795). 'uint class32(float value) { uint bits = asuint(value), magnitude = bits & 0x7fffffffu;' ' bool negative = bits >= 0x80000000u;' From 6883eeb3e78c8b4f927a4efd1417c80829d8931d Mon Sep 17 00:00:00 2001 From: Panam Date: Wed, 25 Nov 2026 01:08:29 +0100 Subject: [PATCH 2/5] tests: supply the eight entry words the med3 draw fixture declares --- tests/startup_gfx2hlsl_f32_med3_check.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/startup_gfx2hlsl_f32_med3_check.py b/tests/startup_gfx2hlsl_f32_med3_check.py index 1cb6c9f286..25fc58b0ba 100644 --- a/tests/startup_gfx2hlsl_f32_med3_check.py +++ b/tests/startup_gfx2hlsl_f32_med3_check.py @@ -135,6 +135,9 @@ def vop3_med3_f32(vdst, src0, src1, src2): return struct.pack(' Date: Wed, 25 Nov 2026 16:59:26 +0100 Subject: [PATCH 3/5] Bump the startup shader cache revision to 16 for the med3 lowering --- docs/startup-runtime.md | 2 +- src/startup_stubs/d3d12_draw.inl | 2 +- tests/startup_gfx2hlsl_buffer_store_check.py | 2 +- tests/startup_indirect_draw_indexed.cpp | 2 +- tools/startup/gfx2hlsl.py | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/startup-runtime.md b/docs/startup-runtime.md index 043429b30c..5b543f4af4 100644 --- a/docs/startup-runtime.md +++ b/docs/startup-runtime.md @@ -204,7 +204,7 @@ 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-14`. Older translations evaluate `s_brev_b32` of a +The shader cache revision is `x2w-startup-shader-16`. 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. Revisions before 12 can overwrite the source mask when a save-EXEC instruction uses the same source and destination register. diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index 335498a90b..ffd6e40b40 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -243,7 +243,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-14"; + 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. diff --git a/tests/startup_gfx2hlsl_buffer_store_check.py b/tests/startup_gfx2hlsl_buffer_store_check.py index af69fdc8b2..99b6ca0df5 100644 --- a/tests/startup_gfx2hlsl_buffer_store_check.py +++ b/tests/startup_gfx2hlsl_buffer_store_check.py @@ -149,7 +149,7 @@ def main(): # 8. The cache revision moved, so a translation from before the store lowering is never loaded. check('cache key uses revision 14', G.pipeline_key(b'a', b'b', ROOT) == - G.fnv(ROOT, G.fnv(b'b', G.fnv(b'a', G.fnv(b'x2w-startup-shader-14'))))) + G.fnv(ROOT, G.fnv(b'b', G.fnv(b'a', G.fnv(b'x2w-startup-shader-16'))))) if failures: print('FAILED: ' + ', '.join(failures)) diff --git a/tests/startup_indirect_draw_indexed.cpp b/tests/startup_indirect_draw_indexed.cpp index 402cb2f0a3..8a46b071cb 100644 --- a/tests/startup_indirect_draw_indexed.cpp +++ b/tests/startup_indirect_draw_indexed.cpp @@ -293,7 +293,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-14"; + 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/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index 79d5dc33d4..42e79f4af7 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -5397,7 +5397,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-14')))) + key = fnv(root_blob, fnv(ps_code, fnv(vs_code, fnv(b'x2w-startup-shader-16')))) return fnv(layout, key) if layout else key From c93f0285f03124825e1f7c7860115de77b23fb38 Mon Sep 17 00:00:00 2001 From: thepatrickworld Date: Wed, 25 Nov 2026 17:14:16 +0100 Subject: [PATCH 4/5] Update the readfirstlane uniformity fixture for the med3_32 helper rename --- tests/startup_gfx2hlsl_readfirstlane_uniform_check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/startup_gfx2hlsl_readfirstlane_uniform_check.py b/tests/startup_gfx2hlsl_readfirstlane_uniform_check.py index eef9354837..b1fb5ee6f5 100644 --- a/tests/startup_gfx2hlsl_readfirstlane_uniform_check.py +++ b/tests/startup_gfx2hlsl_readfirstlane_uniform_check.py @@ -81,9 +81,9 @@ def run(*instructions, exec_known=True): ['v7 = U(1.0 / F(s2));']), # The clamp to [0, 0.5] of a scalar, as compiled shaders write it. ('median of three', ('v_med3_f32 v7, s2, 0, 0.5',), - ['v7 = U(med3(F(s2), F(0x00000000u), 0.5));']), + ['v7 = U(med3_32(F(s2), F(0x00000000u), 0.5));']), ('median of three scalar sources', ('v_med3_f32 v7, s2, -s3, |s2| clamp',), - ['v7 = U(saturate(med3(F(s2), (-F(s3)), abs(F(s2)))));']), + ['v7 = U(saturate(med3_32(F(s2), (-F(s3)), abs(F(s2)))));']), ('move', ('v_mov_b32_e32 v7, s2',), ['v7 = s2;']), ('literal move', ('v_mov_b32_e32 v7, 0x1234',), ['v7 = 0x00001234u;']), ('chain with an in-place write', ('v_mul_f32_e64 v7, s2, 2.0', 'v_cvt_u32_f32_e32 v7, v7'), From 135c11bc8593a43d4917b5d78f1a75be6bd6193f Mon Sep 17 00:00:00 2001 From: panam Date: Wed, 25 Nov 2026 22:40:51 +0100 Subject: [PATCH 5/5] Bump the startup shader cache revision to 17 for the med3 lowering main moved to 16 through #2010, so this branch takes 17 and moves the compute key with it (17cs), as MasterDomino asked in #2095. --- src/startup_stubs/d3d12_draw.inl | 4 ++-- tests/startup_compute_request_offline_check.py | 4 ++-- tests/startup_gfx2hlsl_buffer_store_check.py | 4 ++-- tests/startup_gfx2hlsl_fract_check.py | 8 ++++---- tests/startup_indirect_draw_indexed.cpp | 2 +- tests/startup_resource_retire_title.cpp | 2 +- tools/startup/gfx2hlsl.py | 5 ++--- 7 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index 2eefa8e184..1cf8607453 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-16"; + constexpr char revision[] = "x2w-startup-shader-17"; 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-16cs"; // tools/startup/gfx2hlsl.py compute_key + constexpr char compute_revision[] = "x2w-startup-shader-17cs"; // 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); diff --git a/tests/startup_compute_request_offline_check.py b/tests/startup_compute_request_offline_check.py index 30e6e3c372..f57f4b28c1 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 = 0x4db2818cb07558bf # framed key at revision 16cs +KEY = 0x8421b8080fd0a5e6 # framed key at revision 17cs def framed_key(): h = 1469598103934665603 - for b in b'x2w-startup-shader-16cs': + for b in b'x2w-startup-shader-17cs': h = ((h ^ b) * 1099511628211) & 0xffffffffffffffff for part in (CODE, DATA, ROOT, DESC, STATE_A, STATE_B): for b in struct.pack(' 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-16"; + constexpr char revision[] = "x2w-startup-shader-17"; 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 0850645f78..fa6fbaf4c5 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-16"; // d3d12_draw.inl cached_translation +constexpr char draw_revision[] = "x2w-startup-shader-17"; // 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 60b6e3b960..00fa3c759c 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -6493,7 +6493,6 @@ def common(self): ' 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)); }', # 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. @@ -6932,7 +6931,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-16')))) + key = fnv(root_blob, fnv(ps_code, fnv(vs_code, fnv(b'x2w-startup-shader-17')))) return fnv(layout, key) if layout else key @@ -6941,7 +6940,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-16cs') + key = fnv(b'x2w-startup-shader-17cs') for part in (cs_code, data, root_blob, desc, state_a, state_b): key = fnv(part, fnv(struct.pack('