Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,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"], {}),
Expand Down Expand Up @@ -320,6 +321,7 @@ jobs:
tests/startup_gfx2hlsl_spill_branches_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 \
Expand Down
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4035,6 +4035,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}"
"$<TARGET_FILE:offscreen_check>" ${adapter} $<$<BOOL:${STARTUP_FXC}>:${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}"
Expand Down
32 changes: 32 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -7727,6 +7727,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.
Expand Down
9 changes: 5 additions & 4 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,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.
Expand Down
6 changes: 3 additions & 3 deletions src/startup_stubs/d3d12_draw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,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.
Expand Down Expand Up @@ -474,7 +474,7 @@ u64 publish_compute_request(const void* desc)
std::vector<unsigned char> 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<unsigned char>* order[] = {&code, &data, &root_blob, &fields, &state_a, &state_b};
for (const auto* part : order) key = fnv_part(*part, key);
Expand Down Expand Up @@ -538,7 +538,7 @@ void request_slot57_mesh(Wrapper* pipeline, const std::vector<RootParameter>* 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<u64> written;
Expand Down
13 changes: 8 additions & 5 deletions tests/pixel_aot_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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("<I", struct.pack("<f", x))[0]}
names.update(minmax_zero32=lambda a, b, maximum: (max_num if maximum else min_num)(a, b),
true=True, false=False)
# Evaluate the med3_32 helper of the preamble: its NaN test on the encoding, then the selected form.
helper = (r"^float med3_32\(float a, float b, float c\) \{\n uint top = (.+);\n"
r" return top > (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(
Expand Down Expand Up @@ -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|"),
Expand Down Expand Up @@ -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)
Expand Down
Loading
Loading