2 * Copyright 2010 Red Hat Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Authors: Dave Airlie <airlied@redhat.com>
25 * Jerome Glisse <jglisse@redhat.com>
27 #include "util/u_blitter.h"
28 #include "util/u_memory.h"
29 #include "util/u_format.h"
30 #include "pipebuffer/pb_buffer.h"
31 #include "pipe/p_shader_tokens.h"
32 #include "tgsi/tgsi_parse.h"
33 #include "r600_formats.h"
34 #include "r600_pipe.h"
37 static bool r600_conv_pipe_prim(unsigned pprim
, unsigned *prim
)
39 static const int prim_conv
[] = {
40 V_008958_DI_PT_POINTLIST
,
41 V_008958_DI_PT_LINELIST
,
42 V_008958_DI_PT_LINELOOP
,
43 V_008958_DI_PT_LINESTRIP
,
44 V_008958_DI_PT_TRILIST
,
45 V_008958_DI_PT_TRISTRIP
,
46 V_008958_DI_PT_TRIFAN
,
47 V_008958_DI_PT_QUADLIST
,
48 V_008958_DI_PT_QUADSTRIP
,
49 V_008958_DI_PT_POLYGON
,
56 *prim
= prim_conv
[pprim
];
58 fprintf(stderr
, "%s:%d unsupported %d\n", __func__
, __LINE__
, pprim
);
64 /* common state between evergreen and r600 */
65 void r600_bind_blend_state(struct pipe_context
*ctx
, void *state
)
67 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
68 struct r600_pipe_blend
*blend
= (struct r600_pipe_blend
*)state
;
69 struct r600_pipe_state
*rstate
;
73 rstate
= &blend
->rstate
;
74 rctx
->states
[rstate
->id
] = rstate
;
75 rctx
->cb_target_mask
= blend
->cb_target_mask
;
76 r600_context_pipe_state_set(&rctx
->ctx
, rstate
);
79 void r600_bind_dsa_state(struct pipe_context
*ctx
, void *state
)
81 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
82 struct r600_pipe_dsa
*dsa
= state
;
83 struct r600_pipe_state
*rstate
;
87 rstate
= &dsa
->rstate
;
88 rctx
->states
[rstate
->id
] = rstate
;
89 rctx
->alpha_ref
= dsa
->alpha_ref
;
90 rctx
->alpha_ref_dirty
= true;
91 r600_context_pipe_state_set(&rctx
->ctx
, rstate
);
94 void r600_bind_rs_state(struct pipe_context
*ctx
, void *state
)
96 struct r600_pipe_rasterizer
*rs
= (struct r600_pipe_rasterizer
*)state
;
97 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
102 rctx
->clamp_vertex_color
= rs
->clamp_vertex_color
;
103 rctx
->clamp_fragment_color
= rs
->clamp_fragment_color
;
105 rctx
->sprite_coord_enable
= rs
->sprite_coord_enable
;
106 rctx
->two_side
= rs
->two_side
;
108 rctx
->rasterizer
= rs
;
110 rctx
->states
[rs
->rstate
.id
] = &rs
->rstate
;
111 r600_context_pipe_state_set(&rctx
->ctx
, &rs
->rstate
);
113 if (rctx
->chip_class
>= EVERGREEN
) {
114 evergreen_polygon_offset_update(rctx
);
116 r600_polygon_offset_update(rctx
);
120 void r600_delete_rs_state(struct pipe_context
*ctx
, void *state
)
122 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
123 struct r600_pipe_rasterizer
*rs
= (struct r600_pipe_rasterizer
*)state
;
125 if (rctx
->rasterizer
== rs
) {
126 rctx
->rasterizer
= NULL
;
128 if (rctx
->states
[rs
->rstate
.id
] == &rs
->rstate
) {
129 rctx
->states
[rs
->rstate
.id
] = NULL
;
134 void r600_sampler_view_destroy(struct pipe_context
*ctx
,
135 struct pipe_sampler_view
*state
)
137 struct r600_pipe_sampler_view
*resource
= (struct r600_pipe_sampler_view
*)state
;
139 pipe_resource_reference(&state
->texture
, NULL
);
143 void r600_delete_state(struct pipe_context
*ctx
, void *state
)
145 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
146 struct r600_pipe_state
*rstate
= (struct r600_pipe_state
*)state
;
148 if (rctx
->states
[rstate
->id
] == rstate
) {
149 rctx
->states
[rstate
->id
] = NULL
;
151 for (int i
= 0; i
< rstate
->nregs
; i
++) {
152 pipe_resource_reference((struct pipe_resource
**)&rstate
->regs
[i
].bo
, NULL
);
157 void r600_bind_vertex_elements(struct pipe_context
*ctx
, void *state
)
159 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
160 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
162 rctx
->vertex_elements
= v
;
164 u_vbuf_bind_vertex_elements(rctx
->vbuf_mgr
, state
,
167 rctx
->states
[v
->rstate
.id
] = &v
->rstate
;
168 r600_context_pipe_state_set(&rctx
->ctx
, &v
->rstate
);
172 void r600_delete_vertex_element(struct pipe_context
*ctx
, void *state
)
174 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
175 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
177 if (rctx
->states
[v
->rstate
.id
] == &v
->rstate
) {
178 rctx
->states
[v
->rstate
.id
] = NULL
;
180 if (rctx
->vertex_elements
== state
)
181 rctx
->vertex_elements
= NULL
;
183 pipe_resource_reference((struct pipe_resource
**)&v
->fetch_shader
, NULL
);
184 u_vbuf_destroy_vertex_elements(rctx
->vbuf_mgr
, v
->vmgr_elements
);
189 void r600_set_index_buffer(struct pipe_context
*ctx
,
190 const struct pipe_index_buffer
*ib
)
192 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
194 u_vbuf_set_index_buffer(rctx
->vbuf_mgr
, ib
);
197 void r600_set_vertex_buffers(struct pipe_context
*ctx
, unsigned count
,
198 const struct pipe_vertex_buffer
*buffers
)
200 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
204 for (i
= 0; i
< count
; i
++) {
205 if (!buffers
[i
].buffer
) {
206 if (rctx
->chip_class
>= EVERGREEN
) {
207 evergreen_context_pipe_state_set_fs_resource(&rctx
->ctx
, NULL
, i
);
209 r600_context_pipe_state_set_fs_resource(&rctx
->ctx
, NULL
, i
);
213 for (; i
< rctx
->vbuf_mgr
->nr_real_vertex_buffers
; i
++) {
214 if (rctx
->chip_class
>= EVERGREEN
) {
215 evergreen_context_pipe_state_set_fs_resource(&rctx
->ctx
, NULL
, i
);
217 r600_context_pipe_state_set_fs_resource(&rctx
->ctx
, NULL
, i
);
221 u_vbuf_set_vertex_buffers(rctx
->vbuf_mgr
, count
, buffers
);
224 void *r600_create_vertex_elements(struct pipe_context
*ctx
,
226 const struct pipe_vertex_element
*elements
)
228 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
229 struct r600_vertex_element
*v
= CALLOC_STRUCT(r600_vertex_element
);
237 u_vbuf_create_vertex_elements(rctx
->vbuf_mgr
, count
,
238 elements
, v
->elements
);
240 if (r600_vertex_elements_build_fetch_shader(rctx
, v
)) {
248 void *r600_create_shader_state(struct pipe_context
*ctx
,
249 const struct pipe_shader_state
*state
)
251 struct r600_pipe_shader
*shader
= CALLOC_STRUCT(r600_pipe_shader
);
254 shader
->tokens
= tgsi_dup_tokens(state
->tokens
);
255 shader
->so
= state
->stream_output
;
257 r
= r600_pipe_shader_create(ctx
, shader
);
264 void r600_bind_ps_shader(struct pipe_context
*ctx
, void *state
)
266 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
268 /* TODO delete old shader */
269 rctx
->ps_shader
= (struct r600_pipe_shader
*)state
;
271 r600_context_pipe_state_set(&rctx
->ctx
, &rctx
->ps_shader
->rstate
);
273 if (rctx
->ps_shader
&& rctx
->vs_shader
) {
274 r600_adjust_gprs(rctx
);
278 void r600_bind_vs_shader(struct pipe_context
*ctx
, void *state
)
280 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
282 /* TODO delete old shader */
283 rctx
->vs_shader
= (struct r600_pipe_shader
*)state
;
285 r600_context_pipe_state_set(&rctx
->ctx
, &rctx
->vs_shader
->rstate
);
287 if (rctx
->ps_shader
&& rctx
->vs_shader
) {
288 r600_adjust_gprs(rctx
);
292 void r600_delete_ps_shader(struct pipe_context
*ctx
, void *state
)
294 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
295 struct r600_pipe_shader
*shader
= (struct r600_pipe_shader
*)state
;
297 if (rctx
->ps_shader
== shader
) {
298 rctx
->ps_shader
= NULL
;
301 free(shader
->tokens
);
302 r600_pipe_shader_destroy(ctx
, shader
);
306 void r600_delete_vs_shader(struct pipe_context
*ctx
, void *state
)
308 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
309 struct r600_pipe_shader
*shader
= (struct r600_pipe_shader
*)state
;
311 if (rctx
->vs_shader
== shader
) {
312 rctx
->vs_shader
= NULL
;
315 free(shader
->tokens
);
316 r600_pipe_shader_destroy(ctx
, shader
);
320 static void r600_update_alpha_ref(struct r600_pipe_context
*rctx
)
323 struct r600_pipe_state rstate
;
325 alpha_ref
= rctx
->alpha_ref
;
327 if (rctx
->export_16bpc
)
328 alpha_ref
&= ~0x1FFF;
329 r600_pipe_state_add_reg(&rstate
, R_028438_SX_ALPHA_REF
, alpha_ref
, 0xFFFFFFFF, NULL
, 0);
331 r600_context_pipe_state_set(&rctx
->ctx
, &rstate
);
332 rctx
->alpha_ref_dirty
= false;
335 void r600_set_constant_buffer(struct pipe_context
*ctx
, uint shader
, uint index
,
336 struct pipe_resource
*buffer
)
338 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
339 struct r600_resource
*rbuffer
= r600_resource(buffer
);
340 struct r600_pipe_resource_state
*rstate
;
344 /* Note that the state tracker can unbind constant buffers by
347 if (buffer
== NULL
) {
351 r600_upload_const_buffer(rctx
, &rbuffer
, &offset
);
352 va_offset
= r600_resource_va(ctx
->screen
, (void*)rbuffer
);
357 case PIPE_SHADER_VERTEX
:
358 rctx
->vs_const_buffer
.nregs
= 0;
359 r600_pipe_state_add_reg(&rctx
->vs_const_buffer
,
360 R_028180_ALU_CONST_BUFFER_SIZE_VS_0
,
361 ALIGN_DIVUP(buffer
->width0
>> 4, 16),
362 0xFFFFFFFF, NULL
, 0);
363 r600_pipe_state_add_reg(&rctx
->vs_const_buffer
,
364 R_028980_ALU_CONST_CACHE_VS_0
,
365 va_offset
, 0xFFFFFFFF, rbuffer
, RADEON_USAGE_READ
);
366 r600_context_pipe_state_set(&rctx
->ctx
, &rctx
->vs_const_buffer
);
368 rstate
= &rctx
->vs_const_buffer_resource
[index
];
370 if (rctx
->chip_class
>= EVERGREEN
) {
371 evergreen_pipe_init_buffer_resource(rctx
, rstate
);
373 r600_pipe_init_buffer_resource(rctx
, rstate
);
377 if (rctx
->chip_class
>= EVERGREEN
) {
378 evergreen_pipe_mod_buffer_resource(ctx
, rstate
, rbuffer
, offset
, 16, RADEON_USAGE_READ
);
379 evergreen_context_pipe_state_set_vs_resource(&rctx
->ctx
, rstate
, index
);
381 r600_pipe_mod_buffer_resource(rstate
, rbuffer
, offset
, 16, RADEON_USAGE_READ
);
382 r600_context_pipe_state_set_vs_resource(&rctx
->ctx
, rstate
, index
);
385 case PIPE_SHADER_FRAGMENT
:
386 rctx
->ps_const_buffer
.nregs
= 0;
387 r600_pipe_state_add_reg(&rctx
->ps_const_buffer
,
388 R_028140_ALU_CONST_BUFFER_SIZE_PS_0
,
389 ALIGN_DIVUP(buffer
->width0
>> 4, 16),
390 0xFFFFFFFF, NULL
, 0);
391 r600_pipe_state_add_reg(&rctx
->ps_const_buffer
,
392 R_028940_ALU_CONST_CACHE_PS_0
,
393 va_offset
, 0xFFFFFFFF, rbuffer
, RADEON_USAGE_READ
);
394 r600_context_pipe_state_set(&rctx
->ctx
, &rctx
->ps_const_buffer
);
396 rstate
= &rctx
->ps_const_buffer_resource
[index
];
398 if (rctx
->chip_class
>= EVERGREEN
) {
399 evergreen_pipe_init_buffer_resource(rctx
, rstate
);
401 r600_pipe_init_buffer_resource(rctx
, rstate
);
404 if (rctx
->chip_class
>= EVERGREEN
) {
405 evergreen_pipe_mod_buffer_resource(ctx
, rstate
, rbuffer
, offset
, 16, RADEON_USAGE_READ
);
406 evergreen_context_pipe_state_set_ps_resource(&rctx
->ctx
, rstate
, index
);
408 r600_pipe_mod_buffer_resource(rstate
, rbuffer
, offset
, 16, RADEON_USAGE_READ
);
409 r600_context_pipe_state_set_ps_resource(&rctx
->ctx
, rstate
, index
);
413 R600_ERR("unsupported %d\n", shader
);
417 if (buffer
!= &rbuffer
->b
.b
.b
)
418 pipe_resource_reference((struct pipe_resource
**)&rbuffer
, NULL
);
421 struct pipe_stream_output_target
*
422 r600_create_so_target(struct pipe_context
*ctx
,
423 struct pipe_resource
*buffer
,
424 unsigned buffer_offset
,
425 unsigned buffer_size
)
427 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
428 struct r600_so_target
*t
;
431 t
= CALLOC_STRUCT(r600_so_target
);
436 t
->b
.reference
.count
= 1;
438 pipe_resource_reference(&t
->b
.buffer
, buffer
);
439 t
->b
.buffer_offset
= buffer_offset
;
440 t
->b
.buffer_size
= buffer_size
;
442 t
->filled_size
= (struct r600_resource
*)
443 pipe_buffer_create(ctx
->screen
, PIPE_BIND_CUSTOM
, PIPE_USAGE_STATIC
, 4);
444 ptr
= rctx
->ws
->buffer_map(t
->filled_size
->buf
, rctx
->ctx
.cs
, PIPE_TRANSFER_WRITE
);
445 memset(ptr
, 0, t
->filled_size
->buf
->size
);
446 rctx
->ws
->buffer_unmap(t
->filled_size
->buf
);
451 void r600_so_target_destroy(struct pipe_context
*ctx
,
452 struct pipe_stream_output_target
*target
)
454 struct r600_so_target
*t
= (struct r600_so_target
*)target
;
455 pipe_resource_reference(&t
->b
.buffer
, NULL
);
456 pipe_resource_reference((struct pipe_resource
**)&t
->filled_size
, NULL
);
460 void r600_set_so_targets(struct pipe_context
*ctx
,
461 unsigned num_targets
,
462 struct pipe_stream_output_target
**targets
,
463 unsigned append_bitmask
)
465 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
468 /* Stop streamout. */
469 if (rctx
->ctx
.num_so_targets
) {
470 r600_context_streamout_end(&rctx
->ctx
);
473 /* Set the new targets. */
474 for (i
= 0; i
< num_targets
; i
++) {
475 pipe_so_target_reference((struct pipe_stream_output_target
**)&rctx
->ctx
.so_targets
[i
], targets
[i
]);
477 for (; i
< rctx
->ctx
.num_so_targets
; i
++) {
478 pipe_so_target_reference((struct pipe_stream_output_target
**)&rctx
->ctx
.so_targets
[i
], NULL
);
481 rctx
->ctx
.num_so_targets
= num_targets
;
482 rctx
->ctx
.streamout_start
= num_targets
!= 0;
483 rctx
->ctx
.streamout_append_bitmask
= append_bitmask
;
486 static void r600_vertex_buffer_update(struct r600_pipe_context
*rctx
)
488 struct r600_pipe_resource_state
*rstate
;
489 struct r600_resource
*rbuffer
;
490 struct pipe_vertex_buffer
*vertex_buffer
;
491 unsigned i
, count
, offset
;
493 if (rctx
->vertex_elements
->vbuffer_need_offset
) {
494 /* one resource per vertex elements */
495 count
= rctx
->vertex_elements
->count
;
497 /* bind vertex buffer once */
498 count
= rctx
->vbuf_mgr
->nr_real_vertex_buffers
;
501 for (i
= 0 ; i
< count
; i
++) {
502 rstate
= &rctx
->fs_resource
[i
];
504 if (rctx
->vertex_elements
->vbuffer_need_offset
) {
505 /* one resource per vertex elements */
506 unsigned vbuffer_index
;
507 vbuffer_index
= rctx
->vertex_elements
->elements
[i
].vertex_buffer_index
;
508 vertex_buffer
= &rctx
->vbuf_mgr
->real_vertex_buffer
[vbuffer_index
];
509 rbuffer
= (struct r600_resource
*)vertex_buffer
->buffer
;
510 offset
= rctx
->vertex_elements
->vbuffer_offset
[i
];
512 /* bind vertex buffer once */
513 vertex_buffer
= &rctx
->vbuf_mgr
->real_vertex_buffer
[i
];
514 rbuffer
= (struct r600_resource
*)vertex_buffer
->buffer
;
517 if (vertex_buffer
== NULL
|| rbuffer
== NULL
)
519 offset
+= vertex_buffer
->buffer_offset
;
522 if (rctx
->chip_class
>= EVERGREEN
) {
523 evergreen_pipe_init_buffer_resource(rctx
, rstate
);
525 r600_pipe_init_buffer_resource(rctx
, rstate
);
529 if (rctx
->chip_class
>= EVERGREEN
) {
530 evergreen_pipe_mod_buffer_resource(&rctx
->context
, rstate
, rbuffer
, offset
, vertex_buffer
->stride
, RADEON_USAGE_READ
);
531 evergreen_context_pipe_state_set_fs_resource(&rctx
->ctx
, rstate
, i
);
533 r600_pipe_mod_buffer_resource(rstate
, rbuffer
, offset
, vertex_buffer
->stride
, RADEON_USAGE_READ
);
534 r600_context_pipe_state_set_fs_resource(&rctx
->ctx
, rstate
, i
);
539 static int r600_shader_rebuild(struct pipe_context
* ctx
, struct r600_pipe_shader
* shader
)
541 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
544 r600_pipe_shader_destroy(ctx
, shader
);
545 r
= r600_pipe_shader_create(ctx
, shader
);
549 r600_context_pipe_state_set(&rctx
->ctx
, &shader
->rstate
);
554 static void r600_update_derived_state(struct r600_pipe_context
*rctx
)
556 struct pipe_context
* ctx
= (struct pipe_context
*)rctx
;
557 struct r600_pipe_state rstate
;
558 unsigned user_clip_plane_enable
;
559 unsigned clip_dist_enable
;
561 if (rctx
->vs_shader
->shader
.clip_dist_write
|| rctx
->vs_shader
->shader
.vs_prohibit_ucps
)
562 user_clip_plane_enable
= 0;
564 user_clip_plane_enable
= rctx
->rasterizer
->clip_plane_enable
& 0x3F;
566 clip_dist_enable
= rctx
->rasterizer
->clip_plane_enable
& rctx
->vs_shader
->shader
.clip_dist_write
& 0xFF;
569 if (user_clip_plane_enable
!= rctx
->user_clip_plane_enable
) {
570 r600_pipe_state_add_reg(&rstate
, R_028810_PA_CL_CLIP_CNTL
, user_clip_plane_enable
, 0x3F, NULL
, 0);
571 rctx
->user_clip_plane_enable
= user_clip_plane_enable
;
574 if (clip_dist_enable
!= rctx
->clip_dist_enable
) {
575 r600_pipe_state_add_reg(&rstate
, R_02881C_PA_CL_VS_OUT_CNTL
, clip_dist_enable
, 0xFF, NULL
, 0);
576 rctx
->clip_dist_enable
= clip_dist_enable
;
580 r600_context_pipe_state_set(&rctx
->ctx
, &rstate
);
582 if (!rctx
->blitter
->running
) {
583 if (rctx
->have_depth_fb
|| rctx
->have_depth_texture
)
584 r600_flush_depth_textures(rctx
);
587 if (rctx
->chip_class
< EVERGREEN
) {
588 r600_update_sampler_states(rctx
);
591 if (rctx
->vs_shader
->shader
.clamp_color
!= rctx
->clamp_vertex_color
) {
592 r600_shader_rebuild(&rctx
->context
, rctx
->vs_shader
);
595 if ((rctx
->ps_shader
->shader
.clamp_color
!= rctx
->clamp_fragment_color
) ||
596 (rctx
->ps_shader
->shader
.two_side
!= rctx
->two_side
) ||
597 ((rctx
->chip_class
>= EVERGREEN
) && rctx
->ps_shader
->shader
.fs_write_all
&&
598 (rctx
->ps_shader
->shader
.nr_cbufs
!= rctx
->nr_cbufs
))) {
599 r600_shader_rebuild(&rctx
->context
, rctx
->ps_shader
);
602 if (rctx
->alpha_ref_dirty
) {
603 r600_update_alpha_ref(rctx
);
606 if (rctx
->ps_shader
&& rctx
->sprite_coord_enable
&&
607 (rctx
->ps_shader
->sprite_coord_enable
!= rctx
->sprite_coord_enable
)) {
609 if (rctx
->chip_class
>= EVERGREEN
)
610 evergreen_pipe_shader_ps(ctx
, rctx
->ps_shader
);
612 r600_pipe_shader_ps(ctx
, rctx
->ps_shader
);
614 r600_context_pipe_state_set(&rctx
->ctx
, &rctx
->ps_shader
->rstate
);
619 void r600_draw_vbo(struct pipe_context
*ctx
, const struct pipe_draw_info
*dinfo
)
621 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
622 struct pipe_draw_info info
= *dinfo
;
623 struct r600_draw rdraw
= {};
624 struct pipe_index_buffer ib
= {};
625 unsigned prim
, mask
, ls_mask
= 0;
627 if ((!info
.count
&& (info
.indexed
|| !info
.count_from_stream_output
)) ||
628 (info
.indexed
&& !rctx
->vbuf_mgr
->index_buffer
.buffer
) ||
629 !r600_conv_pipe_prim(info
.mode
, &prim
)) {
633 if (!rctx
->ps_shader
|| !rctx
->vs_shader
)
636 r600_update_derived_state(rctx
);
638 u_vbuf_draw_begin(rctx
->vbuf_mgr
, &info
);
639 r600_vertex_buffer_update(rctx
);
641 rdraw
.vgt_num_indices
= info
.count
;
642 rdraw
.vgt_num_instances
= info
.instance_count
;
645 /* Initialize the index buffer struct. */
646 pipe_resource_reference(&ib
.buffer
, rctx
->vbuf_mgr
->index_buffer
.buffer
);
647 ib
.index_size
= rctx
->vbuf_mgr
->index_buffer
.index_size
;
648 ib
.offset
= rctx
->vbuf_mgr
->index_buffer
.offset
+ info
.start
* ib
.index_size
;
650 /* Translate or upload, if needed. */
651 r600_translate_index_buffer(rctx
, &ib
, info
.count
);
653 if (u_vbuf_resource(ib
.buffer
)->user_ptr
) {
654 r600_upload_index_buffer(rctx
, &ib
, info
.count
);
657 /* Initialize the r600_draw struct with index buffer info. */
658 if (ib
.index_size
== 4) {
659 rdraw
.vgt_index_type
= VGT_INDEX_32
|
660 (R600_BIG_ENDIAN
? VGT_DMA_SWAP_32_BIT
: 0);
662 rdraw
.vgt_index_type
= VGT_INDEX_16
|
663 (R600_BIG_ENDIAN
? VGT_DMA_SWAP_16_BIT
: 0);
665 rdraw
.indices
= (struct r600_resource
*)ib
.buffer
;
666 rdraw
.indices_bo_offset
= ib
.offset
;
667 rdraw
.vgt_draw_initiator
= V_0287F0_DI_SRC_SEL_DMA
;
669 info
.index_bias
= info
.start
;
670 rdraw
.vgt_draw_initiator
= V_0287F0_DI_SRC_SEL_AUTO_INDEX
;
671 if (info
.count_from_stream_output
) {
672 rdraw
.vgt_draw_initiator
|= S_0287F0_USE_OPAQUE(1);
674 r600_context_draw_opaque_count(&rctx
->ctx
, (struct r600_so_target
*)info
.count_from_stream_output
);
678 rctx
->ctx
.vs_so_stride_in_dw
= rctx
->vs_shader
->so
.stride
;
680 mask
= (1ULL << ((unsigned)rctx
->framebuffer
.nr_cbufs
* 4)) - 1;
682 if (rctx
->vgt
.id
!= R600_PIPE_STATE_VGT
) {
683 rctx
->vgt
.id
= R600_PIPE_STATE_VGT
;
685 r600_pipe_state_add_reg(&rctx
->vgt
, R_008958_VGT_PRIMITIVE_TYPE
, prim
, 0xFFFFFFFF, NULL
, 0);
686 r600_pipe_state_add_reg(&rctx
->vgt
, R_028238_CB_TARGET_MASK
, rctx
->cb_target_mask
& mask
, 0xFFFFFFFF, NULL
, 0);
687 r600_pipe_state_add_reg(&rctx
->vgt
, R_028400_VGT_MAX_VTX_INDX
, ~0, 0xFFFFFFFF, NULL
, 0);
688 r600_pipe_state_add_reg(&rctx
->vgt
, R_028404_VGT_MIN_VTX_INDX
, 0, 0xFFFFFFFF, NULL
, 0);
689 r600_pipe_state_add_reg(&rctx
->vgt
, R_028408_VGT_INDX_OFFSET
, info
.index_bias
, 0xFFFFFFFF, NULL
, 0);
690 r600_pipe_state_add_reg(&rctx
->vgt
, R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX
, info
.restart_index
, 0xFFFFFFFF, NULL
, 0);
691 r600_pipe_state_add_reg(&rctx
->vgt
, R_028A94_VGT_MULTI_PRIM_IB_RESET_EN
, info
.primitive_restart
, 0xFFFFFFFF, NULL
, 0);
692 r600_pipe_state_add_reg(&rctx
->vgt
, R_03CFF0_SQ_VTX_BASE_VTX_LOC
, 0, 0xFFFFFFFF, NULL
, 0);
693 r600_pipe_state_add_reg(&rctx
->vgt
, R_03CFF4_SQ_VTX_START_INST_LOC
, info
.start_instance
, 0xFFFFFFFF, NULL
, 0);
694 r600_pipe_state_add_reg(&rctx
->vgt
, R_028A0C_PA_SC_LINE_STIPPLE
,
696 S_028A0C_AUTO_RESET_CNTL(3), NULL
, 0);
697 r600_pipe_state_add_reg(&rctx
->vgt
, R_028814_PA_SU_SC_MODE_CNTL
,
699 S_028814_PROVOKING_VTX_LAST(1), NULL
, 0);
703 r600_pipe_state_mod_reg(&rctx
->vgt
, prim
);
704 r600_pipe_state_mod_reg(&rctx
->vgt
, rctx
->cb_target_mask
& mask
);
705 r600_pipe_state_mod_reg(&rctx
->vgt
, ~0);
706 r600_pipe_state_mod_reg(&rctx
->vgt
, 0);
707 r600_pipe_state_mod_reg(&rctx
->vgt
, info
.index_bias
);
708 r600_pipe_state_mod_reg(&rctx
->vgt
, info
.restart_index
);
709 r600_pipe_state_mod_reg(&rctx
->vgt
, info
.primitive_restart
);
710 r600_pipe_state_mod_reg(&rctx
->vgt
, 0);
711 r600_pipe_state_mod_reg(&rctx
->vgt
, info
.start_instance
);
713 if (prim
== V_008958_DI_PT_LINELIST
)
715 else if (prim
== V_008958_DI_PT_LINESTRIP
)
717 r600_pipe_state_mod_reg(&rctx
->vgt
, S_028A0C_AUTO_RESET_CNTL(ls_mask
));
719 if (info
.mode
== PIPE_PRIM_QUADS
|| info
.mode
== PIPE_PRIM_QUAD_STRIP
|| info
.mode
== PIPE_PRIM_POLYGON
) {
720 r600_pipe_state_mod_reg(&rctx
->vgt
, S_028814_PROVOKING_VTX_LAST(1));
723 r600_context_pipe_state_set(&rctx
->ctx
, &rctx
->vgt
);
725 if (rctx
->chip_class
>= EVERGREEN
) {
726 evergreen_context_draw(&rctx
->ctx
, &rdraw
);
728 r600_context_draw(&rctx
->ctx
, &rdraw
);
731 if (rctx
->framebuffer
.zsbuf
)
733 struct pipe_resource
*tex
= rctx
->framebuffer
.zsbuf
->texture
;
734 ((struct r600_resource_texture
*)tex
)->dirty_db
= TRUE
;
737 pipe_resource_reference(&ib
.buffer
, NULL
);
738 u_vbuf_draw_end(rctx
->vbuf_mgr
);
741 void _r600_pipe_state_add_reg(struct r600_context
*ctx
,
742 struct r600_pipe_state
*state
,
743 u32 offset
, u32 value
, u32 mask
,
744 u32 range_id
, u32 block_id
,
745 struct r600_resource
*bo
,
746 enum radeon_bo_usage usage
)
748 struct r600_range
*range
;
749 struct r600_block
*block
;
751 if (bo
) assert(usage
);
753 range
= &ctx
->range
[range_id
];
754 block
= range
->blocks
[block_id
];
755 state
->regs
[state
->nregs
].block
= block
;
756 state
->regs
[state
->nregs
].id
= (offset
- block
->start_offset
) >> 2;
758 state
->regs
[state
->nregs
].value
= value
;
759 state
->regs
[state
->nregs
].mask
= mask
;
760 state
->regs
[state
->nregs
].bo
= bo
;
761 state
->regs
[state
->nregs
].bo_usage
= usage
;
764 assert(state
->nregs
< R600_BLOCK_MAX_REG
);
767 void r600_pipe_state_add_reg_noblock(struct r600_pipe_state
*state
,
768 u32 offset
, u32 value
, u32 mask
,
769 struct r600_resource
*bo
,
770 enum radeon_bo_usage usage
)
772 if (bo
) assert(usage
);
774 state
->regs
[state
->nregs
].id
= offset
;
775 state
->regs
[state
->nregs
].block
= NULL
;
776 state
->regs
[state
->nregs
].value
= value
;
777 state
->regs
[state
->nregs
].mask
= mask
;
778 state
->regs
[state
->nregs
].bo
= bo
;
779 state
->regs
[state
->nregs
].bo_usage
= usage
;
782 assert(state
->nregs
< R600_BLOCK_MAX_REG
);