diff options
| author | 2020-03-27 02:44:29 -0300 | |
|---|---|---|
| committer | 2020-03-27 03:13:18 -0300 | |
| commit | 92c8d783b3dfb3f6a264ec75cacd42f01a950046 (patch) | |
| tree | 6a96250c0b5ca2696b93582cb05af9d873f471b9 /src | |
| parent | Merge pull request #3544 from makigumo/myfork/patch-2 (diff) | |
| download | yuzu-92c8d783b3dfb3f6a264ec75cacd42f01a950046.tar.gz yuzu-92c8d783b3dfb3f6a264ec75cacd42f01a950046.tar.xz yuzu-92c8d783b3dfb3f6a264ec75cacd42f01a950046.zip | |
renderer_vulkan/wrapper: Add Vulakn wrapper and a span helper
The intention behind a Vulkan wrapper is to drop Vulkan-Hpp.
The issues with Vulkan-Hpp are:
- Regular breaks of the API.
- Copy constructors that do the same as the aggregates (fixed recently)
- External dynamic dispatch that is hard to remove
- Alias KHR handles with non-KHR handles making it impossible to use
smart handles on Vulkan 1.0 instances with extensions that were included
on Vulkan 1.1.
- Dynamic dispatchers silently change size depending on preprocessor
definitions. Different files will have different dispatch definitions,
generating all kinds of hard to debug memory issues.
In other words, Vulkan-Hpp is not "production ready" for our needs and
this wrapper aims to replace it without losing RAII and exception
safety.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/wrapper.h | 83 |
2 files changed, 84 insertions, 0 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 91df062d7..a8ae3827d 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt | |||
| @@ -210,6 +210,7 @@ if (ENABLE_VULKAN) | |||
| 210 | renderer_vulkan/vk_texture_cache.h | 210 | renderer_vulkan/vk_texture_cache.h |
| 211 | renderer_vulkan/vk_update_descriptor.cpp | 211 | renderer_vulkan/vk_update_descriptor.cpp |
| 212 | renderer_vulkan/vk_update_descriptor.h | 212 | renderer_vulkan/vk_update_descriptor.h |
| 213 | renderer_vulkan/wrapper.h | ||
| 213 | ) | 214 | ) |
| 214 | 215 | ||
| 215 | target_include_directories(video_core PRIVATE sirit ../../externals/Vulkan-Headers/include) | 216 | target_include_directories(video_core PRIVATE sirit ../../externals/Vulkan-Headers/include) |
diff --git a/src/video_core/renderer_vulkan/wrapper.h b/src/video_core/renderer_vulkan/wrapper.h new file mode 100644 index 000000000..7ed4cdb3a --- /dev/null +++ b/src/video_core/renderer_vulkan/wrapper.h | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | // Copyright 2020 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <exception> | ||
| 8 | #include <iterator> | ||
| 9 | #include <limits> | ||
| 10 | #include <memory> | ||
| 11 | #include <optional> | ||
| 12 | #include <type_traits> | ||
| 13 | #include <utility> | ||
| 14 | #include <vector> | ||
| 15 | |||
| 16 | #define VK_NO_PROTOTYPES | ||
| 17 | #include <vulkan/vulkan.h> | ||
| 18 | |||
| 19 | #include "common/common_types.h" | ||
| 20 | |||
| 21 | namespace Vulkan::vk { | ||
| 22 | |||
| 23 | /** | ||
| 24 | * Span for Vulkan arrays. | ||
| 25 | * Based on std::span but optimized for array access instead of iterators. | ||
| 26 | * Size returns uint32_t instead of size_t to ease interaction with Vulkan functions. | ||
| 27 | */ | ||
| 28 | template <typename T> | ||
| 29 | class Span { | ||
| 30 | public: | ||
| 31 | /// Construct an empty span. | ||
| 32 | constexpr Span() noexcept = default; | ||
| 33 | |||
| 34 | /// Construct a span from a single element. | ||
| 35 | constexpr Span(const T& value) noexcept : ptr{&value}, num{1} {} | ||
| 36 | |||
| 37 | /// Construct a span from a range. | ||
| 38 | template <typename Range> | ||
| 39 | // requires std::data(const Range&) | ||
| 40 | // requires std::size(const Range&) | ||
| 41 | constexpr Span(const Range& range) : ptr{std::data(range)}, num{std::size(range)} {} | ||
| 42 | |||
| 43 | /// Construct a span from a pointer and a size. | ||
| 44 | /// This is inteded for subranges. | ||
| 45 | constexpr Span(const T* ptr, std::size_t num) noexcept : ptr{ptr}, num{num} {} | ||
| 46 | |||
| 47 | /// Returns the data pointer by the span. | ||
| 48 | constexpr const T* data() const noexcept { | ||
| 49 | return ptr; | ||
| 50 | } | ||
| 51 | |||
| 52 | /// Returns the number of elements in the span. | ||
| 53 | constexpr u32 size() const noexcept { | ||
| 54 | return static_cast<u32>(num); | ||
| 55 | } | ||
| 56 | |||
| 57 | /// Returns true when the span is empty. | ||
| 58 | constexpr bool empty() const noexcept { | ||
| 59 | return num == 0; | ||
| 60 | } | ||
| 61 | |||
| 62 | /// Returns a reference to the element in the passed index. | ||
| 63 | /// @pre: index < size() | ||
| 64 | constexpr const T& operator[](std::size_t index) const noexcept { | ||
| 65 | return ptr[index]; | ||
| 66 | } | ||
| 67 | |||
| 68 | /// Returns an iterator to the beginning of the span. | ||
| 69 | constexpr const T* begin() const noexcept { | ||
| 70 | return ptr; | ||
| 71 | } | ||
| 72 | |||
| 73 | /// Returns an iterator to the end of the span. | ||
| 74 | constexpr const T* end() const noexcept { | ||
| 75 | return ptr + num; | ||
| 76 | } | ||
| 77 | |||
| 78 | private: | ||
| 79 | const T* ptr = nullptr; | ||
| 80 | std::size_t num = 0; | ||
| 81 | }; | ||
| 82 | |||
| 83 | } // namespace Vulkan::vk | ||