From 93150ed7fb4558f6e8dc5d03f93f72a7b09637f4 Mon Sep 17 00:00:00 2001
From: Eliza Velasquez <exv@google.com>
Date: Mon, 13 Nov 2023 15:23:36 -0800
Subject: [PATCH 1/3] 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 ef87c012c..691b6081a 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");
 	}

From 0e9bc69128318ab8d6f20e0dfd8c7d4a7dacbf89 Mon Sep 17 00:00:00 2001
From: Hans-Kristian Arntzen <post@arntzen-software.no>
Date: Thu, 16 Nov 2023 14:00:00 +0100
Subject: [PATCH 2/3] Review nit, update brace placement

---
 spirv_glsl.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp
index 691b6081a..1bbb1650c 100644
--- a/spirv_glsl.cpp
+++ b/spirv_glsl.cpp
@@ -15051,7 +15051,8 @@ string CompilerGLSL::flags_to_qualifiers_glsl(const SPIRType &type, const Bitset
 	{
 		auto &execution = get_entry_point();
 
-		if (type.basetype == SPIRType::UInt && is_legacy()) {
+		if (type.basetype == SPIRType::UInt && is_legacy())
+		{
 			// HACK: This is a bool. See comment in type_to_glsl().
 			qual += "lowp ";
 		}

From bf059200bebe41616ce156204fdf9cc63aae97a4 Mon Sep 17 00:00:00 2001
From: Hans-Kristian Arntzen <post@arntzen-software.no>
Date: Thu, 16 Nov 2023 14:00:48 +0100
Subject: [PATCH 3/3] Only use lowp path for legacy ES

---
 spirv_glsl.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/spirv_glsl.cpp b/spirv_glsl.cpp
index 1bbb1650c..6b84b0618 100644
--- a/spirv_glsl.cpp
+++ b/spirv_glsl.cpp
@@ -15051,7 +15051,7 @@ string CompilerGLSL::flags_to_qualifiers_glsl(const SPIRType &type, const Bitset
 	{
 		auto &execution = get_entry_point();
 
-		if (type.basetype == SPIRType::UInt && is_legacy())
+		if (type.basetype == SPIRType::UInt && is_legacy_es())
 		{
 			// HACK: This is a bool. See comment in type_to_glsl().
 			qual += "lowp ";