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.
27 #include "util/u_inlines.h"
28 #include "util/u_format.h"
29 #include "util/u_memory.h"
30 #include "r600_screen.h"
31 #include "r600_context.h"
32 #include "r600_resource.h"
35 static void *r600_create_blend_state(struct pipe_context
*ctx
,
36 const struct pipe_blend_state
*state
)
38 struct r600_context
*rctx
= r600_context(ctx
);
40 return r600_context_state(rctx
, pipe_blend_type
, state
);
43 static void *r600_create_dsa_state(struct pipe_context
*ctx
,
44 const struct pipe_depth_stencil_alpha_state
*state
)
46 struct r600_context
*rctx
= r600_context(ctx
);
48 return r600_context_state(rctx
, pipe_dsa_type
, state
);
51 static void *r600_create_rs_state(struct pipe_context
*ctx
,
52 const struct pipe_rasterizer_state
*state
)
54 struct r600_context
*rctx
= r600_context(ctx
);
56 return r600_context_state(rctx
, pipe_rasterizer_type
, state
);
59 static void *r600_create_sampler_state(struct pipe_context
*ctx
,
60 const struct pipe_sampler_state
*state
)
62 struct r600_context
*rctx
= r600_context(ctx
);
64 return r600_context_state(rctx
, pipe_sampler_type
, state
);
67 static void r600_sampler_view_destroy(struct pipe_context
*ctx
,
68 struct pipe_sampler_view
*state
)
70 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
72 r600_context_state_decref(rstate
);
75 static struct pipe_sampler_view
*r600_create_sampler_view(struct pipe_context
*ctx
,
76 struct pipe_resource
*texture
,
77 const struct pipe_sampler_view
*state
)
79 struct r600_context
*rctx
= r600_context(ctx
);
80 struct r600_context_state
*rstate
;
82 rstate
= r600_context_state(rctx
, pipe_sampler_type
, state
);
83 pipe_reference(NULL
, &texture
->reference
);
84 rstate
->state
.sampler_view
.texture
= texture
;
85 rstate
->state
.sampler_view
.reference
.count
= 1;
86 return &rstate
->state
.sampler_view
;
89 static void *r600_create_shader_state(struct pipe_context
*ctx
,
90 const struct pipe_shader_state
*state
)
92 struct r600_context
*rctx
= r600_context(ctx
);
94 return r600_context_state(rctx
, pipe_shader_type
, state
);
97 static void *r600_create_vertex_elements(struct pipe_context
*ctx
,
99 const struct pipe_vertex_element
*elements
)
101 struct r600_vertex_element
*v
= CALLOC_STRUCT(r600_vertex_element
);
105 memcpy(v
->elements
, elements
, count
* sizeof(struct pipe_vertex_element
));
110 static void r600_bind_state(struct pipe_context
*ctx
, void *state
)
112 struct r600_context
*rctx
= r600_context(ctx
);
113 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
117 switch (rstate
->type
) {
118 case pipe_rasterizer_type
:
119 rctx
->rasterizer
= r600_context_state_decref(rctx
->rasterizer
);
120 rctx
->rasterizer
= r600_context_state_incref(rstate
);
122 case pipe_poly_stipple_type
:
123 rctx
->poly_stipple
= r600_context_state_decref(rctx
->poly_stipple
);
124 rctx
->poly_stipple
= r600_context_state_incref(rstate
);
126 case pipe_scissor_type
:
127 rctx
->scissor
= r600_context_state_decref(rctx
->scissor
);
128 rctx
->scissor
= r600_context_state_incref(rstate
);
131 rctx
->clip
= r600_context_state_decref(rctx
->clip
);
132 rctx
->clip
= r600_context_state_incref(rstate
);
134 case pipe_depth_type
:
135 rctx
->depth
= r600_context_state_decref(rctx
->depth
);
136 rctx
->depth
= r600_context_state_incref(rstate
);
138 case pipe_stencil_type
:
139 rctx
->stencil
= r600_context_state_decref(rctx
->stencil
);
140 rctx
->stencil
= r600_context_state_incref(rstate
);
142 case pipe_alpha_type
:
143 rctx
->alpha
= r600_context_state_decref(rctx
->alpha
);
144 rctx
->alpha
= r600_context_state_incref(rstate
);
147 rctx
->dsa
= r600_context_state_decref(rctx
->dsa
);
148 rctx
->dsa
= r600_context_state_incref(rstate
);
150 case pipe_blend_type
:
151 rctx
->blend
= r600_context_state_decref(rctx
->blend
);
152 rctx
->blend
= r600_context_state_incref(rstate
);
154 case pipe_framebuffer_type
:
155 rctx
->framebuffer
= r600_context_state_decref(rctx
->framebuffer
);
156 rctx
->framebuffer
= r600_context_state_incref(rstate
);
158 case pipe_stencil_ref_type
:
159 rctx
->stencil_ref
= r600_context_state_decref(rctx
->stencil_ref
);
160 rctx
->stencil_ref
= r600_context_state_incref(rstate
);
162 case pipe_viewport_type
:
163 rctx
->viewport
= r600_context_state_decref(rctx
->viewport
);
164 rctx
->viewport
= r600_context_state_incref(rstate
);
166 case pipe_shader_type
:
167 case pipe_sampler_type
:
168 case pipe_sampler_view_type
:
170 R600_ERR("invalid type %d\n", rstate
->type
);
175 static void r600_bind_ps_shader(struct pipe_context
*ctx
, void *state
)
177 struct r600_context
*rctx
= r600_context(ctx
);
178 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
180 rctx
->ps_shader
= r600_context_state_decref(rctx
->ps_shader
);
181 rctx
->ps_shader
= r600_context_state_incref(rstate
);
184 static void r600_bind_vs_shader(struct pipe_context
*ctx
, void *state
)
186 struct r600_context
*rctx
= r600_context(ctx
);
187 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
189 rctx
->vs_shader
= r600_context_state_decref(rctx
->vs_shader
);
190 rctx
->vs_shader
= r600_context_state_incref(rstate
);
193 static void r600_delete_vertex_element(struct pipe_context
*ctx
, void *state
)
195 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
204 static void r600_bind_vertex_elements(struct pipe_context
*ctx
, void *state
)
206 struct r600_context
*rctx
= r600_context(ctx
);
207 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
209 r600_delete_vertex_element(ctx
, rctx
->vertex_elements
);
210 rctx
->vertex_elements
= v
;
216 static void r600_bind_ps_sampler(struct pipe_context
*ctx
,
217 unsigned count
, void **states
)
219 struct r600_context
*rctx
= r600_context(ctx
);
220 struct r600_context_state
*rstate
;
223 for (i
= 0; i
< rctx
->ps_nsampler
; i
++) {
224 rctx
->ps_sampler
[i
] = r600_context_state_decref(rctx
->ps_sampler
[i
]);
226 for (i
= 0; i
< count
; i
++) {
227 rstate
= (struct r600_context_state
*)states
[i
];
228 rctx
->ps_sampler
[i
] = r600_context_state_incref(rstate
);
230 rctx
->ps_nsampler
= count
;
233 static void r600_bind_vs_sampler(struct pipe_context
*ctx
,
234 unsigned count
, void **states
)
236 struct r600_context
*rctx
= r600_context(ctx
);
237 struct r600_context_state
*rstate
;
240 for (i
= 0; i
< rctx
->vs_nsampler
; i
++) {
241 rctx
->vs_sampler
[i
] = r600_context_state_decref(rctx
->vs_sampler
[i
]);
243 for (i
= 0; i
< count
; i
++) {
244 rstate
= (struct r600_context_state
*)states
[i
];
245 rctx
->vs_sampler
[i
] = r600_context_state_incref(rstate
);
247 rctx
->vs_nsampler
= count
;
250 static void r600_delete_state(struct pipe_context
*ctx
, void *state
)
252 struct r600_context_state
*rstate
= (struct r600_context_state
*)state
;
254 r600_context_state_decref(rstate
);
257 static void r600_set_blend_color(struct pipe_context
*ctx
,
258 const struct pipe_blend_color
*color
)
262 static void r600_set_clip_state(struct pipe_context
*ctx
,
263 const struct pipe_clip_state
*state
)
267 static void r600_set_constant_buffer(struct pipe_context
*ctx
,
268 uint shader
, uint index
,
269 struct pipe_resource
*buffer
)
271 struct r600_screen
*rscreen
= r600_screen(ctx
->screen
);
272 struct r600_context
*rctx
= r600_context(ctx
);
273 unsigned nconstant
= 0, i
, type
, id
;
274 struct radeon_state
*rstate
;
275 struct pipe_transfer
*transfer
;
279 case PIPE_SHADER_VERTEX
:
280 id
= R600_VS_CONSTANT
;
281 type
= R600_VS_CONSTANT_TYPE
;
283 case PIPE_SHADER_FRAGMENT
:
284 id
= R600_PS_CONSTANT
;
285 type
= R600_PS_CONSTANT_TYPE
;
288 fprintf(stderr
, "%s:%d unsupported %d\n", __func__
, __LINE__
, shader
);
291 if (buffer
&& buffer
->width0
> 0) {
292 nconstant
= buffer
->width0
/ 16;
293 ptr
= pipe_buffer_map(ctx
, buffer
, PIPE_TRANSFER_READ
, &transfer
);
296 for (i
= 0; i
< nconstant
; i
++) {
297 rstate
= radeon_state(rscreen
->rw
, type
, id
+ i
);
300 rstate
->states
[R600_PS_CONSTANT__SQ_ALU_CONSTANT0_0
] = ptr
[i
* 4 + 0];
301 rstate
->states
[R600_PS_CONSTANT__SQ_ALU_CONSTANT1_0
] = ptr
[i
* 4 + 1];
302 rstate
->states
[R600_PS_CONSTANT__SQ_ALU_CONSTANT2_0
] = ptr
[i
* 4 + 2];
303 rstate
->states
[R600_PS_CONSTANT__SQ_ALU_CONSTANT3_0
] = ptr
[i
* 4 + 3];
304 if (radeon_state_pm4(rstate
))
306 if (radeon_draw_set_new(rctx
->draw
, rstate
))
309 pipe_buffer_unmap(ctx
, buffer
, transfer
);
313 static void r600_set_ps_sampler_view(struct pipe_context
*ctx
,
315 struct pipe_sampler_view
**views
)
317 struct r600_context
*rctx
= r600_context(ctx
);
318 struct r600_context_state
*rstate
;
321 for (i
= 0; i
< rctx
->ps_nsampler_view
; i
++) {
322 rctx
->ps_sampler_view
[i
] = r600_context_state_decref(rctx
->ps_sampler_view
[i
]);
324 for (i
= 0; i
< count
; i
++) {
325 rstate
= (struct r600_context_state
*)views
[i
];
326 rctx
->ps_sampler_view
[i
] = r600_context_state_incref(rstate
);
328 rctx
->ps_nsampler_view
= count
;
331 static void r600_set_vs_sampler_view(struct pipe_context
*ctx
,
333 struct pipe_sampler_view
**views
)
335 struct r600_context
*rctx
= r600_context(ctx
);
336 struct r600_context_state
*rstate
;
339 for (i
= 0; i
< rctx
->vs_nsampler_view
; i
++) {
340 rctx
->vs_sampler_view
[i
] = r600_context_state_decref(rctx
->vs_sampler_view
[i
]);
342 for (i
= 0; i
< count
; i
++) {
343 rstate
= (struct r600_context_state
*)views
[i
];
344 rctx
->vs_sampler_view
[i
] = r600_context_state_incref(rstate
);
346 rctx
->vs_nsampler_view
= count
;
349 static void r600_set_framebuffer_state(struct pipe_context
*ctx
,
350 const struct pipe_framebuffer_state
*state
)
352 struct r600_context
*rctx
= r600_context(ctx
);
353 struct r600_context_state
*rstate
;
355 rstate
= r600_context_state(rctx
, pipe_framebuffer_type
, state
);
356 r600_bind_state(ctx
, rstate
);
359 static void r600_set_polygon_stipple(struct pipe_context
*ctx
,
360 const struct pipe_poly_stipple
*state
)
364 static void r600_set_sample_mask(struct pipe_context
*pipe
, unsigned sample_mask
)
368 static void r600_set_scissor_state(struct pipe_context
*ctx
,
369 const struct pipe_scissor_state
*state
)
371 struct r600_context
*rctx
= r600_context(ctx
);
372 struct r600_context_state
*rstate
;
374 rstate
= r600_context_state(rctx
, pipe_scissor_type
, state
);
375 r600_bind_state(ctx
, rstate
);
378 static void r600_set_stencil_ref(struct pipe_context
*ctx
,
379 const struct pipe_stencil_ref
*state
)
381 struct r600_context
*rctx
= r600_context(ctx
);
382 struct r600_context_state
*rstate
;
384 rstate
= r600_context_state(rctx
, pipe_stencil_ref_type
, state
);
385 r600_bind_state(ctx
, rstate
);
388 static void r600_set_vertex_buffers(struct pipe_context
*ctx
,
390 const struct pipe_vertex_buffer
*buffers
)
392 struct r600_context
*rctx
= r600_context(ctx
);
395 for (i
= 0; i
< rctx
->nvertex_buffer
; i
++) {
396 pipe_resource_reference(&rctx
->vertex_buffer
[i
].buffer
, NULL
);
398 memcpy(rctx
->vertex_buffer
, buffers
, sizeof(struct pipe_vertex_buffer
) * count
);
399 for (i
= 0; i
< count
; i
++) {
400 rctx
->vertex_buffer
[i
].buffer
= NULL
;
401 pipe_resource_reference(&rctx
->vertex_buffer
[i
].buffer
, buffers
[i
].buffer
);
403 rctx
->nvertex_buffer
= count
;
406 static void r600_set_viewport_state(struct pipe_context
*ctx
,
407 const struct pipe_viewport_state
*state
)
409 struct r600_context
*rctx
= r600_context(ctx
);
410 struct r600_context_state
*rstate
;
412 rstate
= r600_context_state(rctx
, pipe_viewport_type
, state
);
413 r600_bind_state(ctx
, rstate
);
416 void r600_init_state_functions(struct r600_context
*rctx
)
418 rctx
->context
.create_blend_state
= r600_create_blend_state
;
419 rctx
->context
.create_depth_stencil_alpha_state
= r600_create_dsa_state
;
420 rctx
->context
.create_fs_state
= r600_create_shader_state
;
421 rctx
->context
.create_rasterizer_state
= r600_create_rs_state
;
422 rctx
->context
.create_sampler_state
= r600_create_sampler_state
;
423 rctx
->context
.create_sampler_view
= r600_create_sampler_view
;
424 rctx
->context
.create_vertex_elements_state
= r600_create_vertex_elements
;
425 rctx
->context
.create_vs_state
= r600_create_shader_state
;
426 rctx
->context
.bind_blend_state
= r600_bind_state
;
427 rctx
->context
.bind_depth_stencil_alpha_state
= r600_bind_state
;
428 rctx
->context
.bind_fragment_sampler_states
= r600_bind_ps_sampler
;
429 rctx
->context
.bind_fs_state
= r600_bind_ps_shader
;
430 rctx
->context
.bind_rasterizer_state
= r600_bind_state
;
431 rctx
->context
.bind_vertex_elements_state
= r600_bind_vertex_elements
;
432 rctx
->context
.bind_vertex_sampler_states
= r600_bind_vs_sampler
;
433 rctx
->context
.bind_vs_state
= r600_bind_vs_shader
;
434 rctx
->context
.delete_blend_state
= r600_delete_state
;
435 rctx
->context
.delete_depth_stencil_alpha_state
= r600_delete_state
;
436 rctx
->context
.delete_fs_state
= r600_delete_state
;
437 rctx
->context
.delete_rasterizer_state
= r600_delete_state
;
438 rctx
->context
.delete_sampler_state
= r600_delete_state
;
439 rctx
->context
.delete_vertex_elements_state
= r600_delete_vertex_element
;
440 rctx
->context
.delete_vs_state
= r600_delete_state
;
441 rctx
->context
.set_blend_color
= r600_set_blend_color
;
442 rctx
->context
.set_clip_state
= r600_set_clip_state
;
443 rctx
->context
.set_constant_buffer
= r600_set_constant_buffer
;
444 rctx
->context
.set_fragment_sampler_views
= r600_set_ps_sampler_view
;
445 rctx
->context
.set_framebuffer_state
= r600_set_framebuffer_state
;
446 rctx
->context
.set_polygon_stipple
= r600_set_polygon_stipple
;
447 rctx
->context
.set_sample_mask
= r600_set_sample_mask
;
448 rctx
->context
.set_scissor_state
= r600_set_scissor_state
;
449 rctx
->context
.set_stencil_ref
= r600_set_stencil_ref
;
450 rctx
->context
.set_vertex_buffers
= r600_set_vertex_buffers
;
451 rctx
->context
.set_vertex_sampler_views
= r600_set_vs_sampler_view
;
452 rctx
->context
.set_viewport_state
= r600_set_viewport_state
;
453 rctx
->context
.sampler_view_destroy
= r600_sampler_view_destroy
;
456 struct r600_context_state
*r600_context_state_incref(struct r600_context_state
*rstate
)
464 struct r600_context_state
*r600_context_state_decref(struct r600_context_state
*rstate
)
470 if (--rstate
->refcount
)
472 switch (rstate
->type
) {
473 case pipe_sampler_view_type
:
474 pipe_resource_reference(&rstate
->state
.sampler_view
.texture
, NULL
);
476 case pipe_framebuffer_type
:
477 for (i
= 0; i
< rstate
->state
.framebuffer
.nr_cbufs
; i
++) {
478 pipe_surface_reference(&rstate
->state
.framebuffer
.cbufs
[i
], NULL
);
480 pipe_surface_reference(&rstate
->state
.framebuffer
.zsbuf
, NULL
);
482 case pipe_viewport_type
:
483 case pipe_depth_type
:
484 case pipe_rasterizer_type
:
485 case pipe_poly_stipple_type
:
486 case pipe_scissor_type
:
488 case pipe_stencil_type
:
489 case pipe_alpha_type
:
491 case pipe_blend_type
:
492 case pipe_stencil_ref_type
:
493 case pipe_shader_type
:
494 case pipe_sampler_type
:
497 R600_ERR("invalid type %d\n", rstate
->type
);
500 radeon_state_decref(rstate
->rstate
);
505 struct r600_context_state
*r600_context_state(struct r600_context
*rctx
, unsigned type
, const void *state
)
507 struct r600_context_state
*rstate
= CALLOC_STRUCT(r600_context_state
);
508 const union pipe_states
*states
= state
;
515 rstate
->refcount
= 1;
517 switch (rstate
->type
) {
518 case pipe_sampler_view_type
:
519 rstate
->state
.sampler_view
= (*states
).sampler_view
;
520 rstate
->state
.sampler_view
.texture
= NULL
;
522 case pipe_framebuffer_type
:
523 rstate
->state
.framebuffer
= (*states
).framebuffer
;
524 for (i
= 0; i
< rstate
->state
.framebuffer
.nr_cbufs
; i
++) {
525 pipe_surface_reference(&rstate
->state
.framebuffer
.cbufs
[i
],
526 (*states
).framebuffer
.cbufs
[i
]);
528 pipe_surface_reference(&rstate
->state
.framebuffer
.zsbuf
,
529 (*states
).framebuffer
.zsbuf
);
531 case pipe_viewport_type
:
532 rstate
->state
.viewport
= (*states
).viewport
;
534 case pipe_depth_type
:
535 rstate
->state
.depth
= (*states
).depth
;
537 case pipe_rasterizer_type
:
538 rstate
->state
.rasterizer
= (*states
).rasterizer
;
540 case pipe_poly_stipple_type
:
541 rstate
->state
.poly_stipple
= (*states
).poly_stipple
;
543 case pipe_scissor_type
:
544 rstate
->state
.scissor
= (*states
).scissor
;
547 rstate
->state
.clip
= (*states
).clip
;
549 case pipe_stencil_type
:
550 rstate
->state
.stencil
= (*states
).stencil
;
552 case pipe_alpha_type
:
553 rstate
->state
.alpha
= (*states
).alpha
;
556 rstate
->state
.dsa
= (*states
).dsa
;
558 case pipe_blend_type
:
559 rstate
->state
.blend
= (*states
).blend
;
561 case pipe_stencil_ref_type
:
562 rstate
->state
.stencil_ref
= (*states
).stencil_ref
;
564 case pipe_shader_type
:
565 rstate
->state
.shader
= (*states
).shader
;
566 r
= r600_pipe_shader_create(&rctx
->context
, rstate
, rstate
->state
.shader
.tokens
);
568 r600_context_state_decref(rstate
);
572 case pipe_sampler_type
:
573 rstate
->state
.sampler
= (*states
).sampler
;
576 R600_ERR("invalid type %d\n", rstate
->type
);
583 static struct radeon_state
*r600_blend(struct r600_context
*rctx
)
585 struct r600_screen
*rscreen
= rctx
->screen
;
586 struct radeon_state
*rstate
;
588 rstate
= radeon_state(rscreen
->rw
, R600_BLEND_TYPE
, R600_BLEND
);
591 rstate
->states
[R600_BLEND__CB_BLEND_RED
] = 0x00000000;
592 rstate
->states
[R600_BLEND__CB_BLEND_GREEN
] = 0x00000000;
593 rstate
->states
[R600_BLEND__CB_BLEND_BLUE
] = 0x00000000;
594 rstate
->states
[R600_BLEND__CB_BLEND_ALPHA
] = 0x00000000;
595 rstate
->states
[R600_BLEND__CB_BLEND0_CONTROL
] = 0x00010001;
596 rstate
->states
[R600_BLEND__CB_BLEND1_CONTROL
] = 0x00000000;
597 rstate
->states
[R600_BLEND__CB_BLEND2_CONTROL
] = 0x00000000;
598 rstate
->states
[R600_BLEND__CB_BLEND3_CONTROL
] = 0x00000000;
599 rstate
->states
[R600_BLEND__CB_BLEND4_CONTROL
] = 0x00000000;
600 rstate
->states
[R600_BLEND__CB_BLEND5_CONTROL
] = 0x00000000;
601 rstate
->states
[R600_BLEND__CB_BLEND6_CONTROL
] = 0x00000000;
602 rstate
->states
[R600_BLEND__CB_BLEND7_CONTROL
] = 0x00000000;
603 rstate
->states
[R600_BLEND__CB_BLEND_CONTROL
] = 0x00000000;
604 if (radeon_state_pm4(rstate
)) {
605 radeon_state_decref(rstate
);
611 static struct radeon_state
*r600_cb0(struct r600_context
*rctx
)
613 struct r600_screen
*rscreen
= rctx
->screen
;
614 struct r600_resource_texture
*rtex
;
615 struct r600_resource
*rbuffer
;
616 struct radeon_state
*rstate
;
617 const struct pipe_framebuffer_state
*state
= &rctx
->framebuffer
->state
.framebuffer
;
618 unsigned level
= state
->cbufs
[0]->level
;
619 unsigned pitch
, slice
;
621 rstate
= radeon_state(rscreen
->rw
, R600_CB0_TYPE
, R600_CB0
);
624 rtex
= (struct r600_resource_texture
*)state
->cbufs
[0]->texture
;
625 rbuffer
= &rtex
->resource
;
626 rstate
->bo
[0] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
627 rstate
->bo
[1] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
628 rstate
->bo
[2] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
629 rstate
->placement
[0] = RADEON_GEM_DOMAIN_GTT
;
630 rstate
->placement
[2] = RADEON_GEM_DOMAIN_GTT
;
631 rstate
->placement
[4] = RADEON_GEM_DOMAIN_GTT
;
633 pitch
= rtex
->pitch
[level
] / 8 - 1;
634 slice
= rtex
->pitch
[level
] * state
->cbufs
[0]->height
/ 64 - 1;
635 rstate
->states
[R600_CB0__CB_COLOR0_BASE
] = 0x00000000;
636 rstate
->states
[R600_CB0__CB_COLOR0_INFO
] = 0x08110068;
637 rstate
->states
[R600_CB0__CB_COLOR0_SIZE
] = S_028060_PITCH_TILE_MAX(pitch
) |
638 S_028060_SLICE_TILE_MAX(slice
);
639 rstate
->states
[R600_CB0__CB_COLOR0_VIEW
] = 0x00000000;
640 rstate
->states
[R600_CB0__CB_COLOR0_FRAG
] = 0x00000000;
641 rstate
->states
[R600_CB0__CB_COLOR0_TILE
] = 0x00000000;
642 rstate
->states
[R600_CB0__CB_COLOR0_MASK
] = 0x00000000;
643 if (radeon_state_pm4(rstate
)) {
644 radeon_state_decref(rstate
);
650 static struct radeon_state
*r600_db(struct r600_context
*rctx
)
652 struct r600_screen
*rscreen
= rctx
->screen
;
653 struct r600_resource_texture
*rtex
;
654 struct r600_resource
*rbuffer
;
655 struct radeon_state
*rstate
;
656 const struct pipe_framebuffer_state
*state
= &rctx
->framebuffer
->state
.framebuffer
;
657 unsigned level
= state
->cbufs
[0]->level
;
658 unsigned pitch
, slice
;
660 if (state
->zsbuf
== NULL
)
663 rstate
= radeon_state(rscreen
->rw
, R600_DB_TYPE
, R600_DB
);
667 rtex
= (struct r600_resource_texture
*)state
->zsbuf
->texture
;
668 rbuffer
= &rtex
->resource
;
669 rstate
->bo
[0] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
671 rstate
->placement
[0] = RADEON_GEM_DOMAIN_VRAM
;
672 level
= state
->zsbuf
->level
;
673 pitch
= rtex
->pitch
[level
] / 8 - 1;
674 slice
= rtex
->pitch
[level
] * state
->zsbuf
->height
/ 64 - 1;
675 rstate
->states
[R600_DB__DB_DEPTH_BASE
] = 0x00000000;
676 rstate
->states
[R600_DB__DB_DEPTH_INFO
] = 0x00010006;
677 rstate
->states
[R600_DB__DB_DEPTH_VIEW
] = 0x00000000;
678 rstate
->states
[R600_DB__DB_PREFETCH_LIMIT
] = (state
->zsbuf
->height
/ 8) -1;
679 rstate
->states
[R600_DB__DB_DEPTH_SIZE
] = S_028000_PITCH_TILE_MAX(pitch
) |
680 S_028000_SLICE_TILE_MAX(slice
);
681 if (radeon_state_pm4(rstate
)) {
682 radeon_state_decref(rstate
);
688 static struct radeon_state
*r600_rasterizer(struct r600_context
*rctx
)
690 const struct pipe_rasterizer_state
*state
= &rctx
->rasterizer
->state
.rasterizer
;
691 struct r600_screen
*rscreen
= rctx
->screen
;
692 struct radeon_state
*rstate
;
694 rctx
->flat_shade
= state
->flatshade
;
695 rstate
= radeon_state(rscreen
->rw
, R600_RASTERIZER_TYPE
, R600_RASTERIZER
);
698 rstate
->states
[R600_RASTERIZER__SPI_INTERP_CONTROL_0
] = 0x00000001;
699 rstate
->states
[R600_RASTERIZER__PA_CL_CLIP_CNTL
] = 0x00000000;
700 rstate
->states
[R600_RASTERIZER__PA_SU_SC_MODE_CNTL
] = 0x00080000;
701 rstate
->states
[R600_RASTERIZER__PA_CL_VS_OUT_CNTL
] = 0x00000000;
702 rstate
->states
[R600_RASTERIZER__PA_CL_NANINF_CNTL
] = 0x00000000;
703 rstate
->states
[R600_RASTERIZER__PA_SU_POINT_SIZE
] = 0x00080008;
704 rstate
->states
[R600_RASTERIZER__PA_SU_POINT_MINMAX
] = 0x00000000;
705 rstate
->states
[R600_RASTERIZER__PA_SU_LINE_CNTL
] = 0x00000008;
706 rstate
->states
[R600_RASTERIZER__PA_SC_LINE_STIPPLE
] = 0x00000005;
707 rstate
->states
[R600_RASTERIZER__PA_SC_MPASS_PS_CNTL
] = 0x00000000;
708 rstate
->states
[R600_RASTERIZER__PA_SC_LINE_CNTL
] = 0x00000400;
709 rstate
->states
[R600_RASTERIZER__PA_CL_GB_VERT_CLIP_ADJ
] = 0x3F800000;
710 rstate
->states
[R600_RASTERIZER__PA_CL_GB_VERT_DISC_ADJ
] = 0x3F800000;
711 rstate
->states
[R600_RASTERIZER__PA_CL_GB_HORZ_CLIP_ADJ
] = 0x3F800000;
712 rstate
->states
[R600_RASTERIZER__PA_CL_GB_HORZ_DISC_ADJ
] = 0x3F800000;
713 rstate
->states
[R600_RASTERIZER__PA_SU_POLY_OFFSET_DB_FMT_CNTL
] = 0x00000000;
714 rstate
->states
[R600_RASTERIZER__PA_SU_POLY_OFFSET_CLAMP
] = 0x00000000;
715 rstate
->states
[R600_RASTERIZER__PA_SU_POLY_OFFSET_FRONT_SCALE
] = 0x00000000;
716 rstate
->states
[R600_RASTERIZER__PA_SU_POLY_OFFSET_FRONT_OFFSET
] = 0x00000000;
717 rstate
->states
[R600_RASTERIZER__PA_SU_POLY_OFFSET_BACK_SCALE
] = 0x00000000;
718 rstate
->states
[R600_RASTERIZER__PA_SU_POLY_OFFSET_BACK_OFFSET
] = 0x00000000;
719 if (radeon_state_pm4(rstate
)) {
720 radeon_state_decref(rstate
);
726 static struct radeon_state
*r600_scissor(struct r600_context
*rctx
)
728 const struct pipe_scissor_state
*state
= &rctx
->scissor
->state
.scissor
;
729 struct r600_screen
*rscreen
= rctx
->screen
;
730 struct radeon_state
*rstate
;
733 tl
= S_028240_TL_X(state
->minx
) | S_028240_TL_Y(state
->miny
) | S_028240_WINDOW_OFFSET_DISABLE(1);
734 br
= S_028244_BR_X(state
->maxx
) | S_028244_BR_Y(state
->maxy
);
735 rstate
= radeon_state(rscreen
->rw
, R600_SCISSOR_TYPE
, R600_SCISSOR
);
738 rstate
->states
[R600_SCISSOR__PA_SC_SCREEN_SCISSOR_TL
] = tl
;
739 rstate
->states
[R600_SCISSOR__PA_SC_SCREEN_SCISSOR_BR
] = br
;
740 rstate
->states
[R600_SCISSOR__PA_SC_WINDOW_OFFSET
] = 0x00000000;
741 rstate
->states
[R600_SCISSOR__PA_SC_WINDOW_SCISSOR_TL
] = tl
;
742 rstate
->states
[R600_SCISSOR__PA_SC_WINDOW_SCISSOR_BR
] = br
;
743 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_RULE
] = 0x0000FFFF;
744 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_0_TL
] = tl
;
745 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_0_BR
] = br
;
746 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_1_TL
] = tl
;
747 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_1_BR
] = br
;
748 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_2_TL
] = tl
;
749 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_2_BR
] = br
;
750 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_3_TL
] = tl
;
751 rstate
->states
[R600_SCISSOR__PA_SC_CLIPRECT_3_BR
] = br
;
752 rstate
->states
[R600_SCISSOR__PA_SC_EDGERULE
] = 0xAAAAAAAA;
753 rstate
->states
[R600_SCISSOR__PA_SC_GENERIC_SCISSOR_TL
] = tl
;
754 rstate
->states
[R600_SCISSOR__PA_SC_GENERIC_SCISSOR_BR
] = br
;
755 rstate
->states
[R600_SCISSOR__PA_SC_VPORT_SCISSOR_0_TL
] = tl
;
756 rstate
->states
[R600_SCISSOR__PA_SC_VPORT_SCISSOR_0_BR
] = br
;
757 if (radeon_state_pm4(rstate
)) {
758 radeon_state_decref(rstate
);
764 static struct radeon_state
*r600_viewport(struct r600_context
*rctx
)
766 const struct pipe_viewport_state
*state
= &rctx
->viewport
->state
.viewport
;
767 struct r600_screen
*rscreen
= rctx
->screen
;
768 struct radeon_state
*rstate
;
770 rstate
= radeon_state(rscreen
->rw
, R600_VIEWPORT_TYPE
, R600_VIEWPORT
);
773 rstate
->states
[R600_VIEWPORT__PA_SC_VPORT_ZMIN_0
] = 0x00000000;
774 rstate
->states
[R600_VIEWPORT__PA_SC_VPORT_ZMAX_0
] = 0x3F800000;
775 rstate
->states
[R600_VIEWPORT__PA_CL_VPORT_XSCALE_0
] = fui(state
->scale
[0]);
776 rstate
->states
[R600_VIEWPORT__PA_CL_VPORT_YSCALE_0
] = fui(state
->scale
[1]);
777 rstate
->states
[R600_VIEWPORT__PA_CL_VPORT_ZSCALE_0
] = fui(state
->scale
[2]);
778 rstate
->states
[R600_VIEWPORT__PA_CL_VPORT_XOFFSET_0
] = fui(state
->translate
[0]);
779 rstate
->states
[R600_VIEWPORT__PA_CL_VPORT_YOFFSET_0
] = fui(state
->translate
[1]);
780 rstate
->states
[R600_VIEWPORT__PA_CL_VPORT_ZOFFSET_0
] = fui(state
->translate
[2]);
781 rstate
->states
[R600_VIEWPORT__PA_CL_VTE_CNTL
] = 0x0000043F;
782 if (radeon_state_pm4(rstate
)) {
783 radeon_state_decref(rstate
);
789 static struct radeon_state
*r600_dsa(struct r600_context
*rctx
)
791 const struct pipe_depth_stencil_alpha_state
*state
= &rctx
->dsa
->state
.dsa
;
792 struct r600_screen
*rscreen
= rctx
->screen
;
793 struct radeon_state
*rstate
;
794 unsigned db_depth_control
;
796 rstate
= radeon_state(rscreen
->rw
, R600_DSA_TYPE
, R600_DSA
);
799 db_depth_control
= 0x00700700 | S_028800_Z_ENABLE(state
->depth
.enabled
) | S_028800_Z_WRITE_ENABLE(state
->depth
.writemask
) | S_028800_ZFUNC(state
->depth
.func
);
801 rstate
->states
[R600_DSA__DB_STENCIL_CLEAR
] = 0x00000000;
802 rstate
->states
[R600_DSA__DB_DEPTH_CLEAR
] = 0x3F800000;
803 rstate
->states
[R600_DSA__SX_ALPHA_TEST_CONTROL
] = 0x00000000;
804 rstate
->states
[R600_DSA__DB_STENCILREFMASK
] = 0xFFFFFF00;
805 rstate
->states
[R600_DSA__DB_STENCILREFMASK_BF
] = 0xFFFFFF00;
806 rstate
->states
[R600_DSA__SX_ALPHA_REF
] = 0x00000000;
807 rstate
->states
[R600_DSA__SPI_FOG_FUNC_SCALE
] = 0x00000000;
808 rstate
->states
[R600_DSA__SPI_FOG_FUNC_BIAS
] = 0x00000000;
809 rstate
->states
[R600_DSA__SPI_FOG_CNTL
] = 0x00000000;
810 rstate
->states
[R600_DSA__DB_DEPTH_CONTROL
] = db_depth_control
;
811 rstate
->states
[R600_DSA__DB_SHADER_CONTROL
] = 0x00000210;
812 rstate
->states
[R600_DSA__DB_RENDER_CONTROL
] = 0x00000060;
813 rstate
->states
[R600_DSA__DB_RENDER_OVERRIDE
] = 0x0000002A;
814 rstate
->states
[R600_DSA__DB_SRESULTS_COMPARE_STATE1
] = 0x00000000;
815 rstate
->states
[R600_DSA__DB_PRELOAD_CONTROL
] = 0x00000000;
816 rstate
->states
[R600_DSA__DB_ALPHA_TO_MASK
] = 0x0000AA00;
817 if (radeon_state_pm4(rstate
)) {
818 radeon_state_decref(rstate
);
824 static inline unsigned r600_tex_wrap(unsigned wrap
)
828 case PIPE_TEX_WRAP_REPEAT
:
829 return V_03C000_SQ_TEX_WRAP
;
830 case PIPE_TEX_WRAP_CLAMP
:
831 return V_03C000_SQ_TEX_CLAMP_LAST_TEXEL
;
832 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
833 return V_03C000_SQ_TEX_CLAMP_HALF_BORDER
;
834 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
835 return V_03C000_SQ_TEX_CLAMP_BORDER
;
836 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
837 return V_03C000_SQ_TEX_MIRROR
;
838 case PIPE_TEX_WRAP_MIRROR_CLAMP
:
839 return V_03C000_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
840 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
:
841 return V_03C000_SQ_TEX_MIRROR_ONCE_HALF_BORDER
;
842 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
:
843 return V_03C000_SQ_TEX_MIRROR_ONCE_BORDER
;
847 static inline unsigned r600_tex_filter(unsigned filter
)
851 case PIPE_TEX_FILTER_NEAREST
:
852 return V_03C000_SQ_TEX_XY_FILTER_POINT
;
853 case PIPE_TEX_FILTER_LINEAR
:
854 return V_03C000_SQ_TEX_XY_FILTER_BILINEAR
;
858 static inline unsigned r600_tex_mipfilter(unsigned filter
)
861 case PIPE_TEX_MIPFILTER_NEAREST
:
862 return V_03C000_SQ_TEX_Z_FILTER_POINT
;
863 case PIPE_TEX_MIPFILTER_LINEAR
:
864 return V_03C000_SQ_TEX_Z_FILTER_LINEAR
;
866 case PIPE_TEX_MIPFILTER_NONE
:
867 return V_03C000_SQ_TEX_Z_FILTER_NONE
;
871 static inline unsigned r600_tex_compare(unsigned compare
)
875 case PIPE_FUNC_NEVER
:
876 return V_03C000_SQ_TEX_DEPTH_COMPARE_NEVER
;
878 return V_03C000_SQ_TEX_DEPTH_COMPARE_LESS
;
879 case PIPE_FUNC_EQUAL
:
880 return V_03C000_SQ_TEX_DEPTH_COMPARE_EQUAL
;
881 case PIPE_FUNC_LEQUAL
:
882 return V_03C000_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
883 case PIPE_FUNC_GREATER
:
884 return V_03C000_SQ_TEX_DEPTH_COMPARE_GREATER
;
885 case PIPE_FUNC_NOTEQUAL
:
886 return V_03C000_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
887 case PIPE_FUNC_GEQUAL
:
888 return V_03C000_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
889 case PIPE_FUNC_ALWAYS
:
890 return V_03C000_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
894 static struct radeon_state
*r600_sampler(struct r600_context
*rctx
,
895 const struct pipe_sampler_state
*state
,
898 struct r600_screen
*rscreen
= rctx
->screen
;
899 struct radeon_state
*rstate
;
901 rstate
= radeon_state(rscreen
->rw
, R600_PS_SAMPLER_TYPE
, id
);
904 rstate
->states
[R600_PS_SAMPLER__SQ_TEX_SAMPLER_WORD0_0
] =
905 S_03C000_CLAMP_X(r600_tex_wrap(state
->wrap_s
)) |
906 S_03C000_CLAMP_Y(r600_tex_wrap(state
->wrap_t
)) |
907 S_03C000_CLAMP_Z(r600_tex_wrap(state
->wrap_r
)) |
908 S_03C000_XY_MAG_FILTER(r600_tex_filter(state
->mag_img_filter
)) |
909 S_03C000_XY_MIN_FILTER(r600_tex_filter(state
->min_img_filter
)) |
910 S_03C000_MIP_FILTER(r600_tex_mipfilter(state
->min_mip_filter
)) |
911 S_03C000_DEPTH_COMPARE_FUNCTION(r600_tex_compare(state
->compare_func
));
912 /* FIXME LOD it depends on texture base level ... */
913 rstate
->states
[R600_PS_SAMPLER__SQ_TEX_SAMPLER_WORD1_0
] =
914 S_03C004_MIN_LOD(0) |
915 S_03C004_MAX_LOD(0) |
916 S_03C004_LOD_BIAS(0);
917 rstate
->states
[R600_PS_SAMPLER__SQ_TEX_SAMPLER_WORD2_0
] = S_03C008_TYPE(1);
918 if (radeon_state_pm4(rstate
)) {
919 radeon_state_decref(rstate
);
925 static inline unsigned r600_tex_swizzle(unsigned swizzle
)
928 case PIPE_SWIZZLE_RED
:
929 return V_038010_SQ_SEL_X
;
930 case PIPE_SWIZZLE_GREEN
:
931 return V_038010_SQ_SEL_Y
;
932 case PIPE_SWIZZLE_BLUE
:
933 return V_038010_SQ_SEL_Z
;
934 case PIPE_SWIZZLE_ALPHA
:
935 return V_038010_SQ_SEL_W
;
936 case PIPE_SWIZZLE_ZERO
:
937 return V_038010_SQ_SEL_0
;
939 case PIPE_SWIZZLE_ONE
:
940 return V_038010_SQ_SEL_1
;
944 static inline unsigned r600_format_type(unsigned format_type
)
946 switch (format_type
) {
948 case UTIL_FORMAT_TYPE_UNSIGNED
:
949 return V_038010_SQ_FORMAT_COMP_UNSIGNED
;
950 case UTIL_FORMAT_TYPE_SIGNED
:
951 return V_038010_SQ_FORMAT_COMP_SIGNED
;
952 case UTIL_FORMAT_TYPE_FIXED
:
953 return V_038010_SQ_FORMAT_COMP_UNSIGNED_BIASED
;
957 static inline unsigned r600_tex_dim(unsigned dim
)
961 case PIPE_TEXTURE_1D
:
962 return V_038000_SQ_TEX_DIM_1D
;
963 case PIPE_TEXTURE_2D
:
964 return V_038000_SQ_TEX_DIM_2D
;
965 case PIPE_TEXTURE_3D
:
966 return V_038000_SQ_TEX_DIM_3D
;
967 case PIPE_TEXTURE_CUBE
:
968 return V_038000_SQ_TEX_DIM_CUBEMAP
;
972 static struct radeon_state
*r600_resource(struct r600_context
*rctx
,
973 const struct pipe_sampler_view
*view
,
976 struct r600_screen
*rscreen
= rctx
->screen
;
977 const struct util_format_description
*desc
;
978 struct r600_resource_texture
*tmp
;
979 struct r600_resource
*rbuffer
;
980 struct radeon_state
*rstate
;
983 if (r600_conv_pipe_format(view
->texture
->format
, &format
))
985 desc
= util_format_description(view
->texture
->format
);
986 assert(desc
== NULL
);
987 rstate
= radeon_state(rscreen
->rw
, R600_PS_RESOURCE_TYPE
, id
);
988 if (rstate
== NULL
) {
991 tmp
= (struct r600_resource_texture
*)view
->texture
;
992 rbuffer
= &tmp
->resource
;
993 rstate
->bo
[0] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
994 rstate
->bo
[1] = radeon_bo_incref(rscreen
->rw
, rbuffer
->bo
);
996 rstate
->placement
[0] = RADEON_GEM_DOMAIN_GTT
;
997 rstate
->placement
[1] = RADEON_GEM_DOMAIN_GTT
;
998 rstate
->placement
[2] = RADEON_GEM_DOMAIN_GTT
;
999 rstate
->placement
[3] = RADEON_GEM_DOMAIN_GTT
;
1001 /* FIXME properly handle first level != 0 */
1002 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD0
] =
1003 S_038000_DIM(r600_tex_dim(view
->texture
->target
)) |
1004 S_038000_PITCH((tmp
->pitch
[0] / 8) - 1) |
1005 S_038000_TEX_WIDTH(view
->texture
->width0
- 1);
1006 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD1
] =
1007 S_038004_TEX_HEIGHT(view
->texture
->height0
- 1) |
1008 S_038004_TEX_DEPTH(view
->texture
->depth0
- 1) |
1009 S_038004_DATA_FORMAT(format
);
1010 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD2
] = 0;
1011 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD3
] = tmp
->offset
[1] >> 8;
1012 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD4
] =
1013 S_038010_FORMAT_COMP_X(r600_format_type(UTIL_FORMAT_TYPE_UNSIGNED
)) |
1014 S_038010_FORMAT_COMP_Y(r600_format_type(UTIL_FORMAT_TYPE_UNSIGNED
)) |
1015 S_038010_FORMAT_COMP_Z(r600_format_type(UTIL_FORMAT_TYPE_UNSIGNED
)) |
1016 S_038010_FORMAT_COMP_W(r600_format_type(UTIL_FORMAT_TYPE_UNSIGNED
)) |
1017 S_038010_NUM_FORMAT_ALL(V_038010_SQ_NUM_FORMAT_NORM
) |
1018 S_038010_SRF_MODE_ALL(V_038010_SFR_MODE_NO_ZERO
) |
1019 S_038010_REQUEST_SIZE(1) |
1020 S_038010_DST_SEL_X(r600_tex_swizzle(view
->swizzle_r
)) |
1021 S_038010_DST_SEL_Y(r600_tex_swizzle(view
->swizzle_g
)) |
1022 S_038010_DST_SEL_Z(r600_tex_swizzle(view
->swizzle_b
)) |
1023 S_038010_DST_SEL_W(r600_tex_swizzle(view
->swizzle_a
)) |
1024 S_038010_BASE_LEVEL(view
->first_level
);
1025 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD5
] =
1026 S_038014_LAST_LEVEL(view
->last_level
) |
1027 S_038014_BASE_ARRAY(0) |
1028 S_038014_LAST_ARRAY(0);
1029 rstate
->states
[R600_PS_RESOURCE__RESOURCE0_WORD6
] =
1030 S_038018_TYPE(V_038010_SQ_TEX_VTX_VALID_TEXTURE
);
1031 if (radeon_state_pm4(rstate
)) {
1032 radeon_state_decref(rstate
);
1038 int r600_context_hw_states(struct r600_context
*rctx
)
1043 /* free previous TODO determine what need to be updated, what
1046 //radeon_state_decref(rctx->hw_states.config);
1047 //radeon_state_decref(rctx->hw_states.cb_cntl);
1048 radeon_state_decref(rctx
->hw_states
.db
);
1049 radeon_state_decref(rctx
->hw_states
.rasterizer
);
1050 radeon_state_decref(rctx
->hw_states
.scissor
);
1051 radeon_state_decref(rctx
->hw_states
.dsa
);
1052 radeon_state_decref(rctx
->hw_states
.blend
);
1053 radeon_state_decref(rctx
->hw_states
.viewport
);
1054 radeon_state_decref(rctx
->hw_states
.cb0
);
1055 for (i
= 0; i
< rctx
->hw_states
.ps_nresource
; i
++) {
1056 radeon_state_decref(rctx
->hw_states
.ps_resource
[i
]);
1057 rctx
->hw_states
.ps_resource
[i
] = NULL
;
1059 rctx
->hw_states
.ps_nresource
= 0;
1060 for (i
= 0; i
< rctx
->hw_states
.ps_nsampler
; i
++) {
1061 radeon_state_decref(rctx
->hw_states
.ps_sampler
[i
]);
1062 rctx
->hw_states
.ps_sampler
[i
] = NULL
;
1064 rctx
->hw_states
.ps_nsampler
= 0;
1066 /* build new states */
1067 rctx
->hw_states
.rasterizer
= r600_rasterizer(rctx
);
1068 rctx
->hw_states
.scissor
= r600_scissor(rctx
);
1069 rctx
->hw_states
.dsa
= r600_dsa(rctx
);
1070 rctx
->hw_states
.blend
= r600_blend(rctx
);
1071 rctx
->hw_states
.viewport
= r600_viewport(rctx
);
1072 rctx
->hw_states
.cb0
= r600_cb0(rctx
);
1073 rctx
->hw_states
.db
= r600_db(rctx
);
1074 for (i
= 0; i
< rctx
->ps_nsampler
; i
++) {
1075 if (rctx
->ps_sampler
[i
]) {
1076 rctx
->hw_states
.ps_sampler
[i
] = r600_sampler(rctx
,
1077 &rctx
->ps_sampler
[i
]->state
.sampler
,
1078 R600_PS_SAMPLER
+ i
);
1081 rctx
->hw_states
.ps_nsampler
= rctx
->ps_nsampler
;
1082 for (i
= 0; i
< rctx
->ps_nsampler_view
; i
++) {
1083 if (rctx
->ps_sampler_view
[i
]) {
1084 rctx
->hw_states
.ps_resource
[i
] = r600_resource(rctx
,
1085 &rctx
->ps_sampler_view
[i
]->state
.sampler_view
,
1086 R600_PS_RESOURCE
+ i
);
1089 rctx
->hw_states
.ps_nresource
= rctx
->ps_nsampler_view
;
1092 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.db
);
1095 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.rasterizer
);
1098 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.scissor
);
1101 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.dsa
);
1104 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.blend
);
1107 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.viewport
);
1110 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.cb0
);
1113 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.config
);
1116 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.cb_cntl
);
1119 for (i
= 0; i
< rctx
->hw_states
.ps_nresource
; i
++) {
1120 if (rctx
->hw_states
.ps_resource
[i
]) {
1121 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.ps_resource
[i
]);
1126 for (i
= 0; i
< rctx
->hw_states
.ps_nsampler
; i
++) {
1127 if (rctx
->hw_states
.ps_sampler
[i
]) {
1128 r
= radeon_draw_set(rctx
->draw
, rctx
->hw_states
.ps_sampler
[i
]);