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
23 changes: 15 additions & 8 deletions src/startup_stubs/native_mesh57.inl
Original file line number Diff line number Diff line change
Expand Up @@ -298,18 +298,25 @@ void prepare_native_mesh57(Wrapper* pipeline)
if (direct_heap && (!file.read(reinterpret_cast<char*>(&heap_sgpr), sizeof(heap_sgpr)) ||
!(root_heap_flags(root) & D3D12_ROOT_SIGNATURE_FLAG_CBV_SRV_UAV_HEAP_DIRECTLY_INDEXED)))
throw std::runtime_error("missing MS resource heap mapping");
const auto match = [&](UINT part, const void* bytes, size_t size) {
const auto match = [&](UINT part, const char* name, const void* bytes, size_t size) {
if (size != profile.lengths[part])
return false;
throw std::runtime_error(std::string("profile input bytes differ: ") + name +
" length " + std::to_string(profile.lengths[part]) +
" != " + std::to_string(size));
if (!size)
return true;
return;
std::string copy(size, 0);
return file.read(copy.data(), size) && !std::memcmp(copy.data(), bytes, size);
if (!file.read(copy.data(), size) || std::memcmp(copy.data(), bytes, size))
throw std::runtime_error(std::string("profile input bytes differ: ") + name + " content");
};
if (!match(0, normalized.data(), normalized.size()) || !match(1, info->state_a.data(), info->state_a.size()) ||
!match(2, info->state_b.data(), info->state_b.size()) || !match(3, root_blob.data(), root_blob.size()) ||
!match(4, ms_bytes.data(), ms_bytes.size()) || !match(5, ps_bytes.data(), ps_bytes.size()) || file.peek() != EOF)
throw std::runtime_error("profile input bytes differ");
match(0, "normalized descriptor", normalized.data(), normalized.size());
match(1, "state_a", info->state_a.data(), info->state_a.size());
match(2, "state_b", info->state_b.data(), info->state_b.size());
match(3, "root blob", root_blob.data(), root_blob.size());
match(4, "mesh shader", ms_bytes.data(), ms_bytes.size());
match(5, "pixel shader", ps_bytes.data(), ps_bytes.size());
if (file.peek() != EOF)
throw std::runtime_error("profile input bytes differ: trailing bytes after the pixel shader");
if (!profile.targets.NumRenderTargets || profile.targets.NumRenderTargets > D3D12_SIMULTANEOUS_RENDER_TARGET_COUNT ||
((profile.depth.DepthEnable || profile.depth.StencilEnable) && profile.depth_format == DXGI_FORMAT_UNKNOWN) ||
profile.samples.Count != 1 ||
Expand Down
63 changes: 61 additions & 2 deletions tests/startup_indirect_draw_indexed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,8 @@ bool fixed_mesh_create_contract(ID3D12Device* guest)
#include "startup_indirect_mesh_lease.inl"
} // namespace

static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, ID3D12RootSignature* writer)
static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest, ID3D12RootSignature* writer,
const std::wstring& log_path)
{
const bool mrt = GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_MRT", nullptr, 0) != 0;
const bool waterfall=GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57_WATERFALL",nullptr,0)!=0;
Expand All @@ -2070,6 +2071,8 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest,
if (std::filesystem::create_directory(cache)) break;
}
check(SetEnvironmentVariableW(L"X2W_SHADER_CACHE", cache.c_str()) ? S_OK : E_FAIL, "native mesh cache");
DeleteFileW(log_path.c_str());
check(SetEnvironmentVariableW(L"X2W_TRAP_LOG", log_path.c_str()) ? S_OK : E_FAIL, "native mesh log");
// 2000 other cache files: the profile lookups below must not open a name the cache does not hold.
for (UINT64 i = 0; i < 2000; ++i) {
static const char* const others[]{"req_%016llx.c67", "%016llx.txt", "%016llx.cs.cso", "req_%016llx.ia"};
Expand Down Expand Up @@ -2270,6 +2273,20 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest,
const auto pso = create();
fields[15] = 1; // Same stages and root, unreviewed fixed pipeline state.
const auto mismatched = create();
{
// native_mesh57.inl: throw std::runtime_error(std::string("profile input bytes differ: ") + name + " content");
char expected[128];
std::snprintf(expected, sizeof(expected),
"x2w-render native slot57 mesh %016llx refused: profile input bytes differ: normalized descriptor content",
key);
std::ifstream log{std::filesystem::path(log_path)};
std::string line;
while (std::getline(log, line) && line != expected) {}
if (!log) {
std::fprintf(stderr, "unreviewed fixed mesh state: missing log line '%s'\n", expected);
return 1;
}
}
// 64 more fixed states without a profile. Only the two profiles above may be opened.
for (UINT64 extra = 2; extra < 66; ++extra) {
fields[15] = extra;
Expand All @@ -2281,6 +2298,47 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest,
std::printf("native fixed mesh profile lookups %ld, opens %ld (2 profiles, 2000 other cache files)\n", lookups, opens);
if (lookups != 66 || opens != 2)
return 1;
const auto expect_profile_refusal = [&](const char* reason) {
char expected[160];
std::snprintf(expected, sizeof(expected),
"x2w-render native slot57 mesh %016llx refused: profile input bytes differ: %s",
key, reason);
std::ifstream log{std::filesystem::path(log_path)};
std::string line;
while (std::getline(log, line) && line != expected) {}
if (log)
return true;
std::fprintf(stderr, "malformed fixed mesh profile: missing log line '%s'\n", expected);
return false;
};
// Reuse the indexed profile filename with the original descriptor after checking lookup counts.
fields[15] = 0;
const auto profile_path = cache / name;
auto wrong_length = profile;
++wrong_length.lengths[0];
{
std::fstream file(profile_path, std::ios::binary | std::ios::in | std::ios::out);
file.write(reinterpret_cast<const char*>(&wrong_length), sizeof(wrong_length));
file.close();
if (!file)
return 1;
}
create();
if (!expect_profile_refusal("normalized descriptor length 769 != 768"))
return 1;
{
std::fstream file(profile_path, std::ios::binary | std::ios::in | std::ios::out);
file.write(reinterpret_cast<const char*>(&profile), sizeof(profile));
file.seekp(0, std::ios::end);
file.put('\0');
file.close();
if (!file)
return 1;
}
create();
if (!expect_profile_refusal("trailing bytes after the pixel shader"))
return 1;
fields[15] = 1;
state_a.fill(0);
state_b.fill(0);
check(SetEnvironmentVariableA("X2W_MESH57_CAPTURE_STATE", "1") ? S_OK : E_FAIL, "enable fixed-state archive");
Expand Down Expand Up @@ -2358,6 +2416,7 @@ static int native_fixed_mesh_fixture(ID3D12Device* device, ID3D12Device* guest,
}
std::printf("fixed mesh state archives matching creation bytes: accepted=%d refused=%d\n", saw_valid, saw_other);
if (!saw_valid || !saw_other) return 1;
DeleteFileW(log_path.c_str());
std::filesystem::remove_all(cache);
return 0;
}
Expand Down Expand Up @@ -2491,7 +2550,7 @@ int main(int argc, char** argv) try
const D3D12_ROOT_SIGNATURE_DESC graphics_desc{0, nullptr, 0, nullptr, root_flags};
const auto writer = create_root(device.Get(), writer_desc);
if (mesh && GetEnvironmentVariableA("X2W_TEST_NATIVE_MESH57", nullptr, 0))
return native_fixed_mesh_fixture(device.Get(), guest.Get(), writer.Get());
return native_fixed_mesh_fixture(device.Get(), guest.Get(), writer.Get(), log_path);
wchar_t mesh86_dir[MAX_PATH]{};
if (mesh && GetEnvironmentVariableW(L"X2W_MESH86_FIXTURE_DIR", mesh86_dir, MAX_PATH)) {
const bool depth_only = GetEnvironmentVariableA("X2W_MESH86_FIXTURE_DEPTH", nullptr, 0) != 0;
Expand Down
Loading