1
/**************************************************************************
3
* Copyright 2007-2021 VMware, Inc.
6
* Permission is hereby granted, free of charge, to any person obtaining a
7
* copy of this software and associated documentation files (the
8
* "Software"), to deal in the Software without restriction, including
9
* without limitation the rights to use, copy, modify, merge, publish,
10
* distribute, sub license, and/or sell copies of the Software, and to
11
* permit persons to whom the Software is furnished to do so, subject to
12
* the following conditions:
14
* The above copyright notice and this permission notice (including the
15
* next paragraph) shall be included in all copies or substantial portions
18
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21
* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22
* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26
**************************************************************************/
29
* Rasterization for binned rectangles within a tile
33
#include "util/u_math.h"
36
#include "lp_rast_priv.h"
39
/* Our 16-pixel stamps are layed out as:
46
* Define bitmasks for each row and column in this layout:
48
#define COLUMN0 ((1<<0)|(1<<4)|(1<<8) |(1<<12))
49
#define COLUMN1 ((1<<1)|(1<<5)|(1<<9) |(1<<13))
50
#define COLUMN2 ((1<<2)|(1<<6)|(1<<10)|(1<<14))
51
#define COLUMN3 ((1<<3)|(1<<7)|(1<<11)|(1<<15))
53
#define ROW0 ((1<<0) |(1<<1) |(1<<2) |(1<<3))
54
#define ROW1 ((1<<4) |(1<<5) |(1<<6) |(1<<7))
55
#define ROW2 ((1<<8) |(1<<9) |(1<<10)|(1<<11))
56
#define ROW3 ((1<<12)|(1<<13)|(1<<14)|(1<<15))
60
static unsigned left_mask_tab[STAMP_SIZE] = {
61
COLUMN0 | COLUMN1 | COLUMN2 | COLUMN3,
62
COLUMN1 | COLUMN2 | COLUMN3,
67
static unsigned right_mask_tab[STAMP_SIZE] = {
70
COLUMN0 | COLUMN1 | COLUMN2,
71
COLUMN0 | COLUMN1 | COLUMN2 | COLUMN3,
74
static unsigned top_mask_tab[STAMP_SIZE] = {
75
ROW0 | ROW1 | ROW2 | ROW3,
81
static unsigned bottom_mask_tab[STAMP_SIZE] = {
85
ROW0 | ROW1 | ROW2 | ROW3,
90
* Shade all pixels in a 4x4 block. The fragment code omits the
91
* triangle in/out tests.
92
* \param x, y location of 4x4 block in window coords
95
shade_quads_all( struct lp_rasterizer_task *task,
96
const struct lp_rast_shader_inputs *inputs,
97
unsigned x, unsigned y )
99
const struct lp_scene *scene = task->scene;
100
const struct lp_rast_state *state = task->state;
101
struct lp_fragment_shader_variant *variant = state->variant;
102
uint8_t *color = scene->cbufs[0].map;
103
unsigned stride = scene->cbufs[0].stride;
112
assert(!variant->key.depth.enabled);
114
/* run shader on 4x4 block */
115
BEGIN_JIT_CALL(state, task);
116
variant->jit_function[RAST_WHOLE]( &state->jit_context,
119
(const float (*)[4])GET_A0(inputs),
120
(const float (*)[4])GET_DADX(inputs),
121
(const float (*)[4])GET_DADY(inputs),
131
shade_quads_mask(struct lp_rasterizer_task *task,
132
const struct lp_rast_shader_inputs *inputs,
133
unsigned x, unsigned y,
136
const struct lp_rast_state *state = task->state;
137
struct lp_fragment_shader_variant *variant = state->variant;
138
const struct lp_scene *scene = task->scene;
139
uint8_t *color = scene->cbufs[0].map;
140
unsigned stride = scene->cbufs[0].stride;
149
assert(!variant->key.depth.enabled);
151
/* Propagate non-interpolated raster state */
152
task->thread_data.raster_state.viewport_index = inputs->viewport_index;
154
/* run shader on 4x4 block */
155
BEGIN_JIT_CALL(state, task);
156
variant->jit_function[RAST_EDGE_TEST](&state->jit_context,
159
(const float (*)[4])GET_A0(inputs),
160
(const float (*)[4])GET_DADX(inputs),
161
(const float (*)[4])GET_DADY(inputs),
170
/* Shade a 4x4 stamp completely within the rectangle.
173
full(struct lp_rasterizer_task *task,
174
const struct lp_rast_shader_inputs *inputs,
175
unsigned ix, unsigned iy)
177
shade_quads_all(task,
183
/* Shade a 4x4 stamp which may be partially outside the rectangle,
184
* according to the mask parameter.
187
partial(struct lp_rasterizer_task *task,
188
const struct lp_rast_shader_inputs *inputs,
189
unsigned ix, unsigned iy,
192
/* Unfortunately we can end up generating full blocks on this path,
193
* need to catch them.
196
full(task, inputs, ix, iy);
199
shade_quads_mask(task,
209
* Run the full SoA shader.
212
lp_rast_linear_rect_fallback(struct lp_rasterizer_task *task,
213
const struct lp_rast_shader_inputs *inputs,
214
const struct u_rect *box)
216
unsigned ix0, ix1, iy0, iy1;
220
unsigned bottom_mask;
223
/* The interior of the rectangle (if there is one) will be
224
* rasterized as full 4x4 stamps.
226
* At each edge of the rectangle, however, there will be a fringe
227
* of partial blocks where the edge lands somewhere in the middle
228
* of a 4x4-pixel stamp.
230
* For each edge, precalculate a mask of the pixels inside that
231
* edge for the first 4x4-pixel stamp.
233
* Note that at the corners, and for narrow rectangles, an
234
* individual stamp may have two or more edges active. We'll deal
235
* with that below by combining these masks as appropriate.
237
left_mask = left_mask_tab [box->x0 & (STAMP_SIZE - 1)];
238
right_mask = right_mask_tab [box->x1 & (STAMP_SIZE - 1)];
239
top_mask = top_mask_tab [box->y0 & (STAMP_SIZE - 1)];
240
bottom_mask = bottom_mask_tab [box->y1 & (STAMP_SIZE - 1)];
242
ix0 = box->x0 / STAMP_SIZE;
243
ix1 = box->x1 / STAMP_SIZE;
244
iy0 = box->y0 / STAMP_SIZE;
245
iy1 = box->y1 / STAMP_SIZE;
247
/* Various special cases.
249
if (ix0 == ix1 && iy0 == iy1) {
250
/* Rectangle is contained within a single 4x4-pixel stamp:
252
partial(task, inputs, ix0, iy0,
253
(left_mask & right_mask &
254
top_mask & bottom_mask));
256
else if (ix0 == ix1) {
257
/* Left and right edges fall on the same 4-pixel-wide column:
259
unsigned mask = left_mask & right_mask;
260
partial(task, inputs, ix0, iy0, mask & top_mask);
261
for (i = iy0 + 1; i < iy1; i++)
262
partial(task, inputs, ix0, i, mask);
263
partial(task, inputs, ix0, iy1, mask & bottom_mask);
265
else if (iy0 == iy1) {
266
/* Top and bottom edges fall on the same 4-pixel-wide row:
268
unsigned mask = top_mask & bottom_mask;
269
partial(task, inputs, ix0, iy0, mask & left_mask);
270
for (i = ix0 + 1; i < ix1; i++)
271
partial(task, inputs, i, iy0, mask);
272
partial(task, inputs, ix1, iy0, mask & right_mask);
275
/* Each pair of edges falls in a separate 4-pixel-wide
278
partial(task, inputs, ix0, iy0, left_mask & top_mask);
279
partial(task, inputs, ix0, iy1, left_mask & bottom_mask);
280
partial(task, inputs, ix1, iy0, right_mask & top_mask);
281
partial(task, inputs, ix1, iy1, right_mask & bottom_mask);
283
for (i = ix0 + 1; i < ix1; i++)
284
partial(task, inputs, i, iy0, top_mask);
286
for (i = ix0 + 1; i < ix1; i++)
287
partial(task, inputs, i, iy1, bottom_mask);
289
for (i = iy0 + 1; i < iy1; i++)
290
partial(task, inputs, ix0, i, left_mask);
292
for (i = iy0 + 1; i < iy1; i++)
293
partial(task, inputs, ix1, i, right_mask);
295
/* Full interior blocks
297
for (j = iy0 + 1; j < iy1; j++) {
298
for (i = ix0 + 1; i < ix1; i++) {
299
full(task, inputs, i, j);