[Mesa-dev] [PATCH 14/18] nir/glsl: add double packing support to vs and fs
Timothy Arceri
timothy.arceri at collabora.com
Fri Jun 10 23:03:34 UTC 2016
---
src/compiler/glsl/link_varyings.cpp | 16 +++++++++++++---
src/compiler/nir/nir_lower_io.c | 16 ++++++++++++++++
2 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/src/compiler/glsl/link_varyings.cpp b/src/compiler/glsl/link_varyings.cpp
index 22dc2d8..7c0d93a 100644
--- a/src/compiler/glsl/link_varyings.cpp
+++ b/src/compiler/glsl/link_varyings.cpp
@@ -1992,10 +1992,11 @@ set_num_packed_components(struct gl_shader *shader, ir_variable_mode io_mode,
var->type->without_array()->is_matrix())
continue;
+ unsigned dfrac = var->type->without_array()->is_double() ? 2 : 1;
if (var->type->is_array()) {
const glsl_type *type = get_varying_type(var, shader->Stage);
unsigned array_components = type->without_array()->vector_elements +
- var->data.location_frac;
+ var->data.location_frac / dfrac;
assert(type->arrays_of_arrays_size() + idx <=
ARRAY_SIZE(num_components));
for (unsigned i = idx; i < type->arrays_of_arrays_size(); i++) {
@@ -2003,7 +2004,7 @@ set_num_packed_components(struct gl_shader *shader, ir_variable_mode io_mode,
}
} else {
unsigned comps = var->type->vector_elements +
- var->data.location_frac;
+ var->data.location_frac / dfrac;
num_components[idx] = MAX2(comps, num_components[idx]);
}
}
@@ -2031,7 +2032,16 @@ set_num_packed_components(struct gl_shader *shader, ir_variable_mode io_mode,
c = MAX2(c, num_components[i]);
}
} else {
- c = num_components[idx];
+ /* Handle special case of packing dvec3 with a double. The only
+ * valid scenario is packing a double in the 4th component of the
+ * double vector.
+ */
+ if (var->type->is_double() && var->type->vector_elements == 3 &&
+ num_components[idx+1] == 2) {
+ c = 4;
+ } else {
+ c = num_components[idx];
+ }
}
var->data.num_packed_components = c;
}
diff --git a/src/compiler/nir/nir_lower_io.c b/src/compiler/nir/nir_lower_io.c
index 941aa2d..86e7941 100644
--- a/src/compiler/nir/nir_lower_io.c
+++ b/src/compiler/nir/nir_lower_io.c
@@ -76,6 +76,22 @@ nir_assign_var_locations(struct exec_list *var_list, unsigned *size,
if (locations[idx][var->data.index] == -1) {
var->data.driver_location = location;
locations[idx][var->data.index] = location;
+
+ /* A dvec3 can be packed with a double we need special handling
+ * for this as we are packing across two locations.
+ */
+ if (glsl_get_base_type(var->type) == GLSL_TYPE_DOUBLE &&
+ glsl_get_vector_elements(var->type) == 3) {
+ /* Hack around type_size functions that expect vectors to be
+ * padded out to vec4.
+ */
+ unsigned dsize = type_size(glsl_double_type(), 0);
+ unsigned offset = dsize == type_size(glsl_float_type(), 0) ?
+ dsize : type_size(glsl_double_type(), 0) * 2;
+
+ locations[idx + 1][var->data.index] = location + offset;
+ }
+
location += type_size(var->type, var->data.num_packed_components);
} else {
var->data.driver_location = locations[idx][var->data.index];
--
2.5.5
More information about the mesa-dev
mailing list