CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
GPUBuffer.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
10#include "Common.hpp"
11#include "Forward.hpp"
12
13#include "GPUMemory.hpp"
14#include "GPUResource.hpp"
15#include "GPUVertexFormat.hpp"
16
19
26
27#include <function2/function2.hpp>
28
29namespace CeresEngine {
30
34 Generic,
35
37 Vertex,
38
40 Index,
41
43 Uniform,
44
47 Storage,
48
51 };
52
55 Automatic = 0u,
56
59 Source = (1u << 0u),
60
63 Destination = (1u << 1u),
64
67 Uniform = (1u << 2u),
68
71 Index = (1u << 3u),
72
75 Vertex = (1u << 4u),
76 Storage = (1u << 5u),
77
79 Indirect = (1u << 6u),
80 };
81
84
87
90
96
100
103 GPUMemoryProperties memoryProperty = GPUMemoryProperty::HostVisible;
104
108
111 String name;
112
115 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
116 CE_REFL_DATA(type);
117 CE_REFL_DATA(usage);
118 CE_REFL_DATA(memoryProperty);
119 CE_REFL_DATA(size);
120 CE_REFL_DATA(name);
121 }
122 };
123
124 class CE_SCRIPT_EXPORT() GPUBuffer : public TDeviceObject<GPUBufferDescriptor, GPUResource> {
125 public:
127 static inline const constexpr GPUBufferSize whole = ~0UL;
128
129 public:
131 using TDeviceObject::TDeviceObject;
132
134 GPUBuffer(const GPUBuffer&) = delete;
135 GPUBuffer& operator=(const GPUBuffer&) = delete;
136
138 GPUBuffer(GPUBuffer&&) = delete;
140
141 public:
150 [[nodiscard]] Async<ByteBuffer> read(GPUBufferSize offset = 0, GPUBufferSize size = whole);
151
163 [[nodiscard]] Async<ByteBuffer> read(GPUCommandBuffer& commandBuffer, GPUBufferSize offset = 0, GPUBufferSize size = whole);
164
175 Async<> write(ByteBuffer&& rawData, GPUBufferSize offset = 0, GPUBufferSize size = whole);
176
190 Async<> write(GPUCommandBuffer& commandBuffer, ByteBuffer&& rawData, GPUBufferSize offset = 0, GPUBufferSize size = whole);
191
194 [[nodiscard]] virtual GPUBufferData map() = 0;
195
198 virtual void unmap() = 0;
199
201 [[nodiscard]] CE_SCRIPT_EXPORT()
202 virtual GPUBufferSize getSize() const = 0;
203
209 virtual void flush(GPUBufferSize offset = 0, GPUBufferSize size = whole) = 0;
210
216 virtual void invalidate(GPUBufferSize offset = 0, GPUBufferSize size = whole) = 0;
217
218 public:
223 template<typename Block> void data(Block&& block) {
224 const GPUBufferData mapped = map();
225 block(mapped);
226 unmap();
227 }
228 };
229
233
234 public: // Reflection
237 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
240 }
241 };
242
243} // namespace CeresEngine
244
247
#define CE_FLAGS_OPERATORS(Enum)
Defines global operators for a Flags<Enum, Storage> implementation.
Definition Flags.hpp:216
#define CE_REFLECT_HASH(T)
Definition Hash.hpp:89
#define CE_REFL_DATA(N)
Definition Macros.hpp:541
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
Represents a secure buffer i.e.
Definition Buffer.hpp:28
Definition GPUBuffer.hpp:124
GPUBuffer(GPUBuffer &&)=delete
Deleted move constructor.
static const constexpr GPUBufferSize whole
A constant the represents the whole buffer length.
Definition GPUBuffer.hpp:127
GPUBuffer & operator=(const GPUBuffer &)=delete
Async< ByteBuffer > read(GPUBufferSize offset=0, GPUBufferSize size=whole)
Performs an asynchronous read operation on the buffer.
Async write(ByteBuffer &&rawData, GPUBufferSize offset=0, GPUBufferSize size=whole)
Performs an asynchronous write operation on the buffer.
Async< ByteBuffer > read(GPUCommandBuffer &commandBuffer, GPUBufferSize offset=0, GPUBufferSize size=whole)
Performs an asynchronous read operation on the buffer in an specific command buffer.
virtual GPUBufferData map()=0
Maps the buffer into the computers memory.
GPUBuffer(const GPUBuffer &)=delete
Deleted copy constructor.
Async write(GPUCommandBuffer &commandBuffer, ByteBuffer &&rawData, GPUBufferSize offset=0, GPUBufferSize size=whole)
Performs an asynchronous write operation on the buffer in an specific command buffer.
GPUBuffer & operator=(GPUBuffer &&)=delete
Definition GPUCommandBuffer.hpp:77
Definition Common.hpp:62
Definition Application.hpp:19
std::uint64_t UInt64
Definition DataTypes.hpp:26
GPUMemoryData GPUBufferData
A pointer type that represents the buffer raw data.
Definition GPUBuffer.hpp:89
cti::continuable< Args... > Async
Defines a non-copyable continuation type which uses the function2 backend for type erasure.
Definition Async.hpp:22
GPUMemoryProperty
Flag specifying properties for a memory type.
Definition GPUMemory.hpp:18
void * GPUMemoryData
A pointer type that represents the memory raw data.
Definition GPUMemory.hpp:61
GPUBufferUsageFlag
Definition GPUBuffer.hpp:53
@ Automatic
Automatically defines the buffer usage based on type.
@ Destination
Specifies that the buffer can be used as the destination of a transfer command.
UInt64 GPUMemorySize
A type that represents a memory size.
Definition GPUMemory.hpp:58
GPUMemorySize GPUBufferSize
A type that represents a buffer size.
Definition GPUBuffer.hpp:86
GPUBufferType
Hardware buffer type enumeration.
Definition GPUBuffer.hpp:32
@ Indirect
Indirect draw buffer type.
@ Generic
Generic buffer type. Can be used for multiple purposes.
@ Index
Index buffer type.
@ Storage
Storage buffer type (also called "Shader Storage Buffer Object" or "Read/Write Buffer").
@ Uniform
Uniform buffer type (also called "Constant Buffer Object").
@ Source
Refers to a high-level source code.
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Hardware buffer descriptor structure.
Definition GPUBuffer.hpp:92
Definition GPUBuffer.hpp:230
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition GPUBuffer.hpp:237
UInt64 size
Definition GPUBuffer.hpp:232
UInt64 offset
Definition GPUBuffer.hpp:231
A basic vertex type.
Definition Mesh.hpp:51