CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
GPUShader.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 "GPUResource.hpp"
14#include "GPUVertexFormat.hpp"
15
18
24
26
27#include <utility>
28#include <variant>
29
30namespace CeresEngine {
31
37 enum class CE_SCRIPT_EXPORT() GPUPipelineStage : unsigned int {
39 Vertex = (1u << 0u),
40
43 TesselationControl = (1u << 1u),
44
47 TesselationEvaluation = (1u << 2u),
48
50 Geometry = (1u << 3u),
51
53 Fragment = (1u << 4u),
54
56 Compute = (1u << 5u),
57
59 Task = (1u << 6u),
60
62 Mesh = (1u << 7u),
63
65 RayTracingRayGeneration = (1u << 8u),
66
68 RayTracingAnyHit = (1u << 9u),
69
71 RayTracingClosestHit = (1u << 10u),
72
74 RayTracingMiss = (1u << 11u),
75
77 RayTracingIntersection = (1u << 12u),
78
80 RayTracingCallable = (1u << 13u),
81
88 ReadOnlyResource = (1u << 31u),
89
93
97
99 All = (Graphics | Compute),
100 };
101
104
124 struct DescriptorView final {
128 String name;
129
134
141
144 UInt32 slot = 0;
145
148 UInt32 set = 0;
149
155 UInt32 arraySize = 1;
156
163 UInt32 uniformBufferSize = 0;
164
167 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
168 CE_REFL_DATA(name);
169 CE_REFL_DATA(type);
170 CE_REFL_DATA(stages);
171 CE_REFL_DATA(slot);
172 CE_REFL_DATA(set);
173 CE_REFL_DATA(arraySize);
174 CE_REFL_DATA(uniformBufferSize);
175 }
176 };
177
180
183
186 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
187 CE_REFL_DATA(vertexAttributes);
188 CE_REFL_DATA(descriptorViews);
189 }
190 };
191
197 ShaderType type = ShaderType::Undefined;
198
202 String source = "";
203
207 ShaderSourceType sourceType = ShaderSourceType::Binary;
208
211 String profile = "";
212
216 String name;
217
220
223 GPUShaderDescriptor& operator=(const GPUShaderDescriptor&) = default;
224
227 inline GPUShaderDescriptor(const ShaderType type, String source) : type{type}, source{std::move(source)} {}
228
232 inline GPUShaderDescriptor(const ShaderType type, String source, String profile) : type{type}, source{std::move(source)}, profile{std::move(profile)} {}
233
236 CE_EXPLICIT(false) inline GPUShaderDescriptor(const ShaderBinary& binary) // NOLINT
237 : type(binary.type), source(binary.data.data(), binary.data.size()), sourceType(ShaderSourceType::Binary) {}
238
241 CE_EXPLICIT(false) inline GPUShaderDescriptor(const ShaderSource& source) // NOLINT
242 : type(source.type), source(source.source), sourceType(ShaderSourceType::Source) {}
243
244 public:
247 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
248 CE_REFL_DATA(type);
249 CE_REFL_DATA(source);
250 CE_REFL_DATA(sourceType);
251 CE_REFL_DATA(profile);
252 CE_REFL_DATA(name);
253 }
254 };
255
256 class CE_SCRIPT_EXPORT() GPUShader : public TDeviceObject<GPUShaderDescriptor> {
257 public:
261
262 public:
264 explicit GPUShader(GPUDevice& device, const Descriptor& descriptor, const GPUShaderReflectionDescriptor& reflection)
265 : TDeviceObject(device, descriptor), reflection(reflection) {}
266
268 GPUShader(const GPUShader&) = delete;
269 GPUShader& operator=(const GPUShader&) = delete;
270
272 GPUShader(GPUShader&&) = delete;
274
275 public:
278 [[nodiscard]] CE_SCRIPT_EXPORT()
279 const GPUShaderReflectionDescriptor& reflect() const { return reflection; }
280 };
281
286 GPUShaderPtr shader = nullptr;
287
292 String entryPoint = "";
293
296 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
297 CE_REFL_DATA(shader);
298 CE_REFL_DATA(entryPoint);
299 }
300 };
301
310
317
323 GPUShaderProgramStageDescriptor tesselationEvaluation;
324
328
335
341
345 String name;
346
347 public:
350 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
351 CE_REFL_DATA(vertex);
352 CE_REFL_DATA(tesselationControl);
353 CE_REFL_DATA(tesselationEvaluation);
354 CE_REFL_DATA(geometry);
355 CE_REFL_DATA(fragment);
356 CE_REFL_DATA(compute);
357 CE_REFL_DATA(name);
358 }
359 };
360
361 class CE_SCRIPT_EXPORT() GPUShaderProgram : public TDeviceObject<GPUShaderProgramDescriptor> {
362 public:
366
367 public:
369 explicit GPUShaderProgram(GPUDevice& device, const Descriptor& descriptor, const GPUShaderReflectionDescriptor& reflection)
370 : TDeviceObject(device, descriptor), reflection(reflection) {}
371
373 using TDeviceObject::TDeviceObject;
374
378
382
383 public:
386 [[nodiscard]] CE_SCRIPT_EXPORT()
387 const GPUShaderReflectionDescriptor& reflect() const { return reflection; }
388
394 [[nodiscard]] virtual GPUPipelineLayoutPtr getPipelineLayout() const = 0;
395 };
396
397} // namespace CeresEngine
398
401
404
407
410
413
416
419
420
#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
#define CE_EXPLICIT(EXPR)
Definition Macros.hpp:413
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Definition GPUDevice.hpp:357
Definition GPUShader.hpp:256
GPUShader(GPUDevice &device, const Descriptor &descriptor, const GPUShaderReflectionDescriptor &reflection)
Initializes a new Shader object instance.
Definition GPUShader.hpp:264
const GPUShaderReflectionDescriptor & reflection
The shader reflection descriptor.
Definition GPUShader.hpp:260
GPUShader & operator=(const GPUShader &)=delete
GPUShader & operator=(GPUShader &&)=delete
GPUShader(const GPUShader &)=delete
Deleted copy constructor.
GPUShader(GPUShader &&)=delete
Deleted move constructor.
Definition GPUShader.hpp:361
GPUShaderProgram(const GPUShaderProgram &)=delete
Deleted copy constructor.
const GPUShaderReflectionDescriptor & reflection
The shader reflection descriptor.
Definition GPUShader.hpp:365
GPUShaderProgram & operator=(const GPUShaderProgram &)=delete
GPUShaderProgram & operator=(GPUShaderProgram &&)=delete
GPUShaderProgram(GPUDevice &device, const Descriptor &descriptor, const GPUShaderReflectionDescriptor &reflection)
Initializes a new ShaderProgram object instance.
Definition GPUShader.hpp:369
GPUShaderProgram(GPUShaderProgram &&)=delete
Deleted move constructor.
virtual GPUPipelineLayoutPtr getPipelineLayout() const =0
The pipeline layout deduced for this shader program.
A base class for all mesh implementations.
Definition Mesh.hpp:112
A ShaderBinary is an object responsible for wrapping the binary representation of a shader (i....
Definition ShaderSource.hpp:40
A ShaderSource is an object responsible for wrapping the textual representation of a shader (i....
Definition ShaderSource.hpp:112
Definition Common.hpp:62
Definition Application.hpp:19
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
GPUResourceType
An enumeration of supported resource types.
Definition GPUResource.hpp:15
ShaderSourceType
Shader source type enumeration.
Definition ShaderSource.hpp:21
std::uint32_t UInt32
Definition DataTypes.hpp:23
GPUPipelineStage
Shader stage flags enumeration.
Definition GPUShader.hpp:37
@ ReadOnlyResource
Specifies whether a resource is bound to the shader stages for reading only.
@ Tesselation
Specifies all tessellation stages, i.e.
@ All
Specifies all shader stages.
@ Graphics
Specifies all graphics pipeline shader stages, i.e.
@ Fragment
Specifies the fragment shader stage (also "Pixel Shader").
@ TesselationEvaluation
Specifies the tessellation-evaluation shader stage (also "Domain Shader").
@ TesselationControl
Specifies the tessellation-control shader stage (also "Hull Shader").
@ Compute
Specifies the compute shader stage.
@ Geometry
Specifies the geometry shader stage.
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Shader source and binary code descriptor structure.
Definition GPUShader.hpp:193
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition GPUShader.hpp:247
Descriptor structure for shader programs.
Definition GPUShader.hpp:303
Shader reflection descriptor view structure.
Definition GPUShader.hpp:124
Shader reflection descriptor structure.
Definition GPUShader.hpp:108
Vector< GPUVertexAttribute > vertexAttributes
List of all vertex attributes.
Definition GPUShader.hpp:179
Vector< DescriptorView > descriptorViews
List of all shader reflection descriptor views.
Definition GPUShader.hpp:182
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition GPUShader.hpp:186
Shader type enumeration.
Definition ShaderType.hpp:59
A basic vertex type.
Definition Mesh.hpp:51