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 3d2d280db126e3bac25d860ab4bb9ce196dcd621..725703d05883d59e631f1c83df8a5154479c76e9 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 f642c38561a77ddea75a803c2745f5fa17378c80..69d0554fbca1b815e4d147fc6c52f87f3bde5b13 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 d507e99d35237cc28adf40d9f8285a275810e2a1..fec96bac923d7329b83f56711240c0194bcc9c9c 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