Skip to content
Open
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: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
"$<TARGET_FILE:startup_stream_consumer>" "${DXC_BIN_DIR}" ${adapter} "$<TARGET_FILE:compile_dxil>")
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
"$<TARGET_FILE:startup_stream_consumer>" "${DXC_BIN_DIR}" ${adapter} "$<TARGET_FILE:compile_dxil>")
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
Expand Down
30 changes: 21 additions & 9 deletions src/direct_compute_cache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned> captured_interp_count;
std::optional<std::array<bool,2>> stage_wave32;
if (fixed_entry && !reflected) {
Expand Down Expand Up @@ -849,16 +850,17 @@ 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())
const auto max_interpolants = std::min<size_t>(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");
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);
Expand All @@ -874,8 +876,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);
Expand All @@ -897,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.
Expand All @@ -918,9 +923,16 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view
const auto &attrs = interfaces.at(GpuStage::ps).attributes;
std::vector<unsigned> 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;
// 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
Expand Down
51 changes: 47 additions & 4 deletions src/gfx1013_compute_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Parameter> params(mesh_pixel ? 31 : 7);
std::vector<Parameter> 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<unsigned, unsigned> visited;
std::deque<unsigned> pending{0};
Expand Down Expand Up @@ -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<Channel, 4 * D3D12_VS_OUTPUT_REGISTER_COUNT> 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<uint8_t, 2> 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))
Expand All @@ -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<GpuStage> first_stage,
const std::array<unsigned char, 8> &target_components,
std::optional<std::array<bool,2>> stage_wave32) try {
std::optional<std::array<bool,2>> 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()) {
Expand All @@ -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<GuestShaderStage>{read_raw_graphics(bytes,layout,enable_mask,address_mask)} : read_guest_shader_container(bytes);
return raw ? std::vector<GuestShaderStage>{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");
Expand All @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion src/gfx1013_compute_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<GpuStage> first_stage = {},
const std::array<unsigned char, 8> &target_components = {},
std::optional<std::array<bool,2>> stage_wave32 = {});
std::optional<std::array<bool,2>> 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,
Expand Down
2 changes: 2 additions & 0 deletions src/gfx1013_direct_graphics.inl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ struct GraphicsStage {
[&](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))
Expand Down
1 change: 1 addition & 0 deletions src/guest_shader_container.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct GuestShaderStage {
std::vector<PixelExportPatch> exports;
std::vector<ShaderSemantic> input_signature, output_signature;
unsigned pixel_input_address{}, pixel_input_enable = ~0u, depth_control{};
std::optional<unsigned> 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<unsigned char, 8> target_components{};
unsigned mesh_clip_control{}, max_vertices{}, max_primitives{}, topology{};
Expand Down
11 changes: 7 additions & 4 deletions tests/native_direct_container_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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("<Q",body,0,6)
Expand All @@ -100,9 +100,12 @@ def vertex(fetch=False, constants=None, program=None, extra=(), varying=False, t
if program is not None:
code = words(*program)
if varying:
io=record+84
struct.pack_into("<I", body,io+0x188,1)
body[io+0xc8:io+0xce]=bytes((6,0,0,0,0,0))
outputs = ((6, 0, 0, 0, 0, 0),)
if outputs:
io = record + 84
struct.pack_into("<I", body, io+0x188, len(outputs))
for index, output in enumerate(outputs):
struct.pack_into("<6B", body, io+0xc8+index*6, *output)
struct.pack_into("<QQ",body,record,len(body),len(code))
body.extend(code)
return pack(body, (((b"ISG1", signature(b"POSITION")),) if fetch else ()) + extra)
Expand Down
Loading
Loading