Basic commandbuffer implementation
This commit is contained in:
@@ -12,15 +12,14 @@ using namespace Seele;
|
||||
using namespace Seele::Vulkan;
|
||||
|
||||
|
||||
Command::Command(PGraphics graphics, VkCommandPool cmdPool, PCommandPool pool)
|
||||
Command::Command(PGraphics graphics, PCommandPool pool)
|
||||
: graphics(graphics)
|
||||
, pool(pool)
|
||||
, owner(cmdPool)
|
||||
{
|
||||
VkCommandBufferAllocateInfo allocInfo = {
|
||||
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
||||
.pNext = nullptr,
|
||||
.commandPool = owner,
|
||||
.commandPool = pool->getHandle(),
|
||||
.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY,
|
||||
.commandBufferCount = 1,
|
||||
};
|
||||
@@ -34,7 +33,7 @@ Command::Command(PGraphics graphics, VkCommandPool cmdPool, PCommandPool pool)
|
||||
|
||||
Command::~Command()
|
||||
{
|
||||
vkFreeCommandBuffers(graphics->getDevice(), owner, 1, &handle);
|
||||
vkFreeCommandBuffers(graphics->getDevice(), pool->getHandle(), 1, &handle);
|
||||
waitSemaphores.clear();
|
||||
}
|
||||
|
||||
@@ -335,7 +334,7 @@ void RenderCommand::drawIndexed(uint32 indexCount, uint32 instanceCount, int32 f
|
||||
assert(threadId == std::this_thread::get_id());
|
||||
vkCmdDrawIndexed(handle, indexCount, instanceCount, firstIndex, vertexOffset, firstInstance);
|
||||
}
|
||||
void RenderCommand::dispatch(uint32 groupX, uint32 groupY, uint32 groupZ)
|
||||
void RenderCommand::drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ)
|
||||
{
|
||||
assert(threadId == std::this_thread::get_id());
|
||||
graphics->vkCmdDrawMeshTasksEXT(handle, groupX, groupY, groupZ);
|
||||
@@ -461,7 +460,7 @@ CommandPool::CommandPool(PGraphics graphics, PQueue queue)
|
||||
};
|
||||
VK_CHECK(vkCreateCommandPool(graphics->getDevice(), &info, nullptr, &commandPool));
|
||||
// TODO: dont reset individual commands, reset pool instead
|
||||
allocatedBuffers.add(new Command(graphics, commandPool, this));
|
||||
allocatedBuffers.add(new Command(graphics, this));
|
||||
|
||||
command = allocatedBuffers.back();
|
||||
command->begin();
|
||||
@@ -554,7 +553,7 @@ void CommandPool::submitCommands(PSemaphore signalSemaphore)
|
||||
assert(cmdBuffer->state == Command::State::Submit);
|
||||
}
|
||||
}
|
||||
allocatedBuffers.add(new Command(graphics, commandPool, this));
|
||||
allocatedBuffers.add(new Command(graphics, this));
|
||||
command = allocatedBuffers.back();
|
||||
command->begin();
|
||||
command->waitForSemaphore(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, waitSemaphore);
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
|
||||
namespace Seele
|
||||
{
|
||||
struct VertexInputStream;
|
||||
namespace Vulkan
|
||||
{
|
||||
DECLARE_REF(RenderPass)
|
||||
@@ -18,8 +17,8 @@ DECLARE_REF(CommandPool)
|
||||
class Command
|
||||
{
|
||||
public:
|
||||
Command(PGraphics graphics, VkCommandPool cmdPool, PCommandPool pool);
|
||||
virtual ~Command();
|
||||
Command(PGraphics graphics, PCommandPool pool);
|
||||
~Command();
|
||||
constexpr VkCommandBuffer getHandle()
|
||||
{
|
||||
return handle;
|
||||
@@ -54,7 +53,6 @@ private:
|
||||
VkViewport currentViewport;
|
||||
VkRect2D currentScissor;
|
||||
VkCommandBuffer handle;
|
||||
VkCommandPool owner;
|
||||
PRenderPass boundRenderPass;
|
||||
PFramebuffer boundFramebuffer;
|
||||
Array<PSemaphore> waitSemaphores;
|
||||
@@ -82,7 +80,7 @@ public:
|
||||
void begin(PRenderPass renderPass, PFramebuffer framebuffer);
|
||||
void end();
|
||||
void reset();
|
||||
virtual bool isReady() override;
|
||||
bool isReady();
|
||||
virtual void setViewport(Gfx::PViewport viewport) override;
|
||||
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet descriptorSet) override;
|
||||
@@ -92,7 +90,7 @@ public:
|
||||
virtual void pushConstants(Gfx::PPipelineLayout layout, Gfx::SeShaderStageFlags stage, uint32 offset, uint32 size, const void* data) override;
|
||||
virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override;
|
||||
virtual void drawIndexed(uint32 indexCount, uint32 instanceCount, int32 firstIndex, uint32 vertexOffset, uint32 firstInstance) override;
|
||||
virtual void dispatch(uint32 groupX, uint32 groupY, uint32 groupZ) override;
|
||||
virtual void drawMesh(uint32 groupX, uint32 groupY, uint32 groupZ) override;
|
||||
private:
|
||||
PGraphicsPipeline pipeline;
|
||||
bool ready;
|
||||
@@ -119,7 +117,7 @@ public:
|
||||
void begin();
|
||||
void end();
|
||||
void reset();
|
||||
virtual bool isReady() override;
|
||||
bool isReady();
|
||||
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
|
||||
virtual void bindDescriptor(Gfx::PDescriptorSet set) override;
|
||||
virtual void bindDescriptor(const Array<Gfx::PDescriptorSet>& sets) override;
|
||||
|
||||
@@ -149,7 +149,7 @@ void Window::onWindowCloseEvent()
|
||||
{
|
||||
}
|
||||
|
||||
Gfx::PTexture2D Window::getBackBuffer()
|
||||
Gfx::PTexture2D Window::getBackBuffer() const
|
||||
{
|
||||
return PTexture2D(swapChainTextures[currentImageIndex]);
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ public:
|
||||
virtual void pollInput() override;
|
||||
virtual void beginFrame() override;
|
||||
virtual void endFrame() override;
|
||||
virtual Gfx::PTexture2D getBackBuffer() override;
|
||||
virtual Gfx::PTexture2D getBackBuffer() const override;
|
||||
virtual void onWindowCloseEvent() override;
|
||||
virtual void setKeyCallback(std::function<void(KeyCode, InputAction, KeyModifier)> callback) override;
|
||||
virtual void setMouseMoveCallback(std::function<void(double, double)> callback) override;
|
||||
|
||||
Reference in New Issue
Block a user