1 /**************************************************************************
3 * Copyright 2009 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "util/u_memory.h"
33 #include "lp_rast_priv.h"
34 #include "lp_tile_soa.h"
35 #include "lp_bld_debug.h"
38 struct lp_rasterizer
*lp_rast_create( void )
40 return CALLOC_STRUCT(lp_rasterizer
);
43 void lp_rast_bind_surfaces( struct lp_rasterizer
*rast
,
44 struct pipe_surface
*color
,
45 struct pipe_surface
*zstencil
,
46 const float *clear_color
,
48 unsigned clear_stencil
)
50 pipe_surface_reference(&rast
->state
.color
, color
);
51 pipe_surface_reference(&rast
->state
.depth
, depth
);
55 /* Begining of each tile:
57 void lp_rast_start_tile( struct lp_rasterizer
*,
65 void lp_rast_clear_color( struct lp_rasterizer
*rast
,
66 const union lp_rast_cmd_arg
*arg
)
68 const unsigned clear_color
= arg
->clear
.clear_color
;
71 for (i
= 0; i
< TILESIZE
; i
++)
72 for (j
= 0; j
< TILESIZE
; j
++)
73 rast
->tile
[i
][j
] = clear_color
;
76 void lp_rast_clear_zstencil( struct lp_rasterizer
*rast
,
77 const union lp_rast_cmd_arg
*arg
)
79 const unsigned clear_color
= arg
->clear
.clear_zstencil
;
82 for (i
= 0; i
< TILESIZE
; i
++)
83 for (j
= 0; j
< TILESIZE
; j
++)
84 rast
->tile
[i
][j
] = clear_depth
;
88 void lp_rast_load_color( struct lp_rasterizer
*rast
,
89 const union lp_rast_cmd_arg
*arg
)
91 /* call u_tile func to load colors from surface */
94 void lp_rast_load_zstencil( struct lp_rasterizer
*rast
,
95 const union lp_rast_cmd_arg
*arg
)
97 /* call u_tile func to load depth (and stencil?) from surface */
102 void lp_rast_set_state( struct lp_rasterizer
*rast
,
103 const union lp_rast_cmd_arg
*arg
)
105 rast
->shader_state
= arg
->state
;
110 void lp_rast_shade_tile( struct lp_rasterizer
*rast
,
111 const union lp_rast_cmd_arg
*arg
)
112 const struct lp_rast_shader_inputs
*inputs
)
114 /* Set up the silly quad coef pointers
116 for (i
= 0; i
< 4; i
++) {
117 rast
->quads
[i
].posCoef
= &inputs
->posCoef
;
118 rast
->quads
[i
].coef
= inputs
->coef
;
121 /* Use the existing preference for 8x2 (four quads) shading:
123 for (i
= 0; i
< TILESIZE
; i
+= 8) {
124 for (j
= 0; j
< TILESIZE
; j
+= 2) {
125 rast
->shader_state
.shade( inputs
->jc
,
134 void lp_rast_shade_quads( const struct lp_rast_state
*state
,
135 struct lp_rast_tile
*tile
,
136 struct quad_header
**quads
,
139 struct quad_header
*quad
= quads
[0];
140 const unsigned x
= quad
->input
.x0
;
141 const unsigned y
= quad
->input
.y0
;
144 uint32_t ALIGN16_ATTRIB mask
[4][NUM_CHANNELS
];
149 assert(nr
* QUAD_SIZE
== TILE_VECTOR_HEIGHT
* TILE_VECTOR_WIDTH
);
150 assert(x
% TILE_VECTOR_WIDTH
== 0);
151 assert(y
% TILE_VECTOR_HEIGHT
== 0);
152 for (q
= 0; q
< nr
; ++q
) {
153 assert(quads
[q
]->input
.x0
== x
+ q
*2);
154 assert(quads
[q
]->input
.y0
== y
);
158 for (q
= 0; q
< 4; ++q
)
159 for (chan_index
= 0; chan_index
< NUM_CHANNELS
; ++chan_index
)
160 mask
[q
][chan_index
] = quads
[q
]->inout
.mask
& (1 << chan_index
) ? ~0 : 0;
163 color
= &TILE_PIXEL(tile
->color
, x
, y
, 0);
166 assert((x
% 2) == 0);
167 assert((y
% 2) == 0);
168 depth
= (uint8_t *)tile
->depth
+ y
*TILE_SIZE
*4 + 2*x
*4;
170 /* XXX: This will most likely fail on 32bit x86 without -mstackrealign */
171 assert(lp_check_alignment(mask
, 16));
173 assert(lp_check_alignment(depth
, 16));
174 assert(lp_check_alignment(color
, 16));
175 assert(lp_check_alignment(state
->jc
.blend_color
, 16));
178 state
->shader( &state
->jc
,
192 void lp_rast_end_tile( struct lp_rasterizer
*rast
,
193 boolean write_depth
)
195 /* call u_tile func to store colors to surface */
198 /* call u_tile func to store depth/stencil to surface */
204 void lp_rast_destroy( struct lp_rasterizer
*rast
)