Cleanup shader handling
This commit is contained in:
@@ -15,8 +15,6 @@ namespace openVulkanoCpp
|
||||
{
|
||||
namespace Scene
|
||||
{
|
||||
class Shader;
|
||||
|
||||
class Scene : virtual public IInitable, virtual public ICloseable
|
||||
{
|
||||
public:
|
||||
|
||||
@@ -154,6 +154,7 @@ namespace openVulkanoCpp::Vulkan
|
||||
while((drawablePointer = jobQueue->Pop()) != nullptr)
|
||||
{
|
||||
Scene::Drawable* drawable = *drawablePointer;
|
||||
drawContext.EncodeShader(drawable->GetShader());
|
||||
drawable->GetEncoder().vulkan(drawable, &drawContext);
|
||||
}
|
||||
cmdHelper->cmdBuffer.end();
|
||||
|
||||
@@ -61,10 +61,7 @@ namespace openVulkanoCpp::Vulkan
|
||||
device.freeCommandBuffers(cmdPools[i], 1, &cmdBuffers[i]);
|
||||
device.destroyCommandPool(cmdPools[i]);
|
||||
}
|
||||
for (auto shader : shaders)
|
||||
{
|
||||
shader->Close();
|
||||
}
|
||||
shaders.clear();
|
||||
cmdBuffers = nullptr;
|
||||
cmdPools = nullptr;
|
||||
device = nullptr;
|
||||
@@ -88,7 +85,7 @@ namespace openVulkanoCpp::Vulkan
|
||||
|
||||
void ResourceManager::Resize()
|
||||
{
|
||||
for (auto shader : shaders)
|
||||
for (auto& shader : shaders)
|
||||
{
|
||||
shader->Resize();
|
||||
}
|
||||
@@ -173,7 +170,12 @@ namespace openVulkanoCpp::Vulkan
|
||||
|
||||
void ResourceManager::RemoveShader(VulkanShader* shader)
|
||||
{
|
||||
Utils::Remove(shaders, shader);
|
||||
const std::unique_lock lock(mutex);
|
||||
std::vector<std::unique_ptr<VulkanShader>>::iterator object =
|
||||
find_if(shaders.begin(), shaders.end(),
|
||||
[&](auto& obj){ return obj.get() == shader; }
|
||||
);
|
||||
shaders.erase(object);
|
||||
}
|
||||
|
||||
void ResourceManager::FreeBuffer(ManagedBuffer* buffer)
|
||||
@@ -267,9 +269,10 @@ namespace openVulkanoCpp::Vulkan
|
||||
|
||||
VulkanShader* ResourceManager::CreateShader(Scene::Shader* shader)
|
||||
{
|
||||
const std::unique_lock lock(mutex);
|
||||
VulkanShader* vkShader = new VulkanShader();
|
||||
vkShader->Init(context, shader, this);
|
||||
shaders.push_back(vkShader);
|
||||
shaders.emplace_back(vkShader);
|
||||
return vkShader;
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace openVulkanoCpp
|
||||
vk::CommandBuffer* cmdBuffers = nullptr;
|
||||
vk::Semaphore* semaphores = nullptr;
|
||||
std::vector<MemoryAllocation*> allocations;
|
||||
std::vector<VulkanShader*> shaders;
|
||||
std::vector<std::unique_ptr<VulkanShader>> shaders;
|
||||
MemoryAllocation* lastAllocation = nullptr;
|
||||
std::mutex mutex;
|
||||
vk::DeviceSize uniformBufferAlignment;
|
||||
|
||||
@@ -15,15 +15,14 @@ namespace openVulkanoCpp::Vulkan
|
||||
{
|
||||
void EncodeSimpleDrawable(Drawable* instance, Vulkan::VulkanDrawContext* drawContext)
|
||||
{
|
||||
drawContext->EncodeShader(instance->GetShader());
|
||||
Geometry* mesh = dynamic_cast<SimpleDrawable*>(instance)->GetMesh();
|
||||
VulkanGeometry* renderGeo = dynamic_cast<VulkanGeometry*>(mesh->renderGeo);
|
||||
Geometry* mesh = static_cast<SimpleDrawable*>(instance)->GetMesh();
|
||||
VulkanGeometry* renderGeo = static_cast<VulkanGeometry*>(mesh->renderGeo);
|
||||
if (!mesh->renderGeo) renderGeo = drawContext->renderer->GetResourceManager().PrepareGeometry(mesh);
|
||||
renderGeo->RecordBind(drawContext->commandBuffer);
|
||||
for(Node* node : instance->GetNodes())
|
||||
{
|
||||
if (!node->renderNode) drawContext->renderer->GetResourceManager().PrepareNode(node);
|
||||
dynamic_cast<VulkanNode*>(node->renderNode)->Record(drawContext->commandBuffer, drawContext->currentImageId);
|
||||
static_cast<VulkanNode*>(node->renderNode)->Record(drawContext->commandBuffer, drawContext->currentImageId);
|
||||
renderGeo->RecordDraw(drawContext->commandBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
|
||||
namespace openVulkanoCpp::Vulkan
|
||||
{
|
||||
class VulkanGeometry final : virtual public ICloseable
|
||||
class VulkanGeometry final : public ICloseable
|
||||
{
|
||||
Scene::Geometry* m_geometry;
|
||||
ManagedBuffer::Ptr m_vertexBuffer;
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace openVulkanoCpp
|
||||
{
|
||||
namespace Vulkan
|
||||
{
|
||||
struct VulkanNode : virtual IRecordable, virtual ICloseable
|
||||
struct VulkanNode : IRecordable, ICloseable
|
||||
{
|
||||
Scene::Node* node = nullptr;
|
||||
UniformBuffer* buffer = nullptr;
|
||||
|
||||
@@ -11,6 +11,16 @@
|
||||
|
||||
namespace openVulkanoCpp::Vulkan
|
||||
{
|
||||
VulkanShader::~VulkanShader()
|
||||
{
|
||||
if (!shader) return;
|
||||
device.destroyPipeline(pipeline);
|
||||
for(auto& shaderModule : shaderModules)
|
||||
{
|
||||
device.destroyShaderModule(shaderModule);
|
||||
}
|
||||
}
|
||||
|
||||
void VulkanShader::Init(Context* context, Scene::Shader* shader, IShaderOwner* owner)
|
||||
{
|
||||
this->device = context->device->device;
|
||||
@@ -108,11 +118,5 @@ namespace openVulkanoCpp::Vulkan
|
||||
void VulkanShader::Close()
|
||||
{
|
||||
owner->RemoveShader(this);
|
||||
shader = nullptr;
|
||||
device.destroyPipeline(pipeline);
|
||||
for(auto& shaderModule : shaderModules)
|
||||
{
|
||||
device.destroyShaderModule(shaderModule);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,8 +35,7 @@ namespace openVulkanoCpp
|
||||
|
||||
VulkanShader() = default;
|
||||
|
||||
~VulkanShader() override
|
||||
{ if (shader) VulkanShader::Close(); }
|
||||
~VulkanShader() override;
|
||||
|
||||
void Init(Context* context, Scene::Shader* shader, IShaderOwner* owner);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user