summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/video_core/CMakeLists.txt1
-rw-r--r--src/video_core/renderer_vulkan/wrapper.h83
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
21namespace 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 */
28template <typename T>
29class Span {
30public:
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
78private:
79 const T* ptr = nullptr;
80 std::size_t num = 0;
81};
82
83} // namespace Vulkan::vk