From f509a890828dc54ffc113a581147ccfa8408b082 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Fri, 15 Jan 2016 16:15:50 -0800 Subject: [PATCH] nir/lower_system_values: Lower vertexID to id+base if needed --- src/glsl/nir/nir.h | 3 +++ src/glsl/nir/nir_lower_system_values.c | 10 ++++++++++ src/mesa/drivers/dri/i965/brw_shader.cpp | 1 + 3 files changed, 14 insertions(+) diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h index 3d2d280..725703d 100644 --- a/src/glsl/nir/nir.h +++ b/src/glsl/nir/nir.h @@ -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 { diff --git a/src/glsl/nir/nir_lower_system_values.c b/src/glsl/nir/nir_lower_system_values.c index f642c38..69d0554 100644 --- a/src/glsl/nir/nir_lower_system_values.c +++ b/src/glsl/nir/nir_lower_system_values.c @@ -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); diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp index d507e99..fec96ba 100644 --- a/src/mesa/drivers/dri/i965/brw_shader.cpp +++ b/src/mesa/drivers/dri/i965/brw_shader.cpp @@ -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 -- 2.7.4