mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
fixing put pixel, adding scene change checker
This commit is contained in:
@@ -24,6 +24,7 @@ namespace mlx
|
||||
|
||||
void DescriptorPool::Init() noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
VkDescriptorPoolSize pool_sizes[] = {
|
||||
{ VK_DESCRIPTOR_TYPE_SAMPLER, MAX_SETS_PER_POOL },
|
||||
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, MAX_SETS_PER_POOL },
|
||||
@@ -38,99 +39,143 @@ namespace mlx
|
||||
{ VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT, MAX_SETS_PER_POOL }
|
||||
};
|
||||
|
||||
VkDescriptorPoolCreateInfo poolInfo{};
|
||||
poolInfo.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||
poolInfo.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]);
|
||||
poolInfo.pPoolSizes = pool_sizes;
|
||||
poolInfo.maxSets = MAX_SETS_PER_POOL;
|
||||
poolInfo.flags = VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT;
|
||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
kvfCheckVk(RenderCore::Get().vkCreateDescriptorPool(RenderCore::Get().GetDevice(), &poolInfo, nullptr, &m_pools[i]));
|
||||
VkDescriptorPoolCreateInfo pool_info{};
|
||||
pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||
pool_info.poolSizeCount = sizeof(pool_sizes) / sizeof(pool_sizes[0]);
|
||||
pool_info.pPoolSizes = pool_sizes;
|
||||
pool_info.maxSets = MAX_SETS_PER_POOL;
|
||||
pool_info.flags = 0;
|
||||
kvfCheckVk(RenderCore::Get().vkCreateDescriptorPool(RenderCore::Get().GetDevice(), &pool_info, nullptr, &m_pool));
|
||||
m_allocation_count = 0;
|
||||
}
|
||||
|
||||
void DescriptorPool::Destroy() noexcept
|
||||
{
|
||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
{
|
||||
if(m_pools[i] == VK_NULL_HANDLE)
|
||||
continue;
|
||||
RenderCore::Get().vkDestroyDescriptorPool(RenderCore::Get().GetDevice(), m_pools[i], nullptr);
|
||||
m_pools[i] = VK_NULL_HANDLE;
|
||||
}
|
||||
MLX_PROFILE_FUNCTION();
|
||||
if(m_pool == VK_NULL_HANDLE)
|
||||
return;
|
||||
for(auto& set : m_free_sets)
|
||||
kvfDestroyDescriptorSetLayout(RenderCore::Get().GetDevice(), set->m_set_layout);
|
||||
for(auto& set : m_used_sets)
|
||||
kvfDestroyDescriptorSetLayout(RenderCore::Get().GetDevice(), set->m_set_layout);
|
||||
RenderCore::Get().vkDestroyDescriptorPool(RenderCore::Get().GetDevice(), m_pool, nullptr);
|
||||
m_pool = VK_NULL_HANDLE;
|
||||
m_allocation_count = 0;
|
||||
m_free_sets.clear();
|
||||
m_used_sets.clear();
|
||||
}
|
||||
|
||||
VkDescriptorSet DescriptorPool::AllocateDescriptorSet(std::uint32_t frame_index, VkDescriptorSetLayout layout)
|
||||
std::shared_ptr<DescriptorSet> DescriptorPool::RequestDescriptorSet(const ShaderSetLayout& layout, ShaderType shader_type)
|
||||
{
|
||||
VkDescriptorSet set;
|
||||
VkDescriptorSetAllocateInfo alloc_info = {};
|
||||
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||
alloc_info.descriptorPool = m_pools[frame_index];
|
||||
alloc_info.descriptorSetCount = 1;
|
||||
alloc_info.pSetLayouts = &layout;
|
||||
kvfCheckVk(RenderCore::Get().vkAllocateDescriptorSets(RenderCore::Get().GetDevice(), &alloc_info, &set));
|
||||
m_allocation_count++;
|
||||
MLX_PROFILE_FUNCTION();
|
||||
auto it = std::find_if(m_free_sets.begin(), m_free_sets.end(), [&](std::shared_ptr<DescriptorSet> set)
|
||||
{
|
||||
return shader_type == set->GetShaderType() && layout == set->GetShaderLayout();
|
||||
});
|
||||
if(it != m_free_sets.end())
|
||||
{
|
||||
std::shared_ptr<DescriptorSet> set = *it;
|
||||
m_free_sets.erase(it);
|
||||
m_used_sets.push_back(set);
|
||||
return set;
|
||||
}
|
||||
|
||||
std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> vulkan_sets;
|
||||
|
||||
VkShaderStageFlagBits vulkan_shader_stage;
|
||||
switch(shader_type)
|
||||
{
|
||||
case ShaderType::Vertex: vulkan_shader_stage = VK_SHADER_STAGE_VERTEX_BIT; break;
|
||||
case ShaderType::Fragment: vulkan_shader_stage = VK_SHADER_STAGE_FRAGMENT_BIT; break;
|
||||
|
||||
default : FatalError("wtf"); break;
|
||||
}
|
||||
|
||||
std::vector<VkDescriptorSetLayoutBinding> bindings(layout.binds.size());
|
||||
for(std::size_t i = 0; i < layout.binds.size(); i++)
|
||||
{
|
||||
bindings[i].binding = layout.binds[i].first;
|
||||
bindings[i].descriptorCount = 1;
|
||||
bindings[i].descriptorType = layout.binds[i].second;
|
||||
bindings[i].pImmutableSamplers = nullptr;
|
||||
bindings[i].stageFlags = vulkan_shader_stage;
|
||||
}
|
||||
VkDescriptorSetLayout vulkan_layout = kvfCreateDescriptorSetLayout(RenderCore::Get().GetDevice(), bindings.data(), bindings.size());
|
||||
|
||||
for(int i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
{
|
||||
VkDescriptorSetAllocateInfo alloc_info = {};
|
||||
alloc_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO;
|
||||
alloc_info.descriptorPool = m_pool;
|
||||
alloc_info.descriptorSetCount = 1;
|
||||
alloc_info.pSetLayouts = &vulkan_layout;
|
||||
VkDescriptorSet vulkan_set;
|
||||
kvfCheckVk(RenderCore::Get().vkAllocateDescriptorSets(RenderCore::Get().GetDevice(), &alloc_info, &vulkan_set));
|
||||
m_allocation_count++;
|
||||
vulkan_sets[i] = vulkan_set;
|
||||
}
|
||||
|
||||
std::shared_ptr<DescriptorSet> set(new DescriptorSet(*this, vulkan_layout, layout, std::move(vulkan_sets), shader_type));
|
||||
m_used_sets.push_back(set);
|
||||
return set;
|
||||
}
|
||||
|
||||
void DescriptorPool::ResetPoolFromFrameIndex(std::size_t frame_index)
|
||||
void DescriptorPool::ReturnDescriptorSet(std::shared_ptr<class DescriptorSet> set)
|
||||
{
|
||||
Assert(frame_index < MAX_FRAMES_IN_FLIGHT, "invalid frame index");
|
||||
RenderCore::Get().vkResetDescriptorPool(RenderCore::Get().GetDevice(), m_pools[frame_index], 0);
|
||||
}
|
||||
|
||||
void DescriptorPoolManager::ResetPoolsFromFrameIndex(std::size_t frame_index)
|
||||
{
|
||||
for(auto& pool : m_pools)
|
||||
pool.ResetPoolFromFrameIndex(frame_index);
|
||||
auto it = std::find_if(m_used_sets.begin(), m_used_sets.end(), [&](std::shared_ptr<DescriptorSet> rhs_set)
|
||||
{
|
||||
return set == rhs_set;
|
||||
});
|
||||
if(it == m_used_sets.end())
|
||||
{
|
||||
Error("Vulkan : cannot return descriptor set to pool, invalid pool");
|
||||
return;
|
||||
}
|
||||
m_used_sets.erase(it);
|
||||
m_free_sets.push_back(set);
|
||||
}
|
||||
|
||||
DescriptorPool& DescriptorPoolManager::GetAvailablePool()
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
for(auto& pool : m_pools)
|
||||
{
|
||||
if(pool.GetNumberOfSetsAllocated() < MAX_SETS_PER_POOL)
|
||||
return pool;
|
||||
}
|
||||
m_pools.emplace_front().Init();
|
||||
return m_pools.front();
|
||||
m_pools.emplace_back().Init();
|
||||
return m_pools.back();
|
||||
}
|
||||
|
||||
void DescriptorPoolManager::Destroy()
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
#pragma omp parallel for
|
||||
for(auto& pool : m_pools)
|
||||
pool.Destroy();
|
||||
m_pools.clear();
|
||||
}
|
||||
|
||||
DescriptorSet::DescriptorSet(DescriptorPoolManager& pools_manager, const ShaderSetLayout& layout, VkDescriptorSetLayout vklayout, ShaderType shader_type)
|
||||
: m_set_layout(vklayout), p_pools_manager(&pools_manager)
|
||||
DescriptorSet::DescriptorSet(DescriptorPool& pool, VkDescriptorSetLayout vulkan_layout, const ShaderSetLayout& layout, std::array<VkDescriptorSet, MAX_FRAMES_IN_FLIGHT> vulkan_sets, ShaderType shader_type) :
|
||||
m_shader_layout(layout),
|
||||
m_sets(std::move(vulkan_sets)),
|
||||
m_set_layout(vulkan_layout),
|
||||
m_shader_type(shader_type),
|
||||
m_pool(pool)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
for(auto& [binding, type] : layout.binds)
|
||||
{
|
||||
m_descriptors.emplace_back();
|
||||
m_descriptors.back().type = type;
|
||||
m_descriptors.back().shader_type = shader_type;
|
||||
m_descriptors.back().binding = binding;
|
||||
}
|
||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
m_set[i] = p_pools_manager->GetAvailablePool().AllocateDescriptorSet(i, vklayout);
|
||||
}
|
||||
|
||||
DescriptorSet::DescriptorSet(DescriptorPoolManager& pools_manager, VkDescriptorSetLayout layout, const std::vector<Descriptor>& descriptors)
|
||||
: m_descriptors(descriptors), m_set_layout(layout), p_pools_manager(&pools_manager)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
m_set[i] = p_pools_manager->GetAvailablePool().AllocateDescriptorSet(i, layout);
|
||||
}
|
||||
|
||||
void DescriptorSet::SetImage(std::size_t i, std::uint32_t binding, class Image& image)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
Verify(m_set[i] != VK_NULL_HANDLE, "invalid descriptor");
|
||||
Verify(m_sets[i] != VK_NULL_HANDLE, "invalid descriptor");
|
||||
auto it = std::find_if(m_descriptors.begin(), m_descriptors.end(), [=](Descriptor descriptor)
|
||||
{
|
||||
return binding == descriptor.binding;
|
||||
@@ -151,7 +196,7 @@ namespace mlx
|
||||
void DescriptorSet::SetStorageBuffer(std::size_t i, std::uint32_t binding, class GPUBuffer& buffer)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
Verify(m_set[i] != VK_NULL_HANDLE, "invalid descriptor");
|
||||
Verify(m_sets[i] != VK_NULL_HANDLE, "invalid descriptor");
|
||||
auto it = std::find_if(m_descriptors.begin(), m_descriptors.end(), [=](Descriptor descriptor)
|
||||
{
|
||||
return binding == descriptor.binding;
|
||||
@@ -172,7 +217,7 @@ namespace mlx
|
||||
void DescriptorSet::SetUniformBuffer(std::size_t i, std::uint32_t binding, class GPUBuffer& buffer)
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
Verify(m_set[i] != VK_NULL_HANDLE, "invalid descriptor");
|
||||
Verify(m_sets[i] != VK_NULL_HANDLE, "invalid descriptor");
|
||||
auto it = std::find_if(m_descriptors.begin(), m_descriptors.end(), [=](Descriptor descriptor)
|
||||
{
|
||||
return binding == descriptor.binding;
|
||||
@@ -193,7 +238,7 @@ namespace mlx
|
||||
void DescriptorSet::Update(std::size_t i, VkCommandBuffer cmd) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
Verify(m_set[i] != VK_NULL_HANDLE, "invalid descriptor");
|
||||
Verify(m_sets[i] != VK_NULL_HANDLE, "invalid descriptor");
|
||||
std::vector<VkWriteDescriptorSet> writes;
|
||||
std::vector<VkDescriptorBufferInfo> buffer_infos;
|
||||
std::vector<VkDescriptorImageInfo> image_infos;
|
||||
@@ -207,7 +252,7 @@ namespace mlx
|
||||
info.imageLayout = descriptor.image_ptr->GetLayout();
|
||||
info.imageView = descriptor.image_ptr->GetImageView();
|
||||
image_infos.push_back(info);
|
||||
writes.push_back(kvfWriteImageToDescriptorSet(RenderCore::Get().GetDevice(), m_set[i], &image_infos.back(), descriptor.binding));
|
||||
writes.push_back(kvfWriteImageToDescriptorSet(RenderCore::Get().GetDevice(), m_sets[i], &image_infos.back(), descriptor.binding));
|
||||
}
|
||||
else if(descriptor.uniform_buffer_ptr)
|
||||
{
|
||||
@@ -216,7 +261,7 @@ namespace mlx
|
||||
info.offset = descriptor.uniform_buffer_ptr->GetOffset();
|
||||
info.range = VK_WHOLE_SIZE;
|
||||
buffer_infos.push_back(info);
|
||||
writes.push_back(kvfWriteUniformBufferToDescriptorSet(RenderCore::Get().GetDevice(), m_set[i], &buffer_infos.back(), descriptor.binding));
|
||||
writes.push_back(kvfWriteUniformBufferToDescriptorSet(RenderCore::Get().GetDevice(), m_sets[i], &buffer_infos.back(), descriptor.binding));
|
||||
}
|
||||
else if(descriptor.storage_buffer_ptr)
|
||||
{
|
||||
@@ -225,16 +270,14 @@ namespace mlx
|
||||
info.offset = descriptor.storage_buffer_ptr->GetOffset();
|
||||
info.range = VK_WHOLE_SIZE;
|
||||
buffer_infos.push_back(info);
|
||||
writes.push_back(kvfWriteStorageBufferToDescriptorSet(RenderCore::Get().GetDevice(), m_set[i], &buffer_infos.back(), descriptor.binding));
|
||||
writes.push_back(kvfWriteStorageBufferToDescriptorSet(RenderCore::Get().GetDevice(), m_sets[i], &buffer_infos.back(), descriptor.binding));
|
||||
}
|
||||
}
|
||||
RenderCore::Get().vkUpdateDescriptorSets(RenderCore::Get().GetDevice(), writes.size(), writes.data(), 0, nullptr);
|
||||
}
|
||||
|
||||
void DescriptorSet::Reallocate(std::size_t frame_index) noexcept
|
||||
void DescriptorSet::ReturnDescriptorSetToPool()
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
Assert(!p_pools_manager, "invalid pools manager");
|
||||
m_set[frame_index] = p_pools_manager->GetAvailablePool().AllocateDescriptorSet(frame_index, m_set_layout);
|
||||
m_pool.ReturnDescriptorSet(shared_from_this());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include <Renderer/Image.h>
|
||||
#include <Maths/Vec4.h>
|
||||
#include <Renderer/RenderCore.h>
|
||||
#include <Utils/CallOnExit.h>
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#ifdef MLX_COMPILER_GCC
|
||||
@@ -80,14 +81,7 @@ namespace mlx
|
||||
bool is_single_time_cmd_buffer = (cmd == VK_NULL_HANDLE);
|
||||
if(is_single_time_cmd_buffer)
|
||||
cmd = kvfCreateCommandBuffer(RenderCore::Get().GetDevice());
|
||||
KvfImageType kvf_type = KVF_IMAGE_OTHER;
|
||||
switch(m_type)
|
||||
{
|
||||
case ImageType::Color: kvf_type = KVF_IMAGE_COLOR; break;
|
||||
case ImageType::Depth: kvf_type = KVF_IMAGE_DEPTH; break;
|
||||
default: break;
|
||||
}
|
||||
kvfTransitionImageLayout(RenderCore::Get().GetDevice(), m_image, kvf_type, cmd, m_format, m_layout, new_layout, is_single_time_cmd_buffer);
|
||||
kvfTransitionImageLayout(RenderCore::Get().GetDevice(), m_image, KVF_IMAGE_COLOR, cmd, m_format, m_layout, new_layout, is_single_time_cmd_buffer);
|
||||
m_layout = new_layout;
|
||||
}
|
||||
|
||||
@@ -109,18 +103,9 @@ namespace mlx
|
||||
|
||||
VkImageLayout old_layout = m_layout;
|
||||
TransitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, cmd);
|
||||
if(m_type == ImageType::Color)
|
||||
{
|
||||
subresource_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
VkClearColorValue clear_color = VkClearColorValue({ { color.x, color.y, color.z, color.w } });
|
||||
RenderCore::Get().vkCmdClearColorImage(cmd, m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_color, 1, &subresource_range);
|
||||
}
|
||||
else if(m_type == ImageType::Depth)
|
||||
{
|
||||
VkClearDepthStencilValue clear_depth_stencil = { 1.0f, 1 };
|
||||
subresource_range.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
|
||||
RenderCore::Get().vkCmdClearDepthStencilImage(cmd, m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_depth_stencil, 1, &subresource_range);
|
||||
}
|
||||
subresource_range.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||
VkClearColorValue clear_color = VkClearColorValue({ { color.x, color.y, color.z, color.w } });
|
||||
RenderCore::Get().vkCmdClearColorImage(cmd, m_image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &clear_color, 1, &subresource_range);
|
||||
TransitionLayout(old_layout, cmd);
|
||||
|
||||
if(is_single_time_cmd_buffer)
|
||||
@@ -189,6 +174,13 @@ namespace mlx
|
||||
TransitionLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
|
||||
}
|
||||
|
||||
void Texture::Destroy() noexcept
|
||||
{
|
||||
if(m_staging_buffer.has_value())
|
||||
m_staging_buffer->Destroy();
|
||||
Image::Destroy();
|
||||
}
|
||||
|
||||
void Texture::SetPixel(int x, int y, std::uint32_t color) noexcept
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
@@ -266,6 +258,9 @@ namespace mlx
|
||||
MLX_PROFILE_FUNCTION();
|
||||
std::string filename = file.string();
|
||||
|
||||
if(file.stem() == "banana")
|
||||
Message("banana, banana, banana, banana, terracotta banana terracotta, terracotta pie");
|
||||
|
||||
if(!std::filesystem::exists(file))
|
||||
{
|
||||
Error("Image : file not found %", file);
|
||||
@@ -280,14 +275,15 @@ namespace mlx
|
||||
int dummy_h;
|
||||
int channels;
|
||||
std::uint8_t* data = stbi_load(filename.c_str(), (w == nullptr ? &dummy_w : w), (h == nullptr ? &dummy_h : h), &channels, 4);
|
||||
|
||||
CallOnExit defer([=]() { stbi_image_free(data); });
|
||||
|
||||
CPUBuffer buffer((w == nullptr ? dummy_w : *w) * (h == nullptr ? dummy_h : *h) * 4);
|
||||
std::memcpy(buffer.GetData(), data, buffer.GetSize());
|
||||
Texture* texture;
|
||||
|
||||
try { texture = new Texture(buffer, (w == nullptr ? dummy_w : *w), (h == nullptr ? dummy_h : *h), VK_FORMAT_R8G8B8A8_SRGB, false, std::move(filename)); }
|
||||
catch(...) { return NULL; }
|
||||
|
||||
stbi_image_free(data);
|
||||
Texture* texture;
|
||||
try { texture = new Texture(std::move(buffer), (w == nullptr ? dummy_w : *w), (h == nullptr ? dummy_h : *h), VK_FORMAT_R8G8B8A8_SRGB, false, std::move(filename)); }
|
||||
catch(...) { return nullptr; }
|
||||
return texture;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ namespace mlx
|
||||
{
|
||||
case ShaderType::Vertex : m_stage = VK_SHADER_STAGE_VERTEX_BIT; break;
|
||||
case ShaderType::Fragment : m_stage = VK_SHADER_STAGE_FRAGMENT_BIT; break;
|
||||
case ShaderType::Compute : m_stage = VK_SHADER_STAGE_COMPUTE_BIT; break;
|
||||
|
||||
default : FatalError("wtf"); break;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ namespace mlx
|
||||
|
||||
RenderCore::RenderCore()
|
||||
{
|
||||
if(s_instance != nullptr)
|
||||
return;
|
||||
s_instance = this;
|
||||
|
||||
loader = std::make_unique<VulkanLoader>();
|
||||
@@ -193,7 +195,10 @@ namespace mlx
|
||||
|
||||
RenderCore::~RenderCore()
|
||||
{
|
||||
if(s_instance == nullptr)
|
||||
return;
|
||||
WaitDeviceIdle();
|
||||
m_descriptor_pool_manager.Destroy();
|
||||
m_allocator.Destroy();
|
||||
kvfDestroyDevice(m_device);
|
||||
DebugLog("Vulkan : logical device destroyed");
|
||||
|
||||
@@ -45,23 +45,15 @@ namespace mlx
|
||||
};
|
||||
p_fragment_shader = std::make_shared<Shader>(fragment_shader_code, ShaderType::Fragment, std::move(fragment_shader_layout));
|
||||
|
||||
func::function<void(const EventBase&)> functor = [this, &renderer](const EventBase& event)
|
||||
func::function<void(const EventBase&)> functor = [this](const EventBase& event)
|
||||
{
|
||||
if(event.What() == Event::ResizeEventCode)
|
||||
m_pipeline.Destroy();
|
||||
if(event.What() == Event::DescriptorPoolResetEventCode)
|
||||
{
|
||||
std::uint32_t frame_index = renderer.GetCurrentFrameIndex();
|
||||
p_texture_set->Reallocate(frame_index);
|
||||
p_viewer_data_set->Reallocate(frame_index);
|
||||
p_viewer_data_set->SetUniformBuffer(frame_index, 0, p_viewer_data_buffer->Get(frame_index));
|
||||
p_viewer_data_set->Update(frame_index);
|
||||
}
|
||||
};
|
||||
EventBus::RegisterListener({ functor, "__MlxRender2DPass" });
|
||||
|
||||
p_viewer_data_set = std::make_shared<DescriptorSet>(renderer.GetDescriptorPoolManager(), p_vertex_shader->GetShaderLayout().set_layouts[0].second, p_vertex_shader->GetPipelineLayout().set_layouts[0], ShaderType::Vertex);
|
||||
p_texture_set = std::make_shared<DescriptorSet>(renderer.GetDescriptorPoolManager(), p_fragment_shader->GetShaderLayout().set_layouts[0].second, p_fragment_shader->GetPipelineLayout().set_layouts[0], ShaderType::Fragment);
|
||||
p_viewer_data_set = RenderCore::Get().GetDescriptorPoolManager().GetAvailablePool().RequestDescriptorSet(p_vertex_shader->GetShaderLayout().set_layouts[0].second, ShaderType::Vertex);
|
||||
p_texture_set = RenderCore::Get().GetDescriptorPoolManager().GetAvailablePool().RequestDescriptorSet(p_fragment_shader->GetShaderLayout().set_layouts[0].second, ShaderType::Fragment);
|
||||
|
||||
p_viewer_data_buffer = std::make_shared<UniformBuffer>();
|
||||
p_viewer_data_buffer->Init(sizeof(ViewerData), "mlx_2d_pass_viewer_data");
|
||||
@@ -106,7 +98,7 @@ namespace mlx
|
||||
{
|
||||
// Check every textures and update modified ones to GPU before starting the render pass
|
||||
if(!sprite->IsSetInit())
|
||||
sprite->UpdateDescriptorSet(*p_texture_set);
|
||||
sprite->UpdateDescriptorSet(p_texture_set);
|
||||
Verify((bool)sprite->GetTexture(), "a sprite has no texture attached (internal mlx issue, please report to the devs)");
|
||||
sprite->GetTexture()->Update(cmd);
|
||||
}
|
||||
@@ -136,8 +128,10 @@ namespace mlx
|
||||
m_pipeline.Destroy();
|
||||
p_vertex_shader.reset();
|
||||
p_fragment_shader.reset();
|
||||
p_viewer_data_set->ReturnDescriptorSetToPool();
|
||||
p_viewer_data_set.reset();
|
||||
p_viewer_data_buffer->Destroy();
|
||||
p_texture_set->ReturnDescriptorSetToPool();
|
||||
p_texture_set.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,16 +31,14 @@ namespace mlx
|
||||
};
|
||||
p_fragment_shader = std::make_shared<Shader>(fragment_shader_code, ShaderType::Fragment, std::move(fragment_shader_layout));
|
||||
|
||||
func::function<void(const EventBase&)> functor = [this, &renderer](const EventBase& event)
|
||||
func::function<void(const EventBase&)> functor = [this](const EventBase& event)
|
||||
{
|
||||
if(event.What() == Event::ResizeEventCode)
|
||||
m_pipeline.Destroy();
|
||||
if(event.What() == Event::DescriptorPoolResetEventCode)
|
||||
p_set->Reallocate(renderer.GetCurrentFrameIndex());
|
||||
};
|
||||
EventBus::RegisterListener({ functor, "__MlxFinalPass" });
|
||||
|
||||
p_set = std::make_shared<DescriptorSet>(renderer.GetDescriptorPoolManager(), p_fragment_shader->GetShaderLayout().set_layouts[0].second, p_fragment_shader->GetPipelineLayout().set_layouts[0], ShaderType::Fragment);
|
||||
p_set = RenderCore::Get().GetDescriptorPoolManager().GetAvailablePool().RequestDescriptorSet(p_fragment_shader->GetShaderLayout().set_layouts[0].second, ShaderType::Fragment);
|
||||
}
|
||||
|
||||
void FinalPass::Pass([[maybe_unused]] Scene& scene, Renderer& renderer, Texture& render_target)
|
||||
@@ -80,6 +78,7 @@ namespace mlx
|
||||
m_pipeline.Destroy();
|
||||
p_vertex_shader.reset();
|
||||
p_fragment_shader.reset();
|
||||
p_set->ReturnDescriptorSetToPool();
|
||||
p_set.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,11 +18,6 @@ namespace mlx
|
||||
{
|
||||
Event What() const override { return Event::FrameBeginEventCode; }
|
||||
};
|
||||
|
||||
struct DescriptorPoolResetEventBroadcast : public EventBase
|
||||
{
|
||||
Event What() const override { return Event::DescriptorPoolResetEventCode; }
|
||||
};
|
||||
}
|
||||
|
||||
void Renderer::Init(NonOwningPtr<Window> window)
|
||||
@@ -59,13 +54,6 @@ namespace mlx
|
||||
{
|
||||
MLX_PROFILE_FUNCTION();
|
||||
kvfWaitForFence(RenderCore::Get().GetDevice(), m_cmd_fences[m_current_frame_index]);
|
||||
static bool first_run = true;
|
||||
if(!first_run)
|
||||
{
|
||||
m_descriptor_pool_manager.ResetPoolsFromFrameIndex(m_current_frame_index);
|
||||
EventBus::SendBroadcast(Internal::DescriptorPoolResetEventBroadcast{});
|
||||
}
|
||||
first_run = false;
|
||||
VkResult result = RenderCore::Get().vkAcquireNextImageKHR(RenderCore::Get().GetDevice(), m_swapchain, UINT64_MAX, m_image_available_semaphores[m_current_frame_index], VK_NULL_HANDLE, &m_swapchain_image_index);
|
||||
if(result == VK_ERROR_OUT_OF_DATE_KHR)
|
||||
{
|
||||
@@ -150,7 +138,6 @@ namespace mlx
|
||||
DebugLog("Vulkan : fence destroyed");
|
||||
}
|
||||
|
||||
m_descriptor_pool_manager.Destroy();
|
||||
DestroySwapchain();
|
||||
RenderCore::Get().vkDestroySurfaceKHR(RenderCore::Get().GetInstance(), m_surface, nullptr);
|
||||
DebugLog("Vulkan : surface destroyed");
|
||||
|
||||
Reference in New Issue
Block a user