upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorMumogg <104529023+Mumogg@users.noreply.github.com>2026-11-23 21:31:53 -0600
committerMumogg <104529023+Mumogg@users.noreply.github.com>2026-11-23 21:31:53 -0600
commite0d4fd2b81e6636b1c6bb2f76be79e910e84d84b (patch)
tree7fe315b21ab6063043460bc6cb177837971a47c0 /runtime/src
parentaba24099150adb3ae17cbfe33a60adfcab161497 (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/src')
-rw-r--r--runtime/src/vulkan_replay.h157
1 files changed, 31 insertions, 126 deletions
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.
813inline std::uint8_t* g_local_arena_mapped = nullptr;
814inline std::uint64_t g_local_arena_size = 0;
815inline 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).
818inline 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
826struct ReplayFunctions { 812struct 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)) {