Mesa (master): nir/search: Allow for matching variables based on types
Jason Ekstrand
jekstrand at kemper.freedesktop.org
Fri Jan 30 01:13:29 UTC 2015
Module: Mesa
Branch: master
Commit: 026b5cc79274af4a681d3ef41ccfd3b5fa5dc050
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=026b5cc79274af4a681d3ef41ccfd3b5fa5dc050
Author: Jason Ekstrand <jason.ekstrand at intel.com>
Date: Wed Jan 28 16:29:21 2015 -0800
nir/search: Allow for matching variables based on types
This allows you to match on an unknown value but only if it is of a given
type. 90% of the uses of this are for matching only booleans, but adding
the generality of arbitrary types is no more complex.
nir_algebraic.py doesn't handle this yet but that's ok because the C
language will ensure that the default type on all variables is void.
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
---
src/glsl/nir/nir_search.c | 11 +++++++++++
src/glsl/nir/nir_search.h | 12 ++++++++++++
2 files changed, 23 insertions(+)
diff --git a/src/glsl/nir/nir_search.c b/src/glsl/nir/nir_search.c
index ec89817..4671931 100644
--- a/src/glsl/nir/nir_search.c
+++ b/src/glsl/nir/nir_search.c
@@ -82,6 +82,17 @@ match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src,
instr->src[src].src.ssa->parent_instr->type != nir_instr_type_load_const)
return false;
+ if (var->type != nir_type_invalid) {
+ if (instr->src[src].src.ssa->parent_instr->type != nir_instr_type_alu)
+ return false;
+
+ nir_alu_instr *src_alu =
+ nir_instr_as_alu(instr->src[src].src.ssa->parent_instr);
+
+ if (nir_op_infos[src_alu->op].output_type != var->type)
+ return false;
+ }
+
state->variables_seen |= (1 << var->variable);
state->variables[var->variable].src = instr->src[src].src;
state->variables[var->variable].abs = false;
diff --git a/src/glsl/nir/nir_search.h b/src/glsl/nir/nir_search.h
index 18aa28d..7d47792 100644
--- a/src/glsl/nir/nir_search.h
+++ b/src/glsl/nir/nir_search.h
@@ -54,6 +54,18 @@ typedef struct {
* given variable is only allowed to match constant values.
*/
bool is_constant;
+
+ /** Indicates that the given variable must have a certain type
+ *
+ * This is only allowed in search expressions and indicates that the
+ * given variable is only allowed to match values that come from an ALU
+ * instruction with the given output type. A type of nir_type_void
+ * means it can match any type.
+ *
+ * Note: A variable that is both constant and has a non-void type will
+ * never match anything.
+ */
+ nir_alu_type type;
} nir_search_variable;
typedef struct {
More information about the mesa-commit
mailing list