Merge remote branch 'origin/master' into radeon-rewrite
[mesa.git] / src / gallium / drivers / r300 / r300_state.c
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #include "util/u_math.h"
24 #include "util/u_pack_color.h"
25
26 #include "util/u_debug.h"
27 #include "pipe/internal/p_winsys_screen.h"
28
29 #include "r300_context.h"
30 #include "r300_reg.h"
31 #include "r300_state_inlines.h"
32 #include "r300_state_shader.h"
33
34 /* r300_state: Functions used to intialize state context by translating
35 * Gallium state objects into semi-native r300 state objects. */
36
37 /* Create a new blend state based on the CSO blend state.
38 *
39 * This encompasses alpha blending, logic/raster ops, and blend dithering. */
40 static void* r300_create_blend_state(struct pipe_context* pipe,
41 const struct pipe_blend_state* state)
42 {
43 struct r300_blend_state* blend = CALLOC_STRUCT(r300_blend_state);
44
45 if (state->blend_enable) {
46 /* XXX for now, always do separate alpha...
47 * is it faster to do it with one reg? */
48 blend->blend_control = R300_ALPHA_BLEND_ENABLE |
49 R300_SEPARATE_ALPHA_ENABLE |
50 R300_READ_ENABLE |
51 r300_translate_blend_function(state->rgb_func) |
52 (r300_translate_blend_factor(state->rgb_src_factor) <<
53 R300_SRC_BLEND_SHIFT) |
54 (r300_translate_blend_factor(state->rgb_dst_factor) <<
55 R300_DST_BLEND_SHIFT);
56 blend->alpha_blend_control =
57 r300_translate_blend_function(state->alpha_func) |
58 (r300_translate_blend_factor(state->alpha_src_factor) <<
59 R300_SRC_BLEND_SHIFT) |
60 (r300_translate_blend_factor(state->alpha_dst_factor) <<
61 R300_DST_BLEND_SHIFT);
62 }
63
64 /* PIPE_LOGICOP_* don't need to be translated, fortunately. */
65 /* XXX are logicops still allowed if blending's disabled?
66 * Does Gallium take care of it for us? */
67 if (state->logicop_enable) {
68 blend->rop = R300_RB3D_ROPCNTL_ROP_ENABLE |
69 (state->logicop_func) << R300_RB3D_ROPCNTL_ROP_SHIFT;
70 }
71
72 if (state->dither) {
73 blend->dither = R300_RB3D_DITHER_CTL_DITHER_MODE_LUT |
74 R300_RB3D_DITHER_CTL_ALPHA_DITHER_MODE_LUT;
75 }
76
77 return (void*)blend;
78 }
79
80 /* Bind blend state. */
81 static void r300_bind_blend_state(struct pipe_context* pipe,
82 void* state)
83 {
84 struct r300_context* r300 = r300_context(pipe);
85
86 r300->blend_state = (struct r300_blend_state*)state;
87 r300->dirty_state |= R300_NEW_BLEND;
88 }
89
90 /* Free blend state. */
91 static void r300_delete_blend_state(struct pipe_context* pipe,
92 void* state)
93 {
94 FREE(state);
95 }
96
97 /* Set blend color.
98 * Setup both R300 and R500 registers, figure out later which one to write. */
99 static void r300_set_blend_color(struct pipe_context* pipe,
100 const struct pipe_blend_color* color)
101 {
102 struct r300_context* r300 = r300_context(pipe);
103 ubyte ur, ug, ub, ua;
104
105 ur = float_to_ubyte(color->color[0]);
106 ug = float_to_ubyte(color->color[1]);
107 ub = float_to_ubyte(color->color[2]);
108 ua = float_to_ubyte(color->color[3]);
109
110 util_pack_color(color->color, PIPE_FORMAT_A8R8G8B8_UNORM,
111 &r300->blend_color_state->blend_color);
112
113 /* XXX this is wrong */
114 r300->blend_color_state->blend_color_red_alpha = ur | (ua << 16);
115 r300->blend_color_state->blend_color_green_blue = ub | (ug << 16);
116
117 r300->dirty_state |= R300_NEW_BLEND_COLOR;
118 }
119
120 static void r300_set_clip_state(struct pipe_context* pipe,
121 const struct pipe_clip_state* state)
122 {
123 struct r300_context* r300 = r300_context(pipe);
124 /* XXX Draw */
125 draw_flush(r300->draw);
126 draw_set_clip_state(r300->draw, state);
127 }
128
129 static void
130 r300_set_constant_buffer(struct pipe_context* pipe,
131 uint shader, uint index,
132 const struct pipe_constant_buffer* buffer)
133 {
134 struct r300_context* r300 = r300_context(pipe);
135 int i = r300->shader_constants[shader].user_count;
136
137 /* This entire chunk of code seems ever-so-slightly baked.
138 * It's as if I've got pipe_buffer* matryoshkas... */
139 if (buffer && buffer->buffer && buffer->buffer->size) {
140 void* map = pipe->winsys->buffer_map(pipe->winsys, buffer->buffer,
141 PIPE_BUFFER_USAGE_CPU_READ);
142 memcpy(r300->shader_constants[shader].constants,
143 map, buffer->buffer->size);
144 pipe->winsys->buffer_unmap(pipe->winsys, buffer->buffer);
145
146 r300->shader_constants[shader].user_count =
147 buffer->buffer->size / (sizeof(float) * 4);
148 } else {
149 r300->shader_constants[shader].user_count = 0;
150 }
151
152 r300->dirty_state |= R300_NEW_CONSTANTS;
153
154 /* If the number of constants have changed, invalidate the shader. */
155 if (r300->shader_constants[shader].user_count != i) {
156 if (shader == PIPE_SHADER_FRAGMENT && r300->fs) {
157 r300->fs->translated = FALSE;
158 r300_translate_fragment_shader(r300, r300->fs);
159 } else if (shader == PIPE_SHADER_VERTEX && r300->vs) {
160 r300->vs->translated = FALSE;
161 r300_translate_vertex_shader(r300, r300->vs);
162 }
163 }
164 }
165
166 /* Create a new depth, stencil, and alpha state based on the CSO dsa state.
167 *
168 * This contains the depth buffer, stencil buffer, alpha test, and such.
169 * On the Radeon, depth and stencil buffer setup are intertwined, which is
170 * the reason for some of the strange-looking assignments across registers. */
171 static void*
172 r300_create_dsa_state(struct pipe_context* pipe,
173 const struct pipe_depth_stencil_alpha_state* state)
174 {
175 struct r300_dsa_state* dsa = CALLOC_STRUCT(r300_dsa_state);
176
177 /* Depth test setup. */
178 if (state->depth.enabled) {
179 dsa->z_buffer_control |= R300_Z_ENABLE;
180
181 if (state->depth.writemask) {
182 dsa->z_buffer_control |= R300_Z_WRITE_ENABLE;
183 }
184
185 dsa->z_stencil_control |=
186 (r300_translate_depth_stencil_function(state->depth.func) <<
187 R300_Z_FUNC_SHIFT);
188 }
189
190 /* Stencil buffer setup. */
191 if (state->stencil[0].enabled) {
192 dsa->z_buffer_control |= R300_STENCIL_ENABLE;
193 dsa->z_stencil_control |=
194 (r300_translate_depth_stencil_function(state->stencil[0].func) <<
195 R300_S_FRONT_FUNC_SHIFT) |
196 (r300_translate_stencil_op(state->stencil[0].fail_op) <<
197 R300_S_FRONT_SFAIL_OP_SHIFT) |
198 (r300_translate_stencil_op(state->stencil[0].zpass_op) <<
199 R300_S_FRONT_ZPASS_OP_SHIFT) |
200 (r300_translate_stencil_op(state->stencil[0].zfail_op) <<
201 R300_S_FRONT_ZFAIL_OP_SHIFT);
202
203 dsa->stencil_ref_mask = (state->stencil[0].ref_value) |
204 (state->stencil[0].valuemask << R300_STENCILMASK_SHIFT) |
205 (state->stencil[0].writemask << R300_STENCILWRITEMASK_SHIFT);
206
207 if (state->stencil[1].enabled) {
208 dsa->z_buffer_control |= R300_STENCIL_FRONT_BACK;
209 dsa->z_stencil_control |=
210 (r300_translate_depth_stencil_function(state->stencil[1].func) <<
211 R300_S_BACK_FUNC_SHIFT) |
212 (r300_translate_stencil_op(state->stencil[1].fail_op) <<
213 R300_S_BACK_SFAIL_OP_SHIFT) |
214 (r300_translate_stencil_op(state->stencil[1].zpass_op) <<
215 R300_S_BACK_ZPASS_OP_SHIFT) |
216 (r300_translate_stencil_op(state->stencil[1].zfail_op) <<
217 R300_S_BACK_ZFAIL_OP_SHIFT);
218
219 dsa->stencil_ref_bf = (state->stencil[1].ref_value) |
220 (state->stencil[1].valuemask << R300_STENCILMASK_SHIFT) |
221 (state->stencil[1].writemask << R300_STENCILWRITEMASK_SHIFT);
222 }
223 }
224
225 /* Alpha test setup. */
226 if (state->alpha.enabled) {
227 dsa->alpha_function =
228 r300_translate_alpha_function(state->alpha.func) |
229 R300_FG_ALPHA_FUNC_ENABLE;
230 dsa->alpha_reference = CLAMP(state->alpha.ref_value * 1023.0f,
231 0, 1023);
232 } else {
233 dsa->z_buffer_top = R300_ZTOP_ENABLE;
234 }
235
236 return (void*)dsa;
237 }
238
239 /* Bind DSA state. */
240 static void r300_bind_dsa_state(struct pipe_context* pipe,
241 void* state)
242 {
243 struct r300_context* r300 = r300_context(pipe);
244
245 r300->dsa_state = (struct r300_dsa_state*)state;
246 r300->dirty_state |= R300_NEW_DSA;
247 }
248
249 /* Free DSA state. */
250 static void r300_delete_dsa_state(struct pipe_context* pipe,
251 void* state)
252 {
253 FREE(state);
254 }
255
256 static void r300_set_edgeflags(struct pipe_context* pipe,
257 const unsigned* bitfield)
258 {
259 /* XXX you know it's bad when i915 has this blank too */
260 }
261
262 static void
263 r300_set_framebuffer_state(struct pipe_context* pipe,
264 const struct pipe_framebuffer_state* state)
265 {
266 struct r300_context* r300 = r300_context(pipe);
267
268 draw_flush(r300->draw);
269
270 r300->framebuffer_state = *state;
271
272 r300->dirty_state |= R300_NEW_FRAMEBUFFERS;
273 }
274
275 /* Create fragment shader state. */
276 static void* r300_create_fs_state(struct pipe_context* pipe,
277 const struct pipe_shader_state* shader)
278 {
279 struct r300_context* r300 = r300_context(pipe);
280 struct r3xx_fragment_shader* fs = NULL;
281
282 if (r300_screen(r300->context.screen)->caps->is_r500) {
283 fs =
284 (struct r3xx_fragment_shader*)CALLOC_STRUCT(r500_fragment_shader);
285 } else {
286 fs =
287 (struct r3xx_fragment_shader*)CALLOC_STRUCT(r300_fragment_shader);
288 }
289
290 /* Copy state directly into shader. */
291 fs->state = *shader;
292
293 tgsi_scan_shader(shader->tokens, &fs->info);
294
295 return (void*)fs;
296 }
297
298 /* Bind fragment shader state. */
299 static void r300_bind_fs_state(struct pipe_context* pipe, void* shader)
300 {
301 struct r300_context* r300 = r300_context(pipe);
302 struct r3xx_fragment_shader* fs = (struct r3xx_fragment_shader*)shader;
303
304 if (fs == NULL) {
305 r300->fs = NULL;
306 return;
307 } else if (!fs->translated) {
308 r300_translate_fragment_shader(r300, fs);
309 }
310
311 fs->translated = TRUE;
312 r300->fs = fs;
313
314 r300->dirty_state |= R300_NEW_FRAGMENT_SHADER;
315 }
316
317 /* Delete fragment shader state. */
318 static void r300_delete_fs_state(struct pipe_context* pipe, void* shader)
319 {
320 FREE(shader);
321 }
322
323 static void r300_set_polygon_stipple(struct pipe_context* pipe,
324 const struct pipe_poly_stipple* state)
325 {
326 /* XXX */
327 }
328
329 /* Create a new rasterizer state based on the CSO rasterizer state.
330 *
331 * This is a very large chunk of state, and covers most of the graphics
332 * backend (GB), geometry assembly (GA), and setup unit (SU) blocks.
333 *
334 * In a not entirely unironic sidenote, this state has nearly nothing to do
335 * with the actual block on the Radeon called the rasterizer (RS). */
336 static void* r300_create_rs_state(struct pipe_context* pipe,
337 const struct pipe_rasterizer_state* state)
338 {
339 struct r300_rs_state* rs = CALLOC_STRUCT(r300_rs_state);
340
341 /* Copy rasterizer state for Draw. */
342 rs->rs = *state;
343
344 /* If bypassing TCL, or if no TCL engine is present, turn off the HW TCL.
345 * Else, enable HW TCL and force Draw's TCL off. */
346 if (state->bypass_vs_clip_and_viewport ||
347 !r300_screen(pipe->screen)->caps->has_tcl) {
348 rs->vap_control_status = R300_VAP_TCL_BYPASS;
349 } else {
350 rs->rs.bypass_vs_clip_and_viewport = TRUE;
351 rs->vap_control_status = 0;
352 }
353
354 rs->point_size = pack_float_16_6x(state->point_size) |
355 (pack_float_16_6x(state->point_size) << R300_POINTSIZE_X_SHIFT);
356
357 rs->point_minmax =
358 ((int)(state->point_size_min * 6.0) <<
359 R300_GA_POINT_MINMAX_MIN_SHIFT) |
360 ((int)(state->point_size_max * 6.0) <<
361 R300_GA_POINT_MINMAX_MAX_SHIFT);
362
363 rs->line_control = pack_float_16_6x(state->line_width) |
364 R300_GA_LINE_CNTL_END_TYPE_COMP;
365
366 /* Radeons don't think in "CW/CCW", they think in "front/back". */
367 if (state->front_winding == PIPE_WINDING_CW) {
368 rs->cull_mode = R300_FRONT_FACE_CW;
369
370 if (state->offset_cw) {
371 rs->polygon_offset_enable |= R300_FRONT_ENABLE;
372 }
373 if (state->offset_ccw) {
374 rs->polygon_offset_enable |= R300_BACK_ENABLE;
375 }
376 } else {
377 rs->cull_mode = R300_FRONT_FACE_CCW;
378
379 if (state->offset_ccw) {
380 rs->polygon_offset_enable |= R300_FRONT_ENABLE;
381 }
382 if (state->offset_cw) {
383 rs->polygon_offset_enable |= R300_BACK_ENABLE;
384 }
385 }
386 if (state->front_winding & state->cull_mode) {
387 rs->cull_mode |= R300_CULL_FRONT;
388 }
389 if (~(state->front_winding) & state->cull_mode) {
390 rs->cull_mode |= R300_CULL_BACK;
391 }
392
393 if (rs->polygon_offset_enable) {
394 rs->depth_offset_front = rs->depth_offset_back =
395 fui(state->offset_units);
396 rs->depth_scale_front = rs->depth_scale_back =
397 fui(state->offset_scale);
398 }
399
400 if (state->line_stipple_enable) {
401 rs->line_stipple_config =
402 R300_GA_LINE_STIPPLE_CONFIG_LINE_RESET_LINE |
403 (fui((float)state->line_stipple_factor) &
404 R300_GA_LINE_STIPPLE_CONFIG_STIPPLE_SCALE_MASK);
405 /* XXX this might need to be scaled up */
406 rs->line_stipple_value = state->line_stipple_pattern;
407 }
408
409 if (state->flatshade) {
410 rs->color_control = R300_SHADE_MODEL_FLAT;
411 } else {
412 rs->color_control = R300_SHADE_MODEL_SMOOTH;
413 }
414
415 return (void*)rs;
416 }
417
418 /* Bind rasterizer state. */
419 static void r300_bind_rs_state(struct pipe_context* pipe, void* state)
420 {
421 struct r300_context* r300 = r300_context(pipe);
422 struct r300_rs_state* rs = (struct r300_rs_state*)state;
423
424 draw_set_rasterizer_state(r300->draw, &rs->rs);
425
426 r300->rs_state = rs;
427 r300->dirty_state |= R300_NEW_RASTERIZER;
428 }
429
430 /* Free rasterizer state. */
431 static void r300_delete_rs_state(struct pipe_context* pipe, void* state)
432 {
433 FREE(state);
434 }
435
436 static void*
437 r300_create_sampler_state(struct pipe_context* pipe,
438 const struct pipe_sampler_state* state)
439 {
440 struct r300_context* r300 = r300_context(pipe);
441 struct r300_sampler_state* sampler = CALLOC_STRUCT(r300_sampler_state);
442 int lod_bias;
443
444 sampler->filter0 |=
445 (r300_translate_wrap(state->wrap_s) << R300_TX_WRAP_S_SHIFT) |
446 (r300_translate_wrap(state->wrap_t) << R300_TX_WRAP_T_SHIFT) |
447 (r300_translate_wrap(state->wrap_r) << R300_TX_WRAP_R_SHIFT);
448
449 sampler->filter0 |= r300_translate_tex_filters(state->min_img_filter,
450 state->mag_img_filter,
451 state->min_mip_filter);
452
453 lod_bias = CLAMP((int)(state->lod_bias * 32), -(1 << 9), (1 << 9) - 1);
454
455 sampler->filter1 |= lod_bias << R300_LOD_BIAS_SHIFT;
456
457 sampler->filter1 |= r300_anisotropy(state->max_anisotropy);
458
459 util_pack_color(state->border_color, PIPE_FORMAT_A8R8G8B8_UNORM,
460 &sampler->border_color);
461
462 /* R500-specific fixups and optimizations */
463 if (r300_screen(r300->context.screen)->caps->is_r500) {
464 sampler->filter1 |= R500_BORDER_FIX;
465 }
466
467 return (void*)sampler;
468 }
469
470 static void r300_bind_sampler_states(struct pipe_context* pipe,
471 unsigned count,
472 void** states)
473 {
474 struct r300_context* r300 = r300_context(pipe);
475 int i;
476
477 if (count > 8) {
478 return;
479 }
480
481 for (i = 0; i < count; i++) {
482 if (r300->sampler_states[i] != states[i]) {
483 r300->sampler_states[i] = (struct r300_sampler_state*)states[i];
484 r300->dirty_state |= (R300_NEW_SAMPLER << i);
485 }
486 }
487
488 r300->sampler_count = count;
489 }
490
491 static void r300_delete_sampler_state(struct pipe_context* pipe, void* state)
492 {
493 FREE(state);
494 }
495
496 static void r300_set_sampler_textures(struct pipe_context* pipe,
497 unsigned count,
498 struct pipe_texture** texture)
499 {
500 struct r300_context* r300 = r300_context(pipe);
501 int i;
502
503 /* XXX magic num */
504 if (count > 8) {
505 return;
506 }
507
508 for (i = 0; i < count; i++) {
509 if (r300->textures[i] != (struct r300_texture*)texture[i]) {
510 pipe_texture_reference((struct pipe_texture**)&r300->textures[i],
511 texture[i]);
512 r300->dirty_state |= (R300_NEW_TEXTURE << i);
513 }
514 }
515
516 for (i = count; i < 8; i++) {
517 if (r300->textures[i]) {
518 pipe_texture_reference((struct pipe_texture**)&r300->textures[i],
519 NULL);
520 r300->dirty_state |= (R300_NEW_TEXTURE << i);
521 }
522 }
523
524 r300->texture_count = count;
525 }
526
527 static void r300_set_scissor_state(struct pipe_context* pipe,
528 const struct pipe_scissor_state* state)
529 {
530 struct r300_context* r300 = r300_context(pipe);
531 draw_flush(r300->draw);
532
533 if (r300_screen(r300->context.screen)->caps->is_r500) {
534 r300->scissor_state->scissor_top_left =
535 (state->minx << R300_SCISSORS_X_SHIFT) |
536 (state->miny << R300_SCISSORS_Y_SHIFT);
537 r300->scissor_state->scissor_bottom_right =
538 (state->maxx << R300_SCISSORS_X_SHIFT) |
539 (state->maxy << R300_SCISSORS_Y_SHIFT);
540 } else {
541 /* Offset of 1440 in non-R500 chipsets. */
542 r300->scissor_state->scissor_top_left =
543 ((state->minx + 1440) << R300_SCISSORS_X_SHIFT) |
544 ((state->miny + 1440) << R300_SCISSORS_Y_SHIFT);
545 r300->scissor_state->scissor_bottom_right =
546 ((state->maxx + 1440) << R300_SCISSORS_X_SHIFT) |
547 ((state->maxy + 1440) << R300_SCISSORS_Y_SHIFT);
548 }
549
550 r300->dirty_state |= R300_NEW_SCISSOR;
551 }
552
553 static void r300_set_viewport_state(struct pipe_context* pipe,
554 const struct pipe_viewport_state* state)
555 {
556 struct r300_context* r300 = r300_context(pipe);
557
558 r300->viewport_state->xscale = state->scale[0];
559 r300->viewport_state->yscale = state->scale[1];
560 r300->viewport_state->zscale = state->scale[2];
561
562 r300->viewport_state->xoffset = state->translate[0];
563 r300->viewport_state->yoffset = state->translate[1];
564 r300->viewport_state->zoffset = state->translate[2];
565
566 r300->viewport_state->vte_control = 0;
567 if (r300_screen(r300->context.screen)->caps->has_tcl) {
568 /* Do the transform in HW. */
569 r300->viewport_state->vte_control |=
570 R300_VPORT_X_SCALE_ENA | R300_VPORT_X_OFFSET_ENA |
571 R300_VPORT_Y_SCALE_ENA | R300_VPORT_Y_OFFSET_ENA |
572 R300_VPORT_Z_SCALE_ENA | R300_VPORT_Z_OFFSET_ENA;
573 } else {
574 /* Have Draw do the actual transform. */
575 draw_set_viewport_state(r300->draw, state);
576 }
577 }
578
579 static void r300_set_vertex_buffers(struct pipe_context* pipe,
580 unsigned count,
581 const struct pipe_vertex_buffer* buffers)
582 {
583 struct r300_context* r300 = r300_context(pipe);
584
585 memcpy(r300->vertex_buffers, buffers,
586 sizeof(struct pipe_vertex_buffer) * count);
587
588 r300->vertex_buffer_count = count;
589
590 draw_flush(r300->draw);
591 draw_set_vertex_buffers(r300->draw, count, buffers);
592 }
593
594 static void r300_set_vertex_elements(struct pipe_context* pipe,
595 unsigned count,
596 const struct pipe_vertex_element* elements)
597 {
598 struct r300_context* r300 = r300_context(pipe);
599
600 draw_flush(r300->draw);
601 draw_set_vertex_elements(r300->draw, count, elements);
602 }
603
604 static void* r300_create_vs_state(struct pipe_context* pipe,
605 const struct pipe_shader_state* shader)
606 {
607 struct r300_context* r300 = r300_context(pipe);
608
609 if (r300_screen(pipe->screen)->caps->has_tcl) {
610 struct r300_vertex_shader* vs = CALLOC_STRUCT(r300_vertex_shader);
611 /* Copy state directly into shader. */
612 vs->state = *shader;
613
614 tgsi_scan_shader(shader->tokens, &vs->info);
615
616 /* Appease Draw. */
617 vs->draw = draw_create_vertex_shader(r300->draw, shader);
618
619 return (void*)vs;
620 } else {
621 return draw_create_vertex_shader(r300->draw, shader);
622 }
623 }
624
625 static void r300_bind_vs_state(struct pipe_context* pipe, void* shader)
626 {
627 struct r300_context* r300 = r300_context(pipe);
628
629 if (r300_screen(pipe->screen)->caps->has_tcl) {
630 struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader;
631
632 if (vs == NULL) {
633 r300->vs = NULL;
634 return;
635 } else if (!vs->translated) {
636 r300_translate_vertex_shader(r300, vs);
637 }
638
639 draw_bind_vertex_shader(r300->draw, vs->draw);
640 r300->vs = vs;
641 r300->dirty_state |= R300_NEW_VERTEX_SHADER;
642 } else {
643 draw_bind_vertex_shader(r300->draw,
644 (struct draw_vertex_shader*)shader);
645 }
646 }
647
648 static void r300_delete_vs_state(struct pipe_context* pipe, void* shader)
649 {
650 struct r300_context* r300 = r300_context(pipe);
651
652 if (r300_screen(pipe->screen)->caps->has_tcl) {
653 struct r300_vertex_shader* vs = (struct r300_vertex_shader*)shader;
654
655 draw_delete_vertex_shader(r300->draw, vs->draw);
656 FREE(shader);
657 } else {
658 draw_delete_vertex_shader(r300->draw,
659 (struct draw_vertex_shader*)shader);
660 }
661 }
662
663 void r300_init_state_functions(struct r300_context* r300)
664 {
665 r300->context.create_blend_state = r300_create_blend_state;
666 r300->context.bind_blend_state = r300_bind_blend_state;
667 r300->context.delete_blend_state = r300_delete_blend_state;
668
669 r300->context.set_blend_color = r300_set_blend_color;
670
671 r300->context.set_clip_state = r300_set_clip_state;
672
673 r300->context.set_constant_buffer = r300_set_constant_buffer;
674
675 r300->context.create_depth_stencil_alpha_state = r300_create_dsa_state;
676 r300->context.bind_depth_stencil_alpha_state = r300_bind_dsa_state;
677 r300->context.delete_depth_stencil_alpha_state = r300_delete_dsa_state;
678
679 r300->context.set_edgeflags = r300_set_edgeflags;
680
681 r300->context.set_framebuffer_state = r300_set_framebuffer_state;
682
683 r300->context.create_fs_state = r300_create_fs_state;
684 r300->context.bind_fs_state = r300_bind_fs_state;
685 r300->context.delete_fs_state = r300_delete_fs_state;
686
687 r300->context.set_polygon_stipple = r300_set_polygon_stipple;
688
689 r300->context.create_rasterizer_state = r300_create_rs_state;
690 r300->context.bind_rasterizer_state = r300_bind_rs_state;
691 r300->context.delete_rasterizer_state = r300_delete_rs_state;
692
693 r300->context.create_sampler_state = r300_create_sampler_state;
694 r300->context.bind_sampler_states = r300_bind_sampler_states;
695 r300->context.delete_sampler_state = r300_delete_sampler_state;
696
697 r300->context.set_sampler_textures = r300_set_sampler_textures;
698
699 r300->context.set_scissor_state = r300_set_scissor_state;
700
701 r300->context.set_viewport_state = r300_set_viewport_state;
702
703 r300->context.set_vertex_buffers = r300_set_vertex_buffers;
704 r300->context.set_vertex_elements = r300_set_vertex_elements;
705
706 r300->context.create_vs_state = r300_create_vs_state;
707 r300->context.bind_vs_state = r300_bind_vs_state;
708 r300->context.delete_vs_state = r300_delete_vs_state;
709 }