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
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,15 @@ if(TARGET compile_dxil AND EXISTS "${DXC_BIN_DIR}/dxcompiler.dll" AND EXISTS "${
add_test(NAME native_fixed_mesh57_constant_${backend} COMMAND startup_indirect_draw_indexed ${backend} mesh)
set_tests_properties(native_fixed_mesh57_constant_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_TEST_NATIVE_MESH57=1;X2W_TEST_NATIVE_MESH57_CONSTANT=1;X2W_NATIVE_SHADERS=${DXC_BIN_DIR}")
# The same MS reads the same dword through table slot 3 of root parameter 1. Declared as a
# CBV range it is a byte window over the descriptor's memory; declared as a UAV range the
# creation still refuses it.
add_test(NAME native_fixed_mesh57_cbv_${backend} COMMAND startup_indirect_draw_indexed ${backend} mesh)
set_tests_properties(native_fixed_mesh57_cbv_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_TEST_NATIVE_MESH57=1;X2W_TEST_NATIVE_MESH57_CBV=1;X2W_NATIVE_SHADERS=${DXC_BIN_DIR}")
add_test(NAME native_fixed_mesh57_cbv_uav_${backend} COMMAND startup_indirect_draw_indexed ${backend} mesh)
set_tests_properties(native_fixed_mesh57_cbv_uav_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_TEST_NATIVE_MESH57=1;X2W_TEST_NATIVE_MESH57_CBV_UAV=1;X2W_NATIVE_SHADERS=${DXC_BIN_DIR}")
add_test(NAME native_fixed_mesh57_mask_${backend} COMMAND startup_indirect_draw_indexed ${backend} mesh)
set_tests_properties(native_fixed_mesh57_mask_${backend} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77
ENVIRONMENT "X2W_TEST_NATIVE_MESH57=1;X2W_TEST_NATIVE_MESH57_MRT=1;X2W_TEST_NATIVE_MESH57_MASK=1;X2W_NATIVE_SHADERS=${DXC_BIN_DIR}")
Expand Down
26 changes: 23 additions & 3 deletions src/startup_stubs/native_mesh57.inl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ const char* bind_mesh57_buffers(Wrapper* self, Pass& pass, ID3D12GraphicsCommand
std::memcpy(words, reinterpret_cast<const void*>(entry), sizeof(words));
if (words[0] == view_token_magic) {
ViewRecord record{};
if (!token_view(words, record) || record.slot != 18) return "MS descriptor table slot is not an SRV";
if (!token_view(words, record) || (record.slot != 18 && record.slot != 17))
return "MS descriptor table slot is not an SRV or CBV";
if (record.slot == 17 && record.desc_bytes < 12)
return "MS descriptor table CBV lacks its buffer location and size";
} else if (words[3] != 0x31016fac || (words[1] & 0xffff0000)) {
return "unsupported MS native byte buffer descriptor";
}
Expand Down Expand Up @@ -370,15 +373,32 @@ void prepare_native_mesh57(Wrapper* pipeline)
if (param.ParameterType != D3D12_ROOT_PARAMETER_TYPE_SRV || b.byte_offset)
throw std::runtime_error("MS root buffer requires a root SRV");
} else {
if (b.kind != x2w::ComputeViewKind::buffer_srv || param.ParameterType != D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE)
if ((b.kind != x2w::ComputeViewKind::buffer_srv && b.kind != x2w::ComputeViewKind::byte_window_srv &&
b.kind != x2w::ComputeViewKind::heap_buffer_srv) ||
param.ParameterType != D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE)
throw std::runtime_error("MS table read requires a scalar SRV");
// Validate this creation root's range even when reflection already classified the slot.
using Table = x2w::ComputeViewBinding::ScalarTable;
if (b.scalar_table != Table::unknown && b.scalar_table != Table::srv)
throw std::runtime_error("MS table binding is not an SRV");
b.scalar_table = Table::unknown;
x2w::apply_scalar_table_layout(b, param.DescriptorTable);
if (b.scalar_table != x2w::ComputeViewBinding::ScalarTable::srv || b.byte_offset % 32)
// A CBV range is read here through its memory as raw dwords, exactly like a
// byte-window SRV: s_buffer_load has no format, filtering or typed element.
// The console also reads descriptors past the last declared range (a table is
// just a heap region); those stay unclassified here and the submission resolves
// the slot's token, refusing anything that is not a buffer SRV or a CBV.
using ScalarTable = x2w::ComputeViewBinding::ScalarTable;
uint64_t declared_slots = 0;
for (UINT r = 0; r < param.DescriptorTable.NumDescriptorRanges; ++r) {
const auto& range = param.DescriptorTable.pDescriptorRanges[r];
const uint64_t first = range.OffsetInDescriptorsFromTableStart == D3D12_DESCRIPTOR_RANGE_OFFSET_APPEND
? declared_slots : range.OffsetInDescriptorsFromTableStart;
declared_slots = (std::max)(declared_slots, first + range.NumDescriptors);
}
const bool past_table = b.scalar_table == ScalarTable::unknown && b.byte_offset / 32 >= declared_slots;
if ((b.scalar_table != ScalarTable::srv && b.scalar_table != ScalarTable::declared_cbv &&
!past_table) || b.byte_offset % 32)
throw std::runtime_error("MS buffer slot outside a verified SRV range");
}
reads.push_back({b.root_parameter, b.byte_offset, b.required_bytes, direct});
Expand Down
34 changes: 33 additions & 1 deletion tests/startup_indirect_draw_indexed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2390,7 +2390,11 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest,
const bool waterfall=GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_WATERFALL",nullptr,0)!=0;
const bool pixel_heap=waterfall || GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_PIXEL_HEAP",nullptr,0)!=0;
const bool heap = pixel_heap || GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_UINT_HEAP",nullptr,0) != 0;
const bool buffers = heap || GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_BUFFERS", nullptr, 0) != 0;
// The CBV variants keep the buffers shape: the same MS reads the same dword through a table slot
// that the root signature declares as a constant buffer (positive) or a UAV (negative control).
const bool cbv_slot = GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_CBV", nullptr, 0) != 0;
const bool cbv_uav = GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_CBV_UAV", nullptr, 0) != 0;
const bool buffers = heap || cbv_slot || cbv_uav || GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_BUFFERS", nullptr, 0) != 0;
const bool constants = buffers || GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_CONSTANT", nullptr, 0) != 0;
const bool compare_vcc = GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_COMPARE_VCC", nullptr, 0) != 0;
const bool varying = compare_vcc || constants || GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_VARYING", nullptr, 0) != 0;
Expand Down Expand Up @@ -2426,6 +2430,10 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest,
params[i].ParameterType = D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE;
params[i].DescriptorTable = {1, &ranges[i]};
}
// Slot 3 of table 1 holds the dword the MS reads at +4. A CBV range is read as its
// memory; a UAV range stays refused.
if (cbv_slot || cbv_uav)
ranges[1] = {cbv_uav ? D3D12_DESCRIPTOR_RANGE_TYPE_UAV : D3D12_DESCRIPTOR_RANGE_TYPE_CBV, 4, 0, 1, 0};
params[3].ParameterType = D3D12_ROOT_PARAMETER_TYPE_SRV;
params[3].Descriptor = {0, 3};
}
Expand Down Expand Up @@ -2609,6 +2617,30 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest,
return pso;
};
const auto pso = create();
const auto expect_log_line = [&](const char* text) {
std::ifstream log{std::filesystem::path(log_path)};
std::string line;
while (std::getline(log, line) && line != text) {}
if (!log) std::fprintf(stderr, "missing log line '%s'\n", text);
return static_cast<bool>(log);
};
if (cbv_slot || cbv_uav) {
char expected[192];
std::snprintf(expected, sizeof(expected),
cbv_slot ? "x2w-render native slot57 mesh %016llx ready"
: "x2w-render native slot57 mesh %016llx refused: MS buffer slot outside a verified SRV range",
key);
if (!expect_log_line(expected)) return 1;
if (cbv_uav) {
// A slot inside a declared UAV range is not a buffer window; the creation must refuse it
// before the draw path, unlike the CBV slot above that resolves to the same memory.
std::printf("native fixed mesh CBV control: UAV table slot refused as a buffer window\n");
DeleteFileW(log_path.c_str());
std::filesystem::remove_all(cache);
return 0;
}
std::printf("native fixed mesh CBV table slot: PSO created and read as a byte window\n");
}
if (compare_vcc)
std::printf("native fixed mesh compare mask: reviewed stage pair linked and created a color PSO\n");
fields[15] = 1; // Same stages and root, unreviewed fixed pipeline state.
Expand Down
Loading