2
* Mesa 3-D graphics library
5
* Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
6
* Copyright (C) 2010 LunarG Inc.
8
* Permission is hereby granted, free of charge, to any person obtaining a
9
* copy of this software and associated documentation files (the "Software"),
10
* to deal in the Software without restriction, including without limitation
11
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
12
* and/or sell copies of the Software, and to permit persons to whom the
13
* Software is furnished to do so, subject to the following conditions:
15
* The above copyright notice and this permission notice shall be included
16
* in all copies or substantial portions of the Software.
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
* DEALINGS IN THE SOFTWARE.
27
#include "util/u_math.h"
28
#include "util/u_memory.h"
30
#include "draw/draw_context.h"
31
#include "draw/draw_private.h"
32
#include "draw/draw_pt.h"
34
#define SEGMENT_SIZE 1024
37
struct vsplit_frontend {
38
struct draw_pt_front_end base;
39
struct draw_context *draw;
43
struct draw_pt_middle_end *middle;
45
unsigned max_vertices;
48
/* buffers for splitting */
49
unsigned fetch_elts[SEGMENT_SIZE];
50
ushort draw_elts[SEGMENT_SIZE];
51
ushort identity_draw_elts[SEGMENT_SIZE];
54
/* map a fetch element to a draw element */
55
unsigned fetches[MAP_SIZE];
56
ushort draws[MAP_SIZE];
57
boolean has_max_fetch;
59
ushort num_fetch_elts;
66
vsplit_clear_cache(struct vsplit_frontend *vsplit)
68
memset(vsplit->cache.fetches, 0xff, sizeof(vsplit->cache.fetches));
69
vsplit->cache.has_max_fetch = FALSE;
70
vsplit->cache.num_fetch_elts = 0;
71
vsplit->cache.num_draw_elts = 0;
75
vsplit_flush_cache(struct vsplit_frontend *vsplit, unsigned flags)
77
vsplit->middle->run(vsplit->middle,
78
vsplit->fetch_elts, vsplit->cache.num_fetch_elts,
79
vsplit->draw_elts, vsplit->cache.num_draw_elts, flags);
83
* Add a fetch element and add it to the draw elements.
86
vsplit_add_cache(struct vsplit_frontend *vsplit, unsigned fetch)
88
unsigned hash = fetch % MAP_SIZE;
90
if (vsplit->cache.fetches[hash] != fetch) {
92
vsplit->cache.fetches[hash] = fetch;
93
vsplit->cache.draws[hash] = vsplit->cache.num_fetch_elts;
96
assert(vsplit->cache.num_fetch_elts < vsplit->segment_size);
97
vsplit->fetch_elts[vsplit->cache.num_fetch_elts++] = fetch;
100
vsplit->draw_elts[vsplit->cache.num_draw_elts++] = vsplit->cache.draws[hash];
105
* Add a fetch element and add it to the draw elements. The fetch element is
106
* in full range (uint).
109
vsplit_add_cache_uint(struct vsplit_frontend *vsplit, unsigned fetch)
111
/* special care for 0xffffffff */
112
if (fetch == 0xffffffff && !vsplit->cache.has_max_fetch) {
113
unsigned hash = fetch % MAP_SIZE;
114
vsplit->cache.fetches[hash] = fetch - 1; /* force update */
115
vsplit->cache.has_max_fetch = TRUE;
118
vsplit_add_cache(vsplit, fetch);
122
#define FUNC vsplit_run_linear
123
#include "draw_pt_vsplit_tmp.h"
125
#define FUNC vsplit_run_ubyte
126
#define ELT_TYPE ubyte
127
#define ADD_CACHE(vsplit, fetch) vsplit_add_cache(vsplit, fetch)
128
#include "draw_pt_vsplit_tmp.h"
130
#define FUNC vsplit_run_ushort
131
#define ELT_TYPE ushort
132
#define ADD_CACHE(vsplit, fetch) vsplit_add_cache(vsplit, fetch)
133
#include "draw_pt_vsplit_tmp.h"
135
#define FUNC vsplit_run_uint
136
#define ELT_TYPE uint
137
#define ADD_CACHE(vsplit, fetch) vsplit_add_cache_uint(vsplit, fetch)
138
#include "draw_pt_vsplit_tmp.h"
141
static void vsplit_prepare(struct draw_pt_front_end *frontend,
143
struct draw_pt_middle_end *middle,
146
struct vsplit_frontend *vsplit = (struct vsplit_frontend *) frontend;
148
switch (vsplit->draw->pt.user.eltSize) {
150
vsplit->base.run = vsplit_run_linear;
153
vsplit->base.run = vsplit_run_ubyte;
156
vsplit->base.run = vsplit_run_ushort;
159
vsplit->base.run = vsplit_run_uint;
167
vsplit->prim = in_prim;
169
vsplit->middle = middle;
170
middle->prepare(middle, vsplit->prim, opt, &vsplit->max_vertices);
172
vsplit->segment_size = MIN2(SEGMENT_SIZE, vsplit->max_vertices);
176
static void vsplit_finish(struct draw_pt_front_end *frontend)
178
struct vsplit_frontend *vsplit = (struct vsplit_frontend *) frontend;
179
vsplit->middle->finish(vsplit->middle);
180
vsplit->middle = NULL;
184
static void vsplit_destroy(struct draw_pt_front_end *frontend)
190
struct draw_pt_front_end *draw_pt_vsplit(struct draw_context *draw)
192
struct vsplit_frontend *vsplit = CALLOC_STRUCT(vsplit_frontend);
198
vsplit->base.prepare = vsplit_prepare;
199
vsplit->base.run = NULL;
200
vsplit->base.finish = vsplit_finish;
201
vsplit->base.destroy = vsplit_destroy;
204
for (i = 0; i < SEGMENT_SIZE; i++)
205
vsplit->identity_draw_elts[i] = i;
207
return &vsplit->base;