summaryrefslogtreecommitdiffstats
path: root/src/video_core/vulkan_common/vulkan_wrapper.h
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/video_core/vulkan_common/vulkan_wrapper.h175
1 files changed, 142 insertions, 33 deletions
diff --git a/src/video_core/vulkan_common/vulkan_wrapper.h b/src/video_core/vulkan_common/vulkan_wrapper.h
index e86f661cb..44fce47a5 100644
--- a/src/video_core/vulkan_common/vulkan_wrapper.h
+++ b/src/video_core/vulkan_common/vulkan_wrapper.h
@@ -32,6 +32,9 @@
#pragma warning(disable : 26812) // Disable prefer enum class over enum
#endif
+VK_DEFINE_HANDLE(VmaAllocator)
+VK_DEFINE_HANDLE(VmaAllocation)
+
namespace Vulkan::vk {
/**
@@ -68,7 +71,7 @@ public:
constexpr Span(const Range& range) : ptr{std::data(range)}, num{std::size(range)} {}
/// Construct a span from a pointer and a size.
- /// This is inteded for subranges.
+ /// This is intended for subranges.
constexpr Span(const T* ptr_, std::size_t num_) noexcept : ptr{ptr_}, num{num_} {}
/// Returns the data pointer by the span.
@@ -390,11 +393,11 @@ public:
Handle(const Handle&) = delete;
Handle& operator=(const Handle&) = delete;
- /// Construct a handle transfering the ownership from another handle.
+ /// Construct a handle transferring the ownership from another handle.
Handle(Handle&& rhs) noexcept
: handle{std::exchange(rhs.handle, nullptr)}, owner{rhs.owner}, dld{rhs.dld} {}
- /// Assign the current handle transfering the ownership from another handle.
+ /// Assign the current handle transferring the ownership from another handle.
/// Destroys any previously held object.
Handle& operator=(Handle&& rhs) noexcept {
Release();
@@ -463,10 +466,10 @@ public:
Handle(const Handle&) = delete;
Handle& operator=(const Handle&) = delete;
- /// Construct a handle transfering ownership from another handle.
+ /// Construct a handle transferring ownership from another handle.
Handle(Handle&& rhs) noexcept : handle{std::exchange(rhs.handle, nullptr)}, dld{rhs.dld} {}
- /// Assign the current handle transfering the ownership from another handle.
+ /// Assign the current handle transferring the ownership from another handle.
/// Destroys any previously held object.
Handle& operator=(Handle&& rhs) noexcept {
Release();
@@ -533,12 +536,12 @@ public:
PoolAllocations(const PoolAllocations&) = delete;
PoolAllocations& operator=(const PoolAllocations&) = delete;
- /// Construct an allocation transfering ownership from another allocation.
+ /// Construct an allocation transferring ownership from another allocation.
PoolAllocations(PoolAllocations&& rhs) noexcept
: allocations{std::move(rhs.allocations)}, num{rhs.num}, device{rhs.device}, pool{rhs.pool},
dld{rhs.dld} {}
- /// Assign an allocation transfering ownership from another allocation.
+ /// Assign an allocation transferring ownership from another allocation.
PoolAllocations& operator=(PoolAllocations&& rhs) noexcept {
allocations = std::move(rhs.allocations);
num = rhs.num;
@@ -616,6 +619,138 @@ public:
}
};
+class Image {
+public:
+ explicit Image(VkImage handle_, VkDevice owner_, VmaAllocator allocator_,
+ VmaAllocation allocation_, const DeviceDispatch& dld_) noexcept
+ : handle{handle_}, owner{owner_}, allocator{allocator_},
+ allocation{allocation_}, dld{&dld_} {}
+ Image() = default;
+
+ Image(const Image&) = delete;
+ Image& operator=(const Image&) = delete;
+
+ Image(Image&& rhs) noexcept
+ : handle{std::exchange(rhs.handle, nullptr)}, owner{rhs.owner}, allocator{rhs.allocator},
+ allocation{rhs.allocation}, dld{rhs.dld} {}
+
+ Image& operator=(Image&& rhs) noexcept {
+ Release();
+ handle = std::exchange(rhs.handle, nullptr);
+ owner = rhs.owner;
+ allocator = rhs.allocator;
+ allocation = rhs.allocation;
+ dld = rhs.dld;
+ return *this;
+ }
+
+ ~Image() noexcept {
+ Release();
+ }
+
+ VkImage operator*() const noexcept {
+ return handle;
+ }
+
+ void reset() noexcept {
+ Release();
+ handle = nullptr;
+ }
+
+ explicit operator bool() const noexcept {
+ return handle != nullptr;
+ }
+
+ void SetObjectNameEXT(const char* name) const;
+
+private:
+ void Release() const noexcept;
+
+ VkImage handle = nullptr;
+ VkDevice owner = nullptr;
+ VmaAllocator allocator = nullptr;
+ VmaAllocation allocation = nullptr;
+ const DeviceDispatch* dld = nullptr;
+};
+
+class Buffer {
+public:
+ explicit Buffer(VkBuffer handle_, VkDevice owner_, VmaAllocator allocator_,
+ VmaAllocation allocation_, std::span<u8> mapped_, bool is_coherent_,
+ const DeviceDispatch& dld_) noexcept
+ : handle{handle_}, owner{owner_}, allocator{allocator_},
+ allocation{allocation_}, mapped{mapped_}, is_coherent{is_coherent_}, dld{&dld_} {}
+ Buffer() = default;
+
+ Buffer(const Buffer&) = delete;
+ Buffer& operator=(const Buffer&) = delete;
+
+ Buffer(Buffer&& rhs) noexcept
+ : handle{std::exchange(rhs.handle, nullptr)}, owner{rhs.owner}, allocator{rhs.allocator},
+ allocation{rhs.allocation}, mapped{rhs.mapped},
+ is_coherent{rhs.is_coherent}, dld{rhs.dld} {}
+
+ Buffer& operator=(Buffer&& rhs) noexcept {
+ Release();
+ handle = std::exchange(rhs.handle, nullptr);
+ owner = rhs.owner;
+ allocator = rhs.allocator;
+ allocation = rhs.allocation;
+ mapped = rhs.mapped;
+ is_coherent = rhs.is_coherent;
+ dld = rhs.dld;
+ return *this;
+ }
+
+ ~Buffer() noexcept {
+ Release();
+ }
+
+ VkBuffer operator*() const noexcept {
+ return handle;
+ }
+
+ void reset() noexcept {
+ Release();
+ handle = nullptr;
+ }
+
+ explicit operator bool() const noexcept {
+ return handle != nullptr;
+ }
+
+ /// Returns the host mapped memory, an empty span otherwise.
+ std::span<u8> Mapped() noexcept {
+ return mapped;
+ }
+
+ std::span<const u8> Mapped() const noexcept {
+ return mapped;
+ }
+
+ /// Returns true if the buffer is mapped to the host.
+ bool IsHostVisible() const noexcept {
+ return !mapped.empty();
+ }
+
+ void Flush() const;
+
+ void Invalidate() const;
+
+ void SetObjectNameEXT(const char* name) const;
+
+private:
+ void Release() const noexcept;
+
+ VkBuffer handle = nullptr;
+ VkDevice owner = nullptr;
+ VmaAllocator allocator = nullptr;
+ VmaAllocation allocation = nullptr;
+ std::span<u8> mapped = {};
+ bool is_coherent = false;
+ const DeviceDispatch* dld = nullptr;
+};
+
class Queue {
public:
/// Construct an empty queue handle.
@@ -639,17 +774,6 @@ private:
const DeviceDispatch* dld = nullptr;
};
-class Buffer : public Handle<VkBuffer, VkDevice, DeviceDispatch> {
- using Handle<VkBuffer, VkDevice, DeviceDispatch>::Handle;
-
-public:
- /// Attaches a memory allocation.
- void BindMemory(VkDeviceMemory memory, VkDeviceSize offset) const;
-
- /// Set object name.
- void SetObjectNameEXT(const char* name) const;
-};
-
class BufferView : public Handle<VkBufferView, VkDevice, DeviceDispatch> {
using Handle<VkBufferView, VkDevice, DeviceDispatch>::Handle;
@@ -658,17 +782,6 @@ public:
void SetObjectNameEXT(const char* name) const;
};
-class Image : public Handle<VkImage, VkDevice, DeviceDispatch> {
- using Handle<VkImage, VkDevice, DeviceDispatch>::Handle;
-
-public:
- /// Attaches a memory allocation.
- void BindMemory(VkDeviceMemory memory, VkDeviceSize offset) const;
-
- /// Set object name.
- void SetObjectNameEXT(const char* name) const;
-};
-
class ImageView : public Handle<VkImageView, VkDevice, DeviceDispatch> {
using Handle<VkImageView, VkDevice, DeviceDispatch>::Handle;
@@ -840,12 +953,8 @@ public:
Queue GetQueue(u32 family_index) const noexcept;
- Buffer CreateBuffer(const VkBufferCreateInfo& ci) const;
-
BufferView CreateBufferView(const VkBufferViewCreateInfo& ci) const;
- Image CreateImage(const VkImageCreateInfo& ci) const;
-
ImageView CreateImageView(const VkImageViewCreateInfo& ci) const;
Semaphore CreateSemaphore() const;