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: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ The control-flow CPU translator supports [source-built string memory transfers](
| gfx1013 image atomics | Lower [2D `R32_UINT` `image_atomic_add`, `umax` and `cmpswap`](docs/experiments.md#gfx1013-2d-image-atomics) with the gfx1030 lowering and compare every texel of a three-mip texture, including contended adds. | `ctest --preset dev --no-tests=error -R '^compute_store_aot_gfx1013_image_atomics_'` |
| gfx1013 image gathers | Lower [one 2D `image_gather4_l` with a constant sampler and a known integer LOD](docs/experiments.md#gfx1013-2d-explicit-lod-image-gathers) on an RGBA32 FLOAT view. Compare all four taps at three mips and on a view that starts at mip 1. | `ctest --preset dev --no-tests=error -R '^compute_store_aot_gfx1013_gather4_l_'` |
| Startup compute mip-zero gather | Dispatch a [gfx1013 `image_gather4_lz`](docs/experiments.md#compute-mip-zero-gather) and compare four texels from the first visible mip against a CPU reference. | `ctest --preset dev --no-tests=error -R '^startup_compute_gather_lz'` |
| Startup compute FP32 array image store | Bind a [2D-array UAV](docs/experiments/startup-compute-array-uav.md) through the startup runtime, verify the nonzero first slice and per-lane EXEC, and compare every texel after the fence. | `ctest --preset dev --no-tests=error -R '^startup_compute_dispatch_array_'` |
| Startup compute FP32 and packed D16 array image store | Bind a [2D-array UAV](docs/experiments/startup-compute-array-uav.md) through the startup runtime, verify the nonzero first slice and per-lane EXEC, and compare every texel after the fence. | `ctest --preset dev --no-tests=error -R '^startup_compute_dispatch_array_'` |
| Startup compute D16 image store | Write [four packed half-floats](docs/experiments.md#startup-compute-d16-image-store) per active thread and check all three mips. | `ctest --preset dev --no-tests=error -R '^startup_compute_image_store_d16'` |
| Startup explicit-LOD 2D gather | Dispatch and draw [gfx1013 `image_gather4_l`](docs/experiments.md#explicit-lod-2d-gather) across explicit mips, view offsets, clamped edges, and dynamic per-lane LOD against CPU references. | `ctest --preset dev --no-tests=error -R '^startup_compute_gather_l'` |
| Startup compute buffer atomics | Dispatch [gfx1013 32-bit MUBUF raw buffer atomics](docs/experiments.md#startup-compute-raw-buffer-atomics) with thread contention, `glc` old-value returns, `cmpswap` order, and `EXEC` masking. | `ctest --preset dev --no-tests=error -R '^startup_compute_buffer_atomics'` |
Expand Down
18 changes: 11 additions & 7 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -15146,12 +15146,13 @@ ctest --preset release --no-tests=error -R '^startup_compute_gather_lz(_warp|_ha

### Startup compute D16 image store

The startup compute translator accepts a 2D `image_store d16` with all four
DMASK bits set, full-width X/Y and eight intact image descriptor words from a
fixed table offset. The R/G half-floats occupy the low/high halves of the first
The startup compute translator accepts 2D and 2D-array `image_store d16`
with all four DMASK bits set, full-width X/Y (and layer for an array), and eight
intact image descriptor words from a fixed table offset. The R/G half-floats occupy the low/high halves of the first
data VGPR. B/A occupy the second. The translator widens the four halves for a
typed UAV store under the lane's EXEC bit. The version 2 compute manifest
records `uav N tex2d float table P O channels 4`. Raw buffer and texture UAVs
records `uav N tex2d float table P O channels 4` or, for an array,
`uav N tex2da float table P O channels 4`. Raw buffer and texture UAVs
share a register index space. The consumer must validate the bound view against
its dimension and float type. [AMD RDNA 2 ISA, §§8.2.1 and 8.2.5](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content)

Expand All @@ -15161,7 +15162,10 @@ write 16 texels to mip zero of an RGBA16_FLOAT UAV. Each run compares all 1,344
half-words across three mips, including signed zeros, subnormals and untouched
texels. A second program masks out the second row. Omitting the store, swapping
R/G, swapping the packed registers and dropping the EXEC guard produce 64, 32,
64 and 32 differences respectively. Slot-67 runtime binding is tracked in #2274.
64 and 32 differences respectively. Slot-67 2D runtime binding is tracked in #2274.
The [array UAV runtime fixture](experiments/startup-compute-array-uav.md) also
checks packed D16 through the production slot-67/slot-14 path with a nonzero
FirstArraySlice, all six physical slices and five negative controls.

```powershell
cmake --build --preset release --target offscreen_check
Expand All @@ -15175,8 +15179,8 @@ dim:SQ_RSRC_IMG_2D_ARRAY with three full-width address VGPRs for x, y and layer.
It emits an RWTexture2DArray<float4> store under the lane EXEC bit and records
uav N tex2da float table P O channels 4 in the version 2 manifest.
The [startup runtime array UAV binding](experiments/startup-compute-array-uav.md)
consumes this manifest. Pixel arrays,
packed D16 arrays and the 1D, 3D and cube store forms remain refused.
consumes this manifest for full-mask FP32 and packed D16 compute stores.
Pixel arrays and the 1D, 3D and cube store forms remain refused.

The standalone GPU fixture writes the same four words into mip zero of layer 1
and layer 3 of a four-layer allocation. It compares all 5,376 words and detects
Expand Down
23 changes: 19 additions & 4 deletions docs/experiments/startup-compute-array-uav.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
# Startup compute FP32 array UAV binding
# Startup compute FP32 and packed D16 array UAV binding

Refs [#2742](https://github.com/R0Y00/Xbox2Windows/issues/2742).
Depends on the full-mask FP32 compute array image store lowering in
[#2744](https://github.com/R0Y00/Xbox2Windows/pull/2744). Pixel and packed-half
array stores remain refused.
[#2744](https://github.com/R0Y00/Xbox2Windows/pull/2744) and the production
binding in [#2777](https://github.com/R0Y00/Xbox2Windows/pull/2777). Packed
D16 compute stores reuse that binding and the existing 2D two-VGPR lowering;
no new manifest or runtime path is needed. Pixel array stores remain refused.

The production startup compute manifest consumer accepts
`uav N tex2da float table P O channels 4`. It requires an explicitly described
Expand All @@ -22,11 +24,24 @@ partial EXEC are checked for both layers. The wrong-layer and dropped-EXEC
controls must differ by 128 and 32 words respectively. A mismatched 2D view
must be refused with all 1,024 words untouched.

The packed D16 case uses the same 32x8 six-slice allocation with
RGBA16_FLOAT and a 256-byte row pitch. Packed VGPRs 0xc0003c00 and
0x7bff3800 produce half encodings 0x3c00, 0xc000, 0x3800 and 0x7bff
(R/G/B/A). The reference compares all 6,144 raw halfwords after the fence.
For each relative layer (1 and 3), full and partial EXEC must have no
mismatches. The wrong-layer, dropped-EXEC, swapped first two halves, swapped
VGPRs and omitted-store controls must differ by 128, 32, 32, 64 and 64
halfwords respectively; each mutated output is also compared with its own
CPU reference. An incompatible RGBA16_FLOAT 2D view must be refused with
1,024 halfwords unchanged. Before translation, all six slices must remain
unchanged. The source-built instruction sequences for both layers and EXEC
variants are checked against LLVM 15 with the D16 translation controls.

Reproduce on Windows (source-built fixtures only):

```powershell
cmake --build --preset dev --target startup_stream_consumer offscreen_check
ctest --preset dev --no-tests=error -j 1 -R '^startup_compute_dispatch_array_(warp|hardware)$' -V
ctest --preset dev --no-tests=error -j 1 -R '^startup_compute_dispatch_array(_d16)?_(warp|hardware)$' -V
```

No game input, retail program coverage, title execution or guest
Expand Down
4 changes: 4 additions & 0 deletions tests/cmake/startup_compute_dispatch_array.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ if(EXISTS "${INTAKE_PYTHON}" AND TARGET startup_stream_consumer)
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_array_check.py" "$<TARGET_FILE:startup_stream_consumer>"
"${DXC_EXECUTABLE}" ${adapter})
set_tests_properties(startup_compute_dispatch_array_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77)
add_test(NAME startup_compute_dispatch_array_d16_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_compute_dispatch_array_check.py" "$<TARGET_FILE:startup_stream_consumer>"
"${DXC_EXECUTABLE}" ${adapter} --d16)
set_tests_properties(startup_compute_dispatch_array_d16_${adapter} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77)
endforeach()
endif()
86 changes: 53 additions & 33 deletions tests/startup_compute_dispatch_array_check.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Startup FP32 array UAV binding through the production slot-67 / slot-14 path (#2742)."""
"""Startup FP32 and packed D16 array UAV binding through the production slot-67 / slot-14 path (#2742)."""
import os
from pathlib import Path
import subprocess
import sys
import tempfile

import startup_compute_image_store_check as A
import startup_compute_image_store_d16_check as D
import startup_compute_dispatch_texture_check as T
from startup_compute_request_check import DATA, prepare
from startup_compute_translate_check import state_a
Expand All @@ -14,35 +15,40 @@
WORDS = WIDTH * HEIGHT * 4


def reference(layer=None, rows=2, layers=LAYERS):
result = [0xbf000000 | (z << 12) | i for z in range(layers) for i in range(WORDS)]
def reference(layer=None, rows=2, layers=LAYERS, d16=False, values=None):
result = ([0x5000 + i for i in range(layers * WORDS)] if d16 else
[0xbf000000 | (z << 12) | i for z in range(layers) for i in range(WORDS)])
if values is None:
values = D.ARRAY_VALUES if d16 else A.ARRAY_VALUES
if layer is not None:
for y in range(rows):
for x in range(4 * A.fixture.GROUPS):
at = (FIRST + layer) * WORDS + (y * WIDTH + x) * 4
result[at:at + 4] = A.ARRAY_VALUES
result[at:at + 4] = values
return result


def check(directory, consumer, dxc, adapter, layer, masked):
def check(directory, consumer, dxc, adapter, layer, masked, d16=False):
cache, env = prepare(directory)
env.update(X2W_D3D12_LIST_NOOP="1", X2W_D3D12_DEBUG="1")
if adapter == "hardware":
env["X2W_TEST_DISPATCH_HARDWARE"] = "1"
(directory / "compute_root").write_bytes(T.C.root_blob(3, table_range=True))
env["X2W_TEST_COMPUTE_ROOT"] = str(directory / "compute_root")
program = A.array_program(layer)
if masked:
program = D.array_program(layer, masked) if d16 else A.array_program(layer)
if masked and not d16:
assert program.count(A.ARRAY_STORE) == 1
program = program.replace(A.ARRAY_STORE, A.MASK + A.ARRAY_STORE)
(directory / "program").write_bytes(program)
(directory / "data").write_bytes(DATA)
(directory / "state").write_bytes(state_a(A.fixture.GROUP, A.RSRC2))
layout = "<%dI" % (WORDS * LAYERS)
mode = "texture-array"
layout = ("<%dH" if d16 else "<%dI") % (WORDS * LAYERS)
mode = "texture-array-d16" if d16 else "texture-array"
unit = "halves" if d16 else "words"
store = D.ARRAY_LINE if d16 else A.ARRAY_LINE
got, result = T.run(directory, consumer, env, mode, layout)
print(result.stdout, end="")
assert got == reference(), "untranslated dispatch wrote the texture"
assert got == reference(d16=d16), "untranslated dispatch wrote the texture"
assert len(T.lines(result, "Dispatch(2, 1, 1) refused: no translation")) == 1, result.stderr[-3000:]
key = int(T.lines(result, "x2w-draw compute request")[0].split()[3], 16)
T.translate(cache, dxc, key)
Expand All @@ -52,54 +58,68 @@ def check(directory, consumer, dxc, adapter, layer, masked):
cso = cache / f"{key:016x}.cs.cso"
source = hlsl.read_text()
assert "RWTexture2DArray<float4> w0 : register(u0);" in source
expected = reference(layer, 1 if masked else 2)
expected = reference(layer, 1 if masked else 2, d16=d16)
assert store in source
assert sum(a != b for a, b in zip(reference(d16=d16), expected, strict=True)) == (32 if masked else 64)
got, result = T.run(directory, consumer, env, mode, layout)
assert len(T.lines(result, "Dispatch(2, 1, 1) translated")) == 1, result.stderr[-3000:]
debug = T.clean(result)
wrong = sum(a != b for a, b in zip(got, expected))
assert wrong == 0, (layer, masked, wrong)
print(f"{adapter}: relative layer {layer}, physical layer {FIRST + layer}, partial EXEC={masked}: "
f"{len(got)} words, mismatches={wrong}; debug layer: {debug}", flush=True)
f"{len(got)} {unit}, mismatches={wrong}; debug layer: {debug}", flush=True)

# The actual runtime must refuse a plain 2D view of the same format before dispatch.
got, result = T.run(directory, consumer, env, "texture-array-2d", "<%dI" % WORDS)
assert got == reference(layers=1)
got, result = T.run(directory, consumer, env, "texture-store" if d16 else "texture-array-2d",
("<%dH" if d16 else "<%dI") % WORDS)
assert got == reference(layers=1, d16=d16)
refusal = T.lines(result, "Dispatch(2, 1, 1) refused:")
assert len(refusal) == 1 and refusal[0].endswith("an output texture view is not a 2D array"), result.stderr[-3000:]
assert not T.lines(result, "Dispatch(2, 1, 1) translated")
print(f"{adapter}: incompatible 2D UAV refused; {len(got)} words unchanged", flush=True)
print(f"{adapter}: incompatible 2D UAV refused; {len(got)} {unit} unchanged", flush=True)

# Negative controls run through the same production binding, not the offscreen shortcut.
guard = "if (exec & 1) " + A.ARRAY_LINE
guard = "if (exec & 1) " + store
if masked:
assert source.count(guard) == 1
mutant = source.replace(guard, A.ARRAY_LINE)
label, count = "dropped EXEC", 32
cases = [("dropped EXEC", source.replace(guard, store), reference(layer, d16=d16), 32)]
else:
index = "uint3(v8, v9, v10)"
assert source.count(index) == 1
delta = "+ 1u" if layer == 1 else "- 1u"
mutant = source.replace(index, f"uint3(v8, v9, v10 {delta})")
label, count = "wrong layer", 128
hlsl.write_text(mutant, encoding="ascii")
subprocess.run([dxc, "-Gis", "-T", "cs_6_0", "-E", "main", "-Fo", cso, hlsl], check=True)
got, result = T.run(directory, consumer, env, mode, layout)
assert len(T.lines(result, "Dispatch(2, 1, 1) translated")) == 1, result.stderr[-3000:]
T.clean(result)
wrong = sum(a != b for a, b in zip(got, expected))
assert wrong == count, (layer, label, wrong, count)
print(f"{adapter}: {label} control: {len(got)} words, mismatches={wrong} (expected {count})", flush=True)
cases = [("wrong layer", source.replace(index, f"uint3(v8, v9, v10 {delta})"),
reference(2, d16=d16), 128)]
if d16 and layer == 1:
parts = ", ".join(D.PARTS)
assert source.count(parts) == 1 and source.count(store) == 1
for label, order, count in (("swap halves", (1, 0, 2, 3), 32),
("swap VGPRs", (2, 3, 0, 1), 64)):
cases.append((label, source.replace(parts, ", ".join(D.PARTS[i] for i in order)),
reference(layer, d16=True, values=tuple(D.ARRAY_VALUES[i] for i in order)), count))
cases.append(("omit store", source.replace(store, ""), reference(d16=True), 64))
for label, mutant, control_reference, count in cases:
assert mutant != source
predicted = sum(a != b for a, b in zip(control_reference, expected, strict=True))
assert predicted == count, (layer, label, predicted, count)
hlsl.write_text(mutant, encoding="ascii")
subprocess.run([dxc, "-Gis", "-T", "cs_6_0", "-E", "main", "-Fo", cso, hlsl], check=True)
got, result = T.run(directory, consumer, env, mode, layout)
assert len(T.lines(result, "Dispatch(2, 1, 1) translated")) == 1, result.stderr[-3000:]
T.clean(result)
wrong = sum(a != b for a, b in zip(got, expected, strict=True))
assert wrong == predicted and got == control_reference, (layer, label, wrong, predicted)
print(f"{adapter}: {label} control: {len(got)} {unit}, mismatches={wrong} (expected {predicted})", flush=True)


def main(consumer, dxc, adapter):
def main(consumer, dxc, adapter, d16=False):
with tempfile.TemporaryDirectory() as temp:
for layer in (1, 3):
for masked in (False, True):
check(Path(temp) / f"layer-{layer}-{masked}", consumer, dxc, adapter, layer, masked)
print(f"startup_compute_dispatch_array: PASS on {adapter}")
check(Path(temp) / f"layer-{layer}-{masked}", consumer, dxc, adapter, layer, masked, d16)
print(f"startup_compute_dispatch_array{'_d16' if d16 else ''}: PASS on {adapter}")


if __name__ == "__main__":
if len(sys.argv) != 4 or sys.argv[3] not in ("warp", "hardware"):
if len(sys.argv) not in (4, 5) or sys.argv[3] not in ("warp", "hardware") or (len(sys.argv) == 5 and sys.argv[4] != "--d16"):
sys.exit(__doc__)
main(*sys.argv[1:])
main(*sys.argv[1:4], d16=len(sys.argv) == 5)
2 changes: 0 additions & 2 deletions tests/startup_compute_image_store_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ def encoded(line, hex_words):
assert not set(ARRAY_VALUES) & set(G.D.INLINE_FLOAT_LITERALS), G.D.INLINE_FLOAT_LITERALS
# The array address is exactly x, y and layer: a two- or four-register address is refused.
array_mods = ['dmask:0xf', 'dim:SQ_RSRC_IMG_2D_ARRAY']
refused('compute image_store d16 requires a 2D image',
lambda: pipe.cs.op_image_store(['v[14:15]', 'v[8:10]', 's[24:31]'], array_mods + ['d16']))
for address in ('v[8:9]', 'v[8:11]'):
refused('x, y and layer expected',
lambda: pipe.cs.op_image_store(['v[14:17]', address, 's[24:31]'], array_mods))
Expand Down
Loading
Loading