mirror of
https://github.com/seekrs/MacroLibX.git
synced 2026-01-11 22:53:34 +00:00
fixing physical device pick issues
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/08 18:55:57 by maldavid #+# #+# */
|
||||
/* Updated: 2023/11/10 08:14:42 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/11 03:27:31 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -15,12 +15,15 @@
|
||||
#include <renderer/core/render_core.h>
|
||||
#include <vma.h>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
|
||||
namespace mlx
|
||||
{
|
||||
void Buffer::create(Buffer::kind type, VkDeviceSize size, VkBufferUsageFlags usage, const void* data)
|
||||
{
|
||||
_usage = usage;
|
||||
VmaAllocationCreateInfo alloc_info{};
|
||||
alloc_info.flags = VMA_ALLOCATION_CREATE_HOST_ACCESS_RANDOM_BIT;
|
||||
if(type == Buffer::kind::constant)
|
||||
{
|
||||
if(data == nullptr)
|
||||
@@ -28,19 +31,13 @@ namespace mlx
|
||||
core::error::report(e_kind::warning, "Vulkan : trying to create constant buffer without data (constant buffers cannot be modified after creation)");
|
||||
return;
|
||||
}
|
||||
_usage = usage | VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
||||
alloc_info.usage = VMA_MEMORY_USAGE_GPU_ONLY;
|
||||
_usage |= VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
||||
alloc_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST;
|
||||
}
|
||||
else if(type == Buffer::kind::uniform)
|
||||
{
|
||||
_usage = usage;
|
||||
alloc_info.usage = VMA_MEMORY_USAGE_CPU_TO_GPU;
|
||||
}
|
||||
alloc_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_HOST;
|
||||
else
|
||||
{
|
||||
_usage = usage;
|
||||
alloc_info.usage = VMA_MEMORY_USAGE_GPU_TO_CPU;
|
||||
}
|
||||
alloc_info.usage = VMA_MEMORY_USAGE_AUTO;
|
||||
|
||||
createBuffer(_usage, alloc_info, size);
|
||||
|
||||
@@ -58,6 +55,8 @@ namespace mlx
|
||||
|
||||
void Buffer::destroy() noexcept
|
||||
{
|
||||
if(_is_mapped)
|
||||
unmapMem();
|
||||
Render_Core::get().getAllocator().destroyBuffer(_allocation, _buffer);
|
||||
}
|
||||
|
||||
@@ -75,7 +74,7 @@ namespace mlx
|
||||
void Buffer::pushToGPU() noexcept
|
||||
{
|
||||
VmaAllocationCreateInfo alloc_info{};
|
||||
alloc_info.usage = VMA_MEMORY_USAGE_GPU_ONLY;
|
||||
alloc_info.usage = VMA_MEMORY_USAGE_AUTO_PREFER_DEVICE;
|
||||
|
||||
Buffer newBuffer;
|
||||
newBuffer._usage = (_usage & 0xFFFFFFFC) | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 23:18:52 by maldavid #+# #+# */
|
||||
/* Updated: 2023/11/09 19:38:30 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/11 03:29:40 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -23,14 +23,11 @@ namespace mlx
|
||||
public:
|
||||
enum class kind { dynamic, uniform, constant };
|
||||
|
||||
:q
|
||||
void create(kind type, VkDeviceSize size, VkBufferUsageFlags usage, const void* data = nullptr);
|
||||
void destroy() noexcept;
|
||||
|
||||
inline void mapMem(void** data = nullptr) noexcept
|
||||
{
|
||||
Render_Core::get().getAllocator().mapMemory(_allocation, data);
|
||||
_is_mapped = true;
|
||||
}
|
||||
inline void mapMem(void** data = nullptr) noexcept { Render_Core::get().getAllocator().mapMemory(_allocation, data); _is_mapped = true; }
|
||||
inline bool isMapped() const noexcept { return _is_mapped; }
|
||||
inline void unmapMem() noexcept { Render_Core::get().getAllocator().unmapMemory(_allocation);_is_mapped = false; }
|
||||
|
||||
@@ -39,7 +36,7 @@ namespace mlx
|
||||
inline VkBuffer& operator()() noexcept { return _buffer; }
|
||||
inline VkBuffer& get() noexcept { return _buffer; }
|
||||
inline VkDeviceSize getSize() const noexcept { return _alloc_infos.size; }
|
||||
inline VkDeviceSize getOffset() const noexcept { return _alloc_infos.offset; }
|
||||
inline VkDeviceSize getOffset() const noexcept { return _offset; }
|
||||
|
||||
protected:
|
||||
void pushToGPU() noexcept;
|
||||
@@ -49,6 +46,7 @@ namespace mlx
|
||||
VmaAllocation _allocation;
|
||||
VmaAllocationInfo _alloc_infos;
|
||||
VkBuffer _buffer = VK_NULL_HANDLE;
|
||||
VkDeviceSize _offset = 0;
|
||||
|
||||
private:
|
||||
void createBuffer(VkBufferUsageFlags usage, VmaAllocationCreateInfo info, VkDeviceSize size);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/01/25 15:05:05 by maldavid #+# #+# */
|
||||
/* Updated: 2023/11/10 07:53:26 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/11 03:08:10 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace mlx
|
||||
{
|
||||
public:
|
||||
inline void create(uint32_t size, const uint16_t* data) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_INDEX_BUFFER_BIT, data); }
|
||||
inline void bind(Renderer& renderer) noexcept { vkCmdBindIndexBuffer(renderer.getActiveCmdBuffer().get(), _buffer, getOffset(), VK_INDEX_TYPE_UINT16); }
|
||||
inline void bind(Renderer& renderer) noexcept { vkCmdBindIndexBuffer(renderer.getActiveCmdBuffer().get(), _buffer, 0, VK_INDEX_TYPE_UINT16); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* By: maldavid <kbz_8.dev@akel-engine.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2022/10/06 18:27:38 by maldavid #+# #+# */
|
||||
/* Updated: 2023/11/10 07:54:15 by maldavid ### ########.fr */
|
||||
/* Updated: 2023/11/11 03:22:44 by maldavid ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
@@ -22,17 +22,15 @@ namespace mlx
|
||||
{
|
||||
public:
|
||||
inline void create(uint32_t size) { Buffer::create(Buffer::kind::dynamic, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT); }
|
||||
|
||||
void setData(uint32_t size, const void* data);
|
||||
|
||||
inline void bind(Renderer& renderer) noexcept { vkCmdBindVertexBuffers(renderer.getActiveCmdBuffer().get(), 0, 1, &_buffer, &_alloc_infos.offset); }
|
||||
inline void bind(Renderer& renderer) noexcept { vkCmdBindVertexBuffers(renderer.getActiveCmdBuffer().get(), 0, 1, &_buffer, &_offset); }
|
||||
};
|
||||
|
||||
class C_VBO : public Buffer
|
||||
{
|
||||
public:
|
||||
inline void create(uint32_t size, const void* data) { Buffer::create(Buffer::kind::constant, size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, data); }
|
||||
inline void bind(Renderer& renderer) noexcept { vkCmdBindVertexBuffers(renderer.getActiveCmdBuffer().get(), 0, 1, &_buffer, &_alloc_infos.offset); }
|
||||
inline void bind(Renderer& renderer) noexcept { vkCmdBindVertexBuffers(renderer.getActiveCmdBuffer().get(), 0, 1, &_buffer, &_offset); }
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user