1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * Copyright 2010 VMware, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 **************************************************************************/
30 * \brief Quad depth / stencil testing
33 #include "pipe/p_defines.h"
34 #include "util/u_format.h"
35 #include "util/u_memory.h"
36 #include "tgsi/tgsi_scan.h"
37 #include "sp_context.h"
39 #include "sp_quad_pipe.h"
40 #include "sp_tile_cache.h"
41 #include "sp_state.h" /* for sp_fragment_shader */
45 struct pipe_surface
*ps
;
46 enum pipe_format format
;
47 unsigned bzzzz
[QUAD_SIZE
]; /**< Z values fetched from depth buffer */
48 unsigned qzzzz
[QUAD_SIZE
]; /**< Z values from the quad */
49 ubyte stencilVals
[QUAD_SIZE
];
50 struct softpipe_cached_tile
*tile
;
56 get_depth_stencil_values( struct depth_data
*data
,
57 const struct quad_header
*quad
)
60 const struct softpipe_cached_tile
*tile
= data
->tile
;
62 switch (data
->format
) {
63 case PIPE_FORMAT_Z16_UNORM
:
64 for (j
= 0; j
< QUAD_SIZE
; j
++) {
65 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
66 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
67 data
->bzzzz
[j
] = tile
->data
.depth16
[y
][x
];
70 case PIPE_FORMAT_Z32_UNORM
:
71 for (j
= 0; j
< QUAD_SIZE
; j
++) {
72 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
73 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
74 data
->bzzzz
[j
] = tile
->data
.depth32
[y
][x
];
77 case PIPE_FORMAT_Z24X8_UNORM
:
78 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
79 for (j
= 0; j
< QUAD_SIZE
; j
++) {
80 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
81 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
82 data
->bzzzz
[j
] = tile
->data
.depth32
[y
][x
] & 0xffffff;
83 data
->stencilVals
[j
] = tile
->data
.depth32
[y
][x
] >> 24;
86 case PIPE_FORMAT_X8Z24_UNORM
:
87 case PIPE_FORMAT_S8_USCALED_Z24_UNORM
:
88 for (j
= 0; j
< QUAD_SIZE
; j
++) {
89 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
90 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
91 data
->bzzzz
[j
] = tile
->data
.depth32
[y
][x
] >> 8;
92 data
->stencilVals
[j
] = tile
->data
.depth32
[y
][x
] & 0xff;
95 case PIPE_FORMAT_S8_USCALED
:
96 for (j
= 0; j
< QUAD_SIZE
; j
++) {
97 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
98 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
100 data
->stencilVals
[j
] = tile
->data
.stencil8
[y
][x
];
110 * If the shader has not been run, interpolate the depth values
114 interpolate_quad_depth( struct quad_header
*quad
)
116 const float fx
= (float) quad
->input
.x0
;
117 const float fy
= (float) quad
->input
.y0
;
118 const float dzdx
= quad
->posCoef
->dadx
[2];
119 const float dzdy
= quad
->posCoef
->dady
[2];
120 const float z0
= quad
->posCoef
->a0
[2] + dzdx
* fx
+ dzdy
* fy
;
122 quad
->output
.depth
[0] = z0
;
123 quad
->output
.depth
[1] = z0
+ dzdx
;
124 quad
->output
.depth
[2] = z0
+ dzdy
;
125 quad
->output
.depth
[3] = z0
+ dzdx
+ dzdy
;
130 * Compute the depth_data::qzzzz[] values from the float fragment Z values.
133 convert_quad_depth( struct depth_data
*data
,
134 const struct quad_header
*quad
)
138 /* Convert quad's float depth values to int depth values (qzzzz).
139 * If the Z buffer stores integer values, we _have_ to do the depth
140 * compares with integers (not floats). Otherwise, the float->int->float
141 * conversion of Z values (which isn't an identity function) will cause
144 switch (data
->format
) {
145 case PIPE_FORMAT_Z16_UNORM
:
147 float scale
= 65535.0;
149 for (j
= 0; j
< QUAD_SIZE
; j
++) {
150 data
->qzzzz
[j
] = (unsigned) (quad
->output
.depth
[j
] * scale
);
154 case PIPE_FORMAT_Z32_UNORM
:
156 double scale
= (double) (uint
) ~0UL;
158 for (j
= 0; j
< QUAD_SIZE
; j
++) {
159 data
->qzzzz
[j
] = (unsigned) (quad
->output
.depth
[j
] * scale
);
163 case PIPE_FORMAT_Z24X8_UNORM
:
164 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
166 float scale
= (float) ((1 << 24) - 1);
168 for (j
= 0; j
< QUAD_SIZE
; j
++) {
169 data
->qzzzz
[j
] = (unsigned) (quad
->output
.depth
[j
] * scale
);
173 case PIPE_FORMAT_X8Z24_UNORM
:
174 case PIPE_FORMAT_S8_USCALED_Z24_UNORM
:
176 float scale
= (float) ((1 << 24) - 1);
178 for (j
= 0; j
< QUAD_SIZE
; j
++) {
179 data
->qzzzz
[j
] = (unsigned) (quad
->output
.depth
[j
] * scale
);
191 * Write data->bzzzz[] values and data->stencilVals into the Z/stencil buffer.
194 write_depth_stencil_values( struct depth_data
*data
,
195 struct quad_header
*quad
)
197 struct softpipe_cached_tile
*tile
= data
->tile
;
200 /* put updated Z values back into cached tile */
201 switch (data
->format
) {
202 case PIPE_FORMAT_Z16_UNORM
:
203 for (j
= 0; j
< QUAD_SIZE
; j
++) {
204 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
205 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
206 tile
->data
.depth16
[y
][x
] = (ushort
) data
->bzzzz
[j
];
209 case PIPE_FORMAT_Z24X8_UNORM
:
210 case PIPE_FORMAT_Z32_UNORM
:
211 for (j
= 0; j
< QUAD_SIZE
; j
++) {
212 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
213 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
214 tile
->data
.depth32
[y
][x
] = data
->bzzzz
[j
];
217 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
218 for (j
= 0; j
< QUAD_SIZE
; j
++) {
219 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
220 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
221 tile
->data
.depth32
[y
][x
] = (data
->stencilVals
[j
] << 24) | data
->bzzzz
[j
];
224 case PIPE_FORMAT_S8_USCALED_Z24_UNORM
:
225 for (j
= 0; j
< QUAD_SIZE
; j
++) {
226 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
227 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
228 tile
->data
.depth32
[y
][x
] = (data
->bzzzz
[j
] << 8) | data
->stencilVals
[j
];
231 case PIPE_FORMAT_X8Z24_UNORM
:
232 for (j
= 0; j
< QUAD_SIZE
; j
++) {
233 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
234 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
235 tile
->data
.depth32
[y
][x
] = data
->bzzzz
[j
] << 8;
238 case PIPE_FORMAT_S8_USCALED
:
239 for (j
= 0; j
< QUAD_SIZE
; j
++) {
240 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
241 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
242 tile
->data
.stencil8
[y
][x
] = data
->stencilVals
[j
];
253 /** Only 8-bit stencil supported */
254 #define STENCIL_MAX 0xff
258 * Do the basic stencil test (compare stencil buffer values against the
261 * \param data->stencilVals the stencil values from the stencil buffer
262 * \param func the stencil func (PIPE_FUNC_x)
263 * \param ref the stencil reference value
264 * \param valMask the stencil value mask indicating which bits of the stencil
265 * values and ref value are to be used.
266 * \return mask indicating which pixels passed the stencil test
269 do_stencil_test(struct depth_data
*data
,
271 unsigned ref
, unsigned valMask
)
273 unsigned passMask
= 0x0;
279 case PIPE_FUNC_NEVER
:
283 for (j
= 0; j
< QUAD_SIZE
; j
++) {
284 if (ref
< (data
->stencilVals
[j
] & valMask
)) {
285 passMask
|= (1 << j
);
289 case PIPE_FUNC_EQUAL
:
290 for (j
= 0; j
< QUAD_SIZE
; j
++) {
291 if (ref
== (data
->stencilVals
[j
] & valMask
)) {
292 passMask
|= (1 << j
);
296 case PIPE_FUNC_LEQUAL
:
297 for (j
= 0; j
< QUAD_SIZE
; j
++) {
298 if (ref
<= (data
->stencilVals
[j
] & valMask
)) {
299 passMask
|= (1 << j
);
303 case PIPE_FUNC_GREATER
:
304 for (j
= 0; j
< QUAD_SIZE
; j
++) {
305 if (ref
> (data
->stencilVals
[j
] & valMask
)) {
306 passMask
|= (1 << j
);
310 case PIPE_FUNC_NOTEQUAL
:
311 for (j
= 0; j
< QUAD_SIZE
; j
++) {
312 if (ref
!= (data
->stencilVals
[j
] & valMask
)) {
313 passMask
|= (1 << j
);
317 case PIPE_FUNC_GEQUAL
:
318 for (j
= 0; j
< QUAD_SIZE
; j
++) {
319 if (ref
>= (data
->stencilVals
[j
] & valMask
)) {
320 passMask
|= (1 << j
);
324 case PIPE_FUNC_ALWAYS
:
336 * Apply the stencil operator to stencil values.
338 * \param data->stencilVals the stencil buffer values (read and written)
339 * \param mask indicates which pixels to update
340 * \param op the stencil operator (PIPE_STENCIL_OP_x)
341 * \param ref the stencil reference value
342 * \param wrtMask writemask controlling which bits are changed in the
346 apply_stencil_op(struct depth_data
*data
,
347 unsigned mask
, unsigned op
, ubyte ref
, ubyte wrtMask
)
350 ubyte newstencil
[QUAD_SIZE
];
352 for (j
= 0; j
< QUAD_SIZE
; j
++) {
353 newstencil
[j
] = data
->stencilVals
[j
];
357 case PIPE_STENCIL_OP_KEEP
:
360 case PIPE_STENCIL_OP_ZERO
:
361 for (j
= 0; j
< QUAD_SIZE
; j
++) {
362 if (mask
& (1 << j
)) {
367 case PIPE_STENCIL_OP_REPLACE
:
368 for (j
= 0; j
< QUAD_SIZE
; j
++) {
369 if (mask
& (1 << j
)) {
374 case PIPE_STENCIL_OP_INCR
:
375 for (j
= 0; j
< QUAD_SIZE
; j
++) {
376 if (mask
& (1 << j
)) {
377 if (data
->stencilVals
[j
] < STENCIL_MAX
) {
378 newstencil
[j
] = data
->stencilVals
[j
] + 1;
383 case PIPE_STENCIL_OP_DECR
:
384 for (j
= 0; j
< QUAD_SIZE
; j
++) {
385 if (mask
& (1 << j
)) {
386 if (data
->stencilVals
[j
] > 0) {
387 newstencil
[j
] = data
->stencilVals
[j
] - 1;
392 case PIPE_STENCIL_OP_INCR_WRAP
:
393 for (j
= 0; j
< QUAD_SIZE
; j
++) {
394 if (mask
& (1 << j
)) {
395 newstencil
[j
] = data
->stencilVals
[j
] + 1;
399 case PIPE_STENCIL_OP_DECR_WRAP
:
400 for (j
= 0; j
< QUAD_SIZE
; j
++) {
401 if (mask
& (1 << j
)) {
402 newstencil
[j
] = data
->stencilVals
[j
] - 1;
406 case PIPE_STENCIL_OP_INVERT
:
407 for (j
= 0; j
< QUAD_SIZE
; j
++) {
408 if (mask
& (1 << j
)) {
409 newstencil
[j
] = ~data
->stencilVals
[j
];
418 * update the stencil values
420 if (wrtMask
!= STENCIL_MAX
) {
421 /* apply bit-wise stencil buffer writemask */
422 for (j
= 0; j
< QUAD_SIZE
; j
++) {
423 data
->stencilVals
[j
] = (wrtMask
& newstencil
[j
]) | (~wrtMask
& data
->stencilVals
[j
]);
427 for (j
= 0; j
< QUAD_SIZE
; j
++) {
428 data
->stencilVals
[j
] = newstencil
[j
];
436 * To increase efficiency, we should probably have multiple versions
437 * of this function that are specifically for Z16, Z32 and FP Z buffers.
438 * Try to effectively do that with codegen...
441 depth_test_quad(struct quad_stage
*qs
,
442 struct depth_data
*data
,
443 struct quad_header
*quad
)
445 struct softpipe_context
*softpipe
= qs
->softpipe
;
449 switch (softpipe
->depth_stencil
->depth
.func
) {
450 case PIPE_FUNC_NEVER
:
454 /* Note this is pretty much a single sse or cell instruction.
455 * Like this: quad->mask &= (quad->outputs.depth < zzzz);
457 for (j
= 0; j
< QUAD_SIZE
; j
++) {
458 if (data
->qzzzz
[j
] < data
->bzzzz
[j
])
462 case PIPE_FUNC_EQUAL
:
463 for (j
= 0; j
< QUAD_SIZE
; j
++) {
464 if (data
->qzzzz
[j
] == data
->bzzzz
[j
])
468 case PIPE_FUNC_LEQUAL
:
469 for (j
= 0; j
< QUAD_SIZE
; j
++) {
470 if (data
->qzzzz
[j
] <= data
->bzzzz
[j
])
474 case PIPE_FUNC_GREATER
:
475 for (j
= 0; j
< QUAD_SIZE
; j
++) {
476 if (data
->qzzzz
[j
] > data
->bzzzz
[j
])
480 case PIPE_FUNC_NOTEQUAL
:
481 for (j
= 0; j
< QUAD_SIZE
; j
++) {
482 if (data
->qzzzz
[j
] != data
->bzzzz
[j
])
486 case PIPE_FUNC_GEQUAL
:
487 for (j
= 0; j
< QUAD_SIZE
; j
++) {
488 if (data
->qzzzz
[j
] >= data
->bzzzz
[j
])
492 case PIPE_FUNC_ALWAYS
:
499 quad
->inout
.mask
&= zmask
;
500 if (quad
->inout
.mask
== 0)
503 /* Update our internal copy only if writemask set. Even if
504 * depth.writemask is FALSE, may still need to write out buffer
505 * data due to stencil changes.
507 if (softpipe
->depth_stencil
->depth
.writemask
) {
508 for (j
= 0; j
< QUAD_SIZE
; j
++) {
509 if (quad
->inout
.mask
& (1 << j
)) {
510 data
->bzzzz
[j
] = data
->qzzzz
[j
];
521 * Do stencil (and depth) testing. Stenciling depends on the outcome of
525 depth_stencil_test_quad(struct quad_stage
*qs
,
526 struct depth_data
*data
,
527 struct quad_header
*quad
)
529 struct softpipe_context
*softpipe
= qs
->softpipe
;
530 unsigned func
, zFailOp
, zPassOp
, failOp
;
531 ubyte ref
, wrtMask
, valMask
;
532 uint face
= quad
->input
.facing
;
534 if (!softpipe
->depth_stencil
->stencil
[1].enabled
) {
535 /* single-sided stencil test, use front (face=0) state */
539 /* 0 = front-face, 1 = back-face */
540 assert(face
== 0 || face
== 1);
542 /* choose front or back face function, operator, etc */
543 /* XXX we could do these initializations once per primitive */
544 func
= softpipe
->depth_stencil
->stencil
[face
].func
;
545 failOp
= softpipe
->depth_stencil
->stencil
[face
].fail_op
;
546 zFailOp
= softpipe
->depth_stencil
->stencil
[face
].zfail_op
;
547 zPassOp
= softpipe
->depth_stencil
->stencil
[face
].zpass_op
;
548 ref
= softpipe
->stencil_ref
.ref_value
[face
];
549 wrtMask
= softpipe
->depth_stencil
->stencil
[face
].writemask
;
550 valMask
= softpipe
->depth_stencil
->stencil
[face
].valuemask
;
552 /* do the stencil test first */
554 unsigned passMask
, failMask
;
555 passMask
= do_stencil_test(data
, func
, ref
, valMask
);
556 failMask
= quad
->inout
.mask
& ~passMask
;
557 quad
->inout
.mask
&= passMask
;
559 if (failOp
!= PIPE_STENCIL_OP_KEEP
) {
560 apply_stencil_op(data
, failMask
, failOp
, ref
, wrtMask
);
564 if (quad
->inout
.mask
) {
565 /* now the pixels that passed the stencil test are depth tested */
566 if (softpipe
->depth_stencil
->depth
.enabled
) {
567 const unsigned origMask
= quad
->inout
.mask
;
569 depth_test_quad(qs
, data
, quad
); /* quad->mask is updated */
571 /* update stencil buffer values according to z pass/fail result */
572 if (zFailOp
!= PIPE_STENCIL_OP_KEEP
) {
573 const unsigned zFailMask
= origMask
& ~quad
->inout
.mask
;
574 apply_stencil_op(data
, zFailMask
, zFailOp
, ref
, wrtMask
);
577 if (zPassOp
!= PIPE_STENCIL_OP_KEEP
) {
578 const unsigned zPassMask
= origMask
& quad
->inout
.mask
;
579 apply_stencil_op(data
, zPassMask
, zPassOp
, ref
, wrtMask
);
583 /* no depth test, apply Zpass operator to stencil buffer values */
584 apply_stencil_op(data
, quad
->inout
.mask
, zPassOp
, ref
, wrtMask
);
590 #define ALPHATEST( FUNC, COMP ) \
592 alpha_test_quads_##FUNC( struct quad_stage *qs, \
593 struct quad_header *quads[], \
596 const float ref = qs->softpipe->depth_stencil->alpha.ref_value; \
597 const uint cbuf = 0; /* only output[0].alpha is tested */ \
598 unsigned pass_nr = 0; \
601 for (i = 0; i < nr; i++) { \
602 const float *aaaa = quads[i]->output.color[cbuf][3]; \
603 unsigned passMask = 0; \
605 if (aaaa[0] COMP ref) passMask |= (1 << 0); \
606 if (aaaa[1] COMP ref) passMask |= (1 << 1); \
607 if (aaaa[2] COMP ref) passMask |= (1 << 2); \
608 if (aaaa[3] COMP ref) passMask |= (1 << 3); \
610 quads[i]->inout.mask &= passMask; \
612 if (quads[i]->inout.mask) \
613 quads[pass_nr++] = quads[i]; \
621 ALPHATEST( EQUAL
, == )
622 ALPHATEST( LEQUAL
, <= )
623 ALPHATEST( GREATER
, > )
624 ALPHATEST( NOTEQUAL
, != )
625 ALPHATEST( GEQUAL
, >= )
628 /* XXX: Incorporate into shader using KILP.
631 alpha_test_quads(struct quad_stage
*qs
,
632 struct quad_header
*quads
[],
635 switch (qs
->softpipe
->depth_stencil
->alpha
.func
) {
637 return alpha_test_quads_LESS( qs
, quads
, nr
);
638 case PIPE_FUNC_EQUAL
:
639 return alpha_test_quads_EQUAL( qs
, quads
, nr
);
641 case PIPE_FUNC_LEQUAL
:
642 return alpha_test_quads_LEQUAL( qs
, quads
, nr
);
643 case PIPE_FUNC_GREATER
:
644 return alpha_test_quads_GREATER( qs
, quads
, nr
);
645 case PIPE_FUNC_NOTEQUAL
:
646 return alpha_test_quads_NOTEQUAL( qs
, quads
, nr
);
647 case PIPE_FUNC_GEQUAL
:
648 return alpha_test_quads_GEQUAL( qs
, quads
, nr
);
649 case PIPE_FUNC_ALWAYS
:
651 case PIPE_FUNC_NEVER
:
658 static unsigned mask_count
[16] =
681 * General depth/stencil test function. Used when there's no fast-path.
684 depth_test_quads_fallback(struct quad_stage
*qs
,
685 struct quad_header
*quads
[],
688 unsigned i
, pass
= 0;
689 const struct sp_fragment_shader
*fs
= qs
->softpipe
->fs
;
690 boolean interp_depth
= !fs
->info
.writes_z
;
691 struct depth_data data
;
694 if (qs
->softpipe
->depth_stencil
->alpha
.enabled
) {
695 nr
= alpha_test_quads(qs
, quads
, nr
);
698 if (qs
->softpipe
->framebuffer
.zsbuf
&&
699 (qs
->softpipe
->depth_stencil
->depth
.enabled
||
700 qs
->softpipe
->depth_stencil
->stencil
[0].enabled
)) {
702 data
.ps
= qs
->softpipe
->framebuffer
.zsbuf
;
703 data
.format
= data
.ps
->format
;
704 data
.tile
= sp_get_cached_tile(qs
->softpipe
->zsbuf_cache
,
708 for (i
= 0; i
< nr
; i
++) {
709 get_depth_stencil_values(&data
, quads
[i
]);
711 if (qs
->softpipe
->depth_stencil
->depth
.enabled
) {
713 interpolate_quad_depth(quads
[i
]);
715 convert_quad_depth(&data
, quads
[i
]);
718 if (qs
->softpipe
->depth_stencil
->stencil
[0].enabled
) {
719 depth_stencil_test_quad(qs
, &data
, quads
[i
]);
720 write_depth_stencil_values(&data
, quads
[i
]);
723 if (!depth_test_quad(qs
, &data
, quads
[i
]))
726 if (qs
->softpipe
->depth_stencil
->depth
.writemask
)
727 write_depth_stencil_values(&data
, quads
[i
]);
730 quads
[pass
++] = quads
[i
];
736 if (qs
->softpipe
->active_query_count
) {
737 for (i
= 0; i
< nr
; i
++)
738 qs
->softpipe
->occlusion_count
+= mask_count
[quads
[i
]->inout
.mask
];
742 qs
->next
->run(qs
->next
, quads
, nr
);
747 * Special-case Z testing for 16-bit Zbuffer and Z buffer writes enabled.
750 #define NAME depth_interp_z16_less_write
752 #include "sp_quad_depth_test_tmp.h"
754 #define NAME depth_interp_z16_equal_write
756 #include "sp_quad_depth_test_tmp.h"
758 #define NAME depth_interp_z16_lequal_write
760 #include "sp_quad_depth_test_tmp.h"
762 #define NAME depth_interp_z16_greater_write
764 #include "sp_quad_depth_test_tmp.h"
766 #define NAME depth_interp_z16_notequal_write
768 #include "sp_quad_depth_test_tmp.h"
770 #define NAME depth_interp_z16_gequal_write
772 #include "sp_quad_depth_test_tmp.h"
774 #define NAME depth_interp_z16_always_write
776 #include "sp_quad_depth_test_tmp.h"
781 depth_noop(struct quad_stage
*qs
,
782 struct quad_header
*quads
[],
785 qs
->next
->run(qs
->next
, quads
, nr
);
791 choose_depth_test(struct quad_stage
*qs
,
792 struct quad_header
*quads
[],
795 boolean interp_depth
= !qs
->softpipe
->fs
->info
.writes_z
;
797 boolean alpha
= qs
->softpipe
->depth_stencil
->alpha
.enabled
;
799 boolean depth
= qs
->softpipe
->depth_stencil
->depth
.enabled
;
801 unsigned depthfunc
= qs
->softpipe
->depth_stencil
->depth
.func
;
803 boolean stencil
= qs
->softpipe
->depth_stencil
->stencil
[0].enabled
;
805 boolean depthwrite
= qs
->softpipe
->depth_stencil
->depth
.writemask
;
807 boolean occlusion
= qs
->softpipe
->active_query_count
;
809 if(!qs
->softpipe
->framebuffer
.zsbuf
)
810 depth
= depthwrite
= stencil
= FALSE
;
813 qs
->run
= depth_test_quads_fallback
;
815 /* look for special cases */
819 qs
->run
= depth_noop
;
828 if (qs
->softpipe
->framebuffer
.zsbuf
->format
== PIPE_FORMAT_Z16_UNORM
) {
830 case PIPE_FUNC_NEVER
:
831 qs
->run
= depth_test_quads_fallback
;
834 qs
->run
= depth_interp_z16_less_write
;
836 case PIPE_FUNC_EQUAL
:
837 qs
->run
= depth_interp_z16_equal_write
;
839 case PIPE_FUNC_LEQUAL
:
840 qs
->run
= depth_interp_z16_lequal_write
;
842 case PIPE_FUNC_GREATER
:
843 qs
->run
= depth_interp_z16_greater_write
;
845 case PIPE_FUNC_NOTEQUAL
:
846 qs
->run
= depth_interp_z16_notequal_write
;
848 case PIPE_FUNC_GEQUAL
:
849 qs
->run
= depth_interp_z16_gequal_write
;
851 case PIPE_FUNC_ALWAYS
:
852 qs
->run
= depth_interp_z16_always_write
;
855 qs
->run
= depth_test_quads_fallback
;
861 /* next quad/fragment stage */
862 qs
->run( qs
, quads
, nr
);
868 depth_test_begin(struct quad_stage
*qs
)
870 qs
->run
= choose_depth_test
;
871 qs
->next
->begin(qs
->next
);
876 depth_test_destroy(struct quad_stage
*qs
)
883 sp_quad_depth_test_stage(struct softpipe_context
*softpipe
)
885 struct quad_stage
*stage
= CALLOC_STRUCT(quad_stage
);
887 stage
->softpipe
= softpipe
;
888 stage
->begin
= depth_test_begin
;
889 stage
->run
= choose_depth_test
;
890 stage
->destroy
= depth_test_destroy
;