Browse Source

Updated glsl-optimizer.

Branimir Karadžić 10 years ago
parent
commit
80c947d975
100 changed files with 2386 additions and 690 deletions
  1. 2 1
      3rdparty/glsl-optimizer/CMakeLists.txt
  2. 32 0
      3rdparty/glsl-optimizer/Changelog.md
  3. 7 7
      3rdparty/glsl-optimizer/include/c99_compat.h
  4. 31 6
      3rdparty/glsl-optimizer/src/glsl/Makefile
  5. 0 1
      3rdparty/glsl-optimizer/src/glsl/builtin_functions.cpp
  6. 2 8
      3rdparty/glsl-optimizer/src/glsl/builtin_variables.cpp
  7. 36 37
      3rdparty/glsl-optimizer/src/glsl/glcpp/glcpp-lex.c
  8. 0 1
      3rdparty/glsl-optimizer/src/glsl/glcpp/glcpp-lex.l
  9. 86 21
      3rdparty/glsl-optimizer/src/glsl/glsl_optimizer.cpp
  10. 197 32
      3rdparty/glsl-optimizer/src/glsl/ir_print_glsl_visitor.cpp
  11. 3 0
      3rdparty/glsl-optimizer/src/glsl/ir_print_glsl_visitor.h
  12. 30 53
      3rdparty/glsl-optimizer/src/glsl/ir_print_metal_visitor.cpp
  13. 1 1
      3rdparty/glsl-optimizer/src/glsl/linker.cpp
  14. 28 3
      3rdparty/glsl-optimizer/src/glsl/loop_analysis.cpp
  15. 4 2
      3rdparty/glsl-optimizer/src/glsl/loop_analysis.h
  16. 5 1
      3rdparty/glsl-optimizer/src/glsl/loop_controls.cpp
  17. 5 5
      3rdparty/glsl-optimizer/src/glsl/main.cpp
  18. 2 2
      3rdparty/glsl-optimizer/src/glsl/opt_algebraic.cpp
  19. 2 2
      3rdparty/glsl-optimizer/src/glsl/standalone_scaffolding.cpp
  20. 8 7
      3rdparty/glsl-optimizer/src/glsl_optimizer_lib.gyp
  21. 2 2
      3rdparty/glsl-optimizer/src/mesa/main/compiler.h
  22. 1 1
      3rdparty/glsl-optimizer/tests/fragment/array-const-out.txt
  23. 1 1
      3rdparty/glsl-optimizer/tests/fragment/array-const-outES.txt
  24. 1 1
      3rdparty/glsl-optimizer/tests/fragment/array-const-outES3.txt
  25. 1 1
      3rdparty/glsl-optimizer/tests/fragment/array-const-outES3Metal.txt
  26. 1 1
      3rdparty/glsl-optimizer/tests/fragment/array-constconst-out.txt
  27. 1 1
      3rdparty/glsl-optimizer/tests/fragment/array-constconst-outES.txt
  28. 1 1
      3rdparty/glsl-optimizer/tests/fragment/array-constconst-outES3.txt
  29. 1 1
      3rdparty/glsl-optimizer/tests/fragment/array-constconst-outES3Metal.txt
  30. 1 1
      3rdparty/glsl-optimizer/tests/fragment/ast-outES3.txt
  31. 78 0
      3rdparty/glsl-optimizer/tests/fragment/bug-loop-undeclaredinductor-inES3.txt
  32. 88 0
      3rdparty/glsl-optimizer/tests/fragment/bug-loop-undeclaredinductor-outES3.txt
  33. 97 0
      3rdparty/glsl-optimizer/tests/fragment/bug-loop-undeclaredinductor-outES3Metal.txt
  34. 21 0
      3rdparty/glsl-optimizer/tests/fragment/float-literals-in.txt
  35. 23 0
      3rdparty/glsl-optimizer/tests/fragment/float-literals-out.txt
  36. 20 2
      3rdparty/glsl-optimizer/tests/fragment/intrinsics-inES3.txt
  37. 16 16
      3rdparty/glsl-optimizer/tests/fragment/intrinsics-outES.txt
  38. 37 17
      3rdparty/glsl-optimizer/tests/fragment/intrinsics-outES3.txt
  39. 36 16
      3rdparty/glsl-optimizer/tests/fragment/intrinsics-outES3Metal.txt
  40. 1 1
      3rdparty/glsl-optimizer/tests/fragment/loop-for-inES3.txt
  41. 1 1
      3rdparty/glsl-optimizer/tests/fragment/loop-forafterdiscard-inES3.txt
  42. 1 1
      3rdparty/glsl-optimizer/tests/fragment/loop-fornounroll-outES.txt
  43. 2 2
      3rdparty/glsl-optimizer/tests/fragment/loop-forunbounded-outES.txt
  44. 2 2
      3rdparty/glsl-optimizer/tests/fragment/opt-movevars-sideeffect2-outES.txt
  45. 6 6
      3rdparty/glsl-optimizer/tests/fragment/prec-default-outES.txt
  46. 5 5
      3rdparty/glsl-optimizer/tests/fragment/prec-inlineexpr1-outES.txt
  47. 5 5
      3rdparty/glsl-optimizer/tests/fragment/prec-inlineexpr2-outES.txt
  48. 28 0
      3rdparty/glsl-optimizer/tests/fragment/prec-matrix-constr-inES3.txt
  49. 25 0
      3rdparty/glsl-optimizer/tests/fragment/prec-matrix-constr-outES3.txt
  50. 34 0
      3rdparty/glsl-optimizer/tests/fragment/prec-matrix-constr-outES3Metal.txt
  51. 6 6
      3rdparty/glsl-optimizer/tests/fragment/sampler-precision-inES3.txt
  52. 10 1
      3rdparty/glsl-optimizer/tests/fragment/tex2dlod-outES.txt
  53. 2 2
      3rdparty/glsl-optimizer/tests/fragment/texOffset-outES3.txt
  54. 20 2
      3rdparty/glsl-optimizer/tests/fragment/texProj-outES.txt
  55. 136 0
      3rdparty/glsl-optimizer/tests/fragment/z-DirLMBasis-inES3.txt
  56. 55 0
      3rdparty/glsl-optimizer/tests/fragment/z-DirLMBasis-outES3.txt
  57. 64 0
      3rdparty/glsl-optimizer/tests/fragment/z-DirLMBasis-outES3Metal.txt
  58. 1 1
      3rdparty/glsl-optimizer/tests/fragment/z-LightShaftsCoord-outES3.txt
  59. 2 2
      3rdparty/glsl-optimizer/tests/fragment/z-alphabumpspec-inES3.txt
  60. 3 1
      3rdparty/glsl-optimizer/tests/fragment/z-alphabumpspec-outES3.txt
  61. 3 1
      3rdparty/glsl-optimizer/tests/fragment/z-alphabumpspec-outES3Metal.txt
  62. 2 2
      3rdparty/glsl-optimizer/tests/fragment/z-collectshadows-inES3.txt
  63. 1 1
      3rdparty/glsl-optimizer/tests/fragment/z-fxaa-preset3-inES3.txt
  64. 14 14
      3rdparty/glsl-optimizer/tests/fragment/z-fxaa-preset3-out.txt
  65. 15 15
      3rdparty/glsl-optimizer/tests/fragment/z-fxaa-preset3-outES3.txt
  66. 14 14
      3rdparty/glsl-optimizer/tests/fragment/z-fxaa-preset3-outES3Metal.txt
  67. 16 7
      3rdparty/glsl-optimizer/tests/fragment/z-fxaa3-11-consolepc-outES.txt
  68. 41 32
      3rdparty/glsl-optimizer/tests/fragment/z-fxaa3-11-pc39-outES.txt
  69. 5 5
      3rdparty/glsl-optimizer/tests/fragment/z-prepasslight-inES3.txt
  70. 73 75
      3rdparty/glsl-optimizer/tests/fragment/z-prepasslight-outES.txt
  71. 73 75
      3rdparty/glsl-optimizer/tests/fragment/z-prepasslight-outES3.txt
  72. 73 75
      3rdparty/glsl-optimizer/tests/fragment/z-prepasslight-outES3Metal.txt
  73. 3 3
      3rdparty/glsl-optimizer/tests/fragment/z-treeleafloop-inES3.txt
  74. 11 11
      3rdparty/glsl-optimizer/tests/fragment/z-unishader-dirlm-inES3.txt
  75. 9 7
      3rdparty/glsl-optimizer/tests/fragment/z-unishader-dirlm-outES3.txt
  76. 4 2
      3rdparty/glsl-optimizer/tests/fragment/z-unishader-dirlm-outES3Metal.txt
  77. 2 2
      3rdparty/glsl-optimizer/tests/fragment/zun-MobileBumpSpec-inES3.txt
  78. 2 2
      3rdparty/glsl-optimizer/tests/fragment/zun-SSAO24-outES3.txt
  79. 4 4
      3rdparty/glsl-optimizer/tests/fragment/zun-SSAO24-outES3Metal.txt
  80. 2 2
      3rdparty/glsl-optimizer/tests/fragment/zun-SSAO8-outES.txt
  81. 31 0
      3rdparty/glsl-optimizer/tests/global-mutable-inES.txt
  82. 68 0
      3rdparty/glsl-optimizer/tests/global-mutable-inES3.txt
  83. 35 0
      3rdparty/glsl-optimizer/tests/global-mutable-outES.txt
  84. 54 0
      3rdparty/glsl-optimizer/tests/global-mutable-outES3.txt
  85. 63 0
      3rdparty/glsl-optimizer/tests/global-mutable-outES3Metal.txt
  86. 23 12
      3rdparty/glsl-optimizer/tests/glsl_optimizer_tests.cpp
  87. 1 1
      3rdparty/glsl-optimizer/tests/vertex/MF-GodRays-outES.txt
  88. 1 1
      3rdparty/glsl-optimizer/tests/vertex/MF-GodRays-outES3.txt
  89. 9 9
      3rdparty/glsl-optimizer/tests/vertex/bug-swizzle-lhs-cast-outES3.txt
  90. 9 9
      3rdparty/glsl-optimizer/tests/vertex/bug-swizzle-lhs-cast-outES3Metal.txt
  91. 1 1
      3rdparty/glsl-optimizer/tests/vertex/inputs-outES3.txt
  92. 8 10
      3rdparty/glsl-optimizer/tests/vertex/inputs-outES3Metal.txt
  93. 2 2
      3rdparty/glsl-optimizer/tests/vertex/loops-for-withvec4-outES3.txt
  94. 86 0
      3rdparty/glsl-optimizer/tests/vertex/loops-for-withvec4inductorW-inES3.txt
  95. 87 0
      3rdparty/glsl-optimizer/tests/vertex/loops-for-withvec4inductorW-outES3.txt
  96. 97 0
      3rdparty/glsl-optimizer/tests/vertex/loops-for-withvec4inductorW-outES3Metal.txt
  97. 4 4
      3rdparty/glsl-optimizer/tests/vertex/opt-matrix-transpose-mul-outES3.txt
  98. 1 1
      3rdparty/glsl-optimizer/tests/vertex/opt-normalize-out.txt
  99. 1 1
      3rdparty/glsl-optimizer/tests/vertex/uniforms-arrays-outES3.txt
  100. 121 0
      3rdparty/glsl-optimizer/tests/vertex/z-NichsHybridLightVectorInsertBug-in.txt

+ 2 - 1
3rdparty/glsl-optimizer/CMakeLists.txt

@@ -4,6 +4,7 @@ include_directories(include)
 include_directories(src/mesa)
 include_directories(src/mesa)
 include_directories(src/mapi)
 include_directories(src/mapi)
 include_directories(src/glsl)
 include_directories(src/glsl)
+include_directories(src)
 
 
 option (DEBUG "Enable debugging" FALSE)
 option (DEBUG "Enable debugging" FALSE)
 
 
@@ -16,7 +17,7 @@ else()
     set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
     set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -s")
 endif()
 endif()
 
 
-file(GLOB glcpp-library_sources src/glsl/glcpp/*.c)
+file(GLOB glcpp-library_sources src/glsl/glcpp/*.c src/util/*.c)
 #file(GLOB glcpp-library_sources_remove src/glsl/glcpp/glcpp.c)
 #file(GLOB glcpp-library_sources_remove src/glsl/glcpp/glcpp.c)
 #list(REMOVE_ITEM glcpp-library_sources ${glcpp-library_sources_remove})
 #list(REMOVE_ITEM glcpp-library_sources ${glcpp-library_sources_remove})
 add_library(glcpp-library ${glcpp-library_sources})
 add_library(glcpp-library ${glcpp-library_sources})

+ 32 - 0
3rdparty/glsl-optimizer/Changelog.md

@@ -1,6 +1,38 @@
 GLSL optimizer Change Log
 GLSL optimizer Change Log
 =========================
 =========================
 
 
+2015 04
+-------
+
+Fixes:
+
+* Metal: fixed some bugs with translation of weird loops.
+
+
+2015 02
+-------
+
+Tweaks:
+
+* Texture LOD sampling functions on GLES2.0 now produce a wrapper call, that does approximation
+  (mip bias) on devices that don't support GL_EXT_shader_texture_lod.
+* Undefined precision integers on GLES now default to highp.
+
+
+2015 01
+-------
+
+Fixes:
+
+* Float literals are printed with 7 significant digits now.
+* Metal: GLSL mod() is properly translated into Metal's fmod().
+* Metal: Fixed some cases of reciprocal (1/x) printing missing half precision cast.
+* GLES3: textureOffset with a mipmap bias is printed correctly now.
+* Fixed a bug with loop inductor detection if the inductor was used before the loop for some things.
+* Fixed printing of int/float bitcast operations.
+* Improved precision determination of some constructs.
+
+
 2014 10
 2014 10
 -------
 -------
 
 

+ 7 - 7
3rdparty/glsl-optimizer/include/c99_compat.h

@@ -134,13 +134,7 @@
  * C99 __func__ macro
  * C99 __func__ macro
  */
  */
 #ifndef __func__
 #ifndef __func__
-#  if defined(_MSC_VER)
-#    if _MSC_VER >= 1300
-#      define __func__ __FUNCTION__
-#    else
-#      define __func__ "<unknown>"
-#    endif
-#  elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)
+#  if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(_MSC_VER)
      /* C99 */
      /* C99 */
 #  elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
 #  elif defined(__SUNPRO_C) && defined(__C99FEATURES__)
      /* C99 */
      /* C99 */
@@ -150,6 +144,12 @@
 #    else
 #    else
 #      define __func__ "<unknown>"
 #      define __func__ "<unknown>"
 #    endif
 #    endif
+#  elif defined(_MSC_VER)
+#    if _MSC_VER >= 1300
+#      define __func__ __FUNCTION__
+#    else
+#      define __func__ "<unknown>"
+#    endif
 #  else
 #  else
 #    define __func__ "<unknown>"
 #    define __func__ "<unknown>"
 #  endif
 #  endif

+ 31 - 6
3rdparty/glsl-optimizer/src/glsl/Makefile

@@ -3,17 +3,21 @@
 CPPFLAGS += -I../talloc \
 CPPFLAGS += -I../talloc \
 	-I../mesa \
 	-I../mesa \
 	-I../mapi \
 	-I../mapi \
-	-I../../include
+	-I../../include \
+	-I..
 
 
 CXXFLAGS += -s -Wall -Os -fdata-sections -ffunction-sections
 CXXFLAGS += -s -Wall -Os -fdata-sections -ffunction-sections
 CFLAGS += -s -Wall -Os -fdata-sections -ffunction-sections
 CFLAGS += -s -Wall -Os -fdata-sections -ffunction-sections
 
 
 # This list gleaned from the VC project file. Update when needed
 # This list gleaned from the VC project file. Update when needed
-SRC =	ast_expr.cpp \
+SRC = ast_array_index.cpp \
+	ast_expr.cpp \
 	ast_function.cpp \
 	ast_function.cpp \
 	ast_to_hir.cpp \
 	ast_to_hir.cpp \
 	ast_type.cpp \
 	ast_type.cpp \
 	builtin_functions.cpp \
 	builtin_functions.cpp \
+	builtin_types.cpp \
+	builtin_variables.cpp \
 	glsl_lexer.cpp \
 	glsl_lexer.cpp \
 	glsl_optimizer.cpp \
 	glsl_optimizer.cpp \
 	glsl_parser.cpp \
 	glsl_parser.cpp \
@@ -42,21 +46,38 @@ SRC =	ast_expr.cpp \
 	ir_unused_structs.cpp \
 	ir_unused_structs.cpp \
 	ir_validate.cpp \
 	ir_validate.cpp \
 	ir_variable_refcount.cpp \
 	ir_variable_refcount.cpp \
-	link_functions.cpp \
+	link_atomics.cpp \
 	linker.cpp \
 	linker.cpp \
+	link_functions.cpp \
+	link_interface_blocks.cpp \
+	link_uniform_block_active_visitor.cpp \
+	link_uniform_blocks.cpp \
+	link_uniform_initializers.cpp \
+	link_uniforms.cpp \
+	link_varyings.cpp \
 	loop_analysis.cpp \
 	loop_analysis.cpp \
 	loop_controls.cpp \
 	loop_controls.cpp \
 	loop_unroll.cpp \
 	loop_unroll.cpp \
+	lower_clip_distance.cpp \
 	lower_discard.cpp \
 	lower_discard.cpp \
+	lower_discard_flow.cpp \
 	lower_if_to_cond_assign.cpp \
 	lower_if_to_cond_assign.cpp \
 	lower_instructions.cpp \
 	lower_instructions.cpp \
 	lower_jumps.cpp \
 	lower_jumps.cpp \
 	lower_mat_op_to_vec.cpp \
 	lower_mat_op_to_vec.cpp \
+	lower_named_interface_blocks.cpp \
 	lower_noise.cpp \
 	lower_noise.cpp \
+	lower_offset_array.cpp \
+	lower_output_reads.cpp \
+	lower_packed_varyings.cpp \
+	lower_packing_builtins.cpp \
+	lower_ubo_reference.cpp \
 	lower_variable_index_to_cond_assign.cpp \
 	lower_variable_index_to_cond_assign.cpp \
 	lower_vec_index_to_cond_assign.cpp \
 	lower_vec_index_to_cond_assign.cpp \
 	lower_vec_index_to_swizzle.cpp \
 	lower_vec_index_to_swizzle.cpp \
 	lower_vector.cpp \
 	lower_vector.cpp \
+	lower_vector_insert.cpp \
+	lower_vertex_id.cpp \
 	opt_algebraic.cpp \
 	opt_algebraic.cpp \
 	opt_array_splitting.cpp \
 	opt_array_splitting.cpp \
 	opt_constant_folding.cpp \
 	opt_constant_folding.cpp \
@@ -65,6 +86,7 @@ SRC =	ast_expr.cpp \
 	opt_copy_propagation.cpp \
 	opt_copy_propagation.cpp \
 	opt_copy_propagation_elements.cpp \
 	opt_copy_propagation_elements.cpp \
 	opt_cse.cpp \
 	opt_cse.cpp \
+	opt_dead_builtin_variables.cpp \
 	opt_dead_builtin_varyings.cpp \
 	opt_dead_builtin_varyings.cpp \
 	opt_dead_code.cpp \
 	opt_dead_code.cpp \
 	opt_dead_code_local.cpp \
 	opt_dead_code_local.cpp \
@@ -73,23 +95,26 @@ SRC =	ast_expr.cpp \
 	opt_flip_matrices.cpp \
 	opt_flip_matrices.cpp \
 	opt_function_inlining.cpp \
 	opt_function_inlining.cpp \
 	opt_if_simplification.cpp \
 	opt_if_simplification.cpp \
+	opt_minmax.cpp \
 	opt_noop_swizzle.cpp \
 	opt_noop_swizzle.cpp \
+	opt_rebalance_tree.cpp \
 	opt_redundant_jumps.cpp \
 	opt_redundant_jumps.cpp \
 	opt_structure_splitting.cpp \
 	opt_structure_splitting.cpp \
 	opt_swizzle_swizzle.cpp \
 	opt_swizzle_swizzle.cpp \
 	opt_tree_grafting.cpp \
 	opt_tree_grafting.cpp \
 	opt_vectorize.cpp \
 	opt_vectorize.cpp \
-	ralloc.c \
+	opt_vector_splitting.cpp \
 	s_expression.cpp \
 	s_expression.cpp \
 	standalone_scaffolding.cpp \
 	standalone_scaffolding.cpp \
 	strtod.c \
 	strtod.c \
 	glcpp/glcpp-lex.c \
 	glcpp/glcpp-lex.c \
 	glcpp/glcpp-parse.c \
 	glcpp/glcpp-parse.c \
 	glcpp/pp.c \
 	glcpp/pp.c \
-	../mesa/main/hash_table.c \
 	../mesa/main/imports.c \
 	../mesa/main/imports.c \
 	../mesa/program/prog_hash_table.c \
 	../mesa/program/prog_hash_table.c \
-	../mesa/program/symbol_table.c
+	../mesa/program/symbol_table.c \
+	../util/hash_table.c \
+	../util/ralloc.c
 
 
 
 
 OBJS1 = $(SRC:.cpp=.o)
 OBJS1 = $(SRC:.cpp=.o)

+ 0 - 1
3rdparty/glsl-optimizer/src/glsl/builtin_functions.cpp

@@ -53,7 +53,6 @@
  *    name and parameters.
  *    name and parameters.
  */
  */
 
 
-#define _USE_MATH_DEFINES
 #include <stdarg.h>
 #include <stdarg.h>
 #include <stdio.h>
 #include <stdio.h>
 #include "main/core.h" /* for struct gl_shader */
 #include "main/core.h" /* for struct gl_shader */

+ 2 - 8
3rdparty/glsl-optimizer/src/glsl/builtin_variables.cpp

@@ -934,14 +934,14 @@ builtin_variable_generator::generate_fs_special_vars()
       if (state->AMD_shader_stencil_export_warn)
       if (state->AMD_shader_stencil_export_warn)
          var->enable_extension_warning("GL_AMD_shader_stencil_export");
          var->enable_extension_warning("GL_AMD_shader_stencil_export");
    }
    }
-
+	
 	if (state->EXT_frag_depth_enable) {
 	if (state->EXT_frag_depth_enable) {
 		ir_variable *const var =
 		ir_variable *const var =
 		add_output(FRAG_RESULT_DEPTH, float_t, "gl_FragDepthEXT", glsl_precision_high);
 		add_output(FRAG_RESULT_DEPTH, float_t, "gl_FragDepthEXT", glsl_precision_high);
 		if (state->EXT_frag_depth_warn)
 		if (state->EXT_frag_depth_warn)
 			var->enable_extension_warning("GL_EXT_frag_depth");
 			var->enable_extension_warning("GL_EXT_frag_depth");
 	}
 	}
-
+	
 	if (state->EXT_shader_framebuffer_fetch_enable) {
 	if (state->EXT_shader_framebuffer_fetch_enable) {
 		ir_variable *const var =
 		ir_variable *const var =
 			add_input(VARYING_SLOT_VAR0, array(vec4_t, state->Const.MaxDrawBuffers), "gl_LastFragData", glsl_precision_medium);
 			add_input(VARYING_SLOT_VAR0, array(vec4_t, state->Const.MaxDrawBuffers), "gl_LastFragData", glsl_precision_medium);
@@ -949,12 +949,6 @@ builtin_variable_generator::generate_fs_special_vars()
 			var->enable_extension_warning("GL_EXT_shader_framebuffer_fetch");
 			var->enable_extension_warning("GL_EXT_shader_framebuffer_fetch");
 	}
 	}
 
 
-	{
-		ir_variable *var;
-		var = add_output(VARYING_SLOT_PRIMITIVE_ID, int_t, "gl_PrimitiveID", glsl_precision_high);
-		var->data.interpolation = INTERP_QUALIFIER_FLAT;
-	}
-
    if (state->ARB_sample_shading_enable) {
    if (state->ARB_sample_shading_enable) {
       add_system_value(SYSTEM_VALUE_SAMPLE_ID, int_t, "gl_SampleID", glsl_precision_high);
       add_system_value(SYSTEM_VALUE_SAMPLE_ID, int_t, "gl_SampleID", glsl_precision_high);
       add_system_value(SYSTEM_VALUE_SAMPLE_POS, vec2_t, "gl_SamplePosition", glsl_precision_high);
       add_system_value(SYSTEM_VALUE_SAMPLE_POS, vec2_t, "gl_SamplePosition", glsl_precision_high);

+ 36 - 37
3rdparty/glsl-optimizer/src/glsl/glcpp/glcpp-lex.c

@@ -21,7 +21,6 @@
 #include <string.h>
 #include <string.h>
 #include <errno.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <stdlib.h>
-#include <c99_compat.h>
 
 
 /* end standard C headers. */
 /* end standard C headers. */
 
 
@@ -35,7 +34,7 @@
 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
 #if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
 
 
 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
 /* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
- * if you want the limit (max/min) macros for int types.
+ * if you want the limit (max/min) macros for int types. 
  */
  */
 #ifndef __STDC_LIMIT_MACROS
 #ifndef __STDC_LIMIT_MACROS
 #define __STDC_LIMIT_MACROS 1
 #define __STDC_LIMIT_MACROS 1
@@ -52,7 +51,7 @@ typedef uint32_t flex_uint32_t;
 typedef signed char flex_int8_t;
 typedef signed char flex_int8_t;
 typedef short int flex_int16_t;
 typedef short int flex_int16_t;
 typedef int flex_int32_t;
 typedef int flex_int32_t;
-typedef unsigned char flex_uint8_t;
+typedef unsigned char flex_uint8_t; 
 typedef unsigned short int flex_uint16_t;
 typedef unsigned short int flex_uint16_t;
 typedef unsigned int flex_uint32_t;
 typedef unsigned int flex_uint32_t;
 
 
@@ -185,7 +184,7 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE;
 #define EOB_ACT_LAST_MATCH 2
 #define EOB_ACT_LAST_MATCH 2
 
 
     #define YY_LESS_LINENO(n)
     #define YY_LESS_LINENO(n)
-
+    
 /* Return all but the first "n" matched characters back to the input stream. */
 /* Return all but the first "n" matched characters back to the input stream. */
 #define yyless(n) \
 #define yyless(n) \
 	do \
 	do \
@@ -247,7 +246,7 @@ struct yy_buffer_state
 
 
     int yy_bs_lineno; /**< The line count. */
     int yy_bs_lineno; /**< The line count. */
     int yy_bs_column; /**< The column count. */
     int yy_bs_column; /**< The column count. */
-
+    
 	/* Whether to try to fill the input buffer when we reach the
 	/* Whether to try to fill the input buffer when we reach the
 	 * end of it.
 	 * end of it.
 	 */
 	 */
@@ -823,9 +822,9 @@ static int yy_init_globals (yyscan_t yyscanner );
     /* This must go here because YYSTYPE and YYLTYPE are included
     /* This must go here because YYSTYPE and YYLTYPE are included
      * from bison output in section 1.*/
      * from bison output in section 1.*/
     #    define yylval yyg->yylval_r
     #    define yylval yyg->yylval_r
-
+    
     #    define yylloc yyg->yylloc_r
     #    define yylloc yyg->yylloc_r
-
+    
 int glcpp_lex_init (yyscan_t* scanner);
 int glcpp_lex_init (yyscan_t* scanner);
 
 
 int glcpp_lex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
 int glcpp_lex_init_extra (YY_EXTRA_TYPE user_defined,yyscan_t* scanner);
@@ -864,9 +863,9 @@ YYSTYPE * glcpp_get_lval (yyscan_t yyscanner );
 void glcpp_set_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
 void glcpp_set_lval (YYSTYPE * yylval_param ,yyscan_t yyscanner );
 
 
        YYLTYPE *glcpp_get_lloc (yyscan_t yyscanner );
        YYLTYPE *glcpp_get_lloc (yyscan_t yyscanner );
-
+    
         void glcpp_set_lloc (YYLTYPE * yylloc_param ,yyscan_t yyscanner );
         void glcpp_set_lloc (YYLTYPE * yylloc_param ,yyscan_t yyscanner );
-
+    
 /* Macros after this point can all be overridden by user definitions in
 /* Macros after this point can all be overridden by user definitions in
  * section 1.
  * section 1.
  */
  */
@@ -880,7 +879,7 @@ extern int glcpp_wrap (yyscan_t yyscanner );
 #endif
 #endif
 
 
     static void yyunput (int c,char *buf_ptr  ,yyscan_t yyscanner);
     static void yyunput (int c,char *buf_ptr  ,yyscan_t yyscanner);
-
+    
 #ifndef yytext_ptr
 #ifndef yytext_ptr
 static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
 static void yy_flex_strncpy (char *,yyconst char *,int ,yyscan_t yyscanner);
 #endif
 #endif
@@ -900,11 +899,11 @@ static int input (yyscan_t yyscanner );
 #endif
 #endif
 
 
     static void yy_push_state (int new_state ,yyscan_t yyscanner);
     static void yy_push_state (int new_state ,yyscan_t yyscanner);
-
+    
     static void yy_pop_state (yyscan_t yyscanner );
     static void yy_pop_state (yyscan_t yyscanner );
-
+    
     static int yy_top_state (yyscan_t yyscanner );
     static int yy_top_state (yyscan_t yyscanner );
-
+    
 /* Amount of stuff to slurp up with each read. */
 /* Amount of stuff to slurp up with each read. */
 #ifndef YY_READ_BUF_SIZE
 #ifndef YY_READ_BUF_SIZE
 #ifdef __ia64__
 #ifdef __ia64__
@@ -1362,7 +1361,7 @@ YY_RULE_SETUP
 	 * While in the <DEFINE> state we also need to explicitly
 	 * While in the <DEFINE> state we also need to explicitly
 	 * handle a few other things that may appear before the
 	 * handle a few other things that may appear before the
 	 * identifier:
 	 * identifier:
-	 *
+	 * 
 	 * 	* Comments, (handled above with the main support for
 	 * 	* Comments, (handled above with the main support for
 	 * 	  comments).
 	 * 	  comments).
 	 *
 	 *
@@ -2185,7 +2184,7 @@ static void glcpp__load_buffer_state  (yyscan_t yyscanner)
     YY_BUFFER_STATE glcpp__create_buffer  (FILE * file, int  size , yyscan_t yyscanner)
     YY_BUFFER_STATE glcpp__create_buffer  (FILE * file, int  size , yyscan_t yyscanner)
 {
 {
 	YY_BUFFER_STATE b;
 	YY_BUFFER_STATE b;
-
+    
 	b = (YY_BUFFER_STATE) glcpp_alloc(sizeof( struct yy_buffer_state ) ,yyscanner );
 	b = (YY_BUFFER_STATE) glcpp_alloc(sizeof( struct yy_buffer_state ) ,yyscanner );
 	if ( ! b )
 	if ( ! b )
 		YY_FATAL_ERROR( "out of dynamic memory in glcpp__create_buffer()" );
 		YY_FATAL_ERROR( "out of dynamic memory in glcpp__create_buffer()" );
@@ -2251,7 +2250,7 @@ static void glcpp__load_buffer_state  (yyscan_t yyscanner)
     }
     }
 
 
         b->yy_is_interactive = 0;
         b->yy_is_interactive = 0;
-
+    
 	errno = oerrno;
 	errno = oerrno;
 }
 }
 
 
@@ -2357,9 +2356,9 @@ static void glcpp_ensure_buffer_stack (yyscan_t yyscanner)
 								, yyscanner);
 								, yyscanner);
 		if ( ! yyg->yy_buffer_stack )
 		if ( ! yyg->yy_buffer_stack )
 			YY_FATAL_ERROR( "out of dynamic memory in glcpp_ensure_buffer_stack()" );
 			YY_FATAL_ERROR( "out of dynamic memory in glcpp_ensure_buffer_stack()" );
-
+								  
 		memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
 		memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
-
+				
 		yyg->yy_buffer_stack_max = num_to_alloc;
 		yyg->yy_buffer_stack_max = num_to_alloc;
 		yyg->yy_buffer_stack_top = 0;
 		yyg->yy_buffer_stack_top = 0;
 		return;
 		return;
@@ -2388,12 +2387,12 @@ static void glcpp_ensure_buffer_stack (yyscan_t yyscanner)
  * @param base the character buffer
  * @param base the character buffer
  * @param size the size in bytes of the character buffer
  * @param size the size in bytes of the character buffer
  * @param yyscanner The scanner object.
  * @param yyscanner The scanner object.
- * @return the newly allocated buffer state object.
+ * @return the newly allocated buffer state object. 
  */
  */
 YY_BUFFER_STATE glcpp__scan_buffer  (char * base, yy_size_t  size , yyscan_t yyscanner)
 YY_BUFFER_STATE glcpp__scan_buffer  (char * base, yy_size_t  size , yyscan_t yyscanner)
 {
 {
 	YY_BUFFER_STATE b;
 	YY_BUFFER_STATE b;
-
+    
 	if ( size < 2 ||
 	if ( size < 2 ||
 	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
 	     base[size-2] != YY_END_OF_BUFFER_CHAR ||
 	     base[size-1] != YY_END_OF_BUFFER_CHAR )
 	     base[size-1] != YY_END_OF_BUFFER_CHAR )
@@ -2429,7 +2428,7 @@ YY_BUFFER_STATE glcpp__scan_buffer  (char * base, yy_size_t  size , yyscan_t yys
  */
  */
 YY_BUFFER_STATE glcpp__scan_string (yyconst char * yystr , yyscan_t yyscanner)
 YY_BUFFER_STATE glcpp__scan_string (yyconst char * yystr , yyscan_t yyscanner)
 {
 {
-
+    
 	return glcpp__scan_bytes(yystr,strlen(yystr) ,yyscanner);
 	return glcpp__scan_bytes(yystr,strlen(yystr) ,yyscanner);
 }
 }
 
 
@@ -2446,7 +2445,7 @@ YY_BUFFER_STATE glcpp__scan_bytes  (yyconst char * yybytes, int  _yybytes_len ,
 	char *buf;
 	char *buf;
 	yy_size_t n;
 	yy_size_t n;
 	int i;
 	int i;
-
+    
 	/* Get memory for full buffer, including space for trailing EOB's. */
 	/* Get memory for full buffer, including space for trailing EOB's. */
 	n = _yybytes_len + 2;
 	n = _yybytes_len + 2;
 	buf = (char *) glcpp_alloc(n ,yyscanner );
 	buf = (char *) glcpp_alloc(n ,yyscanner );
@@ -2554,10 +2553,10 @@ YY_EXTRA_TYPE glcpp_get_extra  (yyscan_t yyscanner)
 int glcpp_get_lineno  (yyscan_t yyscanner)
 int glcpp_get_lineno  (yyscan_t yyscanner)
 {
 {
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
+    
         if (! YY_CURRENT_BUFFER)
         if (! YY_CURRENT_BUFFER)
             return 0;
             return 0;
-
+    
     return yylineno;
     return yylineno;
 }
 }
 
 
@@ -2567,10 +2566,10 @@ int glcpp_get_lineno  (yyscan_t yyscanner)
 int glcpp_get_column  (yyscan_t yyscanner)
 int glcpp_get_column  (yyscan_t yyscanner)
 {
 {
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
-
+    
         if (! YY_CURRENT_BUFFER)
         if (! YY_CURRENT_BUFFER)
             return 0;
             return 0;
-
+    
     return yycolumn;
     return yycolumn;
 }
 }
 
 
@@ -2631,8 +2630,8 @@ void glcpp_set_lineno (int  line_number , yyscan_t yyscanner)
 
 
         /* lineno is only valid if an input buffer exists. */
         /* lineno is only valid if an input buffer exists. */
         if (! YY_CURRENT_BUFFER )
         if (! YY_CURRENT_BUFFER )
-           yy_fatal_error( "glcpp_set_lineno called with no buffer" , yyscanner);
-
+           yy_fatal_error( "glcpp_set_lineno called with no buffer" , yyscanner); 
+    
     yylineno = line_number;
     yylineno = line_number;
 }
 }
 
 
@@ -2646,8 +2645,8 @@ void glcpp_set_column (int  column_no , yyscan_t yyscanner)
 
 
         /* column is only valid if an input buffer exists. */
         /* column is only valid if an input buffer exists. */
         if (! YY_CURRENT_BUFFER )
         if (! YY_CURRENT_BUFFER )
-           yy_fatal_error( "glcpp_set_column called with no buffer" , yyscanner);
-
+           yy_fatal_error( "glcpp_set_column called with no buffer" , yyscanner); 
+    
     yycolumn = column_no;
     yycolumn = column_no;
 }
 }
 
 
@@ -2700,13 +2699,13 @@ YYLTYPE *glcpp_get_lloc  (yyscan_t yyscanner)
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
     return yylloc;
     return yylloc;
 }
 }
-
+    
 void glcpp_set_lloc (YYLTYPE *  yylloc_param , yyscan_t yyscanner)
 void glcpp_set_lloc (YYLTYPE *  yylloc_param , yyscan_t yyscanner)
 {
 {
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
     yylloc = yylloc_param;
     yylloc = yylloc_param;
 }
 }
-
+    
 /* User-visible API */
 /* User-visible API */
 
 
 /* glcpp_lex_init is special because it creates the scanner itself, so it is
 /* glcpp_lex_init is special because it creates the scanner itself, so it is
@@ -2754,20 +2753,20 @@ int glcpp_lex_init_extra(YY_EXTRA_TYPE yy_user_defined,yyscan_t* ptr_yy_globals
         errno = EINVAL;
         errno = EINVAL;
         return 1;
         return 1;
     }
     }
-
+	
     *ptr_yy_globals = (yyscan_t) glcpp_alloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
     *ptr_yy_globals = (yyscan_t) glcpp_alloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
-
+	
     if (*ptr_yy_globals == NULL){
     if (*ptr_yy_globals == NULL){
         errno = ENOMEM;
         errno = ENOMEM;
         return 1;
         return 1;
     }
     }
-
+    
     /* By setting to 0xAA, we expose bugs in
     /* By setting to 0xAA, we expose bugs in
     yy_init_globals. Leave at 0x00 for releases. */
     yy_init_globals. Leave at 0x00 for releases. */
     memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
     memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
-
+    
     glcpp_set_extra (yy_user_defined, *ptr_yy_globals);
     glcpp_set_extra (yy_user_defined, *ptr_yy_globals);
-
+    
     return yy_init_globals ( *ptr_yy_globals );
     return yy_init_globals ( *ptr_yy_globals );
 }
 }
 
 

+ 0 - 1
3rdparty/glsl-optimizer/src/glsl/glcpp/glcpp-lex.l

@@ -25,7 +25,6 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <string.h>
 #include <string.h>
 #include <ctype.h>
 #include <ctype.h>
-#include <c99_compat.h>
 
 
 #include "glcpp.h"
 #include "glcpp.h"
 #include "glcpp-parse.h"
 #include "glcpp-parse.h"

+ 86 - 21
3rdparty/glsl-optimizer/src/glsl/glsl_optimizer.cpp

@@ -206,6 +206,14 @@ static inline void debug_print_ir (const char* name, exec_list* ir, _mesa_glsl_p
 	#endif
 	#endif
 }
 }
 
 
+
+struct precision_ctx
+{
+	exec_list* root_ir;
+	bool res;
+};
+
+
 static void propagate_precision_deref(ir_instruction *ir, void *data)
 static void propagate_precision_deref(ir_instruction *ir, void *data)
 {
 {
 	// variable deref with undefined precision: take from variable itself
 	// variable deref with undefined precision: take from variable itself
@@ -213,7 +221,7 @@ static void propagate_precision_deref(ir_instruction *ir, void *data)
 	if (der && der->get_precision() == glsl_precision_undefined && der->var->data.precision != glsl_precision_undefined)
 	if (der && der->get_precision() == glsl_precision_undefined && der->var->data.precision != glsl_precision_undefined)
 	{
 	{
 		der->set_precision ((glsl_precision)der->var->data.precision);
 		der->set_precision ((glsl_precision)der->var->data.precision);
-		*(bool*)data = true;
+		((precision_ctx*)data)->res = true;
 	}
 	}
 	
 	
 	// array deref with undefined precision: take from array itself
 	// array deref with undefined precision: take from array itself
@@ -221,7 +229,7 @@ static void propagate_precision_deref(ir_instruction *ir, void *data)
 	if (der_arr && der_arr->get_precision() == glsl_precision_undefined && der_arr->array->get_precision() != glsl_precision_undefined)
 	if (der_arr && der_arr->get_precision() == glsl_precision_undefined && der_arr->array->get_precision() != glsl_precision_undefined)
 	{
 	{
 		der_arr->set_precision (der_arr->array->get_precision());
 		der_arr->set_precision (der_arr->array->get_precision());
-		*(bool*)data = true;
+		((precision_ctx*)data)->res = true;
 	}
 	}
 	
 	
 	// swizzle with undefined precision: take from swizzle argument
 	// swizzle with undefined precision: take from swizzle argument
@@ -229,7 +237,7 @@ static void propagate_precision_deref(ir_instruction *ir, void *data)
 	if (swz && swz->get_precision() == glsl_precision_undefined && swz->val->get_precision() != glsl_precision_undefined)
 	if (swz && swz->get_precision() == glsl_precision_undefined && swz->val->get_precision() != glsl_precision_undefined)
 	{
 	{
 		swz->set_precision (swz->val->get_precision());
 		swz->set_precision (swz->val->get_precision());
-		*(bool*)data = true;
+		((precision_ctx*)data)->res = true;
 	}
 	}
 	
 	
 }
 }
@@ -252,32 +260,88 @@ static void propagate_precision_expr(ir_instruction *ir, void *data)
 	if (expr->get_precision() != prec_params_max)
 	if (expr->get_precision() != prec_params_max)
 	{
 	{
 		expr->set_precision (prec_params_max);
 		expr->set_precision (prec_params_max);
-		*(bool*)data = true;
+		((precision_ctx*)data)->res = true;
 	}
 	}
 	
 	
 }
 }
 
 
+struct undefined_ass_ctx
+{
+	ir_variable* var;
+	bool res;
+};
+
+static void has_only_undefined_precision_assignments(ir_instruction *ir, void *data)
+{
+	ir_assignment* ass = ir->as_assignment();
+	if (!ass)
+		return;
+	undefined_ass_ctx* ctx = (undefined_ass_ctx*)data;
+	if (ass->whole_variable_written() != ctx->var)
+		return;
+	glsl_precision prec = ass->rhs->get_precision();
+	if (prec == glsl_precision_undefined)
+		return;
+	ctx->res = false;
+}
+
 
 
 static void propagate_precision_assign(ir_instruction *ir, void *data)
 static void propagate_precision_assign(ir_instruction *ir, void *data)
 {
 {
 	ir_assignment* ass = ir->as_assignment();
 	ir_assignment* ass = ir->as_assignment();
-	if (ass && ass->lhs && ass->rhs)
+	if (!ass || !ass->lhs || !ass->rhs)
+		return;
+
+	glsl_precision lp = ass->lhs->get_precision();
+	glsl_precision rp = ass->rhs->get_precision();
+
+	// for assignments with LHS having undefined precision, take it from RHS
+	if (rp != glsl_precision_undefined)
 	{
 	{
-		glsl_precision lp = ass->lhs->get_precision();
-		glsl_precision rp = ass->rhs->get_precision();
-		if (rp == glsl_precision_undefined)
-			return;
 		ir_variable* lhs_var = ass->lhs->variable_referenced();
 		ir_variable* lhs_var = ass->lhs->variable_referenced();
 		if (lp == glsl_precision_undefined)
 		if (lp == glsl_precision_undefined)
 		{		
 		{		
 			if (lhs_var)
 			if (lhs_var)
 				lhs_var->data.precision = rp;
 				lhs_var->data.precision = rp;
 			ass->lhs->set_precision (rp);
 			ass->lhs->set_precision (rp);
-			*(bool*)data = true;
+			((precision_ctx*)data)->res = true;
+		}
+		return;
+	}
+	
+	// for assignments where LHS has precision, but RHS is a temporary variable
+	// with undefined precision that's only assigned from other undefined precision
+	// sources -> make the RHS variable take LHS precision
+	if (lp != glsl_precision_undefined && rp == glsl_precision_undefined)
+	{
+		ir_dereference* deref = ass->rhs->as_dereference();
+		if (deref)
+		{
+			ir_variable* rhs_var = deref->variable_referenced();
+			if (rhs_var && rhs_var->data.mode == ir_var_temporary && rhs_var->data.precision == glsl_precision_undefined)
+			{
+				undefined_ass_ctx ctx;
+				ctx.var = rhs_var;
+				// find if we only assign to it from undefined precision sources
+				ctx.res = true;
+				exec_list* root_ir = ((precision_ctx*)data)->root_ir;
+				foreach_in_list(ir_instruction, inst, root_ir)
+				{
+					visit_tree (ir, has_only_undefined_precision_assignments, &ctx);
+				}
+				if (ctx.res)
+				{
+					rhs_var->data.precision = lp;
+					ass->rhs->set_precision(lp);
+					((precision_ctx*)data)->res = true;
+				}
+			}
 		}
 		}
+		return;
 	}
 	}
 }
 }
 
 
+
 static void propagate_precision_call(ir_instruction *ir, void *data)
 static void propagate_precision_call(ir_instruction *ir, void *data)
 {
 {
 	ir_call* call = ir->as_call();
 	ir_call* call = ir->as_call();
@@ -302,28 +366,29 @@ static void propagate_precision_call(ir_instruction *ir, void *data)
 		if (call->return_deref->get_precision() != prec_params_max)
 		if (call->return_deref->get_precision() != prec_params_max)
 		{
 		{
 			call->return_deref->set_precision (prec_params_max);
 			call->return_deref->set_precision (prec_params_max);
-			*(bool*)data = true;
+			((precision_ctx*)data)->res = true;
 		}
 		}
 	}
 	}
 }
 }
 
 
-
 static bool propagate_precision(exec_list* list, bool assign_high_to_undefined)
 static bool propagate_precision(exec_list* list, bool assign_high_to_undefined)
 {
 {
 	bool anyProgress = false;
 	bool anyProgress = false;
-	bool res;
+	precision_ctx ctx;
+	
 	do {
 	do {
-		res = false;
+		ctx.res = false;
+		ctx.root_ir = list;
 		foreach_in_list(ir_instruction, ir, list)
 		foreach_in_list(ir_instruction, ir, list)
 		{
 		{
-			visit_tree (ir, propagate_precision_deref, &res);
-			visit_tree (ir, propagate_precision_assign, &res);
-			visit_tree (ir, propagate_precision_call, &res);
-			visit_tree (ir, propagate_precision_expr, &res);
+			visit_tree (ir, propagate_precision_deref, &ctx);
+			visit_tree (ir, propagate_precision_assign, &ctx);
+			visit_tree (ir, propagate_precision_call, &ctx);
+			visit_tree (ir, propagate_precision_expr, &ctx);
 		}
 		}
-		anyProgress |= res;
-	} while (res);
-	anyProgress |= res;
+		anyProgress |= ctx.res;
+	} while (ctx.res);
+	anyProgress |= ctx.res;
 	
 	
 	// for globals that have undefined precision, set it to highp
 	// for globals that have undefined precision, set it to highp
 	if (assign_high_to_undefined)
 	if (assign_high_to_undefined)

+ 197 - 32
3rdparty/glsl-optimizer/src/glsl/ir_print_glsl_visitor.cpp

@@ -47,6 +47,15 @@ static inline const char* get_precision_string (glsl_precision p)
 	return "";
 	return "";
 }
 }
 
 
+static const int tex_sampler_type_count = 7;
+// [glsl_sampler_dim]
+static const char* tex_sampler_dim_name[tex_sampler_type_count] = {
+	"1D", "2D", "3D", "Cube", "Rect", "Buf", "External",
+};
+static int tex_sampler_dim_size[tex_sampler_type_count] = {
+	1, 2, 3, 3, 2, 2, 2,
+};
+
 struct ga_entry : public exec_node
 struct ga_entry : public exec_node
 {
 {
 	ga_entry(ir_instruction* ir)
 	ga_entry(ir_instruction* ir)
@@ -86,6 +95,8 @@ public:
 		, inside_loop_body(false)
 		, inside_loop_body(false)
 		, skipped_this_ir(false)
 		, skipped_this_ir(false)
 		, previous_skipped(false)
 		, previous_skipped(false)
+		, uses_texlod_impl(0)
+		, uses_texlodproj_impl(0)
 	{
 	{
 		indentation = 0;
 		indentation = 0;
 		expression_depth = 0;
 		expression_depth = 0;
@@ -145,8 +156,61 @@ public:
 	bool	inside_loop_body;
 	bool	inside_loop_body;
 	bool	skipped_this_ir;
 	bool	skipped_this_ir;
 	bool	previous_skipped;
 	bool	previous_skipped;
+	int		uses_texlod_impl; // 3 bits per tex_dimension, bit set for each precision if any texture sampler needs the GLES2 lod workaround.
+	int		uses_texlodproj_impl; // 3 bits per tex_dimension, bit set for each precision if any texture sampler needs the GLES2 lod workaround.
 };
 };
 
 
+static void print_texlod_workarounds(int usage_bitfield, int usage_proj_bitfield, string_buffer &str)
+{
+	static const char *precStrings[3] = {"lowp", "mediump", "highp"};
+	static const char *precNameStrings[3] = { "low_", "medium_", "high_" };
+	// Print out the texlod workarounds
+	for (int prec = 0; prec < 3; prec++)
+	{
+		const char *precString = precStrings[prec];
+		const char *precName = precNameStrings[prec];
+
+		for (int dim = 0; dim < tex_sampler_type_count; dim++)
+		{
+			int mask = 1 << (dim + (prec * 8));
+			if (usage_bitfield & mask)
+			{
+				str.asprintf_append("%s vec4 impl_%stexture%sLodEXT(%s sampler%s sampler, highp vec%d coord, mediump float lod)\n", precString, precName, tex_sampler_dim_name[dim], precString, tex_sampler_dim_name[dim], tex_sampler_dim_size[dim]);
+				str.asprintf_append("{\n");
+				str.asprintf_append("#if defined(GL_EXT_shader_texture_lod)\n");
+				str.asprintf_append("\treturn texture%sLodEXT(sampler, coord, lod);\n", tex_sampler_dim_name[dim]);
+				str.asprintf_append("#else\n");
+				str.asprintf_append("\treturn texture%s(sampler, coord, lod);\n", tex_sampler_dim_name[dim]);
+				str.asprintf_append("#endif\n");
+				str.asprintf_append("}\n\n");
+			}
+			if (usage_proj_bitfield & mask)
+			{
+				// 2D projected read also has a vec4 UV variant
+				if (dim == GLSL_SAMPLER_DIM_2D)
+				{
+					str.asprintf_append("%s vec4 impl_%stexture2DProjLodEXT(%s sampler2D sampler, highp vec4 coord, mediump float lod)\n", precString, precName, precString);
+					str.asprintf_append("{\n");
+					str.asprintf_append("#if defined(GL_EXT_shader_texture_lod)\n");
+					str.asprintf_append("\treturn texture%sProjLodEXT(sampler, coord, lod);\n", tex_sampler_dim_name[dim]);
+					str.asprintf_append("#else\n");
+					str.asprintf_append("\treturn texture%sProj(sampler, coord, lod);\n", tex_sampler_dim_name[dim]);
+					str.asprintf_append("#endif\n");
+					str.asprintf_append("}\n\n");
+				}
+				str.asprintf_append("%s vec4 impl_%stexture%sProjLodEXT(%s sampler%s sampler, highp vec%d coord, mediump float lod)\n", precString, precName, tex_sampler_dim_name[dim], precString, tex_sampler_dim_name[dim], tex_sampler_dim_size[dim] + 1);
+				str.asprintf_append("{\n");
+				str.asprintf_append("#if defined(GL_EXT_shader_texture_lod)\n");
+				str.asprintf_append("\treturn texture%sProjLodEXT(sampler, coord, lod);\n", tex_sampler_dim_name[dim]);
+				str.asprintf_append("#else\n");
+				str.asprintf_append("\treturn texture%sProj(sampler, coord, lod);\n", tex_sampler_dim_name[dim]);
+				str.asprintf_append("#endif\n");
+				str.asprintf_append("}\n\n");
+			}
+		}
+	}
+}
+
 
 
 char*
 char*
 _mesa_print_ir_glsl(exec_list *instructions,
 _mesa_print_ir_glsl(exec_list *instructions,
@@ -154,6 +218,7 @@ _mesa_print_ir_glsl(exec_list *instructions,
 		char* buffer, PrintGlslMode mode)
 		char* buffer, PrintGlslMode mode)
 {
 {
 	string_buffer str(buffer);
 	string_buffer str(buffer);
+	string_buffer body(buffer);
 
 
 	// print version & extensions
 	// print version & extensions
 	if (state) {
 	if (state) {
@@ -181,12 +246,16 @@ _mesa_print_ir_glsl(exec_list *instructions,
 		}
 		}
 		if (state->EXT_shader_framebuffer_fetch_enable)
 		if (state->EXT_shader_framebuffer_fetch_enable)
 			str.asprintf_append ("#extension GL_EXT_shader_framebuffer_fetch : enable\n");
 			str.asprintf_append ("#extension GL_EXT_shader_framebuffer_fetch : enable\n");
+		if (state->ARB_shader_bit_encoding_enable)
+			str.asprintf_append("#extension GL_ARB_shader_bit_encoding : enable\n");
 	}
 	}
 	
 	
 	// remove unused struct declarations
 	// remove unused struct declarations
 	do_remove_unused_typedecls(instructions);
 	do_remove_unused_typedecls(instructions);
 	
 	
 	global_print_tracker gtracker;
 	global_print_tracker gtracker;
+	int uses_texlod_impl = 0;
+	int uses_texlodproj_impl = 0;
 	
 	
 	loop_state* ls = analyze_loop_variables(instructions);
 	loop_state* ls = analyze_loop_variables(instructions);
 	if (ls->loop_found)
 	if (ls->loop_found)
@@ -201,15 +270,23 @@ _mesa_print_ir_glsl(exec_list *instructions,
 				continue;
 				continue;
 		}
 		}
 
 
-		ir_print_glsl_visitor v (str, &gtracker, mode, state->es_shader, state);
+		ir_print_glsl_visitor v (body, &gtracker, mode, state->es_shader, state);
 		v.loopstate = ls;
 		v.loopstate = ls;
 
 
 		ir->accept(&v);
 		ir->accept(&v);
 		if (ir->ir_type != ir_type_function && !v.skipped_this_ir)
 		if (ir->ir_type != ir_type_function && !v.skipped_this_ir)
-			str.asprintf_append (";\n");
+			body.asprintf_append (";\n");
+
+		uses_texlod_impl |= v.uses_texlod_impl;
+		uses_texlodproj_impl |= v.uses_texlodproj_impl;
 	}
 	}
 	
 	
 	delete ls;
 	delete ls;
+	
+	print_texlod_workarounds(uses_texlod_impl, uses_texlodproj_impl, str);
+	
+	// Add the optimized glsl code
+	str.asprintf_append("%s", body.c_str());
 
 
 	return ralloc_strdup(buffer, str.c_str());
 	return ralloc_strdup(buffer, str.c_str());
 }
 }
@@ -280,7 +357,9 @@ void ir_print_glsl_visitor::print_precision (ir_instruction* ir, const glsl_type
 	if (type &&
 	if (type &&
 		!type->is_float() &&
 		!type->is_float() &&
 		!type->is_sampler() &&
 		!type->is_sampler() &&
-		(!type->is_array() || !type->element_type()->is_float())
+		!type->is_integer() &&
+		(!type->is_array() || !type->element_type()->is_float()) &&
+		(!type->is_array() || !type->element_type()->is_integer())
 	)
 	)
 	{
 	{
 		return;
 		return;
@@ -297,6 +376,14 @@ void ir_print_glsl_visitor::print_precision (ir_instruction* ir, const glsl_type
 	{
 	{
 		prec = glsl_precision_high;
 		prec = glsl_precision_high;
 	}
 	}
+	if (type && type->is_integer())
+	{
+		if (prec == glsl_precision_undefined && type && type->is_integer())
+		{
+			// Default to highp on integers
+			prec = glsl_precision_high;
+		}
+	}
 
 
 	// skip precision for samplers that end up being lowp (default anyway) or undefined;
 	// skip precision for samplers that end up being lowp (default anyway) or undefined;
 	// except always emit it for shadowmap samplers (some drivers don't implement
 	// except always emit it for shadowmap samplers (some drivers don't implement
@@ -529,10 +616,10 @@ static const char *const operator_glsl_strs[] = {
 	"float",	// u2f
 	"float",	// u2f
 	"int",		// i2u
 	"int",		// i2u
 	"int",		// u2i
 	"int",		// u2i
-	"float",	// bit i2f
-	"int",		// bit f2i
-	"float",	// bit u2f
-	"int",		// bit f2u
+	"intBitsToFloat",	// bit i2f
+	"floatBitsToInt",		// bit f2i
+	"uintBitsToFloat",	// bit u2f
+	"floatBitsToUint",		// bit f2u
 	"any",
 	"any",
 	"trunc",
 	"trunc",
 	"ceil",
 	"ceil",
@@ -644,7 +731,7 @@ void ir_print_glsl_visitor::visit(ir_expression *ir)
 	newline_indent();
 	newline_indent();
 	
 	
 	if (ir->get_num_operands() == 1) {
 	if (ir->get_num_operands() == 1) {
-		if (ir->operation >= ir_unop_f2i && ir->operation < ir_unop_any) {
+		if (ir->operation >= ir_unop_f2i && ir->operation <= ir_unop_u2i) {
 			print_type(buffer, ir->type, true);
 			print_type(buffer, ir->type, true);
 			buffer.asprintf_append ("(");
 			buffer.asprintf_append ("(");
 		} else if (ir->operation == ir_unop_rcp) {
 		} else if (ir->operation == ir_unop_rcp) {
@@ -723,14 +810,6 @@ void ir_print_glsl_visitor::visit(ir_expression *ir)
 	--this->expression_depth;
 	--this->expression_depth;
 }
 }
 
 
-// [glsl_sampler_dim]
-static const char* tex_sampler_dim_name[] = {
-	"1D", "2D", "3D", "Cube", "Rect", "Buf", "External",
-};
-static int tex_sampler_dim_size[] = {
-	1, 2, 3, 3, 2, 2, 2,
-};
-
 void ir_print_glsl_visitor::visit(ir_texture *ir)
 void ir_print_glsl_visitor::visit(ir_texture *ir)
 {
 {
 	glsl_sampler_dim sampler_dim = (glsl_sampler_dim)ir->sampler->type->sampler_dimensionality;
 	glsl_sampler_dim sampler_dim = (glsl_sampler_dim)ir->sampler->type->sampler_dimensionality;
@@ -741,6 +820,37 @@ void ir_print_glsl_visitor::visit(ir_texture *ir)
 	if (is_shadow)
 	if (is_shadow)
 		sampler_uv_dim += 1;
 		sampler_uv_dim += 1;
 	const bool is_proj = (uv_dim > sampler_uv_dim);
 	const bool is_proj = (uv_dim > sampler_uv_dim);
+	const bool is_lod = (ir->op == ir_txl);
+	
+	if (is_lod && state->es_shader && state->language_version < 300 && state->stage == MESA_SHADER_FRAGMENT)
+	{
+		// Special workaround for GLES 2.0 LOD samplers to prevent a lot of debug spew.
+		const glsl_precision prec = ir->sampler->get_precision();
+		const char *precString = "";
+		// Sampler bitfield is 7 bits, so use 0-7 for lowp, 8-15 for mediump and 16-23 for highp.
+		int position = (int)sampler_dim;
+		switch (prec)
+		{
+		case glsl_precision_high:
+			position += 16;
+			precString = "_high_";
+			break;
+		case glsl_precision_medium:
+			position += 8;
+			precString = "_medium_";
+			break;
+		case glsl_precision_low:
+		default:
+			precString = "_low_";
+			break;
+		}
+		buffer.asprintf_append("impl%s", precString);
+		if (is_proj)
+			uses_texlodproj_impl |= (1 << position);
+		else
+			uses_texlod_impl |= (1 << position);
+	}
+
 	
 	
     // texture function name
     // texture function name
     //ACS: shadow lookups and lookups with dimensionality included in the name were deprecated in 130
     //ACS: shadow lookups and lookups with dimensionality included in the name were deprecated in 130
@@ -792,13 +902,6 @@ void ir_print_glsl_visitor::visit(ir_texture *ir)
 	// texture coordinate
 	// texture coordinate
 	ir->coordinate->accept(this);
 	ir->coordinate->accept(this);
 	
 	
-	// lod bias
-	if (ir->op == ir_txb)
-	{
-		buffer.asprintf_append (", ");
-		ir->lod_info.bias->accept(this);
-	}
-	
 	// lod
 	// lod
 	if (ir->op == ir_txl || ir->op == ir_txf)
 	if (ir->op == ir_txl || ir->op == ir_txf)
 	{
 	{
@@ -814,11 +917,21 @@ void ir_print_glsl_visitor::visit(ir_texture *ir)
 		buffer.asprintf_append (", ");
 		buffer.asprintf_append (", ");
 		ir->lod_info.grad.dPdy->accept(this);
 		ir->lod_info.grad.dPdy->accept(this);
 	}
 	}
+
+	// texel offset
+	if (ir->offset != NULL)
+	{
+		buffer.asprintf_append (", ");
+		ir->offset->accept(this);
+	}
+	
+	// lod bias
+	if (ir->op == ir_txb)
+	{
+		buffer.asprintf_append (", ");
+		ir->lod_info.bias->accept(this);
+	}
 	
 	
-   if (ir->offset != NULL) {
-      buffer.asprintf_append (", ");
-      ir->offset->accept(this);
-   }
     /*
     /*
 	
 	
 	
 	
@@ -889,6 +1002,10 @@ void ir_print_glsl_visitor::visit(ir_swizzle *ir)
 		}
 		}
 		return;
 		return;
 	}
 	}
+	
+	// Swizzling scalar types is not allowed so just return now.
+	if (ir->val->type->vector_elements == 1)
+		return;
 
 
    buffer.asprintf_append (".");
    buffer.asprintf_append (".");
    for (unsigned i = 0; i < ir->mask.num_components; i++) {
    for (unsigned i = 0; i < ir->mask.num_components; i++) {
@@ -1140,7 +1257,15 @@ void ir_print_glsl_visitor::visit(ir_assignment *ir)
 	emit_assignment_part (ir->lhs, ir->rhs, ir->write_mask, NULL);
 	emit_assignment_part (ir->lhs, ir->rhs, ir->write_mask, NULL);
 }
 }
 
 
-static void print_float (string_buffer& buffer, float f)
+
+#ifdef _MSC_VER
+#define isnan(x) _isnan(x)
+#define isinf(x) (!_finite(x))
+#endif
+
+#define fpcheck(x) (isnan(x) || isinf(x))
+
+void print_float (string_buffer& buffer, float f)
 {
 {
 	// Kind of roundabout way, but this is to satisfy two things:
 	// Kind of roundabout way, but this is to satisfy two things:
 	// * MSVC and gcc-based compilers differ a bit in how they treat float
 	// * MSVC and gcc-based compilers differ a bit in how they treat float
@@ -1148,7 +1273,7 @@ static void print_float (string_buffer& buffer, float f)
 	// * GLSL (early version at least) require floats to have ".0" or
 	// * GLSL (early version at least) require floats to have ".0" or
 	//   exponential notation.
 	//   exponential notation.
 	char tmp[64];
 	char tmp[64];
-	snprintf(tmp, 64, "%.6g", f);
+	snprintf(tmp, 64, "%.7g", f);
 
 
 	char* posE = NULL;
 	char* posE = NULL;
 	posE = strchr(tmp, 'e');
 	posE = strchr(tmp, 'e');
@@ -1198,12 +1323,28 @@ void ir_print_glsl_visitor::visit(ir_constant *ir)
 
 
 	if (type == glsl_type::float_type)
 	if (type == glsl_type::float_type)
 	{
 	{
+		if (fpcheck(ir->value.f[0]))
+		{
+			// Non-printable float. If we have bit conversions, we're fine. otherwise do hand-wavey things in print_float().
+			if ((state->es_shader && (state->language_version >= 300))
+				|| (state->language_version >= 330)
+				|| (state->ARB_shader_bit_encoding_enable))
+			{
+				buffer.asprintf_append("uintBitsToFloat(%uu)", ir->value.u[0]);
+				return;
+			}
+		}
+		
 		print_float (buffer, ir->value.f[0]);
 		print_float (buffer, ir->value.f[0]);
 		return;
 		return;
 	}
 	}
 	else if (type == glsl_type::int_type)
 	else if (type == glsl_type::int_type)
 	{
 	{
-		buffer.asprintf_append ("%d", ir->value.i[0]);
+		// Need special handling for INT_MIN
+		if (ir->value.u[0] == 0x80000000)
+			buffer.asprintf_append("int(0x%X)", ir->value.i[0]);
+		else
+			buffer.asprintf_append ("%d", ir->value.i[0]);
 		return;
 		return;
 	}
 	}
 	else if (type == glsl_type::uint_type)
 	else if (type == glsl_type::uint_type)
@@ -1213,7 +1354,13 @@ void ir_print_glsl_visitor::visit(ir_constant *ir)
 			|| (state->language_version < 130))
 			|| (state->language_version < 130))
 			buffer.asprintf_append("%u", ir->value.u[0]);
 			buffer.asprintf_append("%u", ir->value.u[0]);
 		else
 		else
-			buffer.asprintf_append("%uu", ir->value.u[0]);
+		{
+			// Old Adreno drivers try to be smart with '0u' and treat that as 'const int'. Sigh.
+			if (ir->value.u[0] == 0)
+				buffer.asprintf_append("uint(0)");
+			else
+				buffer.asprintf_append("%uu", ir->value.u[0]);
+		}
 		return;
 		return;
 	}
 	}
 
 
@@ -1254,7 +1401,15 @@ void ir_print_glsl_visitor::visit(ir_constant *ir)
 			 buffer.asprintf_append("%uu", ir->value.u[i]);
 			 buffer.asprintf_append("%uu", ir->value.u[i]);
 		 break;
 		 break;
 	 }
 	 }
-	 case GLSL_TYPE_INT:   buffer.asprintf_append ("%d", ir->value.i[i]); break;
+	 case GLSL_TYPE_INT:
+	 {
+		 // Need special handling for INT_MIN
+		 if (ir->value.u[i] == 0x80000000)
+			 buffer.asprintf_append("int(0x%X)", ir->value.i[i]);
+		 else
+			 buffer.asprintf_append("%d", ir->value.i[i]);
+		 break;
+	 }
 	 case GLSL_TYPE_FLOAT: print_float(buffer, ir->value.f[i]); break;
 	 case GLSL_TYPE_FLOAT: print_float(buffer, ir->value.f[i]); break;
 	 case GLSL_TYPE_BOOL:  buffer.asprintf_append ("%d", ir->value.b[i]); break;
 	 case GLSL_TYPE_BOOL:  buffer.asprintf_append ("%d", ir->value.b[i]); break;
 	 default: assert(0);
 	 default: assert(0);
@@ -1406,7 +1561,17 @@ bool ir_print_glsl_visitor::emit_canonical_for (ir_loop* ir)
 			if (indvar->initial_value)
 			if (indvar->initial_value)
 			{
 			{
 				buffer.asprintf_append (" = ");
 				buffer.asprintf_append (" = ");
+				// if the var is an array add the proper initializer
+				if(var->type->is_vector())
+				{
+					print_type(buffer, var->type, false);
+					buffer.asprintf_append ("(");
+				}
 				indvar->initial_value->accept(this);
 				indvar->initial_value->accept(this);
+				if(var->type->is_vector())
+				{
+					buffer.asprintf_append (")");
+				}
 			}
 			}
 		}
 		}
 	}
 	}

+ 3 - 0
3rdparty/glsl-optimizer/src/glsl/ir_print_glsl_visitor.h

@@ -99,4 +99,7 @@ private:
 };
 };
 
 
 
 
+extern void print_float (string_buffer& buffer, float f);
+
+
 #endif /* IR_PRINT_GLSL_VISITOR_H */
 #endif /* IR_PRINT_GLSL_VISITOR_H */

+ 30 - 53
3rdparty/glsl-optimizer/src/glsl/ir_print_metal_visitor.cpp

@@ -179,6 +179,7 @@ public:
 	virtual void visit(ir_end_primitive *);
 	virtual void visit(ir_end_primitive *);
 
 
 	void emit_assignment_part (ir_dereference* lhs, ir_rvalue* rhs, unsigned write_mask, ir_rvalue* dstIndex);
 	void emit_assignment_part (ir_dereference* lhs, ir_rvalue* rhs, unsigned write_mask, ir_rvalue* dstIndex);
+	bool can_emit_canonical_for (loop_variable_state *ls);
 	bool emit_canonical_for (ir_loop* ir);
 	bool emit_canonical_for (ir_loop* ir);
 
 
 	metal_print_context& ctx;
 	metal_print_context& ctx;
@@ -374,7 +375,7 @@ void ir_print_metal_visitor::newline_deindent()
 
 
 void ir_print_metal_visitor::print_var_name (ir_variable* v)
 void ir_print_metal_visitor::print_var_name (ir_variable* v)
 {
 {
-    uintptr_t id = (uintptr_t)hash_table_find (globals->var_hash, v);
+    long id = (long)hash_table_find (globals->var_hash, v);
 	if (!id && v->data.mode == ir_var_temporary)
 	if (!id && v->data.mode == ir_var_temporary)
 	{
 	{
         id = ++globals->var_counter;
         id = ++globals->var_counter;
@@ -543,7 +544,7 @@ void ir_print_metal_visitor::visit(ir_variable *ir)
 	// give an id to any variable defined in a function that is not an uniform
 	// give an id to any variable defined in a function that is not an uniform
 	if ((this->mode == kPrintGlslNone && ir->data.mode != ir_var_uniform))
 	if ((this->mode == kPrintGlslNone && ir->data.mode != ir_var_uniform))
 	{
 	{
-		uintptr_t id = (uintptr_t)hash_table_find (globals->var_hash, ir);
+		long id = (long)hash_table_find (globals->var_hash, ir);
 		if (id == 0)
 		if (id == 0)
 		{
 		{
 			id = ++globals->var_counter;
 			id = ++globals->var_counter;
@@ -565,7 +566,8 @@ void ir_print_metal_visitor::visit(ir_variable *ir)
 	if (!inside_loop_body)
 	if (!inside_loop_body)
 	{
 	{
 		loop_variable_state* inductor_state = loopstate->get_for_inductor(ir);
 		loop_variable_state* inductor_state = loopstate->get_for_inductor(ir);
-		if (inductor_state && inductor_state->private_induction_variable_count == 1)
+		if (inductor_state && inductor_state->private_induction_variable_count == 1 &&
+			can_emit_canonical_for(inductor_state))
 		{
 		{
 			skipped_this_ir = true;
 			skipped_this_ir = true;
 			return;
 			return;
@@ -801,10 +803,10 @@ static const char *const operator_glsl_strs[] = {
 	"float",	// u2f
 	"float",	// u2f
 	"int",		// i2u
 	"int",		// i2u
 	"int",		// u2i
 	"int",		// u2i
-	"float",	// bit i2f
-	"int",		// bit f2i
-	"float",	// bit u2f
-	"int",		// bit f2u
+	"as_type_",	// bit i2f
+	"as_type_",	// bit f2i
+	"as_type_",	// bit u2f
+	"as_type_",	// bit f2u
 	"any",
 	"any",
 	"trunc",
 	"trunc",
 	"ceil",
 	"ceil",
@@ -847,7 +849,7 @@ static const char *const operator_glsl_strs[] = {
 	"/",
 	"/",
 	"carry_TODO",
 	"carry_TODO",
 	"borrow_TODO",
 	"borrow_TODO",
-	"mod",
+	"fmod",
 	"<",
 	"<",
 	">",
 	">",
 	"<=",
 	"<=",
@@ -965,11 +967,16 @@ void ir_print_metal_visitor::visit(ir_expression *ir)
 	{
 	{
 		if (op0cast)
 		if (op0cast)
 			print_cast (buffer, arg_prec, ir->operands[0]);
 			print_cast (buffer, arg_prec, ir->operands[0]);
-		if (ir->operation >= ir_unop_f2i && ir->operation < ir_unop_any) {
+		if (ir->operation >= ir_unop_f2i && ir->operation <= ir_unop_u2i) {
 			print_type(buffer, ir, ir->type, true);
 			print_type(buffer, ir, ir->type, true);
 			buffer.asprintf_append ("(");
 			buffer.asprintf_append ("(");
+		} else if (ir->operation >= ir_unop_bitcast_i2f && ir->operation <= ir_unop_bitcast_f2u) {
+			buffer.asprintf_append("as_type<");
+			print_type(buffer, ir, ir->type, true);
+			buffer.asprintf_append(">(");
 		} else if (ir->operation == ir_unop_rcp) {
 		} else if (ir->operation == ir_unop_rcp) {
-			buffer.asprintf_append ("(1.0/(");
+			const bool halfCast = (arg_prec == glsl_precision_medium || arg_prec == glsl_precision_low);
+			buffer.asprintf_append (halfCast ? "((half)1.0/(" : "(1.0/(");
 		} else {
 		} else {
 			buffer.asprintf_append ("%s(", operator_glsl_strs[ir->operation]);
 			buffer.asprintf_append ("%s(", operator_glsl_strs[ir->operation]);
 		}
 		}
@@ -1445,7 +1452,8 @@ void ir_print_metal_visitor::visit(ir_assignment *ir)
 		if (!ir->condition && whole_var)
 		if (!ir->condition && whole_var)
 		{
 		{
 			loop_variable_state* inductor_state = loopstate->get_for_inductor(whole_var);
 			loop_variable_state* inductor_state = loopstate->get_for_inductor(whole_var);
-			if (inductor_state && inductor_state->private_induction_variable_count == 1)
+			if (inductor_state && inductor_state->private_induction_variable_count == 1 &&
+				can_emit_canonical_for(inductor_state))
 			{
 			{
 				skipped_this_ir = true;
 				skipped_this_ir = true;
 				return;
 				return;
@@ -1501,46 +1509,6 @@ void ir_print_metal_visitor::visit(ir_assignment *ir)
 	emit_assignment_part (ir->lhs, ir->rhs, ir->write_mask, NULL);
 	emit_assignment_part (ir->lhs, ir->rhs, ir->write_mask, NULL);
 }
 }
 
 
-static void print_float (string_buffer& buffer, float f)
-{
-	// Kind of roundabout way, but this is to satisfy two things:
-	// * MSVC and gcc-based compilers differ a bit in how they treat float
-	//   widht/precision specifiers. Want to match for tests.
-	// * GLSL (early version at least) require floats to have ".0" or
-	//   exponential notation.
-	char tmp[64];
-	snprintf(tmp, 64, "%.6g", f);
-
-	char* posE = NULL;
-	posE = strchr(tmp, 'e');
-	if (!posE)
-		posE = strchr(tmp, 'E');
-
-	#if defined(_MSC_VER)
-	// While gcc would print something like 1.0e+07, MSVC will print 1.0e+007 -
-	// only for exponential notation, it seems, will add one extra useless zero. Let's try to remove
-	// that so compiler output matches.
-	if (posE != NULL)
-	{
-		if((posE[1] == '+' || posE[1] == '-') && posE[2] == '0')
-		{
-			char* p = posE+2;
-			while (p[0])
-			{
-				p[0] = p[1];
-				++p;
-			}
-		}
-	}
-	#endif
-
-	buffer.asprintf_append ("%s", tmp);
-
-	// need to append ".0"?
-	if (!strchr(tmp,'.') && (posE == NULL))
-		buffer.asprintf_append(".0");
-}
-
 void ir_print_metal_visitor::visit(ir_constant *ir)
 void ir_print_metal_visitor::visit(ir_constant *ir)
 {
 {
 	const glsl_type* type = ir->type;
 	const glsl_type* type = ir->type;
@@ -1715,9 +1683,8 @@ ir_print_metal_visitor::visit(ir_if *ir)
 }
 }
 
 
 
 
-bool ir_print_metal_visitor::emit_canonical_for (ir_loop* ir)
+bool ir_print_metal_visitor::can_emit_canonical_for (loop_variable_state *ls)
 {
 {
-	loop_variable_state* const ls = this->loopstate->get(ir);
 	if (ls == NULL)
 	if (ls == NULL)
 		return false;
 		return false;
 
 
@@ -1732,6 +1699,16 @@ bool ir_print_metal_visitor::emit_canonical_for (ir_loop* ir)
 	if (terminatorCount != 1)
 	if (terminatorCount != 1)
 		return false;
 		return false;
 
 
+	return true;
+}
+
+bool ir_print_metal_visitor::emit_canonical_for (ir_loop* ir)
+{
+	loop_variable_state* const ls = this->loopstate->get(ir);
+
+	if (!can_emit_canonical_for(ls))
+		return false;
+	
 	hash_table* terminator_hash = hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare);
 	hash_table* terminator_hash = hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare);
 	hash_table* induction_hash = hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare);
 	hash_table* induction_hash = hash_table_ctor(0, hash_table_pointer_hash, hash_table_pointer_compare);
 
 

+ 1 - 1
3rdparty/glsl-optimizer/src/glsl/linker.cpp

@@ -2531,7 +2531,7 @@ link_shaders(struct gl_context *ctx, struct gl_shader_program *prog)
       }
       }
 
 
       prog->ARB_fragment_coord_conventions_enable |=
       prog->ARB_fragment_coord_conventions_enable |=
-         GLboolean(prog->Shaders[i]->ARB_fragment_coord_conventions_enable);
+         prog->Shaders[i]->ARB_fragment_coord_conventions_enable;
 
 
       gl_shader_stage shader_type = prog->Shaders[i]->Stage;
       gl_shader_stage shader_type = prog->Shaders[i]->Stage;
       shader_list[shader_type][num_shaders[shader_type]] = prog->Shaders[i];
       shader_list[shader_type][num_shaders[shader_type]] = prog->Shaders[i];

+ 28 - 3
3rdparty/glsl-optimizer/src/glsl/loop_analysis.cpp

@@ -121,8 +121,10 @@ loop_state::get_for_inductor(const ir_variable *ir)
 }
 }
 
 
 void
 void
-loop_state::insert_inductor(ir_variable* var, loop_variable_state* state, ir_loop* loop)
+loop_state::insert_inductor(loop_variable* loopvar, loop_variable_state* state, ir_loop* loop)
 {
 {
+	ir_variable* var = loopvar->var;
+
 	// Check if this variable is already marked as "sure can't be a private inductor variable"
 	// Check if this variable is already marked as "sure can't be a private inductor variable"
 	if (hash_table_find(this->ht_non_inductors, var))
 	if (hash_table_find(this->ht_non_inductors, var))
 		return;
 		return;
@@ -144,6 +146,29 @@ loop_state::insert_inductor(ir_variable* var, loop_variable_state* state, ir_loo
 			return;
 			return;
 		}
 		}
 	}
 	}
+
+	// Check if this variable is used before the loop anywhere. If it is, it can't be a
+	// variable that's private to the loop.
+	// Skip over the IR that declared the variable or assigned the initial value though.
+	for (exec_node* node = loop->prev;
+		 !node->is_head_sentinel();
+		 node = node->prev)
+	{
+		ir_instruction *ir = (ir_instruction *) node;
+		if (ir == loopvar->initial_value_ir)
+			continue;
+		if (ir->ir_type == ir_type_variable)
+			continue;
+
+		ir->accept (&refs);
+		if (refs.find_variable_entry(var))
+		{
+			// add to list of "non inductors", so that next loop does not try
+			// to add it as inductor again
+			hash_table_insert(this->ht_non_inductors, state, var);
+			return;
+		}
+	}
 	
 	
 	state->private_induction_variable_count++;
 	state->private_induction_variable_count++;
 	hash_table_insert(this->ht_inductors, state, var);
 	hash_table_insert(this->ht_inductors, state, var);
@@ -345,7 +370,7 @@ loop_analysis::visit_leave(ir_loop *ir)
    foreach_in_list_safe(loop_variable, lv, &ls->variables) {
    foreach_in_list_safe(loop_variable, lv, &ls->variables) {
        ir_variable *var = lv->var;
        ir_variable *var = lv->var;
        if (var != NULL) {
        if (var != NULL) {
-           lv->initial_value = find_initial_value(ir, var);
+           lv->initial_value = find_initial_value(ir, var, &lv->initial_value_ir);
        }
        }
       /* Move variables that are already marked as being loop constant to
       /* Move variables that are already marked as being loop constant to
        * a separate list.  These trivially don't need to be tested.
        * a separate list.  These trivially don't need to be tested.
@@ -430,7 +455,7 @@ loop_analysis::visit_leave(ir_loop *ir)
 
 
 	 lv->remove();
 	 lv->remove();
 	 ls->induction_variables.push_tail(lv);
 	 ls->induction_variables.push_tail(lv);
-	 loops->insert_inductor(lv->var, ls, ir);
+	 loops->insert_inductor(lv, ls, ir);
       }
       }
    }
    }
 
 

+ 4 - 2
3rdparty/glsl-optimizer/src/glsl/loop_analysis.h

@@ -58,7 +58,7 @@ unroll_loops(exec_list *instructions, loop_state *ls,
              const struct gl_shader_compiler_options *options);
              const struct gl_shader_compiler_options *options);
 
 
 ir_rvalue *
 ir_rvalue *
-find_initial_value(ir_loop *loop, ir_variable *var);
+find_initial_value(ir_loop *loop, ir_variable *var, ir_instruction **out_containing_ir);
 
 
 int
 int
 calculate_iterations(ir_rvalue *from, ir_rvalue *to, ir_rvalue *increment,
 calculate_iterations(ir_rvalue *from, ir_rvalue *to, ir_rvalue *increment,
@@ -168,6 +168,8 @@ public:
 
 
    /** Reference to initial value outside of the loop. */
    /** Reference to initial value outside of the loop. */
    ir_rvalue *initial_value;
    ir_rvalue *initial_value;
+   /** IR that assigned the initial value. */
+   ir_instruction *initial_value_ir;
 
 
    /** Number of assignments to the variable in the loop body. */
    /** Number of assignments to the variable in the loop body. */
    unsigned num_assignments;
    unsigned num_assignments;
@@ -247,7 +249,7 @@ public:
    loop_variable_state *insert(ir_loop *ir);
    loop_variable_state *insert(ir_loop *ir);
 	
 	
    loop_variable_state* get_for_inductor (const ir_variable*);
    loop_variable_state* get_for_inductor (const ir_variable*);
-   void insert_inductor(ir_variable* var, loop_variable_state* state, ir_loop* loop);
+   void insert_inductor(loop_variable* loopvar, loop_variable_state* state, ir_loop* loop);
 
 
    bool loop_found;
    bool loop_found;
 
 

+ 5 - 1
3rdparty/glsl-optimizer/src/glsl/loop_controls.cpp

@@ -44,8 +44,9 @@
  * \c NULL if no initializer can be found.
  * \c NULL if no initializer can be found.
  */
  */
 ir_rvalue *
 ir_rvalue *
-find_initial_value(ir_loop *loop, ir_variable *var)
+find_initial_value(ir_loop *loop, ir_variable *var, ir_instruction **out_containing_ir)
 {
 {
+   *out_containing_ir = NULL;
    ir_variable_refcount_visitor refs;
    ir_variable_refcount_visitor refs;
    
    
    for (exec_node *node = loop->prev;
    for (exec_node *node = loop->prev;
@@ -74,7 +75,10 @@ find_initial_value(ir_loop *loop, ir_variable *var)
 	 ir_variable *assignee = assign->lhs->whole_variable_referenced();
 	 ir_variable *assignee = assign->lhs->whole_variable_referenced();
 
 
 	 if (assignee == var)
 	 if (assignee == var)
+	 {
+	    *out_containing_ir = assign;
 	    return (assign->condition != NULL) ? NULL : assign->rhs;
 	    return (assign->condition != NULL) ? NULL : assign->rhs;
+	 }
 
 
 	 break;
 	 break;
       }
       }

+ 5 - 5
3rdparty/glsl-optimizer/src/glsl/main.cpp

@@ -40,11 +40,11 @@
 
 
 static int glsl_version = 330;
 static int glsl_version = 330;
 
 
-extern "C" void
-_mesa_error_no_memory(const char *caller)
-{
-   fprintf(stderr, "Mesa error: out of memory in %s", caller);
-}
+//extern "C" void
+//_mesa_error_no_memory(const char *caller)
+//{
+//   fprintf(stderr, "Mesa error: out of memory in %s", caller);
+//}
 
 
 static void
 static void
 initialize_context(struct gl_context *ctx, gl_api api)
 initialize_context(struct gl_context *ctx, gl_api api)

+ 2 - 2
3rdparty/glsl-optimizer/src/glsl/opt_algebraic.cpp

@@ -129,7 +129,7 @@ is_less_than_one(ir_constant *ir)
       return false;
       return false;
 
 
    unsigned component = 0;
    unsigned component = 0;
-   for (unsigned c = 0; c < ir->type->vector_elements; c++) {
+   for (int c = 0; c < ir->type->vector_elements; c++) {
       if (ir->get_float_component(c) < 1.0f)
       if (ir->get_float_component(c) < 1.0f)
          component++;
          component++;
    }
    }
@@ -144,7 +144,7 @@ is_greater_than_zero(ir_constant *ir)
       return false;
       return false;
 
 
    unsigned component = 0;
    unsigned component = 0;
-   for (unsigned c = 0; c < ir->type->vector_elements; c++) {
+   for (int c = 0; c < ir->type->vector_elements; c++) {
       if (ir->get_float_component(c) > 0.0f)
       if (ir->get_float_component(c) > 0.0f)
          component++;
          component++;
    }
    }

+ 2 - 2
3rdparty/glsl-optimizer/src/glsl/standalone_scaffolding.cpp

@@ -44,13 +44,13 @@ _mesa_reference_shader(struct gl_context *ctx, struct gl_shader **ptr,
 }
 }
 
 
 void
 void
-_mesa_shader_debug(struct gl_context *, GLenum, GLuint *,
+_mesa_shader_debug(struct gl_context *, GLenum, GLuint *id,
                    const char *, int)
                    const char *, int)
 {
 {
 }
 }
 
 
 extern "C" void
 extern "C" void
-_mesa_error_no_memory(const char *)
+_mesa_error_no_memory(const char *caller)
 {
 {
 }
 }
 
 

+ 8 - 7
3rdparty/glsl-optimizer/src/glsl_optimizer_lib.gyp

@@ -7,6 +7,7 @@
       'target_name': 'glsl_optimizer_lib',
       'target_name': 'glsl_optimizer_lib',
       'type': 'static_library',
       'type': 'static_library',
       'include_dirs': [
       'include_dirs': [
+        '.',
         'glsl',
         'glsl',
         'mesa',
         'mesa',
         '../include',
         '../include',
@@ -138,8 +139,6 @@
         'glsl/opt_flip_matrices.cpp',
         'glsl/opt_flip_matrices.cpp',
         'glsl/opt_dead_builtin_varyings.cpp',
         'glsl/opt_dead_builtin_varyings.cpp',
         'glsl/program.h',
         'glsl/program.h',
-        'glsl/ralloc.c',
-        'glsl/ralloc.h',
         'glsl/s_expression.cpp',
         'glsl/s_expression.cpp',
         'glsl/s_expression.h',
         'glsl/s_expression.h',
         'glsl/standalone_scaffolding.cpp',
         'glsl/standalone_scaffolding.cpp',
@@ -153,8 +152,6 @@
         'mesa/main/dd.h',
         'mesa/main/dd.h',
         'mesa/main/glheader.h',
         'mesa/main/glheader.h',
         'mesa/main/glminimal.h',
         'mesa/main/glminimal.h',
-        'mesa/main/hash_table.c',
-        'mesa/main/hash_table.h',
         'mesa/main/imports.c',
         'mesa/main/imports.c',
         'mesa/main/imports.h',
         'mesa/main/imports.h',
         'mesa/main/macros.h',
         'mesa/main/macros.h',
@@ -167,11 +164,15 @@
         'mesa/program/prog_statevars.h',
         'mesa/program/prog_statevars.h',
         'mesa/program/symbol_table.c',
         'mesa/program/symbol_table.c',
         'mesa/program/symbol_table.h',
         'mesa/program/symbol_table.h',
+        'util/hash_table.c',
+        'util/hash_table.h',
+        'util/ralloc.c',
+        'util/ralloc.h',
       ],
       ],
       'conditions': [
       'conditions': [
         ['OS=="win"', {
         ['OS=="win"', {
           'include_dirs': [
           'include_dirs': [
-            '../include/c99',          
+            '../include/c99',
           ],
           ],
           'defines': [
           'defines': [
             '_LIB',
             '_LIB',
@@ -184,7 +185,7 @@
           ],
           ],
           'msvs_disabled_warnings': [4028, 4244, 4267, 4996],
           'msvs_disabled_warnings': [4028, 4244, 4267, 4996],
         }],
         }],
-      ],        
+      ],
     }
     }
   ]
   ]
-}
+}

+ 2 - 2
3rdparty/glsl-optimizer/src/mesa/main/compiler.h

@@ -248,11 +248,11 @@ static inline GLuint CPU_TO_LE32(GLuint x)
 #endif
 #endif
 
 
 #ifndef M_PI_2
 #ifndef M_PI_2
-#define M_PI_2 1.57079632679489661923
+#define M_PI_2 (1.57079632679489661923)
 #endif
 #endif
 
 
 #ifndef M_PI_4
 #ifndef M_PI_4
-#define M_PI_4 0.78539816339744830962
+#define M_PI_4 (0.785398163397448309616)
 #endif
 #endif
 
 
 #ifndef M_E
 #ifndef M_E

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/array-const-out.txt

@@ -2,7 +2,7 @@ void main ()
 {
 {
   vec4 c_1;
   vec4 c_1;
   c_1.zw = vec2(0.0, 0.0);
   c_1.zw = vec2(0.0, 0.0);
-  c_1.xy = vec2(-0.34413, 0.050045);
+  c_1.xy = vec2(-0.3441301, 0.05004501);
   gl_FragData[0] = c_1;
   gl_FragData[0] = c_1;
 }
 }
 
 

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/array-const-outES.txt

@@ -2,7 +2,7 @@ void main ()
 {
 {
   mediump vec4 c_1;
   mediump vec4 c_1;
   c_1.zw = vec2(0.0, 0.0);
   c_1.zw = vec2(0.0, 0.0);
-  c_1.xy = vec2(-0.34413, 0.050045);
+  c_1.xy = vec2(-0.3441301, 0.05004501);
   gl_FragData[0] = c_1;
   gl_FragData[0] = c_1;
 }
 }
 
 

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/array-const-outES3.txt

@@ -4,7 +4,7 @@ void main ()
 {
 {
   mediump vec4 c_1;
   mediump vec4 c_1;
   c_1.zw = vec2(0.0, 0.0);
   c_1.zw = vec2(0.0, 0.0);
-  c_1.xy = vec2(-0.34413, 0.050045);
+  c_1.xy = vec2(-0.3441301, 0.05004501);
   _fragData = c_1;
   _fragData = c_1;
 }
 }
 
 

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/array-const-outES3Metal.txt

@@ -12,7 +12,7 @@ fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]]
   xlatMtlShaderOutput _mtl_o;
   xlatMtlShaderOutput _mtl_o;
   half4 c_1;
   half4 c_1;
   c_1.zw = half2(float2(0.0, 0.0));
   c_1.zw = half2(float2(0.0, 0.0));
-  c_1.xy = half2(float2(-0.34413, 0.050045));
+  c_1.xy = half2(float2(-0.3441301, 0.05004501));
   _mtl_o._fragData = c_1;
   _mtl_o._fragData = c_1;
   return _mtl_o;
   return _mtl_o;
 }
 }

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/array-constconst-out.txt

@@ -2,7 +2,7 @@ void main ()
 {
 {
   vec4 c_1;
   vec4 c_1;
   c_1.zw = vec2(0.0, 0.0);
   c_1.zw = vec2(0.0, 0.0);
-  c_1.xy = vec2(-0.34413, 0.050045);
+  c_1.xy = vec2(-0.3441301, 0.05004501);
   gl_FragData[0] = c_1;
   gl_FragData[0] = c_1;
 }
 }
 
 

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/array-constconst-outES.txt

@@ -2,7 +2,7 @@ void main ()
 {
 {
   mediump vec4 c_1;
   mediump vec4 c_1;
   c_1.zw = vec2(0.0, 0.0);
   c_1.zw = vec2(0.0, 0.0);
-  c_1.xy = vec2(-0.34413, 0.050045);
+  c_1.xy = vec2(-0.3441301, 0.05004501);
   gl_FragData[0] = c_1;
   gl_FragData[0] = c_1;
 }
 }
 
 

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/array-constconst-outES3.txt

@@ -4,7 +4,7 @@ void main ()
 {
 {
   mediump vec4 c_1;
   mediump vec4 c_1;
   c_1.zw = vec2(0.0, 0.0);
   c_1.zw = vec2(0.0, 0.0);
-  c_1.xy = vec2(-0.34413, 0.050045);
+  c_1.xy = vec2(-0.3441301, 0.05004501);
   _fragData = c_1;
   _fragData = c_1;
 }
 }
 
 

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/array-constconst-outES3Metal.txt

@@ -12,7 +12,7 @@ fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]]
   xlatMtlShaderOutput _mtl_o;
   xlatMtlShaderOutput _mtl_o;
   half4 c_1;
   half4 c_1;
   c_1.zw = half2(float2(0.0, 0.0));
   c_1.zw = half2(float2(0.0, 0.0));
-  c_1.xy = half2(float2(-0.34413, 0.050045));
+  c_1.xy = half2(float2(-0.3441301, 0.05004501));
   _mtl_o._fragData = c_1;
   _mtl_o._fragData = c_1;
   return _mtl_o;
   return _mtl_o;
 }
 }

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/ast-outES3.txt

@@ -7,7 +7,7 @@ void main ()
     discard;
     discard;
   };
   };
   a_2 = 4.0;
   a_2 = 4.0;
-  for (int i_1 = 0; i_1 < 10; i_1++, a_2 += 1.0) {
+  for (highp int i_1 = 0; i_1 < 10; i_1++, a_2 += 1.0) {
   };
   };
   while (true) {
   while (true) {
     a_2 += 2.0;
     a_2 += 2.0;

+ 78 - 0
3rdparty/glsl-optimizer/tests/fragment/bug-loop-undeclaredinductor-inES3.txt

@@ -0,0 +1,78 @@
+#version 300 es
+
+// from case 685794 at Unity; a particular form of a loop
+// started to generate invalid shaders around Unity 4.6.3.
+
+out mediump vec4 _fragData;
+
+
+struct v2f_surf {
+    mediump vec2 uv;
+    highp vec4 pos;
+};
+uniform sampler2D _MainTex;
+uniform mediump float _NumPasses;
+uniform mediump vec4 _ContrastShift;
+uniform mediump vec4 _SaturationShift;
+uniform lowp vec4 _HueShift;
+uniform lowp vec4 _LuminosityShift;
+
+lowp vec3 TestCycle2( in lowp vec3 res, in mediump float val )
+{
+    return ((res - 0.5) * pow( (cos(val) + 1.0), val));
+}
+
+lowp vec3 TestCycle( in lowp vec3 rgb, in mediump float passes )
+{
+    lowp vec3 res = rgb;
+    // a weird form of loop that was causing a bug
+    highp float i = 0.0;
+    for ( ; (i < 4.0); i += 1.0) {
+       
+        if ((i == passes)){
+            break;
+        }
+        if ((i == 0.0)){
+            res = TestCycle2( res, ((_ContrastShift.x * 3.0) + 12.0));
+        }
+        else{
+            if ((i == 1.0)){
+                res = TestCycle2( res, ((_SaturationShift.y * 3.0) + 12.0));
+            }
+            else{
+                if ((i == 2.0)){
+                    res = TestCycle2( res, ((_HueShift.z * 3.0) + 12.0));
+                }
+                else{
+                    res = TestCycle2( res, ((_LuminosityShift.x * 3.0) + 12.0));
+                }
+            }
+        }
+    }
+   
+    return res;
+}
+
+lowp vec3 surf( in mediump vec2 uv )
+{   
+    lowp vec4 t = texture(_MainTex, uv);
+    if (_NumPasses > 0.0)
+        t.xyz = TestCycle(t.xyz, _NumPasses);
+    return t.xyz;
+}
+
+lowp vec4 frag_surf( in v2f_surf IN )
+{   
+    lowp vec3 col = surf( IN.uv);
+    return vec4( col, 1.0);
+}
+in mediump vec2 xlv_TEXCOORD0;
+void main() {
+    lowp vec4 xl_retval;
+    v2f_surf xlt_IN;
+    xlt_IN.uv = vec2(xlv_TEXCOORD0);
+    xlt_IN.pos = vec4(0.0);
+    xl_retval = frag_surf(xlt_IN);
+    _fragData = vec4(xl_retval);
+}
+

+ 88 - 0
3rdparty/glsl-optimizer/tests/fragment/bug-loop-undeclaredinductor-outES3.txt

@@ -0,0 +1,88 @@
+#version 300 es
+out mediump vec4 _fragData;
+uniform sampler2D _MainTex;
+uniform mediump float _NumPasses;
+uniform mediump vec4 _ContrastShift;
+uniform mediump vec4 _SaturationShift;
+uniform lowp vec4 _HueShift;
+uniform lowp vec4 _LuminosityShift;
+in mediump vec2 xlv_TEXCOORD0;
+void main ()
+{
+  lowp vec4 t_1;
+  lowp vec4 tmpvar_2;
+  tmpvar_2 = texture (_MainTex, xlv_TEXCOORD0);
+  t_1 = tmpvar_2;
+  if ((_NumPasses > 0.0)) {
+    mediump float passes_3;
+    passes_3 = _NumPasses;
+    highp float i_4;
+    lowp vec3 res_5;
+    res_5 = tmpvar_2.xyz;
+    i_4 = 0.0;
+    while (true) {
+      if ((i_4 >= 4.0)) {
+        break;
+      };
+      if ((i_4 == passes_3)) {
+        break;
+      };
+      if ((i_4 == 0.0)) {
+        lowp vec3 tmpvar_6;
+        mediump float val_7;
+        val_7 = ((_ContrastShift.x * 3.0) + 12.0);
+        mediump float tmpvar_8;
+        tmpvar_8 = pow ((cos(val_7) + 1.0), val_7);
+        tmpvar_6 = ((res_5 - 0.5) * tmpvar_8);
+        res_5 = tmpvar_6;
+      } else {
+        if ((i_4 == 1.0)) {
+          lowp vec3 tmpvar_9;
+          mediump float val_10;
+          val_10 = ((_SaturationShift.y * 3.0) + 12.0);
+          mediump float tmpvar_11;
+          tmpvar_11 = pow ((cos(val_10) + 1.0), val_10);
+          tmpvar_9 = ((res_5 - 0.5) * tmpvar_11);
+          res_5 = tmpvar_9;
+        } else {
+          if ((i_4 == 2.0)) {
+            lowp vec3 tmpvar_12;
+            mediump float val_13;
+            val_13 = ((_HueShift.z * 3.0) + 12.0);
+            mediump float tmpvar_14;
+            tmpvar_14 = pow ((cos(val_13) + 1.0), val_13);
+            tmpvar_12 = ((res_5 - 0.5) * tmpvar_14);
+            res_5 = tmpvar_12;
+          } else {
+            lowp vec3 tmpvar_15;
+            mediump float val_16;
+            val_16 = ((_LuminosityShift.x * 3.0) + 12.0);
+            mediump float tmpvar_17;
+            tmpvar_17 = pow ((cos(val_16) + 1.0), val_16);
+            tmpvar_15 = ((res_5 - 0.5) * tmpvar_17);
+            res_5 = tmpvar_15;
+          };
+        };
+      };
+      i_4 += 1.0;
+    };
+    t_1.xyz = res_5;
+  };
+  lowp vec4 tmpvar_18;
+  tmpvar_18.w = 1.0;
+  tmpvar_18.xyz = t_1.xyz;
+  _fragData = tmpvar_18;
+}
+
+
+// stats: 37 alu 1 tex 7 flow
+// inputs: 1
+//  #0: xlv_TEXCOORD0 (medium float) 2x1 [-1]
+// uniforms: 5 (total size: 0)
+//  #0: _NumPasses (medium float) 1x1 [-1]
+//  #1: _ContrastShift (medium float) 4x1 [-1]
+//  #2: _SaturationShift (medium float) 4x1 [-1]
+//  #3: _HueShift (low float) 4x1 [-1]
+//  #4: _LuminosityShift (low float) 4x1 [-1]
+// textures: 1
+//  #0: _MainTex (low 2d) 0x0 [-1]

+ 97 - 0
3rdparty/glsl-optimizer/tests/fragment/bug-loop-undeclaredinductor-outES3Metal.txt

@@ -0,0 +1,97 @@
+#include <metal_stdlib>
+using namespace metal;
+struct xlatMtlShaderInput {
+  half2 xlv_TEXCOORD0;
+};
+struct xlatMtlShaderOutput {
+  half4 _fragData [[color(0)]];
+};
+struct xlatMtlShaderUniform {
+  half _NumPasses;
+  half4 _ContrastShift;
+  half4 _SaturationShift;
+  half4 _HueShift;
+  half4 _LuminosityShift;
+};
+fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]]
+  ,   texture2d<half> _MainTex [[texture(0)]], sampler _mtlsmp__MainTex [[sampler(0)]])
+{
+  xlatMtlShaderOutput _mtl_o;
+  half4 t_1;
+  half4 tmpvar_2;
+  tmpvar_2 = _MainTex.sample(_mtlsmp__MainTex, (float2)(_mtl_i.xlv_TEXCOORD0));
+  t_1 = tmpvar_2;
+  if ((_mtl_u._NumPasses > (half)0.0)) {
+    half passes_3;
+    passes_3 = _mtl_u._NumPasses;
+    float i_4;
+    half3 res_5;
+    res_5 = tmpvar_2.xyz;
+    i_4 = 0.0;
+    while (true) {
+      if ((i_4 >= 4.0)) {
+        break;
+      };
+      if ((i_4 == (float)passes_3)) {
+        break;
+      };
+      if ((i_4 == 0.0)) {
+        half3 tmpvar_6;
+        half val_7;
+        val_7 = ((_mtl_u._ContrastShift.x * (half)3.0) + (half)12.0);
+        half tmpvar_8;
+        tmpvar_8 = pow ((cos(val_7) + (half)1.0), val_7);
+        tmpvar_6 = ((res_5 - (half)0.5) * tmpvar_8);
+        res_5 = tmpvar_6;
+      } else {
+        if ((i_4 == 1.0)) {
+          half3 tmpvar_9;
+          half val_10;
+          val_10 = ((_mtl_u._SaturationShift.y * (half)3.0) + (half)12.0);
+          half tmpvar_11;
+          tmpvar_11 = pow ((cos(val_10) + (half)1.0), val_10);
+          tmpvar_9 = ((res_5 - (half)0.5) * tmpvar_11);
+          res_5 = tmpvar_9;
+        } else {
+          if ((i_4 == 2.0)) {
+            half3 tmpvar_12;
+            half val_13;
+            val_13 = ((_mtl_u._HueShift.z * (half)3.0) + (half)12.0);
+            half tmpvar_14;
+            tmpvar_14 = pow ((cos(val_13) + (half)1.0), val_13);
+            tmpvar_12 = ((res_5 - (half)0.5) * tmpvar_14);
+            res_5 = tmpvar_12;
+          } else {
+            half3 tmpvar_15;
+            half val_16;
+            val_16 = ((_mtl_u._LuminosityShift.x * (half)3.0) + (half)12.0);
+            half tmpvar_17;
+            tmpvar_17 = pow ((cos(val_16) + (half)1.0), val_16);
+            tmpvar_15 = ((res_5 - (half)0.5) * tmpvar_17);
+            res_5 = tmpvar_15;
+          };
+        };
+      };
+      i_4 += 1.0;
+    };
+    t_1.xyz = res_5;
+  };
+  half4 tmpvar_18;
+  tmpvar_18.w = half(1.0);
+  tmpvar_18.xyz = t_1.xyz;
+  _mtl_o._fragData = tmpvar_18;
+  return _mtl_o;
+}
+
+
+// stats: 37 alu 1 tex 7 flow
+// inputs: 1
+//  #0: xlv_TEXCOORD0 (medium float) 2x1 [-1]
+// uniforms: 5 (total size: 40)
+//  #0: _NumPasses (medium float) 1x1 [-1] loc 0
+//  #1: _ContrastShift (medium float) 4x1 [-1] loc 8
+//  #2: _SaturationShift (medium float) 4x1 [-1] loc 16
+//  #3: _HueShift (low float) 4x1 [-1] loc 24
+//  #4: _LuminosityShift (low float) 4x1 [-1] loc 32
+// textures: 1
+//  #0: _MainTex (low 2d) 0x0 [-1] loc 0

+ 21 - 0
3rdparty/glsl-optimizer/tests/fragment/float-literals-in.txt

@@ -0,0 +1,21 @@
+varying vec2 uv;
+
+void main()
+{
+	vec4 c = vec4(0.0);
+	float a, b;
+
+	a = uv.y * 1.111111e+6;
+	b = uv.y * 1.111110e+6;
+	c.x = a-b;
+
+	a = uv.y * 1.23456789;
+	b = uv.y * 1.23456765;
+	c.y = a-b;
+
+	a = uv.y * -1.234567e-6;
+	b = uv.y * -1.234565e-6;
+	c.z = a-b;
+
+	gl_FragColor = c;
+}

+ 23 - 0
3rdparty/glsl-optimizer/tests/fragment/float-literals-out.txt

@@ -0,0 +1,23 @@
+varying vec2 uv;
+void main ()
+{
+  float b_1;
+  float a_2;
+  vec4 c_3;
+  c_3.w = 0.0;
+  a_2 = (uv.y * 1111111.0);
+  b_1 = (uv.y * 1111110.0);
+  c_3.x = (a_2 - b_1);
+  a_2 = (uv.y * 1.234568);
+  b_1 = (uv.y * 1.234568);
+  c_3.y = (a_2 - b_1);
+  a_2 = (uv.y * -1.234567e-06);
+  b_1 = (uv.y * -1.234565e-06);
+  c_3.z = (a_2 - b_1);
+  gl_FragColor = c_3;
+}
+
+
+// stats: 10 alu 0 tex 0 flow
+// inputs: 1
+//  #0: uv (high float) 2x1 [-1]

+ 20 - 2
3rdparty/glsl-optimizer/tests/fragment/intrinsics-inES3.txt

@@ -55,8 +55,9 @@ vec4 xll_modf( vec4 x, out vec4 ip) {
   ip = vec4(i);
   ip = vec4(i);
   return x-ip;
   return x-ip;
 }
 }
-mediump vec4 xlat_main( in highp vec4 uv );
-mediump vec4 xlat_main( in highp vec4 uv ) {
+
+mediump vec4 xlat_main (in highp vec4 uv)
+{
     mediump vec4 c;
     mediump vec4 c;
     mediump vec4 d;
     mediump vec4 d;
     c = vec4( 0.000000);
     c = vec4( 0.000000);
@@ -68,8 +69,25 @@ mediump vec4 xlat_main( in highp vec4 uv ) {
     c.xy  += xll_modf( uv.xy , d.xy );
     c.xy  += xll_modf( uv.xy , d.xy );
     c.xyz  += xll_modf( uv.xyz , d.xyz );
     c.xyz  += xll_modf( uv.xyz , d.xyz );
     c.xyzw  += xll_modf( uv.xyzw , d.xyzw );
     c.xyzw  += xll_modf( uv.xyzw , d.xyzw );
+
+    // GLSL mod function
+    c.x += mod(uv.x, d.x);
+    c.xy += mod(uv.xy, d.xy);
+    c.xyz += mod(uv.xyz, d.xyz);
+
+    // inverse
+    c.x += 1.0/uv.x; // float
+    c.x += max(0.0, 1.0/uv.x);
+
+    c.y += 1.0/c.z; // half
+    c.y += max(0.0, 1.0/c.w);
+
+    // max with different precision arguments
+    c.x += max(uv.x, c.z);
+
     return c;
     return c;
 }
 }
+
 in highp vec4 xlv_TEXCOORD0;
 in highp vec4 xlv_TEXCOORD0;
 out mediump vec4 _fragData;
 out mediump vec4 _fragData;
 void main() {
 void main() {

+ 16 - 16
3rdparty/glsl-optimizer/tests/fragment/intrinsics-outES.txt

@@ -97,31 +97,31 @@ void main ()
   c_1 = (c_1 + tmpvar_22);
   c_1 = (c_1 + tmpvar_22);
   highp float tmpvar_23;
   highp float tmpvar_23;
   mediump float ip_24;
   mediump float ip_24;
-  int tmpvar_25;
+  highp int tmpvar_25;
   tmpvar_25 = int(xlv_TEXCOORD0.x);
   tmpvar_25 = int(xlv_TEXCOORD0.x);
   ip_24 = float(tmpvar_25);
   ip_24 = float(tmpvar_25);
   tmpvar_23 = (xlv_TEXCOORD0.x - ip_24);
   tmpvar_23 = (xlv_TEXCOORD0.x - ip_24);
   c_1.x = (c_1.x + tmpvar_23);
   c_1.x = (c_1.x + tmpvar_23);
   highp vec2 tmpvar_26;
   highp vec2 tmpvar_26;
-  mediump vec2 ip_27;
-  highp vec2 tmpvar_28;
-  tmpvar_28 = vec2(ivec2(xlv_TEXCOORD0.xy));
-  ip_27 = tmpvar_28;
-  tmpvar_26 = (xlv_TEXCOORD0.xy - ip_27);
+  highp ivec2 tmpvar_27;
+  tmpvar_27 = ivec2(xlv_TEXCOORD0.xy);
+  mediump vec2 tmpvar_28;
+  tmpvar_28 = vec2(tmpvar_27);
+  tmpvar_26 = (xlv_TEXCOORD0.xy - tmpvar_28);
   c_1.xy = (c_1.xy + tmpvar_26);
   c_1.xy = (c_1.xy + tmpvar_26);
   highp vec3 tmpvar_29;
   highp vec3 tmpvar_29;
-  mediump vec3 ip_30;
-  highp vec3 tmpvar_31;
-  tmpvar_31 = vec3(ivec3(xlv_TEXCOORD0.xyz));
-  ip_30 = tmpvar_31;
-  tmpvar_29 = (xlv_TEXCOORD0.xyz - ip_30);
+  highp ivec3 tmpvar_30;
+  tmpvar_30 = ivec3(xlv_TEXCOORD0.xyz);
+  mediump vec3 tmpvar_31;
+  tmpvar_31 = vec3(tmpvar_30);
+  tmpvar_29 = (xlv_TEXCOORD0.xyz - tmpvar_31);
   c_1.xyz = (c_1.xyz + tmpvar_29);
   c_1.xyz = (c_1.xyz + tmpvar_29);
   highp vec4 tmpvar_32;
   highp vec4 tmpvar_32;
-  mediump vec4 ip_33;
-  highp vec4 tmpvar_34;
-  tmpvar_34 = vec4(ivec4(xlv_TEXCOORD0));
-  ip_33 = tmpvar_34;
-  tmpvar_32 = (xlv_TEXCOORD0 - ip_33);
+  highp ivec4 tmpvar_33;
+  tmpvar_33 = ivec4(xlv_TEXCOORD0);
+  mediump vec4 tmpvar_34;
+  tmpvar_34 = vec4(tmpvar_33);
+  tmpvar_32 = (xlv_TEXCOORD0 - tmpvar_34);
   c_1 = (c_1 + tmpvar_32);
   c_1 = (c_1 + tmpvar_32);
   gl_FragData[0] = c_1;
   gl_FragData[0] = c_1;
 }
 }

+ 37 - 17
3rdparty/glsl-optimizer/tests/fragment/intrinsics-outES3.txt

@@ -99,36 +99,56 @@ void main ()
   c_1 = (c_1 + tmpvar_22);
   c_1 = (c_1 + tmpvar_22);
   highp float tmpvar_23;
   highp float tmpvar_23;
   mediump float ip_24;
   mediump float ip_24;
-  int tmpvar_25;
+  highp int tmpvar_25;
   tmpvar_25 = int(xlv_TEXCOORD0.x);
   tmpvar_25 = int(xlv_TEXCOORD0.x);
   ip_24 = float(tmpvar_25);
   ip_24 = float(tmpvar_25);
   tmpvar_23 = (xlv_TEXCOORD0.x - ip_24);
   tmpvar_23 = (xlv_TEXCOORD0.x - ip_24);
   c_1.x = (c_1.x + tmpvar_23);
   c_1.x = (c_1.x + tmpvar_23);
   highp vec2 tmpvar_26;
   highp vec2 tmpvar_26;
-  mediump vec2 ip_27;
-  highp vec2 tmpvar_28;
-  tmpvar_28 = vec2(ivec2(xlv_TEXCOORD0.xy));
-  ip_27 = tmpvar_28;
-  tmpvar_26 = (xlv_TEXCOORD0.xy - ip_27);
+  highp ivec2 tmpvar_27;
+  tmpvar_27 = ivec2(xlv_TEXCOORD0.xy);
+  mediump vec2 tmpvar_28;
+  tmpvar_28 = vec2(tmpvar_27);
+  tmpvar_26 = (xlv_TEXCOORD0.xy - tmpvar_28);
   c_1.xy = (c_1.xy + tmpvar_26);
   c_1.xy = (c_1.xy + tmpvar_26);
   highp vec3 tmpvar_29;
   highp vec3 tmpvar_29;
-  mediump vec3 ip_30;
-  highp vec3 tmpvar_31;
-  tmpvar_31 = vec3(ivec3(xlv_TEXCOORD0.xyz));
-  ip_30 = tmpvar_31;
-  tmpvar_29 = (xlv_TEXCOORD0.xyz - ip_30);
+  highp ivec3 tmpvar_30;
+  tmpvar_30 = ivec3(xlv_TEXCOORD0.xyz);
+  mediump vec3 tmpvar_31;
+  tmpvar_31 = vec3(tmpvar_30);
+  tmpvar_29 = (xlv_TEXCOORD0.xyz - tmpvar_31);
   c_1.xyz = (c_1.xyz + tmpvar_29);
   c_1.xyz = (c_1.xyz + tmpvar_29);
   highp vec4 tmpvar_32;
   highp vec4 tmpvar_32;
-  mediump vec4 ip_33;
-  highp vec4 tmpvar_34;
-  tmpvar_34 = vec4(ivec4(xlv_TEXCOORD0));
-  ip_33 = tmpvar_34;
-  tmpvar_32 = (xlv_TEXCOORD0 - ip_33);
+  highp ivec4 tmpvar_33;
+  tmpvar_33 = ivec4(xlv_TEXCOORD0);
+  mediump vec4 tmpvar_34;
+  tmpvar_34 = vec4(tmpvar_33);
+  tmpvar_32 = (xlv_TEXCOORD0 - tmpvar_34);
   c_1 = (c_1 + tmpvar_32);
   c_1 = (c_1 + tmpvar_32);
+  highp float tmpvar_35;
+  tmpvar_35 = (float(mod (xlv_TEXCOORD0.x, tmpvar_34.x)));
+  c_1.x = (c_1.x + tmpvar_35);
+  highp vec2 tmpvar_36;
+  tmpvar_36 = (vec2(mod (xlv_TEXCOORD0.xy, tmpvar_34.xy)));
+  c_1.xy = (c_1.xy + tmpvar_36);
+  highp vec3 tmpvar_37;
+  tmpvar_37 = (vec3(mod (xlv_TEXCOORD0.xyz, tmpvar_34.xyz)));
+  c_1.xyz = (c_1.xyz + tmpvar_37);
+  highp float tmpvar_38;
+  tmpvar_38 = (1.0/(xlv_TEXCOORD0.x));
+  c_1.x = (c_1.x + tmpvar_38);
+  highp float tmpvar_39;
+  tmpvar_39 = max (0.0, tmpvar_38);
+  c_1.x = (c_1.x + tmpvar_39);
+  c_1.y = (c_1.y + (1.0/(c_1.z)));
+  c_1.y = (c_1.y + max (0.0, (1.0/(c_1.w))));
+  highp float tmpvar_40;
+  tmpvar_40 = max (xlv_TEXCOORD0.x, c_1.z);
+  c_1.x = (c_1.x + tmpvar_40);
   _fragData = c_1;
   _fragData = c_1;
 }
 }
 
 
 
 
-// stats: 56 alu 0 tex 10 flow
+// stats: 73 alu 0 tex 10 flow
 // inputs: 1
 // inputs: 1
 //  #0: xlv_TEXCOORD0 (high float) 4x1 [-1]
 //  #0: xlv_TEXCOORD0 (high float) 4x1 [-1]

+ 36 - 16
3rdparty/glsl-optimizer/tests/fragment/intrinsics-outES3Metal.txt

@@ -113,31 +113,51 @@ fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]]
   tmpvar_23 = (_mtl_i.xlv_TEXCOORD0.x - (float)ip_24);
   tmpvar_23 = (_mtl_i.xlv_TEXCOORD0.x - (float)ip_24);
   c_1.x = ((half)((float)c_1.x + tmpvar_23));
   c_1.x = ((half)((float)c_1.x + tmpvar_23));
   float2 tmpvar_26;
   float2 tmpvar_26;
-  half2 ip_27;
-  float2 tmpvar_28;
-  tmpvar_28 = float2(int2(_mtl_i.xlv_TEXCOORD0.xy));
-  ip_27 = half2(tmpvar_28);
-  tmpvar_26 = (_mtl_i.xlv_TEXCOORD0.xy - (float2)ip_27);
+  int2 tmpvar_27;
+  tmpvar_27 = int2(_mtl_i.xlv_TEXCOORD0.xy);
+  half2 tmpvar_28;
+  tmpvar_28 = half2(float2(tmpvar_27));
+  tmpvar_26 = (_mtl_i.xlv_TEXCOORD0.xy - (float2)tmpvar_28);
   c_1.xy = ((half2)((float2)c_1.xy + tmpvar_26));
   c_1.xy = ((half2)((float2)c_1.xy + tmpvar_26));
   float3 tmpvar_29;
   float3 tmpvar_29;
-  half3 ip_30;
-  float3 tmpvar_31;
-  tmpvar_31 = float3(int3(_mtl_i.xlv_TEXCOORD0.xyz));
-  ip_30 = half3(tmpvar_31);
-  tmpvar_29 = (_mtl_i.xlv_TEXCOORD0.xyz - (float3)ip_30);
+  int3 tmpvar_30;
+  tmpvar_30 = int3(_mtl_i.xlv_TEXCOORD0.xyz);
+  half3 tmpvar_31;
+  tmpvar_31 = half3(float3(tmpvar_30));
+  tmpvar_29 = (_mtl_i.xlv_TEXCOORD0.xyz - (float3)tmpvar_31);
   c_1.xyz = ((half3)((float3)c_1.xyz + tmpvar_29));
   c_1.xyz = ((half3)((float3)c_1.xyz + tmpvar_29));
   float4 tmpvar_32;
   float4 tmpvar_32;
-  half4 ip_33;
-  float4 tmpvar_34;
-  tmpvar_34 = float4(int4(_mtl_i.xlv_TEXCOORD0));
-  ip_33 = half4(tmpvar_34);
-  tmpvar_32 = (_mtl_i.xlv_TEXCOORD0 - (float4)ip_33);
+  int4 tmpvar_33;
+  tmpvar_33 = int4(_mtl_i.xlv_TEXCOORD0);
+  half4 tmpvar_34;
+  tmpvar_34 = half4(float4(tmpvar_33));
+  tmpvar_32 = (_mtl_i.xlv_TEXCOORD0 - (float4)tmpvar_34);
   c_1 = ((half4)((float4)c_1 + tmpvar_32));
   c_1 = ((half4)((float4)c_1 + tmpvar_32));
+  float tmpvar_35;
+  tmpvar_35 = (float(fmod (_mtl_i.xlv_TEXCOORD0.x, (float)tmpvar_34.x)));
+  c_1.x = half(((float)c_1.x + tmpvar_35));
+  float2 tmpvar_36;
+  tmpvar_36 = (float2(fmod (_mtl_i.xlv_TEXCOORD0.xy, (float2)tmpvar_34.xy)));
+  c_1.xy = half2(((float2)c_1.xy + tmpvar_36));
+  float3 tmpvar_37;
+  tmpvar_37 = (float3(fmod (_mtl_i.xlv_TEXCOORD0.xyz, (float3)tmpvar_34.xyz)));
+  c_1.xyz = half3(((float3)c_1.xyz + tmpvar_37));
+  float tmpvar_38;
+  tmpvar_38 = (1.0/(_mtl_i.xlv_TEXCOORD0.x));
+  c_1.x = half(((float)c_1.x + tmpvar_38));
+  float tmpvar_39;
+  tmpvar_39 = max (0.0, tmpvar_38);
+  c_1.x = half(((float)c_1.x + tmpvar_39));
+  c_1.y = (c_1.y + ((half)1.0/(c_1.z)));
+  c_1.y = (c_1.y + max ((half)0.0, ((half)1.0/(c_1.w))));
+  float tmpvar_40;
+  tmpvar_40 = max (_mtl_i.xlv_TEXCOORD0.x, (float)c_1.z);
+  c_1.x = half(((float)c_1.x + tmpvar_40));
   _mtl_o._fragData = c_1;
   _mtl_o._fragData = c_1;
   return _mtl_o;
   return _mtl_o;
 }
 }
 
 
 
 
-// stats: 56 alu 0 tex 10 flow
+// stats: 73 alu 0 tex 10 flow
 // inputs: 1
 // inputs: 1
 //  #0: xlv_TEXCOORD0 (high float) 4x1 [-1]
 //  #0: xlv_TEXCOORD0 (high float) 4x1 [-1]

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/loop-for-inES3.txt

@@ -8,7 +8,7 @@ uniform sampler2D _MainTex;
 uniform mediump vec4 _TerrainTreeLightColors[4];
 uniform mediump vec4 _TerrainTreeLightColors[4];
 lowp vec4 xlat_main (in v2f i) {
 lowp vec4 xlat_main (in v2f i) {
     highp int j = 0;
     highp int j = 0;
-    lowp vec4 col = texture2D( _MainTex, i.uv);
+    lowp vec4 col = texture( _MainTex, i.uv);
     mediump vec3 light = vec3(0.0);
     mediump vec3 light = vec3(0.0);
     for ( ; (j < 3); (j++)) {
     for ( ; (j < 3); (j++)) {
         light += col.xyz * i.nl[j] * _TerrainTreeLightColors[j].xyz;
         light += col.xyz * i.nl[j] * _TerrainTreeLightColors[j].xyz;

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/loop-forafterdiscard-inES3.txt

@@ -7,7 +7,7 @@ struct v2f {
 uniform sampler2D _MainTex;
 uniform sampler2D _MainTex;
 uniform mediump vec4 _TerrainTreeLightColors[4];
 uniform mediump vec4 _TerrainTreeLightColors[4];
 lowp vec4 xlat_main (in v2f i) {
 lowp vec4 xlat_main (in v2f i) {
-    lowp vec4 col = texture2D( _MainTex, i.uv);
+    lowp vec4 col = texture( _MainTex, i.uv);
     if (col.w < 0.5)
     if (col.w < 0.5)
         discard;
         discard;
     mediump vec3 light = vec3(0.0);
     mediump vec3 light = vec3(0.0);

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/loop-fornounroll-outES.txt

@@ -2,7 +2,7 @@ void main ()
 {
 {
   highp float f_1;
   highp float f_1;
   f_1 = 0.0;
   f_1 = 0.0;
-  for (int i_2 = 0; i_2 < 32; i_2++) {
+  for (highp int i_2 = 0; i_2 < 32; i_2++) {
     f_1 = (f_1 + (gl_FragCoord.x * float(i_2)));
     f_1 = (f_1 + (gl_FragCoord.x * float(i_2)));
   };
   };
   highp vec4 tmpvar_3;
   highp vec4 tmpvar_3;

+ 2 - 2
3rdparty/glsl-optimizer/tests/fragment/loop-forunbounded-outES.txt

@@ -7,7 +7,7 @@ void main ()
   lowp vec4 tmpvar_1;
   lowp vec4 tmpvar_1;
   highp vec3 tmpvar_2;
   highp vec3 tmpvar_2;
   tmpvar_2 = xlv_nl;
   tmpvar_2 = xlv_nl;
-  int loopCount_4;
+  lowp int loopCount_4;
   mediump vec3 light_5;
   mediump vec3 light_5;
   lowp vec4 col_6;
   lowp vec4 col_6;
   lowp vec4 tmpvar_7;
   lowp vec4 tmpvar_7;
@@ -15,7 +15,7 @@ void main ()
   col_6 = tmpvar_7;
   col_6 = tmpvar_7;
   light_5 = vec3(0.0, 0.0, 0.0);
   light_5 = vec3(0.0, 0.0, 0.0);
   loopCount_4 = int((tmpvar_7.w * 10.0));
   loopCount_4 = int((tmpvar_7.w * 10.0));
-  for (int j_3 = 0; j_3 < loopCount_4; j_3++) {
+  for (highp int j_3 = 0; j_3 < loopCount_4; j_3++) {
     light_5 = (light_5 + ((col_6.xyz * 
     light_5 = (light_5 + ((col_6.xyz * 
       tmpvar_2[j_3]
       tmpvar_2[j_3]
     ) * _TerrainTreeLightColors[j_3].xyz));
     ) * _TerrainTreeLightColors[j_3].xyz));

+ 2 - 2
3rdparty/glsl-optimizer/tests/fragment/opt-movevars-sideeffect2-outES.txt

@@ -2,7 +2,7 @@ varying lowp float xx;
 void main ()
 void main ()
 {
 {
   lowp float c_1;
   lowp float c_1;
-  int tmpvar_3;
+  highp int tmpvar_3;
   if ((xx > 0.5)) {
   if ((xx > 0.5)) {
     tmpvar_3 = 2;
     tmpvar_3 = 2;
   } else {
   } else {
@@ -12,7 +12,7 @@ void main ()
     discard;
     discard;
   };
   };
   c_1 = 0.0;
   c_1 = 0.0;
-  for (int i_2 = tmpvar_3; i_2 < 4; i_2++, c_1 = (c_1 + xx)) {
+  for (highp int i_2 = tmpvar_3; i_2 < 4; i_2++, c_1 = (c_1 + xx)) {
   };
   };
   lowp vec4 tmpvar_4;
   lowp vec4 tmpvar_4;
   tmpvar_4 = vec4(c_1);
   tmpvar_4 = vec4(c_1);

+ 6 - 6
3rdparty/glsl-optimizer/tests/fragment/prec-default-outES.txt

@@ -8,20 +8,20 @@ uniform MyStruct s1;
 uniform float fh1;
 uniform float fh1;
 uniform highp float fh2;
 uniform highp float fh2;
 uniform mediump float fm;
 uniform mediump float fm;
-uniform int il1;
-uniform int il2;
-uniform int im;
+uniform highp int il1;
+uniform lowp int il2;
+uniform mediump int im;
 void main ()
 void main ()
 {
 {
-  int i_1;
+  highp int i_1;
   lowp float f_2;
   lowp float f_2;
   highp float tmpvar_3;
   highp float tmpvar_3;
   tmpvar_3 = (((fh1 + fh2) + fm) + s1.f);
   tmpvar_3 = (((fh1 + fh2) + fm) + s1.f);
   f_2 = tmpvar_3;
   f_2 = tmpvar_3;
-  int tmpvar_4;
+  mediump int tmpvar_4;
   tmpvar_4 = (((il1 + il2) + im) + s1.i);
   tmpvar_4 = (((il1 + il2) + im) + s1.i);
   i_1 = tmpvar_4;
   i_1 = tmpvar_4;
-  float tmpvar_5;
+  highp float tmpvar_5;
   if ((gl_FragCoord.x > 0.5)) {
   if ((gl_FragCoord.x > 0.5)) {
     tmpvar_5 = 0.9;
     tmpvar_5 = 0.9;
   } else {
   } else {

+ 5 - 5
3rdparty/glsl-optimizer/tests/fragment/prec-inlineexpr1-outES.txt

@@ -5,13 +5,13 @@ uniform mediump float _EmberFadeStart;
 varying mediump vec2 xlv_TEXCOORD0;
 varying mediump vec2 xlv_TEXCOORD0;
 void main ()
 void main ()
 {
 {
-  lowp float t_1;
-  mediump float tmpvar_2;
-  tmpvar_2 = clamp (((_EmberFadeStart - 0.05) / (_EmberFadeStart - _EmberFadeEnd)), 0.0, 1.0);
-  t_1 = tmpvar_2;
+  mediump float x_1;
+  x_1 = ((_EmberFadeStart - 0.05) / (_EmberFadeStart - _EmberFadeEnd));
+  lowp float tmpvar_2;
+  tmpvar_2 = clamp (x_1, 0.0, 1.0);
   lowp vec4 tmpvar_3;
   lowp vec4 tmpvar_3;
   tmpvar_3.w = 1.0;
   tmpvar_3.w = 1.0;
-  tmpvar_3.xyz = mix (texture2D (_MainTex, xlv_TEXCOORD0).xyz, texture2D (_BurntTex, xlv_TEXCOORD0).xyz, vec3(t_1));
+  tmpvar_3.xyz = mix (texture2D (_MainTex, xlv_TEXCOORD0).xyz, texture2D (_BurntTex, xlv_TEXCOORD0).xyz, vec3(tmpvar_2));
   gl_FragColor = tmpvar_3;
   gl_FragColor = tmpvar_3;
 }
 }
 
 

+ 5 - 5
3rdparty/glsl-optimizer/tests/fragment/prec-inlineexpr2-outES.txt

@@ -5,13 +5,13 @@ uniform mediump float _EmberFadeStart;
 varying mediump vec2 xlv_TEXCOORD0;
 varying mediump vec2 xlv_TEXCOORD0;
 void main ()
 void main ()
 {
 {
-  lowp vec3 t_1;
-  mediump vec3 tmpvar_2;
-  tmpvar_2 = vec3(clamp (((_EmberFadeStart - 0.05) / (_EmberFadeStart - _EmberFadeEnd)), 0.0, 1.0));
-  t_1 = tmpvar_2;
+  mediump float tmpvar_1;
+  tmpvar_1 = clamp (((_EmberFadeStart - 0.05) / (_EmberFadeStart - _EmberFadeEnd)), 0.0, 1.0);
+  lowp vec3 tmpvar_2;
+  tmpvar_2 = vec3(tmpvar_1);
   lowp vec4 tmpvar_3;
   lowp vec4 tmpvar_3;
   tmpvar_3.w = 1.0;
   tmpvar_3.w = 1.0;
-  tmpvar_3.xyz = mix (texture2D (_MainTex, xlv_TEXCOORD0).xyz, texture2D (_BurntTex, xlv_TEXCOORD0).xyz, t_1);
+  tmpvar_3.xyz = mix (texture2D (_MainTex, xlv_TEXCOORD0).xyz, texture2D (_BurntTex, xlv_TEXCOORD0).xyz, tmpvar_2);
   gl_FragColor = tmpvar_3;
   gl_FragColor = tmpvar_3;
 }
 }
 
 

+ 28 - 0
3rdparty/glsl-optimizer/tests/fragment/prec-matrix-constr-inES3.txt

@@ -0,0 +1,28 @@
+#version 300 es
+
+// A very cut down variant of Unity's directional lightmap;
+// has an inline medium precision matrix constructor,
+// but even if dirBasis is declared as mediump
+// some code was promoting it to high precision.
+
+out mediump vec4 _glesFragData;
+
+mat3 transposem3(mat3 m) {
+  return mat3( m[0][0], m[1][0], m[2][0],
+               m[0][1], m[1][1], m[2][1],
+               m[0][2], m[1][2], m[2][2]);
+}
+
+in mediump vec3 inNormal;
+
+void main()
+{
+    mediump mat3 dirBasis = transposem3(mat3(
+        vec3( 0.8164966, 0.0, 0.5773503),
+        vec3( -0.4082483, 0.7071068, 0.5773503),
+        vec3( -0.4082483, -0.7071068, 0.5773503)));
+    mediump vec4 c;
+    c.xyz = dirBasis * inNormal;
+    c.w = 0.0;
+    _glesFragData = c;
+}

+ 25 - 0
3rdparty/glsl-optimizer/tests/fragment/prec-matrix-constr-outES3.txt

@@ -0,0 +1,25 @@
+#version 300 es
+out mediump vec4 _glesFragData;
+in mediump vec3 inNormal;
+void main ()
+{
+  mediump vec4 c_1;
+  mediump mat3 tmpvar_2;
+  tmpvar_2[uint(0)].x = 0.8164966;
+  tmpvar_2[uint(0)].y = -0.4082483;
+  tmpvar_2[uint(0)].z = -0.4082483;
+  tmpvar_2[1u].x = 0.0;
+  tmpvar_2[1u].y = 0.7071068;
+  tmpvar_2[1u].z = -0.7071068;
+  tmpvar_2[2u].x = 0.5773503;
+  tmpvar_2[2u].y = 0.5773503;
+  tmpvar_2[2u].z = 0.5773503;
+  c_1.xyz = (tmpvar_2 * inNormal);
+  c_1.w = 0.0;
+  _glesFragData = c_1;
+}
+
+
+// stats: 11 alu 0 tex 0 flow
+// inputs: 1
+//  #0: inNormal (medium float) 3x1 [-1]

+ 34 - 0
3rdparty/glsl-optimizer/tests/fragment/prec-matrix-constr-outES3Metal.txt

@@ -0,0 +1,34 @@
+#include <metal_stdlib>
+using namespace metal;
+struct xlatMtlShaderInput {
+  half3 inNormal;
+};
+struct xlatMtlShaderOutput {
+  half4 _glesFragData [[color(0)]];
+};
+struct xlatMtlShaderUniform {
+};
+fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]])
+{
+  xlatMtlShaderOutput _mtl_o;
+  half4 c_1;
+  half3x3 tmpvar_2;
+  tmpvar_2[0].x = half(0.8164966);
+  tmpvar_2[0].y = half(-0.4082483);
+  tmpvar_2[0].z = half(-0.4082483);
+  tmpvar_2[1].x = half(0.0);
+  tmpvar_2[1].y = half(0.7071068);
+  tmpvar_2[1].z = half(-0.7071068);
+  tmpvar_2[2].x = half(0.5773503);
+  tmpvar_2[2].y = half(0.5773503);
+  tmpvar_2[2].z = half(0.5773503);
+  c_1.xyz = (tmpvar_2 * _mtl_i.inNormal);
+  c_1.w = half(0.0);
+  _mtl_o._glesFragData = c_1;
+  return _mtl_o;
+}
+
+
+// stats: 11 alu 0 tex 0 flow
+// inputs: 1
+//  #0: inNormal (medium float) 3x1 [-1]

+ 6 - 6
3rdparty/glsl-optimizer/tests/fragment/sampler-precision-inES3.txt

@@ -9,12 +9,12 @@ uniform highp samplerCube cubehigh;
 
 
 mediump vec4 xlat_main(in highp vec4 uv) {
 mediump vec4 xlat_main(in highp vec4 uv) {
     mediump vec4 c;
     mediump vec4 c;
-    c = texture2D(texlow, uv.xy);
-    c += texture2D(texmed, uv.xy);
-    c += texture2D(texhigh, uv.xy);
-    c += textureCube(cubelow, uv.xyz);
-    c += textureCube(cubemed, uv.xyz);
-    c += textureCube(cubehigh, uv.xyz);
+    c = texture(texlow, uv.xy);
+    c += texture(texmed, uv.xy);
+    c += texture(texhigh, uv.xy);
+    c += texture(cubelow, uv.xyz);
+    c += texture(cubemed, uv.xyz);
+    c += texture(cubehigh, uv.xyz);
     return c;
     return c;
 }
 }
 in highp vec4 varUV;
 in highp vec4 varUV;

+ 10 - 1
3rdparty/glsl-optimizer/tests/fragment/tex2dlod-outES.txt

@@ -1,11 +1,20 @@
 #extension GL_EXT_shader_texture_lod : enable
 #extension GL_EXT_shader_texture_lod : enable
+lowp vec4 impl_low_texture2DLodEXT(lowp sampler2D sampler, highp vec2 coord, mediump float lod)
+{
+#if defined(GL_EXT_shader_texture_lod)
+	return texture2DLodEXT(sampler, coord, lod);
+#else
+	return texture2D(sampler, coord, lod);
+#endif
+}
+
 uniform sampler2D tex;
 uniform sampler2D tex;
 varying highp vec4 xlv_TEXCOORD0;
 varying highp vec4 xlv_TEXCOORD0;
 void main ()
 void main ()
 {
 {
   mediump vec4 tmpvar_1;
   mediump vec4 tmpvar_1;
   lowp vec4 tmpvar_2;
   lowp vec4 tmpvar_2;
-  tmpvar_2 = texture2DLodEXT (tex, xlv_TEXCOORD0.xy, 0.0);
+  tmpvar_2 = impl_low_texture2DLodEXT (tex, xlv_TEXCOORD0.xy, 0.0);
   tmpvar_1 = tmpvar_2;
   tmpvar_1 = tmpvar_2;
   gl_FragData[0] = tmpvar_1;
   gl_FragData[0] = tmpvar_1;
 }
 }

+ 2 - 2
3rdparty/glsl-optimizer/tests/fragment/texOffset-outES3.txt

@@ -6,9 +6,9 @@ uniform lowp sampler3D vol;
 void main ()
 void main ()
 {
 {
   lowp vec4 c_1;
   lowp vec4 c_1;
-  c_1 = (textureOffset (tex, uv.xy, ivec2(-2, -3)) + textureOffset (tex, uv.xy, 0.5, ivec2(4, 5)));
+  c_1 = (textureOffset (tex, uv.xy, ivec2(-2, -3)) + textureOffset (tex, uv.xy, ivec2(4, 5), 0.5));
   c_1 = (c_1 + textureOffset (vol, uv, ivec3(-2, -3, -4)));
   c_1 = (c_1 + textureOffset (vol, uv, ivec3(-2, -3, -4)));
-  c_1 = (c_1 + textureOffset (vol, uv, -0.5, ivec3(4, 5, 6)));
+  c_1 = (c_1 + textureOffset (vol, uv, ivec3(4, 5, 6), -0.5));
   c_1 = (c_1 + texelFetch (tex, ivec2(1, 2), 1));
   c_1 = (c_1 + texelFetch (tex, ivec2(1, 2), 1));
   c_1 = (c_1 + texelFetch (vol, ivec3(1, 2, 3), 2));
   c_1 = (c_1 + texelFetch (vol, ivec3(1, 2, 3), 2));
   c_1 = (c_1 + texelFetchOffset (tex, ivec2(1, 2), 3, ivec2(-2, -3)));
   c_1 = (c_1 + texelFetchOffset (tex, ivec2(1, 2), 3, ivec2(-2, -3)));

+ 20 - 2
3rdparty/glsl-optimizer/tests/fragment/texProj-outES.txt

@@ -1,5 +1,23 @@
 #extension GL_EXT_shader_texture_lod : enable
 #extension GL_EXT_shader_texture_lod : enable
 #extension GL_EXT_shadow_samplers : enable
 #extension GL_EXT_shadow_samplers : enable
+lowp vec4 impl_low_texture2DProjLodEXT(lowp sampler2D sampler, highp vec4 coord, mediump float lod)
+{
+#if defined(GL_EXT_shader_texture_lod)
+	return texture2DProjLodEXT(sampler, coord, lod);
+#else
+	return texture2DProj(sampler, coord, lod);
+#endif
+}
+
+lowp vec4 impl_low_texture2DProjLodEXT(lowp sampler2D sampler, highp vec3 coord, mediump float lod)
+{
+#if defined(GL_EXT_shader_texture_lod)
+	return texture2DProjLodEXT(sampler, coord, lod);
+#else
+	return texture2DProj(sampler, coord, lod);
+#endif
+}
+
 uniform sampler2D tex;
 uniform sampler2D tex;
 uniform lowp sampler2DShadow shadowmap;
 uniform lowp sampler2DShadow shadowmap;
 varying highp vec4 uv;
 varying highp vec4 uv;
@@ -7,8 +25,8 @@ void main ()
 {
 {
   lowp vec4 c_1;
   lowp vec4 c_1;
   c_1 = (texture2DProj (tex, uv) + texture2DProj (tex, uv.xyz));
   c_1 = (texture2DProj (tex, uv) + texture2DProj (tex, uv.xyz));
-  c_1 = (c_1 + texture2DProjLodEXT (tex, uv, 1.0));
-  c_1 = (c_1 + texture2DProjLodEXT (tex, uv.xyz, 1.0));
+  c_1 = (c_1 + impl_low_texture2DProjLodEXT (tex, uv, 1.0));
+  c_1 = (c_1 + impl_low_texture2DProjLodEXT (tex, uv.xyz, 1.0));
   c_1 = (c_1 + vec4(shadow2DEXT (shadowmap, uv.xyz)));
   c_1 = (c_1 + vec4(shadow2DEXT (shadowmap, uv.xyz)));
   c_1 = (c_1 + vec4(shadow2DProjEXT (shadowmap, uv)));
   c_1 = (c_1 + vec4(shadow2DProjEXT (shadowmap, uv)));
   gl_FragColor = c_1;
   gl_FragColor = c_1;

+ 136 - 0
3rdparty/glsl-optimizer/tests/fragment/z-DirLMBasis-inES3.txt

@@ -0,0 +1,136 @@
+#version 300 es
+
+// A variant produced by Unity's directional lightmap;
+// has an inline medium precision matrix constructor,
+// but even if unity_DirBasis is declared as mediump
+// some code was promoting it to high precision.
+
+#define gl_FragColor _glesFragData[0]
+#define gl_FragData _glesFragData
+layout(location = 0)out mediump vec4 _glesFragData[4];
+
+mat3 xll_transpose_mf3x3(mat3 m) {
+  return mat3( m[0][0], m[1][0], m[2][0],
+               m[0][1], m[1][1], m[2][1],
+               m[0][2], m[1][2], m[2][2]);
+}
+vec3 xll_saturate_vf3( vec3 x) {
+  return clamp( x, 0.0, 1.0);
+}
+struct SurfaceOutput {
+    lowp vec3 Albedo;
+    lowp vec3 Normal;
+    lowp vec3 Emission;
+    mediump float Specular;
+    lowp float Gloss;
+    lowp float Alpha;
+};
+struct Input {
+    highp vec2 uv_MainTex;
+};
+struct v2f_surf {
+    highp vec4 pos;
+    highp vec2 pack0;
+    lowp vec3 tSpace0;
+    lowp vec3 tSpace1;
+    lowp vec3 tSpace2;
+    highp vec4 lmap;
+};
+uniform mediump vec4 _WorldSpaceLightPos0;
+uniform sampler2D unity_Lightmap;
+uniform sampler2D unity_LightmapInd;
+uniform lowp vec4 _LightColor0;
+uniform lowp vec4 _SpecColor;
+uniform sampler2D _MainTex;
+uniform highp vec4 _MainTex_ST;
+lowp vec3 DecodeLightmapDoubleLDR( in lowp vec4 color ) {
+    return (2.0 * color.xyz);
+}
+lowp vec3 DecodeLightmap( in lowp vec4 color ) {
+   
+    return DecodeLightmapDoubleLDR( color);
+}
+mediump vec3 DirLightmapDiffuse( in mediump mat3 dirBasis, in lowp vec4 color, in lowp vec4 scale, in mediump vec3 normal, in bool surfFuncWritesNormal, out mediump vec3 scalePerBasisVector ) {
+    mediump vec3 lm = DecodeLightmap( color);
+   
+    scalePerBasisVector = DecodeLightmap( scale);
+    if (surfFuncWritesNormal){
+       
+        mediump vec3 normalInRnmBasis = xll_saturate_vf3((dirBasis * normal));
+        lm *= dot( normalInRnmBasis, scalePerBasisVector);
+    }
+   
+    return lm;
+}
+mediump vec4 LightingLambert_DirLightmap( in SurfaceOutput s, in lowp vec4 color, in lowp vec4 scale, in bool surfFuncWritesNormal ) {
+    mediump mat3 unity_DirBasis = xll_transpose_mf3x3(mat3( vec3( 0.8164966, 0.0, 0.5773503), vec3( -0.4082483, 0.7071068, 0.5773503), vec3( -0.4082483, -0.7071068, 0.5773503)));
+    mediump vec3 scalePerBasisVector;
+   
+    mediump vec4 c;
+    c.xyz = DirLightmapDiffuse( unity_DirBasis, color, scale, s.Normal, surfFuncWritesNormal, scalePerBasisVector);
+    c.w = 0.0;
+   
+    return c;
+}
+void surf( in Input IN, inout SurfaceOutput o ) {
+    mediump vec4 c = texture( _MainTex, IN.uv_MainTex);
+    o.Albedo = c.xyz;
+    o.Alpha = c.w;
+   
+    o.Normal = ((c.xyz * 2.0) - 1.0);
+}
+lowp vec4 frag_surf( in v2f_surf IN ) {
+    Input surfIN;
+   
+    surfIN.uv_MainTex = IN.pack0.xy;
+    highp vec3 lightDir = _WorldSpaceLightPos0.xyz;
+   
+    SurfaceOutput o;
+    o.Albedo = vec3( 0.0);
+    o.Emission = vec3( 0.0);
+   
+    o.Specular = 0.0;
+    o.Alpha = 0.0;
+    o.Gloss = 0.0;
+    lowp vec3 normalWorldVertex = vec3( 0.0, 0.0, 1.0);
+   
+    surf( surfIN, o);
+    lowp float atten = 1.0;
+   
+    lowp vec4 c = vec4( 0.0);
+   
+    lowp vec4 lmtex = texture( unity_Lightmap, IN.lmap.xy);
+    lowp vec4 lmIndTex = texture( unity_LightmapInd, IN.lmap.xy);
+    mediump vec3 lm = LightingLambert_DirLightmap( o, lmtex, lmIndTex, true).xyz;
+   
+    lowp vec3 worldN;
+    worldN.x = dot( IN.tSpace0.xyz, o.Normal);
+    worldN.y = dot( IN.tSpace1.xyz, o.Normal);
+    worldN.z = dot( IN.tSpace2.xyz, o.Normal);
+   
+    o.Normal = worldN;
+   
+    c.w = o.Alpha;
+   
+    c.xyz += (o.Albedo * lm);
+   
+    c.w = 1.0;
+    return c;
+}
+in highp vec2 xlv_TEXCOORD0;
+in lowp vec3 xlv_TEXCOORD1;
+in lowp vec3 xlv_TEXCOORD2;
+in lowp vec3 xlv_TEXCOORD3;
+in highp vec4 xlv_TEXCOORD4;
+void main() {
+    lowp vec4 xl_retval;
+    v2f_surf xlt_IN;
+    xlt_IN.pos = vec4(0.0);
+    xlt_IN.pack0 = vec2(xlv_TEXCOORD0);
+    xlt_IN.tSpace0 = vec3(xlv_TEXCOORD1);
+    xlt_IN.tSpace1 = vec3(xlv_TEXCOORD2);
+    xlt_IN.tSpace2 = vec3(xlv_TEXCOORD3);
+    xlt_IN.lmap = vec4(xlv_TEXCOORD4);
+    xl_retval = frag_surf( xlt_IN);
+    gl_FragData[0] = vec4(xl_retval);
+}

+ 55 - 0
3rdparty/glsl-optimizer/tests/fragment/z-DirLMBasis-outES3.txt

@@ -0,0 +1,55 @@
+#version 300 es
+layout(location=0) out mediump vec4 _glesFragData[4];
+uniform sampler2D unity_Lightmap;
+uniform sampler2D unity_LightmapInd;
+uniform sampler2D _MainTex;
+in highp vec2 xlv_TEXCOORD0;
+in highp vec4 xlv_TEXCOORD4;
+void main ()
+{
+  lowp vec4 c_1;
+  lowp vec3 tmpvar_2;
+  lowp vec3 tmpvar_3;
+  mediump vec4 c_4;
+  lowp vec4 tmpvar_5;
+  tmpvar_5 = texture (_MainTex, xlv_TEXCOORD0);
+  c_4 = tmpvar_5;
+  tmpvar_2 = c_4.xyz;
+  tmpvar_3 = ((c_4.xyz * 2.0) - 1.0);
+  mediump mat3 tmpvar_6;
+  tmpvar_6[uint(0)].x = 0.8164966;
+  tmpvar_6[uint(0)].y = -0.4082483;
+  tmpvar_6[uint(0)].z = -0.4082483;
+  tmpvar_6[1u].x = 0.0;
+  tmpvar_6[1u].y = 0.7071068;
+  tmpvar_6[1u].z = -0.7071068;
+  tmpvar_6[2u].x = 0.5773503;
+  tmpvar_6[2u].y = 0.5773503;
+  tmpvar_6[2u].z = 0.5773503;
+  mediump vec3 normal_7;
+  normal_7 = tmpvar_3;
+  mediump vec3 scalePerBasisVector_8;
+  mediump vec3 lm_9;
+  lowp vec3 tmpvar_10;
+  tmpvar_10 = (2.0 * texture (unity_Lightmap, xlv_TEXCOORD4.xy).xyz);
+  lm_9 = tmpvar_10;
+  lowp vec3 tmpvar_11;
+  tmpvar_11 = (2.0 * texture (unity_LightmapInd, xlv_TEXCOORD4.xy).xyz);
+  scalePerBasisVector_8 = tmpvar_11;
+  lm_9 = (lm_9 * dot (clamp (
+    (tmpvar_6 * normal_7)
+  , 0.0, 1.0), scalePerBasisVector_8));
+  c_1.xyz = (tmpvar_2 * lm_9);
+  c_1.w = 1.0;
+  _glesFragData[0] = c_1;
+}
+
+
+// stats: 19 alu 3 tex 0 flow
+// inputs: 2
+//  #0: xlv_TEXCOORD0 (high float) 2x1 [-1]
+//  #1: xlv_TEXCOORD4 (high float) 4x1 [-1]
+// textures: 3
+//  #0: unity_Lightmap (low 2d) 0x0 [-1]
+//  #1: unity_LightmapInd (low 2d) 0x0 [-1]
+//  #2: _MainTex (low 2d) 0x0 [-1]

+ 64 - 0
3rdparty/glsl-optimizer/tests/fragment/z-DirLMBasis-outES3Metal.txt

@@ -0,0 +1,64 @@
+#include <metal_stdlib>
+using namespace metal;
+struct xlatMtlShaderInput {
+  float2 xlv_TEXCOORD0;
+  float4 xlv_TEXCOORD4;
+};
+struct xlatMtlShaderOutput {
+  half4 _glesFragData_0 [[color(0)]];
+};
+struct xlatMtlShaderUniform {
+};
+fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]]
+  ,   texture2d<half> unity_Lightmap [[texture(0)]], sampler _mtlsmp_unity_Lightmap [[sampler(0)]]
+  ,   texture2d<half> unity_LightmapInd [[texture(1)]], sampler _mtlsmp_unity_LightmapInd [[sampler(1)]]
+  ,   texture2d<half> _MainTex [[texture(2)]], sampler _mtlsmp__MainTex [[sampler(2)]])
+{
+  xlatMtlShaderOutput _mtl_o;
+  half4 c_1;
+  half3 tmpvar_2;
+  half3 tmpvar_3;
+  half4 c_4;
+  half4 tmpvar_5;
+  tmpvar_5 = _MainTex.sample(_mtlsmp__MainTex, (float2)(_mtl_i.xlv_TEXCOORD0));
+  c_4 = tmpvar_5;
+  tmpvar_2 = c_4.xyz;
+  tmpvar_3 = ((c_4.xyz * (half)2.0) - (half)1.0);
+  half3x3 tmpvar_6;
+  tmpvar_6[0].x = half(0.8164966);
+  tmpvar_6[0].y = half(-0.4082483);
+  tmpvar_6[0].z = half(-0.4082483);
+  tmpvar_6[1].x = half(0.0);
+  tmpvar_6[1].y = half(0.7071068);
+  tmpvar_6[1].z = half(-0.7071068);
+  tmpvar_6[2].x = half(0.5773503);
+  tmpvar_6[2].y = half(0.5773503);
+  tmpvar_6[2].z = half(0.5773503);
+  half3 normal_7;
+  normal_7 = tmpvar_3;
+  half3 scalePerBasisVector_8;
+  half3 lm_9;
+  half3 tmpvar_10;
+  tmpvar_10 = ((half)2.0 * unity_Lightmap.sample(_mtlsmp_unity_Lightmap, (float2)(_mtl_i.xlv_TEXCOORD4.xy)).xyz);
+  lm_9 = tmpvar_10;
+  half3 tmpvar_11;
+  tmpvar_11 = ((half)2.0 * unity_LightmapInd.sample(_mtlsmp_unity_LightmapInd, (float2)(_mtl_i.xlv_TEXCOORD4.xy)).xyz);
+  scalePerBasisVector_8 = tmpvar_11;
+  lm_9 = (lm_9 * dot (clamp (
+    (tmpvar_6 * normal_7)
+  , (half)0.0, (half)1.0), scalePerBasisVector_8));
+  c_1.xyz = (tmpvar_2 * lm_9);
+  c_1.w = half(1.0);
+  _mtl_o._glesFragData_0 = c_1;
+  return _mtl_o;
+}
+
+
+// stats: 19 alu 3 tex 0 flow
+// inputs: 2
+//  #0: xlv_TEXCOORD0 (high float) 2x1 [-1]
+//  #1: xlv_TEXCOORD4 (high float) 4x1 [-1]
+// textures: 3
+//  #0: unity_Lightmap (low 2d) 0x0 [-1] loc 0
+//  #1: unity_LightmapInd (low 2d) 0x0 [-1] loc 1
+//  #2: _MainTex (low 2d) 0x0 [-1] loc 2

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/z-LightShaftsCoord-outES3.txt

@@ -19,7 +19,7 @@ void main ()
   highp float tmpvar_5;
   highp float tmpvar_5;
   tmpvar_5 = clamp (sampleOnEpipolarLine_3, 0.0, 1.0);
   tmpvar_5 = clamp (sampleOnEpipolarLine_3, 0.0, 1.0);
   sampleOnEpipolarLine_3 = tmpvar_5;
   sampleOnEpipolarLine_3 = tmpvar_5;
-  int tmpvar_6;
+  highp int tmpvar_6;
   tmpvar_6 = int(clamp (floor(
   tmpvar_6 = int(clamp (floor(
     (tmpvar_4 * 4.0)
     (tmpvar_4 * 4.0)
   ), 0.0, 3.0));
   ), 0.0, 3.0));

+ 2 - 2
3rdparty/glsl-optimizer/tests/fragment/z-alphabumpspec-inES3.txt

@@ -60,12 +60,12 @@ mediump vec4 UnpackNormal( in mediump vec4 packednormal ) {
 }
 }
 void surf( in Input IN, inout SurfaceOutput o ) {
 void surf( in Input IN, inout SurfaceOutput o ) {
     vec4 tex;
     vec4 tex;
-    tex = texture2D( _MainTex, IN.uv_MainTex);
+    tex = texture( _MainTex, IN.uv_MainTex);
     o.Albedo = (tex.xyz  * _Color.xyz );
     o.Albedo = (tex.xyz  * _Color.xyz );
     o.Gloss = tex.w ;
     o.Gloss = tex.w ;
     o.Alpha = (tex.w  * _Color.w );
     o.Alpha = (tex.w  * _Color.w );
     o.Specular = _Shininess;
     o.Specular = _Shininess;
-    o.Normal = vec3( UnpackNormal( texture2D( _BumpMap, IN.uv_BumpMap)));
+    o.Normal = vec3( UnpackNormal( texture( _BumpMap, IN.uv_BumpMap)));
 }
 }
 vec4 LightingBlinnPhong( in SurfaceOutput s, in vec3 lightDir, in vec3 viewDir, in float atten ) {
 vec4 LightingBlinnPhong( in SurfaceOutput s, in vec3 lightDir, in vec3 viewDir, in float atten ) {
     vec3 h;
     vec3 h;

+ 3 - 1
3rdparty/glsl-optimizer/tests/fragment/z-alphabumpspec-outES3.txt

@@ -45,7 +45,9 @@ void main ()
   c_8.w = (tmpvar_3 + ((_LightColor0.w * _SpecColor.w) * spec_9));
   c_8.w = (tmpvar_3 + ((_LightColor0.w * _SpecColor.w) * spec_9));
   c_1.xyz = (c_8.xyz + (tmpvar_2 * _uv3));
   c_1.xyz = (c_8.xyz + (tmpvar_2 * _uv3));
   c_1.w = tmpvar_3;
   c_1.w = tmpvar_3;
-  _fragData = c_1;
+  lowp vec4 tmpvar_11;
+  tmpvar_11 = c_1;
+  _fragData = tmpvar_11;
 }
 }
 
 
 
 

+ 3 - 1
3rdparty/glsl-optimizer/tests/fragment/z-alphabumpspec-outES3Metal.txt

@@ -55,7 +55,9 @@ fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]]
   c_8.w = (tmpvar_3 + ((_mtl_u._LightColor0.w * _mtl_u._SpecColor.w) * spec_9));
   c_8.w = (tmpvar_3 + ((_mtl_u._LightColor0.w * _mtl_u._SpecColor.w) * spec_9));
   c_1.xyz = (c_8.xyz + (tmpvar_2 * _mtl_i._uv3));
   c_1.xyz = (c_8.xyz + (tmpvar_2 * _mtl_i._uv3));
   c_1.w = tmpvar_3;
   c_1.w = tmpvar_3;
-  _mtl_o._fragData = c_1;
+  half4 tmpvar_12;
+  tmpvar_12 = c_1;
+  _mtl_o._fragData = tmpvar_12;
   return _mtl_o;
   return _mtl_o;
 }
 }
 
 

+ 2 - 2
3rdparty/glsl-optimizer/tests/fragment/z-collectshadows-inES3.txt

@@ -38,7 +38,7 @@ mediump float unitySampleShadow( in highp vec4 eyePos ) {
     far = vec4( lessThan( vec4( z ), _LightSplitsFar) );
     far = vec4( lessThan( vec4( z ), _LightSplitsFar) );
     weights = (near * far);
     weights = (near * far);
     coord = vec4( ((((sc0 * weights.x ) + (sc1 * weights.y )) + (sc2 * weights.z )) + (sc3 * weights.w )), 1.00000);
     coord = vec4( ((((sc0 * weights.x ) + (sc1 * weights.y )) + (sc2 * weights.z )) + (sc3 * weights.w )), 1.00000);
-    shadow = ( (texture2D( _ShadowMapTexture, coord.xy ).x  < coord.z ) ) ? ( _LightShadowData.x  ) : ( 1.00000 );
+    shadow = ( (texture( _ShadowMapTexture, coord.xy ).x  < coord.z ) ) ? ( _LightShadowData.x  ) : ( 1.00000 );
     return shadow;
     return shadow;
 }
 }
 highp float Linear01Depth( in highp float z ) {
 highp float Linear01Depth( in highp float z ) {
@@ -58,7 +58,7 @@ mediump vec4 xlat_main( in v2f i ) {
     highp vec4 vpos;
     highp vec4 vpos;
     mediump float shadow;
     mediump float shadow;
     highp vec4 res;
     highp vec4 res;
-    depth = texture2D( _CameraDepthTexture, i.uv).x ;
+    depth = texture( _CameraDepthTexture, i.uv).x ;
     depth = Linear01Depth( depth);
     depth = Linear01Depth( depth);
     vpos = vec4( (i.ray * depth), 1.00000);
     vpos = vec4( (i.ray * depth), 1.00000);
     shadow = unitySampleShadow( vpos);
     shadow = unitySampleShadow( vpos);

+ 1 - 1
3rdparty/glsl-optimizer/tests/fragment/z-fxaa-preset3-inES3.txt

@@ -1,7 +1,7 @@
 #version 300 es
 #version 300 es
 out lowp vec4 _fragData;
 out lowp vec4 _fragData;
 vec4 xll_tex2Dlod(sampler2D s, vec4 coord) {
 vec4 xll_tex2Dlod(sampler2D s, vec4 coord) {
-   return texture2DLod( s, coord.xy, coord.w);
+   return textureLod( s, coord.xy, coord.w);
 }
 }
 uniform sampler2D _MainTex;
 uniform sampler2D _MainTex;
 uniform vec4 _MainTex_TexelSize;
 uniform vec4 _MainTex_TexelSize;

+ 14 - 14
3rdparty/glsl-optimizer/tests/fragment/z-fxaa-preset3-out.txt

@@ -42,16 +42,16 @@ void main ()
   vec4 tmpvar_24;
   vec4 tmpvar_24;
   tmpvar_24 = texture2DLod (_MainTex, tmpvar_23.xy, 0.0);
   tmpvar_24 = texture2DLod (_MainTex, tmpvar_23.xy, 0.0);
   float tmpvar_25;
   float tmpvar_25;
-  tmpvar_25 = ((tmpvar_17.y * 1.96321) + tmpvar_17.x);
+  tmpvar_25 = ((tmpvar_17.y * 1.963211) + tmpvar_17.x);
   lumaN_15 = tmpvar_25;
   lumaN_15 = tmpvar_25;
   float tmpvar_26;
   float tmpvar_26;
-  tmpvar_26 = ((tmpvar_19.y * 1.96321) + tmpvar_19.x);
+  tmpvar_26 = ((tmpvar_19.y * 1.963211) + tmpvar_19.x);
   float tmpvar_27;
   float tmpvar_27;
-  tmpvar_27 = ((tmpvar_20.y * 1.96321) + tmpvar_20.x);
+  tmpvar_27 = ((tmpvar_20.y * 1.963211) + tmpvar_20.x);
   float tmpvar_28;
   float tmpvar_28;
-  tmpvar_28 = ((tmpvar_22.y * 1.96321) + tmpvar_22.x);
+  tmpvar_28 = ((tmpvar_22.y * 1.963211) + tmpvar_22.x);
   float tmpvar_29;
   float tmpvar_29;
-  tmpvar_29 = ((tmpvar_24.y * 1.96321) + tmpvar_24.x);
+  tmpvar_29 = ((tmpvar_24.y * 1.963211) + tmpvar_24.x);
   lumaS_14 = tmpvar_29;
   lumaS_14 = tmpvar_29;
   float tmpvar_30;
   float tmpvar_30;
   tmpvar_30 = max (max (tmpvar_27, tmpvar_25), max (max (tmpvar_26, tmpvar_29), tmpvar_28));
   tmpvar_30 = max (max (tmpvar_27, tmpvar_25), max (max (tmpvar_26, tmpvar_29), tmpvar_28));
@@ -60,7 +60,7 @@ void main ()
     min (tmpvar_26, tmpvar_29)
     min (tmpvar_26, tmpvar_29)
   , tmpvar_28)));
   , tmpvar_28)));
   float tmpvar_32;
   float tmpvar_32;
-  tmpvar_32 = max (0.0416667, (tmpvar_30 * 0.125));
+  tmpvar_32 = max (0.04166667, (tmpvar_30 * 0.125));
   if ((tmpvar_31 < tmpvar_32)) {
   if ((tmpvar_31 < tmpvar_32)) {
     tmpvar_2 = tmpvar_20.xyz;
     tmpvar_2 = tmpvar_20.xyz;
   } else {
   } else {
@@ -69,7 +69,7 @@ void main ()
       ((abs((
       ((abs((
         (((tmpvar_25 + tmpvar_26) + (tmpvar_28 + tmpvar_29)) * 0.25)
         (((tmpvar_25 + tmpvar_26) + (tmpvar_28 + tmpvar_29)) * 0.25)
        - tmpvar_27)) / tmpvar_31) - 0.25)
        - tmpvar_27)) / tmpvar_31) - 0.25)
-    ) * 1.33333));
+    ) * 1.333333));
     vec4 tmpvar_34;
     vec4 tmpvar_34;
     tmpvar_34.zw = vec2(0.0, 0.0);
     tmpvar_34.zw = vec2(0.0, 0.0);
     tmpvar_34.xy = (xlv_TEXCOORD0 - _MainTex_TexelSize.xy);
     tmpvar_34.xy = (xlv_TEXCOORD0 - _MainTex_TexelSize.xy);
@@ -93,15 +93,15 @@ void main ()
     rgbL_13 = (((tmpvar_17.xyz + tmpvar_19.xyz) + (tmpvar_20.xyz + tmpvar_22.xyz)) + ((tmpvar_24.xyz + tmpvar_35.xyz) + (
     rgbL_13 = (((tmpvar_17.xyz + tmpvar_19.xyz) + (tmpvar_20.xyz + tmpvar_22.xyz)) + ((tmpvar_24.xyz + tmpvar_35.xyz) + (
       (tmpvar_37.xyz + tmpvar_39.xyz)
       (tmpvar_37.xyz + tmpvar_39.xyz)
      + tmpvar_41.xyz)));
      + tmpvar_41.xyz)));
-    rgbL_13 = (rgbL_13 * vec3(0.111111, 0.111111, 0.111111));
+    rgbL_13 = (rgbL_13 * vec3(0.1111111, 0.1111111, 0.1111111));
     float tmpvar_42;
     float tmpvar_42;
-    tmpvar_42 = ((tmpvar_35.y * 1.96321) + tmpvar_35.x);
+    tmpvar_42 = ((tmpvar_35.y * 1.963211) + tmpvar_35.x);
     float tmpvar_43;
     float tmpvar_43;
-    tmpvar_43 = ((tmpvar_37.y * 1.96321) + tmpvar_37.x);
+    tmpvar_43 = ((tmpvar_37.y * 1.963211) + tmpvar_37.x);
     float tmpvar_44;
     float tmpvar_44;
-    tmpvar_44 = ((tmpvar_39.y * 1.96321) + tmpvar_39.x);
+    tmpvar_44 = ((tmpvar_39.y * 1.963211) + tmpvar_39.x);
     float tmpvar_45;
     float tmpvar_45;
-    tmpvar_45 = ((tmpvar_41.y * 1.96321) + tmpvar_41.x);
+    tmpvar_45 = ((tmpvar_41.y * 1.963211) + tmpvar_41.x);
     bool tmpvar_46;
     bool tmpvar_46;
     tmpvar_46 = (((
     tmpvar_46 = (((
       abs((((0.25 * tmpvar_42) + (-0.5 * tmpvar_26)) + (0.25 * tmpvar_44)))
       abs((((0.25 * tmpvar_42) + (-0.5 * tmpvar_26)) + (0.25 * tmpvar_44)))
@@ -186,12 +186,12 @@ void main ()
       if (!(doneN_5)) {
       if (!(doneN_5)) {
         vec4 tmpvar_56;
         vec4 tmpvar_56;
         tmpvar_56 = texture2DLod (_MainTex, posN_10, 0.0);
         tmpvar_56 = texture2DLod (_MainTex, posN_10, 0.0);
-        lumaEndN_7 = ((tmpvar_56.y * 1.96321) + tmpvar_56.x);
+        lumaEndN_7 = ((tmpvar_56.y * 1.963211) + tmpvar_56.x);
       };
       };
       if (!(doneP_4)) {
       if (!(doneP_4)) {
         vec4 tmpvar_57;
         vec4 tmpvar_57;
         tmpvar_57 = texture2DLod (_MainTex, posP_9, 0.0);
         tmpvar_57 = texture2DLod (_MainTex, posP_9, 0.0);
-        lumaEndP_6 = ((tmpvar_57.y * 1.96321) + tmpvar_57.x);
+        lumaEndP_6 = ((tmpvar_57.y * 1.963211) + tmpvar_57.x);
       };
       };
       bool tmpvar_58;
       bool tmpvar_58;
       if (doneN_5) {
       if (doneN_5) {

+ 15 - 15
3rdparty/glsl-optimizer/tests/fragment/z-fxaa-preset3-outES3.txt

@@ -43,16 +43,16 @@ void main ()
   lowp vec4 tmpvar_24;
   lowp vec4 tmpvar_24;
   tmpvar_24 = textureLod (_MainTex, tmpvar_23.xy, 0.0);
   tmpvar_24 = textureLod (_MainTex, tmpvar_23.xy, 0.0);
   lowp float tmpvar_25;
   lowp float tmpvar_25;
-  tmpvar_25 = ((tmpvar_17.y * 1.96321) + tmpvar_17.x);
+  tmpvar_25 = ((tmpvar_17.y * 1.963211) + tmpvar_17.x);
   lumaN_15 = tmpvar_25;
   lumaN_15 = tmpvar_25;
   lowp float tmpvar_26;
   lowp float tmpvar_26;
-  tmpvar_26 = ((tmpvar_19.y * 1.96321) + tmpvar_19.x);
+  tmpvar_26 = ((tmpvar_19.y * 1.963211) + tmpvar_19.x);
   lowp float tmpvar_27;
   lowp float tmpvar_27;
-  tmpvar_27 = ((tmpvar_20.y * 1.96321) + tmpvar_20.x);
+  tmpvar_27 = ((tmpvar_20.y * 1.963211) + tmpvar_20.x);
   lowp float tmpvar_28;
   lowp float tmpvar_28;
-  tmpvar_28 = ((tmpvar_22.y * 1.96321) + tmpvar_22.x);
+  tmpvar_28 = ((tmpvar_22.y * 1.963211) + tmpvar_22.x);
   lowp float tmpvar_29;
   lowp float tmpvar_29;
-  tmpvar_29 = ((tmpvar_24.y * 1.96321) + tmpvar_24.x);
+  tmpvar_29 = ((tmpvar_24.y * 1.963211) + tmpvar_24.x);
   lumaS_14 = tmpvar_29;
   lumaS_14 = tmpvar_29;
   lowp float tmpvar_30;
   lowp float tmpvar_30;
   tmpvar_30 = max (max (tmpvar_27, tmpvar_25), max (max (tmpvar_26, tmpvar_29), tmpvar_28));
   tmpvar_30 = max (max (tmpvar_27, tmpvar_25), max (max (tmpvar_26, tmpvar_29), tmpvar_28));
@@ -61,7 +61,7 @@ void main ()
     min (tmpvar_26, tmpvar_29)
     min (tmpvar_26, tmpvar_29)
   , tmpvar_28)));
   , tmpvar_28)));
   lowp float tmpvar_32;
   lowp float tmpvar_32;
-  tmpvar_32 = max (0.0416667, (tmpvar_30 * 0.125));
+  tmpvar_32 = max (0.04166667, (tmpvar_30 * 0.125));
   if ((tmpvar_31 < tmpvar_32)) {
   if ((tmpvar_31 < tmpvar_32)) {
     tmpvar_2 = tmpvar_20.xyz;
     tmpvar_2 = tmpvar_20.xyz;
   } else {
   } else {
@@ -70,7 +70,7 @@ void main ()
       ((abs((
       ((abs((
         (((tmpvar_25 + tmpvar_26) + (tmpvar_28 + tmpvar_29)) * 0.25)
         (((tmpvar_25 + tmpvar_26) + (tmpvar_28 + tmpvar_29)) * 0.25)
        - tmpvar_27)) / tmpvar_31) - 0.25)
        - tmpvar_27)) / tmpvar_31) - 0.25)
-    ) * 1.33333));
+    ) * 1.333333));
     highp vec4 tmpvar_34;
     highp vec4 tmpvar_34;
     tmpvar_34.zw = vec2(0.0, 0.0);
     tmpvar_34.zw = vec2(0.0, 0.0);
     tmpvar_34.xy = (xlv_TEXCOORD0 - _MainTex_TexelSize.xy);
     tmpvar_34.xy = (xlv_TEXCOORD0 - _MainTex_TexelSize.xy);
@@ -94,15 +94,15 @@ void main ()
     rgbL_13 = (((tmpvar_17.xyz + tmpvar_19.xyz) + (tmpvar_20.xyz + tmpvar_22.xyz)) + ((tmpvar_24.xyz + tmpvar_35.xyz) + (
     rgbL_13 = (((tmpvar_17.xyz + tmpvar_19.xyz) + (tmpvar_20.xyz + tmpvar_22.xyz)) + ((tmpvar_24.xyz + tmpvar_35.xyz) + (
       (tmpvar_37.xyz + tmpvar_39.xyz)
       (tmpvar_37.xyz + tmpvar_39.xyz)
      + tmpvar_41.xyz)));
      + tmpvar_41.xyz)));
-    rgbL_13 = (rgbL_13 * vec3(0.111111, 0.111111, 0.111111));
+    rgbL_13 = (rgbL_13 * vec3(0.1111111, 0.1111111, 0.1111111));
     lowp float tmpvar_42;
     lowp float tmpvar_42;
-    tmpvar_42 = ((tmpvar_35.y * 1.96321) + tmpvar_35.x);
+    tmpvar_42 = ((tmpvar_35.y * 1.963211) + tmpvar_35.x);
     lowp float tmpvar_43;
     lowp float tmpvar_43;
-    tmpvar_43 = ((tmpvar_37.y * 1.96321) + tmpvar_37.x);
+    tmpvar_43 = ((tmpvar_37.y * 1.963211) + tmpvar_37.x);
     lowp float tmpvar_44;
     lowp float tmpvar_44;
-    tmpvar_44 = ((tmpvar_39.y * 1.96321) + tmpvar_39.x);
+    tmpvar_44 = ((tmpvar_39.y * 1.963211) + tmpvar_39.x);
     lowp float tmpvar_45;
     lowp float tmpvar_45;
-    tmpvar_45 = ((tmpvar_41.y * 1.96321) + tmpvar_41.x);
+    tmpvar_45 = ((tmpvar_41.y * 1.963211) + tmpvar_41.x);
     bool tmpvar_46;
     bool tmpvar_46;
     tmpvar_46 = (((
     tmpvar_46 = (((
       abs((((0.25 * tmpvar_42) + (-0.5 * tmpvar_26)) + (0.25 * tmpvar_44)))
       abs((((0.25 * tmpvar_42) + (-0.5 * tmpvar_26)) + (0.25 * tmpvar_44)))
@@ -183,16 +183,16 @@ void main ()
     doneP_4 = bool(0);
     doneP_4 = bool(0);
     posN_10 = (posN_10 - tmpvar_53);
     posN_10 = (posN_10 - tmpvar_53);
     posP_9 = (posP_9 + tmpvar_53);
     posP_9 = (posP_9 + tmpvar_53);
-    for (int i_3 = 0; i_3 < 16; i_3++) {
+    for (highp int i_3 = 0; i_3 < 16; i_3++) {
       if (!(doneN_5)) {
       if (!(doneN_5)) {
         lowp vec4 tmpvar_56;
         lowp vec4 tmpvar_56;
         tmpvar_56 = textureLod (_MainTex, posN_10, 0.0);
         tmpvar_56 = textureLod (_MainTex, posN_10, 0.0);
-        lumaEndN_7 = ((tmpvar_56.y * 1.96321) + tmpvar_56.x);
+        lumaEndN_7 = ((tmpvar_56.y * 1.963211) + tmpvar_56.x);
       };
       };
       if (!(doneP_4)) {
       if (!(doneP_4)) {
         lowp vec4 tmpvar_57;
         lowp vec4 tmpvar_57;
         tmpvar_57 = textureLod (_MainTex, posP_9, 0.0);
         tmpvar_57 = textureLod (_MainTex, posP_9, 0.0);
-        lumaEndP_6 = ((tmpvar_57.y * 1.96321) + tmpvar_57.x);
+        lumaEndP_6 = ((tmpvar_57.y * 1.963211) + tmpvar_57.x);
       };
       };
       bool tmpvar_58;
       bool tmpvar_58;
       if (doneN_5) {
       if (doneN_5) {

+ 14 - 14
3rdparty/glsl-optimizer/tests/fragment/z-fxaa-preset3-outES3Metal.txt

@@ -51,16 +51,16 @@ fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]]
   half4 tmpvar_24;
   half4 tmpvar_24;
   tmpvar_24 = _MainTex.sample(_mtlsmp__MainTex, (float2)(tmpvar_23.xy), level(0.0));
   tmpvar_24 = _MainTex.sample(_mtlsmp__MainTex, (float2)(tmpvar_23.xy), level(0.0));
   half tmpvar_25;
   half tmpvar_25;
-  tmpvar_25 = ((tmpvar_17.y * (half)1.96321) + tmpvar_17.x);
+  tmpvar_25 = ((tmpvar_17.y * (half)1.963211) + tmpvar_17.x);
   lumaN_15 = tmpvar_25;
   lumaN_15 = tmpvar_25;
   half tmpvar_26;
   half tmpvar_26;
-  tmpvar_26 = ((tmpvar_19.y * (half)1.96321) + tmpvar_19.x);
+  tmpvar_26 = ((tmpvar_19.y * (half)1.963211) + tmpvar_19.x);
   half tmpvar_27;
   half tmpvar_27;
-  tmpvar_27 = ((tmpvar_20.y * (half)1.96321) + tmpvar_20.x);
+  tmpvar_27 = ((tmpvar_20.y * (half)1.963211) + tmpvar_20.x);
   half tmpvar_28;
   half tmpvar_28;
-  tmpvar_28 = ((tmpvar_22.y * (half)1.96321) + tmpvar_22.x);
+  tmpvar_28 = ((tmpvar_22.y * (half)1.963211) + tmpvar_22.x);
   half tmpvar_29;
   half tmpvar_29;
-  tmpvar_29 = ((tmpvar_24.y * (half)1.96321) + tmpvar_24.x);
+  tmpvar_29 = ((tmpvar_24.y * (half)1.963211) + tmpvar_24.x);
   lumaS_14 = tmpvar_29;
   lumaS_14 = tmpvar_29;
   half tmpvar_30;
   half tmpvar_30;
   tmpvar_30 = max (max (tmpvar_27, tmpvar_25), max (max (tmpvar_26, tmpvar_29), tmpvar_28));
   tmpvar_30 = max (max (tmpvar_27, tmpvar_25), max (max (tmpvar_26, tmpvar_29), tmpvar_28));
@@ -69,7 +69,7 @@ fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]]
     min (tmpvar_26, tmpvar_29)
     min (tmpvar_26, tmpvar_29)
   , tmpvar_28)));
   , tmpvar_28)));
   half tmpvar_32;
   half tmpvar_32;
-  tmpvar_32 = max ((half)0.0416667, (tmpvar_30 * (half)0.125));
+  tmpvar_32 = max ((half)0.04166667, (tmpvar_30 * (half)0.125));
   if ((tmpvar_31 < tmpvar_32)) {
   if ((tmpvar_31 < tmpvar_32)) {
     tmpvar_2 = tmpvar_20.xyz;
     tmpvar_2 = tmpvar_20.xyz;
   } else {
   } else {
@@ -78,7 +78,7 @@ fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]]
       ((abs((
       ((abs((
         (((tmpvar_25 + tmpvar_26) + (tmpvar_28 + tmpvar_29)) * (half)0.25)
         (((tmpvar_25 + tmpvar_26) + (tmpvar_28 + tmpvar_29)) * (half)0.25)
        - tmpvar_27)) / tmpvar_31) - (half)0.25)
        - tmpvar_27)) / tmpvar_31) - (half)0.25)
-    ) * (half)1.33333));
+    ) * (half)1.333333));
     float4 tmpvar_34;
     float4 tmpvar_34;
     tmpvar_34.zw = float2(0.0, 0.0);
     tmpvar_34.zw = float2(0.0, 0.0);
     tmpvar_34.xy = (_mtl_i.xlv_TEXCOORD0 - _mtl_u._MainTex_TexelSize.xy);
     tmpvar_34.xy = (_mtl_i.xlv_TEXCOORD0 - _mtl_u._MainTex_TexelSize.xy);
@@ -102,15 +102,15 @@ fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]]
     rgbL_13 = (((tmpvar_17.xyz + tmpvar_19.xyz) + (tmpvar_20.xyz + tmpvar_22.xyz)) + ((tmpvar_24.xyz + tmpvar_35.xyz) + (
     rgbL_13 = (((tmpvar_17.xyz + tmpvar_19.xyz) + (tmpvar_20.xyz + tmpvar_22.xyz)) + ((tmpvar_24.xyz + tmpvar_35.xyz) + (
       (tmpvar_37.xyz + tmpvar_39.xyz)
       (tmpvar_37.xyz + tmpvar_39.xyz)
      + tmpvar_41.xyz)));
      + tmpvar_41.xyz)));
-    rgbL_13 = (rgbL_13 * (half3)float3(0.111111, 0.111111, 0.111111));
+    rgbL_13 = (rgbL_13 * (half3)float3(0.1111111, 0.1111111, 0.1111111));
     half tmpvar_42;
     half tmpvar_42;
-    tmpvar_42 = ((tmpvar_35.y * (half)1.96321) + tmpvar_35.x);
+    tmpvar_42 = ((tmpvar_35.y * (half)1.963211) + tmpvar_35.x);
     half tmpvar_43;
     half tmpvar_43;
-    tmpvar_43 = ((tmpvar_37.y * (half)1.96321) + tmpvar_37.x);
+    tmpvar_43 = ((tmpvar_37.y * (half)1.963211) + tmpvar_37.x);
     half tmpvar_44;
     half tmpvar_44;
-    tmpvar_44 = ((tmpvar_39.y * (half)1.96321) + tmpvar_39.x);
+    tmpvar_44 = ((tmpvar_39.y * (half)1.963211) + tmpvar_39.x);
     half tmpvar_45;
     half tmpvar_45;
-    tmpvar_45 = ((tmpvar_41.y * (half)1.96321) + tmpvar_41.x);
+    tmpvar_45 = ((tmpvar_41.y * (half)1.963211) + tmpvar_41.x);
     bool tmpvar_46;
     bool tmpvar_46;
     tmpvar_46 = (((
     tmpvar_46 = (((
       abs(((((half)0.25 * tmpvar_42) + ((half)-0.5 * tmpvar_26)) + ((half)0.25 * tmpvar_44)))
       abs(((((half)0.25 * tmpvar_42) + ((half)-0.5 * tmpvar_26)) + ((half)0.25 * tmpvar_44)))
@@ -195,12 +195,12 @@ fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]]
       if (!(doneN_5)) {
       if (!(doneN_5)) {
         half4 tmpvar_56;
         half4 tmpvar_56;
         tmpvar_56 = _MainTex.sample(_mtlsmp__MainTex, (float2)(posN_10), level(0.0));
         tmpvar_56 = _MainTex.sample(_mtlsmp__MainTex, (float2)(posN_10), level(0.0));
-        lumaEndN_7 = ((tmpvar_56.y * (half)1.96321) + tmpvar_56.x);
+        lumaEndN_7 = ((tmpvar_56.y * (half)1.963211) + tmpvar_56.x);
       };
       };
       if (!(doneP_4)) {
       if (!(doneP_4)) {
         half4 tmpvar_57;
         half4 tmpvar_57;
         tmpvar_57 = _MainTex.sample(_mtlsmp__MainTex, (float2)(posP_9), level(0.0));
         tmpvar_57 = _MainTex.sample(_mtlsmp__MainTex, (float2)(posP_9), level(0.0));
-        lumaEndP_6 = ((tmpvar_57.y * (half)1.96321) + tmpvar_57.x);
+        lumaEndP_6 = ((tmpvar_57.y * (half)1.963211) + tmpvar_57.x);
       };
       };
       bool tmpvar_58;
       bool tmpvar_58;
       if (doneN_5) {
       if (doneN_5) {

+ 16 - 7
3rdparty/glsl-optimizer/tests/fragment/z-fxaa3-11-consolepc-outES.txt

@@ -1,4 +1,13 @@
 #extension GL_EXT_shader_texture_lod : enable
 #extension GL_EXT_shader_texture_lod : enable
+lowp vec4 impl_low_texture2DLodEXT(lowp sampler2D sampler, highp vec2 coord, mediump float lod)
+{
+#if defined(GL_EXT_shader_texture_lod)
+	return texture2DLodEXT(sampler, coord, lod);
+#else
+	return texture2D(sampler, coord, lod);
+#endif
+}
+
 uniform sampler2D _MainTex;
 uniform sampler2D _MainTex;
 uniform highp vec4 _MainTex_TexelSize;
 uniform highp vec4 _MainTex_TexelSize;
 varying highp vec2 xlv_TEXCOORD0;
 varying highp vec2 xlv_TEXCOORD0;
@@ -19,23 +28,23 @@ void main ()
   highp float lumaM_10;
   highp float lumaM_10;
   highp float lumaNe_11;
   highp float lumaNe_11;
   lowp vec4 tmpvar_12;
   lowp vec4 tmpvar_12;
-  tmpvar_12 = texture2DLodEXT (_MainTex, xlv_TEXCOORD1.xy, 0.0);
+  tmpvar_12 = impl_low_texture2DLodEXT (_MainTex, xlv_TEXCOORD1.xy, 0.0);
   highp float tmpvar_13;
   highp float tmpvar_13;
   tmpvar_13 = tmpvar_12.y;
   tmpvar_13 = tmpvar_12.y;
   lowp vec4 tmpvar_14;
   lowp vec4 tmpvar_14;
-  tmpvar_14 = texture2DLodEXT (_MainTex, xlv_TEXCOORD1.xw, 0.0);
+  tmpvar_14 = impl_low_texture2DLodEXT (_MainTex, xlv_TEXCOORD1.xw, 0.0);
   highp float tmpvar_15;
   highp float tmpvar_15;
   tmpvar_15 = tmpvar_14.y;
   tmpvar_15 = tmpvar_14.y;
   lowp vec4 tmpvar_16;
   lowp vec4 tmpvar_16;
-  tmpvar_16 = texture2DLodEXT (_MainTex, xlv_TEXCOORD1.zy, 0.0);
+  tmpvar_16 = impl_low_texture2DLodEXT (_MainTex, xlv_TEXCOORD1.zy, 0.0);
   highp float tmpvar_17;
   highp float tmpvar_17;
   tmpvar_17 = tmpvar_16.y;
   tmpvar_17 = tmpvar_16.y;
   lowp vec4 tmpvar_18;
   lowp vec4 tmpvar_18;
-  tmpvar_18 = texture2DLodEXT (_MainTex, xlv_TEXCOORD1.zw, 0.0);
+  tmpvar_18 = impl_low_texture2DLodEXT (_MainTex, xlv_TEXCOORD1.zw, 0.0);
   highp float tmpvar_19;
   highp float tmpvar_19;
   tmpvar_19 = tmpvar_18.y;
   tmpvar_19 = tmpvar_18.y;
   lowp vec4 tmpvar_20;
   lowp vec4 tmpvar_20;
-  tmpvar_20 = texture2DLodEXT (_MainTex, xlv_TEXCOORD0, 0.0);
+  tmpvar_20 = impl_low_texture2DLodEXT (_MainTex, xlv_TEXCOORD0, 0.0);
   lumaM_10 = tmpvar_20.y;
   lumaM_10 = tmpvar_20.y;
   lumaNe_11 = (tmpvar_17 + 0.00260417);
   lumaNe_11 = (tmpvar_17 + 0.00260417);
   highp float tmpvar_21;
   highp float tmpvar_21;
@@ -70,8 +79,8 @@ void main ()
     highp vec4 tmpvar_29;
     highp vec4 tmpvar_29;
     tmpvar_29.zw = vec2(0.0, 0.0);
     tmpvar_29.zw = vec2(0.0, 0.0);
     tmpvar_29.xy = (xlv_TEXCOORD0 + (tmpvar_27 * fxaaConsoleRcpFrameOpt2_2.zw));
     tmpvar_29.xy = (xlv_TEXCOORD0 + (tmpvar_27 * fxaaConsoleRcpFrameOpt2_2.zw));
-    rgbyA_5 = (texture2DLodEXT (_MainTex, tmpvar_25.xy, 0.0) + texture2DLodEXT (_MainTex, tmpvar_26.xy, 0.0));
-    rgbyB_4 = (((texture2DLodEXT (_MainTex, tmpvar_28.xy, 0.0) + texture2DLodEXT (_MainTex, tmpvar_29.xy, 0.0)) * 0.25) + (rgbyA_5 * 0.25));
+    rgbyA_5 = (impl_low_texture2DLodEXT (_MainTex, tmpvar_25.xy, 0.0) + impl_low_texture2DLodEXT (_MainTex, tmpvar_26.xy, 0.0));
+    rgbyB_4 = (((impl_low_texture2DLodEXT (_MainTex, tmpvar_28.xy, 0.0) + impl_low_texture2DLodEXT (_MainTex, tmpvar_29.xy, 0.0)) * 0.25) + (rgbyA_5 * 0.25));
     if (((rgbyB_4.y < tmpvar_22) || (rgbyB_4.y > tmpvar_21))) {
     if (((rgbyB_4.y < tmpvar_22) || (rgbyB_4.y > tmpvar_21))) {
       rgbyB_4.xyz = (rgbyA_5.xyz * 0.5);
       rgbyB_4.xyz = (rgbyA_5.xyz * 0.5);
     };
     };

+ 41 - 32
3rdparty/glsl-optimizer/tests/fragment/z-fxaa3-11-pc39-outES.txt

@@ -1,4 +1,13 @@
 #extension GL_EXT_shader_texture_lod : enable
 #extension GL_EXT_shader_texture_lod : enable
+lowp vec4 impl_low_texture2DLodEXT(lowp sampler2D sampler, highp vec2 coord, mediump float lod)
+{
+#if defined(GL_EXT_shader_texture_lod)
+	return texture2DLodEXT(sampler, coord, lod);
+#else
+	return texture2D(sampler, coord, lod);
+#endif
+}
+
 uniform sampler2D _MainTex;
 uniform sampler2D _MainTex;
 uniform highp vec4 _MainTex_TexelSize;
 uniform highp vec4 _MainTex_TexelSize;
 varying highp vec2 xlv_TEXCOORD0;
 varying highp vec2 xlv_TEXCOORD0;
@@ -48,13 +57,13 @@ void main ()
   highp vec2 posM_41;
   highp vec2 posM_41;
   posM_41 = xlv_TEXCOORD0;
   posM_41 = xlv_TEXCOORD0;
   lowp vec4 tmpvar_42;
   lowp vec4 tmpvar_42;
-  tmpvar_42 = texture2DLodEXT (_MainTex, xlv_TEXCOORD0, 0.0);
+  tmpvar_42 = impl_low_texture2DLodEXT (_MainTex, xlv_TEXCOORD0, 0.0);
   rgbyM_40 = tmpvar_42;
   rgbyM_40 = tmpvar_42;
   highp vec4 tmpvar_43;
   highp vec4 tmpvar_43;
   tmpvar_43.zw = vec2(0.0, 0.0);
   tmpvar_43.zw = vec2(0.0, 0.0);
   tmpvar_43.xy = (xlv_TEXCOORD0 + (vec2(0.0, 1.0) * _MainTex_TexelSize.xy));
   tmpvar_43.xy = (xlv_TEXCOORD0 + (vec2(0.0, 1.0) * _MainTex_TexelSize.xy));
   lowp vec4 tmpvar_44;
   lowp vec4 tmpvar_44;
-  tmpvar_44 = texture2DLodEXT (_MainTex, tmpvar_43.xy, 0.0);
+  tmpvar_44 = impl_low_texture2DLodEXT (_MainTex, tmpvar_43.xy, 0.0);
   highp vec4 rgba_45;
   highp vec4 rgba_45;
   rgba_45 = tmpvar_44;
   rgba_45 = tmpvar_44;
   lumaS_39 = rgba_45.w;
   lumaS_39 = rgba_45.w;
@@ -62,7 +71,7 @@ void main ()
   tmpvar_46.zw = vec2(0.0, 0.0);
   tmpvar_46.zw = vec2(0.0, 0.0);
   tmpvar_46.xy = (xlv_TEXCOORD0 + (vec2(1.0, 0.0) * _MainTex_TexelSize.xy));
   tmpvar_46.xy = (xlv_TEXCOORD0 + (vec2(1.0, 0.0) * _MainTex_TexelSize.xy));
   lowp vec4 tmpvar_47;
   lowp vec4 tmpvar_47;
-  tmpvar_47 = texture2DLodEXT (_MainTex, tmpvar_46.xy, 0.0);
+  tmpvar_47 = impl_low_texture2DLodEXT (_MainTex, tmpvar_46.xy, 0.0);
   highp float tmpvar_48;
   highp float tmpvar_48;
   highp vec4 rgba_49;
   highp vec4 rgba_49;
   rgba_49 = tmpvar_47;
   rgba_49 = tmpvar_47;
@@ -71,7 +80,7 @@ void main ()
   tmpvar_50.zw = vec2(0.0, 0.0);
   tmpvar_50.zw = vec2(0.0, 0.0);
   tmpvar_50.xy = (xlv_TEXCOORD0 + (vec2(0.0, -1.0) * _MainTex_TexelSize.xy));
   tmpvar_50.xy = (xlv_TEXCOORD0 + (vec2(0.0, -1.0) * _MainTex_TexelSize.xy));
   lowp vec4 tmpvar_51;
   lowp vec4 tmpvar_51;
-  tmpvar_51 = texture2DLodEXT (_MainTex, tmpvar_50.xy, 0.0);
+  tmpvar_51 = impl_low_texture2DLodEXT (_MainTex, tmpvar_50.xy, 0.0);
   highp vec4 rgba_52;
   highp vec4 rgba_52;
   rgba_52 = tmpvar_51;
   rgba_52 = tmpvar_51;
   lumaN_38 = rgba_52.w;
   lumaN_38 = rgba_52.w;
@@ -79,7 +88,7 @@ void main ()
   tmpvar_53.zw = vec2(0.0, 0.0);
   tmpvar_53.zw = vec2(0.0, 0.0);
   tmpvar_53.xy = (xlv_TEXCOORD0 + (vec2(-1.0, 0.0) * _MainTex_TexelSize.xy));
   tmpvar_53.xy = (xlv_TEXCOORD0 + (vec2(-1.0, 0.0) * _MainTex_TexelSize.xy));
   lowp vec4 tmpvar_54;
   lowp vec4 tmpvar_54;
-  tmpvar_54 = texture2DLodEXT (_MainTex, tmpvar_53.xy, 0.0);
+  tmpvar_54 = impl_low_texture2DLodEXT (_MainTex, tmpvar_53.xy, 0.0);
   highp float tmpvar_55;
   highp float tmpvar_55;
   highp vec4 rgba_56;
   highp vec4 rgba_56;
   rgba_56 = tmpvar_54;
   rgba_56 = tmpvar_54;
@@ -96,28 +105,28 @@ void main ()
     tmpvar_58.zw = vec2(0.0, 0.0);
     tmpvar_58.zw = vec2(0.0, 0.0);
     tmpvar_58.xy = (xlv_TEXCOORD0 - _MainTex_TexelSize.xy);
     tmpvar_58.xy = (xlv_TEXCOORD0 - _MainTex_TexelSize.xy);
     lowp vec4 tmpvar_59;
     lowp vec4 tmpvar_59;
-    tmpvar_59 = texture2DLodEXT (_MainTex, tmpvar_58.xy, 0.0);
+    tmpvar_59 = impl_low_texture2DLodEXT (_MainTex, tmpvar_58.xy, 0.0);
     highp vec4 rgba_60;
     highp vec4 rgba_60;
     rgba_60 = tmpvar_59;
     rgba_60 = tmpvar_59;
     highp vec4 tmpvar_61;
     highp vec4 tmpvar_61;
     tmpvar_61.zw = vec2(0.0, 0.0);
     tmpvar_61.zw = vec2(0.0, 0.0);
     tmpvar_61.xy = (xlv_TEXCOORD0 + _MainTex_TexelSize.xy);
     tmpvar_61.xy = (xlv_TEXCOORD0 + _MainTex_TexelSize.xy);
     lowp vec4 tmpvar_62;
     lowp vec4 tmpvar_62;
-    tmpvar_62 = texture2DLodEXT (_MainTex, tmpvar_61.xy, 0.0);
+    tmpvar_62 = impl_low_texture2DLodEXT (_MainTex, tmpvar_61.xy, 0.0);
     highp vec4 rgba_63;
     highp vec4 rgba_63;
     rgba_63 = tmpvar_62;
     rgba_63 = tmpvar_62;
     highp vec4 tmpvar_64;
     highp vec4 tmpvar_64;
     tmpvar_64.zw = vec2(0.0, 0.0);
     tmpvar_64.zw = vec2(0.0, 0.0);
     tmpvar_64.xy = (xlv_TEXCOORD0 + (vec2(1.0, -1.0) * _MainTex_TexelSize.xy));
     tmpvar_64.xy = (xlv_TEXCOORD0 + (vec2(1.0, -1.0) * _MainTex_TexelSize.xy));
     lowp vec4 tmpvar_65;
     lowp vec4 tmpvar_65;
-    tmpvar_65 = texture2DLodEXT (_MainTex, tmpvar_64.xy, 0.0);
+    tmpvar_65 = impl_low_texture2DLodEXT (_MainTex, tmpvar_64.xy, 0.0);
     highp vec4 rgba_66;
     highp vec4 rgba_66;
     rgba_66 = tmpvar_65;
     rgba_66 = tmpvar_65;
     highp vec4 tmpvar_67;
     highp vec4 tmpvar_67;
     tmpvar_67.zw = vec2(0.0, 0.0);
     tmpvar_67.zw = vec2(0.0, 0.0);
     tmpvar_67.xy = (xlv_TEXCOORD0 + (vec2(-1.0, 1.0) * _MainTex_TexelSize.xy));
     tmpvar_67.xy = (xlv_TEXCOORD0 + (vec2(-1.0, 1.0) * _MainTex_TexelSize.xy));
     lowp vec4 tmpvar_68;
     lowp vec4 tmpvar_68;
-    tmpvar_68 = texture2DLodEXT (_MainTex, tmpvar_67.xy, 0.0);
+    tmpvar_68 = impl_low_texture2DLodEXT (_MainTex, tmpvar_67.xy, 0.0);
     highp vec4 rgba_69;
     highp vec4 rgba_69;
     rgba_69 = tmpvar_68;
     rgba_69 = tmpvar_68;
     lumaNS_36 = (rgba_52.w + rgba_45.w);
     lumaNS_36 = (rgba_52.w + rgba_45.w);
@@ -187,13 +196,13 @@ void main ()
     posP_20.y = (posB_22.y + tmpvar_73);
     posP_20.y = (posB_22.y + tmpvar_73);
     subpixD_19 = ((-2.0 * tmpvar_71) + 3.0);
     subpixD_19 = ((-2.0 * tmpvar_71) + 3.0);
     lowp vec4 tmpvar_74;
     lowp vec4 tmpvar_74;
-    tmpvar_74 = texture2DLodEXT (_MainTex, posN_21, 0.0);
+    tmpvar_74 = impl_low_texture2DLodEXT (_MainTex, posN_21, 0.0);
     highp vec4 rgba_75;
     highp vec4 rgba_75;
     rgba_75 = tmpvar_74;
     rgba_75 = tmpvar_74;
     lumaEndN_18 = rgba_75.w;
     lumaEndN_18 = rgba_75.w;
     subpixE_17 = (tmpvar_71 * tmpvar_71);
     subpixE_17 = (tmpvar_71 * tmpvar_71);
     lowp vec4 tmpvar_76;
     lowp vec4 tmpvar_76;
-    tmpvar_76 = texture2DLodEXT (_MainTex, posP_20, 0.0);
+    tmpvar_76 = impl_low_texture2DLodEXT (_MainTex, posP_20, 0.0);
     highp vec4 rgba_77;
     highp vec4 rgba_77;
     rgba_77 = tmpvar_76;
     rgba_77 = tmpvar_76;
     lumaEndP_16 = rgba_77.w;
     lumaEndP_16 = rgba_77.w;
@@ -223,14 +232,14 @@ void main ()
     if (doneNP_10) {
     if (doneNP_10) {
       if (!(doneN_12)) {
       if (!(doneN_12)) {
         lowp vec4 tmpvar_78;
         lowp vec4 tmpvar_78;
-        tmpvar_78 = texture2DLodEXT (_MainTex, posN_21, 0.0);
+        tmpvar_78 = impl_low_texture2DLodEXT (_MainTex, posN_21, 0.0);
         highp vec4 rgba_79;
         highp vec4 rgba_79;
         rgba_79 = tmpvar_78;
         rgba_79 = tmpvar_78;
         lumaEndN_18 = rgba_79.w;
         lumaEndN_18 = rgba_79.w;
       };
       };
       if (!(doneP_11)) {
       if (!(doneP_11)) {
         lowp vec4 tmpvar_80;
         lowp vec4 tmpvar_80;
-        tmpvar_80 = texture2DLodEXT (_MainTex, posP_20, 0.0);
+        tmpvar_80 = impl_low_texture2DLodEXT (_MainTex, posP_20, 0.0);
         highp vec4 rgba_81;
         highp vec4 rgba_81;
         rgba_81 = tmpvar_80;
         rgba_81 = tmpvar_80;
         lumaEndP_16 = rgba_81.w;
         lumaEndP_16 = rgba_81.w;
@@ -259,14 +268,14 @@ void main ()
       if (doneNP_10) {
       if (doneNP_10) {
         if (!(doneN_12)) {
         if (!(doneN_12)) {
           lowp vec4 tmpvar_82;
           lowp vec4 tmpvar_82;
-          tmpvar_82 = texture2DLodEXT (_MainTex, posN_21, 0.0);
+          tmpvar_82 = impl_low_texture2DLodEXT (_MainTex, posN_21, 0.0);
           highp vec4 rgba_83;
           highp vec4 rgba_83;
           rgba_83 = tmpvar_82;
           rgba_83 = tmpvar_82;
           lumaEndN_18 = rgba_83.w;
           lumaEndN_18 = rgba_83.w;
         };
         };
         if (!(doneP_11)) {
         if (!(doneP_11)) {
           lowp vec4 tmpvar_84;
           lowp vec4 tmpvar_84;
-          tmpvar_84 = texture2DLodEXT (_MainTex, posP_20, 0.0);
+          tmpvar_84 = impl_low_texture2DLodEXT (_MainTex, posP_20, 0.0);
           highp vec4 rgba_85;
           highp vec4 rgba_85;
           rgba_85 = tmpvar_84;
           rgba_85 = tmpvar_84;
           lumaEndP_16 = rgba_85.w;
           lumaEndP_16 = rgba_85.w;
@@ -295,14 +304,14 @@ void main ()
         if (doneNP_10) {
         if (doneNP_10) {
           if (!(doneN_12)) {
           if (!(doneN_12)) {
             lowp vec4 tmpvar_86;
             lowp vec4 tmpvar_86;
-            tmpvar_86 = texture2DLodEXT (_MainTex, posN_21, 0.0);
+            tmpvar_86 = impl_low_texture2DLodEXT (_MainTex, posN_21, 0.0);
             highp vec4 rgba_87;
             highp vec4 rgba_87;
             rgba_87 = tmpvar_86;
             rgba_87 = tmpvar_86;
             lumaEndN_18 = rgba_87.w;
             lumaEndN_18 = rgba_87.w;
           };
           };
           if (!(doneP_11)) {
           if (!(doneP_11)) {
             lowp vec4 tmpvar_88;
             lowp vec4 tmpvar_88;
-            tmpvar_88 = texture2DLodEXT (_MainTex, posP_20, 0.0);
+            tmpvar_88 = impl_low_texture2DLodEXT (_MainTex, posP_20, 0.0);
             highp vec4 rgba_89;
             highp vec4 rgba_89;
             rgba_89 = tmpvar_88;
             rgba_89 = tmpvar_88;
             lumaEndP_16 = rgba_89.w;
             lumaEndP_16 = rgba_89.w;
@@ -331,14 +340,14 @@ void main ()
           if (doneNP_10) {
           if (doneNP_10) {
             if (!(doneN_12)) {
             if (!(doneN_12)) {
               lowp vec4 tmpvar_90;
               lowp vec4 tmpvar_90;
-              tmpvar_90 = texture2DLodEXT (_MainTex, posN_21, 0.0);
+              tmpvar_90 = impl_low_texture2DLodEXT (_MainTex, posN_21, 0.0);
               highp vec4 rgba_91;
               highp vec4 rgba_91;
               rgba_91 = tmpvar_90;
               rgba_91 = tmpvar_90;
               lumaEndN_18 = rgba_91.w;
               lumaEndN_18 = rgba_91.w;
             };
             };
             if (!(doneP_11)) {
             if (!(doneP_11)) {
               lowp vec4 tmpvar_92;
               lowp vec4 tmpvar_92;
-              tmpvar_92 = texture2DLodEXT (_MainTex, posP_20, 0.0);
+              tmpvar_92 = impl_low_texture2DLodEXT (_MainTex, posP_20, 0.0);
               highp vec4 rgba_93;
               highp vec4 rgba_93;
               rgba_93 = tmpvar_92;
               rgba_93 = tmpvar_92;
               lumaEndP_16 = rgba_93.w;
               lumaEndP_16 = rgba_93.w;
@@ -367,14 +376,14 @@ void main ()
             if (doneNP_10) {
             if (doneNP_10) {
               if (!(doneN_12)) {
               if (!(doneN_12)) {
                 lowp vec4 tmpvar_94;
                 lowp vec4 tmpvar_94;
-                tmpvar_94 = texture2DLodEXT (_MainTex, posN_21, 0.0);
+                tmpvar_94 = impl_low_texture2DLodEXT (_MainTex, posN_21, 0.0);
                 highp vec4 rgba_95;
                 highp vec4 rgba_95;
                 rgba_95 = tmpvar_94;
                 rgba_95 = tmpvar_94;
                 lumaEndN_18 = rgba_95.w;
                 lumaEndN_18 = rgba_95.w;
               };
               };
               if (!(doneP_11)) {
               if (!(doneP_11)) {
                 lowp vec4 tmpvar_96;
                 lowp vec4 tmpvar_96;
-                tmpvar_96 = texture2DLodEXT (_MainTex, posP_20, 0.0);
+                tmpvar_96 = impl_low_texture2DLodEXT (_MainTex, posP_20, 0.0);
                 highp vec4 rgba_97;
                 highp vec4 rgba_97;
                 rgba_97 = tmpvar_96;
                 rgba_97 = tmpvar_96;
                 lumaEndP_16 = rgba_97.w;
                 lumaEndP_16 = rgba_97.w;
@@ -403,14 +412,14 @@ void main ()
               if (doneNP_10) {
               if (doneNP_10) {
                 if (!(doneN_12)) {
                 if (!(doneN_12)) {
                   lowp vec4 tmpvar_98;
                   lowp vec4 tmpvar_98;
-                  tmpvar_98 = texture2DLodEXT (_MainTex, posN_21, 0.0);
+                  tmpvar_98 = impl_low_texture2DLodEXT (_MainTex, posN_21, 0.0);
                   highp vec4 rgba_99;
                   highp vec4 rgba_99;
                   rgba_99 = tmpvar_98;
                   rgba_99 = tmpvar_98;
                   lumaEndN_18 = rgba_99.w;
                   lumaEndN_18 = rgba_99.w;
                 };
                 };
                 if (!(doneP_11)) {
                 if (!(doneP_11)) {
                   lowp vec4 tmpvar_100;
                   lowp vec4 tmpvar_100;
-                  tmpvar_100 = texture2DLodEXT (_MainTex, posP_20, 0.0);
+                  tmpvar_100 = impl_low_texture2DLodEXT (_MainTex, posP_20, 0.0);
                   highp vec4 rgba_101;
                   highp vec4 rgba_101;
                   rgba_101 = tmpvar_100;
                   rgba_101 = tmpvar_100;
                   lumaEndP_16 = rgba_101.w;
                   lumaEndP_16 = rgba_101.w;
@@ -439,14 +448,14 @@ void main ()
                 if (doneNP_10) {
                 if (doneNP_10) {
                   if (!(doneN_12)) {
                   if (!(doneN_12)) {
                     lowp vec4 tmpvar_102;
                     lowp vec4 tmpvar_102;
-                    tmpvar_102 = texture2DLodEXT (_MainTex, posN_21, 0.0);
+                    tmpvar_102 = impl_low_texture2DLodEXT (_MainTex, posN_21, 0.0);
                     highp vec4 rgba_103;
                     highp vec4 rgba_103;
                     rgba_103 = tmpvar_102;
                     rgba_103 = tmpvar_102;
                     lumaEndN_18 = rgba_103.w;
                     lumaEndN_18 = rgba_103.w;
                   };
                   };
                   if (!(doneP_11)) {
                   if (!(doneP_11)) {
                     lowp vec4 tmpvar_104;
                     lowp vec4 tmpvar_104;
-                    tmpvar_104 = texture2DLodEXT (_MainTex, posP_20, 0.0);
+                    tmpvar_104 = impl_low_texture2DLodEXT (_MainTex, posP_20, 0.0);
                     highp vec4 rgba_105;
                     highp vec4 rgba_105;
                     rgba_105 = tmpvar_104;
                     rgba_105 = tmpvar_104;
                     lumaEndP_16 = rgba_105.w;
                     lumaEndP_16 = rgba_105.w;
@@ -475,14 +484,14 @@ void main ()
                   if (doneNP_10) {
                   if (doneNP_10) {
                     if (!(doneN_12)) {
                     if (!(doneN_12)) {
                       lowp vec4 tmpvar_106;
                       lowp vec4 tmpvar_106;
-                      tmpvar_106 = texture2DLodEXT (_MainTex, posN_21, 0.0);
+                      tmpvar_106 = impl_low_texture2DLodEXT (_MainTex, posN_21, 0.0);
                       highp vec4 rgba_107;
                       highp vec4 rgba_107;
                       rgba_107 = tmpvar_106;
                       rgba_107 = tmpvar_106;
                       lumaEndN_18 = rgba_107.w;
                       lumaEndN_18 = rgba_107.w;
                     };
                     };
                     if (!(doneP_11)) {
                     if (!(doneP_11)) {
                       lowp vec4 tmpvar_108;
                       lowp vec4 tmpvar_108;
-                      tmpvar_108 = texture2DLodEXT (_MainTex, posP_20, 0.0);
+                      tmpvar_108 = impl_low_texture2DLodEXT (_MainTex, posP_20, 0.0);
                       highp vec4 rgba_109;
                       highp vec4 rgba_109;
                       rgba_109 = tmpvar_108;
                       rgba_109 = tmpvar_108;
                       lumaEndP_16 = rgba_109.w;
                       lumaEndP_16 = rgba_109.w;
@@ -511,14 +520,14 @@ void main ()
                     if (doneNP_10) {
                     if (doneNP_10) {
                       if (!(doneN_12)) {
                       if (!(doneN_12)) {
                         lowp vec4 tmpvar_110;
                         lowp vec4 tmpvar_110;
-                        tmpvar_110 = texture2DLodEXT (_MainTex, posN_21, 0.0);
+                        tmpvar_110 = impl_low_texture2DLodEXT (_MainTex, posN_21, 0.0);
                         highp vec4 rgba_111;
                         highp vec4 rgba_111;
                         rgba_111 = tmpvar_110;
                         rgba_111 = tmpvar_110;
                         lumaEndN_18 = rgba_111.w;
                         lumaEndN_18 = rgba_111.w;
                       };
                       };
                       if (!(doneP_11)) {
                       if (!(doneP_11)) {
                         lowp vec4 tmpvar_112;
                         lowp vec4 tmpvar_112;
-                        tmpvar_112 = texture2DLodEXT (_MainTex, posP_20, 0.0);
+                        tmpvar_112 = impl_low_texture2DLodEXT (_MainTex, posP_20, 0.0);
                         highp vec4 rgba_113;
                         highp vec4 rgba_113;
                         rgba_113 = tmpvar_112;
                         rgba_113 = tmpvar_112;
                         lumaEndP_16 = rgba_113.w;
                         lumaEndP_16 = rgba_113.w;
@@ -547,14 +556,14 @@ void main ()
                       if (doneNP_10) {
                       if (doneNP_10) {
                         if (!(doneN_12)) {
                         if (!(doneN_12)) {
                           lowp vec4 tmpvar_114;
                           lowp vec4 tmpvar_114;
-                          tmpvar_114 = texture2DLodEXT (_MainTex, posN_21, 0.0);
+                          tmpvar_114 = impl_low_texture2DLodEXT (_MainTex, posN_21, 0.0);
                           highp vec4 rgba_115;
                           highp vec4 rgba_115;
                           rgba_115 = tmpvar_114;
                           rgba_115 = tmpvar_114;
                           lumaEndN_18 = rgba_115.w;
                           lumaEndN_18 = rgba_115.w;
                         };
                         };
                         if (!(doneP_11)) {
                         if (!(doneP_11)) {
                           lowp vec4 tmpvar_116;
                           lowp vec4 tmpvar_116;
-                          tmpvar_116 = texture2DLodEXT (_MainTex, posP_20, 0.0);
+                          tmpvar_116 = impl_low_texture2DLodEXT (_MainTex, posP_20, 0.0);
                           highp vec4 rgba_117;
                           highp vec4 rgba_117;
                           rgba_117 = tmpvar_116;
                           rgba_117 = tmpvar_116;
                           lumaEndP_16 = rgba_117.w;
                           lumaEndP_16 = rgba_117.w;
@@ -626,7 +635,7 @@ void main ()
       posM_41.y = (xlv_TEXCOORD0.y + (tmpvar_121 * lengthSign_31));
       posM_41.y = (xlv_TEXCOORD0.y + (tmpvar_121 * lengthSign_31));
     };
     };
     lowp vec4 tmpvar_122;
     lowp vec4 tmpvar_122;
-    tmpvar_122 = texture2DLodEXT (_MainTex, posM_41, 0.0);
+    tmpvar_122 = impl_low_texture2DLodEXT (_MainTex, posM_41, 0.0);
     highp vec4 tmpvar_123;
     highp vec4 tmpvar_123;
     tmpvar_123.xyz = tmpvar_122.xyz;
     tmpvar_123.xyz = tmpvar_122.xyz;
     tmpvar_123.w = rgbyM_40.w;
     tmpvar_123.w = rgbyM_40.w;

+ 5 - 5
3rdparty/glsl-optimizer/tests/fragment/z-prepasslight-inES3.txt

@@ -69,7 +69,7 @@ highp float DecodeFloatRGBA( in highp vec4 enc ) {
 }
 }
 highp float SampleCubeDistance( in highp vec3 vec ) {
 highp float SampleCubeDistance( in highp vec3 vec ) {
     highp vec4 packDist;
     highp vec4 packDist;
-    packDist = textureCube( _ShadowMapTexture, vec);
+    packDist = texture( _ShadowMapTexture, vec);
     return DecodeFloatRGBA( packDist);
     return DecodeFloatRGBA( packDist);
 }
 }
 mediump float unitySampleShadow( in highp vec3 vec, in highp float mydist ) {
 mediump float unitySampleShadow( in highp vec3 vec, in highp float mydist ) {
@@ -111,19 +111,19 @@ mediump vec4 xlat_main( in v2f i ) {
     highp float fade;
     highp float fade;
     i.ray = (i.ray * (_ProjectionParams.z  / i.ray.z ));
     i.ray = (i.ray * (_ProjectionParams.z  / i.ray.z ));
     uv = (i.uv.xy  / i.uv.w );
     uv = (i.uv.xy  / i.uv.w );
-    nspec = texture2D( _CameraNormalsTexture, uv);
+    nspec = texture( _CameraNormalsTexture, uv);
     normal = ((nspec.xyz  * 2.00000) - 1.00000);
     normal = ((nspec.xyz  * 2.00000) - 1.00000);
     normal = normalize( normal );
     normal = normalize( normal );
-    depth = texture2D( _CameraDepthTexture, uv).x ;
+    depth = texture( _CameraDepthTexture, uv).x ;
     depth = Linear01Depth( depth);
     depth = Linear01Depth( depth);
     vpos = vec4( (i.ray * depth), 1.00000);
     vpos = vec4( (i.ray * depth), 1.00000);
     wpos = ( _CameraToWorld * vpos ).xyz ;
     wpos = ( _CameraToWorld * vpos ).xyz ;
     tolight = (wpos - _LightPos.xyz );
     tolight = (wpos - _LightPos.xyz );
     lightDir = ( -normalize( tolight ) );
     lightDir = ( -normalize( tolight ) );
     att = (dot( tolight, tolight) * _LightPos.w );
     att = (dot( tolight, tolight) * _LightPos.w );
-    atten = texture2D( _LightTextureB0, vec2( vec2( att))).w ;
+    atten = texture( _LightTextureB0, vec2( vec2( att))).w ;
     atten *= ComputeShadow( tolight, vpos.z , uv);
     atten *= ComputeShadow( tolight, vpos.z , uv);
-    atten *= textureCube( _LightTexture0, ( _LightMatrix0 * vec4( wpos, 1.00000) ).xyz ).w ;
+    atten *= texture( _LightTexture0, ( _LightMatrix0 * vec4( wpos, 1.00000) ).xyz ).w ;
     diff = max( 0.000000, dot( lightDir, normal));
     diff = max( 0.000000, dot( lightDir, normal));
     h = normalize( (lightDir - normalize( (wpos - _WorldSpaceCameraPos) )) );
     h = normalize( (lightDir - normalize( (wpos - _WorldSpaceCameraPos) )) );
     spec = pow( max( 0.000000, dot( h, normal)), (nspec.w  * 128.000));
     spec = pow( max( 0.000000, dot( h, normal)), (nspec.w  * 128.000));

+ 73 - 75
3rdparty/glsl-optimizer/tests/fragment/z-prepasslight-outES.txt

@@ -56,101 +56,99 @@ void main ()
   highp float mydist_19;
   highp float mydist_19;
   mydist_19 = (sqrt(dot (tolight_6, tolight_6)) * _LightPositionRange.w);
   mydist_19 = (sqrt(dot (tolight_6, tolight_6)) * _LightPositionRange.w);
   mydist_19 = (mydist_19 * 0.97);
   mydist_19 = (mydist_19 * 0.97);
-  mediump vec4 shadows_20;
-  highp vec4 shadowVals_21;
-  highp vec3 vec_22;
-  vec_22 = (tolight_6 + vec3(0.0078125, 0.0078125, 0.0078125));
-  highp vec4 packDist_23;
-  lowp vec4 tmpvar_24;
-  tmpvar_24 = textureCube (_ShadowMapTexture, vec_22);
-  packDist_23 = tmpvar_24;
-  shadowVals_21.x = dot (packDist_23, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
-  highp vec3 vec_25;
-  vec_25 = (tolight_6 + vec3(-0.0078125, -0.0078125, 0.0078125));
-  highp vec4 packDist_26;
-  lowp vec4 tmpvar_27;
-  tmpvar_27 = textureCube (_ShadowMapTexture, vec_25);
-  packDist_26 = tmpvar_27;
-  shadowVals_21.y = dot (packDist_26, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
-  highp vec3 vec_28;
-  vec_28 = (tolight_6 + vec3(-0.0078125, 0.0078125, -0.0078125));
-  highp vec4 packDist_29;
-  lowp vec4 tmpvar_30;
-  tmpvar_30 = textureCube (_ShadowMapTexture, vec_28);
-  packDist_29 = tmpvar_30;
-  shadowVals_21.z = dot (packDist_29, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
-  highp vec3 vec_31;
-  vec_31 = (tolight_6 + vec3(0.0078125, -0.0078125, -0.0078125));
-  highp vec4 packDist_32;
-  lowp vec4 tmpvar_33;
-  tmpvar_33 = textureCube (_ShadowMapTexture, vec_31);
-  packDist_32 = tmpvar_33;
-  shadowVals_21.w = dot (packDist_32, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
-  bvec4 tmpvar_34;
-  tmpvar_34 = lessThan (shadowVals_21, vec4(mydist_19));
-  highp vec4 tmpvar_35;
-  tmpvar_35 = _LightShadowData.xxxx;
+  highp vec4 shadowVals_20;
+  highp vec3 vec_21;
+  vec_21 = (tolight_6 + vec3(0.0078125, 0.0078125, 0.0078125));
+  highp vec4 packDist_22;
+  lowp vec4 tmpvar_23;
+  tmpvar_23 = textureCube (_ShadowMapTexture, vec_21);
+  packDist_22 = tmpvar_23;
+  shadowVals_20.x = dot (packDist_22, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
+  highp vec3 vec_24;
+  vec_24 = (tolight_6 + vec3(-0.0078125, -0.0078125, 0.0078125));
+  highp vec4 packDist_25;
+  lowp vec4 tmpvar_26;
+  tmpvar_26 = textureCube (_ShadowMapTexture, vec_24);
+  packDist_25 = tmpvar_26;
+  shadowVals_20.y = dot (packDist_25, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
+  highp vec3 vec_27;
+  vec_27 = (tolight_6 + vec3(-0.0078125, 0.0078125, -0.0078125));
+  highp vec4 packDist_28;
+  lowp vec4 tmpvar_29;
+  tmpvar_29 = textureCube (_ShadowMapTexture, vec_27);
+  packDist_28 = tmpvar_29;
+  shadowVals_20.z = dot (packDist_28, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
+  highp vec3 vec_30;
+  vec_30 = (tolight_6 + vec3(0.0078125, -0.0078125, -0.0078125));
+  highp vec4 packDist_31;
+  lowp vec4 tmpvar_32;
+  tmpvar_32 = textureCube (_ShadowMapTexture, vec_30);
+  packDist_31 = tmpvar_32;
+  shadowVals_20.w = dot (packDist_31, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
+  bvec4 tmpvar_33;
+  tmpvar_33 = lessThan (shadowVals_20, vec4(mydist_19));
+  highp vec4 tmpvar_34;
+  tmpvar_34 = _LightShadowData.xxxx;
+  highp float tmpvar_35;
+  if (tmpvar_33.x) {
+    tmpvar_35 = tmpvar_34.x;
+  } else {
+    tmpvar_35 = 1.0;
+  };
   highp float tmpvar_36;
   highp float tmpvar_36;
-  if (tmpvar_34.x) {
-    tmpvar_36 = tmpvar_35.x;
+  if (tmpvar_33.y) {
+    tmpvar_36 = tmpvar_34.y;
   } else {
   } else {
     tmpvar_36 = 1.0;
     tmpvar_36 = 1.0;
   };
   };
   highp float tmpvar_37;
   highp float tmpvar_37;
-  if (tmpvar_34.y) {
-    tmpvar_37 = tmpvar_35.y;
+  if (tmpvar_33.z) {
+    tmpvar_37 = tmpvar_34.z;
   } else {
   } else {
     tmpvar_37 = 1.0;
     tmpvar_37 = 1.0;
   };
   };
   highp float tmpvar_38;
   highp float tmpvar_38;
-  if (tmpvar_34.z) {
-    tmpvar_38 = tmpvar_35.z;
+  if (tmpvar_33.w) {
+    tmpvar_38 = tmpvar_34.w;
   } else {
   } else {
     tmpvar_38 = 1.0;
     tmpvar_38 = 1.0;
   };
   };
-  highp float tmpvar_39;
-  if (tmpvar_34.w) {
-    tmpvar_39 = tmpvar_35.w;
-  } else {
-    tmpvar_39 = 1.0;
-  };
-  highp vec4 tmpvar_40;
-  tmpvar_40.x = tmpvar_36;
-  tmpvar_40.y = tmpvar_37;
-  tmpvar_40.z = tmpvar_38;
-  tmpvar_40.w = tmpvar_39;
-  shadows_20 = tmpvar_40;
-  mediump float tmpvar_41;
-  tmpvar_41 = dot (shadows_20, vec4(0.25, 0.25, 0.25, 0.25));
-  atten_4 = (atten_4 * tmpvar_41);
-  highp vec4 tmpvar_42;
-  tmpvar_42.w = 1.0;
-  tmpvar_42.xyz = wpos_7;
-  lowp vec4 tmpvar_43;
-  highp vec3 P_44;
-  P_44 = (_LightMatrix0 * tmpvar_42).xyz;
-  tmpvar_43 = textureCube (_LightTexture0, P_44);
-  atten_4 = (atten_4 * tmpvar_43.w);
-  highp vec3 tmpvar_45;
-  tmpvar_45 = normalize((lightDir_5 - normalize(
+  mediump vec4 tmpvar_39;
+  tmpvar_39.x = tmpvar_35;
+  tmpvar_39.y = tmpvar_36;
+  tmpvar_39.z = tmpvar_37;
+  tmpvar_39.w = tmpvar_38;
+  mediump float tmpvar_40;
+  tmpvar_40 = dot (tmpvar_39, vec4(0.25, 0.25, 0.25, 0.25));
+  atten_4 = (atten_4 * tmpvar_40);
+  highp vec4 tmpvar_41;
+  tmpvar_41.w = 1.0;
+  tmpvar_41.xyz = wpos_7;
+  lowp vec4 tmpvar_42;
+  highp vec3 P_43;
+  P_43 = (_LightMatrix0 * tmpvar_41).xyz;
+  tmpvar_42 = textureCube (_LightTexture0, P_43);
+  atten_4 = (atten_4 * tmpvar_42.w);
+  highp vec3 tmpvar_44;
+  tmpvar_44 = normalize((lightDir_5 - normalize(
     (wpos_7 - _WorldSpaceCameraPos)
     (wpos_7 - _WorldSpaceCameraPos)
   )));
   )));
-  h_3 = tmpvar_45;
-  mediump float tmpvar_46;
-  tmpvar_46 = pow (max (0.0, dot (h_3, normal_9)), (nspec_10.w * 128.0));
-  spec_2 = tmpvar_46;
+  h_3 = tmpvar_44;
+  mediump float tmpvar_45;
+  tmpvar_45 = pow (max (0.0, dot (h_3, normal_9)), (nspec_10.w * 128.0));
+  spec_2 = tmpvar_45;
   spec_2 = (spec_2 * clamp (atten_4, 0.0, 1.0));
   spec_2 = (spec_2 * clamp (atten_4, 0.0, 1.0));
   res_1.xyz = (_LightColor.xyz * (max (0.0, 
   res_1.xyz = (_LightColor.xyz * (max (0.0, 
     dot (lightDir_5, normal_9)
     dot (lightDir_5, normal_9)
   ) * atten_4));
   ) * atten_4));
-  mediump vec3 c_47;
-  c_47 = _LightColor.xyz;
-  res_1.w = (spec_2 * dot (c_47, vec3(0.22, 0.707, 0.071)));
-  highp float tmpvar_48;
-  tmpvar_48 = clamp ((1.0 - (
+  mediump vec3 c_46;
+  c_46 = _LightColor.xyz;
+  res_1.w = (spec_2 * dot (c_46, vec3(0.22, 0.707, 0.071)));
+  highp float tmpvar_47;
+  tmpvar_47 = clamp ((1.0 - (
     (tmpvar_15.z * unity_LightmapFade.z)
     (tmpvar_15.z * unity_LightmapFade.z)
    + unity_LightmapFade.w)), 0.0, 1.0);
    + unity_LightmapFade.w)), 0.0, 1.0);
-  res_1 = (res_1 * tmpvar_48);
+  res_1 = (res_1 * tmpvar_47);
   gl_FragData[0] = exp2(-(res_1));
   gl_FragData[0] = exp2(-(res_1));
 }
 }
 
 

+ 73 - 75
3rdparty/glsl-optimizer/tests/fragment/z-prepasslight-outES3.txt

@@ -58,101 +58,99 @@ void main ()
   highp float mydist_19;
   highp float mydist_19;
   mydist_19 = (sqrt(dot (tolight_6, tolight_6)) * _LightPositionRange.w);
   mydist_19 = (sqrt(dot (tolight_6, tolight_6)) * _LightPositionRange.w);
   mydist_19 = (mydist_19 * 0.97);
   mydist_19 = (mydist_19 * 0.97);
-  mediump vec4 shadows_20;
-  highp vec4 shadowVals_21;
-  highp vec3 vec_22;
-  vec_22 = (tolight_6 + vec3(0.0078125, 0.0078125, 0.0078125));
-  highp vec4 packDist_23;
-  lowp vec4 tmpvar_24;
-  tmpvar_24 = texture (_ShadowMapTexture, vec_22);
-  packDist_23 = tmpvar_24;
-  shadowVals_21.x = dot (packDist_23, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
-  highp vec3 vec_25;
-  vec_25 = (tolight_6 + vec3(-0.0078125, -0.0078125, 0.0078125));
-  highp vec4 packDist_26;
-  lowp vec4 tmpvar_27;
-  tmpvar_27 = texture (_ShadowMapTexture, vec_25);
-  packDist_26 = tmpvar_27;
-  shadowVals_21.y = dot (packDist_26, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
-  highp vec3 vec_28;
-  vec_28 = (tolight_6 + vec3(-0.0078125, 0.0078125, -0.0078125));
-  highp vec4 packDist_29;
-  lowp vec4 tmpvar_30;
-  tmpvar_30 = texture (_ShadowMapTexture, vec_28);
-  packDist_29 = tmpvar_30;
-  shadowVals_21.z = dot (packDist_29, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
-  highp vec3 vec_31;
-  vec_31 = (tolight_6 + vec3(0.0078125, -0.0078125, -0.0078125));
-  highp vec4 packDist_32;
-  lowp vec4 tmpvar_33;
-  tmpvar_33 = texture (_ShadowMapTexture, vec_31);
-  packDist_32 = tmpvar_33;
-  shadowVals_21.w = dot (packDist_32, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
-  bvec4 tmpvar_34;
-  tmpvar_34 = lessThan (shadowVals_21, vec4(mydist_19));
-  highp vec4 tmpvar_35;
-  tmpvar_35 = _LightShadowData.xxxx;
+  highp vec4 shadowVals_20;
+  highp vec3 vec_21;
+  vec_21 = (tolight_6 + vec3(0.0078125, 0.0078125, 0.0078125));
+  highp vec4 packDist_22;
+  lowp vec4 tmpvar_23;
+  tmpvar_23 = texture (_ShadowMapTexture, vec_21);
+  packDist_22 = tmpvar_23;
+  shadowVals_20.x = dot (packDist_22, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
+  highp vec3 vec_24;
+  vec_24 = (tolight_6 + vec3(-0.0078125, -0.0078125, 0.0078125));
+  highp vec4 packDist_25;
+  lowp vec4 tmpvar_26;
+  tmpvar_26 = texture (_ShadowMapTexture, vec_24);
+  packDist_25 = tmpvar_26;
+  shadowVals_20.y = dot (packDist_25, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
+  highp vec3 vec_27;
+  vec_27 = (tolight_6 + vec3(-0.0078125, 0.0078125, -0.0078125));
+  highp vec4 packDist_28;
+  lowp vec4 tmpvar_29;
+  tmpvar_29 = texture (_ShadowMapTexture, vec_27);
+  packDist_28 = tmpvar_29;
+  shadowVals_20.z = dot (packDist_28, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
+  highp vec3 vec_30;
+  vec_30 = (tolight_6 + vec3(0.0078125, -0.0078125, -0.0078125));
+  highp vec4 packDist_31;
+  lowp vec4 tmpvar_32;
+  tmpvar_32 = texture (_ShadowMapTexture, vec_30);
+  packDist_31 = tmpvar_32;
+  shadowVals_20.w = dot (packDist_31, vec4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
+  bvec4 tmpvar_33;
+  tmpvar_33 = lessThan (shadowVals_20, vec4(mydist_19));
+  highp vec4 tmpvar_34;
+  tmpvar_34 = _LightShadowData.xxxx;
+  highp float tmpvar_35;
+  if (tmpvar_33.x) {
+    tmpvar_35 = tmpvar_34.x;
+  } else {
+    tmpvar_35 = 1.0;
+  };
   highp float tmpvar_36;
   highp float tmpvar_36;
-  if (tmpvar_34.x) {
-    tmpvar_36 = tmpvar_35.x;
+  if (tmpvar_33.y) {
+    tmpvar_36 = tmpvar_34.y;
   } else {
   } else {
     tmpvar_36 = 1.0;
     tmpvar_36 = 1.0;
   };
   };
   highp float tmpvar_37;
   highp float tmpvar_37;
-  if (tmpvar_34.y) {
-    tmpvar_37 = tmpvar_35.y;
+  if (tmpvar_33.z) {
+    tmpvar_37 = tmpvar_34.z;
   } else {
   } else {
     tmpvar_37 = 1.0;
     tmpvar_37 = 1.0;
   };
   };
   highp float tmpvar_38;
   highp float tmpvar_38;
-  if (tmpvar_34.z) {
-    tmpvar_38 = tmpvar_35.z;
+  if (tmpvar_33.w) {
+    tmpvar_38 = tmpvar_34.w;
   } else {
   } else {
     tmpvar_38 = 1.0;
     tmpvar_38 = 1.0;
   };
   };
-  highp float tmpvar_39;
-  if (tmpvar_34.w) {
-    tmpvar_39 = tmpvar_35.w;
-  } else {
-    tmpvar_39 = 1.0;
-  };
-  highp vec4 tmpvar_40;
-  tmpvar_40.x = tmpvar_36;
-  tmpvar_40.y = tmpvar_37;
-  tmpvar_40.z = tmpvar_38;
-  tmpvar_40.w = tmpvar_39;
-  shadows_20 = tmpvar_40;
-  mediump float tmpvar_41;
-  tmpvar_41 = dot (shadows_20, vec4(0.25, 0.25, 0.25, 0.25));
-  atten_4 = (atten_4 * tmpvar_41);
-  highp vec4 tmpvar_42;
-  tmpvar_42.w = 1.0;
-  tmpvar_42.xyz = wpos_7;
-  lowp vec4 tmpvar_43;
-  highp vec3 P_44;
-  P_44 = (_LightMatrix0 * tmpvar_42).xyz;
-  tmpvar_43 = texture (_LightTexture0, P_44);
-  atten_4 = (atten_4 * tmpvar_43.w);
-  highp vec3 tmpvar_45;
-  tmpvar_45 = normalize((lightDir_5 - normalize(
+  mediump vec4 tmpvar_39;
+  tmpvar_39.x = tmpvar_35;
+  tmpvar_39.y = tmpvar_36;
+  tmpvar_39.z = tmpvar_37;
+  tmpvar_39.w = tmpvar_38;
+  mediump float tmpvar_40;
+  tmpvar_40 = dot (tmpvar_39, vec4(0.25, 0.25, 0.25, 0.25));
+  atten_4 = (atten_4 * tmpvar_40);
+  highp vec4 tmpvar_41;
+  tmpvar_41.w = 1.0;
+  tmpvar_41.xyz = wpos_7;
+  lowp vec4 tmpvar_42;
+  highp vec3 P_43;
+  P_43 = (_LightMatrix0 * tmpvar_41).xyz;
+  tmpvar_42 = texture (_LightTexture0, P_43);
+  atten_4 = (atten_4 * tmpvar_42.w);
+  highp vec3 tmpvar_44;
+  tmpvar_44 = normalize((lightDir_5 - normalize(
     (wpos_7 - _WorldSpaceCameraPos)
     (wpos_7 - _WorldSpaceCameraPos)
   )));
   )));
-  h_3 = tmpvar_45;
-  mediump float tmpvar_46;
-  tmpvar_46 = pow (max (0.0, dot (h_3, normal_9)), (nspec_10.w * 128.0));
-  spec_2 = tmpvar_46;
+  h_3 = tmpvar_44;
+  mediump float tmpvar_45;
+  tmpvar_45 = pow (max (0.0, dot (h_3, normal_9)), (nspec_10.w * 128.0));
+  spec_2 = tmpvar_45;
   spec_2 = (spec_2 * clamp (atten_4, 0.0, 1.0));
   spec_2 = (spec_2 * clamp (atten_4, 0.0, 1.0));
   res_1.xyz = (_LightColor.xyz * (max (0.0, 
   res_1.xyz = (_LightColor.xyz * (max (0.0, 
     dot (lightDir_5, normal_9)
     dot (lightDir_5, normal_9)
   ) * atten_4));
   ) * atten_4));
-  mediump vec3 c_47;
-  c_47 = _LightColor.xyz;
-  res_1.w = (spec_2 * dot (c_47, vec3(0.22, 0.707, 0.071)));
-  highp float tmpvar_48;
-  tmpvar_48 = clamp ((1.0 - (
+  mediump vec3 c_46;
+  c_46 = _LightColor.xyz;
+  res_1.w = (spec_2 * dot (c_46, vec3(0.22, 0.707, 0.071)));
+  highp float tmpvar_47;
+  tmpvar_47 = clamp ((1.0 - (
     (tmpvar_15.z * unity_LightmapFade.z)
     (tmpvar_15.z * unity_LightmapFade.z)
    + unity_LightmapFade.w)), 0.0, 1.0);
    + unity_LightmapFade.w)), 0.0, 1.0);
-  res_1 = (res_1 * tmpvar_48);
+  res_1 = (res_1 * tmpvar_47);
   _fragData = exp2(-(res_1));
   _fragData = exp2(-(res_1));
 }
 }
 
 

+ 73 - 75
3rdparty/glsl-optimizer/tests/fragment/z-prepasslight-outES3Metal.txt

@@ -66,101 +66,99 @@ fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]]
   float mydist_19;
   float mydist_19;
   mydist_19 = (sqrt(dot (tolight_6, tolight_6)) * _mtl_u._LightPositionRange.w);
   mydist_19 = (sqrt(dot (tolight_6, tolight_6)) * _mtl_u._LightPositionRange.w);
   mydist_19 = (mydist_19 * 0.97);
   mydist_19 = (mydist_19 * 0.97);
-  half4 shadows_20;
-  float4 shadowVals_21;
-  float3 vec_22;
-  vec_22 = (tolight_6 + float3(0.0078125, 0.0078125, 0.0078125));
-  float4 packDist_23;
-  half4 tmpvar_24;
-  tmpvar_24 = _ShadowMapTexture.sample(_mtlsmp__ShadowMapTexture, (float3)(vec_22));
-  packDist_23 = float4(tmpvar_24);
-  shadowVals_21.x = dot (packDist_23, float4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
-  float3 vec_25;
-  vec_25 = (tolight_6 + float3(-0.0078125, -0.0078125, 0.0078125));
-  float4 packDist_26;
-  half4 tmpvar_27;
-  tmpvar_27 = _ShadowMapTexture.sample(_mtlsmp__ShadowMapTexture, (float3)(vec_25));
-  packDist_26 = float4(tmpvar_27);
-  shadowVals_21.y = dot (packDist_26, float4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
-  float3 vec_28;
-  vec_28 = (tolight_6 + float3(-0.0078125, 0.0078125, -0.0078125));
-  float4 packDist_29;
-  half4 tmpvar_30;
-  tmpvar_30 = _ShadowMapTexture.sample(_mtlsmp__ShadowMapTexture, (float3)(vec_28));
-  packDist_29 = float4(tmpvar_30);
-  shadowVals_21.z = dot (packDist_29, float4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
-  float3 vec_31;
-  vec_31 = (tolight_6 + float3(0.0078125, -0.0078125, -0.0078125));
-  float4 packDist_32;
-  half4 tmpvar_33;
-  tmpvar_33 = _ShadowMapTexture.sample(_mtlsmp__ShadowMapTexture, (float3)(vec_31));
-  packDist_32 = float4(tmpvar_33);
-  shadowVals_21.w = dot (packDist_32, float4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
-  bool4 tmpvar_34;
-  tmpvar_34 = bool4((shadowVals_21 < float4(mydist_19)));
-  float4 tmpvar_35;
-  tmpvar_35 = _mtl_u._LightShadowData.xxxx;
+  float4 shadowVals_20;
+  float3 vec_21;
+  vec_21 = (tolight_6 + float3(0.0078125, 0.0078125, 0.0078125));
+  float4 packDist_22;
+  half4 tmpvar_23;
+  tmpvar_23 = _ShadowMapTexture.sample(_mtlsmp__ShadowMapTexture, (float3)(vec_21));
+  packDist_22 = float4(tmpvar_23);
+  shadowVals_20.x = dot (packDist_22, float4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
+  float3 vec_24;
+  vec_24 = (tolight_6 + float3(-0.0078125, -0.0078125, 0.0078125));
+  float4 packDist_25;
+  half4 tmpvar_26;
+  tmpvar_26 = _ShadowMapTexture.sample(_mtlsmp__ShadowMapTexture, (float3)(vec_24));
+  packDist_25 = float4(tmpvar_26);
+  shadowVals_20.y = dot (packDist_25, float4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
+  float3 vec_27;
+  vec_27 = (tolight_6 + float3(-0.0078125, 0.0078125, -0.0078125));
+  float4 packDist_28;
+  half4 tmpvar_29;
+  tmpvar_29 = _ShadowMapTexture.sample(_mtlsmp__ShadowMapTexture, (float3)(vec_27));
+  packDist_28 = float4(tmpvar_29);
+  shadowVals_20.z = dot (packDist_28, float4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
+  float3 vec_30;
+  vec_30 = (tolight_6 + float3(0.0078125, -0.0078125, -0.0078125));
+  float4 packDist_31;
+  half4 tmpvar_32;
+  tmpvar_32 = _ShadowMapTexture.sample(_mtlsmp__ShadowMapTexture, (float3)(vec_30));
+  packDist_31 = float4(tmpvar_32);
+  shadowVals_20.w = dot (packDist_31, float4(1.0, 0.00392157, 1.53787e-05, 6.22737e-09));
+  bool4 tmpvar_33;
+  tmpvar_33 = bool4((shadowVals_20 < float4(mydist_19)));
+  float4 tmpvar_34;
+  tmpvar_34 = _mtl_u._LightShadowData.xxxx;
+  float tmpvar_35;
+  if (tmpvar_33.x) {
+    tmpvar_35 = tmpvar_34.x;
+  } else {
+    tmpvar_35 = 1.0;
+  };
   float tmpvar_36;
   float tmpvar_36;
-  if (tmpvar_34.x) {
-    tmpvar_36 = tmpvar_35.x;
+  if (tmpvar_33.y) {
+    tmpvar_36 = tmpvar_34.y;
   } else {
   } else {
     tmpvar_36 = 1.0;
     tmpvar_36 = 1.0;
   };
   };
   float tmpvar_37;
   float tmpvar_37;
-  if (tmpvar_34.y) {
-    tmpvar_37 = tmpvar_35.y;
+  if (tmpvar_33.z) {
+    tmpvar_37 = tmpvar_34.z;
   } else {
   } else {
     tmpvar_37 = 1.0;
     tmpvar_37 = 1.0;
   };
   };
   float tmpvar_38;
   float tmpvar_38;
-  if (tmpvar_34.z) {
-    tmpvar_38 = tmpvar_35.z;
+  if (tmpvar_33.w) {
+    tmpvar_38 = tmpvar_34.w;
   } else {
   } else {
     tmpvar_38 = 1.0;
     tmpvar_38 = 1.0;
   };
   };
-  float tmpvar_39;
-  if (tmpvar_34.w) {
-    tmpvar_39 = tmpvar_35.w;
-  } else {
-    tmpvar_39 = 1.0;
-  };
-  float4 tmpvar_40;
-  tmpvar_40.x = tmpvar_36;
-  tmpvar_40.y = tmpvar_37;
-  tmpvar_40.z = tmpvar_38;
-  tmpvar_40.w = tmpvar_39;
-  shadows_20 = half4(tmpvar_40);
-  half tmpvar_41;
-  tmpvar_41 = dot (shadows_20, (half4)float4(0.25, 0.25, 0.25, 0.25));
-  atten_4 = (atten_4 * (float)tmpvar_41);
-  float4 tmpvar_42;
-  tmpvar_42.w = 1.0;
-  tmpvar_42.xyz = wpos_7;
-  half4 tmpvar_43;
-  float3 P_44;
-  P_44 = (_mtl_u._LightMatrix0 * tmpvar_42).xyz;
-  tmpvar_43 = _LightTexture0.sample(_mtlsmp__LightTexture0, (float3)(P_44));
-  atten_4 = (atten_4 * (float)tmpvar_43.w);
-  float3 tmpvar_45;
-  tmpvar_45 = normalize(((float3)lightDir_5 - normalize(
+  half4 tmpvar_39;
+  tmpvar_39.x = half(tmpvar_35);
+  tmpvar_39.y = half(tmpvar_36);
+  tmpvar_39.z = half(tmpvar_37);
+  tmpvar_39.w = half(tmpvar_38);
+  half tmpvar_40;
+  tmpvar_40 = dot (tmpvar_39, (half4)float4(0.25, 0.25, 0.25, 0.25));
+  atten_4 = (atten_4 * (float)tmpvar_40);
+  float4 tmpvar_41;
+  tmpvar_41.w = 1.0;
+  tmpvar_41.xyz = wpos_7;
+  half4 tmpvar_42;
+  float3 P_43;
+  P_43 = (_mtl_u._LightMatrix0 * tmpvar_41).xyz;
+  tmpvar_42 = _LightTexture0.sample(_mtlsmp__LightTexture0, (float3)(P_43));
+  atten_4 = (atten_4 * (float)tmpvar_42.w);
+  float3 tmpvar_44;
+  tmpvar_44 = normalize(((float3)lightDir_5 - normalize(
     (wpos_7 - _mtl_u._WorldSpaceCameraPos)
     (wpos_7 - _mtl_u._WorldSpaceCameraPos)
   )));
   )));
-  h_3 = half3(tmpvar_45);
-  half tmpvar_46;
-  tmpvar_46 = pow (max ((half)0.0, dot (h_3, normal_9)), (nspec_10.w * (half)128.0));
-  spec_2 = float(tmpvar_46);
+  h_3 = half3(tmpvar_44);
+  half tmpvar_45;
+  tmpvar_45 = pow (max ((half)0.0, dot (h_3, normal_9)), (nspec_10.w * (half)128.0));
+  spec_2 = float(tmpvar_45);
   spec_2 = (spec_2 * clamp (atten_4, 0.0, 1.0));
   spec_2 = (spec_2 * clamp (atten_4, 0.0, 1.0));
   res_1.xyz = half3((_mtl_u._LightColor.xyz * ((float)max ((half)0.0, 
   res_1.xyz = half3((_mtl_u._LightColor.xyz * ((float)max ((half)0.0, 
     dot (lightDir_5, normal_9)
     dot (lightDir_5, normal_9)
   ) * atten_4)));
   ) * atten_4)));
-  half3 c_47;
-  c_47 = half3(_mtl_u._LightColor.xyz);
-  res_1.w = half((spec_2 * (float)dot (c_47, (half3)float3(0.22, 0.707, 0.071))));
-  float tmpvar_48;
-  tmpvar_48 = clamp ((1.0 - (
+  half3 c_46;
+  c_46 = half3(_mtl_u._LightColor.xyz);
+  res_1.w = half((spec_2 * (float)dot (c_46, (half3)float3(0.22, 0.707, 0.071))));
+  float tmpvar_47;
+  tmpvar_47 = clamp ((1.0 - (
     (tmpvar_15.z * _mtl_u.unity_LightmapFade.z)
     (tmpvar_15.z * _mtl_u.unity_LightmapFade.z)
    + _mtl_u.unity_LightmapFade.w)), 0.0, 1.0);
    + _mtl_u.unity_LightmapFade.w)), 0.0, 1.0);
-  res_1 = ((half4)((float4)res_1 * tmpvar_48));
+  res_1 = ((half4)((float4)res_1 * tmpvar_47));
   _mtl_o._fragData = exp2(-(res_1));
   _mtl_o._fragData = exp2(-(res_1));
   return _mtl_o;
   return _mtl_o;
 }
 }

+ 3 - 3
3rdparty/glsl-optimizer/tests/fragment/z-treeleafloop-inES3.txt

@@ -35,13 +35,13 @@ lowp vec4 xlat_main( in v2f i ) {
     mediump float nh;
     mediump float nh;
     mediump float spec;
     mediump float spec;
     lowp vec4 c;
     lowp vec4 c;
-    col = texture2D( _MainTex, i.uv);
+    col = texture( _MainTex, i.uv);
     xll_clip((col.w - _Cutoff));
     xll_clip((col.w - _Cutoff));
     #line 35
     #line 35
     albedo = (col.xyz * i.color);
     albedo = (col.xyz * i.color);
-    specular = (texture2D( _BumpSpecMap, i.uv).x * 128.000);
+    specular = (texture( _BumpSpecMap, i.uv).x * 128.000);
     #line 39
     #line 39
-    trngls = texture2D( _TranslucencyMap, i.uv);
+    trngls = texture( _TranslucencyMap, i.uv);
     gloss = trngls.w;
     gloss = trngls.w;
     light = (vec3( UNITY_LIGHTMODEL_AMBIENT) * albedo);
     light = (vec3( UNITY_LIGHTMODEL_AMBIENT) * albedo);
     #line 44
     #line 44

+ 11 - 11
3rdparty/glsl-optimizer/tests/fragment/z-unishader-dirlm-inES3.txt

@@ -85,12 +85,12 @@ uniform float _SelfIllumScale;
 uniform sampler2D _SelfIllum;
 uniform sampler2D _SelfIllum;
 
 
 vec3 Albedo( in vec4 texcoords ) {
 vec3 Albedo( in vec4 texcoords ) {
-    vec3 albedo = (_Color.xyz * texture2D( _MainTex, texcoords.xy).xyz);
-    albedo *= (2.0 * texture2D( _DetailAlbedoMap, texcoords.zw).xyz);
+    vec3 albedo = (_Color.xyz * texture( _MainTex, texcoords.xy).xyz);
+    albedo *= (2.0 * texture( _DetailAlbedoMap, texcoords.zw).xyz);
     return albedo;
     return albedo;
 }
 }
 float Alpha( in vec2 uv ) {
 float Alpha( in vec2 uv ) {
-    return (texture2D( _AlphaMap, uv).w * _Color.w);
+    return (texture( _AlphaMap, uv).w * _Color.w);
 }
 }
 float BlinnPhongTerm( in float roughness, in float NdotH ) {
 float BlinnPhongTerm( in float roughness, in float NdotH ) {
     float m = (pow( roughness, 4.0) + 1e-05);
     float m = (pow( roughness, 4.0) + 1e-05);
@@ -177,10 +177,10 @@ vec3 EnvMap( in vec4 worldNormal ) {
     return fromRGBM( envTexel);
     return fromRGBM( envTexel);
 }
 }
 float Occlusion( in vec2 uv ) {
 float Occlusion( in vec2 uv ) {
-    return texture2D( _Occlusion, uv).x;
+    return texture( _Occlusion, uv).x;
 }
 }
 vec4 SpecularGloss( in vec2 uv ) {
 vec4 SpecularGloss( in vec2 uv ) {
-    vec4 specGloss = texture2D( _SpecGlossMap, uv);
+    vec4 specGloss = texture( _SpecGlossMap, uv);
     return vec4( specGloss.xyz, specGloss.w);
     return vec4( specGloss.xyz, specGloss.w);
 }
 }
 vec3 BlendNormals( in vec3 n1, in vec3 n2 ) {
 vec3 BlendNormals( in vec3 n1, in vec3 n2 ) {
@@ -194,8 +194,8 @@ vec3 UnpackScaleNormal( in vec4 packednormal, in float bumpScale ) {
     return normal;
     return normal;
 }
 }
 vec3 TangentNormal( in vec4 texcoords ) {
 vec3 TangentNormal( in vec4 texcoords ) {
-    vec3 normalTangent = UnpackScaleNormal( texture2D( _BumpMap, texcoords.xy), _BumpScale);
-    vec3 detailNormalTangent = UnpackScaleNormal( texture2D( _DetailNormalMap, texcoords.zw), _DetailNormalMapScale);
+    vec3 normalTangent = UnpackScaleNormal( texture( _BumpMap, texcoords.xy), _BumpScale);
+    vec3 detailNormalTangent = UnpackScaleNormal( texture( _DetailNormalMap, texcoords.zw), _DetailNormalMapScale);
     normalTangent = BlendNormals( normalTangent, detailNormalTangent);
     normalTangent = BlendNormals( normalTangent, detailNormalTangent);
     return normalTangent;
     return normalTangent;
 }
 }
@@ -204,7 +204,7 @@ mat3 TangentToWorld( in vec3 normal, in vec3 tangent, in vec3 flip ) {
     return xll_transpose_mf3x3(mat3( tangent, binormal, normal));
     return xll_transpose_mf3x3(mat3( tangent, binormal, normal));
 }
 }
 float unitySampleShadow( in vec4 shadowCoord ) {
 float unitySampleShadow( in vec4 shadowCoord ) {
-    float shadow = texture2DProj( _ShadowMapTexture, shadowCoord).x;
+    float shadow = textureProj( _ShadowMapTexture, shadowCoord).x;
     return shadow;
     return shadow;
 }
 }
 vec4 frag( in VertexOutput i ) {
 vec4 frag( in VertexOutput i ) {
@@ -224,15 +224,15 @@ vec4 frag( in VertexOutput i ) {
     vec3 lightDir = _WorldSpaceLightPos0.xyz;
     vec3 lightDir = _WorldSpaceLightPos0.xyz;
     float subsurface = 1.0;
     float subsurface = 1.0;
     vec3 ambient = vec3( 0.0);
     vec3 ambient = vec3( 0.0);
-    vec4 lmtex = texture2D( unity_Lightmap, i.extra.xy);
-    vec4 lmIndTex = texture2D( unity_LightmapInd, i.extra.xy);
+    vec4 lmtex = texture( unity_Lightmap, i.extra.xy);
+    vec4 lmIndTex = texture( unity_LightmapInd, i.extra.xy);
     vec3 lightDirTangent;
     vec3 lightDirTangent;
     DecodeDirLightmap( normalTangent, lmtex, lmIndTex, lightColor, lightDirTangent);
     DecodeDirLightmap( normalTangent, lmtex, lmIndTex, lightColor, lightDirTangent);
     lightDir = (lightDirTangent * tanToWorld);
     lightDir = (lightDirTangent * tanToWorld);
     lightDir = normalize(lightDir);
     lightDir = normalize(lightDir);
     vec3 baseColor = EnergyCalculator( specColor, specular, Albedo( i.tex));
     vec3 baseColor = EnergyCalculator( specColor, specular, Albedo( i.tex));
     vec3 color = BRDF_Disney_PBS( baseColor, (atten * lightColor), specColor, specular, roughness, normalWorld, lightDir, (-eyeVec), ambient, env);
     vec3 color = BRDF_Disney_PBS( baseColor, (atten * lightColor), specColor, specular, roughness, normalWorld, lightDir, (-eyeVec), ambient, env);
-    color += (texture2D( _SelfIllum, i.tex.xy).xyz * _SelfIllumScale);
+    color += (texture( _SelfIllum, i.tex.xy).xyz * _SelfIllumScale);
     float alpha = Alpha( i.tex.xy);
     float alpha = Alpha( i.tex.xy);
     return vec4( color, alpha);
     return vec4( color, alpha);
 }
 }

+ 9 - 7
3rdparty/glsl-optimizer/tests/fragment/z-unishader-dirlm-outES3.txt

@@ -33,9 +33,9 @@ void main ()
   tmpvar_3 = xlv_TEXCOORD3.xyz;
   tmpvar_3 = xlv_TEXCOORD3.xyz;
   tmpvar_4 = (((xlv_TEXCOORD2.yzx * xlv_TEXCOORD3.zxy) - (xlv_TEXCOORD2.zxy * xlv_TEXCOORD3.yzx)) * xlv_TEXCOORD3.www);
   tmpvar_4 = (((xlv_TEXCOORD2.yzx * xlv_TEXCOORD3.zxy) - (xlv_TEXCOORD2.zxy * xlv_TEXCOORD3.yzx)) * xlv_TEXCOORD3.www);
   highp mat3 tmpvar_5;
   highp mat3 tmpvar_5;
-  tmpvar_5[0u].x = tmpvar_3.x;
-  tmpvar_5[0u].y = tmpvar_4.x;
-  tmpvar_5[0u].z = xlv_TEXCOORD2.x;
+  tmpvar_5[uint(0)].x = tmpvar_3.x;
+  tmpvar_5[uint(0)].y = tmpvar_4.x;
+  tmpvar_5[uint(0)].z = xlv_TEXCOORD2.x;
   tmpvar_5[1u].x = tmpvar_3.y;
   tmpvar_5[1u].x = tmpvar_3.y;
   tmpvar_5[1u].y = tmpvar_4.y;
   tmpvar_5[1u].y = tmpvar_4.y;
   tmpvar_5[1u].z = xlv_TEXCOORD2.y;
   tmpvar_5[1u].z = xlv_TEXCOORD2.y;
@@ -89,9 +89,9 @@ void main ()
   lowp vec4 tmpvar_20;
   lowp vec4 tmpvar_20;
   tmpvar_20 = texture (unity_LightmapInd, xlv_TEXCOORD4.xy);
   tmpvar_20 = texture (unity_LightmapInd, xlv_TEXCOORD4.xy);
   highp mat3 tmpvar_21;
   highp mat3 tmpvar_21;
-  tmpvar_21[0u].x = 0.816497;
-  tmpvar_21[0u].y = -0.408248;
-  tmpvar_21[0u].z = -0.408248;
+  tmpvar_21[uint(0)].x = 0.816497;
+  tmpvar_21[uint(0)].y = -0.408248;
+  tmpvar_21[uint(0)].z = -0.408248;
   tmpvar_21[1u].x = 0.0;
   tmpvar_21[1u].x = 0.0;
   tmpvar_21[1u].y = 0.707107;
   tmpvar_21[1u].y = 0.707107;
   tmpvar_21[1u].z = -0.707107;
   tmpvar_21[1u].z = -0.707107;
@@ -171,7 +171,9 @@ void main ()
     (((1.0 - dot (tmpvar_12.xyz, vec3(0.299, 0.587, 0.114))) * (1.0 - tmpvar_14)) * pow (abs((1.0 - tmpvar_32)), 5.0))
     (((1.0 - dot (tmpvar_12.xyz, vec3(0.299, 0.587, 0.114))) * (1.0 - tmpvar_14)) * pow (abs((1.0 - tmpvar_32)), 5.0))
    * env_2)) + (texture (_SelfIllum, xlv_TEXCOORD0.xy).xyz * _SelfIllumScale));
    * env_2)) + (texture (_SelfIllum, xlv_TEXCOORD0.xy).xyz * _SelfIllumScale));
   tmpvar_38.w = (texture (_AlphaMap, xlv_TEXCOORD0.xy).w * _Color.w);
   tmpvar_38.w = (texture (_AlphaMap, xlv_TEXCOORD0.xy).w * _Color.w);
-  _fragData = tmpvar_38;
+  mediump vec4 tmpvar_39;
+  tmpvar_39 = tmpvar_38;
+  _fragData = tmpvar_39;
 }
 }
 
 
 
 

+ 4 - 2
3rdparty/glsl-optimizer/tests/fragment/z-unishader-dirlm-outES3Metal.txt

@@ -149,7 +149,7 @@ fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]]
   half VdotH_34;
   half VdotH_34;
   VdotH_34 = (tmpvar_33 + (half)1e-05);
   VdotH_34 = (tmpvar_33 + (half)1e-05);
   half tmpvar_35;
   half tmpvar_35;
-  tmpvar_35 = ((1.0/((
+  tmpvar_35 = (((half)1.0/((
     pow (tmpvar_14, (half)4.0)
     pow (tmpvar_14, (half)4.0)
    + (half)1e-05))) - (half)2.0);
    + (half)1e-05))) - (half)2.0);
   half tmpvar_36;
   half tmpvar_36;
@@ -179,7 +179,9 @@ fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]]
     ((((half)1.0 - dot (tmpvar_12.xyz, (half3)float3(0.299, 0.587, 0.114))) * ((half)1.0 - tmpvar_14)) * pow (abs(((half)1.0 - tmpvar_32)), (half)5.0))
     ((((half)1.0 - dot (tmpvar_12.xyz, (half3)float3(0.299, 0.587, 0.114))) * ((half)1.0 - tmpvar_14)) * pow (abs(((half)1.0 - tmpvar_32)), (half)5.0))
    * env_2)) + ((half3)((float3)_SelfIllum.sample(_mtlsmp__SelfIllum, (float2)(_mtl_i.xlv_TEXCOORD0.xy)).xyz * _mtl_u._SelfIllumScale)));
    * env_2)) + ((half3)((float3)_SelfIllum.sample(_mtlsmp__SelfIllum, (float2)(_mtl_i.xlv_TEXCOORD0.xy)).xyz * _mtl_u._SelfIllumScale)));
   tmpvar_38.w = ((half)((float)_AlphaMap.sample(_mtlsmp__AlphaMap, (float2)(_mtl_i.xlv_TEXCOORD0.xy)).w * _mtl_u._Color.w));
   tmpvar_38.w = ((half)((float)_AlphaMap.sample(_mtlsmp__AlphaMap, (float2)(_mtl_i.xlv_TEXCOORD0.xy)).w * _mtl_u._Color.w));
-  _mtl_o._fragData = tmpvar_38;
+  half4 tmpvar_39;
+  tmpvar_39 = tmpvar_38;
+  _mtl_o._fragData = tmpvar_39;
   return _mtl_o;
   return _mtl_o;
 }
 }
 
 

+ 2 - 2
3rdparty/glsl-optimizer/tests/fragment/zun-MobileBumpSpec-inES3.txt

@@ -32,12 +32,12 @@ lowp vec3 UnpackNormal( in lowp vec4 packednormal ) {
 }
 }
 void surf( in Input IN, inout SurfaceOutput o ) {
 void surf( in Input IN, inout SurfaceOutput o ) {
     lowp vec4 tex;
     lowp vec4 tex;
-    tex = texture2D( _MainTex, IN.uv_MainTex);
+    tex = texture( _MainTex, IN.uv_MainTex);
     o.Albedo = tex.xyz ;
     o.Albedo = tex.xyz ;
     o.Gloss = tex.w ;
     o.Gloss = tex.w ;
     o.Alpha = tex.w ;
     o.Alpha = tex.w ;
     o.Specular = _Shininess;
     o.Specular = _Shininess;
-    o.Normal = UnpackNormal( texture2D( _BumpMap, IN.uv_MainTex));
+    o.Normal = UnpackNormal( texture( _BumpMap, IN.uv_MainTex));
 }
 }
 lowp vec4 LightingMobileBlinnPhong( in SurfaceOutput s, in lowp vec3 lightDir, in lowp vec3 halfDir, in lowp float atten ) {
 lowp vec4 LightingMobileBlinnPhong( in SurfaceOutput s, in lowp vec3 lightDir, in lowp vec3 halfDir, in lowp float atten ) {
     lowp float diff;
     lowp float diff;

+ 2 - 2
3rdparty/glsl-optimizer/tests/fragment/zun-SSAO24-outES3.txt

@@ -32,7 +32,7 @@ void main ()
   depth_6 = (dot (tmpvar_10.zw, vec2(1.0, 0.00392157)) * _ProjectionParams.z);
   depth_6 = (dot (tmpvar_10.zw, vec2(1.0, 0.00392157)) * _ProjectionParams.z);
   scale_5 = (_Params.x / depth_6);
   scale_5 = (_Params.x / depth_6);
   occ_4 = 0.0;
   occ_4 = 0.0;
-  for (int s_3 = 0; s_3 < 8; s_3++) {
+  for (highp int s_3 = 0; s_3 < 8; s_3++) {
     mediump vec3 randomDir_14;
     mediump vec3 randomDir_14;
     highp vec3 tmpvar_15;
     highp vec3 tmpvar_15;
     highp vec3 I_16;
     highp vec3 I_16;
@@ -43,7 +43,7 @@ void main ()
     randomDir_14 = tmpvar_15;
     randomDir_14 = tmpvar_15;
     highp float tmpvar_17;
     highp float tmpvar_17;
     tmpvar_17 = dot (viewNorm_7, randomDir_14);
     tmpvar_17 = dot (viewNorm_7, randomDir_14);
-    highp float tmpvar_18;
+    mediump float tmpvar_18;
     if ((tmpvar_17 < 0.0)) {
     if ((tmpvar_17 < 0.0)) {
       tmpvar_18 = 1.0;
       tmpvar_18 = 1.0;
     } else {
     } else {

+ 4 - 4
3rdparty/glsl-optimizer/tests/fragment/zun-SSAO24-outES3Metal.txt

@@ -52,13 +52,13 @@ fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]]
     randomDir_14 = half3(tmpvar_15);
     randomDir_14 = half3(tmpvar_15);
     float tmpvar_17;
     float tmpvar_17;
     tmpvar_17 = dot (viewNorm_7, (float3)randomDir_14);
     tmpvar_17 = dot (viewNorm_7, (float3)randomDir_14);
-    float tmpvar_18;
+    half tmpvar_18;
     if ((tmpvar_17 < 0.0)) {
     if ((tmpvar_17 < 0.0)) {
-      tmpvar_18 = 1.0;
+      tmpvar_18 = half(1.0);
     } else {
     } else {
-      tmpvar_18 = -1.0;
+      tmpvar_18 = half(-1.0);
     };
     };
-    randomDir_14 = (randomDir_14 * ((half)-(tmpvar_18)));
+    randomDir_14 = (randomDir_14 * -(tmpvar_18));
     randomDir_14 = half3(((float3)randomDir_14 + (viewNorm_7 * 0.3)));
     randomDir_14 = half3(((float3)randomDir_14 + (viewNorm_7 * 0.3)));
     float4 tmpvar_19;
     float4 tmpvar_19;
     tmpvar_19 = float4(_CameraDepthNormalsTexture.sample(_mtlsmp__CameraDepthNormalsTexture, (float2)((tmpvar_2 + ((float2)randomDir_14.xy * scale_5)))));
     tmpvar_19 = float4(_CameraDepthNormalsTexture.sample(_mtlsmp__CameraDepthNormalsTexture, (float2)((tmpvar_2 + ((float2)randomDir_14.xy * scale_5)))));

+ 2 - 2
3rdparty/glsl-optimizer/tests/fragment/zun-SSAO8-outES.txt

@@ -43,7 +43,7 @@ void main ()
   depth_8 = (dot (depthnormal_10.zw, vec2(1.0, 0.00392157)) * _ProjectionParams.z);
   depth_8 = (dot (depthnormal_10.zw, vec2(1.0, 0.00392157)) * _ProjectionParams.z);
   scale_7 = (_Params.x / depth_8);
   scale_7 = (_Params.x / depth_8);
   occ_6 = 0.0;
   occ_6 = 0.0;
-  for (int s_5 = 0; s_5 < 8; s_5++) {
+  for (highp int s_5 = 0; s_5 < 8; s_5++) {
     highp vec4 sampleND_17;
     highp vec4 sampleND_17;
     mediump vec3 randomDir_18;
     mediump vec3 randomDir_18;
     highp vec3 tmpvar_19;
     highp vec3 tmpvar_19;
@@ -55,7 +55,7 @@ void main ()
     randomDir_18 = tmpvar_19;
     randomDir_18 = tmpvar_19;
     highp float tmpvar_21;
     highp float tmpvar_21;
     tmpvar_21 = dot (viewNorm_9, randomDir_18);
     tmpvar_21 = dot (viewNorm_9, randomDir_18);
-    highp float tmpvar_22;
+    mediump float tmpvar_22;
     if ((tmpvar_21 < 0.0)) {
     if ((tmpvar_21 < 0.0)) {
       tmpvar_22 = 1.0;
       tmpvar_22 = 1.0;
     } else {
     } else {

+ 31 - 0
3rdparty/glsl-optimizer/tests/global-mutable-inES.txt

@@ -0,0 +1,31 @@
+uniform highp float uni1;
+uniform mediump vec4 uni4;
+uniform sampler2D tex1;
+
+// global variables that aren't uniforms
+highp float mut_uni1;
+mediump vec4 mut_uni4;
+
+highp vec3 SampleDiffuse(in highp vec2 uv)
+{
+    mut_uni4.xy = uv;
+    return vec3(texture2D(tex1,mut_uni4.xy));
+}
+lowp vec4 xlat_main(in highp vec4 uv)
+{
+    lowp vec4 c = vec4(0.0);
+    c.x += mut_uni4.x;
+    c.xyz += SampleDiffuse(uv.xy);
+    c.z += mut_uni1;
+    mut_uni1 += 2.0;
+    c.w += mut_uni1;
+    return c;
+}
+varying highp vec4 var_uv;
+void main()
+{
+    mut_uni1 = uni1;
+    mut_uni4 = uni4;
+    lowp vec4 r = xlat_main(var_uv);
+    gl_FragData[0] = r;
+}

+ 68 - 0
3rdparty/glsl-optimizer/tests/global-mutable-inES3.txt

@@ -0,0 +1,68 @@
+#version 300 es
+
+uniform highp float uni1;
+uniform mediump vec4 uni4;
+uniform sampler2D tex1;
+uniform lowp vec4 unity_ColorSpaceDouble;
+uniform mediump vec3 _SkyTint;
+uniform mediump float _AtmosphereThickness;
+
+
+// global variables that aren't uniforms
+highp float mut_uni1;
+mediump vec4 mut_uni4;
+// global variables that are modified in complex chains of assignments/branches
+highp vec3 kSkyTintInGammaSpace;
+highp float kKrESun;
+highp float kKr4PI;
+
+
+highp vec3 SampleDiffuse(in highp vec2 uv)
+{
+    mut_uni4.xy = uv;
+    return vec3(texture(tex1, mut_uni4.xy));
+}
+lowp vec4 xlat_main(in highp vec4 uv)
+{
+    lowp vec4 c = vec4(0.0);
+    c.x += mut_uni4.x;
+    c.xyz += SampleDiffuse(uv.xy);
+    c.z += mut_uni1;
+    mut_uni1 += 2.0;
+    c.w += mut_uni1;
+
+    mediump vec3 tmpvar_1;
+    if ((unity_ColorSpaceDouble.x > 2.0)) {
+        tmpvar_1 = pow (_SkyTint, vec3(0.454545, 0.454545, 0.454545));
+    } else {
+        tmpvar_1 = _SkyTint;
+    };
+    kSkyTintInGammaSpace = tmpvar_1;
+    highp vec3 tmpvar_2;
+    tmpvar_2 = (1.0/(pow (mix (vec3(0.5, 0.42, 0.325), vec3(0.8, 0.72, 0.625), 
+        (vec3(1.0, 1.0, 1.0) - kSkyTintInGammaSpace)
+        ), vec3(4.0, 4.0, 4.0))));
+    mediump float tmpvar_3;
+    mediump float cse_4;
+    cse_4 = pow (_AtmosphereThickness, 2.5);
+    tmpvar_3 = (mix (0.0, 0.0025, cse_4) * 20.0);
+    kKrESun = tmpvar_3;
+    mediump float tmpvar_5;
+    tmpvar_5 = (12.5664 * mix (0.0, 0.0025, cse_4));
+    kKr4PI = tmpvar_5;
+
+    if (uv.x > 0.5)
+    {
+        c.x += pow(kKrESun, kKr4PI);
+    }
+    return c;
+}
+in highp vec4 var_uv;
+out mediump vec4 out_data;
+void main()
+{
+    mut_uni1 = uni1;
+    mut_uni4 = uni4;
+    lowp vec4 r = xlat_main(var_uv);
+    out_data = r;
+}

+ 35 - 0
3rdparty/glsl-optimizer/tests/global-mutable-outES.txt

@@ -0,0 +1,35 @@
+uniform highp float uni1;
+uniform mediump vec4 uni4;
+uniform sampler2D tex1;
+highp float mut_uni1;
+mediump vec4 mut_uni4;
+varying highp vec4 var_uv;
+void main ()
+{
+  mut_uni4.zw = uni4.zw;
+  lowp vec4 c_1;
+  c_1.yzw = vec3(0.0, 0.0, 0.0);
+  c_1.x = uni4.x;
+  highp vec3 tmpvar_2;
+  highp vec2 uv_3;
+  uv_3 = var_uv.xy;
+  mut_uni4.xy = uv_3;
+  lowp vec3 tmpvar_4;
+  tmpvar_4 = texture2D (tex1, mut_uni4.xy).xyz;
+  tmpvar_2 = tmpvar_4;
+  c_1.xyz = (c_1.xyz + tmpvar_2);
+  c_1.z = (c_1.z + uni1);
+  mut_uni1 = (uni1 + 2.0);
+  c_1.w = mut_uni1;
+  gl_FragData[0] = c_1;
+}
+
+
+// stats: 4 alu 1 tex 0 flow
+// inputs: 1
+//  #0: var_uv (high float) 4x1 [-1]
+// uniforms: 2 (total size: 0)
+//  #0: uni1 (high float) 1x1 [-1]
+//  #1: uni4 (medium float) 4x1 [-1]
+// textures: 1
+//  #0: tex1 (low 2d) 0x0 [-1]

+ 54 - 0
3rdparty/glsl-optimizer/tests/global-mutable-outES3.txt

@@ -0,0 +1,54 @@
+#version 300 es
+uniform highp float uni1;
+uniform mediump vec4 uni4;
+uniform sampler2D tex1;
+uniform mediump float _AtmosphereThickness;
+highp float mut_uni1;
+mediump vec4 mut_uni4;
+highp float kKrESun;
+highp float kKr4PI;
+in highp vec4 var_uv;
+out mediump vec4 out_data;
+void main ()
+{
+  mut_uni4.zw = uni4.zw;
+  mediump float tmpvar_5_1;
+  mediump float tmpvar_3_2;
+  lowp vec4 c_3;
+  c_3.yzw = vec3(0.0, 0.0, 0.0);
+  c_3.x = uni4.x;
+  highp vec3 tmpvar_4;
+  highp vec2 uv_5;
+  uv_5 = var_uv.xy;
+  mut_uni4.xy = uv_5;
+  lowp vec3 tmpvar_6;
+  tmpvar_6 = texture (tex1, mut_uni4.xy).xyz;
+  tmpvar_4 = tmpvar_6;
+  c_3.xyz = (c_3.xyz + tmpvar_4);
+  c_3.z = (c_3.z + uni1);
+  mut_uni1 = (uni1 + 2.0);
+  c_3.w = mut_uni1;
+  mediump float tmpvar_7;
+  tmpvar_7 = pow (_AtmosphereThickness, 2.5);
+  tmpvar_3_2 = (0.05 * tmpvar_7);
+  kKrESun = tmpvar_3_2;
+  tmpvar_5_1 = (tmpvar_7 * 0.031416);
+  kKr4PI = tmpvar_5_1;
+  if ((var_uv.x > 0.5)) {
+    highp float tmpvar_8;
+    tmpvar_8 = pow (kKrESun, kKr4PI);
+    c_3.x = (c_3.x + tmpvar_8);
+  };
+  out_data = c_3;
+}
+
+
+// stats: 10 alu 1 tex 1 flow
+// inputs: 1
+//  #0: var_uv (high float) 4x1 [-1]
+// uniforms: 3 (total size: 0)
+//  #0: uni1 (high float) 1x1 [-1]
+//  #1: uni4 (medium float) 4x1 [-1]
+//  #2: _AtmosphereThickness (medium float) 1x1 [-1]
+// textures: 1
+//  #0: tex1 (low 2d) 0x0 [-1]

+ 63 - 0
3rdparty/glsl-optimizer/tests/global-mutable-outES3Metal.txt

@@ -0,0 +1,63 @@
+#include <metal_stdlib>
+using namespace metal;
+struct xlatMtlShaderInput {
+  float4 var_uv;
+};
+struct xlatMtlShaderOutput {
+  half4 out_data [[color(0)]];
+};
+struct xlatMtlShaderUniform {
+  float uni1;
+  half4 uni4;
+  half _AtmosphereThickness;
+};
+fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]]
+  ,   texture2d<half> tex1 [[texture(0)]], sampler _mtlsmp_tex1 [[sampler(0)]])
+{
+  xlatMtlShaderOutput _mtl_o;
+float mut_uni1_1;
+half4 mut_uni4_2;
+float kKrESun_3;
+float kKr4PI_4;
+  mut_uni4_2.zw = _mtl_u.uni4.zw;
+  half tmpvar_5_5;
+  half tmpvar_3_6;
+  half4 c_7;
+  c_7.yzw = half3(float3(0.0, 0.0, 0.0));
+  c_7.x = _mtl_u.uni4.x;
+  float3 tmpvar_8;
+  float2 uv_9;
+  uv_9 = _mtl_i.var_uv.xy;
+  mut_uni4_2.xy = half2(uv_9);
+  half3 tmpvar_10;
+  tmpvar_10 = tex1.sample(_mtlsmp_tex1, (float2)(mut_uni4_2.xy)).xyz;
+  tmpvar_8 = float3(tmpvar_10);
+  c_7.xyz = half3(((float3)c_7.xyz + tmpvar_8));
+  c_7.z = half(((float)c_7.z + _mtl_u.uni1));
+  mut_uni1_1 = (_mtl_u.uni1 + 2.0);
+  c_7.w = half(mut_uni1_1);
+  half tmpvar_11;
+  tmpvar_11 = pow (_mtl_u._AtmosphereThickness, (half)2.5);
+  tmpvar_3_6 = ((half)0.05 * tmpvar_11);
+  kKrESun_3 = float(tmpvar_3_6);
+  tmpvar_5_5 = (tmpvar_11 * (half)0.031416);
+  kKr4PI_4 = float(tmpvar_5_5);
+  if ((_mtl_i.var_uv.x > 0.5)) {
+    float tmpvar_12;
+    tmpvar_12 = pow (kKrESun_3, kKr4PI_4);
+    c_7.x = half(((float)c_7.x + tmpvar_12));
+  };
+  _mtl_o.out_data = c_7;
+  return _mtl_o;
+}
+
+
+// stats: 10 alu 1 tex 1 flow
+// inputs: 1
+//  #0: var_uv (high float) 4x1 [-1]
+// uniforms: 3 (total size: 18)
+//  #0: uni1 (high float) 1x1 [-1] loc 0
+//  #1: uni4 (medium float) 4x1 [-1] loc 8
+//  #2: _AtmosphereThickness (medium float) 1x1 [-1] loc 16
+// textures: 1
+//  #0: tex1 (low 2d) 0x0 [-1] loc 0

+ 23 - 12
3rdparty/glsl-optimizer/tests/glsl_optimizer_tests.cpp

@@ -256,8 +256,11 @@ static bool CheckGLSL (bool vertex, bool gles, const std::string& testName, cons
 			src += "#define gl_LastFragData _glesLastFragData\n";
 			src += "#define gl_LastFragData _glesLastFragData\n";
 			src += "varying lowp vec4 _glesLastFragData[4];\n";
 			src += "varying lowp vec4 _glesLastFragData[4];\n";
 		}
 		}
-		src += "float shadow2DEXT (sampler2DShadow s, vec3 p) { return shadow2D(s,p).r; }\n";
-		src += "float shadow2DProjEXT (sampler2DShadow s, vec4 p) { return shadow2DProj(s,p).r; }\n";
+		if (!need3)
+		{
+			src += "float shadow2DEXT (sampler2DShadow s, vec3 p) { return shadow2D(s,p).r; }\n";
+			src += "float shadow2DProjEXT (sampler2DShadow s, vec4 p) { return shadow2DProj(s,p).r; }\n";
+		}
 	}
 	}
 	src += source;
 	src += source;
 	if (gles)
 	if (gles)
@@ -274,8 +277,11 @@ static bool CheckGLSL (bool vertex, bool gles, const std::string& testName, cons
 		replace_string (src, "precision ", "// precision ", 0);
 		replace_string (src, "precision ", "// precision ", 0);
 		replace_string (src, "#version 300 es", "", 0);
 		replace_string (src, "#version 300 es", "", 0);
 	}
 	}
-	replace_string (src, "#extension GL_EXT_shader_framebuffer_fetch : require", "", 0);
-	replace_string (src, "#extension GL_EXT_shader_framebuffer_fetch : enable", "", 0);
+	
+	// can't check FB fetch on PC
+	if (src.find("#extension GL_EXT_shader_framebuffer_fetch") != std::string::npos)
+		return true;
+
 	if (gles && need3)
 	if (gles && need3)
 	{
 	{
 		src = "#version 330\n" + src;
 		src = "#version 330\n" + src;
@@ -283,22 +289,24 @@ static bool CheckGLSL (bool vertex, bool gles, const std::string& testName, cons
 	const char* sourcePtr = src.c_str();
 	const char* sourcePtr = src.c_str();
 
 
 	
 	
-	GLhandleARB shader = glCreateShaderObjectARB (vertex ? GL_VERTEX_SHADER_ARB : GL_FRAGMENT_SHADER_ARB);
-	glShaderSourceARB (shader, 1, &sourcePtr, NULL);
-	glCompileShaderARB (shader);
+	GLuint shader = glCreateShader (vertex ? GL_VERTEX_SHADER : GL_FRAGMENT_SHADER);
+	glShaderSource (shader, 1, &sourcePtr, NULL);
+	glCompileShader (shader);
 	GLint status;
 	GLint status;
-	glGetObjectParameterivARB (shader, GL_OBJECT_COMPILE_STATUS_ARB, &status);
+	
+	glGetShaderiv (shader, GL_COMPILE_STATUS, &status);
+	
 	bool res = true;
 	bool res = true;
-	if (status == 0)
+	if (status != GL_TRUE)
 	{
 	{
 		char log[20000];
 		char log[20000];
 		log[0] = 0;
 		log[0] = 0;
 		GLsizei logLength;
 		GLsizei logLength;
-		glGetInfoLogARB (shader, sizeof(log), &logLength, log);
+		glGetShaderInfoLog (shader, sizeof(log), &logLength, log);
 		printf ("\n  %s: real glsl compiler error on %s:\n%s\n", testName.c_str(), prefix, log);
 		printf ("\n  %s: real glsl compiler error on %s:\n%s\n", testName.c_str(), prefix, log);
 		res = false;
 		res = false;
 	}
 	}
-	glDeleteObjectARB (shader);
+	glDeleteShader (shader);
 	return res;
 	return res;
 }
 }
 
 
@@ -312,13 +320,16 @@ static bool CheckMetal (bool vertex, bool gles, const std::string& testName, con
 	FILE* f = fopen ("metalTemp.metal", "wb");
 	FILE* f = fopen ("metalTemp.metal", "wb");
 	fwrite (source.c_str(), source.size(), 1, f);
 	fwrite (source.c_str(), source.size(), 1, f);
 	fclose (f);
 	fclose (f);
-	
+
+#if defined(__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__)
 	int res = system("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/bin/metal metalTemp.metal -o metalTemp.o -std=ios-metal1.0 -Wno-parentheses-equality");
 	int res = system("/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/usr/bin/metal metalTemp.metal -o metalTemp.o -std=ios-metal1.0 -Wno-parentheses-equality");
 	if (res != 0)
 	if (res != 0)
 	{
 	{
 		printf ("\n  %s: Metal compiler failed\n", testName.c_str());
 		printf ("\n  %s: Metal compiler failed\n", testName.c_str());
 		return false;
 		return false;
 	}
 	}
+#endif //
+
 	return true;
 	return true;
 }
 }
 
 

+ 1 - 1
3rdparty/glsl-optimizer/tests/vertex/MF-GodRays-outES.txt

@@ -54,7 +54,7 @@ void main ()
   dir_15 = (localDir_9 / tmpvar_14);
   dir_15 = (localDir_9 / tmpvar_14);
   highp float tmpvar_16;
   highp float tmpvar_16;
   tmpvar_16 = abs(dir_15.y);
   tmpvar_16 = abs(dir_15.y);
-  vec3 tmpvar_17;
+  highp vec3 tmpvar_17;
   if ((tmpvar_16 > 0.999)) {
   if ((tmpvar_16 > 0.999)) {
     tmpvar_17 = vec3(0.0, 0.0, 1.0);
     tmpvar_17 = vec3(0.0, 0.0, 1.0);
   } else {
   } else {

+ 1 - 1
3rdparty/glsl-optimizer/tests/vertex/MF-GodRays-outES3.txt

@@ -55,7 +55,7 @@ void main ()
   dir_15 = (localDir_9 / tmpvar_14);
   dir_15 = (localDir_9 / tmpvar_14);
   highp float tmpvar_16;
   highp float tmpvar_16;
   tmpvar_16 = abs(dir_15.y);
   tmpvar_16 = abs(dir_15.y);
-  vec3 tmpvar_17;
+  highp vec3 tmpvar_17;
   if ((tmpvar_16 > 0.999)) {
   if ((tmpvar_16 > 0.999)) {
     tmpvar_17 = vec3(0.0, 0.0, 1.0);
     tmpvar_17 = vec3(0.0, 0.0, 1.0);
   } else {
   } else {

+ 9 - 9
3rdparty/glsl-optimizer/tests/vertex/bug-swizzle-lhs-cast-outES3.txt

@@ -13,27 +13,27 @@ void main ()
   tmpvar_3.w = 1.0;
   tmpvar_3.w = 1.0;
   tmpvar_3.xyz = _WorldSpaceCameraPos;
   tmpvar_3.xyz = _WorldSpaceCameraPos;
   viewDir_1 = normalize(((_World2Object * tmpvar_3).xyz - _glesVertex.xyz));
   viewDir_1 = normalize(((_World2Object * tmpvar_3).xyz - _glesVertex.xyz));
-  mediump float backContrib_4;
+  mediump float tmpvar_4;
   highp float tmpvar_5;
   highp float tmpvar_5;
   tmpvar_5 = clamp (dot (viewDir_1, -(_TerrainTreeLightDirections[0])), 0.0, 1.0);
   tmpvar_5 = clamp (dot (viewDir_1, -(_TerrainTreeLightDirections[0])), 0.0, 1.0);
-  backContrib_4 = tmpvar_5;
+  tmpvar_4 = tmpvar_5;
   highp vec3 tmpvar_6;
   highp vec3 tmpvar_6;
   tmpvar_6.yz = tmpvar_2.yz;
   tmpvar_6.yz = tmpvar_2.yz;
-  tmpvar_6.x = (backContrib_4 * 2.0);
-  mediump float backContrib_7;
+  tmpvar_6.x = (tmpvar_4 * 2.0);
+  mediump float tmpvar_7;
   highp float tmpvar_8;
   highp float tmpvar_8;
   tmpvar_8 = clamp (dot (viewDir_1, -(_TerrainTreeLightDirections[1])), 0.0, 1.0);
   tmpvar_8 = clamp (dot (viewDir_1, -(_TerrainTreeLightDirections[1])), 0.0, 1.0);
-  backContrib_7 = tmpvar_8;
+  tmpvar_7 = tmpvar_8;
   highp vec3 tmpvar_9;
   highp vec3 tmpvar_9;
   tmpvar_9.xz = tmpvar_6.xz;
   tmpvar_9.xz = tmpvar_6.xz;
-  tmpvar_9.y = (backContrib_7 * 2.0);
-  mediump float backContrib_10;
+  tmpvar_9.y = (tmpvar_7 * 2.0);
+  mediump float tmpvar_10;
   highp float tmpvar_11;
   highp float tmpvar_11;
   tmpvar_11 = clamp (dot (viewDir_1, -(_TerrainTreeLightDirections[2])), 0.0, 1.0);
   tmpvar_11 = clamp (dot (viewDir_1, -(_TerrainTreeLightDirections[2])), 0.0, 1.0);
-  backContrib_10 = tmpvar_11;
+  tmpvar_10 = tmpvar_11;
   highp vec3 tmpvar_12;
   highp vec3 tmpvar_12;
   tmpvar_12.xy = tmpvar_9.xy;
   tmpvar_12.xy = tmpvar_9.xy;
-  tmpvar_12.z = (backContrib_10 * 2.0);
+  tmpvar_12.z = (tmpvar_10 * 2.0);
   tmpvar_2 = tmpvar_12;
   tmpvar_2 = tmpvar_12;
   gl_Position = (glstate_matrix_mvp * _glesVertex);
   gl_Position = (glstate_matrix_mvp * _glesVertex);
   xlv_TEXCOORD2 = tmpvar_12;
   xlv_TEXCOORD2 = tmpvar_12;

+ 9 - 9
3rdparty/glsl-optimizer/tests/vertex/bug-swizzle-lhs-cast-outES3Metal.txt

@@ -22,27 +22,27 @@ vertex xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]],
   tmpvar_3.w = 1.0;
   tmpvar_3.w = 1.0;
   tmpvar_3.xyz = _mtl_u._WorldSpaceCameraPos;
   tmpvar_3.xyz = _mtl_u._WorldSpaceCameraPos;
   viewDir_1 = normalize(((_mtl_u._World2Object * tmpvar_3).xyz - _mtl_i._glesVertex.xyz));
   viewDir_1 = normalize(((_mtl_u._World2Object * tmpvar_3).xyz - _mtl_i._glesVertex.xyz));
-  half backContrib_4;
+  half tmpvar_4;
   float tmpvar_5;
   float tmpvar_5;
   tmpvar_5 = clamp (dot (viewDir_1, -(_mtl_u._TerrainTreeLightDirections[0])), 0.0, 1.0);
   tmpvar_5 = clamp (dot (viewDir_1, -(_mtl_u._TerrainTreeLightDirections[0])), 0.0, 1.0);
-  backContrib_4 = half(tmpvar_5);
+  tmpvar_4 = half(tmpvar_5);
   float3 tmpvar_6;
   float3 tmpvar_6;
   tmpvar_6.yz = tmpvar_2.yz;
   tmpvar_6.yz = tmpvar_2.yz;
-  tmpvar_6.x = float((backContrib_4 * (half)2.0));
-  half backContrib_7;
+  tmpvar_6.x = float((tmpvar_4 * (half)2.0));
+  half tmpvar_7;
   float tmpvar_8;
   float tmpvar_8;
   tmpvar_8 = clamp (dot (viewDir_1, -(_mtl_u._TerrainTreeLightDirections[1])), 0.0, 1.0);
   tmpvar_8 = clamp (dot (viewDir_1, -(_mtl_u._TerrainTreeLightDirections[1])), 0.0, 1.0);
-  backContrib_7 = half(tmpvar_8);
+  tmpvar_7 = half(tmpvar_8);
   float3 tmpvar_9;
   float3 tmpvar_9;
   tmpvar_9.xz = tmpvar_6.xz;
   tmpvar_9.xz = tmpvar_6.xz;
-  tmpvar_9.y = float((backContrib_7 * (half)2.0));
-  half backContrib_10;
+  tmpvar_9.y = float((tmpvar_7 * (half)2.0));
+  half tmpvar_10;
   float tmpvar_11;
   float tmpvar_11;
   tmpvar_11 = clamp (dot (viewDir_1, -(_mtl_u._TerrainTreeLightDirections[2])), 0.0, 1.0);
   tmpvar_11 = clamp (dot (viewDir_1, -(_mtl_u._TerrainTreeLightDirections[2])), 0.0, 1.0);
-  backContrib_10 = half(tmpvar_11);
+  tmpvar_10 = half(tmpvar_11);
   float3 tmpvar_12;
   float3 tmpvar_12;
   tmpvar_12.xy = tmpvar_9.xy;
   tmpvar_12.xy = tmpvar_9.xy;
-  tmpvar_12.z = float((backContrib_10 * (half)2.0));
+  tmpvar_12.z = float((tmpvar_10 * (half)2.0));
   tmpvar_2 = tmpvar_12;
   tmpvar_2 = tmpvar_12;
   _mtl_o.gl_Position = (_mtl_u.glstate_matrix_mvp * _mtl_i._glesVertex);
   _mtl_o.gl_Position = (_mtl_u.glstate_matrix_mvp * _mtl_i._glesVertex);
   _mtl_o.xlv_TEXCOORD2 = tmpvar_12;
   _mtl_o.xlv_TEXCOORD2 = tmpvar_12;

+ 1 - 1
3rdparty/glsl-optimizer/tests/vertex/inputs-outES3.txt

@@ -7,7 +7,7 @@ out mediump vec2 xlv_TEXCOORD0;
 out lowp vec4 xlv_TEXCOORD1;
 out lowp vec4 xlv_TEXCOORD1;
 void main ()
 void main ()
 {
 {
-  vec4 tmpvar_1;
+  highp vec4 tmpvar_1;
   tmpvar_1.xyz = normalize(_glesTANGENT.xyz);
   tmpvar_1.xyz = normalize(_glesTANGENT.xyz);
   tmpvar_1.w = _glesTANGENT.w;
   tmpvar_1.w = _glesTANGENT.w;
   lowp vec4 tmpvar_2;
   lowp vec4 tmpvar_2;

+ 8 - 10
3rdparty/glsl-optimizer/tests/vertex/inputs-outES3Metal.txt

@@ -16,20 +16,18 @@ struct xlatMtlShaderUniform {
 vertex xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]])
 vertex xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]])
 {
 {
   xlatMtlShaderOutput _mtl_o;
   xlatMtlShaderOutput _mtl_o;
-  float2 tmpvar_1;
-  tmpvar_1 = _mtl_i._glesMultiTexCoord0.xy;
+  half2 tmpvar_1;
+  tmpvar_1 = half2(_mtl_i._glesMultiTexCoord0.xy);
   float4 tmpvar_2;
   float4 tmpvar_2;
   tmpvar_2.xyz = normalize(_mtl_i._glesTANGENT.xyz);
   tmpvar_2.xyz = normalize(_mtl_i._glesTANGENT.xyz);
   tmpvar_2.w = _mtl_i._glesTANGENT.w;
   tmpvar_2.w = _mtl_i._glesTANGENT.w;
-  half2 uv_3;
-  uv_3 = half2(tmpvar_1);
-  half4 tmpvar_4;
-  tmpvar_4.xy = ((half2)(_mtl_i._glesMultiTexCoord0.xy * 0.3));
-  tmpvar_4.xyz = half3(((float3)tmpvar_4.xyz + ((tmpvar_2.xyz * 0.5) + 0.5)));
-  tmpvar_4.w = half(0.0);
+  half4 tmpvar_3;
+  tmpvar_3.xy = (tmpvar_1 * (half)0.3);
+  tmpvar_3.xyz = half3(((float3)tmpvar_3.xyz + ((tmpvar_2.xyz * 0.5) + 0.5)));
+  tmpvar_3.w = half(0.0);
   _mtl_o.gl_Position = (_mtl_u.glstate_matrix_mvp * _mtl_i._glesVertex);
   _mtl_o.gl_Position = (_mtl_u.glstate_matrix_mvp * _mtl_i._glesVertex);
-  _mtl_o.xlv_TEXCOORD0 = uv_3;
-  _mtl_o.xlv_TEXCOORD1 = tmpvar_4;
+  _mtl_o.xlv_TEXCOORD0 = tmpvar_1;
+  _mtl_o.xlv_TEXCOORD1 = tmpvar_3;
   return _mtl_o;
   return _mtl_o;
 }
 }
 
 

+ 2 - 2
3rdparty/glsl-optimizer/tests/vertex/loops-for-withvec4-outES3.txt

@@ -40,13 +40,13 @@ vec4 Temp_0;
 vec4 Temp_1;
 vec4 Temp_1;
 vec4 Temp_2;
 vec4 Temp_2;
 vec4 Temp_3;
 vec4 Temp_3;
-int tmpvar_1;
+highp int tmpvar_1;
 void main ()
 void main ()
 {
 {
   Temp_0 = (dcl_Input0_POSITION0.yyyy * glstate_matrix_mvp[1]);
   Temp_0 = (dcl_Input0_POSITION0.yyyy * glstate_matrix_mvp[1]);
   Temp_0 = ((glstate_matrix_mvp[0] * dcl_Input0_POSITION0.xxxx) + Temp_0);
   Temp_0 = ((glstate_matrix_mvp[0] * dcl_Input0_POSITION0.xxxx) + Temp_0);
   Temp_0 = ((glstate_matrix_mvp[2] * dcl_Input0_POSITION0.zzzz) + Temp_0);
   Temp_0 = ((glstate_matrix_mvp[2] * dcl_Input0_POSITION0.zzzz) + Temp_0);
-  vec4 tmpvar_2;
+  highp vec4 tmpvar_2;
   tmpvar_2 = ((glstate_matrix_mvp[3] * dcl_Input0_POSITION0.wwww) + Temp_0);
   tmpvar_2 = ((glstate_matrix_mvp[3] * dcl_Input0_POSITION0.wwww) + Temp_0);
   VtxGeoOutput1_TEXCOORD0.xy = ((dcl_Input2_TEXCOORD0.xyxx * _MainTex_ST.xyxx) + _MainTex_ST.zwzz).xy;
   VtxGeoOutput1_TEXCOORD0.xy = ((dcl_Input2_TEXCOORD0.xyxx * _MainTex_ST.xyxx) + _MainTex_ST.zwzz).xy;
   Temp_0.xyz = (dcl_Input0_POSITION0.yyyy * glstate_matrix_modelview0[1].xyzx).xyz;
   Temp_0.xyz = (dcl_Input0_POSITION0.yyyy * glstate_matrix_modelview0[1].xyzx).xyz;

+ 86 - 0
3rdparty/glsl-optimizer/tests/vertex/loops-for-withvec4inductorW-inES3.txt

@@ -0,0 +1,86 @@
+#version 300 es
+
+// This was produced at one point from Unity's Reflect/VertexLit
+// shader's "Vertex Lit, emulated in shaders" pass by hlslcc.
+// Loop analysis was not detecting that Temp_int[0] is used as
+// both a loop induction variable (.w component) and for other uses
+// outside the loop.
+
+precision highp float;
+
+uniform     vec4 unity_LightColor[8];
+uniform     vec4 unity_LightPosition[8];
+uniform     vec4 unity_LightAtten[8];
+uniform     vec4 unity_SpotDirection[8];
+uniform     mat4 glstate_matrix_mvp;
+uniform     mat4 glstate_matrix_modelview0;
+uniform     mat4 glstate_matrix_invtrans_modelview0;
+uniform     mat4 _Object2World;
+uniform     mat4 _World2Object;
+uniform     vec4 glstate_lightmodel_ambient;
+uniform     vec4 _MainTex_ST;
+uniform     vec4 _Color;
+uniform     vec4 _ReflectColor;
+ in highp vec4 in_POSITION0;
+vec4 Input0;
+ in highp vec4 in_NORMAL0;
+vec4 Input1;
+ in highp vec4 in_TEXCOORD0;
+vec4 Input2;
+ out highp vec4 TEXCOORD0;
+#define Output0 TEXCOORD0
+ out highp vec4 COLOR0;
+#define Output1 COLOR0
+#undef Output2
+#define Output2 phase0_Output2
+vec4 phase0_Output2;
+vec4 Temp[4];
+ivec4 Temp_int[4];
+void main()
+{
+    Input0 = in_POSITION0;
+    Input1 = in_NORMAL0;
+    Input2 = in_TEXCOORD0;
+    Temp_int[0] = floatBitsToInt(Input0.yyyy * glstate_matrix_mvp[1]);
+    Temp_int[0] = floatBitsToInt(glstate_matrix_mvp[0] * Input0.xxxx + intBitsToFloat(Temp_int[0]));
+    Temp_int[0] = floatBitsToInt(glstate_matrix_mvp[2] * Input0.zzzz + intBitsToFloat(Temp_int[0]));
+    Output2 = glstate_matrix_mvp[3] * Input0.wwww + intBitsToFloat(Temp_int[0]);
+    Output0.xy = Input2.xy * _MainTex_ST.xy + _MainTex_ST.zw;
+    Temp_int[0].xyz = floatBitsToInt(Input0.yyy * glstate_matrix_modelview0[1].xyz);
+    Temp_int[0].xyz = floatBitsToInt(glstate_matrix_modelview0[0].xyz * Input0.xxx + intBitsToFloat(Temp_int[0]).xyz);
+    Temp_int[0].xyz = floatBitsToInt(glstate_matrix_modelview0[2].xyz * Input0.zzz + intBitsToFloat(Temp_int[0]).xyz);
+    Temp_int[0].xyz = floatBitsToInt(glstate_matrix_modelview0[3].xyz * Input0.www + intBitsToFloat(Temp_int[0]).xyz);
+    Temp_int[1].xyz = floatBitsToInt(Input1.yyy * glstate_matrix_invtrans_modelview0[1].xyz);
+    Temp_int[1].xyz = floatBitsToInt(glstate_matrix_invtrans_modelview0[0].xyz * Input1.xxx + intBitsToFloat(Temp_int[1]).xyz);
+    Temp_int[1].xyz = floatBitsToInt(glstate_matrix_invtrans_modelview0[2].xyz * Input1.zzz + intBitsToFloat(Temp_int[1]).xyz);
+    Temp_int[0].w = floatBitsToInt(dot(intBitsToFloat(Temp_int[1]).xyz, intBitsToFloat(Temp_int[1]).xyz));
+    Temp_int[0].w = floatBitsToInt(inversesqrt(intBitsToFloat(Temp_int[0]).w));
+    Temp_int[1].xyz = floatBitsToInt(intBitsToFloat(Temp_int[0]).www * intBitsToFloat(Temp_int[1]).xyz);
+    Temp[2].xyz = glstate_lightmodel_ambient.xyz;
+    Temp_int[0].w = 0x0;
+    while(true){
+        if ((Temp_int[0].w>= 0x4)) { break; }
+        Temp_int[1].w = int((Temp_int[0].w>=0x4) ? 0xFFFFFFFFu : 0u);
+        Temp[3].xyz = (-intBitsToFloat(Temp_int[0]).xyz) * unity_LightPosition[Temp_int[0].w + 0].www + unity_LightPosition[Temp_int[0].w + 0].xyz;
+        Temp_int[1].w = floatBitsToInt(dot(Temp[3].xyz, Temp[3].xyz));
+        Temp[2].w = inversesqrt(intBitsToFloat(Temp_int[1]).w);
+        Temp[3].xyz = Temp[2].www * Temp[3].xyz;
+        Temp_int[1].w = floatBitsToInt(intBitsToFloat(Temp_int[1]).w * unity_LightAtten[Temp_int[0].w + 0].z + intBitsToFloat(0x3F800000));
+        Temp_int[1].w = floatBitsToInt(float(intBitsToFloat(0x3F800000)) / intBitsToFloat(Temp_int[1]).w);
+        Temp[2].w = dot(Temp[3].xyz, unity_SpotDirection[Temp_int[0].w + 0].xyz);
+        Temp[2].w = max(Temp[2].w, intBitsToFloat(0x0));
+        Temp[2].w = Temp[2].w + (-unity_LightAtten[Temp_int[0].w + 0].x);
+        Temp[2].w = Temp[2].w * unity_LightAtten[Temp_int[0].w + 0].y;
+        Temp[2].w = clamp(Temp[2].w, 0.0, 1.0);
+        Temp_int[1].w = floatBitsToInt(intBitsToFloat(Temp_int[1]).w * Temp[2].w);
+        Temp[2].w = dot(intBitsToFloat(Temp_int[1]).xyz, Temp[3].xyz);
+        Temp[2].w = max(Temp[2].w, intBitsToFloat(0x0));
+        Temp_int[1].w = floatBitsToInt(intBitsToFloat(Temp_int[1]).w * Temp[2].w);
+        Temp[2].xyz = unity_LightColor[Temp_int[0].w + 0].xyz * intBitsToFloat(Temp_int[1]).www + Temp[2].xyz;
+        Temp_int[0].w = Temp_int[0].w + 0x1;
+    }
+    Output1.xyz = Temp[2].xyz * _Color.xyz;
+    Output1.w = _Color.w * _ReflectColor.w;
+    gl_Position = vec4(phase0_Output2);
+    return;
+}

+ 87 - 0
3rdparty/glsl-optimizer/tests/vertex/loops-for-withvec4inductorW-outES3.txt

@@ -0,0 +1,87 @@
+#version 300 es
+precision highp float;
+uniform vec4 unity_LightColor[8];
+uniform vec4 unity_LightPosition[8];
+uniform vec4 unity_LightAtten[8];
+uniform vec4 unity_SpotDirection[8];
+uniform mat4 glstate_matrix_mvp;
+uniform mat4 glstate_matrix_modelview0;
+uniform mat4 glstate_matrix_invtrans_modelview0;
+uniform vec4 glstate_lightmodel_ambient;
+uniform vec4 _MainTex_ST;
+uniform vec4 _Color;
+uniform vec4 _ReflectColor;
+in highp vec4 in_POSITION0;
+in highp vec4 in_NORMAL0;
+in highp vec4 in_TEXCOORD0;
+out highp vec4 TEXCOORD0;
+out highp vec4 COLOR0;
+highp vec4 phase0_Output2;
+highp vec4 Temp_2;
+highp vec4 Temp_3;
+highp ivec4 Temp_int_0;
+highp ivec4 Temp_int_1;
+void main ()
+{
+  Temp_int_0 = floatBitsToInt((in_POSITION0.yyyy * glstate_matrix_mvp[1]));
+  Temp_int_0 = floatBitsToInt(((glstate_matrix_mvp[0] * in_POSITION0.xxxx) + intBitsToFloat(Temp_int_0)));
+  Temp_int_0 = floatBitsToInt(((glstate_matrix_mvp[2] * in_POSITION0.zzzz) + intBitsToFloat(Temp_int_0)));
+  phase0_Output2 = ((glstate_matrix_mvp[3] * in_POSITION0.wwww) + intBitsToFloat(Temp_int_0));
+  TEXCOORD0.xy = ((in_TEXCOORD0.xy * _MainTex_ST.xy) + _MainTex_ST.zw);
+  Temp_int_0.xyz = floatBitsToInt((in_POSITION0.yyy * glstate_matrix_modelview0[1].xyz));
+  Temp_int_0.xyz = floatBitsToInt(((glstate_matrix_modelview0[0].xyz * in_POSITION0.xxx) + intBitsToFloat(Temp_int_0).xyz));
+  Temp_int_0.xyz = floatBitsToInt(((glstate_matrix_modelview0[2].xyz * in_POSITION0.zzz) + intBitsToFloat(Temp_int_0).xyz));
+  Temp_int_0.xyz = floatBitsToInt(((glstate_matrix_modelview0[3].xyz * in_POSITION0.www) + intBitsToFloat(Temp_int_0).xyz));
+  Temp_int_1.xyz = floatBitsToInt((in_NORMAL0.yyy * glstate_matrix_invtrans_modelview0[1].xyz));
+  Temp_int_1.xyz = floatBitsToInt(((glstate_matrix_invtrans_modelview0[0].xyz * in_NORMAL0.xxx) + intBitsToFloat(Temp_int_1).xyz));
+  Temp_int_1.xyz = floatBitsToInt(((glstate_matrix_invtrans_modelview0[2].xyz * in_NORMAL0.zzz) + intBitsToFloat(Temp_int_1).xyz));
+  Temp_int_0.w = floatBitsToInt(dot (intBitsToFloat(Temp_int_1).xyz, intBitsToFloat(Temp_int_1).xyz));
+  Temp_int_0.w = floatBitsToInt(inversesqrt(intBitsToFloat(Temp_int_0).w));
+  Temp_int_1.xyz = floatBitsToInt((intBitsToFloat(Temp_int_0).www * intBitsToFloat(Temp_int_1).xyz));
+  Temp_2.xyz = glstate_lightmodel_ambient.xyz;
+  Temp_int_0.w = 0;
+  for (; Temp_int_0.w < 4; Temp_int_0.w = (Temp_int_0.w + 1)) {
+    Temp_3.xyz = ((-(
+      intBitsToFloat(Temp_int_0)
+    .xyz) * unity_LightPosition[Temp_int_0.w].www) + unity_LightPosition[Temp_int_0.w].xyz);
+    Temp_int_1.w = floatBitsToInt(dot (Temp_3.xyz, Temp_3.xyz));
+    Temp_2.w = inversesqrt(intBitsToFloat(Temp_int_1).w);
+    Temp_3.xyz = (Temp_2.www * Temp_3.xyz);
+    Temp_int_1.w = floatBitsToInt(((
+      intBitsToFloat(Temp_int_1)
+    .w * unity_LightAtten[Temp_int_0.w].z) + 1.0));
+    Temp_int_1.w = floatBitsToInt((1.0/(intBitsToFloat(Temp_int_1).w)));
+    Temp_2.w = dot (Temp_3.xyz, unity_SpotDirection[Temp_int_0.w].xyz);
+    Temp_2.w = max (Temp_2.w, 0.0);
+    Temp_2.w = (Temp_2.w - unity_LightAtten[Temp_int_0.w].x);
+    Temp_2.w = (Temp_2.w * unity_LightAtten[Temp_int_0.w].y);
+    Temp_2.w = clamp (Temp_2.w, 0.0, 1.0);
+    Temp_int_1.w = floatBitsToInt((intBitsToFloat(Temp_int_1).w * Temp_2.w));
+    Temp_2.w = dot (intBitsToFloat(Temp_int_1).xyz, Temp_3.xyz);
+    Temp_2.w = max (Temp_2.w, 0.0);
+    Temp_int_1.w = floatBitsToInt((intBitsToFloat(Temp_int_1).w * Temp_2.w));
+    Temp_2.xyz = ((unity_LightColor[Temp_int_0.w].xyz * intBitsToFloat(Temp_int_1).www) + Temp_2.xyz);
+  };
+  COLOR0.xyz = (Temp_2.xyz * _Color.xyz);
+  COLOR0.w = (_Color.w * _ReflectColor.w);
+  gl_Position = phase0_Output2;
+}
+
+
+// stats: 88 alu 0 tex 2 flow
+// inputs: 3
+//  #0: in_POSITION0 (high float) 4x1 [-1]
+//  #1: in_NORMAL0 (high float) 4x1 [-1]
+//  #2: in_TEXCOORD0 (high float) 4x1 [-1]
+// uniforms: 11 (total size: 0)
+//  #0: unity_LightColor (high float) 4x1 [8]
+//  #1: unity_LightPosition (high float) 4x1 [8]
+//  #2: unity_LightAtten (high float) 4x1 [8]
+//  #3: unity_SpotDirection (high float) 4x1 [8]
+//  #4: glstate_matrix_mvp (high float) 4x4 [-1]
+//  #5: glstate_matrix_modelview0 (high float) 4x4 [-1]
+//  #6: glstate_matrix_invtrans_modelview0 (high float) 4x4 [-1]
+//  #7: glstate_lightmodel_ambient (high float) 4x1 [-1]
+//  #8: _MainTex_ST (high float) 4x1 [-1]
+//  #9: _Color (high float) 4x1 [-1]
+//  #10: _ReflectColor (high float) 4x1 [-1]

+ 97 - 0
3rdparty/glsl-optimizer/tests/vertex/loops-for-withvec4inductorW-outES3Metal.txt

@@ -0,0 +1,97 @@
+#include <metal_stdlib>
+using namespace metal;
+struct xlatMtlShaderInput {
+  float4 in_POSITION0 [[attribute(0)]];
+  float4 in_NORMAL0 [[attribute(1)]];
+  float4 in_TEXCOORD0 [[attribute(2)]];
+};
+struct xlatMtlShaderOutput {
+  float4 gl_Position [[position]];
+  float4 TEXCOORD0;
+  float4 COLOR0;
+};
+struct xlatMtlShaderUniform {
+  float4 unity_LightColor[8];
+  float4 unity_LightPosition[8];
+  float4 unity_LightAtten[8];
+  float4 unity_SpotDirection[8];
+  float4x4 glstate_matrix_mvp;
+  float4x4 glstate_matrix_modelview0;
+  float4x4 glstate_matrix_invtrans_modelview0;
+  float4 glstate_lightmodel_ambient;
+  float4 _MainTex_ST;
+  float4 _Color;
+  float4 _ReflectColor;
+};
+;
+vertex xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]])
+{
+  xlatMtlShaderOutput _mtl_o;
+float4 phase0_Output2_1;
+float4 Temp_2_2;
+float4 Temp_3_3;
+int4 Temp_int_0_4;
+int4 Temp_int_1_5;
+  Temp_int_0_4 = as_type<int4>((_mtl_i.in_POSITION0.yyyy * _mtl_u.glstate_matrix_mvp[1]));
+  Temp_int_0_4 = as_type<int4>(((_mtl_u.glstate_matrix_mvp[0] * _mtl_i.in_POSITION0.xxxx) + as_type<float4>(Temp_int_0_4)));
+  Temp_int_0_4 = as_type<int4>(((_mtl_u.glstate_matrix_mvp[2] * _mtl_i.in_POSITION0.zzzz) + as_type<float4>(Temp_int_0_4)));
+  phase0_Output2_1 = ((_mtl_u.glstate_matrix_mvp[3] * _mtl_i.in_POSITION0.wwww) + as_type<float4>(Temp_int_0_4));
+  _mtl_o.TEXCOORD0.xy = ((_mtl_i.in_TEXCOORD0.xy * _mtl_u._MainTex_ST.xy) + _mtl_u._MainTex_ST.zw);
+  Temp_int_0_4.xyz = as_type<int3>((_mtl_i.in_POSITION0.yyy * _mtl_u.glstate_matrix_modelview0[1].xyz));
+  Temp_int_0_4.xyz = as_type<int3>(((_mtl_u.glstate_matrix_modelview0[0].xyz * _mtl_i.in_POSITION0.xxx) + as_type<float4>(Temp_int_0_4).xyz));
+  Temp_int_0_4.xyz = as_type<int3>(((_mtl_u.glstate_matrix_modelview0[2].xyz * _mtl_i.in_POSITION0.zzz) + as_type<float4>(Temp_int_0_4).xyz));
+  Temp_int_0_4.xyz = as_type<int3>(((_mtl_u.glstate_matrix_modelview0[3].xyz * _mtl_i.in_POSITION0.www) + as_type<float4>(Temp_int_0_4).xyz));
+  Temp_int_1_5.xyz = as_type<int3>((_mtl_i.in_NORMAL0.yyy * _mtl_u.glstate_matrix_invtrans_modelview0[1].xyz));
+  Temp_int_1_5.xyz = as_type<int3>(((_mtl_u.glstate_matrix_invtrans_modelview0[0].xyz * _mtl_i.in_NORMAL0.xxx) + as_type<float4>(Temp_int_1_5).xyz));
+  Temp_int_1_5.xyz = as_type<int3>(((_mtl_u.glstate_matrix_invtrans_modelview0[2].xyz * _mtl_i.in_NORMAL0.zzz) + as_type<float4>(Temp_int_1_5).xyz));
+  Temp_int_0_4.w = as_type<int>(dot (as_type<float4>(Temp_int_1_5).xyz, as_type<float4>(Temp_int_1_5).xyz));
+  Temp_int_0_4.w = as_type<int>(rsqrt(as_type<float4>(Temp_int_0_4).w));
+  Temp_int_1_5.xyz = as_type<int3>((as_type<float4>(Temp_int_0_4).www * as_type<float4>(Temp_int_1_5).xyz));
+  Temp_2_2.xyz = _mtl_u.glstate_lightmodel_ambient.xyz;
+  Temp_int_0_4.w = 0;
+  for (; Temp_int_0_4.w < 4; Temp_int_0_4.w = (Temp_int_0_4.w + 1)) {
+    Temp_3_3.xyz = ((-(
+      as_type<float4>(Temp_int_0_4)
+    .xyz) * _mtl_u.unity_LightPosition[Temp_int_0_4.w].www) + _mtl_u.unity_LightPosition[Temp_int_0_4.w].xyz);
+    Temp_int_1_5.w = as_type<int>(dot (Temp_3_3.xyz, Temp_3_3.xyz));
+    Temp_2_2.w = rsqrt(as_type<float4>(Temp_int_1_5).w);
+    Temp_3_3.xyz = (Temp_2_2.www * Temp_3_3.xyz);
+    Temp_int_1_5.w = as_type<int>(((
+      as_type<float4>(Temp_int_1_5)
+    .w * _mtl_u.unity_LightAtten[Temp_int_0_4.w].z) + 1.0));
+    Temp_int_1_5.w = as_type<int>((1.0/(as_type<float4>(Temp_int_1_5).w)));
+    Temp_2_2.w = dot (Temp_3_3.xyz, _mtl_u.unity_SpotDirection[Temp_int_0_4.w].xyz);
+    Temp_2_2.w = max (Temp_2_2.w, 0.0);
+    Temp_2_2.w = (Temp_2_2.w - _mtl_u.unity_LightAtten[Temp_int_0_4.w].x);
+    Temp_2_2.w = (Temp_2_2.w * _mtl_u.unity_LightAtten[Temp_int_0_4.w].y);
+    Temp_2_2.w = clamp (Temp_2_2.w, 0.0, 1.0);
+    Temp_int_1_5.w = as_type<int>((as_type<float4>(Temp_int_1_5).w * Temp_2_2.w));
+    Temp_2_2.w = dot (as_type<float4>(Temp_int_1_5).xyz, Temp_3_3.xyz);
+    Temp_2_2.w = max (Temp_2_2.w, 0.0);
+    Temp_int_1_5.w = as_type<int>((as_type<float4>(Temp_int_1_5).w * Temp_2_2.w));
+    Temp_2_2.xyz = ((_mtl_u.unity_LightColor[Temp_int_0_4.w].xyz * as_type<float4>(Temp_int_1_5).www) + Temp_2_2.xyz);
+  };
+  _mtl_o.COLOR0.xyz = (Temp_2_2.xyz * _mtl_u._Color.xyz);
+  _mtl_o.COLOR0.w = (_mtl_u._Color.w * _mtl_u._ReflectColor.w);
+  _mtl_o.gl_Position = phase0_Output2_1;
+  return _mtl_o;
+}
+
+
+// stats: 88 alu 0 tex 2 flow
+// inputs: 3
+//  #0: in_POSITION0 (high float) 4x1 [-1] loc 0
+//  #1: in_NORMAL0 (high float) 4x1 [-1] loc 1
+//  #2: in_TEXCOORD0 (high float) 4x1 [-1] loc 2
+// uniforms: 11 (total size: 768)
+//  #0: unity_LightColor (high float) 4x1 [8] loc 0
+//  #1: unity_LightPosition (high float) 4x1 [8] loc 128
+//  #2: unity_LightAtten (high float) 4x1 [8] loc 256
+//  #3: unity_SpotDirection (high float) 4x1 [8] loc 384
+//  #4: glstate_matrix_mvp (high float) 4x4 [-1] loc 512
+//  #5: glstate_matrix_modelview0 (high float) 4x4 [-1] loc 576
+//  #6: glstate_matrix_invtrans_modelview0 (high float) 4x4 [-1] loc 640
+//  #7: glstate_lightmodel_ambient (high float) 4x1 [-1] loc 704
+//  #8: _MainTex_ST (high float) 4x1 [-1] loc 720
+//  #9: _Color (high float) 4x1 [-1] loc 736
+//  #10: _ReflectColor (high float) 4x1 [-1] loc 752

+ 4 - 4
3rdparty/glsl-optimizer/tests/vertex/opt-matrix-transpose-mul-outES3.txt

@@ -19,7 +19,7 @@ void main ()
   lowp vec3 tmpvar_4;
   lowp vec3 tmpvar_4;
   lowp vec3 tmpvar_5;
   lowp vec3 tmpvar_5;
   highp mat3 tmpvar_6;
   highp mat3 tmpvar_6;
-  tmpvar_6[0u] = _Object2World[0].xyz;
+  tmpvar_6[uint(0)] = _Object2World[0].xyz;
   tmpvar_6[1u] = _Object2World[1].xyz;
   tmpvar_6[1u] = _Object2World[1].xyz;
   tmpvar_6[2u] = _Object2World[2].xyz;
   tmpvar_6[2u] = _Object2World[2].xyz;
   mediump vec3 tmpvar_7;
   mediump vec3 tmpvar_7;
@@ -31,9 +31,9 @@ void main ()
   tmpvar_8 = attrTangent.xyz;
   tmpvar_8 = attrTangent.xyz;
   tmpvar_9 = (((attrNormal.yzx * attrTangent.zxy) - (attrNormal.zxy * attrTangent.yzx)) * attrTangent.w);
   tmpvar_9 = (((attrNormal.yzx * attrTangent.zxy) - (attrNormal.zxy * attrTangent.yzx)) * attrTangent.w);
   mediump mat3 tmpvar_10;
   mediump mat3 tmpvar_10;
-  tmpvar_10[0u].x = tmpvar_8.x;
-  tmpvar_10[0u].y = tmpvar_9.x;
-  tmpvar_10[0u].z = attrNormal.x;
+  tmpvar_10[uint(0)].x = tmpvar_8.x;
+  tmpvar_10[uint(0)].y = tmpvar_9.x;
+  tmpvar_10[uint(0)].z = attrNormal.x;
   tmpvar_10[1u].x = tmpvar_8.y;
   tmpvar_10[1u].x = tmpvar_8.y;
   tmpvar_10[1u].y = tmpvar_9.y;
   tmpvar_10[1u].y = tmpvar_9.y;
   tmpvar_10[1u].z = attrNormal.y;
   tmpvar_10[1u].z = attrNormal.y;

+ 1 - 1
3rdparty/glsl-optimizer/tests/vertex/opt-normalize-out.txt

@@ -1,7 +1,7 @@
 varying vec3 var_a;
 varying vec3 var_a;
 void main ()
 void main ()
 {
 {
-  gl_Position = (gl_Vertex * vec4(0.182574, 0.365148, 0.547723, 0.730297));
+  gl_Position = (gl_Vertex * vec4(0.1825742, 0.3651484, 0.5477225, 0.7302967));
   var_a = (gl_Vertex.xyz * normalize(vec3(0.0, 0.0, 0.0)));
   var_a = (gl_Vertex.xyz * normalize(vec3(0.0, 0.0, 0.0)));
 }
 }
 
 

+ 1 - 1
3rdparty/glsl-optimizer/tests/vertex/uniforms-arrays-outES3.txt

@@ -30,7 +30,7 @@ void main ()
   tmpvar_8.xyz = tmpvar_1;
   tmpvar_8.xyz = tmpvar_1;
   viewpos_7 = (glstate_matrix_modelview0 * tmpvar_8).xyz;
   viewpos_7 = (glstate_matrix_modelview0 * tmpvar_8).xyz;
   highp mat3 tmpvar_9;
   highp mat3 tmpvar_9;
-  tmpvar_9[0u] = glstate_matrix_invtrans_modelview0[0u].xyz;
+  tmpvar_9[uint(0)] = glstate_matrix_invtrans_modelview0[uint(0)].xyz;
   tmpvar_9[1u] = glstate_matrix_invtrans_modelview0[1u].xyz;
   tmpvar_9[1u] = glstate_matrix_invtrans_modelview0[1u].xyz;
   tmpvar_9[2u] = glstate_matrix_invtrans_modelview0[2u].xyz;
   tmpvar_9[2u] = glstate_matrix_invtrans_modelview0[2u].xyz;
   viewN_6 = (tmpvar_9 * n_2);
   viewN_6 = (tmpvar_9 * n_2);

+ 121 - 0
3rdparty/glsl-optimizer/tests/vertex/z-NichsHybridLightVectorInsertBug-in.txt

@@ -0,0 +1,121 @@
+// stripped down version of Nicholas' Static Sky
+// hybrid lighting shader that exposed vector_insert_todo
+// bug
+
+vec4 xll_tex2Dlod(sampler2D s, vec4 coord) {
+   return texture2DLod( s, coord.xy, coord.w);
+}
+mat3 xll_constructMat3_mf4x4( mat4 m) {
+  return mat3( vec3( m[0]), vec3( m[1]), vec3( m[2]));
+}
+struct Lamp {
+    vec4 posRange;
+    vec4 colorImp;
+};
+struct v2f {
+    vec4 pos;
+    vec3 diffuse;
+};
+struct HybridAppData {
+    vec4 vertex;
+    vec4 tangent;
+    vec3 normal;
+    vec4 texcoord;
+    vec4 bakedCol;
+    vec2 bakedDir;
+};
+uniform vec3 _WorldSpaceCameraPos;
+uniform vec4 _ProjectionParams;
+uniform vec4 _ScreenParams;
+uniform vec4 _ZBufferParams;
+uniform vec4 _WorldSpaceLightPos0;
+
+uniform mat4 _Object2World;
+uniform mat4 _World2Object;
+
+
+
+uniform float _RenderExposure;
+uniform vec2 _DynLampInfo_bufferSize;
+uniform sampler2D _DynLampInfo;
+uniform float LightVertOffset;
+uniform sampler2D LightVertTexture;
+uniform vec4 LightVertTextureSize;
+void CalcDynamicLight( in vec3 worldVert, in vec3 worldNorm, in Lamp lamp[4], inout vec3 hybridDir, inout vec3 hybridCol ) {
+    vec4 atten;
+    int i = 0;
+    for ( ; (i < 4); (i++)) {
+       
+        vec3 lightToVert = (lamp[i].posRange.xyz - worldVert);
+        float lengthSq = dot( lightToVert, lightToVert);
+        vec3 lightToVertNorm = (lightToVert * inversesqrt(lengthSq));
+       
+        atten[i] = (lengthSq * lamp[i].posRange.w);
+        float nDotL = dot( lightToVertNorm, worldNorm);
+        float weight = (atten[i] * nDotL);
+    }
+   
+    int j = 0;
+    for ( ; (j < 4); (j++)) {
+        hybridCol += (lamp[j].colorImp.xyz * atten[j]);
+    }
+}
+void LoadBakedLight( out vec3 hybridCol, out vec3 hybridDir ) {
+}
+vec4 DoSampleGPUBuffer( in sampler2D buffer, in vec2 coord, in vec2 dimensions ) {
+    return xll_tex2Dlod( buffer, vec4( (coord / dimensions), 0.0, 0.0));
+}
+void ReadLightArray3( in ivec4 lightIdx, out Lamp l0, out Lamp l1, out Lamp l2, out Lamp l3 ) {
+   
+    l0.posRange = DoSampleGPUBuffer( _DynLampInfo, vec2( float(lightIdx.x), 1.0), _DynLampInfo_bufferSize);
+    l0.colorImp = DoSampleGPUBuffer( _DynLampInfo, vec2( float(lightIdx.x), 2.0), _DynLampInfo_bufferSize);
+    l1.posRange = DoSampleGPUBuffer( _DynLampInfo, vec2( float(lightIdx.y), 1.0), _DynLampInfo_bufferSize);
+   
+    l1.colorImp = DoSampleGPUBuffer( _DynLampInfo, vec2( float(lightIdx.y), 2.0), _DynLampInfo_bufferSize);
+    l2.posRange = DoSampleGPUBuffer( _DynLampInfo, vec2( float(lightIdx.z), 1.0), _DynLampInfo_bufferSize);
+    l2.colorImp = DoSampleGPUBuffer( _DynLampInfo, vec2( float(lightIdx.z), 2.0), _DynLampInfo_bufferSize);
+   
+    l3.posRange = DoSampleGPUBuffer( _DynLampInfo, vec2( float(lightIdx.w), 1.0), _DynLampInfo_bufferSize);
+    l3.colorImp = DoSampleGPUBuffer( _DynLampInfo, vec2( float(lightIdx.w), 2.0), _DynLampInfo_bufferSize);
+}
+void DoCalcHybridLight2( in vec3 worldVert, in vec3 worldNorm, out vec3 hybridCol, in vec4 bakedColor, in vec2 bakedDir ) {
+    vec3 hybridDir;
+    LoadBakedLight( hybridCol, hybridDir);
+   
+    ivec4 lightIdx = ivec4( int(worldVert.x), int(worldVert.y), int(worldVert.z), int((-worldVert.x)));
+    Lamp l[4];
+    ReadLightArray3( lightIdx, l[0], l[1], l[2], l[3]);
+   
+    CalcDynamicLight( worldVert, worldNorm, l, hybridDir, hybridCol);
+}
+vec3 CalcDiffuseHybridLight( in vec3 worldVert, in vec3 worldNorm, in vec4 bakedColor, in vec2 bakedDir ) {
+    vec3 hybridCol;
+    DoCalcHybridLight2( worldVert, worldNorm, hybridCol, bakedColor, bakedDir);
+   
+    return hybridCol;
+}
+v2f vert( in HybridAppData v ) {
+    v2f o;
+   
+    vec3 worldVert = (_Object2World * v.vertex).xyz;
+    vec3 worldNorm = normalize((xll_constructMat3_mf4x4( _Object2World) * v.normal.xyz));
+    o.diffuse = CalcDiffuseHybridLight( worldVert, worldNorm, v.bakedCol, v.bakedDir);
+   
+    o.pos = (gl_ModelViewProjectionMatrix * v.vertex);
+    return o;
+}
+attribute vec4 TANGENT;
+varying vec3 xlv_TEXCOORD2;
+void main() {
+    v2f xl_retval;
+    HybridAppData xlt_v;
+    xlt_v.vertex = vec4(gl_Vertex);
+    xlt_v.tangent = vec4(TANGENT);
+    xlt_v.normal = vec3(gl_Normal);
+    xlt_v.texcoord = vec4(gl_MultiTexCoord0);
+    xlt_v.bakedCol = vec4(gl_Color);
+    xlt_v.bakedDir = vec2(gl_MultiTexCoord1);
+    xl_retval = vert( xlt_v);
+    gl_Position = vec4(xl_retval.pos);
+    xlv_TEXCOORD2 = vec3(xl_retval.diffuse);
+}

Some files were not shown because too many files changed in this diff