From: "\"Ian Romanick\"" <i...@freedesktop.org> From: Ian Romanick <ian.d.roman...@intel.com>
This changes the generated GLSL IR from something like bvec4 eq = equal(vec4(index), vec4(0, 1, 2, 3)); if (eq.x) lhs = rhs.x; if (eq.y) lhs = rhs.y; if (eq.z) lhs = rhs.z; if (eq.w) lhs = rhs.w; to something like bvec4 eq = equal(vec4(index), vec4(0, 1, 2, 3)); lhs = eq.x ? rhs.x : rhs.y; lhs = eq.z ? rhs.z : lhs; lhs = eq.w ? rhs.w : lhs; Now the comparison of the index with 1 is dead. shader-db changes: G4X / Iron Lake: total instructions in shared programs: 4511136 -> 4511200 (0.00%) instructions in affected programs: 6539 -> 6603 (0.98%) helped: 0 HURT: 64 total cycles in shared programs: 108337124 -> 108337252 (0.00%) cycles in affected programs: 112868 -> 112996 (0.11%) helped: 0 HURT: 64 Sandy Bridge: total instructions in shared programs: 9852966 -> 9853030 (0.00%) instructions in affected programs: 5550 -> 5614 (1.15%) helped: 0 HURT: 64 total cycles in shared programs: 139567270 -> 139567394 (0.00%) cycles in affected programs: 26992 -> 27116 (0.46%) helped: 3 HURT: 37 Ivybridge: total instructions in shared programs: 9119649 -> 9119713 (0.00%) instructions in affected programs: 5325 -> 5389 (1.20%) helped: 0 HURT: 64 total cycles in shared programs: 81708934 -> 81709020 (0.00%) cycles in affected programs: 10446 -> 10532 (0.82%) helped: 0 HURT: 18 Haswell: total instructions in shared programs: 8301165 -> 8301229 (0.00%) instructions in affected programs: 5325 -> 5389 (1.20%) helped: 0 HURT: 64 total cycles in shared programs: 79526732 -> 79526806 (0.00%) cycles in affected programs: 5262 -> 5336 (1.41%) helped: 0 HURT: 11 Broadwell and Skylake: total instructions in shared programs: 13511867 -> 13504225 (-0.06%) instructions in affected programs: 100680 -> 93038 (-7.59%) helped: 86 HURT: 0 total cycles in shared programs: 544335160 -> 540320834 (-0.74%) cycles in affected programs: 56615030 -> 52600704 (-7.09%) helped: 43 HURT: 36 total spills in shared programs: 85420 -> 84334 (-1.27%) spills in affected programs: 3099 -> 2013 (-35.04%) helped: 27 HURT: 0 total fills in shared programs: 88695 -> 87427 (-1.43%) fills in affected programs: 3850 -> 2582 (-32.94%) helped: 27 HURT: 0 The spill / fills helped were all in Dolphin uber shaders. In some cases this change was 86 -> 14. That accounts for a ton of cycles. I have not investigated any of these changes beyond this. Signed-off-by: Ian Romanick <ian.d.roman...@intel.com> --- .../glsl/lower_vec_index_to_cond_assign.cpp | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/compiler/glsl/lower_vec_index_to_cond_assign.cpp b/src/compiler/glsl/lower_vec_index_to_cond_assign.cpp index 926a493..2053342 100644 --- a/src/compiler/glsl/lower_vec_index_to_cond_assign.cpp +++ b/src/compiler/glsl/lower_vec_index_to_cond_assign.cpp @@ -112,9 +112,32 @@ ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(void *mem_ orig_vector->type->vector_elements, mem_ctx); - /* Generate a conditional move of each vector element to the temp. */ - for (unsigned i = 0; i < orig_vector->type->vector_elements; i++) - body.emit(assign(var, swizzle(value, i, 1), swizzle(cond, i, 1))); + /* The swizzle must be 0, 1, 2, or 3. Generate an initial conditional + * select like + * + * var = (i == 0) ? value.x : value.y; + * + * For vectors larger than 2 elements, generate additional conditional + * selects like: + * + * var = (i == 2) ? value.z : var; + * var = (i == 3) ? value.w : var; + */ + body.emit(assign(var, csel(swizzle_x(cond), + swizzle_x(value), + swizzle_y(value)))); + + if (orig_vector->type->vector_elements > 2) { + body.emit(assign(var, csel(swizzle_z(cond), + swizzle_z(value), + var))); + } + + if (orig_vector->type->vector_elements > 3) { + body.emit(assign(var, csel(swizzle_w(cond), + swizzle_w(value), + var))); + } /* Put all of the new instructions in the IR stream before the old * instruction. -- 2.9.5 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/mesa-dev