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 boolean use_shader_stencil_refs;
51 ubyte shader_stencil_refs[QUAD_SIZE];
52 struct softpipe_cached_tile *tile;
58 get_depth_stencil_values( struct depth_data *data,
59 const struct quad_header *quad )
62 const struct softpipe_cached_tile *tile = data->tile;
64 switch (data->format) {
65 case PIPE_FORMAT_Z16_UNORM:
66 for (j = 0; j < QUAD_SIZE; j++) {
67 int x = quad->input.x0 % TILE_SIZE + (j & 1);
68 int y = quad->input.y0 % TILE_SIZE + (j >> 1);
69 data->bzzzz[j] = tile->data.depth16[y][x];
72 case PIPE_FORMAT_Z32_UNORM:
73 for (j = 0; j < QUAD_SIZE; j++) {
74 int x = quad->input.x0 % TILE_SIZE + (j & 1);
75 int y = quad->input.y0 % TILE_SIZE + (j >> 1);
76 data->bzzzz[j] = tile->data.depth32[y][x];
79 case PIPE_FORMAT_Z24X8_UNORM:
80 case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
81 for (j = 0; j < QUAD_SIZE; j++) {
82 int x = quad->input.x0 % TILE_SIZE + (j & 1);
83 int y = quad->input.y0 % TILE_SIZE + (j >> 1);
84 data->bzzzz[j] = tile->data.depth32[y][x] & 0xffffff;
85 data->stencilVals[j] = tile->data.depth32[y][x] >> 24;
88 case PIPE_FORMAT_X8Z24_UNORM:
89 case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
90 for (j = 0; j < QUAD_SIZE; j++) {
91 int x = quad->input.x0 % TILE_SIZE + (j & 1);
92 int y = quad->input.y0 % TILE_SIZE + (j >> 1);
93 data->bzzzz[j] = tile->data.depth32[y][x] >> 8;
94 data->stencilVals[j] = tile->data.depth32[y][x] & 0xff;
97 case PIPE_FORMAT_S8_USCALED:
98 for (j = 0; j < QUAD_SIZE; j++) {
99 int x = quad->input.x0 % TILE_SIZE + (j & 1);
100 int y = quad->input.y0 % TILE_SIZE + (j >> 1);
102 data->stencilVals[j] = tile->data.stencil8[y][x];
112 * If the shader has not been run, interpolate the depth values
116 interpolate_quad_depth( struct quad_header *quad )
118 const float fx = (float) quad->input.x0;
119 const float fy = (float) quad->input.y0;
120 const float dzdx = quad->posCoef->dadx[2];
121 const float dzdy = quad->posCoef->dady[2];
122 const float z0 = quad->posCoef->a0[2] + dzdx * fx + dzdy * fy;
124 quad->output.depth[0] = z0;
125 quad->output.depth[1] = z0 + dzdx;
126 quad->output.depth[2] = z0 + dzdy;
127 quad->output.depth[3] = z0 + dzdx + dzdy;
132 * Compute the depth_data::qzzzz[] values from the float fragment Z values.
135 convert_quad_depth( struct depth_data *data,
136 const struct quad_header *quad )
140 /* Convert quad's float depth values to int depth values (qzzzz).
141 * If the Z buffer stores integer values, we _have_ to do the depth
142 * compares with integers (not floats). Otherwise, the float->int->float
143 * conversion of Z values (which isn't an identity function) will cause
146 switch (data->format) {
147 case PIPE_FORMAT_Z16_UNORM:
149 float scale = 65535.0;
151 for (j = 0; j < QUAD_SIZE; j++) {
152 data->qzzzz[j] = (unsigned) (quad->output.depth[j] * scale);
156 case PIPE_FORMAT_Z32_UNORM:
158 double scale = (double) (uint) ~0UL;
160 for (j = 0; j < QUAD_SIZE; j++) {
161 data->qzzzz[j] = (unsigned) (quad->output.depth[j] * scale);
165 case PIPE_FORMAT_Z24X8_UNORM:
166 case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
168 float scale = (float) ((1 << 24) - 1);
170 for (j = 0; j < QUAD_SIZE; j++) {
171 data->qzzzz[j] = (unsigned) (quad->output.depth[j] * scale);
175 case PIPE_FORMAT_X8Z24_UNORM:
176 case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
178 float scale = (float) ((1 << 24) - 1);
180 for (j = 0; j < QUAD_SIZE; j++) {
181 data->qzzzz[j] = (unsigned) (quad->output.depth[j] * scale);
192 * Compute the depth_data::shader_stencil_refs[] values from the float fragment stencil values.
195 convert_quad_stencil( struct depth_data *data,
196 const struct quad_header *quad )
200 data->use_shader_stencil_refs = TRUE;
201 /* Copy quads stencil values
203 switch (data->format) {
204 case PIPE_FORMAT_Z24X8_UNORM:
205 case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
206 case PIPE_FORMAT_X8Z24_UNORM:
207 case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
208 case PIPE_FORMAT_S8_USCALED:
209 for (j = 0; j < QUAD_SIZE; j++) {
210 data->shader_stencil_refs[j] = ((unsigned)(quad->output.stencil[j]));
219 * Write data->bzzzz[] values and data->stencilVals into the Z/stencil buffer.
222 write_depth_stencil_values( struct depth_data *data,
223 struct quad_header *quad )
225 struct softpipe_cached_tile *tile = data->tile;
228 /* put updated Z values back into cached tile */
229 switch (data->format) {
230 case PIPE_FORMAT_Z16_UNORM:
231 for (j = 0; j < QUAD_SIZE; j++) {
232 int x = quad->input.x0 % TILE_SIZE + (j & 1);
233 int y = quad->input.y0 % TILE_SIZE + (j >> 1);
234 tile->data.depth16[y][x] = (ushort) data->bzzzz[j];
237 case PIPE_FORMAT_Z24X8_UNORM:
238 case PIPE_FORMAT_Z32_UNORM:
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.depth32[y][x] = data->bzzzz[j];
245 case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
246 for (j = 0; j < QUAD_SIZE; j++) {
247 int x = quad->input.x0 % TILE_SIZE + (j & 1);
248 int y = quad->input.y0 % TILE_SIZE + (j >> 1);
249 tile->data.depth32[y][x] = (data->stencilVals[j] << 24) | data->bzzzz[j];
252 case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
253 for (j = 0; j < QUAD_SIZE; j++) {
254 int x = quad->input.x0 % TILE_SIZE + (j & 1);
255 int y = quad->input.y0 % TILE_SIZE + (j >> 1);
256 tile->data.depth32[y][x] = (data->bzzzz[j] << 8) | data->stencilVals[j];
259 case PIPE_FORMAT_X8Z24_UNORM:
260 for (j = 0; j < QUAD_SIZE; j++) {
261 int x = quad->input.x0 % TILE_SIZE + (j & 1);
262 int y = quad->input.y0 % TILE_SIZE + (j >> 1);
263 tile->data.depth32[y][x] = data->bzzzz[j] << 8;
266 case PIPE_FORMAT_S8_USCALED:
267 for (j = 0; j < QUAD_SIZE; j++) {
268 int x = quad->input.x0 % TILE_SIZE + (j & 1);
269 int y = quad->input.y0 % TILE_SIZE + (j >> 1);
270 tile->data.stencil8[y][x] = data->stencilVals[j];
281 /** Only 8-bit stencil supported */
282 #define STENCIL_MAX 0xff
286 * Do the basic stencil test (compare stencil buffer values against the
289 * \param data->stencilVals the stencil values from the stencil buffer
290 * \param func the stencil func (PIPE_FUNC_x)
291 * \param ref the stencil reference value
292 * \param valMask the stencil value mask indicating which bits of the stencil
293 * values and ref value are to be used.
294 * \return mask indicating which pixels passed the stencil test
297 do_stencil_test(struct depth_data *data,
299 unsigned ref, unsigned valMask)
301 unsigned passMask = 0x0;
303 ubyte refs[QUAD_SIZE];
305 for (j = 0; j < QUAD_SIZE; j++) {
306 if (data->use_shader_stencil_refs)
307 refs[j] = data->shader_stencil_refs[j] & valMask;
309 refs[j] = ref & valMask;
313 case PIPE_FUNC_NEVER:
317 for (j = 0; j < QUAD_SIZE; j++) {
318 if (refs[j] < (data->stencilVals[j] & valMask)) {
319 passMask |= (1 << j);
323 case PIPE_FUNC_EQUAL:
324 for (j = 0; j < QUAD_SIZE; j++) {
325 if (refs[j] == (data->stencilVals[j] & valMask)) {
326 passMask |= (1 << j);
330 case PIPE_FUNC_LEQUAL:
331 for (j = 0; j < QUAD_SIZE; j++) {
332 if (refs[j] <= (data->stencilVals[j] & valMask)) {
333 passMask |= (1 << j);
337 case PIPE_FUNC_GREATER:
338 for (j = 0; j < QUAD_SIZE; j++) {
339 if (refs[j] > (data->stencilVals[j] & valMask)) {
340 passMask |= (1 << j);
344 case PIPE_FUNC_NOTEQUAL:
345 for (j = 0; j < QUAD_SIZE; j++) {
346 if (refs[j] != (data->stencilVals[j] & valMask)) {
347 passMask |= (1 << j);
351 case PIPE_FUNC_GEQUAL:
352 for (j = 0; j < QUAD_SIZE; j++) {
353 if (refs[j] >= (data->stencilVals[j] & valMask)) {
354 passMask |= (1 << j);
358 case PIPE_FUNC_ALWAYS:
370 * Apply the stencil operator to stencil values.
372 * \param data->stencilVals the stencil buffer values (read and written)
373 * \param mask indicates which pixels to update
374 * \param op the stencil operator (PIPE_STENCIL_OP_x)
375 * \param ref the stencil reference value
376 * \param wrtMask writemask controlling which bits are changed in the
380 apply_stencil_op(struct depth_data *data,
381 unsigned mask, unsigned op, ubyte ref, ubyte wrtMask)
384 ubyte newstencil[QUAD_SIZE];
385 ubyte refs[QUAD_SIZE];
387 for (j = 0; j < QUAD_SIZE; j++) {
388 newstencil[j] = data->stencilVals[j];
389 if (data->use_shader_stencil_refs)
390 refs[j] = data->shader_stencil_refs[j];
396 case PIPE_STENCIL_OP_KEEP:
399 case PIPE_STENCIL_OP_ZERO:
400 for (j = 0; j < QUAD_SIZE; j++) {
401 if (mask & (1 << j)) {
406 case PIPE_STENCIL_OP_REPLACE:
407 for (j = 0; j < QUAD_SIZE; j++) {
408 if (mask & (1 << j)) {
409 newstencil[j] = refs[j];
413 case PIPE_STENCIL_OP_INCR:
414 for (j = 0; j < QUAD_SIZE; j++) {
415 if (mask & (1 << j)) {
416 if (data->stencilVals[j] < STENCIL_MAX) {
417 newstencil[j] = data->stencilVals[j] + 1;
422 case PIPE_STENCIL_OP_DECR:
423 for (j = 0; j < QUAD_SIZE; j++) {
424 if (mask & (1 << j)) {
425 if (data->stencilVals[j] > 0) {
426 newstencil[j] = data->stencilVals[j] - 1;
431 case PIPE_STENCIL_OP_INCR_WRAP:
432 for (j = 0; j < QUAD_SIZE; j++) {
433 if (mask & (1 << j)) {
434 newstencil[j] = data->stencilVals[j] + 1;
438 case PIPE_STENCIL_OP_DECR_WRAP:
439 for (j = 0; j < QUAD_SIZE; j++) {
440 if (mask & (1 << j)) {
441 newstencil[j] = data->stencilVals[j] - 1;
445 case PIPE_STENCIL_OP_INVERT:
446 for (j = 0; j < QUAD_SIZE; j++) {
447 if (mask & (1 << j)) {
448 newstencil[j] = ~data->stencilVals[j];
457 * update the stencil values
459 if (wrtMask != STENCIL_MAX) {
460 /* apply bit-wise stencil buffer writemask */
461 for (j = 0; j < QUAD_SIZE; j++) {
462 data->stencilVals[j] = (wrtMask & newstencil[j]) | (~wrtMask & data->stencilVals[j]);
466 for (j = 0; j < QUAD_SIZE; j++) {
467 data->stencilVals[j] = newstencil[j];
475 * To increase efficiency, we should probably have multiple versions
476 * of this function that are specifically for Z16, Z32 and FP Z buffers.
477 * Try to effectively do that with codegen...
480 depth_test_quad(struct quad_stage *qs,
481 struct depth_data *data,
482 struct quad_header *quad)
484 struct softpipe_context *softpipe = qs->softpipe;
488 switch (softpipe->depth_stencil->depth.func) {
489 case PIPE_FUNC_NEVER:
493 /* Note this is pretty much a single sse or cell instruction.
494 * Like this: quad->mask &= (quad->outputs.depth < zzzz);
496 for (j = 0; j < QUAD_SIZE; j++) {
497 if (data->qzzzz[j] < data->bzzzz[j])
501 case PIPE_FUNC_EQUAL:
502 for (j = 0; j < QUAD_SIZE; j++) {
503 if (data->qzzzz[j] == data->bzzzz[j])
507 case PIPE_FUNC_LEQUAL:
508 for (j = 0; j < QUAD_SIZE; j++) {
509 if (data->qzzzz[j] <= data->bzzzz[j])
513 case PIPE_FUNC_GREATER:
514 for (j = 0; j < QUAD_SIZE; j++) {
515 if (data->qzzzz[j] > data->bzzzz[j])
519 case PIPE_FUNC_NOTEQUAL:
520 for (j = 0; j < QUAD_SIZE; j++) {
521 if (data->qzzzz[j] != data->bzzzz[j])
525 case PIPE_FUNC_GEQUAL:
526 for (j = 0; j < QUAD_SIZE; j++) {
527 if (data->qzzzz[j] >= data->bzzzz[j])
531 case PIPE_FUNC_ALWAYS:
538 quad->inout.mask &= zmask;
539 if (quad->inout.mask == 0)
542 /* Update our internal copy only if writemask set. Even if
543 * depth.writemask is FALSE, may still need to write out buffer
544 * data due to stencil changes.
546 if (softpipe->depth_stencil->depth.writemask) {
547 for (j = 0; j < QUAD_SIZE; j++) {
548 if (quad->inout.mask & (1 << j)) {
549 data->bzzzz[j] = data->qzzzz[j];
560 * Do stencil (and depth) testing. Stenciling depends on the outcome of
564 depth_stencil_test_quad(struct quad_stage *qs,
565 struct depth_data *data,
566 struct quad_header *quad)
568 struct softpipe_context *softpipe = qs->softpipe;
569 unsigned func, zFailOp, zPassOp, failOp;
570 ubyte ref, wrtMask, valMask;
571 uint face = quad->input.facing;
573 if (!softpipe->depth_stencil->stencil[1].enabled) {
574 /* single-sided stencil test, use front (face=0) state */
578 /* 0 = front-face, 1 = back-face */
579 assert(face == 0 || face == 1);
581 /* choose front or back face function, operator, etc */
582 /* XXX we could do these initializations once per primitive */
583 func = softpipe->depth_stencil->stencil[face].func;
584 failOp = softpipe->depth_stencil->stencil[face].fail_op;
585 zFailOp = softpipe->depth_stencil->stencil[face].zfail_op;
586 zPassOp = softpipe->depth_stencil->stencil[face].zpass_op;
587 ref = softpipe->stencil_ref.ref_value[face];
588 wrtMask = softpipe->depth_stencil->stencil[face].writemask;
589 valMask = softpipe->depth_stencil->stencil[face].valuemask;
591 /* do the stencil test first */
593 unsigned passMask, failMask;
594 passMask = do_stencil_test(data, func, ref, valMask);
595 failMask = quad->inout.mask & ~passMask;
596 quad->inout.mask &= passMask;
598 if (failOp != PIPE_STENCIL_OP_KEEP) {
599 apply_stencil_op(data, failMask, failOp, ref, wrtMask);
603 if (quad->inout.mask) {
604 /* now the pixels that passed the stencil test are depth tested */
605 if (softpipe->depth_stencil->depth.enabled) {
606 const unsigned origMask = quad->inout.mask;
608 depth_test_quad(qs, data, quad); /* quad->mask is updated */
610 /* update stencil buffer values according to z pass/fail result */
611 if (zFailOp != PIPE_STENCIL_OP_KEEP) {
612 const unsigned zFailMask = origMask & ~quad->inout.mask;
613 apply_stencil_op(data, zFailMask, zFailOp, ref, wrtMask);
616 if (zPassOp != PIPE_STENCIL_OP_KEEP) {
617 const unsigned zPassMask = origMask & quad->inout.mask;
618 apply_stencil_op(data, zPassMask, zPassOp, ref, wrtMask);
622 /* no depth test, apply Zpass operator to stencil buffer values */
623 apply_stencil_op(data, quad->inout.mask, zPassOp, ref, wrtMask);
629 #define ALPHATEST( FUNC, COMP ) \
631 alpha_test_quads_##FUNC( struct quad_stage *qs, \
632 struct quad_header *quads[], \
635 const float ref = qs->softpipe->depth_stencil->alpha.ref_value; \
636 const uint cbuf = 0; /* only output[0].alpha is tested */ \
637 unsigned pass_nr = 0; \
640 for (i = 0; i < nr; i++) { \
641 const float *aaaa = quads[i]->output.color[cbuf][3]; \
642 unsigned passMask = 0; \
644 if (aaaa[0] COMP ref) passMask |= (1 << 0); \
645 if (aaaa[1] COMP ref) passMask |= (1 << 1); \
646 if (aaaa[2] COMP ref) passMask |= (1 << 2); \
647 if (aaaa[3] COMP ref) passMask |= (1 << 3); \
649 quads[i]->inout.mask &= passMask; \
651 if (quads[i]->inout.mask) \
652 quads[pass_nr++] = quads[i]; \
660 ALPHATEST( EQUAL, == )
661 ALPHATEST( LEQUAL, <= )
662 ALPHATEST( GREATER, > )
663 ALPHATEST( NOTEQUAL, != )
664 ALPHATEST( GEQUAL, >= )
667 /* XXX: Incorporate into shader using KILP.
670 alpha_test_quads(struct quad_stage *qs,
671 struct quad_header *quads[],
674 switch (qs->softpipe->depth_stencil->alpha.func) {
676 return alpha_test_quads_LESS( qs, quads, nr );
677 case PIPE_FUNC_EQUAL:
678 return alpha_test_quads_EQUAL( qs, quads, nr );
680 case PIPE_FUNC_LEQUAL:
681 return alpha_test_quads_LEQUAL( qs, quads, nr );
682 case PIPE_FUNC_GREATER:
683 return alpha_test_quads_GREATER( qs, quads, nr );
684 case PIPE_FUNC_NOTEQUAL:
685 return alpha_test_quads_NOTEQUAL( qs, quads, nr );
686 case PIPE_FUNC_GEQUAL:
687 return alpha_test_quads_GEQUAL( qs, quads, nr );
688 case PIPE_FUNC_ALWAYS:
690 case PIPE_FUNC_NEVER:
697 static unsigned mask_count[16] =
720 * General depth/stencil test function. Used when there's no fast-path.
723 depth_test_quads_fallback(struct quad_stage *qs,
724 struct quad_header *quads[],
727 unsigned i, pass = 0;
728 const struct sp_fragment_shader *fs = qs->softpipe->fs;
729 boolean interp_depth = !fs->info.writes_z;
730 boolean shader_stencil_ref = fs->info.writes_stencil;
731 struct depth_data data;
733 data.use_shader_stencil_refs = FALSE;
735 if (qs->softpipe->depth_stencil->alpha.enabled) {
736 nr = alpha_test_quads(qs, quads, nr);
739 if (qs->softpipe->framebuffer.zsbuf &&
740 (qs->softpipe->depth_stencil->depth.enabled ||
741 qs->softpipe->depth_stencil->stencil[0].enabled)) {
743 data.ps = qs->softpipe->framebuffer.zsbuf;
744 data.format = data.ps->format;
745 data.tile = sp_get_cached_tile(qs->softpipe->zsbuf_cache,
749 for (i = 0; i < nr; i++) {
750 get_depth_stencil_values(&data, quads[i]);
752 if (qs->softpipe->depth_stencil->depth.enabled) {
754 interpolate_quad_depth(quads[i]);
756 convert_quad_depth(&data, quads[i]);
759 if (qs->softpipe->depth_stencil->stencil[0].enabled) {
760 if (shader_stencil_ref)
761 convert_quad_stencil(&data, quads[i]);
763 depth_stencil_test_quad(qs, &data, quads[i]);
764 write_depth_stencil_values(&data, quads[i]);
767 if (!depth_test_quad(qs, &data, quads[i]))
770 if (qs->softpipe->depth_stencil->depth.writemask)
771 write_depth_stencil_values(&data, quads[i]);
774 quads[pass++] = quads[i];
780 if (qs->softpipe->active_query_count) {
781 for (i = 0; i < nr; i++)
782 qs->softpipe->occlusion_count += mask_count[quads[i]->inout.mask];
786 qs->next->run(qs->next, quads, nr);
791 * Special-case Z testing for 16-bit Zbuffer and Z buffer writes enabled.
794 #define NAME depth_interp_z16_less_write
796 #include "sp_quad_depth_test_tmp.h"
798 #define NAME depth_interp_z16_equal_write
800 #include "sp_quad_depth_test_tmp.h"
802 #define NAME depth_interp_z16_lequal_write
804 #include "sp_quad_depth_test_tmp.h"
806 #define NAME depth_interp_z16_greater_write
808 #include "sp_quad_depth_test_tmp.h"
810 #define NAME depth_interp_z16_notequal_write
812 #include "sp_quad_depth_test_tmp.h"
814 #define NAME depth_interp_z16_gequal_write
816 #include "sp_quad_depth_test_tmp.h"
818 #define NAME depth_interp_z16_always_write
820 #include "sp_quad_depth_test_tmp.h"
825 depth_noop(struct quad_stage *qs,
826 struct quad_header *quads[],
829 qs->next->run(qs->next, quads, nr);
835 choose_depth_test(struct quad_stage *qs,
836 struct quad_header *quads[],
839 boolean interp_depth = !qs->softpipe->fs->info.writes_z;
841 boolean alpha = qs->softpipe->depth_stencil->alpha.enabled;
843 boolean depth = qs->softpipe->depth_stencil->depth.enabled;
845 unsigned depthfunc = qs->softpipe->depth_stencil->depth.func;
847 boolean stencil = qs->softpipe->depth_stencil->stencil[0].enabled;
849 boolean depthwrite = qs->softpipe->depth_stencil->depth.writemask;
851 boolean occlusion = qs->softpipe->active_query_count;
853 if(!qs->softpipe->framebuffer.zsbuf)
854 depth = depthwrite = stencil = FALSE;
857 qs->run = depth_test_quads_fallback;
859 /* look for special cases */
864 qs->run = depth_noop;
873 if (qs->softpipe->framebuffer.zsbuf->format == PIPE_FORMAT_Z16_UNORM) {
875 case PIPE_FUNC_NEVER:
876 qs->run = depth_test_quads_fallback;
879 qs->run = depth_interp_z16_less_write;
881 case PIPE_FUNC_EQUAL:
882 qs->run = depth_interp_z16_equal_write;
884 case PIPE_FUNC_LEQUAL:
885 qs->run = depth_interp_z16_lequal_write;
887 case PIPE_FUNC_GREATER:
888 qs->run = depth_interp_z16_greater_write;
890 case PIPE_FUNC_NOTEQUAL:
891 qs->run = depth_interp_z16_notequal_write;
893 case PIPE_FUNC_GEQUAL:
894 qs->run = depth_interp_z16_gequal_write;
896 case PIPE_FUNC_ALWAYS:
897 qs->run = depth_interp_z16_always_write;
900 qs->run = depth_test_quads_fallback;
906 /* next quad/fragment stage */
907 qs->run( qs, quads, nr );
913 depth_test_begin(struct quad_stage *qs)
915 qs->run = choose_depth_test;
916 qs->next->begin(qs->next);
921 depth_test_destroy(struct quad_stage *qs)
928 sp_quad_depth_test_stage(struct softpipe_context *softpipe)
930 struct quad_stage *stage = CALLOC_STRUCT(quad_stage);
932 stage->softpipe = softpipe;
933 stage->begin = depth_test_begin;
934 stage->run = choose_depth_test;
935 stage->destroy = depth_test_destroy;