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
8 changes: 7 additions & 1 deletion src/gfx1013_compute_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2309,7 +2309,7 @@ static GuestShaderStage read_raw_graphics(std::string_view bytes, const D3D12_RO
throw UnsupportedComputeShader("invalid raw graphics extent");
GuestShaderStage stage{};
unsigned extent = 0;
bool position = false, color = false, ended = false;
bool position = false, color = false, depth = false, ended = false;
struct Parameter { unsigned exported = 0, smooth = 0, flat = 0; };
std::vector<Parameter> params(mesh_pixel ? 31 : 7);
const bool has_params = raw_center_inputs(enable_mask) || mesh_pixel;
Expand Down Expand Up @@ -2343,6 +2343,8 @@ static GuestShaderStage read_raw_graphics(std::string_view bytes, const D3D12_RO
const unsigned target = (w >> 4) & 63;
if (target == 12) position = true;
else if (target < 8) color = true;
// MRTZ with depth alone, uncompressed. Stencil and coverage have no raw signature row.
else if (target == 8 && (w & 0x40f) == 1 && !mesh_pixel) depth = true;
else if (target == 9 && !(w & 15)) {} // Null export on a pixel kill path.
else if (has_params && target >= 32 && target - 32 < params.size() &&
!params[target - 32].exported && !(w & 0x400)) params[target - 32].exported = w & 15;
Expand All @@ -2359,6 +2361,9 @@ static GuestShaderStage read_raw_graphics(std::string_view bytes, const D3D12_RO
}
if (op.name != "s_branch") pending.push_back(pc + op.size);
}
// A raw color target is typed without a signature, so it cannot share a stage with the depth row below.
if (color && depth) refuse(extent, "raw depth export next to a color export requires a stage interface");
color |= depth; // from here on: this is the pixel stage
if (!ended || position == color) refuse(extent, "ambiguous raw graphics stage");
stage.stage = position ? GpuStage::vs : GpuStage::ps;
stage.fixed_vertex_abi = position && has_params;
Expand All @@ -2369,6 +2374,7 @@ static GuestShaderStage read_raw_graphics(std::string_view bytes, const D3D12_RO
}
if ((color && (enable_mask & 0x8f00)) || (position && has_params))
(color ? stage.input_signature : stage.output_signature).push_back({"SV_Position",0,1,3,0,15,15});
if (depth) stage.output_signature.push_back({"SV_Depth",0,D3D_NAME_DEPTH,3,UINT_MAX,1,1});
for (uint8_t attr = 0; attr < params.size(); ++attr) {
const auto &p = params[attr];
if ((position && (p.smooth || p.flat)) || (color && p.exported) || (p.smooth & p.flat))
Expand Down
7 changes: 7 additions & 0 deletions tests/cmake/native_raw_depth_export.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# A raw fixed VS/PS pair whose pixel stage exports depth alone (Refs #3541): the raw front end gives it SV_Depth;
# stencil, coverage, a compressed export and depth next to colour stay refused.
if(TARGET compile_dxil AND EXISTS "${INTAKE_PYTHON}")
add_test(NAME native_raw_depth_export COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_CURRENT_SOURCE_DIR}/tests/native_raw_depth_export_check.py" "$<TARGET_FILE:compile_dxil>"
"${DXC_BIN_DIR}")
endif()
86 changes: 86 additions & 0 deletions tests/native_raw_depth_export_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
"""A raw fixed VS/PS pair whose pixel stage exports depth and no colour.

The fixtures are source-built raw gfx1013 programs with a slot-57 PSI1 entry
and no reviewed .cdxil sidecar, so the pair takes the raw front end. An
uncompressed MRTZ export of depth alone becomes SV_Depth. Stencil or coverage
channels, a compressed export, and depth next to a colour export need a
reviewed interface and stay refused.
"""
import pathlib
import subprocess
import sys
import tempfile

from native_direct_container_check import publish, words
from native_fixed_graphics_psi1_check import END, ROOT, VS, interpolate


COLOUR = (0xF800180F, 0x04040404) # exp mrt0 v4, v4, v4, v4 done vm


def mrtz(enable=1, compressed=False):
# EXP: EN [3:0], TARGET [9:4] = 8 (MRTZ), COMPR [10], DONE [11], VM [12]; VSRC0 = v4 holds depth.
return (0xF8001880 | enable | (0x400 if compressed else 0), 4)


def pixel(*exports):
prefix = [0xD5800000, 255, 17, 0xD5800000, 255, 23]
body = [interpolate(0, 0, 0, 4, 0), interpolate(0, 0, 1, 4, 1)]
for export in exports:
body.extend(export)
return words(*prefix, *body, 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, program, expected=None, expect_hit=None):
requests = base / (name + "-requests")
output = base / (name + "-output")
key = publish(requests, program, VS, ROOT, slot57_inputs=(2, 1))
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, (name, 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)
if expect_hit is not None:
assert f"frontend_cache_hit={expect_hit}" in result.stdout, result.stdout
return output / f"{key}.ps.cso"

def dumpbin(stage):
return subprocess.check_output([sdk / "dxc.exe", "-dumpbin", stage], text=True)

# Depth alone: the pixel stage has one output, SV_Depth, and stores the interpolated value to it.
stage = compile_case("depth", pixel(mrtz()), expect_hit=0)
dump = dumpbin(stage)
assert "SV_Depth" in dump and "storeOutput.f32" in dump and "SV_Target" not in dump, dump

# A second process reads the pair back from the frontend cache: the depth row survives the round trip.
first = stage.read_bytes()
assert compile_case("depth", pixel(mrtz()), expect_hit=1).read_bytes() == first

# Control: the same program exporting colour still compiles and has no depth output.
dump = dumpbin(compile_case("colour", pixel(COLOUR)))
assert "SV_Target" in dump and "SV_Depth" not in dump, dump

# Stencil (EN bit 1) and coverage (EN bit 2) have no raw signature row.
for enable in (3, 5, 2):
compile_case(f"enable-{enable}", pixel(mrtz(enable)),
expected="raw graphics varying or system export requires a stage interface")
compile_case("compressed", pixel(mrtz(compressed=True)),
expected="raw graphics varying or system export requires a stage interface")

# A raw colour target is typed without a signature; with a depth row present it would be refused later
# under a misleading name, so the reader names the combination.
compile_case("colour-and-depth", pixel((0xF800100F, 0x04040404), mrtz()),
expected="raw depth export next to a color export requires a stage interface")


if __name__ == "__main__":
main(*sys.argv[1:])
Loading