Hi everyone,

If your Mesa driver supports GL3 or EXT_texture_array or ARB_draw_instanced, 
Unigine is broken for you. (I tested Unigine Sanctuary and Unigine Heaven, the 
others probably won't be any different)

The only way to make it work seems to be to relax some requirements of the GL 
spec and extensions (i.e. being non-compliant and non-portable in theory, but 
actually being very portable in practice). There are probably more ways to go 
about it. The patch below fixes softpipe and r600g. I think we should discuss 
this and come up with some solution, otherwise Unigine will be broken forever. 
It doesn't have to be exactly like this patch. I think that if we go with an 
out-of-spec behavior, we should print a compiler warning at least.

>From what I gathered, Unigine behaves like this:
if (ARB_draw_instanced) use gl_InstanceID;
if (EXT_texture_array || GL3) use sampler2DArrayShadow;

There are no GLSL preprocessor directives in any shader in Unigine whatsoever.

Comments welcome.

Marek

---
 src/glsl/builtin_variables.cpp  |   22 +++++++++++++++-------
 src/glsl/glsl_parser_extras.cpp |    4 ++++
 src/glsl/glsl_parser_extras.h   |    1 +
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/glsl/builtin_variables.cpp b/src/glsl/builtin_variables.cpp
index ed6b922..a1ecf56 100644
--- a/src/glsl/builtin_variables.cpp
+++ b/src/glsl/builtin_variables.cpp
@@ -761,7 +761,7 @@ initialize_vs_variables(exec_list *instructions,
       break;
    }
 
-   if (state->ARB_draw_instanced_enable)
+   if (state->ARB_draw_instanced_supported)
       generate_ARB_draw_instanced_variables(instructions, state, false,
                                             vertex_shader);
 }
@@ -870,13 +870,21 @@ generate_ARB_draw_instanced_variables(exec_list 
*instructions,
    /* gl_InstanceIDARB is only available in the vertex shader.
     */
    if (target == vertex_shader) {
-      ir_variable *const inst =
-         add_variable(instructions, state->symbols,
-                     "gl_InstanceIDARB", glsl_type::int_type,
-                     ir_var_system_value, SYSTEM_VALUE_INSTANCE_ID);
+      if (state->ARB_draw_instanced_enable) {
+         ir_variable *const inst =
+            add_variable(instructions, state->symbols,
+                         "gl_InstanceIDARB", glsl_type::int_type,
+                         ir_var_system_value, SYSTEM_VALUE_INSTANCE_ID);
+
+         if (warn)
+            inst->warn_extension = "GL_ARB_draw_instanced";
+      }
 
-      if (warn)
-         inst->warn_extension = "GL_ARB_draw_instanced";
+      /* Fixup for Unigine: declare gl_InstanceID if ARB_draw_instanced is
+       * supported. */
+      add_variable(instructions, state->symbols,
+                   "gl_InstanceID", glsl_type::int_type,
+                   ir_var_system_value, SYSTEM_VALUE_INSTANCE_ID);
    }
 }
 
diff --git a/src/glsl/glsl_parser_extras.cpp b/src/glsl/glsl_parser_extras.cpp
index 0b53232..65dd928 100644
--- a/src/glsl/glsl_parser_extras.cpp
+++ b/src/glsl/glsl_parser_extras.cpp
@@ -60,6 +60,10 @@ _mesa_glsl_parse_state::_mesa_glsl_parse_state(struct 
gl_context *ctx,
    this->es_shader = false;
    this->ARB_texture_rectangle_enable = true;
 
+   /* Out-of-spec fixups for Unigine. */
+   this->EXT_texture_array_enable = ctx->Extensions.EXT_texture_array;
+   this->ARB_draw_instanced_supported = ctx->Extensions.ARB_draw_instanced;
+
    /* OpenGL ES 2.0 has different defaults from desktop GL. */
    if (ctx->API == API_OPENGLES2) {
       this->language_version = 100;
diff --git a/src/glsl/glsl_parser_extras.h b/src/glsl/glsl_parser_extras.h
index dd93295..97c3107 100644
--- a/src/glsl/glsl_parser_extras.h
+++ b/src/glsl/glsl_parser_extras.h
@@ -172,6 +172,7 @@ struct _mesa_glsl_parse_state {
    bool ARB_draw_buffers_warn;
    bool ARB_draw_instanced_enable;
    bool ARB_draw_instanced_warn;
+   bool ARB_draw_instanced_supported;
    bool ARB_explicit_attrib_location_enable;
    bool ARB_explicit_attrib_location_warn;
    bool ARB_fragment_coord_conventions_enable;
-- 
1.7.5.4

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to