[virglrenderer-devel] [PATCH 11/19] tessellation: add clip distance support.
Dave Airlie
airlied at gmail.com
Fri Jun 8 05:14:15 UTC 2018
From: Dave Airlie <airlied at redhat.com>
This changes the swizzled clip distance emit to allow for reading
from outputs, which will be used in a later patch
---
src/vrend_shader.c | 63 ++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 52 insertions(+), 11 deletions(-)
diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index bb4c6cf..10c60a9 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -618,7 +618,9 @@ iter_declaration(struct tgsi_iterate_context *iter,
break;
}
case TGSI_SEMANTIC_CLIPDIST:
- if (iter->processor.Processor == TGSI_PROCESSOR_GEOMETRY) {
+ if (iter->processor.Processor == TGSI_PROCESSOR_GEOMETRY ||
+ iter->processor.Processor == TGSI_PROCESSOR_TESS_CTRL ||
+ iter->processor.Processor == TGSI_PROCESSOR_TESS_EVAL) {
name_prefix = "gl_ClipDistance";
ctx->inputs[i].glsl_predefined_no_emit = true;
ctx->inputs[i].glsl_no_index = true;
@@ -750,8 +752,10 @@ iter_declaration(struct tgsi_iterate_context *iter,
ctx->outputs[i].glsl_no_index = true;
ctx->num_clip_dist += 4;
if (iter->processor.Processor == TGSI_PROCESSOR_VERTEX &&
- ctx->key->gs_present)
+ (ctx->key->gs_present || ctx->key->tcs_present))
require_glsl_ver(ctx, 150);
+ if (iter->processor.Processor == TGSI_PROCESSOR_TESS_CTRL)
+ ctx->outputs[i].glsl_gl_block = true;
break;
case TGSI_SEMANTIC_CLIPVERTEX:
name_prefix = "gl_ClipVertex";
@@ -1285,9 +1289,13 @@ static int emit_clip_dist_movs(struct dump_ctx *ctx)
char *sret;
bool has_prop = (ctx->num_clip_dist_prop + ctx->num_cull_dist_prop) > 0;
int ndists;
+ const char *prefix="";
+
+ if (ctx->prog_type == PIPE_SHADER_TESS_CTRL)
+ prefix = "gl_out[gl_InvocationID].";
if (ctx->num_clip_dist == 0 && ctx->key->clip_plane_enable) {
for (i = 0; i < 8; i++) {
- snprintf(buf, 255, "gl_ClipDistance[%d] = dot(%s, clipp[%d]);\n", i, ctx->has_clipvertex ? "clipv_tmp" : "gl_Position", i);
+ snprintf(buf, 255, "%sgl_ClipDistance[%d] = dot(%s, clipp[%d]);\n", prefix, i, ctx->has_clipvertex ? "clipv_tmp" : "gl_Position", i);
sret = add_str_to_glsl_main(ctx, buf);
if (!sret)
return ENOMEM;
@@ -1315,7 +1323,7 @@ static int emit_clip_dist_movs(struct dump_ctx *ctx)
is_cull = true;
}
const char *clip_cull = is_cull ? "Cull" : "Clip";
- snprintf(buf, 255, "gl_%sDistance[%d] = clip_dist_temp[%d].%c;\n", clip_cull,
+ snprintf(buf, 255, "%sgl_%sDistance[%d] = clip_dist_temp[%d].%c;\n", prefix, clip_cull,
is_cull ? i - ctx->num_clip_dist_prop : i, clipidx, wm);
sret = add_str_to_glsl_main(ctx, buf);
if (!sret)
@@ -1873,8 +1881,8 @@ static void
create_swizzled_clipdist(struct dump_ctx *ctx,
char *result,
const struct tgsi_full_src_register *src,
- int input_idx,
- bool gl_in,
+ int sid,
+ int direction,
const char *stypeprefix,
const char *prefix,
const char *arrayname)
@@ -1885,8 +1893,8 @@ create_swizzled_clipdist(struct dump_ctx *ctx,
int num_culls = has_prev_vals ? ctx->key->prev_stage_num_cull_out : 0;
int num_clips = has_prev_vals ? ctx->key->prev_stage_num_clip_out : ctx->num_in_clip_dist;
for (unsigned cc = 0; cc < 4; cc++) {
- const char *cc_name = ctx->inputs[input_idx].glsl_name;
- idx = ctx->inputs[input_idx].sid * 4;
+ const char *cc_name = "gl_ClipDistance";
+ idx = sid * 4;
if (cc == 0)
idx += src->Register.SwizzleX;
else if (cc == 1)
@@ -1909,8 +1917,10 @@ create_swizzled_clipdist(struct dump_ctx *ctx,
if (idx >= ctx->key->prev_stage_num_clip_out)
idx = 0;
}
- if (gl_in)
+ if (direction == -1)
snprintf(clipdistvec[cc], 64, "%sgl_in%s.%s[%d]", prefix, arrayname, cc_name, idx);
+ else if (direction == 1)
+ snprintf(clipdistvec[cc], 64, "%sgl_out%s.%s[%d]", prefix, arrayname, cc_name, idx);
else
snprintf(clipdistvec[cc], 64, "%s%s%s[%d]", prefix, arrayname, cc_name, idx);
}
@@ -2109,7 +2119,7 @@ get_source_info(struct dump_ctx *ctx,
else if (ctx->inputs[j].glsl_gl_block) {
/* GS input clipdist requires a conversion */
if (ctx->inputs[j].name == TGSI_SEMANTIC_CLIPDIST) {
- create_swizzled_clipdist(ctx, srcs[i], src, j, true, get_string(stypeprefix), prefix, arrayname);
+ create_swizzled_clipdist(ctx, srcs[i], src, ctx->inputs[j].sid, -1, get_string(stypeprefix), prefix, arrayname);
} else {
snprintf(srcs[i], 255, "%s(vec4(%sgl_in%s.%s)%s)", get_string(stypeprefix), prefix, arrayname, ctx->inputs[j].glsl_name, swizzle);
}
@@ -2119,7 +2129,7 @@ get_source_info(struct dump_ctx *ctx,
else if (ctx->inputs[j].name == TGSI_SEMANTIC_FACE)
snprintf(srcs[i], 255, "%s(%s ? 1.0 : -1.0)", get_string(stypeprefix), ctx->inputs[j].glsl_name);
else if (ctx->inputs[j].name == TGSI_SEMANTIC_CLIPDIST) {
- create_swizzled_clipdist(ctx, srcs[i], src, j, false, get_string(stypeprefix), prefix, arrayname);
+ create_swizzled_clipdist(ctx, srcs[i], src, j, 0, get_string(stypeprefix), prefix, arrayname);
} else {
enum vrend_type_qualifier srcstypeprefix = stypeprefix;
if (stype == TGSI_TYPE_UNSIGNED &&
@@ -2686,6 +2696,13 @@ iter_instruction(struct tgsi_iterate_context *iter,
if (handle_vertex_proc_exit(ctx) == FALSE)
return FALSE;
} else if (iter->processor.Processor == TGSI_PROCESSOR_TESS_CTRL) {
+ ret = emit_clip_dist_movs(ctx);
+ if (ret)
+ return FALSE;
+ } else if (iter->processor.Processor == TGSI_PROCESSOR_TESS_EVAL) {
+ ret = emit_clip_dist_movs(ctx);
+ if (ret)
+ return FALSE;
if (!ctx->key->gs_present) {
ret = emit_prescale(ctx);
if (ret)
@@ -3207,6 +3224,30 @@ static char *emit_ios(struct dump_ctx *ctx, char *glsl_hdr)
}
}
+ if (ctx->prog_type == TGSI_PROCESSOR_TESS_CTRL || ctx->prog_type == TGSI_PROCESSOR_TESS_EVAL) {
+ 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;
+
+ 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);
+
+ snprintf(buf, 255, "in gl_PerVertex {\n vec4 gl_Position;\n float gl_PointSize; \n %s%s} gl_in[];\n", clip_var, cull_var);
+ STRCAT_WITH_RET(glsl_hdr, buf);
+ }
+ if (ctx->num_clip_dist) {
+ snprintf(buf, 255, "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);
+ STRCAT_WITH_RET(glsl_hdr, buf);
+ snprintf(buf, 255, "vec4 clip_dist_temp[2];\n");
+ STRCAT_WITH_RET(glsl_hdr, buf);
+ }
+ }
+
if (ctx->so) {
char outtype[6] = {0};
for (i = 0; i < ctx->so->num_outputs; i++) {
--
2.14.3
More information about the virglrenderer-devel
mailing list