[Mesa-dev] [RFC PATCH] glsl: use ARB_enhahnced_layouts for packing where possible
Timothy Arceri
timothy.arceri at collabora.com
Sun Jul 31 12:39:26 UTC 2016
If packing doesn't cross locations we can easily make use of
ARB_enhanced_layouts to do packing rather than using the GLSL IR
lowering pass lower_packed_varyings().
Shader-db Broadwell results:
total instructions in shared programs: 8716541 -> 8716423 (-0.00%)
instructions in affected programs: 7055 -> 6937 (-1.67%)
helped: 9
HURT: 2
total cycles in shared programs: 74785148 -> 74774364 (-0.01%)
cycles in affected programs: 2888050 -> 2877266 (-0.37%)
helped: 1287
HURT: 1019
total loops in shared programs: 2083 -> 2083 (0.00%)
loops in affected programs: 0 -> 0
helped: 0
HURT: 0
total spills in shared programs: 2294 -> 2286 (-0.35%)
spills in affected programs: 82 -> 74 (-9.76%)
helped: 1
HURT: 0
total fills in shared programs: 2320 -> 2261 (-2.54%)
fills in affected programs: 448 -> 389 (-13.17%)
helped: 1
HURT: 0
---
Not sure what to do with this.
For these results I applied this patch on top of this [1] series.
[1] https://patchwork.freedesktop.org/series/10306/
src/compiler/glsl/link_varyings.cpp | 68 +++++++++++++++++++++++++++++++++++++
1 file changed, 68 insertions(+)
diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp
index 91d8974..f0dfb6d 100644
--- a/src/compiler/glsl/link_varyings.cpp
+++ b/src/compiler/glsl/link_varyings.cpp
@@ -1185,6 +1185,7 @@ class varying_matches
{
public:
varying_matches(bool disable_varying_packing, bool xfb_enabled,
+ bool enhanced_layouts_enabled,
gl_shader_stage producer_stage,
gl_shader_stage consumer_stage);
~varying_matches();
@@ -1217,6 +1218,8 @@ private:
*/
const bool xfb_enabled;
+ const bool enhanced_layouts_enabled;
+
/**
* Enum representing the order in which varyings are packed within a
* packing class.
@@ -1293,10 +1296,12 @@ private:
varying_matches::varying_matches(bool disable_varying_packing,
bool xfb_enabled,
+ bool enhanced_layouts_enabled,
gl_shader_stage producer_stage,
gl_shader_stage consumer_stage)
: disable_varying_packing(disable_varying_packing),
xfb_enabled(xfb_enabled),
+ enhanced_layouts_enabled(enhanced_layouts_enabled),
producer_stage(producer_stage),
consumer_stage(consumer_stage)
{
@@ -1579,6 +1584,12 @@ varying_matches::assign_locations(struct gl_shader_program *prog,
void
varying_matches::store_locations() const
{
+ /* Check is location needs to be packed with lower_packed_varyings() or if
+ * we can just use ARB_enhanced_layouts packing.
+ */
+ bool pack_loc[MAX_VARYINGS_INCL_PATCH] = { 0 };
+ const glsl_type *loc_type[MAX_VARYINGS_INCL_PATCH][4] = { {NULL, NULL} };
+
for (unsigned i = 0; i < this->num_matches; i++) {
ir_variable *producer_var = this->matches[i].producer_var;
ir_variable *consumer_var = this->matches[i].consumer_var;
@@ -1596,6 +1607,62 @@ varying_matches::store_locations() const
consumer_var->data.location = VARYING_SLOT_VAR0 + slot;
consumer_var->data.location_frac = offset;
}
+
+ /* Find locations suitable for native packing via
+ * ARB_enhanced_layouts.
+ */
+ if (producer_var && consumer_var) {
+ if (enhanced_layouts_enabled) {
+ const glsl_type *type =
+ get_varying_type(producer_var, producer_stage);
+ if (type->is_array() || type->is_matrix() || type->is_record() ||
+ type->is_double()) {
+ unsigned comp_slots = type->component_slots() + offset;
+ unsigned slots = comp_slots / 4;
+ if (comp_slots % 4)
+ slots += 1;
+
+ for (unsigned j = 0; j < slots; j++) {
+ pack_loc[slot + j] = true;
+ }
+ } else if (offset + type->vector_elements > 4) {
+ pack_loc[slot] = true;
+ pack_loc[slot + 1] = true;
+ } else {
+ loc_type[slot][offset] = type;
+ }
+ }
+ }
+ }
+
+ /* Attempt to use ARB_enhanced_layouts for more efficient packing if
+ * suitable.
+ */
+ if (enhanced_layouts_enabled) {
+ for (unsigned i = 0; i < this->num_matches; i++) {
+ ir_variable *producer_var = this->matches[i].producer_var;
+ ir_variable *consumer_var = this->matches[i].consumer_var;
+ unsigned generic_location = this->matches[i].generic_location;
+ unsigned slot = generic_location / 4;
+
+ if (pack_loc[slot] || !producer_var || !consumer_var)
+ continue;
+
+ const glsl_type *type =
+ get_varying_type(producer_var, producer_stage);
+ bool type_match = true;
+ for (unsigned j = 0; j < 4; j++) {
+ if (loc_type[slot][j]) {
+ if (type->base_type != loc_type[slot][j]->base_type)
+ type_match = false;
+ }
+ }
+
+ if (type_match) {
+ producer_var->data.explicit_location = 1;
+ consumer_var->data.explicit_location = 1;
+ }
+ }
}
}
@@ -2054,6 +2121,7 @@ assign_varying_locations(struct gl_context *ctx,
disable_varying_packing = true;
varying_matches matches(disable_varying_packing, xfb_enabled,
+ ctx->Extensions.ARB_enhanced_layouts,
producer ? producer->Stage : (gl_shader_stage)-1,
consumer ? consumer->Stage : (gl_shader_stage)-1);
hash_table *tfeedback_candidates
--
2.7.4
More information about the mesa-dev
mailing list