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.
23 #include "r600_formats.h"
24 #include "r600_shader.h"
25 #include "evergreend.h"
27 #include "pipe/p_shader_tokens.h"
28 #include "util/u_pack_color.h"
29 #include "util/u_memory.h"
30 #include "util/u_framebuffer.h"
31 #include "util/u_dual_blend.h"
32 #include "evergreen_compute.h"
33 #include "util/u_math.h"
35 static inline unsigned evergreen_array_mode(unsigned mode
)
38 case RADEON_SURF_MODE_LINEAR_ALIGNED
: return V_028C70_ARRAY_LINEAR_ALIGNED
;
40 case RADEON_SURF_MODE_1D
: return V_028C70_ARRAY_1D_TILED_THIN1
;
42 case RADEON_SURF_MODE_2D
: return V_028C70_ARRAY_2D_TILED_THIN1
;
44 case RADEON_SURF_MODE_LINEAR
: return V_028C70_ARRAY_LINEAR_GENERAL
;
48 static uint32_t eg_num_banks(uint32_t nbanks
)
64 static unsigned eg_tile_split(unsigned tile_split
)
67 case 64: tile_split
= 0; break;
68 case 128: tile_split
= 1; break;
69 case 256: tile_split
= 2; break;
70 case 512: tile_split
= 3; break;
72 case 1024: tile_split
= 4; break;
73 case 2048: tile_split
= 5; break;
74 case 4096: tile_split
= 6; break;
79 static unsigned eg_macro_tile_aspect(unsigned macro_tile_aspect
)
81 switch (macro_tile_aspect
) {
83 case 1: macro_tile_aspect
= 0; break;
84 case 2: macro_tile_aspect
= 1; break;
85 case 4: macro_tile_aspect
= 2; break;
86 case 8: macro_tile_aspect
= 3; break;
88 return macro_tile_aspect
;
91 static unsigned eg_bank_wh(unsigned bankwh
)
95 case 1: bankwh
= 0; break;
96 case 2: bankwh
= 1; break;
97 case 4: bankwh
= 2; break;
98 case 8: bankwh
= 3; break;
103 static uint32_t r600_translate_blend_function(int blend_func
)
105 switch (blend_func
) {
107 return V_028780_COMB_DST_PLUS_SRC
;
108 case PIPE_BLEND_SUBTRACT
:
109 return V_028780_COMB_SRC_MINUS_DST
;
110 case PIPE_BLEND_REVERSE_SUBTRACT
:
111 return V_028780_COMB_DST_MINUS_SRC
;
113 return V_028780_COMB_MIN_DST_SRC
;
115 return V_028780_COMB_MAX_DST_SRC
;
117 R600_ERR("Unknown blend function %d\n", blend_func
);
124 static uint32_t r600_translate_blend_factor(int blend_fact
)
126 switch (blend_fact
) {
127 case PIPE_BLENDFACTOR_ONE
:
128 return V_028780_BLEND_ONE
;
129 case PIPE_BLENDFACTOR_SRC_COLOR
:
130 return V_028780_BLEND_SRC_COLOR
;
131 case PIPE_BLENDFACTOR_SRC_ALPHA
:
132 return V_028780_BLEND_SRC_ALPHA
;
133 case PIPE_BLENDFACTOR_DST_ALPHA
:
134 return V_028780_BLEND_DST_ALPHA
;
135 case PIPE_BLENDFACTOR_DST_COLOR
:
136 return V_028780_BLEND_DST_COLOR
;
137 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
138 return V_028780_BLEND_SRC_ALPHA_SATURATE
;
139 case PIPE_BLENDFACTOR_CONST_COLOR
:
140 return V_028780_BLEND_CONST_COLOR
;
141 case PIPE_BLENDFACTOR_CONST_ALPHA
:
142 return V_028780_BLEND_CONST_ALPHA
;
143 case PIPE_BLENDFACTOR_ZERO
:
144 return V_028780_BLEND_ZERO
;
145 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
146 return V_028780_BLEND_ONE_MINUS_SRC_COLOR
;
147 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
148 return V_028780_BLEND_ONE_MINUS_SRC_ALPHA
;
149 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
150 return V_028780_BLEND_ONE_MINUS_DST_ALPHA
;
151 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
152 return V_028780_BLEND_ONE_MINUS_DST_COLOR
;
153 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
154 return V_028780_BLEND_ONE_MINUS_CONST_COLOR
;
155 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
156 return V_028780_BLEND_ONE_MINUS_CONST_ALPHA
;
157 case PIPE_BLENDFACTOR_SRC1_COLOR
:
158 return V_028780_BLEND_SRC1_COLOR
;
159 case PIPE_BLENDFACTOR_SRC1_ALPHA
:
160 return V_028780_BLEND_SRC1_ALPHA
;
161 case PIPE_BLENDFACTOR_INV_SRC1_COLOR
:
162 return V_028780_BLEND_INV_SRC1_COLOR
;
163 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA
:
164 return V_028780_BLEND_INV_SRC1_ALPHA
;
166 R600_ERR("Bad blend factor %d not supported!\n", blend_fact
);
173 static unsigned r600_tex_dim(unsigned dim
, unsigned nr_samples
)
177 case PIPE_TEXTURE_1D
:
178 return V_030000_SQ_TEX_DIM_1D
;
179 case PIPE_TEXTURE_1D_ARRAY
:
180 return V_030000_SQ_TEX_DIM_1D_ARRAY
;
181 case PIPE_TEXTURE_2D
:
182 case PIPE_TEXTURE_RECT
:
183 return nr_samples
> 1 ? V_030000_SQ_TEX_DIM_2D_MSAA
:
184 V_030000_SQ_TEX_DIM_2D
;
185 case PIPE_TEXTURE_2D_ARRAY
:
186 return nr_samples
> 1 ? V_030000_SQ_TEX_DIM_2D_ARRAY_MSAA
:
187 V_030000_SQ_TEX_DIM_2D_ARRAY
;
188 case PIPE_TEXTURE_3D
:
189 return V_030000_SQ_TEX_DIM_3D
;
190 case PIPE_TEXTURE_CUBE
:
191 case PIPE_TEXTURE_CUBE_ARRAY
:
192 return V_030000_SQ_TEX_DIM_CUBEMAP
;
196 static uint32_t r600_translate_dbformat(enum pipe_format format
)
199 case PIPE_FORMAT_Z16_UNORM
:
200 return V_028040_Z_16
;
201 case PIPE_FORMAT_Z24X8_UNORM
:
202 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
203 case PIPE_FORMAT_X8Z24_UNORM
:
204 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
205 return V_028040_Z_24
;
206 case PIPE_FORMAT_Z32_FLOAT
:
207 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
208 return V_028040_Z_32_FLOAT
;
214 static bool r600_is_sampler_format_supported(struct pipe_screen
*screen
, enum pipe_format format
)
216 return r600_translate_texformat(screen
, format
, NULL
, NULL
, NULL
) != ~0U;
219 static bool r600_is_colorbuffer_format_supported(enum chip_class chip
, enum pipe_format format
)
221 return r600_translate_colorformat(chip
, format
) != ~0U &&
222 r600_translate_colorswap(format
) != ~0U;
225 static bool r600_is_zs_format_supported(enum pipe_format format
)
227 return r600_translate_dbformat(format
) != ~0U;
230 boolean
evergreen_is_format_supported(struct pipe_screen
*screen
,
231 enum pipe_format format
,
232 enum pipe_texture_target target
,
233 unsigned sample_count
,
236 struct r600_screen
*rscreen
= (struct r600_screen
*)screen
;
239 if (target
>= PIPE_MAX_TEXTURE_TYPES
) {
240 R600_ERR("r600: unsupported texture type %d\n", target
);
244 if (!util_format_is_supported(format
, usage
))
247 if (sample_count
> 1) {
248 if (!rscreen
->has_msaa
)
251 switch (sample_count
) {
261 if (usage
& PIPE_BIND_SAMPLER_VIEW
) {
262 if (target
== PIPE_BUFFER
) {
263 if (r600_is_vertex_format_supported(format
))
264 retval
|= PIPE_BIND_SAMPLER_VIEW
;
266 if (r600_is_sampler_format_supported(screen
, format
))
267 retval
|= PIPE_BIND_SAMPLER_VIEW
;
271 if ((usage
& (PIPE_BIND_RENDER_TARGET
|
272 PIPE_BIND_DISPLAY_TARGET
|
275 PIPE_BIND_BLENDABLE
)) &&
276 r600_is_colorbuffer_format_supported(rscreen
->b
.chip_class
, format
)) {
278 (PIPE_BIND_RENDER_TARGET
|
279 PIPE_BIND_DISPLAY_TARGET
|
282 if (!util_format_is_pure_integer(format
) &&
283 !util_format_is_depth_or_stencil(format
))
284 retval
|= usage
& PIPE_BIND_BLENDABLE
;
287 if ((usage
& PIPE_BIND_DEPTH_STENCIL
) &&
288 r600_is_zs_format_supported(format
)) {
289 retval
|= PIPE_BIND_DEPTH_STENCIL
;
292 if ((usage
& PIPE_BIND_VERTEX_BUFFER
) &&
293 r600_is_vertex_format_supported(format
)) {
294 retval
|= PIPE_BIND_VERTEX_BUFFER
;
297 if (usage
& PIPE_BIND_TRANSFER_READ
)
298 retval
|= PIPE_BIND_TRANSFER_READ
;
299 if (usage
& PIPE_BIND_TRANSFER_WRITE
)
300 retval
|= PIPE_BIND_TRANSFER_WRITE
;
302 return retval
== usage
;
305 static void *evergreen_create_blend_state_mode(struct pipe_context
*ctx
,
306 const struct pipe_blend_state
*state
, int mode
)
308 uint32_t color_control
= 0, target_mask
= 0;
309 struct r600_blend_state
*blend
= CALLOC_STRUCT(r600_blend_state
);
315 r600_init_command_buffer(&blend
->buffer
, 20);
316 r600_init_command_buffer(&blend
->buffer_no_blend
, 20);
318 if (state
->logicop_enable
) {
319 color_control
|= (state
->logicop_func
<< 16) | (state
->logicop_func
<< 20);
321 color_control
|= (0xcc << 16);
323 /* we pretend 8 buffer are used, CB_SHADER_MASK will disable unused one */
324 if (state
->independent_blend_enable
) {
325 for (int i
= 0; i
< 8; i
++) {
326 target_mask
|= (state
->rt
[i
].colormask
<< (4 * i
));
329 for (int i
= 0; i
< 8; i
++) {
330 target_mask
|= (state
->rt
[0].colormask
<< (4 * i
));
334 /* only have dual source on MRT0 */
335 blend
->dual_src_blend
= util_blend_state_is_dual(state
, 0);
336 blend
->cb_target_mask
= target_mask
;
337 blend
->alpha_to_one
= state
->alpha_to_one
;
340 color_control
|= S_028808_MODE(mode
);
342 color_control
|= S_028808_MODE(V_028808_CB_DISABLE
);
345 r600_store_context_reg(&blend
->buffer
, R_028808_CB_COLOR_CONTROL
, color_control
);
346 r600_store_context_reg(&blend
->buffer
, R_028B70_DB_ALPHA_TO_MASK
,
347 S_028B70_ALPHA_TO_MASK_ENABLE(state
->alpha_to_coverage
) |
348 S_028B70_ALPHA_TO_MASK_OFFSET0(2) |
349 S_028B70_ALPHA_TO_MASK_OFFSET1(2) |
350 S_028B70_ALPHA_TO_MASK_OFFSET2(2) |
351 S_028B70_ALPHA_TO_MASK_OFFSET3(2));
352 r600_store_context_reg_seq(&blend
->buffer
, R_028780_CB_BLEND0_CONTROL
, 8);
354 /* Copy over the dwords set so far into buffer_no_blend.
355 * Only the CB_BLENDi_CONTROL registers must be set after this. */
356 memcpy(blend
->buffer_no_blend
.buf
, blend
->buffer
.buf
, blend
->buffer
.num_dw
* 4);
357 blend
->buffer_no_blend
.num_dw
= blend
->buffer
.num_dw
;
359 for (int i
= 0; i
< 8; i
++) {
360 /* state->rt entries > 0 only written if independent blending */
361 const int j
= state
->independent_blend_enable
? i
: 0;
363 unsigned eqRGB
= state
->rt
[j
].rgb_func
;
364 unsigned srcRGB
= state
->rt
[j
].rgb_src_factor
;
365 unsigned dstRGB
= state
->rt
[j
].rgb_dst_factor
;
366 unsigned eqA
= state
->rt
[j
].alpha_func
;
367 unsigned srcA
= state
->rt
[j
].alpha_src_factor
;
368 unsigned dstA
= state
->rt
[j
].alpha_dst_factor
;
371 r600_store_value(&blend
->buffer_no_blend
, 0);
373 if (!state
->rt
[j
].blend_enable
) {
374 r600_store_value(&blend
->buffer
, 0);
378 bc
|= S_028780_BLEND_CONTROL_ENABLE(1);
379 bc
|= S_028780_COLOR_COMB_FCN(r600_translate_blend_function(eqRGB
));
380 bc
|= S_028780_COLOR_SRCBLEND(r600_translate_blend_factor(srcRGB
));
381 bc
|= S_028780_COLOR_DESTBLEND(r600_translate_blend_factor(dstRGB
));
383 if (srcA
!= srcRGB
|| dstA
!= dstRGB
|| eqA
!= eqRGB
) {
384 bc
|= S_028780_SEPARATE_ALPHA_BLEND(1);
385 bc
|= S_028780_ALPHA_COMB_FCN(r600_translate_blend_function(eqA
));
386 bc
|= S_028780_ALPHA_SRCBLEND(r600_translate_blend_factor(srcA
));
387 bc
|= S_028780_ALPHA_DESTBLEND(r600_translate_blend_factor(dstA
));
389 r600_store_value(&blend
->buffer
, bc
);
394 static void *evergreen_create_blend_state(struct pipe_context
*ctx
,
395 const struct pipe_blend_state
*state
)
398 return evergreen_create_blend_state_mode(ctx
, state
, V_028808_CB_NORMAL
);
401 static void *evergreen_create_dsa_state(struct pipe_context
*ctx
,
402 const struct pipe_depth_stencil_alpha_state
*state
)
404 unsigned db_depth_control
, alpha_test_control
, alpha_ref
;
405 struct r600_dsa_state
*dsa
= CALLOC_STRUCT(r600_dsa_state
);
411 r600_init_command_buffer(&dsa
->buffer
, 3);
413 dsa
->valuemask
[0] = state
->stencil
[0].valuemask
;
414 dsa
->valuemask
[1] = state
->stencil
[1].valuemask
;
415 dsa
->writemask
[0] = state
->stencil
[0].writemask
;
416 dsa
->writemask
[1] = state
->stencil
[1].writemask
;
417 dsa
->zwritemask
= state
->depth
.writemask
;
419 db_depth_control
= S_028800_Z_ENABLE(state
->depth
.enabled
) |
420 S_028800_Z_WRITE_ENABLE(state
->depth
.writemask
) |
421 S_028800_ZFUNC(state
->depth
.func
);
424 if (state
->stencil
[0].enabled
) {
425 db_depth_control
|= S_028800_STENCIL_ENABLE(1);
426 db_depth_control
|= S_028800_STENCILFUNC(state
->stencil
[0].func
); /* translates straight */
427 db_depth_control
|= S_028800_STENCILFAIL(r600_translate_stencil_op(state
->stencil
[0].fail_op
));
428 db_depth_control
|= S_028800_STENCILZPASS(r600_translate_stencil_op(state
->stencil
[0].zpass_op
));
429 db_depth_control
|= S_028800_STENCILZFAIL(r600_translate_stencil_op(state
->stencil
[0].zfail_op
));
431 if (state
->stencil
[1].enabled
) {
432 db_depth_control
|= S_028800_BACKFACE_ENABLE(1);
433 db_depth_control
|= S_028800_STENCILFUNC_BF(state
->stencil
[1].func
); /* translates straight */
434 db_depth_control
|= S_028800_STENCILFAIL_BF(r600_translate_stencil_op(state
->stencil
[1].fail_op
));
435 db_depth_control
|= S_028800_STENCILZPASS_BF(r600_translate_stencil_op(state
->stencil
[1].zpass_op
));
436 db_depth_control
|= S_028800_STENCILZFAIL_BF(r600_translate_stencil_op(state
->stencil
[1].zfail_op
));
441 alpha_test_control
= 0;
443 if (state
->alpha
.enabled
) {
444 alpha_test_control
= S_028410_ALPHA_FUNC(state
->alpha
.func
);
445 alpha_test_control
|= S_028410_ALPHA_TEST_ENABLE(1);
446 alpha_ref
= fui(state
->alpha
.ref_value
);
448 dsa
->sx_alpha_test_control
= alpha_test_control
& 0xff;
449 dsa
->alpha_ref
= alpha_ref
;
452 r600_store_context_reg(&dsa
->buffer
, R_028800_DB_DEPTH_CONTROL
, db_depth_control
);
456 static void *evergreen_create_rs_state(struct pipe_context
*ctx
,
457 const struct pipe_rasterizer_state
*state
)
459 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
460 unsigned tmp
, spi_interp
;
461 float psize_min
, psize_max
;
462 struct r600_rasterizer_state
*rs
= CALLOC_STRUCT(r600_rasterizer_state
);
468 r600_init_command_buffer(&rs
->buffer
, 30);
470 rs
->flatshade
= state
->flatshade
;
471 rs
->sprite_coord_enable
= state
->sprite_coord_enable
;
472 rs
->two_side
= state
->light_twoside
;
473 rs
->clip_plane_enable
= state
->clip_plane_enable
;
474 rs
->pa_sc_line_stipple
= state
->line_stipple_enable
?
475 S_028A0C_LINE_PATTERN(state
->line_stipple_pattern
) |
476 S_028A0C_REPEAT_COUNT(state
->line_stipple_factor
) : 0;
477 rs
->pa_cl_clip_cntl
=
478 S_028810_PS_UCP_MODE(3) |
479 S_028810_DX_CLIP_SPACE_DEF(state
->clip_halfz
) |
480 S_028810_ZCLIP_NEAR_DISABLE(!state
->depth_clip
) |
481 S_028810_ZCLIP_FAR_DISABLE(!state
->depth_clip
) |
482 S_028810_DX_LINEAR_ATTR_CLIP_ENA(1) |
483 S_028810_DX_RASTERIZATION_KILL(state
->rasterizer_discard
);
484 rs
->multisample_enable
= state
->multisample
;
487 rs
->offset_units
= state
->offset_units
;
488 rs
->offset_scale
= state
->offset_scale
* 16.0f
;
489 rs
->offset_enable
= state
->offset_point
|| state
->offset_line
|| state
->offset_tri
;
491 if (state
->point_size_per_vertex
) {
492 psize_min
= util_get_min_point_size(state
);
495 /* Force the point size to be as if the vertex output was disabled. */
496 psize_min
= state
->point_size
;
497 psize_max
= state
->point_size
;
500 spi_interp
= S_0286D4_FLAT_SHADE_ENA(1);
501 if (state
->sprite_coord_enable
) {
502 spi_interp
|= S_0286D4_PNT_SPRITE_ENA(1) |
503 S_0286D4_PNT_SPRITE_OVRD_X(2) |
504 S_0286D4_PNT_SPRITE_OVRD_Y(3) |
505 S_0286D4_PNT_SPRITE_OVRD_Z(0) |
506 S_0286D4_PNT_SPRITE_OVRD_W(1);
507 if (state
->sprite_coord_mode
!= PIPE_SPRITE_COORD_UPPER_LEFT
) {
508 spi_interp
|= S_0286D4_PNT_SPRITE_TOP_1(1);
512 r600_store_context_reg_seq(&rs
->buffer
, R_028A00_PA_SU_POINT_SIZE
, 3);
513 /* point size 12.4 fixed point (divide by two, because 0.5 = 1 pixel) */
514 tmp
= r600_pack_float_12p4(state
->point_size
/2);
515 r600_store_value(&rs
->buffer
, /* R_028A00_PA_SU_POINT_SIZE */
516 S_028A00_HEIGHT(tmp
) | S_028A00_WIDTH(tmp
));
517 r600_store_value(&rs
->buffer
, /* R_028A04_PA_SU_POINT_MINMAX */
518 S_028A04_MIN_SIZE(r600_pack_float_12p4(psize_min
/2)) |
519 S_028A04_MAX_SIZE(r600_pack_float_12p4(psize_max
/2)));
520 r600_store_value(&rs
->buffer
, /* R_028A08_PA_SU_LINE_CNTL */
521 S_028A08_WIDTH((unsigned)(state
->line_width
* 8)));
523 r600_store_context_reg(&rs
->buffer
, R_0286D4_SPI_INTERP_CONTROL_0
, spi_interp
);
524 r600_store_context_reg(&rs
->buffer
, R_028A48_PA_SC_MODE_CNTL_0
,
525 S_028A48_MSAA_ENABLE(state
->multisample
) |
526 S_028A48_VPORT_SCISSOR_ENABLE(state
->scissor
) |
527 S_028A48_LINE_STIPPLE_ENABLE(state
->line_stipple_enable
));
529 if (rctx
->b
.chip_class
== CAYMAN
) {
530 r600_store_context_reg(&rs
->buffer
, CM_R_028BE4_PA_SU_VTX_CNTL
,
531 S_028C08_PIX_CENTER_HALF(state
->half_pixel_center
) |
532 S_028C08_QUANT_MODE(V_028C08_X_1_256TH
));
534 r600_store_context_reg(&rs
->buffer
, R_028C08_PA_SU_VTX_CNTL
,
535 S_028C08_PIX_CENTER_HALF(state
->half_pixel_center
) |
536 S_028C08_QUANT_MODE(V_028C08_X_1_256TH
));
539 r600_store_context_reg(&rs
->buffer
, R_028B7C_PA_SU_POLY_OFFSET_CLAMP
, fui(state
->offset_clamp
));
540 r600_store_context_reg(&rs
->buffer
, R_028814_PA_SU_SC_MODE_CNTL
,
541 S_028814_PROVOKING_VTX_LAST(!state
->flatshade_first
) |
542 S_028814_CULL_FRONT((state
->cull_face
& PIPE_FACE_FRONT
) ? 1 : 0) |
543 S_028814_CULL_BACK((state
->cull_face
& PIPE_FACE_BACK
) ? 1 : 0) |
544 S_028814_FACE(!state
->front_ccw
) |
545 S_028814_POLY_OFFSET_FRONT_ENABLE(util_get_offset(state
, state
->fill_front
)) |
546 S_028814_POLY_OFFSET_BACK_ENABLE(util_get_offset(state
, state
->fill_back
)) |
547 S_028814_POLY_OFFSET_PARA_ENABLE(state
->offset_point
|| state
->offset_line
) |
548 S_028814_POLY_MODE(state
->fill_front
!= PIPE_POLYGON_MODE_FILL
||
549 state
->fill_back
!= PIPE_POLYGON_MODE_FILL
) |
550 S_028814_POLYMODE_FRONT_PTYPE(r600_translate_fill(state
->fill_front
)) |
551 S_028814_POLYMODE_BACK_PTYPE(r600_translate_fill(state
->fill_back
)));
555 static void *evergreen_create_sampler_state(struct pipe_context
*ctx
,
556 const struct pipe_sampler_state
*state
)
558 struct r600_pipe_sampler_state
*ss
= CALLOC_STRUCT(r600_pipe_sampler_state
);
559 unsigned aniso_flag_offset
= state
->max_anisotropy
> 1 ? 2 : 0;
565 ss
->border_color_use
= sampler_state_needs_border_color(state
);
567 /* R_03C000_SQ_TEX_SAMPLER_WORD0_0 */
568 ss
->tex_sampler_words
[0] =
569 S_03C000_CLAMP_X(r600_tex_wrap(state
->wrap_s
)) |
570 S_03C000_CLAMP_Y(r600_tex_wrap(state
->wrap_t
)) |
571 S_03C000_CLAMP_Z(r600_tex_wrap(state
->wrap_r
)) |
572 S_03C000_XY_MAG_FILTER(r600_tex_filter(state
->mag_img_filter
) | aniso_flag_offset
) |
573 S_03C000_XY_MIN_FILTER(r600_tex_filter(state
->min_img_filter
) | aniso_flag_offset
) |
574 S_03C000_MIP_FILTER(r600_tex_mipfilter(state
->min_mip_filter
)) |
575 S_03C000_MAX_ANISO(r600_tex_aniso_filter(state
->max_anisotropy
)) |
576 S_03C000_DEPTH_COMPARE_FUNCTION(r600_tex_compare(state
->compare_func
)) |
577 S_03C000_BORDER_COLOR_TYPE(ss
->border_color_use
? V_03C000_SQ_TEX_BORDER_COLOR_REGISTER
: 0);
578 /* R_03C004_SQ_TEX_SAMPLER_WORD1_0 */
579 ss
->tex_sampler_words
[1] =
580 S_03C004_MIN_LOD(S_FIXED(CLAMP(state
->min_lod
, 0, 15), 8)) |
581 S_03C004_MAX_LOD(S_FIXED(CLAMP(state
->max_lod
, 0, 15), 8));
582 /* R_03C008_SQ_TEX_SAMPLER_WORD2_0 */
583 ss
->tex_sampler_words
[2] =
584 S_03C008_LOD_BIAS(S_FIXED(CLAMP(state
->lod_bias
, -16, 16), 8)) |
585 (state
->seamless_cube_map
? 0 : S_03C008_DISABLE_CUBE_WRAP(1)) |
588 if (ss
->border_color_use
) {
589 memcpy(&ss
->border_color
, &state
->border_color
, sizeof(state
->border_color
));
594 static struct pipe_sampler_view
*
595 texture_buffer_sampler_view(struct r600_context
*rctx
,
596 struct r600_pipe_sampler_view
*view
,
597 unsigned width0
, unsigned height0
)
600 struct r600_texture
*tmp
= (struct r600_texture
*)view
->base
.texture
;
602 int stride
= util_format_get_blocksize(view
->base
.format
);
603 unsigned format
, num_format
, format_comp
, endian
;
604 unsigned swizzle_res
;
605 unsigned char swizzle
[4];
606 const struct util_format_description
*desc
;
607 unsigned offset
= view
->base
.u
.buf
.first_element
* stride
;
608 unsigned size
= (view
->base
.u
.buf
.last_element
- view
->base
.u
.buf
.first_element
+ 1) * stride
;
610 swizzle
[0] = view
->base
.swizzle_r
;
611 swizzle
[1] = view
->base
.swizzle_g
;
612 swizzle
[2] = view
->base
.swizzle_b
;
613 swizzle
[3] = view
->base
.swizzle_a
;
615 r600_vertex_data_type(view
->base
.format
,
616 &format
, &num_format
, &format_comp
,
619 desc
= util_format_description(view
->base
.format
);
621 swizzle_res
= r600_get_swizzle_combined(desc
->swizzle
, swizzle
, TRUE
);
623 va
= tmp
->resource
.gpu_address
+ offset
;
624 view
->tex_resource
= &tmp
->resource
;
626 view
->skip_mip_address_reloc
= true;
627 view
->tex_resource_words
[0] = va
;
628 view
->tex_resource_words
[1] = size
- 1;
629 view
->tex_resource_words
[2] = S_030008_BASE_ADDRESS_HI(va
>> 32UL) |
630 S_030008_STRIDE(stride
) |
631 S_030008_DATA_FORMAT(format
) |
632 S_030008_NUM_FORMAT_ALL(num_format
) |
633 S_030008_FORMAT_COMP_ALL(format_comp
) |
634 S_030008_ENDIAN_SWAP(endian
);
635 view
->tex_resource_words
[3] = swizzle_res
;
637 * in theory dword 4 is for number of elements, for use with resinfo,
638 * but it seems to utterly fail to work, the amd gpu shader analyser
639 * uses a const buffer to store the element sizes for buffer txq
641 view
->tex_resource_words
[4] = 0;
642 view
->tex_resource_words
[5] = view
->tex_resource_words
[6] = 0;
643 view
->tex_resource_words
[7] = S_03001C_TYPE(V_03001C_SQ_TEX_VTX_VALID_BUFFER
);
645 if (tmp
->resource
.gpu_address
)
646 LIST_ADDTAIL(&view
->list
, &rctx
->b
.texture_buffers
);
650 struct pipe_sampler_view
*
651 evergreen_create_sampler_view_custom(struct pipe_context
*ctx
,
652 struct pipe_resource
*texture
,
653 const struct pipe_sampler_view
*state
,
654 unsigned width0
, unsigned height0
,
655 unsigned force_level
)
657 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
658 struct r600_screen
*rscreen
= (struct r600_screen
*)ctx
->screen
;
659 struct r600_pipe_sampler_view
*view
= CALLOC_STRUCT(r600_pipe_sampler_view
);
660 struct r600_texture
*tmp
= (struct r600_texture
*)texture
;
661 unsigned format
, endian
;
662 uint32_t word4
= 0, yuv_format
= 0, pitch
= 0;
663 unsigned char swizzle
[4], array_mode
= 0, non_disp_tiling
= 0;
664 unsigned height
, depth
, width
;
665 unsigned macro_aspect
, tile_split
, bankh
, bankw
, nbanks
, fmask_bankh
;
666 enum pipe_format pipe_format
= state
->format
;
667 struct radeon_surf_level
*surflevel
;
668 unsigned base_level
, first_level
, last_level
;
669 unsigned dim
, last_layer
;
675 /* initialize base object */
677 view
->base
.texture
= NULL
;
678 pipe_reference(NULL
, &texture
->reference
);
679 view
->base
.texture
= texture
;
680 view
->base
.reference
.count
= 1;
681 view
->base
.context
= ctx
;
683 if (state
->target
== PIPE_BUFFER
)
684 return texture_buffer_sampler_view(rctx
, view
, width0
, height0
);
686 swizzle
[0] = state
->swizzle_r
;
687 swizzle
[1] = state
->swizzle_g
;
688 swizzle
[2] = state
->swizzle_b
;
689 swizzle
[3] = state
->swizzle_a
;
691 tile_split
= tmp
->surface
.tile_split
;
692 surflevel
= tmp
->surface
.level
;
694 /* Texturing with separate depth and stencil. */
695 if (tmp
->is_depth
&& !tmp
->is_flushing_texture
) {
696 switch (pipe_format
) {
697 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
698 pipe_format
= PIPE_FORMAT_Z32_FLOAT
;
700 case PIPE_FORMAT_X8Z24_UNORM
:
701 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
702 /* Z24 is always stored like this. */
703 pipe_format
= PIPE_FORMAT_Z24X8_UNORM
;
705 case PIPE_FORMAT_X24S8_UINT
:
706 case PIPE_FORMAT_S8X24_UINT
:
707 case PIPE_FORMAT_X32_S8X24_UINT
:
708 pipe_format
= PIPE_FORMAT_S8_UINT
;
709 tile_split
= tmp
->surface
.stencil_tile_split
;
710 surflevel
= tmp
->surface
.stencil_level
;
716 format
= r600_translate_texformat(ctx
->screen
, pipe_format
,
718 &word4
, &yuv_format
);
719 assert(format
!= ~0);
725 endian
= r600_colorformat_endian_swap(format
);
728 first_level
= state
->u
.tex
.first_level
;
729 last_level
= state
->u
.tex
.last_level
;
732 depth
= texture
->depth0
;
735 base_level
= force_level
;
738 width
= u_minify(width
, force_level
);
739 height
= u_minify(height
, force_level
);
740 depth
= u_minify(depth
, force_level
);
743 pitch
= surflevel
[base_level
].nblk_x
* util_format_get_blockwidth(pipe_format
);
744 non_disp_tiling
= tmp
->non_disp_tiling
;
746 switch (surflevel
[base_level
].mode
) {
747 case RADEON_SURF_MODE_LINEAR_ALIGNED
:
748 array_mode
= V_028C70_ARRAY_LINEAR_ALIGNED
;
750 case RADEON_SURF_MODE_2D
:
751 array_mode
= V_028C70_ARRAY_2D_TILED_THIN1
;
753 case RADEON_SURF_MODE_1D
:
754 array_mode
= V_028C70_ARRAY_1D_TILED_THIN1
;
756 case RADEON_SURF_MODE_LINEAR
:
758 array_mode
= V_028C70_ARRAY_LINEAR_GENERAL
;
761 macro_aspect
= tmp
->surface
.mtilea
;
762 bankw
= tmp
->surface
.bankw
;
763 bankh
= tmp
->surface
.bankh
;
764 tile_split
= eg_tile_split(tile_split
);
765 macro_aspect
= eg_macro_tile_aspect(macro_aspect
);
766 bankw
= eg_bank_wh(bankw
);
767 bankh
= eg_bank_wh(bankh
);
768 fmask_bankh
= eg_bank_wh(tmp
->fmask
.bank_height
);
770 /* 128 bit formats require tile type = 1 */
771 if (rscreen
->b
.chip_class
== CAYMAN
) {
772 if (util_format_get_blocksize(pipe_format
) >= 16)
775 nbanks
= eg_num_banks(rscreen
->b
.tiling_info
.num_banks
);
777 if (state
->target
== PIPE_TEXTURE_1D_ARRAY
) {
779 depth
= texture
->array_size
;
780 } else if (state
->target
== PIPE_TEXTURE_2D_ARRAY
) {
781 depth
= texture
->array_size
;
782 } else if (state
->target
== PIPE_TEXTURE_CUBE_ARRAY
)
783 depth
= texture
->array_size
/ 6;
785 va
= tmp
->resource
.gpu_address
;
787 if (state
->format
== PIPE_FORMAT_X24S8_UINT
||
788 state
->format
== PIPE_FORMAT_S8X24_UINT
||
789 state
->format
== PIPE_FORMAT_X32_S8X24_UINT
||
790 state
->format
== PIPE_FORMAT_S8_UINT
)
791 view
->is_stencil_sampler
= true;
793 view
->tex_resource
= &tmp
->resource
;
795 /* array type views and views into array types need to use layer offset */
797 if (state
->target
!= PIPE_TEXTURE_CUBE
)
798 dim
= MAX2(state
->target
, texture
->target
);
800 view
->tex_resource_words
[0] = (S_030000_DIM(r600_tex_dim(dim
, texture
->nr_samples
)) |
801 S_030000_PITCH((pitch
/ 8) - 1) |
802 S_030000_TEX_WIDTH(width
- 1));
803 if (rscreen
->b
.chip_class
== CAYMAN
)
804 view
->tex_resource_words
[0] |= CM_S_030000_NON_DISP_TILING_ORDER(non_disp_tiling
);
806 view
->tex_resource_words
[0] |= S_030000_NON_DISP_TILING_ORDER(non_disp_tiling
);
807 view
->tex_resource_words
[1] = (S_030004_TEX_HEIGHT(height
- 1) |
808 S_030004_TEX_DEPTH(depth
- 1) |
809 S_030004_ARRAY_MODE(array_mode
));
810 view
->tex_resource_words
[2] = (surflevel
[base_level
].offset
+ va
) >> 8;
812 /* TEX_RESOURCE_WORD3.MIP_ADDRESS */
813 if (texture
->nr_samples
> 1 && rscreen
->has_compressed_msaa_texturing
) {
815 /* disable FMASK (0 = disabled) */
816 view
->tex_resource_words
[3] = 0;
817 view
->skip_mip_address_reloc
= true;
819 /* FMASK should be in MIP_ADDRESS for multisample textures */
820 view
->tex_resource_words
[3] = (tmp
->fmask
.offset
+ va
) >> 8;
822 } else if (last_level
&& texture
->nr_samples
<= 1) {
823 view
->tex_resource_words
[3] = (surflevel
[1].offset
+ va
) >> 8;
825 view
->tex_resource_words
[3] = (surflevel
[base_level
].offset
+ va
) >> 8;
828 last_layer
= state
->u
.tex
.last_layer
;
829 if (state
->target
!= texture
->target
&& depth
== 1) {
830 last_layer
= state
->u
.tex
.first_layer
;
832 view
->tex_resource_words
[4] = (word4
|
833 S_030010_ENDIAN_SWAP(endian
));
834 view
->tex_resource_words
[5] = S_030014_BASE_ARRAY(state
->u
.tex
.first_layer
) |
835 S_030014_LAST_ARRAY(last_layer
);
836 view
->tex_resource_words
[6] = S_030018_TILE_SPLIT(tile_split
);
838 if (texture
->nr_samples
> 1) {
839 unsigned log_samples
= util_logbase2(texture
->nr_samples
);
840 if (rscreen
->b
.chip_class
== CAYMAN
) {
841 view
->tex_resource_words
[4] |= S_030010_LOG2_NUM_FRAGMENTS(log_samples
);
843 /* LAST_LEVEL holds log2(nr_samples) for multisample textures */
844 view
->tex_resource_words
[5] |= S_030014_LAST_LEVEL(log_samples
);
845 view
->tex_resource_words
[6] |= S_030018_FMASK_BANK_HEIGHT(fmask_bankh
);
847 view
->tex_resource_words
[4] |= S_030010_BASE_LEVEL(first_level
);
848 view
->tex_resource_words
[5] |= S_030014_LAST_LEVEL(last_level
);
849 /* aniso max 16 samples */
850 view
->tex_resource_words
[6] |= S_030018_MAX_ANISO(4);
853 view
->tex_resource_words
[7] = S_03001C_DATA_FORMAT(format
) |
854 S_03001C_TYPE(V_03001C_SQ_TEX_VTX_VALID_TEXTURE
) |
855 S_03001C_BANK_WIDTH(bankw
) |
856 S_03001C_BANK_HEIGHT(bankh
) |
857 S_03001C_MACRO_TILE_ASPECT(macro_aspect
) |
858 S_03001C_NUM_BANKS(nbanks
) |
859 S_03001C_DEPTH_SAMPLE_ORDER(tmp
->is_depth
&& !tmp
->is_flushing_texture
);
863 static struct pipe_sampler_view
*
864 evergreen_create_sampler_view(struct pipe_context
*ctx
,
865 struct pipe_resource
*tex
,
866 const struct pipe_sampler_view
*state
)
868 return evergreen_create_sampler_view_custom(ctx
, tex
, state
,
869 tex
->width0
, tex
->height0
, 0);
872 static void evergreen_emit_config_state(struct r600_context
*rctx
, struct r600_atom
*atom
)
874 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
875 struct r600_config_state
*a
= (struct r600_config_state
*)atom
;
877 radeon_set_config_reg_seq(cs
, R_008C04_SQ_GPR_RESOURCE_MGMT_1
, 3);
878 if (a
->dyn_gpr_enabled
) {
879 radeon_emit(cs
, S_008C04_NUM_CLAUSE_TEMP_GPRS(rctx
->r6xx_num_clause_temp_gprs
));
883 radeon_emit(cs
, a
->sq_gpr_resource_mgmt_1
);
884 radeon_emit(cs
, a
->sq_gpr_resource_mgmt_2
);
885 radeon_emit(cs
, a
->sq_gpr_resource_mgmt_3
);
887 radeon_set_config_reg(cs
, R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ
, (a
->dyn_gpr_enabled
<< 8));
888 if (a
->dyn_gpr_enabled
) {
889 radeon_set_context_reg(cs
, R_028838_SQ_DYN_GPR_RESOURCE_LIMIT_1
,
890 S_028838_PS_GPRS(0x1e) |
891 S_028838_VS_GPRS(0x1e) |
892 S_028838_GS_GPRS(0x1e) |
893 S_028838_ES_GPRS(0x1e) |
894 S_028838_HS_GPRS(0x1e) |
895 S_028838_LS_GPRS(0x1e)); /* workaround for hw issues with dyn gpr - must set all limits to 240 instead of 0, 0x1e == 240 / 8*/
899 static void evergreen_emit_clip_state(struct r600_context
*rctx
, struct r600_atom
*atom
)
901 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
902 struct pipe_clip_state
*state
= &rctx
->clip_state
.state
;
904 radeon_set_context_reg_seq(cs
, R_0285BC_PA_CL_UCP0_X
, 6*4);
905 radeon_emit_array(cs
, (unsigned*)state
, 6*4);
908 static void evergreen_set_polygon_stipple(struct pipe_context
*ctx
,
909 const struct pipe_poly_stipple
*state
)
913 static void evergreen_get_scissor_rect(struct r600_context
*rctx
,
914 unsigned tl_x
, unsigned tl_y
, unsigned br_x
, unsigned br_y
,
915 uint32_t *tl
, uint32_t *br
)
917 /* EG hw workaround */
923 /* cayman hw workaround */
924 if (rctx
->b
.chip_class
== CAYMAN
) {
925 if (br_x
== 1 && br_y
== 1)
929 *tl
= S_028240_TL_X(tl_x
) | S_028240_TL_Y(tl_y
);
930 *br
= S_028244_BR_X(br_x
) | S_028244_BR_Y(br_y
);
933 static void evergreen_set_scissor_states(struct pipe_context
*ctx
,
935 unsigned num_scissors
,
936 const struct pipe_scissor_state
*state
)
938 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
939 struct r600_scissor_state
*rstate
= &rctx
->scissor
;
942 for (i
= start_slot
; i
< start_slot
+ num_scissors
; i
++)
943 rstate
->scissor
[i
] = state
[i
- start_slot
];
944 rstate
->dirty_mask
|= ((1 << num_scissors
) - 1) << start_slot
;
945 rstate
->atom
.num_dw
= util_bitcount(rstate
->dirty_mask
) * 4;
946 r600_mark_atom_dirty(rctx
, &rstate
->atom
);
949 static void evergreen_emit_scissor_state(struct r600_context
*rctx
, struct r600_atom
*atom
)
951 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
952 struct r600_scissor_state
*rstate
= &rctx
->scissor
;
953 struct pipe_scissor_state
*state
;
958 dirty_mask
= rstate
->dirty_mask
;
959 while (dirty_mask
!= 0) {
960 i
= u_bit_scan(&dirty_mask
);
961 state
= &rstate
->scissor
[i
];
962 evergreen_get_scissor_rect(rctx
, state
->minx
, state
->miny
, state
->maxx
, state
->maxy
, &tl
, &br
);
965 radeon_set_context_reg_seq(cs
, R_028250_PA_SC_VPORT_SCISSOR_0_TL
+ offset
, 2);
969 rstate
->dirty_mask
= 0;
970 rstate
->atom
.num_dw
= 0;
974 * This function intializes the CB* register values for RATs. It is meant
975 * to be used for 1D aligned buffers that do not have an associated
978 void evergreen_init_color_surface_rat(struct r600_context
*rctx
,
979 struct r600_surface
*surf
)
981 struct pipe_resource
*pipe_buffer
= surf
->base
.texture
;
982 unsigned format
= r600_translate_colorformat(rctx
->b
.chip_class
,
984 unsigned endian
= r600_colorformat_endian_swap(format
);
985 unsigned swap
= r600_translate_colorswap(surf
->base
.format
);
986 unsigned block_size
=
987 align(util_format_get_blocksize(pipe_buffer
->format
), 4);
988 unsigned pitch_alignment
=
989 MAX2(64, rctx
->screen
->b
.tiling_info
.group_bytes
/ block_size
);
990 unsigned pitch
= align(pipe_buffer
->width0
, pitch_alignment
);
992 /* XXX: This is copied from evergreen_init_color_surface(). I don't
993 * know why this is necessary.
995 if (pipe_buffer
->usage
== PIPE_USAGE_STAGING
) {
996 endian
= ENDIAN_NONE
;
999 surf
->cb_color_base
= r600_resource(pipe_buffer
)->gpu_address
>> 8;
1001 surf
->cb_color_pitch
= (pitch
/ 8) - 1;
1003 surf
->cb_color_slice
= 0;
1005 surf
->cb_color_view
= 0;
1007 surf
->cb_color_info
=
1008 S_028C70_ENDIAN(endian
)
1009 | S_028C70_FORMAT(format
)
1010 | S_028C70_ARRAY_MODE(V_028C70_ARRAY_LINEAR_ALIGNED
)
1011 | S_028C70_NUMBER_TYPE(V_028C70_NUMBER_UINT
)
1012 | S_028C70_COMP_SWAP(swap
)
1013 | S_028C70_BLEND_BYPASS(1) /* We must set this bit because we
1014 * are using NUMBER_UINT */
1018 surf
->cb_color_attrib
= S_028C74_NON_DISP_TILING_ORDER(1);
1020 /* For buffers, CB_COLOR0_DIM needs to be set to the number of
1022 surf
->cb_color_dim
= pipe_buffer
->width0
;
1024 /* Set the buffer range the GPU will have access to: */
1025 util_range_add(&r600_resource(pipe_buffer
)->valid_buffer_range
,
1026 0, pipe_buffer
->width0
);
1028 surf
->cb_color_fmask
= surf
->cb_color_base
;
1029 surf
->cb_color_fmask_slice
= 0;
1032 void evergreen_init_color_surface(struct r600_context
*rctx
,
1033 struct r600_surface
*surf
)
1035 struct r600_screen
*rscreen
= rctx
->screen
;
1036 struct r600_texture
*rtex
= (struct r600_texture
*)surf
->base
.texture
;
1037 unsigned level
= surf
->base
.u
.tex
.level
;
1038 unsigned pitch
, slice
;
1039 unsigned color_info
, color_attrib
, color_dim
= 0, color_view
;
1040 unsigned format
, swap
, ntype
, endian
;
1041 uint64_t offset
, base_offset
;
1042 unsigned non_disp_tiling
, macro_aspect
, tile_split
, bankh
, bankw
, fmask_bankh
, nbanks
;
1043 const struct util_format_description
*desc
;
1045 bool blend_clamp
= 0, blend_bypass
= 0;
1047 offset
= rtex
->surface
.level
[level
].offset
;
1048 if (rtex
->surface
.level
[level
].mode
== RADEON_SURF_MODE_LINEAR
) {
1049 assert(surf
->base
.u
.tex
.first_layer
== surf
->base
.u
.tex
.last_layer
);
1050 offset
+= rtex
->surface
.level
[level
].slice_size
*
1051 surf
->base
.u
.tex
.first_layer
;
1054 color_view
= S_028C6C_SLICE_START(surf
->base
.u
.tex
.first_layer
) |
1055 S_028C6C_SLICE_MAX(surf
->base
.u
.tex
.last_layer
);
1057 pitch
= (rtex
->surface
.level
[level
].nblk_x
) / 8 - 1;
1058 slice
= (rtex
->surface
.level
[level
].nblk_x
* rtex
->surface
.level
[level
].nblk_y
) / 64;
1063 switch (rtex
->surface
.level
[level
].mode
) {
1064 case RADEON_SURF_MODE_LINEAR_ALIGNED
:
1065 color_info
= S_028C70_ARRAY_MODE(V_028C70_ARRAY_LINEAR_ALIGNED
);
1066 non_disp_tiling
= 1;
1068 case RADEON_SURF_MODE_1D
:
1069 color_info
= S_028C70_ARRAY_MODE(V_028C70_ARRAY_1D_TILED_THIN1
);
1070 non_disp_tiling
= rtex
->non_disp_tiling
;
1072 case RADEON_SURF_MODE_2D
:
1073 color_info
= S_028C70_ARRAY_MODE(V_028C70_ARRAY_2D_TILED_THIN1
);
1074 non_disp_tiling
= rtex
->non_disp_tiling
;
1076 case RADEON_SURF_MODE_LINEAR
:
1078 color_info
= S_028C70_ARRAY_MODE(V_028C70_ARRAY_LINEAR_GENERAL
);
1079 non_disp_tiling
= 1;
1082 tile_split
= rtex
->surface
.tile_split
;
1083 macro_aspect
= rtex
->surface
.mtilea
;
1084 bankw
= rtex
->surface
.bankw
;
1085 bankh
= rtex
->surface
.bankh
;
1086 if (rtex
->fmask
.size
)
1087 fmask_bankh
= rtex
->fmask
.bank_height
;
1089 fmask_bankh
= rtex
->surface
.bankh
;
1090 tile_split
= eg_tile_split(tile_split
);
1091 macro_aspect
= eg_macro_tile_aspect(macro_aspect
);
1092 bankw
= eg_bank_wh(bankw
);
1093 bankh
= eg_bank_wh(bankh
);
1094 fmask_bankh
= eg_bank_wh(fmask_bankh
);
1096 /* 128 bit formats require tile type = 1 */
1097 if (rscreen
->b
.chip_class
== CAYMAN
) {
1098 if (util_format_get_blocksize(surf
->base
.format
) >= 16)
1099 non_disp_tiling
= 1;
1101 nbanks
= eg_num_banks(rscreen
->b
.tiling_info
.num_banks
);
1102 desc
= util_format_description(surf
->base
.format
);
1103 for (i
= 0; i
< 4; i
++) {
1104 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
1109 color_attrib
= S_028C74_TILE_SPLIT(tile_split
)|
1110 S_028C74_NUM_BANKS(nbanks
) |
1111 S_028C74_BANK_WIDTH(bankw
) |
1112 S_028C74_BANK_HEIGHT(bankh
) |
1113 S_028C74_MACRO_TILE_ASPECT(macro_aspect
) |
1114 S_028C74_NON_DISP_TILING_ORDER(non_disp_tiling
) |
1115 S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
1117 if (rctx
->b
.chip_class
== CAYMAN
) {
1118 color_attrib
|= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] ==
1119 UTIL_FORMAT_SWIZZLE_1
);
1121 if (rtex
->resource
.b
.b
.nr_samples
> 1) {
1122 unsigned log_samples
= util_logbase2(rtex
->resource
.b
.b
.nr_samples
);
1123 color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
1124 S_028C74_NUM_FRAGMENTS(log_samples
);
1128 ntype
= V_028C70_NUMBER_UNORM
;
1129 if (desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
)
1130 ntype
= V_028C70_NUMBER_SRGB
;
1131 else if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
1132 if (desc
->channel
[i
].normalized
)
1133 ntype
= V_028C70_NUMBER_SNORM
;
1134 else if (desc
->channel
[i
].pure_integer
)
1135 ntype
= V_028C70_NUMBER_SINT
;
1136 } else if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_UNSIGNED
) {
1137 if (desc
->channel
[i
].normalized
)
1138 ntype
= V_028C70_NUMBER_UNORM
;
1139 else if (desc
->channel
[i
].pure_integer
)
1140 ntype
= V_028C70_NUMBER_UINT
;
1143 format
= r600_translate_colorformat(rctx
->b
.chip_class
, surf
->base
.format
);
1144 assert(format
!= ~0);
1146 swap
= r600_translate_colorswap(surf
->base
.format
);
1149 if (rtex
->resource
.b
.b
.usage
== PIPE_USAGE_STAGING
) {
1150 endian
= ENDIAN_NONE
;
1152 endian
= r600_colorformat_endian_swap(format
);
1155 /* blend clamp should be set for all NORM/SRGB types */
1156 if (ntype
== V_028C70_NUMBER_UNORM
|| ntype
== V_028C70_NUMBER_SNORM
||
1157 ntype
== V_028C70_NUMBER_SRGB
)
1160 /* set blend bypass according to docs if SINT/UINT or
1161 8/24 COLOR variants */
1162 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
1163 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
1164 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
1169 surf
->alphatest_bypass
= ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
;
1171 color_info
|= S_028C70_FORMAT(format
) |
1172 S_028C70_COMP_SWAP(swap
) |
1173 S_028C70_BLEND_CLAMP(blend_clamp
) |
1174 S_028C70_BLEND_BYPASS(blend_bypass
) |
1175 S_028C70_NUMBER_TYPE(ntype
) |
1176 S_028C70_ENDIAN(endian
);
1178 /* EXPORT_NORM is an optimzation that can be enabled for better
1179 * performance in certain cases.
1180 * EXPORT_NORM can be enabled if:
1181 * - 11-bit or smaller UNORM/SNORM/SRGB
1182 * - 16-bit or smaller FLOAT
1184 if (desc
->colorspace
!= UTIL_FORMAT_COLORSPACE_ZS
&&
1185 ((desc
->channel
[i
].size
< 12 &&
1186 desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_FLOAT
&&
1187 ntype
!= V_028C70_NUMBER_UINT
&& ntype
!= V_028C70_NUMBER_SINT
) ||
1188 (desc
->channel
[i
].size
< 17 &&
1189 desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_FLOAT
))) {
1190 color_info
|= S_028C70_SOURCE_FORMAT(V_028C70_EXPORT_4C_16BPC
);
1191 surf
->export_16bpc
= true;
1194 if (rtex
->fmask
.size
) {
1195 color_info
|= S_028C70_COMPRESSION(1);
1198 base_offset
= rtex
->resource
.gpu_address
;
1200 /* XXX handle enabling of CB beyond BASE8 which has different offset */
1201 surf
->cb_color_base
= (base_offset
+ offset
) >> 8;
1202 surf
->cb_color_dim
= color_dim
;
1203 surf
->cb_color_info
= color_info
;
1204 surf
->cb_color_pitch
= S_028C64_PITCH_TILE_MAX(pitch
);
1205 surf
->cb_color_slice
= S_028C68_SLICE_TILE_MAX(slice
);
1206 surf
->cb_color_view
= color_view
;
1207 surf
->cb_color_attrib
= color_attrib
;
1208 if (rtex
->fmask
.size
) {
1209 surf
->cb_color_fmask
= (base_offset
+ rtex
->fmask
.offset
) >> 8;
1210 surf
->cb_color_fmask_slice
= S_028C88_TILE_MAX(rtex
->fmask
.slice_tile_max
);
1212 surf
->cb_color_fmask
= surf
->cb_color_base
;
1213 surf
->cb_color_fmask_slice
= S_028C88_TILE_MAX(slice
);
1216 surf
->color_initialized
= true;
1219 static void evergreen_init_depth_surface(struct r600_context
*rctx
,
1220 struct r600_surface
*surf
)
1222 struct r600_screen
*rscreen
= rctx
->screen
;
1223 struct r600_texture
*rtex
= (struct r600_texture
*)surf
->base
.texture
;
1224 unsigned level
= surf
->base
.u
.tex
.level
;
1225 struct radeon_surf_level
*levelinfo
= &rtex
->surface
.level
[level
];
1227 unsigned format
, array_mode
;
1228 unsigned macro_aspect
, tile_split
, bankh
, bankw
, nbanks
;
1231 format
= r600_translate_dbformat(surf
->base
.format
);
1232 assert(format
!= ~0);
1234 offset
= rtex
->resource
.gpu_address
;
1235 offset
+= rtex
->surface
.level
[level
].offset
;
1237 switch (rtex
->surface
.level
[level
].mode
) {
1238 case RADEON_SURF_MODE_2D
:
1239 array_mode
= V_028C70_ARRAY_2D_TILED_THIN1
;
1241 case RADEON_SURF_MODE_1D
:
1242 case RADEON_SURF_MODE_LINEAR_ALIGNED
:
1243 case RADEON_SURF_MODE_LINEAR
:
1245 array_mode
= V_028C70_ARRAY_1D_TILED_THIN1
;
1248 tile_split
= rtex
->surface
.tile_split
;
1249 macro_aspect
= rtex
->surface
.mtilea
;
1250 bankw
= rtex
->surface
.bankw
;
1251 bankh
= rtex
->surface
.bankh
;
1252 tile_split
= eg_tile_split(tile_split
);
1253 macro_aspect
= eg_macro_tile_aspect(macro_aspect
);
1254 bankw
= eg_bank_wh(bankw
);
1255 bankh
= eg_bank_wh(bankh
);
1256 nbanks
= eg_num_banks(rscreen
->b
.tiling_info
.num_banks
);
1259 surf
->db_z_info
= S_028040_ARRAY_MODE(array_mode
) |
1260 S_028040_FORMAT(format
) |
1261 S_028040_TILE_SPLIT(tile_split
)|
1262 S_028040_NUM_BANKS(nbanks
) |
1263 S_028040_BANK_WIDTH(bankw
) |
1264 S_028040_BANK_HEIGHT(bankh
) |
1265 S_028040_MACRO_TILE_ASPECT(macro_aspect
);
1266 if (rscreen
->b
.chip_class
== CAYMAN
&& rtex
->resource
.b
.b
.nr_samples
> 1) {
1267 surf
->db_z_info
|= S_028040_NUM_SAMPLES(util_logbase2(rtex
->resource
.b
.b
.nr_samples
));
1270 assert(levelinfo
->nblk_x
% 8 == 0 && levelinfo
->nblk_y
% 8 == 0);
1272 surf
->db_depth_base
= offset
;
1273 surf
->db_depth_view
= S_028008_SLICE_START(surf
->base
.u
.tex
.first_layer
) |
1274 S_028008_SLICE_MAX(surf
->base
.u
.tex
.last_layer
);
1275 surf
->db_depth_size
= S_028058_PITCH_TILE_MAX(levelinfo
->nblk_x
/ 8 - 1) |
1276 S_028058_HEIGHT_TILE_MAX(levelinfo
->nblk_y
/ 8 - 1);
1277 surf
->db_depth_slice
= S_02805C_SLICE_TILE_MAX(levelinfo
->nblk_x
*
1278 levelinfo
->nblk_y
/ 64 - 1);
1280 switch (surf
->base
.format
) {
1281 case PIPE_FORMAT_Z24X8_UNORM
:
1282 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
1283 case PIPE_FORMAT_X8Z24_UNORM
:
1284 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
1285 surf
->pa_su_poly_offset_db_fmt_cntl
=
1286 S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS((char)-24);
1288 case PIPE_FORMAT_Z32_FLOAT
:
1289 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
1290 surf
->pa_su_poly_offset_db_fmt_cntl
=
1291 S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS((char)-23) |
1292 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
1294 case PIPE_FORMAT_Z16_UNORM
:
1295 surf
->pa_su_poly_offset_db_fmt_cntl
=
1296 S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS((char)-16);
1301 if (rtex
->surface
.flags
& RADEON_SURF_SBUFFER
) {
1302 uint64_t stencil_offset
;
1303 unsigned stile_split
= rtex
->surface
.stencil_tile_split
;
1305 stile_split
= eg_tile_split(stile_split
);
1307 stencil_offset
= rtex
->surface
.stencil_level
[level
].offset
;
1308 stencil_offset
+= rtex
->resource
.gpu_address
;
1310 surf
->db_stencil_base
= stencil_offset
>> 8;
1311 surf
->db_stencil_info
= S_028044_FORMAT(V_028044_STENCIL_8
) |
1312 S_028044_TILE_SPLIT(stile_split
);
1314 surf
->db_stencil_base
= offset
;
1315 /* DRM 2.6.18 allows the INVALID format to disable stencil.
1316 * Older kernels are out of luck. */
1317 surf
->db_stencil_info
= rctx
->screen
->b
.info
.drm_minor
>= 18 ?
1318 S_028044_FORMAT(V_028044_STENCIL_INVALID
) :
1319 S_028044_FORMAT(V_028044_STENCIL_8
);
1322 /* use htile only for first level */
1323 if (rtex
->htile_buffer
&& !level
) {
1324 uint64_t va
= rtex
->htile_buffer
->gpu_address
;
1325 surf
->db_htile_data_base
= va
>> 8;
1326 surf
->db_htile_surface
= S_028ABC_HTILE_WIDTH(1) |
1327 S_028ABC_HTILE_HEIGHT(1) |
1328 S_028ABC_FULL_CACHE(1);
1329 surf
->db_z_info
|= S_028040_TILE_SURFACE_ENABLE(1);
1330 surf
->db_preload_control
= 0;
1333 surf
->depth_initialized
= true;
1336 static void evergreen_set_framebuffer_state(struct pipe_context
*ctx
,
1337 const struct pipe_framebuffer_state
*state
)
1339 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
1340 struct r600_surface
*surf
;
1341 struct r600_texture
*rtex
;
1342 uint32_t i
, log_samples
;
1344 if (rctx
->framebuffer
.state
.nr_cbufs
) {
1345 rctx
->b
.flags
|= R600_CONTEXT_WAIT_3D_IDLE
| R600_CONTEXT_FLUSH_AND_INV
;
1346 rctx
->b
.flags
|= R600_CONTEXT_FLUSH_AND_INV_CB
|
1347 R600_CONTEXT_FLUSH_AND_INV_CB_META
;
1349 if (rctx
->framebuffer
.state
.zsbuf
) {
1350 rctx
->b
.flags
|= R600_CONTEXT_WAIT_3D_IDLE
| R600_CONTEXT_FLUSH_AND_INV
;
1351 rctx
->b
.flags
|= R600_CONTEXT_FLUSH_AND_INV_DB
;
1353 rtex
= (struct r600_texture
*)rctx
->framebuffer
.state
.zsbuf
->texture
;
1354 if (rtex
->htile_buffer
) {
1355 rctx
->b
.flags
|= R600_CONTEXT_FLUSH_AND_INV_DB_META
;
1359 util_copy_framebuffer_state(&rctx
->framebuffer
.state
, state
);
1362 rctx
->framebuffer
.export_16bpc
= state
->nr_cbufs
!= 0;
1363 rctx
->framebuffer
.cb0_is_integer
= state
->nr_cbufs
&& state
->cbufs
[0] &&
1364 util_format_is_pure_integer(state
->cbufs
[0]->format
);
1365 rctx
->framebuffer
.compressed_cb_mask
= 0;
1366 rctx
->framebuffer
.nr_samples
= util_framebuffer_get_num_samples(state
);
1368 for (i
= 0; i
< state
->nr_cbufs
; i
++) {
1369 surf
= (struct r600_surface
*)state
->cbufs
[i
];
1373 rtex
= (struct r600_texture
*)surf
->base
.texture
;
1375 r600_context_add_resource_size(ctx
, state
->cbufs
[i
]->texture
);
1377 if (!surf
->color_initialized
) {
1378 evergreen_init_color_surface(rctx
, surf
);
1381 if (!surf
->export_16bpc
) {
1382 rctx
->framebuffer
.export_16bpc
= false;
1385 if (rtex
->fmask
.size
&& rtex
->cmask
.size
) {
1386 rctx
->framebuffer
.compressed_cb_mask
|= 1 << i
;
1390 /* Update alpha-test state dependencies.
1391 * Alpha-test is done on the first colorbuffer only. */
1392 if (state
->nr_cbufs
) {
1393 bool alphatest_bypass
= false;
1394 bool export_16bpc
= true;
1396 surf
= (struct r600_surface
*)state
->cbufs
[0];
1398 alphatest_bypass
= surf
->alphatest_bypass
;
1399 export_16bpc
= surf
->export_16bpc
;
1402 if (rctx
->alphatest_state
.bypass
!= alphatest_bypass
) {
1403 rctx
->alphatest_state
.bypass
= alphatest_bypass
;
1404 r600_mark_atom_dirty(rctx
, &rctx
->alphatest_state
.atom
);
1406 if (rctx
->alphatest_state
.cb0_export_16bpc
!= export_16bpc
) {
1407 rctx
->alphatest_state
.cb0_export_16bpc
= export_16bpc
;
1408 r600_mark_atom_dirty(rctx
, &rctx
->alphatest_state
.atom
);
1414 surf
= (struct r600_surface
*)state
->zsbuf
;
1416 r600_context_add_resource_size(ctx
, state
->zsbuf
->texture
);
1418 if (!surf
->depth_initialized
) {
1419 evergreen_init_depth_surface(rctx
, surf
);
1422 if (state
->zsbuf
->format
!= rctx
->poly_offset_state
.zs_format
) {
1423 rctx
->poly_offset_state
.zs_format
= state
->zsbuf
->format
;
1424 r600_mark_atom_dirty(rctx
, &rctx
->poly_offset_state
.atom
);
1427 if (rctx
->db_state
.rsurf
!= surf
) {
1428 rctx
->db_state
.rsurf
= surf
;
1429 r600_mark_atom_dirty(rctx
, &rctx
->db_state
.atom
);
1430 r600_mark_atom_dirty(rctx
, &rctx
->db_misc_state
.atom
);
1432 } else if (rctx
->db_state
.rsurf
) {
1433 rctx
->db_state
.rsurf
= NULL
;
1434 r600_mark_atom_dirty(rctx
, &rctx
->db_state
.atom
);
1435 r600_mark_atom_dirty(rctx
, &rctx
->db_misc_state
.atom
);
1438 if (rctx
->cb_misc_state
.nr_cbufs
!= state
->nr_cbufs
) {
1439 rctx
->cb_misc_state
.nr_cbufs
= state
->nr_cbufs
;
1440 r600_mark_atom_dirty(rctx
, &rctx
->cb_misc_state
.atom
);
1443 if (state
->nr_cbufs
== 0 && rctx
->alphatest_state
.bypass
) {
1444 rctx
->alphatest_state
.bypass
= false;
1445 r600_mark_atom_dirty(rctx
, &rctx
->alphatest_state
.atom
);
1448 log_samples
= util_logbase2(rctx
->framebuffer
.nr_samples
);
1449 /* This is for Cayman to program SAMPLE_RATE, and for RV770 to fix a hw bug. */
1450 if ((rctx
->b
.chip_class
== CAYMAN
||
1451 rctx
->b
.family
== CHIP_RV770
) &&
1452 rctx
->db_misc_state
.log_samples
!= log_samples
) {
1453 rctx
->db_misc_state
.log_samples
= log_samples
;
1454 r600_mark_atom_dirty(rctx
, &rctx
->db_misc_state
.atom
);
1458 /* Calculate the CS size. */
1459 rctx
->framebuffer
.atom
.num_dw
= 4; /* SCISSOR */
1462 if (rctx
->b
.chip_class
== EVERGREEN
)
1463 rctx
->framebuffer
.atom
.num_dw
+= 17; /* Evergreen */
1465 rctx
->framebuffer
.atom
.num_dw
+= 28; /* Cayman */
1468 rctx
->framebuffer
.atom
.num_dw
+= state
->nr_cbufs
* 23;
1469 if (rctx
->keep_tiling_flags
)
1470 rctx
->framebuffer
.atom
.num_dw
+= state
->nr_cbufs
* 2;
1471 rctx
->framebuffer
.atom
.num_dw
+= (12 - state
->nr_cbufs
) * 3;
1475 rctx
->framebuffer
.atom
.num_dw
+= 24;
1476 if (rctx
->keep_tiling_flags
)
1477 rctx
->framebuffer
.atom
.num_dw
+= 2;
1478 } else if (rctx
->screen
->b
.info
.drm_minor
>= 18) {
1479 rctx
->framebuffer
.atom
.num_dw
+= 4;
1482 r600_mark_atom_dirty(rctx
, &rctx
->framebuffer
.atom
);
1484 r600_set_sample_locations_constant_buffer(rctx
);
1487 static void evergreen_set_min_samples(struct pipe_context
*ctx
, unsigned min_samples
)
1489 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
1491 if (rctx
->ps_iter_samples
== min_samples
)
1494 rctx
->ps_iter_samples
= min_samples
;
1495 if (rctx
->framebuffer
.nr_samples
> 1) {
1496 r600_mark_atom_dirty(rctx
, &rctx
->framebuffer
.atom
);
1501 static uint32_t sample_locs_8x
[] = {
1502 FILL_SREG(-1, 1, 1, 5, 3, -5, 5, 3),
1503 FILL_SREG(-7, -1, -3, -7, 7, -3, -5, 7),
1504 FILL_SREG(-1, 1, 1, 5, 3, -5, 5, 3),
1505 FILL_SREG(-7, -1, -3, -7, 7, -3, -5, 7),
1506 FILL_SREG(-1, 1, 1, 5, 3, -5, 5, 3),
1507 FILL_SREG(-7, -1, -3, -7, 7, -3, -5, 7),
1508 FILL_SREG(-1, 1, 1, 5, 3, -5, 5, 3),
1509 FILL_SREG(-7, -1, -3, -7, 7, -3, -5, 7),
1511 static unsigned max_dist_8x
= 7;
1513 static void evergreen_get_sample_position(struct pipe_context
*ctx
,
1514 unsigned sample_count
,
1515 unsigned sample_index
,
1522 switch (sample_count
) {
1525 out_value
[0] = out_value
[1] = 0.5;
1528 offset
= 4 * (sample_index
* 2);
1529 val
.idx
= (eg_sample_locs_2x
[0] >> offset
) & 0xf;
1530 out_value
[0] = (float)(val
.idx
+ 8) / 16.0f
;
1531 val
.idx
= (eg_sample_locs_2x
[0] >> (offset
+ 4)) & 0xf;
1532 out_value
[1] = (float)(val
.idx
+ 8) / 16.0f
;
1535 offset
= 4 * (sample_index
* 2);
1536 val
.idx
= (eg_sample_locs_4x
[0] >> offset
) & 0xf;
1537 out_value
[0] = (float)(val
.idx
+ 8) / 16.0f
;
1538 val
.idx
= (eg_sample_locs_4x
[0] >> (offset
+ 4)) & 0xf;
1539 out_value
[1] = (float)(val
.idx
+ 8) / 16.0f
;
1542 offset
= 4 * (sample_index
% 4 * 2);
1543 index
= (sample_index
/ 4);
1544 val
.idx
= (sample_locs_8x
[index
] >> offset
) & 0xf;
1545 out_value
[0] = (float)(val
.idx
+ 8) / 16.0f
;
1546 val
.idx
= (sample_locs_8x
[index
] >> (offset
+ 4)) & 0xf;
1547 out_value
[1] = (float)(val
.idx
+ 8) / 16.0f
;
1552 static void evergreen_emit_msaa_state(struct r600_context
*rctx
, int nr_samples
, int ps_iter_samples
)
1555 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
1556 unsigned max_dist
= 0;
1558 switch (nr_samples
) {
1563 radeon_set_context_reg_seq(cs
, R_028C1C_PA_SC_AA_SAMPLE_LOCS_0
, Elements(eg_sample_locs_2x
));
1564 radeon_emit_array(cs
, eg_sample_locs_2x
, Elements(eg_sample_locs_2x
));
1565 max_dist
= eg_max_dist_2x
;
1568 radeon_set_context_reg_seq(cs
, R_028C1C_PA_SC_AA_SAMPLE_LOCS_0
, Elements(eg_sample_locs_4x
));
1569 radeon_emit_array(cs
, eg_sample_locs_4x
, Elements(eg_sample_locs_4x
));
1570 max_dist
= eg_max_dist_4x
;
1573 radeon_set_context_reg_seq(cs
, R_028C1C_PA_SC_AA_SAMPLE_LOCS_0
, Elements(sample_locs_8x
));
1574 radeon_emit_array(cs
, sample_locs_8x
, Elements(sample_locs_8x
));
1575 max_dist
= max_dist_8x
;
1579 if (nr_samples
> 1) {
1580 radeon_set_context_reg_seq(cs
, R_028C00_PA_SC_LINE_CNTL
, 2);
1581 radeon_emit(cs
, S_028C00_LAST_PIXEL(1) |
1582 S_028C00_EXPAND_LINE_WIDTH(1)); /* R_028C00_PA_SC_LINE_CNTL */
1583 radeon_emit(cs
, S_028C04_MSAA_NUM_SAMPLES(util_logbase2(nr_samples
)) |
1584 S_028C04_MAX_SAMPLE_DIST(max_dist
)); /* R_028C04_PA_SC_AA_CONFIG */
1585 radeon_set_context_reg(cs
, EG_R_028A4C_PA_SC_MODE_CNTL_1
,
1586 EG_S_028A4C_PS_ITER_SAMPLE(ps_iter_samples
> 1) |
1587 EG_S_028A4C_FORCE_EOV_CNTDWN_ENABLE(1) |
1588 EG_S_028A4C_FORCE_EOV_REZ_ENABLE(1));
1590 radeon_set_context_reg_seq(cs
, R_028C00_PA_SC_LINE_CNTL
, 2);
1591 radeon_emit(cs
, S_028C00_LAST_PIXEL(1)); /* R_028C00_PA_SC_LINE_CNTL */
1592 radeon_emit(cs
, 0); /* R_028C04_PA_SC_AA_CONFIG */
1593 radeon_set_context_reg(cs
, EG_R_028A4C_PA_SC_MODE_CNTL_1
,
1594 EG_S_028A4C_FORCE_EOV_CNTDWN_ENABLE(1) |
1595 EG_S_028A4C_FORCE_EOV_REZ_ENABLE(1));
1599 static void evergreen_emit_framebuffer_state(struct r600_context
*rctx
, struct r600_atom
*atom
)
1601 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
1602 struct pipe_framebuffer_state
*state
= &rctx
->framebuffer
.state
;
1603 unsigned nr_cbufs
= state
->nr_cbufs
;
1605 struct r600_texture
*tex
= NULL
;
1606 struct r600_surface
*cb
= NULL
;
1608 /* XXX support more colorbuffers once we need them */
1609 assert(nr_cbufs
<= 8);
1614 for (i
= 0; i
< nr_cbufs
; i
++) {
1615 unsigned reloc
, cmask_reloc
;
1617 cb
= (struct r600_surface
*)state
->cbufs
[i
];
1619 radeon_set_context_reg(cs
, R_028C70_CB_COLOR0_INFO
+ i
* 0x3C,
1620 S_028C70_FORMAT(V_028C70_COLOR_INVALID
));
1624 tex
= (struct r600_texture
*)cb
->base
.texture
;
1625 reloc
= radeon_add_to_buffer_list(&rctx
->b
,
1627 (struct r600_resource
*)cb
->base
.texture
,
1628 RADEON_USAGE_READWRITE
,
1629 tex
->surface
.nsamples
> 1 ?
1630 RADEON_PRIO_COLOR_BUFFER_MSAA
:
1631 RADEON_PRIO_COLOR_BUFFER
);
1633 if (tex
->cmask_buffer
&& tex
->cmask_buffer
!= &tex
->resource
) {
1634 cmask_reloc
= radeon_add_to_buffer_list(&rctx
->b
, &rctx
->b
.gfx
,
1635 tex
->cmask_buffer
, RADEON_USAGE_READWRITE
,
1638 cmask_reloc
= reloc
;
1641 radeon_set_context_reg_seq(cs
, R_028C60_CB_COLOR0_BASE
+ i
* 0x3C, 13);
1642 radeon_emit(cs
, cb
->cb_color_base
); /* R_028C60_CB_COLOR0_BASE */
1643 radeon_emit(cs
, cb
->cb_color_pitch
); /* R_028C64_CB_COLOR0_PITCH */
1644 radeon_emit(cs
, cb
->cb_color_slice
); /* R_028C68_CB_COLOR0_SLICE */
1645 radeon_emit(cs
, cb
->cb_color_view
); /* R_028C6C_CB_COLOR0_VIEW */
1646 radeon_emit(cs
, cb
->cb_color_info
| tex
->cb_color_info
); /* R_028C70_CB_COLOR0_INFO */
1647 radeon_emit(cs
, cb
->cb_color_attrib
); /* R_028C74_CB_COLOR0_ATTRIB */
1648 radeon_emit(cs
, cb
->cb_color_dim
); /* R_028C78_CB_COLOR0_DIM */
1649 radeon_emit(cs
, tex
->cmask
.base_address_reg
); /* R_028C7C_CB_COLOR0_CMASK */
1650 radeon_emit(cs
, tex
->cmask
.slice_tile_max
); /* R_028C80_CB_COLOR0_CMASK_SLICE */
1651 radeon_emit(cs
, cb
->cb_color_fmask
); /* R_028C84_CB_COLOR0_FMASK */
1652 radeon_emit(cs
, cb
->cb_color_fmask_slice
); /* R_028C88_CB_COLOR0_FMASK_SLICE */
1653 radeon_emit(cs
, tex
->color_clear_value
[0]); /* R_028C8C_CB_COLOR0_CLEAR_WORD0 */
1654 radeon_emit(cs
, tex
->color_clear_value
[1]); /* R_028C90_CB_COLOR0_CLEAR_WORD1 */
1656 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0)); /* R_028C60_CB_COLOR0_BASE */
1657 radeon_emit(cs
, reloc
);
1659 if (!rctx
->keep_tiling_flags
) {
1660 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0)); /* R_028C70_CB_COLOR0_INFO */
1661 radeon_emit(cs
, reloc
);
1664 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0)); /* R_028C74_CB_COLOR0_ATTRIB */
1665 radeon_emit(cs
, reloc
);
1667 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0)); /* R_028C7C_CB_COLOR0_CMASK */
1668 radeon_emit(cs
, cmask_reloc
);
1670 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0)); /* R_028C84_CB_COLOR0_FMASK */
1671 radeon_emit(cs
, reloc
);
1673 /* set CB_COLOR1_INFO for possible dual-src blending */
1674 if (i
== 1 && state
->cbufs
[0]) {
1675 radeon_set_context_reg(cs
, R_028C70_CB_COLOR0_INFO
+ 1 * 0x3C,
1676 cb
->cb_color_info
| tex
->cb_color_info
);
1678 if (!rctx
->keep_tiling_flags
) {
1679 unsigned reloc
= radeon_add_to_buffer_list(&rctx
->b
,
1681 (struct r600_resource
*)state
->cbufs
[0]->texture
,
1682 RADEON_USAGE_READWRITE
,
1683 RADEON_PRIO_COLOR_BUFFER
);
1685 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0)); /* R_028C70_CB_COLOR0_INFO */
1686 radeon_emit(cs
, reloc
);
1690 if (rctx
->keep_tiling_flags
) {
1691 for (; i
< 8 ; i
++) {
1692 radeon_set_context_reg(cs
, R_028C70_CB_COLOR0_INFO
+ i
* 0x3C, 0);
1694 for (; i
< 12; i
++) {
1695 radeon_set_context_reg(cs
, R_028E50_CB_COLOR8_INFO
+ (i
- 8) * 0x1C, 0);
1701 struct r600_surface
*zb
= (struct r600_surface
*)state
->zsbuf
;
1702 unsigned reloc
= radeon_add_to_buffer_list(&rctx
->b
,
1704 (struct r600_resource
*)state
->zsbuf
->texture
,
1705 RADEON_USAGE_READWRITE
,
1706 zb
->base
.texture
->nr_samples
> 1 ?
1707 RADEON_PRIO_DEPTH_BUFFER_MSAA
:
1708 RADEON_PRIO_DEPTH_BUFFER
);
1710 radeon_set_context_reg(cs
, R_028B78_PA_SU_POLY_OFFSET_DB_FMT_CNTL
,
1711 zb
->pa_su_poly_offset_db_fmt_cntl
);
1712 radeon_set_context_reg(cs
, R_028008_DB_DEPTH_VIEW
, zb
->db_depth_view
);
1714 radeon_set_context_reg_seq(cs
, R_028040_DB_Z_INFO
, 8);
1715 radeon_emit(cs
, zb
->db_z_info
); /* R_028040_DB_Z_INFO */
1716 radeon_emit(cs
, zb
->db_stencil_info
); /* R_028044_DB_STENCIL_INFO */
1717 radeon_emit(cs
, zb
->db_depth_base
); /* R_028048_DB_Z_READ_BASE */
1718 radeon_emit(cs
, zb
->db_stencil_base
); /* R_02804C_DB_STENCIL_READ_BASE */
1719 radeon_emit(cs
, zb
->db_depth_base
); /* R_028050_DB_Z_WRITE_BASE */
1720 radeon_emit(cs
, zb
->db_stencil_base
); /* R_028054_DB_STENCIL_WRITE_BASE */
1721 radeon_emit(cs
, zb
->db_depth_size
); /* R_028058_DB_DEPTH_SIZE */
1722 radeon_emit(cs
, zb
->db_depth_slice
); /* R_02805C_DB_DEPTH_SLICE */
1724 if (!rctx
->keep_tiling_flags
) {
1725 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0)); /* R_028040_DB_Z_INFO */
1726 radeon_emit(cs
, reloc
);
1729 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0)); /* R_028048_DB_Z_READ_BASE */
1730 radeon_emit(cs
, reloc
);
1732 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0)); /* R_02804C_DB_STENCIL_READ_BASE */
1733 radeon_emit(cs
, reloc
);
1735 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0)); /* R_028050_DB_Z_WRITE_BASE */
1736 radeon_emit(cs
, reloc
);
1738 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0)); /* R_028054_DB_STENCIL_WRITE_BASE */
1739 radeon_emit(cs
, reloc
);
1740 } else if (rctx
->screen
->b
.info
.drm_minor
>= 18) {
1741 /* DRM 2.6.18 allows the INVALID format to disable depth/stencil.
1742 * Older kernels are out of luck. */
1743 radeon_set_context_reg_seq(cs
, R_028040_DB_Z_INFO
, 2);
1744 radeon_emit(cs
, S_028040_FORMAT(V_028040_Z_INVALID
)); /* R_028040_DB_Z_INFO */
1745 radeon_emit(cs
, S_028044_FORMAT(V_028044_STENCIL_INVALID
)); /* R_028044_DB_STENCIL_INFO */
1748 /* Framebuffer dimensions. */
1749 evergreen_get_scissor_rect(rctx
, 0, 0, state
->width
, state
->height
, &tl
, &br
);
1751 radeon_set_context_reg_seq(cs
, R_028204_PA_SC_WINDOW_SCISSOR_TL
, 2);
1752 radeon_emit(cs
, tl
); /* R_028204_PA_SC_WINDOW_SCISSOR_TL */
1753 radeon_emit(cs
, br
); /* R_028208_PA_SC_WINDOW_SCISSOR_BR */
1755 if (rctx
->b
.chip_class
== EVERGREEN
) {
1756 evergreen_emit_msaa_state(rctx
, rctx
->framebuffer
.nr_samples
, rctx
->ps_iter_samples
);
1758 cayman_emit_msaa_sample_locs(cs
, rctx
->framebuffer
.nr_samples
);
1759 cayman_emit_msaa_config(cs
, rctx
->framebuffer
.nr_samples
, rctx
->ps_iter_samples
, 0);
1763 static void evergreen_emit_polygon_offset(struct r600_context
*rctx
, struct r600_atom
*a
)
1765 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
1766 struct r600_poly_offset_state
*state
= (struct r600_poly_offset_state
*)a
;
1767 float offset_units
= state
->offset_units
;
1768 float offset_scale
= state
->offset_scale
;
1770 switch (state
->zs_format
) {
1771 case PIPE_FORMAT_Z24X8_UNORM
:
1772 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
1773 case PIPE_FORMAT_X8Z24_UNORM
:
1774 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
1775 offset_units
*= 2.0f
;
1777 case PIPE_FORMAT_Z16_UNORM
:
1778 offset_units
*= 4.0f
;
1783 radeon_set_context_reg_seq(cs
, R_028B80_PA_SU_POLY_OFFSET_FRONT_SCALE
, 4);
1784 radeon_emit(cs
, fui(offset_scale
));
1785 radeon_emit(cs
, fui(offset_units
));
1786 radeon_emit(cs
, fui(offset_scale
));
1787 radeon_emit(cs
, fui(offset_units
));
1790 static void evergreen_emit_cb_misc_state(struct r600_context
*rctx
, struct r600_atom
*atom
)
1792 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
1793 struct r600_cb_misc_state
*a
= (struct r600_cb_misc_state
*)atom
;
1794 unsigned fb_colormask
= (1ULL << ((unsigned)a
->nr_cbufs
* 4)) - 1;
1795 unsigned ps_colormask
= (1ULL << ((unsigned)a
->nr_ps_color_outputs
* 4)) - 1;
1797 radeon_set_context_reg_seq(cs
, R_028238_CB_TARGET_MASK
, 2);
1798 radeon_emit(cs
, a
->blend_colormask
& fb_colormask
); /* R_028238_CB_TARGET_MASK */
1799 /* This must match the used export instructions exactly.
1800 * Other values may lead to undefined behavior and hangs.
1802 radeon_emit(cs
, ps_colormask
); /* R_02823C_CB_SHADER_MASK */
1805 static void evergreen_emit_db_state(struct r600_context
*rctx
, struct r600_atom
*atom
)
1807 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
1808 struct r600_db_state
*a
= (struct r600_db_state
*)atom
;
1810 if (a
->rsurf
&& a
->rsurf
->db_htile_surface
) {
1811 struct r600_texture
*rtex
= (struct r600_texture
*)a
->rsurf
->base
.texture
;
1814 radeon_set_context_reg(cs
, R_02802C_DB_DEPTH_CLEAR
, fui(rtex
->depth_clear_value
));
1815 radeon_set_context_reg(cs
, R_028ABC_DB_HTILE_SURFACE
, a
->rsurf
->db_htile_surface
);
1816 radeon_set_context_reg(cs
, R_028AC8_DB_PRELOAD_CONTROL
, a
->rsurf
->db_preload_control
);
1817 radeon_set_context_reg(cs
, R_028014_DB_HTILE_DATA_BASE
, a
->rsurf
->db_htile_data_base
);
1818 reloc_idx
= radeon_add_to_buffer_list(&rctx
->b
, &rctx
->b
.gfx
, rtex
->htile_buffer
,
1819 RADEON_USAGE_READWRITE
, RADEON_PRIO_HTILE
);
1820 cs
->buf
[cs
->cdw
++] = PKT3(PKT3_NOP
, 0, 0);
1821 cs
->buf
[cs
->cdw
++] = reloc_idx
;
1823 radeon_set_context_reg(cs
, R_028ABC_DB_HTILE_SURFACE
, 0);
1824 radeon_set_context_reg(cs
, R_028AC8_DB_PRELOAD_CONTROL
, 0);
1828 static void evergreen_emit_db_misc_state(struct r600_context
*rctx
, struct r600_atom
*atom
)
1830 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
1831 struct r600_db_misc_state
*a
= (struct r600_db_misc_state
*)atom
;
1832 unsigned db_render_control
= 0;
1833 unsigned db_count_control
= 0;
1834 unsigned db_render_override
=
1835 S_02800C_FORCE_HIS_ENABLE0(V_02800C_FORCE_DISABLE
) |
1836 S_02800C_FORCE_HIS_ENABLE1(V_02800C_FORCE_DISABLE
);
1838 if (a
->occlusion_query_enabled
) {
1839 db_count_control
|= S_028004_PERFECT_ZPASS_COUNTS(1);
1840 if (rctx
->b
.chip_class
== CAYMAN
) {
1841 db_count_control
|= S_028004_SAMPLE_RATE(a
->log_samples
);
1843 db_render_override
|= S_02800C_NOOP_CULL_DISABLE(1);
1846 /* This is to fix a lockup when hyperz and alpha test are enabled at
1847 * the same time somehow GPU get confuse on which order to pick for
1850 if (rctx
->alphatest_state
.sx_alpha_test_control
)
1851 db_render_override
|= S_02800C_FORCE_SHADER_Z_ORDER(1);
1853 if (a
->flush_depthstencil_through_cb
) {
1854 assert(a
->copy_depth
|| a
->copy_stencil
);
1856 db_render_control
|= S_028000_DEPTH_COPY_ENABLE(a
->copy_depth
) |
1857 S_028000_STENCIL_COPY_ENABLE(a
->copy_stencil
) |
1858 S_028000_COPY_CENTROID(1) |
1859 S_028000_COPY_SAMPLE(a
->copy_sample
);
1860 } else if (a
->flush_depth_inplace
|| a
->flush_stencil_inplace
) {
1861 db_render_control
|= S_028000_DEPTH_COMPRESS_DISABLE(a
->flush_depth_inplace
) |
1862 S_028000_STENCIL_COMPRESS_DISABLE(a
->flush_stencil_inplace
);
1863 db_render_override
|= S_02800C_DISABLE_PIXEL_RATE_TILES(1);
1865 if (a
->htile_clear
) {
1866 /* FIXME we might want to disable cliprect here */
1867 db_render_control
|= S_028000_DEPTH_CLEAR_ENABLE(1);
1870 radeon_set_context_reg_seq(cs
, R_028000_DB_RENDER_CONTROL
, 2);
1871 radeon_emit(cs
, db_render_control
); /* R_028000_DB_RENDER_CONTROL */
1872 radeon_emit(cs
, db_count_control
); /* R_028004_DB_COUNT_CONTROL */
1873 radeon_set_context_reg(cs
, R_02800C_DB_RENDER_OVERRIDE
, db_render_override
);
1874 radeon_set_context_reg(cs
, R_02880C_DB_SHADER_CONTROL
, a
->db_shader_control
);
1877 static void evergreen_emit_vertex_buffers(struct r600_context
*rctx
,
1878 struct r600_vertexbuf_state
*state
,
1879 unsigned resource_offset
,
1882 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
1883 uint32_t dirty_mask
= state
->dirty_mask
;
1885 while (dirty_mask
) {
1886 struct pipe_vertex_buffer
*vb
;
1887 struct r600_resource
*rbuffer
;
1889 unsigned buffer_index
= u_bit_scan(&dirty_mask
);
1891 vb
= &state
->vb
[buffer_index
];
1892 rbuffer
= (struct r600_resource
*)vb
->buffer
;
1895 va
= rbuffer
->gpu_address
+ vb
->buffer_offset
;
1897 /* fetch resources start at index 992 */
1898 radeon_emit(cs
, PKT3(PKT3_SET_RESOURCE
, 8, 0) | pkt_flags
);
1899 radeon_emit(cs
, (resource_offset
+ buffer_index
) * 8);
1900 radeon_emit(cs
, va
); /* RESOURCEi_WORD0 */
1901 radeon_emit(cs
, rbuffer
->b
.b
.width0
- vb
->buffer_offset
- 1); /* RESOURCEi_WORD1 */
1902 radeon_emit(cs
, /* RESOURCEi_WORD2 */
1903 S_030008_ENDIAN_SWAP(r600_endian_swap(32)) |
1904 S_030008_STRIDE(vb
->stride
) |
1905 S_030008_BASE_ADDRESS_HI(va
>> 32UL));
1906 radeon_emit(cs
, /* RESOURCEi_WORD3 */
1907 S_03000C_DST_SEL_X(V_03000C_SQ_SEL_X
) |
1908 S_03000C_DST_SEL_Y(V_03000C_SQ_SEL_Y
) |
1909 S_03000C_DST_SEL_Z(V_03000C_SQ_SEL_Z
) |
1910 S_03000C_DST_SEL_W(V_03000C_SQ_SEL_W
));
1911 radeon_emit(cs
, 0); /* RESOURCEi_WORD4 */
1912 radeon_emit(cs
, 0); /* RESOURCEi_WORD5 */
1913 radeon_emit(cs
, 0); /* RESOURCEi_WORD6 */
1914 radeon_emit(cs
, 0xc0000000); /* RESOURCEi_WORD7 */
1916 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0) | pkt_flags
);
1917 radeon_emit(cs
, radeon_add_to_buffer_list(&rctx
->b
, &rctx
->b
.gfx
, rbuffer
,
1918 RADEON_USAGE_READ
, RADEON_PRIO_VERTEX_BUFFER
));
1920 state
->dirty_mask
= 0;
1923 static void evergreen_fs_emit_vertex_buffers(struct r600_context
*rctx
, struct r600_atom
* atom
)
1925 evergreen_emit_vertex_buffers(rctx
, &rctx
->vertex_buffer_state
, EG_FETCH_CONSTANTS_OFFSET_FS
, 0);
1928 static void evergreen_cs_emit_vertex_buffers(struct r600_context
*rctx
, struct r600_atom
* atom
)
1930 evergreen_emit_vertex_buffers(rctx
, &rctx
->cs_vertex_buffer_state
, EG_FETCH_CONSTANTS_OFFSET_CS
,
1931 RADEON_CP_PACKET3_COMPUTE_MODE
);
1934 static void evergreen_emit_constant_buffers(struct r600_context
*rctx
,
1935 struct r600_constbuf_state
*state
,
1936 unsigned buffer_id_base
,
1937 unsigned reg_alu_constbuf_size
,
1938 unsigned reg_alu_const_cache
,
1941 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
1942 uint32_t dirty_mask
= state
->dirty_mask
;
1944 while (dirty_mask
) {
1945 struct pipe_constant_buffer
*cb
;
1946 struct r600_resource
*rbuffer
;
1948 unsigned buffer_index
= ffs(dirty_mask
) - 1;
1949 unsigned gs_ring_buffer
= (buffer_index
== R600_GS_RING_CONST_BUFFER
);
1951 cb
= &state
->cb
[buffer_index
];
1952 rbuffer
= (struct r600_resource
*)cb
->buffer
;
1955 va
= rbuffer
->gpu_address
+ cb
->buffer_offset
;
1957 if (!gs_ring_buffer
) {
1958 radeon_set_context_reg_flag(cs
, reg_alu_constbuf_size
+ buffer_index
* 4,
1959 ALIGN_DIVUP(cb
->buffer_size
, 256), pkt_flags
);
1960 radeon_set_context_reg_flag(cs
, reg_alu_const_cache
+ buffer_index
* 4, va
>> 8,
1964 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0) | pkt_flags
);
1965 radeon_emit(cs
, radeon_add_to_buffer_list(&rctx
->b
, &rctx
->b
.gfx
, rbuffer
,
1966 RADEON_USAGE_READ
, RADEON_PRIO_CONST_BUFFER
));
1968 radeon_emit(cs
, PKT3(PKT3_SET_RESOURCE
, 8, 0) | pkt_flags
);
1969 radeon_emit(cs
, (buffer_id_base
+ buffer_index
) * 8);
1970 radeon_emit(cs
, va
); /* RESOURCEi_WORD0 */
1971 radeon_emit(cs
, rbuffer
->b
.b
.width0
- cb
->buffer_offset
- 1); /* RESOURCEi_WORD1 */
1972 radeon_emit(cs
, /* RESOURCEi_WORD2 */
1973 S_030008_ENDIAN_SWAP(gs_ring_buffer
? ENDIAN_NONE
: r600_endian_swap(32)) |
1974 S_030008_STRIDE(gs_ring_buffer
? 4 : 16) |
1975 S_030008_BASE_ADDRESS_HI(va
>> 32UL) |
1976 S_030008_DATA_FORMAT(FMT_32_32_32_32_FLOAT
));
1977 radeon_emit(cs
, /* RESOURCEi_WORD3 */
1978 S_03000C_UNCACHED(gs_ring_buffer
? 1 : 0) |
1979 S_03000C_DST_SEL_X(V_03000C_SQ_SEL_X
) |
1980 S_03000C_DST_SEL_Y(V_03000C_SQ_SEL_Y
) |
1981 S_03000C_DST_SEL_Z(V_03000C_SQ_SEL_Z
) |
1982 S_03000C_DST_SEL_W(V_03000C_SQ_SEL_W
));
1983 radeon_emit(cs
, 0); /* RESOURCEi_WORD4 */
1984 radeon_emit(cs
, 0); /* RESOURCEi_WORD5 */
1985 radeon_emit(cs
, 0); /* RESOURCEi_WORD6 */
1986 radeon_emit(cs
, /* RESOURCEi_WORD7 */
1987 S_03001C_TYPE(V_03001C_SQ_TEX_VTX_VALID_BUFFER
));
1989 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0) | pkt_flags
);
1990 radeon_emit(cs
, radeon_add_to_buffer_list(&rctx
->b
, &rctx
->b
.gfx
, rbuffer
,
1991 RADEON_USAGE_READ
, RADEON_PRIO_CONST_BUFFER
));
1993 dirty_mask
&= ~(1 << buffer_index
);
1995 state
->dirty_mask
= 0;
1998 /* VS constants can be in VS/ES (same space) or LS if tess is enabled */
1999 static void evergreen_emit_vs_constant_buffers(struct r600_context
*rctx
, struct r600_atom
*atom
)
2001 if (rctx
->vs_shader
->current
->shader
.vs_as_ls
) {
2002 evergreen_emit_constant_buffers(rctx
, &rctx
->constbuf_state
[PIPE_SHADER_VERTEX
],
2003 EG_FETCH_CONSTANTS_OFFSET_LS
,
2004 R_028FC0_ALU_CONST_BUFFER_SIZE_LS_0
,
2005 R_028F40_ALU_CONST_CACHE_LS_0
,
2006 0 /* PKT3 flags */);
2008 evergreen_emit_constant_buffers(rctx
, &rctx
->constbuf_state
[PIPE_SHADER_VERTEX
],
2009 EG_FETCH_CONSTANTS_OFFSET_VS
,
2010 R_028180_ALU_CONST_BUFFER_SIZE_VS_0
,
2011 R_028980_ALU_CONST_CACHE_VS_0
,
2012 0 /* PKT3 flags */);
2016 static void evergreen_emit_gs_constant_buffers(struct r600_context
*rctx
, struct r600_atom
*atom
)
2018 evergreen_emit_constant_buffers(rctx
, &rctx
->constbuf_state
[PIPE_SHADER_GEOMETRY
],
2019 EG_FETCH_CONSTANTS_OFFSET_GS
,
2020 R_0281C0_ALU_CONST_BUFFER_SIZE_GS_0
,
2021 R_0289C0_ALU_CONST_CACHE_GS_0
,
2022 0 /* PKT3 flags */);
2025 static void evergreen_emit_ps_constant_buffers(struct r600_context
*rctx
, struct r600_atom
*atom
)
2027 evergreen_emit_constant_buffers(rctx
, &rctx
->constbuf_state
[PIPE_SHADER_FRAGMENT
],
2028 EG_FETCH_CONSTANTS_OFFSET_PS
,
2029 R_028140_ALU_CONST_BUFFER_SIZE_PS_0
,
2030 R_028940_ALU_CONST_CACHE_PS_0
,
2031 0 /* PKT3 flags */);
2034 static void evergreen_emit_cs_constant_buffers(struct r600_context
*rctx
, struct r600_atom
*atom
)
2036 evergreen_emit_constant_buffers(rctx
, &rctx
->constbuf_state
[PIPE_SHADER_COMPUTE
],
2037 EG_FETCH_CONSTANTS_OFFSET_CS
,
2038 R_028FC0_ALU_CONST_BUFFER_SIZE_LS_0
,
2039 R_028F40_ALU_CONST_CACHE_LS_0
,
2040 RADEON_CP_PACKET3_COMPUTE_MODE
);
2043 /* tes constants can be emitted to VS or ES - which are common */
2044 static void evergreen_emit_tes_constant_buffers(struct r600_context
*rctx
, struct r600_atom
*atom
)
2046 if (!rctx
->tes_shader
)
2048 evergreen_emit_constant_buffers(rctx
, &rctx
->constbuf_state
[PIPE_SHADER_TESS_EVAL
],
2049 EG_FETCH_CONSTANTS_OFFSET_VS
,
2050 R_028180_ALU_CONST_BUFFER_SIZE_VS_0
,
2051 R_028980_ALU_CONST_CACHE_VS_0
,
2055 static void evergreen_emit_tcs_constant_buffers(struct r600_context
*rctx
, struct r600_atom
*atom
)
2057 if (!rctx
->tes_shader
)
2059 evergreen_emit_constant_buffers(rctx
, &rctx
->constbuf_state
[PIPE_SHADER_TESS_CTRL
],
2060 EG_FETCH_CONSTANTS_OFFSET_HS
,
2061 R_028F80_ALU_CONST_BUFFER_SIZE_HS_0
,
2062 R_028F00_ALU_CONST_CACHE_HS_0
,
2066 static void evergreen_emit_sampler_views(struct r600_context
*rctx
,
2067 struct r600_samplerview_state
*state
,
2068 unsigned resource_id_base
, unsigned pkt_flags
)
2070 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
2071 uint32_t dirty_mask
= state
->dirty_mask
;
2073 while (dirty_mask
) {
2074 struct r600_pipe_sampler_view
*rview
;
2075 unsigned resource_index
= u_bit_scan(&dirty_mask
);
2078 rview
= state
->views
[resource_index
];
2081 radeon_emit(cs
, PKT3(PKT3_SET_RESOURCE
, 8, 0) | pkt_flags
);
2082 radeon_emit(cs
, (resource_id_base
+ resource_index
) * 8);
2083 radeon_emit_array(cs
, rview
->tex_resource_words
, 8);
2085 reloc
= radeon_add_to_buffer_list(&rctx
->b
, &rctx
->b
.gfx
, rview
->tex_resource
,
2087 r600_get_sampler_view_priority(rview
->tex_resource
));
2088 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0) | pkt_flags
);
2089 radeon_emit(cs
, reloc
);
2091 if (!rview
->skip_mip_address_reloc
) {
2092 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0) | pkt_flags
);
2093 radeon_emit(cs
, reloc
);
2096 state
->dirty_mask
= 0;
2099 static void evergreen_emit_vs_sampler_views(struct r600_context
*rctx
, struct r600_atom
*atom
)
2101 if (rctx
->vs_shader
->current
->shader
.vs_as_ls
) {
2102 evergreen_emit_sampler_views(rctx
, &rctx
->samplers
[PIPE_SHADER_VERTEX
].views
,
2103 EG_FETCH_CONSTANTS_OFFSET_LS
+ R600_MAX_CONST_BUFFERS
, 0);
2105 evergreen_emit_sampler_views(rctx
, &rctx
->samplers
[PIPE_SHADER_VERTEX
].views
,
2106 EG_FETCH_CONSTANTS_OFFSET_VS
+ R600_MAX_CONST_BUFFERS
, 0);
2110 static void evergreen_emit_gs_sampler_views(struct r600_context
*rctx
, struct r600_atom
*atom
)
2112 evergreen_emit_sampler_views(rctx
, &rctx
->samplers
[PIPE_SHADER_GEOMETRY
].views
,
2113 EG_FETCH_CONSTANTS_OFFSET_GS
+ R600_MAX_CONST_BUFFERS
, 0);
2116 static void evergreen_emit_tcs_sampler_views(struct r600_context
*rctx
, struct r600_atom
*atom
)
2118 evergreen_emit_sampler_views(rctx
, &rctx
->samplers
[PIPE_SHADER_TESS_CTRL
].views
,
2119 EG_FETCH_CONSTANTS_OFFSET_HS
+ R600_MAX_CONST_BUFFERS
, 0);
2122 static void evergreen_emit_tes_sampler_views(struct r600_context
*rctx
, struct r600_atom
*atom
)
2124 evergreen_emit_sampler_views(rctx
, &rctx
->samplers
[PIPE_SHADER_TESS_EVAL
].views
,
2125 EG_FETCH_CONSTANTS_OFFSET_VS
+ R600_MAX_CONST_BUFFERS
, 0);
2128 static void evergreen_emit_ps_sampler_views(struct r600_context
*rctx
, struct r600_atom
*atom
)
2130 evergreen_emit_sampler_views(rctx
, &rctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
,
2131 EG_FETCH_CONSTANTS_OFFSET_PS
+ R600_MAX_CONST_BUFFERS
, 0);
2134 static void evergreen_emit_cs_sampler_views(struct r600_context
*rctx
, struct r600_atom
*atom
)
2136 evergreen_emit_sampler_views(rctx
, &rctx
->samplers
[PIPE_SHADER_COMPUTE
].views
,
2137 EG_FETCH_CONSTANTS_OFFSET_CS
+ 2, RADEON_CP_PACKET3_COMPUTE_MODE
);
2140 static void evergreen_emit_sampler_states(struct r600_context
*rctx
,
2141 struct r600_textures_info
*texinfo
,
2142 unsigned resource_id_base
,
2143 unsigned border_index_reg
,
2146 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
2147 uint32_t dirty_mask
= texinfo
->states
.dirty_mask
;
2149 while (dirty_mask
) {
2150 struct r600_pipe_sampler_state
*rstate
;
2151 unsigned i
= u_bit_scan(&dirty_mask
);
2153 rstate
= texinfo
->states
.states
[i
];
2156 radeon_emit(cs
, PKT3(PKT3_SET_SAMPLER
, 3, 0) | pkt_flags
);
2157 radeon_emit(cs
, (resource_id_base
+ i
) * 3);
2158 radeon_emit_array(cs
, rstate
->tex_sampler_words
, 3);
2160 if (rstate
->border_color_use
) {
2161 radeon_set_config_reg_seq(cs
, border_index_reg
, 5);
2163 radeon_emit_array(cs
, rstate
->border_color
.ui
, 4);
2166 texinfo
->states
.dirty_mask
= 0;
2169 static void evergreen_emit_vs_sampler_states(struct r600_context
*rctx
, struct r600_atom
*atom
)
2171 if (rctx
->vs_shader
->current
->shader
.vs_as_ls
) {
2172 evergreen_emit_sampler_states(rctx
, &rctx
->samplers
[PIPE_SHADER_VERTEX
], 72,
2173 R_00A450_TD_LS_SAMPLER0_BORDER_COLOR_INDEX
, 0);
2175 evergreen_emit_sampler_states(rctx
, &rctx
->samplers
[PIPE_SHADER_VERTEX
], 18,
2176 R_00A414_TD_VS_SAMPLER0_BORDER_INDEX
, 0);
2180 static void evergreen_emit_gs_sampler_states(struct r600_context
*rctx
, struct r600_atom
*atom
)
2182 evergreen_emit_sampler_states(rctx
, &rctx
->samplers
[PIPE_SHADER_GEOMETRY
], 36,
2183 R_00A428_TD_GS_SAMPLER0_BORDER_INDEX
, 0);
2186 static void evergreen_emit_tcs_sampler_states(struct r600_context
*rctx
, struct r600_atom
*atom
)
2188 evergreen_emit_sampler_states(rctx
, &rctx
->samplers
[PIPE_SHADER_TESS_CTRL
], 54,
2189 R_00A43C_TD_HS_SAMPLER0_BORDER_COLOR_INDEX
, 0);
2192 static void evergreen_emit_tes_sampler_states(struct r600_context
*rctx
, struct r600_atom
*atom
)
2194 evergreen_emit_sampler_states(rctx
, &rctx
->samplers
[PIPE_SHADER_TESS_EVAL
], 18,
2195 R_00A414_TD_VS_SAMPLER0_BORDER_INDEX
, 0);
2198 static void evergreen_emit_ps_sampler_states(struct r600_context
*rctx
, struct r600_atom
*atom
)
2200 evergreen_emit_sampler_states(rctx
, &rctx
->samplers
[PIPE_SHADER_FRAGMENT
], 0,
2201 R_00A400_TD_PS_SAMPLER0_BORDER_INDEX
, 0);
2204 static void evergreen_emit_cs_sampler_states(struct r600_context
*rctx
, struct r600_atom
*atom
)
2206 evergreen_emit_sampler_states(rctx
, &rctx
->samplers
[PIPE_SHADER_COMPUTE
], 90,
2207 R_00A464_TD_CS_SAMPLER0_BORDER_INDEX
,
2208 RADEON_CP_PACKET3_COMPUTE_MODE
);
2211 static void evergreen_emit_sample_mask(struct r600_context
*rctx
, struct r600_atom
*a
)
2213 struct r600_sample_mask
*s
= (struct r600_sample_mask
*)a
;
2214 uint8_t mask
= s
->sample_mask
;
2216 radeon_set_context_reg(rctx
->b
.gfx
.cs
, R_028C3C_PA_SC_AA_MASK
,
2217 mask
| (mask
<< 8) | (mask
<< 16) | (mask
<< 24));
2220 static void cayman_emit_sample_mask(struct r600_context
*rctx
, struct r600_atom
*a
)
2222 struct r600_sample_mask
*s
= (struct r600_sample_mask
*)a
;
2223 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
2224 uint16_t mask
= s
->sample_mask
;
2226 radeon_set_context_reg_seq(cs
, CM_R_028C38_PA_SC_AA_MASK_X0Y0_X1Y0
, 2);
2227 radeon_emit(cs
, mask
| (mask
<< 16)); /* X0Y0_X1Y0 */
2228 radeon_emit(cs
, mask
| (mask
<< 16)); /* X0Y1_X1Y1 */
2231 static void evergreen_emit_vertex_fetch_shader(struct r600_context
*rctx
, struct r600_atom
*a
)
2233 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
2234 struct r600_cso_state
*state
= (struct r600_cso_state
*)a
;
2235 struct r600_fetch_shader
*shader
= (struct r600_fetch_shader
*)state
->cso
;
2237 radeon_set_context_reg(cs
, R_0288A4_SQ_PGM_START_FS
,
2238 (shader
->buffer
->gpu_address
+ shader
->offset
) >> 8);
2239 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0));
2240 radeon_emit(cs
, radeon_add_to_buffer_list(&rctx
->b
, &rctx
->b
.gfx
, shader
->buffer
,
2242 RADEON_PRIO_INTERNAL_SHADER
));
2245 static void evergreen_emit_shader_stages(struct r600_context
*rctx
, struct r600_atom
*a
)
2247 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
2248 struct r600_shader_stages_state
*state
= (struct r600_shader_stages_state
*)a
;
2250 uint32_t v
= 0, v2
= 0, primid
= 0, tf_param
= 0;
2252 if (rctx
->vs_shader
->current
->shader
.vs_as_gs_a
) {
2253 v2
= S_028A40_MODE(V_028A40_GS_SCENARIO_A
);
2257 if (state
->geom_enable
) {
2260 if (rctx
->gs_shader
->gs_max_out_vertices
<= 128)
2261 cut_val
= V_028A40_GS_CUT_128
;
2262 else if (rctx
->gs_shader
->gs_max_out_vertices
<= 256)
2263 cut_val
= V_028A40_GS_CUT_256
;
2264 else if (rctx
->gs_shader
->gs_max_out_vertices
<= 512)
2265 cut_val
= V_028A40_GS_CUT_512
;
2267 cut_val
= V_028A40_GS_CUT_1024
;
2269 v
= S_028B54_GS_EN(1) |
2270 S_028B54_VS_EN(V_028B54_VS_STAGE_COPY_SHADER
);
2271 if (!rctx
->tes_shader
)
2272 v
|= S_028B54_ES_EN(V_028B54_ES_STAGE_REAL
);
2274 v2
= S_028A40_MODE(V_028A40_GS_SCENARIO_G
) |
2275 S_028A40_CUT_MODE(cut_val
);
2277 if (rctx
->gs_shader
->current
->shader
.gs_prim_id_input
)
2281 if (rctx
->tes_shader
) {
2282 uint32_t type
, partitioning
, topology
;
2283 struct tgsi_shader_info
*info
= &rctx
->tes_shader
->current
->selector
->info
;
2284 unsigned tes_prim_mode
= info
->properties
[TGSI_PROPERTY_TES_PRIM_MODE
];
2285 unsigned tes_spacing
= info
->properties
[TGSI_PROPERTY_TES_SPACING
];
2286 bool tes_vertex_order_cw
= info
->properties
[TGSI_PROPERTY_TES_VERTEX_ORDER_CW
];
2287 bool tes_point_mode
= info
->properties
[TGSI_PROPERTY_TES_POINT_MODE
];
2288 switch (tes_prim_mode
) {
2289 case PIPE_PRIM_LINES
:
2290 type
= V_028B6C_TESS_ISOLINE
;
2292 case PIPE_PRIM_TRIANGLES
:
2293 type
= V_028B6C_TESS_TRIANGLE
;
2295 case PIPE_PRIM_QUADS
:
2296 type
= V_028B6C_TESS_QUAD
;
2303 switch (tes_spacing
) {
2304 case PIPE_TESS_SPACING_FRACTIONAL_ODD
:
2305 partitioning
= V_028B6C_PART_FRAC_ODD
;
2307 case PIPE_TESS_SPACING_FRACTIONAL_EVEN
:
2308 partitioning
= V_028B6C_PART_FRAC_EVEN
;
2310 case PIPE_TESS_SPACING_EQUAL
:
2311 partitioning
= V_028B6C_PART_INTEGER
;
2319 topology
= V_028B6C_OUTPUT_POINT
;
2320 else if (tes_prim_mode
== PIPE_PRIM_LINES
)
2321 topology
= V_028B6C_OUTPUT_LINE
;
2322 else if (tes_vertex_order_cw
)
2323 /* XXX follow radeonsi and invert */
2324 topology
= V_028B6C_OUTPUT_TRIANGLE_CCW
;
2326 topology
= V_028B6C_OUTPUT_TRIANGLE_CW
;
2328 tf_param
= S_028B6C_TYPE(type
) |
2329 S_028B6C_PARTITIONING(partitioning
) |
2330 S_028B6C_TOPOLOGY(topology
);
2333 if (rctx
->tes_shader
) {
2334 v
|= S_028B54_LS_EN(V_028B54_LS_STAGE_ON
) |
2336 if (!state
->geom_enable
)
2337 v
|= S_028B54_VS_EN(V_028B54_VS_STAGE_DS
);
2339 v
|= S_028B54_ES_EN(V_028B54_ES_STAGE_DS
);
2342 radeon_set_context_reg(cs
, R_028AB8_VGT_VTX_CNT_EN
, v
? 1 : 0 );
2343 radeon_set_context_reg(cs
, R_028B54_VGT_SHADER_STAGES_EN
, v
);
2344 radeon_set_context_reg(cs
, R_028A40_VGT_GS_MODE
, v2
);
2345 radeon_set_context_reg(cs
, R_028A84_VGT_PRIMITIVEID_EN
, primid
);
2346 radeon_set_context_reg(cs
, R_028B6C_VGT_TF_PARAM
, tf_param
);
2349 static void evergreen_emit_gs_rings(struct r600_context
*rctx
, struct r600_atom
*a
)
2351 struct radeon_winsys_cs
*cs
= rctx
->b
.gfx
.cs
;
2352 struct r600_gs_rings_state
*state
= (struct r600_gs_rings_state
*)a
;
2353 struct r600_resource
*rbuffer
;
2355 radeon_set_config_reg(cs
, R_008040_WAIT_UNTIL
, S_008040_WAIT_3D_IDLE(1));
2356 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2357 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_VGT_FLUSH
));
2359 if (state
->enable
) {
2360 rbuffer
=(struct r600_resource
*)state
->esgs_ring
.buffer
;
2361 radeon_set_config_reg(cs
, R_008C40_SQ_ESGS_RING_BASE
,
2362 rbuffer
->gpu_address
>> 8);
2363 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0));
2364 radeon_emit(cs
, radeon_add_to_buffer_list(&rctx
->b
, &rctx
->b
.gfx
, rbuffer
,
2365 RADEON_USAGE_READWRITE
,
2366 RADEON_PRIO_RINGS_STREAMOUT
));
2367 radeon_set_config_reg(cs
, R_008C44_SQ_ESGS_RING_SIZE
,
2368 state
->esgs_ring
.buffer_size
>> 8);
2370 rbuffer
=(struct r600_resource
*)state
->gsvs_ring
.buffer
;
2371 radeon_set_config_reg(cs
, R_008C48_SQ_GSVS_RING_BASE
,
2372 rbuffer
->gpu_address
>> 8);
2373 radeon_emit(cs
, PKT3(PKT3_NOP
, 0, 0));
2374 radeon_emit(cs
, radeon_add_to_buffer_list(&rctx
->b
, &rctx
->b
.gfx
, rbuffer
,
2375 RADEON_USAGE_READWRITE
,
2376 RADEON_PRIO_RINGS_STREAMOUT
));
2377 radeon_set_config_reg(cs
, R_008C4C_SQ_GSVS_RING_SIZE
,
2378 state
->gsvs_ring
.buffer_size
>> 8);
2380 radeon_set_config_reg(cs
, R_008C44_SQ_ESGS_RING_SIZE
, 0);
2381 radeon_set_config_reg(cs
, R_008C4C_SQ_GSVS_RING_SIZE
, 0);
2384 radeon_set_config_reg(cs
, R_008040_WAIT_UNTIL
, S_008040_WAIT_3D_IDLE(1));
2385 radeon_emit(cs
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2386 radeon_emit(cs
, EVENT_TYPE(EVENT_TYPE_VGT_FLUSH
));
2389 void cayman_init_common_regs(struct r600_command_buffer
*cb
,
2390 enum chip_class ctx_chip_class
,
2391 enum radeon_family ctx_family
,
2394 r600_store_config_reg_seq(cb
, R_008C00_SQ_CONFIG
, 2);
2395 r600_store_value(cb
, S_008C00_EXPORT_SRC_C(1)); /* R_008C00_SQ_CONFIG */
2396 /* always set the temp clauses */
2397 r600_store_value(cb
, S_008C04_NUM_CLAUSE_TEMP_GPRS(4)); /* R_008C04_SQ_GPR_RESOURCE_MGMT_1 */
2399 r600_store_config_reg_seq(cb
, R_008C10_SQ_GLOBAL_GPR_RESOURCE_MGMT_1
, 2);
2400 r600_store_value(cb
, 0); /* R_008C10_SQ_GLOBAL_GPR_RESOURCE_MGMT_1 */
2401 r600_store_value(cb
, 0); /* R_008C14_SQ_GLOBAL_GPR_RESOURCE_MGMT_2 */
2403 r600_store_config_reg(cb
, R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ
, (1 << 8));
2405 r600_store_context_reg_seq(cb
, R_028350_SX_MISC
, 2);
2406 r600_store_value(cb
, 0);
2407 r600_store_value(cb
, S_028354_SURFACE_SYNC_MASK(0xf));
2409 r600_store_context_reg(cb
, R_028800_DB_DEPTH_CONTROL
, 0);
2412 static void cayman_init_atom_start_cs(struct r600_context
*rctx
)
2414 struct r600_command_buffer
*cb
= &rctx
->start_cs_cmd
;
2417 r600_init_command_buffer(cb
, 338);
2419 /* This must be first. */
2420 r600_store_value(cb
, PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
2421 r600_store_value(cb
, 0x80000000);
2422 r600_store_value(cb
, 0x80000000);
2424 /* We're setting config registers here. */
2425 r600_store_value(cb
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2426 r600_store_value(cb
, EVENT_TYPE(EVENT_TYPE_PS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2428 cayman_init_common_regs(cb
, rctx
->b
.chip_class
,
2429 rctx
->b
.family
, rctx
->screen
->b
.info
.drm_minor
);
2431 r600_store_config_reg(cb
, R_009100_SPI_CONFIG_CNTL
, 0);
2432 r600_store_config_reg(cb
, R_00913C_SPI_CONFIG_CNTL_1
, S_00913C_VTX_DONE_DELAY(4));
2434 /* remove LS/HS from one SIMD for hw workaround */
2435 r600_store_config_reg_seq(cb
, R_008E20_SQ_STATIC_THREAD_MGMT1
, 3);
2436 r600_store_value(cb
, 0xffffffff);
2437 r600_store_value(cb
, 0xffffffff);
2438 r600_store_value(cb
, 0xfffffffe);
2440 r600_store_context_reg_seq(cb
, R_028900_SQ_ESGS_RING_ITEMSIZE
, 6);
2441 r600_store_value(cb
, 0); /* R_028900_SQ_ESGS_RING_ITEMSIZE */
2442 r600_store_value(cb
, 0); /* R_028904_SQ_GSVS_RING_ITEMSIZE */
2443 r600_store_value(cb
, 0); /* R_028908_SQ_ESTMP_RING_ITEMSIZE */
2444 r600_store_value(cb
, 0); /* R_02890C_SQ_GSTMP_RING_ITEMSIZE */
2445 r600_store_value(cb
, 0); /* R_028910_SQ_VSTMP_RING_ITEMSIZE */
2446 r600_store_value(cb
, 0); /* R_028914_SQ_PSTMP_RING_ITEMSIZE */
2448 r600_store_context_reg_seq(cb
, R_02891C_SQ_GS_VERT_ITEMSIZE
, 4);
2449 r600_store_value(cb
, 0); /* R_02891C_SQ_GS_VERT_ITEMSIZE */
2450 r600_store_value(cb
, 0); /* R_028920_SQ_GS_VERT_ITEMSIZE_1 */
2451 r600_store_value(cb
, 0); /* R_028924_SQ_GS_VERT_ITEMSIZE_2 */
2452 r600_store_value(cb
, 0); /* R_028928_SQ_GS_VERT_ITEMSIZE_3 */
2454 r600_store_context_reg_seq(cb
, R_028A10_VGT_OUTPUT_PATH_CNTL
, 13);
2455 r600_store_value(cb
, 0); /* R_028A10_VGT_OUTPUT_PATH_CNTL */
2456 r600_store_value(cb
, 0); /* R_028A14_VGT_HOS_CNTL */
2457 r600_store_value(cb
, fui(64)); /* R_028A18_VGT_HOS_MAX_TESS_LEVEL */
2458 r600_store_value(cb
, fui(0)); /* R_028A1C_VGT_HOS_MIN_TESS_LEVEL */
2459 r600_store_value(cb
, 16); /* R_028A20_VGT_HOS_REUSE_DEPTH */
2460 r600_store_value(cb
, 0); /* R_028A24_VGT_GROUP_PRIM_TYPE */
2461 r600_store_value(cb
, 0); /* R_028A28_VGT_GROUP_FIRST_DECR */
2462 r600_store_value(cb
, 0); /* R_028A2C_VGT_GROUP_DECR */
2463 r600_store_value(cb
, 0); /* R_028A30_VGT_GROUP_VECT_0_CNTL */
2464 r600_store_value(cb
, 0); /* R_028A34_VGT_GROUP_VECT_1_CNTL */
2465 r600_store_value(cb
, 0); /* R_028A38_VGT_GROUP_VECT_0_FMT_CNTL */
2466 r600_store_value(cb
, 0); /* R_028A3C_VGT_GROUP_VECT_1_FMT_CNTL */
2467 r600_store_value(cb
, 0); /* R_028A40_VGT_GS_MODE */
2469 r600_store_context_reg(cb
, R_028B98_VGT_STRMOUT_BUFFER_CONFIG
, 0);
2471 r600_store_config_reg(cb
, R_008A14_PA_CL_ENHANCE
, (3 << 1) | 1);
2473 r600_store_context_reg_seq(cb
, CM_R_028BD4_PA_SC_CENTROID_PRIORITY_0
, 2);
2474 r600_store_value(cb
, 0x76543210); /* CM_R_028BD4_PA_SC_CENTROID_PRIORITY_0 */
2475 r600_store_value(cb
, 0xfedcba98); /* CM_R_028BD8_PA_SC_CENTROID_PRIORITY_1 */
2477 r600_store_context_reg_seq(cb
, R_0288E8_SQ_LDS_ALLOC
, 2);
2478 r600_store_value(cb
, 0); /* R_0288E8_SQ_LDS_ALLOC */
2479 r600_store_value(cb
, 0); /* R_0288EC_SQ_LDS_ALLOC_PS */
2481 r600_store_context_reg(cb
, R_0288F0_SQ_VTX_SEMANTIC_CLEAR
, ~0);
2483 r600_store_context_reg_seq(cb
, R_028400_VGT_MAX_VTX_INDX
, 2);
2484 r600_store_value(cb
, ~0); /* R_028400_VGT_MAX_VTX_INDX */
2485 r600_store_value(cb
, 0); /* R_028404_VGT_MIN_VTX_INDX */
2487 r600_store_ctl_const(cb
, R_03CFF0_SQ_VTX_BASE_VTX_LOC
, 0);
2489 r600_store_context_reg(cb
, R_028028_DB_STENCIL_CLEAR
, 0);
2491 r600_store_context_reg(cb
, R_0286DC_SPI_FOG_CNTL
, 0);
2493 r600_store_context_reg_seq(cb
, R_028AC0_DB_SRESULTS_COMPARE_STATE0
, 3);
2494 r600_store_value(cb
, 0); /* R_028AC0_DB_SRESULTS_COMPARE_STATE0 */
2495 r600_store_value(cb
, 0); /* R_028AC4_DB_SRESULTS_COMPARE_STATE1 */
2496 r600_store_value(cb
, 0); /* R_028AC8_DB_PRELOAD_CONTROL */
2498 r600_store_context_reg(cb
, R_028200_PA_SC_WINDOW_OFFSET
, 0);
2499 r600_store_context_reg(cb
, R_02820C_PA_SC_CLIPRECT_RULE
, 0xFFFF);
2501 r600_store_context_reg_seq(cb
, R_0282D0_PA_SC_VPORT_ZMIN_0
, 2 * R600_MAX_VIEWPORTS
);
2502 for (tmp
= 0; tmp
< R600_MAX_VIEWPORTS
; tmp
++) {
2503 r600_store_value(cb
, 0); /* R_0282D0_PA_SC_VPORT_ZMIN_0 */
2504 r600_store_value(cb
, fui(1.0)); /* R_0282D4_PA_SC_VPORT_ZMAX_0 */
2507 r600_store_context_reg(cb
, R_028230_PA_SC_EDGERULE
, 0xAAAAAAAA);
2508 r600_store_context_reg(cb
, R_028820_PA_CL_NANINF_CNTL
, 0);
2510 r600_store_context_reg_seq(cb
, CM_R_028BE8_PA_CL_GB_VERT_CLIP_ADJ
, 4);
2511 r600_store_value(cb
, fui(1.0)); /* CM_R_028BE8_PA_CL_GB_VERT_CLIP_ADJ */
2512 r600_store_value(cb
, fui(1.0)); /* CM_R_028BEC_PA_CL_GB_VERT_DISC_ADJ */
2513 r600_store_value(cb
, fui(1.0)); /* CM_R_028BF0_PA_CL_GB_HORZ_CLIP_ADJ */
2514 r600_store_value(cb
, fui(1.0)); /* CM_R_028BF4_PA_CL_GB_HORZ_DISC_ADJ */
2516 r600_store_context_reg_seq(cb
, R_028240_PA_SC_GENERIC_SCISSOR_TL
, 2);
2517 r600_store_value(cb
, 0); /* R_028240_PA_SC_GENERIC_SCISSOR_TL */
2518 r600_store_value(cb
, S_028244_BR_X(16384) | S_028244_BR_Y(16384)); /* R_028244_PA_SC_GENERIC_SCISSOR_BR */
2520 r600_store_context_reg_seq(cb
, R_028030_PA_SC_SCREEN_SCISSOR_TL
, 2);
2521 r600_store_value(cb
, 0); /* R_028030_PA_SC_SCREEN_SCISSOR_TL */
2522 r600_store_value(cb
, S_028034_BR_X(16384) | S_028034_BR_Y(16384)); /* R_028034_PA_SC_SCREEN_SCISSOR_BR */
2524 r600_store_context_reg(cb
, R_028848_SQ_PGM_RESOURCES_2_PS
, S_028848_SINGLE_ROUND(V_SQ_ROUND_NEAREST_EVEN
));
2525 r600_store_context_reg(cb
, R_028864_SQ_PGM_RESOURCES_2_VS
, S_028864_SINGLE_ROUND(V_SQ_ROUND_NEAREST_EVEN
));
2526 r600_store_context_reg(cb
, R_02887C_SQ_PGM_RESOURCES_2_GS
, S_028848_SINGLE_ROUND(V_SQ_ROUND_NEAREST_EVEN
));
2527 r600_store_context_reg(cb
, R_028894_SQ_PGM_RESOURCES_2_ES
, S_028848_SINGLE_ROUND(V_SQ_ROUND_NEAREST_EVEN
));
2528 r600_store_context_reg(cb
, R_0288C0_SQ_PGM_RESOURCES_2_HS
, S_028848_SINGLE_ROUND(V_SQ_ROUND_NEAREST_EVEN
));
2529 r600_store_context_reg(cb
, R_0288D8_SQ_PGM_RESOURCES_2_LS
, S_028848_SINGLE_ROUND(V_SQ_ROUND_NEAREST_EVEN
));
2531 r600_store_context_reg(cb
, R_0288A8_SQ_PGM_RESOURCES_FS
, 0);
2533 /* to avoid GPU doing any preloading of constant from random address */
2534 r600_store_context_reg_seq(cb
, R_028140_ALU_CONST_BUFFER_SIZE_PS_0
, 16);
2535 for (i
= 0; i
< 16; i
++)
2536 r600_store_value(cb
, 0);
2538 r600_store_context_reg_seq(cb
, R_028180_ALU_CONST_BUFFER_SIZE_VS_0
, 16);
2539 for (i
= 0; i
< 16; i
++)
2540 r600_store_value(cb
, 0);
2542 r600_store_context_reg_seq(cb
, R_0281C0_ALU_CONST_BUFFER_SIZE_GS_0
, 16);
2543 for (i
= 0; i
< 16; i
++)
2544 r600_store_value(cb
, 0);
2546 r600_store_context_reg_seq(cb
, R_028FC0_ALU_CONST_BUFFER_SIZE_LS_0
, 16);
2547 for (i
= 0; i
< 16; i
++)
2548 r600_store_value(cb
, 0);
2550 r600_store_context_reg_seq(cb
, R_028F80_ALU_CONST_BUFFER_SIZE_HS_0
, 16);
2551 for (i
= 0; i
< 16; i
++)
2552 r600_store_value(cb
, 0);
2554 if (rctx
->screen
->b
.has_streamout
) {
2555 r600_store_context_reg(cb
, R_028B28_VGT_STRMOUT_DRAW_OPAQUE_OFFSET
, 0);
2558 r600_store_context_reg(cb
, R_028010_DB_RENDER_OVERRIDE2
, 0);
2559 r600_store_context_reg(cb
, R_028234_PA_SU_HARDWARE_SCREEN_OFFSET
, 0);
2560 r600_store_context_reg(cb
, R_0286C8_SPI_THREAD_GROUPING
, 0);
2561 r600_store_context_reg_seq(cb
, R_0286E4_SPI_PS_IN_CONTROL_2
, 2);
2562 r600_store_value(cb
, 0); /* R_0286E4_SPI_PS_IN_CONTROL_2 */
2563 r600_store_value(cb
, 0); /* R_0286E8_SPI_COMPUTE_INPUT_CNTL */
2565 r600_store_context_reg_seq(cb
, R_028B54_VGT_SHADER_STAGES_EN
, 2);
2566 r600_store_value(cb
, 0); /* R028B54_VGT_SHADER_STAGES_EN */
2567 r600_store_value(cb
, 0); /* R028B58_VGT_LS_HS_CONFIG */
2568 r600_store_context_reg(cb
, R_028B6C_VGT_TF_PARAM
, 0);
2569 eg_store_loop_const(cb
, R_03A200_SQ_LOOP_CONST_0
, 0x01000FFF);
2570 eg_store_loop_const(cb
, R_03A200_SQ_LOOP_CONST_0
+ (32 * 4), 0x01000FFF);
2571 eg_store_loop_const(cb
, R_03A200_SQ_LOOP_CONST_0
+ (64 * 4), 0x01000FFF);
2572 eg_store_loop_const(cb
, R_03A200_SQ_LOOP_CONST_0
+ (96 * 4), 0x01000FFF);
2573 eg_store_loop_const(cb
, R_03A200_SQ_LOOP_CONST_0
+ (128 * 4), 0x01000FFF);
2576 void evergreen_init_common_regs(struct r600_context
*rctx
, struct r600_command_buffer
*cb
,
2577 enum chip_class ctx_chip_class
,
2578 enum radeon_family ctx_family
,
2600 rctx
->default_gprs
[R600_HW_STAGE_PS
] = 93;
2601 rctx
->default_gprs
[R600_HW_STAGE_VS
] = 46;
2602 rctx
->r6xx_num_clause_temp_gprs
= 4;
2603 rctx
->default_gprs
[R600_HW_STAGE_GS
] = 31;
2604 rctx
->default_gprs
[R600_HW_STAGE_ES
] = 31;
2605 rctx
->default_gprs
[EG_HW_STAGE_HS
] = 23;
2606 rctx
->default_gprs
[EG_HW_STAGE_LS
] = 23;
2609 switch (ctx_family
) {
2617 tmp
|= S_008C00_VC_ENABLE(1);
2620 tmp
|= S_008C00_EXPORT_SRC_C(1);
2621 tmp
|= S_008C00_CS_PRIO(cs_prio
);
2622 tmp
|= S_008C00_LS_PRIO(ls_prio
);
2623 tmp
|= S_008C00_HS_PRIO(hs_prio
);
2624 tmp
|= S_008C00_PS_PRIO(ps_prio
);
2625 tmp
|= S_008C00_VS_PRIO(vs_prio
);
2626 tmp
|= S_008C00_GS_PRIO(gs_prio
);
2627 tmp
|= S_008C00_ES_PRIO(es_prio
);
2629 r600_store_config_reg_seq(cb
, R_008C00_SQ_CONFIG
, 1);
2630 r600_store_value(cb
, tmp
); /* R_008C00_SQ_CONFIG */
2632 r600_store_config_reg_seq(cb
, R_008C10_SQ_GLOBAL_GPR_RESOURCE_MGMT_1
, 2);
2633 r600_store_value(cb
, 0); /* R_008C10_SQ_GLOBAL_GPR_RESOURCE_MGMT_1 */
2634 r600_store_value(cb
, 0); /* R_008C14_SQ_GLOBAL_GPR_RESOURCE_MGMT_2 */
2636 /* The cs checker requires this register to be set. */
2637 r600_store_context_reg(cb
, R_028800_DB_DEPTH_CONTROL
, 0);
2639 r600_store_context_reg_seq(cb
, R_028350_SX_MISC
, 2);
2640 r600_store_value(cb
, 0);
2641 r600_store_value(cb
, S_028354_SURFACE_SYNC_MASK(0xf));
2646 void evergreen_init_atom_start_cs(struct r600_context
*rctx
)
2648 struct r600_command_buffer
*cb
= &rctx
->start_cs_cmd
;
2656 int num_ps_stack_entries
;
2657 int num_vs_stack_entries
;
2658 int num_gs_stack_entries
;
2659 int num_es_stack_entries
;
2660 int num_hs_stack_entries
;
2661 int num_ls_stack_entries
;
2662 enum radeon_family family
;
2665 if (rctx
->b
.chip_class
== CAYMAN
) {
2666 cayman_init_atom_start_cs(rctx
);
2670 r600_init_command_buffer(cb
, 338);
2672 /* This must be first. */
2673 r600_store_value(cb
, PKT3(PKT3_CONTEXT_CONTROL
, 1, 0));
2674 r600_store_value(cb
, 0x80000000);
2675 r600_store_value(cb
, 0x80000000);
2677 /* We're setting config registers here. */
2678 r600_store_value(cb
, PKT3(PKT3_EVENT_WRITE
, 0, 0));
2679 r600_store_value(cb
, EVENT_TYPE(EVENT_TYPE_PS_PARTIAL_FLUSH
) | EVENT_INDEX(4));
2681 evergreen_init_common_regs(rctx
, cb
, rctx
->b
.chip_class
,
2682 rctx
->b
.family
, rctx
->screen
->b
.info
.drm_minor
);
2684 family
= rctx
->b
.family
;
2688 num_ps_threads
= 96;
2689 num_vs_threads
= 16;
2690 num_gs_threads
= 16;
2691 num_es_threads
= 16;
2692 num_hs_threads
= 16;
2693 num_ls_threads
= 16;
2694 num_ps_stack_entries
= 42;
2695 num_vs_stack_entries
= 42;
2696 num_gs_stack_entries
= 42;
2697 num_es_stack_entries
= 42;
2698 num_hs_stack_entries
= 42;
2699 num_ls_stack_entries
= 42;
2702 num_ps_threads
= 128;
2703 num_vs_threads
= 20;
2704 num_gs_threads
= 20;
2705 num_es_threads
= 20;
2706 num_hs_threads
= 20;
2707 num_ls_threads
= 20;
2708 num_ps_stack_entries
= 42;
2709 num_vs_stack_entries
= 42;
2710 num_gs_stack_entries
= 42;
2711 num_es_stack_entries
= 42;
2712 num_hs_stack_entries
= 42;
2713 num_ls_stack_entries
= 42;
2716 num_ps_threads
= 128;
2717 num_vs_threads
= 20;
2718 num_gs_threads
= 20;
2719 num_es_threads
= 20;
2720 num_hs_threads
= 20;
2721 num_ls_threads
= 20;
2722 num_ps_stack_entries
= 85;
2723 num_vs_stack_entries
= 85;
2724 num_gs_stack_entries
= 85;
2725 num_es_stack_entries
= 85;
2726 num_hs_stack_entries
= 85;
2727 num_ls_stack_entries
= 85;
2731 num_ps_threads
= 128;
2732 num_vs_threads
= 20;
2733 num_gs_threads
= 20;
2734 num_es_threads
= 20;
2735 num_hs_threads
= 20;
2736 num_ls_threads
= 20;
2737 num_ps_stack_entries
= 85;
2738 num_vs_stack_entries
= 85;
2739 num_gs_stack_entries
= 85;
2740 num_es_stack_entries
= 85;
2741 num_hs_stack_entries
= 85;
2742 num_ls_stack_entries
= 85;
2745 num_ps_threads
= 96;
2746 num_vs_threads
= 16;
2747 num_gs_threads
= 16;
2748 num_es_threads
= 16;
2749 num_hs_threads
= 16;
2750 num_ls_threads
= 16;
2751 num_ps_stack_entries
= 42;
2752 num_vs_stack_entries
= 42;
2753 num_gs_stack_entries
= 42;
2754 num_es_stack_entries
= 42;
2755 num_hs_stack_entries
= 42;
2756 num_ls_stack_entries
= 42;
2759 num_ps_threads
= 96;
2760 num_vs_threads
= 25;
2761 num_gs_threads
= 25;
2762 num_es_threads
= 25;
2763 num_hs_threads
= 16;
2764 num_ls_threads
= 16;
2765 num_ps_stack_entries
= 42;
2766 num_vs_stack_entries
= 42;
2767 num_gs_stack_entries
= 42;
2768 num_es_stack_entries
= 42;
2769 num_hs_stack_entries
= 42;
2770 num_ls_stack_entries
= 42;
2773 num_ps_threads
= 96;
2774 num_vs_threads
= 25;
2775 num_gs_threads
= 25;
2776 num_es_threads
= 25;
2777 num_hs_threads
= 16;
2778 num_ls_threads
= 16;
2779 num_ps_stack_entries
= 85;
2780 num_vs_stack_entries
= 85;
2781 num_gs_stack_entries
= 85;
2782 num_es_stack_entries
= 85;
2783 num_hs_stack_entries
= 85;
2784 num_ls_stack_entries
= 85;
2787 num_ps_threads
= 128;
2788 num_vs_threads
= 20;
2789 num_gs_threads
= 20;
2790 num_es_threads
= 20;
2791 num_hs_threads
= 20;
2792 num_ls_threads
= 20;
2793 num_ps_stack_entries
= 85;
2794 num_vs_stack_entries
= 85;
2795 num_gs_stack_entries
= 85;
2796 num_es_stack_entries
= 85;
2797 num_hs_stack_entries
= 85;
2798 num_ls_stack_entries
= 85;
2801 num_ps_threads
= 128;
2802 num_vs_threads
= 20;
2803 num_gs_threads
= 20;
2804 num_es_threads
= 20;
2805 num_hs_threads
= 20;
2806 num_ls_threads
= 20;
2807 num_ps_stack_entries
= 42;
2808 num_vs_stack_entries
= 42;
2809 num_gs_stack_entries
= 42;
2810 num_es_stack_entries
= 42;
2811 num_hs_stack_entries
= 42;
2812 num_ls_stack_entries
= 42;
2815 num_ps_threads
= 96;
2816 num_vs_threads
= 10;
2817 num_gs_threads
= 10;
2818 num_es_threads
= 10;
2819 num_hs_threads
= 10;
2820 num_ls_threads
= 10;
2821 num_ps_stack_entries
= 42;
2822 num_vs_stack_entries
= 42;
2823 num_gs_stack_entries
= 42;
2824 num_es_stack_entries
= 42;
2825 num_hs_stack_entries
= 42;
2826 num_ls_stack_entries
= 42;
2830 tmp
= S_008C18_NUM_PS_THREADS(num_ps_threads
);
2831 tmp
|= S_008C18_NUM_VS_THREADS(num_vs_threads
);
2832 tmp
|= S_008C18_NUM_GS_THREADS(num_gs_threads
);
2833 tmp
|= S_008C18_NUM_ES_THREADS(num_es_threads
);
2835 r600_store_config_reg_seq(cb
, R_008C18_SQ_THREAD_RESOURCE_MGMT_1
, 5);
2836 r600_store_value(cb
, tmp
); /* R_008C18_SQ_THREAD_RESOURCE_MGMT_1 */
2838 tmp
= S_008C1C_NUM_HS_THREADS(num_hs_threads
);
2839 tmp
|= S_008C1C_NUM_LS_THREADS(num_ls_threads
);
2840 r600_store_value(cb
, tmp
); /* R_008C1C_SQ_THREAD_RESOURCE_MGMT_2 */
2842 tmp
= S_008C20_NUM_PS_STACK_ENTRIES(num_ps_stack_entries
);
2843 tmp
|= S_008C20_NUM_VS_STACK_ENTRIES(num_vs_stack_entries
);
2844 r600_store_value(cb
, tmp
); /* R_008C20_SQ_STACK_RESOURCE_MGMT_1 */
2846 tmp
= S_008C24_NUM_GS_STACK_ENTRIES(num_gs_stack_entries
);
2847 tmp
|= S_008C24_NUM_ES_STACK_ENTRIES(num_es_stack_entries
);
2848 r600_store_value(cb
, tmp
); /* R_008C24_SQ_STACK_RESOURCE_MGMT_2 */
2850 tmp
= S_008C28_NUM_HS_STACK_ENTRIES(num_hs_stack_entries
);
2851 tmp
|= S_008C28_NUM_LS_STACK_ENTRIES(num_ls_stack_entries
);
2852 r600_store_value(cb
, tmp
); /* R_008C28_SQ_STACK_RESOURCE_MGMT_3 */
2854 r600_store_config_reg(cb
, R_008E2C_SQ_LDS_RESOURCE_MGMT
,
2855 S_008E2C_NUM_PS_LDS(0x1000) | S_008E2C_NUM_LS_LDS(0x1000));
2857 /* remove LS/HS from one SIMD for hw workaround */
2858 r600_store_config_reg_seq(cb
, R_008E20_SQ_STATIC_THREAD_MGMT1
, 3);
2859 r600_store_value(cb
, 0xffffffff);
2860 r600_store_value(cb
, 0xffffffff);
2861 r600_store_value(cb
, 0xfffffffe);
2863 r600_store_config_reg(cb
, R_009100_SPI_CONFIG_CNTL
, 0);
2864 r600_store_config_reg(cb
, R_00913C_SPI_CONFIG_CNTL_1
, S_00913C_VTX_DONE_DELAY(4));
2866 r600_store_context_reg_seq(cb
, R_028900_SQ_ESGS_RING_ITEMSIZE
, 6);
2867 r600_store_value(cb
, 0); /* R_028900_SQ_ESGS_RING_ITEMSIZE */
2868 r600_store_value(cb
, 0); /* R_028904_SQ_GSVS_RING_ITEMSIZE */
2869 r600_store_value(cb
, 0); /* R_028908_SQ_ESTMP_RING_ITEMSIZE */
2870 r600_store_value(cb
, 0); /* R_02890C_SQ_GSTMP_RING_ITEMSIZE */
2871 r600_store_value(cb
, 0); /* R_028910_SQ_VSTMP_RING_ITEMSIZE */
2872 r600_store_value(cb
, 0); /* R_028914_SQ_PSTMP_RING_ITEMSIZE */
2874 r600_store_context_reg_seq(cb
, R_02891C_SQ_GS_VERT_ITEMSIZE
, 4);
2875 r600_store_value(cb
, 0); /* R_02891C_SQ_GS_VERT_ITEMSIZE */
2876 r600_store_value(cb
, 0); /* R_028920_SQ_GS_VERT_ITEMSIZE_1 */
2877 r600_store_value(cb
, 0); /* R_028924_SQ_GS_VERT_ITEMSIZE_2 */
2878 r600_store_value(cb
, 0); /* R_028928_SQ_GS_VERT_ITEMSIZE_3 */
2880 r600_store_context_reg_seq(cb
, R_028A10_VGT_OUTPUT_PATH_CNTL
, 13);
2881 r600_store_value(cb
, 0); /* R_028A10_VGT_OUTPUT_PATH_CNTL */
2882 r600_store_value(cb
, 0); /* R_028A14_VGT_HOS_CNTL */
2883 r600_store_value(cb
, fui(64)); /* R_028A18_VGT_HOS_MAX_TESS_LEVEL */
2884 r600_store_value(cb
, fui(1.0)); /* R_028A1C_VGT_HOS_MIN_TESS_LEVEL */
2885 r600_store_value(cb
, 16); /* R_028A20_VGT_HOS_REUSE_DEPTH */
2886 r600_store_value(cb
, 0); /* R_028A24_VGT_GROUP_PRIM_TYPE */
2887 r600_store_value(cb
, 0); /* R_028A28_VGT_GROUP_FIRST_DECR */
2888 r600_store_value(cb
, 0); /* R_028A2C_VGT_GROUP_DECR */
2889 r600_store_value(cb
, 0); /* R_028A30_VGT_GROUP_VECT_0_CNTL */
2890 r600_store_value(cb
, 0); /* R_028A34_VGT_GROUP_VECT_1_CNTL */
2891 r600_store_value(cb
, 0); /* R_028A38_VGT_GROUP_VECT_0_FMT_CNTL */
2892 r600_store_value(cb
, 0); /* R_028A3C_VGT_GROUP_VECT_1_FMT_CNTL */
2893 r600_store_value(cb
, 0); /* R_028A40_VGT_GS_MODE */
2895 r600_store_config_reg(cb
, R_008A14_PA_CL_ENHANCE
, (3 << 1) | 1);
2897 r600_store_context_reg(cb
, R_0288F0_SQ_VTX_SEMANTIC_CLEAR
, ~0);
2899 r600_store_context_reg_seq(cb
, R_028400_VGT_MAX_VTX_INDX
, 2);
2900 r600_store_value(cb
, ~0); /* R_028400_VGT_MAX_VTX_INDX */
2901 r600_store_value(cb
, 0); /* R_028404_VGT_MIN_VTX_INDX */
2903 r600_store_ctl_const(cb
, R_03CFF0_SQ_VTX_BASE_VTX_LOC
, 0);
2905 r600_store_context_reg(cb
, R_028028_DB_STENCIL_CLEAR
, 0);
2907 r600_store_context_reg(cb
, R_028200_PA_SC_WINDOW_OFFSET
, 0);
2908 r600_store_context_reg(cb
, R_02820C_PA_SC_CLIPRECT_RULE
, 0xFFFF);
2909 r600_store_context_reg(cb
, R_028230_PA_SC_EDGERULE
, 0xAAAAAAAA);
2911 r600_store_context_reg_seq(cb
, R_0282D0_PA_SC_VPORT_ZMIN_0
, 2 * R600_MAX_VIEWPORTS
);
2912 for (tmp
= 0; tmp
< R600_MAX_VIEWPORTS
; tmp
++) {
2913 r600_store_value(cb
, 0); /* R_0282D0_PA_SC_VPORT_ZMIN_0 */
2914 r600_store_value(cb
, fui(1.0)); /* R_0282D4_PA_SC_VPORT_ZMAX_0 */
2917 r600_store_context_reg(cb
, R_0286DC_SPI_FOG_CNTL
, 0);
2918 r600_store_context_reg(cb
, R_028820_PA_CL_NANINF_CNTL
, 0);
2920 r600_store_context_reg_seq(cb
, R_028AC0_DB_SRESULTS_COMPARE_STATE0
, 3);
2921 r600_store_value(cb
, 0); /* R_028AC0_DB_SRESULTS_COMPARE_STATE0 */
2922 r600_store_value(cb
, 0); /* R_028AC4_DB_SRESULTS_COMPARE_STATE1 */
2923 r600_store_value(cb
, 0); /* R_028AC8_DB_PRELOAD_CONTROL */
2925 r600_store_context_reg_seq(cb
, R_028C0C_PA_CL_GB_VERT_CLIP_ADJ
, 4);
2926 r600_store_value(cb
, fui(1.0)); /* R_028C0C_PA_CL_GB_VERT_CLIP_ADJ */
2927 r600_store_value(cb
, fui(1.0)); /* R_028C10_PA_CL_GB_VERT_DISC_ADJ */
2928 r600_store_value(cb
, fui(1.0)); /* R_028C14_PA_CL_GB_HORZ_CLIP_ADJ */
2929 r600_store_value(cb
, fui(1.0)); /* R_028C18_PA_CL_GB_HORZ_DISC_ADJ */
2931 r600_store_context_reg_seq(cb
, R_028240_PA_SC_GENERIC_SCISSOR_TL
, 2);
2932 r600_store_value(cb
, 0); /* R_028240_PA_SC_GENERIC_SCISSOR_TL */
2933 r600_store_value(cb
, S_028244_BR_X(16384) | S_028244_BR_Y(16384)); /* R_028244_PA_SC_GENERIC_SCISSOR_BR */
2935 r600_store_context_reg_seq(cb
, R_028030_PA_SC_SCREEN_SCISSOR_TL
, 2);
2936 r600_store_value(cb
, 0); /* R_028030_PA_SC_SCREEN_SCISSOR_TL */
2937 r600_store_value(cb
, S_028034_BR_X(16384) | S_028034_BR_Y(16384)); /* R_028034_PA_SC_SCREEN_SCISSOR_BR */
2939 r600_store_context_reg(cb
, R_028848_SQ_PGM_RESOURCES_2_PS
, S_028848_SINGLE_ROUND(V_SQ_ROUND_NEAREST_EVEN
));
2940 r600_store_context_reg(cb
, R_028864_SQ_PGM_RESOURCES_2_VS
, S_028864_SINGLE_ROUND(V_SQ_ROUND_NEAREST_EVEN
));
2941 r600_store_context_reg(cb
, R_02887C_SQ_PGM_RESOURCES_2_GS
, S_028848_SINGLE_ROUND(V_SQ_ROUND_NEAREST_EVEN
));
2942 r600_store_context_reg(cb
, R_028894_SQ_PGM_RESOURCES_2_ES
, S_028848_SINGLE_ROUND(V_SQ_ROUND_NEAREST_EVEN
));
2943 r600_store_context_reg(cb
, R_0288A8_SQ_PGM_RESOURCES_FS
, 0);
2944 r600_store_context_reg(cb
, R_0288C0_SQ_PGM_RESOURCES_2_HS
, S_028848_SINGLE_ROUND(V_SQ_ROUND_NEAREST_EVEN
));
2945 r600_store_context_reg(cb
, R_0288D8_SQ_PGM_RESOURCES_2_LS
, S_028848_SINGLE_ROUND(V_SQ_ROUND_NEAREST_EVEN
));
2947 /* to avoid GPU doing any preloading of constant from random address */
2948 r600_store_context_reg_seq(cb
, R_028140_ALU_CONST_BUFFER_SIZE_PS_0
, 16);
2949 for (i
= 0; i
< 16; i
++)
2950 r600_store_value(cb
, 0);
2952 r600_store_context_reg_seq(cb
, R_028180_ALU_CONST_BUFFER_SIZE_VS_0
, 16);
2953 for (i
= 0; i
< 16; i
++)
2954 r600_store_value(cb
, 0);
2956 r600_store_context_reg_seq(cb
, R_0281C0_ALU_CONST_BUFFER_SIZE_GS_0
, 16);
2957 for (i
= 0; i
< 16; i
++)
2958 r600_store_value(cb
, 0);
2960 r600_store_context_reg_seq(cb
, R_028FC0_ALU_CONST_BUFFER_SIZE_LS_0
, 16);
2961 for (i
= 0; i
< 16; i
++)
2962 r600_store_value(cb
, 0);
2964 r600_store_context_reg_seq(cb
, R_028F80_ALU_CONST_BUFFER_SIZE_HS_0
, 16);
2965 for (i
= 0; i
< 16; i
++)
2966 r600_store_value(cb
, 0);
2968 r600_store_context_reg(cb
, R_028B98_VGT_STRMOUT_BUFFER_CONFIG
, 0);
2970 if (rctx
->screen
->b
.has_streamout
) {
2971 r600_store_context_reg(cb
, R_028B28_VGT_STRMOUT_DRAW_OPAQUE_OFFSET
, 0);
2974 r600_store_context_reg(cb
, R_028010_DB_RENDER_OVERRIDE2
, 0);
2975 r600_store_context_reg(cb
, R_028234_PA_SU_HARDWARE_SCREEN_OFFSET
, 0);
2976 r600_store_context_reg(cb
, R_0286C8_SPI_THREAD_GROUPING
, 0);
2977 r600_store_context_reg_seq(cb
, R_0286E4_SPI_PS_IN_CONTROL_2
, 2);
2978 r600_store_value(cb
, 0); /* R_0286E4_SPI_PS_IN_CONTROL_2 */
2979 r600_store_value(cb
, 0); /* R_0286E8_SPI_COMPUTE_INPUT_CNTL */
2981 r600_store_context_reg_seq(cb
, R_0288E8_SQ_LDS_ALLOC
, 2);
2982 r600_store_value(cb
, 0); /* R_0288E8_SQ_LDS_ALLOC */
2983 r600_store_value(cb
, 0); /* R_0288EC_SQ_LDS_ALLOC_PS */
2985 if (rctx
->b
.family
== CHIP_CAICOS
) {
2986 r600_store_context_reg_seq(cb
, R_028B54_VGT_SHADER_STAGES_EN
, 2);
2987 r600_store_value(cb
, 0); /* R028B54_VGT_SHADER_STAGES_EN */
2988 r600_store_value(cb
, 0); /* R028B58_VGT_LS_HS_CONFIG */
2989 r600_store_context_reg(cb
, R_028B6C_VGT_TF_PARAM
, 0);
2991 r600_store_context_reg_seq(cb
, R_028B54_VGT_SHADER_STAGES_EN
, 7);
2992 r600_store_value(cb
, 0); /* R028B54_VGT_SHADER_STAGES_EN */
2993 r600_store_value(cb
, 0); /* R028B58_VGT_LS_HS_CONFIG */
2994 r600_store_value(cb
, 0); /* R028B5C_VGT_LS_SIZE */
2995 r600_store_value(cb
, 0); /* R028B60_VGT_HS_SIZE */
2996 r600_store_value(cb
, 0); /* R028B64_VGT_LS_HS_ALLOC */
2997 r600_store_value(cb
, 0); /* R028B68_VGT_HS_PATCH_CONST */
2998 r600_store_value(cb
, 0); /* R028B68_VGT_TF_PARAM */
3001 eg_store_loop_const(cb
, R_03A200_SQ_LOOP_CONST_0
, 0x01000FFF);
3002 eg_store_loop_const(cb
, R_03A200_SQ_LOOP_CONST_0
+ (32 * 4), 0x01000FFF);
3003 eg_store_loop_const(cb
, R_03A200_SQ_LOOP_CONST_0
+ (64 * 4), 0x01000FFF);
3004 eg_store_loop_const(cb
, R_03A200_SQ_LOOP_CONST_0
+ (96 * 4), 0x01000FFF);
3005 eg_store_loop_const(cb
, R_03A200_SQ_LOOP_CONST_0
+ (128 * 4), 0x01000FFF);
3008 void evergreen_update_ps_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
3010 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
3011 struct r600_command_buffer
*cb
= &shader
->command_buffer
;
3012 struct r600_shader
*rshader
= &shader
->shader
;
3013 unsigned i
, exports_ps
, num_cout
, spi_ps_in_control_0
, spi_input_z
, spi_ps_in_control_1
, db_shader_control
= 0;
3014 int pos_index
= -1, face_index
= -1, fixed_pt_position_index
= -1;
3016 boolean have_perspective
= FALSE
, have_linear
= FALSE
;
3017 static const unsigned spi_baryc_enable_bit
[6] = {
3018 S_0286E0_PERSP_SAMPLE_ENA(1),
3019 S_0286E0_PERSP_CENTER_ENA(1),
3020 S_0286E0_PERSP_CENTROID_ENA(1),
3021 S_0286E0_LINEAR_SAMPLE_ENA(1),
3022 S_0286E0_LINEAR_CENTER_ENA(1),
3023 S_0286E0_LINEAR_CENTROID_ENA(1)
3025 unsigned spi_baryc_cntl
= 0, sid
, tmp
, num
= 0;
3026 unsigned z_export
= 0, stencil_export
= 0, mask_export
= 0;
3027 unsigned sprite_coord_enable
= rctx
->rasterizer
? rctx
->rasterizer
->sprite_coord_enable
: 0;
3028 uint32_t spi_ps_input_cntl
[32];
3031 r600_init_command_buffer(cb
, 64);
3036 for (i
= 0; i
< rshader
->ninput
; i
++) {
3037 /* evergreen NUM_INTERP only contains values interpolated into the LDS,
3038 POSITION goes via GPRs from the SC so isn't counted */
3039 if (rshader
->input
[i
].name
== TGSI_SEMANTIC_POSITION
)
3041 else if (rshader
->input
[i
].name
== TGSI_SEMANTIC_FACE
) {
3042 if (face_index
== -1)
3045 else if (rshader
->input
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
) {
3046 if (face_index
== -1)
3047 face_index
= i
; /* lives in same register, same enable bit */
3049 else if (rshader
->input
[i
].name
== TGSI_SEMANTIC_SAMPLEID
) {
3050 fixed_pt_position_index
= i
;
3054 int k
= eg_get_interpolator_index(
3055 rshader
->input
[i
].interpolate
,
3056 rshader
->input
[i
].interpolate_location
);
3058 spi_baryc_cntl
|= spi_baryc_enable_bit
[k
];
3059 have_perspective
|= k
< 3;
3060 have_linear
|= !(k
< 3);
3064 sid
= rshader
->input
[i
].spi_sid
;
3067 tmp
= S_028644_SEMANTIC(sid
);
3069 if (rshader
->input
[i
].name
== TGSI_SEMANTIC_POSITION
||
3070 rshader
->input
[i
].interpolate
== TGSI_INTERPOLATE_CONSTANT
||
3071 (rshader
->input
[i
].interpolate
== TGSI_INTERPOLATE_COLOR
&&
3072 rctx
->rasterizer
&& rctx
->rasterizer
->flatshade
)) {
3073 tmp
|= S_028644_FLAT_SHADE(1);
3076 if (rshader
->input
[i
].name
== TGSI_SEMANTIC_GENERIC
&&
3077 (sprite_coord_enable
& (1 << rshader
->input
[i
].sid
))) {
3078 tmp
|= S_028644_PT_SPRITE_TEX(1);
3081 spi_ps_input_cntl
[num
++] = tmp
;
3085 r600_store_context_reg_seq(cb
, R_028644_SPI_PS_INPUT_CNTL_0
, num
);
3086 r600_store_array(cb
, num
, spi_ps_input_cntl
);
3088 for (i
= 0; i
< rshader
->noutput
; i
++) {
3089 if (rshader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
3091 if (rshader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
)
3093 if (rshader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
&&
3094 rctx
->framebuffer
.nr_samples
> 1 && rctx
->ps_iter_samples
> 0)
3097 if (rshader
->uses_kill
)
3098 db_shader_control
|= S_02880C_KILL_ENABLE(1);
3100 db_shader_control
|= S_02880C_Z_EXPORT_ENABLE(z_export
);
3101 db_shader_control
|= S_02880C_STENCIL_EXPORT_ENABLE(stencil_export
);
3102 db_shader_control
|= S_02880C_MASK_EXPORT_ENABLE(mask_export
);
3104 switch (rshader
->ps_conservative_z
) {
3105 default: /* fall through */
3106 case TGSI_FS_DEPTH_LAYOUT_ANY
:
3107 db_shader_control
|= S_02880C_CONSERVATIVE_Z_EXPORT(V_02880C_EXPORT_ANY_Z
);
3109 case TGSI_FS_DEPTH_LAYOUT_GREATER
:
3110 db_shader_control
|= S_02880C_CONSERVATIVE_Z_EXPORT(V_02880C_EXPORT_GREATER_THAN_Z
);
3112 case TGSI_FS_DEPTH_LAYOUT_LESS
:
3113 db_shader_control
|= S_02880C_CONSERVATIVE_Z_EXPORT(V_02880C_EXPORT_LESS_THAN_Z
);
3118 for (i
= 0; i
< rshader
->noutput
; i
++) {
3119 if (rshader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
||
3120 rshader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
||
3121 rshader
->output
[i
].name
== TGSI_SEMANTIC_SAMPLEMASK
)
3125 num_cout
= rshader
->nr_ps_color_exports
;
3127 exports_ps
|= S_02884C_EXPORT_COLORS(num_cout
);
3129 /* always at least export 1 component per pixel */
3132 shader
->nr_ps_color_outputs
= num_cout
;
3135 have_perspective
= TRUE
;
3137 if (!spi_baryc_cntl
)
3138 spi_baryc_cntl
|= spi_baryc_enable_bit
[0];
3140 if (!have_perspective
&& !have_linear
)
3141 have_perspective
= TRUE
;
3143 spi_ps_in_control_0
= S_0286CC_NUM_INTERP(ninterp
) |
3144 S_0286CC_PERSP_GRADIENT_ENA(have_perspective
) |
3145 S_0286CC_LINEAR_GRADIENT_ENA(have_linear
);
3147 if (pos_index
!= -1) {
3148 spi_ps_in_control_0
|= S_0286CC_POSITION_ENA(1) |
3149 S_0286CC_POSITION_CENTROID(rshader
->input
[pos_index
].interpolate_location
== TGSI_INTERPOLATE_LOC_CENTROID
) |
3150 S_0286CC_POSITION_ADDR(rshader
->input
[pos_index
].gpr
);
3151 spi_input_z
|= S_0286D8_PROVIDE_Z_TO_SPI(1);
3154 spi_ps_in_control_1
= 0;
3155 if (face_index
!= -1) {
3156 spi_ps_in_control_1
|= S_0286D0_FRONT_FACE_ENA(1) |
3157 S_0286D0_FRONT_FACE_ADDR(rshader
->input
[face_index
].gpr
);
3159 if (fixed_pt_position_index
!= -1) {
3160 spi_ps_in_control_1
|= S_0286D0_FIXED_PT_POSITION_ENA(1) |
3161 S_0286D0_FIXED_PT_POSITION_ADDR(rshader
->input
[fixed_pt_position_index
].gpr
);
3164 r600_store_context_reg_seq(cb
, R_0286CC_SPI_PS_IN_CONTROL_0
, 2);
3165 r600_store_value(cb
, spi_ps_in_control_0
); /* R_0286CC_SPI_PS_IN_CONTROL_0 */
3166 r600_store_value(cb
, spi_ps_in_control_1
); /* R_0286D0_SPI_PS_IN_CONTROL_1 */
3168 r600_store_context_reg(cb
, R_0286E0_SPI_BARYC_CNTL
, spi_baryc_cntl
);
3169 r600_store_context_reg(cb
, R_0286D8_SPI_INPUT_Z
, spi_input_z
);
3170 r600_store_context_reg(cb
, R_02884C_SQ_PGM_EXPORTS_PS
, exports_ps
);
3172 r600_store_context_reg_seq(cb
, R_028840_SQ_PGM_START_PS
, 2);
3173 r600_store_value(cb
, shader
->bo
->gpu_address
>> 8);
3174 r600_store_value(cb
, /* R_028844_SQ_PGM_RESOURCES_PS */
3175 S_028844_NUM_GPRS(rshader
->bc
.ngpr
) |
3176 S_028844_PRIME_CACHE_ON_DRAW(1) |
3177 S_028844_STACK_SIZE(rshader
->bc
.nstack
));
3178 /* After that, the NOP relocation packet must be emitted (shader->bo, RADEON_USAGE_READ). */
3180 shader
->db_shader_control
= db_shader_control
;
3181 shader
->ps_depth_export
= z_export
| stencil_export
| mask_export
;
3183 shader
->sprite_coord_enable
= sprite_coord_enable
;
3184 if (rctx
->rasterizer
)
3185 shader
->flatshade
= rctx
->rasterizer
->flatshade
;
3188 void evergreen_update_es_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
3190 struct r600_command_buffer
*cb
= &shader
->command_buffer
;
3191 struct r600_shader
*rshader
= &shader
->shader
;
3193 r600_init_command_buffer(cb
, 32);
3195 r600_store_context_reg(cb
, R_028890_SQ_PGM_RESOURCES_ES
,
3196 S_028890_NUM_GPRS(rshader
->bc
.ngpr
) |
3197 S_028890_STACK_SIZE(rshader
->bc
.nstack
));
3198 r600_store_context_reg(cb
, R_02888C_SQ_PGM_START_ES
,
3199 shader
->bo
->gpu_address
>> 8);
3200 /* After that, the NOP relocation packet must be emitted (shader->bo, RADEON_USAGE_READ). */
3203 void evergreen_update_gs_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
3205 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
3206 struct r600_command_buffer
*cb
= &shader
->command_buffer
;
3207 struct r600_shader
*rshader
= &shader
->shader
;
3208 struct r600_shader
*cp_shader
= &shader
->gs_copy_shader
->shader
;
3209 unsigned gsvs_itemsizes
[4] = {
3210 (cp_shader
->ring_item_sizes
[0] * shader
->selector
->gs_max_out_vertices
) >> 2,
3211 (cp_shader
->ring_item_sizes
[1] * shader
->selector
->gs_max_out_vertices
) >> 2,
3212 (cp_shader
->ring_item_sizes
[2] * shader
->selector
->gs_max_out_vertices
) >> 2,
3213 (cp_shader
->ring_item_sizes
[3] * shader
->selector
->gs_max_out_vertices
) >> 2
3216 r600_init_command_buffer(cb
, 64);
3218 /* VGT_GS_MODE is written by evergreen_emit_shader_stages */
3221 r600_store_context_reg(cb
, R_028B38_VGT_GS_MAX_VERT_OUT
,
3222 S_028B38_MAX_VERT_OUT(shader
->selector
->gs_max_out_vertices
));
3223 r600_store_context_reg(cb
, R_028A6C_VGT_GS_OUT_PRIM_TYPE
,
3224 r600_conv_prim_to_gs_out(shader
->selector
->gs_output_prim
));
3226 if (rctx
->screen
->b
.info
.drm_minor
>= 35) {
3227 r600_store_context_reg(cb
, R_028B90_VGT_GS_INSTANCE_CNT
,
3228 S_028B90_CNT(MIN2(shader
->selector
->gs_num_invocations
, 127)) |
3229 S_028B90_ENABLE(shader
->selector
->gs_num_invocations
> 0));
3231 r600_store_context_reg_seq(cb
, R_02891C_SQ_GS_VERT_ITEMSIZE
, 4);
3232 r600_store_value(cb
, cp_shader
->ring_item_sizes
[0] >> 2);
3233 r600_store_value(cb
, cp_shader
->ring_item_sizes
[1] >> 2);
3234 r600_store_value(cb
, cp_shader
->ring_item_sizes
[2] >> 2);
3235 r600_store_value(cb
, cp_shader
->ring_item_sizes
[3] >> 2);
3237 r600_store_context_reg(cb
, R_028900_SQ_ESGS_RING_ITEMSIZE
,
3238 (rshader
->ring_item_sizes
[0]) >> 2);
3240 r600_store_context_reg(cb
, R_028904_SQ_GSVS_RING_ITEMSIZE
,
3246 r600_store_context_reg_seq(cb
, R_02892C_SQ_GSVS_RING_OFFSET_1
, 3);
3247 r600_store_value(cb
, gsvs_itemsizes
[0]);
3248 r600_store_value(cb
, gsvs_itemsizes
[0] + gsvs_itemsizes
[1]);
3249 r600_store_value(cb
, gsvs_itemsizes
[0] + gsvs_itemsizes
[1] + gsvs_itemsizes
[2]);
3251 /* FIXME calculate these values somehow ??? */
3252 r600_store_context_reg_seq(cb
, R_028A54_GS_PER_ES
, 3);
3253 r600_store_value(cb
, 0x80); /* GS_PER_ES */
3254 r600_store_value(cb
, 0x100); /* ES_PER_GS */
3255 r600_store_value(cb
, 0x2); /* GS_PER_VS */
3257 r600_store_context_reg(cb
, R_028878_SQ_PGM_RESOURCES_GS
,
3258 S_028878_NUM_GPRS(rshader
->bc
.ngpr
) |
3259 S_028878_STACK_SIZE(rshader
->bc
.nstack
));
3260 r600_store_context_reg(cb
, R_028874_SQ_PGM_START_GS
,
3261 shader
->bo
->gpu_address
>> 8);
3262 /* After that, the NOP relocation packet must be emitted (shader->bo, RADEON_USAGE_READ). */
3266 void evergreen_update_vs_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
3268 struct r600_command_buffer
*cb
= &shader
->command_buffer
;
3269 struct r600_shader
*rshader
= &shader
->shader
;
3270 unsigned spi_vs_out_id
[10] = {};
3271 unsigned i
, tmp
, nparams
= 0;
3273 for (i
= 0; i
< rshader
->noutput
; i
++) {
3274 if (rshader
->output
[i
].spi_sid
) {
3275 tmp
= rshader
->output
[i
].spi_sid
<< ((nparams
& 3) * 8);
3276 spi_vs_out_id
[nparams
/ 4] |= tmp
;
3281 r600_init_command_buffer(cb
, 32);
3283 r600_store_context_reg_seq(cb
, R_02861C_SPI_VS_OUT_ID_0
, 10);
3284 for (i
= 0; i
< 10; i
++) {
3285 r600_store_value(cb
, spi_vs_out_id
[i
]);
3288 /* Certain attributes (position, psize, etc.) don't count as params.
3289 * VS is required to export at least one param and r600_shader_from_tgsi()
3290 * takes care of adding a dummy export.
3295 r600_store_context_reg(cb
, R_0286C4_SPI_VS_OUT_CONFIG
,
3296 S_0286C4_VS_EXPORT_COUNT(nparams
- 1));
3297 r600_store_context_reg(cb
, R_028860_SQ_PGM_RESOURCES_VS
,
3298 S_028860_NUM_GPRS(rshader
->bc
.ngpr
) |
3299 S_028860_STACK_SIZE(rshader
->bc
.nstack
));
3300 if (rshader
->vs_position_window_space
) {
3301 r600_store_context_reg(cb
, R_028818_PA_CL_VTE_CNTL
,
3302 S_028818_VTX_XY_FMT(1) | S_028818_VTX_Z_FMT(1));
3304 r600_store_context_reg(cb
, R_028818_PA_CL_VTE_CNTL
,
3305 S_028818_VTX_W0_FMT(1) |
3306 S_028818_VPORT_X_SCALE_ENA(1) | S_028818_VPORT_X_OFFSET_ENA(1) |
3307 S_028818_VPORT_Y_SCALE_ENA(1) | S_028818_VPORT_Y_OFFSET_ENA(1) |
3308 S_028818_VPORT_Z_SCALE_ENA(1) | S_028818_VPORT_Z_OFFSET_ENA(1));
3311 r600_store_context_reg(cb
, R_02885C_SQ_PGM_START_VS
,
3312 shader
->bo
->gpu_address
>> 8);
3313 /* After that, the NOP relocation packet must be emitted (shader->bo, RADEON_USAGE_READ). */
3315 shader
->pa_cl_vs_out_cntl
=
3316 S_02881C_VS_OUT_CCDIST0_VEC_ENA((rshader
->clip_dist_write
& 0x0F) != 0) |
3317 S_02881C_VS_OUT_CCDIST1_VEC_ENA((rshader
->clip_dist_write
& 0xF0) != 0) |
3318 S_02881C_VS_OUT_MISC_VEC_ENA(rshader
->vs_out_misc_write
) |
3319 S_02881C_USE_VTX_POINT_SIZE(rshader
->vs_out_point_size
) |
3320 S_02881C_USE_VTX_EDGE_FLAG(rshader
->vs_out_edgeflag
) |
3321 S_02881C_USE_VTX_VIEWPORT_INDX(rshader
->vs_out_viewport
) |
3322 S_02881C_USE_VTX_RENDER_TARGET_INDX(rshader
->vs_out_layer
);
3325 void evergreen_update_hs_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
3327 struct r600_command_buffer
*cb
= &shader
->command_buffer
;
3328 struct r600_shader
*rshader
= &shader
->shader
;
3330 r600_init_command_buffer(cb
, 32);
3331 r600_store_context_reg(cb
, R_0288BC_SQ_PGM_RESOURCES_HS
,
3332 S_0288BC_NUM_GPRS(rshader
->bc
.ngpr
) |
3333 S_0288BC_STACK_SIZE(rshader
->bc
.nstack
));
3334 r600_store_context_reg(cb
, R_0288B8_SQ_PGM_START_HS
,
3335 shader
->bo
->gpu_address
>> 8);
3338 void evergreen_update_ls_state(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
3340 struct r600_command_buffer
*cb
= &shader
->command_buffer
;
3341 struct r600_shader
*rshader
= &shader
->shader
;
3343 r600_init_command_buffer(cb
, 32);
3344 r600_store_context_reg(cb
, R_0288D4_SQ_PGM_RESOURCES_LS
,
3345 S_0288D4_NUM_GPRS(rshader
->bc
.ngpr
) |
3346 S_0288D4_STACK_SIZE(rshader
->bc
.nstack
));
3347 r600_store_context_reg(cb
, R_0288D0_SQ_PGM_START_LS
,
3348 shader
->bo
->gpu_address
>> 8);
3350 void *evergreen_create_resolve_blend(struct r600_context
*rctx
)
3352 struct pipe_blend_state blend
;
3354 memset(&blend
, 0, sizeof(blend
));
3355 blend
.independent_blend_enable
= true;
3356 blend
.rt
[0].colormask
= 0xf;
3357 return evergreen_create_blend_state_mode(&rctx
->b
.b
, &blend
, V_028808_CB_RESOLVE
);
3360 void *evergreen_create_decompress_blend(struct r600_context
*rctx
)
3362 struct pipe_blend_state blend
;
3363 unsigned mode
= rctx
->screen
->has_compressed_msaa_texturing
?
3364 V_028808_CB_FMASK_DECOMPRESS
: V_028808_CB_DECOMPRESS
;
3366 memset(&blend
, 0, sizeof(blend
));
3367 blend
.independent_blend_enable
= true;
3368 blend
.rt
[0].colormask
= 0xf;
3369 return evergreen_create_blend_state_mode(&rctx
->b
.b
, &blend
, mode
);
3372 void *evergreen_create_fastclear_blend(struct r600_context
*rctx
)
3374 struct pipe_blend_state blend
;
3375 unsigned mode
= V_028808_CB_ELIMINATE_FAST_CLEAR
;
3377 memset(&blend
, 0, sizeof(blend
));
3378 blend
.independent_blend_enable
= true;
3379 blend
.rt
[0].colormask
= 0xf;
3380 return evergreen_create_blend_state_mode(&rctx
->b
.b
, &blend
, mode
);
3383 void *evergreen_create_db_flush_dsa(struct r600_context
*rctx
)
3385 struct pipe_depth_stencil_alpha_state dsa
= {{0}};
3387 return rctx
->b
.b
.create_depth_stencil_alpha_state(&rctx
->b
.b
, &dsa
);
3390 void evergreen_update_db_shader_control(struct r600_context
* rctx
)
3393 unsigned db_shader_control
;
3395 if (!rctx
->ps_shader
) {
3399 dual_export
= rctx
->framebuffer
.export_16bpc
&&
3400 !rctx
->ps_shader
->current
->ps_depth_export
;
3402 db_shader_control
= rctx
->ps_shader
->current
->db_shader_control
|
3403 S_02880C_DUAL_EXPORT_ENABLE(dual_export
) |
3404 S_02880C_DB_SOURCE_FORMAT(dual_export
? V_02880C_EXPORT_DB_TWO
:
3405 V_02880C_EXPORT_DB_FULL
) |
3406 S_02880C_ALPHA_TO_MASK_DISABLE(rctx
->framebuffer
.cb0_is_integer
);
3408 /* When alpha test is enabled we can't trust the hw to make the proper
3409 * decision on the order in which ztest should be run related to fragment
3412 * If alpha test is enabled perform early z rejection (RE_Z) but don't early
3413 * write to the zbuffer. Write to zbuffer is delayed after fragment shader
3414 * execution and thus after alpha test so if discarded by the alpha test
3415 * the z value is not written.
3416 * If ReZ is enabled, and the zfunc/zenable/zwrite values change you can
3417 * get a hang unless you flush the DB in between. For now just use
3420 if (rctx
->alphatest_state
.sx_alpha_test_control
) {
3421 db_shader_control
|= S_02880C_Z_ORDER(V_02880C_LATE_Z
);
3423 db_shader_control
|= S_02880C_Z_ORDER(V_02880C_EARLY_Z_THEN_LATE_Z
);
3426 if (db_shader_control
!= rctx
->db_misc_state
.db_shader_control
) {
3427 rctx
->db_misc_state
.db_shader_control
= db_shader_control
;
3428 r600_mark_atom_dirty(rctx
, &rctx
->db_misc_state
.atom
);
3432 static void evergreen_dma_copy_tile(struct r600_context
*rctx
,
3433 struct pipe_resource
*dst
,
3438 struct pipe_resource
*src
,
3443 unsigned copy_height
,
3447 struct radeon_winsys_cs
*cs
= rctx
->b
.dma
.cs
;
3448 struct r600_texture
*rsrc
= (struct r600_texture
*)src
;
3449 struct r600_texture
*rdst
= (struct r600_texture
*)dst
;
3450 unsigned array_mode
, lbpp
, pitch_tile_max
, slice_tile_max
, size
;
3451 unsigned ncopy
, height
, cheight
, detile
, i
, x
, y
, z
, src_mode
, dst_mode
;
3452 unsigned sub_cmd
, bank_h
, bank_w
, mt_aspect
, nbanks
, tile_split
, non_disp_tiling
= 0;
3453 uint64_t base
, addr
;
3455 dst_mode
= rdst
->surface
.level
[dst_level
].mode
;
3456 src_mode
= rsrc
->surface
.level
[src_level
].mode
;
3457 /* downcast linear aligned to linear to simplify test */
3458 src_mode
= src_mode
== RADEON_SURF_MODE_LINEAR_ALIGNED
? RADEON_SURF_MODE_LINEAR
: src_mode
;
3459 dst_mode
= dst_mode
== RADEON_SURF_MODE_LINEAR_ALIGNED
? RADEON_SURF_MODE_LINEAR
: dst_mode
;
3460 assert(dst_mode
!= src_mode
);
3462 /* non_disp_tiling bit needs to be set for depth, stencil, and fmask surfaces */
3463 if (util_format_has_depth(util_format_description(src
->format
)))
3464 non_disp_tiling
= 1;
3467 sub_cmd
= EG_DMA_COPY_TILED
;
3468 lbpp
= util_logbase2(bpp
);
3469 pitch_tile_max
= ((pitch
/ bpp
) / 8) - 1;
3470 nbanks
= eg_num_banks(rctx
->screen
->b
.tiling_info
.num_banks
);
3472 if (dst_mode
== RADEON_SURF_MODE_LINEAR
) {
3474 array_mode
= evergreen_array_mode(src_mode
);
3475 slice_tile_max
= (rsrc
->surface
.level
[src_level
].nblk_x
* rsrc
->surface
.level
[src_level
].nblk_y
) / (8*8);
3476 slice_tile_max
= slice_tile_max
? slice_tile_max
- 1 : 0;
3477 /* linear height must be the same as the slice tile max height, it's ok even
3478 * if the linear destination/source have smaller heigh as the size of the
3479 * dma packet will be using the copy_height which is always smaller or equal
3480 * to the linear height
3482 height
= rsrc
->surface
.level
[src_level
].npix_y
;
3487 base
= rsrc
->surface
.level
[src_level
].offset
;
3488 addr
= rdst
->surface
.level
[dst_level
].offset
;
3489 addr
+= rdst
->surface
.level
[dst_level
].slice_size
* dst_z
;
3490 addr
+= dst_y
* pitch
+ dst_x
* bpp
;
3491 bank_h
= eg_bank_wh(rsrc
->surface
.bankh
);
3492 bank_w
= eg_bank_wh(rsrc
->surface
.bankw
);
3493 mt_aspect
= eg_macro_tile_aspect(rsrc
->surface
.mtilea
);
3494 tile_split
= eg_tile_split(rsrc
->surface
.tile_split
);
3495 base
+= rsrc
->resource
.gpu_address
;
3496 addr
+= rdst
->resource
.gpu_address
;
3499 array_mode
= evergreen_array_mode(dst_mode
);
3500 slice_tile_max
= (rdst
->surface
.level
[dst_level
].nblk_x
* rdst
->surface
.level
[dst_level
].nblk_y
) / (8*8);
3501 slice_tile_max
= slice_tile_max
? slice_tile_max
- 1 : 0;
3502 /* linear height must be the same as the slice tile max height, it's ok even
3503 * if the linear destination/source have smaller heigh as the size of the
3504 * dma packet will be using the copy_height which is always smaller or equal
3505 * to the linear height
3507 height
= rdst
->surface
.level
[dst_level
].npix_y
;
3512 base
= rdst
->surface
.level
[dst_level
].offset
;
3513 addr
= rsrc
->surface
.level
[src_level
].offset
;
3514 addr
+= rsrc
->surface
.level
[src_level
].slice_size
* src_z
;
3515 addr
+= src_y
* pitch
+ src_x
* bpp
;
3516 bank_h
= eg_bank_wh(rdst
->surface
.bankh
);
3517 bank_w
= eg_bank_wh(rdst
->surface
.bankw
);
3518 mt_aspect
= eg_macro_tile_aspect(rdst
->surface
.mtilea
);
3519 tile_split
= eg_tile_split(rdst
->surface
.tile_split
);
3520 base
+= rdst
->resource
.gpu_address
;
3521 addr
+= rsrc
->resource
.gpu_address
;
3524 size
= (copy_height
* pitch
) / 4;
3525 ncopy
= (size
/ EG_DMA_COPY_MAX_SIZE
) + !!(size
% EG_DMA_COPY_MAX_SIZE
);
3526 r600_need_dma_space(&rctx
->b
, ncopy
* 9);
3528 for (i
= 0; i
< ncopy
; i
++) {
3529 cheight
= copy_height
;
3530 if (((cheight
* pitch
) / 4) > EG_DMA_COPY_MAX_SIZE
) {
3531 cheight
= (EG_DMA_COPY_MAX_SIZE
* 4) / pitch
;
3533 size
= (cheight
* pitch
) / 4;
3534 /* emit reloc before writing cs so that cs is always in consistent state */
3535 radeon_add_to_buffer_list(&rctx
->b
, &rctx
->b
.dma
, &rsrc
->resource
,
3536 RADEON_USAGE_READ
, RADEON_PRIO_SDMA_TEXTURE
);
3537 radeon_add_to_buffer_list(&rctx
->b
, &rctx
->b
.dma
, &rdst
->resource
,
3538 RADEON_USAGE_WRITE
, RADEON_PRIO_SDMA_TEXTURE
);
3539 cs
->buf
[cs
->cdw
++] = DMA_PACKET(DMA_PACKET_COPY
, sub_cmd
, size
);
3540 cs
->buf
[cs
->cdw
++] = base
>> 8;
3541 cs
->buf
[cs
->cdw
++] = (detile
<< 31) | (array_mode
<< 27) |
3542 (lbpp
<< 24) | (bank_h
<< 21) |
3543 (bank_w
<< 18) | (mt_aspect
<< 16);
3544 cs
->buf
[cs
->cdw
++] = (pitch_tile_max
<< 0) | ((height
- 1) << 16);
3545 cs
->buf
[cs
->cdw
++] = (slice_tile_max
<< 0);
3546 cs
->buf
[cs
->cdw
++] = (x
<< 0) | (z
<< 18);
3547 cs
->buf
[cs
->cdw
++] = (y
<< 0) | (tile_split
<< 21) | (nbanks
<< 25) | (non_disp_tiling
<< 28);
3548 cs
->buf
[cs
->cdw
++] = addr
& 0xfffffffc;
3549 cs
->buf
[cs
->cdw
++] = (addr
>> 32UL) & 0xff;
3550 copy_height
-= cheight
;
3551 addr
+= cheight
* pitch
;
3556 static void evergreen_dma_copy(struct pipe_context
*ctx
,
3557 struct pipe_resource
*dst
,
3559 unsigned dstx
, unsigned dsty
, unsigned dstz
,
3560 struct pipe_resource
*src
,
3562 const struct pipe_box
*src_box
)
3564 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
3565 struct r600_texture
*rsrc
= (struct r600_texture
*)src
;
3566 struct r600_texture
*rdst
= (struct r600_texture
*)dst
;
3567 unsigned dst_pitch
, src_pitch
, bpp
, dst_mode
, src_mode
, copy_height
;
3568 unsigned src_w
, dst_w
;
3569 unsigned src_x
, src_y
;
3570 unsigned dst_x
= dstx
, dst_y
= dsty
, dst_z
= dstz
;
3572 if (rctx
->b
.dma
.cs
== NULL
) {
3576 if (dst
->target
== PIPE_BUFFER
&& src
->target
== PIPE_BUFFER
) {
3577 evergreen_dma_copy_buffer(rctx
, dst
, src
, dst_x
, src_box
->x
, src_box
->width
);
3581 if (src
->format
!= dst
->format
|| src_box
->depth
> 1 ||
3582 (rdst
->dirty_level_mask
| rdst
->stencil_dirty_level_mask
) & (1 << dst_level
)) {
3586 if (rsrc
->dirty_level_mask
& (1 << src_level
)) {
3587 ctx
->flush_resource(ctx
, src
);
3590 src_x
= util_format_get_nblocksx(src
->format
, src_box
->x
);
3591 dst_x
= util_format_get_nblocksx(src
->format
, dst_x
);
3592 src_y
= util_format_get_nblocksy(src
->format
, src_box
->y
);
3593 dst_y
= util_format_get_nblocksy(src
->format
, dst_y
);
3595 bpp
= rdst
->surface
.bpe
;
3596 dst_pitch
= rdst
->surface
.level
[dst_level
].pitch_bytes
;
3597 src_pitch
= rsrc
->surface
.level
[src_level
].pitch_bytes
;
3598 src_w
= rsrc
->surface
.level
[src_level
].npix_x
;
3599 dst_w
= rdst
->surface
.level
[dst_level
].npix_x
;
3600 copy_height
= src_box
->height
/ rsrc
->surface
.blk_h
;
3602 dst_mode
= rdst
->surface
.level
[dst_level
].mode
;
3603 src_mode
= rsrc
->surface
.level
[src_level
].mode
;
3604 /* downcast linear aligned to linear to simplify test */
3605 src_mode
= src_mode
== RADEON_SURF_MODE_LINEAR_ALIGNED
? RADEON_SURF_MODE_LINEAR
: src_mode
;
3606 dst_mode
= dst_mode
== RADEON_SURF_MODE_LINEAR_ALIGNED
? RADEON_SURF_MODE_LINEAR
: dst_mode
;
3608 if (src_pitch
!= dst_pitch
|| src_box
->x
|| dst_x
|| src_w
!= dst_w
) {
3609 /* FIXME evergreen can do partial blit */
3612 /* the x test here are currently useless (because we don't support partial blit)
3613 * but keep them around so we don't forget about those
3615 if (src_pitch
% 8 || src_box
->x
% 8 || dst_x
% 8 || src_box
->y
% 8 || dst_y
% 8) {
3619 /* 128 bpp surfaces require non_disp_tiling for both
3620 * tiled and linear buffers on cayman. However, async
3621 * DMA only supports it on the tiled side. As such
3622 * the tile order is backwards after a L2T/T2L packet.
3624 if ((rctx
->b
.chip_class
== CAYMAN
) &&
3625 (src_mode
!= dst_mode
) &&
3626 (util_format_get_blocksize(src
->format
) >= 16)) {
3630 if (src_mode
== dst_mode
) {
3631 uint64_t dst_offset
, src_offset
;
3632 /* simple dma blit would do NOTE code here assume :
3635 * dst_pitch == src_pitch
3637 src_offset
= rsrc
->surface
.level
[src_level
].offset
;
3638 src_offset
+= rsrc
->surface
.level
[src_level
].slice_size
* src_box
->z
;
3639 src_offset
+= src_y
* src_pitch
+ src_x
* bpp
;
3640 dst_offset
= rdst
->surface
.level
[dst_level
].offset
;
3641 dst_offset
+= rdst
->surface
.level
[dst_level
].slice_size
* dst_z
;
3642 dst_offset
+= dst_y
* dst_pitch
+ dst_x
* bpp
;
3643 evergreen_dma_copy_buffer(rctx
, dst
, src
, dst_offset
, src_offset
,
3644 src_box
->height
* src_pitch
);
3646 evergreen_dma_copy_tile(rctx
, dst
, dst_level
, dst_x
, dst_y
, dst_z
,
3647 src
, src_level
, src_x
, src_y
, src_box
->z
,
3648 copy_height
, dst_pitch
, bpp
);
3653 r600_resource_copy_region(ctx
, dst
, dst_level
, dstx
, dsty
, dstz
,
3654 src
, src_level
, src_box
);
3657 static void evergreen_set_tess_state(struct pipe_context
*ctx
,
3658 const float default_outer_level
[4],
3659 const float default_inner_level
[2])
3661 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
3663 memcpy(rctx
->tess_state
, default_outer_level
, sizeof(float) * 4);
3664 memcpy(rctx
->tess_state
+4, default_inner_level
, sizeof(float) * 2);
3665 rctx
->tess_state_dirty
= true;
3668 void evergreen_init_state_functions(struct r600_context
*rctx
)
3673 * To avoid GPU lockup registers must be emited in a specific order
3674 * (no kidding ...). The order below is important and have been
3675 * partialy infered from analyzing fglrx command stream.
3677 * Don't reorder atom without carefully checking the effect (GPU lockup
3678 * or piglit regression).
3681 if (rctx
->b
.chip_class
== EVERGREEN
) {
3682 r600_init_atom(rctx
, &rctx
->config_state
.atom
, id
++, evergreen_emit_config_state
, 11);
3683 if (rctx
->screen
->b
.info
.drm_minor
>= 7)
3684 rctx
->config_state
.dyn_gpr_enabled
= true;
3686 r600_init_atom(rctx
, &rctx
->framebuffer
.atom
, id
++, evergreen_emit_framebuffer_state
, 0);
3688 r600_init_atom(rctx
, &rctx
->constbuf_state
[PIPE_SHADER_VERTEX
].atom
, id
++, evergreen_emit_vs_constant_buffers
, 0);
3689 r600_init_atom(rctx
, &rctx
->constbuf_state
[PIPE_SHADER_GEOMETRY
].atom
, id
++, evergreen_emit_gs_constant_buffers
, 0);
3690 r600_init_atom(rctx
, &rctx
->constbuf_state
[PIPE_SHADER_FRAGMENT
].atom
, id
++, evergreen_emit_ps_constant_buffers
, 0);
3691 r600_init_atom(rctx
, &rctx
->constbuf_state
[PIPE_SHADER_TESS_CTRL
].atom
, id
++, evergreen_emit_tcs_constant_buffers
, 0);
3692 r600_init_atom(rctx
, &rctx
->constbuf_state
[PIPE_SHADER_TESS_EVAL
].atom
, id
++, evergreen_emit_tes_constant_buffers
, 0);
3693 r600_init_atom(rctx
, &rctx
->constbuf_state
[PIPE_SHADER_COMPUTE
].atom
, id
++, evergreen_emit_cs_constant_buffers
, 0);
3694 /* shader program */
3695 r600_init_atom(rctx
, &rctx
->cs_shader_state
.atom
, id
++, evergreen_emit_cs_shader
, 0);
3697 r600_init_atom(rctx
, &rctx
->samplers
[PIPE_SHADER_VERTEX
].states
.atom
, id
++, evergreen_emit_vs_sampler_states
, 0);
3698 r600_init_atom(rctx
, &rctx
->samplers
[PIPE_SHADER_GEOMETRY
].states
.atom
, id
++, evergreen_emit_gs_sampler_states
, 0);
3699 r600_init_atom(rctx
, &rctx
->samplers
[PIPE_SHADER_TESS_CTRL
].states
.atom
, id
++, evergreen_emit_tcs_sampler_states
, 0);
3700 r600_init_atom(rctx
, &rctx
->samplers
[PIPE_SHADER_TESS_EVAL
].states
.atom
, id
++, evergreen_emit_tes_sampler_states
, 0);
3701 r600_init_atom(rctx
, &rctx
->samplers
[PIPE_SHADER_FRAGMENT
].states
.atom
, id
++, evergreen_emit_ps_sampler_states
, 0);
3702 r600_init_atom(rctx
, &rctx
->samplers
[PIPE_SHADER_COMPUTE
].states
.atom
, id
++, evergreen_emit_cs_sampler_states
, 0);
3704 r600_init_atom(rctx
, &rctx
->vertex_buffer_state
.atom
, id
++, evergreen_fs_emit_vertex_buffers
, 0);
3705 r600_init_atom(rctx
, &rctx
->cs_vertex_buffer_state
.atom
, id
++, evergreen_cs_emit_vertex_buffers
, 0);
3706 r600_init_atom(rctx
, &rctx
->samplers
[PIPE_SHADER_VERTEX
].views
.atom
, id
++, evergreen_emit_vs_sampler_views
, 0);
3707 r600_init_atom(rctx
, &rctx
->samplers
[PIPE_SHADER_GEOMETRY
].views
.atom
, id
++, evergreen_emit_gs_sampler_views
, 0);
3708 r600_init_atom(rctx
, &rctx
->samplers
[PIPE_SHADER_TESS_CTRL
].views
.atom
, id
++, evergreen_emit_tcs_sampler_views
, 0);
3709 r600_init_atom(rctx
, &rctx
->samplers
[PIPE_SHADER_TESS_EVAL
].views
.atom
, id
++, evergreen_emit_tes_sampler_views
, 0);
3710 r600_init_atom(rctx
, &rctx
->samplers
[PIPE_SHADER_FRAGMENT
].views
.atom
, id
++, evergreen_emit_ps_sampler_views
, 0);
3711 r600_init_atom(rctx
, &rctx
->samplers
[PIPE_SHADER_COMPUTE
].views
.atom
, id
++, evergreen_emit_cs_sampler_views
, 0);
3713 r600_init_atom(rctx
, &rctx
->vgt_state
.atom
, id
++, r600_emit_vgt_state
, 10);
3715 if (rctx
->b
.chip_class
== EVERGREEN
) {
3716 r600_init_atom(rctx
, &rctx
->sample_mask
.atom
, id
++, evergreen_emit_sample_mask
, 3);
3718 r600_init_atom(rctx
, &rctx
->sample_mask
.atom
, id
++, cayman_emit_sample_mask
, 4);
3720 rctx
->sample_mask
.sample_mask
= ~0;
3722 r600_init_atom(rctx
, &rctx
->alphatest_state
.atom
, id
++, r600_emit_alphatest_state
, 6);
3723 r600_init_atom(rctx
, &rctx
->blend_color
.atom
, id
++, r600_emit_blend_color
, 6);
3724 r600_init_atom(rctx
, &rctx
->blend_state
.atom
, id
++, r600_emit_cso_state
, 0);
3725 r600_init_atom(rctx
, &rctx
->cb_misc_state
.atom
, id
++, evergreen_emit_cb_misc_state
, 4);
3726 r600_init_atom(rctx
, &rctx
->clip_misc_state
.atom
, id
++, r600_emit_clip_misc_state
, 9);
3727 r600_init_atom(rctx
, &rctx
->clip_state
.atom
, id
++, evergreen_emit_clip_state
, 26);
3728 r600_init_atom(rctx
, &rctx
->db_misc_state
.atom
, id
++, evergreen_emit_db_misc_state
, 10);
3729 r600_init_atom(rctx
, &rctx
->db_state
.atom
, id
++, evergreen_emit_db_state
, 14);
3730 r600_init_atom(rctx
, &rctx
->dsa_state
.atom
, id
++, r600_emit_cso_state
, 0);
3731 r600_init_atom(rctx
, &rctx
->poly_offset_state
.atom
, id
++, evergreen_emit_polygon_offset
, 6);
3732 r600_init_atom(rctx
, &rctx
->rasterizer_state
.atom
, id
++, r600_emit_cso_state
, 0);
3733 r600_init_atom(rctx
, &rctx
->scissor
.atom
, id
++, evergreen_emit_scissor_state
, 0);
3734 r600_init_atom(rctx
, &rctx
->viewport
.atom
, id
++, r600_emit_viewport_state
, 0);
3735 r600_init_atom(rctx
, &rctx
->stencil_ref
.atom
, id
++, r600_emit_stencil_ref
, 4);
3736 r600_init_atom(rctx
, &rctx
->vertex_fetch_shader
.atom
, id
++, evergreen_emit_vertex_fetch_shader
, 5);
3737 r600_add_atom(rctx
, &rctx
->b
.render_cond_atom
, id
++);
3738 r600_add_atom(rctx
, &rctx
->b
.streamout
.begin_atom
, id
++);
3739 r600_add_atom(rctx
, &rctx
->b
.streamout
.enable_atom
, id
++);
3740 for (i
= 0; i
< EG_NUM_HW_STAGES
; i
++)
3741 r600_init_atom(rctx
, &rctx
->hw_shader_stages
[i
].atom
, id
++, r600_emit_shader
, 0);
3742 r600_init_atom(rctx
, &rctx
->shader_stages
.atom
, id
++, evergreen_emit_shader_stages
, 15);
3743 r600_init_atom(rctx
, &rctx
->gs_rings
.atom
, id
++, evergreen_emit_gs_rings
, 26);
3745 rctx
->b
.b
.create_blend_state
= evergreen_create_blend_state
;
3746 rctx
->b
.b
.create_depth_stencil_alpha_state
= evergreen_create_dsa_state
;
3747 rctx
->b
.b
.create_rasterizer_state
= evergreen_create_rs_state
;
3748 rctx
->b
.b
.create_sampler_state
= evergreen_create_sampler_state
;
3749 rctx
->b
.b
.create_sampler_view
= evergreen_create_sampler_view
;
3750 rctx
->b
.b
.set_framebuffer_state
= evergreen_set_framebuffer_state
;
3751 rctx
->b
.b
.set_polygon_stipple
= evergreen_set_polygon_stipple
;
3752 rctx
->b
.b
.set_min_samples
= evergreen_set_min_samples
;
3753 rctx
->b
.b
.set_scissor_states
= evergreen_set_scissor_states
;
3754 rctx
->b
.b
.set_tess_state
= evergreen_set_tess_state
;
3755 if (rctx
->b
.chip_class
== EVERGREEN
)
3756 rctx
->b
.b
.get_sample_position
= evergreen_get_sample_position
;
3758 rctx
->b
.b
.get_sample_position
= cayman_get_sample_position
;
3759 rctx
->b
.dma_copy
= evergreen_dma_copy
;
3761 evergreen_init_compute_state_functions(rctx
);
3765 * This calculates the LDS size for tessellation shaders (VS, TCS, TES).
3767 * The information about LDS and other non-compile-time parameters is then
3768 * written to the const buffer.
3770 * const buffer contains -
3771 * uint32_t input_patch_size
3772 * uint32_t input_vertex_size
3773 * uint32_t num_tcs_input_cp
3774 * uint32_t num_tcs_output_cp;
3775 * uint32_t output_patch_size
3776 * uint32_t output_vertex_size
3777 * uint32_t output_patch0_offset
3778 * uint32_t perpatch_output_offset
3779 * and the same constbuf is bound to LS/HS/VS(ES).
3781 void evergreen_setup_tess_constants(struct r600_context
*rctx
, const struct pipe_draw_info
*info
, unsigned *num_patches
)
3783 struct pipe_constant_buffer constbuf
= {0};
3784 struct r600_pipe_shader_selector
*tcs
= rctx
->tcs_shader
? rctx
->tcs_shader
: rctx
->tes_shader
;
3785 struct r600_pipe_shader_selector
*ls
= rctx
->vs_shader
;
3786 unsigned num_tcs_input_cp
= info
->vertices_per_patch
;
3787 unsigned num_tcs_outputs
;
3788 unsigned num_tcs_output_cp
;
3789 unsigned num_tcs_patch_outputs
;
3790 unsigned num_tcs_inputs
;
3791 unsigned input_vertex_size
, output_vertex_size
;
3792 unsigned input_patch_size
, pervertex_output_patch_size
, output_patch_size
;
3793 unsigned output_patch0_offset
, perpatch_output_offset
, lds_size
;
3794 uint32_t values
[16];
3796 unsigned num_pipes
= rctx
->screen
->b
.info
.r600_max_pipes
;
3797 unsigned wave_divisor
= (16 * num_pipes
);
3801 if (!rctx
->tes_shader
) {
3802 rctx
->lds_alloc
= 0;
3803 rctx
->b
.b
.set_constant_buffer(&rctx
->b
.b
, PIPE_SHADER_VERTEX
,
3804 R600_LDS_INFO_CONST_BUFFER
, NULL
);
3805 rctx
->b
.b
.set_constant_buffer(&rctx
->b
.b
, PIPE_SHADER_TESS_CTRL
,
3806 R600_LDS_INFO_CONST_BUFFER
, NULL
);
3807 rctx
->b
.b
.set_constant_buffer(&rctx
->b
.b
, PIPE_SHADER_TESS_EVAL
,
3808 R600_LDS_INFO_CONST_BUFFER
, NULL
);
3812 if (rctx
->lds_alloc
!= 0 &&
3813 rctx
->last_ls
== ls
&&
3814 !rctx
->tess_state_dirty
&&
3815 rctx
->last_num_tcs_input_cp
== num_tcs_input_cp
&&
3816 rctx
->last_tcs
== tcs
)
3819 num_tcs_inputs
= util_last_bit64(ls
->lds_outputs_written_mask
);
3821 if (rctx
->tcs_shader
) {
3822 num_tcs_outputs
= util_last_bit64(tcs
->lds_outputs_written_mask
);
3823 num_tcs_output_cp
= tcs
->info
.properties
[TGSI_PROPERTY_TCS_VERTICES_OUT
];
3824 num_tcs_patch_outputs
= util_last_bit64(tcs
->lds_patch_outputs_written_mask
);
3826 num_tcs_outputs
= num_tcs_inputs
;
3827 num_tcs_output_cp
= num_tcs_input_cp
;
3828 num_tcs_patch_outputs
= 2; /* TESSINNER + TESSOUTER */
3832 input_vertex_size
= num_tcs_inputs
* 16;
3833 output_vertex_size
= num_tcs_outputs
* 16;
3835 input_patch_size
= num_tcs_input_cp
* input_vertex_size
;
3837 pervertex_output_patch_size
= num_tcs_output_cp
* output_vertex_size
;
3838 output_patch_size
= pervertex_output_patch_size
+ num_tcs_patch_outputs
* 16;
3840 output_patch0_offset
= rctx
->tcs_shader
? input_patch_size
* *num_patches
: 0;
3841 perpatch_output_offset
= output_patch0_offset
+ pervertex_output_patch_size
;
3843 lds_size
= output_patch0_offset
+ output_patch_size
* *num_patches
;
3845 values
[0] = input_patch_size
;
3846 values
[1] = input_vertex_size
;
3847 values
[2] = num_tcs_input_cp
;
3848 values
[3] = num_tcs_output_cp
;
3850 values
[4] = output_patch_size
;
3851 values
[5] = output_vertex_size
;
3852 values
[6] = output_patch0_offset
;
3853 values
[7] = perpatch_output_offset
;
3855 /* docs say HS_NUM_WAVES - CEIL((LS_HS_CONFIG.NUM_PATCHES *
3856 LS_HS_CONFIG.HS_NUM_OUTPUT_CP) / (NUM_GOOD_PIPES * 16)) */
3857 num_waves
= ceilf((float)(*num_patches
* num_tcs_output_cp
) / (float)wave_divisor
);
3859 rctx
->lds_alloc
= (lds_size
| (num_waves
<< 14));
3861 memcpy(&values
[8], rctx
->tess_state
, 6 * sizeof(float));
3865 rctx
->tess_state_dirty
= false;
3867 rctx
->last_tcs
= tcs
;
3868 rctx
->last_num_tcs_input_cp
= num_tcs_input_cp
;
3870 constbuf
.user_buffer
= values
;
3871 constbuf
.buffer_size
= 16 * 4;
3873 rctx
->b
.b
.set_constant_buffer(&rctx
->b
.b
, PIPE_SHADER_VERTEX
,
3874 R600_LDS_INFO_CONST_BUFFER
, &constbuf
);
3875 rctx
->b
.b
.set_constant_buffer(&rctx
->b
.b
, PIPE_SHADER_TESS_CTRL
,
3876 R600_LDS_INFO_CONST_BUFFER
, &constbuf
);
3877 rctx
->b
.b
.set_constant_buffer(&rctx
->b
.b
, PIPE_SHADER_TESS_EVAL
,
3878 R600_LDS_INFO_CONST_BUFFER
, &constbuf
);
3879 pipe_resource_reference(&constbuf
.buffer
, NULL
);
3882 uint32_t evergreen_get_ls_hs_config(struct r600_context
*rctx
,
3883 const struct pipe_draw_info
*info
,
3884 unsigned num_patches
)
3886 unsigned num_output_cp
;
3888 if (!rctx
->tes_shader
)
3891 num_output_cp
= rctx
->tcs_shader
?
3892 rctx
->tcs_shader
->info
.properties
[TGSI_PROPERTY_TCS_VERTICES_OUT
] :
3893 info
->vertices_per_patch
;
3895 return S_028B58_NUM_PATCHES(num_patches
) |
3896 S_028B58_HS_NUM_INPUT_CP(info
->vertices_per_patch
) |
3897 S_028B58_HS_NUM_OUTPUT_CP(num_output_cp
);
3900 void evergreen_set_ls_hs_config(struct r600_context
*rctx
,
3901 struct radeon_winsys_cs
*cs
,
3902 uint32_t ls_hs_config
)
3904 radeon_set_context_reg(cs
, R_028B58_VGT_LS_HS_CONFIG
, ls_hs_config
);
3907 void evergreen_set_lds_alloc(struct r600_context
*rctx
,
3908 struct radeon_winsys_cs
*cs
,
3911 radeon_set_context_reg(cs
, R_0288E8_SQ_LDS_ALLOC
, lds_alloc
);
3914 /* on evergreen if you are running tessellation you need to disable dynamic
3915 GPRs to workaround a hardware bug.*/
3916 bool evergreen_adjust_gprs(struct r600_context
*rctx
)
3918 unsigned num_gprs
[EG_NUM_HW_STAGES
];
3919 unsigned def_gprs
[EG_NUM_HW_STAGES
];
3920 unsigned cur_gprs
[EG_NUM_HW_STAGES
];
3921 unsigned new_gprs
[EG_NUM_HW_STAGES
];
3922 unsigned def_num_clause_temp_gprs
= rctx
->r6xx_num_clause_temp_gprs
;
3925 unsigned total_gprs
;
3927 bool rework
= false, set_default
= false, set_dirty
= false;
3929 for (i
= 0; i
< EG_NUM_HW_STAGES
; i
++) {
3930 def_gprs
[i
] = rctx
->default_gprs
[i
];
3931 max_gprs
+= def_gprs
[i
];
3933 max_gprs
+= def_num_clause_temp_gprs
* 2;
3935 /* if we have no TESS and dyn gpr is enabled then do nothing. */
3936 if (!rctx
->hw_shader_stages
[EG_HW_STAGE_HS
].shader
|| rctx
->screen
->b
.info
.drm_minor
< 7) {
3937 if (rctx
->config_state
.dyn_gpr_enabled
)
3940 /* transition back to dyn gpr enabled state */
3941 rctx
->config_state
.dyn_gpr_enabled
= true;
3942 r600_mark_atom_dirty(rctx
, &rctx
->config_state
.atom
);
3943 rctx
->b
.flags
|= R600_CONTEXT_WAIT_3D_IDLE
;
3948 /* gather required shader gprs */
3949 for (i
= 0; i
< EG_NUM_HW_STAGES
; i
++) {
3950 if (rctx
->hw_shader_stages
[i
].shader
)
3951 num_gprs
[i
] = rctx
->hw_shader_stages
[i
].shader
->shader
.bc
.ngpr
;
3956 cur_gprs
[R600_HW_STAGE_PS
] = G_008C04_NUM_PS_GPRS(rctx
->config_state
.sq_gpr_resource_mgmt_1
);
3957 cur_gprs
[R600_HW_STAGE_VS
] = G_008C04_NUM_VS_GPRS(rctx
->config_state
.sq_gpr_resource_mgmt_1
);
3958 cur_gprs
[R600_HW_STAGE_GS
] = G_008C08_NUM_GS_GPRS(rctx
->config_state
.sq_gpr_resource_mgmt_2
);
3959 cur_gprs
[R600_HW_STAGE_ES
] = G_008C08_NUM_ES_GPRS(rctx
->config_state
.sq_gpr_resource_mgmt_2
);
3960 cur_gprs
[EG_HW_STAGE_LS
] = G_008C0C_NUM_LS_GPRS(rctx
->config_state
.sq_gpr_resource_mgmt_3
);
3961 cur_gprs
[EG_HW_STAGE_HS
] = G_008C0C_NUM_HS_GPRS(rctx
->config_state
.sq_gpr_resource_mgmt_3
);
3964 for (i
= 0; i
< EG_NUM_HW_STAGES
; i
++) {
3965 new_gprs
[i
] = num_gprs
[i
];
3966 total_gprs
+= num_gprs
[i
];
3969 if (total_gprs
> (max_gprs
- (2 * def_num_clause_temp_gprs
)))
3972 for (i
= 0; i
< EG_NUM_HW_STAGES
; i
++) {
3973 if (new_gprs
[i
] > cur_gprs
[i
]) {
3979 if (rctx
->config_state
.dyn_gpr_enabled
) {
3981 rctx
->config_state
.dyn_gpr_enabled
= false;
3986 for (i
= 0; i
< EG_NUM_HW_STAGES
; i
++) {
3987 if (new_gprs
[i
] > def_gprs
[i
])
3988 set_default
= false;
3992 for (i
= 0; i
< EG_NUM_HW_STAGES
; i
++) {
3993 new_gprs
[i
] = def_gprs
[i
];
3996 unsigned ps_value
= max_gprs
;
3998 ps_value
-= (def_num_clause_temp_gprs
* 2);
3999 for (i
= R600_HW_STAGE_VS
; i
< EG_NUM_HW_STAGES
; i
++)
4000 ps_value
-= new_gprs
[i
];
4002 new_gprs
[R600_HW_STAGE_PS
] = ps_value
;
4005 tmp
[0] = S_008C04_NUM_PS_GPRS(new_gprs
[R600_HW_STAGE_PS
]) |
4006 S_008C04_NUM_VS_GPRS(new_gprs
[R600_HW_STAGE_VS
]) |
4007 S_008C04_NUM_CLAUSE_TEMP_GPRS(def_num_clause_temp_gprs
);
4009 tmp
[1] = S_008C08_NUM_ES_GPRS(new_gprs
[R600_HW_STAGE_ES
]) |
4010 S_008C08_NUM_GS_GPRS(new_gprs
[R600_HW_STAGE_GS
]);
4012 tmp
[2] = S_008C0C_NUM_HS_GPRS(new_gprs
[EG_HW_STAGE_HS
]) |
4013 S_008C0C_NUM_LS_GPRS(new_gprs
[EG_HW_STAGE_LS
]);
4015 if (rctx
->config_state
.sq_gpr_resource_mgmt_1
!= tmp
[0] ||
4016 rctx
->config_state
.sq_gpr_resource_mgmt_2
!= tmp
[1] ||
4017 rctx
->config_state
.sq_gpr_resource_mgmt_3
!= tmp
[2]) {
4018 rctx
->config_state
.sq_gpr_resource_mgmt_1
= tmp
[0];
4019 rctx
->config_state
.sq_gpr_resource_mgmt_2
= tmp
[1];
4020 rctx
->config_state
.sq_gpr_resource_mgmt_3
= tmp
[2];
4027 r600_mark_atom_dirty(rctx
, &rctx
->config_state
.atom
);
4028 rctx
->b
.flags
|= R600_CONTEXT_WAIT_3D_IDLE
;