Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5564 serge 1
/**************************************************************************
2
 *
3
 * Copyright 2010 VMware, Inc.  All Rights Reserved.
4
 *
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:
12
 *
13
 * The above copyright notice and this permission notice (including the
14
 * next paragraph) shall be included in all copies or substantial portions
15
 * of the Software.
16
 *
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.
24
 *
25
 **************************************************************************/
26
 
27
 
28
/*
29
 * Template for generating Z test functions
30
 * Only PIPE_FORMAT_Z16_UNORM supported at this time.
31
 */
32
 
33
 
34
#ifndef NAME
35
#error "NAME is not defined!"
36
#endif
37
 
38
#if !defined(OPERATOR) && !defined(ALWAYS)
39
#error "neither OPERATOR nor ALWAYS is defined!"
40
#endif
41
 
42
 
43
/*
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.
47
 */
48
static void
49
NAME(struct quad_stage *qs,
50
     struct quad_header *quads[],
51
     unsigned nr)
52
{
53
   unsigned i, pass = 0;
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;
65
 
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);
71
 
72
   depth_step = (ushort)(dzdx * scale);
73
 
74
   tile = sp_get_cached_tile(qs->softpipe->zsbuf_cache, ix, iy, quads[0]->input.layer);
75
 
76
   for (i = 0; i < nr; i++) {
77
      const unsigned outmask = quads[i]->inout.mask;
78
      const int dx = quads[i]->input.x0 - ix;
79
      unsigned mask = 0;
80
 
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;
86
 
87
      depth16 = (ushort (*)[TILE_SIZE])
88
         &tile->data.depth16[iy % TILE_SIZE][(ix + dx)% TILE_SIZE];
89
 
90
#ifdef ALWAYS
91
      if (outmask & 1) {
92
         depth16[0][0] = idepth[0];
93
         mask |= (1 << 0);
94
      }
95
 
96
      if (outmask & 2) {
97
         depth16[0][1] = idepth[1];
98
         mask |= (1 << 1);
99
      }
100
 
101
      if (outmask & 4) {
102
         depth16[1][0] = idepth[2];
103
         mask |= (1 << 2);
104
      }
105
 
106
      if (outmask & 8) {
107
         depth16[1][1] = idepth[3];
108
         mask |= (1 << 3);
109
      }
110
#else
111
      /* Note: OPERATOR appears here: */
112
      if ((outmask & 1) && (idepth[0] OPERATOR depth16[0][0])) {
113
         depth16[0][0] = idepth[0];
114
         mask |= (1 << 0);
115
      }
116
 
117
      if ((outmask & 2) && (idepth[1] OPERATOR depth16[0][1])) {
118
         depth16[0][1] = idepth[1];
119
         mask |= (1 << 1);
120
      }
121
 
122
      if ((outmask & 4) && (idepth[2] OPERATOR depth16[1][0])) {
123
         depth16[1][0] = idepth[2];
124
         mask |= (1 << 2);
125
      }
126
 
127
      if ((outmask & 8) && (idepth[3] OPERATOR depth16[1][1])) {
128
         depth16[1][1] = idepth[3];
129
         mask |= (1 << 3);
130
      }
131
#endif
132
 
133
      depth16 = (ushort (*)[TILE_SIZE]) &depth16[0][2];
134
 
135
      quads[i]->inout.mask = mask;
136
      if (quads[i]->inout.mask)
137
         quads[pass++] = quads[i];
138
   }
139
 
140
   if (pass)
141
      qs->next->run(qs->next, quads, pass);
142
}
143
 
144
 
145
#undef NAME
146
#undef OPERATOR
147
#undef ALWAYS