diff --git a/src/direct_compute_cache.cpp b/src/direct_compute_cache.cpp index 83af0a61b2..e5e05a78d0 100644 --- a/src/direct_compute_cache.cpp +++ b/src/direct_compute_cache.cpp @@ -621,7 +621,13 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view const std::array raw{a, b}; const std::array digests{shader_digest(a), shader_digest(b)}; Bytes identity = Bytes(X2W_NATIVE_SHADER_REVISION) + "/linked/vs_ps_6_6/"; - if (!cache.empty() && a.substr(0,4) != "DXBC" && b.substr(0,4) != "DXBC") { + const bool fixed_entry = pixel_entry.size() == 12 && pixel_entry.substr(0,4) == "PSI1"; + const char *lookup_failure = "VS and PS companions not found"; + if (cache.empty()) { + lookup_failure = "lookup skipped (no cache directory)"; + } else if (a.substr(0,4) == "DXBC" || b.substr(0,4) == "DXBC") { + lookup_failure = "lookup skipped (DXBC stage present)"; + } else { for (size_t i = 0; i < raw.size(); ++i) { auto file = cache / "interfaces" / (digests[i] + ".cdxil"); if (std::filesystem::exists(file)) companions[i] = read_shader_container_bytes(file); @@ -632,8 +638,20 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view if (auto index = load_interfaces(library)) { for (size_t i = 0; i < raw.size(); ++i) if (companions[i].empty()) companions[i] = indexed_interface(library,*index,raw[i],digests[i]); - // An incomplete library must still allow a self-describing raw pair. - if (!pinned && (companions[0].empty() || companions[1].empty())) companions = {}; + // Slot 57 saves PS from +0x28 in .a and VS from +0x48 in .b. + const bool ps_missing = companions[0].empty(), vs_missing = companions[1].empty(); + if (ps_missing != vs_missing) { + if (pinned) { + lookup_failure = ps_missing ? "PS companion not found" : "VS companion not found"; + } else { + lookup_failure = ps_missing ? "catalog hit discarded because its partner was missing (PS)" + : "catalog hit discarded because its partner was missing (VS)"; + // An incomplete library must still allow a self-describing raw pair. + companions = {}; + } + } + } else { + lookup_failure = "no catalog loaded"; } } } @@ -642,7 +660,10 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view identity += shader_digest(companions[i]); } const bool reflected = !companions[0].empty(); - if (reflected != !companions[1].empty()) throw UnsupportedComputeShader("incomplete raw graphics interface pair"); + if (reflected != !companions[1].empty()) { + if (fixed_entry) throw FixedGraphicsInterfaceRefusal(lookup_failure); + throw UnsupportedComputeShader("incomplete raw graphics interface pair"); + } if (reflected && root.empty()) throw UnsupportedComputeShader("missing captured root for reflected graphics"); // The base pair keeps its key. A variant adds its target types, so formats of one type share an entry. const Bytes typed = rtv_formats.empty() ? Bytes{} @@ -697,9 +718,8 @@ DirectGraphicsPair prepare_direct_graphics(std::string_view a, std::string_view bool exact_pair = reflected; bool exact_pixel_code = false; Bytes entry; - const bool fixed_entry = pixel_entry.size() == 12 && pixel_entry.substr(0,4) == "PSI1"; if (fixed_entry && !reflected) - throw UnsupportedComputeShader("fixed graphics entry requires matching stage interfaces"); + throw FixedGraphicsInterfaceRefusal(lookup_failure); bool packed_xy = false; std::optional captured_interp_count; std::optional> stage_wave32; diff --git a/src/direct_compute_cache.h b/src/direct_compute_cache.h index ec388dc541..5fc20ae3b2 100644 --- a/src/direct_compute_cache.h +++ b/src/direct_compute_cache.h @@ -7,6 +7,16 @@ namespace x2w { enum class ComputePackResult { miss, prepared, unsupported }; struct ComputePackCounts { size_t prepared{}, unsupported{}; std::vector errors; }; +// The reason is a fixed lookup diagnostic suitable for the runtime refusal census. +class FixedGraphicsInterfaceRefusal : public UnsupportedComputeShader { +public: + explicit FixedGraphicsInterfaceRefusal(const char *reason) + : UnsupportedComputeShader(std::string("fixed graphics entry requires matching stage interfaces: ") + reason), + reason_(reason) {} + const char *reason() const { return reason_; } +private: + const char *reason_; +}; class ComputeFrontendPack { struct Record { std::string digest, payload; bool unsupported; }; std::unordered_map records_; diff --git a/src/startup_stubs/d3d12_draw.inl b/src/startup_stubs/d3d12_draw.inl index f6e88d4e4f..207f4daaaa 100644 --- a/src/startup_stubs/d3d12_draw.inl +++ b/src/startup_stubs/d3d12_draw.inl @@ -620,6 +620,8 @@ void load_translation(Translation& tr, const std::string& rtv_request = {}, std: } #ifdef X2W_NATIVE_SHADERS +static x2w_startup::PerReasonRefusalCensus native_graphics_lookup_census{"native graphics lookup"}; + static bool try_native_graphics(Translation& tr, bool variant = false) { wchar_t sdk[MAX_PATH], path[MAX_PATH]; @@ -669,6 +671,9 @@ static bool try_native_graphics(Translation& tr, bool variant = false) tr.key, tr.state == 1, frontend_hit, vs_hit, ps_hit); return true; } catch (const std::exception& error) { + // One shared key aggregates the fixed lookup reasons across pipelines. + if (const auto* lookup = dynamic_cast(&error)) + native_graphics_lookup_census.note(0, lookup->reason()); log("x2w-draw native graphics %016llx refused: %s", tr.key, error.what()); tr.native_refusal = error.what(); return false; diff --git a/src/startup_stubs/d3d12_xs_device.cpp b/src/startup_stubs/d3d12_xs_device.cpp index cc1f9abc54..cc59c7c442 100644 --- a/src/startup_stubs/d3d12_xs_device.cpp +++ b/src/startup_stubs/d3d12_xs_device.cpp @@ -8112,6 +8112,9 @@ HRESULT __stdcall queue_present(Wrapper* self, UINT planes, const void* plane_pa indirect_other_refusal_census.report([](const char* line) { log("%s", line); }, true); indirect_pipeline_refusal_census.report([](const char* line) { log("%s", line); }, true); emit_pipeline_refusal_counts([](const char* line) { log("%s", line); }); +#ifdef X2W_NATIVE_SHADERS + native_graphics_lookup_census.report([](const char* line) { log("%s", line); }, true); +#endif log("x2w-d3d12 heartbeat: %ld frames presented in %.1f s (%.1f fps overall); frame waits by type %ld/%ld/%ld/%ld, " "%lld ms slept", frame, (now - started) / 1000.0, frame * 1000.0 / (now - started ? now - started : 1), frame_waits[0], frame_waits[1], frame_waits[2], frame_waits[3], static_cast(frame_wait_ms)); diff --git a/tests/native_graphics_interface_library_check.py b/tests/native_graphics_interface_library_check.py index d5475858ca..8f3472fdfb 100644 --- a/tests/native_graphics_interface_library_check.py +++ b/tests/native_graphics_interface_library_check.py @@ -1,4 +1,5 @@ """Index source-built native containers and replay their raw runtime form.""" +import hashlib import pathlib import subprocess import sys @@ -36,9 +37,30 @@ def run(*args, expected=None): stem = publish(requests, ps, vs, root) def batch(folder, output, **kwargs): return run(sdk, cache, "gfx1013-container-pair", "--requests", folder, output, **kwargs) + + def fixed_refusal(name, reason, a=ps, b=vs, frontend=cache): + folder = base / ("lookup-" + name) + publish(folder, a, b, root, slot57_inputs=(2, 1)) + run(sdk, frontend, "gfx1013-container-pair", "--requests", folder, folder / "output", + expected=f"fixed graphics entry requires matching stage interfaces: {reason}\n") + batch(requests, base / "bare", expected="verified stage interface") + fixed_refusal("no-cache", "lookup skipped (no cache directory)", frontend="") + fixed_refusal("dxbc", "lookup skipped (DXBC stage present)", b=vertex_file.read_bytes()) + fixed_refusal("no-catalog", "no catalog loaded") install = ("--index-graphics-interfaces", library, cache) run(*install) + unseen_ps = words(0x7e0002f0, 0xf800180f, 0, end) + unseen_vs = words(0x7e020b00, 0xf80008cf, 0, end) + fixed_refusal("neither", "VS and PS companions not found", unseen_ps, unseen_vs) + for stage, a, b, known, container in ( + ("VS", ps, unseen_vs, ps, pixel_file), + ("PS", unseen_ps, vs, vs, vertex_file)): + fixed_refusal(f"discard-{stage}", f"catalog hit discarded because its partner was missing ({stage})", a, b) + pin = cache / "interfaces" / (hashlib.sha256(known).hexdigest() + ".cdxil") + pin.write_bytes(container.read_bytes()) + fixed_refusal(f"missing-{stage}", f"{stage} companion not found", a, b) + pin.unlink() for name, hit in (("cold",0), ("warm",1)): assert f"frontend_cache_hit={hit}" in batch(requests, base / name) run(sdk,cache,"gfx1013-container-pair",vertex_file,base/"vertex.cso",pixel_file,base/"pixel.cso")