mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-04 14:02:45 +01:00
memory_allocator: Remove OpenGL interop
* Appears to be unused atm
This commit is contained in:
parent
6448eade2e
commit
c60eed36b7
4 changed files with 8 additions and 67 deletions
|
@ -89,8 +89,8 @@ RendererVulkan::RendererVulkan(Core::TelemetrySession& telemetry_session_,
|
||||||
Settings::values.renderer_debug.GetValue())),
|
Settings::values.renderer_debug.GetValue())),
|
||||||
debug_callback(Settings::values.renderer_debug ? CreateDebugCallback(instance) : nullptr),
|
debug_callback(Settings::values.renderer_debug ? CreateDebugCallback(instance) : nullptr),
|
||||||
surface(CreateSurface(instance, render_window.GetWindowInfo())),
|
surface(CreateSurface(instance, render_window.GetWindowInfo())),
|
||||||
device(CreateDevice(instance, dld, *surface)), memory_allocator(device, false),
|
device(CreateDevice(instance, dld, *surface)), memory_allocator(device), state_tracker(),
|
||||||
state_tracker(), scheduler(device, state_tracker),
|
scheduler(device, state_tracker),
|
||||||
swapchain(*surface, device, scheduler, render_window.GetFramebufferLayout().width,
|
swapchain(*surface, device, scheduler, render_window.GetFramebufferLayout().width,
|
||||||
render_window.GetFramebufferLayout().height, false),
|
render_window.GetFramebufferLayout().height, false),
|
||||||
present_manager(instance, render_window, device, memory_allocator, scheduler, swapchain,
|
present_manager(instance, render_window, device, memory_allocator, scheduler, swapchain,
|
||||||
|
|
|
@ -18,7 +18,7 @@ using namespace Common::Literals;
|
||||||
|
|
||||||
TurboMode::TurboMode(const vk::Instance& instance, const vk::InstanceDispatch& dld)
|
TurboMode::TurboMode(const vk::Instance& instance, const vk::InstanceDispatch& dld)
|
||||||
#ifndef ANDROID
|
#ifndef ANDROID
|
||||||
: m_device{CreateDevice(instance, dld, VK_NULL_HANDLE)}, m_allocator{m_device, false}
|
: m_device{CreateDevice(instance, dld, VK_NULL_HANDLE)}, m_allocator{m_device}
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <glad/glad.h>
|
|
||||||
|
|
||||||
#include "common/alignment.h"
|
#include "common/alignment.h"
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
@ -54,17 +52,6 @@ struct Range {
|
||||||
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
return VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr VkExportMemoryAllocateInfo EXPORT_ALLOCATE_INFO{
|
|
||||||
.sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO,
|
|
||||||
.pNext = nullptr,
|
|
||||||
#ifdef _WIN32
|
|
||||||
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT,
|
|
||||||
#elif __unix__
|
|
||||||
.handleTypes = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT,
|
|
||||||
#else
|
|
||||||
.handleTypes = 0,
|
|
||||||
#endif
|
|
||||||
};
|
|
||||||
} // Anonymous namespace
|
} // Anonymous namespace
|
||||||
|
|
||||||
class MemoryAllocation {
|
class MemoryAllocation {
|
||||||
|
@ -74,14 +61,6 @@ public:
|
||||||
: allocator{allocator_}, memory{std::move(memory_)}, allocation_size{allocation_size_},
|
: allocator{allocator_}, memory{std::move(memory_)}, allocation_size{allocation_size_},
|
||||||
property_flags{properties}, shifted_memory_type{1U << type} {}
|
property_flags{properties}, shifted_memory_type{1U << type} {}
|
||||||
|
|
||||||
#if defined(_WIN32) || defined(__unix__)
|
|
||||||
~MemoryAllocation() {
|
|
||||||
if (owning_opengl_handle != 0) {
|
|
||||||
glDeleteMemoryObjectsEXT(1, &owning_opengl_handle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
MemoryAllocation& operator=(const MemoryAllocation&) = delete;
|
MemoryAllocation& operator=(const MemoryAllocation&) = delete;
|
||||||
MemoryAllocation(const MemoryAllocation&) = delete;
|
MemoryAllocation(const MemoryAllocation&) = delete;
|
||||||
|
|
||||||
|
@ -120,31 +99,6 @@ public:
|
||||||
return memory_mapped_span;
|
return memory_mapped_span;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef _WIN32
|
|
||||||
[[nodiscard]] u32 ExportOpenGLHandle() {
|
|
||||||
if (!owning_opengl_handle) {
|
|
||||||
glCreateMemoryObjectsEXT(1, &owning_opengl_handle);
|
|
||||||
glImportMemoryWin32HandleEXT(owning_opengl_handle, allocation_size,
|
|
||||||
GL_HANDLE_TYPE_OPAQUE_WIN32_EXT,
|
|
||||||
memory.GetMemoryWin32HandleKHR());
|
|
||||||
}
|
|
||||||
return owning_opengl_handle;
|
|
||||||
}
|
|
||||||
#elif __unix__
|
|
||||||
[[nodiscard]] u32 ExportOpenGLHandle() {
|
|
||||||
if (!owning_opengl_handle) {
|
|
||||||
glCreateMemoryObjectsEXT(1, &owning_opengl_handle);
|
|
||||||
glImportMemoryFdEXT(owning_opengl_handle, allocation_size, GL_HANDLE_TYPE_OPAQUE_FD_EXT,
|
|
||||||
memory.GetMemoryFdKHR());
|
|
||||||
}
|
|
||||||
return owning_opengl_handle;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
[[nodiscard]] u32 ExportOpenGLHandle() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/// Returns whether this allocation is compatible with the arguments.
|
/// Returns whether this allocation is compatible with the arguments.
|
||||||
[[nodiscard]] bool IsCompatible(VkMemoryPropertyFlags flags, u32 type_mask) const {
|
[[nodiscard]] bool IsCompatible(VkMemoryPropertyFlags flags, u32 type_mask) const {
|
||||||
return (flags & property_flags) == flags && (type_mask & shifted_memory_type) != 0;
|
return (flags & property_flags) == flags && (type_mask & shifted_memory_type) != 0;
|
||||||
|
@ -182,9 +136,6 @@ private:
|
||||||
const u32 shifted_memory_type; ///< Shifted Vulkan memory type.
|
const u32 shifted_memory_type; ///< Shifted Vulkan memory type.
|
||||||
std::vector<Range> commits; ///< All commit ranges done from this allocation.
|
std::vector<Range> commits; ///< All commit ranges done from this allocation.
|
||||||
std::span<u8> memory_mapped_span; ///< Memory mapped span. Empty if not queried before.
|
std::span<u8> memory_mapped_span; ///< Memory mapped span. Empty if not queried before.
|
||||||
#if defined(_WIN32) || defined(__unix__)
|
|
||||||
u32 owning_opengl_handle{}; ///< Owning OpenGL memory object handle.
|
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
MemoryCommit::MemoryCommit(MemoryAllocation* allocation_, VkDeviceMemory memory_, u64 begin_,
|
MemoryCommit::MemoryCommit(MemoryAllocation* allocation_, VkDeviceMemory memory_, u64 begin_,
|
||||||
|
@ -216,19 +167,14 @@ std::span<u8> MemoryCommit::Map() {
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 MemoryCommit::ExportOpenGLHandle() const {
|
|
||||||
return allocation->ExportOpenGLHandle();
|
|
||||||
}
|
|
||||||
|
|
||||||
void MemoryCommit::Release() {
|
void MemoryCommit::Release() {
|
||||||
if (allocation) {
|
if (allocation) {
|
||||||
allocation->Free(begin);
|
allocation->Free(begin);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryAllocator::MemoryAllocator(const Device& device_, bool export_allocations_)
|
MemoryAllocator::MemoryAllocator(const Device& device_)
|
||||||
: device{device_}, properties{device_.GetPhysical().GetMemoryProperties().memoryProperties},
|
: device{device_}, properties{device_.GetPhysical().GetMemoryProperties().memoryProperties},
|
||||||
export_allocations{export_allocations_},
|
|
||||||
buffer_image_granularity{
|
buffer_image_granularity{
|
||||||
device_.GetPhysical().GetProperties().limits.bufferImageGranularity} {}
|
device_.GetPhysical().GetProperties().limits.bufferImageGranularity} {}
|
||||||
|
|
||||||
|
@ -271,7 +217,7 @@ bool MemoryAllocator::TryAllocMemory(VkMemoryPropertyFlags flags, u32 type_mask,
|
||||||
const u32 type = FindType(flags, type_mask).value();
|
const u32 type = FindType(flags, type_mask).value();
|
||||||
vk::DeviceMemory memory = device.GetLogical().TryAllocateMemory({
|
vk::DeviceMemory memory = device.GetLogical().TryAllocateMemory({
|
||||||
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO,
|
||||||
.pNext = export_allocations ? &EXPORT_ALLOCATE_INFO : nullptr,
|
.pNext = nullptr,
|
||||||
.allocationSize = size,
|
.allocationSize = size,
|
||||||
.memoryTypeIndex = type,
|
.memoryTypeIndex = type,
|
||||||
});
|
});
|
||||||
|
|
|
@ -41,9 +41,6 @@ public:
|
||||||
/// It will map the backing allocation if it hasn't been mapped before.
|
/// It will map the backing allocation if it hasn't been mapped before.
|
||||||
std::span<u8> Map();
|
std::span<u8> Map();
|
||||||
|
|
||||||
/// Returns an non-owning OpenGL handle, creating one if it doesn't exist.
|
|
||||||
u32 ExportOpenGLHandle() const;
|
|
||||||
|
|
||||||
/// Returns the Vulkan memory handler.
|
/// Returns the Vulkan memory handler.
|
||||||
VkDeviceMemory Memory() const {
|
VkDeviceMemory Memory() const {
|
||||||
return memory;
|
return memory;
|
||||||
|
@ -74,11 +71,10 @@ public:
|
||||||
* Construct memory allocator
|
* Construct memory allocator
|
||||||
*
|
*
|
||||||
* @param device_ Device to allocate from
|
* @param device_ Device to allocate from
|
||||||
* @param export_allocations_ True when allocations have to be exported
|
|
||||||
*
|
*
|
||||||
* @throw vk::Exception on failure
|
* @throw vk::Exception on failure
|
||||||
*/
|
*/
|
||||||
explicit MemoryAllocator(const Device& device_, bool export_allocations_);
|
explicit MemoryAllocator(const Device& device_);
|
||||||
~MemoryAllocator();
|
~MemoryAllocator();
|
||||||
|
|
||||||
MemoryAllocator& operator=(const MemoryAllocator&) = delete;
|
MemoryAllocator& operator=(const MemoryAllocator&) = delete;
|
||||||
|
@ -117,9 +113,8 @@ private:
|
||||||
/// Returns index to the fastest memory type compatible with the passed requirements.
|
/// Returns index to the fastest memory type compatible with the passed requirements.
|
||||||
std::optional<u32> FindType(VkMemoryPropertyFlags flags, u32 type_mask) const;
|
std::optional<u32> FindType(VkMemoryPropertyFlags flags, u32 type_mask) const;
|
||||||
|
|
||||||
const Device& device; ///< Device handle.
|
const Device& device; ///< Device handle.
|
||||||
const VkPhysicalDeviceMemoryProperties properties; ///< Physical device properties.
|
const VkPhysicalDeviceMemoryProperties properties; ///< Physical device properties.
|
||||||
const bool export_allocations; ///< True when memory allocations have to be exported.
|
|
||||||
std::vector<std::unique_ptr<MemoryAllocation>> allocations; ///< Current allocations.
|
std::vector<std::unique_ptr<MemoryAllocation>> allocations; ///< Current allocations.
|
||||||
VkDeviceSize buffer_image_granularity; // The granularity for adjacent offsets between buffers
|
VkDeviceSize buffer_image_granularity; // The granularity for adjacent offsets between buffers
|
||||||
// and optimal images
|
// and optimal images
|
||||||
|
|
Loading…
Reference in a new issue