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 <gert.wollny@collabora.com>
Reviewed-By: Gurchetan Singh <gurchetansingh@chromium.org>
macos/master
Gert Wollny 6 years ago committed by Gert Wollny
parent 9157dcbca0
commit 31562ef40b
  1. 39
      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); 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 static
void emit_fs_clipdistance_load(struct dump_ctx *ctx) 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; 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"); emit_buf(ctx, "void main(void)\n{\n");
if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT) { if (iter->processor.Processor == TGSI_PROCESSOR_FRAGMENT) {
emit_color_select(ctx); 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) static void emit_ios_vs(struct dump_ctx *ctx)
{ {
uint32_t i; uint32_t i;
char postfix[8]; char postfix[32];
const char *prefix = "", *auxprefix = ""; const char *prefix = "", *auxprefix = "";
bool fcolor_emitted[2], bcolor_emitted[2]; bool fcolor_emitted[2], bcolor_emitted[2];
@ -5368,6 +5403,8 @@ static void emit_ios_vs(struct dump_ctx *ctx)
prefix = ""; prefix = "";
auxprefix = ""; auxprefix = "";
postfix[0] = 0; 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); emit_hdrf(ctx, "%s%sin vec4 %s%s;\n", prefix, auxprefix, ctx->inputs[i].glsl_name, postfix);
} }
} }

Loading…
Cancel
Save