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
193 * fragment stencil values.
196 convert_quad_stencil( struct depth_data
*data
,
197 const struct quad_header
*quad
)
201 data
->use_shader_stencil_refs
= TRUE
;
202 /* Copy quads stencil values
204 switch (data
->format
) {
205 case PIPE_FORMAT_Z24X8_UNORM
:
206 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
207 case PIPE_FORMAT_X8Z24_UNORM
:
208 case PIPE_FORMAT_S8_USCALED_Z24_UNORM
:
209 case PIPE_FORMAT_S8_USCALED
:
210 for (j
= 0; j
< QUAD_SIZE
; j
++) {
211 data
->shader_stencil_refs
[j
] = ((unsigned)(quad
->output
.stencil
[j
]));
221 * Write data->bzzzz[] values and data->stencilVals into the Z/stencil buffer.
224 write_depth_stencil_values( struct depth_data
*data
,
225 struct quad_header
*quad
)
227 struct softpipe_cached_tile
*tile
= data
->tile
;
230 /* put updated Z values back into cached tile */
231 switch (data
->format
) {
232 case PIPE_FORMAT_Z16_UNORM
:
233 for (j
= 0; j
< QUAD_SIZE
; j
++) {
234 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
235 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
236 tile
->data
.depth16
[y
][x
] = (ushort
) data
->bzzzz
[j
];
239 case PIPE_FORMAT_Z24X8_UNORM
:
240 case PIPE_FORMAT_Z32_UNORM
:
241 for (j
= 0; j
< QUAD_SIZE
; j
++) {
242 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
243 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
244 tile
->data
.depth32
[y
][x
] = data
->bzzzz
[j
];
247 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
248 for (j
= 0; j
< QUAD_SIZE
; j
++) {
249 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
250 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
251 tile
->data
.depth32
[y
][x
] = (data
->stencilVals
[j
] << 24) | data
->bzzzz
[j
];
254 case PIPE_FORMAT_S8_USCALED_Z24_UNORM
:
255 for (j
= 0; j
< QUAD_SIZE
; j
++) {
256 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
257 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
258 tile
->data
.depth32
[y
][x
] = (data
->bzzzz
[j
] << 8) | data
->stencilVals
[j
];
261 case PIPE_FORMAT_X8Z24_UNORM
:
262 for (j
= 0; j
< QUAD_SIZE
; j
++) {
263 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
264 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
265 tile
->data
.depth32
[y
][x
] = data
->bzzzz
[j
] << 8;
268 case PIPE_FORMAT_S8_USCALED
:
269 for (j
= 0; j
< QUAD_SIZE
; j
++) {
270 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
271 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
272 tile
->data
.stencil8
[y
][x
] = data
->stencilVals
[j
];
283 /** Only 8-bit stencil supported */
284 #define STENCIL_MAX 0xff
288 * Do the basic stencil test (compare stencil buffer values against the
291 * \param data->stencilVals the stencil values from the stencil buffer
292 * \param func the stencil func (PIPE_FUNC_x)
293 * \param ref the stencil reference value
294 * \param valMask the stencil value mask indicating which bits of the stencil
295 * values and ref value are to be used.
296 * \return mask indicating which pixels passed the stencil test
299 do_stencil_test(struct depth_data
*data
,
301 unsigned ref
, unsigned valMask
)
303 unsigned passMask
= 0x0;
305 ubyte refs
[QUAD_SIZE
];
307 for (j
= 0; j
< QUAD_SIZE
; j
++) {
308 if (data
->use_shader_stencil_refs
)
309 refs
[j
] = data
->shader_stencil_refs
[j
] & valMask
;
311 refs
[j
] = ref
& valMask
;
315 case PIPE_FUNC_NEVER
:
319 for (j
= 0; j
< QUAD_SIZE
; j
++) {
320 if (refs
[j
] < (data
->stencilVals
[j
] & valMask
)) {
321 passMask
|= (1 << j
);
325 case PIPE_FUNC_EQUAL
:
326 for (j
= 0; j
< QUAD_SIZE
; j
++) {
327 if (refs
[j
] == (data
->stencilVals
[j
] & valMask
)) {
328 passMask
|= (1 << j
);
332 case PIPE_FUNC_LEQUAL
:
333 for (j
= 0; j
< QUAD_SIZE
; j
++) {
334 if (refs
[j
] <= (data
->stencilVals
[j
] & valMask
)) {
335 passMask
|= (1 << j
);
339 case PIPE_FUNC_GREATER
:
340 for (j
= 0; j
< QUAD_SIZE
; j
++) {
341 if (refs
[j
] > (data
->stencilVals
[j
] & valMask
)) {
342 passMask
|= (1 << j
);
346 case PIPE_FUNC_NOTEQUAL
:
347 for (j
= 0; j
< QUAD_SIZE
; j
++) {
348 if (refs
[j
] != (data
->stencilVals
[j
] & valMask
)) {
349 passMask
|= (1 << j
);
353 case PIPE_FUNC_GEQUAL
:
354 for (j
= 0; j
< QUAD_SIZE
; j
++) {
355 if (refs
[j
] >= (data
->stencilVals
[j
] & valMask
)) {
356 passMask
|= (1 << j
);
360 case PIPE_FUNC_ALWAYS
:
372 * Apply the stencil operator to stencil values.
374 * \param data->stencilVals the stencil buffer values (read and written)
375 * \param mask indicates which pixels to update
376 * \param op the stencil operator (PIPE_STENCIL_OP_x)
377 * \param ref the stencil reference value
378 * \param wrtMask writemask controlling which bits are changed in the
382 apply_stencil_op(struct depth_data
*data
,
383 unsigned mask
, unsigned op
, ubyte ref
, ubyte wrtMask
)
386 ubyte newstencil
[QUAD_SIZE
];
387 ubyte refs
[QUAD_SIZE
];
389 for (j
= 0; j
< QUAD_SIZE
; j
++) {
390 newstencil
[j
] = data
->stencilVals
[j
];
391 if (data
->use_shader_stencil_refs
)
392 refs
[j
] = data
->shader_stencil_refs
[j
];
398 case PIPE_STENCIL_OP_KEEP
:
401 case PIPE_STENCIL_OP_ZERO
:
402 for (j
= 0; j
< QUAD_SIZE
; j
++) {
403 if (mask
& (1 << j
)) {
408 case PIPE_STENCIL_OP_REPLACE
:
409 for (j
= 0; j
< QUAD_SIZE
; j
++) {
410 if (mask
& (1 << j
)) {
411 newstencil
[j
] = refs
[j
];
415 case PIPE_STENCIL_OP_INCR
:
416 for (j
= 0; j
< QUAD_SIZE
; j
++) {
417 if (mask
& (1 << j
)) {
418 if (data
->stencilVals
[j
] < STENCIL_MAX
) {
419 newstencil
[j
] = data
->stencilVals
[j
] + 1;
424 case PIPE_STENCIL_OP_DECR
:
425 for (j
= 0; j
< QUAD_SIZE
; j
++) {
426 if (mask
& (1 << j
)) {
427 if (data
->stencilVals
[j
] > 0) {
428 newstencil
[j
] = data
->stencilVals
[j
] - 1;
433 case PIPE_STENCIL_OP_INCR_WRAP
:
434 for (j
= 0; j
< QUAD_SIZE
; j
++) {
435 if (mask
& (1 << j
)) {
436 newstencil
[j
] = data
->stencilVals
[j
] + 1;
440 case PIPE_STENCIL_OP_DECR_WRAP
:
441 for (j
= 0; j
< QUAD_SIZE
; j
++) {
442 if (mask
& (1 << j
)) {
443 newstencil
[j
] = data
->stencilVals
[j
] - 1;
447 case PIPE_STENCIL_OP_INVERT
:
448 for (j
= 0; j
< QUAD_SIZE
; j
++) {
449 if (mask
& (1 << j
)) {
450 newstencil
[j
] = ~data
->stencilVals
[j
];
459 * update the stencil values
461 if (wrtMask
!= STENCIL_MAX
) {
462 /* apply bit-wise stencil buffer writemask */
463 for (j
= 0; j
< QUAD_SIZE
; j
++) {
464 data
->stencilVals
[j
] = (wrtMask
& newstencil
[j
]) | (~wrtMask
& data
->stencilVals
[j
]);
468 for (j
= 0; j
< QUAD_SIZE
; j
++) {
469 data
->stencilVals
[j
] = newstencil
[j
];
477 * To increase efficiency, we should probably have multiple versions
478 * of this function that are specifically for Z16, Z32 and FP Z buffers.
479 * Try to effectively do that with codegen...
482 depth_test_quad(struct quad_stage
*qs
,
483 struct depth_data
*data
,
484 struct quad_header
*quad
)
486 struct softpipe_context
*softpipe
= qs
->softpipe
;
490 switch (softpipe
->depth_stencil
->depth
.func
) {
491 case PIPE_FUNC_NEVER
:
495 /* Note this is pretty much a single sse or cell instruction.
496 * Like this: quad->mask &= (quad->outputs.depth < zzzz);
498 for (j
= 0; j
< QUAD_SIZE
; j
++) {
499 if (data
->qzzzz
[j
] < data
->bzzzz
[j
])
503 case PIPE_FUNC_EQUAL
:
504 for (j
= 0; j
< QUAD_SIZE
; j
++) {
505 if (data
->qzzzz
[j
] == data
->bzzzz
[j
])
509 case PIPE_FUNC_LEQUAL
:
510 for (j
= 0; j
< QUAD_SIZE
; j
++) {
511 if (data
->qzzzz
[j
] <= data
->bzzzz
[j
])
515 case PIPE_FUNC_GREATER
:
516 for (j
= 0; j
< QUAD_SIZE
; j
++) {
517 if (data
->qzzzz
[j
] > data
->bzzzz
[j
])
521 case PIPE_FUNC_NOTEQUAL
:
522 for (j
= 0; j
< QUAD_SIZE
; j
++) {
523 if (data
->qzzzz
[j
] != data
->bzzzz
[j
])
527 case PIPE_FUNC_GEQUAL
:
528 for (j
= 0; j
< QUAD_SIZE
; j
++) {
529 if (data
->qzzzz
[j
] >= data
->bzzzz
[j
])
533 case PIPE_FUNC_ALWAYS
:
540 quad
->inout
.mask
&= zmask
;
541 if (quad
->inout
.mask
== 0)
544 /* Update our internal copy only if writemask set. Even if
545 * depth.writemask is FALSE, may still need to write out buffer
546 * data due to stencil changes.
548 if (softpipe
->depth_stencil
->depth
.writemask
) {
549 for (j
= 0; j
< QUAD_SIZE
; j
++) {
550 if (quad
->inout
.mask
& (1 << j
)) {
551 data
->bzzzz
[j
] = data
->qzzzz
[j
];
562 * Do stencil (and depth) testing. Stenciling depends on the outcome of
566 depth_stencil_test_quad(struct quad_stage
*qs
,
567 struct depth_data
*data
,
568 struct quad_header
*quad
)
570 struct softpipe_context
*softpipe
= qs
->softpipe
;
571 unsigned func
, zFailOp
, zPassOp
, failOp
;
572 ubyte ref
, wrtMask
, valMask
;
573 uint face
= quad
->input
.facing
;
575 if (!softpipe
->depth_stencil
->stencil
[1].enabled
) {
576 /* single-sided stencil test, use front (face=0) state */
580 /* 0 = front-face, 1 = back-face */
581 assert(face
== 0 || face
== 1);
583 /* choose front or back face function, operator, etc */
584 /* XXX we could do these initializations once per primitive */
585 func
= softpipe
->depth_stencil
->stencil
[face
].func
;
586 failOp
= softpipe
->depth_stencil
->stencil
[face
].fail_op
;
587 zFailOp
= softpipe
->depth_stencil
->stencil
[face
].zfail_op
;
588 zPassOp
= softpipe
->depth_stencil
->stencil
[face
].zpass_op
;
589 ref
= softpipe
->stencil_ref
.ref_value
[face
];
590 wrtMask
= softpipe
->depth_stencil
->stencil
[face
].writemask
;
591 valMask
= softpipe
->depth_stencil
->stencil
[face
].valuemask
;
593 /* do the stencil test first */
595 unsigned passMask
, failMask
;
596 passMask
= do_stencil_test(data
, func
, ref
, valMask
);
597 failMask
= quad
->inout
.mask
& ~passMask
;
598 quad
->inout
.mask
&= passMask
;
600 if (failOp
!= PIPE_STENCIL_OP_KEEP
) {
601 apply_stencil_op(data
, failMask
, failOp
, ref
, wrtMask
);
605 if (quad
->inout
.mask
) {
606 /* now the pixels that passed the stencil test are depth tested */
607 if (softpipe
->depth_stencil
->depth
.enabled
) {
608 const unsigned origMask
= quad
->inout
.mask
;
610 depth_test_quad(qs
, data
, quad
); /* quad->mask is updated */
612 /* update stencil buffer values according to z pass/fail result */
613 if (zFailOp
!= PIPE_STENCIL_OP_KEEP
) {
614 const unsigned zFailMask
= origMask
& ~quad
->inout
.mask
;
615 apply_stencil_op(data
, zFailMask
, zFailOp
, ref
, wrtMask
);
618 if (zPassOp
!= PIPE_STENCIL_OP_KEEP
) {
619 const unsigned zPassMask
= origMask
& quad
->inout
.mask
;
620 apply_stencil_op(data
, zPassMask
, zPassOp
, ref
, wrtMask
);
624 /* no depth test, apply Zpass operator to stencil buffer values */
625 apply_stencil_op(data
, quad
->inout
.mask
, zPassOp
, ref
, wrtMask
);
631 #define ALPHATEST( FUNC, COMP ) \
633 alpha_test_quads_##FUNC( struct quad_stage *qs, \
634 struct quad_header *quads[], \
637 const float ref = qs->softpipe->depth_stencil->alpha.ref_value; \
638 const uint cbuf = 0; /* only output[0].alpha is tested */ \
639 unsigned pass_nr = 0; \
642 for (i = 0; i < nr; i++) { \
643 const float *aaaa = quads[i]->output.color[cbuf][3]; \
644 unsigned passMask = 0; \
646 if (aaaa[0] COMP ref) passMask |= (1 << 0); \
647 if (aaaa[1] COMP ref) passMask |= (1 << 1); \
648 if (aaaa[2] COMP ref) passMask |= (1 << 2); \
649 if (aaaa[3] COMP ref) passMask |= (1 << 3); \
651 quads[i]->inout.mask &= passMask; \
653 if (quads[i]->inout.mask) \
654 quads[pass_nr++] = quads[i]; \
662 ALPHATEST( EQUAL
, == )
663 ALPHATEST( LEQUAL
, <= )
664 ALPHATEST( GREATER
, > )
665 ALPHATEST( NOTEQUAL
, != )
666 ALPHATEST( GEQUAL
, >= )
669 /* XXX: Incorporate into shader using KILP.
672 alpha_test_quads(struct quad_stage
*qs
,
673 struct quad_header
*quads
[],
676 switch (qs
->softpipe
->depth_stencil
->alpha
.func
) {
678 return alpha_test_quads_LESS( qs
, quads
, nr
);
679 case PIPE_FUNC_EQUAL
:
680 return alpha_test_quads_EQUAL( qs
, quads
, nr
);
682 case PIPE_FUNC_LEQUAL
:
683 return alpha_test_quads_LEQUAL( qs
, quads
, nr
);
684 case PIPE_FUNC_GREATER
:
685 return alpha_test_quads_GREATER( qs
, quads
, nr
);
686 case PIPE_FUNC_NOTEQUAL
:
687 return alpha_test_quads_NOTEQUAL( qs
, quads
, nr
);
688 case PIPE_FUNC_GEQUAL
:
689 return alpha_test_quads_GEQUAL( qs
, quads
, nr
);
690 case PIPE_FUNC_ALWAYS
:
692 case PIPE_FUNC_NEVER
:
699 static unsigned mask_count
[16] =
722 * General depth/stencil test function. Used when there's no fast-path.
725 depth_test_quads_fallback(struct quad_stage
*qs
,
726 struct quad_header
*quads
[],
729 unsigned i
, pass
= 0;
730 const struct sp_fragment_shader
*fs
= qs
->softpipe
->fs
;
731 boolean interp_depth
= !fs
->info
.writes_z
;
732 boolean shader_stencil_ref
= fs
->info
.writes_stencil
;
733 struct depth_data data
;
735 data
.use_shader_stencil_refs
= FALSE
;
737 if (qs
->softpipe
->depth_stencil
->alpha
.enabled
) {
738 nr
= alpha_test_quads(qs
, quads
, nr
);
741 if (qs
->softpipe
->framebuffer
.zsbuf
&&
742 (qs
->softpipe
->depth_stencil
->depth
.enabled
||
743 qs
->softpipe
->depth_stencil
->stencil
[0].enabled
)) {
745 data
.ps
= qs
->softpipe
->framebuffer
.zsbuf
;
746 data
.format
= data
.ps
->format
;
747 data
.tile
= sp_get_cached_tile(qs
->softpipe
->zsbuf_cache
,
751 for (i
= 0; i
< nr
; i
++) {
752 get_depth_stencil_values(&data
, quads
[i
]);
754 if (qs
->softpipe
->depth_stencil
->depth
.enabled
) {
756 interpolate_quad_depth(quads
[i
]);
758 convert_quad_depth(&data
, quads
[i
]);
761 if (qs
->softpipe
->depth_stencil
->stencil
[0].enabled
) {
762 if (shader_stencil_ref
)
763 convert_quad_stencil(&data
, quads
[i
]);
765 depth_stencil_test_quad(qs
, &data
, quads
[i
]);
766 write_depth_stencil_values(&data
, quads
[i
]);
769 if (!depth_test_quad(qs
, &data
, quads
[i
]))
772 if (qs
->softpipe
->depth_stencil
->depth
.writemask
)
773 write_depth_stencil_values(&data
, quads
[i
]);
776 quads
[pass
++] = quads
[i
];
782 if (qs
->softpipe
->active_query_count
) {
783 for (i
= 0; i
< nr
; i
++)
784 qs
->softpipe
->occlusion_count
+= mask_count
[quads
[i
]->inout
.mask
];
788 qs
->next
->run(qs
->next
, quads
, nr
);
793 * Special-case Z testing for 16-bit Zbuffer and Z buffer writes enabled.
796 #define NAME depth_interp_z16_less_write
798 #include "sp_quad_depth_test_tmp.h"
800 #define NAME depth_interp_z16_equal_write
802 #include "sp_quad_depth_test_tmp.h"
804 #define NAME depth_interp_z16_lequal_write
806 #include "sp_quad_depth_test_tmp.h"
808 #define NAME depth_interp_z16_greater_write
810 #include "sp_quad_depth_test_tmp.h"
812 #define NAME depth_interp_z16_notequal_write
814 #include "sp_quad_depth_test_tmp.h"
816 #define NAME depth_interp_z16_gequal_write
818 #include "sp_quad_depth_test_tmp.h"
820 #define NAME depth_interp_z16_always_write
822 #include "sp_quad_depth_test_tmp.h"
827 depth_noop(struct quad_stage
*qs
,
828 struct quad_header
*quads
[],
831 qs
->next
->run(qs
->next
, quads
, nr
);
837 choose_depth_test(struct quad_stage
*qs
,
838 struct quad_header
*quads
[],
841 boolean interp_depth
= !qs
->softpipe
->fs
->info
.writes_z
;
843 boolean alpha
= qs
->softpipe
->depth_stencil
->alpha
.enabled
;
845 boolean depth
= qs
->softpipe
->depth_stencil
->depth
.enabled
;
847 unsigned depthfunc
= qs
->softpipe
->depth_stencil
->depth
.func
;
849 boolean stencil
= qs
->softpipe
->depth_stencil
->stencil
[0].enabled
;
851 boolean depthwrite
= qs
->softpipe
->depth_stencil
->depth
.writemask
;
853 boolean occlusion
= qs
->softpipe
->active_query_count
;
855 if(!qs
->softpipe
->framebuffer
.zsbuf
)
856 depth
= depthwrite
= stencil
= FALSE
;
859 qs
->run
= depth_test_quads_fallback
;
861 /* look for special cases */
866 qs
->run
= depth_noop
;
875 if (qs
->softpipe
->framebuffer
.zsbuf
->format
== PIPE_FORMAT_Z16_UNORM
) {
877 case PIPE_FUNC_NEVER
:
878 qs
->run
= depth_test_quads_fallback
;
881 qs
->run
= depth_interp_z16_less_write
;
883 case PIPE_FUNC_EQUAL
:
884 qs
->run
= depth_interp_z16_equal_write
;
886 case PIPE_FUNC_LEQUAL
:
887 qs
->run
= depth_interp_z16_lequal_write
;
889 case PIPE_FUNC_GREATER
:
890 qs
->run
= depth_interp_z16_greater_write
;
892 case PIPE_FUNC_NOTEQUAL
:
893 qs
->run
= depth_interp_z16_notequal_write
;
895 case PIPE_FUNC_GEQUAL
:
896 qs
->run
= depth_interp_z16_gequal_write
;
898 case PIPE_FUNC_ALWAYS
:
899 qs
->run
= depth_interp_z16_always_write
;
902 qs
->run
= depth_test_quads_fallback
;
908 /* next quad/fragment stage */
909 qs
->run( qs
, quads
, nr
);
915 depth_test_begin(struct quad_stage
*qs
)
917 qs
->run
= choose_depth_test
;
918 qs
->next
->begin(qs
->next
);
923 depth_test_destroy(struct quad_stage
*qs
)
930 sp_quad_depth_test_stage(struct softpipe_context
*softpipe
)
932 struct quad_stage
*stage
= CALLOC_STRUCT(quad_stage
);
934 stage
->softpipe
= softpipe
;
935 stage
->begin
= depth_test_begin
;
936 stage
->run
= choose_depth_test
;
937 stage
->destroy
= depth_test_destroy
;