26#include <score_plugin_gfx_export.h>
28#include <QtGui/qtguiglobal.h>
30#if QT_CONFIG(vulkan) && __has_include(<vulkan/vulkan.h>)
31#define SCORE_HAS_VULKAN_CUDA_BOUNCE 1
33#include <Gfx/Graph/interop/CudaInterop.h>
42class QRhiCommandBuffer;
45namespace score::gfx::interop
48struct VulkanCudaBounceConfig
52 std::size_t frameBytes{};
53 const char* debugName{
"vk-cuda-bounce"};
56class SCORE_PLUGIN_GFX_EXPORT VulkanCudaBounce
59 VulkanCudaBounce() =
default;
60 ~VulkanCudaBounce() { release(); }
61 VulkanCudaBounce(
const VulkanCudaBounce&) =
delete;
62 VulkanCudaBounce& operator=(
const VulkanCudaBounce&) =
delete;
65 bool init(
const VulkanCudaBounceConfig& cfg);
68 bool valid() const noexcept {
return !m_slots.empty(); }
69 std::size_t slotCount() const noexcept {
return m_slots.size(); }
73 void* cudaPtr(std::size_t i)
const noexcept
75 return i < m_slots.size() ? m_slots[i].bouncePtr :
nullptr;
80 bool flushToBounce(std::size_t i, std::size_t bytes);
84 bool flushFromBounce(std::size_t i, std::size_t bytes);
89 bool recordCopyToSlot(
90 QRhiCommandBuffer& cb,
void* srcVkBuffer, std::size_t bytes,
95 void debugPeek(std::size_t i,
const char* tag);
99 bool timelineSupported() const noexcept
101 return m_gfxQueue && m_fnQueueSubmit && m_sem.valid();
109 bool signalCopyDoneOnQueue();
114 bool waitCopyDoneOnStream();
120 bool recordCopySlotToTexture(
121 QRhiCommandBuffer& cb, QRhiTexture* dst,
int width,
int height,
122 int texelBytes, std::size_t i);
127 vkinterop::ExternalBuffer vk{};
129 CudaInteropResourceHandle vkCudaHandle{};
133 CudaInteropContextHandle m_p2p{};
134 vkinterop::VulkanCtx m_vk{};
135 std::vector<Slot> m_slots;
136 std::size_t m_frameBytes{};
139 void* m_fnCopyBuffer{};
140 void* m_fnCopyBufferToImage{};
141 void* m_fnPipelineBarrier{};
144 vkinterop::VkCudaTimelineSemaphore m_sem;
145 uint64_t m_semValue{0};
147 void* m_fnQueueSubmit{};
Exportable Vulkan timeline semaphore + CUDA-side import pair.
Vulkan external-memory image/buffer create + export + import helpers.