Repository: google/filament
File: filament/backend/include/backend/DriverEnums.h (C/C++)

Code before:
 * - The Metal backend can prefer precompiled Metal libraries, while falling back to MSL.
 */
enum class ShaderLanguage {
    ESSL1 = 0,
    ESSL3 = 1,
    SPIRV = 2,
    MSL = 3,
    METAL_LIBRARY = 4,
    WGSL = 5,
};

static constexpr const char* shaderLanguageToString(ShaderLanguage shaderLanguage) {
    switch (shaderLanguage) {
        case ShaderLanguage::ESSL1:
            return "ESSL 1.0";
        case ShaderLanguage::ESSL3:
            return "ESSL 3.0";
        case ShaderLanguage::SPIRV:
            return "SPIR-V";
        case ShaderLanguage::MSL:
            return "MSL";
        case ShaderLanguage::METAL_LIBRARY:
            return "Metal precompiled library";
        case ShaderLanguage::WGSL:
            return "WebGPU";
        // TODO Should we add this?
        default:
            return "Unknown";
    }
}

enum class ShaderStage : uint8_t {
    VERTEX = 0,
    FRAGMENT = 1,
    COMPUTE = 2
};

static constexpr size_t PIPELINE_STAGE_COUNT = 2;
enum class ShaderStageFlags : uint8_t {
    NONE        =    0,
    VERTEX      =    0x1,
    FRAGMENT    =    0x2,
    COMPUTE     =    0x4,
    ALL_SHADER_STAGE_FLAGS = VERTEX | FRAGMENT | COMPUTE
};

static inline constexpr bool hasShaderType(ShaderStageFlags flags, ShaderStage type) noexcept {
    switch (type) {
        case ShaderStage::VERTEX:
            return bool(uint8_t(flags) & uint8_t(ShaderStageFlags::VERTEX));
        case ShaderStage::FRAGMENT:

Review comment (bug):
We should definitely have a default case. The question is whether we should return "Unknown", as you have done, or blow up/panic/crash (fail loudly). Normally, I would opt for the later and fail loudly, as I suspect that would get caught pretty early/quickly in the process and the "Unknown" return might not fail here, but later on in an unexpected way. So, I would lean that way myself (fail loudly) (this is not a case that should ever practically happen. if it does it is a programming error/miss).

Code after:

/**
 * Defines the shader language. Similar to the above backend enum, with some differences:
 * - The OpenGL backend can select between two shader languages: ESSL 1.0 and ESSL 3.0.
 * - The Metal backend can prefer precompiled Metal libraries, while falling back to MSL.
 */
enum class ShaderLanguage {
    ESSL1 = 0,
    ESSL3 = 1,
    SPIRV = 2,
    MSL = 3,
    METAL_LIBRARY = 4,
    WGSL = 5,
};

static constexpr const char* shaderLanguageToString(ShaderLanguage shaderLanguage) {
    switch (shaderLanguage) {
        case ShaderLanguage::ESSL1:
            return "ESSL 1.0";
        case ShaderLanguage::ESSL3:
            return "ESSL 3.0";
        case ShaderLanguage::SPIRV:
            return "SPIR-V";
        case ShaderLanguage::MSL:
            return "MSL";
        case ShaderLanguage::METAL_LIBRARY:
            return "Metal precompiled library";
        case ShaderLanguage::WGSL:
            return "WGSL";
    }
}

enum class ShaderStage : uint8_t {
    VERTEX = 0,
    FRAGMENT = 1,
    COMPUTE = 2
};

static constexpr size_t PIPELINE_STAGE_COUNT = 2;
enum class ShaderStageFlags : uint8_t {
    NONE        =    0,
    VERTEX      =    0x1,
    FRAGMENT    =    0x2,
    COMPUTE     =    0x4,
    ALL_SHADER_STAGE_FLAGS = VERTEX | FRAGMENT | COMPUTE
};

static inline constexpr bool hasShaderType(ShaderStageFlags flags, ShaderStage type) noexcept {
    switch (type) {
        case ShaderStage::VERTEX:
            return bool(uint8_t(flags) & uint8_t(ShaderStageFlags::VERTEX));