[Mesa-dev] [PATCH] glsl: add support for gl_InstanceID
Marcin Slusarz
marcin.slusarz at gmail.com
Thu Mar 10 15:30:30 PST 2011
...by copying support for gl_InstanceIDARB, but without "#extension" check,
because EXT_draw_instanced spec does not say anything about it (as opposed
to ARB_draw_instanced / gl_InstanceIDARB) and NVIDIA driver already allow it
---
I'm not sure this is correct.
With this patch applied (+ merged floating branch) I can run OilRush on nv50
(run == watch the game crash in a few seconds ;)
src/glsl/ir_variable.cpp | 25 +++++++++++++++++++++++++
1 files changed, 25 insertions(+), 0 deletions(-)
diff --git a/src/glsl/ir_variable.cpp b/src/glsl/ir_variable.cpp
index 18a3e0f..bd776ee 100644
--- a/src/glsl/ir_variable.cpp
+++ b/src/glsl/ir_variable.cpp
@@ -34,6 +34,10 @@ static void
generate_ARB_draw_instanced_variables(exec_list *,
struct _mesa_glsl_parse_state *,
bool, _mesa_glsl_parser_targets);
+static void
+generate_EXT_draw_instanced_variables(exec_list *,
+ struct _mesa_glsl_parse_state *,
+ bool, _mesa_glsl_parser_targets);
static ir_variable *
add_variable(const char *name, enum ir_variable_mode mode, int slot,
@@ -335,6 +339,8 @@ initialize_vs_variables(exec_list *instructions,
if (state->ARB_draw_instanced_enable)
generate_ARB_draw_instanced_variables(instructions, state, false,
vertex_shader);
+ generate_EXT_draw_instanced_variables(instructions, state, false,
+ vertex_shader);
}
@@ -454,6 +460,25 @@ generate_ARB_draw_instanced_variables(exec_list *instructions,
}
}
+static void
+generate_EXT_draw_instanced_variables(exec_list *instructions,
+ struct _mesa_glsl_parse_state *state,
+ bool warn,
+ _mesa_glsl_parser_targets target)
+{
+ /* gl_InstanceID is only available in the vertex shader.
+ */
+ if (target == vertex_shader) {
+ ir_variable *const inst =
+ add_variable("gl_InstanceID", ir_var_system_value,
+ SYSTEM_VALUE_INSTANCE_ID,
+ glsl_type::int_type, instructions, state->symbols);
+
+ if (warn)
+ inst->warn_extension = "GL_EXT_draw_instanced";
+ }
+}
+
static void
generate_ARB_shader_stencil_export_variables(exec_list *instructions,
--
1.7.2.2
More information about the mesa-dev
mailing list