[Mesa-dev] [PATCH 4/7] nir/search: Add a swizzle to nir_search_variable and use it for replacements
Jason Ekstrand
jason at jlekstrand.net
Wed Jan 21 17:42:44 PST 2015
---
src/glsl/nir/nir_algebraic.py | 14 ++++++++++++++
src/glsl/nir/nir_search.c | 6 +++++-
src/glsl/nir/nir_search.h | 7 +++++++
3 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/src/glsl/nir/nir_algebraic.py b/src/glsl/nir/nir_algebraic.py
index f9b246d..37eb523 100644
--- a/src/glsl/nir/nir_algebraic.py
+++ b/src/glsl/nir/nir_algebraic.py
@@ -28,6 +28,7 @@ import itertools
import struct
import sys
import mako.template
+import re
# Represents a set of variables, each with a unique id
class VarSet(object):
@@ -60,6 +61,7 @@ static const ${val.c_type} ${val.name} = {
{ ${hex(val)} /* ${val.value} */ },
% elif isinstance(val, Variable):
${val.index}, /* ${val.var_name} */
+ { ${', '.join(str(s) for s in val.swizzle)} },
% elif isinstance(val, Expression):
nir_op_${val.opcode},
{ ${', '.join(src.c_ptr for src in val.sources)} },
@@ -106,13 +108,25 @@ class Constant(Value):
else:
assert False
+_swizzle_re = re.compile(r'(.*)\.([xyzw]{1,4})')
+
class Variable(Value):
def __init__(self, val, name, varset):
+ match = _swizzle_re.match(name)
+ if match:
+ name = match.group(1)
+
Value.__init__(self, name, "variable")
+
self.var_name = val
self.index = varset[val]
self.name = name
+ if match:
+ self.swizzle = ['xyzw'.find(s) for s in match.group(2)]
+ else:
+ self.swizzle = range(4)
+
class Expression(Value):
def __init__(self, expr, name_base, varset):
Value.__init__(self, name_base, "expression")
diff --git a/src/glsl/nir/nir_search.c b/src/glsl/nir/nir_search.c
index 4f46cf6..4af34bf 100644
--- a/src/glsl/nir/nir_search.c
+++ b/src/glsl/nir/nir_search.c
@@ -69,6 +69,8 @@ match_value(const nir_search_value *value, nir_alu_instr *instr, unsigned src,
case nir_search_value_variable: {
nir_search_variable *var = nir_search_value_as_variable(value);
+ assert(memcmp(var->swizzle, identity_swizzle, 4) == 0);
+
if (state->variables_seen & (1 << var->variable)) {
if (state->variables[var->variable].ssa != instr->src[src].src.ssa)
return false;
@@ -242,7 +244,9 @@ construct_value(const nir_search_value *value, nir_alu_type type,
val.src = nir_src_for_ssa(state->variables[var->variable].ssa);
val.abs = false;
val.negate = false;
- memcpy(val.swizzle, state->variables[var->variable].swizzle, 4);
+
+ for (unsigned i = 0; i < 4; ++i)
+ val.swizzle[i] = state->variables[var->variable].swizzle[var->swizzle[i]];
return val;
}
diff --git a/src/glsl/nir/nir_search.h b/src/glsl/nir/nir_search.h
index 8ec58b0..8b89dd0 100644
--- a/src/glsl/nir/nir_search.h
+++ b/src/glsl/nir/nir_search.h
@@ -47,6 +47,13 @@ typedef struct {
/** The variable index; Must be less than NIR_SEARCH_MAX_VARIABLES */
unsigned variable;
+
+ /** A swizzle value corresponding to nir_alu_src.swizzle
+ *
+ * This is currently only allowed in replacement expressions, not
+ * searches.
+ */
+ uint8_t swizzle[4];
} nir_search_variable;
typedef struct {
--
2.2.1
More information about the mesa-dev
mailing list