From 31562ef40bed75753b11ad51824d36fbc50583b2 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Tue, 12 Feb 2019 19:52:26 +0100 Subject: [PATCH] shader: rewrite POS inputs that are read indirectly as array By enabling input arrays the TGSI may emit code that defines a number of POS inputs individually, but accesses them indirectly. Rewriting them as array makes it possible to emit proper GLSL in this case. Signed-off-by: Gert Wollny Reviewed-By: Gurchetan Singh --- src/vrend_shader.c | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/vrend_shader.c b/src/vrend_shader.c index a4193ff..fbdf8ab 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -3874,6 +3874,34 @@ void rewrite_components(unsigned nio, struct vrend_shader_io *io, rename_variables(nio, io, name_prefix, coord_replace); } +static +void rewrite_vs_pos_array(struct dump_ctx *ctx) +{ + int range_start = 0xffff; + int range_end = 0; + int io_idx = 0; + + for (uint i = 0; i < ctx->num_inputs; ++i) { + if (ctx->inputs[i].name == TGSI_SEMANTIC_POSITION) { + ctx->inputs[i].glsl_predefined_no_emit = true; + if (ctx->inputs[i].first < range_start) { + io_idx = i; + range_start = ctx->inputs[i].first; + } + if (ctx->inputs[i].last > range_end) + range_end = ctx->inputs[i].last; + } + } + + if (range_start != range_end) { + ctx->inputs[io_idx].first = range_start; + ctx->inputs[io_idx].last = range_end; + ctx->inputs[io_idx].glsl_predefined_no_emit = false; + require_glsl_ver(ctx, 150); + } +} + + static void emit_fs_clipdistance_load(struct dump_ctx *ctx) { @@ -4116,6 +4144,13 @@ iter_instruction(struct tgsi_iterate_context *iter, ctx->shader_req_bits |= SHADER_REQ_SEPERATE_SHADER_OBJECTS; } + /* Vertex shader inputs are not send as arrays, but the access may still be + * indirect. so we have to deal with that */ + if (ctx->prog_type == TGSI_PROCESSOR_VERTEX && + ctx->info.indirect_files & (1 << TGSI_FILE_INPUT)) { + rewrite_vs_pos_array(ctx); + } + emit_buf(ctx, "void main(void)\n{\n"); if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT) { emit_color_select(ctx); @@ -5349,7 +5384,7 @@ emit_ios_patch(struct dump_ctx *ctx, const char *prefix, const struct vrend_shad static void emit_ios_vs(struct dump_ctx *ctx) { uint32_t i; - char postfix[8]; + char postfix[32]; const char *prefix = "", *auxprefix = ""; bool fcolor_emitted[2], bcolor_emitted[2]; @@ -5368,6 +5403,8 @@ static void emit_ios_vs(struct dump_ctx *ctx) prefix = ""; auxprefix = ""; postfix[0] = 0; + if (ctx->inputs[i].first != ctx->inputs[i].last) + snprintf(postfix, sizeof(postfix), "[%d]", ctx->inputs[i].last - ctx->inputs[i].first + 1); emit_hdrf(ctx, "%s%sin vec4 %s%s;\n", prefix, auxprefix, ctx->inputs[i].glsl_name, postfix); } }