nir/lower_system_values: Lower vertexID to id+base if needed
authorJason Ekstrand <jason.ekstrand@intel.com>
Sat, 16 Jan 2016 00:15:50 +0000 (16:15 -0800)
committerJason Ekstrand <jason.ekstrand@intel.com>
Sat, 16 Jan 2016 00:15:50 +0000 (16:15 -0800)
src/glsl/nir/nir.h
src/glsl/nir/nir_lower_system_values.c
src/mesa/drivers/dri/i965/brw_shader.cpp

index 3d2d280..725703d 100644 (file)
@@ -1534,6 +1534,9 @@ typedef struct nir_shader_compiler_options {
     * are simulated by floats.)
     */
    bool native_integers;
+
+   /* Indicates that the driver only has zero-based vertex id */
+   bool vertex_id_zero_based;
 } nir_shader_compiler_options;
 
 typedef struct nir_shader_info {
index f642c38..69d0554 100644 (file)
@@ -103,6 +103,16 @@ convert_block(nir_block *block, void *void_state)
          break;
       }
 
+      case SYSTEM_VALUE_VERTEX_ID:
+         if (b->shader->options->vertex_id_zero_based) {
+            sysval = nir_iadd(b,
+               nir_load_system_value(b, nir_intrinsic_load_vertex_id_zero_base, 0),
+               nir_load_system_value(b, nir_intrinsic_load_base_vertex, 0));
+         } else {
+            sysval = nir_load_system_value(b, nir_intrinsic_load_vertex_id, 0);
+         }
+         break;
+
       default: {
          nir_intrinsic_op sysval_op =
             nir_intrinsic_from_system_value(var->data.location);
index d507e99..fec96ba 100644 (file)
@@ -96,6 +96,7 @@ brw_compiler_create(void *mem_ctx, const struct brw_device_info *devinfo)
    nir_shader_compiler_options *nir_options =
       rzalloc(compiler, nir_shader_compiler_options);
    nir_options->native_integers = true;
+   nir_options->vertex_id_zero_based = true;
    nir_options->lower_fdiv = true;
    /* In order to help allow for better CSE at the NIR level we tell NIR
     * to split all ffma instructions during opt_algebraic and we then