[Mesa-dev] [PATCH 2/2] nir/instr_set: allow rewrite of SSBO loads
Iago Toral Quiroga
itoral at igalia.com
Thu Oct 22 04:21:19 PDT 2015
So we can effectively CSE the ones that are safe to reuse. Makes a shader
such as this:
buffer SSBO {
mat4 sm4;
};
uniform mat4 um4;
void main() {
sm4 *= um4;
}
go from 16 SSBO loads to only 4.
---
src/glsl/nir/nir_instr_set.c | 24 ++++++++++++++++++++----
1 file changed, 20 insertions(+), 4 deletions(-)
diff --git a/src/glsl/nir/nir_instr_set.c b/src/glsl/nir/nir_instr_set.c
index d3f939f..470683f 100644
--- a/src/glsl/nir/nir_instr_set.c
+++ b/src/glsl/nir/nir_instr_set.c
@@ -398,6 +398,13 @@ dest_is_ssa(nir_dest *dest, void *data)
return dest->is_ssa;
}
+static bool
+is_ssbo_load(nir_intrinsic_instr *instr)
+{
+ return instr->intrinsic == nir_intrinsic_load_ssbo ||
+ instr->intrinsic == nir_intrinsic_load_ssbo_indirect;
+}
+
/* This function determines if uses of an instruction can safely be rewritten
* to use another identical instruction instead. Note that this function must
* be kept in sync with hash_instr() and nir_instrs_equal() -- only
@@ -428,11 +435,20 @@ instr_can_rewrite(nir_instr *instr)
return true;
}
case nir_instr_type_intrinsic: {
+ nir_intrinsic_instr *intrinsic = nir_instr_as_intrinsic(instr);
const nir_intrinsic_info *info =
- &nir_intrinsic_infos[nir_instr_as_intrinsic(instr)->intrinsic];
- return (info->flags & NIR_INTRINSIC_CAN_ELIMINATE) &&
- (info->flags & NIR_INTRINSIC_CAN_REORDER) &&
- info->num_variables == 0; /* not implemented yet */
+ &nir_intrinsic_infos[intrinsic->intrinsic];
+ bool can_eliminate_and_reorder =
+ (info->flags & NIR_INTRINSIC_CAN_ELIMINATE) &&
+ (info->flags & NIR_INTRINSIC_CAN_REORDER) &&
+ info->num_variables == 0; /* not implemented yet */
+
+ /* SSBO loads are special: they can be reordered only in certain
+ * situations, so they don't set NIR_INTRINSIC_CAN_REORDER, however,
+ * we do want to CSE them in the cases where it is safe, so return
+ * true for them here.
+ */
+ return can_eliminate_and_reorder ? true : is_ssbo_load(intrinsic);
}
case nir_instr_type_call:
case nir_instr_type_jump:
--
1.9.1
More information about the mesa-dev
mailing list