diff options
| author | Mumogg <104529023+Mumogg@users.noreply.github.com> | 2026-11-23 15:20:43 -0600 |
|---|---|---|
| committer | Mumogg <104529023+Mumogg@users.noreply.github.com> | 2026-11-23 15:20:43 -0600 |
| commit | 237f9e0ba83c8b8e740dd7bcc0e10d311fddb897 (patch) | |
| tree | 4890c217a2c816e61874897ebe6e37eea254f86a /runtime/src | |
| parent | e64653e58599b0372a3e3e4d8909bd652eb704e8 (diff) | |
local: diagnostics (draw/present/clear/rect state), rect experiments
Diffstat (limited to 'runtime/src')
| -rw-r--r-- | runtime/src/vulkan_backend.h | 6 | ||||
| -rw-r--r-- | runtime/src/vulkan_replay.h | 120 |
2 files changed, 92 insertions, 34 deletions
diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index 77c8827b0..0d4d84d6b 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h | |||
| @@ -1247,6 +1247,12 @@ public: | |||
| 1247 | replay_.zero_size = size; | 1247 | replay_.zero_size = size; |
| 1248 | } | 1248 | } |
| 1249 | 1249 | ||
| 1250 | // LOCAL: the copy-in fallback for vertex and index views in title memory (ReplayFunctions::title_memory). | ||
| 1251 | void set_title_memory(std::function<bool(std::uint64_t, std::uint64_t, VkBuffer&, VkDeviceSize&)> copy) { | ||
| 1252 | std::unique_lock lock(resource_mutex_); | ||
| 1253 | replay_.title_memory = std::move(copy); | ||
| 1254 | } | ||
| 1255 | |||
| 1250 | // Pre-expanded 32-bit triangle indices for non-indexed quad lists (ReplayFunctions::quad_indices). | 1256 | // Pre-expanded 32-bit triangle indices for non-indexed quad lists (ReplayFunctions::quad_indices). |
| 1251 | void set_quad_indices(VkBuffer buffer, VkDeviceSize offset, std::uint32_t count) { | 1257 | void set_quad_indices(VkBuffer buffer, VkDeviceSize offset, std::uint32_t count) { |
| 1252 | std::unique_lock lock(resource_mutex_); | 1258 | std::unique_lock lock(resource_mutex_); |
diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index af58efbbd..0daaae4ba 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h | |||
| @@ -1,3 +1,4 @@ | |||
| 1 | #include <atomic> | ||
| 1 | #pragma once | 2 | #pragma once |
| 2 | 3 | ||
| 3 | #include "resource_tiling.h" | 4 | #include "resource_tiling.h" |
| @@ -808,6 +809,14 @@ enum class ReplayResult { | |||
| 808 | 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 |
| 809 | unsupported | 810 | unsupported |
| 810 | }; | 811 | }; |
| 812 | // LOCAL DIAGNOSTIC: which check returned unresolved_resource (first 3 times per source line). | ||
| 813 | inline ReplayResult local_unresolved_at(int line) { | ||
| 814 | static std::atomic<int> seen[8192]; | ||
| 815 | if (line >= 0 && line < 8192 && seen[line].fetch_add(1, std::memory_order_relaxed) < 3) | ||
| 816 | std::fprintf(stderr, "[rt] localdbg: unresolved_resource at vulkan_replay.h:%d\n", line); | ||
| 817 | return ReplayResult::unresolved_resource; | ||
| 818 | } | ||
| 819 | |||
| 811 | 820 | ||
| 812 | struct ReplayFunctions { | 821 | struct ReplayFunctions { |
| 813 | // Set 0 for the pipelines that declare one (their own `bindless_set` is only the marker): the device's current | 822 | // Set 0 for the pipelines that declare one (their own `bindless_set` is only the marker): the device's current |
| @@ -868,6 +877,10 @@ struct ReplayFunctions { | |||
| 868 | // cut to what the buffer holds from there: vertex and index views use what fits, WriteBufferImmediate needs all | 877 | // cut to what the buffer holds from there: vertex and index views use what fits, WriteBufferImmediate needs all |
| 869 | // of it. | 878 | // of it. |
| 870 | std::function<bool(std::uint64_t va, std::uint64_t& size, VkBuffer&, VkDeviceSize&)> buffer_at; | 879 | std::function<bool(std::uint64_t va, std::uint64_t& size, VkBuffer&, VkDeviceSize&)> buffer_at; |
| 880 | // LOCAL: a vertex or index view whose VA is the title's own CPU memory, not a registered buffer (on the console | ||
| 881 | // the GPU reads title memory directly). Copies [va, va + size) into a GPU-visible ring and names the copy; false | ||
| 882 | // when the range is not readable host memory. | ||
| 883 | std::function<bool(std::uint64_t va, std::uint64_t size, VkBuffer&, VkDeviceSize&)> title_memory; | ||
| 871 | // Host bytes for a whole console VA range; `not_cpu_written` when it names GPU-writable memory. For small | 884 | // Host bytes for a whole console VA range; `not_cpu_written` when it names GPU-writable memory. For small |
| 872 | // CPU-written inputs, such as the pointer list of an ARRAY_OF_POINTERS TLAS build. | 885 | // CPU-written inputs, such as the pointer list of an ARRAY_OF_POINTERS TLAS build. |
| 873 | std::function<HostReadStatus(std::uint64_t va, std::uint64_t bytes, const std::uint8_t*&)> host_at; | 886 | std::function<HostReadStatus(std::uint64_t va, std::uint64_t bytes, const std::uint8_t*&)> host_at; |
| @@ -2100,7 +2113,7 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct | |||
| 2100 | !vk.draw_indexed || !vk.bind_pipeline || !vk.push_constants) | 2113 | !vk.draw_indexed || !vk.bind_pipeline || !vk.push_constants) |
| 2101 | return ReplayResult::unsupported; | 2114 | return ReplayResult::unsupported; |
| 2102 | const GraphicsPipeline* pipeline = vk.graphics_pipeline(draw.pipeline); | 2115 | const GraphicsPipeline* pipeline = vk.graphics_pipeline(draw.pipeline); |
| 2103 | if (!pipeline || !pipeline->pipeline) return ReplayResult::unresolved_resource; | 2116 | if (!pipeline || !pipeline->pipeline) return local_unresolved_at(__LINE__); |
| 2104 | if (pipeline->mesh != draw.mesh) return ReplayResult::invalid_draw; | 2117 | if (pipeline->mesh != draw.mesh) return ReplayResult::invalid_draw; |
| 2105 | if (draw.mesh && !vk.draw_mesh_tasks) return ReplayResult::unsupported; | 2118 | if (draw.mesh && !vk.draw_mesh_tasks) return ReplayResult::unsupported; |
| 2106 | if (pipeline->bindless_set && !vk.bind_descriptor_sets) return ReplayResult::unsupported; | 2119 | if (pipeline->bindless_set && !vk.bind_descriptor_sets) return ReplayResult::unsupported; |
| @@ -2121,7 +2134,7 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct | |||
| 2121 | const TargetView& target = draw.views->render_targets[slot]; | 2134 | const TargetView& target = draw.views->render_targets[slot]; |
| 2122 | if (!target.resource) continue; | 2135 | if (!target.resource) continue; |
| 2123 | const ResourceBinding* binding = resolve(target.resource); | 2136 | const ResourceBinding* binding = resolve(target.resource); |
| 2124 | if (!binding) return ReplayResult::unresolved_resource; | 2137 | if (!binding) return local_unresolved_at(__LINE__); |
| 2125 | auto& a = p.colors[slot]; | 2138 | auto& a = p.colors[slot]; |
| 2126 | a.binding = *binding; | 2139 | a.binding = *binding; |
| 2127 | a.id = target.resource; | 2140 | a.id = target.resource; |
| @@ -2138,7 +2151,7 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct | |||
| 2138 | } | 2151 | } |
| 2139 | if (draw.depth.resource && pipeline->depth_format != VK_FORMAT_UNDEFINED) { | 2152 | if (draw.depth.resource && pipeline->depth_format != VK_FORMAT_UNDEFINED) { |
| 2140 | const ResourceBinding* binding = resolve(draw.depth.resource); | 2153 | const ResourceBinding* binding = resolve(draw.depth.resource); |
| 2141 | if (!binding) return ReplayResult::unresolved_resource; | 2154 | if (!binding) return local_unresolved_at(__LINE__); |
| 2142 | auto& a = p.depth; | 2155 | auto& a = p.depth; |
| 2143 | a.binding = *binding; | 2156 | a.binding = *binding; |
| 2144 | a.id = draw.depth.resource; | 2157 | a.id = draw.depth.resource; |
| @@ -2179,7 +2192,7 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct | |||
| 2179 | const bool bound = draw.views && slot < draw.views->vertex_buffers.size() && | 2192 | const bool bound = draw.views && slot < draw.views->vertex_buffers.size() && |
| 2180 | draw.views->vertex_buffers[slot].va; | 2193 | draw.views->vertex_buffers[slot].va; |
| 2181 | if (!bound) { | 2194 | if (!bound) { |
| 2182 | if (!vk.zero_buffer) return ReplayResult::unresolved_resource; | 2195 | if (!vk.zero_buffer) return local_unresolved_at(__LINE__); |
| 2183 | p.vertex_buffers[slot] = vk.zero_buffer; | 2196 | p.vertex_buffers[slot] = vk.zero_buffer; |
| 2184 | p.vertex_offsets[slot] = vk.zero_offset; | 2197 | p.vertex_offsets[slot] = vk.zero_offset; |
| 2185 | p.vertex_sizes[slot] = vk.zero_size; | 2198 | p.vertex_sizes[slot] = vk.zero_size; |
| @@ -2188,26 +2201,65 @@ ReplayResult prepare_draw(const Draw& draw, Resolve&& resolve, const ReplayFunct | |||
| 2188 | } | 2201 | } |
| 2189 | const VertexBufferView& view = draw.views->vertex_buffers[slot]; | 2202 | const VertexBufferView& view = draw.views->vertex_buffers[slot]; |
| 2190 | std::uint64_t size = view.size; | 2203 | std::uint64_t size = view.size; |
| 2191 | if (!vk.buffer_at(view.va, size, p.vertex_buffers[slot], p.vertex_offsets[slot])) | 2204 | if (!vk.buffer_at(view.va, size, p.vertex_buffers[slot], p.vertex_offsets[slot])) { |
| 2192 | return ReplayResult::unresolved_resource; | 2205 | size = view.size; |
| 2206 | if (!vk.title_memory || !vk.title_memory(view.va, size, p.vertex_buffers[slot], p.vertex_offsets[slot])) | ||
| 2207 | return local_unresolved_at(__LINE__); | ||
| 2208 | { // LOCAL DIAGNOSTIC: the first draws that read title memory | ||
| 2209 | static std::atomic<int> shown{0}; | ||
| 2210 | if (shown.fetch_add(1, std::memory_order_relaxed) < 12) { | ||
| 2211 | const float* f = reinterpret_cast<const float*>(view.va); | ||
| 2212 | std::fprintf(stderr, "[rt] localdbg: draw slot=%u topology=%u count=%u instances=%u first=%u stride=%u " | ||
| 2213 | "bytes=%llu viewport=%.0f,%.0f %.0fx%.0f depth %.2f..%.2f\n", slot, draw.topology, | ||
| 2214 | draw.count, draw.instances, draw.first, view.stride, | ||
| 2215 | static_cast<unsigned long long>(view.size), draw.viewport.x, draw.viewport.y, | ||
| 2216 | draw.viewport.width, draw.viewport.height, draw.viewport.min_depth, draw.viewport.max_depth); | ||
| 2217 | for (std::uint32_t t = 0; draw.views && t < draw.views->render_target_count; ++t) | ||
| 2218 | std::fprintf(stderr, "[rt] localdbg: target %u resource=0x%llx mip=%u pipeline=0x%llx depth=0x%llx " | ||
| 2219 | "scissor=%d,%d..%d,%d\n", t, | ||
| 2220 | static_cast<unsigned long long>(draw.views->render_targets[t].resource), | ||
| 2221 | draw.views->render_targets[t].mip, static_cast<unsigned long long>(draw.pipeline), | ||
| 2222 | static_cast<unsigned long long>(draw.depth.resource), draw.scissor.left, | ||
| 2223 | draw.scissor.top, draw.scissor.right, draw.scissor.bottom); | ||
| 2224 | std::fprintf(stderr, "[rt] localdbg: heap_base=0x%llx user_data:", static_cast<unsigned long long>(vk.heap_base)); | ||
| 2225 | for (int w = 0; w < 16; ++w) std::fprintf(stderr, " %08x", draw.user_data[w]); | ||
| 2226 | std::fprintf(stderr, "\n"); | ||
| 2227 | for (int w = 0; w < 16; ++w) { // which root words name a registered buffer | ||
| 2228 | std::uint64_t room = 1; VkBuffer bb = VK_NULL_HANDLE; VkDeviceSize bo = 0; | ||
| 2229 | if (draw.user_data[w] && vk.buffer_at(draw.user_data[w], room, bb, bo)) | ||
| 2230 | std::fprintf(stderr, "[rt] localdbg: user_data[%d] is a registered buffer VA\n", w); | ||
| 2231 | } | ||
| 2232 | const std::uint32_t words = view.stride / 4 ? view.stride / 4 : 1; | ||
| 2233 | for (std::uint32_t v = 0; v < 4 && (draw.first + v + 1) * view.stride <= view.size; ++v) { | ||
| 2234 | const float* q = f + (draw.first + v) * words; | ||
| 2235 | std::fprintf(stderr, "[rt] localdbg: v%u = %g %g %g %g %g %g\n", v, q[0], q[1], | ||
| 2236 | words > 2 ? q[2] : 0.f, words > 3 ? q[3] : 0.f, words > 4 ? q[4] : 0.f, | ||
| 2237 | words > 5 ? q[5] : 0.f); | ||
| 2238 | } | ||
| 2239 | } | ||
| 2240 | } | ||
| 2241 | } | ||
| 2193 | p.vertex_sizes[slot] = size; | 2242 | p.vertex_sizes[slot] = size; |
| 2194 | p.vertex_strides[slot] = (pipeline->zero_step_slots & (1u << slot)) ? 0 : view.stride; | 2243 | p.vertex_strides[slot] = (pipeline->zero_step_slots & (1u << slot)) ? 0 : view.stride; |
| 2195 | } | 2244 | } |
| 2196 | // A non-indexed quad list is drawn from the shared triangle index buffer (emit). | 2245 | // A non-indexed quad list is drawn from the shared triangle index buffer (emit). |
| 2197 | if (!draw.indexed && !draw.mesh && draw.topology == topology_quad_list && !vk.quad_indices) | 2246 | if (!draw.indexed && !draw.mesh && draw.topology == topology_quad_list && !vk.quad_indices) |
| 2198 | return ReplayResult::unresolved_resource; | 2247 | return local_unresolved_at(__LINE__); |
| 2199 | if (draw.indexed) { | 2248 | if (draw.indexed) { |
| 2200 | if (draw.index.format == 57) p.index_type = VK_INDEX_TYPE_UINT16; | 2249 | if (draw.index.format == 57) p.index_type = VK_INDEX_TYPE_UINT16; |
| 2201 | else if (draw.index.format == 42) p.index_type = VK_INDEX_TYPE_UINT32; | 2250 | else if (draw.index.format == 42) p.index_type = VK_INDEX_TYPE_UINT32; |
| 2202 | else if (draw.index.va) return ReplayResult::unsupported; | 2251 | else if (draw.index.va) return ReplayResult::unsupported; |
| 2203 | if (!draw.index.va) { // no index buffer: every index reads 0 | 2252 | if (!draw.index.va) { // no index buffer: every index reads 0 |
| 2204 | if (!vk.zero_buffer) return ReplayResult::unresolved_resource; | 2253 | if (!vk.zero_buffer) return local_unresolved_at(__LINE__); |
| 2205 | p.index_buffer = vk.zero_buffer; | 2254 | p.index_buffer = vk.zero_buffer; |
| 2206 | p.index_offset = vk.zero_offset; | 2255 | p.index_offset = vk.zero_offset; |
| 2207 | } else { | 2256 | } else { |
| 2208 | std::uint64_t size = draw.index.size; | 2257 | std::uint64_t size = draw.index.size; |
| 2209 | if (!vk.buffer_at(draw.index.va, size, p.index_buffer, p.index_offset)) | 2258 | if (!vk.buffer_at(draw.index.va, size, p.index_buffer, p.index_offset)) { |
| 2210 | return ReplayResult::unresolved_resource; | 2259 | size = draw.index.size; |
| 2260 | if (!vk.title_memory || !vk.title_memory(draw.index.va, size, p.index_buffer, p.index_offset)) | ||
| 2261 | return local_unresolved_at(__LINE__); | ||
| 2262 | } | ||
| 2211 | } | 2263 | } |
| 2212 | } | 2264 | } |
| 2213 | return ReplayResult::success; | 2265 | return ReplayResult::success; |
| @@ -2626,7 +2678,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2626 | }; | 2678 | }; |
| 2627 | 2679 | ||
| 2628 | if (const auto* transition = std::get_if<TransitionBarrier>(&command)) { | 2680 | if (const auto* transition = std::get_if<TransitionBarrier>(&command)) { |
| 2629 | if (!bind(transition->resource)) return ReplayResult::unresolved_resource; | 2681 | if (!bind(transition->resource)) return local_unresolved_at(__LINE__); |
| 2630 | if (p.binding.image == VK_NULL_HANDLE) { | 2682 | if (p.binding.image == VK_NULL_HANDLE) { |
| 2631 | if (transition->subresource != 0 && transition->subresource != all_subresources) | 2683 | if (transition->subresource != 0 && transition->subresource != all_subresources) |
| 2632 | return ReplayResult::invalid_subresource; | 2684 | return ReplayResult::invalid_subresource; |
| @@ -2636,14 +2688,14 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2636 | } else if (std::holds_alternative<GlobalBarrier>(command) || std::holds_alternative<BufferBarrier>(command)) { | 2688 | } else if (std::holds_alternative<GlobalBarrier>(command) || std::holds_alternative<BufferBarrier>(command)) { |
| 2637 | if (!vk.pipeline_barrier2) return ReplayResult::unsupported; | 2689 | if (!vk.pipeline_barrier2) return ReplayResult::unsupported; |
| 2638 | if (const auto* buffer_barrier = std::get_if<BufferBarrier>(&command)) | 2690 | if (const auto* buffer_barrier = std::get_if<BufferBarrier>(&command)) |
| 2639 | if (!bind(buffer_barrier->resource)) return ReplayResult::unresolved_resource; | 2691 | if (!bind(buffer_barrier->resource)) return local_unresolved_at(__LINE__); |
| 2640 | } else if (const auto* texture = std::get_if<TextureBarrier>(&command)) { | 2692 | } else if (const auto* texture = std::get_if<TextureBarrier>(&command)) { |
| 2641 | if (!vk.pipeline_barrier2) return ReplayResult::unsupported; | 2693 | if (!vk.pipeline_barrier2) return ReplayResult::unsupported; |
| 2642 | if (!bind(texture->resource)) return ReplayResult::unresolved_resource; | 2694 | if (!bind(texture->resource)) return local_unresolved_at(__LINE__); |
| 2643 | if (!p.binding.image || !barrier_range(p.binding, texture->range, p.range)) | 2695 | if (!p.binding.image || !barrier_range(p.binding, texture->range, p.range)) |
| 2644 | return ReplayResult::invalid_subresource; | 2696 | return ReplayResult::invalid_subresource; |
| 2645 | } else if (const auto* color_clear = std::get_if<ClearRenderTarget>(&command)) { | 2697 | } else if (const auto* color_clear = std::get_if<ClearRenderTarget>(&command)) { |
| 2646 | if (!bind(color_clear->target.resource)) return ReplayResult::unresolved_resource; | 2698 | if (!bind(color_clear->target.resource)) return local_unresolved_at(__LINE__); |
| 2647 | if (!p.binding.image || p.binding.aspects != VK_IMAGE_ASPECT_COLOR_BIT) return ReplayResult::invalid_clear; | 2699 | if (!p.binding.image || p.binding.aspects != VK_IMAGE_ASPECT_COLOR_BIT) return ReplayResult::invalid_clear; |
| 2648 | if (!detail::view_range(p.binding, color_clear->target, VK_IMAGE_ASPECT_COLOR_BIT, p.range)) | 2700 | if (!detail::view_range(p.binding, color_clear->target, VK_IMAGE_ASPECT_COLOR_BIT, p.range)) |
| 2649 | return ReplayResult::invalid_subresource; | 2701 | return ReplayResult::invalid_subresource; |
| @@ -2665,7 +2717,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2665 | r != ReplayResult::success) return r; | 2717 | r != ReplayResult::success) return r; |
| 2666 | if (!p.skip && p.rects.empty() && !vk.clear_color_image) return ReplayResult::unsupported; | 2718 | if (!p.skip && p.rects.empty() && !vk.clear_color_image) return ReplayResult::unsupported; |
| 2667 | } else if (const auto* depth_clear = std::get_if<ClearDepthStencil>(&command)) { | 2719 | } else if (const auto* depth_clear = std::get_if<ClearDepthStencil>(&command)) { |
| 2668 | if (!bind(depth_clear->target.resource)) return ReplayResult::unresolved_resource; | 2720 | if (!bind(depth_clear->target.resource)) return local_unresolved_at(__LINE__); |
| 2669 | VkImageAspectFlags aspects = 0; | 2721 | VkImageAspectFlags aspects = 0; |
| 2670 | if (depth_clear->flags & clear_depth) aspects |= VK_IMAGE_ASPECT_DEPTH_BIT; | 2722 | if (depth_clear->flags & clear_depth) aspects |= VK_IMAGE_ASPECT_DEPTH_BIT; |
| 2671 | if (depth_clear->flags & clear_stencil) aspects |= VK_IMAGE_ASPECT_STENCIL_BIT; | 2723 | if (depth_clear->flags & clear_stencil) aspects |= VK_IMAGE_ASPECT_STENCIL_BIT; |
| @@ -2685,7 +2737,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2685 | if (!p.skip && p.rects.empty() && !vk.clear_depth_stencil_image) return ReplayResult::unsupported; | 2737 | if (!p.skip && p.rects.empty() && !vk.clear_depth_stencil_image) return ReplayResult::unsupported; |
| 2686 | } else if (const auto* uav = std::get_if<ClearUnorderedAccess>(&command)) { | 2738 | } else if (const auto* uav = std::get_if<ClearUnorderedAccess>(&command)) { |
| 2687 | const UavView& view = uav->view; | 2739 | const UavView& view = uav->view; |
| 2688 | if (!bind(view.resource)) return ReplayResult::unresolved_resource; | 2740 | if (!bind(view.resource)) return local_unresolved_at(__LINE__); |
| 2689 | if (view.buffer) { | 2741 | if (view.buffer) { |
| 2690 | if (!vk.fill_buffer || !vk.update_buffer || !vk.copy_buffer) return ReplayResult::unsupported; | 2742 | if (!vk.fill_buffer || !vk.update_buffer || !vk.copy_buffer) return ReplayResult::unsupported; |
| 2691 | if (predicated) ++out.unpredicated_copies; // fills and copies are transfer commands | 2743 | if (predicated) ++out.unpredicated_copies; // fills and copies are transfer commands |
| @@ -2745,7 +2797,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2745 | if (predicated && !std::holds_alternative<CopyBuffer>(command)) ++out.unpredicated_copies; | 2797 | if (predicated && !std::holds_alternative<CopyBuffer>(command)) ++out.unpredicated_copies; |
| 2746 | const auto [dst_id, src_id] = copy_ids(command); | 2798 | const auto [dst_id, src_id] = copy_ids(command); |
| 2747 | const ResourceBinding* source = resolve(src_id); | 2799 | const ResourceBinding* source = resolve(src_id); |
| 2748 | if (!bind(dst_id) || !source) return ReplayResult::unresolved_resource; | 2800 | if (!bind(dst_id) || !source) return local_unresolved_at(__LINE__); |
| 2749 | p.source = *source; | 2801 | p.source = *source; |
| 2750 | ReplayResult result = ReplayResult::success; | 2802 | ReplayResult result = ReplayResult::success; |
| 2751 | if (const auto* buffer_copy = std::get_if<CopyBuffer>(&command)) { | 2803 | if (const auto* buffer_copy = std::get_if<CopyBuffer>(&command)) { |
| @@ -2878,7 +2930,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2878 | if (!vk.resolve_image) return ReplayResult::unsupported; | 2930 | if (!vk.resolve_image) return ReplayResult::unsupported; |
| 2879 | if (predicated) ++out.unpredicated_copies; // a transfer command, like the copies | 2931 | if (predicated) ++out.unpredicated_copies; // a transfer command, like the copies |
| 2880 | const ResourceBinding* source = resolve(resolve_command->src); | 2932 | const ResourceBinding* source = resolve(resolve_command->src); |
| 2881 | if (!bind(resolve_command->dst) || !source) return ReplayResult::unresolved_resource; | 2933 | if (!bind(resolve_command->dst) || !source) return local_unresolved_at(__LINE__); |
| 2882 | p.source = *source; | 2934 | p.source = *source; |
| 2883 | if (const auto result = detail::prepare_resolve(*resolve_command, p); result != ReplayResult::success) | 2935 | if (const auto result = detail::prepare_resolve(*resolve_command, p); result != ReplayResult::success) |
| 2884 | return result; | 2936 | return result; |
| @@ -2909,7 +2961,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2909 | } | 2961 | } |
| 2910 | } else if (const auto* discard = std::get_if<DiscardResource>(&command)) { | 2962 | } else if (const auto* discard = std::get_if<DiscardResource>(&command)) { |
| 2911 | // Buffers and partial (rectangle) discards keep their contents, which "undefined" allows. | 2963 | // Buffers and partial (rectangle) discards keep their contents, which "undefined" allows. |
| 2912 | if (!bind(discard->resource)) return ReplayResult::unresolved_resource; | 2964 | if (!bind(discard->resource)) return local_unresolved_at(__LINE__); |
| 2913 | const std::uint64_t end = std::uint64_t(discard->first_subresource) + discard->count; | 2965 | const std::uint64_t end = std::uint64_t(discard->first_subresource) + discard->count; |
| 2914 | if (!p.binding.image) { | 2966 | if (!p.binding.image) { |
| 2915 | if (!discard->whole && end > 1) return ReplayResult::invalid_subresource; | 2967 | if (!discard->whole && end > 1) return ReplayResult::invalid_subresource; |
| @@ -2929,7 +2981,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2929 | if (!vk.update_buffer || !vk.buffer_at) return ReplayResult::unsupported; | 2981 | if (!vk.update_buffer || !vk.buffer_at) return ReplayResult::unsupported; |
| 2930 | std::uint64_t bytes = 4; | 2982 | std::uint64_t bytes = 4; |
| 2931 | if (!vk.buffer_at(write->address, bytes, p.write_buffer, p.write_offset) || bytes < 4) | 2983 | if (!vk.buffer_at(write->address, bytes, p.write_buffer, p.write_offset) || bytes < 4) |
| 2932 | return ReplayResult::unresolved_resource; | 2984 | return local_unresolved_at(__LINE__); |
| 2933 | if (p.write_offset % 4) return ReplayResult::invalid_copy; | 2985 | if (p.write_offset % 4) return ReplayResult::invalid_copy; |
| 2934 | // WriteBufferImmediate resolves by VA and may target a readback buffer in COPY_DEST. | 2986 | // WriteBufferImmediate resolves by VA and may target a readback buffer in COPY_DEST. |
| 2935 | out.wrote_readback = true; | 2987 | out.wrote_readback = true; |
| @@ -2938,14 +2990,14 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2938 | if (!vk.copy_buffer) return ReplayResult::unsupported; | 2990 | if (!vk.copy_buffer) return ReplayResult::unsupported; |
| 2939 | if (predicated) ++out.unpredicated_copies; // a transfer command, like the copies | 2991 | if (predicated) ++out.unpredicated_copies; // a transfer command, like the copies |
| 2940 | const ResourceBinding* source = resolve(atomic->src); | 2992 | const ResourceBinding* source = resolve(atomic->src); |
| 2941 | if (!bind(atomic->dst) || !source) return ReplayResult::unresolved_resource; | 2993 | if (!bind(atomic->dst) || !source) return local_unresolved_at(__LINE__); |
| 2942 | p.source = *source; | 2994 | p.source = *source; |
| 2943 | if (!p.binding.buffer || !p.source.buffer || !detail::within(atomic->dst_offset, atomic->bytes, p.binding.size) || | 2995 | if (!p.binding.buffer || !p.source.buffer || !detail::within(atomic->dst_offset, atomic->bytes, p.binding.size) || |
| 2944 | !detail::within(atomic->src_offset, atomic->bytes, p.source.size)) | 2996 | !detail::within(atomic->src_offset, atomic->bytes, p.source.size)) |
| 2945 | return ReplayResult::invalid_copy; | 2997 | return ReplayResult::invalid_copy; |
| 2946 | for (const auto& d : atomic->dependencies) { | 2998 | for (const auto& d : atomic->dependencies) { |
| 2947 | const ResourceBinding* dependent = resolve(d.resource); | 2999 | const ResourceBinding* dependent = resolve(d.resource); |
| 2948 | if (!dependent) return ReplayResult::unresolved_resource; | 3000 | if (!dependent) return local_unresolved_at(__LINE__); |
| 2949 | if (!dependent->image) { | 3001 | if (!dependent->image) { |
| 2950 | const std::uint64_t end = d.end == UINT64_MAX ? dependent->size : d.end; | 3002 | const std::uint64_t end = d.end == UINT64_MAX ? dependent->size : d.end; |
| 2951 | if (d.subresource != 0 || d.begin >= end || end > dependent->size) | 3003 | if (d.subresource != 0 || d.begin >= end || end > dependent->size) |
| @@ -2964,7 +3016,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2964 | if (!conditional) return ReplayResult::unsupported; | 3016 | if (!conditional) return ReplayResult::unsupported; |
| 2965 | // Without physical segments the capture dispatch would pollute CSInvocations. | 3017 | // Without physical segments the capture dispatch would pollute CSInvocations. |
| 2966 | if (statistics_active && !statistics_helpers) return ReplayResult::unsupported; | 3018 | if (statistics_active && !statistics_helpers) return ReplayResult::unsupported; |
| 2967 | if (!bind(predication->buffer)) return ReplayResult::unresolved_resource; | 3019 | if (!bind(predication->buffer)) return local_unresolved_at(__LINE__); |
| 2968 | if (!p.binding.buffer || !detail::within(predication->offset, 8, p.binding.size) || | 3020 | if (!p.binding.buffer || !detail::within(predication->offset, 8, p.binding.size) || |
| 2969 | predication->offset > UINT64_MAX - p.binding.buffer_offset) | 3021 | predication->offset > UINT64_MAX - p.binding.buffer_offset) |
| 2970 | return ReplayResult::invalid_predication; | 3022 | return ReplayResult::invalid_predication; |
| @@ -2976,7 +3028,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2976 | // not suppress them (emit_query suspends conditional rendering around ResolveQueryData). | 3028 | // not suppress them (emit_query suspends conditional rendering around ResolveQueryData). |
| 2977 | if (!queries) return ReplayResult::unsupported; | 3029 | if (!queries) return ReplayResult::unsupported; |
| 2978 | QueryPool* heap = vk.query_pool(range.heap); | 3030 | QueryPool* heap = vk.query_pool(range.heap); |
| 2979 | if (!heap) return ReplayResult::unresolved_resource; | 3031 | if (!heap) return local_unresolved_at(__LINE__); |
| 2980 | if (!query_fits_heap(heap->heap_type, range.type)) return ReplayResult::invalid_query; | 3032 | if (!query_fits_heap(heap->heap_type, range.type)) return ReplayResult::invalid_query; |
| 2981 | if (range.first >= heap->count || range.count > heap->count - range.first) | 3033 | if (range.first >= heap->count || range.count > heap->count - range.first) |
| 2982 | return ReplayResult::invalid_query; | 3034 | return ReplayResult::invalid_query; |
| @@ -2999,7 +3051,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 2999 | } | 3051 | } |
| 3000 | if (const auto* resolve_queries = std::get_if<ResolveQueries>(&command)) { | 3052 | if (const auto* resolve_queries = std::get_if<ResolveQueries>(&command)) { |
| 3001 | // The destination is a buffer, as D3D12 requires, large enough for every result. | 3053 | // The destination is a buffer, as D3D12 requires, large enough for every result. |
| 3002 | if (!bind(resolve_queries->dst)) return ReplayResult::unresolved_resource; | 3054 | if (!bind(resolve_queries->dst)) return local_unresolved_at(__LINE__); |
| 3003 | const std::uint64_t bytes = std::uint64_t(range.count) * query_result_size(range.type); | 3055 | const std::uint64_t bytes = std::uint64_t(range.count) * query_result_size(range.type); |
| 3004 | if (!p.binding.buffer || p.binding.buffer_offset % 8 || | 3056 | if (!p.binding.buffer || p.binding.buffer_offset % 8 || |
| 3005 | !detail::within(resolve_queries->offset, bytes, p.binding.size) || | 3057 | !detail::within(resolve_queries->offset, bytes, p.binding.size) || |
| @@ -3017,7 +3069,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3017 | } | 3069 | } |
| 3018 | out.queries.push_back({i, heap, statistics_active}); | 3070 | out.queries.push_back({i, heap, statistics_active}); |
| 3019 | } else if (const auto* ind = std::get_if<ExecuteIndirect>(&command)) { | 3071 | } else if (const auto* ind = std::get_if<ExecuteIndirect>(&command)) { |
| 3020 | if (!bind(ind->argument_buffer) || !p.binding.buffer) return ReplayResult::unresolved_resource; | 3072 | if (!bind(ind->argument_buffer) || !p.binding.buffer) return local_unresolved_at(__LINE__); |
| 3021 | const VkDeviceSize record_size = detail::indirect_record_size(ind->kind); | 3073 | const VkDeviceSize record_size = detail::indirect_record_size(ind->kind); |
| 3022 | if (!record_size || ind->stride < record_size || ind->stride % sizeof(std::uint32_t)) | 3074 | if (!record_size || ind->stride < record_size || ind->stride % sizeof(std::uint32_t)) |
| 3023 | return ReplayResult::invalid_indirect_arguments; | 3075 | return ReplayResult::invalid_indirect_arguments; |
| @@ -3026,7 +3078,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3026 | return ReplayResult::invalid_indirect_arguments; | 3078 | return ReplayResult::invalid_indirect_arguments; |
| 3027 | if (ind->count_buffer) { | 3079 | if (ind->count_buffer) { |
| 3028 | const ResourceBinding* cnt = resolve(ind->count_buffer); | 3080 | const ResourceBinding* cnt = resolve(ind->count_buffer); |
| 3029 | if (!cnt || !cnt->buffer) return ReplayResult::unresolved_resource; | 3081 | if (!cnt || !cnt->buffer) return local_unresolved_at(__LINE__); |
| 3030 | if (!detail::indirect_range(*cnt, ind->count_offset, sizeof(std::uint32_t))) | 3082 | if (!detail::indirect_range(*cnt, ind->count_offset, sizeof(std::uint32_t))) |
| 3031 | return ReplayResult::invalid_indirect_arguments; | 3083 | return ReplayResult::invalid_indirect_arguments; |
| 3032 | p.source = *cnt; | 3084 | p.source = *cnt; |
| @@ -3052,7 +3104,7 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3052 | if (ind->kind == IndirectKind::dispatch && ind->pipeline) { // the pipeline and root arguments it was recorded | 3104 | if (ind->kind == IndirectKind::dispatch && ind->pipeline) { // the pipeline and root arguments it was recorded |
| 3053 | if (!vk.bind_pipeline || !vk.push_constants || !vk.compute_pipeline) return ReplayResult::unsupported; | 3105 | if (!vk.bind_pipeline || !vk.push_constants || !vk.compute_pipeline) return ReplayResult::unsupported; |
| 3054 | const ComputePipeline* pipeline = vk.compute_pipeline(ind->pipeline); | 3106 | const ComputePipeline* pipeline = vk.compute_pipeline(ind->pipeline); |
| 3055 | if (!pipeline || !pipeline->pipeline) return ReplayResult::unresolved_resource; | 3107 | if (!pipeline || !pipeline->pipeline) return local_unresolved_at(__LINE__); |
| 3056 | if (pipeline->bindless_set && !vk.bind_descriptor_sets) return ReplayResult::unsupported; | 3108 | if (pipeline->bindless_set && !vk.bind_descriptor_sets) return ReplayResult::unsupported; |
| 3057 | p.pipeline = *pipeline; | 3109 | p.pipeline = *pipeline; |
| 3058 | } | 3110 | } |
| @@ -3064,10 +3116,10 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3064 | if (!vk.build_acceleration_structures || !vk.resolve_acceleration_structure) | 3116 | if (!vk.build_acceleration_structures || !vk.resolve_acceleration_structure) |
| 3065 | return ReplayResult::unsupported; | 3117 | return ReplayResult::unsupported; |
| 3066 | p.accel_dst = vk.resolve_acceleration_structure(build->dst_va); | 3118 | p.accel_dst = vk.resolve_acceleration_structure(build->dst_va); |
| 3067 | if (!p.accel_dst) return ReplayResult::unresolved_resource; | 3119 | if (!p.accel_dst) return local_unresolved_at(__LINE__); |
| 3068 | if (build->update && build->src_va) { | 3120 | if (build->update && build->src_va) { |
| 3069 | p.accel_src = vk.resolve_acceleration_structure(build->src_va); | 3121 | p.accel_src = vk.resolve_acceleration_structure(build->src_va); |
| 3070 | if (!p.accel_src) return ReplayResult::unresolved_resource; | 3122 | if (!p.accel_src) return local_unresolved_at(__LINE__); |
| 3071 | } | 3123 | } |
| 3072 | if (build->is_tlas && build->instance_pointers && build->instance_count) { | 3124 | if (build->is_tlas && build->instance_pointers && build->instance_count) { |
| 3073 | if (!vk.prepare_khr_instances || !vk.host_at || !vk.buffer_at) return ReplayResult::unsupported; | 3125 | if (!vk.prepare_khr_instances || !vk.host_at || !vk.buffer_at) return ReplayResult::unsupported; |
| @@ -3081,9 +3133,9 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3081 | std::uint64_t room = ~std::uint64_t(0); | 3133 | std::uint64_t room = ~std::uint64_t(0); |
| 3082 | VkBuffer buffer = VK_NULL_HANDLE; | 3134 | VkBuffer buffer = VK_NULL_HANDLE; |
| 3083 | VkDeviceSize offset = 0; | 3135 | VkDeviceSize offset = 0; |
| 3084 | if (!vk.buffer_at(copy->dst_va, room, buffer, offset)) return ReplayResult::unresolved_resource; | 3136 | if (!vk.buffer_at(copy->dst_va, room, buffer, offset)) return local_unresolved_at(__LINE__); |
| 3085 | std::uint64_t source = ~std::uint64_t(0); | 3137 | std::uint64_t source = ~std::uint64_t(0); |
| 3086 | if (!vk.buffer_at(copy->src_va, source, buffer, offset)) return ReplayResult::unresolved_resource; | 3138 | if (!vk.buffer_at(copy->src_va, source, buffer, offset)) return local_unresolved_at(__LINE__); |
| 3087 | p.xdxr_bytes = std::min(room, source); | 3139 | p.xdxr_bytes = std::min(room, source); |
| 3088 | } else if (const auto* info = std::get_if<AccelerationStructurePostbuild>(&command)) { | 3140 | } else if (const auto* info = std::get_if<AccelerationStructurePostbuild>(&command)) { |
| 3089 | // The KHR path never wrote postbuild values; it keeps skipping them rather than failing the list. | 3141 | // The KHR path never wrote postbuild values; it keeps skipping them rather than failing the list. |
| @@ -3094,14 +3146,14 @@ ReplayResult prepare(const CommandList& list, Resolve&& resolve, const ReplayFun | |||
| 3094 | std::uint64_t room = 8 * info->sources.size(); | 3146 | std::uint64_t room = 8 * info->sources.size(); |
| 3095 | VkBuffer buffer = VK_NULL_HANDLE; | 3147 | VkBuffer buffer = VK_NULL_HANDLE; |
| 3096 | VkDeviceSize offset = 0; | 3148 | VkDeviceSize offset = 0; |
| 3097 | if (!vk.buffer_at(info->dest_va, room, buffer, offset)) return ReplayResult::unresolved_resource; | 3149 | if (!vk.buffer_at(info->dest_va, room, buffer, offset)) return local_unresolved_at(__LINE__); |
| 3098 | if (room < 8 * info->sources.size()) return ReplayResult::invalid_copy; | 3150 | if (room < 8 * info->sources.size()) return ReplayResult::invalid_copy; |
| 3099 | } | 3151 | } |
| 3100 | } else if (const auto* dispatch = std::get_if<Dispatch>(&command)) { | 3152 | } else if (const auto* dispatch = std::get_if<Dispatch>(&command)) { |
| 3101 | if (!vk.bind_pipeline || !vk.push_constants || !vk.dispatch || !vk.compute_pipeline) | 3153 | if (!vk.bind_pipeline || !vk.push_constants || !vk.dispatch || !vk.compute_pipeline) |
| 3102 | return ReplayResult::unsupported; | 3154 | return ReplayResult::unsupported; |
| 3103 | const ComputePipeline* pipeline = vk.compute_pipeline(dispatch->pipeline); | 3155 | const ComputePipeline* pipeline = vk.compute_pipeline(dispatch->pipeline); |
| 3104 | if (!pipeline || !pipeline->pipeline) return ReplayResult::unresolved_resource; | 3156 | if (!pipeline || !pipeline->pipeline) return local_unresolved_at(__LINE__); |
| 3105 | if (pipeline->bindless_set && !vk.bind_descriptor_sets) return ReplayResult::unsupported; | 3157 | if (pipeline->bindless_set && !vk.bind_descriptor_sets) return ReplayResult::unsupported; |
| 3106 | p.pipeline = *pipeline; | 3158 | p.pipeline = *pipeline; |
| 3107 | } else if (const auto* draw = std::get_if<Draw>(&command)) { | 3159 | } else if (const auto* draw = std::get_if<Draw>(&command)) { |