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_hw_context_priv.h"
34 #include "radeonsi_pipe.h"
37 static void r600_emit_surface_sync(struct r600_context
*rctx
, struct r600_atom
*atom
)
39 struct radeon_winsys_cs
*cs
= rctx
->cs
;
40 struct r600_atom_surface_sync
*a
= (struct r600_atom_surface_sync
*)atom
;
42 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_SURFACE_SYNC
, 3, 0);
43 cs
->buf
[cs
->cdw
++] = a
->flush_flags
; /* CP_COHER_CNTL */
44 cs
->buf
[cs
->cdw
++] = 0xffffffff; /* CP_COHER_SIZE */
45 cs
->buf
[cs
->cdw
++] = 0; /* CP_COHER_BASE */
46 cs
->buf
[cs
->cdw
++] = 0x0000000A; /* POLL_INTERVAL */
51 static void r600_emit_r6xx_flush_and_inv(struct r600_context
*rctx
, struct r600_atom
*atom
)
53 struct radeon_winsys_cs
*cs
= rctx
->cs
;
54 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_EVENT_WRITE
, 0, 0);
55 cs
->buf
[cs
->cdw
++] = EVENT_TYPE(EVENT_TYPE_CACHE_FLUSH_AND_INV_EVENT
) | EVENT_INDEX(0);
58 static void r600_init_atom(struct r600_atom
*atom
,
59 void (*emit
)(struct r600_context
*ctx
, struct r600_atom
*state
),
61 enum r600_atom_flags flags
)
64 atom
->num_dw
= num_dw
;
68 void r600_init_common_atoms(struct r600_context
*rctx
)
70 r600_init_atom(&rctx
->atom_surface_sync
.atom
, r600_emit_surface_sync
, 5, EMIT_EARLY
);
71 r600_init_atom(&rctx
->atom_r6xx_flush_and_inv
, r600_emit_r6xx_flush_and_inv
, 2, EMIT_EARLY
);
74 unsigned r600_get_cb_flush_flags(struct r600_context
*rctx
)
78 if (rctx
->framebuffer
.nr_cbufs
) {
79 flags
|= S_0085F0_CB_ACTION_ENA(1) |
80 (((1 << rctx
->framebuffer
.nr_cbufs
) - 1) << S_0085F0_CB0_DEST_BASE_ENA_SHIFT
);
86 void r600_texture_barrier(struct pipe_context
*ctx
)
88 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
90 rctx
->atom_surface_sync
.flush_flags
|= S_0085F0_TC_ACTION_ENA(1) | r600_get_cb_flush_flags(rctx
);
91 r600_atom_dirty(rctx
, &rctx
->atom_surface_sync
.atom
);
94 static bool r600_conv_pipe_prim(unsigned pprim
, unsigned *prim
)
96 static const int prim_conv
[] = {
97 V_008958_DI_PT_POINTLIST
,
98 V_008958_DI_PT_LINELIST
,
99 V_008958_DI_PT_LINELOOP
,
100 V_008958_DI_PT_LINESTRIP
,
101 V_008958_DI_PT_TRILIST
,
102 V_008958_DI_PT_TRISTRIP
,
103 V_008958_DI_PT_TRIFAN
,
104 V_008958_DI_PT_QUADLIST
,
105 V_008958_DI_PT_QUADSTRIP
,
106 V_008958_DI_PT_POLYGON
,
113 *prim
= prim_conv
[pprim
];
115 fprintf(stderr
, "%s:%d unsupported %d\n", __func__
, __LINE__
, pprim
);
121 /* common state between evergreen and r600 */
122 void r600_bind_blend_state(struct pipe_context
*ctx
, void *state
)
124 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
125 struct r600_pipe_blend
*blend
= (struct r600_pipe_blend
*)state
;
126 struct r600_pipe_state
*rstate
;
130 rstate
= &blend
->rstate
;
131 rctx
->states
[rstate
->id
] = rstate
;
132 rctx
->cb_target_mask
= blend
->cb_target_mask
;
133 rctx
->cb_color_control
= blend
->cb_color_control
;
135 r600_context_pipe_state_set(rctx
, rstate
);
138 static void r600_set_stencil_ref(struct pipe_context
*ctx
,
139 const struct r600_stencil_ref
*state
)
141 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
142 struct r600_pipe_state
*rstate
= CALLOC_STRUCT(r600_pipe_state
);
147 rstate
->id
= R600_PIPE_STATE_STENCIL_REF
;
148 r600_pipe_state_add_reg(rstate
,
149 R_028430_DB_STENCILREFMASK
,
150 S_028430_STENCILTESTVAL(state
->ref_value
[0]) |
151 S_028430_STENCILMASK(state
->valuemask
[0]) |
152 S_028430_STENCILWRITEMASK(state
->writemask
[0]),
154 r600_pipe_state_add_reg(rstate
,
155 R_028434_DB_STENCILREFMASK_BF
,
156 S_028434_STENCILTESTVAL_BF(state
->ref_value
[1]) |
157 S_028434_STENCILMASK_BF(state
->valuemask
[1]) |
158 S_028434_STENCILWRITEMASK_BF(state
->writemask
[1]),
161 free(rctx
->states
[R600_PIPE_STATE_STENCIL_REF
]);
162 rctx
->states
[R600_PIPE_STATE_STENCIL_REF
] = rstate
;
163 r600_context_pipe_state_set(rctx
, rstate
);
166 void r600_set_pipe_stencil_ref(struct pipe_context
*ctx
,
167 const struct pipe_stencil_ref
*state
)
169 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
170 struct r600_pipe_dsa
*dsa
= (struct r600_pipe_dsa
*)rctx
->states
[R600_PIPE_STATE_DSA
];
171 struct r600_stencil_ref ref
;
173 rctx
->stencil_ref
= *state
;
178 ref
.ref_value
[0] = state
->ref_value
[0];
179 ref
.ref_value
[1] = state
->ref_value
[1];
180 ref
.valuemask
[0] = dsa
->valuemask
[0];
181 ref
.valuemask
[1] = dsa
->valuemask
[1];
182 ref
.writemask
[0] = dsa
->writemask
[0];
183 ref
.writemask
[1] = dsa
->writemask
[1];
185 r600_set_stencil_ref(ctx
, &ref
);
188 void r600_bind_dsa_state(struct pipe_context
*ctx
, void *state
)
190 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
191 struct r600_pipe_dsa
*dsa
= state
;
192 struct r600_pipe_state
*rstate
;
193 struct r600_stencil_ref ref
;
197 rstate
= &dsa
->rstate
;
198 rctx
->states
[rstate
->id
] = rstate
;
199 rctx
->alpha_ref
= dsa
->alpha_ref
;
200 rctx
->alpha_ref_dirty
= true;
201 r600_context_pipe_state_set(rctx
, rstate
);
203 ref
.ref_value
[0] = rctx
->stencil_ref
.ref_value
[0];
204 ref
.ref_value
[1] = rctx
->stencil_ref
.ref_value
[1];
205 ref
.valuemask
[0] = dsa
->valuemask
[0];
206 ref
.valuemask
[1] = dsa
->valuemask
[1];
207 ref
.writemask
[0] = dsa
->writemask
[0];
208 ref
.writemask
[1] = dsa
->writemask
[1];
210 r600_set_stencil_ref(ctx
, &ref
);
213 void r600_bind_rs_state(struct pipe_context
*ctx
, void *state
)
215 struct r600_pipe_rasterizer
*rs
= (struct r600_pipe_rasterizer
*)state
;
216 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
221 rctx
->sprite_coord_enable
= rs
->sprite_coord_enable
;
222 rctx
->pa_sc_line_stipple
= rs
->pa_sc_line_stipple
;
223 rctx
->pa_su_sc_mode_cntl
= rs
->pa_su_sc_mode_cntl
;
224 rctx
->pa_cl_clip_cntl
= rs
->pa_cl_clip_cntl
;
225 rctx
->pa_cl_vs_out_cntl
= rs
->pa_cl_vs_out_cntl
;
227 rctx
->rasterizer
= rs
;
229 rctx
->states
[rs
->rstate
.id
] = &rs
->rstate
;
230 r600_context_pipe_state_set(rctx
, &rs
->rstate
);
232 if (rctx
->chip_class
>= CAYMAN
) {
233 cayman_polygon_offset_update(rctx
);
237 void r600_delete_rs_state(struct pipe_context
*ctx
, void *state
)
239 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
240 struct r600_pipe_rasterizer
*rs
= (struct r600_pipe_rasterizer
*)state
;
242 if (rctx
->rasterizer
== rs
) {
243 rctx
->rasterizer
= NULL
;
245 if (rctx
->states
[rs
->rstate
.id
] == &rs
->rstate
) {
246 rctx
->states
[rs
->rstate
.id
] = NULL
;
251 void r600_sampler_view_destroy(struct pipe_context
*ctx
,
252 struct pipe_sampler_view
*state
)
254 struct r600_pipe_sampler_view
*resource
= (struct r600_pipe_sampler_view
*)state
;
256 pipe_resource_reference(&state
->texture
, NULL
);
260 void r600_delete_state(struct pipe_context
*ctx
, void *state
)
262 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
263 struct r600_pipe_state
*rstate
= (struct r600_pipe_state
*)state
;
265 if (rctx
->states
[rstate
->id
] == rstate
) {
266 rctx
->states
[rstate
->id
] = NULL
;
268 for (int i
= 0; i
< rstate
->nregs
; i
++) {
269 pipe_resource_reference((struct pipe_resource
**)&rstate
->regs
[i
].bo
, NULL
);
274 void r600_bind_vertex_elements(struct pipe_context
*ctx
, void *state
)
276 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
277 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
279 rctx
->vertex_elements
= v
;
281 r600_inval_shader_cache(rctx
);
282 u_vbuf_bind_vertex_elements(rctx
->vbuf_mgr
, state
,
285 rctx
->states
[v
->rstate
.id
] = &v
->rstate
;
286 r600_context_pipe_state_set(rctx
, &v
->rstate
);
290 void r600_delete_vertex_element(struct pipe_context
*ctx
, void *state
)
292 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
293 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
295 if (rctx
->states
[v
->rstate
.id
] == &v
->rstate
) {
296 rctx
->states
[v
->rstate
.id
] = NULL
;
298 if (rctx
->vertex_elements
== state
)
299 rctx
->vertex_elements
= NULL
;
301 u_vbuf_destroy_vertex_elements(rctx
->vbuf_mgr
, v
->vmgr_elements
);
306 void r600_set_index_buffer(struct pipe_context
*ctx
,
307 const struct pipe_index_buffer
*ib
)
309 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
311 u_vbuf_set_index_buffer(rctx
->vbuf_mgr
, ib
);
314 void r600_set_vertex_buffers(struct pipe_context
*ctx
, unsigned count
,
315 const struct pipe_vertex_buffer
*buffers
)
317 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
319 u_vbuf_set_vertex_buffers(rctx
->vbuf_mgr
, count
, buffers
);
322 void *si_create_vertex_elements(struct pipe_context
*ctx
,
324 const struct pipe_vertex_element
*elements
)
326 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
327 struct r600_vertex_element
*v
= CALLOC_STRUCT(r600_vertex_element
);
335 u_vbuf_create_vertex_elements(rctx
->vbuf_mgr
, count
,
336 elements
, v
->elements
);
341 void *si_create_shader_state(struct pipe_context
*ctx
,
342 const struct pipe_shader_state
*state
)
344 struct si_pipe_shader
*shader
= CALLOC_STRUCT(si_pipe_shader
);
346 shader
->tokens
= tgsi_dup_tokens(state
->tokens
);
347 shader
->so
= state
->stream_output
;
352 void r600_bind_ps_shader(struct pipe_context
*ctx
, void *state
)
354 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
356 if (rctx
->ps_shader
!= state
)
357 rctx
->shader_dirty
= true;
359 /* TODO delete old shader */
360 rctx
->ps_shader
= (struct si_pipe_shader
*)state
;
362 r600_inval_shader_cache(rctx
);
363 r600_context_pipe_state_set(rctx
, &rctx
->ps_shader
->rstate
);
367 void r600_bind_vs_shader(struct pipe_context
*ctx
, void *state
)
369 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
371 if (rctx
->vs_shader
!= state
)
372 rctx
->shader_dirty
= true;
374 /* TODO delete old shader */
375 rctx
->vs_shader
= (struct si_pipe_shader
*)state
;
377 r600_inval_shader_cache(rctx
);
378 r600_context_pipe_state_set(rctx
, &rctx
->vs_shader
->rstate
);
382 void r600_delete_ps_shader(struct pipe_context
*ctx
, void *state
)
384 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
385 struct si_pipe_shader
*shader
= (struct si_pipe_shader
*)state
;
387 if (rctx
->ps_shader
== shader
) {
388 rctx
->ps_shader
= NULL
;
391 free(shader
->tokens
);
392 si_pipe_shader_destroy(ctx
, shader
);
396 void r600_delete_vs_shader(struct pipe_context
*ctx
, void *state
)
398 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
399 struct si_pipe_shader
*shader
= (struct si_pipe_shader
*)state
;
401 if (rctx
->vs_shader
== shader
) {
402 rctx
->vs_shader
= NULL
;
405 free(shader
->tokens
);
406 si_pipe_shader_destroy(ctx
, shader
);
410 static void r600_update_alpha_ref(struct r600_context
*rctx
)
414 struct r600_pipe_state rstate
;
416 alpha_ref
= rctx
->alpha_ref
;
418 if (rctx
->export_16bpc
)
419 alpha_ref
&= ~0x1FFF;
420 r600_pipe_state_add_reg(&rstate
, R_028438_SX_ALPHA_REF
, alpha_ref
, NULL
, 0);
422 r600_context_pipe_state_set(rctx
, &rstate
);
423 rctx
->alpha_ref_dirty
= false;
427 void r600_set_constant_buffer(struct pipe_context
*ctx
, uint shader
, uint index
,
428 struct pipe_resource
*buffer
)
430 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
431 struct r600_resource
*rbuffer
= r600_resource(buffer
);
432 struct r600_pipe_state
*rstate
;
436 /* Note that the state tracker can unbind constant buffers by
439 if (buffer
== NULL
) {
443 r600_inval_shader_cache(rctx
);
445 r600_upload_const_buffer(rctx
, &rbuffer
, &offset
);
446 va_offset
= r600_resource_va(ctx
->screen
, (void*)rbuffer
);
451 case PIPE_SHADER_VERTEX
:
452 rstate
= &rctx
->vs_const_buffer
;
454 r600_pipe_state_add_reg(rstate
,
455 R_00B138_SPI_SHADER_USER_DATA_VS_2
,
456 va_offset
, rbuffer
, RADEON_USAGE_READ
);
457 r600_pipe_state_add_reg(rstate
,
458 R_00B13C_SPI_SHADER_USER_DATA_VS_3
,
459 va_offset
>> 32, NULL
, 0);
461 case PIPE_SHADER_FRAGMENT
:
462 rstate
= &rctx
->ps_const_buffer
;
464 r600_pipe_state_add_reg(rstate
,
465 R_00B030_SPI_SHADER_USER_DATA_PS_0
,
466 va_offset
, rbuffer
, RADEON_USAGE_READ
);
467 r600_pipe_state_add_reg(rstate
,
468 R_00B034_SPI_SHADER_USER_DATA_PS_1
,
469 va_offset
>> 32, NULL
, 0);
472 R600_ERR("unsupported %d\n", shader
);
476 r600_context_pipe_state_set(rctx
, rstate
);
478 if (buffer
!= &rbuffer
->b
.b
.b
)
479 pipe_resource_reference((struct pipe_resource
**)&rbuffer
, NULL
);
482 struct pipe_stream_output_target
*
483 r600_create_so_target(struct pipe_context
*ctx
,
484 struct pipe_resource
*buffer
,
485 unsigned buffer_offset
,
486 unsigned buffer_size
)
488 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
489 struct r600_so_target
*t
;
492 t
= CALLOC_STRUCT(r600_so_target
);
497 t
->b
.reference
.count
= 1;
499 pipe_resource_reference(&t
->b
.buffer
, buffer
);
500 t
->b
.buffer_offset
= buffer_offset
;
501 t
->b
.buffer_size
= buffer_size
;
503 t
->filled_size
= (struct r600_resource
*)
504 pipe_buffer_create(ctx
->screen
, PIPE_BIND_CUSTOM
, PIPE_USAGE_STATIC
, 4);
505 ptr
= rctx
->ws
->buffer_map(t
->filled_size
->buf
, rctx
->cs
, PIPE_TRANSFER_WRITE
);
506 memset(ptr
, 0, t
->filled_size
->buf
->size
);
507 rctx
->ws
->buffer_unmap(t
->filled_size
->buf
);
512 void r600_so_target_destroy(struct pipe_context
*ctx
,
513 struct pipe_stream_output_target
*target
)
515 struct r600_so_target
*t
= (struct r600_so_target
*)target
;
516 pipe_resource_reference(&t
->b
.buffer
, NULL
);
517 pipe_resource_reference((struct pipe_resource
**)&t
->filled_size
, NULL
);
521 void r600_set_so_targets(struct pipe_context
*ctx
,
522 unsigned num_targets
,
523 struct pipe_stream_output_target
**targets
,
524 unsigned append_bitmask
)
526 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
529 /* Stop streamout. */
530 if (rctx
->num_so_targets
) {
531 r600_context_streamout_end(rctx
);
534 /* Set the new targets. */
535 for (i
= 0; i
< num_targets
; i
++) {
536 pipe_so_target_reference((struct pipe_stream_output_target
**)&rctx
->so_targets
[i
], targets
[i
]);
538 for (; i
< rctx
->num_so_targets
; i
++) {
539 pipe_so_target_reference((struct pipe_stream_output_target
**)&rctx
->so_targets
[i
], NULL
);
542 rctx
->num_so_targets
= num_targets
;
543 rctx
->streamout_start
= num_targets
!= 0;
544 rctx
->streamout_append_bitmask
= append_bitmask
;
547 static void r600_vertex_buffer_update(struct r600_context
*rctx
)
549 struct pipe_context
*ctx
= &rctx
->context
;
550 struct r600_pipe_state
*rstate
= &rctx
->vs_user_data
;
551 struct r600_resource
*rbuffer
, *t_list_buffer
;
552 struct pipe_vertex_buffer
*vertex_buffer
;
553 unsigned i
, count
, offset
;
557 r600_inval_vertex_cache(rctx
);
559 if (rctx
->vertex_elements
->vbuffer_need_offset
) {
560 /* one resource per vertex elements */
561 count
= rctx
->vertex_elements
->count
;
563 /* bind vertex buffer once */
564 count
= rctx
->vbuf_mgr
->nr_real_vertex_buffers
;
566 assert(count
<= 256 / 4);
568 t_list_buffer
= (struct r600_resource
*)
569 pipe_buffer_create(ctx
->screen
, PIPE_BIND_CUSTOM
,
570 PIPE_USAGE_IMMUTABLE
, 4 * 4 * count
);
571 if (t_list_buffer
== NULL
)
574 ptr
= (uint32_t*)rctx
->ws
->buffer_map(t_list_buffer
->buf
,
576 PIPE_TRANSFER_WRITE
);
578 for (i
= 0 ; i
< count
; i
++, ptr
+= 4) {
579 struct pipe_vertex_element
*velem
= &rctx
->vertex_elements
->elements
[i
];
580 const struct util_format_description
*desc
;
581 unsigned data_format
, num_format
;
584 if (rctx
->vertex_elements
->vbuffer_need_offset
) {
585 /* one resource per vertex elements */
586 unsigned vbuffer_index
;
587 vbuffer_index
= rctx
->vertex_elements
->elements
[i
].vertex_buffer_index
;
588 vertex_buffer
= &rctx
->vbuf_mgr
->real_vertex_buffer
[vbuffer_index
];
589 rbuffer
= (struct r600_resource
*)vertex_buffer
->buffer
;
590 offset
= rctx
->vertex_elements
->vbuffer_offset
[i
];
592 /* bind vertex buffer once */
593 vertex_buffer
= &rctx
->vbuf_mgr
->real_vertex_buffer
[i
];
594 rbuffer
= (struct r600_resource
*)vertex_buffer
->buffer
;
597 if (vertex_buffer
== NULL
|| rbuffer
== NULL
)
599 offset
+= vertex_buffer
->buffer_offset
;
601 va
= r600_resource_va(ctx
->screen
, (void*)rbuffer
);
604 desc
= util_format_description(velem
->src_format
);
605 first_non_void
= util_format_get_first_non_void_channel(velem
->src_format
);
606 data_format
= si_translate_vertexformat(ctx
->screen
,
608 desc
, first_non_void
);
610 switch (desc
->channel
[first_non_void
].type
) {
611 case UTIL_FORMAT_TYPE_FIXED
:
612 num_format
= V_008F0C_BUF_NUM_FORMAT_USCALED
; /* XXX */
614 case UTIL_FORMAT_TYPE_SIGNED
:
615 num_format
= V_008F0C_BUF_NUM_FORMAT_SNORM
;
617 case UTIL_FORMAT_TYPE_UNSIGNED
:
618 num_format
= V_008F0C_BUF_NUM_FORMAT_UNORM
;
620 case UTIL_FORMAT_TYPE_FLOAT
:
622 num_format
= V_008F14_IMG_NUM_FORMAT_FLOAT
;
625 /* Fill in T# buffer resource description */
626 ptr
[0] = va
& 0xFFFFFFFF;
627 ptr
[1] = ((va
>> 32) & 0xFFFF) |
628 (vertex_buffer
->stride
& 0x3FFF) << 16;
629 ptr
[2] = (vertex_buffer
->buffer
->width0
- offset
) / vertex_buffer
->stride
;
630 /* XXX: Hardcoding RGBA */
631 ptr
[3] = 4 | 5 << 3 | 6 << 6 | 7 << 9 |
632 num_format
<< 12 | data_format
<< 15;
634 r600_context_bo_reloc(rctx
, rbuffer
, RADEON_USAGE_READ
);
639 va
= r600_resource_va(ctx
->screen
, (void*)t_list_buffer
);
640 r600_pipe_state_add_reg(rstate
,
641 R_00B130_SPI_SHADER_USER_DATA_VS_0
,
642 va
, t_list_buffer
, RADEON_USAGE_READ
);
643 r600_pipe_state_add_reg(rstate
,
644 R_00B134_SPI_SHADER_USER_DATA_VS_1
,
648 r600_context_pipe_state_set(rctx
, rstate
);
651 static void si_update_derived_state(struct r600_context
*rctx
)
653 struct pipe_context
* ctx
= (struct pipe_context
*)rctx
;
655 if (!rctx
->blitter
->running
) {
656 if (rctx
->have_depth_fb
|| rctx
->have_depth_texture
)
657 r600_flush_depth_textures(rctx
);
660 if (rctx
->shader_dirty
) {
661 si_pipe_shader_destroy(&rctx
->context
, rctx
->vs_shader
);
664 if (rctx
->shader_dirty
||
665 (rctx
->ps_shader
->shader
.fs_write_all
&&
666 (rctx
->ps_shader
->shader
.nr_cbufs
!= rctx
->nr_cbufs
)) ||
667 (rctx
->sprite_coord_enable
&&
668 (rctx
->ps_shader
->sprite_coord_enable
!= rctx
->sprite_coord_enable
))) {
669 si_pipe_shader_destroy(&rctx
->context
, rctx
->ps_shader
);
672 if (rctx
->alpha_ref_dirty
) {
673 r600_update_alpha_ref(rctx
);
676 if (!rctx
->vs_shader
->bo
) {
677 si_pipe_shader_vs(ctx
, rctx
->vs_shader
);
679 r600_context_pipe_state_set(rctx
, &rctx
->vs_shader
->rstate
);
682 if (!rctx
->ps_shader
->bo
) {
683 si_pipe_shader_ps(ctx
, rctx
->ps_shader
);
685 r600_context_pipe_state_set(rctx
, &rctx
->ps_shader
->rstate
);
688 if (rctx
->shader_dirty
) {
689 si_update_spi_map(rctx
);
690 rctx
->shader_dirty
= false;
694 void r600_draw_vbo(struct pipe_context
*ctx
, const struct pipe_draw_info
*dinfo
)
696 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
697 struct r600_pipe_dsa
*dsa
= (struct r600_pipe_dsa
*)rctx
->states
[R600_PIPE_STATE_DSA
];
698 struct pipe_draw_info info
= *dinfo
;
699 struct r600_draw rdraw
= {};
700 struct pipe_index_buffer ib
= {};
701 unsigned prim
, mask
, ls_mask
= 0;
702 struct r600_block
*dirty_block
= NULL
, *next_block
= NULL
;
703 struct r600_atom
*state
= NULL
, *next_state
= NULL
;
706 if ((!info
.count
&& (info
.indexed
|| !info
.count_from_stream_output
)) ||
707 (info
.indexed
&& !rctx
->vbuf_mgr
->index_buffer
.buffer
) ||
708 !r600_conv_pipe_prim(info
.mode
, &prim
)) {
712 if (!rctx
->ps_shader
|| !rctx
->vs_shader
)
715 si_update_derived_state(rctx
);
717 u_vbuf_draw_begin(rctx
->vbuf_mgr
, &info
);
718 r600_vertex_buffer_update(rctx
);
720 rdraw
.vgt_num_indices
= info
.count
;
721 rdraw
.vgt_num_instances
= info
.instance_count
;
724 /* Initialize the index buffer struct. */
725 pipe_resource_reference(&ib
.buffer
, rctx
->vbuf_mgr
->index_buffer
.buffer
);
726 ib
.index_size
= rctx
->vbuf_mgr
->index_buffer
.index_size
;
727 ib
.offset
= rctx
->vbuf_mgr
->index_buffer
.offset
+ info
.start
* ib
.index_size
;
729 /* Translate or upload, if needed. */
730 r600_translate_index_buffer(rctx
, &ib
, info
.count
);
732 if (u_vbuf_resource(ib
.buffer
)->user_ptr
) {
733 r600_upload_index_buffer(rctx
, &ib
, info
.count
);
736 /* Initialize the r600_draw struct with index buffer info. */
737 if (ib
.index_size
== 4) {
738 rdraw
.vgt_index_type
= V_028A7C_VGT_INDEX_32
|
739 (R600_BIG_ENDIAN
? V_028A7C_VGT_DMA_SWAP_32_BIT
: 0);
741 rdraw
.vgt_index_type
= V_028A7C_VGT_INDEX_16
|
742 (R600_BIG_ENDIAN
? V_028A7C_VGT_DMA_SWAP_16_BIT
: 0);
744 rdraw
.indices
= (struct r600_resource
*)ib
.buffer
;
745 rdraw
.indices_bo_offset
= ib
.offset
;
746 rdraw
.vgt_draw_initiator
= V_0287F0_DI_SRC_SEL_DMA
;
748 info
.index_bias
= info
.start
;
749 rdraw
.vgt_draw_initiator
= V_0287F0_DI_SRC_SEL_AUTO_INDEX
;
750 if (info
.count_from_stream_output
) {
751 rdraw
.vgt_draw_initiator
|= S_0287F0_USE_OPAQUE(1);
753 r600_context_draw_opaque_count(rctx
, (struct r600_so_target
*)info
.count_from_stream_output
);
757 rctx
->vs_shader_so_strides
= rctx
->vs_shader
->so_strides
;
759 mask
= (1ULL << ((unsigned)rctx
->framebuffer
.nr_cbufs
* 4)) - 1;
761 if (rctx
->vgt
.id
!= R600_PIPE_STATE_VGT
) {
762 rctx
->vgt
.id
= R600_PIPE_STATE_VGT
;
764 r600_pipe_state_add_reg(&rctx
->vgt
, R_008958_VGT_PRIMITIVE_TYPE
, prim
, NULL
, 0);
765 r600_pipe_state_add_reg(&rctx
->vgt
, R_028238_CB_TARGET_MASK
, rctx
->cb_target_mask
& mask
, NULL
, 0);
766 r600_pipe_state_add_reg(&rctx
->vgt
, R_028400_VGT_MAX_VTX_INDX
, ~0, NULL
, 0);
767 r600_pipe_state_add_reg(&rctx
->vgt
, R_028404_VGT_MIN_VTX_INDX
, 0, NULL
, 0);
768 r600_pipe_state_add_reg(&rctx
->vgt
, R_028408_VGT_INDX_OFFSET
, info
.index_bias
, NULL
, 0);
769 r600_pipe_state_add_reg(&rctx
->vgt
, R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX
, info
.restart_index
, NULL
, 0);
770 r600_pipe_state_add_reg(&rctx
->vgt
, R_028A94_VGT_MULTI_PRIM_IB_RESET_EN
, info
.primitive_restart
, NULL
, 0);
772 r600_pipe_state_add_reg(&rctx
->vgt
, R_03CFF0_SQ_VTX_BASE_VTX_LOC
, 0, NULL
, 0);
773 r600_pipe_state_add_reg(&rctx
->vgt
, R_03CFF4_SQ_VTX_START_INST_LOC
, info
.start_instance
, NULL
, 0);
775 r600_pipe_state_add_reg(&rctx
->vgt
, R_028A0C_PA_SC_LINE_STIPPLE
, 0, NULL
, 0);
776 r600_pipe_state_add_reg(&rctx
->vgt
, R_028814_PA_SU_SC_MODE_CNTL
, 0, NULL
, 0);
777 r600_pipe_state_add_reg(&rctx
->vgt
, R_02881C_PA_CL_VS_OUT_CNTL
, 0, NULL
, 0);
778 r600_pipe_state_add_reg(&rctx
->vgt
, R_028810_PA_CL_CLIP_CNTL
, 0x0, NULL
, 0);
782 r600_pipe_state_mod_reg(&rctx
->vgt
, prim
);
783 r600_pipe_state_mod_reg(&rctx
->vgt
, rctx
->cb_target_mask
& mask
);
784 r600_pipe_state_mod_reg(&rctx
->vgt
, ~0);
785 r600_pipe_state_mod_reg(&rctx
->vgt
, 0);
786 r600_pipe_state_mod_reg(&rctx
->vgt
, info
.index_bias
);
787 r600_pipe_state_mod_reg(&rctx
->vgt
, info
.restart_index
);
788 r600_pipe_state_mod_reg(&rctx
->vgt
, info
.primitive_restart
);
790 r600_pipe_state_mod_reg(&rctx
->vgt
, 0);
791 r600_pipe_state_mod_reg(&rctx
->vgt
, info
.start_instance
);
794 if (prim
== V_008958_DI_PT_LINELIST
)
796 else if (prim
== V_008958_DI_PT_LINESTRIP
)
798 r600_pipe_state_mod_reg(&rctx
->vgt
, S_028A0C_AUTO_RESET_CNTL(ls_mask
) | rctx
->pa_sc_line_stipple
);
800 if (info
.mode
== PIPE_PRIM_QUADS
|| info
.mode
== PIPE_PRIM_QUAD_STRIP
|| info
.mode
== PIPE_PRIM_POLYGON
) {
801 r600_pipe_state_mod_reg(&rctx
->vgt
, S_028814_PROVOKING_VTX_LAST(1) | rctx
->pa_su_sc_mode_cntl
);
803 r600_pipe_state_mod_reg(&rctx
->vgt
, rctx
->pa_su_sc_mode_cntl
);
805 r600_pipe_state_mod_reg(&rctx
->vgt
,
806 rctx
->pa_cl_vs_out_cntl
/*|
807 (rctx->rasterizer->clip_plane_enable & rctx->vs_shader->shader.clip_dist_write)*/);
808 r600_pipe_state_mod_reg(&rctx
->vgt
,
809 rctx
->pa_cl_clip_cntl
/*|
810 (rctx->vs_shader->shader.clip_dist_write ||
811 rctx->vs_shader->shader.vs_prohibit_ucps ?
812 0 : rctx->rasterizer->clip_plane_enable & 0x3F)*/);
814 r600_context_pipe_state_set(rctx
, &rctx
->vgt
);
816 rdraw
.db_render_override
= dsa
->db_render_override
;
817 rdraw
.db_render_control
= dsa
->db_render_control
;
820 r600_need_cs_space(rctx
, 0, TRUE
);
822 LIST_FOR_EACH_ENTRY_SAFE(state
, next_state
, &rctx
->dirty_states
, head
) {
823 r600_emit_atom(rctx
, state
);
825 LIST_FOR_EACH_ENTRY_SAFE(dirty_block
, next_block
, &rctx
->dirty
,list
) {
826 r600_context_block_emit_dirty(rctx
, dirty_block
);
828 rctx
->pm4_dirty_cdwords
= 0;
830 /* Enable stream out if needed. */
831 if (rctx
->streamout_start
) {
832 r600_context_streamout_begin(rctx
);
833 rctx
->streamout_start
= FALSE
;
836 for (i
= 0; i
< NUM_TEX_UNITS
; i
++) {
837 if (rctx
->ps_samplers
.views
[i
])
838 r600_context_bo_reloc(rctx
,
839 (struct r600_resource
*)rctx
->ps_samplers
.views
[i
]->base
.texture
,
843 if (rctx
->chip_class
>= CAYMAN
) {
844 evergreen_context_draw(rctx
, &rdraw
);
847 rctx
->flags
|= R600_CONTEXT_DST_CACHES_DIRTY
| R600_CONTEXT_DRAW_PENDING
;
849 if (rctx
->framebuffer
.zsbuf
)
851 struct pipe_resource
*tex
= rctx
->framebuffer
.zsbuf
->texture
;
852 ((struct r600_resource_texture
*)tex
)->dirty_db
= TRUE
;
855 pipe_resource_reference(&ib
.buffer
, NULL
);
856 u_vbuf_draw_end(rctx
->vbuf_mgr
);
859 void _r600_pipe_state_add_reg(struct r600_context
*ctx
,
860 struct r600_pipe_state
*state
,
861 uint32_t offset
, uint32_t value
,
862 uint32_t range_id
, uint32_t block_id
,
863 struct r600_resource
*bo
,
864 enum radeon_bo_usage usage
)
866 struct r600_range
*range
;
867 struct r600_block
*block
;
869 if (bo
) assert(usage
);
871 range
= &ctx
->range
[range_id
];
872 block
= range
->blocks
[block_id
];
873 state
->regs
[state
->nregs
].block
= block
;
874 state
->regs
[state
->nregs
].id
= (offset
- block
->start_offset
) >> 2;
876 state
->regs
[state
->nregs
].value
= value
;
877 state
->regs
[state
->nregs
].bo
= bo
;
878 state
->regs
[state
->nregs
].bo_usage
= usage
;
881 assert(state
->nregs
< R600_BLOCK_MAX_REG
);
884 void r600_pipe_state_add_reg_noblock(struct r600_pipe_state
*state
,
885 uint32_t offset
, uint32_t value
,
886 struct r600_resource
*bo
,
887 enum radeon_bo_usage usage
)
889 if (bo
) assert(usage
);
891 state
->regs
[state
->nregs
].id
= offset
;
892 state
->regs
[state
->nregs
].block
= NULL
;
893 state
->regs
[state
->nregs
].value
= value
;
894 state
->regs
[state
->nregs
].bo
= bo
;
895 state
->regs
[state
->nregs
].bo_usage
= usage
;
898 assert(state
->nregs
< R600_BLOCK_MAX_REG
);