[Mesa-dev] [PATCH 3/3] draw/softpipe: add clip vertex support.
Dave Airlie
airlied at gmail.com
Wed Jan 4 04:13:01 PST 2012
From: Dave Airlie <airlied at redhat.com>
softpipe always clipped using the position vector, however for unclipped
vertices it stored the position in window coordinates, however when position
and clipping are separated, we need to store the clip-space position and
the clip-space vertex clip, so we can interpolate both separately.
This means we have to take the clip space position and store it to use later.
This allows softpipe to pass all the clip-vertex piglit tests.
Signed-off-by: Dave Airlie <airlied at redhat.com>
---
src/gallium/auxiliary/draw/draw_cliptest_tmp.h | 18 ++++++++++++------
src/gallium/auxiliary/draw/draw_context.c | 10 ++++++++++
src/gallium/auxiliary/draw/draw_pipe_clip.c | 9 ++++++---
src/gallium/auxiliary/draw/draw_private.h | 5 +++--
src/gallium/auxiliary/draw/draw_pt_fetch.c | 4 ++--
src/gallium/auxiliary/draw/draw_vs.c | 9 +++++++++
src/gallium/auxiliary/draw/draw_vs.h | 1 +
7 files changed, 43 insertions(+), 13 deletions(-)
diff --git a/src/gallium/auxiliary/draw/draw_cliptest_tmp.h b/src/gallium/auxiliary/draw/draw_cliptest_tmp.h
index 1ca1529..7ae95a6 100644
--- a/src/gallium/auxiliary/draw/draw_cliptest_tmp.h
+++ b/src/gallium/auxiliary/draw/draw_cliptest_tmp.h
@@ -35,11 +35,13 @@ static boolean TAG(do_cliptest)( struct pt_post_vs *pvs,
const float *trans = pvs->draw->viewport.translate;
/* const */ float (*plane)[4] = pvs->draw->plane;
const unsigned pos = draw_current_shader_position_output(pvs->draw);
+ const unsigned cv = draw_current_shader_clipvertex_output(pvs->draw);
const unsigned ef = pvs->draw->vs.edgeflag_output;
const unsigned nr = pvs->draw->nr_planes;
const unsigned flags = (FLAGS);
unsigned need_pipeline = 0;
unsigned j;
+ unsigned i;
for (j = 0; j < info->count; j++) {
float *position = out->data[pos];
@@ -49,10 +51,15 @@ static boolean TAG(do_cliptest)( struct pt_post_vs *pvs,
if (flags & (DO_CLIP_XY | DO_CLIP_XY_GUARD_BAND |
DO_CLIP_FULL_Z | DO_CLIP_HALF_Z | DO_CLIP_USER)) {
- out->clip[0] = position[0];
- out->clip[1] = position[1];
- out->clip[2] = position[2];
- out->clip[3] = position[3];
+ float *clipvertex = position;
+
+ if ((flags & DO_CLIP_USER) && cv != pos)
+ clipvertex = out->data[cv];
+
+ for (i = 0; i < 4; i++) {
+ out->clip[i] = clipvertex[i];
+ out->pre_clip_pos[i] = position[i];
+ }
/* Do the hardwired planes first:
*/
@@ -81,9 +88,8 @@ static boolean TAG(do_cliptest)( struct pt_post_vs *pvs,
}
if (flags & DO_CLIP_USER) {
- unsigned i;
for (i = 6; i < nr; i++) {
- if (dot4(position, plane[i]) < 0)
+ if (dot4(clipvertex, plane[i]) < 0)
mask |= (1<<i);
}
}
diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c
index 9c00687..6b58073 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -675,6 +675,16 @@ draw_current_shader_position_output(const struct draw_context *draw)
/**
+ * Return the index of the shader output which will contain the
+ * vertex position.
+ */
+uint
+draw_current_shader_clipvertex_output(const struct draw_context *draw)
+{
+ return draw->vs.clipvertex_output;
+}
+
+/**
* Return a pointer/handle for a driver/CSO rasterizer object which
* disabled culling, stippling, unfilled tris, etc.
* This is used by some pipeline stages (such as wide_point, aa_line
diff --git a/src/gallium/auxiliary/draw/draw_pipe_clip.c b/src/gallium/auxiliary/draw/draw_pipe_clip.c
index e1eabe2..fbc8f67 100644
--- a/src/gallium/auxiliary/draw/draw_pipe_clip.c
+++ b/src/gallium/auxiliary/draw/draw_pipe_clip.c
@@ -118,6 +118,7 @@ static void interp( const struct clip_stage *clip,
{
const unsigned nr_attrs = draw_current_shader_outputs(clip->stage.draw);
const unsigned pos_attr = draw_current_shader_position_output(clip->stage.draw);
+ const unsigned clip_attr = draw_current_shader_clipvertex_output(clip->stage.draw);
unsigned j;
/* Vertex header.
@@ -130,12 +131,14 @@ static void interp( const struct clip_stage *clip,
/* Interpolate the clip-space coords.
*/
interp_attr(dst->clip, t, in->clip, out->clip);
+ /* interpolate the clip-space position */
+ interp_attr(dst->pre_clip_pos, t, in->pre_clip_pos, out->pre_clip_pos);
/* Do the projective divide and viewport transformation to get
* new window coordinates:
*/
{
- const float *pos = dst->clip;
+ const float *pos = dst->pre_clip_pos;
const float *scale = clip->stage.draw->viewport.scale;
const float *trans = clip->stage.draw->viewport.translate;
const float oow = 1.0f / pos[3];
@@ -149,8 +152,8 @@ static void interp( const struct clip_stage *clip,
/* Other attributes
*/
for (j = 0; j < nr_attrs; j++) {
- if (j != pos_attr)
- interp_attr(dst->data[j], t, in->data[j], out->data[j]);
+ if (j != pos_attr && j != clip_attr)
+ interp_attr(dst->data[j], t, in->data[j], out->data[j]);
}
}
diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h
index 89653e1..d101c32 100644
--- a/src/gallium/auxiliary/draw/draw_private.h
+++ b/src/gallium/auxiliary/draw/draw_private.h
@@ -76,7 +76,7 @@ struct vertex_header {
unsigned vertex_id:16;
float clip[4];
-
+ float pre_clip_pos[4];
/* This will probably become float (*data)[4] soon:
*/
float data[][4];
@@ -230,6 +230,7 @@ struct draw_context
uint num_vs_outputs; /**< convenience, from vertex_shader */
uint position_output;
uint edgeflag_output;
+ uint clipvertex_output;
/** TGSI program interpreter runtime state */
struct tgsi_exec_machine *machine;
@@ -380,7 +381,7 @@ void draw_gs_destroy( struct draw_context *draw );
*/
uint draw_current_shader_outputs(const struct draw_context *draw);
uint draw_current_shader_position_output(const struct draw_context *draw);
-
+uint draw_current_shader_clipvertex_output(const struct draw_context *draw);
int draw_alloc_extra_vertex_attrib(struct draw_context *draw,
uint semantic_name, uint semantic_index);
void draw_remove_extra_vertex_attribs(struct draw_context *draw);
diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch.c b/src/gallium/auxiliary/draw/draw_pt_fetch.c
index 81c7ec7..2b05762 100644
--- a/src/gallium/auxiliary/draw/draw_pt_fetch.c
+++ b/src/gallium/auxiliary/draw/draw_pt_fetch.c
@@ -71,9 +71,9 @@ void draw_pt_fetch_prepare( struct pt_fetch *fetch,
/* Leave the clipmask/edgeflags/pad/vertex_id untouched
*/
dst_offset += 1 * sizeof(float);
- /* Just leave the clip[] array untouched.
+ /* Just leave the clip[] and pre_clip_pos[] array untouched.
*/
- dst_offset += 4 * sizeof(float);
+ dst_offset += 8 * sizeof(float);
if (instance_id_index != ~0) {
num_extra_inputs++;
diff --git a/src/gallium/auxiliary/draw/draw_vs.c b/src/gallium/auxiliary/draw/draw_vs.c
index bc1c90b..150653c 100644
--- a/src/gallium/auxiliary/draw/draw_vs.c
+++ b/src/gallium/auxiliary/draw/draw_vs.c
@@ -120,6 +120,7 @@ draw_create_vertex_shader(struct draw_context *draw,
if (vs)
{
uint i;
+ bool found_clipvertex = FALSE;
for (i = 0; i < vs->info.num_outputs; i++) {
if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_POSITION &&
vs->info.output_semantic_index[i] == 0)
@@ -127,7 +128,14 @@ draw_create_vertex_shader(struct draw_context *draw,
else if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_EDGEFLAG &&
vs->info.output_semantic_index[i] == 0)
vs->edgeflag_output = i;
+ else if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_CLIPVERTEX &&
+ vs->info.output_semantic_index[i] == 0) {
+ found_clipvertex = TRUE;
+ vs->clipvertex_output = i;
+ }
}
+ if (!found_clipvertex)
+ vs->clipvertex_output = vs->position_output;
}
assert(vs);
@@ -147,6 +155,7 @@ draw_bind_vertex_shader(struct draw_context *draw,
draw->vs.num_vs_outputs = dvs->info.num_outputs;
draw->vs.position_output = dvs->position_output;
draw->vs.edgeflag_output = dvs->edgeflag_output;
+ draw->vs.clipvertex_output = dvs->clipvertex_output;
dvs->prepare( dvs, draw );
}
else {
diff --git a/src/gallium/auxiliary/draw/draw_vs.h b/src/gallium/auxiliary/draw/draw_vs.h
index 49229f8..a3b90fa 100644
--- a/src/gallium/auxiliary/draw/draw_vs.h
+++ b/src/gallium/auxiliary/draw/draw_vs.h
@@ -111,6 +111,7 @@ struct draw_vertex_shader {
struct tgsi_shader_info info;
unsigned position_output;
unsigned edgeflag_output;
+ unsigned clipvertex_output;
/* Extracted from shader:
*/
--
1.7.7.3
More information about the mesa-dev
mailing list