[Mesa-dev] [PATCH 18/21] RFC glsl: support packing of tessellation shader varyings with an explict location
Timothy Arceri
t_arceri at yahoo.com.au
Mon Dec 21 22:13:53 PST 2015
On Tue, 2015-12-22 at 17:02 +1100, Timothy Arceri wrote:
> Rather than passing in the vertex count to the packing pass just us
> the outermost array size to get the count.
>
> Also teach lower_packed_varyings() about the tessellation shader
> varyings.
>
> Note: This patch doesn't really work for tessellation shaders because
> of the shared store for varyings. For tessellation we can just turn
That should be "we *can't* just turn"
> the
> old varying into a temporary and copy all the values like we do in
> other
> stages we instead would need to replace the old varying completely
> and use
> a swizzle to set/get the right components.
> ---
> src/glsl/ir_optimization.h | 3 +-
> src/glsl/link_varyings.cpp | 21 ++++------
> src/glsl/lower_packed_varyings.cpp | 79 ++++++++++++++++++++++------
> ----------
> 3 files changed, 54 insertions(+), 49 deletions(-)
>
> diff --git a/src/glsl/ir_optimization.h b/src/glsl/ir_optimization.h
> index a313e30..e4af753 100644
> --- a/src/glsl/ir_optimization.h
> +++ b/src/glsl/ir_optimization.h
> @@ -128,8 +128,7 @@ void lower_shared_reference(struct gl_shader
> *shader, unsigned *shared_size);
> void lower_ubo_reference(struct gl_shader *shader);
> void lower_packed_varyings(void *mem_ctx,
> unsigned locations_used, ir_variable_mode
> mode,
> - unsigned gs_input_vertices, gl_shader
> *shader,
> - unsigned base_location,
> + gl_shader *shader, unsigned
> base_location,
> bool disable_varying_packing,
> bool has_enhanced_layouts);
> bool lower_vector_insert(exec_list *instructions, bool
> lower_nonconstant_index);
> diff --git a/src/glsl/link_varyings.cpp b/src/glsl/link_varyings.cpp
> index 2908af7..b7de0ef 100644
> --- a/src/glsl/link_varyings.cpp
> +++ b/src/glsl/link_varyings.cpp
> @@ -1678,10 +1678,6 @@ assign_varying_locations(struct gl_context
> *ctx,
> NULL,
> };
>
> - unsigned consumer_vertices = 0;
> - if (consumer && consumer->Stage == MESA_SHADER_GEOMETRY)
> - consumer_vertices = prog->Geom.VerticesIn;
> -
> /* Operate in a total of four passes.
> *
> * 1. Sort inputs / outputs into a canonical order. This is
> necessary so
> @@ -1835,16 +1831,15 @@ assign_varying_locations(struct gl_context
> *ctx,
> unsigned vertex_attributes =
> _mesa_bitcount_64(reserved_slots);
> if (vertex_attributes > 0)
> lower_packed_varyings(mem_ctx, vertex_attributes,
> - ir_var_shader_in, 0, producer,
> + ir_var_shader_in, producer,
> VERT_ATTRIB_GENERIC0, true,
> ctx
> ->Extensions.ARB_enhanced_layouts);
> }
>
> remove_unused_shader_inputs_and_outputs(prog, producer,
> ir_var_shader_out);
> - lower_packed_varyings(mem_ctx, slots_used, ir_var_shader_out,
> - 0, producer, VARYING_SLOT_VAR0,
> - disable_varying_packing,
> + lower_packed_varyings(mem_ctx, slots_used, ir_var_shader_out,
> producer,
> + VARYING_SLOT_VAR0,
> disable_varying_packing,
> ctx->Extensions.ARB_enhanced_layouts);
> }
>
> @@ -1860,17 +1855,15 @@ assign_varying_locations(struct gl_context
> *ctx,
> /* Pack frag outputs with the component layout qualifier */
> unsigned frag_outs = _mesa_bitcount_64(reserved_slots);
> if (frag_outs > 0)
> - lower_packed_varyings(mem_ctx, frag_outs,
> - ir_var_shader_out, 0, consumer,
> - FRAG_RESULT_DATA0, true,
> + lower_packed_varyings(mem_ctx, frag_outs,
> ir_var_shader_out,
> + consumer, FRAG_RESULT_DATA0, true,
> ctx
> ->Extensions.ARB_enhanced_layouts);
> }
>
> remove_unused_shader_inputs_and_outputs(prog, consumer,
> ir_var_shader_in);
> - lower_packed_varyings(mem_ctx, slots_used, ir_var_shader_in,
> - consumer_vertices, consumer,
> VARYING_SLOT_VAR0,
> - disable_varying_packing,
> + lower_packed_varyings(mem_ctx, slots_used, ir_var_shader_in,
> consumer,
> + VARYING_SLOT_VAR0,
> disable_varying_packing,
> ctx->Extensions.ARB_enhanced_layouts);
> }
>
> diff --git a/src/glsl/lower_packed_varyings.cpp
> b/src/glsl/lower_packed_varyings.cpp
> index 9a8c336..79de38b 100644
> --- a/src/glsl/lower_packed_varyings.cpp
> +++ b/src/glsl/lower_packed_varyings.cpp
> @@ -166,7 +166,7 @@ class lower_packed_varyings_visitor
> public:
> lower_packed_varyings_visitor(void *mem_ctx, unsigned
> locations_used,
> ir_variable_mode mode,
> - unsigned gs_input_vertices,
> + bool is_outer_array_vert_idx,
> exec_list *out_instructions,
> exec_list *out_variables,
> unsigned base_location,
> @@ -180,13 +180,13 @@ private:
> void bitwise_assign_unpack(ir_rvalue *lhs, ir_rvalue *rhs);
> unsigned lower_rvalue(ir_rvalue *rvalue, unsigned fine_location,
> ir_variable *unpacked_var, const char
> *name,
> - bool gs_input_toplevel, unsigned
> vertex_index,
> + bool is_outer_array_vert_idx, unsigned
> vertex_index,
> bool explicit_location);
> unsigned lower_arraylike(ir_rvalue *rvalue, unsigned array_size,
> unsigned fine_location,
> ir_variable *unpacked_var, const char
> *name,
> - bool gs_input_toplevel, unsigned
> vertex_index,
> - bool explicit_location);
> + bool is_outer_array_vert_idx,
> + unsigned vertex_index, bool
> explicit_location);
> ir_dereference *get_packed_varying_deref(unsigned location,
> ir_variable
> *unpacked_var,
> const char *name,
> @@ -222,10 +222,10 @@ private:
> const ir_variable_mode mode;
>
> /**
> - * If we are currently lowering geometry shader inputs, the
> number of input
> - * vertices the geometry shader accepts. Otherwise zero.
> + * Are we are currently lowering a stage where the input or
> output vertices
> + * are indexed by the outmost array.
> */
> - const unsigned gs_input_vertices;
> + const bool is_outer_array_vert_idx;
>
> /**
> * Exec list into which the visitor should insert the packing
> instructions.
> @@ -247,7 +247,7 @@ private:
>
> lower_packed_varyings_visitor::lower_packed_varyings_visitor(
> void *mem_ctx, unsigned locations_used, ir_variable_mode mode,
> - unsigned gs_input_vertices, exec_list *out_instructions,
> + bool is_outer_array_vert_idx, exec_list *out_instructions,
> exec_list *out_variables, unsigned base_location,
> bool disable_varying_packing, bool has_enhanced_layouts)
> : mem_ctx(mem_ctx),
> @@ -257,7 +257,7 @@
> lower_packed_varyings_visitor::lower_packed_varyings_visitor(
> rzalloc_array_size(mem_ctx,
> sizeof(*packed_varyings),
> locations_used)),
> mode(mode),
> - gs_input_vertices(gs_input_vertices),
> + is_outer_array_vert_idx(is_outer_array_vert_idx),
> out_instructions(out_instructions),
> out_variables(out_variables),
> disable_varying_packing(disable_varying_packing),
> @@ -304,7 +304,7 @@ lower_packed_varyings_visitor::run(struct
> gl_shader *shader)
>
> /* Recursively pack or unpack it. */
> this->lower_rvalue(deref, var->data.location * 4 + var
> ->data.location_frac, var,
> - var->name, this->gs_input_vertices != 0, 0,
> + var->name, is_outer_array_vert_idx, 0,
> var->data.explicit_location);
> }
> }
> @@ -419,9 +419,9 @@
> lower_packed_varyings_visitor::bitwise_assign_unpack(ir_rvalue *lhs,
> * in multiples of a float, rather than multiples of a vec4 as is
> used
> * elsewhere in Mesa.
> *
> - * \param gs_input_toplevel should be set to true if we are lowering
> geometry
> - * shader inputs, and we are currently lowering the whole input
> variable
> - * (i.e. we are lowering the array whose index selects the vertex).
> + * \param is_outer_array_vert_idx should be set to true if we are
> lowering an
> + * array whose index selects a vertex e.g the outermost array of a
> geometry
> + * shader input.
> *
> * \param vertex_index: if we are lowering geometry shader inputs,
> and the
> * level of the array that we are currently lowering is *not* the
> top level,
> @@ -436,15 +436,15 @@
> lower_packed_varyings_visitor::lower_rvalue(ir_rvalue *rvalue,
> unsigned fine_location,
> ir_variable
> *unpacked_var,
> const char *name,
> - bool gs_input_toplevel,
> + bool
> is_outer_array_vert_idx,
> unsigned vertex_index,
> bool explicit_location)
> {
> unsigned dmul = rvalue->type->is_double() ? 2 : 1;
> - /* When gs_input_toplevel is set, we should be looking at a
> geometry shader
> - * input array.
> + /* When is_outer_array_vert_idx is set, we should be looking at a
> varying
> + * array.
> */
> - assert(!gs_input_toplevel || rvalue->type->is_array());
> + assert(!is_outer_array_vert_idx || rvalue->type->is_array());
>
> if (rvalue->type->is_record()) {
> for (unsigned i = 0; i < rvalue->type->length; i++) {
> @@ -466,7 +466,7 @@
> lower_packed_varyings_visitor::lower_rvalue(ir_rvalue *rvalue,
> */
> return this->lower_arraylike(rvalue, rvalue->type
> ->array_size(),
> fine_location, unpacked_var,
> name,
> - gs_input_toplevel, vertex_index,
> + is_outer_array_vert_idx,
> vertex_index,
> explicit_location);
> } else if (rvalue->type->is_matrix()) {
> /* Matrices are packed/unpacked by considering each column
> vector in
> @@ -562,9 +562,9 @@
> lower_packed_varyings_visitor::lower_rvalue(ir_rvalue *rvalue,
> * This takes care of both arrays and matrices, since
> ir_dereference_array
> * treats a matrix like an array of its column vectors.
> *
> - * \param gs_input_toplevel should be set to true if we are lowering
> geometry
> - * shader inputs, and we are currently lowering the whole input
> variable
> - * (i.e. we are lowering the array whose index selects the vertex).
> + * \param is_outer_array_vert_idx should be set to true if we are
> lowering an
> + * array whose index selects a vertex e.g the outermost array of a
> geometry
> + * shader input.
> *
> * \param vertex_index: if we are lowering geometry shader inputs,
> and the
> * level of the array that we are currently lowering is *not* the
> top level,
> @@ -577,7 +577,7 @@
> lower_packed_varyings_visitor::lower_arraylike(ir_rvalue *rvalue,
> unsigned
> fine_location,
> ir_variable
> *unpacked_var,
> const char *name,
> - bool
> gs_input_toplevel,
> + bool
> is_outer_array_vert_idx,
> unsigned
> vertex_index,
> bool
> explicit_location)
> {
> @@ -587,7 +587,7 @@
> lower_packed_varyings_visitor::lower_arraylike(ir_rvalue *rvalue,
> ir_constant *constant = new(this->mem_ctx) ir_constant(i);
> ir_dereference_array *dereference_array = new(this->mem_ctx)
> ir_dereference_array(rvalue, constant);
> - if (gs_input_toplevel) {
> + if (is_outer_array_vert_idx) {
> /* Geometry shader inputs are a special case. Instead of
> storing
> * each element of the array at a different location, all
> elements
> * are at the same location, but with a different vertex
> index.
> @@ -633,18 +633,18 @@
> lower_packed_varyings_visitor::get_packed_varying_deref(
> packed_type = glsl_type::ivec4_type;
> else
> packed_type = glsl_type::vec4_type;
> - if (this->gs_input_vertices != 0) {
> + if (this->is_outer_array_vert_idx) {
> packed_type =
> glsl_type::get_array_instance(packed_type,
> - this->gs_input_vertices);
> + unpacked_var->type
> ->length);
> }
> ir_variable *packed_var = new(this->mem_ctx)
> ir_variable(packed_type, packed_name, this->mode);
> - if (this->gs_input_vertices != 0) {
> + if (this->is_outer_array_vert_idx) {
> /* Prevent update_array_sizes() from messing with the size
> of the
> * array.
> */
> - packed_var->data.max_array_access = this->gs_input_vertices
> - 1;
> + packed_var->data.max_array_access = unpacked_var->type
> ->length - 1;
> }
> packed_var->data.centroid = unpacked_var->data.centroid;
> packed_var->data.sample = unpacked_var->data.sample;
> @@ -659,7 +659,7 @@
> lower_packed_varyings_visitor::get_packed_varying_deref(
> /* For geometry shader inputs, only update the packed variable
> name the
> * first time we visit each component.
> */
> - if (this->gs_input_vertices == 0 || vertex_index == 0) {
> + if (!this->is_outer_array_vert_idx || vertex_index == 0) {
> ralloc_asprintf_append((char **) &this
> ->packed_varyings[slot]->name,
> ",%s", name);
> }
> @@ -667,7 +667,7 @@
> lower_packed_varyings_visitor::get_packed_varying_deref(
>
> ir_dereference *deref = new(this->mem_ctx)
> ir_dereference_variable(this->packed_varyings[slot]);
> - if (this->gs_input_vertices != 0) {
> + if (this->is_outer_array_vert_idx) {
> /* When lowering GS inputs, the packed variable is an array,
> so we need
> * to dereference it using vertex_index.
> */
> @@ -750,9 +750,9 @@
> lower_packed_varyings_gs_splicer::visit_leave(ir_emit_vertex *ev)
>
> void
> lower_packed_varyings(void *mem_ctx, unsigned locations_used,
> - ir_variable_mode mode, unsigned
> gs_input_vertices,
> - gl_shader *shader, unsigned base_location,
> - bool disable_varying_packing, bool
> has_enhanced_layouts)
> + ir_variable_mode mode, gl_shader *shader,
> + unsigned base_location, bool
> disable_varying_packing,
> + bool has_enhanced_layouts)
> {
> exec_list *instructions = shader->ir;
> ir_function *main_func = shader->symbols->get_function("main");
> @@ -760,8 +760,21 @@ lower_packed_varyings(void *mem_ctx, unsigned
> locations_used,
> ir_function_signature *main_func_sig
> = main_func->matching_signature(NULL, &void_parameters,
> false);
> exec_list new_instructions, new_variables;
> +
> + bool is_outer_array_vert_idx = false;
> + if (mode == ir_var_shader_in) {
> + if (shader->Stage == MESA_SHADER_GEOMETRY ||
> + shader->Stage == MESA_SHADER_TESS_CTRL ||
> + shader->Stage == MESA_SHADER_TESS_EVAL) {
> + is_outer_array_vert_idx = true;
> + }
> + } else if (mode == ir_var_shader_out &&
> + shader->Stage == MESA_SHADER_TESS_CTRL) {
> + is_outer_array_vert_idx = true;
> + }
> +
> lower_packed_varyings_visitor visitor(mem_ctx, locations_used,
> mode,
> - gs_input_vertices,
> + is_outer_array_vert_idx,
> &new_instructions,
> &new_variables,
> base_location,
More information about the mesa-dev
mailing list