diff options
| author | Mumogg <104529023+Mumogg@users.noreply.github.com> | 2026-11-23 21:31:53 -0600 |
|---|---|---|
| committer | Mumogg <104529023+Mumogg@users.noreply.github.com> | 2026-11-23 21:31:53 -0600 |
| commit | e0d4fd2b81e6636b1c6bb2f76be79e910e84d84b (patch) | |
| tree | 7fe315b21ab6063043460bc6cb177837971a47c0 /runtime | |
| parent | aba24099150adb3ae17cbfe33a60adfcab161497 (diff) | |
runtime: remove the local diagnostics and experiments; descriptor copies check their memory
- The "[rt] localdbg:" lines and the experiment switches are gone: LEONIDA_RECT_GREEN, LEONIDA_RECT_VS,
LEONIDA_RECT_NOGS, LEONIDA_RECT_NOCULL, LEONIDA_RECT_FORCE, LEONIDA_VTX_TEST and LEONIDA_DEBUG_CLEAR, with the
hard-coded test shader words. vulkan_replay.h returns unresolved_resource directly again.
- The descriptor write-through and the table mirror for title-backed heaps only copy between committed memory
they may read and write. A handle that is only a number (xs_proxy_mock's heaps) is left alone; the test
crashed there before.
- A slot 70 view over memory no buffer holds becomes a raw buffer view only when the title-memory registry
(title_va_alias.h) holds the whole range, instead of any address below 4 GiB. xs_proxy_mock's null-view case
passes again.
Still switches: LEONIDA_GRAPHICS_STAGE_LAYOUT, LEONIDA_DESC_MIRROR, LEONIDA_SLOT70_TITLE, LEONIDA_RECT_FOURTH.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HxBQf4pXH8PWpC5oZsM4bt
Diffstat (limited to 'runtime')
| -rw-r--r-- | runtime/shims/d3d12_com.cpp | 11 | ||||
| -rw-r--r-- | runtime/shims/d3d12_vulkan_device.cpp | 108 | ||||
| -rw-r--r-- | runtime/shims/d3d12_xs_device.cpp | 77 | ||||
| -rw-r--r-- | runtime/shims/xbox_present.cpp | 9 | ||||
| -rw-r--r-- | runtime/src/vulkan_replay.h | 157 |
5 files changed, 65 insertions, 297 deletions
diff --git a/runtime/shims/d3d12_com.cpp b/runtime/shims/d3d12_com.cpp index 89b87e004..a1aa3ccc5 100644 --- a/runtime/shims/d3d12_com.cpp +++ b/runtime/shims/d3d12_com.cpp | |||
| @@ -705,17 +705,6 @@ public: | |||
| 705 | d3d12_trace::record("ID3D12GraphicsCommandList::ClearRenderTargetView"); | 705 | d3d12_trace::record("ID3D12GraphicsCommandList::ClearRenderTargetView"); |
| 706 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false); | 706 | if (type_ == D3D12_COMMAND_LIST_TYPE_BUNDLE) return check(false); |
| 707 | if (!view.ptr || !color) return check(false); | 707 | if (!view.ptr || !color) return check(false); |
| 708 | // LOCAL DIAGNOSTIC: LEONIDA_DEBUG_CLEAR=1 clears to magenta; the first clears are logged. | ||
| 709 | static const bool magenta = [] { const char* v = std::getenv("LEONIDA_DEBUG_CLEAR"); return v && *v == '1'; }(); | ||
| 710 | const auto* target = reinterpret_cast<const leonida::TargetView*>(view.ptr); | ||
| 711 | static std::atomic<int> shown{0}; | ||
| 712 | if (shown.fetch_add(1, std::memory_order_relaxed) < 6) | ||
| 713 | std::fprintf(stderr, "[rt] localdbg: clear resource=0x%llx colour=%g %g %g %g rects=%u\n", | ||
| 714 | static_cast<unsigned long long>(target->resource), color[0], color[1], color[2], color[3], count); | ||
| 715 | if (magenta) { | ||
| 716 | check(list_.clear_render_target(*target, {1.0f, 0.0f, 1.0f, 1.0f}, to_rects(count, rects))); | ||
| 717 | return; | ||
| 718 | } | ||
| 719 | check(list_.clear_render_target(*reinterpret_cast<const leonida::TargetView*>(view.ptr), | 708 | check(list_.clear_render_target(*reinterpret_cast<const leonida::TargetView*>(view.ptr), |
| 720 | {color[0], color[1], color[2], color[3]}, to_rects(count, rects))); | 709 | {color[0], color[1], color[2], color[3]}, to_rects(count, rects))); |
| 721 | } | 710 | } |
diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index d82ba6f5d..1a9f1d6e4 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp | |||
| @@ -4142,18 +4142,6 @@ public: | |||
| 4142 | stage.words = std::move(patched); | 4142 | stage.words = std::move(patched); |
| 4143 | } | 4143 | } |
| 4144 | } | 4144 | } |
| 4145 | { // LOCAL EXPERIMENT: LEONIDA_RECT_GREEN=1 gives rectangle-list pipelines a solid green pixel stage, to | ||
| 4146 | // tell "no fragments" from "the pixel shader writes nothing". | ||
| 4147 | static const bool green = [] { const char* v = std::getenv("LEONIDA_RECT_GREEN"); return v && *v == '1'; }(); | ||
| 4148 | static const bool trivial_vs = [] { const char* v = std::getenv("LEONIDA_RECT_VS"); return v && *v == '1'; }(); | ||
| 4149 | if (trivial_vs && rect_list && stage.bit == VK_SHADER_STAGE_VERTEX_BIT) | ||
| 4150 | stage.words = {0x7230203,0x10500,0x70000,0x1d,0x0,0x20011,0x1,0x3000e,0x0,0x1,0x7000f,0x0,0x1,0x6e69616d,0x0,0x2,0x3,0x40047,0x2,0xb,0x2a,0x40047,0x3,0xb,0x0,0x20013,0x4,0x30021,0x5,0x4,0x30016,0x6,0x20,0x40015,0x7,0x20,0x1,0x40017,0x8,0x6,0x4,0x40020,0x9,0x1,0x7,0x40020,0xa,0x3,0x8,0x4003b,0x9,0x2,0x1,0x4003b,0xa,0x3,0x3,0x4002b,0x7,0xb,0x1,0x4002b,0x7,0xc,0x2,0x4002b,0x6,0xd,0x0,0x4002b,0x6,0xe,0x3f800000,0x4002b,0x6,0xf,0x40800000,0x4002b,0x6,0x10,0xbf800000,0x50036,0x4,0x1,0x0,0x5,0x200f8,0x11,0x4003d,0x7,0x12,0x2,0x500c7,0x7,0x13,0x12,0xb,0x500c3,0x7,0x14,0x12,0xb,0x500c7,0x7,0x15,0x14,0xb,0x4006f,0x6,0x16,0x13,0x4006f,0x6,0x17,0x15,0x50085,0x6,0x18,0x16,0xf,0x50085,0x6,0x19,0x17,0xf,0x50081,0x6,0x1a,0x18,0x10,0x50081,0x6,0x1b,0x19,0x10,0x70050,0x8,0x1c,0x1a,0x1b,0xd,0xe,0x3003e,0x3,0x1c,0x100fd,0x10038}; | ||
| 4151 | static const bool passthrough_vs = [] { const char* v = std::getenv("LEONIDA_RECT_VS"); return v && *v == '2'; }(); | ||
| 4152 | if (passthrough_vs && rect_list && stage.bit == VK_SHADER_STAGE_VERTEX_BIT) | ||
| 4153 | stage.words = {0x7230203,0x10500,0x70000,0x11,0x0,0x20011,0x1,0x3000e,0x0,0x1,0x7000f,0x0,0x1,0x6e69616d,0x0,0x2,0x3,0x40047,0x2,0x1e,0x0,0x40047,0x3,0xb,0x0,0x20013,0x4,0x30021,0x5,0x4,0x30016,0x6,0x20,0x40017,0x7,0x6,0x4,0x40020,0x8,0x1,0x7,0x40020,0x9,0x3,0x7,0x4003b,0x8,0x2,0x1,0x4003b,0x9,0x3,0x3,0x4002b,0x6,0xa,0x0,0x4002b,0x6,0xb,0x3f800000,0x50036,0x4,0x1,0x0,0x5,0x200f8,0xc,0x4003d,0x7,0xd,0x2,0x50051,0x6,0xe,0xd,0x0,0x50051,0x6,0xf,0xd,0x1,0x70050,0x7,0x10,0xe,0xf,0xa,0xb,0x3003e,0x3,0x10,0x100fd,0x10038}; | ||
| 4154 | if (green && rect_list && stage.bit == VK_SHADER_STAGE_FRAGMENT_BIT) | ||
| 4155 | stage.words = {0x7230203,0x10500,0x70000,0xc,0x0,0x20011,0x1,0x3000e,0x0,0x1,0x6000f,0x4,0x1,0x6e69616d,0x0,0x2,0x30010,0x1,0x7,0x40047,0x2,0x1e,0x0,0x20013,0x3,0x30021,0x4,0x3,0x30016,0x5,0x20,0x40017,0x6,0x5,0x4,0x40020,0x7,0x3,0x6,0x4003b,0x7,0x2,0x3,0x4002b,0x5,0x8,0x0,0x4002b,0x5,0x9,0x3f800000,0x7002c,0x6,0xa,0x8,0x9,0x8,0x9,0x50036,0x3,0x1,0x0,0x4,0x200f8,0xb,0x3003e,0x2,0xa,0x100fd,0x10038}; | ||
| 4156 | } | ||
| 4157 | VkShaderModuleCreateInfo module_info{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; | 4145 | VkShaderModuleCreateInfo module_info{VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; |
| 4158 | module_info.codeSize = stage.words.size() * 4; | 4146 | module_info.codeSize = stage.words.size() * 4; |
| 4159 | module_info.pCode = stage.words.data(); | 4147 | module_info.pCode = stage.words.data(); |
| @@ -4167,9 +4155,7 @@ public: | |||
| 4167 | subgroup_size_for(*stage.entry, required_sizes[stage_infos.size()], info); | 4155 | subgroup_size_for(*stage.entry, required_sizes[stage_infos.size()], info); |
| 4168 | stage_infos.push_back(info); | 4156 | stage_infos.push_back(info); |
| 4169 | } | 4157 | } |
| 4170 | // LOCAL EXPERIMENT: LEONIDA_RECT_NOGS=1 draws the rectangle list's three corners as a plain triangle. | 4158 | if (rect_list) { // the stage that adds each rectangle's fourth corner, from the vertex shader's outputs |
| 4171 | static const bool local_no_gs = [] { const char* v = std::getenv("LEONIDA_RECT_NOGS"); return v && *v == '1'; }(); | ||
| 4172 | if (rect_list && !local_no_gs) { // the stage that adds each rectangle's fourth corner, from the vertex shader's outputs | ||
| 4173 | std::string why; | 4159 | std::string why; |
| 4174 | const std::vector<std::uint32_t> words = leonida::rect_list_geometry(vs_stage.words, why); | 4160 | const std::vector<std::uint32_t> words = leonida::rect_list_geometry(vs_stage.words, why); |
| 4175 | if (words.empty()) { | 4161 | if (words.empty()) { |
| @@ -4230,16 +4216,6 @@ public: | |||
| 4230 | if (e.system_value == 0 && e.semantic_index == element.SemanticIndex && | 4216 | if (e.system_value == 0 && e.semantic_index == element.SemanticIndex && |
| 4231 | equal_semantic(e.semantic, element.SemanticName)) | 4217 | equal_semantic(e.semantic, element.SemanticName)) |
| 4232 | input = &e; | 4218 | input = &e; |
| 4233 | { // LOCAL DIAGNOSTIC: the input layout of the first graphics pipelines with one | ||
| 4234 | static std::atomic<int> said{0}; | ||
| 4235 | const std::string& vsn = stages[0].entry->name; | ||
| 4236 | if ((vsn.find("Blit") != std::string::npos || vsn.find("sga_dr") != std::string::npos) && said.fetch_add(1) < 24) | ||
| 4237 | std::fprintf(stderr, "[rt] localdbg: input element %u/%u %s%u dxgi=%d slot=%u offset=%u -> %s (vs %s)\n", i, | ||
| 4238 | desc.InputLayout.NumElements, element.SemanticName ? element.SemanticName : "?", | ||
| 4239 | element.SemanticIndex, int(element.Format), element.InputSlot, offset, | ||
| 4240 | input ? ("location " + std::to_string(input->register_index)).c_str() : "not read", | ||
| 4241 | stages[0].entry->name.c_str()); | ||
| 4242 | } | ||
| 4243 | if (!input) continue; // the shader does not read this element | 4219 | if (!input) continue; // the shader does not read this element |
| 4244 | attributes.push_back({input->register_index, element.InputSlot, format, offset}); | 4220 | attributes.push_back({input->register_index, element.InputSlot, format, offset}); |
| 4245 | const bool instance = element.InputSlotClass == D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA; | 4221 | const bool instance = element.InputSlotClass == D3D12_INPUT_CLASSIFICATION_PER_INSTANCE_DATA; |
| @@ -4262,13 +4238,6 @@ public: | |||
| 4262 | instance ? VK_VERTEX_INPUT_RATE_INSTANCE : VK_VERTEX_INPUT_RATE_VERTEX}); | 4238 | instance ? VK_VERTEX_INPUT_RATE_INSTANCE : VK_VERTEX_INPUT_RATE_VERTEX}); |
| 4263 | } | 4239 | } |
| 4264 | } | 4240 | } |
| 4265 | { // LOCAL DIAGNOSTIC | ||
| 4266 | static std::atomic<int> said2{0}; | ||
| 4267 | const std::string& vsn = stages[0].entry->name; | ||
| 4268 | if (!mesh && (vsn.find("Blit") != std::string::npos || vsn.find("sga_dr") != std::string::npos) && said2.fetch_add(1) < 8) | ||
| 4269 | std::fprintf(stderr, "[rt] localdbg: %s input layout elements=%u attributes=%zu signature=%zu\n", vsn.c_str(), | ||
| 4270 | desc.InputLayout.NumElements, attributes.size(), stages[0].entry->input_signature.size()); | ||
| 4271 | } | ||
| 4272 | for (const auto& e : stages[0].entry->input_signature) { | 4241 | for (const auto& e : stages[0].entry->input_signature) { |
| 4273 | if (e.system_value) continue; | 4242 | if (e.system_value) continue; |
| 4274 | const bool fed = std::any_of(attributes.begin(), attributes.end(), | 4243 | const bool fed = std::any_of(attributes.begin(), attributes.end(), |
| @@ -4319,16 +4288,6 @@ public: | |||
| 4319 | : VK_CULL_MODE_NONE; | 4288 | : VK_CULL_MODE_NONE; |
| 4320 | // With the negative-height viewport, framebuffer winding matches D3D12's screen-space winding. | 4289 | // With the negative-height viewport, framebuffer winding matches D3D12's screen-space winding. |
| 4321 | raster.frontFace = r.FrontCounterClockwise ? VK_FRONT_FACE_COUNTER_CLOCKWISE : VK_FRONT_FACE_CLOCKWISE; | 4290 | raster.frontFace = r.FrontCounterClockwise ? VK_FRONT_FACE_COUNTER_CLOCKWISE : VK_FRONT_FACE_CLOCKWISE; |
| 4322 | // LOCAL EXPERIMENT: LEONIDA_RECT_NOCULL=1 draws rectangle lists without face culling (hypothesis: the | ||
| 4323 | // console's rectangle primitive has no facing, so the PSO's cull mode does not apply to it). | ||
| 4324 | if (rect_list) { | ||
| 4325 | static const bool no_cull = [] { const char* v = std::getenv("LEONIDA_RECT_NOCULL"); return v && *v == '1'; }(); | ||
| 4326 | static std::atomic<int> said{0}; | ||
| 4327 | if (said.fetch_add(1) < 4) | ||
| 4328 | std::fprintf(stderr, "[rt] localdbg: rect-list pipeline cull=%u frontCCW=%d depthClip=%d no_cull=%d\n", | ||
| 4329 | unsigned(r.CullMode), int(r.FrontCounterClockwise), int(r.DepthClipEnable), int(no_cull)); | ||
| 4330 | if (no_cull) raster.cullMode = VK_CULL_MODE_NONE; | ||
| 4331 | } | ||
| 4332 | // The D24-as-D32 pixel stage applies the bias itself, in D24 units (depth24_fragment above): the | 4291 | // The D24-as-D32 pixel stage applies the bias itself, in D24 units (depth24_fragment above): the |
| 4333 | // rasterizer's bias stays off and zero, so its clamp needs no depthBiasClamp feature either. | 4292 | // rasterizer's bias stays off and zero, so its clamp needs no depthBiasClamp feature either. |
| 4334 | raster.depthBiasEnable = !depth24_fragment && (r.DepthBias || r.SlopeScaledDepthBias != 0.0f); | 4293 | raster.depthBiasEnable = !depth24_fragment && (r.DepthBias || r.SlopeScaledDepthBias != 0.0f); |
| @@ -4369,31 +4328,6 @@ public: | |||
| 4369 | blends[i].dstAlphaBlendFactor = blend_factor(b.DestBlendAlpha); | 4328 | blends[i].dstAlphaBlendFactor = blend_factor(b.DestBlendAlpha); |
| 4370 | blends[i].alphaBlendOp = blend_op(b.BlendOpAlpha); | 4329 | blends[i].alphaBlendOp = blend_op(b.BlendOpAlpha); |
| 4371 | blends[i].colorWriteMask = b.RenderTargetWriteMask & 0xf; // R, G, B, A in both APIs | 4330 | blends[i].colorWriteMask = b.RenderTargetWriteMask & 0xf; // R, G, B, A in both APIs |
| 4372 | if (rect_list) { // LOCAL DIAGNOSTIC / EXPERIMENT (LEONIDA_RECT_FORCE=1: opaque, no depth or stencil test) | ||
| 4373 | static const bool force = [] { const char* v = std::getenv("LEONIDA_RECT_FORCE"); return v && *v == '1'; }(); | ||
| 4374 | static std::atomic<int> said{0}; | ||
| 4375 | if (said.load() < 6) | ||
| 4376 | for (const auto& st : stages) | ||
| 4377 | if (st.entry) | ||
| 4378 | std::fprintf(stderr, "[rt] localdbg: rect pipeline stage %s = %s wave64=%d emulated=%d push=%u\n", | ||
| 4379 | st.entry->stage.c_str(), st.entry->name.c_str(), int(st.entry->wave64), | ||
| 4380 | int(st.entry->emulated()), st.entry->push_constant_bytes); | ||
| 4381 | if (said.fetch_add(1) < 6) | ||
| 4382 | std::fprintf(stderr, "[rt] localdbg: rect pipeline rt%u/%u blend=%d src=%d dst=%d op=%d srcA=%d dstA=%d " | ||
| 4383 | "mask=0x%x depth=%d write=%d func=%d stencil=%d samplemask=0x%x fmt=%d a2c=%d force=%d\n", | ||
| 4384 | i, desc.NumRenderTargets, int(b.BlendEnable), int(b.SrcBlend), int(b.DestBlend), | ||
| 4385 | int(b.BlendOp), int(b.SrcBlendAlpha), int(b.DestBlendAlpha), | ||
| 4386 | unsigned(b.RenderTargetWriteMask), int(ds.DepthEnable), int(ds.DepthWriteMask), | ||
| 4387 | int(ds.DepthFunc), int(ds.StencilEnable), unsigned(desc.SampleMask), | ||
| 4388 | int(desc.RTVFormats[i]), int(desc.BlendState.AlphaToCoverageEnable), int(force)); | ||
| 4389 | if (force) { | ||
| 4390 | blends[i].blendEnable = VK_FALSE; | ||
| 4391 | blends[i].colorWriteMask = 0xf; | ||
| 4392 | depth.depthTestEnable = VK_FALSE; | ||
| 4393 | depth.depthWriteEnable = VK_FALSE; | ||
| 4394 | depth.stencilTestEnable = VK_FALSE; | ||
| 4395 | } | ||
| 4396 | } | ||
| 4397 | // B8G8R8X8 has no alpha, so blending reads destination alpha as 1 there (WARP and AMD's D3D12 driver), | 4331 | // B8G8R8X8 has no alpha, so blending reads destination alpha as 1 there (WARP and AMD's D3D12 driver), |
| 4398 | // where its BGRA8 Vulkan image would read the X byte. For colour SRC_ALPHA_SAT is min(As, 1 - Ad), so 0; | 4332 | // where its BGRA8 Vulkan image would read the X byte. For colour SRC_ALPHA_SAT is min(As, 1 - Ad), so 0; |
| 4399 | // for alpha it is 1 in both APIs already. | 4333 | // for alpha it is 1 in both APIs already. |
| @@ -6099,10 +6033,7 @@ public: | |||
| 6099 | state_.context->set_heap_base(arena.address); | 6033 | state_.context->set_heap_base(arena.address); |
| 6100 | state_.context->set_zero_page(arena.buffer, 0, kZeroPage); | 6034 | state_.context->set_zero_page(arena.buffer, 0, kZeroPage); |
| 6101 | state_.context->set_quad_indices(arena.buffer, kZeroPage, kQuadIndexCount); | 6035 | state_.context->set_quad_indices(arena.buffer, kZeroPage, kQuadIndexCount); |
| 6102 | leonida::g_local_arena_mapped = arena.mapped; // LOCAL DIAGNOSTIC | 6036 | // Vertex and index views that name the title's own CPU memory are copied into a ring carved from the |
| 6103 | std::fprintf(stderr, "[rt] localdbg: arena mapped at %p\n", static_cast<void*>(arena.mapped)); | ||
| 6104 | leonida::g_local_arena_size = arena.size; | ||
| 6105 | // LOCAL: vertex and index views that name the title's own CPU memory are copied into a ring carved from the | ||
| 6106 | // arena at replay (not fence-tracked: the ring is large against a frame's few KiB of immediate geometry). | 6037 | // arena at replay (not fence-tracked: the ring is large against a frame's few KiB of immediate geometry). |
| 6107 | state_.context->set_title_memory( | 6038 | state_.context->set_title_memory( |
| 6108 | [st = &state_](std::uint64_t va, std::uint64_t size, VkBuffer& buffer, VkDeviceSize& offset) { | 6039 | [st = &state_](std::uint64_t va, std::uint64_t size, VkBuffer& buffer, VkDeviceSize& offset) { |
| @@ -6110,16 +6041,6 @@ public: | |||
| 6110 | static std::mutex mutex; | 6041 | static std::mutex mutex; |
| 6111 | static VkDeviceSize ring_base = 0, ring_next = 0; | 6042 | static VkDeviceSize ring_base = 0, ring_next = 0; |
| 6112 | static bool tried = false, logged = false; | 6043 | static bool tried = false, logged = false; |
| 6113 | static std::atomic<int> dbg{0}; | ||
| 6114 | if (dbg.fetch_add(1) < 6) { | ||
| 6115 | MEMORY_BASIC_INFORMATION q{}; | ||
| 6116 | const SIZE_T got = VirtualQuery(reinterpret_cast<const void*>(va), &q, sizeof(q)); | ||
| 6117 | std::fprintf(stderr, "[rt] localdbg: title_memory va=0x%llx size=0x%llx query=%zu state=0x%lx " | ||
| 6118 | "protect=0x%lx type=0x%lx region=0x%llx mapped=%d\n", | ||
| 6119 | static_cast<unsigned long long>(va), static_cast<unsigned long long>(size), | ||
| 6120 | static_cast<std::size_t>(got), q.State, q.Protect, q.Type, | ||
| 6121 | static_cast<unsigned long long>(q.RegionSize), st->arena.mapped != nullptr); | ||
| 6122 | } | ||
| 6123 | if (!va || !size || size > kRing / 4 || !st->arena.mapped) return false; | 6044 | if (!va || !size || size > kRing / 4 || !st->arena.mapped) return false; |
| 6124 | // The whole range must be committed, readable host memory. | 6045 | // The whole range must be committed, readable host memory. |
| 6125 | for (std::uint64_t at = va; at < va + size;) { | 6046 | for (std::uint64_t at = va; at < va + size;) { |
| @@ -6139,35 +6060,12 @@ public: | |||
| 6139 | if (ring_next + aligned > kRing) ring_next = 0; | 6060 | if (ring_next + aligned > kRing) ring_next = 0; |
| 6140 | std::memcpy(st->arena.mapped + ring_base + ring_next, reinterpret_cast<const void*>(va), | 6061 | std::memcpy(st->arena.mapped + ring_base + ring_next, reinterpret_cast<const void*>(va), |
| 6141 | std::size_t(size)); | 6062 | std::size_t(size)); |
| 6142 | { // LOCAL EXPERIMENT: LEONIDA_VTX_TEST=1 overwrites the copy with a screen-covering triangle (stride 24) | ||
| 6143 | static const char mode = [] { const char* v = std::getenv("LEONIDA_VTX_TEST"); return v ? *v : '0'; }(); | ||
| 6144 | const float second_y = reinterpret_cast<const float*>(st->arena.mapped + ring_base + ring_next)[7]; | ||
| 6145 | const bool test = mode == '1' || (mode == 'A' && second_y < 100.f) || (mode == 'B' && second_y >= 100.f); | ||
| 6146 | if (test && size >= 72) { | ||
| 6147 | const float tri[3][2] = {{-1.f, -1.f}, {3.f, -1.f}, {-1.f, 3.f}}; | ||
| 6148 | for (int v = 0; v < 3; ++v) { | ||
| 6149 | float* q = reinterpret_cast<float*>(st->arena.mapped + ring_base + ring_next + v * 24); | ||
| 6150 | q[0] = tri[v][0]; q[1] = tri[v][1]; q[2] = 0.f; | ||
| 6151 | } | ||
| 6152 | } | ||
| 6153 | static std::atomic<int> said{0}; | ||
| 6154 | if (said.load() < 6) { | ||
| 6155 | const float* q = reinterpret_cast<const float*>(st->arena.mapped + ring_base + ring_next); | ||
| 6156 | std::fprintf(stderr, "[rt] localdbg: ring copy holds %g,%g | %g,%g | %g,%g (size %llu)\n", q[0], q[1], | ||
| 6157 | q[6], q[7], q[12], q[13], static_cast<unsigned long long>(size)); | ||
| 6158 | } | ||
| 6159 | if (said.fetch_add(1) < 3) | ||
| 6160 | std::fprintf(stderr, "[rt] localdbg: ring copy at arena offset 0x%llx (ring_base 0x%llx) arena size 0x%llx\n", | ||
| 6161 | static_cast<unsigned long long>(ring_base + ring_next), | ||
| 6162 | static_cast<unsigned long long>(ring_base), | ||
| 6163 | static_cast<unsigned long long>(st->arena.size)); | ||
| 6164 | } | ||
| 6165 | buffer = st->arena.buffer; | 6063 | buffer = st->arena.buffer; |
| 6166 | offset = ring_base + ring_next; | 6064 | offset = ring_base + ring_next; |
| 6167 | ring_next += aligned; | 6065 | ring_next += aligned; |
| 6168 | if (!logged) { | 6066 | if (!logged) { |
| 6169 | logged = true; | 6067 | logged = true; |
| 6170 | std::fprintf(stderr, "[rt] d3d12: local: vertex/index views in title memory are copied into a " | 6068 | std::fprintf(stderr, "[rt] d3d12: vertex/index views in title memory are copied into a " |
| 6171 | "%llu MiB ring (first: %llu bytes)\n", | 6069 | "%llu MiB ring (first: %llu bytes)\n", |
| 6172 | static_cast<unsigned long long>(kRing >> 20), static_cast<unsigned long long>(size)); | 6070 | static_cast<unsigned long long>(kRing >> 20), static_cast<unsigned long long>(size)); |
| 6173 | } | 6071 | } |
diff --git a/runtime/shims/d3d12_xs_device.cpp b/runtime/shims/d3d12_xs_device.cpp index 09d753a86..9bfa5ea7f 100644 --- a/runtime/shims/d3d12_xs_device.cpp +++ b/runtime/shims/d3d12_xs_device.cpp | |||
| @@ -24,6 +24,7 @@ | |||
| 24 | // 78 SetFrameIntervalX, 79 ScheduleFrameEventX and 80 WaitFrameEventX. The slots can be moved with LEONIDA_XS_*_SLOT | 24 | // 78 SetFrameIntervalX, 79 ScheduleFrameEventX and 80 WaitFrameEventX. The slots can be moved with LEONIDA_XS_*_SLOT |
| 25 | // for a trace that disagrees. The frame-event calls answer from a per-device token counter: there is no vblank source | 25 | // for a trace that disagrees. The frame-event calls answer from a per-device token counter: there is no vblank source |
| 26 | // behind the device before a presenter exists, so WaitFrameEventX returns at once with a fresh non-zero token. | 26 | // behind the device before a presenter exists, so WaitFrameEventX returns at once with a fresh non-zero token. |
| 27 | #include "../src/title_va_alias.h" | ||
| 27 | #include "title_window.h" | 28 | #include "title_window.h" |
| 28 | #include "d3d12_xs_device.h" | 29 | #include "d3d12_xs_device.h" |
| 29 | #include "d3d12_trace.h" | 30 | #include "d3d12_trace.h" |
| @@ -166,9 +167,6 @@ bool register_descriptor_range(const DeviceProxy* device, const HeapProxy* heap, | |||
| 166 | return false; | 167 | return false; |
| 167 | try { | 168 | try { |
| 168 | std::lock_guard lock(descriptor_range_mutex()); | 169 | std::lock_guard lock(descriptor_range_mutex()); |
| 169 | std::fprintf(stderr, "[rt] localdbg: descriptor range custom=0x%llx..0x%llx real_cpu=0x%llx heap=%p\n", | ||
| 170 | static_cast<unsigned long long>(custom_start), static_cast<unsigned long long>(custom_start + byte_size), | ||
| 171 | static_cast<unsigned long long>(real_start), static_cast<const void*>(heap)); | ||
| 172 | descriptor_ranges().push_back({custom_start, custom_start + byte_size, real_start, device, heap}); | 170 | descriptor_ranges().push_back({custom_start, custom_start + byte_size, real_start, device, heap}); |
| 173 | g_custom_range_count.store(descriptor_ranges().size(), std::memory_order_release); | 171 | g_custom_range_count.store(descriptor_ranges().size(), std::memory_order_release); |
| 174 | return true; | 172 | return true; |
| @@ -216,10 +214,33 @@ bool local_desc_mirror() { | |||
| 216 | return on; | 214 | return on; |
| 217 | } | 215 | } |
| 218 | 216 | ||
| 217 | // Whether [address, address + bytes) is committed memory that can be read (and, with `write`, written). A handle | ||
| 218 | // that is only a number (a mock's, or a range the title has released) is left alone instead of faulting. | ||
| 219 | bool local_accessible(std::uint64_t address, std::uint64_t bytes, bool write) { | ||
| 220 | const std::uint64_t end = address + bytes; | ||
| 221 | if (!address || end < address) return false; | ||
| 222 | while (address < end) { | ||
| 223 | MEMORY_BASIC_INFORMATION info{}; | ||
| 224 | if (!VirtualQuery(reinterpret_cast<const void*>(address), &info, sizeof(info)) || info.State != MEM_COMMIT) | ||
| 225 | return false; | ||
| 226 | const DWORD protect = info.Protect & 0xff; | ||
| 227 | if (info.Protect & PAGE_GUARD) return false; | ||
| 228 | const bool writable = protect == PAGE_READWRITE || protect == PAGE_WRITECOPY || | ||
| 229 | protect == PAGE_EXECUTE_READWRITE || protect == PAGE_EXECUTE_WRITECOPY; | ||
| 230 | const bool readable = writable || protect == PAGE_READONLY || protect == PAGE_EXECUTE_READ; | ||
| 231 | if (write ? !writable : !readable) return false; | ||
| 232 | address = reinterpret_cast<std::uint64_t>(info.BaseAddress) + info.RegionSize; | ||
| 233 | } | ||
| 234 | return true; | ||
| 235 | } | ||
| 236 | |||
| 219 | void local_write_through(const DeviceProxy* device, D3D12_CPU_DESCRIPTOR_HANDLE custom, SIZE_T count) { | 237 | void local_write_through(const DeviceProxy* device, D3D12_CPU_DESCRIPTOR_HANDLE custom, SIZE_T count) { |
| 220 | if (!local_desc_mirror() || !custom.ptr || !count) return; | 238 | if (!local_desc_mirror() || !custom.ptr || !count) return; |
| 221 | const D3D12_CPU_DESCRIPTOR_HANDLE real = translate_cpu_handle(device, custom); | 239 | const D3D12_CPU_DESCRIPTOR_HANDLE real = translate_cpu_handle(device, custom); |
| 222 | if (real.ptr == custom.ptr) return; | 240 | if (real.ptr == custom.ptr) return; |
| 241 | if (!local_accessible(real.ptr, count * kLocalDescriptorBytes, false) || | ||
| 242 | !local_accessible(custom.ptr, count * kLocalDescriptorBytes, true)) | ||
| 243 | return; | ||
| 223 | std::memcpy(reinterpret_cast<void*>(custom.ptr), reinterpret_cast<const void*>(real.ptr), | 244 | std::memcpy(reinterpret_cast<void*>(custom.ptr), reinterpret_cast<const void*>(real.ptr), |
| 224 | count * kLocalDescriptorBytes); | 245 | count * kLocalDescriptorBytes); |
| 225 | static std::atomic<bool> said{false}; | 246 | static std::atomic<bool> said{false}; |
| @@ -240,6 +261,9 @@ void local_mirror_table(const DeviceProxy* device, std::uint64_t gpu_handle) { | |||
| 240 | if (!gpu_start || gpu_handle < gpu_start || gpu_handle >= gpu_start + bytes) continue; | 261 | if (!gpu_start || gpu_handle < gpu_start || gpu_handle >= gpu_start + bytes) continue; |
| 241 | const std::uint64_t offset = (gpu_handle - gpu_start) / kLocalDescriptorBytes * kLocalDescriptorBytes; | 262 | const std::uint64_t offset = (gpu_handle - gpu_start) / kLocalDescriptorBytes * kLocalDescriptorBytes; |
| 242 | const std::uint64_t slots = (std::min<std::uint64_t>)(kLocalMirrorSlots, (bytes - offset) / kLocalDescriptorBytes); | 263 | const std::uint64_t slots = (std::min<std::uint64_t>)(kLocalMirrorSlots, (bytes - offset) / kLocalDescriptorBytes); |
| 264 | if (!local_accessible(range.custom_start + offset, slots * kLocalDescriptorBytes, false) || | ||
| 265 | !local_accessible(range.real_start + offset, slots * kLocalDescriptorBytes, true)) | ||
| 266 | return; | ||
| 243 | std::uint64_t copied = 0; | 267 | std::uint64_t copied = 0; |
| 244 | for (std::uint64_t i = 0; i < slots; ++i) { | 268 | for (std::uint64_t i = 0; i < slots; ++i) { |
| 245 | const auto* from = reinterpret_cast<const std::uint64_t*>(range.custom_start + offset + i * kLocalDescriptorBytes); | 269 | const auto* from = reinterpret_cast<const std::uint64_t*>(range.custom_start + offset + i * kLocalDescriptorBytes); |
| @@ -740,22 +764,12 @@ D3D12_CPU_DESCRIPTOR_HANDLE heap_get_cpu_handle(HeapProxy* self) { | |||
| 740 | 764 | ||
| 741 | D3D12_GPU_DESCRIPTOR_HANDLE heap_get_gpu_handle(HeapProxy* self) { | 765 | D3D12_GPU_DESCRIPTOR_HANDLE heap_get_gpu_handle(HeapProxy* self) { |
| 742 | note_heap_slot(10); | 766 | note_heap_slot(10); |
| 743 | { | ||
| 744 | static std::atomic<int> said{0}; | ||
| 745 | if (said.fetch_add(1) < 8) std::fprintf(stderr, "[rt] localdbg: heap slot 10 (GPU handle) asked on heap %p\n", static_cast<void*>(self)); | ||
| 746 | } | ||
| 747 | constexpr UINT64 kUnset = ~static_cast<UINT64>(0); | 767 | constexpr UINT64 kUnset = ~static_cast<UINT64>(0); |
| 748 | D3D12_GPU_DESCRIPTOR_HANDLE handle{}; | 768 | D3D12_GPU_DESCRIPTOR_HANDLE handle{}; |
| 749 | handle.ptr = kUnset; | 769 | handle.ptr = kUnset; |
| 750 | using Fn = D3D12_GPU_DESCRIPTOR_HANDLE(WINAPI*)(ID3D12DescriptorHeap*, D3D12_GPU_DESCRIPTOR_HANDLE*); | 770 | using Fn = D3D12_GPU_DESCRIPTOR_HANDLE(WINAPI*)(ID3D12DescriptorHeap*, D3D12_GPU_DESCRIPTOR_HANDLE*); |
| 751 | const D3D12_GPU_DESCRIPTOR_HANDLE returned = | 771 | const D3D12_GPU_DESCRIPTOR_HANDLE returned = |
| 752 | reinterpret_cast<Fn>(self->real_vtable[10])(self->real, &handle); | 772 | reinterpret_cast<Fn>(self->real_vtable[10])(self->real, &handle); |
| 753 | { | ||
| 754 | static std::atomic<int> said{0}; | ||
| 755 | if (said.fetch_add(1) < 4) | ||
| 756 | std::fprintf(stderr, "[rt] localdbg: heap %p slot 10 answers GPU handle 0x%llx\n", static_cast<void*>(self), | ||
| 757 | static_cast<unsigned long long>(handle.ptr != kUnset ? handle.ptr : returned.ptr)); | ||
| 758 | } | ||
| 759 | return handle.ptr != kUnset ? handle : returned; | 773 | return handle.ptr != kUnset ? handle : returned; |
| 760 | } | 774 | } |
| 761 | 775 | ||
| @@ -2538,12 +2552,6 @@ void proxy_create_srv_from_raw_x(DeviceProxy* self, std::uint64_t texture_words, | |||
| 2538 | std::uint64_t custom; | 2552 | std::uint64_t custom; |
| 2539 | ~LocalWriteThrough() { local_write_through(self, D3D12_CPU_DESCRIPTOR_HANDLE{static_cast<SIZE_T>(custom)}, 1); } | 2553 | ~LocalWriteThrough() { local_write_through(self, D3D12_CPU_DESCRIPTOR_HANDLE{static_cast<SIZE_T>(custom)}, 1); } |
| 2540 | } local_write_back{self, destination}; | 2554 | } local_write_back{self, destination}; |
| 2541 | { | ||
| 2542 | static std::atomic<int> calls{0}; | ||
| 2543 | const int n = calls.fetch_add(1); | ||
| 2544 | if (n < 4 || n % 5000 == 0) | ||
| 2545 | std::fprintf(stderr, "[rt] localdbg: slot 70 call #%d dest=0x%llx\n", n, static_cast<unsigned long long>(destination)); | ||
| 2546 | } | ||
| 2547 | // The console hands a CPU descriptor handle in the title's heap memory; #7021 translates it to the real heap's. | 2555 | // The console hands a CPU descriptor handle in the title's heap memory; #7021 translates it to the real heap's. |
| 2548 | destination = translate_cpu_handle(self, D3D12_CPU_DESCRIPTOR_HANDLE{static_cast<SIZE_T>(destination)}).ptr; | 2556 | destination = translate_cpu_handle(self, D3D12_CPU_DESCRIPTOR_HANDLE{static_cast<SIZE_T>(destination)}).ptr; |
| 2549 | 2557 | ||
| @@ -2561,7 +2569,10 @@ void proxy_create_srv_from_raw_x(DeviceProxy* self, std::uint64_t texture_words, | |||
| 2561 | // LOCAL: a small raw view over the title's own memory becomes a raw buffer V# through the constant-view path, | 2569 | // LOCAL: a small raw view over the title's own memory becomes a raw buffer V# through the constant-view path, |
| 2562 | // which resolves a title address to its GPU copy (#9137). LEONIDA_SLOT70_TITLE=0 keeps the null view. | 2570 | // which resolves a title address to its GPU copy (#9137). LEONIDA_SLOT70_TITLE=0 keeps the null view. |
| 2563 | static const bool title_views = [] { const char* v = std::getenv("LEONIDA_SLOT70_TITLE"); return !(v && *v == '0'); }(); | 2571 | static const bool title_views = [] { const char* v = std::getenv("LEONIDA_SLOT70_TITLE"); return !(v && *v == '0'); }(); |
| 2564 | if (title_views && shape.va && shape.va < 0x100000000ull && shape.resource.Width && shape.resource.Width <= 65536) { | 2572 | std::uint64_t title_lo = 0, title_hi = 0; |
| 2573 | if (title_views && shape.resource.Width && shape.resource.Width <= 65536 && | ||
| 2574 | leonida::title_va_aliases().title_memory(shape.va, title_lo, title_hi) && | ||
| 2575 | shape.resource.Width <= title_hi - shape.va) { | ||
| 2565 | D3D12_CONSTANT_BUFFER_VIEW_DESC constants{}; | 2576 | D3D12_CONSTANT_BUFFER_VIEW_DESC constants{}; |
| 2566 | constants.BufferLocation = shape.va; | 2577 | constants.BufferLocation = shape.va; |
| 2567 | constants.SizeInBytes = static_cast<UINT>(shape.resource.Width); | 2578 | constants.SizeInBytes = static_cast<UINT>(shape.resource.Width); |
| @@ -2573,13 +2584,6 @@ void proxy_create_srv_from_raw_x(DeviceProxy* self, std::uint64_t texture_words, | |||
| 2573 | return; | 2584 | return; |
| 2574 | } | 2585 | } |
| 2575 | log_slot70_null_once("no buffer holds the address", texture_words, view_desc); | 2586 | log_slot70_null_once("no buffer holds the address", texture_words, view_desc); |
| 2576 | { | ||
| 2577 | static std::atomic<int> nulls{0}; | ||
| 2578 | const int n = nulls.fetch_add(1); | ||
| 2579 | if (n < 3 || n % 5000 == 0) | ||
| 2580 | std::fprintf(stderr, "[rt] localdbg: slot 70 null #%d: no buffer holds va=0x%llx width=%llu\n", n, | ||
| 2581 | static_cast<unsigned long long>(shape.va), static_cast<unsigned long long>(shape.resource.Width)); | ||
| 2582 | } | ||
| 2583 | write_null_srv(self, destination); | 2587 | write_null_srv(self, destination); |
| 2584 | return; | 2588 | return; |
| 2585 | } | 2589 | } |
| @@ -2783,25 +2787,6 @@ HRESULT proxy_create_descriptor_heap(DeviceProxy* self, const D3D12_DESCRIPTOR_H | |||
| 2783 | void proxy_create_cbv(DeviceProxy* self, const D3D12_CONSTANT_BUFFER_VIEW_DESC* desc, | 2787 | void proxy_create_cbv(DeviceProxy* self, const D3D12_CONSTANT_BUFFER_VIEW_DESC* desc, |
| 2784 | D3D12_CPU_DESCRIPTOR_HANDLE dest) { | 2788 | D3D12_CPU_DESCRIPTOR_HANDLE dest) { |
| 2785 | note_slot(17); | 2789 | note_slot(17); |
| 2786 | { // LOCAL DIAGNOSTIC | ||
| 2787 | static std::atomic<int> said{0}; | ||
| 2788 | const int n = said.fetch_add(1); | ||
| 2789 | if (n < 6 || (n > 3000 && n < 3008)) { | ||
| 2790 | const D3D12_CPU_DESCRIPTOR_HANDLE t = translate_cpu_handle(self, dest); | ||
| 2791 | std::fprintf(stderr, "[rt] localdbg: CreateCBV #%d dest=0x%llx -> 0x%llx location=0x%llx size=%u\n", n, | ||
| 2792 | static_cast<unsigned long long>(dest.ptr), static_cast<unsigned long long>(t.ptr), | ||
| 2793 | desc ? static_cast<unsigned long long>(desc->BufferLocation) : 0ull, desc ? desc->SizeInBytes : 0u); | ||
| 2794 | MEMORY_BASIC_INFORMATION q{}; | ||
| 2795 | if (desc && desc->BufferLocation && desc->BufferLocation < 0x100000000ull && | ||
| 2796 | VirtualQuery(reinterpret_cast<const void*>(desc->BufferLocation), &q, sizeof(q)) && q.State == MEM_COMMIT && | ||
| 2797 | !(q.Protect & (PAGE_NOACCESS | PAGE_GUARD))) { | ||
| 2798 | const float* f = reinterpret_cast<const float*>(desc->BufferLocation); | ||
| 2799 | std::fprintf(stderr, "[rt] localdbg: constants now:"); | ||
| 2800 | for (int w = 0; w < 24 && w * 4u < desc->SizeInBytes; ++w) std::fprintf(stderr, " %g", f[w]); | ||
| 2801 | std::fprintf(stderr, "\n"); | ||
| 2802 | } | ||
| 2803 | } | ||
| 2804 | } | ||
| 2805 | self->real->CreateConstantBufferView(desc, translate_cpu_handle(self, dest)); | 2790 | self->real->CreateConstantBufferView(desc, translate_cpu_handle(self, dest)); |
| 2806 | local_write_through(self, dest, 1); | 2791 | local_write_through(self, dest, 1); |
| 2807 | } | 2792 | } |
diff --git a/runtime/shims/xbox_present.cpp b/runtime/shims/xbox_present.cpp index 56299afe2..6fbed007d 100644 --- a/runtime/shims/xbox_present.cpp +++ b/runtime/shims/xbox_present.cpp | |||
| @@ -154,15 +154,6 @@ HRESULT XboxPresentation::present_x(UINT plane_count, const XboxPresentPlanePara | |||
| 154 | return result; | 154 | return result; |
| 155 | } | 155 | } |
| 156 | 156 | ||
| 157 | { // LOCAL DIAGNOSTIC: what the first presents show | ||
| 158 | static std::atomic<int> shown{0}; | ||
| 159 | if (shown.fetch_add(1, std::memory_order_relaxed) < 8) | ||
| 160 | for (UINT i = 0; i < plane_count; ++i) | ||
| 161 | std::fprintf(stderr, "[rt] localdbg: PresentX plane %u/%u resource=%p count=%u src=%p dest=%p cs=%d flags=0x%x\n", | ||
| 162 | i, plane_count, planes[i].ppResources ? static_cast<void*>(planes[i].ppResources[0]) : nullptr, | ||
| 163 | planes[i].ResourceCount, static_cast<const void*>(planes[i].pSrcViewRects), | ||
| 164 | static_cast<const void*>(planes[i].pDestPlacementBase), planes[i].ColorSpace, planes[i].Flags); | ||
| 165 | } | ||
| 166 | // All planes carry the token of one frame. | 157 | // All planes carry the token of one frame. |
| 167 | const std::uint64_t token = planes[0].Token; | 158 | const std::uint64_t token = planes[0].Token; |
| 168 | for (UINT i = 0; i < plane_count; ++i) { | 159 | for (UINT i = 0; i < plane_count; ++i) { |
diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index a531c9e72..cdc6b5bfe 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h | |||
| @@ -809,20 +809,6 @@ enum class ReplayResult { | |||
| 809 | invalid_draw, // DispatchMesh with a pipeline that has no mesh shader, or a vertex draw with one that has | 809 | invalid_draw, // DispatchMesh with a pipeline that has no mesh shader, or a vertex draw with one that has |
| 810 | unsupported | 810 | unsupported |
| 811 | }; | 811 | }; |
| 812 | // LOCAL DIAGNOSTIC: the arena's host mapping and size, for dumps of what a shader would read. | ||
| 813 | inline std::uint8_t* g_local_arena_mapped = nullptr; | ||
| 814 | inline std::uint64_t g_local_arena_size = 0; | ||
| 815 | inline std::atomic<std::uint64_t> g_local_last_cb96{0}; // title address of the last 96-byte constant view created | ||
| 816 | |||
| 817 | // LOCAL DIAGNOSTIC: which check returned unresolved_resource (first 3 times per source line). | ||
| 818 | inline ReplayResult local_unresolved_at(int line) { | ||
| 819 | static std::atomic<int> seen[8192]; | ||
| 820 | if (line >= 0 && line < 8192 && seen[line].fetch_add(1, std::memory_order_relaxed) < 3) | ||
| 821 | std::fprintf(stderr, "[rt] localdbg: unresolved_resource at vulkan_replay.h:%d\n", line); | ||
| 822 | return ReplayResult::unresolved_resource; | ||
| 823 | } | ||
| 824 | |||
| 825 | |||
| 826 | struct ReplayFunctions { | 812 | struct ReplayFunctions { |
| 827 | // Set 0 for the pipelines that declare one (their own `bindless_set` is only the marker): the device's current | 813 | // Set 0 for the pipelines that declare one (their own `bindless_set` is only the marker): the device's current |
| 828 | // generation of it, which a flush may have replaced since the pipeline was made. Null: the pipeline's. | 814 | // generation of it, which a flush may have replaced since the pipeline was made. Null: the pipeline's. |
| @@ -882,7 +868,7 @@ struct ReplayFunctions { | |||
| 882 | // cut to what the buffer holds from there: vertex and index views use what fits, WriteBufferImmediate needs all | 868 | // cut to what the buffer holds from there: vertex and index views use what fits, WriteBufferImmediate needs all |
| 883 | // of it. | 869 | // of it. |
| 884 | std::function<bool(std::uint64_t va, std::uint64_t& size, VkBuffer&, VkDeviceSize&)> buffer_at; | 870 | std::function<bool(std::uint64_t va, std::uint64_t& size, VkBuffer&, VkDeviceSize&)> buffer_at; |
| 885 | // LOCAL: a vertex or index view whose VA is the title's own CPU memory, not a registered buffer (on the console | 871 | // A vertex or index view whose VA is the title's own CPU memory, not a registered buffer (on the console |
| 886 | // the GPU reads title memory directly). Copies [va, va + size) into a GPU-visible ring and names the copy; false | 872 | // the GPU reads title memory directly). Copies [va, va + size) into a GPU-visible ring and names the copy; false |
| 887 | // when the range is not readable host memory. | 873 | // when the range is not readable host memory. |
| 888 | std::function<bool(std::uint64_t va, std::uint64_t size, VkBuffer&, VkDeviceSize&)> title_memory; | 874 | std::function<bool(std::uint64_t va, std::uint64_t size, VkBuffer&, VkDeviceSize&)> title_memory; |
| @@ -2131,7 +2117,7 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct | |||
| 2131 | !vk.draw_indexed || !vk.bind_pipeline || !vk.push_constants) | 2117 | !vk.draw_indexed || !vk.bind_pipeline || !vk.push_constants) |
| 2132 | return ReplayResult::unsupported; | 2118 | return ReplayResult::unsupported; |
| 2133 | const GraphicsPipeline* pipeline = vk.graphics_pipeline(draw.pipeline); | 2119 | const GraphicsPipeline* pipeline = vk.graphics_pipeline(draw.pipeline); |
| 2134 | if (!pipeline || !pipeline->pipeline) return local_unresolved_at(__LINE__); | 2120 | if (!pipeline || !pipeline->pipeline) return ReplayResult::unresolved_resource; |
| 2135 | if (pipeline->mesh != draw.mesh) return ReplayResult::invalid_draw; | 2121 | if (pipeline->mesh != draw.mesh) return ReplayResult::invalid_draw; |
| 2136 | if (draw.mesh && !vk.draw_mesh_tasks) return ReplayResult::unsupported; | 2122 | if (draw.mesh && !vk.draw_mesh_tasks) return ReplayResult::unsupported; |
| 2137 | if (pipeline->bindless_set && !vk.bind_descriptor_sets) return ReplayResult::unsupported; | 2123 | if (pipeline->bindless_set && !vk.bind_descriptor_sets) return ReplayResult::unsupported; |
| @@ -2152,7 +2138,7 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct | |||
| 2152 | const TargetView& target = draw.views->render_targets[slot]; | 2138 | const TargetView& target = draw.views->render_targets[slot]; |
| 2153 | if (!target.resource) continue; | 2139 | if (!target.resource) continue; |
| 2154 | const ResourceBinding* binding = resolve(target.resource); | 2140 | const ResourceBinding* binding = resolve(target.resource); |
| 2155 | if (!binding) return local_unresolved_at(__LINE__); | 2141 | if (!binding) return ReplayResult::unresolved_resource; |
| 2156 | auto& a = p.colors[slot]; | 2142 | auto& a = p.colors[slot]; |
| 2157 | a.binding = *binding; | 2143 | a.binding = *binding; |
| 2158 | a.id = target.resource; | 2144 | a.id = target.resource; |
| @@ -2169,7 +2155,7 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct | |||
| 2169 | } | 2155 | } |
| 2170 | if (draw.depth.resource && pipeline->depth_format != VK_FORMAT_UNDEFINED) { | 2156 | if (draw.depth.resource && pipeline->depth_format != VK_FORMAT_UNDEFINED) { |
| 2171 | const ResourceBinding* binding = resolve(draw.depth.resource); | 2157 | const ResourceBinding* binding = resolve(draw.depth.resource); |
| 2172 | if (!binding) return local_unresolved_at(__LINE__); | 2158 | if (!binding) return ReplayResult::unresolved_resource; |
| 2173 | auto& a = p.depth; | 2159 | auto& a = p.depth; |
| 2174 | a.binding = *binding; | 2160 | a.binding = *binding; |
| 2175 | a.id = draw.depth.resource; | 2161 | a.id = draw.depth.resource; |
| @@ -2210,7 +2196,7 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct | |||
| 2210 | const bool bound = draw.views && slot < draw.views->vertex_buffers.size() && | 2196 | const bool bound = draw.views && slot < draw.views->vertex_buffers.size() && |
| 2211 | draw.views->vertex_buffers[slot].va; | 2197 | draw.views->vertex_buffers[slot].va; |
| 2212 | if (!bound) { | 2198 | if (!bound) { |
| 2213 | if (!vk.zero_buffer) return local_unresolved_at(__LINE__); | 2199 | if (!vk.zero_buffer) return ReplayResult::unresolved_resource; |
| 2214 | p.vertex_buffers[slot] = vk.zero_buffer; | 2200 | p.vertex_buffers[slot] = vk.zero_buffer; |
| 2215 | p.vertex_offsets[slot] = vk.zero_offset; | 2201 | p.vertex_offsets[slot] = vk.zero_offset; |
| 2216 | p.vertex_sizes[slot] = vk.zero_size; | 2202 | p.vertex_sizes[slot] = vk.zero_size; |
| @@ -2222,101 +2208,20 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct | |||
| 2222 | if (!vk.buffer_at(view.va, size, p.vertex_buffers[slot], p.vertex_offsets[slot])) { | 2208 | if (!vk.buffer_at(view.va, size, p.vertex_buffers[slot], p.vertex_offsets[slot])) { |
| 2223 | size = view.size; | 2209 | size = view.size; |
| 2224 | if (!vk.title_memory || !vk.title_memory(view.va, size, p.vertex_buffers[slot], p.vertex_offsets[slot])) | 2210 | if (!vk.title_memory || !vk.title_memory(view.va, size, p.vertex_buffers[slot], p.vertex_offsets[slot])) |
| 2225 | return local_unresolved_at(__LINE__); | 2211 | return ReplayResult::unresolved_resource; |
| 2226 | { // LOCAL DIAGNOSTIC: the first draws that read title memory | ||
| 2227 | static std::atomic<int> shown{0}; | ||
| 2228 | const int nth = shown.fetch_add(1, std::memory_order_relaxed); | ||
| 2229 | if (nth < 12 || (nth % 20000) < 3) { | ||
| 2230 | const float* f = reinterpret_cast<const float*>(view.va); | ||
| 2231 | std::fprintf(stderr, "[rt] localdbg: draw slot=%u topology=%u count=%u instances=%u first=%u stride=%u " | ||
| 2232 | "bytes=%llu viewport=%.0f,%.0f %.0fx%.0f depth %.2f..%.2f\n", slot, draw.topology, | ||
| 2233 | draw.count, draw.instances, draw.first, view.stride, | ||
| 2234 | static_cast<unsigned long long>(view.size), draw.viewport.x, draw.viewport.y, | ||
| 2235 | draw.viewport.width, draw.viewport.height, draw.viewport.min_depth, draw.viewport.max_depth); | ||
| 2236 | for (std::uint32_t t = 0; draw.views && t < draw.views->render_target_count; ++t) | ||
| 2237 | std::fprintf(stderr, "[rt] localdbg: target %u resource=0x%llx mip=%u pipeline=0x%llx depth=0x%llx " | ||
| 2238 | "scissor=%d,%d..%d,%d\n", t, | ||
| 2239 | static_cast<unsigned long long>(draw.views->render_targets[t].resource), | ||
| 2240 | draw.views->render_targets[t].mip, static_cast<unsigned long long>(draw.pipeline), | ||
| 2241 | static_cast<unsigned long long>(draw.depth.resource), draw.scissor.left, | ||
| 2242 | draw.scissor.top, draw.scissor.right, draw.scissor.bottom); | ||
| 2243 | std::fprintf(stderr, "[rt] localdbg: heap_base=0x%llx user_data:", static_cast<unsigned long long>(vk.heap_base)); | ||
| 2244 | for (int w = 0; w < 16; ++w) std::fprintf(stderr, " %08x", draw.user_data[w]); | ||
| 2245 | std::fprintf(stderr, "\n"); | ||
| 2246 | for (int w = 0; w < 16; ++w) { // which root words name a registered buffer | ||
| 2247 | std::uint64_t room = 1; VkBuffer bb = VK_NULL_HANDLE; VkDeviceSize bo = 0; | ||
| 2248 | if (draw.user_data[w] && vk.buffer_at(draw.user_data[w], room, bb, bo)) | ||
| 2249 | std::fprintf(stderr, "[rt] localdbg: user_data[%d] is a registered buffer VA\n", w); | ||
| 2250 | } | ||
| 2251 | const std::uint32_t local_table = draw.user_data[0] ? draw.user_data[0] : draw.user_data[8]; | ||
| 2252 | if (g_local_arena_mapped && local_table && local_table + 256ull <= g_local_arena_size) { | ||
| 2253 | const std::uint32_t* t = reinterpret_cast<const std::uint32_t*>(g_local_arena_mapped + local_table); | ||
| 2254 | for (int e = 0; e < 4; ++e) { | ||
| 2255 | std::fprintf(stderr, "[rt] localdbg: table[%d]:", e); | ||
| 2256 | for (int w = 0; w < 8; ++w) std::fprintf(stderr, " %08x", t[e * 8 + w]); | ||
| 2257 | std::fprintf(stderr, "\n"); | ||
| 2258 | const std::uint64_t va = (std::uint64_t(t[e * 8 + 1] & 0xffff) << 32) | t[e * 8]; | ||
| 2259 | if (va && va + 128 <= g_local_arena_size) { | ||
| 2260 | const float* f2 = reinterpret_cast<const float*>(g_local_arena_mapped + va); | ||
| 2261 | std::fprintf(stderr, "[rt] localdbg: at va 0x%llx:", static_cast<unsigned long long>(va)); | ||
| 2262 | for (int w = 0; w < 32; ++w) std::fprintf(stderr, " %g", f2[w]); | ||
| 2263 | std::fprintf(stderr, "\n"); | ||
| 2264 | } | ||
| 2265 | } | ||
| 2266 | } | ||
| 2267 | { // the same table read from the title's memory, taking the high dword from the vertex view's VA | ||
| 2268 | const std::uint64_t guess = (view.va & 0xffffffff00000000ull) | draw.user_data[0]; | ||
| 2269 | std::fprintf(stderr, "[rt] localdbg: vertex va=0x%llx table guess=0x%llx delta=%lld\n", | ||
| 2270 | static_cast<unsigned long long>(view.va), static_cast<unsigned long long>(guess), | ||
| 2271 | static_cast<long long>(view.va - guess)); | ||
| 2272 | std::uint64_t probe = 256; VkBuffer pb = VK_NULL_HANDLE; VkDeviceSize po = 0; | ||
| 2273 | if (draw.user_data[0] && vk.title_memory && vk.title_memory(guess, probe, pb, po)) { | ||
| 2274 | const std::uint32_t* t = reinterpret_cast<const std::uint32_t*>(guess); | ||
| 2275 | for (int e = 0; e < 3; ++e) { | ||
| 2276 | std::fprintf(stderr, "[rt] localdbg: title table[%d]:", e); | ||
| 2277 | for (int w = 0; w < 8; ++w) std::fprintf(stderr, " %08x", t[e * 8 + w]); | ||
| 2278 | std::fprintf(stderr, "\n"); | ||
| 2279 | } | ||
| 2280 | } else { | ||
| 2281 | std::fprintf(stderr, "[rt] localdbg: title table guess is not readable title memory\n"); | ||
| 2282 | } | ||
| 2283 | } | ||
| 2284 | if (const std::uint64_t cb = g_local_last_cb96.load()) { | ||
| 2285 | const float* f3 = reinterpret_cast<const float*>(cb); | ||
| 2286 | std::fprintf(stderr, "[rt] localdbg: 96-byte constants in title memory at draw time:"); | ||
| 2287 | for (int w = 0; w < 24; ++w) std::fprintf(stderr, " %g", f3[w]); | ||
| 2288 | std::fprintf(stderr, "\n"); | ||
| 2289 | } | ||
| 2290 | { // what sits just before the vertices in the title's ring | ||
| 2291 | const std::uint32_t* t = reinterpret_cast<const std::uint32_t*>(view.va - 0x60); | ||
| 2292 | for (int e = 0; e < 3; ++e) { | ||
| 2293 | std::fprintf(stderr, "[rt] localdbg: before vertices[-0x%x]:", 0x60 - e * 0x20); | ||
| 2294 | for (int w = 0; w < 8; ++w) std::fprintf(stderr, " %08x", t[e * 8 + w]); | ||
| 2295 | std::fprintf(stderr, "\n"); | ||
| 2296 | } | ||
| 2297 | } | ||
| 2298 | const std::uint32_t words = view.stride / 4 ? view.stride / 4 : 1; | ||
| 2299 | for (std::uint32_t v = 0; v < 4 && (draw.first + v + 1) * view.stride <= view.size; ++v) { | ||
| 2300 | const float* q = f + (draw.first + v) * words; | ||
| 2301 | std::fprintf(stderr, "[rt] localdbg: v%u = %g %g %g %g %g %g\n", v, q[0], q[1], | ||
| 2302 | words > 2 ? q[2] : 0.f, words > 3 ? q[3] : 0.f, words > 4 ? q[4] : 0.f, | ||
| 2303 | words > 5 ? q[5] : 0.f); | ||
| 2304 | } | ||
| 2305 | } | ||
| 2306 | } | ||
| 2307 | } | 2212 | } |
| 2308 | p.vertex_sizes[slot] = size; | 2213 | p.vertex_sizes[slot] = size; |
| 2309 | p.vertex_strides[slot] = (pipeline->zero_step_slots & (1u << slot)) ? 0 : view.stride; | 2214 | p.vertex_strides[slot] = (pipeline->zero_step_slots & (1u << slot)) ? 0 : view.stride; |
| 2310 | } | 2215 | } |
| 2311 | // A non-indexed quad list is drawn from the shared triangle index buffer (emit). | 2216 | // A non-indexed quad list is drawn from the shared triangle index buffer (emit). |
| 2312 | if (!draw.indexed && !draw.mesh && draw.topology == topology_quad_list && !vk.quad_indices) | 2217 | if (!draw.indexed && !draw.mesh && draw.topology == topology_quad_list && !vk.quad_indices) |
| 2313 | return local_unresolved_at(__LINE__); | 2218 | return ReplayResult::unresolved_resource; |
| 2314 | if (draw.indexed) { | 2219 | if (draw.indexed) { |
| 2315 | if (draw.index.format == 57) p.index_type = VK_INDEX_TYPE_UINT16; | 2220 | if (draw.index.format == 57) p.index_type = VK_INDEX_TYPE_UINT16; |
| 2316 | else if (draw.index.format == 42) p.index_type = VK_INDEX_TYPE_UINT32; | 2221 | else if (draw.index.format == 42) p.index_type = VK_INDEX_TYPE_UINT32; |
| 2317 | else if (draw.index.va) return ReplayResult::unsupported; | 2222 | else if (draw.index.va) return ReplayResult::unsupported; |
| 2318 | if (!draw.index.va) { // no index buffer: every index reads 0 | 2223 | if (!draw.index.va) { // no index buffer: every index reads 0 |
| 2319 | if (!vk.zero_buffer) return local_unresolved_at(__LINE__); | 2224 | if (!vk.zero_buffer) return ReplayResult::unresolved_resource; |
| 2320 | p.index_buffer = vk.zero_buffer; | 2225 | p.index_buffer = vk.zero_buffer; |
| 2321 | p.index_offset = vk.zero_offset; | 2226 | p.index_offset = vk.zero_offset; |
| 2322 | } else { | 2227 | } else { |
| @@ -2324,7 +2229,7 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct | |||
| 2324 | if (!vk.buffer_at(draw.index.va, size, p.index_buffer, p.index_offset)) { | 2229 | if (!vk.buffer_at(draw.index.va, size, p.index_buffer, p.index_offset)) { |
| 2325 | size = draw.index.size; | 2230 | size = draw.index.size; |
| 2326 | if (!vk.title_memory || !vk.title_memory(draw.index.va, size, p.index_buffer, p.index_offset)) | 2231 | if (!vk.title_memory || !vk.title_memory(draw.index.va, size, p.index_buffer, p.index_offset)) |
| 2327 | return local_unresolved_at(__LINE__); | 2232 | return ReplayResult::unresolved_resource; |
| 2328 | } | 2233 | } |
| 2329 | } | 2234 | } |
| 2330 | } | 2235 | } |
| @@ -2746,7 +2651,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2746 | }; | 2651 | }; |
| 2747 | 2652 | ||
| 2748 | if (const auto* transition = std::get_if<TransitionBarrier>(&command)) { | 2653 | if (const auto* transition = std::get_if<TransitionBarrier>(&command)) { |
| 2749 | if (!bind(transition->resource)) return local_unresolved_at(__LINE__); | 2654 | if (!bind(transition->resource)) return ReplayResult::unresolved_resource; |
| 2750 | if (p.binding.image == VK_NULL_HANDLE) { | 2655 | if (p.binding.image == VK_NULL_HANDLE) { |
| 2751 | if (transition->subresource != 0 && transition->subresource != all_subresources) | 2656 | if (transition->subresource != 0 && transition->subresource != all_subresources) |
| 2752 | return ReplayResult::invalid_subresource; | 2657 | return ReplayResult::invalid_subresource; |
| @@ -2756,14 +2661,14 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2756 | } else if (std::holds_alternative<GlobalBarrier>(command) || std::holds_alternative<BufferBarrier>(command)) { | 2661 | } else if (std::holds_alternative<GlobalBarrier>(command) || std::holds_alternative<BufferBarrier>(command)) { |
| 2757 | if (!vk.pipeline_barrier2) return ReplayResult::unsupported; | 2662 | if (!vk.pipeline_barrier2) return ReplayResult::unsupported; |
| 2758 | if (const auto* buffer_barrier = std::get_if<BufferBarrier>(&command)) | 2663 | if (const auto* buffer_barrier = std::get_if<BufferBarrier>(&command)) |
| 2759 | if (!bind(buffer_barrier->resource)) return local_unresolved_at(__LINE__); | 2664 | if (!bind(buffer_barrier->resource)) return ReplayResult::unresolved_resource; |
| 2760 | } else if (const auto* texture = std::get_if<TextureBarrier>(&command)) { | 2665 | } else if (const auto* texture = std::get_if<TextureBarrier>(&command)) { |
| 2761 | if (!vk.pipeline_barrier2) return ReplayResult::unsupported; | 2666 | if (!vk.pipeline_barrier2) return ReplayResult::unsupported; |
| 2762 | if (!bind(texture->resource)) return local_unresolved_at(__LINE__); | 2667 | if (!bind(texture->resource)) return ReplayResult::unresolved_resource; |
| 2763 | if (!p.binding.image || !barrier_range(p.binding, texture->range, p.range)) | 2668 | if (!p.binding.image || !barrier_range(p.binding, texture->range, p.range)) |
| 2764 | return ReplayResult::invalid_subresource; | 2669 | return ReplayResult::invalid_subresource; |
| 2765 | } else if (const auto* color_clear = std::get_if<ClearRenderTarget>(&command)) { | 2670 | } else if (const auto* color_clear = std::get_if<ClearRenderTarget>(&command)) { |
| 2766 | if (!bind(color_clear->target.resource)) return local_unresolved_at(__LINE__); | 2671 | if (!bind(color_clear->target.resource)) return ReplayResult::unresolved_resource; |
| 2767 | if (!p.binding.image || p.binding.aspects != VK_IMAGE_ASPECT_COLOR_BIT) return ReplayResult::invalid_clear; | 2672 | if (!p.binding.image || p.binding.aspects != VK_IMAGE_ASPECT_COLOR_BIT) return ReplayResult::invalid_clear; |
| 2768 | if (!detail::view_range(p.binding, color_clear->target, VK_IMAGE_ASPECT_COLOR_BIT, p.range)) | 2673 | if (!detail::view_range(p.binding, color_clear->target, VK_IMAGE_ASPECT_COLOR_BIT, p.range)) |
| 2769 | return ReplayResult::invalid_subresource; | 2674 | return ReplayResult::invalid_subresource; |
| @@ -2785,7 +2690,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2785 | r != ReplayResult::success) return r; | 2690 | r != ReplayResult::success) return r; |
| 2786 | if (!p.skip && p.rects.empty() && !vk.clear_color_image) return ReplayResult::unsupported; | 2691 | if (!p.skip && p.rects.empty() && !vk.clear_color_image) return ReplayResult::unsupported; |
| 2787 | } else if (const auto* depth_clear = std::get_if<ClearDepthStencil>(&command)) { | 2692 | } else if (const auto* depth_clear = std::get_if<ClearDepthStencil>(&command)) { |
| 2788 | if (!bind(depth_clear->target.resource)) return local_unresolved_at(__LINE__); | 2693 | if (!bind(depth_clear->target.resource)) return ReplayResult::unresolved_resource; |
| 2789 | VkImageAspectFlags aspects = 0; | 2694 | VkImageAspectFlags aspects = 0; |
| 2790 | if (depth_clear->flags & clear_depth) aspects |= VK_IMAGE_ASPECT_DEPTH_BIT; | 2695 | if (depth_clear->flags & clear_depth) aspects |= VK_IMAGE_ASPECT_DEPTH_BIT; |
| 2791 | if (depth_clear->flags & clear_stencil) aspects |= VK_IMAGE_ASPECT_STENCIL_BIT; | 2696 | if (depth_clear->flags & clear_stencil) aspects |= VK_IMAGE_ASPECT_STENCIL_BIT; |
| @@ -2805,7 +2710,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2805 | if (!p.skip && p.rects.empty() && !vk.clear_depth_stencil_image) return ReplayResult::unsupported; | 2710 | if (!p.skip && p.rects.empty() && !vk.clear_depth_stencil_image) return ReplayResult::unsupported; |
| 2806 | } else if (const auto* uav = std::get_if<ClearUnorderedAccess>(&command)) { | 2711 | } else if (const auto* uav = std::get_if<ClearUnorderedAccess>(&command)) { |
| 2807 | const UavView& view = uav->view; | 2712 | const UavView& view = uav->view; |
| 2808 | if (!bind(view.resource)) return local_unresolved_at(__LINE__); | 2713 | if (!bind(view.resource)) return ReplayResult::unresolved_resource; |
| 2809 | if (view.buffer) { | 2714 | if (view.buffer) { |
| 2810 | if (!vk.fill_buffer || !vk.update_buffer || !vk.copy_buffer) return ReplayResult::unsupported; | 2715 | if (!vk.fill_buffer || !vk.update_buffer || !vk.copy_buffer) return ReplayResult::unsupported; |
| 2811 | if (predicated) ++out.unpredicated_copies; // fills and copies are transfer commands | 2716 | if (predicated) ++out.unpredicated_copies; // fills and copies are transfer commands |
| @@ -2865,7 +2770,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2865 | if (predicated && !std::holds_alternative<CopyBuffer>(command)) ++out.unpredicated_copies; | 2770 | if (predicated && !std::holds_alternative<CopyBuffer>(command)) ++out.unpredicated_copies; |
| 2866 | const auto [dst_id, src_id] = copy_ids(command); | 2771 | const auto [dst_id, src_id] = copy_ids(command); |
| 2867 | const ResourceBinding* source = resolve(src_id); | 2772 | const ResourceBinding* source = resolve(src_id); |
| 2868 | if (!bind(dst_id) || !source) return local_unresolved_at(__LINE__); | 2773 | if (!bind(dst_id) || !source) return ReplayResult::unresolved_resource; |
| 2869 | p.source = *source; | 2774 | p.source = *source; |
| 2870 | ReplayResult result = ReplayResult::success; | 2775 | ReplayResult result = ReplayResult::success; |
| 2871 | if (const auto* buffer_copy = std::get_if<CopyBuffer>(&command)) { | 2776 | if (const auto* buffer_copy = std::get_if<CopyBuffer>(&command)) { |
| @@ -2998,7 +2903,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2998 | if (!vk.resolve_image) return ReplayResult::unsupported; | 2903 | if (!vk.resolve_image) return ReplayResult::unsupported; |
| 2999 | if (predicated) ++out.unpredicated_copies; // a transfer command, like the copies | 2904 | if (predicated) ++out.unpredicated_copies; // a transfer command, like the copies |
| 3000 | const ResourceBinding* source = resolve(resolve_command->src); | 2905 | const ResourceBinding* source = resolve(resolve_command->src); |
| 3001 | if (!bind(resolve_command->dst) || !source) return local_unresolved_at(__LINE__); | 2906 | if (!bind(resolve_command->dst) || !source) return ReplayResult::unresolved_resource; |
| 3002 | p.source = *source; | 2907 | p.source = *source; |
| 3003 | if (const auto result = detail::prepare_resolve(*resolve_command, p); result != ReplayResult::success) | 2908 | if (const auto result = detail::prepare_resolve(*resolve_command, p); result != ReplayResult::success) |
| 3004 | return result; | 2909 | return result; |
| @@ -3029,7 +2934,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3029 | } | 2934 | } |
| 3030 | } else if (const auto* discard = std::get_if<DiscardResource>(&command)) { | 2935 | } else if (const auto* discard = std::get_if<DiscardResource>(&command)) { |
| 3031 | // Buffers and partial (rectangle) discards keep their contents, which "undefined" allows. | 2936 | // Buffers and partial (rectangle) discards keep their contents, which "undefined" allows. |
| 3032 | if (!bind(discard->resource)) return local_unresolved_at(__LINE__); | 2937 | if (!bind(discard->resource)) return ReplayResult::unresolved_resource; |
| 3033 | const std::uint64_t end = std::uint64_t(discard->first_subresource) + discard->count; | 2938 | const std::uint64_t end = std::uint64_t(discard->first_subresource) + discard->count; |
| 3034 | if (!p.binding.image) { | 2939 | if (!p.binding.image) { |
| 3035 | if (!discard->whole && end > 1) return ReplayResult::invalid_subresource; | 2940 | if (!discard->whole && end > 1) return ReplayResult::invalid_subresource; |
| @@ -3049,7 +2954,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3049 | if (!vk.update_buffer || !vk.buffer_at) return ReplayResult::unsupported; | 2954 | if (!vk.update_buffer || !vk.buffer_at) return ReplayResult::unsupported; |
| 3050 | std::uint64_t bytes = 4; | 2955 | std::uint64_t bytes = 4; |
| 3051 | if (!vk.buffer_at(write->address, bytes, p.write_buffer, p.write_offset) || bytes < 4) | 2956 | if (!vk.buffer_at(write->address, bytes, p.write_buffer, p.write_offset) || bytes < 4) |
| 3052 | return local_unresolved_at(__LINE__); | 2957 | return ReplayResult::unresolved_resource; |
| 3053 | if (p.write_offset % 4) return ReplayResult::invalid_copy; | 2958 | if (p.write_offset % 4) return ReplayResult::invalid_copy; |
| 3054 | // WriteBufferImmediate resolves by VA and may target a readback buffer in COPY_DEST. | 2959 | // WriteBufferImmediate resolves by VA and may target a readback buffer in COPY_DEST. |
| 3055 | out.wrote_readback = true; | 2960 | out.wrote_readback = true; |
| @@ -3058,14 +2963,14 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3058 | if (!vk.copy_buffer) return ReplayResult::unsupported; | 2963 | if (!vk.copy_buffer) return ReplayResult::unsupported; |
| 3059 | if (predicated) ++out.unpredicated_copies; // a transfer command, like the copies | 2964 | if (predicated) ++out.unpredicated_copies; // a transfer command, like the copies |
| 3060 | const ResourceBinding* source = resolve(atomic->src); | 2965 | const ResourceBinding* source = resolve(atomic->src); |
| 3061 | if (!bind(atomic->dst) || !source) return local_unresolved_at(__LINE__); | 2966 | if (!bind(atomic->dst) || !source) return ReplayResult::unresolved_resource; |
| 3062 | p.source = *source; | 2967 | p.source = *source; |
| 3063 | if (!p.binding.buffer || !p.source.buffer || !detail::within(atomic->dst_offset, atomic->bytes, p.binding.size) || | 2968 | if (!p.binding.buffer || !p.source.buffer || !detail::within(atomic->dst_offset, atomic->bytes, p.binding.size) || |
| 3064 | !detail::within(atomic->src_offset, atomic->bytes, p.source.size)) | 2969 | !detail::within(atomic->src_offset, atomic->bytes, p.source.size)) |
| 3065 | return ReplayResult::invalid_copy; | 2970 | return ReplayResult::invalid_copy; |
| 3066 | for (const auto& d : atomic->dependencies) { | 2971 | for (const auto& d : atomic->dependencies) { |
| 3067 | const ResourceBinding* dependent = resolve(d.resource); | 2972 | const ResourceBinding* dependent = resolve(d.resource); |
| 3068 | if (!dependent) return local_unresolved_at(__LINE__); | 2973 | if (!dependent) return ReplayResult::unresolved_resource; |
| 3069 | if (!dependent->image) { | 2974 | if (!dependent->image) { |
| 3070 | const std::uint64_t end = d.end == UINT64_MAX ? dependent->size : d.end; | 2975 | const std::uint64_t end = d.end == UINT64_MAX ? dependent->size : d.end; |
| 3071 | if (d.subresource != 0 || d.begin >= end || end > dependent->size) | 2976 | if (d.subresource != 0 || d.begin >= end || end > dependent->size) |
| @@ -3084,7 +2989,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3084 | if (!conditional) return ReplayResult::unsupported; | 2989 | if (!conditional) return ReplayResult::unsupported; |
| 3085 | // Without physical segments the capture dispatch would pollute CSInvocations. | 2990 | // Without physical segments the capture dispatch would pollute CSInvocations. |
| 3086 | if (statistics_active && !statistics_helpers) return ReplayResult::unsupported; | 2991 | if (statistics_active && !statistics_helpers) return ReplayResult::unsupported; |
| 3087 | if (!bind(predication->buffer)) return local_unresolved_at(__LINE__); | 2992 | if (!bind(predication->buffer)) return ReplayResult::unresolved_resource; |
| 3088 | if (!p.binding.buffer || !detail::within(predication->offset, 8, p.binding.size) || | 2993 | if (!p.binding.buffer || !detail::within(predication->offset, 8, p.binding.size) || |
| 3089 | predication->offset > UINT64_MAX - p.binding.buffer_offset) | 2994 | predication->offset > UINT64_MAX - p.binding.buffer_offset) |
| 3090 | return ReplayResult::invalid_predication; | 2995 | return ReplayResult::invalid_predication; |
| @@ -3096,7 +3001,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3096 | // not suppress them (emit_query suspends conditional rendering around ResolveQueryData). | 3001 | // not suppress them (emit_query suspends conditional rendering around ResolveQueryData). |
| 3097 | if (!queries) return ReplayResult::unsupported; | 3002 | if (!queries) return ReplayResult::unsupported; |
| 3098 | QueryPool* heap = vk.query_pool(range.heap); | 3003 | QueryPool* heap = vk.query_pool(range.heap); |
| 3099 | if (!heap) return local_unresolved_at(__LINE__); | 3004 | if (!heap) return ReplayResult::unresolved_resource; |
| 3100 | if (!query_fits_heap(heap->heap_type, range.type)) return ReplayResult::invalid_query; | 3005 | if (!query_fits_heap(heap->heap_type, range.type)) return ReplayResult::invalid_query; |
| 3101 | if (range.first >= heap->count || range.count > heap->count - range.first) | 3006 | if (range.first >= heap->count || range.count > heap->count - range.first) |
| 3102 | return ReplayResult::invalid_query; | 3007 | return ReplayResult::invalid_query; |
| @@ -3119,7 +3024,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3119 | } | 3024 | } |
| 3120 | if (const auto* resolve_queries = std::get_if<ResolveQueries>(&command)) { | 3025 | if (const auto* resolve_queries = std::get_if<ResolveQueries>(&command)) { |
| 3121 | // The destination is a buffer, as D3D12 requires, large enough for every result. | 3026 | // The destination is a buffer, as D3D12 requires, large enough for every result. |
| 3122 | if (!bind(resolve_queries->dst)) return local_unresolved_at(__LINE__); | 3027 | if (!bind(resolve_queries->dst)) return ReplayResult::unresolved_resource; |
| 3123 | const std::uint64_t bytes = std::uint64_t(range.count) * query_result_size(range.type); | 3028 | const std::uint64_t bytes = std::uint64_t(range.count) * query_result_size(range.type); |
| 3124 | if (!p.binding.buffer || p.binding.buffer_offset % 8 || | 3029 | if (!p.binding.buffer || p.binding.buffer_offset % 8 || |
| 3125 | !detail::within(resolve_queries->offset, bytes, p.binding.size) || | 3030 | !detail::within(resolve_queries->offset, bytes, p.binding.size) || |
| @@ -3137,7 +3042,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3137 | } | 3042 | } |
| 3138 | out.queries.push_back({i, heap, statistics_active}); | 3043 | out.queries.push_back({i, heap, statistics_active}); |
| 3139 | } else if (const auto* ind = std::get_if<ExecuteIndirect>(&command)) { | 3044 | } else if (const auto* ind = std::get_if<ExecuteIndirect>(&command)) { |
| 3140 | if (!bind(ind->argument_buffer) || !p.binding.buffer) return local_unresolved_at(__LINE__); | 3045 | if (!bind(ind->argument_buffer) || !p.binding.buffer) return ReplayResult::unresolved_resource; |
| 3141 | const VkDeviceSize record_size = detail::indirect_record_size(ind->kind); | 3046 | const VkDeviceSize record_size = detail::indirect_record_size(ind->kind); |
| 3142 | if (!record_size || ind->stride < record_size || ind->stride % sizeof(std::uint32_t)) | 3047 | if (!record_size || ind->stride < record_size || ind->stride % sizeof(std::uint32_t)) |
| 3143 | return ReplayResult::invalid_indirect_arguments; | 3048 | return ReplayResult::invalid_indirect_arguments; |
| @@ -3151,7 +3056,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3151 | return ReplayResult::invalid_indirect_arguments; | 3056 | return ReplayResult::invalid_indirect_arguments; |
| 3152 | if (ind->count_buffer) { | 3057 | if (ind->count_buffer) { |
| 3153 | const ResourceBinding* cnt = resolve(ind->count_buffer); | 3058 | const ResourceBinding* cnt = resolve(ind->count_buffer); |
| 3154 | if (!cnt || !cnt->buffer) return local_unresolved_at(__LINE__); | 3059 | if (!cnt || !cnt->buffer) return ReplayResult::unresolved_resource; |
| 3155 | if (!detail::indirect_range(*cnt, ind->count_offset, sizeof(std::uint32_t))) | 3060 | if (!detail::indirect_range(*cnt, ind->count_offset, sizeof(std::uint32_t))) |
| 3156 | return ReplayResult::invalid_indirect_arguments; | 3061 | return ReplayResult::invalid_indirect_arguments; |
| 3157 | p.source = *cnt; | 3062 | p.source = *cnt; |
| @@ -3177,7 +3082,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3177 | if (ind->kind == IndirectKind::dispatch && ind->pipeline) { // the pipeline and root arguments it was recorded | 3082 | if (ind->kind == IndirectKind::dispatch && ind->pipeline) { // the pipeline and root arguments it was recorded |
| 3178 | if (!vk.bind_pipeline || !vk.push_constants || !vk.compute_pipeline) return ReplayResult::unsupported; | 3083 | if (!vk.bind_pipeline || !vk.push_constants || !vk.compute_pipeline) return ReplayResult::unsupported; |
| 3179 | const ComputePipeline* pipeline = vk.compute_pipeline(ind->pipeline); | 3084 | const ComputePipeline* pipeline = vk.compute_pipeline(ind->pipeline); |
| 3180 | if (!pipeline || !pipeline->pipeline) return local_unresolved_at(__LINE__); | 3085 | if (!pipeline || !pipeline->pipeline) return ReplayResult::unresolved_resource; |
| 3181 | if (pipeline->bindless_set && !vk.bind_descriptor_sets) return ReplayResult::unsupported; | 3086 | if (pipeline->bindless_set && !vk.bind_descriptor_sets) return ReplayResult::unsupported; |
| 3182 | p.pipeline = *pipeline; | 3087 | p.pipeline = *pipeline; |
| 3183 | } | 3088 | } |
| @@ -3189,10 +3094,10 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3189 | if (!vk.build_acceleration_structures || !vk.resolve_acceleration_structure) | 3094 | if (!vk.build_acceleration_structures || !vk.resolve_acceleration_structure) |
| 3190 | return ReplayResult::unsupported; | 3095 | return ReplayResult::unsupported; |
| 3191 | p.accel_dst = vk.resolve_acceleration_structure(build->dst_va); | 3096 | p.accel_dst = vk.resolve_acceleration_structure(build->dst_va); |
| 3192 | if (!p.accel_dst) return local_unresolved_at(__LINE__); | 3097 | if (!p.accel_dst) return ReplayResult::unresolved_resource; |
| 3193 | if (build->update && build->src_va) { | 3098 | if (build->update && build->src_va) { |
| 3194 | p.accel_src = vk.resolve_acceleration_structure(build->src_va); | 3099 | p.accel_src = vk.resolve_acceleration_structure(build->src_va); |
| 3195 | if (!p.accel_src) return local_unresolved_at(__LINE__); | 3100 | if (!p.accel_src) return ReplayResult::unresolved_resource; |
| 3196 | } | 3101 | } |
| 3197 | if (build->is_tlas && build->instance_pointers && build->instance_count) { | 3102 | if (build->is_tlas && build->instance_pointers && build->instance_count) { |
| 3198 | if (!vk.prepare_khr_instances || !vk.host_at || !vk.buffer_at) return ReplayResult::unsupported; | 3103 | if (!vk.prepare_khr_instances || !vk.host_at || !vk.buffer_at) return ReplayResult::unsupported; |
| @@ -3226,7 +3131,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3226 | std::uint64_t room = 8 * info->sources.size(); | 3131 | std::uint64_t room = 8 * info->sources.size(); |
| 3227 | VkBuffer buffer = VK_NULL_HANDLE; | 3132 | VkBuffer buffer = VK_NULL_HANDLE; |
| 3228 | VkDeviceSize offset = 0; | 3133 | VkDeviceSize offset = 0; |
| 3229 | if (!vk.buffer_at(info->dest_va, room, buffer, offset)) return local_unresolved_at(__LINE__); | 3134 | if (!vk.buffer_at(info->dest_va, room, buffer, offset)) return ReplayResult::unresolved_resource; |
| 3230 | if (room < 8 * info->sources.size()) return ReplayResult::invalid_copy; | 3135 | if (room < 8 * info->sources.size()) return ReplayResult::invalid_copy; |
| 3231 | } else if (info->type == 0 && vk.write_acceleration_structures_properties && | 3136 | } else if (info->type == 0 && vk.write_acceleration_structures_properties && |
| 3232 | vk.resolve_acceleration_structure && vk.reset_query_pool && vk.copy_query_pool_results && | 3137 | vk.resolve_acceleration_structure && vk.reset_query_pool && vk.copy_query_pool_results && |
| @@ -3265,7 +3170,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3265 | if (!vk.bind_pipeline || !vk.push_constants || !vk.dispatch || !vk.compute_pipeline) | 3170 | if (!vk.bind_pipeline || !vk.push_constants || !vk.dispatch || !vk.compute_pipeline) |
| 3266 | return ReplayResult::unsupported; | 3171 | return ReplayResult::unsupported; |
| 3267 | const ComputePipeline* pipeline = vk.compute_pipeline(dispatch->pipeline); | 3172 | const ComputePipeline* pipeline = vk.compute_pipeline(dispatch->pipeline); |
| 3268 | if (!pipeline || !pipeline->pipeline) return local_unresolved_at(__LINE__); | 3173 | if (!pipeline || !pipeline->pipeline) return ReplayResult::unresolved_resource; |
| 3269 | if (pipeline->bindless_set && !vk.bind_descriptor_sets) return ReplayResult::unsupported; | 3174 | if (pipeline->bindless_set && !vk.bind_descriptor_sets) return ReplayResult::unsupported; |
| 3270 | p.pipeline = *pipeline; | 3175 | p.pipeline = *pipeline; |
| 3271 | } else if (const auto* draw = std::get_if<Draw>(&command)) { | 3176 | } else if (const auto* draw = std::get_if<Draw>(&command)) { |