summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/llvmpipe/lp_rasterizer.c
blob: 089ea5972928210661bc722e3e978b8bb14de76c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157

struct lp_rasterizer {

   /* We can choose whatever layout for the internal tile storage we
    * prefer:
    */
   struct {
      unsigned color[TILESIZE][TILESIZE];
      unsigned depth[TILESIZE][TILESIZE];
      char stencil[TILESIZE][TILESIZE];
   } tile;

      
   unsigned x;
   unsigned y;

   
   struct {
      struct pipe_surface *color;
      struct pipe_surface *zstencil;
      unsigned clear_color;
      unsigned clear_depth;
      char clear_stencil;
   } state;
};

struct lp_rasterizer *lp_rast_create( void )
{
   return CALLOC_STRUCT(lp_rasterizer);
}

void lp_rast_bind_surfaces( struct lp_rasterizer *,
			    struct pipe_surface *color,
			    struct pipe_surface *zstencil,
			    const float *clear_color,
			    double clear_depth,
			    unsigned clear_stencil)
{
   pipe_surface_reference(&rast->state.color, color);
   pipe_surface_reference(&rast->state.depth, depth);
   rast->state.clear_color = util_pack_8888(clear_color);
   rast->state.clear_depth = clear_depth * 0xffffffff;
   rast->state.clear_stencil = clear_stencil;
}

/* Begining of each tile:
 */
void lp_rast_start_tile( struct lp_rasterizer *,
			 unsigned x,
			 unsigned y )
{
   rast->x = x;
   rast->y = y;
}

void lp_rast_clear_color( struct lp_rasterizer *rast )
{
   const unsigned clear_color = rast->state.clear_color;
   unsigned i, j;
   
   for (i = 0; i < TILESIZE; i++)
      for (j = 0; j < TILESIZE; j++)
	 rast->tile[i][j] = clear_color;
}

void lp_rast_clear_depth( struct lp_rasterizer *rast )
{
   const unsigned clear_depth = rast->state.clear_depth;
   unsigned i, j;
   
   for (i = 0; i < TILESIZE; i++)
      for (j = 0; j < TILESIZE; j++)
	 rast->tile[i][j] = clear_depth;
}

void lp_rast_clear_stencil( struct lp_rasterizer *rast )
{
   const unsigned clear_stencil = rast->state.clear_stencil;

   memset(rast->tile.stencil, clear_stencil, sizeof rast->tile.stencil );
}

void lp_rast_load_color( struct lp_rasterizer *rast )
{
   /* call u_tile func to load colors from surface */
}

void lp_rast_load_zstencil( struct lp_rasterizer *rast )
{
   /* call u_tile func to load depth (and stencil?) from surface */
}

/* Within a tile:
 */
void lp_rast_set_state( struct lp_rasterizer *rast,
		       const struct lp_rast_state *state )
{
   rast->shader_state = state;
}

void lp_rast_triangle( struct lp_rasterizer *rast,
		       const struct lp_rast_triangle *inputs )
{
   /* Set up the silly quad coef pointers
    */
   for (i = 0; i < 4; i++) {
      rast->quads[i].posCoef = inputs->posCoef;
      rast->quads[i].coef = inputs->coef;
   }

   /* Scan the tile in 4x4 chunks (?) and figure out which bits to
    * rasterize:
    */

}

void lp_rast_shade_tile( struct lp_rasterizer *rast,
			 const struct lp_rast_shader_inputs *inputs )
{
   /* Set up the silly quad coef pointers
    */
   for (i = 0; i < 4; i++) {
      rast->quads[i].posCoef = inputs->posCoef;
      rast->quads[i].coef = inputs->coef;
   }

   /* Use the existing preference for 8x2 (four quads) shading:
    */
   for (i = 0; i < TILESIZE; i += 8) {
      for (j = 0; j < TILESIZE; j += 2) {
	 rast->shader_state.shade( inputs->jc,
				   rast->x + i,
				   rast->y + j,
				   rast->quads, 4 );
      }
   }
}

/* End of tile:
 */
void lp_rast_store_color( struct lp_rasterizer *rast )
{
   /* call u_tile func to store colors to surface */
}

void lp_rast_store_zstencil( struct lp_rasterizer *rast )
{
   /* call u_tile func to store depth/stencil to surface */
}

/* Shutdown:
 */
void lp_rast_destroy( struct lp_rasterizer *rast )
{
   FREE(rast);
}