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;
102 * If the shader has not been run, interpolate the depth values
106 interpolate_quad_depth( struct quad_header
*quad
)
108 const float fx
= (float) quad
->input
.x0
;
109 const float fy
= (float) quad
->input
.y0
;
110 const float dzdx
= quad
->posCoef
->dadx
[2];
111 const float dzdy
= quad
->posCoef
->dady
[2];
112 const float z0
= quad
->posCoef
->a0
[2] + dzdx
* fx
+ dzdy
* fy
;
114 quad
->output
.depth
[0] = z0
;
115 quad
->output
.depth
[1] = z0
+ dzdx
;
116 quad
->output
.depth
[2] = z0
+ dzdy
;
117 quad
->output
.depth
[3] = z0
+ dzdx
+ dzdy
;
122 * Compute the depth_data::qzzzz[] values from the float fragment Z values.
125 convert_quad_depth( struct depth_data
*data
,
126 const struct quad_header
*quad
)
130 /* Convert quad's float depth values to int depth values (qzzzz).
131 * If the Z buffer stores integer values, we _have_ to do the depth
132 * compares with integers (not floats). Otherwise, the float->int->float
133 * conversion of Z values (which isn't an identity function) will cause
136 switch (data
->format
) {
137 case PIPE_FORMAT_Z16_UNORM
:
139 float scale
= 65535.0;
141 for (j
= 0; j
< QUAD_SIZE
; j
++) {
142 data
->qzzzz
[j
] = (unsigned) (quad
->output
.depth
[j
] * scale
);
146 case PIPE_FORMAT_Z32_UNORM
:
148 double scale
= (double) (uint
) ~0UL;
150 for (j
= 0; j
< QUAD_SIZE
; j
++) {
151 data
->qzzzz
[j
] = (unsigned) (quad
->output
.depth
[j
] * scale
);
155 case PIPE_FORMAT_Z24X8_UNORM
:
156 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
158 float scale
= (float) ((1 << 24) - 1);
160 for (j
= 0; j
< QUAD_SIZE
; j
++) {
161 data
->qzzzz
[j
] = (unsigned) (quad
->output
.depth
[j
] * scale
);
165 case PIPE_FORMAT_X8Z24_UNORM
:
166 case PIPE_FORMAT_S8_USCALED_Z24_UNORM
:
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
);
183 * Write data->bzzzz[] values and data->stencilVals into the Z/stencil buffer.
186 write_depth_stencil_values( struct depth_data
*data
,
187 struct quad_header
*quad
)
189 struct softpipe_cached_tile
*tile
= data
->tile
;
192 /* put updated Z values back into cached tile */
193 switch (data
->format
) {
194 case PIPE_FORMAT_Z16_UNORM
:
195 for (j
= 0; j
< QUAD_SIZE
; j
++) {
196 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
197 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
198 tile
->data
.depth16
[y
][x
] = (ushort
) data
->bzzzz
[j
];
201 case PIPE_FORMAT_Z24X8_UNORM
:
202 case PIPE_FORMAT_Z32_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
.depth32
[y
][x
] = data
->bzzzz
[j
];
209 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
210 for (j
= 0; j
< QUAD_SIZE
; j
++) {
211 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
212 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
213 tile
->data
.depth32
[y
][x
] = (data
->stencilVals
[j
] << 24) | data
->bzzzz
[j
];
216 case PIPE_FORMAT_S8_USCALED_Z24_UNORM
:
217 for (j
= 0; j
< QUAD_SIZE
; j
++) {
218 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
219 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
220 tile
->data
.depth32
[y
][x
] = (data
->bzzzz
[j
] << 8) | data
->stencilVals
[j
];
223 case PIPE_FORMAT_X8Z24_UNORM
:
224 for (j
= 0; j
< QUAD_SIZE
; j
++) {
225 int x
= quad
->input
.x0
% TILE_SIZE
+ (j
& 1);
226 int y
= quad
->input
.y0
% TILE_SIZE
+ (j
>> 1);
227 tile
->data
.depth32
[y
][x
] = data
->bzzzz
[j
] << 8;
237 /** Only 8-bit stencil supported */
238 #define STENCIL_MAX 0xff
242 * Do the basic stencil test (compare stencil buffer values against the
245 * \param data->stencilVals the stencil values from the stencil buffer
246 * \param func the stencil func (PIPE_FUNC_x)
247 * \param ref the stencil reference value
248 * \param valMask the stencil value mask indicating which bits of the stencil
249 * values and ref value are to be used.
250 * \return mask indicating which pixels passed the stencil test
253 do_stencil_test(struct depth_data
*data
,
255 unsigned ref
, unsigned valMask
)
257 unsigned passMask
= 0x0;
263 case PIPE_FUNC_NEVER
:
267 for (j
= 0; j
< QUAD_SIZE
; j
++) {
268 if (ref
< (data
->stencilVals
[j
] & valMask
)) {
269 passMask
|= (1 << j
);
273 case PIPE_FUNC_EQUAL
:
274 for (j
= 0; j
< QUAD_SIZE
; j
++) {
275 if (ref
== (data
->stencilVals
[j
] & valMask
)) {
276 passMask
|= (1 << j
);
280 case PIPE_FUNC_LEQUAL
:
281 for (j
= 0; j
< QUAD_SIZE
; j
++) {
282 if (ref
<= (data
->stencilVals
[j
] & valMask
)) {
283 passMask
|= (1 << j
);
287 case PIPE_FUNC_GREATER
:
288 for (j
= 0; j
< QUAD_SIZE
; j
++) {
289 if (ref
> (data
->stencilVals
[j
] & valMask
)) {
290 passMask
|= (1 << j
);
294 case PIPE_FUNC_NOTEQUAL
:
295 for (j
= 0; j
< QUAD_SIZE
; j
++) {
296 if (ref
!= (data
->stencilVals
[j
] & valMask
)) {
297 passMask
|= (1 << j
);
301 case PIPE_FUNC_GEQUAL
:
302 for (j
= 0; j
< QUAD_SIZE
; j
++) {
303 if (ref
>= (data
->stencilVals
[j
] & valMask
)) {
304 passMask
|= (1 << j
);
308 case PIPE_FUNC_ALWAYS
:
320 * Apply the stencil operator to stencil values.
322 * \param data->stencilVals the stencil buffer values (read and written)
323 * \param mask indicates which pixels to update
324 * \param op the stencil operator (PIPE_STENCIL_OP_x)
325 * \param ref the stencil reference value
326 * \param wrtMask writemask controlling which bits are changed in the
330 apply_stencil_op(struct depth_data
*data
,
331 unsigned mask
, unsigned op
, ubyte ref
, ubyte wrtMask
)
334 ubyte newstencil
[QUAD_SIZE
];
336 for (j
= 0; j
< QUAD_SIZE
; j
++) {
337 newstencil
[j
] = data
->stencilVals
[j
];
341 case PIPE_STENCIL_OP_KEEP
:
344 case PIPE_STENCIL_OP_ZERO
:
345 for (j
= 0; j
< QUAD_SIZE
; j
++) {
346 if (mask
& (1 << j
)) {
351 case PIPE_STENCIL_OP_REPLACE
:
352 for (j
= 0; j
< QUAD_SIZE
; j
++) {
353 if (mask
& (1 << j
)) {
358 case PIPE_STENCIL_OP_INCR
:
359 for (j
= 0; j
< QUAD_SIZE
; j
++) {
360 if (mask
& (1 << j
)) {
361 if (data
->stencilVals
[j
] < STENCIL_MAX
) {
362 newstencil
[j
] = data
->stencilVals
[j
] + 1;
367 case PIPE_STENCIL_OP_DECR
:
368 for (j
= 0; j
< QUAD_SIZE
; j
++) {
369 if (mask
& (1 << j
)) {
370 if (data
->stencilVals
[j
] > 0) {
371 newstencil
[j
] = data
->stencilVals
[j
] - 1;
376 case PIPE_STENCIL_OP_INCR_WRAP
:
377 for (j
= 0; j
< QUAD_SIZE
; j
++) {
378 if (mask
& (1 << j
)) {
379 newstencil
[j
] = data
->stencilVals
[j
] + 1;
383 case PIPE_STENCIL_OP_DECR_WRAP
:
384 for (j
= 0; j
< QUAD_SIZE
; j
++) {
385 if (mask
& (1 << j
)) {
386 newstencil
[j
] = data
->stencilVals
[j
] - 1;
390 case PIPE_STENCIL_OP_INVERT
:
391 for (j
= 0; j
< QUAD_SIZE
; j
++) {
392 if (mask
& (1 << j
)) {
393 newstencil
[j
] = ~data
->stencilVals
[j
];
402 * update the stencil values
404 if (wrtMask
!= STENCIL_MAX
) {
405 /* apply bit-wise stencil buffer writemask */
406 for (j
= 0; j
< QUAD_SIZE
; j
++) {
407 data
->stencilVals
[j
] = (wrtMask
& newstencil
[j
]) | (~wrtMask
& data
->stencilVals
[j
]);
411 for (j
= 0; j
< QUAD_SIZE
; j
++) {
412 data
->stencilVals
[j
] = newstencil
[j
];
420 * To increase efficiency, we should probably have multiple versions
421 * of this function that are specifically for Z16, Z32 and FP Z buffers.
422 * Try to effectively do that with codegen...
425 depth_test_quad(struct quad_stage
*qs
,
426 struct depth_data
*data
,
427 struct quad_header
*quad
)
429 struct softpipe_context
*softpipe
= qs
->softpipe
;
433 switch (softpipe
->depth_stencil
->depth
.func
) {
434 case PIPE_FUNC_NEVER
:
438 /* Note this is pretty much a single sse or cell instruction.
439 * Like this: quad->mask &= (quad->outputs.depth < zzzz);
441 for (j
= 0; j
< QUAD_SIZE
; j
++) {
442 if (data
->qzzzz
[j
] < data
->bzzzz
[j
])
446 case PIPE_FUNC_EQUAL
:
447 for (j
= 0; j
< QUAD_SIZE
; j
++) {
448 if (data
->qzzzz
[j
] == data
->bzzzz
[j
])
452 case PIPE_FUNC_LEQUAL
:
453 for (j
= 0; j
< QUAD_SIZE
; j
++) {
454 if (data
->qzzzz
[j
] <= data
->bzzzz
[j
])
458 case PIPE_FUNC_GREATER
:
459 for (j
= 0; j
< QUAD_SIZE
; j
++) {
460 if (data
->qzzzz
[j
] > data
->bzzzz
[j
])
464 case PIPE_FUNC_NOTEQUAL
:
465 for (j
= 0; j
< QUAD_SIZE
; j
++) {
466 if (data
->qzzzz
[j
] != data
->bzzzz
[j
])
470 case PIPE_FUNC_GEQUAL
:
471 for (j
= 0; j
< QUAD_SIZE
; j
++) {
472 if (data
->qzzzz
[j
] >= data
->bzzzz
[j
])
476 case PIPE_FUNC_ALWAYS
:
483 quad
->inout
.mask
&= zmask
;
484 if (quad
->inout
.mask
== 0)
487 /* Update our internal copy only if writemask set. Even if
488 * depth.writemask is FALSE, may still need to write out buffer
489 * data due to stencil changes.
491 if (softpipe
->depth_stencil
->depth
.writemask
) {
492 for (j
= 0; j
< QUAD_SIZE
; j
++) {
493 if (quad
->inout
.mask
& (1 << j
)) {
494 data
->bzzzz
[j
] = data
->qzzzz
[j
];
505 * Do stencil (and depth) testing. Stenciling depends on the outcome of
509 depth_stencil_test_quad(struct quad_stage
*qs
,
510 struct depth_data
*data
,
511 struct quad_header
*quad
)
513 struct softpipe_context
*softpipe
= qs
->softpipe
;
514 unsigned func
, zFailOp
, zPassOp
, failOp
;
515 ubyte ref
, wrtMask
, valMask
;
516 uint face
= quad
->input
.facing
;
518 if (!softpipe
->depth_stencil
->stencil
[1].enabled
) {
519 /* single-sided stencil test, use front (face=0) state */
523 /* 0 = front-face, 1 = back-face */
524 assert(face
== 0 || face
== 1);
526 /* choose front or back face function, operator, etc */
527 /* XXX we could do these initializations once per primitive */
528 func
= softpipe
->depth_stencil
->stencil
[face
].func
;
529 failOp
= softpipe
->depth_stencil
->stencil
[face
].fail_op
;
530 zFailOp
= softpipe
->depth_stencil
->stencil
[face
].zfail_op
;
531 zPassOp
= softpipe
->depth_stencil
->stencil
[face
].zpass_op
;
532 ref
= softpipe
->stencil_ref
.ref_value
[face
];
533 wrtMask
= softpipe
->depth_stencil
->stencil
[face
].writemask
;
534 valMask
= softpipe
->depth_stencil
->stencil
[face
].valuemask
;
536 /* do the stencil test first */
538 unsigned passMask
, failMask
;
539 passMask
= do_stencil_test(data
, func
, ref
, valMask
);
540 failMask
= quad
->inout
.mask
& ~passMask
;
541 quad
->inout
.mask
&= passMask
;
543 if (failOp
!= PIPE_STENCIL_OP_KEEP
) {
544 apply_stencil_op(data
, failMask
, failOp
, ref
, wrtMask
);
548 if (quad
->inout
.mask
) {
549 /* now the pixels that passed the stencil test are depth tested */
550 if (softpipe
->depth_stencil
->depth
.enabled
) {
551 const unsigned origMask
= quad
->inout
.mask
;
553 depth_test_quad(qs
, data
, quad
); /* quad->mask is updated */
555 /* update stencil buffer values according to z pass/fail result */
556 if (zFailOp
!= PIPE_STENCIL_OP_KEEP
) {
557 const unsigned zFailMask
= origMask
& ~quad
->inout
.mask
;
558 apply_stencil_op(data
, zFailMask
, zFailOp
, ref
, wrtMask
);
561 if (zPassOp
!= PIPE_STENCIL_OP_KEEP
) {
562 const unsigned zPassMask
= origMask
& quad
->inout
.mask
;
563 apply_stencil_op(data
, zPassMask
, zPassOp
, ref
, wrtMask
);
567 /* no depth test, apply Zpass operator to stencil buffer values */
568 apply_stencil_op(data
, quad
->inout
.mask
, zPassOp
, ref
, wrtMask
);
574 #define ALPHATEST( FUNC, COMP ) \
576 alpha_test_quads_##FUNC( struct quad_stage *qs, \
577 struct quad_header *quads[], \
580 const float ref = qs->softpipe->depth_stencil->alpha.ref_value; \
581 const uint cbuf = 0; /* only output[0].alpha is tested */ \
582 unsigned pass_nr = 0; \
585 for (i = 0; i < nr; i++) { \
586 const float *aaaa = quads[i]->output.color[cbuf][3]; \
587 unsigned passMask = 0; \
589 if (aaaa[0] COMP ref) passMask |= (1 << 0); \
590 if (aaaa[1] COMP ref) passMask |= (1 << 1); \
591 if (aaaa[2] COMP ref) passMask |= (1 << 2); \
592 if (aaaa[3] COMP ref) passMask |= (1 << 3); \
594 quads[i]->inout.mask &= passMask; \
596 if (quads[i]->inout.mask) \
597 quads[pass_nr++] = quads[i]; \
605 ALPHATEST( EQUAL
, == )
606 ALPHATEST( LEQUAL
, <= )
607 ALPHATEST( GREATER
, > )
608 ALPHATEST( NOTEQUAL
, != )
609 ALPHATEST( GEQUAL
, >= )
612 /* XXX: Incorporate into shader using KILP.
615 alpha_test_quads(struct quad_stage
*qs
,
616 struct quad_header
*quads
[],
619 switch (qs
->softpipe
->depth_stencil
->alpha
.func
) {
621 return alpha_test_quads_LESS( qs
, quads
, nr
);
622 case PIPE_FUNC_EQUAL
:
623 return alpha_test_quads_EQUAL( qs
, quads
, nr
);
625 case PIPE_FUNC_LEQUAL
:
626 return alpha_test_quads_LEQUAL( qs
, quads
, nr
);
627 case PIPE_FUNC_GREATER
:
628 return alpha_test_quads_GREATER( qs
, quads
, nr
);
629 case PIPE_FUNC_NOTEQUAL
:
630 return alpha_test_quads_NOTEQUAL( qs
, quads
, nr
);
631 case PIPE_FUNC_GEQUAL
:
632 return alpha_test_quads_GEQUAL( qs
, quads
, nr
);
633 case PIPE_FUNC_ALWAYS
:
635 case PIPE_FUNC_NEVER
:
642 static unsigned mask_count
[16] =
664 /** helper to get number of Z buffer bits */
666 get_depth_bits(struct quad_stage
*qs
)
668 struct pipe_surface
*zsurf
= qs
->softpipe
->framebuffer
.zsbuf
;
670 return util_format_get_component_bits(zsurf
->format
,
671 UTIL_FORMAT_COLORSPACE_ZS
, 0);
679 * General depth/stencil test function. Used when there's no fast-path.
682 depth_test_quads_fallback(struct quad_stage
*qs
,
683 struct quad_header
*quads
[],
686 unsigned i
, pass
= 0;
687 const struct sp_fragment_shader
*fs
= qs
->softpipe
->fs
;
688 boolean interp_depth
= !fs
->info
.writes_z
;
689 struct depth_data data
;
692 if (qs
->softpipe
->depth_stencil
->alpha
.enabled
) {
693 nr
= alpha_test_quads(qs
, quads
, nr
);
696 if (get_depth_bits(qs
) > 0 &&
697 (qs
->softpipe
->depth_stencil
->depth
.enabled
||
698 qs
->softpipe
->depth_stencil
->stencil
[0].enabled
)) {
700 data
.ps
= qs
->softpipe
->framebuffer
.zsbuf
;
701 data
.format
= data
.ps
->format
;
702 data
.tile
= sp_get_cached_tile(qs
->softpipe
->zsbuf_cache
,
706 for (i
= 0; i
< nr
; i
++) {
707 get_depth_stencil_values(&data
, quads
[i
]);
709 if (qs
->softpipe
->depth_stencil
->depth
.enabled
) {
711 interpolate_quad_depth(quads
[i
]);
713 convert_quad_depth(&data
, quads
[i
]);
716 if (qs
->softpipe
->depth_stencil
->stencil
[0].enabled
) {
717 depth_stencil_test_quad(qs
, &data
, quads
[i
]);
718 write_depth_stencil_values(&data
, quads
[i
]);
721 if (!depth_test_quad(qs
, &data
, quads
[i
]))
724 if (qs
->softpipe
->depth_stencil
->depth
.writemask
)
725 write_depth_stencil_values(&data
, quads
[i
]);
728 quads
[pass
++] = quads
[i
];
734 if (qs
->softpipe
->active_query_count
) {
735 for (i
= 0; i
< nr
; i
++)
736 qs
->softpipe
->occlusion_count
+= mask_count
[quads
[i
]->inout
.mask
];
740 qs
->next
->run(qs
->next
, quads
, nr
);
745 * Special-case Z testing for 16-bit Zbuffer and Z buffer writes enabled.
748 #define NAME depth_interp_z16_less_write
750 #include "sp_quad_depth_test_tmp.h"
752 #define NAME depth_interp_z16_equal_write
754 #include "sp_quad_depth_test_tmp.h"
756 #define NAME depth_interp_z16_lequal_write
758 #include "sp_quad_depth_test_tmp.h"
760 #define NAME depth_interp_z16_greater_write
762 #include "sp_quad_depth_test_tmp.h"
764 #define NAME depth_interp_z16_notequal_write
766 #include "sp_quad_depth_test_tmp.h"
768 #define NAME depth_interp_z16_gequal_write
770 #include "sp_quad_depth_test_tmp.h"
772 #define NAME depth_interp_z16_always_write
774 #include "sp_quad_depth_test_tmp.h"
779 depth_noop(struct quad_stage
*qs
,
780 struct quad_header
*quads
[],
783 qs
->next
->run(qs
->next
, quads
, nr
);
789 choose_depth_test(struct quad_stage
*qs
,
790 struct quad_header
*quads
[],
793 boolean interp_depth
= !qs
->softpipe
->fs
->info
.writes_z
;
795 boolean alpha
= qs
->softpipe
->depth_stencil
->alpha
.enabled
;
797 boolean depth
= (get_depth_bits(qs
) > 0 &&
798 qs
->softpipe
->depth_stencil
->depth
.enabled
);
800 unsigned depthfunc
= qs
->softpipe
->depth_stencil
->depth
.func
;
802 boolean stencil
= qs
->softpipe
->depth_stencil
->stencil
[0].enabled
;
804 boolean depthwrite
= qs
->softpipe
->depth_stencil
->depth
.writemask
;
806 boolean occlusion
= qs
->softpipe
->active_query_count
;
809 qs
->run
= depth_test_quads_fallback
;
811 /* look for special cases */
815 qs
->run
= depth_noop
;
824 if (qs
->softpipe
->framebuffer
.zsbuf
->format
== PIPE_FORMAT_Z16_UNORM
) {
826 case PIPE_FUNC_NEVER
:
827 qs
->run
= depth_test_quads_fallback
;
830 qs
->run
= depth_interp_z16_less_write
;
832 case PIPE_FUNC_EQUAL
:
833 qs
->run
= depth_interp_z16_equal_write
;
835 case PIPE_FUNC_LEQUAL
:
836 qs
->run
= depth_interp_z16_lequal_write
;
838 case PIPE_FUNC_GREATER
:
839 qs
->run
= depth_interp_z16_greater_write
;
841 case PIPE_FUNC_NOTEQUAL
:
842 qs
->run
= depth_interp_z16_notequal_write
;
844 case PIPE_FUNC_GEQUAL
:
845 qs
->run
= depth_interp_z16_gequal_write
;
847 case PIPE_FUNC_ALWAYS
:
848 qs
->run
= depth_interp_z16_always_write
;
851 qs
->run
= depth_test_quads_fallback
;
857 /* next quad/fragment stage */
858 qs
->run( qs
, quads
, nr
);
864 depth_test_begin(struct quad_stage
*qs
)
866 qs
->run
= choose_depth_test
;
867 qs
->next
->begin(qs
->next
);
872 depth_test_destroy(struct quad_stage
*qs
)
879 sp_quad_depth_test_stage(struct softpipe_context
*softpipe
)
881 struct quad_stage
*stage
= CALLOC_STRUCT(quad_stage
);
883 stage
->softpipe
= softpipe
;
884 stage
->begin
= depth_test_begin
;
885 stage
->run
= choose_depth_test
;
886 stage
->destroy
= depth_test_destroy
;