diff --git a/CMakeLists.txt b/CMakeLists.txt index 5da721cd70..0986b851ef 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2063,6 +2063,9 @@ if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${ add_test(NAME native_direct_mesh COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/native_direct_mesh_check.py" "$" "${DXC_BIN_DIR}") + add_test(NAME native_fixed_graphics_psi1 + COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/native_fixed_graphics_psi1_check.py" + "$" "${DXC_BIN_DIR}") add_executable(native_frozen_request_check tests/native_frozen_request_check.cpp) target_include_directories(native_frozen_request_check PRIVATE src) target_compile_features(native_frozen_request_check PRIVATE cxx_std_17) diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index ab7ff78833..e363e5c94d 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -698,11 +698,27 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view bool exact_pixel_code = false; Bytes entry; const bool fixed_entry = pixel_entry.size() == 12 && pixel_entry.substr(0,4) == "PSI1"; - if (fixed_entry && !reflected) - throw UnsupportedComputeShader("fixed graphics entry requires matching stage interfaces"); bool packed_xy = false; std::optional captured_interp_count; std::optional> stage_wave32; + if (fixed_entry && !reflected) { + // Fixed slot 57 exposes SPI_PS_INPUT_ADDR and SPI_PS_IN_CONTROL but no .cdxil + // sidecar. The raw frontend derives both stage interfaces from the programs; + // hand it the same psin1 record the reflected path would build. + uint32_t address, interpolants; + std::memcpy(&address, pixel_entry.data() + 4, 4); + std::memcpy(&interpolants, pixel_entry.data() + 8, 4); + if (address != 2 && address != 0x8002) + throw UnsupportedComputeShader("unsupported fixed pixel entry layout"); + if (!interpolants || interpolants > 7) + throw UnsupportedComputeShader("unsupported fixed pixel entry control"); + captured_interp_count = interpolants; + packed_xy = address == 0x8002; + entry = "psin1"; + word(entry, address); + word(entry, address); + pixel_entry = entry; + } if (reflected) { for (size_t i = 0; i < companions.size(); ++i) { bool exact = false; @@ -772,8 +788,15 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view interfaces.at(GpuStage::ps).target_components = targets; pair = translate_reflected_graphics(interfaces.at(GpuStage::vs),interfaces.at(GpuStage::ps),layout); } else pair = translate_graphics_pair(a, b, layout, pixel_entry, first_stage, targets, stage_wave32); + if (fixed_entry && !reflected && captured_interp_count) { + for (const auto &r : pair.pixel.inputs) { + if (r.kind == 28 || r.name == "SV_Position") continue; + if (r.name != "TEXCOORD" || r.index / 4 >= *captured_interp_count) + throw UnsupportedComputeShader("raw interpolation exceeds captured pixel entry"); + } + } pair.target_components = targets; - if (!entry.empty()) { + if (!entry.empty() && reflected) { const auto &attrs = interfaces.at(GpuStage::ps).attributes; std::vector channels(attrs.size()); for (const auto &r : pair.pixel.inputs) { diff --git a/tests/native_fixed_graphics_psi1_check.py b/tests/native_fixed_graphics_psi1_check.py new file mode 100644 index 0000000000..9b2f578847 --- /dev/null +++ b/tests/native_fixed_graphics_psi1_check.py @@ -0,0 +1,102 @@ +"""Fixed VS/PS pairs with a slot-57 PSI1 entry and no reviewed .cdxil sidecar. + +The fixtures are source-built raw gfx1013 programs. The test derives the +minimal pixel interface from SPI_PS_INPUT_ADDR, SPI_PS_IN_CONTROL and the +programs themselves, and checks that unsupported masks or a contradictory +interface are refused before any stage is published. +""" +import pathlib +import struct +import subprocess +import sys +import tempfile + +from native_direct_container_check import publish, words + + +END = 0xBF810000 +VS = words(0x7E0002F2, 0xF80008CF, 0, 0xF800020F, 0, 0xF800021F, 0, END) +ROOT = b"DXBC" + bytes(16) + words(1, 68, 1, 36) + b"RTS0" + words(24, 2, 0, 24, 0, 24, 0) + + +def interpolate(attr, channel, op, dst, src): + return 0xC8000000 | dst << 18 | op << 16 | attr << 10 | channel << 8 | src + + +def center_pixel(): + prefix = [0xD5800000, 255, 17, 0xD5800000, 255, 23] + return words(*prefix, interpolate(0, 0, 0, 4, 0), interpolate(0, 0, 1, 4, 1), + 0xF800180F, 0x04040404, END) + + +def two_attribute_pixel(): + prefix = [0xD5800000, 255, 17, 0xD5800000, 255, 23] + return words(*prefix, interpolate(0, 0, 0, 4, 0), interpolate(0, 0, 1, 4, 1), + interpolate(1, 0, 0, 6, 0), interpolate(1, 0, 1, 6, 1), + 0xF800180F, 0x06060606, END) + + +def packed_position_pixel(): + # SPI_PS_INPUT_ADDR bit 15 delivers the packed screen coordinate in v2. + return words(0x7E000302, 0xF800180F, 0x01010101, END) + + +def main(compiler, sdk): + compiler, sdk = pathlib.Path(compiler), pathlib.Path(sdk) + with tempfile.TemporaryDirectory() as tmp: + base = pathlib.Path(tmp) + cache = base / "cache" + + def compile_case(name, pixel, entry, expected=None, expect_hit=None): + requests = base / (name + "-requests") + output = base / (name + "-output") + key = publish(requests, pixel, VS, ROOT, slot57_inputs=entry) + result = subprocess.run( + [compiler, sdk, cache, "gfx1013-container-pair", "--requests", requests, output], + capture_output=True, text=True) + if expected is not None: + assert result.returncode and expected in result.stderr, (result.stdout, result.stderr) + assert not list(output.glob("*.cso")), (name, sorted(p.name for p in output.glob("*"))) + return None + assert result.returncode == 0, (name, result.stdout, result.stderr) + for stage in ("vs", "ps"): + assert (output / f"{key}.{stage}.cso").read_bytes().startswith(b"DXBC"), (name, stage) + if expect_hit is not None: + assert f"frontend_cache_hit={expect_hit}" in result.stdout, result.stdout + return key, output + + # The base refusal: a fixed pair with PSI1 and only raw programs. + key, output = compile_case("center", center_pixel(), (2, 1)) + dump = subprocess.check_output( + [sdk / "dxc.exe", "-dumpbin", output / f"{key}.ps.cso"], text=True) + assert "loadInput.f32" in dump and "TEXCOORD" in dump, dump + + # A second lookup uses the published frontend pair rather than a sidecar. + compile_case("center", center_pixel(), (2, 1), expect_hit=1) + + # The reviewed interface uses ADDR 0x302 for this captured 0x8002 mask. + # Without a sidecar the raw address still allocates the packed XY VGPR. + key, output = compile_case("packed", packed_position_pixel(), (0x8002, 1)) + dump = subprocess.check_output( + [sdk / "dxc.exe", "-dumpbin", output / f"{key}.ps.cso"], text=True) + assert "SV_Position" in dump or "loadInput" in dump, dump + + # Only the two reviewed address forms are accepted without an interface. + for address in (0x8003, 0x302, 3): + compile_case(f"address-{address:04x}", center_pixel(), (address, 1), + expected="unsupported fixed pixel entry layout") + compile_case("control-flags", center_pixel(), (2, 0x10), + expected="unsupported fixed pixel entry control") + + # A raw PS that interpolates more rows than SPI_PS_IN_CONTROL says + # contradicts the captured entry, even when the VS exports those rows. + compile_case("too-many-interpolants", two_attribute_pixel(), (2, 1), + expected="raw interpolation exceeds captured pixel entry") + + # ADDR 2 does not allocate the packed position VGPR that this PS reads. + compile_case("packed-without-address", packed_position_pixel(), (2, 1), + expected="unsupported pixel entry VGPR 2") + + +if __name__ == "__main__": + main(*sys.argv[1:])