shader: rewrite the componets when no arrays are sent

The guest might send component layouts that we don't want to deal with
when we are in the no-guest-arrays code path, so rewrite the component
layouts and then rename the variables.

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 7523f35e62
commit 04e5adfa0c
  1. 60
      src/vrend_shader.c

@ -3732,6 +3732,59 @@ void rewrite_io_ranged(struct dump_ctx *ctx)
} }
static void rename_variables(unsigned nio, struct vrend_shader_io *io,
const char *name_prefix, unsigned coord_replace)
{
/* Rename the generic and patch variables after applying all identifications */
for (unsigned i = 0; i < nio; ++i) {
if ((io[i].name != TGSI_SEMANTIC_GENERIC &&
io[i].name != TGSI_SEMANTIC_PATCH) ||
(coord_replace & (1 << io[i].sid)))
continue;
char io_type = io[i].name == TGSI_SEMANTIC_GENERIC ? 'g' : 'p';
snprintf(io[i].glsl_name, 64, "%s_%c%dA%d_%x", name_prefix, io_type, io[i].sid, io[i].array_id, io[i].usage_mask);
}
}
static
void rewrite_components(unsigned nio, struct vrend_shader_io *io,
const char *name_prefix, unsigned coord_replace,
bool no_input_arrays)
{
if (!nio)
return;
for (unsigned i = 0; i < nio - 1; ++i) {
if ((io[i].name != TGSI_SEMANTIC_GENERIC &&
io[i].name != TGSI_SEMANTIC_PATCH) ||
io[i].glsl_predefined_no_emit)
continue;
for (unsigned j = i + 1; j < nio; ++j) {
if ((io[j].name != TGSI_SEMANTIC_GENERIC &&
io[j].name != TGSI_SEMANTIC_PATCH) ||
io[j].glsl_predefined_no_emit)
continue;
if (io[i].first == io[j].first)
io[j].glsl_predefined_no_emit = true;
}
}
for (unsigned i = 0; i < nio; ++i) {
if ((io[i].name != TGSI_SEMANTIC_GENERIC &&
io[i].name != TGSI_SEMANTIC_PATCH) ||
!no_input_arrays)
continue;
io[i].usage_mask = 0xf;
io[i].num_components = 4;
io[i].swizzle_offset = 0;
io[i].override_no_wm = false;
}
rename_variables(nio, io, name_prefix, coord_replace);
}
static static
void emit_fs_clipdistance_load(struct dump_ctx *ctx) void emit_fs_clipdistance_load(struct dump_ctx *ctx)
{ {
@ -3820,8 +3873,13 @@ iter_instruction(struct tgsi_iterate_context *iter,
/* The guest didn't send real arrays, do we might have to add a big array /* The guest didn't send real arrays, do we might have to add a big array
* for all generic and another ofr patch inputs */ * for all generic and another ofr patch inputs */
rewrite_io_ranged(ctx); rewrite_io_ranged(ctx);
} rewrite_components(ctx->num_inputs, ctx->inputs,
get_stage_input_name_prefix(ctx, ctx->prog_type),
ctx->key->coord_replace, true);
rewrite_components(ctx->num_outputs, ctx->outputs,
get_stage_output_name_prefix(ctx->prog_type), 0, true);
}
emit_buf(ctx, "void main(void)\n{\n"); emit_buf(ctx, "void main(void)\n{\n");
if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT) { if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT) {

Loading…
Cancel
Save