[Mesa-dev] [PATCH 1/2] mesa/st: add support for dynamic ubo selection

Brian Paul brianp at vmware.com
Wed Jul 9 06:06:30 PDT 2014


On 07/08/2014 08:40 PM, Ilia Mirkin wrote:
> Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
> ---
>
> With ChrisF's patches to add support for this in core mesa, this generates
> code like:
>
> FRAG
> DCL OUT[0], COLOR
> DCL CONST[0]
> DCL CONST[1][0]
> DCL CONST[2][0]
> DCL CONST[3][0]
> DCL CONST[4][0]
> DCL TEMP[0], LOCAL
> DCL ADDR[0..1]
> IMM[0] UINT32 {0, 0, 0, 0}
> IMM[1] INT32 {1, 0, 0, 0}
>    0: UADD TEMP[0].x, CONST[0].xxxx, IMM[1].xxxx
>    1: UARL ADDR[1].x, TEMP[0].xxxx
>    2: UARL ADDR[1].x, TEMP[0].xxxx
>    3: MOV TEMP[0], CONST[ADDR[1].x][0]
>    4: MOV OUT[0], TEMP[0]
>    5: END
>
> Not sure what the deal is with the two UARL's, but nouveau's backend removes
> one of them pretty easily. I assume others handle this too.

Yeah, I noticed this too when I was doing some UBO work last week.  I 
haven't had time to investigate yet.

-Brian

>
> Unfortunately the core patches aren't quite ready yet, but this patch doesn't
> regress anything.
>
>   src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 20 +++++++++++++++++---
>   1 file changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> index 9bc7500..3202c56 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> @@ -1947,16 +1947,16 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
>         break;
>
>      case ir_binop_ubo_load: {
> -      ir_constant *uniform_block = ir->operands[0]->as_constant();
> +      ir_constant *const_uniform_block = ir->operands[0]->as_constant();
>         ir_constant *const_offset_ir = ir->operands[1]->as_constant();
>         unsigned const_offset = const_offset_ir ? const_offset_ir->value.u[0] : 0;
> +      unsigned const_block = const_uniform_block ? const_uniform_block->value.u[0] + 1 : 0;
>         st_src_reg index_reg = get_temp(glsl_type::uint_type);
>         st_src_reg cbuf;
>
>         cbuf.type = glsl_type::vec4_type->base_type;
>         cbuf.file = PROGRAM_CONSTANT;
>         cbuf.index = 0;
> -      cbuf.index2D = uniform_block->value.u[0] + 1;
>         cbuf.reladdr = NULL;
>         cbuf.negate = 0;
>
> @@ -1966,7 +1966,6 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
>            /* Constant index into constant buffer */
>            cbuf.reladdr = NULL;
>            cbuf.index = const_offset / 16;
> -         cbuf.has_index2 = true;
>         }
>         else {
>            /* Relative/variable index into constant buffer */
> @@ -1976,6 +1975,21 @@ glsl_to_tgsi_visitor::visit(ir_expression *ir)
>            memcpy(cbuf.reladdr, &index_reg, sizeof(index_reg));
>         }
>
> +      if (const_uniform_block) {
> +         /* Constant constant buffer */
> +         cbuf.reladdr2 = NULL;
> +         cbuf.index2D = const_block;
> +         cbuf.has_index2 = true;
> +      }
> +      else {
> +         /* Relative/variable constant buffer */
> +         emit(ir, TGSI_OPCODE_UADD, st_dst_reg(index_reg), op[0],
> +              st_src_reg_for_int(1));
> +         cbuf.reladdr2 = ralloc(mem_ctx, st_src_reg);
> +         memcpy(cbuf.reladdr2, &index_reg, sizeof(index_reg));
> +         cbuf.has_index2 = true;
> +      }
> +
>         cbuf.swizzle = swizzle_for_size(ir->type->vector_elements);
>         cbuf.swizzle += MAKE_SWIZZLE4(const_offset % 16 / 4,
>                                       const_offset % 16 / 4,
>



More information about the mesa-dev mailing list