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_memory.h>
28 #include <util/u_format.h>
29 #include <pipebuffer/pb_buffer.h>
30 #include "pipe/p_shader_tokens.h"
31 #include "r600_formats.h"
32 #include "r600_pipe.h"
35 static void r600_spi_update(struct r600_pipe_context
*rctx
);
37 static int 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
->flatshade
= rs
->flatshade
;
103 rctx
->sprite_coord_enable
= rs
->sprite_coord_enable
;
104 rctx
->rasterizer
= rs
;
106 rctx
->states
[rs
->rstate
.id
] = &rs
->rstate
;
107 r600_context_pipe_state_set(&rctx
->ctx
, &rs
->rstate
);
109 if (rctx
->family
>= CHIP_CEDAR
) {
110 evergreen_polygon_offset_update(rctx
);
112 r600_polygon_offset_update(rctx
);
114 if (rctx
->ps_shader
&& rctx
->vs_shader
)
115 r600_spi_update(rctx
);
118 void r600_delete_rs_state(struct pipe_context
*ctx
, void *state
)
120 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
121 struct r600_pipe_rasterizer
*rs
= (struct r600_pipe_rasterizer
*)state
;
123 if (rctx
->rasterizer
== rs
) {
124 rctx
->rasterizer
= NULL
;
126 if (rctx
->states
[rs
->rstate
.id
] == &rs
->rstate
) {
127 rctx
->states
[rs
->rstate
.id
] = NULL
;
132 void r600_sampler_view_destroy(struct pipe_context
*ctx
,
133 struct pipe_sampler_view
*state
)
135 struct r600_pipe_sampler_view
*resource
= (struct r600_pipe_sampler_view
*)state
;
137 pipe_resource_reference(&state
->texture
, NULL
);
141 void r600_delete_state(struct pipe_context
*ctx
, void *state
)
143 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
144 struct r600_pipe_state
*rstate
= (struct r600_pipe_state
*)state
;
146 if (rctx
->states
[rstate
->id
] == rstate
) {
147 rctx
->states
[rstate
->id
] = NULL
;
149 for (int i
= 0; i
< rstate
->nregs
; i
++) {
150 r600_bo_reference(rctx
->radeon
, &rstate
->regs
[i
].bo
, NULL
);
155 void r600_bind_vertex_elements(struct pipe_context
*ctx
, void *state
)
157 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
158 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
160 rctx
->vertex_elements
= v
;
162 u_vbuf_mgr_bind_vertex_elements(rctx
->vbuf_mgr
, state
,
165 rctx
->states
[v
->rstate
.id
] = &v
->rstate
;
166 r600_context_pipe_state_set(&rctx
->ctx
, &v
->rstate
);
170 void r600_delete_vertex_element(struct pipe_context
*ctx
, void *state
)
172 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
173 struct r600_vertex_element
*v
= (struct r600_vertex_element
*)state
;
175 if (rctx
->states
[v
->rstate
.id
] == &v
->rstate
) {
176 rctx
->states
[v
->rstate
.id
] = NULL
;
178 if (rctx
->vertex_elements
== state
)
179 rctx
->vertex_elements
= NULL
;
181 r600_bo_reference(rctx
->radeon
, &v
->fetch_shader
, NULL
);
182 u_vbuf_mgr_destroy_vertex_elements(rctx
->vbuf_mgr
, v
->vmgr_elements
);
187 void r600_set_index_buffer(struct pipe_context
*ctx
,
188 const struct pipe_index_buffer
*ib
)
190 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
193 pipe_resource_reference(&rctx
->index_buffer
.buffer
, ib
->buffer
);
194 memcpy(&rctx
->index_buffer
, ib
, sizeof(rctx
->index_buffer
));
196 pipe_resource_reference(&rctx
->index_buffer
.buffer
, NULL
);
197 memset(&rctx
->index_buffer
, 0, sizeof(rctx
->index_buffer
));
200 /* TODO make this more like a state */
203 void r600_set_vertex_buffers(struct pipe_context
*ctx
, unsigned count
,
204 const struct pipe_vertex_buffer
*buffers
)
206 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
210 for (i
= 0; i
< count
; i
++) {
211 if (!buffers
[i
].buffer
) {
212 if (rctx
->family
>= CHIP_CEDAR
) {
213 evergreen_context_pipe_state_set_fs_resource(&rctx
->ctx
, NULL
, i
);
215 r600_context_pipe_state_set_fs_resource(&rctx
->ctx
, NULL
, i
);
219 for (; i
< rctx
->vbuf_mgr
->nr_real_vertex_buffers
; i
++) {
220 if (rctx
->family
>= CHIP_CEDAR
) {
221 evergreen_context_pipe_state_set_fs_resource(&rctx
->ctx
, NULL
, i
);
223 r600_context_pipe_state_set_fs_resource(&rctx
->ctx
, NULL
, i
);
227 u_vbuf_mgr_set_vertex_buffers(rctx
->vbuf_mgr
, count
, buffers
);
230 void *r600_create_vertex_elements(struct pipe_context
*ctx
,
232 const struct pipe_vertex_element
*elements
)
234 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
235 struct r600_vertex_element
*v
= CALLOC_STRUCT(r600_vertex_element
);
243 u_vbuf_mgr_create_vertex_elements(rctx
->vbuf_mgr
, count
,
244 elements
, v
->elements
);
246 if (r600_vertex_elements_build_fetch_shader(rctx
, v
)) {
254 void *r600_create_shader_state(struct pipe_context
*ctx
,
255 const struct pipe_shader_state
*state
)
257 struct r600_pipe_shader
*shader
= CALLOC_STRUCT(r600_pipe_shader
);
260 r
= r600_pipe_shader_create(ctx
, shader
, state
->tokens
);
267 void r600_bind_ps_shader(struct pipe_context
*ctx
, void *state
)
269 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
271 /* TODO delete old shader */
272 rctx
->ps_shader
= (struct r600_pipe_shader
*)state
;
274 r600_context_pipe_state_set(&rctx
->ctx
, &rctx
->ps_shader
->rstate
);
276 if (rctx
->ps_shader
&& rctx
->vs_shader
) {
277 r600_spi_update(rctx
);
278 r600_adjust_gprs(rctx
);
282 void r600_bind_vs_shader(struct pipe_context
*ctx
, void *state
)
284 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
286 /* TODO delete old shader */
287 rctx
->vs_shader
= (struct r600_pipe_shader
*)state
;
289 r600_context_pipe_state_set(&rctx
->ctx
, &rctx
->vs_shader
->rstate
);
291 if (rctx
->ps_shader
&& rctx
->vs_shader
) {
292 r600_spi_update(rctx
);
293 r600_adjust_gprs(rctx
);
297 void r600_delete_ps_shader(struct pipe_context
*ctx
, void *state
)
299 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
300 struct r600_pipe_shader
*shader
= (struct r600_pipe_shader
*)state
;
302 if (rctx
->ps_shader
== shader
) {
303 rctx
->ps_shader
= NULL
;
306 r600_pipe_shader_destroy(ctx
, shader
);
310 void r600_delete_vs_shader(struct pipe_context
*ctx
, void *state
)
312 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
313 struct r600_pipe_shader
*shader
= (struct r600_pipe_shader
*)state
;
315 if (rctx
->vs_shader
== shader
) {
316 rctx
->vs_shader
= NULL
;
319 r600_pipe_shader_destroy(ctx
, shader
);
323 static void r600_update_alpha_ref(struct r600_pipe_context
*rctx
)
326 struct r600_pipe_state rstate
;
328 alpha_ref
= rctx
->alpha_ref
;
330 if (rctx
->export_16bpc
)
331 alpha_ref
&= ~0x1FFF;
332 r600_pipe_state_add_reg(&rstate
, R_028438_SX_ALPHA_REF
, alpha_ref
, 0xFFFFFFFF, NULL
);
334 r600_context_pipe_state_set(&rctx
->ctx
, &rstate
);
335 rctx
->alpha_ref_dirty
= false;
338 /* FIXME optimize away spi update when it's not needed */
339 static void r600_spi_block_init(struct r600_pipe_context
*rctx
, struct r600_pipe_state
*rstate
)
343 rstate
->id
= R600_PIPE_STATE_SPI
;
344 for (i
= 0; i
< 32; i
++) {
345 r600_pipe_state_add_reg(rstate
, R_028644_SPI_PS_INPUT_CNTL_0
+ i
* 4, 0, 0xFFFFFFFF, NULL
);
349 static void r600_spi_update(struct r600_pipe_context
*rctx
)
351 struct r600_pipe_shader
*shader
= rctx
->ps_shader
;
352 struct r600_pipe_state
*rstate
= &rctx
->spi
;
353 struct r600_shader
*rshader
= &shader
->shader
;
354 unsigned i
, tmp
, sid
;
356 if (rctx
->spi
.id
== 0)
357 r600_spi_block_init(rctx
, &rctx
->spi
);
360 for (i
= 0; i
< rshader
->ninput
; i
++) {
361 if (rshader
->input
[i
].name
== TGSI_SEMANTIC_POSITION
||
362 rshader
->input
[i
].name
== TGSI_SEMANTIC_FACE
)
363 if (rctx
->family
>= CHIP_CEDAR
)
368 sid
=r600_find_vs_semantic_index(&rctx
->vs_shader
->shader
, rshader
, i
);
370 tmp
= S_028644_SEMANTIC(sid
);
372 if (rshader
->input
[i
].name
== TGSI_SEMANTIC_COLOR
||
373 rshader
->input
[i
].name
== TGSI_SEMANTIC_BCOLOR
||
374 rshader
->input
[i
].name
== TGSI_SEMANTIC_POSITION
) {
375 tmp
|= S_028644_FLAT_SHADE(rctx
->flatshade
);
378 if (rshader
->input
[i
].name
== TGSI_SEMANTIC_GENERIC
&&
379 rctx
->sprite_coord_enable
& (1 << rshader
->input
[i
].sid
)) {
380 tmp
|= S_028644_PT_SPRITE_TEX(1);
383 if (rctx
->family
< CHIP_CEDAR
) {
384 if (rshader
->input
[i
].centroid
)
385 tmp
|= S_028644_SEL_CENTROID(1);
387 if (rshader
->input
[i
].interpolate
== TGSI_INTERPOLATE_LINEAR
)
388 tmp
|= S_028644_SEL_LINEAR(1);
391 r600_pipe_state_mod_reg(rstate
, tmp
);
394 r600_context_pipe_state_set(&rctx
->ctx
, rstate
);
397 void r600_set_constant_buffer(struct pipe_context
*ctx
, uint shader
, uint index
,
398 struct pipe_resource
*buffer
)
400 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
401 struct r600_resource_buffer
*rbuffer
= r600_buffer(buffer
);
402 struct r600_pipe_resource_state
*rstate
;
405 /* Note that the state tracker can unbind constant buffers by
408 if (buffer
== NULL
) {
412 r600_upload_const_buffer(rctx
, &rbuffer
, &offset
);
413 offset
+= r600_bo_offset(rbuffer
->r
.bo
);
416 case PIPE_SHADER_VERTEX
:
417 rctx
->vs_const_buffer
.nregs
= 0;
418 r600_pipe_state_add_reg(&rctx
->vs_const_buffer
,
419 R_028180_ALU_CONST_BUFFER_SIZE_VS_0
,
420 ALIGN_DIVUP(buffer
->width0
>> 4, 16),
422 r600_pipe_state_add_reg(&rctx
->vs_const_buffer
,
423 R_028980_ALU_CONST_CACHE_VS_0
,
424 offset
>> 8, 0xFFFFFFFF, rbuffer
->r
.bo
);
425 r600_context_pipe_state_set(&rctx
->ctx
, &rctx
->vs_const_buffer
);
427 rstate
= &rctx
->vs_const_buffer_resource
[index
];
429 if (rctx
->family
>= CHIP_CEDAR
) {
430 evergreen_pipe_init_buffer_resource(rctx
, rstate
);
432 r600_pipe_init_buffer_resource(rctx
, rstate
);
436 if (rctx
->family
>= CHIP_CEDAR
) {
437 evergreen_pipe_mod_buffer_resource(rstate
, &rbuffer
->r
, offset
, 16);
438 evergreen_context_pipe_state_set_vs_resource(&rctx
->ctx
, rstate
, index
);
440 r600_pipe_mod_buffer_resource(rstate
, &rbuffer
->r
, offset
, 16);
441 r600_context_pipe_state_set_vs_resource(&rctx
->ctx
, rstate
, index
);
444 case PIPE_SHADER_FRAGMENT
:
445 rctx
->ps_const_buffer
.nregs
= 0;
446 r600_pipe_state_add_reg(&rctx
->ps_const_buffer
,
447 R_028140_ALU_CONST_BUFFER_SIZE_PS_0
,
448 ALIGN_DIVUP(buffer
->width0
>> 4, 16),
450 r600_pipe_state_add_reg(&rctx
->ps_const_buffer
,
451 R_028940_ALU_CONST_CACHE_PS_0
,
452 offset
>> 8, 0xFFFFFFFF, rbuffer
->r
.bo
);
453 r600_context_pipe_state_set(&rctx
->ctx
, &rctx
->ps_const_buffer
);
455 rstate
= &rctx
->ps_const_buffer_resource
[index
];
457 if (rctx
->family
>= CHIP_CEDAR
) {
458 evergreen_pipe_init_buffer_resource(rctx
, rstate
);
460 r600_pipe_init_buffer_resource(rctx
, rstate
);
463 if (rctx
->family
>= CHIP_CEDAR
) {
464 evergreen_pipe_mod_buffer_resource(rstate
, &rbuffer
->r
, offset
, 16);
465 evergreen_context_pipe_state_set_ps_resource(&rctx
->ctx
, rstate
, index
);
467 r600_pipe_mod_buffer_resource(rstate
, &rbuffer
->r
, offset
, 16);
468 r600_context_pipe_state_set_ps_resource(&rctx
->ctx
, rstate
, index
);
472 R600_ERR("unsupported %d\n", shader
);
476 if (buffer
!= &rbuffer
->r
.b
.b
.b
)
477 pipe_resource_reference((struct pipe_resource
**)&rbuffer
, NULL
);
480 static void r600_vertex_buffer_update(struct r600_pipe_context
*rctx
)
482 struct r600_pipe_resource_state
*rstate
;
483 struct r600_resource
*rbuffer
;
484 struct pipe_vertex_buffer
*vertex_buffer
;
485 unsigned i
, count
, offset
;
487 if (rctx
->vertex_elements
->vbuffer_need_offset
) {
488 /* one resource per vertex elements */
489 count
= rctx
->vertex_elements
->count
;
491 /* bind vertex buffer once */
492 count
= rctx
->vbuf_mgr
->nr_real_vertex_buffers
;
495 for (i
= 0 ; i
< count
; i
++) {
496 rstate
= &rctx
->fs_resource
[i
];
498 if (rctx
->vertex_elements
->vbuffer_need_offset
) {
499 /* one resource per vertex elements */
500 unsigned vbuffer_index
;
501 vbuffer_index
= rctx
->vertex_elements
->elements
[i
].vertex_buffer_index
;
502 vertex_buffer
= &rctx
->vbuf_mgr
->vertex_buffer
[vbuffer_index
];
503 rbuffer
= (struct r600_resource
*)rctx
->vbuf_mgr
->real_vertex_buffer
[vbuffer_index
];
504 offset
= rctx
->vertex_elements
->vbuffer_offset
[i
];
506 /* bind vertex buffer once */
507 vertex_buffer
= &rctx
->vbuf_mgr
->vertex_buffer
[i
];
508 rbuffer
= (struct r600_resource
*)rctx
->vbuf_mgr
->real_vertex_buffer
[i
];
511 if (vertex_buffer
== NULL
|| rbuffer
== NULL
)
513 offset
+= vertex_buffer
->buffer_offset
+ r600_bo_offset(rbuffer
->bo
);
516 if (rctx
->family
>= CHIP_CEDAR
) {
517 evergreen_pipe_init_buffer_resource(rctx
, rstate
);
519 r600_pipe_init_buffer_resource(rctx
, rstate
);
523 if (rctx
->family
>= CHIP_CEDAR
) {
524 evergreen_pipe_mod_buffer_resource(rstate
, rbuffer
, offset
, vertex_buffer
->stride
);
525 evergreen_context_pipe_state_set_fs_resource(&rctx
->ctx
, rstate
, i
);
527 r600_pipe_mod_buffer_resource(rstate
, rbuffer
, offset
, vertex_buffer
->stride
);
528 r600_context_pipe_state_set_fs_resource(&rctx
->ctx
, rstate
, i
);
533 void r600_draw_vbo(struct pipe_context
*ctx
, const struct pipe_draw_info
*info
)
535 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
536 struct r600_resource
*rbuffer
;
537 struct r600_draw rdraw
;
538 struct r600_drawl draw
;
542 if (rctx
->have_depth_fb
|| rctx
->have_depth_texture
)
543 r600_flush_depth_textures(rctx
);
545 u_vbuf_mgr_draw_begin(rctx
->vbuf_mgr
, info
);
546 r600_vertex_buffer_update(rctx
);
550 draw
.index_buffer
= NULL
;
551 if (info
->indexed
&& rctx
->index_buffer
.buffer
) {
552 draw
.info
.start
+= rctx
->index_buffer
.offset
/ rctx
->index_buffer
.index_size
;
553 pipe_resource_reference(&draw
.index_buffer
, rctx
->index_buffer
.buffer
);
555 r600_translate_index_buffer(rctx
, &draw
.index_buffer
,
556 &rctx
->index_buffer
.index_size
,
560 draw
.index_size
= rctx
->index_buffer
.index_size
;
561 draw
.index_buffer_offset
= draw
.info
.start
* draw
.index_size
;
564 if (u_vbuf_resource(draw
.index_buffer
)->user_ptr
) {
565 r600_upload_index_buffer(rctx
, &draw
);
569 draw
.index_buffer_offset
= 0;
570 draw
.info
.index_bias
= info
->start
;
573 if (r600_conv_pipe_prim(draw
.info
.mode
, &prim
))
576 if (rctx
->alpha_ref_dirty
)
577 r600_update_alpha_ref(rctx
);
580 for (int i
= 0; i
< rctx
->framebuffer
.nr_cbufs
; i
++) {
581 mask
|= (0xF << (i
* 4));
584 if (rctx
->vgt
.id
!= R600_PIPE_STATE_VGT
) {
585 rctx
->vgt
.id
= R600_PIPE_STATE_VGT
;
587 r600_pipe_state_add_reg(&rctx
->vgt
, R_008958_VGT_PRIMITIVE_TYPE
, prim
, 0xFFFFFFFF, NULL
);
588 r600_pipe_state_add_reg(&rctx
->vgt
, R_028238_CB_TARGET_MASK
, rctx
->cb_target_mask
& mask
, 0xFFFFFFFF, NULL
);
589 r600_pipe_state_add_reg(&rctx
->vgt
, R_028400_VGT_MAX_VTX_INDX
, draw
.info
.max_index
, 0xFFFFFFFF, NULL
);
590 r600_pipe_state_add_reg(&rctx
->vgt
, R_028404_VGT_MIN_VTX_INDX
, draw
.info
.min_index
, 0xFFFFFFFF, NULL
);
591 r600_pipe_state_add_reg(&rctx
->vgt
, R_028408_VGT_INDX_OFFSET
, draw
.info
.index_bias
, 0xFFFFFFFF, NULL
);
592 r600_pipe_state_add_reg(&rctx
->vgt
, R_03CFF0_SQ_VTX_BASE_VTX_LOC
, 0, 0xFFFFFFFF, NULL
);
593 r600_pipe_state_add_reg(&rctx
->vgt
, R_03CFF4_SQ_VTX_START_INST_LOC
, draw
.info
.start_instance
, 0xFFFFFFFF, NULL
);
594 r600_pipe_state_add_reg(&rctx
->vgt
, R_028814_PA_SU_SC_MODE_CNTL
,
596 S_028814_PROVOKING_VTX_LAST(1), NULL
);
601 r600_pipe_state_mod_reg(&rctx
->vgt
, prim
);
602 r600_pipe_state_mod_reg(&rctx
->vgt
, rctx
->cb_target_mask
& mask
);
603 r600_pipe_state_mod_reg(&rctx
->vgt
, draw
.info
.max_index
);
604 r600_pipe_state_mod_reg(&rctx
->vgt
, draw
.info
.min_index
);
605 r600_pipe_state_mod_reg(&rctx
->vgt
, draw
.info
.index_bias
);
606 r600_pipe_state_mod_reg(&rctx
->vgt
, 0);
607 r600_pipe_state_mod_reg(&rctx
->vgt
, draw
.info
.start_instance
);
608 if (draw
.info
.mode
== PIPE_PRIM_QUADS
|| draw
.info
.mode
== PIPE_PRIM_QUAD_STRIP
|| draw
.info
.mode
== PIPE_PRIM_POLYGON
) {
609 r600_pipe_state_mod_reg(&rctx
->vgt
, S_028814_PROVOKING_VTX_LAST(1));
612 r600_context_pipe_state_set(&rctx
->ctx
, &rctx
->vgt
);
614 rdraw
.vgt_num_indices
= draw
.info
.count
;
615 rdraw
.vgt_num_instances
= draw
.info
.instance_count
;
616 rdraw
.vgt_index_type
= ((draw
.index_size
== 4) ? 1 : 0);
618 rdraw
.vgt_index_type
|= (draw
.index_size
>> 1) << 2;
619 rdraw
.vgt_draw_initiator
= draw
.index_size
? 0 : 2;
620 rdraw
.indices
= NULL
;
621 if (draw
.index_buffer
) {
622 rbuffer
= (struct r600_resource
*)draw
.index_buffer
;
623 rdraw
.indices
= rbuffer
->bo
;
624 rdraw
.indices_bo_offset
= draw
.index_buffer_offset
;
627 if (rctx
->family
>= CHIP_CEDAR
) {
628 evergreen_context_draw(&rctx
->ctx
, &rdraw
);
630 r600_context_draw(&rctx
->ctx
, &rdraw
);
633 if (rctx
->framebuffer
.zsbuf
)
635 struct pipe_resource
*tex
= rctx
->framebuffer
.zsbuf
->texture
;
636 ((struct r600_resource_texture
*)tex
)->dirty_db
= TRUE
;
639 pipe_resource_reference(&draw
.index_buffer
, NULL
);
641 u_vbuf_mgr_draw_end(rctx
->vbuf_mgr
);
644 void _r600_pipe_state_add_reg(struct r600_context
*ctx
,
645 struct r600_pipe_state
*state
,
646 u32 offset
, u32 value
, u32 mask
,
647 u32 range_id
, u32 block_id
,
650 struct r600_range
*range
;
651 struct r600_block
*block
;
653 range
= &ctx
->range
[range_id
];
654 block
= range
->blocks
[block_id
];
655 state
->regs
[state
->nregs
].block
= block
;
656 state
->regs
[state
->nregs
].id
= (offset
- block
->start_offset
) >> 2;
658 state
->regs
[state
->nregs
].value
= value
;
659 state
->regs
[state
->nregs
].mask
= mask
;
660 state
->regs
[state
->nregs
].bo
= bo
;
663 assert(state
->nregs
< R600_BLOCK_MAX_REG
);
666 void r600_pipe_state_add_reg_noblock(struct r600_pipe_state
*state
,
667 u32 offset
, u32 value
, u32 mask
,
670 state
->regs
[state
->nregs
].id
= offset
;
671 state
->regs
[state
->nregs
].block
= NULL
;
672 state
->regs
[state
->nregs
].value
= value
;
673 state
->regs
[state
->nregs
].mask
= mask
;
674 state
->regs
[state
->nregs
].bo
= bo
;
677 assert(state
->nregs
< R600_BLOCK_MAX_REG
);