mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 16:08:37 +00:00
d3d12: name the memory a V# resolved to nothing names, and what one compute program's V#s read (RT-PAGE-MIRROR)
Run 64w2 hung in a min-pyramid dispatch whose loop bounds divide sizes from one constant buffer by divisors behind a V# from its descriptor table. Its log cannot name that buffer: it has no record of the dispatch. The heap's line counts V# halves resolved to nothing (not title memory 14378, bit 47 12312, arena offset 5506 in 10 s) but not where their bases lie. - Always on, the console heap's "resolved to nothing" line now splits the arena-offset and not-title-memory classes by what the host has at the base: image, mapped, private, reserved or free (one VirtualQuery per V# half that resolves to nothing). - LEONIDA_COMPUTE_INPUTS (with LEONIDA_DEVICE_FAULT) knows the page mirror. The slot words of a heap read in place are read from its home, where the GPU reads them. A V# base is classed mirror-home or mirror-unbound before the older backings. Each V# prints the host's kind of memory at its base, the title's first 16 dwords there and whether the GPU-side bytes differ. A slot the layer turned to null prints the title's V#, where it lies and its bytes. LEONIDA_COMPUTE_INPUT_SLOTS takes runs such as 5/0-15. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@ -4,6 +4,8 @@
|
||||
#include "../src/fsdraw_probe.h"
|
||||
#include "../src/title_va_alias.h"
|
||||
#include "../src/title_page_watch.h"
|
||||
#include "../src/title_mirror_space.h"
|
||||
#include "../src/title_mirror.h"
|
||||
#include "xmem.h"
|
||||
#include <windows.h>
|
||||
#include <algorithm>
|
||||
@ -41,7 +43,8 @@ inline bool matches(const char* name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Each decimal pair selects a table root dword and a 32-byte descriptor index.
|
||||
// Each decimal pair selects a table root dword and a 32-byte descriptor index; root/first-last selects a run of
|
||||
// them (at most 64).
|
||||
inline const auto& slots() {
|
||||
static const auto pairs = [] {
|
||||
std::vector<std::pair<unsigned, unsigned>> result;
|
||||
@ -49,12 +52,19 @@ inline const auto& slots() {
|
||||
if (!p) return result;
|
||||
const char* end = p + std::strlen(p);
|
||||
while (p != end && result.size() < 256) {
|
||||
unsigned root{}, slot{};
|
||||
unsigned root{}, slot{}, last{};
|
||||
auto r = std::from_chars(p, end, root);
|
||||
if (r.ec != std::errc{} || r.ptr == end || *r.ptr != '/') break;
|
||||
auto s = std::from_chars(r.ptr + 1, end, slot);
|
||||
if (s.ec != std::errc{} || (s.ptr != end && *s.ptr != ',')) break;
|
||||
if (root < 32 && slot < (1u << 21)) result.emplace_back(root, slot);
|
||||
if (s.ec != std::errc{}) break;
|
||||
last = slot;
|
||||
if (s.ptr != end && *s.ptr == '-') {
|
||||
s = std::from_chars(s.ptr + 1, end, last);
|
||||
if (s.ec != std::errc{} || last < slot) break;
|
||||
last = std::min(last, slot + 63);
|
||||
}
|
||||
if (s.ptr != end && *s.ptr != ',') break;
|
||||
for (unsigned k = slot; k <= last && root < 32 && k < (1u << 21); ++k) result.emplace_back(root, k);
|
||||
p = s.ptr == end ? end : s.ptr + 1;
|
||||
}
|
||||
return result;
|
||||
@ -86,16 +96,44 @@ inline bool read_backing(Backing b, std::uint64_t offset, void* out, std::size_t
|
||||
// The device owns the arena mapping for its lifetime. Linux cross-process reads can reject a
|
||||
// device mapping even though the current process can read it directly.
|
||||
if (std::string_view(b.kind) == "arena" || std::string_view(b.kind) == "arena-shadow" ||
|
||||
std::string_view(b.kind) == "window-shadow") {
|
||||
std::string_view(b.kind) == "window-shadow" || std::string_view(b.kind) == "mirror-home") {
|
||||
std::memcpy(out, reinterpret_cast<const void*>(b.host + offset), size);
|
||||
return true;
|
||||
}
|
||||
return read_cpu(b.host + offset, out, size);
|
||||
}
|
||||
|
||||
// The page mirror's home of the title page at `va` (what heap_base + va reads), to the page's end: null when the mirror
|
||||
// holds no page there. A device-local home is read over the bus (slow; a diagnostic only).
|
||||
template<class State>
|
||||
const std::uint8_t* mirror_home(State& state, std::uint64_t va, std::uint64_t& room) {
|
||||
if (!state.page_mirror.mirror) return nullptr;
|
||||
std::lock_guard lock(state.page_mirror.mutex);
|
||||
const std::uint8_t* home = state.page_mirror.mirror->home_bytes(va);
|
||||
if (!home) return nullptr;
|
||||
room = leonida::TitleMirror::kPage - (va & (leonida::TitleMirror::kPage - 1));
|
||||
return home + (va & (leonida::TitleMirror::kPage - 1));
|
||||
}
|
||||
|
||||
// What the host has at `va` as an address.
|
||||
inline const char* host_kind(std::uint64_t va) {
|
||||
MEMORY_BASIC_INFORMATION info{};
|
||||
if (!VirtualQuery(reinterpret_cast<const void*>(static_cast<std::uintptr_t>(va)), &info, sizeof(info)) ||
|
||||
info.State == MEM_FREE)
|
||||
return "free";
|
||||
if (info.State != MEM_COMMIT) return "reserved";
|
||||
return info.Type == MEM_IMAGE ? "image" : info.Type == MEM_MAPPED ? "mapped" : "private";
|
||||
}
|
||||
|
||||
template<class State>
|
||||
Backing backing(State& state, std::uint64_t base) {
|
||||
auto& aliases = leonida::title_va_aliases();
|
||||
if (base >= state.arena.size && !(base & (1ull << 47))) {
|
||||
std::uint64_t room = 0;
|
||||
if (const std::uint8_t* home = mirror_home(state, base, room))
|
||||
return {"mirror-home", base, reinterpret_cast<std::uint64_t>(home), room};
|
||||
if (leonida::title_mirror_space::contains(base)) return {"mirror-unbound", base};
|
||||
}
|
||||
std::uint64_t source{}, room{};
|
||||
const bool alias = aliases.source_of_vsharp(base, source, room);
|
||||
if (base < state.arena.size) {
|
||||
@ -306,6 +344,13 @@ Backing descriptor(State& state, std::uint64_t seq, std::size_t list, std::size_
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!have_gpu && title_at) {
|
||||
std::uint64_t room = 0;
|
||||
if (const std::uint8_t* home = mirror_home(state, title_at, room); home && room >= sizeof(gpu)) {
|
||||
std::memcpy(gpu.data(), home, sizeof(gpu)); // a heap read in place: the filtered home
|
||||
have_gpu = true;
|
||||
}
|
||||
}
|
||||
if (!have_gpu) have_gpu = leonida::fsdraw::arena_words(at, gpu.data(), gpu.size());
|
||||
if (have_gpu) remember(at, seq, cmd, reg, slot, gpu);
|
||||
const auto prefix = "[rt] compute-input: execute=%llu list=%zu cmd=%zu s%u/%u ";
|
||||
@ -324,7 +369,27 @@ Backing descriptor(State& state, std::uint64_t seq, std::size_t list, std::size_
|
||||
std::fprintf(stderr, "texture key=%s\n", leonida::fsdraw::has_tsharp(gpu.data()) ? "registered" : "absent");
|
||||
return {"texture"};
|
||||
}
|
||||
if (!(gpu[0] | gpu[1] | gpu[2] | gpu[3])) { std::fputs("null\n", stderr); return {"null"}; }
|
||||
if (!(gpu[0] | gpu[1] | gpu[2] | gpu[3])) {
|
||||
// Null on the GPU side: when the title's slot holds a buffer V#, the layer resolved it to nothing (a heap read
|
||||
// in place zeroes it). Where its base lies, and the title's bytes there, name the memory that read as zeros.
|
||||
if (table && (raw[0] | raw[1] | raw[2] | raw[3]) && !(raw[3] >> 30)) {
|
||||
const auto title_base = std::uint64_t(raw[0]) | (std::uint64_t(raw[1] & 0xffff) << 32);
|
||||
const auto title_stride = (raw[1] >> 16) & 0x3fffu;
|
||||
std::array<std::uint32_t, 16> title{};
|
||||
const auto t = std::min<std::uint64_t>(std::uint64_t(raw[2]) * (title_stride ? title_stride : 1), sizeof(title)) / 4;
|
||||
const bool high = title_base & (1ull << 47);
|
||||
const auto tb = backing(state, title_base);
|
||||
std::fprintf(stderr, "null (resolved to nothing) title-V#=0x%llx stride=%u records=%u storage=%s host=%s",
|
||||
(unsigned long long)title_base, title_stride, raw[2], tb.kind,
|
||||
high ? "bit47" : host_kind(title_base));
|
||||
if (!high && title_base >= state.arena.size && t && read_cpu(title_base, title.data(), 4 * t))
|
||||
std::fprintf(stderr, " title-sample=[%s]", leonida::fsdraw::hex_words(title.data(), t).c_str());
|
||||
std::fputc('\n', stderr);
|
||||
return {"null"};
|
||||
}
|
||||
std::fputs("null\n", stderr);
|
||||
return {"null"};
|
||||
}
|
||||
const auto base = std::uint64_t(gpu[0]) | (std::uint64_t(gpu[1] & 0xffff) << 32);
|
||||
const auto stride = (gpu[1] >> 16) & 0x3fffu;
|
||||
const auto span = std::uint64_t(gpu[2]) * (stride ? stride : 1);
|
||||
@ -337,6 +402,18 @@ Backing descriptor(State& state, std::uint64_t seq, std::size_t list, std::size_
|
||||
const auto n = std::min<std::uint64_t>({span, b.available, sizeof(data)}) / 4;
|
||||
if (n && read_backing(b, 0, data.data(), 4 * n))
|
||||
std::fprintf(stderr, " cpu-sample=[%s]", leonida::fsdraw::hex_words(data.data(), n).c_str());
|
||||
// The title's own bytes at the base (as the title wrote them), when the host has the address: against what the
|
||||
// GPU reads there, the first 16 dwords.
|
||||
{
|
||||
std::array<std::uint32_t, 16> title{};
|
||||
const auto t = std::min<std::uint64_t>(span ? span : 4, sizeof(title)) / 4;
|
||||
const bool read = base >= state.arena.size && !(base & (1ull << 47)) && t && read_cpu(base, title.data(), 4 * t);
|
||||
std::fprintf(stderr, " host=%s", base & (1ull << 47) ? "bit47" : host_kind(base));
|
||||
if (read) {
|
||||
std::fprintf(stderr, " title-sample=[%s]", leonida::fsdraw::hex_words(title.data(), t).c_str());
|
||||
if (n) std::fprintf(stderr, " gpu-vs-title=%s", std::memcmp(title.data(), data.data(), 4 * std::min<std::uint64_t>(n, t)) ? "DIFFER" : "same");
|
||||
}
|
||||
}
|
||||
if (std::string_view(b.kind) == "untranslated-title") {
|
||||
std::uint64_t created_at{};
|
||||
const bool from_cbv = leonida::fsdraw::cbv_origin(base, created_at);
|
||||
|
||||
@ -5525,6 +5525,9 @@ struct DeviceState {
|
||||
std::uint64_t resolutions = 0;
|
||||
double resolution_ms = 0;
|
||||
std::uint64_t nothing[nothing_classes] = {};
|
||||
// For the arena-offset and not-title-memory classes: what the host has at the base as an address
|
||||
// (nothing_where_kind), so a log names the memory a V# resolved to nothing names.
|
||||
std::uint64_t nothing_where[2][5] = {};
|
||||
double max_ms = 0, max_pages_ms = 0, max_changes_ms = 0, max_fix_ms = 0;
|
||||
// Read in place (add_heap_in_place): the page mirror holds the title's heap pages, bound a second time into the
|
||||
// arena at shader_va, and fills their home through filter_heap_page. No copy, no page tracker of its own.
|
||||
@ -6138,6 +6141,17 @@ struct DeviceState {
|
||||
default: break;
|
||||
}
|
||||
++heap.nothing[kind];
|
||||
if (kind == nothing_arena || kind == nothing_not_title)
|
||||
++heap.nothing_where[kind == nothing_not_title][nothing_where_kind(base)];
|
||||
}
|
||||
// What the host has at `base` taken as an address: 0 image, 1 mapped, 2 private committed, 3 reserved, 4 free.
|
||||
static unsigned nothing_where_kind(std::uint64_t base) {
|
||||
MEMORY_BASIC_INFORMATION info{};
|
||||
if (!VirtualQuery(reinterpret_cast<const void*>(static_cast<std::uintptr_t>(base)), &info, sizeof(info)) ||
|
||||
info.State == MEM_FREE)
|
||||
return 4;
|
||||
if (info.State != MEM_COMMIT) return 3;
|
||||
return info.Type == MEM_IMAGE ? 0 : info.Type == MEM_MAPPED ? 1 : 2;
|
||||
}
|
||||
|
||||
void note_refused_tsharp(ConsoleHeap& heap, std::size_t offset, const leonida::gfx10::ImageWords& words,
|
||||
@ -6329,6 +6343,20 @@ struct DeviceState {
|
||||
if (heap->nothing[i])
|
||||
classes += (classes.empty() ? "" : ", ") + std::string(kNothingNames[i]) + " " +
|
||||
std::to_string(heap->nothing[i]);
|
||||
// Where the host has those bases (nothing_where_kind).
|
||||
for (unsigned c = 0; c < 2; ++c) {
|
||||
const std::uint64_t* w = heap->nothing_where[c];
|
||||
if (!(w[0] | w[1] | w[2] | w[3] | w[4])) continue;
|
||||
char text[200];
|
||||
std::snprintf(text, sizeof(text),
|
||||
" (%s bases as host addresses: image %llu, mapped %llu, private %llu, reserved "
|
||||
"%llu, free %llu)",
|
||||
c ? "not title memory" : "arena offset", static_cast<unsigned long long>(w[0]),
|
||||
static_cast<unsigned long long>(w[1]), static_cast<unsigned long long>(w[2]),
|
||||
static_cast<unsigned long long>(w[3]), static_cast<unsigned long long>(w[4]));
|
||||
classes += text;
|
||||
}
|
||||
std::memset(heap->nothing_where, 0, sizeof(heap->nothing_where));
|
||||
std::fprintf(stderr,
|
||||
"[rt] d3d12: console descriptor heap 0x%llx V# halves per submission: %.1f answered by a "
|
||||
"resolved record of their range, %.1f by a waiting one, %.1f resolved anew (%.3f ms, %.2f "
|
||||
|
||||
Reference in New Issue
Block a user