From 9a1b35f99beaf0c727f5e421a4aac93a4184a5ba Mon Sep 17 00:00:00 2001 From: Leyukaka <45659323+Leyukaka@users.noreply.github.com> Date: Sun, 29 Nov 2026 22:39:05 +0100 Subject: [PATCH 1/3] native: admit reviewed zero-interpolant fixed pixel entries --- src/direct_compute_cache.cpp | 23 ++++--- src/gfx1013_direct_graphics.inl | 2 + src/guest_shader_container.h | 1 + ...native_graphics_interface_library_check.py | 66 +++++++++++++++++-- tests/startup_native_graphics_draw_check.py | 48 ++++++++++++-- 5 files changed, 123 insertions(+), 17 deletions(-) diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index 8cceb9747f..cdb82933d2 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -811,6 +811,7 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view // consequently v1, while the existing 0x8002 layout places it at v2. const bool packed_position_only = fixed_entry && address == 0x8080 && interpolants == 0; bool packed_xy = false; + bool float_position_only = false; std::optional captured_interp_count; std::optional> stage_wave32; if (fixed_entry && !reflected) { @@ -849,16 +850,16 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view // Fixed slot 57 supplies ADDR and NUM_INTERP, not ENA. Intersect // the observed ABI with the reviewed stage and the raw consumers. if (!packed_position_only) { - if (!interpolants || interpolants > 7 || interpolants > pixel_defaults.attributes.size()) + if ((!interpolants && !exact_pair) || interpolants > 7 || interpolants > pixel_defaults.attributes.size()) throw UnsupportedComputeShader("captured interpolation count disagrees with pixel interface"); - packed_xy = address == 0x8002 && pixel_defaults.pixel_input_address == 0x302; - if (!(address == 2 && pixel_defaults.pixel_input_address == 2) && !packed_xy) + const bool matched_address = address == pixel_defaults.pixel_input_address; + float_position_only = !interpolants && matched_address && address && !(address & ~0x0f00u); + packed_xy = interpolants && address == 0x8002 && pixel_defaults.pixel_input_address == 0x302; + if (!(matched_address && (address == 2 || (!interpolants && address == 0))) && + !float_position_only && !packed_xy) throw UnsupportedComputeShader("unsupported fixed pixel entry layout"); } captured_interp_count = interpolants; - // Center I/J and, in the specialized position variant, packed XY - // are the supported inputs. The frontend checks each register - // use and the linked inputs are checked below. entry = "psin1"; word(entry, address); word(entry, address); @@ -874,8 +875,10 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view if (enable_mask > 0xffff || address_mask > 0xffff || (enable_mask & ~address_mask)) throw UnsupportedComputeShader("contradictory pixel input enable/address masks"); exact_pair = ps.pixel_input_address == address_mask; - if (exact_pair) + if (exact_pair) { ps.pixel_input_enable = enable_mask; + ps.pixel_interpolant_count = captured_interp_count; + } } if (pixel_entry.empty() && !exact_pair) { const auto &ps = interfaces.at(GpuStage::ps); @@ -918,15 +921,17 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view const auto &attrs = interfaces.at(GpuStage::ps).attributes; std::vector channels(attrs.size()); for (const auto &r : pair.pixel.inputs) { - if (r.kind == 28 && r.interpolation == 2) continue; + if (r.kind == 28 && r.interpolation == 2 && captured_interp_count != 0) continue; if (packed_xy && r.kind == 3 && r.name == "SV_Position" && r.first == 0 && r.index == 0 && r.width == 4 && r.interpolation == 4) continue; + if (float_position_only && r.kind == 3 && r.name == "SV_Position" && r.component == 9 && + r.index == 0 && r.interpolation == 4) continue; // Fixed pipelines may specialize individual components from // P1/P2 to VINTRP_MOV P0. The raw front end links each observed // component to a VS PARAM channel and emits flat mode only for // that P0 instruction. It may drop unused reflected rows, too. if (r.name != "TEXCOORD" || r.index / 4 >= channels.size() || - (captured_interp_count && r.index / 4 >= *captured_interp_count) || + (!exact_pair && captured_interp_count && r.index / 4 >= *captured_interp_count) || (r.interpolation != 2 && !(fixed_entry && r.interpolation == 1)) || r.width != 1 || r.first != r.index % 4) throw UnsupportedComputeShader("raw and reflected interpolation inputs disagree"); diff --git a/src/gfx1013_direct_graphics.inl b/src/gfx1013_direct_graphics.inl index 0ee9bd2fc7..ad5dcef4cf 100644 --- a/src/gfx1013_direct_graphics.inl +++ b/src/gfx1013_direct_graphics.inl @@ -44,6 +44,8 @@ struct GraphicsStage { dest = 256 + ((w >> 18) & 255); if (!pixel) refuse(pc, "interpolation outside pixel stage"); + if (stage.pixel_interpolant_count && attr >= *stage.pixel_interpolant_count) + refuse(pc, "raw and reflected interpolation inputs disagree"); const auto it = std::find_if(stage.attributes.begin(), stage.attributes.end(), [&](auto &a) { return a.location == attr && (a.mask & (1u << channel)); }); if (it == stage.attributes.end() || it->usage != 6 || (it->flags & 0x18)) diff --git a/src/guest_shader_container.h b/src/guest_shader_container.h index 16445b03a9..269cf27414 100644 --- a/src/guest_shader_container.h +++ b/src/guest_shader_container.h @@ -47,6 +47,7 @@ struct GuestShaderStage { std::vector exports; std::vector input_signature, output_signature; unsigned pixel_input_address{}, pixel_input_enable = ~0u, depth_control{}; + std::optional pixel_interpolant_count; // The signature component (9 f32, 5 u32, 4 i32) an RTV variant request asks of each color target; 0 when none. std::array target_components{}; unsigned mesh_clip_control{}, max_vertices{}, max_primitives{}, topology{}; diff --git a/tests/native_graphics_interface_library_check.py b/tests/native_graphics_interface_library_check.py index d15946f7a0..5fc549d14d 100644 --- a/tests/native_graphics_interface_library_check.py +++ b/tests/native_graphics_interface_library_check.py @@ -5,10 +5,50 @@ import sys import tempfile -from native_direct_container_check import patched_pixel, publish, vertex, words +from native_direct_container_check import patched_pixel, publish, signature, vertex, words from startup_run_ps1_check import OLDER_CACHE, RUN_PS1, run_case +END = 0xbf810000 +EMBEDDED_ID = [0xd5800000, 255, 17, 0xd5800000, 255, 23] + + +def interpolate(attr, channel, op, dst, src): + return 0xc8000000 | dst << 18 | op << 16 | attr << 10 | channel << 8 | src + + +def fixed_pixel(program, address, sources, **metadata): + export = (0xf800180f, sources) + return (words(*program, *export, END), + patched_pixel(len(program), program, input_address=address, export=export, **metadata)) + + +def zero_fixed_cases(): + # v2 = 0, v3 = 1. At 0x100/0x300 the entry places float X/XY in v0/v1. + constants = [0x7e040280, 0x7e0602f2] + position = ((b"ISG1", signature(b"SV_Position", 1)),) + for address, sources in ((0, 0x03020203), (2, 0x03020203), (0x100, 0x03020200), (0x300, 0x03020100)): + yield address, fixed_pixel(constants, address, sources, + input_signature=position if address & 0x300 else ()) + + +def fixed_slot57_job(base, name, run, batch, cache, root, raw_vs, reviewed_vs, raw_ps, reviewed_ps, entry, + expected=None): + case = base / name + case.mkdir() + library = case / "library" + library.mkdir() + (library / "vertex.cdxil").write_bytes(reviewed_vs) + (library / "pixel.cdxil").write_bytes(reviewed_ps) + run("--index-graphics-interfaces", library, cache) + requests, output = case / "requests", case / "output" + stem = publish(requests, raw_ps, raw_vs, root, slot57_inputs=entry) + batch(requests, output, expected=expected) + for suffix in (".vs.cso", ".ps.cso", ".txt"): + assert (output / (stem + suffix)).exists() == (expected is None), (name, suffix) + return output, stem + + def main(compiler, sdk): def run(*args, expected=None): result = subprocess.run([compiler, *args], capture_output=True, text=True) @@ -25,7 +65,7 @@ def run(*args, expected=None): # The old raw reader has no PS state for this scalar branch. Exact # native programs recover the full stage ABI from the catalog. branch = [0xbf008180, 0xbf850002, 0x7e0002f2, 0xbf820001, 0x7e0002f4] - prefix = [0xd5800000, 255, 17, 0xd5800000, 255, 23] + prefix = EMBEDDED_ID program = prefix + branch end = 0xbf810000 vs = words(0x7e020b00, 0xf80008cf, 0x01010101, end) @@ -87,8 +127,6 @@ def tree(folder): fixed.mkdir() vp = [0x7e0002f2, 0xf80008cf, 0, 0xf800020f, 0, 0xf800021f, 0, end] (fixed / "varying.cdxil").write_bytes(vertex(program=vp)) - def interpolate(attr, channel, op, dst, src): - return 0xc8000000 | dst << 18 | op << 16 | attr << 10 | channel << 8 | src template = prefix + [interpolate(0, 0, 0, 4, 0), interpolate(0, 0, 1, 4, 1)] attributes = [(6, row, 15, row, 0, 0, row, 2) for row in range(2)] (fixed / "smooth.cdxil").write_bytes(patched_pixel( @@ -118,6 +156,26 @@ def interpolate(attr, channel, op, dst, src): publish(folder, code, words(*producer), root, slot57_inputs=(2, 1)) batch(folder, base / f"raw-linked-{mask}", expected=None if mask == 15 else "graphics stages disagree") + def slot57(name, raw_ps, reviewed_ps, entry, expected=None): + return fixed_slot57_job(base, name, run, batch, cache, root, vs, vertex(), raw_ps, reviewed_ps, entry, + expected) + + for address, (raw_ps, reviewed_ps) in zero_fixed_cases(): + slot57(f"zero-{address:x}", raw_ps, reviewed_ps, (address, 0)) + if address == 0x100: + slot57("zero-position-mismatch", raw_ps, reviewed_ps, (0x300, 0), + "unsupported fixed pixel entry layout") + raw_ps, reviewed_ps = fixed_pixel([0x7e0402f2], 0x102, 0x04040404) + slot57("zero-center-position", raw_ps, reviewed_ps, (0x102, 0), "unsupported fixed pixel entry layout") + raw_ps, reviewed_ps = fixed_pixel([*prefix, 0x7e0002f2], 2, 0) + slot57("zero-inexact", raw_ps[:24] + words(0xbf800000) + raw_ps[24:], reviewed_ps, (2, 0), + "captured interpolation count disagrees with pixel interface") + raw_ps, reviewed_ps = fixed_pixel(template, 2, 0x04040404, attributes=[(6, 1, 1, 0, 0, 0, 0, 2)], + input_signature=((b"ISG1", signature(b"TEXCOORD", row=1, mask=1)),)) + slot57("zero-param", raw_ps, reviewed_ps, (2, 0), "raw and reflected interpolation inputs disagree") + raw_ps, reviewed_ps = fixed_pixel([0x7e0402f2], 2, 0x04000000) + slot57("zero-barycentrics", raw_ps, reviewed_ps, (2, 0), "raw and reflected interpolation inputs disagree") + # An exact VS writes a four-component image through the second # guest slot. The serialized root covers just the first slot. # The FSSM offset, descriptor width, class and SGPR establish the diff --git a/tests/startup_native_graphics_draw_check.py b/tests/startup_native_graphics_draw_check.py index b62230cca7..51d5dfb3f9 100644 --- a/tests/startup_native_graphics_draw_check.py +++ b/tests/startup_native_graphics_draw_check.py @@ -6,23 +6,50 @@ import tempfile from pathlib import Path -from native_direct_container_check import patched_pixel, vertex +from native_direct_container_check import patched_pixel, vertex, words +from native_graphics_interface_library_check import zero_fixed_cases from startup_stream_draw_check import vop1, vop2 -def triangle(): +def triangle_program(): code = [vop2(0x1a, 1, 129, 0), vop2(0x1b, 1, 130, 1), vop2(0x1b, 2, 130, 0)] for v in (1, 2): code.extend([vop1(6, v, 256 + v), vop2(8, v, 244, v), vop2(3, v, 243, v)]) code.extend([vop1(1, 3, 128), vop1(1, 4, 242), 0xf80008cf, 0x04030201, 0xbf810000]) - return vertex(program=code) + return code + + +def draw_slot57(folder, consumer, adapter, compiler, env, entry, raw_vs, reviewed_vs, raw_ps, reviewed_ps): + folder.mkdir() + library, cache = folder / "library", folder / "cache" + library.mkdir() + cache.mkdir() + (library / "vertex.cdxil").write_bytes(reviewed_vs) + (library / "pixel.cdxil").write_bytes(reviewed_ps) + subprocess.run([compiler, "--index-graphics-interfaces", library, cache], check=True, timeout=45) + vs, ps, root, pixels = [folder / name for name in ("vs", "ps", "root", "pixels")] + vs.write_bytes(raw_vs) + ps.write_bytes(raw_ps) + address, count = entry + result = subprocess.run([consumer, vs, ps, root, adapter, pixels, "slot57", f"58:{address:x},5c:{count:x}"], + env=dict(env, X2W_SHADER_CACHE=str(cache), X2W_NATIVE_SHADERS_ONLY="1"), + capture_output=True, text=True, timeout=45) + assert result.returncode == 0 and "ready=1 cache(frontend,vs,ps)=0,0,0" in result.stderr, result.stderr + assert "-> drawn;" in result.stderr, result.stderr + assert [p.read_bytes() for p in cache.glob("*.ps57in")] == [b"PSI1" + words(*entry)] + for line in result.stderr.splitlines(): + if "x2w-d3d12-debug " in line: + assert " sev=0 " not in line and " sev=1 " not in line, line + return pixels.read_bytes() def check(folder, consumer, sdk, adapter, compiler): cache = folder / "cache" cache.mkdir() vs, ps, root, pixels = [folder / name for name in ("vs", "ps", "root", "pixels")] - vs.write_bytes(triangle()) + triangle = triangle_program() + reviewed_vs = vertex(program=triangle) + vs.write_bytes(reviewed_vs) ps.write_bytes(patched_pixel(2, [vop1(1, 0, 128), vop1(1, 1, 242)], export=(0xf800180f, 0x01000001))) env = dict(os.environ, X2W_SHADER_CACHE=str(cache), X2W_NATIVE_SHADERS=sdk, X2W_D3D12_DEBUG="1", X2W_D3D12_RENDER="1", X2W_D3D12_PERMISSIVE="1", X2W_D3D12_LIST_NOOP="1") @@ -78,6 +105,19 @@ def check(folder, consumer, sdk, adapter, compiler): assert run.returncode == 0 and "refused:" in run.stderr and "-> drawn;" not in run.stderr, run.stderr assert pixels.read_bytes() == clear * 32 print("unsupported stage: all 32 pixels retain the clear color") + for address, (raw_ps, reviewed_ps) in zero_fixed_cases(): + image = draw_slot57(folder / f"slot57-zero-{address:x}", consumer, adapter, compiler, env, (address, 0), + words(*triangle), reviewed_vs, raw_ps, reviewed_ps) + assert len(image) == 8 * 4 * 4 + for y in range(4): + for x in range(8): + expected = (128 if address & 0x100 and x == 0 else 255, + (128 if y == 0 else 255) if address & 0x200 else 0, 0, 255) + if x >= 4: + expected = tuple(clear) + pixel = tuple(image[4 * (8 * y + x):4 * (8 * y + x + 1)]) + assert all(abs(a - e) <= (e == 128) for a, e in zip(pixel, expected)), (address, x, y, pixel, expected) + print(f"{adapter} slot 57 ADDR={address:#x} NUM_INTERP=0: all pixels matched") # The first DWORD is 0.25 in record zero, 1.0 in record one. Its byte-1 window is 0x003e8000. records = bytearray(64) struct.pack_into(" Date: Sun, 29 Nov 2026 22:45:17 +0100 Subject: [PATCH 2/3] native: link fixed pixel interpolants within the signature budget --- CMakeLists.txt | 4 + src/direct_compute_cache.cpp | 13 ++- src/gfx1013_compute_native.cpp | 51 +++++++++++- src/gfx1013_compute_native.h | 3 +- src/gfx1013_direct_graphics.inl | 4 +- tests/native_direct_container_check.py | 11 ++- ...native_graphics_interface_library_check.py | 77 ++++++++++++++++-- tests/startup_native_graphics_draw_check.py | 79 +++++++++++++------ 8 files changed, 200 insertions(+), 42 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 278354d49d..a3b6d37079 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2138,6 +2138,10 @@ if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${ "${CMAKE_SOURCE_DIR}/tests/startup_native_graphics_draw_check.py" "$" "${DXC_BIN_DIR}" ${adapter} "$") set_tests_properties(startup_native_graphics_draw_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) + add_test(NAME startup_native_graphics_fixed_entry_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_native_graphics_draw_check.py" --fixed-slot57 + "$" "${DXC_BIN_DIR}" ${adapter} "$") + set_tests_properties(startup_native_graphics_fixed_entry_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) endforeach() foreach(backend IN ITEMS hardware warp) add_test(NAME native_descriptor_scc_${backend} COMMAND "${INTAKE_PYTHON}" -B diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index cdb82933d2..81dc508cca 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -850,7 +850,8 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view // Fixed slot 57 supplies ADDR and NUM_INTERP, not ENA. Intersect // the observed ABI with the reviewed stage and the raw consumers. if (!packed_position_only) { - if ((!interpolants && !exact_pair) || interpolants > 7 || interpolants > pixel_defaults.attributes.size()) + const auto max_interpolants = std::min(D3D12_VS_OUTPUT_REGISTER_COUNT, pixel_defaults.attributes.size()); + if ((!interpolants && !exact_pair) || interpolants > max_interpolants) throw UnsupportedComputeShader("captured interpolation count disagrees with pixel interface"); const bool matched_address = address == pixel_defaults.pixel_input_address; float_position_only = !interpolants && matched_address && address && !(address & ~0x0f00u); @@ -900,7 +901,8 @@ 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); + } else pair = translate_graphics_pair(a, b, layout, pixel_entry, first_stage, targets, stage_wave32, + captured_interp_count && *captured_interp_count > 7); if (packed_position_only) { // The captured zero count describes the running program. A catalog // variant can still contain PARAM attributes that it has dropped. @@ -926,12 +928,17 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view r.index == 0 && r.width == 4 && r.interpolation == 4) continue; if (float_position_only && r.kind == 3 && r.name == "SV_Position" && r.component == 9 && r.index == 0 && r.interpolation == 4) continue; + // Exact lowering checks the guest locations at each VINTRP and + // links the reflected row and channels to their VS producer. + // A desktop semantic index need not encode a guest PARAM index. + if (fixed_entry && exact_pair && r.kind == 0 && r.name == "TEXCOORD" && + (r.interpolation == 2 || r.interpolation == 1)) continue; // Fixed pipelines may specialize individual components from // P1/P2 to VINTRP_MOV P0. The raw front end links each observed // component to a VS PARAM channel and emits flat mode only for // that P0 instruction. It may drop unused reflected rows, too. if (r.name != "TEXCOORD" || r.index / 4 >= channels.size() || - (!exact_pair && captured_interp_count && r.index / 4 >= *captured_interp_count) || + (captured_interp_count && r.index / 4 >= *captured_interp_count) || (r.interpolation != 2 && !(fixed_entry && r.interpolation == 1)) || r.width != 1 || r.first != r.index % 4) throw UnsupportedComputeShader("raw and reflected interpolation inputs disagree"); diff --git a/src/gfx1013_compute_native.cpp b/src/gfx1013_compute_native.cpp index cc4aaa51ee..6287f9750b 100644 --- a/src/gfx1013_compute_native.cpp +++ b/src/gfx1013_compute_native.cpp @@ -2371,14 +2371,15 @@ x2w::MeshRootMapping x2w::derive_mesh_root_mapping(const D3D12_ROOT_SIGNATURE_DE } static GuestShaderStage read_raw_graphics(std::string_view bytes, const D3D12_ROOT_SIGNATURE_DESC1 &layout, - unsigned enable_mask, unsigned address_mask, bool mesh_pixel = false) { + unsigned enable_mask, unsigned address_mask, bool mesh_pixel = false, + bool extended_fixed_params = false) { if (bytes.empty() || bytes.size() % 4 || bytes.size() > (1u << 20)) throw UnsupportedComputeShader("invalid raw graphics extent"); GuestShaderStage stage{}; unsigned extent = 0; bool position = false, color = false, depth = false, ended = false; struct Parameter { unsigned exported = 0, smooth = 0, flat = 0; }; - std::vector params(mesh_pixel ? 31 : 7); + std::vector params(mesh_pixel ? 31 : extended_fixed_params ? D3D12_VS_OUTPUT_REGISTER_COUNT : 7); const bool has_params = raw_center_inputs(enable_mask) || mesh_pixel; std::map visited; std::deque pending{0}; @@ -2466,6 +2467,44 @@ static GuestShaderStage read_raw_graphics(std::string_view bytes, const D3D12_RO return stage; } +static void pack_fixed_graphics_varyings(GuestShaderStage &vs, GuestShaderStage &ps) { + // The raw reader gives each channel the provisional register 1 + 4*PARAM + channel. + // Keep those assignments when they fit, including SV_Position at register 0. + const auto outside_budget = [](const auto &r) { return r.row >= D3D12_VS_OUTPUT_REGISTER_COUNT; }; + if (std::none_of(vs.output_signature.begin(), vs.output_signature.end(), outside_budget) && + std::none_of(ps.input_signature.begin(), ps.input_signature.end(), outside_budget)) return; + + struct Channel { bool used = false, flat = false; uint8_t row = 0; }; + std::array channels{}; + for (const auto &a : vs.outputs) channels[a.row - 1].used = true; + for (const auto &a : ps.attributes) channels[a.row - 1] = {true, bool(a.flags & 1), 0}; + + // Share one register per PARAM and interpolation mode, with the same + // channel assignment on both sides of the rasterizer. Keep VS-only channels. + uint8_t next_row = 1; + for (size_t param = 0; param < channels.size(); param += 4) { + std::array mode_rows{}; + for (size_t i = param; i < param + 4; ++i) { + auto &channel = channels[i]; + if (!channel.used) continue; + auto &row = mode_rows[channel.flat]; + if (!row) { + if (next_row >= D3D12_VS_OUTPUT_REGISTER_COUNT) + refuse(0, "invalid signature register or component mask"); + row = next_row++; + } + channel.row = row; + } + } + const auto remap = [&](auto &attrs, auto &signature) { + for (auto &a : attrs) a.row = channels[a.row - 1].row; + for (auto &r : signature) + if (!r.system) r.row = channels[r.row - 1].row; + }; + remap(vs.outputs, vs.output_signature); + remap(ps.attributes, ps.input_signature); +} + x2w::NativeComputeShader x2w::translate_mesh_pixel_program(std::string_view code, unsigned enable, unsigned address, unsigned wave_size, const D3D12_ROOT_SIGNATURE_DESC1 *root) try { if (address > 0xffff || (enable & ~address) || (wave_size != 32 && wave_size != 64)) @@ -2483,7 +2522,8 @@ x2w::DirectGraphicsPair x2w::translate_graphics_pair(std::string_view a,std::str const D3D12_ROOT_SIGNATURE_DESC1 &layout, std::string_view pixel_entry, std::optional first_stage, const std::array &target_components, - std::optional> stage_wave32) try { + std::optional> stage_wave32, + bool extended_fixed_params) try { const bool raw = a.substr(0,4)!="DXBC" && b.substr(0,4)!="DXBC"; unsigned enable_mask=0, address_mask=0; if (!pixel_entry.empty()) { @@ -2495,7 +2535,9 @@ x2w::DirectGraphicsPair x2w::translate_graphics_pair(std::string_view a,std::str refuse(0,"contradictory pixel input enable/address masks"); } auto read_stage = [&](std::string_view bytes) { - return raw ? std::vector{read_raw_graphics(bytes,layout,enable_mask,address_mask)} : read_guest_shader_container(bytes); + return raw ? std::vector{read_raw_graphics(bytes, layout, enable_mask, address_mask, + false, extended_fixed_params)} + : read_guest_shader_container(bytes); }; auto left=read_stage(a),right=read_stage(b); if(left.size()!=1 || right.size()!=1)refuse(0,"expected a distinct stage per graphics container"); @@ -2504,6 +2546,7 @@ x2w::DirectGraphicsPair x2w::translate_graphics_pair(std::string_view a,std::str auto *vs=&left.front(),*ps=&right.front(); if(vs->stage==GpuStage::ps)std::swap(vs,ps); if(vs->stage!=GpuStage::vs || ps->stage!=GpuStage::ps)refuse(0,"expected vertex and pixel stages"); + if (raw && extended_fixed_params) pack_fixed_graphics_varyings(*vs, *ps); ps->target_components=target_components; if (raw && stage_wave32) { vs->wave32 = (*stage_wave32)[0]; diff --git a/src/gfx1013_compute_native.h b/src/gfx1013_compute_native.h index dd20f9d629..3c2ef6e027 100644 --- a/src/gfx1013_compute_native.h +++ b/src/gfx1013_compute_native.h @@ -228,7 +228,8 @@ DirectGraphicsPair translate_graphics_pair(std::string_view a, std::string_view const D3D12_ROOT_SIGNATURE_DESC1 &layout, std::string_view pixel_entry = {}, std::optional first_stage = {}, const std::array &target_components = {}, - std::optional> stage_wave32 = {}); + std::optional> stage_wave32 = {}, + bool extended_fixed_params = false); DirectGraphicsPair translate_graphics_pair(std::string_view a, std::string_view b); void validate_raster_link(const NativeComputeShader &producer, const NativeComputeShader &pixel); DirectGraphicsPair translate_reflected_graphics(GuestShaderStage &vs, GuestShaderStage &ps, diff --git a/src/gfx1013_direct_graphics.inl b/src/gfx1013_direct_graphics.inl index ad5dcef4cf..e5e0df0128 100644 --- a/src/gfx1013_direct_graphics.inl +++ b/src/gfx1013_direct_graphics.inl @@ -44,12 +44,12 @@ struct GraphicsStage { dest = 256 + ((w >> 18) & 255); if (!pixel) refuse(pc, "interpolation outside pixel stage"); - if (stage.pixel_interpolant_count && attr >= *stage.pixel_interpolant_count) - refuse(pc, "raw and reflected interpolation inputs disagree"); const auto it = std::find_if(stage.attributes.begin(), stage.attributes.end(), [&](auto &a) { return a.location == attr && (a.mask & (1u << channel)); }); if (it == stage.attributes.end() || it->usage != 6 || (it->flags & 0x18)) refuse(pc, "missing or packed interpolation attribute"); + if (stage.pixel_interpolant_count && attr >= *stage.pixel_interpolant_count) + refuse(pc, "raw and reflected interpolation inputs disagree"); unsigned mode = 1; if (op == 2) { if (src != 2 || !(it->flags & 1)) diff --git a/tests/native_direct_container_check.py b/tests/native_direct_container_check.py index 413865f68c..ce2f94c119 100644 --- a/tests/native_direct_container_check.py +++ b/tests/native_direct_container_check.py @@ -73,7 +73,7 @@ def add_root_input(body, record, parameter, count, kind=0): body.extend(words(kind, 0, count, 0, parameter << 8)) -def vertex(fetch=False, constants=None, program=None, extra=(), varying=False, table=False, uses=()): +def vertex(fetch=False, constants=None, program=None, extra=(), varying=False, table=False, uses=(), outputs=()): record=112 body=bytearray(record+84+0x18c) struct.pack_into(" drawn;" in result.stderr, result.stderr assert [p.read_bytes() for p in cache.glob("*.ps57in")] == [b"PSI1" + words(*entry)] for line in result.stderr.splitlines(): if "x2w-d3d12-debug " in line: assert " sev=0 " not in line and " sev=1 " not in line, line + if "debug layer:" in line: + print(line) + print(result.stdout.strip()) return pixels.read_bytes() +def assert_slot57_pixels(image, color): + assert len(image) == 8 * 4 * 4 + for y in range(4): + for x in range(8): + expected = color(x, y) if x < 4 else tuple(CLEAR) + pixel = tuple(image[4 * (8 * y + x):4 * (8 * y + x + 1)]) + assert all(abs(a - e) <= (0 < e < 255) for a, e in zip(pixel, expected)), (x, y, pixel, expected) + + +def check_fixed_entries(folder, consumer, sdk, adapter, compiler): + triangle = triangle_program() + reviewed_vs = vertex(program=triangle) + for address, (raw_ps, reviewed_ps) in zero_fixed_cases(): + image = draw_slot57(folder / f"zero-{address:x}", consumer, sdk, adapter, compiler, (address, 0), + words(*triangle), reviewed_vs, raw_ps, reviewed_ps) + if image is None: + return 77 + assert_slot57_pixels(image, lambda x, y: (128 if address & 0x100 and x == 0 else 255, + (128 if y == 0 else 255) if address & 0x200 else 0, 0, 255)) + print(f"{adapter} slot 57 ADDR={address:#x} NUM_INTERP=0: all pixels matched") + for count in (8, 32): + for label in ("exact", "raw"): + fixture = fixed_varying_case(triangle, count, raw_variant=label == "raw") + image = draw_slot57(folder / f"{label}-{count}", consumer, sdk, adapter, compiler, (2, count), *fixture) + if image is None: + return 77 + assert_slot57_pixels(image, lambda x, y: (0, 64, 128, 255)) + print(f"{adapter} slot 57 {label} NUM_INTERP={count}: all pixels matched") + return 0 + + def check(folder, consumer, sdk, adapter, compiler): cache = folder / "cache" cache.mkdir() vs, ps, root, pixels = [folder / name for name in ("vs", "ps", "root", "pixels")] - triangle = triangle_program() - reviewed_vs = vertex(program=triangle) - vs.write_bytes(reviewed_vs) + vs.write_bytes(vertex(program=triangle_program())) ps.write_bytes(patched_pixel(2, [vop1(1, 0, 128), vop1(1, 1, 242)], export=(0xf800180f, 0x01000001))) - env = dict(os.environ, X2W_SHADER_CACHE=str(cache), X2W_NATIVE_SHADERS=sdk, - X2W_D3D12_DEBUG="1", X2W_D3D12_RENDER="1", X2W_D3D12_PERMISSIVE="1", X2W_D3D12_LIST_NOOP="1") - clear = bytes((0, 0, 255, 255)) + env = graphics_env(sdk, cache) + clear = CLEAR red = bytes((255, 0, 0, 255)) args = [consumer, vs, ps, root, adapter, pixels] for name, hits in (("cold", "0,0,0"), ("hot", "1,1,1")): @@ -105,19 +146,6 @@ def check(folder, consumer, sdk, adapter, compiler): assert run.returncode == 0 and "refused:" in run.stderr and "-> drawn;" not in run.stderr, run.stderr assert pixels.read_bytes() == clear * 32 print("unsupported stage: all 32 pixels retain the clear color") - for address, (raw_ps, reviewed_ps) in zero_fixed_cases(): - image = draw_slot57(folder / f"slot57-zero-{address:x}", consumer, adapter, compiler, env, (address, 0), - words(*triangle), reviewed_vs, raw_ps, reviewed_ps) - assert len(image) == 8 * 4 * 4 - for y in range(4): - for x in range(8): - expected = (128 if address & 0x100 and x == 0 else 255, - (128 if y == 0 else 255) if address & 0x200 else 0, 0, 255) - if x >= 4: - expected = tuple(clear) - pixel = tuple(image[4 * (8 * y + x):4 * (8 * y + x + 1)]) - assert all(abs(a - e) <= (e == 128) for a, e in zip(pixel, expected)), (address, x, y, pixel, expected) - print(f"{adapter} slot 57 ADDR={address:#x} NUM_INTERP=0: all pixels matched") # The first DWORD is 0.25 in record zero, 1.0 in record one. Its byte-1 window is 0x003e8000. records = bytearray(64) struct.pack_into(" Date: Sun, 29 Nov 2026 22:52:34 +0100 Subject: [PATCH 3/3] native: distinguish unallocated pixel VGPRs from zero interpolants --- tests/native_graphics_interface_library_check.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/native_graphics_interface_library_check.py b/tests/native_graphics_interface_library_check.py index 1b708c1e87..cde17c99ef 100644 --- a/tests/native_graphics_interface_library_check.py +++ b/tests/native_graphics_interface_library_check.py @@ -211,7 +211,12 @@ def slot57(name, raw_ps, reviewed_ps, entry, expected=None): raw_ps, reviewed_ps = fixed_pixel([*prefix, 0x7e0002f2], 2, 0) slot57("zero-inexact", raw_ps[:24] + words(0xbf800000) + raw_ps[24:], reviewed_ps, (2, 0), "captured interpolation count disagrees with pixel interface") + # The move initializes v2. Entry address 2 allocates v0/v1, so an export of v4 fails during lowering. raw_ps, reviewed_ps = fixed_pixel([0x7e0402f2], 2, 0x04000000) + slot57("zero-unallocated-vgpr", raw_ps, reviewed_ps, (2, 0), + "native compute +0x4: unsupported pixel entry VGPR 4") + # Export center I and the initialized v2 to exercise the zero-count restriction. + raw_ps, reviewed_ps = fixed_pixel([0x7e0402f2], 2, 0x02000000) slot57("zero-barycentrics", raw_ps, reviewed_ps, (2, 0), "raw and reflected interpolation inputs disagree") def varying_job(name, fixture, count, expected=None):