mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-12 15:13:34 +00:00
fixing frame capture
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:26:06 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/23 01:32:02 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/24 12:58:36 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -85,7 +85,8 @@ namespace mlx
|
||||
VkFence fence;
|
||||
vkCreateFence(device, &fenceCreateInfo, nullptr, &fence);
|
||||
vkResetFences(device, 1, &fence);
|
||||
vkQueueSubmit(Render_Core::get().getQueue().getGraphic(), 1, &submitInfo, fence);
|
||||
if(vkQueueSubmit(Render_Core::get().getQueue().getGraphic(), 1, &submitInfo, fence) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan error : failed to submit a single time command buffer");
|
||||
_state = state::submitted;
|
||||
vkWaitForFences(device, 1, &fence, VK_TRUE, UINT64_MAX);
|
||||
vkDestroyFence(device, fence, nullptr);
|
||||
@@ -102,6 +103,11 @@ namespace mlx
|
||||
signalSemaphores[0] = semaphores->getRenderImageSemaphore();
|
||||
waitSemaphores[0] = semaphores->getImageSemaphore();
|
||||
}
|
||||
else
|
||||
{
|
||||
signalSemaphores[0] = nullptr;
|
||||
waitSemaphores[0] = nullptr;
|
||||
}
|
||||
VkPipelineStageFlags waitStages[] = { VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
|
||||
|
||||
VkSubmitInfo submitInfo{};
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/23 18:40:44 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/14 16:45:11 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/24 09:37:55 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "vk_descriptor_set_layout.h"
|
||||
#include <renderer/buffers/vk_ubo.h>
|
||||
#include <renderer/renderer.h>
|
||||
#include <renderer/images/vk_image.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@@ -66,14 +67,14 @@ namespace mlx
|
||||
}
|
||||
}
|
||||
|
||||
void DescriptorSet::writeDescriptor(int binding, VkImageView view, VkSampler sampler) const noexcept
|
||||
void DescriptorSet::writeDescriptor(int binding, const Image& image) const noexcept
|
||||
{
|
||||
auto device = Render_Core::get().getDevice().get();
|
||||
|
||||
VkDescriptorImageInfo imageInfo{};
|
||||
imageInfo.imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL;
|
||||
imageInfo.imageView = view;
|
||||
imageInfo.sampler = sampler;
|
||||
imageInfo.imageLayout = image.getLayout();
|
||||
imageInfo.imageView = image.getImageView();
|
||||
imageInfo.sampler = image.getSampler();
|
||||
|
||||
VkWriteDescriptorSet descriptorWrite{};
|
||||
descriptorWrite.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/23 18:39:36 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/14 17:12:49 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/23 18:47:49 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace mlx
|
||||
void init(class Renderer* renderer, class DescriptorPool* pool, class DescriptorSetLayout* layout);
|
||||
|
||||
void writeDescriptor(int binding, class UBO* ubo) const noexcept;
|
||||
void writeDescriptor(int binding, VkImageView view, VkSampler sampler) const noexcept;
|
||||
void writeDescriptor(int binding, const class Image& image) const noexcept;
|
||||
|
||||
inline bool isInit() const noexcept { return _pool != nullptr && _renderer != nullptr; }
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/31 18:03:35 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/23 01:52:49 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/23 18:49:53 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -121,16 +121,11 @@ namespace mlx
|
||||
_has_been_modified = false;
|
||||
}
|
||||
auto cmd = renderer.getActiveCmdBuffer();
|
||||
VkImageLayout layout_save = getLayout();
|
||||
if(getLayout() != VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL)
|
||||
transitionLayout(VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, &cmd);
|
||||
_vbo.bind(renderer);
|
||||
_ibo.bind(renderer);
|
||||
glm::vec2 translate(x, y);
|
||||
vkCmdPushConstants(cmd.get(), renderer.getPipeline().getPipelineLayout(), VK_SHADER_STAGE_VERTEX_BIT, 0, sizeof(translate), &translate);
|
||||
vkCmdDrawIndexed(cmd.get(), static_cast<uint32_t>(_ibo.getSize() / sizeof(uint16_t)), 1, 0, 0, 0);
|
||||
if(getLayout() != layout_save)
|
||||
transitionLayout(layout_save, &cmd);
|
||||
}
|
||||
|
||||
void Texture::destroy() noexcept
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/08 02:24:58 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/14 14:37:08 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/23 18:49:12 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace mlx
|
||||
|
||||
inline void setDescriptor(DescriptorSet set) noexcept { _set = std::move(set); }
|
||||
inline VkDescriptorSet getSet() noexcept { return _set.isInit() ? _set.get() : VK_NULL_HANDLE; }
|
||||
inline void updateSet(int binding) noexcept { _set.writeDescriptor(binding, getImageView(), getSampler()); _has_been_updated = true; }
|
||||
inline void updateSet(int binding) noexcept { _set.writeDescriptor(binding, *this); _has_been_updated = true; }
|
||||
inline bool hasBeenUpdated() const noexcept { return _has_been_updated; }
|
||||
inline constexpr void resetUpdate() noexcept { _has_been_updated = false; }
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/04/07 16:36:33 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/14 17:12:54 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/23 18:49:25 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace mlx
|
||||
|
||||
inline void setDescriptor(DescriptorSet&& set) noexcept { _set = set; }
|
||||
inline VkDescriptorSet getSet() noexcept { return _set.isInit() ? _set.get() : VK_NULL_HANDLE; }
|
||||
inline void updateSet(int binding) const noexcept { _set.writeDescriptor(binding, getImageView(), getSampler()); }
|
||||
inline void updateSet(int binding) const noexcept { _set.writeDescriptor(binding, *this); }
|
||||
|
||||
~TextureAtlas() = default;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/03/31 15:14:50 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/14 18:26:03 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/12/23 19:34:30 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace mlx
|
||||
{
|
||||
_texture.render(renderer, 0, 0);
|
||||
}
|
||||
|
||||
|
||||
void PixelPutPipeline::destroy() noexcept
|
||||
{
|
||||
_buffer.destroy();
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/12/18 17:25:16 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/23 01:28:03 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/24 16:04:04 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace mlx
|
||||
|
||||
for(std::size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++)
|
||||
_semaphores[i].init();
|
||||
|
||||
|
||||
_uniform_buffer.reset(new UBO);
|
||||
#ifdef DEBUG
|
||||
_uniform_buffer->create(this, sizeof(glm::mat4), "__mlx_matrices_uniform_buffer_");
|
||||
@@ -51,14 +51,14 @@ namespace mlx
|
||||
{ VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 4096 }
|
||||
};
|
||||
_desc_pool.init(2, pool_sizes);
|
||||
|
||||
|
||||
_vert_layout.init({
|
||||
{0, VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER}
|
||||
}, VK_SHADER_STAGE_VERTEX_BIT);
|
||||
_frag_layout.init({
|
||||
{0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER}
|
||||
}, VK_SHADER_STAGE_FRAGMENT_BIT);
|
||||
|
||||
|
||||
_vert_set.init(this, &_desc_pool, &_vert_layout);
|
||||
_frag_set.init(this, &_desc_pool, &_frag_layout);
|
||||
|
||||
@@ -73,9 +73,9 @@ namespace mlx
|
||||
{
|
||||
auto device = Render_Core::get().getDevice().get();
|
||||
|
||||
_cmd.getCmdBuffer(_current_frame_index).waitForExecution();
|
||||
if(_render_target == nullptr)
|
||||
{
|
||||
_cmd.getCmdBuffer(_current_frame_index).waitForExecution();
|
||||
VkResult result = vkAcquireNextImageKHR(device, _swapchain(), UINT64_MAX, _semaphores[_current_frame_index].getImageSemaphore(), VK_NULL_HANDLE, &_image_index);
|
||||
|
||||
if(result == VK_ERROR_OUT_OF_DATE_KHR)
|
||||
@@ -87,7 +87,11 @@ namespace mlx
|
||||
core::error::report(e_kind::fatal_error, "Vulkan error : failed to acquire swapchain image");
|
||||
}
|
||||
else
|
||||
{
|
||||
_image_index = 0;
|
||||
if(_render_target->getLayout() != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL)
|
||||
_render_target->transitionLayout(VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
|
||||
}
|
||||
|
||||
_cmd.getCmdBuffer(_current_frame_index).reset();
|
||||
_cmd.getCmdBuffer(_current_frame_index).beginRecord();
|
||||
@@ -107,7 +111,7 @@ namespace mlx
|
||||
|
||||
VkRect2D scissor{};
|
||||
scissor.offset = { 0, 0 };
|
||||
scissor.extent = _swapchain.getExtent();
|
||||
scissor.extent = { fb.getWidth(), fb.getHeight()};
|
||||
vkCmdSetScissor(_cmd.getCmdBuffer(_current_frame_index).get(), 0, 1, &scissor);
|
||||
|
||||
return true;
|
||||
@@ -142,11 +146,13 @@ namespace mlx
|
||||
}
|
||||
else if(result != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan error : failed to present swap chain image");
|
||||
_current_frame_index = (_current_frame_index + 1) % MAX_FRAMES_IN_FLIGHT;
|
||||
}
|
||||
else
|
||||
_cmd.getCmdBuffer(_current_frame_index).submit(nullptr);
|
||||
|
||||
_current_frame_index = (_current_frame_index + 1) % MAX_FRAMES_IN_FLIGHT;
|
||||
{
|
||||
_cmd.getCmdBuffer(_current_frame_index).submitIdle();
|
||||
_current_frame_index = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::destroy()
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:21:36 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/22 23:05:38 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/24 15:31:02 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -14,7 +14,6 @@
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <renderer/renderer.h>
|
||||
#include <renderer/renderpass/vk_framebuffer.h>
|
||||
#include <vulkan/vulkan_core.h>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
@@ -36,17 +35,40 @@ namespace mlx
|
||||
colorAttachmentRef.attachment = 0;
|
||||
colorAttachmentRef.layout = (layout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR ? VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL : layout);
|
||||
|
||||
VkSubpassDescription subpass{};
|
||||
subpass.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
subpass.colorAttachmentCount = 1;
|
||||
subpass.pColorAttachments = &colorAttachmentRef;
|
||||
VkSubpassDescription subpass1{};
|
||||
subpass1.pipelineBindPoint = VK_PIPELINE_BIND_POINT_GRAPHICS;
|
||||
subpass1.colorAttachmentCount = 1;
|
||||
subpass1.pColorAttachments = &colorAttachmentRef;
|
||||
|
||||
VkSubpassDescription subpasses[] = { subpass1 };
|
||||
|
||||
std::vector<VkSubpassDependency> subpassesDeps;
|
||||
subpassesDeps.emplace_back();
|
||||
subpassesDeps.back().srcSubpass = VK_SUBPASS_EXTERNAL;
|
||||
subpassesDeps.back().dstSubpass = 0;
|
||||
subpassesDeps.back().srcStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||
subpassesDeps.back().dstStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
subpassesDeps.back().srcAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
||||
subpassesDeps.back().dstAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
subpassesDeps.back().dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
||||
|
||||
subpassesDeps.emplace_back();
|
||||
subpassesDeps.back().srcSubpass = 0;
|
||||
subpassesDeps.back().dstSubpass = VK_SUBPASS_EXTERNAL;
|
||||
subpassesDeps.back().srcStageMask = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
subpassesDeps.back().dstStageMask = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||
subpassesDeps.back().srcAccessMask = VK_ACCESS_COLOR_ATTACHMENT_READ_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT;
|
||||
subpassesDeps.back().dstAccessMask = VK_ACCESS_MEMORY_READ_BIT;
|
||||
subpassesDeps.back().dependencyFlags = VK_DEPENDENCY_BY_REGION_BIT;
|
||||
|
||||
VkRenderPassCreateInfo renderPassInfo{};
|
||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_CREATE_INFO;
|
||||
renderPassInfo.attachmentCount = 1;
|
||||
renderPassInfo.pAttachments = &colorAttachment;
|
||||
renderPassInfo.subpassCount = 1;
|
||||
renderPassInfo.pSubpasses = &subpass;
|
||||
renderPassInfo.subpassCount = sizeof(subpasses) / sizeof(VkSubpassDescription);
|
||||
renderPassInfo.pSubpasses = subpasses;
|
||||
renderPassInfo.dependencyCount = static_cast<uint32_t>(subpassesDeps.size());
|
||||
renderPassInfo.pDependencies = subpassesDeps.data();
|
||||
|
||||
if(vkCreateRenderPass(Render_Core::get().getDevice().get(), &renderPassInfo, nullptr, &_renderPass) != VK_SUCCESS)
|
||||
core::error::report(e_kind::fatal_error, "Vulkan : failed to create render pass");
|
||||
@@ -78,7 +100,6 @@ namespace mlx
|
||||
{
|
||||
if(!_is_running)
|
||||
return;
|
||||
|
||||
vkCmdEndRenderPass(cmd.get());
|
||||
_is_running = false;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:22:00 by maldavid #+# #+# */
|
||||
/* Updated: 2023/12/22 23:00:00 by kbz_8 ### ########.fr */
|
||||
/* Updated: 2023/12/24 13:01:56 by kbz_8 ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user