X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fgallium%2Fauxiliary%2Fdraw%2Fdraw_pt_fetch_emit.c;h=dc6decba70e7bf9b1853a76cbe1245eb9f97a28e;hb=7756aae815a26c533948081c2c319c20bcf5962c;hp=5158c6341c016ecddec14b458e17e5fb8b8c8831;hpb=3293bcdc80cdfa20a2381aae2b94505bdf95d857;p=mesa.git diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c b/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c index 5158c6341c0..dc6decba70e 100644 --- a/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_emit.c @@ -1,8 +1,8 @@ /************************************************************************** - * + * * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. * All Rights Reserved. - * + * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including @@ -10,11 +10,11 @@ * distribute, sub license, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: - * + * * The above copyright notice and this permission notice (including the * next paragraph) shall be included in all copies or substantial portions * of the Software. - * + * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. @@ -22,7 +22,7 @@ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - * + * **************************************************************************/ /* @@ -36,18 +36,19 @@ #include "draw/draw_vbuf.h" #include "draw/draw_vertex.h" #include "draw/draw_pt.h" +#include "draw/draw_gs.h" #include "translate/translate.h" #include "translate/translate_cache.h" -/* The simplest 'middle end' in the new vertex code. - * +/* The simplest 'middle end' in the new vertex code. + * * The responsibilities of a middle end are to: * - perform vertex fetch using * - draw vertex element/buffer state * - a list of fetch indices we received as an input * - run the vertex shader - * - cliptest, - * - clip coord calculation + * - cliptest, + * - clip coord calculation * - viewport transformation * - if necessary, run the primitive pipeline, passing it: * - a linear array of vertex_header vertices constructed here @@ -74,7 +75,7 @@ struct fetch_emit_middle_end { struct draw_pt_middle_end base; struct draw_context *draw; - + struct translate *translate; const struct vertex_info *vinfo; @@ -86,8 +87,6 @@ struct fetch_emit_middle_end { }; - - static void fetch_emit_prepare( struct draw_pt_middle_end *middle, unsigned prim, unsigned opt, @@ -97,22 +96,16 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle, struct draw_context *draw = feme->draw; const struct vertex_info *vinfo; unsigned i, dst_offset; - boolean ok; struct translate_key key; + unsigned gs_out_prim = (draw->gs.geometry_shader ? + draw->gs.geometry_shader->output_primitive : + prim); + draw->render->set_primitive(draw->render, gs_out_prim); - ok = draw->render->set_primitive( draw->render, - prim ); - if (!ok) { - assert(0); - return; - } - /* Must do this after set_primitive() above: */ vinfo = feme->vinfo = draw->render->get_vertex_info(draw->render); - - /* Transform from API vertices to HW vertices, skipping the * pipeline_vertex intermediate step. @@ -148,7 +141,7 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle, key.element[i].instance_divisor = src->instance_divisor; key.element[i].output_format = output_format; key.element[i].output_offset = dst_offset; - + dst_offset += emit_sz; } @@ -158,81 +151,63 @@ static void fetch_emit_prepare( struct draw_pt_middle_end *middle, /* Don't bother with caching at this stage: */ if (!feme->translate || - translate_key_compare(&feme->translate->key, &key) != 0) + translate_key_compare(&feme->translate->key, &key) != 0) { translate_key_sanitize(&key); feme->translate = translate_cache_find(feme->cache, &key); - - feme->translate->set_buffer(feme->translate, - draw->pt.nr_vertex_buffers, + feme->translate->set_buffer(feme->translate, + draw->pt.nr_vertex_buffers, &feme->point_size, 0, ~0); } - + feme->point_size = draw->rasterizer->point_size; for (i = 0; i < draw->pt.nr_vertex_buffers; i++) { - feme->translate->set_buffer(feme->translate, - i, - ((char *)draw->pt.user.vbuffer[i] + + feme->translate->set_buffer(feme->translate, + i, + ((char *)draw->pt.user.vbuffer[i].map + draw->pt.vertex_buffer[i].buffer_offset), draw->pt.vertex_buffer[i].stride, - draw->pt.vertex_buffer[i].max_index); + draw->pt.max_index); } - *max_vertices = (draw->render->max_vertex_buffer_bytes / + *max_vertices = (draw->render->max_vertex_buffer_bytes / (vinfo->size * 4)); - - /* Return an even number of verts. - * This prevents "parity" errors when splitting long triangle strips which - * can lead to front/back culling mix-ups. - * Every other triangle in a strip has an alternate front/back orientation - * so splitting at an odd position can cause the orientation of subsequent - * triangles to get reversed. - */ - *max_vertices = *max_vertices & ~1; } - - - static void fetch_emit_run( struct draw_pt_middle_end *middle, const unsigned *fetch_elts, unsigned fetch_count, const ushort *draw_elts, - unsigned draw_count ) + unsigned draw_count, + unsigned prim_flags ) { struct fetch_emit_middle_end *feme = (struct fetch_emit_middle_end *)middle; struct draw_context *draw = feme->draw; void *hw_verts; - - /* XXX: need to flush to get prim_vbuf.c to release its allocation?? + + /* XXX: need to flush to get prim_vbuf.c to release its allocation?? */ draw_do_flush( draw, DRAW_FLUSH_BACKEND ); - if (fetch_count >= UNDEFINED_VERTEX_ID) { - assert(0); - return; - } - draw->render->allocate_vertices( draw->render, (ushort)feme->translate->key.output_stride, (ushort)fetch_count ); hw_verts = draw->render->map_vertices( draw->render ); if (!hw_verts) { - assert(0); + debug_warn_once("vertex buffer allocation failed (out of memory?)"); return; } - - + /* Single routine to fetch vertices and emit HW verts. */ - feme->translate->run_elts( feme->translate, + feme->translate->run_elts( feme->translate, fetch_elts, fetch_count, draw->instance_id, @@ -242,23 +217,23 @@ static void fetch_emit_run( struct draw_pt_middle_end *middle, unsigned i; for (i = 0; i < fetch_count; i++) { debug_printf("\n\nvertex %d:\n", i); - draw_dump_emitted_vertex( feme->vinfo, + draw_dump_emitted_vertex( feme->vinfo, (const uint8_t *)hw_verts + feme->vinfo->size * 4 * i ); } } - draw->render->unmap_vertices( draw->render, - 0, + draw->render->unmap_vertices( draw->render, + 0, (ushort)(fetch_count - 1) ); /* XXX: Draw arrays path to avoid re-emitting index list again and * again. */ - draw->render->draw_elements( draw->render, - draw_elts, + draw->render->draw_elements( draw->render, + draw_elts, draw_count ); - /* Done -- that was easy, wasn't it: + /* Done -- that was easy, wasn't it: */ draw->render->release_vertices( draw->render ); @@ -267,7 +242,8 @@ static void fetch_emit_run( struct draw_pt_middle_end *middle, static void fetch_emit_run_linear( struct draw_pt_middle_end *middle, unsigned start, - unsigned count ) + unsigned count, + unsigned prim_flags ) { struct fetch_emit_middle_end *feme = (struct fetch_emit_middle_end *)middle; struct draw_context *draw = feme->draw; @@ -277,16 +253,13 @@ static void fetch_emit_run_linear( struct draw_pt_middle_end *middle, */ draw_do_flush( draw, DRAW_FLUSH_BACKEND ); - if (count >= UNDEFINED_VERTEX_ID) - goto fail; - if (!draw->render->allocate_vertices( draw->render, (ushort)feme->translate->key.output_stride, - (ushort)count )) + (ushort)count )) goto fail; hw_verts = draw->render->map_vertices( draw->render ); - if (!hw_verts) + if (!hw_verts) goto fail; /* Single routine to fetch vertices and emit HW verts. @@ -319,7 +292,7 @@ static void fetch_emit_run_linear( struct draw_pt_middle_end *middle, return; fail: - assert(0); + debug_warn_once("allocate or map of vertex buffer failed (out of memory?)"); return; } @@ -328,7 +301,8 @@ static boolean fetch_emit_run_linear_elts( struct draw_pt_middle_end *middle, unsigned start, unsigned count, const ushort *draw_elts, - unsigned draw_count ) + unsigned draw_count, + unsigned prim_flags ) { struct fetch_emit_middle_end *feme = (struct fetch_emit_middle_end *)middle; struct draw_context *draw = feme->draw; @@ -338,16 +312,13 @@ static boolean fetch_emit_run_linear_elts( struct draw_pt_middle_end *middle, */ draw_do_flush( draw, DRAW_FLUSH_BACKEND ); - if (count >= UNDEFINED_VERTEX_ID) - return FALSE; - if (!draw->render->allocate_vertices( draw->render, (ushort)feme->translate->key.output_stride, (ushort)count )) return FALSE; hw_verts = draw->render->map_vertices( draw->render ); - if (!hw_verts) + if (!hw_verts) return FALSE; /* Single routine to fetch vertices and emit HW verts. @@ -363,8 +334,8 @@ static boolean fetch_emit_run_linear_elts( struct draw_pt_middle_end *middle, /* XXX: Draw arrays path to avoid re-emitting index list again and * again. */ - draw->render->draw_elements( draw->render, - draw_elts, + draw->render->draw_elements( draw->render, + draw_elts, draw_count ); /* Done -- that was easy, wasn't it: @@ -375,13 +346,12 @@ static boolean fetch_emit_run_linear_elts( struct draw_pt_middle_end *middle, } - - static void fetch_emit_finish( struct draw_pt_middle_end *middle ) { /* nothing to do */ } + static void fetch_emit_destroy( struct draw_pt_middle_end *middle ) { struct fetch_emit_middle_end *feme = (struct fetch_emit_middle_end *)middle; @@ -413,7 +383,7 @@ struct draw_pt_middle_end *draw_pt_fetch_emit( struct draw_context *draw ) fetch_emit->base.destroy = fetch_emit_destroy; fetch_emit->draw = draw; - + return &fetch_emit->base; }