Module: Mesa Branch: master Commit: 886d46b0897182e489e03f7302a575b54004faca URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=886d46b0897182e489e03f7302a575b54004faca
Author: Neil Roberts <n...@linux.intel.com> Date: Thu Jul 30 12:10:08 2015 +0100 nir: Add a function to determine if a source is dynamically uniform Adds nir_src_is_dynamically_uniform which returns true if the source is known to be dynamically uniform. This will be used in a later patch to add a workaround for cases that only work with dynamically uniform sources. Note that the function is not definitive, it can return false negatives (but not false positives). Currently it only detects constants and uniform accesses. It could easily be extended to include more cases. Reviewed-by: Matt Turner <matts...@gmail.com> --- src/glsl/nir/nir.c | 29 +++++++++++++++++++++++++++++ src/glsl/nir/nir.h | 1 + 2 files changed, 30 insertions(+) diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c index e12da80..c8fc428 100644 --- a/src/glsl/nir/nir.c +++ b/src/glsl/nir/nir.c @@ -1080,6 +1080,35 @@ nir_src_as_const_value(nir_src src) return &load->value; } +/** + * Returns true if the source is known to be dynamically uniform. Otherwise it + * returns false which means it may or may not be dynamically uniform but it + * can't be determined. + */ +bool +nir_src_is_dynamically_uniform(nir_src src) +{ + if (!src.is_ssa) + return false; + + /* Constants are trivially dynamically uniform */ + if (src.ssa->parent_instr->type == nir_instr_type_load_const) + return true; + + /* As are uniform variables */ + if (src.ssa->parent_instr->type == nir_instr_type_intrinsic) { + nir_intrinsic_instr *intr = nir_instr_as_intrinsic(src.ssa->parent_instr); + + if (intr->intrinsic == nir_intrinsic_load_uniform) + return true; + } + + /* XXX: this could have many more tests, such as when a sampler function is + * called with dynamically uniform arguments. + */ + return false; +} + bool nir_srcs_equal(nir_src src1, nir_src src2) { diff --git a/src/glsl/nir/nir.h b/src/glsl/nir/nir.h index bde9f49..95e2191 100644 --- a/src/glsl/nir/nir.h +++ b/src/glsl/nir/nir.h @@ -1784,6 +1784,7 @@ bool nir_foreach_dest(nir_instr *instr, nir_foreach_dest_cb cb, void *state); bool nir_foreach_src(nir_instr *instr, nir_foreach_src_cb cb, void *state); nir_const_value *nir_src_as_const_value(nir_src src); +bool nir_src_is_dynamically_uniform(nir_src src); bool nir_srcs_equal(nir_src src1, nir_src src2); void nir_instr_rewrite_src(nir_instr *instr, nir_src *src, nir_src new_src); void nir_instr_move_src(nir_instr *dest_instr, nir_src *dest, nir_src *src); _______________________________________________ mesa-commit mailing list mesa-commit@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-commit