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
4 changes: 2 additions & 2 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -6488,9 +6488,9 @@ The e64 draws use `offscreen_check <backend> --check-pixel-batch <shader.cso> <c

`v_frexp_mant_f32` (in e32 and e64 encodings) and `v_ldexp_f32` lower through explicit IEEE-754 binary32 bit helpers (`frexp_mant32` and `ldexp32`) so subnormals, signed zero, infinity, NaN, and large exponent shifts stay independent of desktop driver flush-to-zero modes. `v_ldexp_f32` accepts float source modifiers on `src0` and `clamp`, while decoding `src1` as a signed 32-bit integer and rejecting float modifiers on the exponent. Binary and draw fixtures check normal values, signed zero, source negation and absolute value, runtime scalar exponents, negative exponents, and output clamping; replacing `v_frexp_mant_f32` with `v_mov_b32` or inverting a `v_ldexp_f32` exponent sign must report a pixel mismatch.

Quad-local conversion DPP16 and DPP8 reuse the same routing helpers as the other pixel operations. This slice handles signed and unsigned float32-to-integer and integer-to-float32 conversion, extraction of four unsigned byte positions, and the signed four-bit offset scaled by 1/16. Float32-to-integer conversion uses the shared helpers for truncation, NaN to zero, and saturation. DPP16 permits abs and neg on floating sources. DPP8 repeats the same quad permutation in both halves. Partial masks, cross-quad routing, additional modifiers and uninitialized operands are refused. Binary16 destination, packed, FLR and RPI forms remain outside this slice.
Quad-local conversion DPP16 and DPP8 reuse the same routing helpers as the other pixel operations. This slice handles signed and unsigned float32-to-integer (truncate, floor `v_cvt_flr_i32_f32_dpp` and round-to-+inf `v_cvt_rpi_i32_f32_dpp`), integer-to-float32 conversion, extraction of four unsigned byte positions, the signed four-bit offset scaled by 1/16, and the compressed-export binary16 pack `v_cvt_pkrtz_f16_f32_dpp` (swizzling `src0` across the quad, keeping `src1` on the current lane, and producing the same compressed-export pair as `v_cvt_pkrtz_f16_f32_e32`). Float32-to-integer conversions reuse the shared helpers (`cvt_i32_f32`, `cvt_u32_f32`, `cvt_flr_i32_f32`, `cvt_rpi_i32_f32`) for NaN, infinity and saturation. DPP16 permits abs and neg on floating sources (`src0`, and `src1` for `v_cvt_pkrtz_f16_f32_dpp`). DPP8 repeats the same quad permutation in both halves and refuses source modifiers. Partial masks, cross-quad routing, additional modifiers, uninitialized operands and non-export reads of packed `v_cvt_pkrtz_f16_f32_dpp` results are refused.

The source-built draw compares all four channels as raw words. It covers signed and unsigned endpoints, infinities and NaN, the rounding point 2^24+1, each byte position and both signs of the four-bit offset. All four routed lanes contribute distinct base-4 weights. Changing the DPP8 rotation, swapping the DPP16 axes, discarding the source negation, or reading the wrong byte must mismatch. The LLVM 15 binary round trip covers both programs. Run `ctest --preset dev --no-tests=error -R '^pixel_aot_dpp_cvt_' -V`.
The source-built draw (`pixel_aot_dpp_cvt_{warp,hardware}`) compares all four channels as raw words for `from_float`, `to_float` and `flr_rpi` (covering signed/unsigned endpoints, fractional half-integers `-1.5`, `-0.5`, `+0.5`, `+1.5`, infinities, signed NaNs, the rounding point 2^24+1, each byte position and both signs of the four-bit offset, with all four routed lanes contributing distinct base-4 weights), and draws `pkrtz` through the compressed export path (verifying quad-broadcast `src0` routing, DPP16 `-`/`|.|` modifiers on both sources, DPP8 broadcast, and round-toward-zero vs round-to-nearest-even). Mutations that change the DPP8 rotation, swap DPP16 axes, drop source negation or abs, confuse `flr`/`rpi`/`trunc`, read the wrong byte, or expect RNE instead of RTZ must mismatch. The LLVM 15 binary round trip covers all four programs. Run `ctest --preset dev --no-tests=error -R '^pixel_aot_dpp_cvt_' -V`.

`v_frexp_exp_i32_f32` in e32 and e64 encodings returns a signed 32-bit exponent. The binary32 bit helper handles normal and subnormal inputs and returns zero for signed zeros, infinities and NaNs. Source negation and absolute value leave the magnitude unchanged, so the lowerer can omit float sign operations that could flush subnormals. The lowerer keeps the result as integer bits in the destination register. The synthetic draw compares those bits before pixel export for 12 input words, including the smallest and largest subnormals. A reference with an exponent one too large for the smallest subnormal must report a pixel mismatch. Run the dedicated cases with `ctest --preset dev --no-tests=error -R '^pixel_aot_frexp_exp_'`.

Expand Down
14 changes: 9 additions & 5 deletions tests/form_coverage_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,20 +497,24 @@ def check_shader_records():
without = fc.measure({"pixel_aot_warp": "pass"}, root, {"pixel_aot_warp": pixel.ACCEPTED - words})
assert covered["gfx1013"]["covered"] == without["gfx1013"]["covered"] + len(rounding)
# Float-to-word conversions (truncate, floor, round-to-+inf) cover VOP1 e32 and VOP3 e64;
# DPP/SDWA variants stay excluded.
# SDWA variants stay excluded while DPP16/DPP8 flr, rpi and pkrtz are covered.
cvt_f32_int = {
("VOP1", "v_cvt_u32_f32"), ("VOP1", "v_cvt_i32_f32"),
("VOP1", "v_cvt_flr_i32_f32"), ("VOP1", "v_cvt_rpi_i32_f32"),
("VOP3", "v_cvt_u32_f32_e64"), ("VOP3", "v_cvt_i32_f32_e64"),
("VOP3", "v_cvt_flr_i32_f32_e64"), ("VOP3", "v_cvt_rpi_i32_f32_e64"),
}
cvt_f32_excluded = {"v_cvt_flr_i32_f32_dpp", "v_cvt_flr_i32_f32_sdwa",
"v_cvt_rpi_i32_f32_dpp", "v_cvt_rpi_i32_f32_sdwa"}
cvt_dpp_forms = {
(group, form)
for group in ("DPP16", "DPP8")
for form in ("v_cvt_flr_i32_f32_dpp", "v_cvt_rpi_i32_f32_dpp", "v_cvt_pkrtz_f16_f32_dpp")
}
cvt_f32_excluded = {"v_cvt_flr_i32_f32_sdwa", "v_cvt_rpi_i32_f32_sdwa"}
for name in ("gfx1013.tsv", "rdna2.tsv"):
reference = fc.load_reference(name)
assert cvt_f32_int <= reference, name
assert cvt_f32_int | cvt_dpp_forms <= reference, name
forms = fc.gfx_forms(pixel.ACCEPTED, reference)
assert cvt_f32_int <= forms, (name, sorted(cvt_f32_int - forms))
assert cvt_f32_int | cvt_dpp_forms <= forms, (name, sorted((cvt_f32_int | cvt_dpp_forms) - forms))
assert not ({form for _, form in forms} & cvt_f32_excluded), name


Expand Down
134 changes: 132 additions & 2 deletions tests/pixel_aot_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -9237,12 +9237,83 @@ def check_three_way_templates():
"v_fma_f32 v14, 0x41000000, v27, v14",
"v_cvt_off_f32_i4_dpp v15, v22 dpp8:[1,0,3,2,5,4,7,6]",
]
DPP_CVT_FLR_RPI = [
*DPP_CVT_LANES,
"v_add_f32_e32 v21, 0.5, v20",
"v_cvt_flr_i32_f32_dpp v22, v21 dpp8:[1,2,3,0,5,6,7,4]",
"v_cvt_rpi_i32_f32_dpp v23, v21 quad_perm:[2,3,0,1] row_mask:0xf bank_mask:0xf",
*[f"v_cvt_f32_i32_dpp v{24+lane}, v22 quad_perm:[{lane},{lane},{lane},{lane}] row_mask:0xf bank_mask:0xf"
for lane in range(4)],
*[f"v_cvt_f32_i32_dpp v{28+lane}, v23 quad_perm:[{lane},{lane},{lane},{lane}] row_mask:0xf bank_mask:0xf"
for lane in range(4)],
"v_fma_f32 v13, 4.0, v25, v24",
"v_fma_f32 v13, 0x41800000, v26, v13",
"v_fma_f32 v13, 0x42800000, v27, v13",
"v_fma_f32 v15, 4.0, v29, v28",
"v_fma_f32 v15, 0x41800000, v30, v15",
"v_fma_f32 v15, 0x42800000, v31, v15",
"v_mov_b32_e32 v40, s44",
"v_mov_b32_e32 v41, s45",
"v_cvt_flr_i32_f32_dpp v12, -v40 quad_perm:[1,0,3,2] row_mask:0xf bank_mask:0xf",
"v_cvt_rpi_i32_f32_dpp v14, v41 dpp8:[2,3,0,1,6,7,4,5]",
]


def dpp_pkrtz_program():
body = [
*DPP_CVT_LANES,
"v_add_f32_e32 v22, 1.0, v20",
"v_mov_b32_e32 v24, s44",
"v_mov_b32_e32 v25, s45",
]
program = with_constants(body)
i16 = program.index("v_cvt_pkrtz_f16_f32_e32 v16, v12, v13")
i17 = program.index("v_cvt_pkrtz_f16_f32_e32 v17, v14, v15")
program[i16] = "v_cvt_pkrtz_f16_f32_dpp v16, -v22, |v25| quad_perm:[3,3,3,3] row_mask:0xf bank_mask:0xf"
program[i17] = "v_cvt_pkrtz_f16_f32_dpp v17, v22, v24 dpp8:[2,2,2,2,6,6,6,6]"
return program


def check_dpp_cvt_refusals():
# Positive static checks: lower flr/rpi and pkrtz DPP fixtures so form_coverage_check counts all 6 forms
# and pin that pkrtz swizzles src0 only (never src1) and accepts RTZ HW_REG_MODE.
flr_rpi_hlsl = translate_int(uncompressed_export(DPP_CVT_FLR_RPI))
assert "cvt_flr_i32_f32(" in flr_rpi_hlsl and "cvt_rpi_i32_f32(" in flr_rpi_hlsl
pkrtz_hlsl = translate(dpp_pkrtz_program())
assert "QuadReadLaneAt(" in pkrtz_hlsl and "export16(" in pkrtz_hlsl
hi_lines = [line for line in pkrtz_hlsl.splitlines() if "_hi = " in line]
assert len(hi_lines) == 2 and all("QuadRead" not in line for line in hi_lines), hi_lines
rtz_pkrtz = list(dpp_pkrtz_program())
nop_pkrtz = list(dpp_pkrtz_program())
rtz_pos = rtz_pkrtz.index("v_cvt_pkrtz_f16_f32_dpp v16, -v22, |v25| quad_perm:[3,3,3,3] row_mask:0xf bank_mask:0xf")
rtz_pkrtz.insert(rtz_pos, "s_setreg_imm32_b32 hwreg(HW_REG_MODE, 2, 2), 3")
nop_pkrtz.insert(rtz_pos, "s_nop 0")
assert translate(rtz_pkrtz) == translate(nop_pkrtz)
for instruction, message in (
("v_cvt_f32_i32_dpp v256, v12 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf",
"Invalid conversion DPP operation"),
("v_cvt_flr_i32_f32_dpp v256, v12 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf",
"Invalid conversion DPP operation"),
("v_cvt_rpi_i32_f32_dpp v12, -v12 dpp8:[1,0,3,2,5,4,7,6]",
"Source modifiers are not allowed"),
("v_cvt_flr_i32_f32_dpp v12, |v12| dpp8:[1,0,3,2,5,4,7,6]",
"Source modifiers are not allowed"),
("v_cvt_flr_i32_f32_dpp v12, v12 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0x3",
"Unsupported DPP16 modifier"),
("v_cvt_rpi_i32_f32_dpp v12, v255 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf",
"DPP operand v255 is read before it is written"),
("v_cvt_pkrtz_f16_f32_dpp v256, v12, v13 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf",
"Invalid pack DPP operation"),
("v_cvt_pkrtz_f16_f32_dpp v16, v12 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf",
"Invalid DPP operand count"),
("v_cvt_pkrtz_f16_f32_dpp v16, -v12, v13 dpp8:[1,0,3,2,5,4,7,6]",
"Source modifiers are not allowed"),
("v_cvt_pkrtz_f16_f32_dpp v16, v12, |v13| dpp8:[1,0,3,2,5,4,7,6]",
"Source modifiers are not allowed"),
("v_cvt_pkrtz_f16_f32_dpp v16, v12, v255 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf",
"DPP operand v255 is read before it is written"),
("v_cvt_pkrtz_f16_f32_dpp v16, v12, v13 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf bound_ctrl:1",
"Unsupported DPP16 modifier"),
("v_cvt_i16_f16_dpp v55, v12 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf",
"Unsupported instruction"),
("v_cvt_f32_i32_dpp v12, v255 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf",
Expand All @@ -9269,6 +9340,13 @@ def check_dpp_cvt_refusals():
"Source modifiers are not allowed"),
):
expect_value_error(translate, with_constants([instruction]), message)
# Packed pair from v_cvt_pkrtz_f16_f32_dpp stays refused as a numeric ALU operand (export-only contract).
expect_value_error(
translate,
with_constants(["v_cvt_pkrtz_f16_f32_dpp v20, v12, v13 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf",
"v_add_f32_e32 v12, v20, v13"]),
"Expected a numeric register",
)


def check_dpp_cvt_draw(directory, compiler, renderer, backend):
Expand All @@ -9288,6 +9366,14 @@ def bits(value):
((0xffffffff, 0xffffffff, 0x87654325),
(bits(-1), bits(4294967296), bits(37 + 2*67 + 4*101 + 8*135), bits(0.3125))),
]
flr_rpi_rows = [
((0x3fc00000, 0xbf000000), (0xfffffffe, bits(57), 0, bits(163))),
((0xbf000000, 0x3f000000), (0, bits(57), 1, bits(163))),
((0xbf800001, 0xbf000001), (1, bits(57), 0xffffffff, bits(163))),
((0x7f800000, 0x4f000000), (0x80000000, bits(57), 0x7fffffff, bits(163))),
((0x7fc00001, 0xffc00001), (0x80000000, bits(57), 0x80000000, bits(163))),
((0xffc00001, 0x7fc00001), (0x7fffffff, bits(57), 0x7fffffff, bits(163))),
]
for name, body, rows, mutations in (
("from_float", DPP_CVT_FROM_FLOAT, from_float_rows, (
("dpp8:[1,2,3,0,5,6,7,4]", "dpp8:[3,0,1,2,7,4,5,6]"),
Expand All @@ -9297,6 +9383,13 @@ def bits(value):
("to_float", DPP_CVT_TO_FLOAT, to_float_rows, (
("v_cvt_f32_ubyte0_dpp", "v_cvt_f32_ubyte1_dpp"),
)),
("flr_rpi", DPP_CVT_FLR_RPI, flr_rpi_rows, (
("dpp8:[1,2,3,0,5,6,7,4]", "dpp8:[3,0,1,2,7,4,5,6]"),
("v23, v21 quad_perm:[2,3,0,1]", "v23, v21 quad_perm:[1,0,3,2]"),
("v_cvt_rpi_i32_f32_dpp v23", "v_cvt_flr_i32_f32_dpp v23"),
("v12, -v40", "v12, v40"),
("v_cvt_flr_i32_f32_dpp v12", "v_cvt_i32_f32_dpp v12"),
)),
):
src = directory / f"dpp_cvt_{name}.hlsl"
shader = directory / f"dpp_cvt_{name}.cso"
Expand All @@ -9318,6 +9411,42 @@ def bits(value):
src.write_text(translate_int(changed), encoding="ascii")
compile_shader(compiler, src, shader)
run_pixel_batch(renderer, backend, shader, [(cases[0][0], "mismatch")])

# Compressed-export draw for v_cvt_pkrtz_f16_f32_dpp (DPP16 with -/|.| and DPP8 broadcast).
pkrtz_prog = dpp_pkrtz_program()
pkrtz_src = directory / "dpp_cvt_pkrtz.hlsl"
pkrtz_shader = directory / "dpp_cvt_pkrtz.cso"
pkrtz_src.write_text(translate(pkrtz_prog), encoding="ascii")
compile_shader(compiler, pkrtz_src, pkrtz_shader)
pkrtz_rows = (
((0x3f801800, 0xc0200000), (-4.0, 2.5, 3.0, 1.0)),
((0xbf801800, 0x40500000), (-4.0, 3.25, 3.0, -1.0)),
)
pkrtz_cases = []
for i, (inputs, expected) in enumerate(pkrtz_rows):
constants = bytearray(256)
struct.pack_into("<2I", constants, 12, *inputs)
case = directory / f"dpp_cvt_pkrtz_{i}.case"
write_case(case, constants, expected)
pkrtz_cases.append((case, "pass"))
# RNE instead of RTZ on 0x3f801800 (1 + 1.5*2^-11) would export 1.0009765625 instead of 1.0.
rne_constants = bytearray(256)
struct.pack_into("<2I", rne_constants, 12, *pkrtz_rows[0][0])
rne_wrong = directory / "dpp_cvt_pkrtz_rne_wrong.case"
write_case(rne_wrong, rne_constants, (-4.0, 2.5, 3.0, 1.0009765625))
pkrtz_cases.insert(-1, (rne_wrong, "mismatch"))
run_pixel_batch(renderer, backend, pkrtz_shader, pkrtz_cases)
for old, new in (
("quad_perm:[3,3,3,3]", "quad_perm:[1,1,1,1]"),
("dpp8:[2,2,2,2,6,6,6,6]", "dpp8:[0,0,0,0,4,4,4,4]"),
("-v22, |v25|", "v22, |v25|"),
("-v22, |v25|", "-v22, v25"),
):
changed = [line.replace(old, new) for line in pkrtz_prog]
assert changed != pkrtz_prog, old
pkrtz_src.write_text(translate(changed), encoding="ascii")
compile_shader(compiler, pkrtz_src, pkrtz_shader)
run_pixel_batch(renderer, backend, pkrtz_shader, [(pkrtz_cases[0][0], "mismatch")])
return 0


Expand Down Expand Up @@ -15968,7 +16097,7 @@ def _check_controls_inline(directory):
for bad in ("v_cvt_u32_f32_e64 v12, s44 clamp", "v_cvt_i32_f32_e64 v12, s44 omod:2",
"v_cvt_flr_i32_f32_e64 v12, s44 clamp", "v_cvt_rpi_i32_f32_e64 v12, s44 omod:2",
"v_cvt_i32_f32_sdwa v12, v13 dst_sel:DWORD src0_sel:DWORD",
"v_cvt_flr_i32_f32_dpp v12, v13 quad_perm:[0,1,2,3] row_mask:0xf bank_mask:0xf",
"v_cvt_flr_i32_f32_sdwa v12, v13 dst_sel:DWORD src0_sel:DWORD",
"v_cvt_rpi_i32_f32_sdwa v12, v13 dst_sel:DWORD src0_sel:DWORD",
"v_cvt_u32_f32_e32 v12, 0.5", "v_cvt_u32_f32_e32 v12, 1", "v_cvt_i32_f32_e32 v12, -1",
"v_cvt_flr_i32_f32_e32 v12, 0.5", "v_cvt_rpi_i32_f32_e32 v12, -1",
Expand Down Expand Up @@ -18122,7 +18251,8 @@ def check_binary(directory, assembler, objcopy, library):
fixtures.extend((program, function) for _, program, function, _ in e64_spelling_programs())
fixtures.append((vop1_nop_program(), translate))
fixtures.extend((uncompressed_export(body), translate_int, "gfx1013")
for body in (DPP_CVT_FROM_FLOAT, DPP_CVT_TO_FLOAT))
for body in (DPP_CVT_FROM_FLOAT, DPP_CVT_TO_FLOAT, DPP_CVT_FLR_RPI))
fixtures.append((dpp_pkrtz_program(), translate, "gfx1013"))
fixtures.append((with_constants(DPP_EXTRA_BODY), translate, "gfx1013"))
fixtures.append((with_constants(DPP_EXTRA_SEMANTICS_BODY), translate, "gfx1013"))
fixtures.append((uncompressed_export(DPP_EXTRA_SUBNORMAL_BODY), translate_int, "gfx1013"))
Expand Down
27 changes: 27 additions & 0 deletions tools/pixel_aot.py
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,8 @@ def check_vopc_e32_dst(enc, dst):
"cvt_off_f32_i4": (False, "(float(asint({0} << 28) >> 28) * 0.0625f)", None),
"cvt_i32_f32": (True, "asfloat(cvt_i32_f32({0}))", "cvt_i32_f32"),
"cvt_u32_f32": (True, "asfloat(cvt_u32_f32({0}))", "cvt_u32_f32"),
"cvt_flr_i32_f32": (True, "asfloat(cvt_flr_i32_f32({0}))", "cvt_flr_i32_f32"),
"cvt_rpi_i32_f32": (True, "asfloat(cvt_rpi_i32_f32({0}))", "cvt_rpi_i32_f32"),
}
DPP_INT32 = {
"not_b32": (1, "(~{0})", None),
Expand Down Expand Up @@ -5584,6 +5586,31 @@ def sample_coord(reg):
helpers.add(helper)
vector[dst] = f"alu{i}"
lines.append(f" precise float alu{i} = {template.format(bits)};")
elif m := match(r"v_cvt_pkrtz_f16_f32_dpp (v\d+), (.+)"):
# Quad-local DPP16/DPP8 compressed-export pack: src0 is swizzled across the quad,
# src1 stays on the current lane, DPP16 allows abs/neg on either source, and the
# destination holds the same (lo, hi) compressed-export pair as v_cvt_pkrtz_f16_f32_e32.
dst, rest = m.groups()
if mask != "entry" or not 0 <= int(dst[1:]) <= 255:
raise ValueError("Invalid pack DPP operation")
if dst in sample_dest:
raise ValueError("Write overlaps an outstanding sample")
tokens, perm, is_dpp8 = parse_dpp(rest, 2)
s0_val, abs0, neg0 = dpp_vgpr(tokens[0], vector, sample_dest, allow_mods=not is_dpp8)
s1_val, abs1, neg1 = dpp_vgpr(tokens[1], vector, sample_dest, allow_mods=not is_dpp8)
s0_bits = emit_quad_swizzle_u32(lines, i, s0_val, perm)
if abs0:
s0_bits = f"({s0_bits} & 0x7fffffffu)"
if neg0:
s0_bits = f"({s0_bits} ^ 0x80000000u)"
s1_bits = f"asuint({s1_val})"
if abs1:
s1_bits = f"({s1_bits} & 0x7fffffffu)"
if neg1:
s1_bits = f"({s1_bits} ^ 0x80000000u)"
lines.append(f" precise float alu{i}_lo = asfloat({s0_bits});")
lines.append(f" precise float alu{i}_hi = asfloat({s1_bits});")
vector[dst] = (f"alu{i}_lo", f"alu{i}_hi")
elif m := match(rf"({'|'.join(DPP_EXTRA)}) (v\d+), (.+)"):
op, dst, rest = m.groups()
if mask != "entry" or not 0 <= int(dst[1:]) <= 255:
Expand Down
Loading