[Mesa-dev] Mesa (master): draw: fix flat shading and screen-space linear interpolation in clipper
Jose Fonseca
jfonseca at vmware.com
Thu Jun 21 10:28:22 PDT 2012
Olivier,
This patch series is causing regressions in select/feedback mode. Can you take a look?
In piglit:
piglit-ci/framework/../bin/select general
Returncode: -11
And in conform:
New LWP 15135]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `conform -v 2 -1 select.c -direct -D 1'.
Program terminated with signal 11, Segmentation fault.
#0 clip_init_state (stage=0x11c7ad0) at src/gallium/auxiliary/draw/draw_pipe_clip.c:598
#0 clip_init_state (stage=0x11c7ad0) at src/gallium/auxiliary/draw/draw_pipe_clip.c:598
vs = 0x1258d10
fs = 0x0
i = <optimized out>
indexed_interp = {20, 0}
#1 0x00007fca71f4a26b in clip_first_line (stage=0x11c7ad0, header=0x7fff07fb63c0) at src/gallium/auxiliary/draw/draw_pipe_clip.c:665
No locals.
#2 0x00007fca71f4ea61 in validate_line (stage=<optimized out>, header=0x7fff07fb63c0) at src/gallium/auxiliary/draw/draw_pipe_validate.c:299
pipeline = <optimized out>
#3 0x00007fca71f4476a in do_line (v1=<optimized out>, v0=<optimized out>, flags=8, draw=<optimized out>) at src/gallium/auxiliary/draw/draw_pipe.c:143
prim = {det = 2.24207754e-44, flags = 8, pad = 0, v = {0x12a6fc0, 0x12a7004, 0x800000008}}
#4 pipe_run_linear (draw=<optimized out>, prim=<optimized out>, prim_flags=<optimized out>, vertices=0x12a6fc0, stride=68, count=68) at src/gallium/auxiliary/draw/draw_decompose_tmp.h:76
idx = <optimized out>
i = <optimized out>
flags = <optimized out>
verts = 0x12a6fc0 "\020@\377\377|\024\256\276|\024\256\276"
quads_flatshade_last = <optimized out>
last_vertex_last = <optimized out>
__FUNCTION__ = "pipe_run_linear"
#5 0x00007fca71f46911 in draw_pipeline_run_linear (draw=0x11c2f60, vert_info=0x7fff07fb64e0, prim_info=0x7fff07fb6570) at src/gallium/auxiliary/draw/draw_pipe.c:330
count = <optimized out>
verts = 0x12a6fc0 "\020@\377\377|\024\256\276|\024\256\276"
i = <optimized out>
start = <optimized out>
__FUNCTION__ = "draw_pipeline_run_linear"
#6 0x00007fca7202c814 in pipeline (prim_info=0x7fff07fb6570, vert_info=0x7fff07fb64e0, llvm=<optimized out>) at src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c:192
No locals.
#7 llvm_pipeline_generic (middle=0x11cf0a0, fetch_info=0x0, prim_info=0x7fff07fb6570) at src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c:293
fpme = 0x11cf0a0
draw = <optimized out>
gshader = 0x0
gs_prim_info = {linear = 0 '\000', start = 0, elts = 0xb0, count = 0, prim = 0, flags = 0, primitive_lengths = 0x0, primitive_count = 0}
llvm_vert_info = {verts = 0x12a6fc0, vertex_size = 68, stride = 68, count = 2}
gs_vert_info = {verts = 0x6e0000005b, vertex_size = 119, stride = 124, count = 18619848}
vert_info = 0x7fff07fb64e0
opt = <optimized out>
clipped = <optimized out>
__FUNCTION__ = "llvm_pipeline_generic"
#8 0x00007fca7202ca08 in llvm_middle_end_linear_run (middle=<optimized out>, start=<optimized out>, count=2, prim_flags=<optimized out>) at src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c:358
fpme = <optimized out>
fetch_info = {linear = 1 '\001', start = 0, elts = 0x0, count = 2}
prim_info = {linear = 1 '\001', start = 0, elts = 0x0, count = 2, prim = 1, flags = 0, primitive_lengths = 0x7fff07fb656c, primitive_count = 1}
#9 0x00007fca71f568d7 in vsplit_segment_simple_linear (icount=2, istart=0, flags=0, vsplit=<optimized out>) at src/gallium/auxiliary/draw/draw_pt_vsplit_tmp.h:235
No locals.
#10 vsplit_run_linear (frontend=0x11cc270, start=0, count=2) at src/gallium/auxiliary/draw/draw_split_tmp.h:61
first = 2
incr = 2
vsplit = 0x11cc270
prim = 1
max_count_simple = 4096
max_count_loop = 1023
max_count_fan = 1024
__FUNCTION__ = "vsplit_run_linear"
#11 0x00007fca71f50c25 in draw_pt_arrays (draw=0x11c2f60, prim=1, start=0, count=2) at src/gallium/auxiliary/draw/draw_pt.c:142
frontend = 0x11cc270
middle = <optimized out>
opt = <optimized out>
#12 0x00007fca71f51005 in draw_vbo (draw=0x11c2f60, info=0x7fff07fb6700) at src/gallium/auxiliary/draw/draw_pt.c:526
instance = <optimized out>
index_limit = <optimized out>
__FUNCTION__ = "draw_vbo"
#13 0x00007fca71f512df in draw_arrays_instanced (count=<optimized out>, start=<optimized out>, mode=<optimized out>, draw=<optimized out>, startInstance=<optimized out>, instanceCount=<optimized out>) at src/gallium/auxiliary/draw/draw_pt.c:443
info = {indexed = 0 '\000', mode = 1, start = 0, count = 2, start_instance = 0, instance_count = 1, index_bias = 0, min_index = 0, max_index = 1, primitive_restart = 0 '\000', restart_index = 0, count_from_stream_output = 0x0}
#14 draw_arrays (draw=<optimized out>, prim=<optimized out>, start=<optimized out>, count=<optimized out>) at src/gallium/auxiliary/draw/draw_pt.c:411
No locals.
#15 0x00007fca71eb5ef9 in st_feedback_draw_vbo (ctx=<optimized out>, prims=0x11ace3c, nr_prims=1, ib=0x0, index_bounds_valid=<optimized out>, min_index=0, max_index=1, tfb_vertcount=0x0) at src/mesa/state_tracker/st_draw_feedback.c:248
st = 0x11aaef0
pipe = 0x108b9f0
draw = 0x11c2f60
vp = 0x1278390
vs = <optimized out>
vbuffers = {{stride = 12, buffer_offset = 24, buffer = 0x11b1c50, user_buffer = 0x0}, {stride = 0, buffer_offset = 0, buffer = 0x0, user_buffer = 0x0} <repeats 24 times>, {stride = 0, buffer_offset = 0, buffer = 0x0, user_buffer = 0x50}, {stride = 0, buffer_offset = 0, buffer = 0x3000000003, user_buffer = 0x6e0000005b}, {stride = 119, buffer_offset = 124, buffer = 0x0, user_buffer = 0x7fca717b6720}, {stride = 34, buffer_offset = 0, buffer = 0x1266200, user_buffer = 0x0}, {stride = 0, buffer_offset = 0, buffer = 0x4, user_buffer = 0x7fca71482a45}, {stride = 0, buffer_offset = 0, buffer = 0x0, user_buffer = 0x7fff07fb6ad0}, {stride = 19292672, buffer_offset = 0, buffer = 0x0, user_buffer = 0x7fca71d2c9db}}
velements = {{src_offset = 0, instance_divisor = 0, vertex_buffer_index = 0, src_format = PIPE_FORMAT_R32G32B32_FLOAT}, {src_offset = 133917520, instance_divisor = 32767, vertex_buffer_index = 1910501066, src_format = 32714}, {src_offset = 0, instance_divisor = 0, vertex_buffer_index = 133917920, src_format = 32767}, {src_offset = 1903912736, instance_divisor = 32714, vertex_buffer_index = 1903912736, src_format = 32714}, {src_offset = 48, instance_divisor = 0, vertex_buffer_index = 18467776, src_format = PIPE_FORMAT_NONE}, {src_offset = 2156396949, instance_divisor = 0, vertex_buffer_index = 19292672, src_format = PIPE_FORMAT_NONE}, {src_offset = 48, instance_divisor = 0, vertex_buffer_index = 1900554821, src_format = 32714}, {src_offset = 133917600, instance_divisor = 32767, vertex_buffer_index = 133917920, src_format = 32767}, {src_offset = 133917600, instance_divisor = 32767, vertex_buffer_index = 18467776, src_format = PIPE_FORMAT_NONE}, {src_offset = 2156396949, instance_divisor = 0, vertex_buffer_index = 1910486858, src_format = 32714}, {src_offset = 19366800, instance_divisor = 0, vertex_buffer_index = 18047344, src_format = PIPE_FORMAT_NONE}, {src_offset = 133917600, instance_divisor = 32767, vertex_buffer_index = 18047344, src_format = PIPE_FORMAT_NONE}, {src_offset = 19366800, instance_divisor = 0, vertex_buffer_index = 133917920, src_format = 32767}, {src_offset = 133917856, instance_divisor = 32767, vertex_buffer_index = 14, src_format = PIPE_FORMAT_NONE}, {src_offset = 133918128, instance_divisor = 32767, vertex_buffer_index = 1910801340, src_format = 32714}, {src_offset = 14, instance_divisor = 32767, vertex_buffer_index = 1910486527, src_format = 32714}, {src_offset = 1907105304, instance_divisor = 32714, vertex_buffer_index = 18047344, src_format = PIPE_FORMAT_NONE}, {src_offset = 8, instance_divisor = 0, vertex_buffer_index = 18060880, src_format = PIPE_FORMAT_NONE}, {src_offset = 18060544, instance_divisor = 0, vertex_buffer_index = 8, src_format = PIPE_FORMAT_NONE}, {src_offset = 133918288, instance_divisor = 32767, vertex_buffer_index = 1910767180, src_format = 32714}, {src_offset = 0, instance_divisor = 0, vertex_buffer_index = 1910486527, src_format = 32714}, {src_offset = 0, instance_divisor = 0, vertex_buffer_index = 18047344, src_format = PIPE_FORMAT_NONE}, {src_offset = 0, instance_divisor = 0, vertex_buffer_index = 133918080, src_format = 32767}, {src_offset = 0, instance_divisor = 0, vertex_buffer_index = 18531800, src_format = PIPE_FORMAT_NONE}, {src_offset = 0, instance_divisor = 0, vertex_buffer_index = 3, src_format = PIPE_FORMAT_NONE}, {src_offset = 133918272, instance_divisor = 32767, vertex_buffer_index = 1911011467, src_format = 32714}, {src_offset = 0, instance_divisor = 0, vertex_buffer_index = 18047344, src_format = PIPE_FORMAT_NONE}, {src_offset = 0, instance_divisor = 0, vertex_buffer_index = 0, src_format = 32714}, {src_offset = 18528656, instance_divisor = 0, vertex_buffer_index = 18553936, src_format = PIPE_FORMAT_NONE}, {src_offset = 133917984, instance_divisor = 32767, vertex_buffer_index = 133918192, src_format = 32767}, {src_offset = 0, instance_divisor = 0, vertex_buffer_index = 17349104, src_format = PIPE_FORMAT_NONE}, {src_offset = 65512, instance_divisor = 0, vertex_buffer_index = 1908922780, src_format = 32714}}
ibuffer = {index_size = 0, offset = 0, buffer = 0x0, user_buffer = 0x0}
vb_transfer = {0x125bb80, 0x0 <repeats 31 times>}
ib_transfer = 0x0
arrays = 0x11ae9a8
attr = <optimized out>
i = <optimized out>
low_addr = <optimized out>
mapped_indices = <optimized out>
__FUNCTION__ = "st_feedback_draw_vbo"
#16 0x00007fca71e8fdf0 in vbo_exec_vtx_flush (exec=<optimized out>, keepUnmapped=<optimized out>) at src/mesa/vbo/vbo_exec_draw.c:409
ctx = 0x1136170
#17 0x00007fca71e8ad84 in vbo_exec_FlushVertices_internal (unmap=1 '\001', exec=0x11ac5d8) at src/mesa/vbo/vbo_exec_api.c:539
No locals.
#18 vbo_exec_FlushVertices (ctx=0x1136170, flags=1) at src/mesa/vbo/vbo_exec_api.c:1296
exec = 0x11ac5d8
__PRETTY_FUNCTION__ = "vbo_exec_FlushVertices"
#19 0x00007fca71d653ce in _mesa_PushName (name=2) at src/mesa/main/feedback.c:357
ctx = 0x1136170
__FUNCTION__ = "_mesa_PushName"
#20 0x000000000043aee6 in Test (Func=0x43b7e0 <Line>, buf=0x122f7c0) at select.c:237
i = <optimized out>
#21 0x000000000043b0d0 in SelectExec () at select.c:287
No locals.
#22 0x000000000044c2a7 in DriverExec (Func=0x11c7ad0) at driver.c:135
error = <optimized out>
x = <optimized out>
buf = "\260`{q\312\177\000\000\000,f", '\000' <repeats 13 times>, "\002\000\000\000\000\000\000\000$/E\000\000\000\000"
#23 0x000000000044c62a in Driver () at driver.c:251
----- Original Message -----
> Module: Mesa
> Branch: master
> Commit: 4625a9b1adf7a30c56e2bbeb41573fbba4465851
> URL:
> http://cgit.freedesktop.org/mesa/mesa/commit/?id=4625a9b1adf7a30c56e2bbeb41573fbba4465851
>
> Author: Olivier Galibert <galibert at pobox.com>
> Date: Tue Jun 19 20:51:19 2012 +0200
>
> draw: fix flat shading and screen-space linear interpolation in
> clipper
>
> This includes:
> - picking up correctly which attributes are flatshaded and which are
> noperspective
>
> - copying the flatshaded attributes when needed, including the
> non-built-in ones
>
> - correctly interpolating the noperspective attributes in
> screen-space
> instead than in a 3d-correct fashion.
>
> Signed-off-by: Olivier Galibert <galibert at pobox.com>
> Reviewed-by: Brian Paul <brianp at vmware.com>
>
> ---
>
> src/gallium/auxiliary/draw/draw_pipe_clip.c | 144
> +++++++++++++++++++++------
> 1 files changed, 113 insertions(+), 31 deletions(-)
>
> diff --git a/src/gallium/auxiliary/draw/draw_pipe_clip.c
> b/src/gallium/auxiliary/draw/draw_pipe_clip.c
> index 4da4d65..2d36eb3 100644
> --- a/src/gallium/auxiliary/draw/draw_pipe_clip.c
> +++ b/src/gallium/auxiliary/draw/draw_pipe_clip.c
> @@ -39,6 +39,7 @@
>
> #include "draw_vs.h"
> #include "draw_pipe.h"
> +#include "draw_fs.h"
>
>
> #ifndef IS_NEGATIVE
> @@ -56,11 +57,12 @@
> struct clip_stage {
> struct draw_stage stage; /**< base class */
>
> - /* Basically duplicate some of the flatshading logic here:
> - */
> - boolean flat;
> - uint num_color_attribs;
> - uint color_attribs[4]; /* front/back primary/secondary colors */
> + /* List of the attributes to be flatshaded. */
> + uint num_flat_attribs;
> + uint flat_attribs[PIPE_MAX_SHADER_OUTPUTS];
> +
> + /* Mask of attributes in noperspective mode */
> + boolean noperspective_attribs[PIPE_MAX_SHADER_OUTPUTS];
>
> float (*plane)[4];
> };
> @@ -91,17 +93,16 @@ static void interp_attr( float dst[4],
>
>
> /**
> - * Copy front/back, primary/secondary colors from src vertex to dst
> vertex.
> - * Used when flat shading.
> + * Copy flat shaded attributes src vertex to dst vertex.
> */
> -static void copy_colors( struct draw_stage *stage,
> - struct vertex_header *dst,
> - const struct vertex_header *src )
> +static void copy_flat( struct draw_stage *stage,
> + struct vertex_header *dst,
> + const struct vertex_header *src )
> {
> const struct clip_stage *clipper = clip_stage(stage);
> uint i;
> - for (i = 0; i < clipper->num_color_attribs; i++) {
> - const uint attr = clipper->color_attribs[i];
> + for (i = 0; i < clipper->num_flat_attribs; i++) {
> + const uint attr = clipper->flat_attribs[i];
> COPY_4FV(dst->data[attr], src->data[attr]);
> }
> }
> @@ -120,6 +121,7 @@ static void interp( const struct clip_stage
> *clip,
> 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;
> + float t_nopersp;
>
> /* Vertex header.
> */
> @@ -148,12 +150,36 @@ static void interp( const struct clip_stage
> *clip,
> dst->data[pos_attr][2] = pos[2] * oow * scale[2] + trans[2];
> dst->data[pos_attr][3] = oow;
> }
> +
> + /**
> + * Compute the t in screen-space instead of 3d space to use
> + * for noperspective interpolation.
> + *
> + * The points can be aligned with the X axis, so in that case try
> + * the Y. When both points are at the same screen position, we
> can
> + * pick whatever value (the interpolated point won't be in front
> + * anyway), so just use the 3d t.
> + */
> + {
> + int k;
> + t_nopersp = t;
> + for (k = 0; k < 2; k++)
> + if (in->data[pos_attr][k] != out->data[pos_attr][k]) {
> + t_nopersp = (dst->data[pos_attr][k] -
> out->data[pos_attr][k]) /
> + (in->data[pos_attr][k] - out->data[pos_attr][k]);
> + break;
> + }
> + }
>
> /* Other attributes
> */
> for (j = 0; j < nr_attrs; j++) {
> - if (j != pos_attr && j != clip_attr)
> - interp_attr(dst->data[j], t, in->data[j], out->data[j]);
> + if (j != pos_attr && j != clip_attr) {
> + if (clip->noperspective_attribs[j])
> + interp_attr(dst->data[j], t_nopersp, in->data[j],
> out->data[j]);
> + else
> + interp_attr(dst->data[j], t, in->data[j], out->data[j]);
> + }
> }
> }
>
> @@ -406,14 +432,14 @@ do_clip_tri( struct draw_stage *stage,
> /* If flat-shading, copy provoking vertex color to polygon
> vertex[0]
> */
> if (n >= 3) {
> - if (clipper->flat) {
> + if (clipper->num_flat_attribs) {
> if (stage->draw->rasterizer->flatshade_first) {
> if (inlist[0] != header->v[0]) {
> assert(tmpnr < MAX_CLIPPED_VERTICES + 1);
> if (tmpnr >= MAX_CLIPPED_VERTICES + 1)
> return;
> inlist[0] = dup_vert(stage, inlist[0], tmpnr++);
> - copy_colors(stage, inlist[0], header->v[0]);
> + copy_flat(stage, inlist[0], header->v[0]);
> }
> }
> else {
> @@ -422,7 +448,7 @@ do_clip_tri( struct draw_stage *stage,
> if (tmpnr >= MAX_CLIPPED_VERTICES + 1)
> return;
> inlist[0] = dup_vert(stage, inlist[0], tmpnr++);
> - copy_colors(stage, inlist[0], header->v[2]);
> + copy_flat(stage, inlist[0], header->v[2]);
> }
> }
> }
> @@ -471,10 +497,7 @@ do_clip_line( struct draw_stage *stage,
>
> if (v0->clipmask) {
> interp( clipper, stage->tmp[0], t0, v0, v1 );
> -
> - if (clipper->flat)
> - copy_colors(stage, stage->tmp[0], v0);
> -
> + copy_flat(stage, stage->tmp[0], v0);
> newprim.v[0] = stage->tmp[0];
> }
> else {
> @@ -548,20 +571,79 @@ static void
> clip_init_state( struct draw_stage *stage )
> {
> struct clip_stage *clipper = clip_stage( stage );
> + const struct draw_vertex_shader *vs =
> stage->draw->vs.vertex_shader;
> + const struct draw_fragment_shader *fs =
> stage->draw->fs.fragment_shader;
> + uint i;
>
> - clipper->flat = stage->draw->rasterizer->flatshade ? TRUE :
> FALSE;
> + /* We need to know for each attribute what kind of interpolation
> is
> + * done on it (flat, smooth or noperspective). But the
> information
> + * is not directly accessible for outputs, only for inputs. So
> we
> + * have to match semantic name and index between the VS (or
> GS/ES)
> + * outputs and the FS inputs to get to the interpolation mode.
> + *
> + * The only hitch is with gl_FrontColor/gl_BackColor which map to
> + * gl_Color, and their Secondary versions. First there are (up
> to)
> + * two outputs for one input, so we tuck the information in a
> + * specific array. Second if they don't have qualifiers, the
> + * default value has to be picked from the global shade mode.
> + */
>
> - if (clipper->flat) {
> - const struct draw_vertex_shader *vs =
> stage->draw->vs.vertex_shader;
> - uint i;
> + /* First pick up the interpolation mode for
> + * gl_Color/gl_SecondaryColor, with the correct default.
> + */
> + int indexed_interp[2];
> + indexed_interp[0] = indexed_interp[1] =
> stage->draw->rasterizer->flatshade ?
> + TGSI_INTERPOLATE_CONSTANT : TGSI_INTERPOLATE_PERSPECTIVE;
> +
> + for (i = 0; i < fs->info.num_inputs; i++) {
> + if (fs->info.input_semantic_name[i] == TGSI_SEMANTIC_COLOR) {
> + if (fs->info.input_interpolate[i] !=
> TGSI_INTERPOLATE_COLOR)
> + indexed_interp[fs->info.input_semantic_index[i]] =
> fs->info.input_interpolate[i];
> + }
> + }
>
> - clipper->num_color_attribs = 0;
> - for (i = 0; i < vs->info.num_outputs; i++) {
> - if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_COLOR ||
> - vs->info.output_semantic_name[i] == TGSI_SEMANTIC_BCOLOR) {
> - clipper->color_attribs[clipper->num_color_attribs++] = i;
> - }
> + /* Then resolve the interpolation mode for every output
> attribute.
> + *
> + * Given how the rest of the code, the most efficient way is to
> + * have a vector of flat-mode attributes, and a mask for
> + * noperspective attributes.
> + */
> +
> + clipper->num_flat_attribs = 0;
> + memset(clipper->noperspective_attribs, 0,
> sizeof(clipper->noperspective_attribs));
> + for (i = 0; i < vs->info.num_outputs; i++) {
> + /* Find the interpolation mode for a specific attribute
> + */
> + int interp;
> +
> + /* If it's gl_{Front,Back}{,Secondary}Color, pick up the mode
> + * from the array we've filled before. */
> + if (vs->info.output_semantic_name[i] == TGSI_SEMANTIC_COLOR ||
> + vs->info.output_semantic_name[i] == TGSI_SEMANTIC_BCOLOR)
> {
> + interp = indexed_interp[vs->info.output_semantic_index[i]];
> + } else {
> + /* Otherwise, search in the FS inputs, with a decent
> default
> + * if we don't find it.
> + */
> + uint j;
> + interp = TGSI_INTERPOLATE_PERSPECTIVE;
> + for (j = 0; j < fs->info.num_inputs; j++) {
> + if (vs->info.output_semantic_name[i] ==
> fs->info.input_semantic_name[j] &&
> + vs->info.output_semantic_index[i] ==
> fs->info.input_semantic_index[j]) {
> + interp = fs->info.input_interpolate[j];
> + break;
> + }
> + }
> }
> +
> + /* If it's flat, add it to the flat vector. Otherwise update
> + * the noperspective mask.
> + */
> + if (interp == TGSI_INTERPOLATE_CONSTANT) {
> + clipper->flat_attribs[clipper->num_flat_attribs] = i;
> + clipper->num_flat_attribs++;
> + } else
> + clipper->noperspective_attribs[i] = interp ==
> TGSI_INTERPOLATE_LINEAR;
> }
>
> stage->tri = clip_tri;
>
> _______________________________________________
> mesa-commit mailing list
> mesa-commit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-commit
>
More information about the mesa-dev
mailing list