CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
GPUImage.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 "GPUFormat.hpp"
14#include "GPUMemory.hpp"
15#include "GPUResource.hpp"
16
19
26
30
31#include <ostream>
32#include <utility>
33
34namespace CeresEngine {
35
48
51 Attachment = (1u << 0u),
52
55 Sample = (1u << 1u),
56
59 Storage = (1u << 2u),
60 };
61
64
72
84 UInt32 baseArrayLayer = 0;
85
90 UInt32 numArrayLayers = 1;
91
95 UInt32 baseMipLevel = 0;
96
101 UInt32 numMipLevels = 1;
102
103 friend bool operator==(const GPUImageSubresource& lhs, const GPUImageSubresource& rhs);
104 friend bool operator!=(const GPUImageSubresource& lhs, const GPUImageSubresource& rhs);
105
106 public: // Reflection
109 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
110 CE_REFL_DATA(baseArrayLayer);
111 CE_REFL_DATA(numArrayLayers);
112 CE_REFL_DATA(baseMipLevel);
113 CE_REFL_DATA(numMipLevels);
114 }
115 };
116
125 TOffset3<UInt32> offset = {0, 0, 0};
126
132 UInt32 arrayLayer = 0;
133
137 UInt32 mipLevel = 0;
138
139 friend bool operator==(const GPUImageLocation& lhs, const GPUImageLocation& rhs);
140 friend bool operator!=(const GPUImageLocation& lhs, const GPUImageLocation& rhs);
141
142 public: // Reflection
145 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
146 CE_REFL_DATA(offset);
147 CE_REFL_DATA(arrayLayer);
148 CE_REFL_DATA(mipLevel);
149 }
150 };
151
165
171 TOffset3<UInt32> offset = {0, 0, 0};
172
174 TExtent3<UInt32> extent = {0, 0, 0};
175
176 friend bool operator==(const GPUImageRegion& lhs, const GPUImageRegion& rhs);
177 friend bool operator!=(const GPUImageRegion& lhs, const GPUImageRegion& rhs);
178
179 public: // Reflection
182 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
183 CE_REFL_DATA(subresource);
184 CE_REFL_DATA(offset);
185 CE_REFL_DATA(extent);
186 }
187 };
188
194 Zero,
195
197 One,
198
200 Red,
201
203 Green,
204
206 Blue,
207
209 Alpha
210 };
211
220
224
228
232
233 friend bool operator==(const GPUImageSwizzleRGBA& lhs, const GPUImageSwizzleRGBA& rhs);
234 friend bool operator!=(const GPUImageSwizzleRGBA& lhs, const GPUImageSwizzleRGBA& rhs);
235
236 public: // Reflection
239 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
240 CE_REFL_DATA(r);
241 CE_REFL_DATA(g);
242 CE_REFL_DATA(b);
243 CE_REFL_DATA(a);
244 }
245 };
246
250 GPUImageType type = GPUImageType::Image2D;
251
255
258 GPUMemoryProperties memoryProperty = GPUMemoryProperty::DeviceLocal;
259
261 Format format = Format::RGBA8UNorm;
262
271 TExtent3<UInt32> extent = {1, 1, 1};
272
287 UInt32 arrayLayers = 1;
288
296 UInt32 mipLevels = 1;
297
303 UInt32 samples = 1;
304
306 GPUImageLayout initialLayout = GPUImageLayout::DontCare;
307
310 String name;
311
312 friend bool operator==(const GPUImageDescriptor& lhs, const GPUImageDescriptor& rhs);
313 friend bool operator!=(const GPUImageDescriptor& lhs, const GPUImageDescriptor& rhs);
314
315 public: // Reflection
318 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
319 CE_REFL_DATA(type);
320 CE_REFL_DATA(usage);
321 CE_REFL_DATA(memoryProperty);
322 CE_REFL_DATA(format);
323 CE_REFL_DATA(extent);
324 CE_REFL_DATA(arrayLayers);
325 CE_REFL_DATA(mipLevels);
326 CE_REFL_DATA(samples);
327 CE_REFL_DATA(name);
328 }
329 };
330
331 class CE_SCRIPT_EXPORT() GPUImage : public TDeviceObject<GPUImageDescriptor, GPUResource> {
332 public:
334 using TDeviceObject::TDeviceObject;
335
337 GPUImage(const GPUImage&) = delete;
338 GPUImage& operator=(const GPUImage&) = delete;
339
341 GPUImage(GPUImage&&) = delete;
343
344 public:
345#if 0
354 Async<ByteBuffer> read(BufferSize offset = 0, BufferSize size = ~0u);
355
367 Async<ByteBuffer> read(CommandBuffer& commandBuffer, BufferSize offset = 0,
368 BufferSize size = ~0u);
369
380 Async<> write(ByteBuffer&& rawData, BufferSize offset = 0, BufferSize size = ~0u);
381
395 Async<> write(CommandBuffer& commandBuffer, ByteBuffer&& rawData,
396 BufferSize offset = 0, BufferSize size = ~0u);
397#endif
398
399 public:
406 virtual GPUImageViewPtr createView(const GPUImageViewDescriptor& descriptor) = 0;
407
408 public:
419 [[nodiscard]] CE_SCRIPT_EXPORT()
420 static UInt32 numMipLevels(UInt32 width, UInt32 height = 1, UInt32 depth = 1) noexcept;
421
429 [[nodiscard]] CE_SCRIPT_EXPORT()
430 static UInt32 numMipLevels(const GPUImageDescriptor& imageDesc) noexcept;
431
443 [[nodiscard]] CE_SCRIPT_EXPORT()
444 static UInt32 bufferSize(Format format, UInt32 numTexels) noexcept;
445
448 [[nodiscard]] CE_SCRIPT_EXPORT()
449 static UInt32 size(const GPUImageDescriptor& imageDesc) noexcept;
450
456 [[nodiscard]] CE_SCRIPT_EXPORT()
457 static bool isMipMapped(const GPUImageDescriptor& imageDesc) noexcept;
458
463 [[nodiscard]] CE_SCRIPT_EXPORT()
464 static bool isArray(GPUImageType type) noexcept;
465
469 [[nodiscard]] CE_SCRIPT_EXPORT()
470 static bool isMultiSample(GPUImageType type) noexcept;
471
475 [[nodiscard]] CE_SCRIPT_EXPORT()
476 static bool isCube(GPUImageType type) noexcept;
477 };
478
485 GPUImageType type = GPUImageType::Image2D;
486
491 Format format = Format::Undefined;
492
498
506
510 String name;
511
512 friend bool operator==(const GPUImageViewDescriptor& lhs, const GPUImageViewDescriptor& rhs);
513 friend bool operator!=(const GPUImageViewDescriptor& lhs, const GPUImageViewDescriptor& rhs);
514
515 public: // Reflection
518 template<typename Processor> static constexpr void reflect(Processor&& RTTI) {
519 CE_REFL_DATA(type);
520 CE_REFL_DATA(format);
521 CE_REFL_DATA(subresource);
522 CE_REFL_DATA(swizzle);
523 CE_REFL_DATA(name);
524 }
525 };
526
527 class CE_SCRIPT_EXPORT() GPUImageView : public TDeviceObject<GPUImageViewDescriptor> {
528 public:
531 GPUImage& image;
532
533 public:
535 explicit GPUImageView(GPUImage& image, const GPUImageViewDescriptor& descriptor);
536
538 ~GPUImageView() override;
539
541 GPUImageView(const GPUImageView&) = delete;
542 GPUImageView& operator=(const GPUImageView&) = delete;
543
546 GPUImageView& operator=(GPUImageView&&) = delete;
547 };
548
550 StringView toString(GPUImageType type);
551
553 std::ostream& operator<<(std::ostream& os, GPUImageType type);
554
556 StringView toString(GPUImageLayout layout);
557
559 std::ostream& operator<<(std::ostream& os, GPUImageLayout layout);
560
562 String toString(const GPUImageDescriptor& descriptor);
563
565 std::ostream& operator<<(std::ostream& os, const GPUImageDescriptor& descriptor);
566
567} // namespace CeresEngine
568
571
574
577
580
583
#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
A retain-release type of smart pointer.
Definition SmartPtr.hpp:132
Definition GPUImage.hpp:331
GPUImage(GPUImage &&)=delete
Deleted move constructor.
GPUImage & operator=(const GPUImage &)=delete
GPUImage & operator=(GPUImage &&)=delete
GPUImage(const GPUImage &)=delete
Deleted copy constructor.
Definition GPUImage.hpp:527
Definition Common.hpp:62
Definition Application.hpp:19
GPUImageSwizzle
Image component swizzle enumeration.
Definition GPUImage.hpp:192
@ Alpha
The component is replaced by alpha component.
@ Blue
The component is replaced by blue component.
@ Green
The component is replaced by green component.
@ Red
The component is replaced by red component.
GPUImageUsageFlags
Definition GPUImage.hpp:49
@ Sample
Image can be used for sampling (e.g.
@ Attachment
Image can be used as render target attachment.
cti::continuable< Args... > Async
Defines a non-copyable continuation type which uses the function2 backend for type erasure.
Definition Async.hpp:22
GPUImageLayout
Definition GPUImage.hpp:65
@ One
Data source is the color white (1, 1, 1, 1).
GPUMemoryProperty
Flag specifying properties for a memory type.
Definition GPUMemory.hpp:18
Format
Definition TextureFormat.hpp:54
@ Zero
Set stencil data to 0.
GPUImageType
Definition GPUImage.hpp:36
@ Image3D
3-Dimensional image.
@ Image2DArray
2-Dimensional array image.
@ Image1D
1-Dimensional image.
@ ImageCubeArray
Cube array image.
@ Image2DMSArray
2-Dimensional multi-sample array image.
@ Image2D
2-Dimensional image.
@ Image1DArray
1-Dimensional array image.
@ Image2DMS
2-Dimensional multi-sample image.
@ Storage
Storage buffer type (also called "Shader Storage Buffer Object" or "Read/Write Buffer").
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
Definition Span.hpp:668
Definition GPUImage.hpp:247
Image location structure: MIP-map level and offset.
Definition GPUImage.hpp:120
Image region structure: Subresource (MIP-map level and array layer range), offset,...
Definition GPUImage.hpp:156
friend bool operator==(const GPUImageRegion &lhs, const GPUImageRegion &rhs)
friend bool operator!=(const GPUImageRegion &lhs, const GPUImageRegion &rhs)
static constexpr void reflect(Processor &&RTTI)
Executes the given processor for every field of the struct.
Definition GPUImage.hpp:182
Image subresource descriptor which specifies the array layer and MIP-map level range of a image resou...
Definition GPUImage.hpp:77
Image component swizzle structure for red, green, blue, and alpha components.
Definition GPUImage.hpp:216
Image view descriptor structure.
Definition GPUImage.hpp:482