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
:
209 for (j
= 0; j
< QUAD_SIZE
; j
++) {
210 data
->shader_stencil_refs
[j
] = ((unsigned)(quad
->output
.stencil
[j
]));
220 * Write data->bzzzz[] values and data->stencilVals into the Z/stencil buffer.
223 write_depth_stencil_values( struct depth_data
*data
,
224 struct quad_header
*quad
)
226 struct softpipe_cached_tile
*tile
= data
->tile
;
229 /* put updated Z values back into cached tile */
230 switch (data
->format
) {
231 case PIPE_FORMAT_Z16_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
.depth16
[y
][x
] = (ushort
) data
->bzzzz
[j
];
238 case PIPE_FORMAT_Z24X8_UNORM
:
239 case PIPE_FORMAT_Z32_UNORM
:
240 for (j
= 0; j
< QUAD_SIZE
; j
++) {
241 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
242 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
243 tile
->data
.depth32
[y
][x
] = data
->bzzzz
[j
];
246 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
247 for (j
= 0; j
< QUAD_SIZE
; j
++) {
248 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
249 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
250 tile
->data
.depth32
[y
][x
] = (data
->stencilVals
[j
] << 24) | data
->bzzzz
[j
];
253 case PIPE_FORMAT_S8_USCALED_Z24_UNORM
:
254 for (j
= 0; j
< QUAD_SIZE
; j
++) {
255 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
256 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
257 tile
->data
.depth32
[y
][x
] = (data
->bzzzz
[j
] << 8) | data
->stencilVals
[j
];
260 case PIPE_FORMAT_X8Z24_UNORM
:
261 for (j
= 0; j
< QUAD_SIZE
; j
++) {
262 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
263 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
264 tile
->data
.depth32
[y
][x
] = data
->bzzzz
[j
] << 8;
267 case PIPE_FORMAT_S8_USCALED
:
268 for (j
= 0; j
< QUAD_SIZE
; j
++) {
269 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
270 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
271 tile
->data
.stencil8
[y
][x
] = data
->stencilVals
[j
];
282 /** Only 8-bit stencil supported */
283 #define STENCIL_MAX 0xff
287 * Do the basic stencil test (compare stencil buffer values against the
290 * \param data->stencilVals the stencil values from the stencil buffer
291 * \param func the stencil func (PIPE_FUNC_x)
292 * \param ref the stencil reference value
293 * \param valMask the stencil value mask indicating which bits of the stencil
294 * values and ref value are to be used.
295 * \return mask indicating which pixels passed the stencil test
298 do_stencil_test(struct depth_data
*data
,
300 unsigned ref
, unsigned valMask
)
302 unsigned passMask
= 0x0;
304 ubyte refs
[QUAD_SIZE
];
306 for (j
= 0; j
< QUAD_SIZE
; j
++) {
307 if (data
->use_shader_stencil_refs
)
308 refs
[j
] = data
->shader_stencil_refs
[j
] & valMask
;
310 refs
[j
] = ref
& valMask
;
314 case PIPE_FUNC_NEVER
:
318 for (j
= 0; j
< QUAD_SIZE
; j
++) {
319 if (refs
[j
] < (data
->stencilVals
[j
] & valMask
)) {
320 passMask
|= (1 << j
);
324 case PIPE_FUNC_EQUAL
:
325 for (j
= 0; j
< QUAD_SIZE
; j
++) {
326 if (refs
[j
] == (data
->stencilVals
[j
] & valMask
)) {
327 passMask
|= (1 << j
);
331 case PIPE_FUNC_LEQUAL
:
332 for (j
= 0; j
< QUAD_SIZE
; j
++) {
333 if (refs
[j
] <= (data
->stencilVals
[j
] & valMask
)) {
334 passMask
|= (1 << j
);
338 case PIPE_FUNC_GREATER
:
339 for (j
= 0; j
< QUAD_SIZE
; j
++) {
340 if (refs
[j
] > (data
->stencilVals
[j
] & valMask
)) {
341 passMask
|= (1 << j
);
345 case PIPE_FUNC_NOTEQUAL
:
346 for (j
= 0; j
< QUAD_SIZE
; j
++) {
347 if (refs
[j
] != (data
->stencilVals
[j
] & valMask
)) {
348 passMask
|= (1 << j
);
352 case PIPE_FUNC_GEQUAL
:
353 for (j
= 0; j
< QUAD_SIZE
; j
++) {
354 if (refs
[j
] >= (data
->stencilVals
[j
] & valMask
)) {
355 passMask
|= (1 << j
);
359 case PIPE_FUNC_ALWAYS
:
371 * Apply the stencil operator to stencil values.
373 * \param data->stencilVals the stencil buffer values (read and written)
374 * \param mask indicates which pixels to update
375 * \param op the stencil operator (PIPE_STENCIL_OP_x)
376 * \param ref the stencil reference value
377 * \param wrtMask writemask controlling which bits are changed in the
381 apply_stencil_op(struct depth_data
*data
,
382 unsigned mask
, unsigned op
, ubyte ref
, ubyte wrtMask
)
385 ubyte newstencil
[QUAD_SIZE
];
386 ubyte refs
[QUAD_SIZE
];
388 for (j
= 0; j
< QUAD_SIZE
; j
++) {
389 newstencil
[j
] = data
->stencilVals
[j
];
390 if (data
->use_shader_stencil_refs
)
391 refs
[j
] = data
->shader_stencil_refs
[j
];
397 case PIPE_STENCIL_OP_KEEP
:
400 case PIPE_STENCIL_OP_ZERO
:
401 for (j
= 0; j
< QUAD_SIZE
; j
++) {
402 if (mask
& (1 << j
)) {
407 case PIPE_STENCIL_OP_REPLACE
:
408 for (j
= 0; j
< QUAD_SIZE
; j
++) {
409 if (mask
& (1 << j
)) {
410 newstencil
[j
] = refs
[j
];
414 case PIPE_STENCIL_OP_INCR
:
415 for (j
= 0; j
< QUAD_SIZE
; j
++) {
416 if (mask
& (1 << j
)) {
417 if (data
->stencilVals
[j
] < STENCIL_MAX
) {
418 newstencil
[j
] = data
->stencilVals
[j
] + 1;
423 case PIPE_STENCIL_OP_DECR
:
424 for (j
= 0; j
< QUAD_SIZE
; j
++) {
425 if (mask
& (1 << j
)) {
426 if (data
->stencilVals
[j
] > 0) {
427 newstencil
[j
] = data
->stencilVals
[j
] - 1;
432 case PIPE_STENCIL_OP_INCR_WRAP
:
433 for (j
= 0; j
< QUAD_SIZE
; j
++) {
434 if (mask
& (1 << j
)) {
435 newstencil
[j
] = data
->stencilVals
[j
] + 1;
439 case PIPE_STENCIL_OP_DECR_WRAP
:
440 for (j
= 0; j
< QUAD_SIZE
; j
++) {
441 if (mask
& (1 << j
)) {
442 newstencil
[j
] = data
->stencilVals
[j
] - 1;
446 case PIPE_STENCIL_OP_INVERT
:
447 for (j
= 0; j
< QUAD_SIZE
; j
++) {
448 if (mask
& (1 << j
)) {
449 newstencil
[j
] = ~data
->stencilVals
[j
];
458 * update the stencil values
460 if (wrtMask
!= STENCIL_MAX
) {
461 /* apply bit-wise stencil buffer writemask */
462 for (j
= 0; j
< QUAD_SIZE
; j
++) {
463 data
->stencilVals
[j
] = (wrtMask
& newstencil
[j
]) | (~wrtMask
& data
->stencilVals
[j
]);
467 for (j
= 0; j
< QUAD_SIZE
; j
++) {
468 data
->stencilVals
[j
] = newstencil
[j
];
476 * To increase efficiency, we should probably have multiple versions
477 * of this function that are specifically for Z16, Z32 and FP Z buffers.
478 * Try to effectively do that with codegen...
481 depth_test_quad(struct quad_stage
*qs
,
482 struct depth_data
*data
,
483 struct quad_header
*quad
)
485 struct softpipe_context
*softpipe
= qs
->softpipe
;
489 switch (softpipe
->depth_stencil
->depth
.func
) {
490 case PIPE_FUNC_NEVER
:
494 /* Note this is pretty much a single sse or cell instruction.
495 * Like this: quad->mask &= (quad->outputs.depth < zzzz);
497 for (j
= 0; j
< QUAD_SIZE
; j
++) {
498 if (data
->qzzzz
[j
] < data
->bzzzz
[j
])
502 case PIPE_FUNC_EQUAL
:
503 for (j
= 0; j
< QUAD_SIZE
; j
++) {
504 if (data
->qzzzz
[j
] == data
->bzzzz
[j
])
508 case PIPE_FUNC_LEQUAL
:
509 for (j
= 0; j
< QUAD_SIZE
; j
++) {
510 if (data
->qzzzz
[j
] <= data
->bzzzz
[j
])
514 case PIPE_FUNC_GREATER
:
515 for (j
= 0; j
< QUAD_SIZE
; j
++) {
516 if (data
->qzzzz
[j
] > data
->bzzzz
[j
])
520 case PIPE_FUNC_NOTEQUAL
:
521 for (j
= 0; j
< QUAD_SIZE
; j
++) {
522 if (data
->qzzzz
[j
] != data
->bzzzz
[j
])
526 case PIPE_FUNC_GEQUAL
:
527 for (j
= 0; j
< QUAD_SIZE
; j
++) {
528 if (data
->qzzzz
[j
] >= data
->bzzzz
[j
])
532 case PIPE_FUNC_ALWAYS
:
539 quad
->inout
.mask
&= zmask
;
540 if (quad
->inout
.mask
== 0)
543 /* Update our internal copy only if writemask set. Even if
544 * depth.writemask is FALSE, may still need to write out buffer
545 * data due to stencil changes.
547 if (softpipe
->depth_stencil
->depth
.writemask
) {
548 for (j
= 0; j
< QUAD_SIZE
; j
++) {
549 if (quad
->inout
.mask
& (1 << j
)) {
550 data
->bzzzz
[j
] = data
->qzzzz
[j
];
561 * Do stencil (and depth) testing. Stenciling depends on the outcome of
565 depth_stencil_test_quad(struct quad_stage
*qs
,
566 struct depth_data
*data
,
567 struct quad_header
*quad
)
569 struct softpipe_context
*softpipe
= qs
->softpipe
;
570 unsigned func
, zFailOp
, zPassOp
, failOp
;
571 ubyte ref
, wrtMask
, valMask
;
572 uint face
= quad
->input
.facing
;
574 if (!softpipe
->depth_stencil
->stencil
[1].enabled
) {
575 /* single-sided stencil test, use front (face=0) state */
579 /* 0 = front-face, 1 = back-face */
580 assert(face
== 0 || face
== 1);
582 /* choose front or back face function, operator, etc */
583 /* XXX we could do these initializations once per primitive */
584 func
= softpipe
->depth_stencil
->stencil
[face
].func
;
585 failOp
= softpipe
->depth_stencil
->stencil
[face
].fail_op
;
586 zFailOp
= softpipe
->depth_stencil
->stencil
[face
].zfail_op
;
587 zPassOp
= softpipe
->depth_stencil
->stencil
[face
].zpass_op
;
588 ref
= softpipe
->stencil_ref
.ref_value
[face
];
589 wrtMask
= softpipe
->depth_stencil
->stencil
[face
].writemask
;
590 valMask
= softpipe
->depth_stencil
->stencil
[face
].valuemask
;
592 /* do the stencil test first */
594 unsigned passMask
, failMask
;
595 passMask
= do_stencil_test(data
, func
, ref
, valMask
);
596 failMask
= quad
->inout
.mask
& ~passMask
;
597 quad
->inout
.mask
&= passMask
;
599 if (failOp
!= PIPE_STENCIL_OP_KEEP
) {
600 apply_stencil_op(data
, failMask
, failOp
, ref
, wrtMask
);
604 if (quad
->inout
.mask
) {
605 /* now the pixels that passed the stencil test are depth tested */
606 if (softpipe
->depth_stencil
->depth
.enabled
) {
607 const unsigned origMask
= quad
->inout
.mask
;
609 depth_test_quad(qs
, data
, quad
); /* quad->mask is updated */
611 /* update stencil buffer values according to z pass/fail result */
612 if (zFailOp
!= PIPE_STENCIL_OP_KEEP
) {
613 const unsigned zFailMask
= origMask
& ~quad
->inout
.mask
;
614 apply_stencil_op(data
, zFailMask
, zFailOp
, ref
, wrtMask
);
617 if (zPassOp
!= PIPE_STENCIL_OP_KEEP
) {
618 const unsigned zPassMask
= origMask
& quad
->inout
.mask
;
619 apply_stencil_op(data
, zPassMask
, zPassOp
, ref
, wrtMask
);
623 /* no depth test, apply Zpass operator to stencil buffer values */
624 apply_stencil_op(data
, quad
->inout
.mask
, zPassOp
, ref
, wrtMask
);
630 #define ALPHATEST( FUNC, COMP ) \
632 alpha_test_quads_##FUNC( struct quad_stage *qs, \
633 struct quad_header *quads[], \
636 const float ref = qs->softpipe->depth_stencil->alpha.ref_value; \
637 const uint cbuf = 0; /* only output[0].alpha is tested */ \
638 unsigned pass_nr = 0; \
641 for (i = 0; i < nr; i++) { \
642 const float *aaaa = quads[i]->output.color[cbuf][3]; \
643 unsigned passMask = 0; \
645 if (aaaa[0] COMP ref) passMask |= (1 << 0); \
646 if (aaaa[1] COMP ref) passMask |= (1 << 1); \
647 if (aaaa[2] COMP ref) passMask |= (1 << 2); \
648 if (aaaa[3] COMP ref) passMask |= (1 << 3); \
650 quads[i]->inout.mask &= passMask; \
652 if (quads[i]->inout.mask) \
653 quads[pass_nr++] = quads[i]; \
661 ALPHATEST( EQUAL
, == )
662 ALPHATEST( LEQUAL
, <= )
663 ALPHATEST( GREATER
, > )
664 ALPHATEST( NOTEQUAL
, != )
665 ALPHATEST( GEQUAL
, >= )
668 /* XXX: Incorporate into shader using KILP.
671 alpha_test_quads(struct quad_stage
*qs
,
672 struct quad_header
*quads
[],
675 switch (qs
->softpipe
->depth_stencil
->alpha
.func
) {
677 return alpha_test_quads_LESS( qs
, quads
, nr
);
678 case PIPE_FUNC_EQUAL
:
679 return alpha_test_quads_EQUAL( qs
, quads
, nr
);
681 case PIPE_FUNC_LEQUAL
:
682 return alpha_test_quads_LEQUAL( qs
, quads
, nr
);
683 case PIPE_FUNC_GREATER
:
684 return alpha_test_quads_GREATER( qs
, quads
, nr
);
685 case PIPE_FUNC_NOTEQUAL
:
686 return alpha_test_quads_NOTEQUAL( qs
, quads
, nr
);
687 case PIPE_FUNC_GEQUAL
:
688 return alpha_test_quads_GEQUAL( qs
, quads
, nr
);
689 case PIPE_FUNC_ALWAYS
:
691 case PIPE_FUNC_NEVER
:
698 static unsigned mask_count
[16] =
721 * General depth/stencil test function. Used when there's no fast-path.
724 depth_test_quads_fallback(struct quad_stage
*qs
,
725 struct quad_header
*quads
[],
728 unsigned i
, pass
= 0;
729 const struct sp_fragment_shader
*fs
= qs
->softpipe
->fs
;
730 boolean interp_depth
= !fs
->info
.writes_z
;
731 boolean shader_stencil_ref
= fs
->info
.writes_stencil
;
732 struct depth_data data
;
734 data
.use_shader_stencil_refs
= FALSE
;
736 if (qs
->softpipe
->depth_stencil
->alpha
.enabled
) {
737 nr
= alpha_test_quads(qs
, quads
, nr
);
740 if (qs
->softpipe
->framebuffer
.zsbuf
&&
741 (qs
->softpipe
->depth_stencil
->depth
.enabled
||
742 qs
->softpipe
->depth_stencil
->stencil
[0].enabled
)) {
744 data
.ps
= qs
->softpipe
->framebuffer
.zsbuf
;
745 data
.format
= data
.ps
->format
;
746 data
.tile
= sp_get_cached_tile(qs
->softpipe
->zsbuf_cache
,
750 for (i
= 0; i
< nr
; i
++) {
751 get_depth_stencil_values(&data
, quads
[i
]);
753 if (qs
->softpipe
->depth_stencil
->depth
.enabled
) {
755 interpolate_quad_depth(quads
[i
]);
757 convert_quad_depth(&data
, quads
[i
]);
760 if (qs
->softpipe
->depth_stencil
->stencil
[0].enabled
) {
761 if (shader_stencil_ref
)
762 convert_quad_stencil(&data
, quads
[i
]);
764 depth_stencil_test_quad(qs
, &data
, quads
[i
]);
765 write_depth_stencil_values(&data
, quads
[i
]);
768 if (!depth_test_quad(qs
, &data
, quads
[i
]))
771 if (qs
->softpipe
->depth_stencil
->depth
.writemask
)
772 write_depth_stencil_values(&data
, quads
[i
]);
775 quads
[pass
++] = quads
[i
];
781 if (qs
->softpipe
->active_query_count
) {
782 for (i
= 0; i
< nr
; i
++)
783 qs
->softpipe
->occlusion_count
+= mask_count
[quads
[i
]->inout
.mask
];
787 qs
->next
->run(qs
->next
, quads
, nr
);
792 * Special-case Z testing for 16-bit Zbuffer and Z buffer writes enabled.
795 #define NAME depth_interp_z16_less_write
797 #include "sp_quad_depth_test_tmp.h"
799 #define NAME depth_interp_z16_equal_write
801 #include "sp_quad_depth_test_tmp.h"
803 #define NAME depth_interp_z16_lequal_write
805 #include "sp_quad_depth_test_tmp.h"
807 #define NAME depth_interp_z16_greater_write
809 #include "sp_quad_depth_test_tmp.h"
811 #define NAME depth_interp_z16_notequal_write
813 #include "sp_quad_depth_test_tmp.h"
815 #define NAME depth_interp_z16_gequal_write
817 #include "sp_quad_depth_test_tmp.h"
819 #define NAME depth_interp_z16_always_write
821 #include "sp_quad_depth_test_tmp.h"
826 depth_noop(struct quad_stage
*qs
,
827 struct quad_header
*quads
[],
830 qs
->next
->run(qs
->next
, quads
, nr
);
836 choose_depth_test(struct quad_stage
*qs
,
837 struct quad_header
*quads
[],
840 boolean interp_depth
= !qs
->softpipe
->fs
->info
.writes_z
;
842 boolean alpha
= qs
->softpipe
->depth_stencil
->alpha
.enabled
;
844 boolean depth
= qs
->softpipe
->depth_stencil
->depth
.enabled
;
846 unsigned depthfunc
= qs
->softpipe
->depth_stencil
->depth
.func
;
848 boolean stencil
= qs
->softpipe
->depth_stencil
->stencil
[0].enabled
;
850 boolean depthwrite
= qs
->softpipe
->depth_stencil
->depth
.writemask
;
852 boolean occlusion
= qs
->softpipe
->active_query_count
;
854 if(!qs
->softpipe
->framebuffer
.zsbuf
)
855 depth
= depthwrite
= stencil
= FALSE
;
858 qs
->run
= depth_test_quads_fallback
;
860 /* 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
;