Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
GPUObjects.hpp
1#pragma once
2
3#include "Common.hpp"
4#include "graphics/GPUTypes.hpp"
5
6#undef VK_NULL_HANDLE
7#undef VK_DEFINE_HANDLE
8#include <volk/volk.h>
9
10// Forward declarations.
11VK_DEFINE_HANDLE(VmaAllocation);
12class Buffer;
13
19public:
23 GPUTexture(const Layout & layoutFormat);
24
26 void clean();
27
31 GPUTexture & operator=(const GPUTexture &) = delete;
32
34 GPUTexture(const GPUTexture &) = delete;
35
40
42 GPUTexture(GPUTexture &&) = delete;
43
48 static unsigned int getChannelsCount(const Layout& format);
49
54 static bool isSRGB(const Layout& format);
55
56 VkFormat format;
57 VkImageAspectFlags aspect;
58
59 uint channels;
60
61 VkImage image = VK_NULL_HANDLE;
62 VkImageView view = VK_NULL_HANDLE;
63
65 struct MipViews {
66 std::vector<VkImageView> views;
67 VkImageView mipView;
68 };
69 std::vector<MipViews> views;
70
71 VmaAllocation data = VK_NULL_HANDLE;
72 ImTextureID imgui = (ImTextureID)VK_NULL_HANDLE;
73
74 std::vector<std::vector<VkImageLayout>> layouts;
75 VkImageLayout defaultLayout;
76
77 bool owned = true;
78
79};
80
81
86class GPUBuffer {
87public:
88
92 GPUBuffer(BufferType atype);
93
95 void clean();
96
100 GPUBuffer & operator=(const GPUBuffer &) = delete;
101
103 GPUBuffer(const GPUBuffer &) = delete;
104
109
111 GPUBuffer(GPUBuffer &&) = delete;
112
113 VkBuffer buffer = VK_NULL_HANDLE;
114 VmaAllocation data = VK_NULL_HANDLE;
115 char* mapped = nullptr;
116 bool mappable = false;
117
118};
119
120
125class GPUMesh {
126public:
127
128 std::unique_ptr<Buffer> vertexBuffer;
129 std::unique_ptr<Buffer> indexBuffer;
130
131 size_t count = 0;
132
134 void clean();
135
140 bool isEquivalent(const GPUMesh& other) const;
141
143 GPUMesh() = default;
144
148 GPUMesh & operator=(const GPUMesh &) = delete;
149
151 GPUMesh(const GPUMesh &) = delete;
152
156 GPUMesh & operator=(GPUMesh &&) = delete;
157
159 GPUMesh(GPUMesh &&) = delete;
160
162 struct State {
163 std::vector<VkVertexInputAttributeDescription> attributes;
164 std::vector<VkVertexInputBindingDescription> bindings;
165 std::vector<VkBuffer> buffers;
166 std::vector<VkDeviceSize> offsets;
167
172 bool isEquivalent(const State& other) const;
173 };
174
176};
General purpose GPU buffer, with different use types determining its memory type, visibility and acce...
Definition: Buffer.hpp:10
Store data in a GPU buffer.
Definition: GPUObjects.hpp:86
GPUBuffer & operator=(const GPUBuffer &)=delete
char * mapped
If the buffer is CPU-mappable, its CPU address.
Definition: GPUObjects.hpp:115
GPUBuffer(const GPUBuffer &)=delete
void clean()
Definition: GPUObjects.cpp:39
GPUBuffer & operator=(GPUBuffer &&)=delete
VmaAllocation data
Internal allocation.
Definition: GPUObjects.hpp:114
bool mappable
Is the buffer mappable on the CPU.
Definition: GPUObjects.hpp:116
GPUBuffer(GPUBuffer &&)=delete
VkBuffer buffer
Buffer native handle.
Definition: GPUObjects.hpp:113
Store vertices and triangles data on the GPU, linked by an array object.
Definition: GPUObjects.hpp:125
size_t count
The number of vertices (cached).
Definition: GPUObjects.hpp:131
bool isEquivalent(const GPUMesh &other) const
Definition: GPUObjects.cpp:57
GPUMesh(GPUMesh &&)=delete
void clean()
Definition: GPUObjects.cpp:43
GPUMesh(const GPUMesh &)=delete
std::unique_ptr< Buffer > indexBuffer
Index element buffer.
Definition: GPUObjects.hpp:129
std::unique_ptr< Buffer > vertexBuffer
Vertex data buffer.
Definition: GPUObjects.hpp:128
State state
Internal GPU layout.
Definition: GPUObjects.hpp:175
GPUMesh()=default
GPUMesh & operator=(const GPUMesh &)=delete
GPUMesh & operator=(GPUMesh &&)=delete
Store a texture data on the GPU.
Definition: GPUObjects.hpp:18
VkImageLayout defaultLayout
Default layout to restore to in some cases.
Definition: GPUObjects.hpp:75
GPUTexture(GPUTexture &&)=delete
void clean()
Definition: GPUObjects.cpp:20
ImTextureID imgui
ImGui compatible handle (internally a descriptor set).
Definition: GPUObjects.hpp:72
std::vector< MipViews > views
Per-mip image views.
Definition: GPUObjects.hpp:69
GPUTexture(const GPUTexture &)=delete
static bool isSRGB(const Layout &format)
Definition: GPUObjects.cpp:31
std::vector< std::vector< VkImageLayout > > layouts
Per-mip per-layer image layout.
Definition: GPUObjects.hpp:74
GPUTexture & operator=(GPUTexture &&)=delete
VkImage image
Native image handle.
Definition: GPUObjects.hpp:61
uint channels
Number of channels.
Definition: GPUObjects.hpp:59
VmaAllocation data
Internal allocation.
Definition: GPUObjects.hpp:71
VkFormat format
Texture native format.
Definition: GPUObjects.hpp:56
bool owned
Do we own our Vulkan data (not the case for swapchain images).
Definition: GPUObjects.hpp:77
VkImageAspectFlags aspect
Texture aspects.
Definition: GPUObjects.hpp:57
static unsigned int getChannelsCount(const Layout &format)
Definition: GPUObjects.cpp:26
VkImageView view
Native main image view (all mips).
Definition: GPUObjects.hpp:62
GPUTexture & operator=(const GPUTexture &)=delete
BufferType
The type of data a buffer is storing, determining its use.
Definition: GPUTypes.hpp:33
Layout
The layout of a texture: components count and type.
Definition: GPUTypes.hpp:225
Internal GPU state for pipeline compatibility.
Definition: GPUObjects.hpp:162
std::vector< VkVertexInputBindingDescription > bindings
List of bindings.
Definition: GPUObjects.hpp:164
std::vector< VkVertexInputAttributeDescription > attributes
List of attributes.
Definition: GPUObjects.hpp:163
bool isEquivalent(const State &other) const
Definition: GPUObjects.cpp:61
std::vector< VkDeviceSize > offsets
Offsets in each buffer.
Definition: GPUObjects.hpp:166
std::vector< VkBuffer > buffers
Buffers used.
Definition: GPUObjects.hpp:165
Aggregate views for each view.
Definition: GPUObjects.hpp:65
std::vector< VkImageView > views
Views covering each layer of the mip, separately.
Definition: GPUObjects.hpp:66
VkImageView mipView
View covering all layers of the mip.
Definition: GPUObjects.hpp:67