Browse Source

Merge pull request #62226 from RandomShaper/fix_intel_hd_shaders_3.5

[3.x] Use signed integers for async shader conditionals
Rémi Verschelde 3 years ago
parent
commit
56a2dab0b7

+ 8 - 3
drivers/gles3/shader_gles3.cpp

@@ -189,6 +189,11 @@ bool ShaderGLES3::_bind_ubershader() {
 	ERR_FAIL_COND_V(conditionals_uniform == -1, false);
 	ERR_FAIL_COND_V(conditionals_uniform == -1, false);
 #endif
 #endif
 	new_conditional_version.version &= ~VersionKey::UBERSHADER_FLAG;
 	new_conditional_version.version &= ~VersionKey::UBERSHADER_FLAG;
+#ifdef DEV_ENABLED
+	// So far we don't need bit 31 for conditionals. That allows us to use signed integers,
+	// which are more compatible across GL driver vendors.
+	CRASH_COND(new_conditional_version.version >= 0x80000000);
+#endif
 	glUniform1ui(conditionals_uniform, new_conditional_version.version);
 	glUniform1ui(conditionals_uniform, new_conditional_version.version);
 	return bound;
 	return bound;
 }
 }
@@ -499,11 +504,11 @@ static CharString _prepare_ubershader_chunk(const CharString &p_chunk) {
 			} else if (l.begins_with("#ifdef")) {
 			} else if (l.begins_with("#ifdef")) {
 				Vector<String> pieces = l.split_spaces();
 				Vector<String> pieces = l.split_spaces();
 				CRASH_COND(pieces.size() != 2);
 				CRASH_COND(pieces.size() != 2);
-				s += "if ((ubershader_flags & FLAG_" + pieces[1] + ") != 0u) {\n";
+				s += "if ((ubershader_flags & FLAG_" + pieces[1] + ") != 0) {\n";
 			} else if (l.begins_with("#ifndef")) {
 			} else if (l.begins_with("#ifndef")) {
 				Vector<String> pieces = l.split_spaces();
 				Vector<String> pieces = l.split_spaces();
 				CRASH_COND(pieces.size() != 2);
 				CRASH_COND(pieces.size() != 2);
-				s += "if ((ubershader_flags & FLAG_" + pieces[1] + ") == 0u) {\n";
+				s += "if ((ubershader_flags & FLAG_" + pieces[1] + ") == 0) {\n";
 			} else {
 			} else {
 				CRASH_NOW_MSG("The shader template is using too complex syntax in a line marked with ubershader-runtime.");
 				CRASH_NOW_MSG("The shader template is using too complex syntax in a line marked with ubershader-runtime.");
 			}
 			}
@@ -577,7 +582,7 @@ ShaderGLES3::Version *ShaderGLES3::get_current_version(bool &r_async_forbidden)
 	if (build_ubershader) {
 	if (build_ubershader) {
 		strings_common.push_back("#define IS_UBERSHADER\n");
 		strings_common.push_back("#define IS_UBERSHADER\n");
 		for (int i = 0; i < conditional_count; i++) {
 		for (int i = 0; i < conditional_count; i++) {
-			String s = vformat("#define FLAG_%s (1u << %du)\n", String(conditional_defines[i]).strip_edges().trim_prefix("#define "), i);
+			String s = vformat("#define FLAG_%s (1 << %d)\n", String(conditional_defines[i]).strip_edges().trim_prefix("#define "), i);
 			CharString cs = s.ascii();
 			CharString cs = s.ascii();
 			flag_macros.push_back(cs);
 			flag_macros.push_back(cs);
 			strings_common.push_back(cs.ptr());
 			strings_common.push_back(cs.ptr());

+ 2 - 2
drivers/gles3/shaders/particles.glsl

@@ -2,7 +2,7 @@
 [vertex]
 [vertex]
 
 
 #if defined(IS_UBERSHADER)
 #if defined(IS_UBERSHADER)
-uniform highp uint ubershader_flags;
+uniform highp int ubershader_flags;
 #endif
 #endif
 
 
 layout(location = 0) in highp vec4 color;
 layout(location = 0) in highp vec4 color;
@@ -222,7 +222,7 @@ VERTEX_SHADER_CODE
 [fragment]
 [fragment]
 
 
 #if defined(IS_UBERSHADER)
 #if defined(IS_UBERSHADER)
-uniform highp uint ubershader_flags;
+uniform highp int ubershader_flags;
 #endif
 #endif
 
 
 // any code here is never executed, stuff is filled just so it works
 // any code here is never executed, stuff is filled just so it works

+ 2 - 2
drivers/gles3/shaders/scene.glsl

@@ -2,7 +2,7 @@
 [vertex]
 [vertex]
 
 
 #if defined(IS_UBERSHADER)
 #if defined(IS_UBERSHADER)
-uniform highp uint ubershader_flags;
+uniform highp int ubershader_flags;
 #endif
 #endif
 
 
 #define M_PI 3.14159265359
 #define M_PI 3.14159265359
@@ -645,7 +645,7 @@ VERTEX_SHADER_CODE
 [fragment]
 [fragment]
 
 
 #if defined(IS_UBERSHADER)
 #if defined(IS_UBERSHADER)
-uniform highp uint ubershader_flags;
+uniform highp int ubershader_flags;
 // These are more performant and make the ubershaderification simpler
 // These are more performant and make the ubershaderification simpler
 #define VCT_QUALITY_HIGH
 #define VCT_QUALITY_HIGH
 #define USE_LIGHTMAP_FILTER_BICUBIC
 #define USE_LIGHTMAP_FILTER_BICUBIC