2 * Copyright 2012 Advanced Micro Devices, Inc.
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.
24 * Christian König <christian.koenig@amd.com>
27 #include "util/u_memory.h"
28 #include "util/u_framebuffer.h"
29 #include "util/u_blitter.h"
30 #include "tgsi/tgsi_parse.h"
31 #include "radeonsi_pipe.h"
32 #include "radeonsi_shader.h"
40 static void si_pipe_shader_vs(struct pipe_context
*ctx
, struct si_pipe_shader
*shader
)
42 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
43 struct si_pm4_state
*pm4
;
44 unsigned num_sgprs
, num_user_sgprs
;
48 si_pm4_delete_state(rctx
, vs
, shader
->pm4
);
49 pm4
= shader
->pm4
= CALLOC_STRUCT(si_pm4_state
);
51 si_pm4_inval_shader_cache(pm4
);
53 /* Certain attributes (position, psize, etc.) don't count as params.
54 * VS is required to export at least one param and r600_shader_from_tgsi()
55 * takes care of adding a dummy export.
57 for (nparams
= 0, i
= 0 ; i
< shader
->shader
.noutput
; i
++) {
58 if (shader
->shader
.output
[i
].name
!= TGSI_SEMANTIC_POSITION
)
64 si_pm4_set_reg(pm4
, R_0286C4_SPI_VS_OUT_CONFIG
,
65 S_0286C4_VS_EXPORT_COUNT(nparams
- 1));
67 si_pm4_set_reg(pm4
, R_02870C_SPI_SHADER_POS_FORMAT
,
68 S_02870C_POS0_EXPORT_FORMAT(V_02870C_SPI_SHADER_4COMP
) |
69 S_02870C_POS1_EXPORT_FORMAT(V_02870C_SPI_SHADER_NONE
) |
70 S_02870C_POS2_EXPORT_FORMAT(V_02870C_SPI_SHADER_NONE
) |
71 S_02870C_POS3_EXPORT_FORMAT(V_02870C_SPI_SHADER_NONE
));
73 va
= r600_resource_va(ctx
->screen
, (void *)shader
->bo
);
74 si_pm4_add_bo(pm4
, shader
->bo
, RADEON_USAGE_READ
);
75 si_pm4_set_reg(pm4
, R_00B120_SPI_SHADER_PGM_LO_VS
, va
>> 8);
76 si_pm4_set_reg(pm4
, R_00B124_SPI_SHADER_PGM_HI_VS
, va
>> 40);
78 num_user_sgprs
= SI_VS_NUM_USER_SGPR
;
79 num_sgprs
= shader
->num_sgprs
;
80 if (num_user_sgprs
> num_sgprs
)
81 num_sgprs
= num_user_sgprs
;
82 /* Last 2 reserved SGPRs are used for VCC */
84 assert(num_sgprs
<= 104);
86 si_pm4_set_reg(pm4
, R_00B128_SPI_SHADER_PGM_RSRC1_VS
,
87 S_00B128_VGPRS((shader
->num_vgprs
- 1) / 4) |
88 S_00B128_SGPRS((num_sgprs
- 1) / 8));
89 si_pm4_set_reg(pm4
, R_00B12C_SPI_SHADER_PGM_RSRC2_VS
,
90 S_00B12C_USER_SGPR(num_user_sgprs
));
92 si_pm4_bind_state(rctx
, vs
, shader
->pm4
);
95 static void si_pipe_shader_ps(struct pipe_context
*ctx
, struct si_pipe_shader
*shader
)
97 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
98 struct si_pm4_state
*pm4
;
99 unsigned i
, exports_ps
, num_cout
, spi_ps_in_control
, db_shader_control
;
100 unsigned num_sgprs
, num_user_sgprs
;
101 boolean have_linear
= FALSE
, have_centroid
= FALSE
, have_perspective
= FALSE
;
102 unsigned fragcoord_interp_mode
= 0;
103 unsigned spi_baryc_cntl
, spi_ps_input_ena
;
106 si_pm4_delete_state(rctx
, ps
, shader
->pm4
);
107 pm4
= shader
->pm4
= CALLOC_STRUCT(si_pm4_state
);
109 si_pm4_inval_shader_cache(pm4
);
111 db_shader_control
= S_02880C_Z_ORDER(V_02880C_EARLY_Z_THEN_LATE_Z
);
112 for (i
= 0; i
< shader
->shader
.ninput
; i
++) {
113 if (shader
->shader
.input
[i
].name
== TGSI_SEMANTIC_POSITION
) {
114 if (shader
->shader
.input
[i
].centroid
) {
115 /* fragcoord_interp_mode will be written to
116 * SPI_BARYC_CNTL.POS_FLOAT_LOCATION
118 * 0 -> Position = pixel center (default)
119 * 1 -> Position = pixel centroid
120 * 2 -> Position = iterated sample number XXX:
121 * What does this mean?
123 fragcoord_interp_mode
= 1;
128 /* XXX: Flat shading hangs the GPU */
129 if (shader
->shader
.input
[i
].interpolate
== TGSI_INTERPOLATE_CONSTANT
||
130 (shader
->shader
.input
[i
].interpolate
== TGSI_INTERPOLATE_COLOR
&&
131 rctx
->queued
.named
.rasterizer
->flatshade
))
133 if (shader
->shader
.input
[i
].interpolate
== TGSI_INTERPOLATE_LINEAR
)
135 if (shader
->shader
.input
[i
].interpolate
== TGSI_INTERPOLATE_PERSPECTIVE
)
136 have_perspective
= TRUE
;
137 if (shader
->shader
.input
[i
].centroid
)
138 have_centroid
= TRUE
;
141 for (i
= 0; i
< shader
->shader
.noutput
; i
++) {
142 if (shader
->shader
.output
[i
].name
== TGSI_SEMANTIC_POSITION
)
143 db_shader_control
|= S_02880C_Z_EXPORT_ENABLE(1);
144 if (shader
->shader
.output
[i
].name
== TGSI_SEMANTIC_STENCIL
)
145 db_shader_control
|= 0; // XXX OP_VAL or TEST_VAL?
147 if (shader
->shader
.uses_kill
)
148 db_shader_control
|= S_02880C_KILL_ENABLE(1);
152 for (i
= 0; i
< shader
->shader
.noutput
; i
++) {
153 if (shader
->shader
.output
[i
].name
== TGSI_SEMANTIC_POSITION
||
154 shader
->shader
.output
[i
].name
== TGSI_SEMANTIC_STENCIL
)
156 else if (shader
->shader
.output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
157 if (shader
->shader
.fs_write_all
)
158 num_cout
= shader
->shader
.nr_cbufs
;
164 /* always at least export 1 component per pixel */
168 spi_ps_in_control
= S_0286D8_NUM_INTERP(shader
->shader
.ninterp
);
171 if (have_perspective
)
172 spi_baryc_cntl
|= have_centroid
?
173 S_0286E0_PERSP_CENTROID_CNTL(1) : S_0286E0_PERSP_CENTER_CNTL(1);
175 spi_baryc_cntl
|= have_centroid
?
176 S_0286E0_LINEAR_CENTROID_CNTL(1) : S_0286E0_LINEAR_CENTER_CNTL(1);
177 spi_baryc_cntl
|= S_0286E0_POS_FLOAT_LOCATION(fragcoord_interp_mode
);
179 si_pm4_set_reg(pm4
, R_0286E0_SPI_BARYC_CNTL
, spi_baryc_cntl
);
180 spi_ps_input_ena
= shader
->spi_ps_input_ena
;
181 /* we need to enable at least one of them, otherwise we hang the GPU */
182 assert(G_0286CC_PERSP_SAMPLE_ENA(spi_ps_input_ena
) ||
183 G_0286CC_PERSP_CENTER_ENA(spi_ps_input_ena
) ||
184 G_0286CC_PERSP_CENTROID_ENA(spi_ps_input_ena
) ||
185 G_0286CC_PERSP_PULL_MODEL_ENA(spi_ps_input_ena
) ||
186 G_0286CC_LINEAR_SAMPLE_ENA(spi_ps_input_ena
) ||
187 G_0286CC_LINEAR_CENTER_ENA(spi_ps_input_ena
) ||
188 G_0286CC_LINEAR_CENTROID_ENA(spi_ps_input_ena
) ||
189 G_0286CC_LINE_STIPPLE_TEX_ENA(spi_ps_input_ena
));
191 si_pm4_set_reg(pm4
, R_0286CC_SPI_PS_INPUT_ENA
, spi_ps_input_ena
);
192 si_pm4_set_reg(pm4
, R_0286D0_SPI_PS_INPUT_ADDR
, spi_ps_input_ena
);
193 si_pm4_set_reg(pm4
, R_0286D8_SPI_PS_IN_CONTROL
, spi_ps_in_control
);
195 /* XXX: Depends on Z buffer format? */
196 si_pm4_set_reg(pm4
, R_028710_SPI_SHADER_Z_FORMAT
, 0);
198 va
= r600_resource_va(ctx
->screen
, (void *)shader
->bo
);
199 si_pm4_add_bo(pm4
, shader
->bo
, RADEON_USAGE_READ
);
200 si_pm4_set_reg(pm4
, R_00B020_SPI_SHADER_PGM_LO_PS
, va
>> 8);
201 si_pm4_set_reg(pm4
, R_00B024_SPI_SHADER_PGM_HI_PS
, va
>> 40);
203 num_user_sgprs
= SI_PS_NUM_USER_SGPR
;
204 num_sgprs
= shader
->num_sgprs
;
205 if (num_user_sgprs
> num_sgprs
)
206 num_sgprs
= num_user_sgprs
;
207 /* Last 2 reserved SGPRs are used for VCC */
209 assert(num_sgprs
<= 104);
211 si_pm4_set_reg(pm4
, R_00B028_SPI_SHADER_PGM_RSRC1_PS
,
212 S_00B028_VGPRS((shader
->num_vgprs
- 1) / 4) |
213 S_00B028_SGPRS((num_sgprs
- 1) / 8));
214 si_pm4_set_reg(pm4
, R_00B02C_SPI_SHADER_PGM_RSRC2_PS
,
215 S_00B02C_USER_SGPR(num_user_sgprs
));
217 si_pm4_set_reg(pm4
, R_02880C_DB_SHADER_CONTROL
, db_shader_control
);
219 shader
->sprite_coord_enable
= rctx
->sprite_coord_enable
;
220 si_pm4_bind_state(rctx
, ps
, shader
->pm4
);
227 static unsigned si_conv_pipe_prim(unsigned pprim
)
229 static const unsigned prim_conv
[] = {
230 [PIPE_PRIM_POINTS
] = V_008958_DI_PT_POINTLIST
,
231 [PIPE_PRIM_LINES
] = V_008958_DI_PT_LINELIST
,
232 [PIPE_PRIM_LINE_LOOP
] = V_008958_DI_PT_LINELOOP
,
233 [PIPE_PRIM_LINE_STRIP
] = V_008958_DI_PT_LINESTRIP
,
234 [PIPE_PRIM_TRIANGLES
] = V_008958_DI_PT_TRILIST
,
235 [PIPE_PRIM_TRIANGLE_STRIP
] = V_008958_DI_PT_TRISTRIP
,
236 [PIPE_PRIM_TRIANGLE_FAN
] = V_008958_DI_PT_TRIFAN
,
237 [PIPE_PRIM_QUADS
] = V_008958_DI_PT_QUADLIST
,
238 [PIPE_PRIM_QUAD_STRIP
] = V_008958_DI_PT_QUADSTRIP
,
239 [PIPE_PRIM_POLYGON
] = V_008958_DI_PT_POLYGON
,
240 [PIPE_PRIM_LINES_ADJACENCY
] = ~0,
241 [PIPE_PRIM_LINE_STRIP_ADJACENCY
] = ~0,
242 [PIPE_PRIM_TRIANGLES_ADJACENCY
] = ~0,
243 [PIPE_PRIM_TRIANGLE_STRIP_ADJACENCY
] = ~0
245 unsigned result
= prim_conv
[pprim
];
247 R600_ERR("unsupported primitive type %d\n", pprim
);
252 static bool si_update_draw_info_state(struct r600_context
*rctx
,
253 const struct pipe_draw_info
*info
)
255 struct si_pm4_state
*pm4
= CALLOC_STRUCT(si_pm4_state
);
256 unsigned prim
= si_conv_pipe_prim(info
->mode
);
257 unsigned ls_mask
= 0;
267 si_pm4_set_reg(pm4
, R_008958_VGT_PRIMITIVE_TYPE
, prim
);
268 si_pm4_set_reg(pm4
, R_028400_VGT_MAX_VTX_INDX
, ~0);
269 si_pm4_set_reg(pm4
, R_028404_VGT_MIN_VTX_INDX
, 0);
270 si_pm4_set_reg(pm4
, R_028408_VGT_INDX_OFFSET
,
271 info
->indexed
? info
->index_bias
: info
->start
);
272 si_pm4_set_reg(pm4
, R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX
, info
->restart_index
);
273 si_pm4_set_reg(pm4
, R_028A94_VGT_MULTI_PRIM_IB_RESET_EN
, info
->primitive_restart
);
275 si_pm4_set_reg(pm4
, R_03CFF0_SQ_VTX_BASE_VTX_LOC
, 0);
276 si_pm4_set_reg(pm4
, R_03CFF4_SQ_VTX_START_INST_LOC
, info
->start_instance
);
279 if (prim
== V_008958_DI_PT_LINELIST
)
281 else if (prim
== V_008958_DI_PT_LINESTRIP
)
283 si_pm4_set_reg(pm4
, R_028A0C_PA_SC_LINE_STIPPLE
,
284 S_028A0C_AUTO_RESET_CNTL(ls_mask
) |
285 rctx
->pa_sc_line_stipple
);
287 if (info
->mode
== PIPE_PRIM_QUADS
|| info
->mode
== PIPE_PRIM_QUAD_STRIP
|| info
->mode
== PIPE_PRIM_POLYGON
) {
288 si_pm4_set_reg(pm4
, R_028814_PA_SU_SC_MODE_CNTL
,
289 S_028814_PROVOKING_VTX_LAST(1) | rctx
->pa_su_sc_mode_cntl
);
291 si_pm4_set_reg(pm4
, R_028814_PA_SU_SC_MODE_CNTL
, rctx
->pa_su_sc_mode_cntl
);
293 si_pm4_set_reg(pm4
, R_02881C_PA_CL_VS_OUT_CNTL
,
294 prim
== PIPE_PRIM_POINTS
? rctx
->pa_cl_vs_out_cntl
: 0
295 /*| (rctx->rasterizer->clip_plane_enable &
296 rctx->vs_shader->shader.clip_dist_write)*/);
297 si_pm4_set_reg(pm4
, R_028810_PA_CL_CLIP_CNTL
, rctx
->pa_cl_clip_cntl
298 /*| (rctx->vs_shader->shader.clip_dist_write ||
299 rctx->vs_shader->shader.vs_prohibit_ucps ?
300 0 : rctx->rasterizer->clip_plane_enable & 0x3F)*/);
302 si_pm4_set_state(rctx
, draw_info
, pm4
);
306 static void si_update_alpha_ref(struct r600_context
*rctx
)
310 struct r600_pipe_state rstate
;
312 alpha_ref
= rctx
->alpha_ref
;
314 if (rctx
->export_16bpc
)
315 alpha_ref
&= ~0x1FFF;
316 si_pm4_set_reg(&rstate
, R_028438_SX_ALPHA_REF
, alpha_ref
);
318 si_pm4_set_state(rctx
, TODO
, pm4
);
319 rctx
->alpha_ref_dirty
= false;
323 static void si_update_spi_map(struct r600_context
*rctx
)
325 struct si_shader
*ps
= &rctx
->ps_shader
->current
->shader
;
326 struct si_shader
*vs
= &rctx
->vs_shader
->current
->shader
;
327 struct si_pm4_state
*pm4
= CALLOC_STRUCT(si_pm4_state
);
330 for (i
= 0; i
< ps
->ninput
; i
++) {
334 /* XXX: Flat shading hangs the GPU */
335 if (ps
->input
[i
].name
== TGSI_SEMANTIC_POSITION
||
336 ps
->input
[i
].interpolate
== TGSI_INTERPOLATE_CONSTANT
||
337 (ps
->input
[i
].interpolate
== TGSI_INTERPOLATE_COLOR
&&
338 rctx
->rasterizer
&& rctx
->rasterizer
->flatshade
)) {
339 tmp
|= S_028644_FLAT_SHADE(1);
343 if (ps
->input
[i
].name
== TGSI_SEMANTIC_GENERIC
&&
344 rctx
->sprite_coord_enable
& (1 << ps
->input
[i
].sid
)) {
345 tmp
|= S_028644_PT_SPRITE_TEX(1);
348 for (j
= 0; j
< vs
->noutput
; j
++) {
349 if (ps
->input
[i
].name
== vs
->output
[j
].name
&&
350 ps
->input
[i
].sid
== vs
->output
[j
].sid
) {
351 tmp
|= S_028644_OFFSET(vs
->output
[j
].param_offset
);
356 if (j
== vs
->noutput
) {
357 /* No corresponding output found, load defaults into input */
358 tmp
|= S_028644_OFFSET(0x20);
362 R_028644_SPI_PS_INPUT_CNTL_0
+ ps
->input
[i
].param_offset
* 4,
366 si_pm4_set_state(rctx
, spi
, pm4
);
369 static void si_update_derived_state(struct r600_context
*rctx
)
371 struct pipe_context
* ctx
= (struct pipe_context
*)rctx
;
372 unsigned ps_dirty
= 0;
374 if (!rctx
->blitter
->running
) {
375 if (rctx
->have_depth_fb
|| rctx
->have_depth_texture
)
376 si_flush_depth_textures(rctx
);
379 si_shader_select(ctx
, rctx
->ps_shader
, &ps_dirty
);
381 if (rctx
->alpha_ref_dirty
) {
382 si_update_alpha_ref(rctx
);
385 if (!rctx
->vs_shader
->current
->pm4
) {
386 si_pipe_shader_vs(ctx
, rctx
->vs_shader
->current
);
389 if (!rctx
->ps_shader
->current
->pm4
) {
390 si_pipe_shader_ps(ctx
, rctx
->ps_shader
->current
);
393 if (!rctx
->ps_shader
->current
->bo
) {
394 if (!rctx
->dummy_pixel_shader
->pm4
)
395 si_pipe_shader_ps(ctx
, rctx
->dummy_pixel_shader
);
397 si_pm4_bind_state(rctx
, vs
, rctx
->dummy_pixel_shader
->pm4
);
403 si_pm4_bind_state(rctx
, ps
, rctx
->ps_shader
->current
->pm4
);
406 if (si_pm4_state_changed(rctx
, ps
) || si_pm4_state_changed(rctx
, vs
)) {
407 si_update_spi_map(rctx
);
411 static void si_vertex_buffer_update(struct r600_context
*rctx
)
413 struct pipe_context
*ctx
= &rctx
->context
;
414 struct si_pm4_state
*pm4
= CALLOC_STRUCT(si_pm4_state
);
415 bool bound
[PIPE_MAX_ATTRIBS
] = {};
419 si_pm4_inval_vertex_cache(pm4
);
421 /* bind vertex buffer once */
422 count
= rctx
->vertex_elements
->count
;
423 assert(count
<= 256 / 4);
425 si_pm4_sh_data_begin(pm4
);
426 for (i
= 0 ; i
< count
; i
++) {
427 struct pipe_vertex_element
*ve
= &rctx
->vertex_elements
->elements
[i
];
428 struct pipe_vertex_buffer
*vb
;
429 struct si_resource
*rbuffer
;
432 if (ve
->vertex_buffer_index
>= rctx
->nr_vertex_buffers
)
435 vb
= &rctx
->vertex_buffer
[ve
->vertex_buffer_index
];
436 rbuffer
= (struct si_resource
*)vb
->buffer
;
441 offset
+= vb
->buffer_offset
;
442 offset
+= ve
->src_offset
;
444 va
= r600_resource_va(ctx
->screen
, (void*)rbuffer
);
447 /* Fill in T# buffer resource description */
448 si_pm4_sh_data_add(pm4
, va
& 0xFFFFFFFF);
449 si_pm4_sh_data_add(pm4
, (S_008F04_BASE_ADDRESS_HI(va
>> 32) |
450 S_008F04_STRIDE(vb
->stride
)));
451 si_pm4_sh_data_add(pm4
, (vb
->buffer
->width0
- vb
->buffer_offset
) /
452 MAX2(vb
->stride
, 1));
453 si_pm4_sh_data_add(pm4
, rctx
->vertex_elements
->rsrc_word3
[i
]);
455 if (!bound
[ve
->vertex_buffer_index
]) {
456 si_pm4_add_bo(pm4
, rbuffer
, RADEON_USAGE_READ
);
457 bound
[ve
->vertex_buffer_index
] = true;
460 si_pm4_sh_data_end(pm4
, R_00B130_SPI_SHADER_USER_DATA_VS_0
, SI_SGPR_VERTEX_BUFFER
);
461 si_pm4_set_state(rctx
, vertex_buffers
, pm4
);
464 static void si_state_draw(struct r600_context
*rctx
,
465 const struct pipe_draw_info
*info
,
466 const struct pipe_index_buffer
*ib
)
468 struct si_pm4_state
*pm4
= CALLOC_STRUCT(si_pm4_state
);
470 /* queries need some special values
471 * (this is non-zero if any query is active) */
472 if (rctx
->num_cs_dw_queries_suspend
) {
473 struct si_state_dsa
*dsa
= rctx
->queued
.named
.dsa
;
475 si_pm4_set_reg(pm4
, R_028004_DB_COUNT_CONTROL
,
476 S_028004_PERFECT_ZPASS_COUNTS(1));
477 si_pm4_set_reg(pm4
, R_02800C_DB_RENDER_OVERRIDE
,
478 dsa
->db_render_override
|
479 S_02800C_NOOP_CULL_DISABLE(1));
483 si_pm4_cmd_begin(pm4
, PKT3_INDEX_TYPE
);
484 if (ib
->index_size
== 4) {
485 si_pm4_cmd_add(pm4
, V_028A7C_VGT_INDEX_32
| (R600_BIG_ENDIAN
?
486 V_028A7C_VGT_DMA_SWAP_32_BIT
: 0));
488 si_pm4_cmd_add(pm4
, V_028A7C_VGT_INDEX_16
| (R600_BIG_ENDIAN
?
489 V_028A7C_VGT_DMA_SWAP_16_BIT
: 0));
491 si_pm4_cmd_end(pm4
, rctx
->predicate_drawing
);
493 si_pm4_cmd_begin(pm4
, PKT3_NUM_INSTANCES
);
494 si_pm4_cmd_add(pm4
, info
->instance_count
);
495 si_pm4_cmd_end(pm4
, rctx
->predicate_drawing
);
498 uint32_t max_size
= (ib
->buffer
->width0
- ib
->offset
) /
499 rctx
->index_buffer
.index_size
;
501 va
= r600_resource_va(&rctx
->screen
->screen
, ib
->buffer
);
504 si_pm4_add_bo(pm4
, (struct si_resource
*)ib
->buffer
, RADEON_USAGE_READ
);
505 si_cmd_draw_index_2(pm4
, max_size
, va
, info
->count
,
506 V_0287F0_DI_SRC_SEL_DMA
,
507 rctx
->predicate_drawing
);
509 uint32_t initiator
= V_0287F0_DI_SRC_SEL_AUTO_INDEX
;
510 initiator
|= S_0287F0_USE_OPAQUE(!!info
->count_from_stream_output
);
511 si_cmd_draw_index_auto(pm4
, info
->count
, initiator
, rctx
->predicate_drawing
);
513 si_pm4_set_state(rctx
, draw
, pm4
);
516 void si_draw_vbo(struct pipe_context
*ctx
, const struct pipe_draw_info
*info
)
518 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
519 struct pipe_index_buffer ib
= {};
520 uint32_t cp_coher_cntl
;
522 if ((!info
->count
&& (info
->indexed
|| !info
->count_from_stream_output
)) ||
523 (info
->indexed
&& !rctx
->index_buffer
.buffer
)) {
527 if (!rctx
->ps_shader
|| !rctx
->vs_shader
)
530 si_update_derived_state(rctx
);
531 si_vertex_buffer_update(rctx
);
534 /* Initialize the index buffer struct. */
535 pipe_resource_reference(&ib
.buffer
, rctx
->index_buffer
.buffer
);
536 ib
.index_size
= rctx
->index_buffer
.index_size
;
537 ib
.offset
= rctx
->index_buffer
.offset
+ info
->start
* ib
.index_size
;
539 /* Translate or upload, if needed. */
540 r600_translate_index_buffer(rctx
, &ib
, info
->count
);
542 if (ib
.user_buffer
) {
543 r600_upload_index_buffer(rctx
, &ib
, info
->count
);
546 } else if (info
->count_from_stream_output
) {
547 r600_context_draw_opaque_count(rctx
, (struct r600_so_target
*)info
->count_from_stream_output
);
550 rctx
->vs_shader_so_strides
= rctx
->vs_shader
->current
->so_strides
;
552 if (!si_update_draw_info_state(rctx
, info
))
555 si_state_draw(rctx
, info
, &ib
);
557 cp_coher_cntl
= si_pm4_sync_flags(rctx
);
559 struct si_pm4_state
*pm4
= CALLOC_STRUCT(si_pm4_state
);
560 si_cmd_surface_sync(pm4
, cp_coher_cntl
);
561 si_pm4_set_state(rctx
, sync
, pm4
);
565 rctx
->pm4_dirty_cdwords
+= si_pm4_dirty_dw(rctx
);
567 si_need_cs_space(rctx
, 0, TRUE
);
569 si_pm4_emit_dirty(rctx
);
570 rctx
->pm4_dirty_cdwords
= 0;
573 /* Enable stream out if needed. */
574 if (rctx
->streamout_start
) {
575 r600_context_streamout_begin(rctx
);
576 rctx
->streamout_start
= FALSE
;
581 rctx
->flags
|= R600_CONTEXT_DST_CACHES_DIRTY
;
583 if (rctx
->framebuffer
.zsbuf
)
585 struct pipe_resource
*tex
= rctx
->framebuffer
.zsbuf
->texture
;
586 ((struct r600_resource_texture
*)tex
)->dirty_db
= TRUE
;
589 pipe_resource_reference(&ib
.buffer
, NULL
);