From 7418567f0c5d5b37eeae64df8aa580f6931a78dc Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Wed, 9 Jan 2019 16:14:13 +0100 Subject: [PATCH] shader: clean up TCS IO emit Signed-off-by: Gert Wollny Reviewed-by: Dave Airlie --- src/vrend_shader.c | 83 ++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 50 deletions(-) diff --git a/src/vrend_shader.c b/src/vrend_shader.c index f9d79c6..cd6dd55 100644 --- a/src/vrend_shader.c +++ b/src/vrend_shader.c @@ -4672,8 +4672,6 @@ static void emit_ios_geom(struct dump_ctx *ctx) static void emit_ios_tcs(struct dump_ctx *ctx) { uint32_t i; - char postfix[8]; - const char *prefix = ""; if (ctx_indirect_inputs(ctx)) { const char *name_prefix = get_stage_input_name_prefix(ctx, ctx->prog_type); @@ -4688,10 +4686,7 @@ static void emit_ios_tcs(struct dump_ctx *ctx) for (i = 0; i < ctx->num_inputs; i++) { if (!ctx->inputs[i].glsl_predefined_no_emit) { - if (ctx->inputs[i].name != TGSI_SEMANTIC_PATCH) { - snprintf(postfix, 8, "[]"); - } else - postfix[0] = 0; + const char *postfix = (ctx->inputs[i].name != TGSI_SEMANTIC_PATCH) ? "[]" : ""; emit_hdrf(ctx, "in vec4 %s%s;\n", ctx->inputs[i].glsl_name, postfix); } } @@ -4710,14 +4705,11 @@ static void emit_ios_tcs(struct dump_ctx *ctx) for (i = 0; i < ctx->num_outputs; i++) { if (!ctx->outputs[i].glsl_predefined_no_emit) { - prefix = ""; /* ugly leave spaces to patch interp in later */ - if (ctx->prog_type == TGSI_PROCESSOR_TESS_CTRL) { - if (ctx->outputs[i].name == TGSI_SEMANTIC_PATCH) - emit_hdrf(ctx, "patch out vec4 %s;\n", ctx->outputs[i].glsl_name); - else - emit_hdrf(ctx, "%sout vec4 %s[];\n", prefix, ctx->outputs[i].glsl_name); - } + if (ctx->outputs[i].name == TGSI_SEMANTIC_PATCH) + emit_hdrf(ctx, "patch out vec4 %s;\n", ctx->outputs[i].glsl_name); + else + emit_hdrf(ctx, "out vec4 %s[];\n", ctx->outputs[i].glsl_name); } else if (ctx->outputs[i].invariant || ctx->outputs[i].precise) { emit_hdrf(ctx, "%s%s;\n", ctx->outputs[i].precise ? "precise " : @@ -4726,33 +4718,29 @@ static void emit_ios_tcs(struct dump_ctx *ctx) } } - if (ctx->prog_type == TGSI_PROCESSOR_TESS_CTRL) { - if (ctx->num_in_clip_dist || ctx->key->prev_stage_pervertex_out) { - int clip_dist, cull_dist; - char clip_var[64] = {}, cull_var[64] = {}; + if (ctx->num_in_clip_dist || ctx->key->prev_stage_pervertex_out) { + int clip_dist, cull_dist; + char clip_var[64] = "", cull_var[64] = ""; - clip_dist = ctx->key->prev_stage_num_clip_out ? ctx->key->prev_stage_num_clip_out : ctx->num_in_clip_dist; - cull_dist = ctx->key->prev_stage_num_cull_out; + clip_dist = ctx->key->prev_stage_num_clip_out ? ctx->key->prev_stage_num_clip_out : ctx->num_in_clip_dist; + cull_dist = ctx->key->prev_stage_num_cull_out; - if (clip_dist) - snprintf(clip_var, 64, "float gl_ClipDistance[%d];\n", clip_dist); - if (cull_dist) - snprintf(cull_var, 64, "float gl_CullDistance[%d];\n", cull_dist); + if (clip_dist) + snprintf(clip_var, 64, "float gl_ClipDistance[%d];\n", clip_dist); + if (cull_dist) + snprintf(cull_var, 64, "float gl_CullDistance[%d];\n", cull_dist); - emit_hdrf(ctx, "in gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize; \n %s%s} gl_in[];\n", clip_var, cull_var); - } - if (ctx->num_clip_dist) { - emit_hdrf(ctx, "out gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize;\n float gl_ClipDistance[%d];\n} gl_out[];\n", ctx->num_clip_dist ? ctx->num_clip_dist : 8); - emit_hdr(ctx, "vec4 clip_dist_temp[2];\n"); - } + emit_hdrf(ctx, "in gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize; \n %s%s} gl_in[];\n", clip_var, cull_var); + } + if (ctx->num_clip_dist) { + emit_hdrf(ctx, "out gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize;\n float gl_ClipDistance[%d];\n} gl_out[];\n", ctx->num_clip_dist ? ctx->num_clip_dist : 8); + emit_hdr(ctx, "vec4 clip_dist_temp[2];\n"); } } static void emit_ios_tes(struct dump_ctx *ctx) { uint32_t i; - char postfix[8]; - const char *prefix = "", *auxprefix = ""; if (ctx_indirect_inputs(ctx)) { const char *name_prefix = get_stage_input_name_prefix(ctx, ctx->prog_type); @@ -4763,29 +4751,24 @@ static void emit_ios_tes(struct dump_ctx *ctx) emit_hdrf(ctx, "patch in vec4 %sp%d[%d];\n", name_prefix, ctx->patch_input_range.first, size); } - if (ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL) { - if (ctx->generic_input_range.used) { - int size = ctx->generic_input_range.last - ctx->generic_input_range.first + 1; - if (size < ctx->key->num_indirect_generic_inputs) - size = ctx->key->num_indirect_generic_inputs; - emit_hdrf(ctx, "in block { vec4 %s%d[%d]; } blk[];\n", name_prefix, ctx->generic_input_range.first, size); - } + if (ctx->generic_input_range.used) { + int size = ctx->generic_input_range.last - ctx->generic_input_range.first + 1; + if (size < ctx->key->num_indirect_generic_inputs) + size = ctx->key->num_indirect_generic_inputs; + emit_hdrf(ctx, "in block { vec4 %s%d[%d]; } blk[];\n", name_prefix, ctx->generic_input_range.first, size); } } + for (i = 0; i < ctx->num_inputs; i++) { if (!ctx->inputs[i].glsl_predefined_no_emit) { - prefix = ""; - auxprefix = ""; - if (ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL && ctx->inputs[i].name == TGSI_SEMANTIC_PATCH) + const char *prefix = ""; + const char *postfix = ""; + if (ctx->inputs[i].name == TGSI_SEMANTIC_PATCH) prefix = "patch "; - - if (ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL && ctx->inputs[i].name != TGSI_SEMANTIC_PATCH) { - snprintf(postfix, 8, "[]"); - } else - postfix[0] = 0; - emit_hdrf(ctx, "%s%sin vec4 %s%s;\n", prefix, auxprefix, ctx->inputs[i].glsl_name, postfix); + else + postfix = "[]"; + emit_hdrf(ctx, "%sin vec4 %s%s;\n", prefix, ctx->inputs[i].glsl_name, postfix); } - } emit_hdrf(ctx, "layout(%s, %s, %s%s) in;\n", @@ -4796,13 +4779,13 @@ static void emit_ios_tes(struct dump_ctx *ctx) for (i = 0; i < ctx->num_outputs; i++) { if (!ctx->outputs[i].glsl_predefined_no_emit) { + const char *prefix = ""; if (ctx->outputs[i].name == TGSI_SEMANTIC_GENERIC || ctx->outputs[i].name == TGSI_SEMANTIC_COLOR || ctx->outputs[i].name == TGSI_SEMANTIC_BCOLOR) { ctx->num_interps++; prefix = INTERP_PREFIX; - } else - prefix = ""; + } /* ugly leave spaces to patch interp in later */ emit_hdrf(ctx, "%s%s%s%s vec4 %s;\n",