shader: Update the evaluation of the generic IOs to use array and mask info

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 cadf0219e8
commit dbf5489555
  1. 140
      src/vrend_shader.c

@ -5236,54 +5236,98 @@ static void emit_ios_indirect_generics_input(struct dump_ctx *ctx, const char *p
} }
static void static void
emit_ios_generics(struct dump_ctx *ctx, enum io_type io_type, emit_ios_generics(struct dump_ctx *ctx, enum io_type iot, const char *prefix,
const char *prefix, const char *stage_prefix,
const struct vrend_shader_io *io, const char *inout, const struct vrend_shader_io *io, const char *inout,
const char *postfix) const char *postfix)
{ {
if (io->first == io->last) const char type[4][6] = {"float", " vec2", " vec3", " vec4"};
const char *t = " vec4";
char layout[128] = "";
if (io->layout_location > 0) {
/* we need to define a layout here because interleaved arrays might be emited */
if (io->swizzle_offset)
snprintf(layout, sizeof(layout), "layout(location = %d, component = %d)\n",
io->layout_location - 1, io->swizzle_offset);
else
snprintf(layout, sizeof(layout), "layout(location = %d)\n", io->layout_location - 1);
}
if (io->usage_mask != 0xf && io->name == TGSI_SEMANTIC_GENERIC)
t = type[io->num_components - 1];
if (io->first == io->last) {
emit_hdr(ctx, layout);
/* ugly leave spaces to patch interp in later */ /* ugly leave spaces to patch interp in later */
emit_hdrf(ctx, "%s%s%s%s vec4 %s%s;\n", emit_hdrf(ctx, "%s%s%s %s %s %s%s;\n",
prefix, prefix,
io->precise ? "precise " : "", io->precise ? "precise " : "",
io->invariant ? "invariant " : "", io->invariant ? "invariant " : "",
inout, inout,
io->glsl_name, postfix); t,
else { io->glsl_name,
if (prefer_generic_io_block(ctx, io_type)) postfix);
emit_hdrf(ctx, "%s block_%sg%d {\n %s%s%s vec4 %s[%d]; \n} %sg%d%s;\n", } else {
inout, if (prefer_generic_io_block(ctx, iot)) {
stage_prefix, const char *stage_prefix = iot == io_in ? get_stage_input_name_prefix(ctx, ctx->prog_type):
io->sid, get_stage_output_name_prefix(ctx->prog_type);
char blockname[64];
get_blockname(blockname, stage_prefix, io);
char blockvarame[64];
get_blockvarname(blockvarame, stage_prefix, io, postfix);
emit_hdrf(ctx, "%s %s {\n", inout, blockname);
emit_hdr(ctx, layout);
emit_hdrf(ctx, "%s%s%s vec4 %s[%d]; \n} %s;\n",
prefix, prefix,
io->precise ? "precise " : "", io->precise ? "precise " : "",
io->invariant ? "invariant " : "", io->invariant ? "invariant " : "",
io->glsl_name, io->glsl_name,
io->last - io->first +1, io->last - io->first +1,
stage_prefix, blockvarame);
io->sid, } else {
postfix); emit_hdr(ctx, layout);
else emit_hdrf(ctx, "%s%s%s %s %s %s%s[%d];\n",
emit_hdrf(ctx, "%s%s%s %s vec4 %s%s[%d];\n",
prefix, prefix,
io->precise ? "precise " : "", io->precise ? "precise " : "",
io->invariant ? "invariant " : "", io->invariant ? "invariant " : "",
inout, inout,
t,
io->glsl_name, io->glsl_name,
postfix, postfix,
io->last - io->first +1); io->last - io->first +1);
}
} }
} }
static void static void
emit_ios_patch(struct dump_ctx *ctx, const char *prefix, const char *stage_prefix, emit_ios_patch(struct dump_ctx *ctx, const char *prefix, const struct vrend_shader_io *io,
const struct vrend_shader_io *io, const char *inout, int size) const char *inout, int size)
{ {
const char type[4][6] = {"float", " vec2", " vec3", " vec4"};
const char *t = " vec4";
if (io->layout_location > 0) {
/* we need to define a layout here because interleaved arrays might be emited */
if (io->swizzle_offset)
emit_hdrf(ctx, "layout(location = %d, component = %d)\n",
io->layout_location - 1, io->swizzle_offset);
else
emit_hdrf(ctx, "layout(location = %d)\n", io->layout_location - 1);
}
if (io->usage_mask != 0xf)
t = type[io->num_components - 1];
if (io->last == io->first) if (io->last == io->first)
emit_hdrf(ctx, "%s %s vec4 %s;\n", prefix, inout, io->glsl_name); emit_hdrf(ctx, "%s %s %s %s;\n", prefix, inout, t, io->glsl_name);
else else
emit_hdrf(ctx, "%s %s vec4 %s_p%d[%d];\n", prefix, inout, stage_prefix, emit_hdrf(ctx, "%s %s %s %s[%d];\n", prefix, inout, t,
io->sid, size); io->glsl_name, size);
} }
@ -5332,9 +5376,7 @@ static void emit_ios_vs(struct dump_ctx *ctx)
} else } else
prefix = ""; prefix = "";
emit_ios_generics(ctx, io_out, prefix, emit_ios_generics(ctx, io_out, prefix, &ctx->outputs[i],
get_stage_output_name_prefix(ctx->prog_type),
&ctx->outputs[i],
ctx->outputs[i].fbfetch_used ? "inout" : "out", ""); ctx->outputs[i].fbfetch_used ? "inout" : "out", "");
} else if (ctx->outputs[i].invariant || ctx->outputs[i].precise) { } else if (ctx->outputs[i].invariant || ctx->outputs[i].precise) {
@ -5427,9 +5469,7 @@ static void emit_ios_fs(struct dump_ctx *ctx)
char prefixes[64]; char prefixes[64];
snprintf(prefixes, sizeof(prefixes), "%s %s", prefix, auxprefix); snprintf(prefixes, sizeof(prefixes), "%s %s", prefix, auxprefix);
emit_ios_generics(ctx, io_in, prefixes, emit_ios_generics(ctx, io_in, prefixes, &ctx->inputs[i], "in", "");
get_stage_input_name_prefix(ctx, ctx->prog_type),
&ctx->inputs[i], "in", "");
} }
if (ctx->cfg->use_gles && !ctx->key->winsys_adjust_y_emitted && if (ctx->cfg->use_gles && !ctx->key->winsys_adjust_y_emitted &&
@ -5457,9 +5497,7 @@ static void emit_ios_fs(struct dump_ctx *ctx)
for (i = 0; i < ctx->num_outputs; i++) { for (i = 0; i < ctx->num_outputs; i++) {
if (!ctx->outputs[i].glsl_predefined_no_emit) { if (!ctx->outputs[i].glsl_predefined_no_emit) {
emit_ios_generics(ctx, io_out, "", emit_ios_generics(ctx, io_out, "", &ctx->outputs[i],
get_stage_output_name_prefix(ctx->prog_type),
&ctx->outputs[i],
ctx->outputs[i].fbfetch_used ? "inout" : "out", ""); ctx->outputs[i].fbfetch_used ? "inout" : "out", "");
} else if (ctx->outputs[i].invariant || ctx->outputs[i].precise) { } else if (ctx->outputs[i].invariant || ctx->outputs[i].precise) {
@ -5503,9 +5541,7 @@ static void emit_ios_geom(struct dump_ctx *ctx)
if (!ctx->inputs[i].glsl_predefined_no_emit) { if (!ctx->inputs[i].glsl_predefined_no_emit) {
char postfix[64]; char postfix[64];
snprintf(postfix, sizeof(postfix), "[%d]", gs_input_prim_to_size(ctx->gs_in_prim)); snprintf(postfix, sizeof(postfix), "[%d]", gs_input_prim_to_size(ctx->gs_in_prim));
emit_ios_generics(ctx, io_in, "", emit_ios_generics(ctx, io_in, "", &ctx->inputs[i], "in", postfix);
get_stage_input_name_prefix(ctx, ctx->prog_type),
&ctx->inputs[i], "in", postfix);
} }
} }
@ -5527,9 +5563,7 @@ static void emit_ios_geom(struct dump_ctx *ctx)
ctx->outputs[i].invariant ? "invariant " : "", ctx->outputs[i].invariant ? "invariant " : "",
ctx->outputs[i].glsl_name); ctx->outputs[i].glsl_name);
else else
emit_ios_generics(ctx, io_out, prefix, emit_ios_generics(ctx, io_out, prefix, &ctx->outputs[i],
get_stage_output_name_prefix(ctx->prog_type),
&ctx->outputs[i],
ctx->outputs[i].fbfetch_used ? "inout" : "out", ""); ctx->outputs[i].fbfetch_used ? "inout" : "out", "");
} else if (ctx->outputs[i].invariant || ctx->outputs[i].precise) { } else if (ctx->outputs[i].invariant || ctx->outputs[i].precise) {
emit_hdrf(ctx, "%s%s;\n", emit_hdrf(ctx, "%s%s;\n",
@ -5585,12 +5619,9 @@ static void emit_ios_tcs(struct dump_ctx *ctx)
for (i = 0; i < ctx->num_inputs; i++) { for (i = 0; i < ctx->num_inputs; i++) {
if (!ctx->inputs[i].glsl_predefined_no_emit) { if (!ctx->inputs[i].glsl_predefined_no_emit) {
if (ctx->inputs[i].name == TGSI_SEMANTIC_PATCH) if (ctx->inputs[i].name == TGSI_SEMANTIC_PATCH)
emit_ios_patch(ctx, "", get_stage_input_name_prefix(ctx, ctx->prog_type), emit_ios_patch(ctx, "", &ctx->inputs[i], "in", ctx->inputs[i].last - ctx->inputs[i].first + 1);
&ctx->inputs[i], "in", ctx->inputs[i].last - ctx->inputs[i].first + 1);
else else
emit_ios_generics(ctx, io_in, "", emit_ios_generics(ctx, io_in, "", &ctx->inputs[i], "in", "[]");
get_stage_input_name_prefix(ctx, ctx->prog_type),
&ctx->inputs[i], "in", "[]");
} }
} }
@ -5598,21 +5629,17 @@ static void emit_ios_tcs(struct dump_ctx *ctx)
emit_ios_indirect_generics_output(ctx, "[]"); emit_ios_indirect_generics_output(ctx, "[]");
const char *stage_prefix = get_stage_output_name_prefix(ctx->prog_type);
if (ctx->patch_output_range.used) if (ctx->patch_output_range.used)
emit_ios_patch(ctx, "patch", stage_prefix, &ctx->patch_output_range.io, "out", emit_ios_patch(ctx, "patch", &ctx->patch_output_range.io, "out",
ctx->patch_output_range.io.last - ctx->patch_output_range.io.sid + 1); ctx->patch_output_range.io.last - ctx->patch_output_range.io.sid + 1);
for (i = 0; i < ctx->num_outputs; i++) { for (i = 0; i < ctx->num_outputs; i++) {
if (!ctx->outputs[i].glsl_predefined_no_emit) { if (!ctx->outputs[i].glsl_predefined_no_emit) {
const char *stage_prefix = get_stage_output_name_prefix(ctx->prog_type); if (ctx->outputs[i].name == TGSI_SEMANTIC_PATCH) {
if (ctx->outputs[i].name == TGSI_SEMANTIC_PATCH) emit_ios_patch(ctx, "patch", &ctx->outputs[i], "out",
emit_ios_patch(ctx, "patch", stage_prefix, &ctx->outputs[i], "out",
ctx->outputs[i].last - ctx->outputs[i].first + 1); ctx->outputs[i].last - ctx->outputs[i].first + 1);
else } else
emit_ios_generics(ctx, io_out, "", stage_prefix, emit_ios_generics(ctx, io_out, "", &ctx->outputs[i], "out", "[]");
&ctx->outputs[i], "out", "[]");
} else if (ctx->outputs[i].invariant || ctx->outputs[i].precise) { } else if (ctx->outputs[i].invariant || ctx->outputs[i].precise) {
emit_hdrf(ctx, "%s%s;\n", emit_hdrf(ctx, "%s%s;\n",
ctx->outputs[i].precise ? "precise " : ctx->outputs[i].precise ? "precise " :
@ -5645,10 +5672,8 @@ static void emit_ios_tes(struct dump_ctx *ctx)
{ {
uint32_t i; uint32_t i;
const char *name_prefix = get_stage_input_name_prefix(ctx, ctx->prog_type);
if (ctx->patch_input_range.used) if (ctx->patch_input_range.used)
emit_ios_patch(ctx, "patch", name_prefix, &ctx->patch_input_range.io, "in", emit_ios_patch(ctx, "patch", &ctx->patch_input_range.io, "in",
ctx->patch_input_range.io.last - ctx->patch_input_range.io.sid + 1); ctx->patch_input_range.io.last - ctx->patch_input_range.io.sid + 1);
if (ctx->generic_input_range.used) if (ctx->generic_input_range.used)
@ -5657,11 +5682,10 @@ static void emit_ios_tes(struct dump_ctx *ctx)
for (i = 0; i < ctx->num_inputs; i++) { for (i = 0; i < ctx->num_inputs; i++) {
if (!ctx->inputs[i].glsl_predefined_no_emit) { if (!ctx->inputs[i].glsl_predefined_no_emit) {
if (ctx->inputs[i].name == TGSI_SEMANTIC_PATCH) if (ctx->inputs[i].name == TGSI_SEMANTIC_PATCH)
emit_ios_patch(ctx, "patch", name_prefix, &ctx->inputs[i], "in", emit_ios_patch(ctx, "patch", &ctx->inputs[i], "in",
ctx->inputs[i].last - ctx->inputs[i].first + 1); ctx->inputs[i].last - ctx->inputs[i].first + 1);
else else
emit_ios_generics(ctx, io_in, "", name_prefix, emit_ios_generics(ctx, io_in, "", &ctx->inputs[i], "in", "[]");
&ctx->inputs[i], "in", "[]");
} }
} }
@ -5680,9 +5704,7 @@ static void emit_ios_tes(struct dump_ctx *ctx)
ctx->num_interps++; ctx->num_interps++;
prefix = INTERP_PREFIX; prefix = INTERP_PREFIX;
} }
emit_ios_generics(ctx, io_out, prefix, emit_ios_generics(ctx, io_out, prefix, &ctx->outputs[i],
get_stage_output_name_prefix(ctx->prog_type),
&ctx->outputs[i],
ctx->outputs[i].fbfetch_used ? "inout" : "out", ""); ctx->outputs[i].fbfetch_used ? "inout" : "out", "");
} else if (ctx->outputs[i].invariant || ctx->outputs[i].precise) { } else if (ctx->outputs[i].invariant || ctx->outputs[i].precise) {

Loading…
Cancel
Save