[Mesa-dev] [PATCH 4/6] nir: Add native_integers to nir_shader_compiler_options.

Kenneth Graunke kenneth at whitecape.org
Fri Mar 6 02:17:54 PST 2015


glsl_to_nir, tgsi_to_nir, and prog_to_nir all want to know whether the
driver supports native integers.  Presumably other passes may as well.

Adding this to nir_shader_compiler_options is an easy way to provide
that information, as it's accessible via nir_shader::options.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/glsl/nir/glsl_to_nir.cpp             | 11 +++++------
 src/glsl/nir/glsl_to_nir.h               |  2 +-
 src/glsl/nir/nir.h                       |  6 ++++++
 src/mesa/drivers/dri/i965/brw_context.c  |  4 +++-
 src/mesa/drivers/dri/i965/brw_fs_nir.cpp |  2 +-
 5 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/glsl/nir/glsl_to_nir.cpp b/src/glsl/nir/glsl_to_nir.cpp
index 7e40ef4..0d96e03 100644
--- a/src/glsl/nir/glsl_to_nir.cpp
+++ b/src/glsl/nir/glsl_to_nir.cpp
@@ -43,7 +43,7 @@ namespace {
 class nir_visitor : public ir_visitor
 {
 public:
-   nir_visitor(nir_shader *shader, bool supports_ints);
+   nir_visitor(nir_shader *shader);
    ~nir_visitor();
 
    virtual void visit(ir_variable *);
@@ -125,12 +125,11 @@ private:
 }; /* end of anonymous namespace */
 
 nir_shader *
-glsl_to_nir(exec_list *ir, bool native_integers,
-            const nir_shader_compiler_options *options)
+glsl_to_nir(exec_list *ir, const nir_shader_compiler_options *options)
 {
    nir_shader *shader = nir_shader_create(NULL, options);
 
-   nir_visitor v1(shader, native_integers);
+   nir_visitor v1(shader);
    nir_function_visitor v2(&v1);
    v2.run(ir);
    visit_exec_list(ir, &v1);
@@ -138,9 +137,9 @@ glsl_to_nir(exec_list *ir, bool native_integers,
    return shader;
 }
 
-nir_visitor::nir_visitor(nir_shader *shader, bool supports_ints)
+nir_visitor::nir_visitor(nir_shader *shader)
 {
-   this->supports_ints = supports_ints;
+   this->supports_ints = shader->options->native_integers;
    this->shader = shader;
    this->is_global = true;
    this->var_table = _mesa_hash_table_create(NULL, _mesa_hash_pointer,
diff --git a/src/glsl/nir/glsl_to_nir.h b/src/glsl/nir/glsl_to_nir.h
index 7300945..dd62793 100644
--- a/src/glsl/nir/glsl_to_nir.h
+++ b/src/glsl/nir/glsl_to_nir.h
@@ -32,7 +32,7 @@
 extern "C" {
 #endif
 
-nir_shader *glsl_to_nir(exec_list *ir, bool native_integers,
+nir_shader *glsl_to_nir(exec_list *ir,
                         const nir_shader_compiler_options *options);
 
 #ifdef __cplusplus
diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h
index b935354..669a26e 100644
--- a/src/glsl/nir/nir.h
+++ b/src/glsl/nir/nir.h
@@ -1370,6 +1370,12 @@ typedef struct nir_shader_compiler_options {
    bool lower_fsqrt;
    /** lowers fneg and ineg to fsub and isub. */
    bool lower_negate;
+
+   /**
+    * Does the driver support real 32-bit integers?  (Otherwise, integers
+    * are simulated by floats.)
+    */
+   bool native_integers;
 } nir_shader_compiler_options;
 
 typedef struct nir_shader {
diff --git a/src/mesa/drivers/dri/i965/brw_context.c b/src/mesa/drivers/dri/i965/brw_context.c
index 892d4ca..03547e9 100644
--- a/src/mesa/drivers/dri/i965/brw_context.c
+++ b/src/mesa/drivers/dri/i965/brw_context.c
@@ -551,7 +551,9 @@ brw_initialize_context_constants(struct brw_context *brw)
       ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxInputComponents = 128;
    }
 
-   static const nir_shader_compiler_options nir_options = {};
+   static const nir_shader_compiler_options nir_options = {
+      .native_integers = true,
+   };
 
    /* We want the GLSL compiler to emit code that uses condition codes */
    for (int i = 0; i < MESA_SHADER_STAGES; i++) {
diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
index e24bf92..ccb5cea 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
@@ -87,7 +87,7 @@ fs_visitor::emit_nir_code()
 
    /* first, lower the GLSL IR shader to NIR */
    lower_output_reads(shader->base.ir);
-   nir_shader *nir = glsl_to_nir(shader->base.ir, true, options);
+   nir_shader *nir = glsl_to_nir(shader->base.ir, options);
    nir_validate_shader(nir);
 
    nir_lower_global_vars_to_local(nir);
-- 
2.2.1



More information about the mesa-dev mailing list