adding async chunk generation

This commit is contained in:
Kbz-8
2025-05-17 23:10:31 +02:00
parent de4d826d57
commit 904f079cd1
19 changed files with 167 additions and 75 deletions

View File

@@ -15,7 +15,7 @@ namespace Scop
public:
GPUBuffer() = default;
void Init(BufferType type, VkDeviceSize size, VkBufferUsageFlags usage, CPUBuffer data, std::string_view name = {});
void Init(BufferType type, VkDeviceSize size, VkBufferUsageFlags usage, CPUBuffer data, std::string_view name = {}, bool dedicated_alloc = false);
void Destroy() noexcept;
bool CopyFrom(const GPUBuffer& buffer, std::size_t src_offset = 0, std::size_t dst_offset = 0) noexcept;
@@ -43,7 +43,7 @@ namespace Scop
MemoryBlock m_memory = NULL_MEMORY_BLOCK;
private:
void CreateBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, std::string_view name);
void CreateBuffer(VkDeviceSize size, VkBufferUsageFlags usage, VkMemoryPropertyFlags properties, std::string_view name, bool dedicated_alloc);
private:
inline static std::size_t s_buffer_count = 0;
@@ -52,6 +52,7 @@ namespace Scop
VkBufferUsageFlags m_usage = 0;
VkMemoryPropertyFlags m_flags = 0;
bool m_is_dedicated_alloc = false;
};
class VertexBuffer : public GPUBuffer
@@ -77,7 +78,7 @@ namespace Scop
{
m_vertex_offset = 0;
m_index_offset = vertex_size;
GPUBuffer::Init(BufferType::LowDynamic, vertex_size + index_size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT | additional_flags, std::move(data), std::move(name));
GPUBuffer::Init(BufferType::LowDynamic, vertex_size + index_size, VK_BUFFER_USAGE_VERTEX_BUFFER_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT | additional_flags, std::move(data), std::move(name), true);
}
void SetVertexData(CPUBuffer data);
void SetIndexData(CPUBuffer data);

View File

@@ -12,12 +12,13 @@ namespace Scop
class MemoryChunk
{
public:
MemoryChunk(VkDevice device, VkPhysicalDevice physical, VkDeviceSize size, std::int32_t memory_type_index);
MemoryChunk(VkDevice device, VkPhysicalDevice physical, VkDeviceSize size, std::int32_t memory_type_index, bool is_dedicated);
[[nodiscard]] std::optional<MemoryBlock> Allocate(VkDeviceSize size, VkDeviceSize alignment);
void Deallocate(const MemoryBlock& block);
[[nodiscard]] inline bool Has(const MemoryBlock& block) const noexcept { return block.memory == m_memory; }
[[nodiscard]] inline std::int32_t GetMemoryTypeIndex() const noexcept { return m_memory_type_index; }
[[nodiscard]] inline bool IsDedicated() const noexcept { return m_is_dedicated; }
~MemoryChunk();
@@ -29,6 +30,7 @@ namespace Scop
void* p_map = nullptr;
VkDeviceSize m_size = 0;
std::int32_t m_memory_type_index;
bool m_is_dedicated;
};
}

View File

@@ -1,6 +1,7 @@
#ifndef __SCOP_VULKAN_MEMORY_DEVICE_ALLOCATOR__
#define __SCOP_VULKAN_MEMORY_DEVICE_ALLOCATOR__
#include <mutex>
#include <vector>
#include <memory>
#include <cstdint>
@@ -29,6 +30,8 @@ namespace Scop
VkDevice m_device = VK_NULL_HANDLE;
VkPhysicalDevice m_physical = VK_NULL_HANDLE;
std::size_t m_allocations_count = 0;
std::mutex m_alloc_mutex;
std::mutex m_dealloc_mutex;
};
}

View File

@@ -6,9 +6,6 @@
#include <cstdint>
#include <optional>
#ifdef DEBUG
#define KVF_ENABLE_VALIDATION_LAYERS
#endif
#include <kvf.h>
#include <Renderer/Memory/DeviceAllocator.h>
@@ -36,17 +33,21 @@ namespace Scop
[[nodiscard]] inline VkInstance& GetInstanceRef() noexcept { return m_instance; }
[[nodiscard]] inline VkDevice GetDevice() const noexcept { return m_device; }
[[nodiscard]] inline VkPhysicalDevice GetPhysicalDevice() const noexcept { return m_physical_device; }
[[nodiscard]] inline DeviceAllocator& GetAllocator() noexcept { return m_allocator; }
[[nodiscard]] inline DeviceAllocator& GetAllocator() noexcept { return m_allocator; }
[[nodiscard]] inline bool StackSubmits() const noexcept { return m_stack_submits; }
[[nodiscard]] inline std::shared_ptr<class Shader> GetDefaultVertexShader() const { return m_internal_shaders[DEFAULT_VERTEX_SHADER_ID]; }
[[nodiscard]] inline std::shared_ptr<class Shader> GetBasicFragmentShader() const { return m_internal_shaders[BASIC_FRAGMENT_SHADER_ID]; }
[[nodiscard]] inline std::shared_ptr<class Shader> GetDefaultFragmentShader() const { return m_internal_shaders[DEFAULT_FRAGMENT_SHADER_ID]; }
inline void WaitDeviceIdle() const noexcept { vkDeviceWaitIdle(m_device); }
inline void WaitQueueIdle(KvfQueueType queue) const noexcept { vkQueueWaitIdle(kvfGetDeviceQueue(m_device, queue)); }
inline static bool IsInit() noexcept { return s_instance != nullptr; }
inline static RenderCore& Get() noexcept { return *s_instance; }
inline void ShouldStackSubmits(bool should) noexcept { m_stack_submits = should; }
#define SCOP_VULKAN_GLOBAL_FUNCTION(fn) PFN_##fn fn = nullptr;
#define SCOP_VULKAN_INSTANCE_FUNCTION(fn) PFN_##fn fn = nullptr;
#define SCOP_VULKAN_DEVICE_FUNCTION(fn) PFN_##fn fn = nullptr;
@@ -70,6 +71,7 @@ namespace Scop
VkInstance m_instance = VK_NULL_HANDLE;
VkDevice m_device = VK_NULL_HANDLE;
VkPhysicalDevice m_physical_device = VK_NULL_HANDLE;
bool m_stack_submits = false;
};
}