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_Z24S8_UNORM
:
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_S8Z24_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_Z24S8_UNORM
:
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_S8Z24_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_Z24S8_UNORM
:
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_S8Z24_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 /* choose front or back face function, operator, etc */
524 /* XXX we could do these initializations once per primitive */
525 func
= softpipe
->depth_stencil
->stencil
[face
].func
;
526 failOp
= softpipe
->depth_stencil
->stencil
[face
].fail_op
;
527 zFailOp
= softpipe
->depth_stencil
->stencil
[face
].zfail_op
;
528 zPassOp
= softpipe
->depth_stencil
->stencil
[face
].zpass_op
;
529 ref
= softpipe
->stencil_ref
.ref_value
[face
];
530 wrtMask
= softpipe
->depth_stencil
->stencil
[face
].writemask
;
531 valMask
= softpipe
->depth_stencil
->stencil
[face
].valuemask
;
533 /* do the stencil test first */
535 unsigned passMask
, failMask
;
536 passMask
= do_stencil_test(data
, func
, ref
, valMask
);
537 failMask
= quad
->inout
.mask
& ~passMask
;
538 quad
->inout
.mask
&= passMask
;
540 if (failOp
!= PIPE_STENCIL_OP_KEEP
) {
541 apply_stencil_op(data
, failMask
, failOp
, ref
, wrtMask
);
545 if (quad
->inout
.mask
) {
546 /* now the pixels that passed the stencil test are depth tested */
547 if (softpipe
->depth_stencil
->depth
.enabled
) {
548 const unsigned origMask
= quad
->inout
.mask
;
550 depth_test_quad(qs
, data
, quad
); /* quad->mask is updated */
552 /* update stencil buffer values according to z pass/fail result */
553 if (zFailOp
!= PIPE_STENCIL_OP_KEEP
) {
554 const unsigned zFailMask
= origMask
& ~quad
->inout
.mask
;
555 apply_stencil_op(data
, zFailMask
, zFailOp
, ref
, wrtMask
);
558 if (zPassOp
!= PIPE_STENCIL_OP_KEEP
) {
559 const unsigned zPassMask
= origMask
& quad
->inout
.mask
;
560 apply_stencil_op(data
, zPassMask
, zPassOp
, ref
, wrtMask
);
564 /* no depth test, apply Zpass operator to stencil buffer values */
565 apply_stencil_op(data
, quad
->inout
.mask
, zPassOp
, ref
, wrtMask
);
571 #define ALPHATEST( FUNC, COMP ) \
573 alpha_test_quads_##FUNC( struct quad_stage *qs, \
574 struct quad_header *quads[], \
577 const float ref = qs->softpipe->depth_stencil->alpha.ref_value; \
578 const uint cbuf = 0; /* only output[0].alpha is tested */ \
579 unsigned pass_nr = 0; \
582 for (i = 0; i < nr; i++) { \
583 const float *aaaa = quads[i]->output.color[cbuf][3]; \
584 unsigned passMask = 0; \
586 if (aaaa[0] COMP ref) passMask |= (1 << 0); \
587 if (aaaa[1] COMP ref) passMask |= (1 << 1); \
588 if (aaaa[2] COMP ref) passMask |= (1 << 2); \
589 if (aaaa[3] COMP ref) passMask |= (1 << 3); \
591 quads[i]->inout.mask &= passMask; \
593 if (quads[i]->inout.mask) \
594 quads[pass_nr++] = quads[i]; \
602 ALPHATEST( EQUAL
, == )
603 ALPHATEST( LEQUAL
, <= )
604 ALPHATEST( GREATER
, > )
605 ALPHATEST( NOTEQUAL
, != )
606 ALPHATEST( GEQUAL
, >= )
609 /* XXX: Incorporate into shader using KILP.
612 alpha_test_quads(struct quad_stage
*qs
,
613 struct quad_header
*quads
[],
616 switch (qs
->softpipe
->depth_stencil
->alpha
.func
) {
618 return alpha_test_quads_LESS( qs
, quads
, nr
);
619 case PIPE_FUNC_EQUAL
:
620 return alpha_test_quads_EQUAL( qs
, quads
, nr
);
622 case PIPE_FUNC_LEQUAL
:
623 return alpha_test_quads_LEQUAL( qs
, quads
, nr
);
624 case PIPE_FUNC_GREATER
:
625 return alpha_test_quads_GREATER( qs
, quads
, nr
);
626 case PIPE_FUNC_NOTEQUAL
:
627 return alpha_test_quads_NOTEQUAL( qs
, quads
, nr
);
628 case PIPE_FUNC_GEQUAL
:
629 return alpha_test_quads_GEQUAL( qs
, quads
, nr
);
630 case PIPE_FUNC_ALWAYS
:
632 case PIPE_FUNC_NEVER
:
639 static unsigned mask_count
[16] =
661 /** helper to get number of Z buffer bits */
663 get_depth_bits(struct quad_stage
*qs
)
665 struct pipe_surface
*zsurf
= qs
->softpipe
->framebuffer
.zsbuf
;
667 return util_format_get_component_bits(zsurf
->format
,
668 UTIL_FORMAT_COLORSPACE_ZS
, 0);
676 * General depth/stencil test function. Used when there's no fast-path.
679 depth_test_quads_fallback(struct quad_stage
*qs
,
680 struct quad_header
*quads
[],
683 unsigned i
, pass
= 0;
684 const struct sp_fragment_shader
*fs
= qs
->softpipe
->fs
;
685 boolean interp_depth
= !fs
->info
.writes_z
;
686 struct depth_data data
;
689 if (qs
->softpipe
->depth_stencil
->alpha
.enabled
) {
690 nr
= alpha_test_quads(qs
, quads
, nr
);
693 if (get_depth_bits(qs
) > 0 &&
694 (qs
->softpipe
->depth_stencil
->depth
.enabled
||
695 qs
->softpipe
->depth_stencil
->stencil
[0].enabled
)) {
697 data
.ps
= qs
->softpipe
->framebuffer
.zsbuf
;
698 data
.format
= data
.ps
->format
;
699 data
.tile
= sp_get_cached_tile(qs
->softpipe
->zsbuf_cache
,
703 for (i
= 0; i
< nr
; i
++) {
704 get_depth_stencil_values(&data
, quads
[i
]);
706 if (qs
->softpipe
->depth_stencil
->depth
.enabled
) {
708 interpolate_quad_depth(quads
[i
]);
710 convert_quad_depth(&data
, quads
[i
]);
713 if (qs
->softpipe
->depth_stencil
->stencil
[0].enabled
) {
714 depth_stencil_test_quad(qs
, &data
, quads
[i
]);
715 write_depth_stencil_values(&data
, quads
[i
]);
718 if (!depth_test_quad(qs
, &data
, quads
[i
]))
721 if (qs
->softpipe
->depth_stencil
->depth
.writemask
)
722 write_depth_stencil_values(&data
, quads
[i
]);
725 quads
[pass
++] = quads
[i
];
731 if (qs
->softpipe
->active_query_count
) {
732 for (i
= 0; i
< nr
; i
++)
733 qs
->softpipe
->occlusion_count
+= mask_count
[quads
[i
]->inout
.mask
];
737 qs
->next
->run(qs
->next
, quads
, nr
);
742 * Special-case Z testing for 16-bit Zbuffer and Z buffer writes enabled.
745 #define NAME depth_interp_z16_less_write
747 #include "sp_quad_depth_test_tmp.h"
749 #define NAME depth_interp_z16_equal_write
751 #include "sp_quad_depth_test_tmp.h"
753 #define NAME depth_interp_z16_lequal_write
755 #include "sp_quad_depth_test_tmp.h"
757 #define NAME depth_interp_z16_greater_write
759 #include "sp_quad_depth_test_tmp.h"
761 #define NAME depth_interp_z16_notequal_write
763 #include "sp_quad_depth_test_tmp.h"
765 #define NAME depth_interp_z16_gequal_write
767 #include "sp_quad_depth_test_tmp.h"
769 #define NAME depth_interp_z16_always_write
771 #include "sp_quad_depth_test_tmp.h"
776 depth_noop(struct quad_stage
*qs
,
777 struct quad_header
*quads
[],
780 qs
->next
->run(qs
->next
, quads
, nr
);
786 choose_depth_test(struct quad_stage
*qs
,
787 struct quad_header
*quads
[],
790 boolean interp_depth
= !qs
->softpipe
->fs
->info
.writes_z
;
792 boolean alpha
= qs
->softpipe
->depth_stencil
->alpha
.enabled
;
794 boolean depth
= (get_depth_bits(qs
) > 0 &&
795 qs
->softpipe
->depth_stencil
->depth
.enabled
);
797 unsigned depthfunc
= qs
->softpipe
->depth_stencil
->depth
.func
;
799 boolean stencil
= qs
->softpipe
->depth_stencil
->stencil
[0].enabled
;
801 boolean depthwrite
= qs
->softpipe
->depth_stencil
->depth
.writemask
;
803 boolean occlusion
= qs
->softpipe
->active_query_count
;
806 qs
->run
= depth_test_quads_fallback
;
808 /* look for special cases */
812 qs
->run
= depth_noop
;
821 if (qs
->softpipe
->framebuffer
.zsbuf
->format
== PIPE_FORMAT_Z16_UNORM
) {
823 case PIPE_FUNC_NEVER
:
824 qs
->run
= depth_test_quads_fallback
;
827 qs
->run
= depth_interp_z16_less_write
;
829 case PIPE_FUNC_EQUAL
:
830 qs
->run
= depth_interp_z16_equal_write
;
832 case PIPE_FUNC_LEQUAL
:
833 qs
->run
= depth_interp_z16_lequal_write
;
835 case PIPE_FUNC_GREATER
:
836 qs
->run
= depth_interp_z16_greater_write
;
838 case PIPE_FUNC_NOTEQUAL
:
839 qs
->run
= depth_interp_z16_notequal_write
;
841 case PIPE_FUNC_GEQUAL
:
842 qs
->run
= depth_interp_z16_gequal_write
;
844 case PIPE_FUNC_ALWAYS
:
845 qs
->run
= depth_interp_z16_always_write
;
848 qs
->run
= depth_test_quads_fallback
;
854 /* next quad/fragment stage */
855 qs
->run( qs
, quads
, nr
);
861 depth_test_begin(struct quad_stage
*qs
)
863 qs
->run
= choose_depth_test
;
864 qs
->next
->begin(qs
->next
);
869 depth_test_destroy(struct quad_stage
*qs
)
876 sp_quad_depth_test_stage(struct softpipe_context
*softpipe
)
878 struct quad_stage
*stage
= CALLOC_STRUCT(quad_stage
);
880 stage
->softpipe
= softpipe
;
881 stage
->begin
= depth_test_begin
;
882 stage
->run
= choose_depth_test
;
883 stage
->destroy
= depth_test_destroy
;