Skip to content

add sampler type in DescriptorSetLayout #8705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEW_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ for next branch cut* header.
appropriate header in [RELEASE_NOTES.md](./RELEASE_NOTES.md).

## Release notes for next branch cut

- materials: sampler now export their type in the material binary [⚠️ **New Material Version**]
115 changes: 85 additions & 30 deletions filament/backend/include/backend/DriverEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <array>
#include <type_traits>
#include <variant>
#include <string_view>

#include <stddef.h>
#include <stdint.h>
Expand Down Expand Up @@ -159,7 +160,7 @@ enum class TimerQueryResult : int8_t {
AVAILABLE = 1, // result is available
};

static constexpr const char* backendToString(Backend backend) {
constexpr std::string_view to_string(Backend const backend) noexcept {
switch (backend) {
case Backend::NOOP:
return "Noop";
Expand All @@ -171,9 +172,11 @@ static constexpr const char* backendToString(Backend backend) {
return "Metal";
case Backend::WEBGPU:
return "WebGPU";
default:
return "Unknown";
case Backend::DEFAULT:
return "Default";
break;
}
return "Unknown";
}

/**
Expand All @@ -190,7 +193,7 @@ enum class ShaderLanguage {
WGSL = 5,
};

static constexpr const char* shaderLanguageToString(ShaderLanguage shaderLanguage) {
constexpr const char* shaderLanguageToString(ShaderLanguage shaderLanguage) noexcept {
switch (shaderLanguage) {
case ShaderLanguage::ESSL1:
return "ESSL 1.0";
Expand All @@ -205,6 +208,7 @@ static constexpr const char* shaderLanguageToString(ShaderLanguage shaderLanguag
case ShaderLanguage::WGSL:
return "WGSL";
}
return "UNKNOWN";
}

enum class ShaderStage : uint8_t {
Expand All @@ -222,7 +226,7 @@ enum class ShaderStageFlags : uint8_t {
ALL_SHADER_STAGE_FLAGS = VERTEX | FRAGMENT | COMPUTE
};

static inline constexpr bool hasShaderType(ShaderStageFlags flags, ShaderStage type) noexcept {
constexpr bool hasShaderType(ShaderStageFlags flags, ShaderStage type) noexcept {
switch (type) {
case ShaderStage::VERTEX:
return bool(uint8_t(flags) & uint8_t(ShaderStageFlags::VERTEX));
Expand All @@ -233,14 +237,52 @@ static inline constexpr bool hasShaderType(ShaderStageFlags flags, ShaderStage t
}
}

enum class TextureType : uint8_t {
FLOAT,
INT,
UINT,
DEPTH,
STENCIL,
DEPTH_STENCIL
};

constexpr std::string_view to_string(TextureType type) noexcept {
switch (type) {
case TextureType::FLOAT: return "FLOAT";
case TextureType::INT: return "INT";
case TextureType::UINT: return "UINT";
case TextureType::DEPTH: return "DEPTH";
case TextureType::STENCIL: return "STENCIL";
case TextureType::DEPTH_STENCIL: return "DEPTH_STENCIL";
}
return "UNKNOWN";
}

enum class DescriptorType : uint8_t {
SAMPLER_FLOAT,
SAMPLER_INT,
SAMPLER_UINT,
SAMPLER_DEPTH,
SAMPLER_EXTERNAL,
UNIFORM_BUFFER,
SHADER_STORAGE_BUFFER,
SAMPLER,
INPUT_ATTACHMENT,
SAMPLER_EXTERNAL
};

constexpr std::string_view to_string(DescriptorType type) noexcept {
switch (type) {
case DescriptorType::SAMPLER_FLOAT: return "SAMPLER_FLOAT";
case DescriptorType::SAMPLER_INT: return "SAMPLER_INT";
case DescriptorType::SAMPLER_UINT: return "SAMPLER_UINT";
case DescriptorType::SAMPLER_DEPTH: return "SAMPLER_DEPTH";
case DescriptorType::SAMPLER_EXTERNAL: return "SAMPLER_EXTERNAL";
case DescriptorType::UNIFORM_BUFFER: return "UNIFORM_BUFFER";
case DescriptorType::SHADER_STORAGE_BUFFER: return "SHADER_STORAGE_BUFFER";
case DescriptorType::INPUT_ATTACHMENT: return "INPUT_ATTACHMENT";
}
return "UNKNOWN";
}

enum class DescriptorFlags : uint8_t {
NONE = 0x00,
DYNAMIC_OFFSET = 0x01
Expand All @@ -251,6 +293,13 @@ using descriptor_set_t = uint8_t;
using descriptor_binding_t = uint8_t;

struct DescriptorSetLayoutBinding {
static bool isSampler(DescriptorType type) noexcept {
return int(type) <= int(DescriptorType::SAMPLER_EXTERNAL);
}
static bool isBuffer(DescriptorType type) noexcept {
return type == DescriptorType::UNIFORM_BUFFER ||
type == DescriptorType::SHADER_STORAGE_BUFFER;
}
DescriptorType type;
ShaderStageFlags stageFlags;
descriptor_binding_t binding;
Expand All @@ -261,7 +310,7 @@ struct DescriptorSetLayoutBinding {
// no uninitialized padding bytes.
// uint8_t externalSamplerDataIndex = EXTERNAL_SAMPLER_DATA_INDEX_UNUSED;

friend inline bool operator==(DescriptorSetLayoutBinding const& lhs,
friend bool operator==(DescriptorSetLayoutBinding const& lhs,
DescriptorSetLayoutBinding const& rhs) noexcept {
return lhs.type == rhs.type &&
lhs.flags == rhs.flags &&
Expand Down Expand Up @@ -294,7 +343,7 @@ enum class TargetBufferFlags : uint32_t {
ALL = COLOR_ALL | DEPTH | STENCIL //!< Color, depth and stencil buffer selected.
};

inline constexpr TargetBufferFlags getTargetBufferFlagsAt(size_t index) noexcept {
constexpr TargetBufferFlags getTargetBufferFlagsAt(size_t index) noexcept {
if (index == 0u) return TargetBufferFlags::COLOR0;
if (index == 1u) return TargetBufferFlags::COLOR1;
if (index == 2u) return TargetBufferFlags::COLOR2;
Expand Down Expand Up @@ -764,6 +813,8 @@ enum class TextureFormat : uint16_t {
SRGB_ALPHA_BPTC_UNORM, // BC7 sRGB
};

TextureType getTextureType(TextureFormat format) noexcept;

//! Bitmask describing the intended Texture Usage
enum class TextureUsage : uint16_t {
NONE = 0x0000,
Expand Down Expand Up @@ -791,7 +842,7 @@ enum class TextureSwizzle : uint8_t {
};

//! returns whether this format a depth format
static constexpr bool isDepthFormat(TextureFormat format) noexcept {
constexpr bool isDepthFormat(TextureFormat format) noexcept {
switch (format) {
case TextureFormat::DEPTH32F:
case TextureFormat::DEPTH24:
Expand All @@ -804,7 +855,7 @@ static constexpr bool isDepthFormat(TextureFormat format) noexcept {
}
}

static constexpr bool isStencilFormat(TextureFormat format) noexcept {
constexpr bool isStencilFormat(TextureFormat format) noexcept {
switch (format) {
case TextureFormat::STENCIL8:
case TextureFormat::DEPTH24_STENCIL8:
Expand All @@ -815,7 +866,7 @@ static constexpr bool isStencilFormat(TextureFormat format) noexcept {
}
}

inline constexpr bool isColorFormat(TextureFormat format) noexcept {
constexpr bool isColorFormat(TextureFormat format) noexcept {
switch (format) {
// Standard color formats
case TextureFormat::R8:
Expand All @@ -842,7 +893,7 @@ inline constexpr bool isColorFormat(TextureFormat format) noexcept {
return false;
}

static constexpr bool isUnsignedIntFormat(TextureFormat format) {
constexpr bool isUnsignedIntFormat(TextureFormat format) {
switch (format) {
case TextureFormat::R8UI:
case TextureFormat::R16UI:
Expand All @@ -863,7 +914,7 @@ static constexpr bool isUnsignedIntFormat(TextureFormat format) {
}
}

static constexpr bool isSignedIntFormat(TextureFormat format) {
constexpr bool isSignedIntFormat(TextureFormat format) {
switch (format) {
case TextureFormat::R8I:
case TextureFormat::R16I:
Expand All @@ -885,35 +936,35 @@ static constexpr bool isSignedIntFormat(TextureFormat format) {
}

//! returns whether this format is a compressed format
static constexpr bool isCompressedFormat(TextureFormat format) noexcept {
constexpr bool isCompressedFormat(TextureFormat format) noexcept {
return format >= TextureFormat::EAC_R11;
}

//! returns whether this format is an ETC2 compressed format
static constexpr bool isETC2Compression(TextureFormat format) noexcept {
constexpr bool isETC2Compression(TextureFormat format) noexcept {
return format >= TextureFormat::EAC_R11 && format <= TextureFormat::ETC2_EAC_SRGBA8;
}

//! returns whether this format is an S3TC compressed format
static constexpr bool isS3TCCompression(TextureFormat format) noexcept {
constexpr bool isS3TCCompression(TextureFormat format) noexcept {
return format >= TextureFormat::DXT1_RGB && format <= TextureFormat::DXT5_SRGBA;
}

static constexpr bool isS3TCSRGBCompression(TextureFormat format) noexcept {
constexpr bool isS3TCSRGBCompression(TextureFormat format) noexcept {
return format >= TextureFormat::DXT1_SRGB && format <= TextureFormat::DXT5_SRGBA;
}

//! returns whether this format is an RGTC compressed format
static constexpr bool isRGTCCompression(TextureFormat format) noexcept {
constexpr bool isRGTCCompression(TextureFormat format) noexcept {
return format >= TextureFormat::RED_RGTC1 && format <= TextureFormat::SIGNED_RED_GREEN_RGTC2;
}

//! returns whether this format is an BPTC compressed format
static constexpr bool isBPTCCompression(TextureFormat format) noexcept {
constexpr bool isBPTCCompression(TextureFormat format) noexcept {
return format >= TextureFormat::RGB_BPTC_SIGNED_FLOAT && format <= TextureFormat::SRGB_ALPHA_BPTC_UNORM;
}

static constexpr bool isASTCCompression(TextureFormat format) noexcept {
constexpr bool isASTCCompression(TextureFormat format) noexcept {
return format >= TextureFormat::RGBA_ASTC_4x4 && format <= TextureFormat::SRGB8_ALPHA8_ASTC_12x12;
}

Expand Down Expand Up @@ -1038,15 +1089,19 @@ struct SamplerParams { // NOLINT
}
};

bool isFiltered() const noexcept {
return filterMag != SamplerMagFilter::NEAREST || filterMin != SamplerMinFilter::NEAREST;
}

private:
friend inline bool operator == (SamplerParams lhs, SamplerParams rhs) noexcept {
return SamplerParams::EqualTo{}(lhs, rhs);
friend bool operator == (SamplerParams lhs, SamplerParams rhs) noexcept {
return EqualTo{}(lhs, rhs);
}
friend inline bool operator != (SamplerParams lhs, SamplerParams rhs) noexcept {
return !SamplerParams::EqualTo{}(lhs, rhs);
friend bool operator != (SamplerParams lhs, SamplerParams rhs) noexcept {
return !EqualTo{}(lhs, rhs);
}
friend inline bool operator < (SamplerParams lhs, SamplerParams rhs) noexcept {
return SamplerParams::LessThan{}(lhs, rhs);
friend bool operator < (SamplerParams lhs, SamplerParams rhs) noexcept {
return LessThan{}(lhs, rhs);
}
};

Expand Down Expand Up @@ -1096,15 +1151,15 @@ struct SamplerYcbcrConversion {// NOLINT
};

private:
friend inline bool operator == (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
friend bool operator == (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
noexcept {
return SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
}
friend inline bool operator != (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
friend bool operator != (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
noexcept {
return !SamplerYcbcrConversion::EqualTo{}(lhs, rhs);
}
friend inline bool operator < (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
friend bool operator < (SamplerYcbcrConversion lhs, SamplerYcbcrConversion rhs)
noexcept {
return SamplerYcbcrConversion::LessThan{}(lhs, rhs);
}
Expand Down
Loading