mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 14:43:34 +00:00
working on cmd resources management
This commit is contained in:
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
|
/* Created: 2022/10/04 17:55:21 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/03 12:29:31 by maldavid ### ########.fr */
|
/* Updated: 2024/01/04 12:44:58 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@@ -6,11 +6,12 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
|
/* Created: 2022/10/04 16:56:35 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/12/27 17:19:50 by maldavid ### ########.fr */
|
/* Updated: 2024/01/05 19:53:13 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
// MacroLibX official repo https://github.com/seekrs/MacroLibX
|
// MacroLibX official repo https://github.com/seekrs/MacroLibX
|
||||||
|
// MacroLibX official website https://macrolibx.kbz8.me/
|
||||||
|
|
||||||
#ifndef __MACRO_LIB_X_H__
|
#ifndef __MACRO_LIB_X_H__
|
||||||
#define __MACRO_LIB_X_H__
|
#define __MACRO_LIB_X_H__
|
||||||
@@ -147,10 +148,10 @@ MLX_API int mlx_on_event(void* mlx, void* win, mlx_event_type event, int (*f)(in
|
|||||||
* @param win Internal window
|
* @param win Internal window
|
||||||
* @param x X coordinate
|
* @param x X coordinate
|
||||||
* @param y Y coordinate
|
* @param y Y coordinate
|
||||||
* @param color Color of the pixel (coded on 3 bytes in an int, 0x00RRGGBB)
|
* @param color Color of the pixel (coded on 4 bytes in an int, 0xAARRGGBB)
|
||||||
*
|
*
|
||||||
* Note : If your're reading pixel colors from an image, don't forget to shift them
|
* Note : If your're reading pixel colors from an image, don't forget to shift them
|
||||||
* one byte to the right as image pixels are encoded as 0xRRGGBBAA and pixel put takes 0x00RRGGBB.
|
* one byte to the right as image pixels are encoded as 0xRRGGBBAA and pixel put takes 0xAARRGGBB.
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
||||||
*/
|
*/
|
||||||
@@ -283,7 +284,7 @@ MLX_API void* mlx_bmp_file_to_image(void* mlx, char* filename, int* width, int*
|
|||||||
* @param win Internal window
|
* @param win Internal window
|
||||||
* @param x X coordinate
|
* @param x X coordinate
|
||||||
* @param y Y coordinate
|
* @param y Y coordinate
|
||||||
* @param color Color of the pixel (coded on 3 bytes in an int, 0x00RRGGBB)
|
* @param color Color of the pixel (coded on 4 bytes in an int, 0xAARRGGBB)
|
||||||
* @param str Text to put
|
* @param str Text to put
|
||||||
*
|
*
|
||||||
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
* @return (int) Always return 0, made this to copy the behaviour of the original MLX
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/04 17:48:06 by maldavid #+# #+# */
|
/* Created: 2022/10/04 17:48:06 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/11/14 07:14:57 by maldavid ### ########.fr */
|
/* Updated: 2024/01/05 20:41:17 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/12/15 19:57:49 by maldavid #+# #+# */
|
/* Created: 2023/12/15 19:57:49 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/12/17 20:10:25 by maldavid ### ########.fr */
|
/* Updated: 2024/01/05 20:29:01 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -51,4 +51,6 @@ namespace mlx
|
|||||||
});
|
});
|
||||||
_pool.destroy();
|
_pool.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SingleTimeCmdManager::~SingleTimeCmdManager() {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/12/15 18:25:57 by maldavid #+# #+# */
|
/* Created: 2023/12/15 18:25:57 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/12/17 17:36:18 by maldavid ### ########.fr */
|
/* Updated: 2024/01/05 20:28:41 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -32,7 +32,7 @@ namespace mlx
|
|||||||
inline CmdPool& getCmdPool() noexcept { return _pool; }
|
inline CmdPool& getCmdPool() noexcept { return _pool; }
|
||||||
CmdBuffer& getCmdBuffer() noexcept;
|
CmdBuffer& getCmdBuffer() noexcept;
|
||||||
|
|
||||||
~SingleTimeCmdManager() = default;
|
~SingleTimeCmdManager();
|
||||||
|
|
||||||
inline static constexpr const uint8_t MIN_POOL_SIZE = 8;
|
inline static constexpr const uint8_t MIN_POOL_SIZE = 8;
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/06 18:26:06 by maldavid #+# #+# */
|
/* Created: 2022/10/06 18:26:06 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/04 12:27:19 by maldavid ### ########.fr */
|
/* Updated: 2024/01/05 23:06:04 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@
|
|||||||
#include <renderer/command/cmd_manager.h>
|
#include <renderer/command/cmd_manager.h>
|
||||||
#include <renderer/core/vk_semaphore.h>
|
#include <renderer/core/vk_semaphore.h>
|
||||||
#include <renderer/buffers/vk_buffer.h>
|
#include <renderer/buffers/vk_buffer.h>
|
||||||
|
#include <renderer/images/vk_image.h>
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
@@ -73,6 +74,124 @@ namespace mlx
|
|||||||
buffer.recordedInCmdBuffer();
|
buffer.recordedInCmdBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CmdBuffer::bindIndexBuffer(Buffer& buffer) const noexcept
|
||||||
|
{
|
||||||
|
if(!isRecording())
|
||||||
|
{
|
||||||
|
core::error::report(e_kind::warning, "Vulkan : trying to bind a index buffer to a non recording command buffer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
vkCmdBindIndexBuffer(_cmd_buffer, buffer.get(), buffer.getOffset(), VK_INDEX_TYPE_UINT16);
|
||||||
|
buffer.recordedInCmdBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CmdBuffer::copyBuffer(Buffer& dst, Buffer& src) const noexcept
|
||||||
|
{
|
||||||
|
if(!isRecording())
|
||||||
|
{
|
||||||
|
core::error::report(e_kind::warning, "Vulkan : trying to do a buffer to buffer copy in a non recording command buffer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
VkBufferCopy copyRegion{};
|
||||||
|
copyRegion.size = src.getSize();
|
||||||
|
vkCmdCopyBuffer(_cmd_buffer, src.get(), dst.get(), 1, ©Region);
|
||||||
|
dst.recordedInCmdBuffer();
|
||||||
|
src.recordedInCmdBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CmdBuffer::copyBufferToImage(Buffer& buffer, Image& image) const noexcept
|
||||||
|
{
|
||||||
|
if(!isRecording())
|
||||||
|
{
|
||||||
|
core::error::report(e_kind::warning, "Vulkan : trying to do a buffer to image copy in a non recording command buffer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
VkBufferImageCopy region{};
|
||||||
|
region.bufferOffset = 0;
|
||||||
|
region.bufferRowLength = 0;
|
||||||
|
region.bufferImageHeight = 0;
|
||||||
|
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
region.imageSubresource.mipLevel = 0;
|
||||||
|
region.imageSubresource.baseArrayLayer = 0;
|
||||||
|
region.imageSubresource.layerCount = 1;
|
||||||
|
region.imageOffset = { 0, 0, 0 };
|
||||||
|
region.imageExtent = { image.getWidth(), image.getHeight(), 1 };
|
||||||
|
|
||||||
|
vkCmdCopyBufferToImage(_cmd_buffer, buffer.get(), image.get(), VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
||||||
|
|
||||||
|
image.recordedInCmdBuffer();
|
||||||
|
buffer.recordedInCmdBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CmdBuffer::copyImagetoBuffer(Image& image, Buffer& buffer) const noexcept
|
||||||
|
{
|
||||||
|
if(!isRecording())
|
||||||
|
{
|
||||||
|
core::error::report(e_kind::warning, "Vulkan : trying to do an image to buffer copy in a non recording command buffer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
VkBufferImageCopy region{};
|
||||||
|
region.bufferOffset = 0;
|
||||||
|
region.bufferRowLength = 0;
|
||||||
|
region.bufferImageHeight = 0;
|
||||||
|
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
region.imageSubresource.mipLevel = 0;
|
||||||
|
region.imageSubresource.baseArrayLayer = 0;
|
||||||
|
region.imageSubresource.layerCount = 1;
|
||||||
|
region.imageOffset = { 0, 0, 0 };
|
||||||
|
region.imageExtent = { image.getWidth(), image.getHeight(), 1 };
|
||||||
|
|
||||||
|
vkCmdCopyImageToBuffer(_cmd_buffer, image.get(), VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buffer.get(), 1, ®ion);
|
||||||
|
|
||||||
|
image.recordedInCmdBuffer();
|
||||||
|
buffer.recordedInCmdBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
|
void CmdBuffer::transitionImageLayout(Image& image, VkImageLayout new_layout) const noexcept
|
||||||
|
{
|
||||||
|
if(!isRecording())
|
||||||
|
{
|
||||||
|
core::error::report(e_kind::warning, "Vulkan : trying to do an image layout transition in a non recording command buffer");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
VkImageMemoryBarrier barrier{};
|
||||||
|
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
||||||
|
barrier.oldLayout = image.getLayout();
|
||||||
|
barrier.newLayout = new_layout;
|
||||||
|
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
|
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
||||||
|
barrier.image = image.get();
|
||||||
|
barrier.subresourceRange.aspectMask = isDepthFormat(image.getFormat()) ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
|
||||||
|
barrier.subresourceRange.baseMipLevel = 0;
|
||||||
|
barrier.subresourceRange.levelCount = 1;
|
||||||
|
barrier.subresourceRange.baseArrayLayer = 0;
|
||||||
|
barrier.subresourceRange.layerCount = 1;
|
||||||
|
barrier.srcAccessMask = layoutToAccessMask(image.getLayout(), false);
|
||||||
|
barrier.dstAccessMask = layoutToAccessMask(new_layout, true);
|
||||||
|
if(isStencilFormat(image.getFormat()))
|
||||||
|
barrier.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
|
||||||
|
|
||||||
|
VkPipelineStageFlags sourceStage = 0;
|
||||||
|
if(barrier.oldLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
|
||||||
|
sourceStage = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||||
|
else if(barrier.srcAccessMask != 0)
|
||||||
|
sourceStage = accessFlagsToPipelineStage(barrier.srcAccessMask, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||||
|
else
|
||||||
|
sourceStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||||
|
|
||||||
|
VkPipelineStageFlags destinationStage = 0;
|
||||||
|
if(barrier.newLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
|
||||||
|
destinationStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
||||||
|
else if(barrier.dstAccessMask != 0)
|
||||||
|
destinationStage = accessFlagsToPipelineStage(barrier.dstAccessMask, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
||||||
|
else
|
||||||
|
destinationStage = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
||||||
|
|
||||||
|
vkCmdPipelineBarrier(_cmd_buffer, sourceStage, destinationStage, 0, 0, nullptr, 0, nullptr, 1, &barrier);
|
||||||
|
image.recordedInCmdBuffer();
|
||||||
|
}
|
||||||
|
|
||||||
void CmdBuffer::endRecord()
|
void CmdBuffer::endRecord()
|
||||||
{
|
{
|
||||||
if(!isInit())
|
if(!isInit())
|
||||||
|
|||||||
@@ -6,16 +6,18 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2022/10/06 18:25:42 by maldavid #+# #+# */
|
/* Created: 2022/10/06 18:25:42 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/03 15:27:20 by maldavid ### ########.fr */
|
/* Updated: 2024/01/05 23:10:01 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#ifndef __MLX_VK_CMD_BUFFER__
|
#ifndef __MLX_VK_CMD_BUFFER__
|
||||||
#define __MLX_VK_CMD_BUFFER__
|
#define __MLX_VK_CMD_BUFFER__
|
||||||
|
|
||||||
|
#include <renderer/core/cmd_resource.h>
|
||||||
#include <mlx_profile.h>
|
#include <mlx_profile.h>
|
||||||
#include <volk.h>
|
#include <volk.h>
|
||||||
#include <renderer/core/vk_fence.h>
|
#include <renderer/core/vk_fence.h>
|
||||||
|
#include <unordered_set>
|
||||||
|
|
||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
@@ -57,6 +59,7 @@ namespace mlx
|
|||||||
void copyBuffer(Buffer& dst, Buffer& src) const noexcept;
|
void copyBuffer(Buffer& dst, Buffer& src) const noexcept;
|
||||||
void copyBufferToImage(Buffer& buffer, Image& image) const noexcept;
|
void copyBufferToImage(Buffer& buffer, Image& image) const noexcept;
|
||||||
void copyImagetoBuffer(Image& image, Buffer& buffer) const noexcept;
|
void copyImagetoBuffer(Image& image, Buffer& buffer) const noexcept;
|
||||||
|
void transitionImageLayout(Image& image, VkImageLayout new_layout) const noexcept;
|
||||||
|
|
||||||
inline bool isInit() const noexcept { return _state != state::uninit; }
|
inline bool isInit() const noexcept { return _state != state::uninit; }
|
||||||
inline bool isReadyToBeUsed() const noexcept { return _state == state::ready; }
|
inline bool isReadyToBeUsed() const noexcept { return _state == state::ready; }
|
||||||
@@ -69,6 +72,7 @@ namespace mlx
|
|||||||
inline Fence& getFence() noexcept { return _fence; }
|
inline Fence& getFence() noexcept { return _fence; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::unordered_set<CmdResource> _resources;
|
||||||
Fence _fence;
|
Fence _fence;
|
||||||
VkCommandBuffer _cmd_buffer = VK_NULL_HANDLE;
|
VkCommandBuffer _cmd_buffer = VK_NULL_HANDLE;
|
||||||
class CmdPool* _pool = nullptr;
|
class CmdPool* _pool = nullptr;
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/12/16 20:44:29 by maldavid #+# #+# */
|
/* Created: 2023/12/16 20:44:29 by maldavid #+# #+# */
|
||||||
/* Updated: 2023/12/17 17:10:03 by maldavid ### ########.fr */
|
/* Updated: 2024/01/05 23:12:45 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -47,16 +47,30 @@ namespace mlx
|
|||||||
else
|
else
|
||||||
_destroy_required = true;
|
_destroy_required = true;
|
||||||
}
|
}
|
||||||
|
inline uint64_t getUUID() const noexcept { return _uuid; }
|
||||||
virtual ~CmdResource() = default;
|
virtual ~CmdResource() = default;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void realDestroy();
|
void realDestroy();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
uint64_t _uuid = 0;
|
||||||
state _state = state::out_cmd_buffer;
|
state _state = state::out_cmd_buffer;
|
||||||
func::function<void(void)> _destroyer;
|
func::function<void(void)> _destroyer;
|
||||||
bool _destroy_required = false;
|
bool _destroy_required = false;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
namespace std
|
||||||
|
{
|
||||||
|
template <>
|
||||||
|
struct hash<mlx::CmdResource>
|
||||||
|
{
|
||||||
|
std::size_t operator()(const mlx::CmdResource& res) const noexcept
|
||||||
|
{
|
||||||
|
return res.getUUID();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/25 11:59:07 by maldavid #+# #+# */
|
/* Created: 2023/01/25 11:59:07 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/03 13:16:21 by maldavid ### ########.fr */
|
/* Updated: 2024/01/05 23:08:47 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -225,18 +225,7 @@ namespace mlx
|
|||||||
VkImageLayout layout_save = _layout;
|
VkImageLayout layout_save = _layout;
|
||||||
transitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &cmd);
|
transitionLayout(VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, &cmd);
|
||||||
|
|
||||||
VkBufferImageCopy region{};
|
cmd.copyBufferToImage(buffer, *this);
|
||||||
region.bufferOffset = 0;
|
|
||||||
region.bufferRowLength = 0;
|
|
||||||
region.bufferImageHeight = 0;
|
|
||||||
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
||||||
region.imageSubresource.mipLevel = 0;
|
|
||||||
region.imageSubresource.baseArrayLayer = 0;
|
|
||||||
region.imageSubresource.layerCount = 1;
|
|
||||||
region.imageOffset = { 0, 0, 0 };
|
|
||||||
region.imageExtent = { _width, _height, 1 };
|
|
||||||
|
|
||||||
vkCmdCopyBufferToImage(cmd.get(), buffer.get(), _image, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, 1, ®ion);
|
|
||||||
|
|
||||||
transitionLayout(layout_save, &cmd);
|
transitionLayout(layout_save, &cmd);
|
||||||
|
|
||||||
@@ -252,18 +241,7 @@ namespace mlx
|
|||||||
VkImageLayout layout_save = _layout;
|
VkImageLayout layout_save = _layout;
|
||||||
transitionLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, &cmd);
|
transitionLayout(VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, &cmd);
|
||||||
|
|
||||||
VkBufferImageCopy region{};
|
cmd.copyImagetoBuffer(*this, buffer);
|
||||||
region.bufferOffset = 0;
|
|
||||||
region.bufferRowLength = 0;
|
|
||||||
region.bufferImageHeight = 0;
|
|
||||||
region.imageSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
|
|
||||||
region.imageSubresource.mipLevel = 0;
|
|
||||||
region.imageSubresource.baseArrayLayer = 0;
|
|
||||||
region.imageSubresource.layerCount = 1;
|
|
||||||
region.imageOffset = { 0, 0, 0 };
|
|
||||||
region.imageExtent = { _width, _height, 1 };
|
|
||||||
|
|
||||||
vkCmdCopyImageToBuffer(cmd.get(), _image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, buffer.get(), 1, ®ion);
|
|
||||||
|
|
||||||
transitionLayout(layout_save, &cmd);
|
transitionLayout(layout_save, &cmd);
|
||||||
|
|
||||||
@@ -283,40 +261,7 @@ namespace mlx
|
|||||||
cmd->beginRecord();
|
cmd->beginRecord();
|
||||||
}
|
}
|
||||||
|
|
||||||
VkImageMemoryBarrier barrier{};
|
cmd->transitionImageLayout(*this, new_layout);
|
||||||
barrier.sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER;
|
|
||||||
barrier.oldLayout = _layout;
|
|
||||||
barrier.newLayout = new_layout;
|
|
||||||
barrier.srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
|
||||||
barrier.dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED;
|
|
||||||
barrier.image = _image;
|
|
||||||
barrier.subresourceRange.aspectMask = isDepthFormat(_format) ? VK_IMAGE_ASPECT_DEPTH_BIT : VK_IMAGE_ASPECT_COLOR_BIT;
|
|
||||||
barrier.subresourceRange.baseMipLevel = 0;
|
|
||||||
barrier.subresourceRange.levelCount = 1;
|
|
||||||
barrier.subresourceRange.baseArrayLayer = 0;
|
|
||||||
barrier.subresourceRange.layerCount = 1;
|
|
||||||
barrier.srcAccessMask = layoutToAccessMask(_layout, false);
|
|
||||||
barrier.dstAccessMask = layoutToAccessMask(new_layout, true);
|
|
||||||
if(isStencilFormat(_format))
|
|
||||||
barrier.subresourceRange.aspectMask |= VK_IMAGE_ASPECT_STENCIL_BIT;
|
|
||||||
|
|
||||||
VkPipelineStageFlags sourceStage = 0;
|
|
||||||
if(barrier.oldLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
|
|
||||||
sourceStage = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
||||||
else if(barrier.srcAccessMask != 0)
|
|
||||||
sourceStage = accessFlagsToPipelineStage(barrier.srcAccessMask, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
|
||||||
else
|
|
||||||
sourceStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
|
||||||
|
|
||||||
VkPipelineStageFlags destinationStage = 0;
|
|
||||||
if(barrier.newLayout == VK_IMAGE_LAYOUT_PRESENT_SRC_KHR)
|
|
||||||
destinationStage = VK_PIPELINE_STAGE_TOP_OF_PIPE_BIT;
|
|
||||||
else if(barrier.dstAccessMask != 0)
|
|
||||||
destinationStage = accessFlagsToPipelineStage(barrier.dstAccessMask, VK_PIPELINE_STAGE_VERTEX_SHADER_BIT | VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT | VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT);
|
|
||||||
else
|
|
||||||
destinationStage = VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT;
|
|
||||||
|
|
||||||
vkCmdPipelineBarrier(cmd->get(), sourceStage, destinationStage, 0, 0, nullptr, 0, nullptr, 1, &barrier);
|
|
||||||
|
|
||||||
if(singleTime)
|
if(singleTime)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
|
/* Created: 2023/01/25 11:54:21 by maldavid #+# #+# */
|
||||||
/* Updated: 2024/01/03 15:28:07 by maldavid ### ########.fr */
|
/* Updated: 2024/01/05 22:36:58 by maldavid ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@@ -25,6 +25,11 @@
|
|||||||
namespace mlx
|
namespace mlx
|
||||||
{
|
{
|
||||||
uint32_t formatSize(VkFormat format);
|
uint32_t formatSize(VkFormat format);
|
||||||
|
bool isStencilFormat(VkFormat format);
|
||||||
|
bool isDepthFormat(VkFormat format);
|
||||||
|
VkFormat bitsToFormat(uint32_t bits);
|
||||||
|
VkPipelineStageFlags layoutToAccessMask(VkImageLayout layout, bool isDestination);
|
||||||
|
VkPipelineStageFlags accessFlagsToPipelineStage(VkAccessFlags accessFlags, VkPipelineStageFlags stageFlags);
|
||||||
|
|
||||||
class Image : public CmdResource
|
class Image : public CmdResource
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user