2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
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:
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
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.
28 #include "util/u_inlines.h"
29 #include "util/u_format.h"
30 #include "util/u_memory.h"
31 #include "r600_screen.h"
32 #include "r600_context.h"
33 #include "r600_resource.h"
35 #include "r600_state_inlines.h"
37 static void *r600_create_blend_state(struct pipe_context
*ctx
,
38 const struct pipe_blend_state
*state
)
40 struct r600_context
*rctx
= r600_context(ctx
);
42 return r600_context_state(rctx
, pipe_blend_type
, state
);
45 static void *r600_create_dsa_state(struct pipe_context
*ctx
,
46 const struct pipe_depth_stencil_alpha_state
*state
)
48 struct r600_context
*rctx
= r600_context(ctx
);
50 return r600_context_state(rctx
, pipe_dsa_type
, state
);
53 static void *r600_create_rs_state(struct pipe_context
*ctx
,
54 const struct pipe_rasterizer_state
*state
)
56 struct r600_context
*rctx
= r600_context(ctx
);
58 return r600_context_state(rctx
, pipe_rasterizer_type
, state
);
61 static void *r600_create_sampler_state(struct pipe_context
*ctx
,
62 const struct pipe_sampler_state
*state
)
64 struct r600_context
*rctx
= r600_context(ctx
);
66 return r600_context_state(rctx
, pipe_sampler_type
, state
);
69 static void r600_sampler_view_destroy(struct pipe_context
*ctx
,
70 struct pipe_sampler_view
*state
)
72 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
74 r600_context_state_decref(rstate
);
77 static struct pipe_sampler_view
*r600_create_sampler_view(struct pipe_context
*ctx
,
78 struct pipe_resource
*texture
,
79 const struct pipe_sampler_view
*state
)
81 struct r600_context
*rctx
= r600_context(ctx
);
82 struct r600_context_state
*rstate
;
84 rstate
= r600_context_state(rctx
, pipe_sampler_type
, state
);
85 pipe_reference(NULL
, &texture
->reference
);
86 rstate
->state
.sampler_view
.texture
= texture
;
87 rstate
->state
.sampler_view
.reference
.count
= 1;
88 rstate
->state
.sampler_view
.context
= ctx
;
89 return &rstate
->state
.sampler_view
;
92 static void *r600_create_shader_state(struct pipe_context
*ctx
,
93 const struct pipe_shader_state
*state
)
95 struct r600_context
*rctx
= r600_context(ctx
);
97 return r600_context_state(rctx
, pipe_shader_type
, state
);
100 static void *r600_create_vertex_elements(struct pipe_context
*ctx
,
102 const struct pipe_vertex_element
*elements
)
104 struct r600_vertex_element
*v
= CALLOC_STRUCT(r600_vertex_element
);
108 memcpy(v
->elements
, elements
, count
* sizeof(struct pipe_vertex_element
));
113 static void r600_bind_state(struct pipe_context
*ctx
, void *state
)
115 struct r600_context
*rctx
= r600_context(ctx
);
116 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
120 switch (rstate
->type
) {
121 case pipe_rasterizer_type
:
122 rctx
->rasterizer
= r600_context_state_decref(rctx
->rasterizer
);
123 rctx
->rasterizer
= r600_context_state_incref(rstate
);
125 case pipe_poly_stipple_type
:
126 rctx
->poly_stipple
= r600_context_state_decref(rctx
->poly_stipple
);
127 rctx
->poly_stipple
= r600_context_state_incref(rstate
);
129 case pipe_scissor_type
:
130 rctx
->scissor
= r600_context_state_decref(rctx
->scissor
);
131 rctx
->scissor
= r600_context_state_incref(rstate
);
134 rctx
->clip
= r600_context_state_decref(rctx
->clip
);
135 rctx
->clip
= r600_context_state_incref(rstate
);
137 case pipe_depth_type
:
138 rctx
->depth
= r600_context_state_decref(rctx
->depth
);
139 rctx
->depth
= r600_context_state_incref(rstate
);
141 case pipe_stencil_type
:
142 rctx
->stencil
= r600_context_state_decref(rctx
->stencil
);
143 rctx
->stencil
= r600_context_state_incref(rstate
);
145 case pipe_alpha_type
:
146 rctx
->alpha
= r600_context_state_decref(rctx
->alpha
);
147 rctx
->alpha
= r600_context_state_incref(rstate
);
150 rctx
->dsa
= r600_context_state_decref(rctx
->dsa
);
151 rctx
->dsa
= r600_context_state_incref(rstate
);
153 case pipe_blend_type
:
154 rctx
->blend
= r600_context_state_decref(rctx
->blend
);
155 rctx
->blend
= r600_context_state_incref(rstate
);
157 case pipe_framebuffer_type
:
158 rctx
->framebuffer
= r600_context_state_decref(rctx
->framebuffer
);
159 rctx
->framebuffer
= r600_context_state_incref(rstate
);
161 case pipe_stencil_ref_type
:
162 rctx
->stencil_ref
= r600_context_state_decref(rctx
->stencil_ref
);
163 rctx
->stencil_ref
= r600_context_state_incref(rstate
);
165 case pipe_viewport_type
:
166 rctx
->viewport
= r600_context_state_decref(rctx
->viewport
);
167 rctx
->viewport
= r600_context_state_incref(rstate
);
169 case pipe_shader_type
:
170 case pipe_sampler_type
:
171 case pipe_sampler_view_type
:
173 R600_ERR("invalid type %d\n", rstate
->type
);
178 static void r600_bind_ps_shader(struct pipe_context
*ctx
, void *state
)
180 struct r600_context
*rctx
= r600_context(ctx
);
181 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
183 rctx
->ps_shader
= r600_context_state_decref(rctx
->ps_shader
);
184 rctx
->ps_shader
= r600_context_state_incref(rstate
);
187 static void r600_bind_vs_shader(struct pipe_context
*ctx
, void *state
)
189 struct r600_context
*rctx
= r600_context(ctx
);
190 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
192 rctx
->vs_shader
= r600_context_state_decref(rctx
->vs_shader
);
193 rctx
->vs_shader
= r600_context_state_incref(rstate
);
196 static void r600_delete_vertex_element(struct pipe_context
*ctx
, void *state
)
198 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
207 static void r600_bind_vertex_elements(struct pipe_context
*ctx
, void *state
)
209 struct r600_context
*rctx
= r600_context(ctx
);
210 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
212 r600_delete_vertex_element(ctx
, rctx
->vertex_elements
);
213 rctx
->vertex_elements
= v
;
219 static void r600_bind_ps_sampler(struct pipe_context
*ctx
,
220 unsigned count
, void **states
)
222 struct r600_context
*rctx
= r600_context(ctx
);
223 struct r600_context_state
*rstate
;
226 for (i
= 0; i
< rctx
->ps_nsampler
; i
++) {
227 rctx
->ps_sampler
[i
] = r600_context_state_decref(rctx
->ps_sampler
[i
]);
229 for (i
= 0; i
< count
; i
++) {
230 rstate
= (struct r600_context_state
*)states
[i
];
231 rctx
->ps_sampler
[i
] = r600_context_state_incref(rstate
);
233 rctx
->ps_nsampler
= count
;
236 static void r600_bind_vs_sampler(struct pipe_context
*ctx
,
237 unsigned count
, void **states
)
239 struct r600_context
*rctx
= r600_context(ctx
);
240 struct r600_context_state
*rstate
;
243 for (i
= 0; i
< rctx
->vs_nsampler
; i
++) {
244 rctx
->vs_sampler
[i
] = r600_context_state_decref(rctx
->vs_sampler
[i
]);
246 for (i
= 0; i
< count
; i
++) {
247 rstate
= (struct r600_context_state
*)states
[i
];
248 rctx
->vs_sampler
[i
] = r600_context_state_incref(rstate
);
250 rctx
->vs_nsampler
= count
;
253 static void r600_delete_state(struct pipe_context
*ctx
, void *state
)
255 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
257 r600_context_state_decref(rstate
);
260 static void r600_set_blend_color(struct pipe_context
*ctx
,
261 const struct pipe_blend_color
*color
)
263 struct r600_context
*rctx
= r600_context(ctx
);
265 rctx
->blend_color
= *color
;
268 static void r600_set_clip_state(struct pipe_context
*ctx
,
269 const struct pipe_clip_state
*state
)
273 static void r600_set_constant_buffer(struct pipe_context
*ctx
,
274 uint shader
, uint index
,
275 struct pipe_resource
*buffer
)
277 struct r600_screen
*rscreen
= r600_screen(ctx
->screen
);
278 struct r600_context
*rctx
= r600_context(ctx
);
279 unsigned nconstant
= 0, i
, type
, id
;
280 struct radeon_state
*rstate
;
281 struct pipe_transfer
*transfer
;
285 case PIPE_SHADER_VERTEX
:
286 id
= R600_VS_CONSTANT
;
287 type
= R600_VS_CONSTANT_TYPE
;
289 case PIPE_SHADER_FRAGMENT
:
290 id
= R600_PS_CONSTANT
;
291 type
= R600_PS_CONSTANT_TYPE
;
294 R600_ERR("unsupported %d\n", shader
);
297 if (buffer
&& buffer
->width0
> 0) {
298 nconstant
= buffer
->width0
/ 16;
299 ptr
= pipe_buffer_map(ctx
, buffer
, PIPE_TRANSFER_READ
, &transfer
);
302 for (i
= 0; i
< nconstant
; i
++) {
303 rstate
= radeon_state(rscreen
->rw
, type
, id
+ i
);
306 rstate
->states
[R600_PS_CONSTANT__SQ_ALU_CONSTANT0_0
] = ptr
[i
* 4 + 0];
307 rstate
->states
[R600_PS_CONSTANT__SQ_ALU_CONSTANT1_0
] = ptr
[i
* 4 + 1];
308 rstate
->states
[R600_PS_CONSTANT__SQ_ALU_CONSTANT2_0
] = ptr
[i
* 4 + 2];
309 rstate
->states
[R600_PS_CONSTANT__SQ_ALU_CONSTANT3_0
] = ptr
[i
* 4 + 3];
310 if (radeon_state_pm4(rstate
))
312 if (radeon_draw_set_new(rctx
->draw
, rstate
))
315 pipe_buffer_unmap(ctx
, buffer
, transfer
);
319 static void r600_set_ps_sampler_view(struct pipe_context
*ctx
,
321 struct pipe_sampler_view
**views
)
323 struct r600_context
*rctx
= r600_context(ctx
);
324 struct r600_context_state
*rstate
;
327 for (i
= 0; i
< rctx
->ps_nsampler_view
; i
++) {
328 rctx
->ps_sampler_view
[i
] = r600_context_state_decref(rctx
->ps_sampler_view
[i
]);
330 for (i
= 0; i
< count
; i
++) {
331 rstate
= (struct r600_context_state
*)views
[i
];
332 rctx
->ps_sampler_view
[i
] = r600_context_state_incref(rstate
);
334 rctx
->ps_nsampler_view
= count
;
337 static void r600_set_vs_sampler_view(struct pipe_context
*ctx
,
339 struct pipe_sampler_view
**views
)
341 struct r600_context
*rctx
= r600_context(ctx
);
342 struct r600_context_state
*rstate
;
345 for (i
= 0; i
< rctx
->vs_nsampler_view
; i
++) {
346 rctx
->vs_sampler_view
[i
] = r600_context_state_decref(rctx
->vs_sampler_view
[i
]);
348 for (i
= 0; i
< count
; i
++) {
349 rstate
= (struct r600_context_state
*)views
[i
];
350 rctx
->vs_sampler_view
[i
] = r600_context_state_incref(rstate
);
352 rctx
->vs_nsampler_view
= count
;
355 static void r600_set_framebuffer_state(struct pipe_context
*ctx
,
356 const struct pipe_framebuffer_state
*state
)
358 struct r600_context
*rctx
= r600_context(ctx
);
359 struct r600_context_state
*rstate
;
361 rstate
= r600_context_state(rctx
, pipe_framebuffer_type
, state
);
362 r600_bind_state(ctx
, rstate
);
365 static void r600_set_polygon_stipple(struct pipe_context
*ctx
,
366 const struct pipe_poly_stipple
*state
)
370 static void r600_set_sample_mask(struct pipe_context
*pipe
, unsigned sample_mask
)
374 static void r600_set_scissor_state(struct pipe_context
*ctx
,
375 const struct pipe_scissor_state
*state
)
377 struct r600_context
*rctx
= r600_context(ctx
);
378 struct r600_context_state
*rstate
;
380 rstate
= r600_context_state(rctx
, pipe_scissor_type
, state
);
381 r600_bind_state(ctx
, rstate
);
384 static void r600_set_stencil_ref(struct pipe_context
*ctx
,
385 const struct pipe_stencil_ref
*state
)
387 struct r600_context
*rctx
= r600_context(ctx
);
388 struct r600_context_state
*rstate
;
390 rstate
= r600_context_state(rctx
, pipe_stencil_ref_type
, state
);
391 r600_bind_state(ctx
, rstate
);
394 static void r600_set_vertex_buffers(struct pipe_context
*ctx
,
396 const struct pipe_vertex_buffer
*buffers
)
398 struct r600_context
*rctx
= r600_context(ctx
);
401 for (i
= 0; i
< rctx
->nvertex_buffer
; i
++) {
402 pipe_resource_reference(&rctx
->vertex_buffer
[i
].buffer
, NULL
);
404 memcpy(rctx
->vertex_buffer
, buffers
, sizeof(struct pipe_vertex_buffer
) * count
);
405 for (i
= 0; i
< count
; i
++) {
406 rctx
->vertex_buffer
[i
].buffer
= NULL
;
407 pipe_resource_reference(&rctx
->vertex_buffer
[i
].buffer
, buffers
[i
].buffer
);
409 rctx
->nvertex_buffer
= count
;
412 static void r600_set_index_buffer(struct pipe_context
*ctx
,
413 const struct pipe_index_buffer
*ib
)
415 struct r600_context
*rctx
= r600_context(ctx
);
418 pipe_resource_reference(&rctx
->index_buffer
.buffer
, ib
->buffer
);
419 memcpy(&rctx
->index_buffer
, ib
, sizeof(rctx
->index_buffer
));
421 pipe_resource_reference(&rctx
->index_buffer
.buffer
, NULL
);
422 memset(&rctx
->index_buffer
, 0, sizeof(rctx
->index_buffer
));
425 /* TODO make this more like a state */
428 static void r600_set_viewport_state(struct pipe_context
*ctx
,
429 const struct pipe_viewport_state
*state
)
431 struct r600_context
*rctx
= r600_context(ctx
);
432 struct r600_context_state
*rstate
;
434 rstate
= r600_context_state(rctx
, pipe_viewport_type
, state
);
435 r600_bind_state(ctx
, rstate
);
438 void r600_init_state_functions(struct r600_context
*rctx
)
440 rctx
->context
.create_blend_state
= r600_create_blend_state
;
441 rctx
->context
.create_depth_stencil_alpha_state
= r600_create_dsa_state
;
442 rctx
->context
.create_fs_state
= r600_create_shader_state
;
443 rctx
->context
.create_rasterizer_state
= r600_create_rs_state
;
444 rctx
->context
.create_sampler_state
= r600_create_sampler_state
;
445 rctx
->context
.create_sampler_view
= r600_create_sampler_view
;
446 rctx
->context
.create_vertex_elements_state
= r600_create_vertex_elements
;
447 rctx
->context
.create_vs_state
= r600_create_shader_state
;
448 rctx
->context
.bind_blend_state
= r600_bind_state
;
449 rctx
->context
.bind_depth_stencil_alpha_state
= r600_bind_state
;
450 rctx
->context
.bind_fragment_sampler_states
= r600_bind_ps_sampler
;
451 rctx
->context
.bind_fs_state
= r600_bind_ps_shader
;
452 rctx
->context
.bind_rasterizer_state
= r600_bind_state
;
453 rctx
->context
.bind_vertex_elements_state
= r600_bind_vertex_elements
;
454 rctx
->context
.bind_vertex_sampler_states
= r600_bind_vs_sampler
;
455 rctx
->context
.bind_vs_state
= r600_bind_vs_shader
;
456 rctx
->context
.delete_blend_state
= r600_delete_state
;
457 rctx
->context
.delete_depth_stencil_alpha_state
= r600_delete_state
;
458 rctx
->context
.delete_fs_state
= r600_delete_state
;
459 rctx
->context
.delete_rasterizer_state
= r600_delete_state
;
460 rctx
->context
.delete_sampler_state
= r600_delete_state
;
461 rctx
->context
.delete_vertex_elements_state
= r600_delete_vertex_element
;
462 rctx
->context
.delete_vs_state
= r600_delete_state
;
463 rctx
->context
.set_blend_color
= r600_set_blend_color
;
464 rctx
->context
.set_clip_state
= r600_set_clip_state
;
465 rctx
->context
.set_constant_buffer
= r600_set_constant_buffer
;
466 rctx
->context
.set_fragment_sampler_views
= r600_set_ps_sampler_view
;
467 rctx
->context
.set_framebuffer_state
= r600_set_framebuffer_state
;
468 rctx
->context
.set_polygon_stipple
= r600_set_polygon_stipple
;
469 rctx
->context
.set_sample_mask
= r600_set_sample_mask
;
470 rctx
->context
.set_scissor_state
= r600_set_scissor_state
;
471 rctx
->context
.set_stencil_ref
= r600_set_stencil_ref
;
472 rctx
->context
.set_vertex_buffers
= r600_set_vertex_buffers
;
473 rctx
->context
.set_index_buffer
= r600_set_index_buffer
;
474 rctx
->context
.set_vertex_sampler_views
= r600_set_vs_sampler_view
;
475 rctx
->context
.set_viewport_state
= r600_set_viewport_state
;
476 rctx
->context
.sampler_view_destroy
= r600_sampler_view_destroy
;
479 struct r600_context_state
*r600_context_state_incref(struct r600_context_state
*rstate
)
487 struct r600_context_state
*r600_context_state_decref(struct r600_context_state
*rstate
)
493 if (--rstate
->refcount
)
495 switch (rstate
->type
) {
496 case pipe_sampler_view_type
:
497 pipe_resource_reference(&rstate
->state
.sampler_view
.texture
, NULL
);
499 case pipe_framebuffer_type
:
500 for (i
= 0; i
< rstate
->state
.framebuffer
.nr_cbufs
; i
++) {
501 pipe_surface_reference(&rstate
->state
.framebuffer
.cbufs
[i
], NULL
);
503 pipe_surface_reference(&rstate
->state
.framebuffer
.zsbuf
, NULL
);
505 case pipe_viewport_type
:
506 case pipe_depth_type
:
507 case pipe_rasterizer_type
:
508 case pipe_poly_stipple_type
:
509 case pipe_scissor_type
:
511 case pipe_stencil_type
:
512 case pipe_alpha_type
:
514 case pipe_blend_type
:
515 case pipe_stencil_ref_type
:
516 case pipe_shader_type
:
517 case pipe_sampler_type
:
520 R600_ERR("invalid type %d\n", rstate
->type
);
523 radeon_state_decref(rstate
->rstate
);
528 struct r600_context_state
*r600_context_state(struct r600_context
*rctx
, unsigned type
, const void *state
)
530 struct r600_context_state
*rstate
= CALLOC_STRUCT(r600_context_state
);
531 const union pipe_states
*states
= state
;
538 rstate
->refcount
= 1;
540 switch (rstate
->type
) {
541 case pipe_sampler_view_type
:
542 rstate
->state
.sampler_view
= (*states
).sampler_view
;
543 rstate
->state
.sampler_view
.texture
= NULL
;
545 case pipe_framebuffer_type
:
546 rstate
->state
.framebuffer
= (*states
).framebuffer
;
547 for (i
= 0; i
< rstate
->state
.framebuffer
.nr_cbufs
; i
++) {
548 pipe_surface_reference(&rstate
->state
.framebuffer
.cbufs
[i
],
549 (*states
).framebuffer
.cbufs
[i
]);
551 pipe_surface_reference(&rstate
->state
.framebuffer
.zsbuf
,
552 (*states
).framebuffer
.zsbuf
);
554 case pipe_viewport_type
:
555 rstate
->state
.viewport
= (*states
).viewport
;
557 case pipe_depth_type
:
558 rstate
->state
.depth
= (*states
).depth
;
560 case pipe_rasterizer_type
:
561 rstate
->state
.rasterizer
= (*states
).rasterizer
;
563 case pipe_poly_stipple_type
:
564 rstate
->state
.poly_stipple
= (*states
).poly_stipple
;
566 case pipe_scissor_type
:
567 rstate
->state
.scissor
= (*states
).scissor
;
570 rstate
->state
.clip
= (*states
).clip
;
572 case pipe_stencil_type
:
573 rstate
->state
.stencil
= (*states
).stencil
;
575 case pipe_alpha_type
:
576 rstate
->state
.alpha
= (*states
).alpha
;
579 rstate
->state
.dsa
= (*states
).dsa
;
581 case pipe_blend_type
:
582 rstate
->state
.blend
= (*states
).blend
;
584 case pipe_stencil_ref_type
:
585 rstate
->state
.stencil_ref
= (*states
).stencil_ref
;
587 case pipe_shader_type
:
588 rstate
->state
.shader
= (*states
).shader
;
589 r
= r600_pipe_shader_create(&rctx
->context
, rstate
, rstate
->state
.shader
.tokens
);
591 r600_context_state_decref(rstate
);
595 case pipe_sampler_type
:
596 rstate
->state
.sampler
= (*states
).sampler
;
599 R600_ERR("invalid type %d\n", rstate
->type
);
606 static struct radeon_state
*r600_blend(struct r600_context
*rctx
)
608 struct r600_screen
*rscreen
= rctx
->screen
;
609 struct radeon_state
*rstate
;
610 const struct pipe_blend_state
*state
= &rctx
->blend
->state
.blend
;
613 rstate
= radeon_state(rscreen
->rw
, R600_BLEND_TYPE
, R600_BLEND
);
616 rstate
->states
[R600_BLEND__CB_BLEND_RED
] = fui(rctx
->blend_color
.color
[0]);
617 rstate
->states
[R600_BLEND__CB_BLEND_GREEN
] = fui(rctx
->blend_color
.color
[1]);
618 rstate
->states
[R600_BLEND__CB_BLEND_BLUE
] = fui(rctx
->blend_color
.color
[2]);
619 rstate
->states
[R600_BLEND__CB_BLEND_ALPHA
] = fui(rctx
->blend_color
.color
[3]);
620 rstate
->states
[R600_BLEND__CB_BLEND0_CONTROL
] = 0x00000000;
621 rstate
->states
[R600_BLEND__CB_BLEND1_CONTROL
] = 0x00000000;
622 rstate
->states
[R600_BLEND__CB_BLEND2_CONTROL
] = 0x00000000;
623 rstate
->states
[R600_BLEND__CB_BLEND3_CONTROL
] = 0x00000000;
624 rstate
->states
[R600_BLEND__CB_BLEND4_CONTROL
] = 0x00000000;
625 rstate
->states
[R600_BLEND__CB_BLEND5_CONTROL
] = 0x00000000;
626 rstate
->states
[R600_BLEND__CB_BLEND6_CONTROL
] = 0x00000000;
627 rstate
->states
[R600_BLEND__CB_BLEND7_CONTROL
] = 0x00000000;
628 rstate
->states
[R600_BLEND__CB_BLEND_CONTROL
] = 0x00000000;
630 for (i
= 0; i
< 8; i
++) {
632 unsigned eqRGB
= state
->rt
[i
].rgb_func
;
633 unsigned srcRGB
= state
->rt
[i
].rgb_src_factor
;
634 unsigned dstRGB
= state
->rt
[i
].rgb_dst_factor
;
636 unsigned eqA
= state
->rt
[i
].alpha_func
;
637 unsigned srcA
= state
->rt
[i
].alpha_src_factor
;
638 unsigned dstA
= state
->rt
[i
].alpha_dst_factor
;
641 if (!state
->rt
[i
].blend_enable
)
644 bc
|= S_028804_COLOR_COMB_FCN(r600_translate_blend_function(eqRGB
));
645 bc
|= S_028804_COLOR_SRCBLEND(r600_translate_blend_factor(srcRGB
));
646 bc
|= S_028804_COLOR_DESTBLEND(r600_translate_blend_factor(dstRGB
));
648 if (srcA
!= srcRGB
|| dstA
!= dstRGB
|| eqA
!= eqRGB
) {
649 bc
|= S_028804_SEPARATE_ALPHA_BLEND(1);
650 bc
|= S_028804_ALPHA_COMB_FCN(r600_translate_blend_function(eqA
));
651 bc
|= S_028804_ALPHA_SRCBLEND(r600_translate_blend_factor(srcA
));
652 bc
|= S_028804_ALPHA_DESTBLEND(r600_translate_blend_factor(dstA
));
655 rstate
->states
[R600_BLEND__CB_BLEND0_CONTROL
+ i
] = bc
;
657 rstate
->states
[R600_BLEND__CB_BLEND_CONTROL
] = bc
;
660 if (radeon_state_pm4(rstate
)) {
661 radeon_state_decref(rstate
);
667 static struct radeon_state
*r600_cb0(struct r600_context
*rctx
)
669 struct r600_screen
*rscreen
= rctx
->screen
;
670 struct r600_resource_texture
*rtex
;
671 struct r600_resource
*rbuffer
;
672 struct radeon_state
*rstate
;
673 const struct pipe_framebuffer_state
*state
= &rctx
->framebuffer
->state
.framebuffer
;
674 unsigned level
= state
->cbufs
[0]->level
;
675 unsigned pitch
, slice
;
677 rstate
= radeon_state(rscreen
->rw
, R600_CB0_TYPE
, R600_CB0
);
680 rtex
= (struct r600_resource_texture
*)state
->cbufs
[0]->texture
;
681 rbuffer
= &rtex
->resource
;
682 rstate
->bo
[0] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
683 rstate
->bo
[1] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
684 rstate
->bo
[2] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
685 rstate
->placement
[0] = RADEON_GEM_DOMAIN_GTT
;
686 rstate
->placement
[2] = RADEON_GEM_DOMAIN_GTT
;
687 rstate
->placement
[4] = RADEON_GEM_DOMAIN_GTT
;
689 pitch
= (rtex
->pitch
[level
] / rtex
->bpt
) / 8 - 1;
690 slice
= (rtex
->pitch
[level
] / rtex
->bpt
) * state
->cbufs
[0]->height
/ 64 - 1;
691 rstate
->states
[R600_CB0__CB_COLOR0_BASE
] = 0x00000000;
692 rstate
->states
[R600_CB0__CB_COLOR0_INFO
] = 0x08110068;
693 rstate
->states
[R600_CB0__CB_COLOR0_SIZE
] = S_028060_PITCH_TILE_MAX(pitch
) |
694 S_028060_SLICE_TILE_MAX(slice
);
695 rstate
->states
[R600_CB0__CB_COLOR0_VIEW
] = 0x00000000;
696 rstate
->states
[R600_CB0__CB_COLOR0_FRAG
] = 0x00000000;
697 rstate
->states
[R600_CB0__CB_COLOR0_TILE
] = 0x00000000;
698 rstate
->states
[R600_CB0__CB_COLOR0_MASK
] = 0x00000000;
699 if (radeon_state_pm4(rstate
)) {
700 radeon_state_decref(rstate
);
706 static int r600_db_format(unsigned pformat
, unsigned *format
)
709 case PIPE_FORMAT_Z24X8_UNORM
:
710 *format
= V_028010_DEPTH_X8_24
;
712 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
713 *format
= V_028010_DEPTH_8_24
;
716 *format
= V_028010_DEPTH_INVALID
;
717 R600_ERR("unsupported %d\n", pformat
);
722 static struct radeon_state
*r600_db(struct r600_context
*rctx
)
724 struct r600_screen
*rscreen
= rctx
->screen
;
725 struct r600_resource_texture
*rtex
;
726 struct r600_resource
*rbuffer
;
727 struct radeon_state
*rstate
;
728 const struct pipe_framebuffer_state
*state
= &rctx
->framebuffer
->state
.framebuffer
;
729 unsigned level
= state
->cbufs
[0]->level
;
730 unsigned pitch
, slice
, format
;
732 if (state
->zsbuf
== NULL
)
735 rstate
= radeon_state(rscreen
->rw
, R600_DB_TYPE
, R600_DB
);
739 rtex
= (struct r600_resource_texture
*)state
->zsbuf
->texture
;
740 rbuffer
= &rtex
->resource
;
741 rstate
->bo
[0] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
743 rstate
->placement
[0] = RADEON_GEM_DOMAIN_VRAM
;
744 level
= state
->zsbuf
->level
;
745 pitch
= (rtex
->pitch
[level
] / rtex
->bpt
) / 8 - 1;
746 slice
= (rtex
->pitch
[level
] / rtex
->bpt
) * state
->zsbuf
->height
/ 64 - 1;
747 if (r600_db_format(state
->zsbuf
->texture
->format
, &format
)) {
748 radeon_state_decref(rstate
);
751 rstate
->states
[R600_DB__DB_DEPTH_BASE
] = 0x00000000;
752 rstate
->states
[R600_DB__DB_DEPTH_INFO
] = 0x00010000 |
753 S_028010_FORMAT(format
);
754 rstate
->states
[R600_DB__DB_DEPTH_VIEW
] = 0x00000000;
755 rstate
->states
[R600_DB__DB_PREFETCH_LIMIT
] = (state
->zsbuf
->height
/ 8) -1;
756 rstate
->states
[R600_DB__DB_DEPTH_SIZE
] = S_028000_PITCH_TILE_MAX(pitch
) |
757 S_028000_SLICE_TILE_MAX(slice
);
758 if (radeon_state_pm4(rstate
)) {
759 radeon_state_decref(rstate
);
765 static struct radeon_state
*r600_rasterizer(struct r600_context
*rctx
)
767 const struct pipe_rasterizer_state
*state
= &rctx
->rasterizer
->state
.rasterizer
;
768 struct r600_screen
*rscreen
= rctx
->screen
;
769 struct radeon_state
*rstate
;
771 rctx
->flat_shade
= state
->flatshade
;
772 rstate
= radeon_state(rscreen
->rw
, R600_RASTERIZER_TYPE
, R600_RASTERIZER
);
775 rstate
->states
[R600_RASTERIZER__SPI_INTERP_CONTROL_0
] = 0x00000001;
776 rstate
->states
[R600_RASTERIZER__PA_CL_CLIP_CNTL
] = 0x00000000;
777 rstate
->states
[R600_RASTERIZER__PA_SU_SC_MODE_CNTL
] = 0x00080000 |
778 S_028814_CULL_FRONT((state
->cull_face
& PIPE_FACE_FRONT
) ? 1 : 0) |
779 S_028814_CULL_BACK((state
->cull_face
& PIPE_FACE_BACK
) ? 1 : 0) |
780 S_028814_FACE(!state
->front_ccw
);
781 rstate
->states
[R600_RASTERIZER__PA_CL_VS_OUT_CNTL
] = 0x00000000;
782 rstate
->states
[R600_RASTERIZER__PA_CL_NANINF_CNTL
] = 0x00000000;
783 rstate
->states
[R600_RASTERIZER__PA_SU_POINT_SIZE
] = 0x00080008;
784 rstate
->states
[R600_RASTERIZER__PA_SU_POINT_MINMAX
] = 0x00000000;
785 rstate
->states
[R600_RASTERIZER__PA_SU_LINE_CNTL
] = 0x00000008;
786 rstate
->states
[R600_RASTERIZER__PA_SC_LINE_STIPPLE
] = 0x00000005;
787 rstate
->states
[R600_RASTERIZER__PA_SC_MPASS_PS_CNTL
] = 0x00000000;
788 rstate
->states
[R600_RASTERIZER__PA_SC_LINE_CNTL
] = 0x00000400;
789 rstate
->states
[R600_RASTERIZER__PA_CL_GB_VERT_CLIP_ADJ
] = 0x3F800000;
790 rstate
->states
[R600_RASTERIZER__PA_CL_GB_VERT_DISC_ADJ
] = 0x3F800000;
791 rstate
->states
[R600_RASTERIZER__PA_CL_GB_HORZ_CLIP_ADJ
] = 0x3F800000;
792 rstate
->states
[R600_RASTERIZER__PA_CL_GB_HORZ_DISC_ADJ
] = 0x3F800000;
793 rstate
->states
[R600_RASTERIZER__PA_SU_POLY_OFFSET_DB_FMT_CNTL
] = 0x00000000;
794 rstate
->states
[R600_RASTERIZER__PA_SU_POLY_OFFSET_CLAMP
] = 0x00000000;
795 rstate
->states
[R600_RASTERIZER__PA_SU_POLY_OFFSET_FRONT_SCALE
] = 0x00000000;
796 rstate
->states
[R600_RASTERIZER__PA_SU_POLY_OFFSET_FRONT_OFFSET
] = 0x00000000;
797 rstate
->states
[R600_RASTERIZER__PA_SU_POLY_OFFSET_BACK_SCALE
] = 0x00000000;
798 rstate
->states
[R600_RASTERIZER__PA_SU_POLY_OFFSET_BACK_OFFSET
] = 0x00000000;
799 if (radeon_state_pm4(rstate
)) {
800 radeon_state_decref(rstate
);
806 static struct radeon_state
*r600_scissor(struct r600_context
*rctx
)
808 const struct pipe_scissor_state
*state
= &rctx
->scissor
->state
.scissor
;
809 struct r600_screen
*rscreen
= rctx
->screen
;
810 struct radeon_state
*rstate
;
813 tl
= S_028240_TL_X(state
->minx
) | S_028240_TL_Y(state
->miny
) | S_028240_WINDOW_OFFSET_DISABLE(1);
814 br
= S_028244_BR_X(state
->maxx
) | S_028244_BR_Y(state
->maxy
);
815 rstate
= radeon_state(rscreen
->rw
, R600_SCISSOR_TYPE
, R600_SCISSOR
);
818 rstate
->states
[R600_SCISSOR__PA_SC_SCREEN_SCISSOR_TL
] = tl
;
819 rstate
->states
[R600_SCISSOR__PA_SC_SCREEN_SCISSOR_BR
] = br
;
820 rstate
->states
[R600_SCISSOR__PA_SC_WINDOW_OFFSET
] = 0x00000000;
821 rstate
->states
[R600_SCISSOR__PA_SC_WINDOW_SCISSOR_TL
] = tl
;
822 rstate
->states
[R600_SCISSOR__PA_SC_WINDOW_SCISSOR_BR
] = br
;
823 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_RULE
] = 0x0000FFFF;
824 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_0_TL
] = tl
;
825 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_0_BR
] = br
;
826 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_1_TL
] = tl
;
827 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_1_BR
] = br
;
828 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_2_TL
] = tl
;
829 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_2_BR
] = br
;
830 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_3_TL
] = tl
;
831 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_3_BR
] = br
;
832 rstate
->states
[R600_SCISSOR__PA_SC_EDGERULE
] = 0xAAAAAAAA;
833 rstate
->states
[R600_SCISSOR__PA_SC_GENERIC_SCISSOR_TL
] = tl
;
834 rstate
->states
[R600_SCISSOR__PA_SC_GENERIC_SCISSOR_BR
] = br
;
835 rstate
->states
[R600_SCISSOR__PA_SC_VPORT_SCISSOR_0_TL
] = tl
;
836 rstate
->states
[R600_SCISSOR__PA_SC_VPORT_SCISSOR_0_BR
] = br
;
837 if (radeon_state_pm4(rstate
)) {
838 radeon_state_decref(rstate
);
844 static struct radeon_state
*r600_viewport(struct r600_context
*rctx
)
846 const struct pipe_viewport_state
*state
= &rctx
->viewport
->state
.viewport
;
847 struct r600_screen
*rscreen
= rctx
->screen
;
848 struct radeon_state
*rstate
;
850 rstate
= radeon_state(rscreen
->rw
, R600_VIEWPORT_TYPE
, R600_VIEWPORT
);
853 rstate
->states
[R600_VIEWPORT__PA_SC_VPORT_ZMIN_0
] = 0x00000000;
854 rstate
->states
[R600_VIEWPORT__PA_SC_VPORT_ZMAX_0
] = 0x3F800000;
855 rstate
->states
[R600_VIEWPORT__PA_CL_VPORT_XSCALE_0
] = fui(state
->scale
[0]);
856 rstate
->states
[R600_VIEWPORT__PA_CL_VPORT_YSCALE_0
] = fui(state
->scale
[1]);
857 rstate
->states
[R600_VIEWPORT__PA_CL_VPORT_ZSCALE_0
] = fui(state
->scale
[2]);
858 rstate
->states
[R600_VIEWPORT__PA_CL_VPORT_XOFFSET_0
] = fui(state
->translate
[0]);
859 rstate
->states
[R600_VIEWPORT__PA_CL_VPORT_YOFFSET_0
] = fui(state
->translate
[1]);
860 rstate
->states
[R600_VIEWPORT__PA_CL_VPORT_ZOFFSET_0
] = fui(state
->translate
[2]);
861 rstate
->states
[R600_VIEWPORT__PA_CL_VTE_CNTL
] = 0x0000043F;
862 if (radeon_state_pm4(rstate
)) {
863 radeon_state_decref(rstate
);
869 static struct radeon_state
*r600_dsa(struct r600_context
*rctx
)
871 const struct pipe_depth_stencil_alpha_state
*state
= &rctx
->dsa
->state
.dsa
;
872 const struct pipe_stencil_ref
*stencil_ref
= &rctx
->stencil_ref
->state
.stencil_ref
;
873 struct r600_screen
*rscreen
= rctx
->screen
;
874 struct radeon_state
*rstate
;
875 unsigned db_depth_control
, alpha_test_control
, alpha_ref
;
876 unsigned stencil_ref_mask
, stencil_ref_mask_bf
;
878 rstate
= radeon_state(rscreen
->rw
, R600_DSA_TYPE
, R600_DSA
);
882 stencil_ref_mask
= 0;
883 stencil_ref_mask_bf
= 0;
884 db_depth_control
= S_028800_Z_ENABLE(state
->depth
.enabled
) |
885 S_028800_Z_WRITE_ENABLE(state
->depth
.writemask
) |
886 S_028800_ZFUNC(state
->depth
.func
);
887 /* set stencil enable */
889 if (state
->stencil
[0].enabled
) {
890 db_depth_control
|= S_028800_STENCIL_ENABLE(1);
891 db_depth_control
|= S_028800_STENCILFUNC(r600_translate_ds_func(state
->stencil
[0].func
));
892 db_depth_control
|= S_028800_STENCILFAIL(r600_translate_stencil_op(state
->stencil
[0].fail_op
));
893 db_depth_control
|= S_028800_STENCILZPASS(r600_translate_stencil_op(state
->stencil
[0].zpass_op
));
894 db_depth_control
|= S_028800_STENCILZFAIL(r600_translate_stencil_op(state
->stencil
[0].zfail_op
));
896 stencil_ref_mask
= S_028430_STENCILMASK(state
->stencil
[0].valuemask
) |
897 S_028430_STENCILWRITEMASK(state
->stencil
[0].writemask
);
898 stencil_ref_mask
|= S_028430_STENCILREF(stencil_ref
->ref_value
[0]);
899 if (state
->stencil
[1].enabled
) {
900 db_depth_control
|= S_028800_BACKFACE_ENABLE(1);
901 db_depth_control
|= S_028800_STENCILFUNC_BF(r600_translate_ds_func(state
->stencil
[1].func
));
902 db_depth_control
|= S_028800_STENCILFAIL_BF(r600_translate_stencil_op(state
->stencil
[1].fail_op
));
903 db_depth_control
|= S_028800_STENCILZPASS_BF(r600_translate_stencil_op(state
->stencil
[1].zpass_op
));
904 db_depth_control
|= S_028800_STENCILZFAIL_BF(r600_translate_stencil_op(state
->stencil
[1].zfail_op
));
905 stencil_ref_mask_bf
= S_028434_STENCILMASK_BF(state
->stencil
[1].valuemask
) |
906 S_028434_STENCILWRITEMASK_BF(state
->stencil
[1].writemask
);
907 stencil_ref_mask_bf
|= S_028430_STENCILREF(stencil_ref
->ref_value
[1]);
911 alpha_test_control
= 0;
913 if (state
->alpha
.enabled
) {
914 alpha_test_control
= S_028410_ALPHA_FUNC(state
->alpha
.func
);
915 alpha_test_control
|= S_028410_ALPHA_TEST_ENABLE(1);
916 alpha_ref
= fui(state
->alpha
.ref_value
);
919 rstate
->states
[R600_DSA__DB_STENCIL_CLEAR
] = 0x00000000;
920 rstate
->states
[R600_DSA__DB_DEPTH_CLEAR
] = 0x3F800000;
921 rstate
->states
[R600_DSA__SX_ALPHA_TEST_CONTROL
] = alpha_test_control
;
922 rstate
->states
[R600_DSA__DB_STENCILREFMASK
] = stencil_ref_mask
;
923 rstate
->states
[R600_DSA__DB_STENCILREFMASK_BF
] = stencil_ref_mask_bf
;
924 rstate
->states
[R600_DSA__SX_ALPHA_REF
] = alpha_ref
;
925 rstate
->states
[R600_DSA__SPI_FOG_FUNC_SCALE
] = 0x00000000;
926 rstate
->states
[R600_DSA__SPI_FOG_FUNC_BIAS
] = 0x00000000;
927 rstate
->states
[R600_DSA__SPI_FOG_CNTL
] = 0x00000000;
928 rstate
->states
[R600_DSA__DB_DEPTH_CONTROL
] = db_depth_control
;
929 rstate
->states
[R600_DSA__DB_SHADER_CONTROL
] = 0x00000210;
930 rstate
->states
[R600_DSA__DB_RENDER_CONTROL
] = 0x00000060;
931 rstate
->states
[R600_DSA__DB_RENDER_OVERRIDE
] = 0x0000002A;
932 rstate
->states
[R600_DSA__DB_SRESULTS_COMPARE_STATE1
] = 0x00000000;
933 rstate
->states
[R600_DSA__DB_PRELOAD_CONTROL
] = 0x00000000;
934 rstate
->states
[R600_DSA__DB_ALPHA_TO_MASK
] = 0x0000AA00;
935 if (radeon_state_pm4(rstate
)) {
936 radeon_state_decref(rstate
);
942 static inline unsigned r600_tex_wrap(unsigned wrap
)
946 case PIPE_TEX_WRAP_REPEAT
:
947 return V_03C000_SQ_TEX_WRAP
;
948 case PIPE_TEX_WRAP_CLAMP
:
949 return V_03C000_SQ_TEX_CLAMP_LAST_TEXEL
;
950 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
951 return V_03C000_SQ_TEX_CLAMP_HALF_BORDER
;
952 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
953 return V_03C000_SQ_TEX_CLAMP_BORDER
;
954 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
955 return V_03C000_SQ_TEX_MIRROR
;
956 case PIPE_TEX_WRAP_MIRROR_CLAMP
:
957 return V_03C000_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
958 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
:
959 return V_03C000_SQ_TEX_MIRROR_ONCE_HALF_BORDER
;
960 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
:
961 return V_03C000_SQ_TEX_MIRROR_ONCE_BORDER
;
965 static inline unsigned r600_tex_filter(unsigned filter
)
969 case PIPE_TEX_FILTER_NEAREST
:
970 return V_03C000_SQ_TEX_XY_FILTER_POINT
;
971 case PIPE_TEX_FILTER_LINEAR
:
972 return V_03C000_SQ_TEX_XY_FILTER_BILINEAR
;
976 static inline unsigned r600_tex_mipfilter(unsigned filter
)
979 case PIPE_TEX_MIPFILTER_NEAREST
:
980 return V_03C000_SQ_TEX_Z_FILTER_POINT
;
981 case PIPE_TEX_MIPFILTER_LINEAR
:
982 return V_03C000_SQ_TEX_Z_FILTER_LINEAR
;
984 case PIPE_TEX_MIPFILTER_NONE
:
985 return V_03C000_SQ_TEX_Z_FILTER_NONE
;
989 static inline unsigned r600_tex_compare(unsigned compare
)
993 case PIPE_FUNC_NEVER
:
994 return V_03C000_SQ_TEX_DEPTH_COMPARE_NEVER
;
996 return V_03C000_SQ_TEX_DEPTH_COMPARE_LESS
;
997 case PIPE_FUNC_EQUAL
:
998 return V_03C000_SQ_TEX_DEPTH_COMPARE_EQUAL
;
999 case PIPE_FUNC_LEQUAL
:
1000 return V_03C000_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
1001 case PIPE_FUNC_GREATER
:
1002 return V_03C000_SQ_TEX_DEPTH_COMPARE_GREATER
;
1003 case PIPE_FUNC_NOTEQUAL
:
1004 return V_03C000_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
1005 case PIPE_FUNC_GEQUAL
:
1006 return V_03C000_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
1007 case PIPE_FUNC_ALWAYS
:
1008 return V_03C000_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
1012 static INLINE u32
S_FIXED(float value
, u32 frac_bits
)
1014 return value
* (1 << frac_bits
);
1017 static struct radeon_state
*r600_sampler(struct r600_context
*rctx
,
1018 const struct pipe_sampler_state
*state
,
1021 struct r600_screen
*rscreen
= rctx
->screen
;
1022 struct radeon_state
*rstate
;
1024 rstate
= radeon_state(rscreen
->rw
, R600_PS_SAMPLER_TYPE
, id
);
1027 rstate
->states
[R600_PS_SAMPLER__SQ_TEX_SAMPLER_WORD0_0
] =
1028 S_03C000_CLAMP_X(r600_tex_wrap(state
->wrap_s
)) |
1029 S_03C000_CLAMP_Y(r600_tex_wrap(state
->wrap_t
)) |
1030 S_03C000_CLAMP_Z(r600_tex_wrap(state
->wrap_r
)) |
1031 S_03C000_XY_MAG_FILTER(r600_tex_filter(state
->mag_img_filter
)) |
1032 S_03C000_XY_MIN_FILTER(r600_tex_filter(state
->min_img_filter
)) |
1033 S_03C000_MIP_FILTER(r600_tex_mipfilter(state
->min_mip_filter
)) |
1034 S_03C000_DEPTH_COMPARE_FUNCTION(r600_tex_compare(state
->compare_func
));
1035 /* FIXME LOD it depends on texture base level ... */
1036 rstate
->states
[R600_PS_SAMPLER__SQ_TEX_SAMPLER_WORD1_0
] =
1037 S_03C004_MIN_LOD(S_FIXED(CLAMP(state
->min_lod
, 0, 15), 6)) |
1038 S_03C004_MAX_LOD(S_FIXED(CLAMP(state
->max_lod
, 0, 15), 6)) |
1039 S_03C004_LOD_BIAS(S_FIXED(CLAMP(state
->lod_bias
, -16, 16), 6));
1040 rstate
->states
[R600_PS_SAMPLER__SQ_TEX_SAMPLER_WORD2_0
] = S_03C008_TYPE(1);
1041 if (radeon_state_pm4(rstate
)) {
1042 radeon_state_decref(rstate
);
1048 static inline unsigned r600_tex_swizzle(unsigned swizzle
)
1051 case PIPE_SWIZZLE_RED
:
1052 return V_038010_SQ_SEL_X
;
1053 case PIPE_SWIZZLE_GREEN
:
1054 return V_038010_SQ_SEL_Y
;
1055 case PIPE_SWIZZLE_BLUE
:
1056 return V_038010_SQ_SEL_Z
;
1057 case PIPE_SWIZZLE_ALPHA
:
1058 return V_038010_SQ_SEL_W
;
1059 case PIPE_SWIZZLE_ZERO
:
1060 return V_038010_SQ_SEL_0
;
1062 case PIPE_SWIZZLE_ONE
:
1063 return V_038010_SQ_SEL_1
;
1067 static inline unsigned r600_format_type(unsigned format_type
)
1069 switch (format_type
) {
1071 case UTIL_FORMAT_TYPE_UNSIGNED
:
1072 return V_038010_SQ_FORMAT_COMP_UNSIGNED
;
1073 case UTIL_FORMAT_TYPE_SIGNED
:
1074 return V_038010_SQ_FORMAT_COMP_SIGNED
;
1075 case UTIL_FORMAT_TYPE_FIXED
:
1076 return V_038010_SQ_FORMAT_COMP_UNSIGNED_BIASED
;
1080 static inline unsigned r600_tex_dim(unsigned dim
)
1084 case PIPE_TEXTURE_1D
:
1085 return V_038000_SQ_TEX_DIM_1D
;
1086 case PIPE_TEXTURE_2D
:
1087 return V_038000_SQ_TEX_DIM_2D
;
1088 case PIPE_TEXTURE_3D
:
1089 return V_038000_SQ_TEX_DIM_3D
;
1090 case PIPE_TEXTURE_CUBE
:
1091 return V_038000_SQ_TEX_DIM_CUBEMAP
;
1095 static struct radeon_state
*r600_resource(struct r600_context
*rctx
,
1096 const struct pipe_sampler_view
*view
,
1099 struct r600_screen
*rscreen
= rctx
->screen
;
1100 const struct util_format_description
*desc
;
1101 struct r600_resource_texture
*tmp
;
1102 struct r600_resource
*rbuffer
;
1103 struct radeon_state
*rstate
;
1106 if (r600_conv_pipe_format(view
->texture
->format
, &format
))
1108 desc
= util_format_description(view
->texture
->format
);
1110 R600_ERR("unknow format %d\n", view
->texture
->format
);
1113 rstate
= radeon_state(rscreen
->rw
, R600_PS_RESOURCE_TYPE
, id
);
1114 if (rstate
== NULL
) {
1117 tmp
= (struct r600_resource_texture
*)view
->texture
;
1118 rbuffer
= &tmp
->resource
;
1119 rstate
->bo
[0] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
1120 rstate
->bo
[1] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
1122 rstate
->placement
[0] = RADEON_GEM_DOMAIN_GTT
;
1123 rstate
->placement
[1] = RADEON_GEM_DOMAIN_GTT
;
1124 rstate
->placement
[2] = RADEON_GEM_DOMAIN_GTT
;
1125 rstate
->placement
[3] = RADEON_GEM_DOMAIN_GTT
;
1127 /* FIXME properly handle first level != 0 */
1128 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD0
] =
1129 S_038000_DIM(r600_tex_dim(view
->texture
->target
)) |
1130 S_038000_PITCH(((tmp
->pitch
[0] / tmp
->bpt
) / 8) - 1) |
1131 S_038000_TEX_WIDTH(view
->texture
->width0
- 1);
1132 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD1
] =
1133 S_038004_TEX_HEIGHT(view
->texture
->height0
- 1) |
1134 S_038004_TEX_DEPTH(view
->texture
->depth0
- 1) |
1135 S_038004_DATA_FORMAT(format
);
1136 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD2
] = 0;
1137 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD3
] = tmp
->offset
[1] >> 8;
1138 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD4
] =
1139 S_038010_FORMAT_COMP_X(r600_format_type(UTIL_FORMAT_TYPE_UNSIGNED
)) |
1140 S_038010_FORMAT_COMP_Y(r600_format_type(UTIL_FORMAT_TYPE_UNSIGNED
)) |
1141 S_038010_FORMAT_COMP_Z(r600_format_type(UTIL_FORMAT_TYPE_UNSIGNED
)) |
1142 S_038010_FORMAT_COMP_W(r600_format_type(UTIL_FORMAT_TYPE_UNSIGNED
)) |
1143 S_038010_NUM_FORMAT_ALL(V_038010_SQ_NUM_FORMAT_NORM
) |
1144 S_038010_SRF_MODE_ALL(V_038010_SFR_MODE_NO_ZERO
) |
1145 S_038010_REQUEST_SIZE(1) |
1146 S_038010_DST_SEL_X(r600_tex_swizzle(view
->swizzle_b
)) |
1147 S_038010_DST_SEL_Y(r600_tex_swizzle(view
->swizzle_g
)) |
1148 S_038010_DST_SEL_Z(r600_tex_swizzle(view
->swizzle_r
)) |
1149 S_038010_DST_SEL_W(r600_tex_swizzle(view
->swizzle_a
)) |
1150 S_038010_BASE_LEVEL(view
->first_level
);
1151 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD5
] =
1152 S_038014_LAST_LEVEL(view
->last_level
) |
1153 S_038014_BASE_ARRAY(0) |
1154 S_038014_LAST_ARRAY(0);
1155 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD6
] =
1156 S_038018_TYPE(V_038010_SQ_TEX_VTX_VALID_TEXTURE
);
1157 if (radeon_state_pm4(rstate
)) {
1158 radeon_state_decref(rstate
);
1164 static struct radeon_state
*r600_cb_cntl(struct r600_context
*rctx
)
1166 struct r600_screen
*rscreen
= rctx
->screen
;
1167 struct radeon_state
*rstate
;
1168 const struct pipe_blend_state
*pbs
= &rctx
->blend
->state
.blend
;
1169 uint32_t color_control
, target_mask
;
1175 if (pbs
->logicop_enable
) {
1176 color_control
|= (pbs
->logicop_func
) << 16;
1178 color_control
|= (0xcc << 16);
1180 target_mask
|= (pbs
->rt
[0].colormask
);
1181 for (i
= 0; i
< 8; i
++) {
1182 if (pbs
->rt
[i
].blend_enable
) {
1183 color_control
|= (1 << (8 + i
));
1184 target_mask
|= (pbs
->rt
[0].colormask
<< (4 * i
));
1188 rstate
= radeon_state(rscreen
->rw
, R600_CB_CNTL_TYPE
, R600_CB_CNTL
);
1189 rstate
->states
[R600_CB_CNTL__CB_SHADER_MASK
] = 0x0000000F;
1190 rstate
->states
[R600_CB_CNTL__CB_TARGET_MASK
] = target_mask
;
1191 rstate
->states
[R600_CB_CNTL__CB_COLOR_CONTROL
] = color_control
;
1192 rstate
->states
[R600_CB_CNTL__PA_SC_AA_CONFIG
] = 0x00000000;
1193 rstate
->states
[R600_CB_CNTL__PA_SC_AA_SAMPLE_LOCS_MCTX
] = 0x00000000;
1194 rstate
->states
[R600_CB_CNTL__PA_SC_AA_SAMPLE_LOCS_8S_WD1_MCTX
] = 0x00000000;
1195 rstate
->states
[R600_CB_CNTL__CB_CLRCMP_CONTROL
] = 0x01000000;
1196 rstate
->states
[R600_CB_CNTL__CB_CLRCMP_SRC
] = 0x00000000;
1197 rstate
->states
[R600_CB_CNTL__CB_CLRCMP_DST
] = 0x000000FF;
1198 rstate
->states
[R600_CB_CNTL__CB_CLRCMP_MSK
] = 0xFFFFFFFF;
1199 rstate
->states
[R600_CB_CNTL__PA_SC_AA_MASK
] = 0xFFFFFFFF;
1200 if (radeon_state_pm4(rstate
)) {
1201 radeon_state_decref(rstate
);
1207 int r600_context_hw_states(struct r600_context
*rctx
)
1212 /* free previous TODO determine what need to be updated, what
1215 //radeon_state_decref(rctx->hw_states.config);
1216 radeon_state_decref(rctx
->hw_states
.cb_cntl
);
1217 radeon_state_decref(rctx
->hw_states
.db
);
1218 radeon_state_decref(rctx
->hw_states
.rasterizer
);
1219 radeon_state_decref(rctx
->hw_states
.scissor
);
1220 radeon_state_decref(rctx
->hw_states
.dsa
);
1221 radeon_state_decref(rctx
->hw_states
.blend
);
1222 radeon_state_decref(rctx
->hw_states
.viewport
);
1223 radeon_state_decref(rctx
->hw_states
.cb0
);
1224 for (i
= 0; i
< rctx
->hw_states
.ps_nresource
; i
++) {
1225 radeon_state_decref(rctx
->hw_states
.ps_resource
[i
]);
1226 rctx
->hw_states
.ps_resource
[i
] = NULL
;
1228 rctx
->hw_states
.ps_nresource
= 0;
1229 for (i
= 0; i
< rctx
->hw_states
.ps_nsampler
; i
++) {
1230 radeon_state_decref(rctx
->hw_states
.ps_sampler
[i
]);
1231 rctx
->hw_states
.ps_sampler
[i
] = NULL
;
1233 rctx
->hw_states
.ps_nsampler
= 0;
1235 /* build new states */
1236 rctx
->hw_states
.rasterizer
= r600_rasterizer(rctx
);
1237 rctx
->hw_states
.scissor
= r600_scissor(rctx
);
1238 rctx
->hw_states
.dsa
= r600_dsa(rctx
);
1239 rctx
->hw_states
.blend
= r600_blend(rctx
);
1240 rctx
->hw_states
.viewport
= r600_viewport(rctx
);
1241 rctx
->hw_states
.cb0
= r600_cb0(rctx
);
1242 rctx
->hw_states
.db
= r600_db(rctx
);
1243 rctx
->hw_states
.cb_cntl
= r600_cb_cntl(rctx
);
1245 for (i
= 0; i
< rctx
->ps_nsampler
; i
++) {
1246 if (rctx
->ps_sampler
[i
]) {
1247 rctx
->hw_states
.ps_sampler
[i
] = r600_sampler(rctx
,
1248 &rctx
->ps_sampler
[i
]->state
.sampler
,
1249 R600_PS_SAMPLER
+ i
);
1252 rctx
->hw_states
.ps_nsampler
= rctx
->ps_nsampler
;
1253 for (i
= 0; i
< rctx
->ps_nsampler_view
; i
++) {
1254 if (rctx
->ps_sampler_view
[i
]) {
1255 rctx
->hw_states
.ps_resource
[i
] = r600_resource(rctx
,
1256 &rctx
->ps_sampler_view
[i
]->state
.sampler_view
,
1257 R600_PS_RESOURCE
+ i
);
1260 rctx
->hw_states
.ps_nresource
= rctx
->ps_nsampler_view
;
1263 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.db
);
1266 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.rasterizer
);
1269 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.scissor
);
1272 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.dsa
);
1275 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.blend
);
1278 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.viewport
);
1281 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.cb0
);
1284 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.config
);
1287 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.cb_cntl
);
1290 for (i
= 0; i
< rctx
->hw_states
.ps_nresource
; i
++) {
1291 if (rctx
->hw_states
.ps_resource
[i
]) {
1292 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.ps_resource
[i
]);
1297 for (i
= 0; i
< rctx
->hw_states
.ps_nsampler
; i
++) {
1298 if (rctx
->hw_states
.ps_sampler
[i
]) {
1299 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.ps_sampler
[i
]);