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
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,11 @@ foreach(backend IN ITEMS warp hardware)
set_tests_properties(startup_indirect_mesh_${backend} PROPERTIES TIMEOUT 30 SKIP_RETURN_CODE 77)
endforeach()
set_tests_properties(startup_indirect_draw_indexed_hardware startup_indirect_draw_hardware PROPERTIES SKIP_RETURN_CODE 77)
# Negative control for the x2w-render indirect line: one forwarded call too many must be reported as a mismatch.
add_test(NAME startup_indirect_counts_control_warp COMMAND startup_indirect_draw_indexed warp count-control)
# "got" is printed only for a mismatch, and the pattern holds the real counts. No semicolons: CMake would split it.
set_tests_properties(startup_indirect_counts_control_warp PROPERTIES TIMEOUT 30
PASS_REGULAR_EXPRESSION "got +'x2w-render indirect: forwarded: drawindexed 3. refused graphics-pipeline: drawindexed 1. compute-pipeline: dispatch 1. placeholder-signature: other 1. other: drawindexed 3'")

# OMSetRenderTargets with a single descriptor range, handles that hold no view, and a cleared copied descriptor.
add_executable(startup_rtv_bind tests/startup_rtv_bind.cpp)
Expand Down
2 changes: 1 addition & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"displayName": "Windows pull request smoke tests",
"filter": {
"include": {
"name": "^(desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_tools_lint|startup_indirect_(dispatch|draw(_indexed)?|mesh)_warp)$"
"name": "^(desktop_root_signature|era_heap_(allocation|failure)|xmem_shim_mapped_pages|cpu_aot_fuzz_smoke|cpu_archive_texture_gpu_warp|dual_uav_warp|spirv_.*_warp|static_exe_intake|descriptor_heap_paging(_swapped)?_warp|startup_launch|startup_tools_lint|startup_indirect_(dispatch|draw(_indexed)?|mesh|counts_control)_warp)$"
}
}
},
Expand Down
8 changes: 8 additions & 0 deletions docs/startup-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,14 @@ x2w-render totals: ... translated draws N (not drawn M), pipelines translated P

Compare the last line of each run. More translated draws and fewer "not drawn" mean a translator change reached real draws. "missing" is a live count of pipelines still waiting for a manifest. It can grow while things improve, if the run gets further and requests new pipelines.

Beside the totals line, one line counts every `ExecuteIndirect` call (command-list slot 61) since the start, forwarded or by refusal reason, then by signature kind (`draw`, `drawindexed`, `dispatch`, `dispatchmesh`, or `other` for a placeholder or unknown signature); a reason with no calls reads `0`:

```
x2w-render indirect: forwarded: drawindexed 3; refused graphics-pipeline: drawindexed 1; compute-pipeline: dispatch 1; placeholder-signature: other 1; other: drawindexed 3
```

`graphics-pipeline` is a draw without a matching desktop pipeline and root, `compute-pipeline` a dispatch without a desktop compute pipeline and root, and `other` every remaining refusal, counted under the signature's kind whenever the signature is known. The `x2w-render ExecuteIndirect refused` lines still stop after 16. `startup_indirect_draw_indexed_warp` checks this line; `startup_indirect_counts_control_warp` expects one forwarded call too many and must report the mismatch.

### 4. Census, then rank

The first refusal hides the rest. Run the [refusal census](experiments.md#startup-translator-refusal-census) on a copy of the cache:
Expand Down
38 changes: 33 additions & 5 deletions src/startup_stubs/d3d12_xs_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2112,11 +2112,21 @@ HRESULT __stdcall device_create_query_heap(Wrapper* self, const D3D12_QUERY_HEAP
return hr;
}

// Slot-61 calls by outcome and signature kind (IndirectCommand; none counts placeholder and unknown
// signatures), reported with the render totals. 64-bit and never reset, so they neither wrap nor stall.
enum { indirect_forwarded, indirect_graphics_pipeline, indirect_compute_pipeline, indirect_placeholder, indirect_other,
indirect_outcomes };
volatile LONG64 indirect_calls[indirect_outcomes][5];

// The guest method has independent resource and byte-offset arguments.
void __stdcall list_execute_indirect(Wrapper* self, void* signature, UINT count, void* argument, u64 offset,
void* count_buffer, u64 count_offset)
{
const auto refuse = [](const char* reason) {
// Every refusal is counted under the signature's kind, including those before the signature is checked.
Wrapper* sig = as_wrapper(signature);
IndirectCommand kind = sig && sig->own().kind == command_signature_kind ? sig->own().indirect_command : IndirectCommand::none;
const auto refuse = [&kind](const char* reason, int outcome = indirect_other) {
InterlockedIncrement64(&indirect_calls[outcome][static_cast<int>(kind)]);
static LONG refusals;
if (first_calls(refusals, 16)) log("x2w-render ExecuteIndirect refused: %s", reason);
};
Expand All @@ -2126,9 +2136,8 @@ void __stdcall list_execute_indirect(Wrapper* self, void* signature, UINT count,
if (type != D3D12_COMMAND_LIST_TYPE_DIRECT && type != D3D12_COMMAND_LIST_TYPE_COMPUTE)
return refuse("requires a direct or compute command list");
if (count != 1 || count_buffer || count_offset) return refuse("requires one command and no count buffer");
Wrapper* sig = as_wrapper(signature);
if (!sig || sig->own().kind != command_signature_kind || !sig->own().real)
return refuse("missing or placeholder signature");
return refuse("missing or placeholder signature", indirect_placeholder);
const Wrapper* device = self->own().list_device;
if (!device || sig->own().signature_device != device)
return refuse("requires a supported signature from this device");
Expand All @@ -2144,7 +2153,8 @@ void __stdcall list_execute_indirect(Wrapper* self, void* signature, UINT count,
else bytes = sizeof(D3D12_DRAW_ARGUMENTS);
if (type != D3D12_COMMAND_LIST_TYPE_DIRECT || !pass.indirect_graphics.root ||
pass.indirect_graphics.root != pass.graphics_root || pass.indirect_graphics.mesh != mesh)
return refuse("indirect graphics requires a direct list with a matching desktop pipeline and root");
return refuse("indirect graphics requires a direct list with a matching desktop pipeline and root",
indirect_graphics_pipeline);
if (!pass.targets_bound || pass.target_count != 1 || !pass.target0 ||
pass.target_formats[0] != pass.indirect_graphics.target_format ||
pass.dsv_format != DXGI_FORMAT_UNKNOWN || !pass.viewport_set || !pass.scissor_set)
Expand All @@ -2155,7 +2165,7 @@ void __stdcall list_execute_indirect(Wrapper* self, void* signature, UINT count,
if (samples.Count != 1 || samples.Quality)
return refuse("draw requires a single-sample render target");
} else if (!pass.compute_pipeline || !pass.compute_root) {
return refuse("requires a desktop compute pipeline and root");
return refuse("requires a desktop compute pipeline and root", indirect_compute_pipeline);
} else if (sig->own().signature_root && sig->own().signature_root != pass.compute_root) {
return refuse("signature root constants require the bound compute root");
}
Expand Down Expand Up @@ -2201,6 +2211,7 @@ void __stdcall list_execute_indirect(Wrapper* self, void* signature, UINT count,
}
require_state(self, resource, argument_state);
list->ExecuteIndirect(static_cast<ID3D12CommandSignature*>(sig->own().real), count, resource, offset, nullptr, 0);
InterlockedIncrement64(&indirect_calls[indirect_forwarded][static_cast<int>(kind)]);
}
// List slot 34 (desktop 30 + 4), SetGraphicsRootSignature. The title's parameters are tracked for translated
// draws either way. A root signature that indexes a descriptor heap directly is not set on the desktop list: the
Expand Down Expand Up @@ -3776,6 +3787,23 @@ HRESULT __stdcall queue_present(Wrapper* self, UINT planes, const void* plane_pa
heap_root_refusals[static_cast<int>(x2w_startup::RealRootDecision::sampler_heap_missing)],
heap_root_refusals[static_cast<int>(x2w_startup::RealRootDecision::both_heaps_missing)],
heap_root_refusals[static_cast<int>(x2w_startup::RealRootDecision::state_not_restorable)]);
if (render_mode() && frame % 300 == 0) {
// Slot-61 calls since the start, by outcome, then by signature kind (zero kinds left out).
static const char* const outcomes[] = {"forwarded", "refused graphics-pipeline", "compute-pipeline",
"placeholder-signature", "other"};
static const char* const kinds[] = {"other", "dispatch", "draw", "drawindexed", "dispatchmesh"};
char line[1024]; // fits every outcome with five 19-digit counts
int n = std::snprintf(line, sizeof(line), "x2w-render indirect:");
for (int o = 0; o < indirect_outcomes; ++o) {
n += std::snprintf(line + n, sizeof(line) - n, "%s %s:", o ? ";" : "", outcomes[o]);
const int start = n;
for (int k = 0; k < 5; ++k)
if (const LONG64 calls = indirect_calls[o][k])
n += std::snprintf(line + n, sizeof(line) - n, " %s %lld", kinds[k], static_cast<long long>(calls));
if (n == start) n += std::snprintf(line + n, sizeof(line) - n, " 0");
}
log("%s", line);
}
if (render_mode() && frame % 300 == 0) {
// Which command-list slots the title called in the last 300 frames, per frame.
char line[2048];
Expand Down
67 changes: 66 additions & 1 deletion tests/startup_indirect_draw_indexed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
#include <cstdint>
#include <cstdio>
#include <cstring>
#include <fstream>
#include <memory>
#include <optional>
#include <string>
#include <vector>

extern "C" __declspec(dllimport) HRESULT WINAPI D3D12XboxCreateDevice(IUnknown*, const void*, REFIID, void**);
Expand Down Expand Up @@ -405,14 +407,55 @@ bool run(ID3D12Device* device, ID3D12Device* guest, ID3D12RootSignature* writer_
std::printf("%s: %u/%u non-clear pixels, argument guards intact\n", label, painted, width * height);
return pixels_match;
}
// Calls refused before any argument is read: one per counted reason, and one with two commands, which is
// counted as other under its signature's kind. The list is closed and dropped.
void refuse_each_reason(ID3D12Device* guest, ID3D12CommandSignature* draw_indexed)
{
D3D12_INDIRECT_ARGUMENT_DESC dispatch{};
dispatch.Type = D3D12_INDIRECT_ARGUMENT_TYPE_DISPATCH;
const D3D12_COMMAND_SIGNATURE_DESC dispatch_desc{sizeof(D3D12_DISPATCH_ARGUMENTS), 1, &dispatch, 0};
ComPtr<ID3D12CommandSignature> dispatch_signature;
check(guest->CreateCommandSignature(&dispatch_desc, nullptr, IID_PPV_ARGS(&dispatch_signature)), "create guest dispatch signature");
ComPtr<ID3D12CommandAllocator> allocator;
check(guest->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(&allocator)), "create guest allocator");
const auto list = begin_guest_list(guest, allocator.Get());
using Execute = void (WINAPI*)(IUnknown*, IUnknown*, UINT, IUnknown*, UINT64, IUnknown*, UINT64);
const auto execute = slot<Execute>(list.Get(), 61);
execute(list.Get(), nullptr, 1, nullptr, 0, nullptr, 0); // placeholder signature
execute(list.Get(), draw_indexed, 1, nullptr, 0, nullptr, 0); // no desktop graphics pipeline bound
execute(list.Get(), dispatch_signature.Get(), 1, nullptr, 0, nullptr, 0); // no desktop compute pipeline bound
execute(list.Get(), draw_indexed, 2, nullptr, 0, nullptr, 0); // two commands
check(slot<HRESULT (WINAPI*)(IUnknown*)>(list.Get(), 9)(list.Get()), "close refusal list");
}

// 300 empty console presents (queue slot 32) reach the render-totals heartbeat; nothing is shown.
std::string indirect_line(ID3D12Device* guest, const std::wstring& log_path)
{
const D3D12_COMMAND_QUEUE_DESC desc{};
ComPtr<IUnknown> queue;
check(guest->CreateCommandQueue(&desc, __uuidof(ID3D12CommandQueue), reinterpret_cast<void**>(queue.GetAddressOf())),
"create guest queue");
using Present = HRESULT (WINAPI*)(IUnknown*, UINT, const void*, const void*);
const std::array<unsigned char, 0x50> planes{};
const std::array<unsigned char, 0x40> present{};
for (int frame = 0; frame < 300; ++frame) slot<Present>(queue.Get(), 32)(queue.Get(), 0, planes.data(), present.data());
std::ifstream file(log_path, std::ios::binary);
std::string line, found;
while (std::getline(file, line))
if (line.rfind("x2w-render indirect:", 0) == 0) found = line;
while (!found.empty() && (found.back() == '\r' || found.back() == '\n')) found.pop_back();
return found;
}
} // namespace

int main(int argc, char** argv) try
{
DrawKind kind = DrawKind::indexed;
// "count-control" is the negative control: it expects one forwarded call too many.
const bool count_control = argc == 3 && std::strcmp(argv[2], "count-control") == 0;
if (argc == 3 && std::strcmp(argv[2], "draw") == 0) kind = DrawKind::vertices;
else if (argc == 3 && std::strcmp(argv[2], "mesh") == 0) kind = DrawKind::mesh;
else if (argc != 2) return 2;
else if (argc != 2 && !count_control) return 2;
const bool indexed = kind == DrawKind::indexed;
const bool mesh = kind == DrawKind::mesh;
const bool warp = std::strcmp(argv[1], "warp") == 0;
Expand Down Expand Up @@ -443,6 +486,14 @@ int main(int argc, char** argv) try
(!mesh || supports_mesh(probe.Get()))) break;
}
}
wchar_t directory[MAX_PATH];
if (!GetTempPathW(MAX_PATH, directory)) return 4;
const std::wstring log_path = std::wstring(directory) + L"x2w_indirect_counts_" + std::to_wstring(GetCurrentProcessId()) + L".log";
if (indexed) {
DeleteFileW(log_path.c_str());
SetEnvironmentVariableW(L"X2W_TRAP_LOG", log_path.c_str());
SetEnvironmentVariableA("X2W_PRESENT_SIGNATURE_EVERY", "0");
}
DXGI_ADAPTER_DESC1 desc{};
check(adapter->GetDesc1(&desc), "get selected adapter description");
std::printf("adapter: %ls, debug layer %s\n", desc.Description, debug ? "enabled" : "unavailable");
Expand Down Expand Up @@ -510,6 +561,20 @@ int main(int argc, char** argv) try
!verify(left.Get(), false, Refusal::short_argument, "short argument range")) return 1;
if (indexed ? !verify(left.Get(), false, Refusal::invalid_index, "invalid index range")
: !verify(left.Get(), false, Refusal::missing_viewport, "missing viewport")) return 1;
if (indexed) {
// Forwarded: the three unrefused runs. Other reasons: the short argument range, the invalid index range and two commands.
refuse_each_reason(guest.Get(), signature.Get());
const std::string line = indirect_line(guest.Get(), log_path);
DeleteFileW(log_path.c_str());
const std::string expected = std::string("x2w-render indirect: forwarded: drawindexed ") + (count_control ? "4" : "3") +
"; refused graphics-pipeline: drawindexed 1; compute-pipeline: dispatch 1; placeholder-signature: other 1; "
"other: drawindexed 3";
if (line != expected) {
std::fprintf(stderr, "indirect line mismatch:\n got '%s'\n expected '%s'\n", line.c_str(), expected.c_str());
return 1;
}
std::printf("%s\n", line.c_str());
}
if (info) {
for (UINT64 i = 0; i < info->GetNumStoredMessages(); ++i) {
SIZE_T bytes = 0;
Expand Down
Loading