From 7523f35e625e6930540a8c107ec26c9b6845b840 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Tue, 12 Feb 2019 14:37:38 +0100 Subject: [PATCH] shader: renumber the input arrays to get consistent interfaces If the guest sends individual arrays they might be numbered in an abitrary way, but we need them ordered to be able to find corresponding in and outputs. Signed-off-by: Gert Wollny Reviewed-By: Gurchetan Singh --- src/vrend_shader.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/vrend_shader.c b/src/vrend_shader.c index 55f3c6c..94a0bd8 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -3774,6 +3774,19 @@ void emit_fs_clipdistance_load(struct dump_ctx *ctx) } +static +void renumber_io_arrays(unsigned nio, struct vrend_shader_io *io) +{ + int next_array_id = 1; + for (unsigned i = 0; i < nio; ++i) { + if (io[i].name != TGSI_SEMANTIC_GENERIC && + io[i].name != TGSI_SEMANTIC_PATCH) + continue; + if (io[i].array_id > 0) + io[i].array_id = next_array_id++; + } +} + static boolean iter_instruction(struct tgsi_iterate_context *iter, struct tgsi_full_instruction *inst) @@ -3795,10 +3808,20 @@ iter_instruction(struct tgsi_iterate_context *iter, if (instno == 0) { /* If the guest sent real IO arrays then we declare them individually, - * otherwise we might have to add a big array for all generic and patch - * inputs */ - if (!ctx->guest_sent_io_arrays) + * and have to do some work to deal with overlapping values, regions and + * enhanced layouts */ + if (ctx->guest_sent_io_arrays) { + + /* Array ID numbering is not ordered accross shaders, so do + * some renumbering for generics and patches. */ + renumber_io_arrays(ctx->num_inputs, ctx->inputs); + renumber_io_arrays(ctx->num_outputs, ctx->outputs); + } else { + /* The guest didn't send real arrays, do we might have to add a big array + * for all generic and another ofr patch inputs */ rewrite_io_ranged(ctx); + } + emit_buf(ctx, "void main(void)\n{\n"); if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT) {