Path: blob/21.2-virgl/src/gallium/auxiliary/draw/draw_split_tmp.h
4565 views
/*1* Mesa 3-D graphics library2*3* Copyright 2008 VMware, Inc.4* Copyright (C) 2010 LunarG Inc.5*6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the "Software"),8* to deal in the Software without restriction, including without limitation9* the rights to use, copy, modify, merge, publish, distribute, sublicense,10* and/or sell copies of the Software, and to permit persons to whom the11* Software is furnished to do so, subject to the following conditions:12*13* The above copyright notice and this permission notice shall be included14* in all copies or substantial portions of the Software.15*16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR17* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,18* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL19* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER20* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING21* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER22* DEALINGS IN THE SOFTWARE.23*/2425static void26FUNC(FUNC_VARS)27{28unsigned first, incr;29LOCAL_VARS3031/*32* prim, start, count, and max_count_{simple,loop,fan} should have been33* defined34*/35if (0) {36debug_printf("%s: prim 0x%x, start %d, count %d, max_count_simple %d, "37"max_count_loop %d, max_count_fan %d\n",38__FUNCTION__, prim, start, count, max_count_simple,39max_count_loop, max_count_fan);40}4142if (prim == PIPE_PRIM_PATCHES) {43first = vsplit->draw->pt.vertices_per_patch;44incr = vsplit->draw->pt.vertices_per_patch;45} else46draw_pt_split_prim(prim, &first, &incr);47/* sanitize primitive length */48count = draw_pt_trim_count(count, first, incr);49if (count < first)50return;5152/* try flushing the entire primitive */53if (PRIMITIVE(start, count))54return;5556/* must be able to at least flush two complete primitives */57assert(max_count_simple >= first + incr &&58max_count_loop >= first + incr &&59max_count_fan >= first + incr);6061/* no splitting required */62if (count <= max_count_simple) {63SEGMENT_SIMPLE(0x0, start, count);64}65else {66const unsigned rollback = first - incr;67unsigned flags = DRAW_SPLIT_AFTER, seg_start = 0, seg_max;6869/*70* Both count and seg_max below are explicitly trimmed. Because71*72* seg_start = N * (seg_max - rollback) = N' * incr,73*74* we have75*76* remaining = count - seg_start = first + N'' * incr.77*78* That is, remaining is implicitly trimmed.79*/80switch (prim) {81case PIPE_PRIM_PATCHES:82case PIPE_PRIM_POINTS:83case PIPE_PRIM_LINES:84case PIPE_PRIM_LINE_STRIP:85case PIPE_PRIM_TRIANGLES:86case PIPE_PRIM_TRIANGLE_STRIP:87case PIPE_PRIM_QUADS:88case PIPE_PRIM_QUAD_STRIP:89case PIPE_PRIM_LINES_ADJACENCY:90case PIPE_PRIM_LINE_STRIP_ADJACENCY:91case PIPE_PRIM_TRIANGLES_ADJACENCY:92case PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY:93seg_max =94draw_pt_trim_count(MIN2(max_count_simple, count), first, incr);95if (prim == PIPE_PRIM_TRIANGLE_STRIP ||96prim == PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY) {97/* make sure we flush even number of triangles at a time */98if (seg_max < count && !(((seg_max - first) / incr) & 1))99seg_max -= incr;100}101102do {103const unsigned remaining = count - seg_start;104105if (remaining > seg_max) {106SEGMENT_SIMPLE(flags, start + seg_start, seg_max);107seg_start += seg_max - rollback;108109flags |= DRAW_SPLIT_BEFORE;110}111else {112flags &= ~DRAW_SPLIT_AFTER;113114SEGMENT_SIMPLE(flags, start + seg_start, remaining);115seg_start += remaining;116}117} while (seg_start < count);118break;119120case PIPE_PRIM_LINE_LOOP:121seg_max =122draw_pt_trim_count(MIN2(max_count_loop, count), first, incr);123124do {125const unsigned remaining = count - seg_start;126127if (remaining > seg_max) {128SEGMENT_LOOP(flags, start + seg_start, seg_max, start);129seg_start += seg_max - rollback;130131flags |= DRAW_SPLIT_BEFORE;132}133else {134flags &= ~DRAW_SPLIT_AFTER;135136SEGMENT_LOOP(flags, start + seg_start, remaining, start);137seg_start += remaining;138}139} while (seg_start < count);140break;141142case PIPE_PRIM_TRIANGLE_FAN:143case PIPE_PRIM_POLYGON:144seg_max =145draw_pt_trim_count(MIN2(max_count_fan, count), first, incr);146147do {148const unsigned remaining = count - seg_start;149150if (remaining > seg_max) {151SEGMENT_FAN(flags, start + seg_start, seg_max, start);152seg_start += seg_max - rollback;153154flags |= DRAW_SPLIT_BEFORE;155}156else {157flags &= ~DRAW_SPLIT_AFTER;158159SEGMENT_FAN(flags, start + seg_start, remaining, start);160seg_start += remaining;161}162} while (seg_start < count);163break;164165default:166assert(0);167break;168}169}170}171172#undef FUNC173#undef FUNC_VARS174#undef LOCAL_VARS175176#undef PRIMITIVE177#undef SEGMENT_SIMPLE178#undef SEGMENT_LOOP179#undef SEGMENT_FAN180181182