Skip to content

Commit 2d7afa8

Browse files
committed
select the proper descriptor set layout in the rendering loop
Now that the per-view layout can be different based on the type of shadow, we need to make sure we set the proper layout in the pipeline and use the corresponding descriptor set. There are now 16 "per-view" layouts and their corresponding descriptor set. There are two sets of 8, the current set is determined by the shadow type on the view. Then during rendering, when we set the pipeline we need to select the corresponding layout; each material now offers both versions of the layout and we just pick the right one. DescriptorSet::setBuffer and setSampler now need the layout in order to do some validation that the correct type of descriptor is used. This will help catch problems earlier.
1 parent 583b72b commit 2d7afa8

26 files changed

+648
-295
lines changed

filament/backend/include/backend/DriverEnums.h

+77-28
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <array>
3838
#include <type_traits>
3939
#include <variant>
40+
#include <string_view>
4041

4142
#include <stddef.h>
4243
#include <stdint.h>
@@ -159,7 +160,7 @@ enum class TimerQueryResult : int8_t {
159160
AVAILABLE = 1, // result is available
160161
};
161162

162-
static constexpr const char* backendToString(Backend backend) {
163+
constexpr std::string_view to_string(Backend const backend) noexcept {
163164
switch (backend) {
164165
case Backend::NOOP:
165166
return "Noop";
@@ -171,9 +172,11 @@ static constexpr const char* backendToString(Backend backend) {
171172
return "Metal";
172173
case Backend::WEBGPU:
173174
return "WebGPU";
174-
default:
175-
return "Unknown";
175+
case Backend::DEFAULT:
176+
return "Default";
177+
break;
176178
}
179+
return "Unknown";
177180
}
178181

179182
/**
@@ -190,7 +193,7 @@ enum class ShaderLanguage {
190193
WGSL = 5,
191194
};
192195

193-
static constexpr const char* shaderLanguageToString(ShaderLanguage shaderLanguage) {
196+
constexpr const char* shaderLanguageToString(ShaderLanguage shaderLanguage) noexcept {
194197
switch (shaderLanguage) {
195198
case ShaderLanguage::ESSL1:
196199
return "ESSL 1.0";
@@ -205,6 +208,7 @@ static constexpr const char* shaderLanguageToString(ShaderLanguage shaderLanguag
205208
case ShaderLanguage::WGSL:
206209
return "WGSL";
207210
}
211+
return "UNKNOWN";
208212
}
209213

210214
enum class ShaderStage : uint8_t {
@@ -222,7 +226,7 @@ enum class ShaderStageFlags : uint8_t {
222226
ALL_SHADER_STAGE_FLAGS = VERTEX | FRAGMENT | COMPUTE
223227
};
224228

225-
static inline constexpr bool hasShaderType(ShaderStageFlags flags, ShaderStage type) noexcept {
229+
constexpr bool hasShaderType(ShaderStageFlags flags, ShaderStage type) noexcept {
226230
switch (type) {
227231
case ShaderStage::VERTEX:
228232
return bool(uint8_t(flags) & uint8_t(ShaderStageFlags::VERTEX));
@@ -233,6 +237,27 @@ static inline constexpr bool hasShaderType(ShaderStageFlags flags, ShaderStage t
233237
}
234238
}
235239

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+
236261
enum class DescriptorType : uint8_t {
237262
SAMPLER_FLOAT,
238263
SAMPLER_INT,
@@ -244,6 +269,20 @@ enum class DescriptorType : uint8_t {
244269
INPUT_ATTACHMENT,
245270
};
246271

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+
247286
enum class DescriptorFlags : uint8_t {
248287
NONE = 0x00,
249288
DYNAMIC_OFFSET = 0x01
@@ -257,6 +296,10 @@ struct DescriptorSetLayoutBinding {
257296
static bool isSampler(DescriptorType type) noexcept {
258297
return int(type) <= int(DescriptorType::SAMPLER_EXTERNAL);
259298
}
299+
static bool isBuffer(DescriptorType type) noexcept {
300+
return type == DescriptorType::UNIFORM_BUFFER ||
301+
type == DescriptorType::SHADER_STORAGE_BUFFER;
302+
}
260303
DescriptorType type;
261304
ShaderStageFlags stageFlags;
262305
descriptor_binding_t binding;
@@ -267,7 +310,7 @@ struct DescriptorSetLayoutBinding {
267310
// no uninitialized padding bytes.
268311
// uint8_t externalSamplerDataIndex = EXTERNAL_SAMPLER_DATA_INDEX_UNUSED;
269312

270-
friend inline bool operator==(DescriptorSetLayoutBinding const& lhs,
313+
friend bool operator==(DescriptorSetLayoutBinding const& lhs,
271314
DescriptorSetLayoutBinding const& rhs) noexcept {
272315
return lhs.type == rhs.type &&
273316
lhs.flags == rhs.flags &&
@@ -300,7 +343,7 @@ enum class TargetBufferFlags : uint32_t {
300343
ALL = COLOR_ALL | DEPTH | STENCIL //!< Color, depth and stencil buffer selected.
301344
};
302345

303-
inline constexpr TargetBufferFlags getTargetBufferFlagsAt(size_t index) noexcept {
346+
constexpr TargetBufferFlags getTargetBufferFlagsAt(size_t index) noexcept {
304347
if (index == 0u) return TargetBufferFlags::COLOR0;
305348
if (index == 1u) return TargetBufferFlags::COLOR1;
306349
if (index == 2u) return TargetBufferFlags::COLOR2;
@@ -770,6 +813,8 @@ enum class TextureFormat : uint16_t {
770813
SRGB_ALPHA_BPTC_UNORM, // BC7 sRGB
771814
};
772815

816+
TextureType getTextureType(TextureFormat format) noexcept;
817+
773818
//! Bitmask describing the intended Texture Usage
774819
enum class TextureUsage : uint16_t {
775820
NONE = 0x0000,
@@ -797,7 +842,7 @@ enum class TextureSwizzle : uint8_t {
797842
};
798843

799844
//! returns whether this format a depth format
800-
static constexpr bool isDepthFormat(TextureFormat format) noexcept {
845+
constexpr bool isDepthFormat(TextureFormat format) noexcept {
801846
switch (format) {
802847
case TextureFormat::DEPTH32F:
803848
case TextureFormat::DEPTH24:
@@ -810,7 +855,7 @@ static constexpr bool isDepthFormat(TextureFormat format) noexcept {
810855
}
811856
}
812857

813-
static constexpr bool isStencilFormat(TextureFormat format) noexcept {
858+
constexpr bool isStencilFormat(TextureFormat format) noexcept {
814859
switch (format) {
815860
case TextureFormat::STENCIL8:
816861
case TextureFormat::DEPTH24_STENCIL8:
@@ -821,7 +866,7 @@ static constexpr bool isStencilFormat(TextureFormat format) noexcept {
821866
}
822867
}
823868

824-
inline constexpr bool isColorFormat(TextureFormat format) noexcept {
869+
constexpr bool isColorFormat(TextureFormat format) noexcept {
825870
switch (format) {
826871
// Standard color formats
827872
case TextureFormat::R8:
@@ -848,7 +893,7 @@ inline constexpr bool isColorFormat(TextureFormat format) noexcept {
848893
return false;
849894
}
850895

851-
static constexpr bool isUnsignedIntFormat(TextureFormat format) {
896+
constexpr bool isUnsignedIntFormat(TextureFormat format) {
852897
switch (format) {
853898
case TextureFormat::R8UI:
854899
case TextureFormat::R16UI:
@@ -869,7 +914,7 @@ static constexpr bool isUnsignedIntFormat(TextureFormat format) {
869914
}
870915
}
871916

872-
static constexpr bool isSignedIntFormat(TextureFormat format) {
917+
constexpr bool isSignedIntFormat(TextureFormat format) {
873918
switch (format) {
874919
case TextureFormat::R8I:
875920
case TextureFormat::R16I:
@@ -891,35 +936,35 @@ static constexpr bool isSignedIntFormat(TextureFormat format) {
891936
}
892937

893938
//! returns whether this format is a compressed format
894-
static constexpr bool isCompressedFormat(TextureFormat format) noexcept {
939+
constexpr bool isCompressedFormat(TextureFormat format) noexcept {
895940
return format >= TextureFormat::EAC_R11;
896941
}
897942

898943
//! returns whether this format is an ETC2 compressed format
899-
static constexpr bool isETC2Compression(TextureFormat format) noexcept {
944+
constexpr bool isETC2Compression(TextureFormat format) noexcept {
900945
return format >= TextureFormat::EAC_R11 && format <= TextureFormat::ETC2_EAC_SRGBA8;
901946
}
902947

903948
//! returns whether this format is an S3TC compressed format
904-
static constexpr bool isS3TCCompression(TextureFormat format) noexcept {
949+
constexpr bool isS3TCCompression(TextureFormat format) noexcept {
905950
return format >= TextureFormat::DXT1_RGB && format <= TextureFormat::DXT5_SRGBA;
906951
}
907952

908-
static constexpr bool isS3TCSRGBCompression(TextureFormat format) noexcept {
953+
constexpr bool isS3TCSRGBCompression(TextureFormat format) noexcept {
909954
return format >= TextureFormat::DXT1_SRGB && format <= TextureFormat::DXT5_SRGBA;
910955
}
911956

912957
//! returns whether this format is an RGTC compressed format
913-
static constexpr bool isRGTCCompression(TextureFormat format) noexcept {
958+
constexpr bool isRGTCCompression(TextureFormat format) noexcept {
914959
return format >= TextureFormat::RED_RGTC1 && format <= TextureFormat::SIGNED_RED_GREEN_RGTC2;
915960
}
916961

917962
//! returns whether this format is an BPTC compressed format
918-
static constexpr bool isBPTCCompression(TextureFormat format) noexcept {
963+
constexpr bool isBPTCCompression(TextureFormat format) noexcept {
919964
return format >= TextureFormat::RGB_BPTC_SIGNED_FLOAT && format <= TextureFormat::SRGB_ALPHA_BPTC_UNORM;
920965
}
921966

922-
static constexpr bool isASTCCompression(TextureFormat format) noexcept {
967+
constexpr bool isASTCCompression(TextureFormat format) noexcept {
923968
return format >= TextureFormat::RGBA_ASTC_4x4 && format <= TextureFormat::SRGB8_ALPHA8_ASTC_12x12;
924969
}
925970

@@ -1044,15 +1089,19 @@ struct SamplerParams { // NOLINT
10441089
}
10451090
};
10461091

1092+
bool isFiltered() const noexcept {
1093+
return filterMag != SamplerMagFilter::NEAREST || filterMin != SamplerMinFilter::NEAREST;
1094+
}
1095+
10471096
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);
10501099
}
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);
10531102
}
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);
10561105
}
10571106
};
10581107

@@ -1102,15 +1151,15 @@ struct SamplerYcbcrConversion {// NOLINT
11021151
};
11031152

11041153
private:
1105-
friend inline bool operator == (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
1154+
friend bool operator == (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
11061155
noexcept {
11071156
return SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
11081157
}
1109-
friend inline bool operator != (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
1158+
friend bool operator != (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
11101159
noexcept {
11111160
return !SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
11121161
}
1113-
friend inline bool operator < (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
1162+
friend bool operator < (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
11141163
noexcept {
11151164
return SamplerYcbcrConversion::LessThan{}(lhs, rhs);
11161165
}

0 commit comments

Comments
 (0)