From cdc59625395b224577d5aa41d3aa416dbfa5c1f5 Mon Sep 17 00:00:00 2001 From: Tyrannys <80750971+Tyrannys@users.noreply.github.com> Date: Fri, 27 Nov 2026 04:45:48 -0600 Subject: [PATCH 1/2] vulkan: the depth24 conversion keeps its shader barriers on a copy queue (RT-DEPTH24-COPY-QUEUE-BARRIERS) A D3D12 copy queue on a compute-capable Vulkan family runs the depth24/rgb96 footprint conversion (depth24_prepare is installed whenever the family is not the transfer-only one), but its replay's queue_stages are queue_stages_copy, which have no COMPUTE_SHADER bit. restrict_to_queue then zeroed the shader access of the four barriers around run_depth24, and the host-readback barrier was masked down to TRANSFER, so neither the copy's writes reached the dispatch nor the dispatch's writes the host. Found by kevincommits in #1608. - detail::depth24_barrier: the barriers around the conversion's dispatch are restricted to the queue's stages plus COMPUTE_SHADER, the stage the dispatch already needs on that queue. restrict_to_queue and memory_barrier now take their stages through restrict_to_stages/memory_barrier_within; every other barrier is unchanged. - The host-readback barrier allows COMPUTE_SHADER where depth24_prepare is installed. - queue_stages itself is unchanged, so the other compute paths stay refused on a copy queue. depth24_convert_test watches vkCmdPipelineBarrier through the context's device proc: on every queue kind, the depth24 and rgb96 readbacks must have a barrier into the shader's reads and one out of its writes, and the host barrier must come from COMPUTE_SHADER/MEMORY_WRITE. Both checks fail on main. AI-assisted (Claude Code) Co-Authored-By: Claude Opus 5.5 --- runtime/src/vulkan_backend.h | 5 +- runtime/src/vulkan_replay.h | 73 ++++++++++++++++++-------- runtime/test/depth24_convert_test.cpp | 75 ++++++++++++++++++++------- 3 files changed, 110 insertions(+), 43 deletions(-) diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index bf970aa282..99d00177c3 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h @@ -3735,7 +3735,10 @@ class VulkanQueue : private QueueHolds::Holder { close_labels(command_buffer, replay, open_labels); // Only flush GPU writes to the host domain when this batch actually wrote to a readback buffer. if (wrote_readback) { - const VkPipelineStageFlags2 allowed = queue_supported_stages(kind_); + // A copy queue on a compute-capable family runs the depth24/rgb96 conversion (depth24_prepare), whose + // compute writes the host must see too. + const VkPipelineStageFlags2 allowed = + queue_supported_stages(kind_) | (replay.depth24_prepare ? VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT : 0); VkPipelineStageFlags2 src_stages = readback_stages & allowed; if (!src_stages) src_stages = VK_PIPELINE_STAGE_2_TRANSFER_BIT; const bool copy_only = diff --git a/runtime/src/vulkan_replay.h b/runtime/src/vulkan_replay.h index 548fb4c17a..1ccd6c48c6 100644 --- a/runtime/src/vulkan_replay.h +++ b/runtime/src/vulkan_replay.h @@ -1757,29 +1757,41 @@ inline constexpr VkPipelineStageFlags2 queue_stages_compute = queue_stages_copy | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT | VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT | VK_PIPELINE_STAGE_2_CLEAR_BIT; -inline void restrict_to_queue(const ReplayFunctions& vk, VkPipelineStageFlags2& stages, VkAccessFlags2& access) { - if (!vk.queue_stages) return; +// Keeps the stages and accesses a queue with `queue_stages` supports (0: any). The ReplayFunctions overloads use the +// executing queue's own. +inline void restrict_to_stages(VkPipelineStageFlags2 queue_stages, VkPipelineStageFlags2& stages, + VkAccessFlags2& access) { + if (!queue_stages) return; VkAccessFlags2 allowed = VK_ACCESS_2_TRANSFER_READ_BIT | VK_ACCESS_2_TRANSFER_WRITE_BIT | VK_ACCESS_2_MEMORY_READ_BIT | VK_ACCESS_2_MEMORY_WRITE_BIT | VK_ACCESS_2_HOST_READ_BIT | VK_ACCESS_2_HOST_WRITE_BIT; - if (vk.queue_stages & VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT) + if (queue_stages & VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT) allowed |= VK_ACCESS_2_SHADER_READ_BIT | VK_ACCESS_2_SHADER_WRITE_BIT | VK_ACCESS_2_UNIFORM_READ_BIT | VK_ACCESS_2_SHADER_SAMPLED_READ_BIT | VK_ACCESS_2_SHADER_STORAGE_READ_BIT | VK_ACCESS_2_SHADER_STORAGE_WRITE_BIT | VK_ACCESS_2_INDIRECT_COMMAND_READ_BIT; - stages &= vk.queue_stages; + stages &= queue_stages; if (!stages) stages = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT; access &= allowed; } -inline void restrict_to_queue(const ReplayFunctions& vk, VkPipelineStageFlags& stages, VkAccessFlags& access) { - if (!vk.queue_stages) return; +inline void restrict_to_stages(VkPipelineStageFlags2 queue_stages, VkPipelineStageFlags& stages, + VkAccessFlags& access) { + if (!queue_stages) return; VkPipelineStageFlags2 s2 = stages; VkAccessFlags2 a2 = access; - restrict_to_queue(vk, s2, a2); + restrict_to_stages(queue_stages, s2, a2); stages = static_cast(s2 & 0xFFFFFFFFull); access = static_cast(a2 & 0xFFFFFFFFull); } +inline void restrict_to_queue(const ReplayFunctions& vk, VkPipelineStageFlags2& stages, VkAccessFlags2& access) { + restrict_to_stages(vk.queue_stages, stages, access); +} + +inline void restrict_to_queue(const ReplayFunctions& vk, VkPipelineStageFlags& stages, VkAccessFlags& access) { + restrict_to_stages(vk.queue_stages, stages, access); +} + // A D3D12 barrier on a volume mip covers every W slice, including on devices with maintenance9. inline VkImageSubresourceRange layout_range(const ResourceBinding& resource, VkImageSubresourceRange range) { if (resource.volume) range.layerCount = VK_REMAINING_ARRAY_LAYERS; @@ -1805,10 +1817,12 @@ inline void image_barrier(const ReplayFunctions& vk, VkCommandBuffer command_buf vk.pipeline_barrier(command_buffer, src_stages, dst_stages, 0, 0, nullptr, 0, nullptr, 1, &barrier); } -inline void memory_barrier(const ReplayFunctions& vk, VkCommandBuffer command_buffer, VkAccessFlags src_access, - VkPipelineStageFlags src_stages, VkAccessFlags dst_access, VkPipelineStageFlags dst_stages) { - restrict_to_queue(vk, src_stages, src_access); - restrict_to_queue(vk, dst_stages, dst_access); +inline void memory_barrier_within(VkPipelineStageFlags2 queue_stages, const ReplayFunctions& vk, + VkCommandBuffer command_buffer, VkAccessFlags src_access, + VkPipelineStageFlags src_stages, VkAccessFlags dst_access, + VkPipelineStageFlags dst_stages) { + restrict_to_stages(queue_stages, src_stages, src_access); + restrict_to_stages(queue_stages, dst_stages, dst_access); VkMemoryBarrier barrier{}; barrier.sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER; barrier.srcAccessMask = src_access; @@ -1816,6 +1830,21 @@ inline void memory_barrier(const ReplayFunctions& vk, VkCommandBuffer command_bu vk.pipeline_barrier(command_buffer, src_stages, dst_stages, 0, 1, &barrier, 0, nullptr, 0, nullptr); } +inline void memory_barrier(const ReplayFunctions& vk, VkCommandBuffer command_buffer, VkAccessFlags src_access, + VkPipelineStageFlags src_stages, VkAccessFlags dst_access, VkPipelineStageFlags dst_stages) { + memory_barrier_within(vk.queue_stages, vk, command_buffer, src_access, src_stages, dst_access, dst_stages); +} + +// A barrier around the depth24/rgb96 conversion's dispatch (depth24_run). The backend installs depth24_prepare +// only on a queue whose family runs compute, which includes a D3D12 copy queue sharing a compute-capable family, +// whose queue_stages (queue_stages_copy) would otherwise drop the shader stage and access the dispatch needs. +inline void depth24_barrier(const ReplayFunctions& vk, VkCommandBuffer command_buffer, VkAccessFlags src_access, + VkPipelineStageFlags src_stages, VkAccessFlags dst_access, VkPipelineStageFlags dst_stages) { + const VkPipelineStageFlags2 queue = + vk.queue_stages ? vk.queue_stages | VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT : 0; + memory_barrier_within(queue, vk, command_buffer, src_access, src_stages, dst_access, dst_stages); +} + // The current layouts of a range: from the tracker, or `assumed` for an untracked image. inline LayoutPieces current(const LayoutTracker* tracker, ResourceId id, const VkImageSubresourceRange& range, VkImageLayout assumed) { @@ -5093,14 +5122,14 @@ inline void emit_commands(const PreparedList& prepared, VkCommandBuffer command_ source = p.tile_scratch; } else if (p.has_depth24) { // The words become floats in the scratch buffer, which the copy then reads (tightly packed). - detail::memory_barrier(vk, command_buffer, VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + detail::depth24_barrier(vk, command_buffer, VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT); end_statistics(); for (const auto& part : p.depth24_parts) run_depth24(part); begin_statistics(); - detail::memory_barrier(vk, command_buffer, VK_ACCESS_SHADER_WRITE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); + detail::depth24_barrier(vk, command_buffer, VK_ACCESS_SHADER_WRITE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + VK_ACCESS_TRANSFER_READ_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT); converted = p.buffer_image_copies; converted[0].bufferOffset = p.depth24.scratch_offset; converted[0].bufferRowLength = 0; @@ -5135,15 +5164,15 @@ inline void emit_commands(const PreparedList& prepared, VkCommandBuffer command_ region.bufferRowLength = 0; region.bufferImageHeight = 0; vk.copy_image_to_buffer(command_buffer, p.source.image, src_layout, p.depth24.scratch, 1, ®ion); - detail::memory_barrier(vk, command_buffer, VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, - VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, - VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT); + detail::depth24_barrier(vk, command_buffer, VK_ACCESS_MEMORY_WRITE_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, + VK_ACCESS_SHADER_READ_BIT | VK_ACCESS_SHADER_WRITE_BIT, + VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT); end_statistics(); for (const auto& part : p.depth24_parts) run_depth24(part); begin_statistics(); - detail::memory_barrier(vk, command_buffer, VK_ACCESS_SHADER_WRITE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, - VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, - VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); + detail::depth24_barrier(vk, command_buffer, VK_ACCESS_SHADER_WRITE_BIT, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, + VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, + VK_PIPELINE_STAGE_ALL_COMMANDS_BIT); } } } else if (std::holds_alternative(command)) { diff --git a/runtime/test/depth24_convert_test.cpp b/runtime/test/depth24_convert_test.cpp index dd8d35b85e..d738cb6070 100644 --- a/runtime/test/depth24_convert_test.cpp +++ b/runtime/test/depth24_convert_test.cpp @@ -62,6 +62,38 @@ VKAPI_ATTR void VKAPI_CALL observe_host(VkCommandBuffer cb, const VkDependencyIn real_barrier2(cb, dep); } +// The conversion's own barriers (vkCmdPipelineBarrier, through the context's device proc): the one before its +// dispatch must make the copy's writes visible to the shader, and the one after must make the shader's writes +// visible to what follows, on every queue kind that runs it (RT-DEPTH24-COPY-QUEUE-BARRIERS). +PFN_vkGetDeviceProcAddr real_device_proc = nullptr; +PFN_vkCmdPipelineBarrier real_barrier = nullptr; +bool watch_dispatch_barriers = false; +std::uint32_t to_shader_barriers = 0, from_shader_barriers = 0; +VKAPI_ATTR void VKAPI_CALL observe_barrier(VkCommandBuffer cb, VkPipelineStageFlags src_stages, + VkPipelineStageFlags dst_stages, VkDependencyFlags flags, + std::uint32_t memory_count, const VkMemoryBarrier* memory, + std::uint32_t buffer_count, const VkBufferMemoryBarrier* buffers, + std::uint32_t image_count, const VkImageMemoryBarrier* images) { + if (watch_dispatch_barriers) { + for (std::uint32_t i = 0; i < memory_count; ++i) { + if ((dst_stages & VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT) && + (memory[i].dstAccessMask & VK_ACCESS_SHADER_READ_BIT)) + ++to_shader_barriers; + if ((src_stages & VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT) && + (memory[i].srcAccessMask & VK_ACCESS_SHADER_WRITE_BIT)) + ++from_shader_barriers; + } + } + real_barrier(cb, src_stages, dst_stages, flags, memory_count, memory, buffer_count, buffers, image_count, images); +} +VKAPI_ATTR PFN_vkVoidFunction VKAPI_CALL observing_device_proc(VkDevice device, const char* name) { + if (name && !std::strcmp(name, "vkCmdPipelineBarrier")) { + real_barrier = reinterpret_cast(real_device_proc(device, name)); + return real_barrier ? reinterpret_cast(observe_barrier) : nullptr; + } + return real_device_proc(device, name); +} + } // namespace int main() { @@ -250,7 +282,8 @@ int main() { return VK_NULL_HANDLE; }; - VulkanContext context(gpu.device_proc, gpu.device, true); + real_device_proc = gpu.device_proc; + VulkanContext context(observing_device_proc, gpu.device, true); EXPECT(context.loaded()); context.enable_depth24(gpu.device_proc, alloc_device_local); context.set_occlusion_resolve_memory(mem_props); @@ -563,9 +596,10 @@ int main() { std::printf("depth24: shared-buffer offsets (CopyResource, RGBA8, depth24 and rgb96 CopyTexture) ok\n"); // Host-readback barrier observation across logical queue kinds: compute-converted depth24 and rgb96 - // readbacks must emit COMPUTE_SHADER_BIT / MEMORY_WRITE_BIT -> HOST_BIT / HOST_READ_BIT on direct and - // compute queues (and stay within queue_supported_stages on copy queues), and a host_readable buffer UAV - // clear must emit a TRANSFER_BIT / TRANSFER_WRITE_BIT -> HOST_BIT / HOST_READ_BIT barrier. + // readbacks must emit COMPUTE_SHADER_BIT / MEMORY_WRITE_BIT -> HOST_BIT / HOST_READ_BIT on direct, + // compute and (on a compute-capable family) copy queues, with the conversion's own barriers keeping their + // shader access, and a host_readable buffer UAV clear must emit a TRANSFER_BIT / TRANSFER_WRITE_BIT -> + // HOST_BIT / HOST_READ_BIT barrier. real_barrier2 = context.vk.vkCmdPipelineBarrier2; EXPECT(real_barrier2 != nullptr); context.vk.vkCmdPipelineBarrier2 = observe_host; @@ -584,22 +618,24 @@ int main() { VulkanQueue::QueueKind::copy}) { VulkanQueue typed(context, gpu.queue, gpu.family, kind); EXPECT(typed.ok()); + // Every kind here shares the test's one compute-capable family, so a copy queue runs the conversion + // as well; its barriers keep the shader stage and access, and so does the host readback's. + constexpr VkPipelineStageFlags2 compute = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; // depth24_as_float readback for (std::uint32_t i = 0; i < slice_words; ++i) arena_ptr[d24_rb_off / 4 + i] = poison_word; host_barriers = 0; host_src_stages = 0; host_src_access = 0; + to_shader_barriers = from_shader_barriers = 0; + watch_dispatch_barriers = true; EXPECT(typed.execute({&d24_ptr, 1}) == ReplayResult::success); + watch_dispatch_barriers = false; EXPECT(typed.idle() && host_barriers == 1); - EXPECT((host_src_stages & ~VulkanQueue::queue_supported_stages(kind)) == 0); - if (kind == VulkanQueue::QueueKind::copy) { - EXPECT(host_src_stages == VK_PIPELINE_STAGE_2_TRANSFER_BIT); - EXPECT(host_src_access == VK_ACCESS_2_TRANSFER_WRITE_BIT); - } else { - EXPECT(host_src_stages == VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT); - EXPECT(host_src_access == VK_ACCESS_2_MEMORY_WRITE_BIT); - } + EXPECT(to_shader_barriers >= 1 && from_shader_barriers >= 1); + EXPECT((host_src_stages & ~(VulkanQueue::queue_supported_stages(kind) | compute)) == 0); + EXPECT(host_src_stages == VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT); + EXPECT(host_src_access == VK_ACCESS_2_MEMORY_WRITE_BIT); for (std::uint32_t i = 0; i < slice_words; ++i) EXPECT(arena_ptr[d24_rb_off / 4 + i] == (arena_ptr[src_off / 4 + i] & depth24_max)); @@ -612,16 +648,15 @@ int main() { host_barriers = 0; host_src_stages = 0; host_src_access = 0; + to_shader_barriers = from_shader_barriers = 0; + watch_dispatch_barriers = true; EXPECT(typed.execute({&rgb96_ptr, 1}) == ReplayResult::success); + watch_dispatch_barriers = false; EXPECT(typed.idle() && host_barriers == 1); - EXPECT((host_src_stages & ~VulkanQueue::queue_supported_stages(kind)) == 0); - if (kind == VulkanQueue::QueueKind::copy) { - EXPECT(host_src_stages == VK_PIPELINE_STAGE_2_TRANSFER_BIT); - EXPECT(host_src_access == VK_ACCESS_2_TRANSFER_WRITE_BIT); - } else { - EXPECT(host_src_stages == VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT); - EXPECT(host_src_access == VK_ACCESS_2_MEMORY_WRITE_BIT); - } + EXPECT(to_shader_barriers >= 1 && from_shader_barriers >= 1); + EXPECT((host_src_stages & ~(VulkanQueue::queue_supported_stages(kind) | compute)) == 0); + EXPECT(host_src_stages == VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT); + EXPECT(host_src_access == VK_ACCESS_2_MEMORY_WRITE_BIT); for (std::uint32_t y = 0; y < rgb96_h; ++y) for (std::uint32_t x = 0; x < rgb96_w; ++x) for (std::uint32_t c = 0; c < 3; ++c) From 26fd3b3bb3c56dfb980b7047950d609d45ff382e Mon Sep 17 00:00:00 2001 From: Tyrannys <80750971+Tyrannys@users.noreply.github.com> Date: Sat, 28 Nov 2026 07:06:16 -0600 Subject: [PATCH 2/2] vulkan: keep the depth24 conversion off transfer-only queue families Review of #2469 (timbot103): - execute_now() copies context_.replay_, where enable_depth24() installed depth24_prepare and depth24_run. On a transfer-only family the queue only skipped wrapping prepare, so the inherited callbacks stayed callable and a depth24 or rgb96 copy there could record the compute dispatch and its COMPUTE_SHADER barriers. Both callbacks are now cleared on such a family, so the copy is refused as unsupported before anything is recorded. - The D3D12 device registered the transfer-only copy family only inside `if (info.conditional_rendering)`. It now registers it on every device; predication setup stays behind conditional rendering. depth24_convert_test registers the test's family as transfer-only and checks that depth24 and rgb96 uploads and readbacks on a copy queue are refused with no conversion or host barriers (fails at line 705 without the queue fix). It also checks the conversion barriers on buffer-to-image uploads on every queue kind (lixonik's note). Co-Authored-By: Claude Opus 5.5 --- runtime/shims/d3d12_vulkan_device.cpp | 21 ++++++++------ runtime/src/vulkan_backend.h | 6 ++++ runtime/test/depth24_convert_test.cpp | 40 +++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 10 deletions(-) diff --git a/runtime/shims/d3d12_vulkan_device.cpp b/runtime/shims/d3d12_vulkan_device.cpp index 031fa22e12..3afb2f2283 100644 --- a/runtime/shims/d3d12_vulkan_device.cpp +++ b/runtime/shims/d3d12_vulkan_device.cpp @@ -14970,20 +14970,25 @@ class Device final }; leonida::mem_probe::start(std::move(facts)); } - if (info.conditional_rendering) { + { const auto properties = reinterpret_cast( info.get_instance_proc(info.instance, "vkGetPhysicalDeviceProperties")); const auto families = reinterpret_cast( info.get_instance_proc(info.instance, "vkGetPhysicalDeviceQueueFamilyProperties")); - if (properties && families) { - VkPhysicalDeviceProperties limits{}; - properties(info.physical, &limits); - std::uint32_t count = 0; + std::uint32_t count = 0; + std::vector queues; + if (families) { families(info.physical, &count, nullptr); - std::vector queues(count); + queues.resize(count); families(info.physical, &count, queues.data()); - if (info.copy_family < count && !(queues[info.copy_family].queueFlags & VK_QUEUE_COMPUTE_BIT)) - state_.context->set_transfer_only_family(info.copy_family); + } + // On every device, not only with conditional rendering: the queue keeps compute work (bindless commits, + // the depth24 conversion) off a copy family without compute. + if (info.copy_family < count && !(queues[info.copy_family].queueFlags & VK_QUEUE_COMPUTE_BIT)) + state_.context->set_transfer_only_family(info.copy_family); + if (info.conditional_rendering && properties && families) { + VkPhysicalDeviceProperties limits{}; + properties(info.physical, &limits); if (info.queue_family < count && (queues[info.queue_family].queueFlags & VK_QUEUE_COMPUTE_BIT)) { state_.context->configure_predication(get_device, state_.memory, limits.limits.maxStorageBufferRange, info.queue_family); if (info.storage_buffer_8bit) state_.context->configure_predicated_copy(get_device, limits.limits); diff --git a/runtime/src/vulkan_backend.h b/runtime/src/vulkan_backend.h index 554a422606..bc01ceb18f 100644 --- a/runtime/src/vulkan_backend.h +++ b/runtime/src/vulkan_backend.h @@ -3396,6 +3396,12 @@ class VulkanQueue : private QueueHolds::Holder { } return context_.depth24_->prepare(job, parts); }; + } else if (transfer_only) { + // The conversion is a compute dispatch with shader-stage barriers, which a transfer-only family may + // not record: drop the callbacks copied from context_.replay_ (enable_depth24), so its copies are + // refused as unsupported instead. + replay.depth24_prepare = {}; + replay.depth24_run = {}; } if (can_resolve_occlusion) { replay.sum_occlusion = [this](VkCommandBuffer cb, VkQueryPool pool, std::uint32_t first, diff --git a/runtime/test/depth24_convert_test.cpp b/runtime/test/depth24_convert_test.cpp index d738cb6070..5ca3e60207 100644 --- a/runtime/test/depth24_convert_test.cpp +++ b/runtime/test/depth24_convert_test.cpp @@ -604,8 +604,10 @@ int main() { EXPECT(real_barrier2 != nullptr); context.vk.vkCmdPipelineBarrier2 = observe_host; - CommandList d24_rb_only, rgb96_rb_only, uav_clear_rb; + CommandList d24_rb_only, rgb96_rb_only, uav_clear_rb, d24_up_only, rgb96_up_only; EXPECT(d24_rb_only.copy_texture({fp_d24_rb, 0, 0, 0, loc_d24, false, {}}) && d24_rb_only.close()); + EXPECT(d24_up_only.copy_texture({loc_d24, 0, 0, 0, fp_src, false, {}}) && d24_up_only.close()); + EXPECT(rgb96_up_only.copy_texture({loc_rgb96, 0, 0, 0, fp_rgb96_src, false, {}}) && rgb96_up_only.close()); EXPECT(rgb96_rb_only.copy_texture({fp_rgb96_rb, 0, 0, 0, loc_rgb96, false, {}}) && rgb96_rb_only.close()); EXPECT(uav_clear_rb.clear_unordered_access({id_copy, true, 0, 0, slice_bytes, 4, 0, 0, 1}, false, {0x13572468u, 0, 0, 0}, {}) && @@ -614,6 +616,8 @@ int main() { const CommandList* d24_ptr = &d24_rb_only; const CommandList* rgb96_ptr = &rgb96_rb_only; const CommandList* uav_ptr = &uav_clear_rb; + const CommandList* d24_up_ptr = &d24_up_only; + const CommandList* rgb96_up_ptr = &rgb96_up_only; for (const auto kind : {VulkanQueue::QueueKind::direct, VulkanQueue::QueueKind::compute, VulkanQueue::QueueKind::copy}) { VulkanQueue typed(context, gpu.queue, gpu.family, kind); @@ -622,6 +626,17 @@ int main() { // as well; its barriers keep the shader stage and access, and so does the host readback's. constexpr VkPipelineStageFlags2 compute = VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT; + // Uploads (buffer -> image) run the conversion before the copy: its barriers keep their shader + // stage and access on every kind too. + for (const CommandList* const* upload : {&d24_up_ptr, &rgb96_up_ptr}) { + to_shader_barriers = from_shader_barriers = 0; + watch_dispatch_barriers = true; + EXPECT(typed.execute({upload, 1}) == ReplayResult::success); + watch_dispatch_barriers = false; + EXPECT(typed.idle()); + EXPECT(to_shader_barriers >= 1 && from_shader_barriers >= 1); + } + // depth24_as_float readback for (std::uint32_t i = 0; i < slice_words; ++i) arena_ptr[d24_rb_off / 4 + i] = poison_word; host_barriers = 0; @@ -674,8 +689,29 @@ int main() { EXPECT(host_src_access == VK_ACCESS_2_TRANSFER_WRITE_BIT); for (std::uint32_t i = 0; i < slice_words; ++i) EXPECT(arena_ptr[copy_off / 4 + i] == 0x13572468u); } + + // A copy queue on a transfer-only family (timbot103's review of #2469): the context's depth24 + // callbacks must not reach it, so a depth24 or rgb96 copy there is refused before anything is + // recorded, and no conversion barrier with a shader stage is emitted. The test's family has compute; + // registering it as transfer-only makes the queue take that path. + context.set_transfer_only_family(gpu.family); + { + VulkanQueue dma(context, gpu.queue, gpu.family, VulkanQueue::QueueKind::copy); + EXPECT(dma.ok()); + for (const CommandList* const* list : {&d24_ptr, &rgb96_ptr, &d24_up_ptr, &rgb96_up_ptr}) { + to_shader_barriers = from_shader_barriers = 0; + host_barriers = 0; + watch_dispatch_barriers = true; + EXPECT(dma.execute({list, 1}) == ReplayResult::unsupported); + watch_dispatch_barriers = false; + EXPECT(dma.idle()); + EXPECT(to_shader_barriers == 0 && from_shader_barriers == 0 && host_barriers == 0); + } + } + context.set_transfer_only_family(UINT32_MAX); context.vk.vkCmdPipelineBarrier2 = real_barrier2; - std::printf("depth24: host-readback visibility barriers (depth24, rgb96, buffer UAV clear) ok\n"); + std::printf("depth24: host-readback visibility barriers (depth24, rgb96, buffer UAV clear), uploads, and " + "no conversion on a transfer-only family ok\n"); } }