From 93150ed7fb4558f6e8dc5d03f93f72a7b09637f4 Mon Sep 17 00:00:00 2001 From: Eliza Velasquez Date: Mon, 13 Nov 2023 15:23:36 -0800 Subject: [PATCH] Workaround for generating bool uniforms in ESSL1 Fixes #2223. --- spirv_glsl.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp index ef87c012..691b6081 100644 --- a/spirv_glsl.cpp +++ b/spirv_glsl.cpp @@ -15051,7 +15051,11 @@ string CompilerGLSL::flags_to_qualifiers_glsl(const SPIRType &type, const Bitset { auto &execution = get_entry_point(); - if (flags.get(DecorationRelaxedPrecision)) + if (type.basetype == SPIRType::UInt && is_legacy()) { + // HACK: This is a bool. See comment in type_to_glsl(). + qual += "lowp "; + } + else if (flags.get(DecorationRelaxedPrecision)) { bool implied_fmediump = type.basetype == SPIRType::Float && options.fragment.default_float_precision == Options::Mediump && @@ -15585,7 +15589,11 @@ string CompilerGLSL::type_to_glsl(const SPIRType &type, uint32_t id) if (type.basetype == SPIRType::UInt && is_legacy()) { if (options.es) - SPIRV_CROSS_THROW("Unsigned integers are not supported on legacy ESSL."); + // HACK: spirv-cross changes bools into uints and generates code which compares them to + // zero. Input code will have already been validated as not to have contained any uints, + // so any remaining uints must in fact be bools. However, simply returning "bool" here + // will result in invalid code. Instead, return an int. + return backend.basic_int_type; else require_extension_internal("GL_EXT_gpu_shader4"); }