81 lines
2.1 KiB
C++
81 lines
2.1 KiB
C++
#include "XCEngine/RHI/Vulkan/VulkanCommandQueue.h"
|
|
|
|
#include "XCEngine/RHI/RHIFence.h"
|
|
#include "XCEngine/RHI/Vulkan/VulkanCommandList.h"
|
|
#include "XCEngine/RHI/Vulkan/VulkanDevice.h"
|
|
|
|
#include <vector>
|
|
|
|
namespace XCEngine {
|
|
namespace RHI {
|
|
|
|
bool VulkanCommandQueue::Initialize(VulkanDevice* device, CommandQueueType type) {
|
|
if (device == nullptr || device->GetGraphicsQueue() == VK_NULL_HANDLE) {
|
|
return false;
|
|
}
|
|
|
|
m_device = device;
|
|
m_queue = device->GetGraphicsQueue();
|
|
m_type = type;
|
|
return true;
|
|
}
|
|
|
|
void VulkanCommandQueue::Shutdown() {
|
|
m_queue = VK_NULL_HANDLE;
|
|
m_device = nullptr;
|
|
m_currentFrame = 0;
|
|
}
|
|
|
|
void VulkanCommandQueue::ExecuteCommandLists(uint32_t count, void** lists) {
|
|
if (m_queue == VK_NULL_HANDLE || count == 0 || lists == nullptr) {
|
|
return;
|
|
}
|
|
|
|
std::vector<VkCommandBuffer> commandBuffers;
|
|
commandBuffers.reserve(count);
|
|
for (uint32_t i = 0; i < count; ++i) {
|
|
auto* commandList = static_cast<VulkanCommandList*>(lists[i]);
|
|
if (commandList != nullptr && commandList->GetCommandBuffer() != VK_NULL_HANDLE) {
|
|
commandBuffers.push_back(commandList->GetCommandBuffer());
|
|
}
|
|
}
|
|
|
|
if (commandBuffers.empty()) {
|
|
return;
|
|
}
|
|
|
|
VkSubmitInfo submitInfo = {};
|
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
|
|
submitInfo.commandBufferCount = static_cast<uint32_t>(commandBuffers.size());
|
|
submitInfo.pCommandBuffers = commandBuffers.data();
|
|
|
|
vkQueueSubmit(m_queue, 1, &submitInfo, VK_NULL_HANDLE);
|
|
vkQueueWaitIdle(m_queue);
|
|
++m_currentFrame;
|
|
}
|
|
|
|
void VulkanCommandQueue::Signal(RHIFence* fence, uint64_t value) {
|
|
if (fence != nullptr) {
|
|
fence->Signal(value);
|
|
}
|
|
}
|
|
|
|
void VulkanCommandQueue::Wait(RHIFence* fence, uint64_t value) {
|
|
if (fence != nullptr) {
|
|
fence->Wait(value);
|
|
}
|
|
}
|
|
|
|
uint64_t VulkanCommandQueue::GetCompletedValue() {
|
|
return m_currentFrame;
|
|
}
|
|
|
|
void VulkanCommandQueue::WaitForIdle() {
|
|
if (m_queue != VK_NULL_HANDLE) {
|
|
vkQueueWaitIdle(m_queue);
|
|
}
|
|
}
|
|
|
|
} // namespace RHI
|
|
} // namespace XCEngine
|