1 /**************************************************************************
3 * Copyright 2010 VMware, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sub license, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial portions
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
20 * IN NO EVENT SHALL THE AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR
21 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 **************************************************************************/
29 * Template for generating Z test functions
30 * Only PIPE_FORMAT_Z16_UNORM supported at this time.
35 #error "NAME is not defined!"
38 #if !defined(OPERATOR) && !defined(ALWAYS)
39 #error "neither OPERATOR nor ALWAYS is defined!"
44 * NOTE: there's no guarantee that the quads are sequentially side by
45 * side. The fragment shader may have culled some quads, etc. Sliver
46 * triangles may generate non-sequential quads.
49 NAME(struct quad_stage
*qs
,
50 struct quad_header
*quads
[],
54 const unsigned ix
= quads
[0]->input
.x0
;
55 const unsigned iy
= quads
[0]->input
.y0
;
56 const float fx
= (float) ix
;
57 const float fy
= (float) iy
;
58 const float dzdx
= quads
[0]->posCoef
->dadx
[2];
59 const float dzdy
= quads
[0]->posCoef
->dady
[2];
60 const float z0
= quads
[0]->posCoef
->a0
[2] + dzdx
* fx
+ dzdy
* fy
;
61 struct softpipe_cached_tile
*tile
;
62 ushort (*depth16
)[TILE_SIZE
];
63 ushort init_idepth
[4], idepth
[4], depth_step
;
64 const float scale
= 65535.0;
66 /* compute scaled depth of the four pixels in first quad */
67 init_idepth
[0] = (ushort
)((z0
) * scale
);
68 init_idepth
[1] = (ushort
)((z0
+ dzdx
) * scale
);
69 init_idepth
[2] = (ushort
)((z0
+ dzdy
) * scale
);
70 init_idepth
[3] = (ushort
)((z0
+ dzdx
+ dzdy
) * scale
);
72 depth_step
= (ushort
)(dzdx
* scale
);
74 tile
= sp_get_cached_tile(qs
->softpipe
->zsbuf_cache
, ix
, iy
, quads
[0]->input
.layer
);
76 for (i
= 0; i
< nr
; i
++) {
77 const unsigned outmask
= quads
[i
]->inout
.mask
;
78 const int dx
= quads
[i
]->input
.x0
- ix
;
81 /* compute depth for this quad */
82 idepth
[0] = init_idepth
[0] + dx
* depth_step
;
83 idepth
[1] = init_idepth
[1] + dx
* depth_step
;
84 idepth
[2] = init_idepth
[2] + dx
* depth_step
;
85 idepth
[3] = init_idepth
[3] + dx
* depth_step
;
87 depth16
= (ushort (*)[TILE_SIZE
])
88 &tile
->data
.depth16
[iy
% TILE_SIZE
][(ix
+ dx
)% TILE_SIZE
];
92 depth16
[0][0] = idepth
[0];
97 depth16
[0][1] = idepth
[1];
102 depth16
[1][0] = idepth
[2];
107 depth16
[1][1] = idepth
[3];
111 /* Note: OPERATOR appears here: */
112 if ((outmask
& 1) && (idepth
[0] OPERATOR depth16
[0][0])) {
113 depth16
[0][0] = idepth
[0];
117 if ((outmask
& 2) && (idepth
[1] OPERATOR depth16
[0][1])) {
118 depth16
[0][1] = idepth
[1];
122 if ((outmask
& 4) && (idepth
[2] OPERATOR depth16
[1][0])) {
123 depth16
[1][0] = idepth
[2];
127 if ((outmask
& 8) && (idepth
[3] OPERATOR depth16
[1][1])) {
128 depth16
[1][1] = idepth
[3];
133 depth16
= (ushort (*)[TILE_SIZE
]) &depth16
[0][2];
135 quads
[i
]->inout
.mask
= mask
;
136 if (quads
[i
]->inout
.mask
)
137 quads
[pass
++] = quads
[i
];
141 qs
->next
->run(qs
->next
, quads
, pass
);