r300g: Correct colorbuffer measurements.
[mesa.git] / src / gallium / drivers / r300 / r300_state.c
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 * Copyright 2009 Marek Olšák <maraeo@gmail.com>
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
23
24 #include "draw/draw_context.h"
25
26 #include "util/u_math.h"
27 #include "util/u_memory.h"
28 #include "util/u_pack_color.h"
29
30 #include "tgsi/tgsi_parse.h"
31
32 #include "pipe/p_config.h"
33
34 #include "r300_context.h"
35 #include "r300_reg.h"
36 #include "r300_screen.h"
37 #include "r300_state_inlines.h"
38 #include "r300_fs.h"
39 #include "r300_vs.h"
40
41 /* r300_state: Functions used to intialize state context by translating
42 * Gallium state objects into semi-native r300 state objects. */
43
44 static boolean blend_discard_if_src_alpha_0(unsigned srcRGB, unsigned srcA,
45 unsigned dstRGB, unsigned dstA)
46 {
47 /* If the blend equation is ADD or REVERSE_SUBTRACT,
48 * SRC_ALPHA == 0, and the following state is set, the colorbuffer
49 * will not be changed.
50 * Notice that the dst factors are the src factors inverted. */
51 return (srcRGB == PIPE_BLENDFACTOR_SRC_ALPHA ||
52 srcRGB == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE ||
53 srcRGB == PIPE_BLENDFACTOR_ZERO) &&
54 (srcA == PIPE_BLENDFACTOR_SRC_COLOR ||
55 srcA == PIPE_BLENDFACTOR_SRC_ALPHA ||
56 srcA == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE ||
57 srcA == PIPE_BLENDFACTOR_ZERO) &&
58 (dstRGB == PIPE_BLENDFACTOR_INV_SRC_ALPHA ||
59 dstRGB == PIPE_BLENDFACTOR_ONE) &&
60 (dstA == PIPE_BLENDFACTOR_INV_SRC_COLOR ||
61 dstA == PIPE_BLENDFACTOR_INV_SRC_ALPHA ||
62 dstA == PIPE_BLENDFACTOR_ONE);
63 }
64
65 static boolean blend_discard_if_src_alpha_1(unsigned srcRGB, unsigned srcA,
66 unsigned dstRGB, unsigned dstA)
67 {
68 /* If the blend equation is ADD or REVERSE_SUBTRACT,
69 * SRC_ALPHA == 1, and the following state is set, the colorbuffer
70 * will not be changed.
71 * Notice that the dst factors are the src factors inverted. */
72 return (srcRGB == PIPE_BLENDFACTOR_INV_SRC_ALPHA ||
73 srcRGB == PIPE_BLENDFACTOR_ZERO) &&
74 (srcA == PIPE_BLENDFACTOR_INV_SRC_COLOR ||
75 srcA == PIPE_BLENDFACTOR_INV_SRC_ALPHA ||
76 srcA == PIPE_BLENDFACTOR_ZERO) &&
77 (dstRGB == PIPE_BLENDFACTOR_SRC_ALPHA ||
78 dstRGB == PIPE_BLENDFACTOR_ONE) &&
79 (dstA == PIPE_BLENDFACTOR_SRC_COLOR ||
80 dstA == PIPE_BLENDFACTOR_SRC_ALPHA ||
81 dstA == PIPE_BLENDFACTOR_ONE);
82 }
83
84 static boolean blend_discard_if_src_color_0(unsigned srcRGB, unsigned srcA,
85 unsigned dstRGB, unsigned dstA)
86 {
87 /* If the blend equation is ADD or REVERSE_SUBTRACT,
88 * SRC_COLOR == (0,0,0), and the following state is set, the colorbuffer
89 * will not be changed.
90 * Notice that the dst factors are the src factors inverted. */
91 return (srcRGB == PIPE_BLENDFACTOR_SRC_COLOR ||
92 srcRGB == PIPE_BLENDFACTOR_ZERO) &&
93 (srcA == PIPE_BLENDFACTOR_ZERO) &&
94 (dstRGB == PIPE_BLENDFACTOR_INV_SRC_COLOR ||
95 dstRGB == PIPE_BLENDFACTOR_ONE) &&
96 (dstA == PIPE_BLENDFACTOR_ONE);
97 }
98
99 static boolean blend_discard_if_src_color_1(unsigned srcRGB, unsigned srcA,
100 unsigned dstRGB, unsigned dstA)
101 {
102 /* If the blend equation is ADD or REVERSE_SUBTRACT,
103 * SRC_COLOR == (1,1,1), and the following state is set, the colorbuffer
104 * will not be changed.
105 * Notice that the dst factors are the src factors inverted. */
106 return (srcRGB == PIPE_BLENDFACTOR_INV_SRC_COLOR ||
107 srcRGB == PIPE_BLENDFACTOR_ZERO) &&
108 (srcA == PIPE_BLENDFACTOR_ZERO) &&
109 (dstRGB == PIPE_BLENDFACTOR_SRC_COLOR ||
110 dstRGB == PIPE_BLENDFACTOR_ONE) &&
111 (dstA == PIPE_BLENDFACTOR_ONE);
112 }
113
114 static boolean blend_discard_if_src_alpha_color_0(unsigned srcRGB, unsigned srcA,
115 unsigned dstRGB, unsigned dstA)
116 {
117 /* If the blend equation is ADD or REVERSE_SUBTRACT,
118 * SRC_ALPHA_COLOR == (0,0,0,0), and the following state is set,
119 * the colorbuffer will not be changed.
120 * Notice that the dst factors are the src factors inverted. */
121 return (srcRGB == PIPE_BLENDFACTOR_SRC_COLOR ||
122 srcRGB == PIPE_BLENDFACTOR_SRC_ALPHA ||
123 srcRGB == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE ||
124 srcRGB == PIPE_BLENDFACTOR_ZERO) &&
125 (srcA == PIPE_BLENDFACTOR_SRC_COLOR ||
126 srcA == PIPE_BLENDFACTOR_SRC_ALPHA ||
127 srcA == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE ||
128 srcA == PIPE_BLENDFACTOR_ZERO) &&
129 (dstRGB == PIPE_BLENDFACTOR_INV_SRC_COLOR ||
130 dstRGB == PIPE_BLENDFACTOR_INV_SRC_ALPHA ||
131 dstRGB == PIPE_BLENDFACTOR_ONE) &&
132 (dstA == PIPE_BLENDFACTOR_INV_SRC_COLOR ||
133 dstA == PIPE_BLENDFACTOR_INV_SRC_ALPHA ||
134 dstA == PIPE_BLENDFACTOR_ONE);
135 }
136
137 static boolean blend_discard_if_src_alpha_color_1(unsigned srcRGB, unsigned srcA,
138 unsigned dstRGB, unsigned dstA)
139 {
140 /* If the blend equation is ADD or REVERSE_SUBTRACT,
141 * SRC_ALPHA_COLOR == (1,1,1,1), and the following state is set,
142 * the colorbuffer will not be changed.
143 * Notice that the dst factors are the src factors inverted. */
144 return (srcRGB == PIPE_BLENDFACTOR_INV_SRC_COLOR ||
145 srcRGB == PIPE_BLENDFACTOR_INV_SRC_ALPHA ||
146 srcRGB == PIPE_BLENDFACTOR_ZERO) &&
147 (srcA == PIPE_BLENDFACTOR_INV_SRC_COLOR ||
148 srcA == PIPE_BLENDFACTOR_INV_SRC_ALPHA ||
149 srcA == PIPE_BLENDFACTOR_ZERO) &&
150 (dstRGB == PIPE_BLENDFACTOR_SRC_COLOR ||
151 dstRGB == PIPE_BLENDFACTOR_SRC_ALPHA ||
152 dstRGB == PIPE_BLENDFACTOR_ONE) &&
153 (dstA == PIPE_BLENDFACTOR_SRC_COLOR ||
154 dstA == PIPE_BLENDFACTOR_SRC_ALPHA ||
155 dstA == PIPE_BLENDFACTOR_ONE);
156 }
157
158 static unsigned bgra_cmask(unsigned mask)
159 {
160 /* Gallium uses RGBA color ordering while R300 expects BGRA. */
161
162 return ((mask & PIPE_MASK_R) << 2) |
163 ((mask & PIPE_MASK_B) >> 2) |
164 (mask & (PIPE_MASK_G | PIPE_MASK_A));
165 }
166
167 /* Create a new blend state based on the CSO blend state.
168 *
169 * This encompasses alpha blending, logic/raster ops, and blend dithering. */
170 static void* r300_create_blend_state(struct pipe_context* pipe,
171 const struct pipe_blend_state* state)
172 {
173 struct r300_screen* r300screen = r300_screen(pipe->screen);
174 struct r300_blend_state* blend = CALLOC_STRUCT(r300_blend_state);
175
176 if (state->rt[0].blend_enable)
177 {
178 unsigned eqRGB = state->rt[0].rgb_func;
179 unsigned srcRGB = state->rt[0].rgb_src_factor;
180 unsigned dstRGB = state->rt[0].rgb_dst_factor;
181
182 unsigned eqA = state->rt[0].alpha_func;
183 unsigned srcA = state->rt[0].alpha_src_factor;
184 unsigned dstA = state->rt[0].alpha_dst_factor;
185
186 /* despite the name, ALPHA_BLEND_ENABLE has nothing to do with alpha,
187 * this is just the crappy D3D naming */
188 blend->blend_control = R300_ALPHA_BLEND_ENABLE |
189 r300_translate_blend_function(eqRGB) |
190 ( r300_translate_blend_factor(srcRGB) << R300_SRC_BLEND_SHIFT) |
191 ( r300_translate_blend_factor(dstRGB) << R300_DST_BLEND_SHIFT);
192
193 /* Optimization: some operations do not require the destination color.
194 *
195 * When SRC_ALPHA_SATURATE is used, colorbuffer reads must be enabled,
196 * otherwise blending gives incorrect results. It seems to be
197 * a hardware bug. */
198 if (eqRGB == PIPE_BLEND_MIN || eqA == PIPE_BLEND_MIN ||
199 eqRGB == PIPE_BLEND_MAX || eqA == PIPE_BLEND_MAX ||
200 dstRGB != PIPE_BLENDFACTOR_ZERO ||
201 dstA != PIPE_BLENDFACTOR_ZERO ||
202 srcRGB == PIPE_BLENDFACTOR_DST_COLOR ||
203 srcRGB == PIPE_BLENDFACTOR_DST_ALPHA ||
204 srcRGB == PIPE_BLENDFACTOR_INV_DST_COLOR ||
205 srcRGB == PIPE_BLENDFACTOR_INV_DST_ALPHA ||
206 srcA == PIPE_BLENDFACTOR_DST_COLOR ||
207 srcA == PIPE_BLENDFACTOR_DST_ALPHA ||
208 srcA == PIPE_BLENDFACTOR_INV_DST_COLOR ||
209 srcA == PIPE_BLENDFACTOR_INV_DST_ALPHA ||
210 srcRGB == PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE) {
211 /* Enable reading from the colorbuffer. */
212 blend->blend_control |= R300_READ_ENABLE;
213
214 if (r300_screen(r300_context(pipe)->context.screen)->caps->is_r500) {
215 /* Optimization: Depending on incoming pixels, we can
216 * conditionally disable the reading in hardware... */
217 if (eqRGB != PIPE_BLEND_MIN && eqA != PIPE_BLEND_MIN &&
218 eqRGB != PIPE_BLEND_MAX && eqA != PIPE_BLEND_MAX) {
219 /* Disable reading if SRC_ALPHA == 0. */
220 if ((dstRGB == PIPE_BLENDFACTOR_SRC_ALPHA ||
221 dstRGB == PIPE_BLENDFACTOR_ZERO) &&
222 (dstA == PIPE_BLENDFACTOR_SRC_COLOR ||
223 dstA == PIPE_BLENDFACTOR_SRC_ALPHA ||
224 dstA == PIPE_BLENDFACTOR_ZERO)) {
225 blend->blend_control |= R500_SRC_ALPHA_0_NO_READ;
226 }
227
228 /* Disable reading if SRC_ALPHA == 1. */
229 if ((dstRGB == PIPE_BLENDFACTOR_INV_SRC_ALPHA ||
230 dstRGB == PIPE_BLENDFACTOR_ZERO) &&
231 (dstA == PIPE_BLENDFACTOR_INV_SRC_COLOR ||
232 dstA == PIPE_BLENDFACTOR_INV_SRC_ALPHA ||
233 dstA == PIPE_BLENDFACTOR_ZERO)) {
234 blend->blend_control |= R500_SRC_ALPHA_1_NO_READ;
235 }
236 }
237 }
238 }
239
240 /* Optimization: discard pixels which don't change the colorbuffer.
241 *
242 * The code below is non-trivial and some math is involved.
243 *
244 * Discarding pixels must be disabled when FP16 AA is enabled.
245 * This is a hardware bug. Also, this implementation wouldn't work
246 * with FP blending enabled and equation clamping disabled.
247 *
248 * Equations other than ADD are rarely used and therefore won't be
249 * optimized. */
250 if ((eqRGB == PIPE_BLEND_ADD || eqRGB == PIPE_BLEND_REVERSE_SUBTRACT) &&
251 (eqA == PIPE_BLEND_ADD || eqA == PIPE_BLEND_REVERSE_SUBTRACT)) {
252 /* ADD: X+Y
253 * REVERSE_SUBTRACT: Y-X
254 *
255 * The idea is:
256 * If X = src*srcFactor = 0 and Y = dst*dstFactor = 1,
257 * then CB will not be changed.
258 *
259 * Given the srcFactor and dstFactor variables, we can derive
260 * what src and dst should be equal to and discard appropriate
261 * pixels.
262 */
263 if (blend_discard_if_src_alpha_0(srcRGB, srcA, dstRGB, dstA)) {
264 blend->blend_control |= R300_DISCARD_SRC_PIXELS_SRC_ALPHA_0;
265 } else if (blend_discard_if_src_alpha_1(srcRGB, srcA,
266 dstRGB, dstA)) {
267 blend->blend_control |= R300_DISCARD_SRC_PIXELS_SRC_ALPHA_1;
268 } else if (blend_discard_if_src_color_0(srcRGB, srcA,
269 dstRGB, dstA)) {
270 blend->blend_control |= R300_DISCARD_SRC_PIXELS_SRC_COLOR_0;
271 } else if (blend_discard_if_src_color_1(srcRGB, srcA,
272 dstRGB, dstA)) {
273 blend->blend_control |= R300_DISCARD_SRC_PIXELS_SRC_COLOR_1;
274 } else if (blend_discard_if_src_alpha_color_0(srcRGB, srcA,
275 dstRGB, dstA)) {
276 blend->blend_control |=
277 R300_DISCARD_SRC_PIXELS_SRC_ALPHA_COLOR_0;
278 } else if (blend_discard_if_src_alpha_color_1(srcRGB, srcA,
279 dstRGB, dstA)) {
280 blend->blend_control |=
281 R300_DISCARD_SRC_PIXELS_SRC_ALPHA_COLOR_1;
282 }
283 }
284
285 /* separate alpha */
286 if (srcA != srcRGB || dstA != dstRGB || eqA != eqRGB) {
287 blend->blend_control |= R300_SEPARATE_ALPHA_ENABLE;
288 blend->alpha_blend_control =
289 r300_translate_blend_function(eqA) |
290 (r300_translate_blend_factor(srcA) << R300_SRC_BLEND_SHIFT) |
291 (r300_translate_blend_factor(dstA) << R300_DST_BLEND_SHIFT);
292 }
293 }
294
295 /* PIPE_LOGICOP_* don't need to be translated, fortunately. */
296 if (state->logicop_enable) {
297 blend->rop = R300_RB3D_ROPCNTL_ROP_ENABLE |
298 (state->logicop_func) << R300_RB3D_ROPCNTL_ROP_SHIFT;
299 }
300
301 /* Color channel masks for all MRTs. */
302 blend->color_channel_mask = bgra_cmask(state->rt[0].colormask);
303 if (r300screen->caps->is_r500 && state->independent_blend_enable) {
304 if (state->rt[1].blend_enable) {
305 blend->color_channel_mask |= bgra_cmask(state->rt[1].colormask) << 4;
306 }
307 if (state->rt[2].blend_enable) {
308 blend->color_channel_mask |= bgra_cmask(state->rt[2].colormask) << 8;
309 }
310 if (state->rt[3].blend_enable) {
311 blend->color_channel_mask |= bgra_cmask(state->rt[3].colormask) << 12;
312 }
313 }
314
315 if (state->dither) {
316 blend->dither = R300_RB3D_DITHER_CTL_DITHER_MODE_LUT |
317 R300_RB3D_DITHER_CTL_ALPHA_DITHER_MODE_LUT;
318 }
319
320 return (void*)blend;
321 }
322
323 /* Bind blend state. */
324 static void r300_bind_blend_state(struct pipe_context* pipe,
325 void* state)
326 {
327 struct r300_context* r300 = r300_context(pipe);
328
329 r300->blend_state.state = state;
330 r300->blend_state.dirty = TRUE;
331 }
332
333 /* Free blend state. */
334 static void r300_delete_blend_state(struct pipe_context* pipe,
335 void* state)
336 {
337 FREE(state);
338 }
339
340 /* Convert float to 10bit integer */
341 static unsigned float_to_fixed10(float f)
342 {
343 return CLAMP((unsigned)(f * 1023.9f), 0, 1023);
344 }
345
346 /* Set blend color.
347 * Setup both R300 and R500 registers, figure out later which one to write. */
348 static void r300_set_blend_color(struct pipe_context* pipe,
349 const struct pipe_blend_color* color)
350 {
351 struct r300_context* r300 = r300_context(pipe);
352 struct r300_screen* r300screen = r300_screen(pipe->screen);
353 struct r300_blend_color_state* state =
354 (struct r300_blend_color_state*)r300->blend_color_state.state;
355 union util_color uc;
356
357 util_pack_color(color->color, PIPE_FORMAT_A8R8G8B8_UNORM, &uc);
358 state->blend_color = uc.ui;
359
360 /* XXX if FP16 blending is enabled, we should use the FP16 format */
361 state->blend_color_red_alpha =
362 float_to_fixed10(color->color[0]) |
363 (float_to_fixed10(color->color[3]) << 16);
364 state->blend_color_green_blue =
365 float_to_fixed10(color->color[2]) |
366 (float_to_fixed10(color->color[1]) << 16);
367
368 r300->blend_color_state.size = r300screen->caps->is_r500 ? 3 : 2;
369 r300->blend_color_state.dirty = TRUE;
370 }
371
372 static void r300_set_clip_state(struct pipe_context* pipe,
373 const struct pipe_clip_state* state)
374 {
375 struct r300_context* r300 = r300_context(pipe);
376
377 if (r300_screen(pipe->screen)->caps->has_tcl) {
378 memcpy(r300->clip_state.state, state, sizeof(struct pipe_clip_state));
379 r300->clip_state.size = 29;
380 } else {
381 draw_flush(r300->draw);
382 draw_set_clip_state(r300->draw, state);
383 r300->clip_state.size = 2;
384 }
385
386 r300->clip_state.dirty = TRUE;
387 }
388
389 /* Create a new depth, stencil, and alpha state based on the CSO dsa state.
390 *
391 * This contains the depth buffer, stencil buffer, alpha test, and such.
392 * On the Radeon, depth and stencil buffer setup are intertwined, which is
393 * the reason for some of the strange-looking assignments across registers. */
394 static void*
395 r300_create_dsa_state(struct pipe_context* pipe,
396 const struct pipe_depth_stencil_alpha_state* state)
397 {
398 struct r300_capabilities *caps =
399 r300_screen(r300_context(pipe)->context.screen)->caps;
400 struct r300_dsa_state* dsa = CALLOC_STRUCT(r300_dsa_state);
401
402 /* Depth test setup. */
403 if (state->depth.enabled) {
404 dsa->z_buffer_control |= R300_Z_ENABLE;
405
406 if (state->depth.writemask) {
407 dsa->z_buffer_control |= R300_Z_WRITE_ENABLE;
408 }
409
410 dsa->z_stencil_control |=
411 (r300_translate_depth_stencil_function(state->depth.func) <<
412 R300_Z_FUNC_SHIFT);
413 }
414
415 /* Stencil buffer setup. */
416 if (state->stencil[0].enabled) {
417 dsa->z_buffer_control |= R300_STENCIL_ENABLE;
418 dsa->z_stencil_control |=
419 (r300_translate_depth_stencil_function(state->stencil[0].func) <<
420 R300_S_FRONT_FUNC_SHIFT) |
421 (r300_translate_stencil_op(state->stencil[0].fail_op) <<
422 R300_S_FRONT_SFAIL_OP_SHIFT) |
423 (r300_translate_stencil_op(state->stencil[0].zpass_op) <<
424 R300_S_FRONT_ZPASS_OP_SHIFT) |
425 (r300_translate_stencil_op(state->stencil[0].zfail_op) <<
426 R300_S_FRONT_ZFAIL_OP_SHIFT);
427
428 dsa->stencil_ref_mask = (state->stencil[0].ref_value) |
429 (state->stencil[0].valuemask << R300_STENCILMASK_SHIFT) |
430 (state->stencil[0].writemask << R300_STENCILWRITEMASK_SHIFT);
431
432 if (state->stencil[1].enabled) {
433 dsa->z_buffer_control |= R300_STENCIL_FRONT_BACK;
434 dsa->z_stencil_control |=
435 (r300_translate_depth_stencil_function(state->stencil[1].func) <<
436 R300_S_BACK_FUNC_SHIFT) |
437 (r300_translate_stencil_op(state->stencil[1].fail_op) <<
438 R300_S_BACK_SFAIL_OP_SHIFT) |
439 (r300_translate_stencil_op(state->stencil[1].zpass_op) <<
440 R300_S_BACK_ZPASS_OP_SHIFT) |
441 (r300_translate_stencil_op(state->stencil[1].zfail_op) <<
442 R300_S_BACK_ZFAIL_OP_SHIFT);
443
444 if (caps->is_r500)
445 {
446 dsa->z_buffer_control |= R500_STENCIL_REFMASK_FRONT_BACK;
447 dsa->stencil_ref_bf = (state->stencil[1].ref_value) |
448 (state->stencil[1].valuemask <<
449 R300_STENCILMASK_SHIFT) |
450 (state->stencil[1].writemask <<
451 R300_STENCILWRITEMASK_SHIFT);
452 }
453 }
454 }
455
456 /* Alpha test setup. */
457 if (state->alpha.enabled) {
458 dsa->alpha_function =
459 r300_translate_alpha_function(state->alpha.func) |
460 R300_FG_ALPHA_FUNC_ENABLE;
461
462 /* We could use 10bit alpha ref but who needs that? */
463 dsa->alpha_function |= float_to_ubyte(state->alpha.ref_value);
464
465 if (caps->is_r500)
466 dsa->alpha_function |= R500_FG_ALPHA_FUNC_8BIT;
467 }
468
469 return (void*)dsa;
470 }
471
472 /* Bind DSA state. */
473 static void r300_bind_dsa_state(struct pipe_context* pipe,
474 void* state)
475 {
476 struct r300_context* r300 = r300_context(pipe);
477 struct r300_screen* r300screen = r300_screen(pipe->screen);
478
479 r300->dsa_state.state = state;
480 r300->dsa_state.size = r300screen->caps->is_r500 ? 8 : 6;
481 r300->dsa_state.dirty = TRUE;
482 }
483
484 /* Free DSA state. */
485 static void r300_delete_dsa_state(struct pipe_context* pipe,
486 void* state)
487 {
488 FREE(state);
489 }
490
491 static void
492 r300_set_framebuffer_state(struct pipe_context* pipe,
493 const struct pipe_framebuffer_state* state)
494 {
495 struct r300_context* r300 = r300_context(pipe);
496 struct r300_screen* r300screen = r300_screen(pipe->screen);
497 unsigned max_width, max_height;
498 uint32_t zbuffer_bpp = 0;
499
500 r300->fb_state.size = (10 * state->nr_cbufs) +
501 (2 * (4 - state->nr_cbufs)) +
502 (state->zsbuf ? 10 : 0) + 6;
503
504 if (state->nr_cbufs > 4) {
505 debug_printf("r300: Implementation error: Too many MRTs in %s, "
506 "refusing to bind framebuffer state!\n", __FUNCTION__);
507 return;
508 }
509
510 if (r300screen->caps->is_r500) {
511 max_width = max_height = 4096;
512 } else if (r300screen->caps->is_r400) {
513 max_width = max_height = 4021;
514 } else {
515 max_width = max_height = 2560;
516 }
517
518 if (state->width > max_width || state->height > max_height) {
519 debug_printf("r300: Implementation error: Render targets are too "
520 "big in %s, refusing to bind framebuffer state!\n", __FUNCTION__);
521 return;
522 }
523
524 if (r300->draw) {
525 draw_flush(r300->draw);
526 }
527
528 memcpy(r300->fb_state.state, state, sizeof(struct pipe_framebuffer_state));
529
530 /* Don't rely on the order of states being set for the first time. */
531 /* XXX wait what */
532 r300->blend_state.dirty = TRUE;
533 r300->dsa_state.dirty = TRUE;
534 r300->fb_state.dirty = TRUE;
535 r300->scissor_state.dirty = TRUE;
536
537 /* Polygon offset depends on the zbuffer bit depth. */
538 if (state->zsbuf && r300->polygon_offset_enabled) {
539 switch (util_format_get_blocksize(state->zsbuf->texture->format)) {
540 case 2:
541 zbuffer_bpp = 16;
542 break;
543 case 4:
544 zbuffer_bpp = 24;
545 break;
546 }
547
548 if (r300->zbuffer_bpp != zbuffer_bpp) {
549 r300->zbuffer_bpp = zbuffer_bpp;
550 r300->rs_state.dirty = TRUE;
551 }
552 }
553 }
554
555 /* Create fragment shader state. */
556 static void* r300_create_fs_state(struct pipe_context* pipe,
557 const struct pipe_shader_state* shader)
558 {
559 struct r300_fragment_shader* fs = NULL;
560
561 fs = (struct r300_fragment_shader*)CALLOC_STRUCT(r300_fragment_shader);
562
563 /* Copy state directly into shader. */
564 fs->state = *shader;
565 fs->state.tokens = tgsi_dup_tokens(shader->tokens);
566
567 tgsi_scan_shader(shader->tokens, &fs->info);
568 r300_shader_read_fs_inputs(&fs->info, &fs->inputs);
569
570 return (void*)fs;
571 }
572
573 /* Bind fragment shader state. */
574 static void r300_bind_fs_state(struct pipe_context* pipe, void* shader)
575 {
576 struct r300_context* r300 = r300_context(pipe);
577 struct r300_fragment_shader* fs = (struct r300_fragment_shader*)shader;
578
579 if (fs == NULL) {
580 r300->fs = NULL;
581 return;
582 }
583
584 r300->fs = fs;
585 r300_pick_fragment_shader(r300);
586
587 if (r300->vs && r300_vertex_shader_setup_wpos(r300)) {
588 r300->vertex_format_state.dirty = TRUE;
589 }
590
591 r300->dirty_state |= R300_NEW_FRAGMENT_SHADER | R300_NEW_FRAGMENT_SHADER_CONSTANTS;
592 }
593
594 /* Delete fragment shader state. */
595 static void r300_delete_fs_state(struct pipe_context* pipe, void* shader)
596 {
597 struct r300_fragment_shader* fs = (struct r300_fragment_shader*)shader;
598 struct r300_fragment_shader_code *tmp, *ptr = fs->first;
599
600 while (ptr) {
601 tmp = ptr;
602 ptr = ptr->next;
603 rc_constants_destroy(&tmp->code.constants);
604 FREE(tmp);
605 }
606 FREE((void*)fs->state.tokens);
607 FREE(shader);
608 }
609
610 static void r300_set_polygon_stipple(struct pipe_context* pipe,
611 const struct pipe_poly_stipple* state)
612 {
613 /* XXX no idea how to set this up, but not terribly important */
614 }
615
616 /* Create a new rasterizer state based on the CSO rasterizer state.
617 *
618 * This is a very large chunk of state, and covers most of the graphics
619 * backend (GB), geometry assembly (GA), and setup unit (SU) blocks.
620 *
621 * In a not entirely unironic sidenote, this state has nearly nothing to do
622 * with the actual block on the Radeon called the rasterizer (RS). */
623 static void* r300_create_rs_state(struct pipe_context* pipe,
624 const struct pipe_rasterizer_state* state)
625 {
626 struct r300_screen* r300screen = r300_screen(pipe->screen);
627 struct r300_rs_state* rs = CALLOC_STRUCT(r300_rs_state);
628
629 /* Copy rasterizer state for Draw. */
630 rs->rs = *state;
631
632 #ifdef PIPE_ARCH_LITTLE_ENDIAN
633 rs->vap_control_status = R300_VC_NO_SWAP;
634 #else
635 rs->vap_control_status = R300_VC_32BIT_SWAP;
636 #endif
637
638 /* If bypassing TCL, or if no TCL engine is present, turn off the HW TCL.
639 * Else, enable HW TCL and force Draw's TCL off. */
640 if (state->bypass_vs_clip_and_viewport ||
641 !r300screen->caps->has_tcl) {
642 rs->vap_control_status |= R300_VAP_TCL_BYPASS;
643 }
644
645 rs->point_size = pack_float_16_6x(state->point_size) |
646 (pack_float_16_6x(state->point_size) << R300_POINTSIZE_X_SHIFT);
647
648 /* Point minimum and maximum sizes. This register has to be emitted,
649 * and it'd be a step backwards to put it in invariant state. */
650 if (r300screen->caps->is_r500) {
651 rs->point_minmax =
652 ((int)(0.0 * 6.0) << R300_GA_POINT_MINMAX_MIN_SHIFT) |
653 ((int)(4096.0 * 6.0) << R300_GA_POINT_MINMAX_MAX_SHIFT);
654 } else if (r300screen->caps->is_r500) {
655 rs->point_minmax =
656 ((int)(0.0 * 6.0) << R300_GA_POINT_MINMAX_MIN_SHIFT) |
657 ((int)(4021.0 * 6.0) << R300_GA_POINT_MINMAX_MAX_SHIFT);
658 } else {
659 rs->point_minmax =
660 ((int)(0.0 * 6.0) << R300_GA_POINT_MINMAX_MIN_SHIFT) |
661 ((int)(2560.0 * 6.0) << R300_GA_POINT_MINMAX_MAX_SHIFT);
662 }
663
664 rs->line_control = pack_float_16_6x(state->line_width) |
665 R300_GA_LINE_CNTL_END_TYPE_COMP;
666
667 /* Enable polygon mode */
668 if (state->fill_cw != PIPE_POLYGON_MODE_FILL ||
669 state->fill_ccw != PIPE_POLYGON_MODE_FILL) {
670 rs->polygon_mode = R300_GA_POLY_MODE_DUAL;
671 }
672
673 /* Radeons don't think in "CW/CCW", they think in "front/back". */
674 if (state->front_winding == PIPE_WINDING_CW) {
675 rs->cull_mode = R300_FRONT_FACE_CW;
676
677 /* Polygon offset */
678 if (state->offset_cw) {
679 rs->polygon_offset_enable |= R300_FRONT_ENABLE;
680 }
681 if (state->offset_ccw) {
682 rs->polygon_offset_enable |= R300_BACK_ENABLE;
683 }
684
685 /* Polygon mode */
686 if (rs->polygon_mode) {
687 rs->polygon_mode |=
688 r300_translate_polygon_mode_front(state->fill_cw);
689 rs->polygon_mode |=
690 r300_translate_polygon_mode_back(state->fill_ccw);
691 }
692 } else {
693 rs->cull_mode = R300_FRONT_FACE_CCW;
694
695 /* Polygon offset */
696 if (state->offset_ccw) {
697 rs->polygon_offset_enable |= R300_FRONT_ENABLE;
698 }
699 if (state->offset_cw) {
700 rs->polygon_offset_enable |= R300_BACK_ENABLE;
701 }
702
703 /* Polygon mode */
704 if (rs->polygon_mode) {
705 rs->polygon_mode |=
706 r300_translate_polygon_mode_front(state->fill_ccw);
707 rs->polygon_mode |=
708 r300_translate_polygon_mode_back(state->fill_cw);
709 }
710 }
711 if (state->front_winding & state->cull_mode) {
712 rs->cull_mode |= R300_CULL_FRONT;
713 }
714 if (~(state->front_winding) & state->cull_mode) {
715 rs->cull_mode |= R300_CULL_BACK;
716 }
717
718 if (rs->polygon_offset_enable) {
719 rs->depth_offset = state->offset_units;
720 rs->depth_scale = state->offset_scale;
721 }
722
723 if (state->line_stipple_enable) {
724 rs->line_stipple_config =
725 R300_GA_LINE_STIPPLE_CONFIG_LINE_RESET_LINE |
726 (fui((float)state->line_stipple_factor) &
727 R300_GA_LINE_STIPPLE_CONFIG_STIPPLE_SCALE_MASK);
728 /* XXX this might need to be scaled up */
729 rs->line_stipple_value = state->line_stipple_pattern;
730 }
731
732 if (state->flatshade) {
733 rs->color_control = R300_SHADE_MODEL_FLAT;
734 } else {
735 rs->color_control = R300_SHADE_MODEL_SMOOTH;
736 }
737
738 return (void*)rs;
739 }
740
741 /* Bind rasterizer state. */
742 static void r300_bind_rs_state(struct pipe_context* pipe, void* state)
743 {
744 struct r300_context* r300 = r300_context(pipe);
745 struct r300_rs_state* rs = (struct r300_rs_state*)state;
746
747 if (r300->draw) {
748 draw_flush(r300->draw);
749 draw_set_rasterizer_state(r300->draw, &rs->rs);
750 }
751
752 if (rs) {
753 r300->tcl_bypass = rs->rs.bypass_vs_clip_and_viewport;
754 r300->polygon_offset_enabled = rs->rs.offset_cw || rs->rs.offset_ccw;
755 } else {
756 r300->tcl_bypass = FALSE;
757 r300->polygon_offset_enabled = FALSE;
758 }
759
760 r300->rs_state.state = rs;
761 r300->rs_state.dirty = TRUE;
762 /* XXX Why is this still needed, dammit!? */
763 r300->scissor_state.dirty = TRUE;
764 r300->viewport_state.dirty = TRUE;
765
766 /* XXX Clean these up when we move to atom emits */
767 if (r300->fs && r300->fs->inputs.wpos != ATTR_UNUSED) {
768 r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS;
769 }
770 }
771
772 /* Free rasterizer state. */
773 static void r300_delete_rs_state(struct pipe_context* pipe, void* state)
774 {
775 FREE(state);
776 }
777
778 static void*
779 r300_create_sampler_state(struct pipe_context* pipe,
780 const struct pipe_sampler_state* state)
781 {
782 struct r300_context* r300 = r300_context(pipe);
783 struct r300_sampler_state* sampler = CALLOC_STRUCT(r300_sampler_state);
784 int lod_bias;
785 union util_color uc;
786
787 sampler->state = *state;
788
789 sampler->filter0 |=
790 (r300_translate_wrap(state->wrap_s) << R300_TX_WRAP_S_SHIFT) |
791 (r300_translate_wrap(state->wrap_t) << R300_TX_WRAP_T_SHIFT) |
792 (r300_translate_wrap(state->wrap_r) << R300_TX_WRAP_R_SHIFT);
793
794 sampler->filter0 |= r300_translate_tex_filters(state->min_img_filter,
795 state->mag_img_filter,
796 state->min_mip_filter,
797 state->max_anisotropy > 1.0);
798
799 /* Unfortunately, r300-r500 don't support floating-point mipmap lods. */
800 /* We must pass these to the emit function to clamp them properly. */
801 sampler->min_lod = MAX2((unsigned)state->min_lod, 0);
802 sampler->max_lod = MAX2((unsigned)ceilf(state->max_lod), 0);
803
804 lod_bias = CLAMP((int)(state->lod_bias * 32), -(1 << 9), (1 << 9) - 1);
805
806 sampler->filter1 |= lod_bias << R300_LOD_BIAS_SHIFT;
807
808 sampler->filter1 |= r300_anisotropy(state->max_anisotropy);
809
810 util_pack_color(state->border_color, PIPE_FORMAT_A8R8G8B8_UNORM, &uc);
811 sampler->border_color = uc.ui;
812
813 /* R500-specific fixups and optimizations */
814 if (r300_screen(r300->context.screen)->caps->is_r500) {
815 sampler->filter1 |= R500_BORDER_FIX;
816 }
817
818 return (void*)sampler;
819 }
820
821 static void r300_bind_sampler_states(struct pipe_context* pipe,
822 unsigned count,
823 void** states)
824 {
825 struct r300_context* r300 = r300_context(pipe);
826 int i;
827
828 if (count > 8) {
829 return;
830 }
831
832 for (i = 0; i < count; i++) {
833 if (r300->sampler_states[i] != states[i]) {
834 r300->sampler_states[i] = (struct r300_sampler_state*)states[i];
835 r300->dirty_state |= (R300_NEW_SAMPLER << i);
836 }
837 }
838
839 r300->sampler_count = count;
840
841 /* Pick a fragment shader based on the texture compare state. */
842 if (r300->fs && (r300->dirty_state & R300_ANY_NEW_SAMPLERS)) {
843 if (r300_pick_fragment_shader(r300)) {
844 r300->dirty_state |= R300_NEW_FRAGMENT_SHADER |
845 R300_NEW_FRAGMENT_SHADER_CONSTANTS;
846 }
847 }
848 }
849
850 static void r300_lacks_vertex_textures(struct pipe_context* pipe,
851 unsigned count,
852 void** states)
853 {
854 }
855
856 static void r300_delete_sampler_state(struct pipe_context* pipe, void* state)
857 {
858 FREE(state);
859 }
860
861 static void r300_set_sampler_textures(struct pipe_context* pipe,
862 unsigned count,
863 struct pipe_texture** texture)
864 {
865 struct r300_context* r300 = r300_context(pipe);
866 boolean is_r500 = r300_screen(r300->context.screen)->caps->is_r500;
867 int i;
868
869 /* XXX magic num */
870 if (count > 8) {
871 return;
872 }
873
874 for (i = 0; i < count; i++) {
875 if (r300->textures[i] != (struct r300_texture*)texture[i]) {
876 pipe_texture_reference((struct pipe_texture**)&r300->textures[i],
877 texture[i]);
878 r300->dirty_state |= (R300_NEW_TEXTURE << i);
879
880 /* R300-specific - set the texrect factor in a fragment shader */
881 if (!is_r500 && r300->textures[i]->is_npot) {
882 /* XXX It would be nice to re-emit just 1 constant,
883 * XXX not all of them */
884 r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS;
885 }
886 }
887 }
888
889 for (i = count; i < 8; i++) {
890 if (r300->textures[i]) {
891 pipe_texture_reference((struct pipe_texture**)&r300->textures[i],
892 NULL);
893 r300->dirty_state |= (R300_NEW_TEXTURE << i);
894 }
895 }
896
897 r300->texture_count = count;
898 }
899
900 static void r300_set_scissor_state(struct pipe_context* pipe,
901 const struct pipe_scissor_state* state)
902 {
903 struct r300_context* r300 = r300_context(pipe);
904
905 memcpy(r300->scissor_state.state, state,
906 sizeof(struct pipe_scissor_state));
907
908 r300->scissor_state.dirty = TRUE;
909 }
910
911 static void r300_set_viewport_state(struct pipe_context* pipe,
912 const struct pipe_viewport_state* state)
913 {
914 struct r300_context* r300 = r300_context(pipe);
915 struct r300_viewport_state* viewport =
916 (struct r300_viewport_state*)r300->viewport_state.state;
917
918 /* Do the transform in HW. */
919 viewport->vte_control = R300_VTX_W0_FMT;
920
921 if (state->scale[0] != 1.0f) {
922 viewport->xscale = state->scale[0];
923 viewport->vte_control |= R300_VPORT_X_SCALE_ENA;
924 }
925 if (state->scale[1] != 1.0f) {
926 viewport->yscale = state->scale[1];
927 viewport->vte_control |= R300_VPORT_Y_SCALE_ENA;
928 }
929 if (state->scale[2] != 1.0f) {
930 viewport->zscale = state->scale[2];
931 viewport->vte_control |= R300_VPORT_Z_SCALE_ENA;
932 }
933 if (state->translate[0] != 0.0f) {
934 viewport->xoffset = state->translate[0];
935 viewport->vte_control |= R300_VPORT_X_OFFSET_ENA;
936 }
937 if (state->translate[1] != 0.0f) {
938 viewport->yoffset = state->translate[1];
939 viewport->vte_control |= R300_VPORT_Y_OFFSET_ENA;
940 }
941 if (state->translate[2] != 0.0f) {
942 viewport->zoffset = state->translate[2];
943 viewport->vte_control |= R300_VPORT_Z_OFFSET_ENA;
944 }
945
946 r300->viewport_state.dirty = TRUE;
947 if (r300->fs && r300->fs->inputs.wpos != ATTR_UNUSED) {
948 r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS;
949 }
950 }
951
952 static void r300_set_vertex_buffers(struct pipe_context* pipe,
953 unsigned count,
954 const struct pipe_vertex_buffer* buffers)
955 {
956 struct r300_context* r300 = r300_context(pipe);
957
958 memcpy(r300->vertex_buffer, buffers,
959 sizeof(struct pipe_vertex_buffer) * count);
960 r300->vertex_buffer_count = count;
961
962 if (r300->draw) {
963 draw_flush(r300->draw);
964 draw_set_vertex_buffers(r300->draw, count, buffers);
965 }
966
967 r300->vertex_format_state.dirty = TRUE;
968 }
969
970 static boolean r300_validate_aos(struct r300_context *r300)
971 {
972 struct pipe_vertex_buffer *vbuf = r300->vertex_buffer;
973 struct pipe_vertex_element *velem = r300->vertex_element;
974 int i;
975
976 /* Check if formats and strides are aligned to the size of DWORD. */
977 for (i = 0; i < r300->vertex_element_count; i++) {
978 if (vbuf[velem[i].vertex_buffer_index].stride % 4 != 0 ||
979 util_format_get_blocksize(velem[i].src_format) % 4 != 0) {
980 return FALSE;
981 }
982 }
983 return TRUE;
984 }
985
986 static void r300_set_vertex_elements(struct pipe_context* pipe,
987 unsigned count,
988 const struct pipe_vertex_element* elements)
989 {
990 struct r300_context* r300 = r300_context(pipe);
991
992 memcpy(r300->vertex_element,
993 elements,
994 sizeof(struct pipe_vertex_element) * count);
995 r300->vertex_element_count = count;
996
997 if (r300->draw) {
998 draw_flush(r300->draw);
999 draw_set_vertex_elements(r300->draw, count, elements);
1000 }
1001
1002 if (!r300_validate_aos(r300)) {
1003 /* XXX We should fallback using draw. */
1004 assert(0);
1005 abort();
1006 }
1007 }
1008
1009 static void* r300_create_vs_state(struct pipe_context* pipe,
1010 const struct pipe_shader_state* shader)
1011 {
1012 struct r300_context* r300 = r300_context(pipe);
1013
1014 if (r300_screen(pipe->screen)->caps->has_tcl) {
1015 struct r300_vertex_shader* vs = CALLOC_STRUCT(r300_vertex_shader);
1016 /* Copy state directly into shader. */
1017 vs->state = *shader;
1018 vs->state.tokens = tgsi_dup_tokens(shader->tokens);
1019
1020 tgsi_scan_shader(shader->tokens, &vs->info);
1021
1022 return (void*)vs;
1023 } else {
1024 return draw_create_vertex_shader(r300->draw, shader);
1025 }
1026 }
1027
1028 static void r300_bind_vs_state(struct pipe_context* pipe, void* shader)
1029 {
1030 struct r300_context* r300 = r300_context(pipe);
1031
1032 if (r300_screen(pipe->screen)->caps->has_tcl) {
1033 struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader;
1034
1035 if (vs == NULL) {
1036 r300->vs = NULL;
1037 return;
1038 } else if (!vs->translated) {
1039 r300_translate_vertex_shader(r300, vs);
1040 }
1041
1042 r300->vs = vs;
1043 if (r300->fs) {
1044 r300_vertex_shader_setup_wpos(r300);
1045 }
1046
1047 r300->vertex_format_state.dirty = TRUE;
1048
1049 r300->dirty_state |=
1050 R300_NEW_VERTEX_SHADER | R300_NEW_VERTEX_SHADER_CONSTANTS;
1051 } else {
1052 draw_flush(r300->draw);
1053 draw_bind_vertex_shader(r300->draw,
1054 (struct draw_vertex_shader*)shader);
1055 }
1056 }
1057
1058 static void r300_delete_vs_state(struct pipe_context* pipe, void* shader)
1059 {
1060 struct r300_context* r300 = r300_context(pipe);
1061
1062 if (r300_screen(pipe->screen)->caps->has_tcl) {
1063 struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader;
1064
1065 rc_constants_destroy(&vs->code.constants);
1066 FREE((void*)vs->state.tokens);
1067 FREE(shader);
1068 } else {
1069 draw_delete_vertex_shader(r300->draw,
1070 (struct draw_vertex_shader*)shader);
1071 }
1072 }
1073
1074 static void r300_set_constant_buffer(struct pipe_context *pipe,
1075 uint shader, uint index,
1076 struct pipe_buffer *buf)
1077 {
1078 struct r300_context* r300 = r300_context(pipe);
1079 void *mapped;
1080
1081 if (buf == NULL || buf->size == 0 ||
1082 (mapped = pipe_buffer_map(pipe->screen, buf, PIPE_BUFFER_USAGE_CPU_READ)) == NULL)
1083 {
1084 r300->shader_constants[shader].count = 0;
1085 return;
1086 }
1087
1088 assert((buf->size % 4 * sizeof(float)) == 0);
1089 memcpy(r300->shader_constants[shader].constants, mapped, buf->size);
1090 r300->shader_constants[shader].count = buf->size / (4 * sizeof(float));
1091 pipe_buffer_unmap(pipe->screen, buf);
1092
1093 if (shader == PIPE_SHADER_VERTEX)
1094 r300->dirty_state |= R300_NEW_VERTEX_SHADER_CONSTANTS;
1095 else if (shader == PIPE_SHADER_FRAGMENT)
1096 r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS;
1097 }
1098
1099 void r300_init_state_functions(struct r300_context* r300)
1100 {
1101 r300->context.create_blend_state = r300_create_blend_state;
1102 r300->context.bind_blend_state = r300_bind_blend_state;
1103 r300->context.delete_blend_state = r300_delete_blend_state;
1104
1105 r300->context.set_blend_color = r300_set_blend_color;
1106
1107 r300->context.set_clip_state = r300_set_clip_state;
1108
1109 r300->context.set_constant_buffer = r300_set_constant_buffer;
1110
1111 r300->context.create_depth_stencil_alpha_state = r300_create_dsa_state;
1112 r300->context.bind_depth_stencil_alpha_state = r300_bind_dsa_state;
1113 r300->context.delete_depth_stencil_alpha_state = r300_delete_dsa_state;
1114
1115 r300->context.set_framebuffer_state = r300_set_framebuffer_state;
1116
1117 r300->context.create_fs_state = r300_create_fs_state;
1118 r300->context.bind_fs_state = r300_bind_fs_state;
1119 r300->context.delete_fs_state = r300_delete_fs_state;
1120
1121 r300->context.set_polygon_stipple = r300_set_polygon_stipple;
1122
1123 r300->context.create_rasterizer_state = r300_create_rs_state;
1124 r300->context.bind_rasterizer_state = r300_bind_rs_state;
1125 r300->context.delete_rasterizer_state = r300_delete_rs_state;
1126
1127 r300->context.create_sampler_state = r300_create_sampler_state;
1128 r300->context.bind_fragment_sampler_states = r300_bind_sampler_states;
1129 r300->context.bind_vertex_sampler_states = r300_lacks_vertex_textures;
1130 r300->context.delete_sampler_state = r300_delete_sampler_state;
1131
1132 r300->context.set_fragment_sampler_textures = r300_set_sampler_textures;
1133
1134 r300->context.set_scissor_state = r300_set_scissor_state;
1135
1136 r300->context.set_viewport_state = r300_set_viewport_state;
1137
1138 r300->context.set_vertex_buffers = r300_set_vertex_buffers;
1139 r300->context.set_vertex_elements = r300_set_vertex_elements;
1140
1141 r300->context.create_vs_state = r300_create_vs_state;
1142 r300->context.bind_vs_state = r300_bind_vs_state;
1143 r300->context.delete_vs_state = r300_delete_vs_state;
1144 }