yum-mirror/slang
Making it easier to work with shaders
git clone https://git.yummers.dev/yum-mirror/slang
f65d756bf
master
1// vk-device-queue.h 2#pragma once 3 4#include "vk-api.h" 5#include "vk-descriptor-allocator.h" 6 7namespace gfx 8{ 9 10struct VulkanDeviceQueue 11{ 12enum 13 { 14kMaxCommandBuffers = 8 , 15 }; 16 17enum class EventType 18 { 19BeginFrame , 20EndFrame , 21CountOf , 22 }; 23 24/// Initialize - must be called before anything else can be done 25SlangResult init (const VulkanApi & api ,VkQueue queue ,int queueIndex ); 26 27/// Flushes the current command list, and steps to next (internally this is equivalent to a 28/// stepA followed by stepB) 29void flush (); 30/// Performs a full flush, and then waits for idle. 31void flushAndWait (); 32 33/// Blocks until all work submitted to GPU has completed 34void waitForIdle () {m_api -> vkQueueWaitIdle (m_queue ); } 35 36/// Get the graphics queue index (as set on init) 37int getQueueIndex ()const {return m_queueIndex ; } 38 39/// Make the specified event 'current' - meaning it's semaphore must be waited on 40VkSemaphore makeCurrent (EventType eventType ); 41VkSemaphore getSemaphore (EventType eventType ); 42/// Makes the event no longer required to be waited on 43void makeCompleted (EventType eventType ); 44/// Returns true if the event is already current 45SLANG_FORCE_INLINE bool isCurrent (EventType eventType )const 46 { 47return m_currentSemaphores [int (eventType )]!= VK_NULL_HANDLE ; 48 } 49 50/// Get the command buffer 51VkCommandBuffer getCommandBuffer ()const {return m_commandBuffer ; } 52 53/// Get the queue 54VkQueue getQueue ()const {return m_queue ; } 55 56/// Get the API 57const VulkanApi * getApi ()const {return m_api ; } 58 59/// Flushes the current command list 60void flushStepA (); 61/// Steps to next command buffer and opens. May block if command buffer is still in use 62void flushStepB (); 63 64/// Destroy the device queue 65void destroy (); 66 67/// True if the queue appears to be valid and has been initialized 68bool isValid ()const {return m_api != nullptr ; } 69 70/// Dtor 71 ~VulkanDeviceQueue (); 72 73protected : 74struct Fence 75 { 76VkFence fence ; 77bool active ; 78uint64_t value ; 79 }; 80 81void _updateFenceAtIndex ( int fenceIndex, bool blocking); 82 83VkQueue m_queue = VK_NULL_HANDLE ; 84 85int m_numCommandBuffers = 0 ; 86int m_commandBufferIndex = 0 ; 87// There are the same amount of command buffers as fences 88VkCommandPool m_commandPools[kMaxCommandBuffers] = { VK_NULL_HANDLE }; 89VkCommandBuffer m_commandBuffers[kMaxCommandBuffers] = { VK_NULL_HANDLE }; 90 91Fence m_fences[kMaxCommandBuffers] = {{ VK_NULL_HANDLE , 0 , 0u }}; 92 93VkCommandBuffer m_commandBuffer = VK_NULL_HANDLE ; 94VkCommandPool m_commandPool = VK_NULL_HANDLE ; 95VkSemaphore m_semaphores[ int (EventType::CountOf)]; 96VkSemaphore m_currentSemaphores[ int (EventType::CountOf)]; 97 98uint64_t m_lastFenceCompleted = 1 ; 99uint64_t m_nextFenceValue = 2 ; 100 101int m_queueIndex = 0 ; 102 103const VulkanApi * m_api = nullptr ; 104}; 105 106} // namespace gfx