37
37
#include < array>
38
38
#include < type_traits>
39
39
#include < variant>
40
+ #include < string_view>
40
41
41
42
#include < stddef.h>
42
43
#include < stdint.h>
@@ -159,7 +160,7 @@ enum class TimerQueryResult : int8_t {
159
160
AVAILABLE = 1 , // result is available
160
161
};
161
162
162
- static constexpr const char * backendToString (Backend backend) {
163
+ constexpr std::string_view to_string (Backend const backend) noexcept {
163
164
switch (backend) {
164
165
case Backend::NOOP:
165
166
return " Noop" ;
@@ -171,9 +172,11 @@ static constexpr const char* backendToString(Backend backend) {
171
172
return " Metal" ;
172
173
case Backend::WEBGPU:
173
174
return " WebGPU" ;
174
- default :
175
- return " Unknown" ;
175
+ case Backend::DEFAULT:
176
+ return " Default" ;
177
+ break ;
176
178
}
179
+ return " Unknown" ;
177
180
}
178
181
179
182
/* *
@@ -190,7 +193,7 @@ enum class ShaderLanguage {
190
193
WGSL = 5 ,
191
194
};
192
195
193
- static constexpr const char * shaderLanguageToString (ShaderLanguage shaderLanguage) {
196
+ constexpr const char * shaderLanguageToString (ShaderLanguage shaderLanguage) noexcept {
194
197
switch (shaderLanguage) {
195
198
case ShaderLanguage::ESSL1:
196
199
return " ESSL 1.0" ;
@@ -205,6 +208,7 @@ static constexpr const char* shaderLanguageToString(ShaderLanguage shaderLanguag
205
208
case ShaderLanguage::WGSL:
206
209
return " WGSL" ;
207
210
}
211
+ return " UNKNOWN" ;
208
212
}
209
213
210
214
enum class ShaderStage : uint8_t {
@@ -222,7 +226,7 @@ enum class ShaderStageFlags : uint8_t {
222
226
ALL_SHADER_STAGE_FLAGS = VERTEX | FRAGMENT | COMPUTE
223
227
};
224
228
225
- static inline constexpr bool hasShaderType (ShaderStageFlags flags, ShaderStage type) noexcept {
229
+ constexpr bool hasShaderType (ShaderStageFlags flags, ShaderStage type) noexcept {
226
230
switch (type) {
227
231
case ShaderStage::VERTEX:
228
232
return bool (uint8_t (flags) & uint8_t (ShaderStageFlags::VERTEX));
@@ -233,6 +237,27 @@ static inline constexpr bool hasShaderType(ShaderStageFlags flags, ShaderStage t
233
237
}
234
238
}
235
239
240
+ enum class TextureType : uint8_t {
241
+ FLOAT,
242
+ INT,
243
+ UINT,
244
+ DEPTH,
245
+ STENCIL,
246
+ DEPTH_STENCIL
247
+ };
248
+
249
+ constexpr std::string_view to_string (TextureType type) noexcept {
250
+ switch (type) {
251
+ case TextureType::FLOAT: return " FLOAT" ;
252
+ case TextureType::INT: return " INT" ;
253
+ case TextureType::UINT: return " UINT" ;
254
+ case TextureType::DEPTH: return " DEPTH" ;
255
+ case TextureType::STENCIL: return " STENCIL" ;
256
+ case TextureType::DEPTH_STENCIL: return " DEPTH_STENCIL" ;
257
+ }
258
+ return " UNKNOWN" ;
259
+ }
260
+
236
261
enum class DescriptorType : uint8_t {
237
262
SAMPLER_FLOAT,
238
263
SAMPLER_INT,
@@ -244,6 +269,20 @@ enum class DescriptorType : uint8_t {
244
269
INPUT_ATTACHMENT,
245
270
};
246
271
272
+ constexpr std::string_view to_string (DescriptorType type) noexcept {
273
+ switch (type) {
274
+ case DescriptorType::SAMPLER_FLOAT: return " SAMPLER_FLOAT" ;
275
+ case DescriptorType::SAMPLER_INT: return " SAMPLER_INT" ;
276
+ case DescriptorType::SAMPLER_UINT: return " SAMPLER_UINT" ;
277
+ case DescriptorType::SAMPLER_DEPTH: return " SAMPLER_DEPTH" ;
278
+ case DescriptorType::SAMPLER_EXTERNAL: return " SAMPLER_EXTERNAL" ;
279
+ case DescriptorType::UNIFORM_BUFFER: return " UNIFORM_BUFFER" ;
280
+ case DescriptorType::SHADER_STORAGE_BUFFER: return " SHADER_STORAGE_BUFFER" ;
281
+ case DescriptorType::INPUT_ATTACHMENT: return " INPUT_ATTACHMENT" ;
282
+ }
283
+ return " UNKNOWN" ;
284
+ }
285
+
247
286
enum class DescriptorFlags : uint8_t {
248
287
NONE = 0x00 ,
249
288
DYNAMIC_OFFSET = 0x01
@@ -257,6 +296,10 @@ struct DescriptorSetLayoutBinding {
257
296
static bool isSampler (DescriptorType type) noexcept {
258
297
return int (type) <= int (DescriptorType::SAMPLER_EXTERNAL);
259
298
}
299
+ static bool isBuffer (DescriptorType type) noexcept {
300
+ return type == DescriptorType::UNIFORM_BUFFER ||
301
+ type == DescriptorType::SHADER_STORAGE_BUFFER;
302
+ }
260
303
DescriptorType type;
261
304
ShaderStageFlags stageFlags;
262
305
descriptor_binding_t binding;
@@ -267,7 +310,7 @@ struct DescriptorSetLayoutBinding {
267
310
// no uninitialized padding bytes.
268
311
// uint8_t externalSamplerDataIndex = EXTERNAL_SAMPLER_DATA_INDEX_UNUSED;
269
312
270
- friend inline bool operator ==(DescriptorSetLayoutBinding const & lhs,
313
+ friend bool operator ==(DescriptorSetLayoutBinding const & lhs,
271
314
DescriptorSetLayoutBinding const & rhs) noexcept {
272
315
return lhs.type == rhs.type &&
273
316
lhs.flags == rhs.flags &&
@@ -300,7 +343,7 @@ enum class TargetBufferFlags : uint32_t {
300
343
ALL = COLOR_ALL | DEPTH | STENCIL // !< Color, depth and stencil buffer selected.
301
344
};
302
345
303
- inline constexpr TargetBufferFlags getTargetBufferFlagsAt (size_t index) noexcept {
346
+ constexpr TargetBufferFlags getTargetBufferFlagsAt (size_t index) noexcept {
304
347
if (index == 0u ) return TargetBufferFlags::COLOR0;
305
348
if (index == 1u ) return TargetBufferFlags::COLOR1;
306
349
if (index == 2u ) return TargetBufferFlags::COLOR2;
@@ -770,6 +813,8 @@ enum class TextureFormat : uint16_t {
770
813
SRGB_ALPHA_BPTC_UNORM, // BC7 sRGB
771
814
};
772
815
816
+ TextureType getTextureType (TextureFormat format) noexcept ;
817
+
773
818
// ! Bitmask describing the intended Texture Usage
774
819
enum class TextureUsage : uint16_t {
775
820
NONE = 0x0000 ,
@@ -797,7 +842,7 @@ enum class TextureSwizzle : uint8_t {
797
842
};
798
843
799
844
// ! returns whether this format a depth format
800
- static constexpr bool isDepthFormat (TextureFormat format) noexcept {
845
+ constexpr bool isDepthFormat (TextureFormat format) noexcept {
801
846
switch (format) {
802
847
case TextureFormat::DEPTH32F:
803
848
case TextureFormat::DEPTH24:
@@ -810,7 +855,7 @@ static constexpr bool isDepthFormat(TextureFormat format) noexcept {
810
855
}
811
856
}
812
857
813
- static constexpr bool isStencilFormat (TextureFormat format) noexcept {
858
+ constexpr bool isStencilFormat (TextureFormat format) noexcept {
814
859
switch (format) {
815
860
case TextureFormat::STENCIL8:
816
861
case TextureFormat::DEPTH24_STENCIL8:
@@ -821,7 +866,7 @@ static constexpr bool isStencilFormat(TextureFormat format) noexcept {
821
866
}
822
867
}
823
868
824
- inline constexpr bool isColorFormat (TextureFormat format) noexcept {
869
+ constexpr bool isColorFormat (TextureFormat format) noexcept {
825
870
switch (format) {
826
871
// Standard color formats
827
872
case TextureFormat::R8:
@@ -848,7 +893,7 @@ inline constexpr bool isColorFormat(TextureFormat format) noexcept {
848
893
return false ;
849
894
}
850
895
851
- static constexpr bool isUnsignedIntFormat (TextureFormat format) {
896
+ constexpr bool isUnsignedIntFormat (TextureFormat format) {
852
897
switch (format) {
853
898
case TextureFormat::R8UI:
854
899
case TextureFormat::R16UI:
@@ -869,7 +914,7 @@ static constexpr bool isUnsignedIntFormat(TextureFormat format) {
869
914
}
870
915
}
871
916
872
- static constexpr bool isSignedIntFormat (TextureFormat format) {
917
+ constexpr bool isSignedIntFormat (TextureFormat format) {
873
918
switch (format) {
874
919
case TextureFormat::R8I:
875
920
case TextureFormat::R16I:
@@ -891,35 +936,35 @@ static constexpr bool isSignedIntFormat(TextureFormat format) {
891
936
}
892
937
893
938
// ! returns whether this format is a compressed format
894
- static constexpr bool isCompressedFormat (TextureFormat format) noexcept {
939
+ constexpr bool isCompressedFormat (TextureFormat format) noexcept {
895
940
return format >= TextureFormat::EAC_R11;
896
941
}
897
942
898
943
// ! returns whether this format is an ETC2 compressed format
899
- static constexpr bool isETC2Compression (TextureFormat format) noexcept {
944
+ constexpr bool isETC2Compression (TextureFormat format) noexcept {
900
945
return format >= TextureFormat::EAC_R11 && format <= TextureFormat::ETC2_EAC_SRGBA8;
901
946
}
902
947
903
948
// ! returns whether this format is an S3TC compressed format
904
- static constexpr bool isS3TCCompression (TextureFormat format) noexcept {
949
+ constexpr bool isS3TCCompression (TextureFormat format) noexcept {
905
950
return format >= TextureFormat::DXT1_RGB && format <= TextureFormat::DXT5_SRGBA;
906
951
}
907
952
908
- static constexpr bool isS3TCSRGBCompression (TextureFormat format) noexcept {
953
+ constexpr bool isS3TCSRGBCompression (TextureFormat format) noexcept {
909
954
return format >= TextureFormat::DXT1_SRGB && format <= TextureFormat::DXT5_SRGBA;
910
955
}
911
956
912
957
// ! returns whether this format is an RGTC compressed format
913
- static constexpr bool isRGTCCompression (TextureFormat format) noexcept {
958
+ constexpr bool isRGTCCompression (TextureFormat format) noexcept {
914
959
return format >= TextureFormat::RED_RGTC1 && format <= TextureFormat::SIGNED_RED_GREEN_RGTC2;
915
960
}
916
961
917
962
// ! returns whether this format is an BPTC compressed format
918
- static constexpr bool isBPTCCompression (TextureFormat format) noexcept {
963
+ constexpr bool isBPTCCompression (TextureFormat format) noexcept {
919
964
return format >= TextureFormat::RGB_BPTC_SIGNED_FLOAT && format <= TextureFormat::SRGB_ALPHA_BPTC_UNORM;
920
965
}
921
966
922
- static constexpr bool isASTCCompression (TextureFormat format) noexcept {
967
+ constexpr bool isASTCCompression (TextureFormat format) noexcept {
923
968
return format >= TextureFormat::RGBA_ASTC_4x4 && format <= TextureFormat::SRGB8_ALPHA8_ASTC_12x12;
924
969
}
925
970
@@ -1044,15 +1089,19 @@ struct SamplerParams { // NOLINT
1044
1089
}
1045
1090
};
1046
1091
1092
+ bool isFiltered () const noexcept {
1093
+ return filterMag != SamplerMagFilter::NEAREST || filterMin != SamplerMinFilter::NEAREST;
1094
+ }
1095
+
1047
1096
private:
1048
- friend inline bool operator == (SamplerParams lhs, SamplerParams rhs) noexcept {
1049
- return SamplerParams:: EqualTo{}(lhs, rhs);
1097
+ friend bool operator == (SamplerParams lhs, SamplerParams rhs) noexcept {
1098
+ return EqualTo{}(lhs, rhs);
1050
1099
}
1051
- friend inline bool operator != (SamplerParams lhs, SamplerParams rhs) noexcept {
1052
- return !SamplerParams:: EqualTo{}(lhs, rhs);
1100
+ friend bool operator != (SamplerParams lhs, SamplerParams rhs) noexcept {
1101
+ return !EqualTo{}(lhs, rhs);
1053
1102
}
1054
- friend inline bool operator < (SamplerParams lhs, SamplerParams rhs) noexcept {
1055
- return SamplerParams:: LessThan{}(lhs, rhs);
1103
+ friend bool operator < (SamplerParams lhs, SamplerParams rhs) noexcept {
1104
+ return LessThan{}(lhs, rhs);
1056
1105
}
1057
1106
};
1058
1107
@@ -1102,15 +1151,15 @@ struct SamplerYcbcrConversion {// NOLINT
1102
1151
};
1103
1152
1104
1153
private:
1105
- friend inline bool operator == (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
1154
+ friend bool operator == (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
1106
1155
noexcept {
1107
1156
return SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
1108
1157
}
1109
- friend inline bool operator != (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
1158
+ friend bool operator != (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
1110
1159
noexcept {
1111
1160
return !SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
1112
1161
}
1113
- friend inline bool operator < (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
1162
+ friend bool operator < (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
1114
1163
noexcept {
1115
1164
return SamplerYcbcrConversion::LessThan{}(lhs, rhs);
1116
1165
}
0 commit comments