Removing multiple inheritance from cmd buffers

This commit is contained in:
Dynamitos
2021-10-19 11:00:39 +02:00
parent 1e742c1f45
commit a0693daa67
14 changed files with 131 additions and 121 deletions
+7 -2
View File
@@ -124,9 +124,14 @@
"-Wno-dev" "-Wno-dev"
], ],
"C_Cpp.default.cppStandard": "c++20", "C_Cpp.default.cppStandard": "c++20",
"C_Cpp.default.intelliSenseMode": "gcc-x64", "C_Cpp.default.intelliSenseMode": "msvc-x64",
"C_Cpp.files.exclude": {
"**/.vscode": true,
"external/**": true
},
"files.watcherExclude": { "files.watcherExclude": {
"**/target": true "**/target": true
}, },
"C_Cpp.errorSquiggles": "Disabled" "C_Cpp.errorSquiggles": "Disabled",
"git.ignoreSubmodules": true
} }
+1 -1
View File
@@ -36,7 +36,7 @@ void MeshAsset::load()
void MeshAsset::addMesh(PMesh mesh) void MeshAsset::addMesh(PMesh mesh)
{ {
std::scoped_lock lck(lock); std::unique_lock lck(lock);
meshes.add(mesh); meshes.add(mesh);
referencedMaterials.add(mesh->referencedMaterial); referencedMaterials.add(mesh->referencedMaterial);
} }
+2 -2
View File
@@ -14,12 +14,12 @@ public:
virtual void load() override; virtual void load() override;
void setTexture(Gfx::PTexture texture) void setTexture(Gfx::PTexture texture)
{ {
std::scoped_lock lck(lock); std::unique_lock lck(lock);
this->texture = texture; this->texture = texture;
} }
Gfx::PTexture getTexture() Gfx::PTexture getTexture()
{ {
std::scoped_lock lck(lock); std::unique_lock lck(lock);
return texture; return texture;
} }
private: private:
+1 -1
View File
@@ -162,7 +162,7 @@ typedef uint32 KeyModifierFlags;
namespace Gfx namespace Gfx
{ {
static constexpr bool useAsyncCompute = true; static constexpr bool useAsyncCompute = true;
static constexpr bool waitIdleOnSubmit = false; static constexpr bool waitIdleOnSubmit = true;
static constexpr uint32 numFramesBuffered = 8; static constexpr uint32 numFramesBuffered = 8;
extern uint32 currentFrameIndex; extern uint32 currentFrameIndex;
extern double currentFrameDelta; extern double currentFrameDelta;
+1 -1
View File
@@ -276,7 +276,7 @@ static Map<uint32, PVertexDeclaration> vertexDeclarationCache;
PVertexDeclaration VertexDeclaration::createDeclaration(PGraphics graphics, const Array<VertexElement>& elementList) PVertexDeclaration VertexDeclaration::createDeclaration(PGraphics graphics, const Array<VertexElement>& elementList)
{ {
std::scoped_lock lock(vertexDeclarationLock); std::unique_lock lock(vertexDeclarationLock);
boost::crc_32_type result; boost::crc_32_type result;
result.process_bytes(&elementList, sizeof(VertexElement) * elementList.size()); result.process_bytes(&elementList, sizeof(VertexElement) * elementList.size());
uint32 key = result.checksum(); uint32 key = result.checksum();
@@ -74,7 +74,7 @@ Allocation::~Allocation()
PSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDeviceSize alignment) PSubAllocation Allocation::getSuballocation(VkDeviceSize requestedSize, VkDeviceSize alignment)
{ {
std::scoped_lock lck(lock); std::unique_lock lck(lock);
if (isDedicated) if (isDedicated)
{ {
if (activeAllocations.empty() && requestedSize == bytesAllocated) if (activeAllocations.empty() && requestedSize == bytesAllocated)
@@ -131,7 +131,7 @@ void Allocation::markFree(SubAllocation *allocation)
VkDeviceSize lowerBound = allocation->allocatedOffset; VkDeviceSize lowerBound = allocation->allocatedOffset;
VkDeviceSize upperBound = allocation->allocatedOffset + allocation->allocatedSize; VkDeviceSize upperBound = allocation->allocatedOffset + allocation->allocatedSize;
PSubAllocation allocHandle; PSubAllocation allocHandle;
std::scoped_lock lck(lock); std::unique_lock lck(lock);
//Join lower bound //Join lower bound
for (auto freeRange : freeRanges) for (auto freeRange : freeRanges)
{ {
@@ -193,7 +193,7 @@ Allocator::Allocator(PGraphics graphics)
Allocator::~Allocator() Allocator::~Allocator()
{ {
std::scoped_lock lck(lock); std::unique_lock lck(lock);
for (auto heap : heaps) for (auto heap : heaps)
{ {
for (auto alloc : heap.allocations) for (auto alloc : heap.allocations)
@@ -208,7 +208,7 @@ Allocator::~Allocator()
PSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2, VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo) PSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2, VkMemoryPropertyFlags properties, VkMemoryDedicatedAllocateInfo *dedicatedInfo)
{ {
std::scoped_lock lck(lock); std::unique_lock lck(lock);
const VkMemoryRequirements &requirements = memRequirements2.memoryRequirements; const VkMemoryRequirements &requirements = memRequirements2.memoryRequirements;
uint8 memoryTypeIndex; uint8 memoryTypeIndex;
VK_CHECK(findMemoryType(requirements.memoryTypeBits, properties, &memoryTypeIndex)); VK_CHECK(findMemoryType(requirements.memoryTypeBits, properties, &memoryTypeIndex));
@@ -241,7 +241,7 @@ PSubAllocation Allocator::allocate(const VkMemoryRequirements2 &memRequirements2
void Allocator::free(Allocation *allocation) void Allocator::free(Allocation *allocation)
{ {
std::scoped_lock lck(lock); std::unique_lock lck(lock);
for (auto heap : heaps) for (auto heap : heaps)
{ {
for (uint32 i = 0; i < heap.allocations.size(); ++i) for (uint32 i = 0; i < heap.allocations.size(); ++i)
@@ -296,7 +296,7 @@ void StagingManager::clearPending()
PStagingBuffer StagingManager::allocateStagingBuffer(uint32 size, VkBufferUsageFlags usage, bool bCPURead) PStagingBuffer StagingManager::allocateStagingBuffer(uint32 size, VkBufferUsageFlags usage, bool bCPURead)
{ {
std::scoped_lock l(lock); std::unique_lock l(lock);
for (auto it = freeBuffers.begin(); it != freeBuffers.end(); ++it) for (auto it = freeBuffers.begin(); it != freeBuffers.end(); ++it)
{ {
auto freeBuffer = *it; auto freeBuffer = *it;
@@ -344,7 +344,7 @@ PStagingBuffer StagingManager::allocateStagingBuffer(uint32 size, VkBufferUsageF
void StagingManager::releaseStagingBuffer(PStagingBuffer buffer) void StagingManager::releaseStagingBuffer(PStagingBuffer buffer)
{ {
std::scoped_lock l(lock); std::unique_lock l(lock);
freeBuffers.add(buffer); freeBuffers.add(buffer);
activeBuffers.remove(activeBuffers.find(buffer.getHandle())); activeBuffers.remove(activeBuffers.find(buffer.getHandle()));
} }
@@ -12,22 +12,14 @@
using namespace Seele; using namespace Seele;
using namespace Seele::Vulkan; using namespace Seele::Vulkan;
CmdBufferBase::CmdBufferBase(PGraphics graphics, VkCommandPool cmdPool)
: graphics(graphics), owner(cmdPool)
{
}
CmdBufferBase::~CmdBufferBase()
{
graphics = nullptr;
}
CmdBuffer::CmdBuffer(PGraphics graphics, VkCommandPool cmdPool, PCommandBufferManager manager) CmdBuffer::CmdBuffer(PGraphics graphics, VkCommandPool cmdPool, PCommandBufferManager manager)
: CmdBufferBase(graphics, cmdPool) : graphics(graphics)
, manager(manager) , manager(manager)
, renderPass(nullptr) , renderPass(nullptr)
, framebuffer(nullptr) , framebuffer(nullptr)
, subpassIndex(0) , subpassIndex(0)
, owner(cmdPool)
{ {
VkCommandBufferAllocateInfo allocInfo = VkCommandBufferAllocateInfo allocInfo =
init::CommandBufferAllocateInfo(cmdPool, init::CommandBufferAllocateInfo(cmdPool,
@@ -174,9 +166,9 @@ PCommandBufferManager CmdBuffer::getManager()
return manager; return manager;
} }
SecondaryCmdBuffer::SecondaryCmdBuffer(PGraphics graphics, VkCommandPool cmdPool) RenderCommand::RenderCommand(PGraphics graphics, VkCommandPool cmdPool)
: CmdBufferBase(graphics, cmdPool) : graphics(graphics)
, ready(true) , owner(cmdPool)
{ {
VkCommandBufferAllocateInfo allocInfo = VkCommandBufferAllocateInfo allocInfo =
init::CommandBufferAllocateInfo(cmdPool, init::CommandBufferAllocateInfo(cmdPool,
@@ -185,31 +177,10 @@ SecondaryCmdBuffer::SecondaryCmdBuffer(PGraphics graphics, VkCommandPool cmdPool
VK_CHECK(vkAllocateCommandBuffers(graphics->getDevice(), &allocInfo, &handle)); VK_CHECK(vkAllocateCommandBuffers(graphics->getDevice(), &allocInfo, &handle));
} }
SecondaryCmdBuffer::~SecondaryCmdBuffer()
{
vkFreeCommandBuffers(graphics->getDevice(), owner, 1, &handle);
}
void SecondaryCmdBuffer::end()
{
VK_CHECK(vkEndCommandBuffer(handle));
}
void SecondaryCmdBuffer::reset()
{
vkResetCommandBuffer(handle, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
boundDescriptors.clear();
ready = true;
}
RenderCommand::RenderCommand(PGraphics graphics, VkCommandPool cmdPool)
: SecondaryCmdBuffer(graphics, cmdPool)
{}
RenderCommand::~RenderCommand() RenderCommand::~RenderCommand()
{ {
vkFreeCommandBuffers(graphics->getDevice(), owner, 1, &handle);
} }
void RenderCommand::begin(PCmdBuffer parent) void RenderCommand::begin(PCmdBuffer parent)
@@ -227,6 +198,17 @@ void RenderCommand::begin(PCmdBuffer parent)
VK_CHECK(vkBeginCommandBuffer(handle, &beginInfo)); 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;
}
bool RenderCommand::isReady() bool RenderCommand::isReady()
{ {
@@ -250,7 +232,7 @@ void RenderCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
{ {
auto descriptor = descriptorSet.cast<DescriptorSet>(); auto descriptor = descriptorSet.cast<DescriptorSet>();
boundDescriptors.add(descriptor.getHandle()); boundDescriptors.add(descriptor.getHandle());
descriptor->bind(this); descriptor->bind();
VkDescriptorSet setHandle = descriptor->getHandle(); VkDescriptorSet setHandle = descriptor->getHandle();
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr); vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr);
@@ -261,7 +243,7 @@ void RenderCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptorS
for(uint32 i = 0; i < descriptorSets.size(); ++i) for(uint32 i = 0; i < descriptorSets.size(); ++i)
{ {
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>(); auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
descriptorSet->bind(this); descriptorSet->bind();
boundDescriptors.add(descriptorSet.getHandle()); boundDescriptors.add(descriptorSet.getHandle());
sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle(); sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle();
@@ -297,12 +279,20 @@ void RenderCommand::draw(uint32 vertexCount, uint32 instanceCount, int32 firstVe
} }
ComputeCommand::ComputeCommand(PGraphics graphics, VkCommandPool cmdPool) ComputeCommand::ComputeCommand(PGraphics graphics, VkCommandPool cmdPool)
: SecondaryCmdBuffer(graphics, cmdPool) : graphics(graphics)
, owner(cmdPool)
{ {
VkCommandBufferAllocateInfo allocInfo =
init::CommandBufferAllocateInfo(cmdPool,
VK_COMMAND_BUFFER_LEVEL_SECONDARY,
1);
VK_CHECK(vkAllocateCommandBuffers(graphics->getDevice(), &allocInfo, &handle));
} }
ComputeCommand::~ComputeCommand() ComputeCommand::~ComputeCommand()
{ {
vkFreeCommandBuffers(graphics->getDevice(), owner, 1, &handle);
} }
void ComputeCommand::begin(PCmdBuffer) void ComputeCommand::begin(PCmdBuffer)
@@ -319,6 +309,17 @@ void ComputeCommand::begin(PCmdBuffer)
VK_CHECK(vkBeginCommandBuffer(handle, &beginInfo)); VK_CHECK(vkBeginCommandBuffer(handle, &beginInfo));
} }
void ComputeCommand::end()
{
VK_CHECK(vkEndCommandBuffer(handle));
}
void ComputeCommand::reset()
{
vkResetCommandBuffer(handle, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT);
boundDescriptors.clear();
ready = true;
}
bool ComputeCommand::isReady() bool ComputeCommand::isReady()
{ {
return ready; return ready;
@@ -334,7 +335,7 @@ void ComputeCommand::bindDescriptor(Gfx::PDescriptorSet descriptorSet)
{ {
auto descriptor = descriptorSet.cast<DescriptorSet>(); auto descriptor = descriptorSet.cast<DescriptorSet>();
boundDescriptors.add(descriptor.getHandle()); boundDescriptors.add(descriptor.getHandle());
descriptor->bind(this); descriptor->bind();
//std::cout << "Binding descriptor " << descriptor->getHandle() << " to cmd " << handle << std::endl; //std::cout << "Binding descriptor " << descriptor->getHandle() << " to cmd " << handle << std::endl;
VkDescriptorSet setHandle = descriptor->getHandle(); VkDescriptorSet setHandle = descriptor->getHandle();
vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr); vkCmdBindDescriptorSets(handle, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline->getLayout(), descriptorSet->getSetIndex(), 1, &setHandle, 0, nullptr);
@@ -347,7 +348,7 @@ void ComputeCommand::bindDescriptor(const Array<Gfx::PDescriptorSet>& descriptor
{ {
auto descriptorSet = descriptorSets[i].cast<DescriptorSet>(); auto descriptorSet = descriptorSets[i].cast<DescriptorSet>();
boundDescriptors.add(descriptorSet.getHandle()); boundDescriptors.add(descriptorSet.getHandle());
descriptorSet->bind(this); descriptorSet->bind();
//std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl; //std::cout << "Binding descriptor " << descriptorSet->getHandle() << " to cmd " << handle << std::endl;
sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle(); sets[descriptorSet->getSetIndex()] = descriptorSet->getHandle();
} }
@@ -390,7 +391,7 @@ PCmdBuffer CommandBufferManager::getCommands()
PRenderCommand CommandBufferManager::createRenderCommand(const std::string& name) PRenderCommand CommandBufferManager::createRenderCommand(const std::string& name)
{ {
std::scoped_lock lck(allocatedRenderLock); std::unique_lock lck(allocatedRenderLock);
for (uint32 i = 0; i < allocatedRenderCommands.size(); ++i) for (uint32 i = 0; i < allocatedRenderCommands.size(); ++i)
{ {
PRenderCommand cmdBuffer = allocatedRenderCommands[i]; PRenderCommand cmdBuffer = allocatedRenderCommands[i];
@@ -402,18 +403,18 @@ PRenderCommand CommandBufferManager::createRenderCommand(const std::string& name
} }
PRenderCommand result = new RenderCommand(graphics, commandPool); PRenderCommand result = new RenderCommand(graphics, commandPool);
result->name = name; result->name = name;
allocatedRenderCommands.add(result);
result->begin(activeCmdBuffer); result->begin(activeCmdBuffer);
allocatedRenderCommands.add(result);
return result; return result;
} }
PComputeCommand CommandBufferManager::createComputeCommand(const std::string& name) PComputeCommand CommandBufferManager::createComputeCommand(const std::string& name)
{ {
std::scoped_lock lck(allocatedComputeLock); std::unique_lock lck(allocatedComputeLock);
for (uint32 i = 0; i < allocatedComputeCommands.size(); ++i) for (uint32 i = 0; i < allocatedComputeCommands.size(); ++i)
{ {
PComputeCommand cmdBuffer = allocatedComputeCommands[i]; PComputeCommand cmdBuffer = allocatedComputeCommands[i];
if (cmdBuffer->ready) if (cmdBuffer->isReady())
{ {
cmdBuffer->begin(activeCmdBuffer); cmdBuffer->begin(activeCmdBuffer);
return cmdBuffer; return cmdBuffer;
@@ -421,8 +422,8 @@ PComputeCommand CommandBufferManager::createComputeCommand(const std::string& na
} }
PComputeCommand result = new ComputeCommand(graphics, commandPool); PComputeCommand result = new ComputeCommand(graphics, commandPool);
result->name = name; result->name = name;
allocatedComputeCommands.add(result);
result->begin(activeCmdBuffer); result->begin(activeCmdBuffer);
allocatedComputeCommands.add(result);
return result; return result;
} }
@@ -445,7 +446,7 @@ void CommandBufferManager::submitCommands(PSemaphore signalSemaphore)
queue->submitCommandBuffer(activeCmdBuffer); queue->submitCommandBuffer(activeCmdBuffer);
} }
} }
std::scoped_lock lock(allocatedBufferLock); std::unique_lock lock(allocatedBufferLock);
for (uint32 i = 0; i < allocatedBuffers.size(); ++i) for (uint32 i = 0; i < allocatedBuffers.size(); ++i)
{ {
PCmdBuffer cmdBuffer = allocatedBuffers[i]; PCmdBuffer cmdBuffer = allocatedBuffers[i];
@@ -9,35 +9,20 @@ namespace Vulkan
{ {
DECLARE_REF(RenderPass) DECLARE_REF(RenderPass)
DECLARE_REF(Framebuffer) DECLARE_REF(Framebuffer)
class CmdBufferBase DECLARE_REF(RenderCommand)
DECLARE_REF(ComputeCommand)
DECLARE_REF(DescriptorSet)
DECLARE_REF(CommandBufferManager)
class CmdBuffer
{ {
public: public:
CmdBufferBase(PGraphics graphics, VkCommandPool cmdPool); CmdBuffer(PGraphics graphics, VkCommandPool cmdPool, PCommandBufferManager manager);
virtual ~CmdBufferBase(); virtual ~CmdBuffer();
inline VkCommandBuffer getHandle() inline VkCommandBuffer getHandle()
{ {
return handle; return handle;
} }
void reset(); void reset();
VkViewport currentViewport;
VkRect2D currentScissor;
protected:
PGraphics graphics;
VkCommandBuffer handle;
VkCommandPool owner;
};
DEFINE_REF(CmdBufferBase)
DECLARE_REF(RenderCommand)
DECLARE_REF(ComputeCommand)
DECLARE_REF(DescriptorSet)
DECLARE_REF(CommandBufferManager)
class CmdBuffer : public CmdBufferBase
{
public:
CmdBuffer(PGraphics graphics, VkCommandPool cmdPool, PCommandBufferManager manager);
virtual ~CmdBuffer();
void begin(); void begin();
void end(); void end();
void beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer); void beginRenderPass(PRenderPass renderPass, PFramebuffer framebuffer);
@@ -59,12 +44,17 @@ public:
}; };
private: private:
PGraphics graphics;
PCommandBufferManager manager; PCommandBufferManager manager;
PRenderPass renderPass; PRenderPass renderPass;
PFramebuffer framebuffer; PFramebuffer framebuffer;
PFence fence; PFence fence;
uint32 subpassIndex; uint32 subpassIndex;
State state; State state;
VkViewport currentViewport;
VkRect2D currentScissor;
VkCommandBuffer handle;
VkCommandPool owner;
Array<PSemaphore> waitSemaphores; Array<PSemaphore> waitSemaphores;
Array<VkPipelineStageFlags> waitFlags; Array<VkPipelineStageFlags> waitFlags;
Array<PRenderCommand> executingRenders; Array<PRenderCommand> executingRenders;
@@ -78,29 +68,18 @@ DEFINE_REF(CmdBuffer)
DECLARE_REF(GraphicsPipeline) DECLARE_REF(GraphicsPipeline)
DECLARE_REF(ComputePipeline) DECLARE_REF(ComputePipeline)
class RenderCommand : public Gfx::RenderCommand
class SecondaryCmdBuffer: public CmdBufferBase
{
public:
SecondaryCmdBuffer(PGraphics graphics, VkCommandPool cmdPool);
virtual ~SecondaryCmdBuffer();
virtual void begin(PCmdBuffer parent) = 0;
void end();
void reset();
bool ready;
protected:
Array<DescriptorSet*> boundDescriptors;
friend class CmdBuffer;
};
DEFINE_REF(SecondaryCmdBuffer);
class RenderCommand : public Gfx::RenderCommand, public SecondaryCmdBuffer
{ {
public: public:
RenderCommand(PGraphics graphics, VkCommandPool cmdPool); RenderCommand(PGraphics graphics, VkCommandPool cmdPool);
virtual ~RenderCommand(); virtual ~RenderCommand();
virtual void begin(PCmdBuffer parent) override; inline VkCommandBuffer getHandle()
{
return handle;
}
void begin(PCmdBuffer parent);
void end();
void reset();
virtual bool isReady() override; virtual bool isReady() override;
virtual void setViewport(Gfx::PViewport viewport) override; virtual void setViewport(Gfx::PViewport viewport) override;
virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override; virtual void bindPipeline(Gfx::PGraphicsPipeline pipeline) override;
@@ -112,16 +91,29 @@ public:
virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override; virtual void draw(uint32 vertexCount, uint32 instanceCount, int32 firstVertex, uint32 firstInstance) override;
private: private:
PGraphicsPipeline pipeline; PGraphicsPipeline pipeline;
bool ready;
Array<DescriptorSet*> boundDescriptors;
VkViewport currentViewport;
VkRect2D currentScissor;
PGraphics graphics;
VkCommandBuffer handle;
VkCommandPool owner;
friend class CmdBuffer; friend class CmdBuffer;
}; };
DEFINE_REF(RenderCommand) DEFINE_REF(RenderCommand)
class ComputeCommand : public Gfx::ComputeCommand, public SecondaryCmdBuffer class ComputeCommand : public Gfx::ComputeCommand
{ {
public: public:
ComputeCommand(PGraphics graphics, VkCommandPool cmdPool); ComputeCommand(PGraphics graphics, VkCommandPool cmdPool);
virtual ~ComputeCommand(); virtual ~ComputeCommand();
virtual void begin(PCmdBuffer parent) override; inline VkCommandBuffer getHandle()
{
return handle;
}
void begin(PCmdBuffer parent);
void end();
void reset();
virtual bool isReady() override; virtual bool isReady() override;
virtual void bindPipeline(Gfx::PComputePipeline pipeline) override; virtual void bindPipeline(Gfx::PComputePipeline pipeline) override;
virtual void bindDescriptor(Gfx::PDescriptorSet set) override; virtual void bindDescriptor(Gfx::PDescriptorSet set) override;
@@ -129,6 +121,13 @@ public:
virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override; virtual void dispatch(uint32 threadX, uint32 threadY, uint32 threadZ) override;
private: private:
PComputePipeline pipeline; PComputePipeline pipeline;
bool ready;
Array<DescriptorSet*> boundDescriptors;
VkViewport currentViewport;
VkRect2D currentScissor;
PGraphics graphics;
VkCommandBuffer handle;
VkCommandPool owner;
friend class CmdBuffer; friend class CmdBuffer;
}; };
DEFINE_REF(ComputeCommand) DEFINE_REF(ComputeCommand)
@@ -55,7 +55,6 @@ private:
}; };
DEFINE_REF(PipelineLayout) DEFINE_REF(PipelineLayout)
DECLARE_REF(SecondaryCmdBuffer)
class DescriptorSet : public Gfx::DescriptorSet class DescriptorSet : public Gfx::DescriptorSet
{ {
public: public:
@@ -63,7 +62,6 @@ public:
: setHandle(VK_NULL_HANDLE) : setHandle(VK_NULL_HANDLE)
, graphics(graphics) , graphics(graphics)
, owner(owner) , owner(owner)
, boundBuffer(nullptr)
, currentlyBound(false) , currentlyBound(false)
, currentlyInUse(false) , currentlyInUse(false)
{ {
@@ -84,14 +82,12 @@ public:
{ {
return currentlyInUse; return currentlyInUse;
} }
void bind(PSecondaryCmdBuffer cmdBuffer) void bind()
{ {
boundBuffer = cmdBuffer;
currentlyBound = true; currentlyBound = true;
} }
void unbind() void unbind()
{ {
boundBuffer = nullptr;
currentlyBound = false; currentlyBound = false;
} }
void allocate() void allocate()
@@ -119,12 +115,10 @@ private:
VkDescriptorSet setHandle; VkDescriptorSet setHandle;
PGraphics graphics; PGraphics graphics;
PDescriptorAllocator owner; PDescriptorAllocator owner;
PSecondaryCmdBuffer boundBuffer;
bool currentlyBound; bool currentlyBound;
bool currentlyInUse; bool currentlyInUse;
friend class DescriptorAllocator; friend class DescriptorAllocator;
friend class CmdBuffer; friend class CmdBuffer;
friend class SecondaryCmdBuffer;
}; };
DEFINE_REF(DescriptorSet) DEFINE_REF(DescriptorSet)
@@ -309,7 +309,7 @@ PCommandBufferManager Graphics::getQueueCommands(Gfx::QueueType queueType)
std::mutex graphicsCommandLock; std::mutex graphicsCommandLock;
PCommandBufferManager Graphics::getGraphicsCommands() PCommandBufferManager Graphics::getGraphicsCommands()
{ {
std::scoped_lock lock(graphicsCommandLock); std::unique_lock lock(graphicsCommandLock);
auto id = std::this_thread::get_id(); auto id = std::this_thread::get_id();
if(graphicsCommands.find(id) == graphicsCommands.end()) if(graphicsCommands.find(id) == graphicsCommands.end())
{ {
@@ -320,7 +320,7 @@ PCommandBufferManager Graphics::getGraphicsCommands()
std::mutex computeCommandLock; std::mutex computeCommandLock;
PCommandBufferManager Graphics::getComputeCommands() PCommandBufferManager Graphics::getComputeCommands()
{ {
std::scoped_lock lock(computeCommandLock); std::unique_lock lock(computeCommandLock);
auto id = std::this_thread::get_id(); auto id = std::this_thread::get_id();
if(computeCommands.find(id) == computeCommands.end()) if(computeCommands.find(id) == computeCommands.end())
{ {
@@ -331,7 +331,7 @@ PCommandBufferManager Graphics::getComputeCommands()
std::mutex transferCommandLock; std::mutex transferCommandLock;
PCommandBufferManager Graphics::getTransferCommands() PCommandBufferManager Graphics::getTransferCommands()
{ {
std::scoped_lock lock(transferCommandLock); std::unique_lock lock(transferCommandLock);
auto id = std::this_thread::get_id(); auto id = std::this_thread::get_id();
if(transferCommands.find(id) == transferCommands.end()) if(transferCommands.find(id) == transferCommands.end())
{ {
@@ -342,7 +342,7 @@ PCommandBufferManager Graphics::getTransferCommands()
std::mutex dedicatedCommandLock; std::mutex dedicatedCommandLock;
PCommandBufferManager Graphics::getDedicatedTransferCommands() PCommandBufferManager Graphics::getDedicatedTransferCommands()
{ {
std::scoped_lock lock(dedicatedCommandLock); std::unique_lock lock(dedicatedCommandLock);
auto id = std::this_thread::get_id(); auto id = std::this_thread::get_id();
if(dedicatedTransferCommands.find(id) == dedicatedTransferCommands.end()) if(dedicatedTransferCommands.find(id) == dedicatedTransferCommands.end())
{ {
+1 -1
View File
@@ -22,7 +22,7 @@ Queue::~Queue()
void Queue::submitCommandBuffer(PCmdBuffer cmdBuffer, uint32 numSignalSemaphores, VkSemaphore *signalSemaphores) void Queue::submitCommandBuffer(PCmdBuffer cmdBuffer, uint32 numSignalSemaphores, VkSemaphore *signalSemaphores)
{ {
std::scoped_lock lck(queueLock); std::unique_lock lck(queueLock);
assert(cmdBuffer->state == CmdBuffer::State::Ended); assert(cmdBuffer->state == CmdBuffer::State::Ended);
PFence fence = cmdBuffer->fence; PFence fence = cmdBuffer->fence;
+3 -3
View File
@@ -50,12 +50,12 @@ public:
~RefObject() ~RefObject()
{ {
{ {
std::scoped_lock lock(registeredObjectsLock); std::unique_lock lock(registeredObjectsLock);
registeredObjects.erase(handle); registeredObjects.erase(handle);
} }
// #pragma warning( disable: 4150) #pragma warning( disable: 4150)
delete handle; delete handle;
// #pragma warning( default: 4150) #pragma warning( default: 4150)
} }
RefObject &operator=(const RefObject &rhs) RefObject &operator=(const RefObject &rhs)
{ {
+13 -2
View File
@@ -16,7 +16,7 @@ Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const Viewpo
{ {
scene = new Scene(graphics); scene = new Scene(graphics);
scene->addActor(activeCamera); scene->addActor(activeCamera);
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png"); /*AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Diffuse.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png"); AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Body_Lightmap.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png"); AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Face_Diffuse.png");
AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png"); AssetRegistry::importFile("/home/dynamitos/Assets/Ayaka/Avatar_Girl_Sword_Ayaka_Tex_Hair_Diffuse.png");
@@ -26,7 +26,18 @@ Seele::SceneView::SceneView(Gfx::PGraphics graphics, PWindow owner, const Viewpo
PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka")); PPrimitiveComponent ayaka = new PrimitiveComponent(AssetRegistry::findMesh("Ayaka"));
ayaka->addWorldTranslation(Vector(0, 0, 100)); ayaka->addWorldTranslation(Vector(0, 0, 100));
ayaka->setWorldScale(Vector(0.1f, 0.1f, 0.1f)); ayaka->setWorldScale(Vector(0.1f, 0.1f, 0.1f));
scene->addPrimitiveComponent(ayaka); scene->addPrimitiveComponent(ayaka);*/
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Ely\\Ely.fbx");
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Cube\\cube.obj");
AssetRegistry::importFile("D:\\Private\\Programming\\Unreal Engine\\Assets\\Plane\\plane.fbx");
PPrimitiveComponent plane = new PrimitiveComponent(AssetRegistry::findMesh("plane"));
plane->setWorldScale(Vector(100, 100, 100));
PPrimitiveComponent arissa = new PrimitiveComponent(AssetRegistry::findMesh("Ely"));
arissa->addWorldTranslation(Vector(0, 0, 100));
arissa->setWorldScale(Vector(0.1f, 0.1f, 0.1f));
scene->addPrimitiveComponent(plane);
scene->addPrimitiveComponent(arissa);
PRenderGraphResources resources = new RenderGraphResources(); PRenderGraphResources resources = new RenderGraphResources();
depthPrepass.setResources(resources); depthPrepass.setResources(resources);
+1 -1
View File
@@ -9,7 +9,7 @@ using namespace Seele;
int main() int main()
{ {
PWindowManager windowManager = new WindowManager(); PWindowManager windowManager = new WindowManager();
AssetRegistry::init("/home/dynamitos/TestSeeleProject"); AssetRegistry::init("D:\\Private\\Programming\\C++\\TestSeeleProject\\");
WindowCreateInfo mainWindowInfo; WindowCreateInfo mainWindowInfo;
mainWindowInfo.title = "SeeleEngine"; mainWindowInfo.title = "SeeleEngine";
mainWindowInfo.width = 1280; mainWindowInfo.width = 1280;