[Mesa-dev] [PATCH] i965: Implement get_nir_src_imm() helpers.

Kenneth Graunke kenneth at whitecape.org
Wed Dec 2 00:26:05 PST 2015


Normally, get_nir_src() won't return an immediate value - it moves it to
a temporary VGRF.  There are consumers of get_nir_src() that rely on
this, and are unprepared to handle immediate values.

This patch introduces new helpers which return immediates for single
component constant values, and VGRFs for other values.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/drivers/dri/i965/brw_fs.h         |  1 +
 src/mesa/drivers/dri/i965/brw_fs_nir.cpp   | 11 +++++++++++
 src/mesa/drivers/dri/i965/brw_vec4.h       |  1 +
 src/mesa/drivers/dri/i965/brw_vec4_nir.cpp |  7 +++++++
 4 files changed, 20 insertions(+)

I'm using this in my tessellation branch, but I noticed Jason open-coding
this pattern in a bunch of his recent patches, so I thought I'd send it out
a bit early in case he wanted to use it, too.

diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
index bca4589..ce3bdef 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.h
+++ b/src/mesa/drivers/dri/i965/brw_fs.h
@@ -256,6 +256,7 @@ public:
    void nir_emit_jump(const brw::fs_builder &bld,
                       nir_jump_instr *instr);
    fs_reg get_nir_src(nir_src src);
+   fs_reg get_nir_src_imm(nir_src src);
    fs_reg get_nir_dest(nir_dest dest);
    fs_reg get_nir_image_deref(const nir_deref_var *deref);
    void emit_percomp(const brw::fs_builder &bld, const fs_inst &inst,
diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
index 9b50e4e..fc71a0f 100644
--- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
@@ -1136,6 +1136,17 @@ fs_visitor::get_nir_src(nir_src src)
    return retype(reg, BRW_REGISTER_TYPE_D);
 }
 
+/**
+ * Return an IMM for constants; otherwise call get_nir_src() as normal.
+ */
+fs_reg
+fs_visitor::get_nir_src_imm(nir_src src)
+{
+   nir_const_value *val = nir_src_as_const_value(src);
+   return val && src.ssa->num_components == 1 ? fs_reg(brw_imm_d(val->i[0]))
+                                              : get_nir_src(src);
+}
+
 fs_reg
 fs_visitor::get_nir_dest(nir_dest dest)
 {
diff --git a/src/mesa/drivers/dri/i965/brw_vec4.h b/src/mesa/drivers/dri/i965/brw_vec4.h
index 25b1139..0150bb9 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4.h
+++ b/src/mesa/drivers/dri/i965/brw_vec4.h
@@ -341,6 +341,7 @@ public:
                        unsigned num_components = 4);
    src_reg get_nir_src(nir_src src,
                        unsigned num_components = 4);
+   src_reg get_nir_src_imm(nir_src src, enum brw_reg_type type);
 
    virtual dst_reg *make_reg_for_system_value(int location,
                                               const glsl_type *type) = 0;
diff --git a/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp b/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp
index 4aed60e..ffd480a 100644
--- a/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp
+++ b/src/mesa/drivers/dri/i965/brw_vec4_nir.cpp
@@ -348,6 +348,13 @@ vec4_visitor::get_nir_src(nir_src src, unsigned num_components)
    return get_nir_src(src, nir_type_int, num_components);
 }
 
+src_reg
+vec4_visitor::get_nir_src_imm(nir_src src, enum brw_reg_type type)
+{
+   nir_const_value *val = nir_src_as_const_value(src);
+   return val ? retype(src_reg(val->u[0]), type) : get_nir_src(src, type, 1);
+}
+
 void
 vec4_visitor::nir_emit_load_const(nir_load_const_instr *instr)
 {
-- 
2.6.2



More information about the mesa-dev mailing list