shader: unify block and varible name evalution for generated IO arrays

Extract the generation of the block and varable name and use these
functions.

Signed-off-by: Gert Wollny <gert.wollny@collabora.com>
Reviewed-By: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Gert Wollny 6 years ago committed by Gert Wollny
parent cb51104a07
commit 636a7c2aa4
  1. 113
      src/vrend_shader.c

@ -1616,17 +1616,35 @@ static const struct vrend_shader_io *get_io_slot(const struct vrend_shader_io *s
assert(0 && "Output not found"); assert(0 && "Output not found");
} }
static void get_so_name(bool use_gles, const struct vrend_shader_io *output, int index, char out_var[255], static inline void
const char *prefix, const char *stage_prefix) get_blockname(char outvar[64], const char *stage_prefix, const struct vrend_shader_io *io)
{
snprintf(outvar, 64, "block_%sg%dA%d", stage_prefix, io->sid, io->array_id);
}
static inline void
get_blockvarname(char outvar[64], const char *stage_prefix, const struct vrend_shader_io *io, const char *postfix)
{
snprintf(outvar, 64, "%sg%dA%d_%x%s", stage_prefix, io->sid, io->array_id, io->usage_mask, postfix);
}
static void get_so_name(struct dump_ctx *ctx, bool from_block, const struct vrend_shader_io *output, int index, char out_var[255], char *wm)
{ {
if (output->first == output->last || output->name != TGSI_SEMANTIC_GENERIC) if (output->first == output->last || output->name != TGSI_SEMANTIC_GENERIC)
snprintf(out_var, 255, "%s", output->glsl_name); snprintf(out_var, 255, "%s%s", output->glsl_name, wm);
else else {
if (use_gles) if ((output->name == TGSI_SEMANTIC_GENERIC) && prefer_generic_io_block(ctx, io_out)) {
snprintf(out_var, 255, "%s[%d]", output->glsl_name, index - output->first); char blockname[64];
else const char *stage_prefix = get_stage_output_name_prefix(ctx->prog_type);
snprintf(out_var, 255, "%s%sg%d.%s[%d]", prefix, stage_prefix, output->sid, if (from_block)
output->glsl_name, index - output->first); get_blockname(blockname, stage_prefix, output);
else
get_blockvarname(blockname, stage_prefix, output, "");
snprintf(out_var, 255, "%s.%s[%d]%s", blockname, output->glsl_name, index - output->first, wm);
} else {
snprintf(out_var, 255, "%s[%d]%s", output->glsl_name, index - output->first, wm);
}
}
} }
static void emit_so_movs(struct dump_ctx *ctx) static void emit_so_movs(struct dump_ctx *ctx)
@ -2785,12 +2803,15 @@ static void get_destination_info_generic(struct dump_ctx *ctx,
snprintf(dsts, 255, "%s%s%s", io->glsl_name, blkarray, wm); snprintf(dsts, 255, "%s%s%s", io->glsl_name, blkarray, wm);
else { else {
if (prefer_generic_io_block(ctx, io_out)) { if (prefer_generic_io_block(ctx, io_out)) {
char outvarname[64];
get_blockvarname(outvarname, stage_prefix, io, blkarray);
if (dst_reg->Register.Indirect) if (dst_reg->Register.Indirect)
snprintf(dsts, 255, "%sg%d%s.%s[addr%d + %d]%s", stage_prefix, io->sid, blkarray, snprintf(dsts, 255, "%s.%s[addr%d + %d]%s", outvarname, io->glsl_name,
io->glsl_name, dst_reg->Indirect.Index, dst_reg->Register.Index - io->first, wm); dst_reg->Indirect.Index, dst_reg->Register.Index - io->first, wm);
else else
snprintf(dsts, 255, "%sg%d%s.%s[%d]%s", stage_prefix, io->sid, blkarray, snprintf(dsts, 255, "%s.%s[%d]%s", outvarname, io->glsl_name,
io->glsl_name, dst_reg->Register.Index - io->first, wm); dst_reg->Register.Index - io->first, wm);
} else { } else {
if (dst_reg->Register.Indirect) if (dst_reg->Register.Indirect)
snprintf(dsts, 255, "%s%s[addr%d + %d]%s", io->glsl_name, blkarray, snprintf(dsts, 255, "%s%s[addr%d + %d]%s", io->glsl_name, blkarray,
@ -3035,20 +3056,18 @@ static void get_source_info_generic(struct dump_ctx *ctx,
prefix, io->glsl_name, arrayname, io->is_int ? "" : swizzle); prefix, io->glsl_name, arrayname, io->is_int ? "" : swizzle);
} else { } else {
if (prefer_generic_io_block(ctx, iot)) { if (prefer_generic_io_block(ctx, iot)) {
char outvarname[64];
const char *stage_prefix = iot == io_in ? get_stage_input_name_prefix(ctx, ctx->prog_type) : const char *stage_prefix = iot == io_in ? get_stage_input_name_prefix(ctx, ctx->prog_type) :
get_stage_output_name_prefix(ctx->prog_type); get_stage_output_name_prefix(ctx->prog_type);
get_blockvarname(outvarname, stage_prefix, io, arrayname);
if (src->Register.Indirect) if (src->Register.Indirect)
snprintf(srcs, 255, "%s(%s %sg%d%s.%s[addr%d + %d] %s)", get_string(srcstypeprefix), prefix, snprintf(srcs, 255, "%s(%s %s.%s[addr%d + %d] %s)", get_string(srcstypeprefix), prefix,
stage_prefix, io->sid, arrayname, outvarname, io->glsl_name, src->Indirect.Index, src->Register.Index - io->first,
io->glsl_name,
src->Indirect.Index,
src->Register.Index - io->first,
io->is_int ? "" : swizzle); io->is_int ? "" : swizzle);
else else
snprintf(srcs, 255, "%s(%s %sg%d%s.%s[%d] %s)", get_string(srcstypeprefix), prefix, snprintf(srcs, 255, "%s(%s %s.%s[%d] %s)", get_string(srcstypeprefix), prefix,
stage_prefix, io->sid, arrayname, outvarname, io->glsl_name, src->Register.Index - io->first,
io->glsl_name,
src->Register.Index - io->first,
io->is_int ? "" : swizzle); io->is_int ? "" : swizzle);
} else { } else {
if (src->Register.Indirect) if (src->Register.Indirect)
@ -4771,20 +4790,20 @@ static inline void emit_winsys_correction(struct dump_ctx *ctx)
static void emit_ios_indirect_generics_output(struct dump_ctx *ctx, const char *postfix) static void emit_ios_indirect_generics_output(struct dump_ctx *ctx, const char *postfix)
{ {
if (ctx->generic_output_range.used) { if (ctx->generic_output_range.used) {
const char *stage_prefix = get_stage_output_name_prefix(ctx->prog_type);
int size = ctx->generic_output_range.io.last - ctx->generic_output_range.io.sid + 1; int size = ctx->generic_output_range.io.last - ctx->generic_output_range.io.sid + 1;
if (prefer_generic_io_block(ctx, io_out)) if (prefer_generic_io_block(ctx, io_out)) {
emit_hdrf(ctx, "out block_%sg%d {\n vec4 %s[%d]; \n} %sg%d%s;\n", char blockname[64];
stage_prefix, const char *stage_prefix = get_stage_output_name_prefix(ctx->prog_type);
ctx->generic_output_range.io.sid, get_blockname(blockname, stage_prefix, &ctx->generic_output_range.io);
ctx->generic_output_range.io.glsl_name,
size, char blockvarame[64];
stage_prefix, get_blockvarname(blockvarame, stage_prefix, &ctx->generic_output_range.io, postfix);
ctx->generic_output_range.io.sid,
postfix); emit_hdrf(ctx, "out %s {\n vec4 %s[%d]; \n} %s;\n", blockname,
else ctx->generic_output_range.io.glsl_name, size, blockvarame);
} else
emit_hdrf(ctx, "out vec4 %s%s[%d];\n", emit_hdrf(ctx, "out vec4 %s%s[%d];\n",
ctx->generic_input_range.io.glsl_name, ctx->generic_output_range.io.glsl_name,
postfix, postfix,
size); size);
} }
@ -4793,23 +4812,25 @@ static void emit_ios_indirect_generics_output(struct dump_ctx *ctx, const char *
static void emit_ios_indirect_generics_input(struct dump_ctx *ctx, const char *postfix) static void emit_ios_indirect_generics_input(struct dump_ctx *ctx, const char *postfix)
{ {
if (ctx->generic_input_range.used) { if (ctx->generic_input_range.used) {
const char *stage_prefix = get_stage_input_name_prefix(ctx, ctx->prog_type);
int size = ctx->generic_input_range.io.last - ctx->generic_input_range.io.sid + 1; int size = ctx->generic_input_range.io.last - ctx->generic_input_range.io.sid + 1;
assert(size < 256 && size >= 0); assert(size < 256 && size >= 0);
if (size < ctx->key->num_indirect_generic_inputs) if (size < ctx->key->num_indirect_generic_inputs)
ctx->key->num_indirect_generic_inputs = (unsigned char)size; // This is wrong but needed for debugging ctx->key->num_indirect_generic_inputs = (unsigned char)size; // This is wrong but needed for debugging
if (prefer_generic_io_block(ctx, io_in)) if (prefer_generic_io_block(ctx, io_in)) {
emit_hdrf(ctx,
"in block_%sg%d {\n vec4 %s[%d]; \n} %sg%d%s;\n", char blockname[64];
stage_prefix, char blockvarame[64];
ctx->generic_input_range.io.sid, const char *stage_prefix = get_stage_output_name_prefix(ctx->prog_type);
ctx->generic_input_range.io.glsl_name,
size, get_blockname(blockname, stage_prefix, &ctx->generic_output_range.io);
stage_prefix, get_blockvarname(blockvarame, stage_prefix, &ctx->generic_output_range.io,
ctx->generic_input_range.io.sid, postfix);
postfix);
else emit_hdrf(ctx, "in %s {\n vec4 %s[%d]; \n} %s;\n",
blockname, ctx->generic_input_range.io.glsl_name,
size, blockvarame);
} else
emit_hdrf(ctx, "in vec4 %s%s[%d];\n", emit_hdrf(ctx, "in vec4 %s%s[%d];\n",
ctx->generic_input_range.io.glsl_name, ctx->generic_input_range.io.glsl_name,
postfix, postfix,

Loading…
Cancel
Save