Files
Seele/src/Engine/Graphics/Vulkan/Command.cpp
T

527 lines
16 KiB
C++
Raw Normal View History

2023-10-26 18:37:29 +02:00
#include "CommandBuffer.h"
#include "Initializer.h"
#include "Graphics.h"
#include "Pipeline.h"
#include "Enums.h"
#include "Framebuffer.h"
#include "RenderPass.h"
#include "Pipeline.h"
#include "DescriptorSets.h"
2023-11-01 23:12:30 +01:00
#include "RenderTarget.h"
#include <vulkan/vulkan_core.h>
2020-03-24 21:05:32 +01:00
using namespace Seele;
using namespace Seele::Vulkan;
2023-11-15 00:06:00 +01:00
Command::Command(PGraphics graphics, VkCommandPool cmdPool, PCommandBufferManager manager)
: graphics(graphics)
2021-04-01 16:40:14 +02:00
, manager(manager)
, owner(cmdPool)
2020-03-24 21:05:32 +01:00
{
2023-11-15 00:06:00 +01:00
VkCommandBufferAllocateInfo allocInfo = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.pNext = nullptr,
.commandPool = owner,
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
.commandBufferCount = 1,
};
2020-03-24 21:05:32 +01:00
VK_CHECK(vkAllocateCommandBuffers(graphics->getDevice(), &allocInfo, &handle))
2020-04-12 15:47:19 +02:00
fence = new Fence(graphics);
2023-11-15 00:06:00 +01:00
state = State::Init;
2020-03-24 21:05:32 +01:00
}
2023-11-15 00:06:00 +01:00
Command::~Command()
2020-03-24 21:05:32 +01:00
{
vkFreeCommandBuffers(graphics->getDevice(), owner, 1, &handle);
2020-04-12 15:47:19 +02:00
waitSemaphores.clear();
2020-03-24 21:05:32 +01:00
}
2023-11-15 00:06:00 +01:00
void Command::begin()
2020-03-24 21:05:32 +01:00
{
2023-11-15 00:06:00 +01:00
VkCommandBufferBeginInfo beginInfo = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO,
.pNext = nullptr,
.flags = 0,
.pInheritanceInfo = nullptr,
};
2020-03-24 21:05:32 +01:00
VK_CHECK(vkBeginCommandBuffer(handle, &beginInfo));
2023-11-15 00:06:00 +01:00
state = State::Begin;
2020-03-24 21:05:32 +01:00
}
2023-11-15 00:06:00 +01:00
void Command::end()
2020-03-24 21:05:32 +01:00
{
VK_CHECK(vkEndCommandBuffer(handle));
2023-11-15 00:06:00 +01:00
state = State::End;
2020-03-24 21:05:32 +01:00
}
2023-11-15 00:06:00 +01:00
void Command::beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer)
2020-03-24 21:05:32 +01:00
{
2023-11-15 00:06:00 +01:00
assert(state == State::Begin);
2020-04-12 15:47:19 +02:00
2023-11-15 00:06:00 +01:00
VkRenderPassBeginInfo beginInfo = {
.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO,
.pNext = nullptr,
.renderPass = renderPass->getHandle(),
.framebuffer = framebuffer->getHandle(),
.renderArea = renderPass->getRenderArea(),
.clearValueCount = (uint32)renderPass->getClearValueCount(),
.pClearValues = renderPass->getClearValues(),
};
2020-03-24 21:05:32 +01:00
vkCmdBeginRenderPass(handle, &beginInfo, renderPass->getSubpassContents());
2023-11-15 00:06:00 +01:00
state = State::RenderPass;
2020-03-24 21:05:32 +01:00
}
2023-11-15 00:06:00 +01:00
void Command::endRenderPass()
2020-03-24 21:05:32 +01:00
{
vkCmdEndRenderPass(handle);
2023-11-15 00:06:00 +01:00
state = State::Begin;
2020-04-12 15:47:19 +02:00
}
2023-11-15 00:06:00 +01:00
void Command::executeCommands(const Array<Gfx::PRenderCommand>& commands)
2020-04-12 15:47:19 +02:00
{
2023-11-15 00:06:00 +01:00
assert(state == State::RenderPass);
2021-12-02 13:00:03 +01:00
if(commands.size() == 0)
{
2022-03-19 22:45:30 +01:00
//std::cout << "No commands provided" << std::endl;
2021-12-02 13:00:03 +01:00
return;
}
2020-04-12 15:47:19 +02:00
Array<VkCommandBuffer> cmdBuffers(commands.size());
for (uint32 i = 0; i < commands.size(); ++i)
{
2021-05-10 23:57:55 +02:00
auto command = commands[i].cast<RenderCommand>();
command->end();
2021-05-10 23:57:55 +02:00
executingRenders.add(command);
2023-11-15 00:06:00 +01:00
for(auto& descriptor : command->boundDescriptors)
{
boundDescriptors.add(descriptor);
}
2021-05-10 23:57:55 +02:00
cmdBuffers[i] = command->getHandle();
}
vkCmdExecuteCommands(handle, (uint32)cmdBuffers.size(), cmdBuffers.data());
}
2023-11-15 00:06:00 +01:00
void Command::executeCommands(const Array<Gfx::PComputeCommand>& commands)
2021-05-10 23:57:55 +02:00
{
2021-12-02 13:00:03 +01:00
if(commands.size() == 0)
{
return;
}
2021-05-10 23:57:55 +02:00
Array<VkCommandBuffer> cmdBuffers(commands.size());
for (uint32 i = 0; i < commands.size(); ++i)
{
auto command = commands[i].cast<ComputeCommand>();
command->end();
executingComputes.add(command);
2023-11-15 00:06:00 +01:00
for(auto& descriptor : command->boundDescriptors)
{
boundDescriptors.add(descriptor);
}
cmdBuffers[i] = command->getHandle();
2020-04-12 15:47:19 +02:00
}
2021-03-31 12:18:16 +02:00
vkCmdExecuteCommands(handle, (uint32)cmdBuffers.size(), cmdBuffers.data());
2020-04-12 15:47:19 +02:00
}
2023-11-15 00:06:00 +01:00
void Command::waitForSemaphore(VkPipelineStageFlags flags, PSemaphore semaphore)
2020-04-12 15:47:19 +02:00
{
waitSemaphores.add(semaphore);
waitFlags.add(flags);
}
2023-11-15 00:06:00 +01:00
void Command::checkFence()
2020-04-12 15:47:19 +02:00
{
2023-11-15 00:06:00 +01:00
assert(state == State::Submit || !fence->isSignaled());
if (fence->isSignaled())
2020-04-12 15:47:19 +02:00
{
2023-11-15 00:06:00 +01:00
vkResetCommandBuffer(handle, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
fence->reset();
for(auto& command : executingComputes)
2020-04-12 15:47:19 +02:00
{
2023-11-15 00:06:00 +01:00
command->reset();
2020-04-12 15:47:19 +02:00
}
2023-11-15 00:06:00 +01:00
executingComputes.clear();
for(auto& command : executingRenders)
{
command->reset();
}
executingRenders.clear();
for(auto& descriptor : boundDescriptors)
{
descriptor->unbind();
}
boundDescriptors.clear();
graphics->getDestructionManager()->notifyCmdComplete(this);
state = State::Init;
2020-04-12 15:47:19 +02:00
}
2020-03-24 21:05:32 +01:00
}
2023-11-15 00:06:00 +01:00
void Command::waitForCommand(uint32 timeout)
2021-05-10 23:57:55 +02:00
{
2023-02-13 14:56:13 +01:00
manager->submitCommands();
2023-11-15 00:06:00 +01:00
if (state == State::Begin)
2023-02-13 14:56:13 +01:00
{
// is already done
return;
}
2021-05-10 23:57:55 +02:00
fence->wait(timeout);
2023-11-15 00:06:00 +01:00
checkFence();
2021-05-10 23:57:55 +02:00
}
2023-11-15 00:06:00 +01:00
PFence Command::getFence()
2020-05-05 01:51:13 +02:00
{
return fence;
}
2023-11-15 00:06:00 +01:00
PCommandBufferManager Command::getManager()
2020-09-19 14:36:50 +02:00
{
return manager;
}
RenderCommand::RenderCommand(PGraphics graphics, VkCommandPool cmdPool)
: graphics(graphics)
, owner(cmdPool)
2020-03-24 21:05:32 +01:00
{
2023-11-15 00:06:00 +01:00
VkCommandBufferAllocateInfo allocInfo = {
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
.pNext = nullptr,
.commandPool = owner,
.level = VK_COMMAND_BUFFER_LEVEL_SECONDARY,
.commandBufferCount = 1,
};
2020-03-24 21:05:32 +01:00
VK_CHECK(vkAllocateCommandBuffers(graphics->getDevice(), &allocInfo, &handle));
}
2021-05-10 23:57:55 +02:00
RenderCommand::~RenderCommand()
{
vkFreeCommandBuffers(graphics->getDevice(), owner, 1, &handle);
2021-05-10 23:57:55 +02:00
}
2022-01-12 14:40:26 +01:00
void RenderCommand::begin(PRenderPass renderPass, PFramebuffer framebuffer)
2021-05-10 23:57:55 +02:00
{
threadId = std::this_thread::get_id();
2021-05-10 23:57:55 +02:00
ready = false;
VkCommandBufferBeginInfo beginInfo =
init::CommandBufferBeginInfo();
VkCommandBufferInheritanceInfo inheritanceInfo =
init::CommandBufferInheritanceInfo();
2022-01-12 14:40:26 +01:00
inheritanceInfo.framebuffer = framebuffer->getHandle();
inheritanceInfo.renderPass = renderPass->getHandle();
inheritanceInfo.subpass = 0;
2021-05-10 23:57:55 +02:00
beginInfo.pInheritanceInfo = &inheritanceInfo;
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT;
VK_CHECK(vkBeginCommandBuffer(handle, &beginInfo));
}
void RenderCommand::end()
{
VK_CHECK(vkEndCommandBuffer(handle));
}
void RenderCommand::reset()
{
vkResetCommandBuffer(handle, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
boundDescriptors.clear();
ready = true;
}
2021-05-10 23:57:55 +02:00
bool RenderCommand::isReady()
{
2021-04-13 23:09:16 +02:00
return ready;
}
2021-05-10 23:57:55 +02:00
void RenderCommand::setViewport(Gfx::PViewport viewport)
2020-10-03 11:00:10 +02:00
{
assert(threadId == std::this_thread::get_id());
2020-10-03 11:00:10 +02:00
VkViewport vp = viewport.cast<Viewport>()->getHandle();
2023-11-15 00:06:00 +01:00
VkRect2D scissors = init::Rect2D(viewport->getWidth(), viewport->getHeight(), viewport->getOffsetX(), viewport->getOffsetY());
2020-10-03 11:00:10 +02:00
vkCmdSetViewport(handle, 0, 1, &vp);
vkCmdSetScissor(handle, 0, 1, &scissors);
}
2021-05-10 23:57:55 +02:00
void RenderCommand::bindPipeline(Gfx::PGraphicsPipeline gfxPipeline)
2020-05-05 01:51:13 +02:00
{
assert(threadId == std::this_thread::get_id());
2020-05-05 01:51:13 +02:00
pipeline = gfxPipeline.cast<GraphicsPipeline>();
pipeline->bind(handle);
}
2021-05-10 23:57:55 +02:00
void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
2020-05-05 01:51:13 +02:00
{
assert(threadId == std::this_thread::get_id());
auto descriptor = descriptorSet.cast<DescriptorSet>();
2022-04-15 23:45:44 +02:00
assert(descriptor->writeDescriptors.size() == 0);
2021-04-13 23:09:16 +02:00
boundDescriptors.add(descriptor.getHandle());
descriptor->bind();
2021-09-23 10:10:39 +02:00
VkDescriptorSet setHandle = descriptor->getHandle();
2020-05-05 01:51:13 +02:00
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr);
}
2021-05-10 23:57:55 +02:00
void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets)
2020-10-03 11:00:10 +02:00
{
assert(threadId == std::this_thread::get_id());
2020-10-03 11:00:10 +02:00
VkDescriptorSet* sets = new VkDescriptorSet[descriptorSets.size()];
for(uint32 i = 0; i < descriptorSets.size(); ++i)
{
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
2022-04-15 23:45:44 +02:00
assert(descriptorSet->writeDescriptors.size() == 0);
descriptorSet->bind();
2021-09-23 10:10:39 +02:00
2021-04-13 23:09:16 +02:00
boundDescriptors.add(descriptorSet.getHandle());
2020-10-03 11:00:10 +02:00
sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle();
}
2021-03-31 12:18:16 +02:00
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, 0, nullptr);
2020-10-03 11:00:10 +02:00
delete[] sets;
}
2023-11-01 23:12:30 +01:00
void RenderCommand::bindVertexBuffer(const Array<Gfx::PVertexBuffer>& streams)
2020-05-05 01:51:13 +02:00
{
assert(threadId == std::this_thread::get_id());
2020-06-08 01:44:47 +02:00
Array<VkBuffer> buffers(streams.size());
Array<VkDeviceSize> offsets(streams.size());
for(uint32 i = 0; i < streams.size(); ++i)
{
2023-11-01 23:12:30 +01:00
PVertexBuffer buf = streams[i].cast<VertexBuffer>();
2020-06-08 01:44:47 +02:00
buffers[i] = buf->getHandle();
2023-11-01 23:12:30 +01:00
offsets[i] = 0;
2020-06-08 01:44:47 +02:00
};
2021-03-31 12:18:16 +02:00
vkCmdBindVertexBuffers(handle, 0, (uint32)streams.size(), buffers.data(), offsets.data());
2020-05-05 01:51:13 +02:00
}
2021-05-10 23:57:55 +02:00
void RenderCommand::bindIndexBuffer(Gfx::PIndexBuffer indexBuffer)
2020-05-05 01:51:13 +02:00
{
assert(threadId == std::this_thread::get_id());
2020-05-05 01:51:13 +02:00
PIndexBuffer buf = indexBuffer.cast<IndexBuffer>();
2020-10-23 01:47:56 +02:00
vkCmdBindIndexBuffer(handle, buf->getHandle(), 0, cast(buf->getIndexType()));
2020-05-05 01:51:13 +02:00
}
2022-04-15 11:19:30 +02:00
void RenderCommand::pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data)
{
assert(threadId == std::this_thread::get_id());
vkCmdPushConstants(handle, layout.cast<PipelineLayout>()->getHandle(), stage, offset, size, data);
}
2021-09-23 10:10:39 +02:00
void RenderCommand::draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance)
{
assert(threadId == std::this_thread::get_id());
2021-09-23 10:10:39 +02:00
vkCmdDraw(handle, vertexCount, instanceCount, firstVertex, firstInstance);
}
void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset, uint32 firstInstance)
{
assert(threadId == std::this_thread::get_id());
2023-11-11 13:56:12 +01:00
vkCmdDrawIndexed(handle, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
}
2023-10-24 15:01:09 +02:00
void RenderCommand::dispatch(uint32 groupX, uint32 groupY, uint32 groupZ)
{
assert(threadId == std::this_thread::get_id());
2023-11-05 10:36:01 +01:00
graphics->vkCmdDrawMeshTasksEXT(handle, groupX, groupY, groupZ);
2023-10-24 15:01:09 +02:00
}
2021-05-10 23:57:55 +02:00
ComputeCommand::ComputeCommand(PGraphics graphics, VkCommandPool cmdPool)
: graphics(graphics)
, owner(cmdPool)
2021-05-10 23:57:55 +02:00
{
VkCommandBufferAllocateInfo allocInfo =
init::CommandBufferAllocateInfo(cmdPool,
VK_COMMAND_BUFFER_LEVEL_SECONDARY,
1);
VK_CHECK(vkAllocateCommandBuffers(graphics->getDevice(), &allocInfo, &handle));
2021-05-10 23:57:55 +02:00
}
2021-05-10 23:57:55 +02:00
ComputeCommand::~ComputeCommand()
{
vkFreeCommandBuffers(graphics->getDevice(), owner, 1, &handle);
2021-05-10 23:57:55 +02:00
}
2021-10-15 23:12:29 +02:00
void ComputeCommand::begin(PCmdBuffer)
2021-05-10 23:57:55 +02:00
{
threadId = std::this_thread::get_id();
2021-05-10 23:57:55 +02:00
ready = false;
VkCommandBufferBeginInfo beginInfo =
init::CommandBufferBeginInfo();
VkCommandBufferInheritanceInfo inheritanceInfo =
init::CommandBufferInheritanceInfo();
inheritanceInfo.framebuffer = VK_NULL_HANDLE;
inheritanceInfo.renderPass = VK_NULL_HANDLE;
inheritanceInfo.subpass = 0;
beginInfo.pInheritanceInfo = &inheritanceInfo;
VK_CHECK(vkBeginCommandBuffer(handle, &beginInfo));
}
void ComputeCommand::end()
{
assert(threadId == std::this_thread::get_id());
VK_CHECK(vkEndCommandBuffer(handle));
}
void ComputeCommand::reset()
{
assert(threadId == std::this_thread::get_id());
vkResetCommandBuffer(handle, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
boundDescriptors.clear();
ready = true;
}
2021-05-10 23:57:55 +02:00
bool ComputeCommand::isReady()
{
return ready;
}
void ComputeCommand::bindPipeline(Gfx::PComputePipeline computePipeline)
{
assert(threadId == std::this_thread::get_id());
2021-05-10 23:57:55 +02:00
pipeline = computePipeline.cast<ComputePipeline>();
pipeline->bind(handle);
}
void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
{
assert(threadId == std::this_thread::get_id());
2021-05-10 23:57:55 +02:00
auto descriptor = descriptorSet.cast<DescriptorSet>();
2022-04-15 23:45:44 +02:00
assert(descriptor->writeDescriptors.size() == 0);
2021-05-10 23:57:55 +02:00
boundDescriptors.add(descriptor.getHandle());
descriptor->bind();
2021-10-19 23:04:38 +02:00
2021-05-10 23:57:55 +02:00
VkDescriptorSet setHandle = descriptor->getHandle();
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr);
}
void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorSets)
{
assert(threadId == std::this_thread::get_id());
2021-05-10 23:57:55 +02:00
VkDescriptorSet* sets = new VkDescriptorSet[descriptorSets.size()];
for(uint32 i = 0; i < descriptorSets.size(); ++i)
{
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
2022-04-15 23:45:44 +02:00
assert(descriptorSet->writeDescriptors.size() == 0);
descriptorSet->bind();
2022-04-15 23:45:44 +02:00
//std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl;
2022-04-15 23:45:44 +02:00
boundDescriptors.add(descriptorSet.getHandle());
2021-05-10 23:57:55 +02:00
sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle();
}
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), 0, (uint32)descriptorSets.size(), sets, 0, nullptr);
delete[] sets;
}
2022-04-15 11:19:30 +02:00
void ComputeCommand::pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data)
{
assert(threadId == std::this_thread::get_id());
vkCmdPushConstants(handle, layout.cast<PipelineLayout>()->getHandle(), stage, offset, size, data);
}
2021-05-10 23:57:55 +02:00
void ComputeCommand::dispatch(uint32 threadX, uint32 threadY, uint32 threadZ)
{
assert(threadId == std::this_thread::get_id());
2021-05-10 23:57:55 +02:00
vkCmdDispatch(handle, threadX, threadY, threadZ);
}
2023-11-15 00:06:00 +01:00
CommandPool::CommandPool(PGraphics graphics, PQueue queue)
2020-06-08 01:44:47 +02:00
: graphics(graphics), queue(queue), queueFamilyIndex(queue->getFamilyIndex())
2020-03-24 21:05:32 +01:00
{
VkCommandPoolCreateInfo info =
init::CommandPoolCreateInfo();
info.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
info.queueFamilyIndex = queue->getFamilyIndex();
VK_CHECK(vkCreateCommandPool(graphics->getDevice(), &info, nullptr, &commandPool));
2023-11-15 00:06:00 +01:00
allocatedBuffers.add(new Command(graphics, commandPool, this));
2023-11-01 23:12:30 +01:00
2023-11-15 00:06:00 +01:00
command = allocatedBuffers.back();
command->begin();
2020-03-24 21:05:32 +01:00
}
2023-11-15 00:06:00 +01:00
CommandPool::~CommandPool()
2020-03-24 21:05:32 +01:00
{
vkDestroyCommandPool(graphics->getDevice(), commandPool, nullptr);
2020-04-12 15:47:19 +02:00
graphics = nullptr;
queue = nullptr;
2020-03-24 21:05:32 +01:00
}
2023-11-15 00:06:00 +01:00
PCmdBuffer CommandPool::getCommands()
2020-03-24 21:05:32 +01:00
{
2023-11-15 00:06:00 +01:00
return command;
2020-03-24 21:05:32 +01:00
}
2023-11-15 00:06:00 +01:00
PRenderCommand CommandPool::createRenderCommand(PRenderPass renderPass, PFramebuffer framebuffer, const std::string& name)
2020-03-24 21:05:32 +01:00
{
2022-01-12 14:40:26 +01:00
std::scoped_lock lck(allocatedRenderLock);
2021-05-10 23:57:55 +02:00
for (uint32 i = 0; i < allocatedRenderCommands.size(); ++i)
2021-04-13 23:09:16 +02:00
{
2021-05-10 23:57:55 +02:00
PRenderCommand cmdBuffer = allocatedRenderCommands[i];
2021-10-16 12:59:11 +02:00
if (cmdBuffer->isReady())
2021-04-13 23:09:16 +02:00
{
2021-10-19 23:04:38 +02:00
cmdBuffer->name = name;
2022-01-12 14:40:26 +01:00
cmdBuffer->begin(renderPass, framebuffer);
2021-04-13 23:09:16 +02:00
return cmdBuffer;
}
}
2023-11-01 23:12:30 +01:00
allocatedRenderCommands.add(new RenderCommand(graphics, commandPool));
PRenderCommand result = allocatedRenderCommands.back();
2021-05-10 23:57:55 +02:00
result->name = name;
2022-01-12 14:40:26 +01:00
result->begin(renderPass, framebuffer);
2021-05-10 23:57:55 +02:00
return result;
}
2023-11-15 00:06:00 +01:00
PComputeCommand CommandPool::createComputeCommand(const std::string& name)
2021-05-10 23:57:55 +02:00
{
2022-01-12 14:40:26 +01:00
std::scoped_lock lck(allocatedComputeLock);
2021-05-10 23:57:55 +02:00
for (uint32 i = 0; i < allocatedComputeCommands.size(); ++i)
{
PComputeCommand cmdBuffer = allocatedComputeCommands[i];
if (cmdBuffer->isReady())
2021-05-10 23:57:55 +02:00
{
2021-10-19 23:04:38 +02:00
cmdBuffer->name = name;
2023-11-15 00:06:00 +01:00
cmdBuffer->begin(command);
2021-05-10 23:57:55 +02:00
return cmdBuffer;
}
}
2023-11-01 23:12:30 +01:00
allocatedComputeCommands.add(new ComputeCommand(graphics, commandPool));
PComputeCommand result = allocatedComputeCommands.back();
2021-05-10 23:57:55 +02:00
result->name = name;
2023-11-15 00:06:00 +01:00
result->begin(command);
2021-04-13 23:09:16 +02:00
return result;
2020-03-24 21:05:32 +01:00
}
2023-11-15 00:06:00 +01:00
void CommandPool::submitCommands(PSemaphore signalSemaphore)
2020-03-24 21:05:32 +01:00
{
2023-11-15 00:06:00 +01:00
if (command->state == Command::State::Begin || command->state == Command::State::RenderPass)
2020-04-01 02:17:49 +02:00
{
2023-11-15 00:06:00 +01:00
if (command->state == Command::State::RenderPass)
2020-04-01 02:17:49 +02:00
{
std::cout << "End of renderpass forced" << std::endl;
2023-11-15 00:06:00 +01:00
command->endRenderPass();
2020-04-01 02:17:49 +02:00
}
2023-11-15 00:06:00 +01:00
command->end();
2020-04-12 15:47:19 +02:00
if (signalSemaphore != nullptr)
2020-04-01 02:17:49 +02:00
{
2023-11-15 00:06:00 +01:00
queue->submitCommandBuffer(command, signalSemaphore->getHandle());
2020-04-01 02:17:49 +02:00
}
else
{
2023-11-15 00:06:00 +01:00
queue->submitCommandBuffer(command);
2020-04-01 02:17:49 +02:00
}
}
2023-11-15 00:06:00 +01:00
std::scoped_lock map(allocatedBufferLock);
2020-04-12 15:47:19 +02:00
for (uint32 i = 0; i < allocatedBuffers.size(); ++i)
2020-04-01 02:17:49 +02:00
{
PCmdBuffer cmdBuffer = allocatedBuffers[i];
2023-11-15 00:06:00 +01:00
cmdBuffer->checkFence();
if (cmdBuffer->state == Command::State::Init)
2020-04-01 02:17:49 +02:00
{
2023-11-15 00:06:00 +01:00
command = cmdBuffer;
command->begin();
2020-04-01 02:17:49 +02:00
return;
}
else
{
2023-11-15 00:06:00 +01:00
assert(cmdBuffer->state == Command::State::Submit);
2020-04-01 02:17:49 +02:00
}
}
2023-11-15 00:06:00 +01:00
allocatedBuffers.add(new Command(graphics, commandPool, this));
command = allocatedBuffers.back();
command->begin();
2023-11-11 13:56:12 +01:00
}