2 * Copyright 2012 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Christian König <christian.koenig@amd.com>
29 #include "radeon/r600_cs.h"
30 #include "radeon/r600_query.h"
32 #include "util/u_dual_blend.h"
33 #include "util/u_format.h"
34 #include "util/u_format_s3tc.h"
35 #include "util/u_memory.h"
36 #include "util/u_resource.h"
37 #include "util/u_upload_mgr.h"
39 /* Initialize an external atom (owned by ../radeon). */
41 si_init_external_atom(struct si_context
*sctx
, struct r600_atom
*atom
,
42 struct r600_atom
**list_elem
)
44 atom
->id
= list_elem
- sctx
->atoms
.array
;
48 /* Initialize an atom owned by radeonsi. */
49 void si_init_atom(struct si_context
*sctx
, struct r600_atom
*atom
,
50 struct r600_atom
**list_elem
,
51 void (*emit_func
)(struct si_context
*ctx
, struct r600_atom
*state
))
53 atom
->emit
= (void*)emit_func
;
54 atom
->id
= list_elem
- sctx
->atoms
.array
;
58 static unsigned si_map_swizzle(unsigned swizzle
)
62 return V_008F0C_SQ_SEL_Y
;
64 return V_008F0C_SQ_SEL_Z
;
66 return V_008F0C_SQ_SEL_W
;
68 return V_008F0C_SQ_SEL_0
;
70 return V_008F0C_SQ_SEL_1
;
71 default: /* PIPE_SWIZZLE_X */
72 return V_008F0C_SQ_SEL_X
;
76 static uint32_t S_FIXED(float value
, uint32_t frac_bits
)
78 return value
* (1 << frac_bits
);
81 /* 12.4 fixed-point */
82 static unsigned si_pack_float_12p4(float x
)
85 x
>= 4096 ? 0xffff : x
* 16;
89 * Inferred framebuffer and blender state.
91 * CB_TARGET_MASK is emitted here to avoid a hang with dual source blending
92 * if there is not enough PS outputs.
94 static void si_emit_cb_render_state(struct si_context
*sctx
, struct r600_atom
*atom
)
96 struct radeon_winsys_cs
*cs
= sctx
->b
.gfx
.cs
;
97 struct si_state_blend
*blend
= sctx
->queued
.named
.blend
;
98 /* CB_COLORn_INFO.FORMAT=INVALID should disable unbound colorbuffers,
99 * but you never know. */
100 uint32_t cb_target_mask
= sctx
->framebuffer
.colorbuf_enabled_4bit
;
104 cb_target_mask
&= blend
->cb_target_mask
;
106 /* Avoid a hang that happens when dual source blending is enabled
107 * but there is not enough color outputs. This is undefined behavior,
108 * so disable color writes completely.
110 * Reproducible with Unigine Heaven 4.0 and drirc missing.
112 if (blend
&& blend
->dual_src_blend
&&
113 sctx
->ps_shader
.cso
&&
114 (sctx
->ps_shader
.cso
->info
.colors_written
& 0x3) != 0x3)
117 radeon_set_context_reg(cs
, R_028238_CB_TARGET_MASK
, cb_target_mask
);
119 /* STONEY-specific register settings. */
120 if (sctx
->b
.family
== CHIP_STONEY
) {
121 unsigned spi_shader_col_format
=
122 sctx
->ps_shader
.cso
?
123 sctx
->ps_shader
.current
->key
.part
.ps
.epilog
.spi_shader_col_format
: 0;
124 unsigned sx_ps_downconvert
= 0;
125 unsigned sx_blend_opt_epsilon
= 0;
126 unsigned sx_blend_opt_control
= 0;
128 for (i
= 0; i
< sctx
->framebuffer
.state
.nr_cbufs
; i
++) {
129 struct r600_surface
*surf
=
130 (struct r600_surface
*)sctx
->framebuffer
.state
.cbufs
[i
];
131 unsigned format
, swap
, spi_format
, colormask
;
132 bool has_alpha
, has_rgb
;
137 format
= G_028C70_FORMAT(surf
->cb_color_info
);
138 swap
= G_028C70_COMP_SWAP(surf
->cb_color_info
);
139 spi_format
= (spi_shader_col_format
>> (i
* 4)) & 0xf;
140 colormask
= (cb_target_mask
>> (i
* 4)) & 0xf;
142 /* Set if RGB and A are present. */
143 has_alpha
= !G_028C74_FORCE_DST_ALPHA_1(surf
->cb_color_attrib
);
145 if (format
== V_028C70_COLOR_8
||
146 format
== V_028C70_COLOR_16
||
147 format
== V_028C70_COLOR_32
)
148 has_rgb
= !has_alpha
;
152 /* Check the colormask and export format. */
153 if (!(colormask
& (PIPE_MASK_RGBA
& ~PIPE_MASK_A
)))
155 if (!(colormask
& PIPE_MASK_A
))
158 if (spi_format
== V_028714_SPI_SHADER_ZERO
) {
163 /* Disable value checking for disabled channels. */
165 sx_blend_opt_control
|= S_02875C_MRT0_COLOR_OPT_DISABLE(1) << (i
* 4);
167 sx_blend_opt_control
|= S_02875C_MRT0_ALPHA_OPT_DISABLE(1) << (i
* 4);
169 /* Enable down-conversion for 32bpp and smaller formats. */
171 case V_028C70_COLOR_8
:
172 case V_028C70_COLOR_8_8
:
173 case V_028C70_COLOR_8_8_8_8
:
174 /* For 1 and 2-channel formats, use the superset thereof. */
175 if (spi_format
== V_028714_SPI_SHADER_FP16_ABGR
||
176 spi_format
== V_028714_SPI_SHADER_UINT16_ABGR
||
177 spi_format
== V_028714_SPI_SHADER_SINT16_ABGR
) {
178 sx_ps_downconvert
|= V_028754_SX_RT_EXPORT_8_8_8_8
<< (i
* 4);
179 sx_blend_opt_epsilon
|= V_028758_8BIT_FORMAT
<< (i
* 4);
183 case V_028C70_COLOR_5_6_5
:
184 if (spi_format
== V_028714_SPI_SHADER_FP16_ABGR
) {
185 sx_ps_downconvert
|= V_028754_SX_RT_EXPORT_5_6_5
<< (i
* 4);
186 sx_blend_opt_epsilon
|= V_028758_6BIT_FORMAT
<< (i
* 4);
190 case V_028C70_COLOR_1_5_5_5
:
191 if (spi_format
== V_028714_SPI_SHADER_FP16_ABGR
) {
192 sx_ps_downconvert
|= V_028754_SX_RT_EXPORT_1_5_5_5
<< (i
* 4);
193 sx_blend_opt_epsilon
|= V_028758_5BIT_FORMAT
<< (i
* 4);
197 case V_028C70_COLOR_4_4_4_4
:
198 if (spi_format
== V_028714_SPI_SHADER_FP16_ABGR
) {
199 sx_ps_downconvert
|= V_028754_SX_RT_EXPORT_4_4_4_4
<< (i
* 4);
200 sx_blend_opt_epsilon
|= V_028758_4BIT_FORMAT
<< (i
* 4);
204 case V_028C70_COLOR_32
:
205 if (swap
== V_0280A0_SWAP_STD
&&
206 spi_format
== V_028714_SPI_SHADER_32_R
)
207 sx_ps_downconvert
|= V_028754_SX_RT_EXPORT_32_R
<< (i
* 4);
208 else if (swap
== V_0280A0_SWAP_ALT_REV
&&
209 spi_format
== V_028714_SPI_SHADER_32_AR
)
210 sx_ps_downconvert
|= V_028754_SX_RT_EXPORT_32_A
<< (i
* 4);
213 case V_028C70_COLOR_16
:
214 case V_028C70_COLOR_16_16
:
215 /* For 1-channel formats, use the superset thereof. */
216 if (spi_format
== V_028714_SPI_SHADER_UNORM16_ABGR
||
217 spi_format
== V_028714_SPI_SHADER_SNORM16_ABGR
||
218 spi_format
== V_028714_SPI_SHADER_UINT16_ABGR
||
219 spi_format
== V_028714_SPI_SHADER_SINT16_ABGR
) {
220 if (swap
== V_0280A0_SWAP_STD
||
221 swap
== V_0280A0_SWAP_STD_REV
)
222 sx_ps_downconvert
|= V_028754_SX_RT_EXPORT_16_16_GR
<< (i
* 4);
224 sx_ps_downconvert
|= V_028754_SX_RT_EXPORT_16_16_AR
<< (i
* 4);
228 case V_028C70_COLOR_10_11_11
:
229 if (spi_format
== V_028714_SPI_SHADER_FP16_ABGR
) {
230 sx_ps_downconvert
|= V_028754_SX_RT_EXPORT_10_11_11
<< (i
* 4);
231 sx_blend_opt_epsilon
|= V_028758_11BIT_FORMAT
<< (i
* 4);
235 case V_028C70_COLOR_2_10_10_10
:
236 if (spi_format
== V_028714_SPI_SHADER_FP16_ABGR
) {
237 sx_ps_downconvert
|= V_028754_SX_RT_EXPORT_2_10_10_10
<< (i
* 4);
238 sx_blend_opt_epsilon
|= V_028758_10BIT_FORMAT
<< (i
* 4);
244 if (sctx
->screen
->b
.debug_flags
& DBG_NO_RB_PLUS
) {
245 sx_ps_downconvert
= 0;
246 sx_blend_opt_epsilon
= 0;
247 sx_blend_opt_control
= 0;
250 radeon_set_context_reg_seq(cs
, R_028754_SX_PS_DOWNCONVERT
, 3);
251 radeon_emit(cs
, sx_ps_downconvert
); /* R_028754_SX_PS_DOWNCONVERT */
252 radeon_emit(cs
, sx_blend_opt_epsilon
); /* R_028758_SX_BLEND_OPT_EPSILON */
253 radeon_emit(cs
, sx_blend_opt_control
); /* R_02875C_SX_BLEND_OPT_CONTROL */
261 static uint32_t si_translate_blend_function(int blend_func
)
263 switch (blend_func
) {
265 return V_028780_COMB_DST_PLUS_SRC
;
266 case PIPE_BLEND_SUBTRACT
:
267 return V_028780_COMB_SRC_MINUS_DST
;
268 case PIPE_BLEND_REVERSE_SUBTRACT
:
269 return V_028780_COMB_DST_MINUS_SRC
;
271 return V_028780_COMB_MIN_DST_SRC
;
273 return V_028780_COMB_MAX_DST_SRC
;
275 R600_ERR("Unknown blend function %d\n", blend_func
);
282 static uint32_t si_translate_blend_factor(int blend_fact
)
284 switch (blend_fact
) {
285 case PIPE_BLENDFACTOR_ONE
:
286 return V_028780_BLEND_ONE
;
287 case PIPE_BLENDFACTOR_SRC_COLOR
:
288 return V_028780_BLEND_SRC_COLOR
;
289 case PIPE_BLENDFACTOR_SRC_ALPHA
:
290 return V_028780_BLEND_SRC_ALPHA
;
291 case PIPE_BLENDFACTOR_DST_ALPHA
:
292 return V_028780_BLEND_DST_ALPHA
;
293 case PIPE_BLENDFACTOR_DST_COLOR
:
294 return V_028780_BLEND_DST_COLOR
;
295 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
296 return V_028780_BLEND_SRC_ALPHA_SATURATE
;
297 case PIPE_BLENDFACTOR_CONST_COLOR
:
298 return V_028780_BLEND_CONSTANT_COLOR
;
299 case PIPE_BLENDFACTOR_CONST_ALPHA
:
300 return V_028780_BLEND_CONSTANT_ALPHA
;
301 case PIPE_BLENDFACTOR_ZERO
:
302 return V_028780_BLEND_ZERO
;
303 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
304 return V_028780_BLEND_ONE_MINUS_SRC_COLOR
;
305 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
306 return V_028780_BLEND_ONE_MINUS_SRC_ALPHA
;
307 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
308 return V_028780_BLEND_ONE_MINUS_DST_ALPHA
;
309 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
310 return V_028780_BLEND_ONE_MINUS_DST_COLOR
;
311 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
312 return V_028780_BLEND_ONE_MINUS_CONSTANT_COLOR
;
313 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
314 return V_028780_BLEND_ONE_MINUS_CONSTANT_ALPHA
;
315 case PIPE_BLENDFACTOR_SRC1_COLOR
:
316 return V_028780_BLEND_SRC1_COLOR
;
317 case PIPE_BLENDFACTOR_SRC1_ALPHA
:
318 return V_028780_BLEND_SRC1_ALPHA
;
319 case PIPE_BLENDFACTOR_INV_SRC1_COLOR
:
320 return V_028780_BLEND_INV_SRC1_COLOR
;
321 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA
:
322 return V_028780_BLEND_INV_SRC1_ALPHA
;
324 R600_ERR("Bad blend factor %d not supported!\n", blend_fact
);
331 static uint32_t si_translate_blend_opt_function(int blend_func
)
333 switch (blend_func
) {
335 return V_028760_OPT_COMB_ADD
;
336 case PIPE_BLEND_SUBTRACT
:
337 return V_028760_OPT_COMB_SUBTRACT
;
338 case PIPE_BLEND_REVERSE_SUBTRACT
:
339 return V_028760_OPT_COMB_REVSUBTRACT
;
341 return V_028760_OPT_COMB_MIN
;
343 return V_028760_OPT_COMB_MAX
;
345 return V_028760_OPT_COMB_BLEND_DISABLED
;
349 static uint32_t si_translate_blend_opt_factor(int blend_fact
, bool is_alpha
)
351 switch (blend_fact
) {
352 case PIPE_BLENDFACTOR_ZERO
:
353 return V_028760_BLEND_OPT_PRESERVE_NONE_IGNORE_ALL
;
354 case PIPE_BLENDFACTOR_ONE
:
355 return V_028760_BLEND_OPT_PRESERVE_ALL_IGNORE_NONE
;
356 case PIPE_BLENDFACTOR_SRC_COLOR
:
357 return is_alpha
? V_028760_BLEND_OPT_PRESERVE_A1_IGNORE_A0
358 : V_028760_BLEND_OPT_PRESERVE_C1_IGNORE_C0
;
359 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
360 return is_alpha
? V_028760_BLEND_OPT_PRESERVE_A0_IGNORE_A1
361 : V_028760_BLEND_OPT_PRESERVE_C0_IGNORE_C1
;
362 case PIPE_BLENDFACTOR_SRC_ALPHA
:
363 return V_028760_BLEND_OPT_PRESERVE_A1_IGNORE_A0
;
364 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
365 return V_028760_BLEND_OPT_PRESERVE_A0_IGNORE_A1
;
366 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
367 return is_alpha
? V_028760_BLEND_OPT_PRESERVE_ALL_IGNORE_NONE
368 : V_028760_BLEND_OPT_PRESERVE_NONE_IGNORE_A0
;
370 return V_028760_BLEND_OPT_PRESERVE_NONE_IGNORE_NONE
;
375 * Get rid of DST in the blend factors by commuting the operands:
376 * func(src * DST, dst * 0) ---> func(src * 0, dst * SRC)
378 static void si_blend_remove_dst(unsigned *func
, unsigned *src_factor
,
379 unsigned *dst_factor
, unsigned expected_dst
,
380 unsigned replacement_src
)
382 if (*src_factor
== expected_dst
&&
383 *dst_factor
== PIPE_BLENDFACTOR_ZERO
) {
384 *src_factor
= PIPE_BLENDFACTOR_ZERO
;
385 *dst_factor
= replacement_src
;
387 /* Commuting the operands requires reversing subtractions. */
388 if (*func
== PIPE_BLEND_SUBTRACT
)
389 *func
= PIPE_BLEND_REVERSE_SUBTRACT
;
390 else if (*func
== PIPE_BLEND_REVERSE_SUBTRACT
)
391 *func
= PIPE_BLEND_SUBTRACT
;
395 static bool si_blend_factor_uses_dst(unsigned factor
)
397 return factor
== PIPE_BLENDFACTOR_DST_COLOR
||
398 factor
== PIPE_BLENDFACTOR_DST_ALPHA
||
399 factor
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
||
400 factor
== PIPE_BLENDFACTOR_INV_DST_ALPHA
||
401 factor
== PIPE_BLENDFACTOR_INV_DST_COLOR
;
404 static void *si_create_blend_state_mode(struct pipe_context
*ctx
,
405 const struct pipe_blend_state
*state
,
408 struct si_context
*sctx
= (struct si_context
*)ctx
;
409 struct si_state_blend
*blend
= CALLOC_STRUCT(si_state_blend
);
410 struct si_pm4_state
*pm4
= &blend
->pm4
;
411 uint32_t sx_mrt_blend_opt
[8] = {0};
412 uint32_t color_control
= 0;
417 blend
->alpha_to_coverage
= state
->alpha_to_coverage
;
418 blend
->alpha_to_one
= state
->alpha_to_one
;
419 blend
->dual_src_blend
= util_blend_state_is_dual(state
, 0);
421 if (state
->logicop_enable
) {
422 color_control
|= S_028808_ROP3(state
->logicop_func
| (state
->logicop_func
<< 4));
424 color_control
|= S_028808_ROP3(0xcc);
427 si_pm4_set_reg(pm4
, R_028B70_DB_ALPHA_TO_MASK
,
428 S_028B70_ALPHA_TO_MASK_ENABLE(state
->alpha_to_coverage
) |
429 S_028B70_ALPHA_TO_MASK_OFFSET0(2) |
430 S_028B70_ALPHA_TO_MASK_OFFSET1(2) |
431 S_028B70_ALPHA_TO_MASK_OFFSET2(2) |
432 S_028B70_ALPHA_TO_MASK_OFFSET3(2));
434 if (state
->alpha_to_coverage
)
435 blend
->need_src_alpha_4bit
|= 0xf;
437 blend
->cb_target_mask
= 0;
438 for (int i
= 0; i
< 8; i
++) {
439 /* state->rt entries > 0 only written if independent blending */
440 const int j
= state
->independent_blend_enable
? i
: 0;
442 unsigned eqRGB
= state
->rt
[j
].rgb_func
;
443 unsigned srcRGB
= state
->rt
[j
].rgb_src_factor
;
444 unsigned dstRGB
= state
->rt
[j
].rgb_dst_factor
;
445 unsigned eqA
= state
->rt
[j
].alpha_func
;
446 unsigned srcA
= state
->rt
[j
].alpha_src_factor
;
447 unsigned dstA
= state
->rt
[j
].alpha_dst_factor
;
449 unsigned srcRGB_opt
, dstRGB_opt
, srcA_opt
, dstA_opt
;
450 unsigned blend_cntl
= 0;
452 sx_mrt_blend_opt
[i
] =
453 S_028760_COLOR_COMB_FCN(V_028760_OPT_COMB_BLEND_DISABLED
) |
454 S_028760_ALPHA_COMB_FCN(V_028760_OPT_COMB_BLEND_DISABLED
);
456 /* Only set dual source blending for MRT0 to avoid a hang. */
457 if (i
>= 1 && blend
->dual_src_blend
) {
458 /* Vulkan does this for dual source blending. */
460 blend_cntl
|= S_028780_ENABLE(1);
462 si_pm4_set_reg(pm4
, R_028780_CB_BLEND0_CONTROL
+ i
* 4, blend_cntl
);
466 /* Only addition and subtraction equations are supported with
467 * dual source blending.
469 if (blend
->dual_src_blend
&&
470 (eqRGB
== PIPE_BLEND_MIN
|| eqRGB
== PIPE_BLEND_MAX
||
471 eqA
== PIPE_BLEND_MIN
|| eqA
== PIPE_BLEND_MAX
)) {
472 assert(!"Unsupported equation for dual source blending");
473 si_pm4_set_reg(pm4
, R_028780_CB_BLEND0_CONTROL
+ i
* 4, blend_cntl
);
477 /* cb_render_state will disable unused ones */
478 blend
->cb_target_mask
|= (unsigned)state
->rt
[j
].colormask
<< (4 * i
);
480 if (!state
->rt
[j
].colormask
|| !state
->rt
[j
].blend_enable
) {
481 si_pm4_set_reg(pm4
, R_028780_CB_BLEND0_CONTROL
+ i
* 4, blend_cntl
);
485 /* Blending optimizations for Stoney.
486 * These transformations don't change the behavior.
488 * First, get rid of DST in the blend factors:
489 * func(src * DST, dst * 0) ---> func(src * 0, dst * SRC)
491 si_blend_remove_dst(&eqRGB
, &srcRGB
, &dstRGB
,
492 PIPE_BLENDFACTOR_DST_COLOR
,
493 PIPE_BLENDFACTOR_SRC_COLOR
);
494 si_blend_remove_dst(&eqA
, &srcA
, &dstA
,
495 PIPE_BLENDFACTOR_DST_COLOR
,
496 PIPE_BLENDFACTOR_SRC_COLOR
);
497 si_blend_remove_dst(&eqA
, &srcA
, &dstA
,
498 PIPE_BLENDFACTOR_DST_ALPHA
,
499 PIPE_BLENDFACTOR_SRC_ALPHA
);
501 /* Look up the ideal settings from tables. */
502 srcRGB_opt
= si_translate_blend_opt_factor(srcRGB
, false);
503 dstRGB_opt
= si_translate_blend_opt_factor(dstRGB
, false);
504 srcA_opt
= si_translate_blend_opt_factor(srcA
, true);
505 dstA_opt
= si_translate_blend_opt_factor(dstA
, true);
507 /* Handle interdependencies. */
508 if (si_blend_factor_uses_dst(srcRGB
))
509 dstRGB_opt
= V_028760_BLEND_OPT_PRESERVE_NONE_IGNORE_NONE
;
510 if (si_blend_factor_uses_dst(srcA
))
511 dstA_opt
= V_028760_BLEND_OPT_PRESERVE_NONE_IGNORE_NONE
;
513 if (srcRGB
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
&&
514 (dstRGB
== PIPE_BLENDFACTOR_ZERO
||
515 dstRGB
== PIPE_BLENDFACTOR_SRC_ALPHA
||
516 dstRGB
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
))
517 dstRGB_opt
= V_028760_BLEND_OPT_PRESERVE_NONE_IGNORE_A0
;
519 /* Set the final value. */
520 sx_mrt_blend_opt
[i
] =
521 S_028760_COLOR_SRC_OPT(srcRGB_opt
) |
522 S_028760_COLOR_DST_OPT(dstRGB_opt
) |
523 S_028760_COLOR_COMB_FCN(si_translate_blend_opt_function(eqRGB
)) |
524 S_028760_ALPHA_SRC_OPT(srcA_opt
) |
525 S_028760_ALPHA_DST_OPT(dstA_opt
) |
526 S_028760_ALPHA_COMB_FCN(si_translate_blend_opt_function(eqA
));
528 /* Set blend state. */
529 blend_cntl
|= S_028780_ENABLE(1);
530 blend_cntl
|= S_028780_COLOR_COMB_FCN(si_translate_blend_function(eqRGB
));
531 blend_cntl
|= S_028780_COLOR_SRCBLEND(si_translate_blend_factor(srcRGB
));
532 blend_cntl
|= S_028780_COLOR_DESTBLEND(si_translate_blend_factor(dstRGB
));
534 if (srcA
!= srcRGB
|| dstA
!= dstRGB
|| eqA
!= eqRGB
) {
535 blend_cntl
|= S_028780_SEPARATE_ALPHA_BLEND(1);
536 blend_cntl
|= S_028780_ALPHA_COMB_FCN(si_translate_blend_function(eqA
));
537 blend_cntl
|= S_028780_ALPHA_SRCBLEND(si_translate_blend_factor(srcA
));
538 blend_cntl
|= S_028780_ALPHA_DESTBLEND(si_translate_blend_factor(dstA
));
540 si_pm4_set_reg(pm4
, R_028780_CB_BLEND0_CONTROL
+ i
* 4, blend_cntl
);
542 blend
->blend_enable_4bit
|= 0xfu
<< (i
* 4);
544 /* This is only important for formats without alpha. */
545 if (srcRGB
== PIPE_BLENDFACTOR_SRC_ALPHA
||
546 dstRGB
== PIPE_BLENDFACTOR_SRC_ALPHA
||
547 srcRGB
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
||
548 dstRGB
== PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
||
549 srcRGB
== PIPE_BLENDFACTOR_INV_SRC_ALPHA
||
550 dstRGB
== PIPE_BLENDFACTOR_INV_SRC_ALPHA
)
551 blend
->need_src_alpha_4bit
|= 0xfu
<< (i
* 4);
554 if (blend
->cb_target_mask
) {
555 color_control
|= S_028808_MODE(mode
);
557 color_control
|= S_028808_MODE(V_028808_CB_DISABLE
);
560 if (sctx
->b
.family
== CHIP_STONEY
) {
561 /* Disable RB+ blend optimizations for dual source blending.
564 if (blend
->dual_src_blend
) {
565 for (int i
= 0; i
< 8; i
++) {
566 sx_mrt_blend_opt
[i
] =
567 S_028760_COLOR_COMB_FCN(V_028760_OPT_COMB_NONE
) |
568 S_028760_ALPHA_COMB_FCN(V_028760_OPT_COMB_NONE
);
572 for (int i
= 0; i
< 8; i
++)
573 si_pm4_set_reg(pm4
, R_028760_SX_MRT0_BLEND_OPT
+ i
* 4,
574 sx_mrt_blend_opt
[i
]);
576 /* RB+ doesn't work with dual source blending, logic op, and RESOLVE. */
577 if (blend
->dual_src_blend
|| state
->logicop_enable
||
578 mode
== V_028808_CB_RESOLVE
)
579 color_control
|= S_028808_DISABLE_DUAL_QUAD(1);
582 si_pm4_set_reg(pm4
, R_028808_CB_COLOR_CONTROL
, color_control
);
586 static void *si_create_blend_state(struct pipe_context
*ctx
,
587 const struct pipe_blend_state
*state
)
589 return si_create_blend_state_mode(ctx
, state
, V_028808_CB_NORMAL
);
592 static void si_bind_blend_state(struct pipe_context
*ctx
, void *state
)
594 struct si_context
*sctx
= (struct si_context
*)ctx
;
595 si_pm4_bind_state(sctx
, blend
, (struct si_state_blend
*)state
);
596 si_mark_atom_dirty(sctx
, &sctx
->cb_render_state
);
597 sctx
->do_update_shaders
= true;
600 static void si_delete_blend_state(struct pipe_context
*ctx
, void *state
)
602 struct si_context
*sctx
= (struct si_context
*)ctx
;
603 si_pm4_delete_state(sctx
, blend
, (struct si_state_blend
*)state
);
606 static void si_set_blend_color(struct pipe_context
*ctx
,
607 const struct pipe_blend_color
*state
)
609 struct si_context
*sctx
= (struct si_context
*)ctx
;
611 if (memcmp(&sctx
->blend_color
.state
, state
, sizeof(*state
)) == 0)
614 sctx
->blend_color
.state
= *state
;
615 si_mark_atom_dirty(sctx
, &sctx
->blend_color
.atom
);
618 static void si_emit_blend_color(struct si_context
*sctx
, struct r600_atom
*atom
)
620 struct radeon_winsys_cs
*cs
= sctx
->b
.gfx
.cs
;
622 radeon_set_context_reg_seq(cs
, R_028414_CB_BLEND_RED
, 4);
623 radeon_emit_array(cs
, (uint32_t*)sctx
->blend_color
.state
.color
, 4);
630 static void si_set_clip_state(struct pipe_context
*ctx
,
631 const struct pipe_clip_state
*state
)
633 struct si_context
*sctx
= (struct si_context
*)ctx
;
634 struct pipe_constant_buffer cb
;
636 if (memcmp(&sctx
->clip_state
.state
, state
, sizeof(*state
)) == 0)
639 sctx
->clip_state
.state
= *state
;
640 si_mark_atom_dirty(sctx
, &sctx
->clip_state
.atom
);
643 cb
.user_buffer
= state
->ucp
;
644 cb
.buffer_offset
= 0;
645 cb
.buffer_size
= 4*4*8;
646 si_set_rw_buffer(sctx
, SI_VS_CONST_CLIP_PLANES
, &cb
);
647 pipe_resource_reference(&cb
.buffer
, NULL
);
650 static void si_emit_clip_state(struct si_context
*sctx
, struct r600_atom
*atom
)
652 struct radeon_winsys_cs
*cs
= sctx
->b
.gfx
.cs
;
654 radeon_set_context_reg_seq(cs
, R_0285BC_PA_CL_UCP_0_X
, 6*4);
655 radeon_emit_array(cs
, (uint32_t*)sctx
->clip_state
.state
.ucp
, 6*4);
658 #define SIX_BITS 0x3F
660 static void si_emit_clip_regs(struct si_context
*sctx
, struct r600_atom
*atom
)
662 struct radeon_winsys_cs
*cs
= sctx
->b
.gfx
.cs
;
663 struct si_shader
*vs
= si_get_vs_state(sctx
);
664 struct tgsi_shader_info
*info
= si_get_vs_info(sctx
);
665 struct si_state_rasterizer
*rs
= sctx
->queued
.named
.rasterizer
;
666 unsigned window_space
=
667 info
->properties
[TGSI_PROPERTY_VS_WINDOW_SPACE_POSITION
];
668 unsigned clipdist_mask
=
669 info
->writes_clipvertex
? SIX_BITS
: info
->clipdist_writemask
;
670 unsigned ucp_mask
= clipdist_mask
? 0 : rs
->clip_plane_enable
& SIX_BITS
;
671 unsigned culldist_mask
= info
->culldist_writemask
<< info
->num_written_clipdistance
;
675 if (vs
->key
.opt
.hw_vs
.clip_disable
) {
676 assert(!info
->culldist_writemask
);
680 total_mask
= clipdist_mask
| culldist_mask
;
682 /* Clip distances on points have no effect, so need to be implemented
683 * as cull distances. This applies for the clipvertex case as well.
685 * Setting this for primitives other than points should have no adverse
688 clipdist_mask
&= rs
->clip_plane_enable
;
689 culldist_mask
|= clipdist_mask
;
691 misc_vec_ena
= info
->writes_psize
|| info
->writes_edgeflag
||
692 info
->writes_layer
|| info
->writes_viewport_index
;
694 radeon_set_context_reg(cs
, R_02881C_PA_CL_VS_OUT_CNTL
,
695 S_02881C_USE_VTX_POINT_SIZE(info
->writes_psize
) |
696 S_02881C_USE_VTX_EDGE_FLAG(info
->writes_edgeflag
) |
697 S_02881C_USE_VTX_RENDER_TARGET_INDX(info
->writes_layer
) |
698 S_02881C_USE_VTX_VIEWPORT_INDX(info
->writes_viewport_index
) |
699 S_02881C_VS_OUT_CCDIST0_VEC_ENA((total_mask
& 0x0F) != 0) |
700 S_02881C_VS_OUT_CCDIST1_VEC_ENA((total_mask
& 0xF0) != 0) |
701 S_02881C_VS_OUT_MISC_VEC_ENA(misc_vec_ena
) |
702 S_02881C_VS_OUT_MISC_SIDE_BUS_ENA(misc_vec_ena
) |
703 clipdist_mask
| (culldist_mask
<< 8));
704 radeon_set_context_reg(cs
, R_028810_PA_CL_CLIP_CNTL
,
705 rs
->pa_cl_clip_cntl
|
707 S_028810_CLIP_DISABLE(window_space
));
709 /* reuse needs to be set off if we write oViewport */
710 radeon_set_context_reg(cs
, R_028AB4_VGT_REUSE_OFF
,
711 S_028AB4_REUSE_OFF(info
->writes_viewport_index
));
715 * inferred state between framebuffer and rasterizer
717 static void si_update_poly_offset_state(struct si_context
*sctx
)
719 struct si_state_rasterizer
*rs
= sctx
->queued
.named
.rasterizer
;
721 if (!rs
|| !rs
->uses_poly_offset
|| !sctx
->framebuffer
.state
.zsbuf
) {
722 si_pm4_bind_state(sctx
, poly_offset
, NULL
);
726 /* Use the user format, not db_render_format, so that the polygon
727 * offset behaves as expected by applications.
729 switch (sctx
->framebuffer
.state
.zsbuf
->texture
->format
) {
730 case PIPE_FORMAT_Z16_UNORM
:
731 si_pm4_bind_state(sctx
, poly_offset
, &rs
->pm4_poly_offset
[0]);
733 default: /* 24-bit */
734 si_pm4_bind_state(sctx
, poly_offset
, &rs
->pm4_poly_offset
[1]);
736 case PIPE_FORMAT_Z32_FLOAT
:
737 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
738 si_pm4_bind_state(sctx
, poly_offset
, &rs
->pm4_poly_offset
[2]);
747 static uint32_t si_translate_fill(uint32_t func
)
750 case PIPE_POLYGON_MODE_FILL
:
751 return V_028814_X_DRAW_TRIANGLES
;
752 case PIPE_POLYGON_MODE_LINE
:
753 return V_028814_X_DRAW_LINES
;
754 case PIPE_POLYGON_MODE_POINT
:
755 return V_028814_X_DRAW_POINTS
;
758 return V_028814_X_DRAW_POINTS
;
762 static void *si_create_rs_state(struct pipe_context
*ctx
,
763 const struct pipe_rasterizer_state
*state
)
765 struct si_state_rasterizer
*rs
= CALLOC_STRUCT(si_state_rasterizer
);
766 struct si_pm4_state
*pm4
= &rs
->pm4
;
768 float psize_min
, psize_max
;
774 rs
->scissor_enable
= state
->scissor
;
775 rs
->clip_halfz
= state
->clip_halfz
;
776 rs
->two_side
= state
->light_twoside
;
777 rs
->multisample_enable
= state
->multisample
;
778 rs
->force_persample_interp
= state
->force_persample_interp
;
779 rs
->clip_plane_enable
= state
->clip_plane_enable
;
780 rs
->line_stipple_enable
= state
->line_stipple_enable
;
781 rs
->poly_stipple_enable
= state
->poly_stipple_enable
;
782 rs
->line_smooth
= state
->line_smooth
;
783 rs
->poly_smooth
= state
->poly_smooth
;
784 rs
->uses_poly_offset
= state
->offset_point
|| state
->offset_line
||
786 rs
->clamp_fragment_color
= state
->clamp_fragment_color
;
787 rs
->flatshade
= state
->flatshade
;
788 rs
->sprite_coord_enable
= state
->sprite_coord_enable
;
789 rs
->rasterizer_discard
= state
->rasterizer_discard
;
790 rs
->pa_sc_line_stipple
= state
->line_stipple_enable
?
791 S_028A0C_LINE_PATTERN(state
->line_stipple_pattern
) |
792 S_028A0C_REPEAT_COUNT(state
->line_stipple_factor
) : 0;
793 rs
->pa_cl_clip_cntl
=
794 S_028810_DX_CLIP_SPACE_DEF(state
->clip_halfz
) |
795 S_028810_ZCLIP_NEAR_DISABLE(!state
->depth_clip
) |
796 S_028810_ZCLIP_FAR_DISABLE(!state
->depth_clip
) |
797 S_028810_DX_RASTERIZATION_KILL(state
->rasterizer_discard
) |
798 S_028810_DX_LINEAR_ATTR_CLIP_ENA(1);
800 si_pm4_set_reg(pm4
, R_0286D4_SPI_INTERP_CONTROL_0
,
801 S_0286D4_FLAT_SHADE_ENA(1) |
802 S_0286D4_PNT_SPRITE_ENA(1) |
803 S_0286D4_PNT_SPRITE_OVRD_X(V_0286D4_SPI_PNT_SPRITE_SEL_S
) |
804 S_0286D4_PNT_SPRITE_OVRD_Y(V_0286D4_SPI_PNT_SPRITE_SEL_T
) |
805 S_0286D4_PNT_SPRITE_OVRD_Z(V_0286D4_SPI_PNT_SPRITE_SEL_0
) |
806 S_0286D4_PNT_SPRITE_OVRD_W(V_0286D4_SPI_PNT_SPRITE_SEL_1
) |
807 S_0286D4_PNT_SPRITE_TOP_1(state
->sprite_coord_mode
!= PIPE_SPRITE_COORD_UPPER_LEFT
));
809 /* point size 12.4 fixed point */
810 tmp
= (unsigned)(state
->point_size
* 8.0);
811 si_pm4_set_reg(pm4
, R_028A00_PA_SU_POINT_SIZE
, S_028A00_HEIGHT(tmp
) | S_028A00_WIDTH(tmp
));
813 if (state
->point_size_per_vertex
) {
814 psize_min
= util_get_min_point_size(state
);
817 /* Force the point size to be as if the vertex output was disabled. */
818 psize_min
= state
->point_size
;
819 psize_max
= state
->point_size
;
821 /* Divide by two, because 0.5 = 1 pixel. */
822 si_pm4_set_reg(pm4
, R_028A04_PA_SU_POINT_MINMAX
,
823 S_028A04_MIN_SIZE(si_pack_float_12p4(psize_min
/2)) |
824 S_028A04_MAX_SIZE(si_pack_float_12p4(psize_max
/2)));
826 tmp
= (unsigned)state
->line_width
* 8;
827 si_pm4_set_reg(pm4
, R_028A08_PA_SU_LINE_CNTL
, S_028A08_WIDTH(tmp
));
828 si_pm4_set_reg(pm4
, R_028A48_PA_SC_MODE_CNTL_0
,
829 S_028A48_LINE_STIPPLE_ENABLE(state
->line_stipple_enable
) |
830 S_028A48_MSAA_ENABLE(state
->multisample
||
831 state
->poly_smooth
||
832 state
->line_smooth
) |
833 S_028A48_VPORT_SCISSOR_ENABLE(1));
835 si_pm4_set_reg(pm4
, R_028BE4_PA_SU_VTX_CNTL
,
836 S_028BE4_PIX_CENTER(state
->half_pixel_center
) |
837 S_028BE4_QUANT_MODE(V_028BE4_X_16_8_FIXED_POINT_1_256TH
));
839 si_pm4_set_reg(pm4
, R_028B7C_PA_SU_POLY_OFFSET_CLAMP
, fui(state
->offset_clamp
));
840 si_pm4_set_reg(pm4
, R_028814_PA_SU_SC_MODE_CNTL
,
841 S_028814_PROVOKING_VTX_LAST(!state
->flatshade_first
) |
842 S_028814_CULL_FRONT((state
->cull_face
& PIPE_FACE_FRONT
) ? 1 : 0) |
843 S_028814_CULL_BACK((state
->cull_face
& PIPE_FACE_BACK
) ? 1 : 0) |
844 S_028814_FACE(!state
->front_ccw
) |
845 S_028814_POLY_OFFSET_FRONT_ENABLE(util_get_offset(state
, state
->fill_front
)) |
846 S_028814_POLY_OFFSET_BACK_ENABLE(util_get_offset(state
, state
->fill_back
)) |
847 S_028814_POLY_OFFSET_PARA_ENABLE(state
->offset_point
|| state
->offset_line
) |
848 S_028814_POLY_MODE(state
->fill_front
!= PIPE_POLYGON_MODE_FILL
||
849 state
->fill_back
!= PIPE_POLYGON_MODE_FILL
) |
850 S_028814_POLYMODE_FRONT_PTYPE(si_translate_fill(state
->fill_front
)) |
851 S_028814_POLYMODE_BACK_PTYPE(si_translate_fill(state
->fill_back
)));
852 si_pm4_set_reg(pm4
, R_00B130_SPI_SHADER_USER_DATA_VS_0
+
853 SI_SGPR_VS_STATE_BITS
* 4, state
->clamp_vertex_color
);
855 /* Precalculate polygon offset states for 16-bit, 24-bit, and 32-bit zbuffers. */
856 for (i
= 0; i
< 3; i
++) {
857 struct si_pm4_state
*pm4
= &rs
->pm4_poly_offset
[i
];
858 float offset_units
= state
->offset_units
;
859 float offset_scale
= state
->offset_scale
* 16.0f
;
860 uint32_t pa_su_poly_offset_db_fmt_cntl
= 0;
862 if (!state
->offset_units_unscaled
) {
864 case 0: /* 16-bit zbuffer */
865 offset_units
*= 4.0f
;
866 pa_su_poly_offset_db_fmt_cntl
=
867 S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-16);
869 case 1: /* 24-bit zbuffer */
870 offset_units
*= 2.0f
;
871 pa_su_poly_offset_db_fmt_cntl
=
872 S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-24);
874 case 2: /* 32-bit zbuffer */
875 offset_units
*= 1.0f
;
876 pa_su_poly_offset_db_fmt_cntl
= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(-23) |
877 S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
882 si_pm4_set_reg(pm4
, R_028B80_PA_SU_POLY_OFFSET_FRONT_SCALE
,
884 si_pm4_set_reg(pm4
, R_028B84_PA_SU_POLY_OFFSET_FRONT_OFFSET
,
886 si_pm4_set_reg(pm4
, R_028B88_PA_SU_POLY_OFFSET_BACK_SCALE
,
888 si_pm4_set_reg(pm4
, R_028B8C_PA_SU_POLY_OFFSET_BACK_OFFSET
,
890 si_pm4_set_reg(pm4
, R_028B78_PA_SU_POLY_OFFSET_DB_FMT_CNTL
,
891 pa_su_poly_offset_db_fmt_cntl
);
897 static void si_bind_rs_state(struct pipe_context
*ctx
, void *state
)
899 struct si_context
*sctx
= (struct si_context
*)ctx
;
900 struct si_state_rasterizer
*old_rs
=
901 (struct si_state_rasterizer
*)sctx
->queued
.named
.rasterizer
;
902 struct si_state_rasterizer
*rs
= (struct si_state_rasterizer
*)state
;
907 if (!old_rs
|| old_rs
->multisample_enable
!= rs
->multisample_enable
) {
908 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
910 /* Update the small primitive filter workaround if necessary. */
911 if (sctx
->b
.family
>= CHIP_POLARIS10
&&
912 sctx
->framebuffer
.nr_samples
> 1)
913 si_mark_atom_dirty(sctx
, &sctx
->msaa_sample_locs
.atom
);
916 r600_viewport_set_rast_deps(&sctx
->b
, rs
->scissor_enable
, rs
->clip_halfz
);
918 si_pm4_bind_state(sctx
, rasterizer
, rs
);
919 si_update_poly_offset_state(sctx
);
921 si_mark_atom_dirty(sctx
, &sctx
->clip_regs
);
922 sctx
->ia_multi_vgt_param_key
.u
.line_stipple_enabled
=
923 rs
->line_stipple_enable
;
924 sctx
->do_update_shaders
= true;
927 static void si_delete_rs_state(struct pipe_context
*ctx
, void *state
)
929 struct si_context
*sctx
= (struct si_context
*)ctx
;
931 if (sctx
->queued
.named
.rasterizer
== state
)
932 si_pm4_bind_state(sctx
, poly_offset
, NULL
);
933 si_pm4_delete_state(sctx
, rasterizer
, (struct si_state_rasterizer
*)state
);
937 * infeered state between dsa and stencil ref
939 static void si_emit_stencil_ref(struct si_context
*sctx
, struct r600_atom
*atom
)
941 struct radeon_winsys_cs
*cs
= sctx
->b
.gfx
.cs
;
942 struct pipe_stencil_ref
*ref
= &sctx
->stencil_ref
.state
;
943 struct si_dsa_stencil_ref_part
*dsa
= &sctx
->stencil_ref
.dsa_part
;
945 radeon_set_context_reg_seq(cs
, R_028430_DB_STENCILREFMASK
, 2);
946 radeon_emit(cs
, S_028430_STENCILTESTVAL(ref
->ref_value
[0]) |
947 S_028430_STENCILMASK(dsa
->valuemask
[0]) |
948 S_028430_STENCILWRITEMASK(dsa
->writemask
[0]) |
949 S_028430_STENCILOPVAL(1));
950 radeon_emit(cs
, S_028434_STENCILTESTVAL_BF(ref
->ref_value
[1]) |
951 S_028434_STENCILMASK_BF(dsa
->valuemask
[1]) |
952 S_028434_STENCILWRITEMASK_BF(dsa
->writemask
[1]) |
953 S_028434_STENCILOPVAL_BF(1));
956 static void si_set_stencil_ref(struct pipe_context
*ctx
,
957 const struct pipe_stencil_ref
*state
)
959 struct si_context
*sctx
= (struct si_context
*)ctx
;
961 if (memcmp(&sctx
->stencil_ref
.state
, state
, sizeof(*state
)) == 0)
964 sctx
->stencil_ref
.state
= *state
;
965 si_mark_atom_dirty(sctx
, &sctx
->stencil_ref
.atom
);
973 static uint32_t si_translate_stencil_op(int s_op
)
976 case PIPE_STENCIL_OP_KEEP
:
977 return V_02842C_STENCIL_KEEP
;
978 case PIPE_STENCIL_OP_ZERO
:
979 return V_02842C_STENCIL_ZERO
;
980 case PIPE_STENCIL_OP_REPLACE
:
981 return V_02842C_STENCIL_REPLACE_TEST
;
982 case PIPE_STENCIL_OP_INCR
:
983 return V_02842C_STENCIL_ADD_CLAMP
;
984 case PIPE_STENCIL_OP_DECR
:
985 return V_02842C_STENCIL_SUB_CLAMP
;
986 case PIPE_STENCIL_OP_INCR_WRAP
:
987 return V_02842C_STENCIL_ADD_WRAP
;
988 case PIPE_STENCIL_OP_DECR_WRAP
:
989 return V_02842C_STENCIL_SUB_WRAP
;
990 case PIPE_STENCIL_OP_INVERT
:
991 return V_02842C_STENCIL_INVERT
;
993 R600_ERR("Unknown stencil op %d", s_op
);
1000 static void *si_create_dsa_state(struct pipe_context
*ctx
,
1001 const struct pipe_depth_stencil_alpha_state
*state
)
1003 struct si_state_dsa
*dsa
= CALLOC_STRUCT(si_state_dsa
);
1004 struct si_pm4_state
*pm4
= &dsa
->pm4
;
1005 unsigned db_depth_control
;
1006 uint32_t db_stencil_control
= 0;
1012 dsa
->stencil_ref
.valuemask
[0] = state
->stencil
[0].valuemask
;
1013 dsa
->stencil_ref
.valuemask
[1] = state
->stencil
[1].valuemask
;
1014 dsa
->stencil_ref
.writemask
[0] = state
->stencil
[0].writemask
;
1015 dsa
->stencil_ref
.writemask
[1] = state
->stencil
[1].writemask
;
1017 db_depth_control
= S_028800_Z_ENABLE(state
->depth
.enabled
) |
1018 S_028800_Z_WRITE_ENABLE(state
->depth
.writemask
) |
1019 S_028800_ZFUNC(state
->depth
.func
) |
1020 S_028800_DEPTH_BOUNDS_ENABLE(state
->depth
.bounds_test
);
1023 if (state
->stencil
[0].enabled
) {
1024 db_depth_control
|= S_028800_STENCIL_ENABLE(1);
1025 db_depth_control
|= S_028800_STENCILFUNC(state
->stencil
[0].func
);
1026 db_stencil_control
|= S_02842C_STENCILFAIL(si_translate_stencil_op(state
->stencil
[0].fail_op
));
1027 db_stencil_control
|= S_02842C_STENCILZPASS(si_translate_stencil_op(state
->stencil
[0].zpass_op
));
1028 db_stencil_control
|= S_02842C_STENCILZFAIL(si_translate_stencil_op(state
->stencil
[0].zfail_op
));
1030 if (state
->stencil
[1].enabled
) {
1031 db_depth_control
|= S_028800_BACKFACE_ENABLE(1);
1032 db_depth_control
|= S_028800_STENCILFUNC_BF(state
->stencil
[1].func
);
1033 db_stencil_control
|= S_02842C_STENCILFAIL_BF(si_translate_stencil_op(state
->stencil
[1].fail_op
));
1034 db_stencil_control
|= S_02842C_STENCILZPASS_BF(si_translate_stencil_op(state
->stencil
[1].zpass_op
));
1035 db_stencil_control
|= S_02842C_STENCILZFAIL_BF(si_translate_stencil_op(state
->stencil
[1].zfail_op
));
1040 if (state
->alpha
.enabled
) {
1041 dsa
->alpha_func
= state
->alpha
.func
;
1043 si_pm4_set_reg(pm4
, R_00B030_SPI_SHADER_USER_DATA_PS_0
+
1044 SI_SGPR_ALPHA_REF
* 4, fui(state
->alpha
.ref_value
));
1046 dsa
->alpha_func
= PIPE_FUNC_ALWAYS
;
1049 si_pm4_set_reg(pm4
, R_028800_DB_DEPTH_CONTROL
, db_depth_control
);
1050 si_pm4_set_reg(pm4
, R_02842C_DB_STENCIL_CONTROL
, db_stencil_control
);
1051 if (state
->depth
.bounds_test
) {
1052 si_pm4_set_reg(pm4
, R_028020_DB_DEPTH_BOUNDS_MIN
, fui(state
->depth
.bounds_min
));
1053 si_pm4_set_reg(pm4
, R_028024_DB_DEPTH_BOUNDS_MAX
, fui(state
->depth
.bounds_max
));
1059 static void si_bind_dsa_state(struct pipe_context
*ctx
, void *state
)
1061 struct si_context
*sctx
= (struct si_context
*)ctx
;
1062 struct si_state_dsa
*dsa
= state
;
1067 si_pm4_bind_state(sctx
, dsa
, dsa
);
1069 if (memcmp(&dsa
->stencil_ref
, &sctx
->stencil_ref
.dsa_part
,
1070 sizeof(struct si_dsa_stencil_ref_part
)) != 0) {
1071 sctx
->stencil_ref
.dsa_part
= dsa
->stencil_ref
;
1072 si_mark_atom_dirty(sctx
, &sctx
->stencil_ref
.atom
);
1074 sctx
->do_update_shaders
= true;
1077 static void si_delete_dsa_state(struct pipe_context
*ctx
, void *state
)
1079 struct si_context
*sctx
= (struct si_context
*)ctx
;
1080 si_pm4_delete_state(sctx
, dsa
, (struct si_state_dsa
*)state
);
1083 static void *si_create_db_flush_dsa(struct si_context
*sctx
)
1085 struct pipe_depth_stencil_alpha_state dsa
= {};
1087 return sctx
->b
.b
.create_depth_stencil_alpha_state(&sctx
->b
.b
, &dsa
);
1090 /* DB RENDER STATE */
1092 static void si_set_active_query_state(struct pipe_context
*ctx
, boolean enable
)
1094 struct si_context
*sctx
= (struct si_context
*)ctx
;
1096 /* Pipeline stat & streamout queries. */
1098 sctx
->b
.flags
&= ~R600_CONTEXT_STOP_PIPELINE_STATS
;
1099 sctx
->b
.flags
|= R600_CONTEXT_START_PIPELINE_STATS
;
1101 sctx
->b
.flags
&= ~R600_CONTEXT_START_PIPELINE_STATS
;
1102 sctx
->b
.flags
|= R600_CONTEXT_STOP_PIPELINE_STATS
;
1105 /* Occlusion queries. */
1106 if (sctx
->occlusion_queries_disabled
!= !enable
) {
1107 sctx
->occlusion_queries_disabled
= !enable
;
1108 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
1112 static void si_set_occlusion_query_state(struct pipe_context
*ctx
, bool enable
)
1114 struct si_context
*sctx
= (struct si_context
*)ctx
;
1116 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
1119 static void si_save_qbo_state(struct pipe_context
*ctx
, struct r600_qbo_state
*st
)
1121 struct si_context
*sctx
= (struct si_context
*)ctx
;
1123 st
->saved_compute
= sctx
->cs_shader_state
.program
;
1125 si_get_pipe_constant_buffer(sctx
, PIPE_SHADER_COMPUTE
, 0, &st
->saved_const0
);
1126 si_get_shader_buffers(sctx
, PIPE_SHADER_COMPUTE
, 0, 3, st
->saved_ssbo
);
1129 static void si_emit_db_render_state(struct si_context
*sctx
, struct r600_atom
*state
)
1131 struct radeon_winsys_cs
*cs
= sctx
->b
.gfx
.cs
;
1132 struct si_state_rasterizer
*rs
= sctx
->queued
.named
.rasterizer
;
1133 unsigned db_shader_control
;
1135 radeon_set_context_reg_seq(cs
, R_028000_DB_RENDER_CONTROL
, 2);
1137 /* DB_RENDER_CONTROL */
1138 if (sctx
->dbcb_depth_copy_enabled
||
1139 sctx
->dbcb_stencil_copy_enabled
) {
1141 S_028000_DEPTH_COPY(sctx
->dbcb_depth_copy_enabled
) |
1142 S_028000_STENCIL_COPY(sctx
->dbcb_stencil_copy_enabled
) |
1143 S_028000_COPY_CENTROID(1) |
1144 S_028000_COPY_SAMPLE(sctx
->dbcb_copy_sample
));
1145 } else if (sctx
->db_flush_depth_inplace
|| sctx
->db_flush_stencil_inplace
) {
1147 S_028000_DEPTH_COMPRESS_DISABLE(sctx
->db_flush_depth_inplace
) |
1148 S_028000_STENCIL_COMPRESS_DISABLE(sctx
->db_flush_stencil_inplace
));
1151 S_028000_DEPTH_CLEAR_ENABLE(sctx
->db_depth_clear
) |
1152 S_028000_STENCIL_CLEAR_ENABLE(sctx
->db_stencil_clear
));
1155 /* DB_COUNT_CONTROL (occlusion queries) */
1156 if (sctx
->b
.num_occlusion_queries
> 0 &&
1157 !sctx
->occlusion_queries_disabled
) {
1158 bool perfect
= sctx
->b
.num_perfect_occlusion_queries
> 0;
1160 if (sctx
->b
.chip_class
>= CIK
) {
1162 S_028004_PERFECT_ZPASS_COUNTS(perfect
) |
1163 S_028004_SAMPLE_RATE(sctx
->framebuffer
.log_samples
) |
1164 S_028004_ZPASS_ENABLE(1) |
1165 S_028004_SLICE_EVEN_ENABLE(1) |
1166 S_028004_SLICE_ODD_ENABLE(1));
1169 S_028004_PERFECT_ZPASS_COUNTS(perfect
) |
1170 S_028004_SAMPLE_RATE(sctx
->framebuffer
.log_samples
));
1173 /* Disable occlusion queries. */
1174 if (sctx
->b
.chip_class
>= CIK
) {
1177 radeon_emit(cs
, S_028004_ZPASS_INCREMENT_DISABLE(1));
1181 /* DB_RENDER_OVERRIDE2 */
1182 radeon_set_context_reg(cs
, R_028010_DB_RENDER_OVERRIDE2
,
1183 S_028010_DISABLE_ZMASK_EXPCLEAR_OPTIMIZATION(sctx
->db_depth_disable_expclear
) |
1184 S_028010_DISABLE_SMEM_EXPCLEAR_OPTIMIZATION(sctx
->db_stencil_disable_expclear
) |
1185 S_028010_DECOMPRESS_Z_ON_FLUSH(sctx
->framebuffer
.nr_samples
>= 4));
1187 db_shader_control
= sctx
->ps_db_shader_control
;
1189 /* Bug workaround for smoothing (overrasterization) on SI. */
1190 if (sctx
->b
.chip_class
== SI
&& sctx
->smoothing_enabled
) {
1191 db_shader_control
&= C_02880C_Z_ORDER
;
1192 db_shader_control
|= S_02880C_Z_ORDER(V_02880C_LATE_Z
);
1195 /* Disable the gl_SampleMask fragment shader output if MSAA is disabled. */
1196 if (!rs
|| !rs
->multisample_enable
)
1197 db_shader_control
&= C_02880C_MASK_EXPORT_ENABLE
;
1199 if (sctx
->b
.family
== CHIP_STONEY
&&
1200 sctx
->screen
->b
.debug_flags
& DBG_NO_RB_PLUS
)
1201 db_shader_control
|= S_02880C_DUAL_QUAD_DISABLE(1);
1203 radeon_set_context_reg(cs
, R_02880C_DB_SHADER_CONTROL
,
1208 * format translation
1210 static uint32_t si_translate_colorformat(enum pipe_format format
)
1212 const struct util_format_description
*desc
= util_format_description(format
);
1214 #define HAS_SIZE(x,y,z,w) \
1215 (desc->channel[0].size == (x) && desc->channel[1].size == (y) && \
1216 desc->channel[2].size == (z) && desc->channel[3].size == (w))
1218 if (format
== PIPE_FORMAT_R11G11B10_FLOAT
) /* isn't plain */
1219 return V_028C70_COLOR_10_11_11
;
1221 if (desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
)
1222 return V_028C70_COLOR_INVALID
;
1224 /* hw cannot support mixed formats (except depth/stencil, since
1225 * stencil is not written to). */
1226 if (desc
->is_mixed
&& desc
->colorspace
!= UTIL_FORMAT_COLORSPACE_ZS
)
1227 return V_028C70_COLOR_INVALID
;
1229 switch (desc
->nr_channels
) {
1231 switch (desc
->channel
[0].size
) {
1233 return V_028C70_COLOR_8
;
1235 return V_028C70_COLOR_16
;
1237 return V_028C70_COLOR_32
;
1241 if (desc
->channel
[0].size
== desc
->channel
[1].size
) {
1242 switch (desc
->channel
[0].size
) {
1244 return V_028C70_COLOR_8_8
;
1246 return V_028C70_COLOR_16_16
;
1248 return V_028C70_COLOR_32_32
;
1250 } else if (HAS_SIZE(8,24,0,0)) {
1251 return V_028C70_COLOR_24_8
;
1252 } else if (HAS_SIZE(24,8,0,0)) {
1253 return V_028C70_COLOR_8_24
;
1257 if (HAS_SIZE(5,6,5,0)) {
1258 return V_028C70_COLOR_5_6_5
;
1259 } else if (HAS_SIZE(32,8,24,0)) {
1260 return V_028C70_COLOR_X24_8_32_FLOAT
;
1264 if (desc
->channel
[0].size
== desc
->channel
[1].size
&&
1265 desc
->channel
[0].size
== desc
->channel
[2].size
&&
1266 desc
->channel
[0].size
== desc
->channel
[3].size
) {
1267 switch (desc
->channel
[0].size
) {
1269 return V_028C70_COLOR_4_4_4_4
;
1271 return V_028C70_COLOR_8_8_8_8
;
1273 return V_028C70_COLOR_16_16_16_16
;
1275 return V_028C70_COLOR_32_32_32_32
;
1277 } else if (HAS_SIZE(5,5,5,1)) {
1278 return V_028C70_COLOR_1_5_5_5
;
1279 } else if (HAS_SIZE(10,10,10,2)) {
1280 return V_028C70_COLOR_2_10_10_10
;
1284 return V_028C70_COLOR_INVALID
;
1287 static uint32_t si_colorformat_endian_swap(uint32_t colorformat
)
1289 if (SI_BIG_ENDIAN
) {
1290 switch(colorformat
) {
1291 /* 8-bit buffers. */
1292 case V_028C70_COLOR_8
:
1293 return V_028C70_ENDIAN_NONE
;
1295 /* 16-bit buffers. */
1296 case V_028C70_COLOR_5_6_5
:
1297 case V_028C70_COLOR_1_5_5_5
:
1298 case V_028C70_COLOR_4_4_4_4
:
1299 case V_028C70_COLOR_16
:
1300 case V_028C70_COLOR_8_8
:
1301 return V_028C70_ENDIAN_8IN16
;
1303 /* 32-bit buffers. */
1304 case V_028C70_COLOR_8_8_8_8
:
1305 case V_028C70_COLOR_2_10_10_10
:
1306 case V_028C70_COLOR_8_24
:
1307 case V_028C70_COLOR_24_8
:
1308 case V_028C70_COLOR_16_16
:
1309 return V_028C70_ENDIAN_8IN32
;
1311 /* 64-bit buffers. */
1312 case V_028C70_COLOR_16_16_16_16
:
1313 return V_028C70_ENDIAN_8IN16
;
1315 case V_028C70_COLOR_32_32
:
1316 return V_028C70_ENDIAN_8IN32
;
1318 /* 128-bit buffers. */
1319 case V_028C70_COLOR_32_32_32_32
:
1320 return V_028C70_ENDIAN_8IN32
;
1322 return V_028C70_ENDIAN_NONE
; /* Unsupported. */
1325 return V_028C70_ENDIAN_NONE
;
1329 static uint32_t si_translate_dbformat(enum pipe_format format
)
1332 case PIPE_FORMAT_Z16_UNORM
:
1333 return V_028040_Z_16
;
1334 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
1335 case PIPE_FORMAT_X8Z24_UNORM
:
1336 case PIPE_FORMAT_Z24X8_UNORM
:
1337 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
1338 return V_028040_Z_24
; /* deprecated on SI */
1339 case PIPE_FORMAT_Z32_FLOAT
:
1340 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
1341 return V_028040_Z_32_FLOAT
;
1343 return V_028040_Z_INVALID
;
1348 * Texture translation
1351 static uint32_t si_translate_texformat(struct pipe_screen
*screen
,
1352 enum pipe_format format
,
1353 const struct util_format_description
*desc
,
1356 struct si_screen
*sscreen
= (struct si_screen
*)screen
;
1357 bool enable_compressed_formats
= (sscreen
->b
.info
.drm_major
== 2 &&
1358 sscreen
->b
.info
.drm_minor
>= 31) ||
1359 sscreen
->b
.info
.drm_major
== 3;
1360 bool uniform
= true;
1363 /* Colorspace (return non-RGB formats directly). */
1364 switch (desc
->colorspace
) {
1365 /* Depth stencil formats */
1366 case UTIL_FORMAT_COLORSPACE_ZS
:
1368 case PIPE_FORMAT_Z16_UNORM
:
1369 return V_008F14_IMG_DATA_FORMAT_16
;
1370 case PIPE_FORMAT_X24S8_UINT
:
1371 case PIPE_FORMAT_S8X24_UINT
:
1373 * Implemented as an 8_8_8_8 data format to fix texture
1374 * gathers in stencil sampling. This affects at least
1375 * GL45-CTS.texture_cube_map_array.sampling on VI.
1377 return V_008F14_IMG_DATA_FORMAT_8_8_8_8
;
1378 case PIPE_FORMAT_Z24X8_UNORM
:
1379 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
1380 return V_008F14_IMG_DATA_FORMAT_8_24
;
1381 case PIPE_FORMAT_X8Z24_UNORM
:
1382 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
1383 return V_008F14_IMG_DATA_FORMAT_24_8
;
1384 case PIPE_FORMAT_S8_UINT
:
1385 return V_008F14_IMG_DATA_FORMAT_8
;
1386 case PIPE_FORMAT_Z32_FLOAT
:
1387 return V_008F14_IMG_DATA_FORMAT_32
;
1388 case PIPE_FORMAT_X32_S8X24_UINT
:
1389 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
1390 return V_008F14_IMG_DATA_FORMAT_X24_8_32
;
1395 case UTIL_FORMAT_COLORSPACE_YUV
:
1396 goto out_unknown
; /* TODO */
1398 case UTIL_FORMAT_COLORSPACE_SRGB
:
1399 if (desc
->nr_channels
!= 4 && desc
->nr_channels
!= 1)
1407 if (desc
->layout
== UTIL_FORMAT_LAYOUT_RGTC
) {
1408 if (!enable_compressed_formats
)
1412 case PIPE_FORMAT_RGTC1_SNORM
:
1413 case PIPE_FORMAT_LATC1_SNORM
:
1414 case PIPE_FORMAT_RGTC1_UNORM
:
1415 case PIPE_FORMAT_LATC1_UNORM
:
1416 return V_008F14_IMG_DATA_FORMAT_BC4
;
1417 case PIPE_FORMAT_RGTC2_SNORM
:
1418 case PIPE_FORMAT_LATC2_SNORM
:
1419 case PIPE_FORMAT_RGTC2_UNORM
:
1420 case PIPE_FORMAT_LATC2_UNORM
:
1421 return V_008F14_IMG_DATA_FORMAT_BC5
;
1427 if (desc
->layout
== UTIL_FORMAT_LAYOUT_ETC
&&
1428 sscreen
->b
.family
== CHIP_STONEY
) {
1430 case PIPE_FORMAT_ETC1_RGB8
:
1431 case PIPE_FORMAT_ETC2_RGB8
:
1432 case PIPE_FORMAT_ETC2_SRGB8
:
1433 return V_008F14_IMG_DATA_FORMAT_ETC2_RGB
;
1434 case PIPE_FORMAT_ETC2_RGB8A1
:
1435 case PIPE_FORMAT_ETC2_SRGB8A1
:
1436 return V_008F14_IMG_DATA_FORMAT_ETC2_RGBA1
;
1437 case PIPE_FORMAT_ETC2_RGBA8
:
1438 case PIPE_FORMAT_ETC2_SRGBA8
:
1439 return V_008F14_IMG_DATA_FORMAT_ETC2_RGBA
;
1440 case PIPE_FORMAT_ETC2_R11_UNORM
:
1441 case PIPE_FORMAT_ETC2_R11_SNORM
:
1442 return V_008F14_IMG_DATA_FORMAT_ETC2_R
;
1443 case PIPE_FORMAT_ETC2_RG11_UNORM
:
1444 case PIPE_FORMAT_ETC2_RG11_SNORM
:
1445 return V_008F14_IMG_DATA_FORMAT_ETC2_RG
;
1451 if (desc
->layout
== UTIL_FORMAT_LAYOUT_BPTC
) {
1452 if (!enable_compressed_formats
)
1456 case PIPE_FORMAT_BPTC_RGBA_UNORM
:
1457 case PIPE_FORMAT_BPTC_SRGBA
:
1458 return V_008F14_IMG_DATA_FORMAT_BC7
;
1459 case PIPE_FORMAT_BPTC_RGB_FLOAT
:
1460 case PIPE_FORMAT_BPTC_RGB_UFLOAT
:
1461 return V_008F14_IMG_DATA_FORMAT_BC6
;
1467 if (desc
->layout
== UTIL_FORMAT_LAYOUT_SUBSAMPLED
) {
1469 case PIPE_FORMAT_R8G8_B8G8_UNORM
:
1470 case PIPE_FORMAT_G8R8_B8R8_UNORM
:
1471 return V_008F14_IMG_DATA_FORMAT_GB_GR
;
1472 case PIPE_FORMAT_G8R8_G8B8_UNORM
:
1473 case PIPE_FORMAT_R8G8_R8B8_UNORM
:
1474 return V_008F14_IMG_DATA_FORMAT_BG_RG
;
1480 if (desc
->layout
== UTIL_FORMAT_LAYOUT_S3TC
) {
1481 if (!enable_compressed_formats
)
1484 if (!util_format_s3tc_enabled
) {
1489 case PIPE_FORMAT_DXT1_RGB
:
1490 case PIPE_FORMAT_DXT1_RGBA
:
1491 case PIPE_FORMAT_DXT1_SRGB
:
1492 case PIPE_FORMAT_DXT1_SRGBA
:
1493 return V_008F14_IMG_DATA_FORMAT_BC1
;
1494 case PIPE_FORMAT_DXT3_RGBA
:
1495 case PIPE_FORMAT_DXT3_SRGBA
:
1496 return V_008F14_IMG_DATA_FORMAT_BC2
;
1497 case PIPE_FORMAT_DXT5_RGBA
:
1498 case PIPE_FORMAT_DXT5_SRGBA
:
1499 return V_008F14_IMG_DATA_FORMAT_BC3
;
1505 if (format
== PIPE_FORMAT_R9G9B9E5_FLOAT
) {
1506 return V_008F14_IMG_DATA_FORMAT_5_9_9_9
;
1507 } else if (format
== PIPE_FORMAT_R11G11B10_FLOAT
) {
1508 return V_008F14_IMG_DATA_FORMAT_10_11_11
;
1511 /* R8G8Bx_SNORM - TODO CxV8U8 */
1513 /* hw cannot support mixed formats (except depth/stencil, since only
1515 if (desc
->is_mixed
&& desc
->colorspace
!= UTIL_FORMAT_COLORSPACE_ZS
)
1518 /* See whether the components are of the same size. */
1519 for (i
= 1; i
< desc
->nr_channels
; i
++) {
1520 uniform
= uniform
&& desc
->channel
[0].size
== desc
->channel
[i
].size
;
1523 /* Non-uniform formats. */
1525 switch(desc
->nr_channels
) {
1527 if (desc
->channel
[0].size
== 5 &&
1528 desc
->channel
[1].size
== 6 &&
1529 desc
->channel
[2].size
== 5) {
1530 return V_008F14_IMG_DATA_FORMAT_5_6_5
;
1534 if (desc
->channel
[0].size
== 5 &&
1535 desc
->channel
[1].size
== 5 &&
1536 desc
->channel
[2].size
== 5 &&
1537 desc
->channel
[3].size
== 1) {
1538 return V_008F14_IMG_DATA_FORMAT_1_5_5_5
;
1540 if (desc
->channel
[0].size
== 10 &&
1541 desc
->channel
[1].size
== 10 &&
1542 desc
->channel
[2].size
== 10 &&
1543 desc
->channel
[3].size
== 2) {
1544 return V_008F14_IMG_DATA_FORMAT_2_10_10_10
;
1551 if (first_non_void
< 0 || first_non_void
> 3)
1554 /* uniform formats */
1555 switch (desc
->channel
[first_non_void
].size
) {
1557 switch (desc
->nr_channels
) {
1558 #if 0 /* Not supported for render targets */
1560 return V_008F14_IMG_DATA_FORMAT_4_4
;
1563 return V_008F14_IMG_DATA_FORMAT_4_4_4_4
;
1567 switch (desc
->nr_channels
) {
1569 return V_008F14_IMG_DATA_FORMAT_8
;
1571 return V_008F14_IMG_DATA_FORMAT_8_8
;
1573 return V_008F14_IMG_DATA_FORMAT_8_8_8_8
;
1577 switch (desc
->nr_channels
) {
1579 return V_008F14_IMG_DATA_FORMAT_16
;
1581 return V_008F14_IMG_DATA_FORMAT_16_16
;
1583 return V_008F14_IMG_DATA_FORMAT_16_16_16_16
;
1587 switch (desc
->nr_channels
) {
1589 return V_008F14_IMG_DATA_FORMAT_32
;
1591 return V_008F14_IMG_DATA_FORMAT_32_32
;
1592 #if 0 /* Not supported for render targets */
1594 return V_008F14_IMG_DATA_FORMAT_32_32_32
;
1597 return V_008F14_IMG_DATA_FORMAT_32_32_32_32
;
1602 /* R600_ERR("Unable to handle texformat %d %s\n", format, util_format_name(format)); */
1606 static unsigned si_tex_wrap(unsigned wrap
)
1610 case PIPE_TEX_WRAP_REPEAT
:
1611 return V_008F30_SQ_TEX_WRAP
;
1612 case PIPE_TEX_WRAP_CLAMP
:
1613 return V_008F30_SQ_TEX_CLAMP_HALF_BORDER
;
1614 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
1615 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
1616 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
1617 return V_008F30_SQ_TEX_CLAMP_BORDER
;
1618 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
1619 return V_008F30_SQ_TEX_MIRROR
;
1620 case PIPE_TEX_WRAP_MIRROR_CLAMP
:
1621 return V_008F30_SQ_TEX_MIRROR_ONCE_HALF_BORDER
;
1622 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
:
1623 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
1624 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
:
1625 return V_008F30_SQ_TEX_MIRROR_ONCE_BORDER
;
1629 static unsigned si_tex_mipfilter(unsigned filter
)
1632 case PIPE_TEX_MIPFILTER_NEAREST
:
1633 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
1634 case PIPE_TEX_MIPFILTER_LINEAR
:
1635 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
1637 case PIPE_TEX_MIPFILTER_NONE
:
1638 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
1642 static unsigned si_tex_compare(unsigned compare
)
1646 case PIPE_FUNC_NEVER
:
1647 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
1648 case PIPE_FUNC_LESS
:
1649 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
1650 case PIPE_FUNC_EQUAL
:
1651 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
1652 case PIPE_FUNC_LEQUAL
:
1653 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
1654 case PIPE_FUNC_GREATER
:
1655 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
1656 case PIPE_FUNC_NOTEQUAL
:
1657 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
1658 case PIPE_FUNC_GEQUAL
:
1659 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
1660 case PIPE_FUNC_ALWAYS
:
1661 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
1665 static unsigned si_tex_dim(unsigned res_target
, unsigned view_target
,
1666 unsigned nr_samples
)
1668 if (view_target
== PIPE_TEXTURE_CUBE
||
1669 view_target
== PIPE_TEXTURE_CUBE_ARRAY
)
1670 res_target
= view_target
;
1671 /* If interpreting cubemaps as something else, set 2D_ARRAY. */
1672 else if (res_target
== PIPE_TEXTURE_CUBE
||
1673 res_target
== PIPE_TEXTURE_CUBE_ARRAY
)
1674 res_target
= PIPE_TEXTURE_2D_ARRAY
;
1676 switch (res_target
) {
1678 case PIPE_TEXTURE_1D
:
1679 return V_008F1C_SQ_RSRC_IMG_1D
;
1680 case PIPE_TEXTURE_1D_ARRAY
:
1681 return V_008F1C_SQ_RSRC_IMG_1D_ARRAY
;
1682 case PIPE_TEXTURE_2D
:
1683 case PIPE_TEXTURE_RECT
:
1684 return nr_samples
> 1 ? V_008F1C_SQ_RSRC_IMG_2D_MSAA
:
1685 V_008F1C_SQ_RSRC_IMG_2D
;
1686 case PIPE_TEXTURE_2D_ARRAY
:
1687 return nr_samples
> 1 ? V_008F1C_SQ_RSRC_IMG_2D_MSAA_ARRAY
:
1688 V_008F1C_SQ_RSRC_IMG_2D_ARRAY
;
1689 case PIPE_TEXTURE_3D
:
1690 return V_008F1C_SQ_RSRC_IMG_3D
;
1691 case PIPE_TEXTURE_CUBE
:
1692 case PIPE_TEXTURE_CUBE_ARRAY
:
1693 return V_008F1C_SQ_RSRC_IMG_CUBE
;
1698 * Format support testing
1701 static bool si_is_sampler_format_supported(struct pipe_screen
*screen
, enum pipe_format format
)
1703 return si_translate_texformat(screen
, format
, util_format_description(format
),
1704 util_format_get_first_non_void_channel(format
)) != ~0U;
1707 static uint32_t si_translate_buffer_dataformat(struct pipe_screen
*screen
,
1708 const struct util_format_description
*desc
,
1713 if (desc
->format
== PIPE_FORMAT_R11G11B10_FLOAT
)
1714 return V_008F0C_BUF_DATA_FORMAT_10_11_11
;
1716 assert(first_non_void
>= 0);
1718 if (desc
->nr_channels
== 4 &&
1719 desc
->channel
[0].size
== 10 &&
1720 desc
->channel
[1].size
== 10 &&
1721 desc
->channel
[2].size
== 10 &&
1722 desc
->channel
[3].size
== 2)
1723 return V_008F0C_BUF_DATA_FORMAT_2_10_10_10
;
1725 /* See whether the components are of the same size. */
1726 for (i
= 0; i
< desc
->nr_channels
; i
++) {
1727 if (desc
->channel
[first_non_void
].size
!= desc
->channel
[i
].size
)
1728 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
1731 switch (desc
->channel
[first_non_void
].size
) {
1733 switch (desc
->nr_channels
) {
1735 case 3: /* 3 loads */
1736 return V_008F0C_BUF_DATA_FORMAT_8
;
1738 return V_008F0C_BUF_DATA_FORMAT_8_8
;
1740 return V_008F0C_BUF_DATA_FORMAT_8_8_8_8
;
1744 switch (desc
->nr_channels
) {
1746 case 3: /* 3 loads */
1747 return V_008F0C_BUF_DATA_FORMAT_16
;
1749 return V_008F0C_BUF_DATA_FORMAT_16_16
;
1751 return V_008F0C_BUF_DATA_FORMAT_16_16_16_16
;
1755 switch (desc
->nr_channels
) {
1757 return V_008F0C_BUF_DATA_FORMAT_32
;
1759 return V_008F0C_BUF_DATA_FORMAT_32_32
;
1761 return V_008F0C_BUF_DATA_FORMAT_32_32_32
;
1763 return V_008F0C_BUF_DATA_FORMAT_32_32_32_32
;
1767 /* Legacy double formats. */
1768 switch (desc
->nr_channels
) {
1769 case 1: /* 1 load */
1770 return V_008F0C_BUF_DATA_FORMAT_32_32
;
1771 case 2: /* 1 load */
1772 return V_008F0C_BUF_DATA_FORMAT_32_32_32_32
;
1773 case 3: /* 3 loads */
1774 return V_008F0C_BUF_DATA_FORMAT_32_32
;
1775 case 4: /* 2 loads */
1776 return V_008F0C_BUF_DATA_FORMAT_32_32_32_32
;
1781 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
1784 static uint32_t si_translate_buffer_numformat(struct pipe_screen
*screen
,
1785 const struct util_format_description
*desc
,
1788 if (desc
->format
== PIPE_FORMAT_R11G11B10_FLOAT
)
1789 return V_008F0C_BUF_NUM_FORMAT_FLOAT
;
1791 assert(first_non_void
>= 0);
1793 switch (desc
->channel
[first_non_void
].type
) {
1794 case UTIL_FORMAT_TYPE_SIGNED
:
1795 case UTIL_FORMAT_TYPE_FIXED
:
1796 if (desc
->channel
[first_non_void
].size
>= 32 ||
1797 desc
->channel
[first_non_void
].pure_integer
)
1798 return V_008F0C_BUF_NUM_FORMAT_SINT
;
1799 else if (desc
->channel
[first_non_void
].normalized
)
1800 return V_008F0C_BUF_NUM_FORMAT_SNORM
;
1802 return V_008F0C_BUF_NUM_FORMAT_SSCALED
;
1804 case UTIL_FORMAT_TYPE_UNSIGNED
:
1805 if (desc
->channel
[first_non_void
].size
>= 32 ||
1806 desc
->channel
[first_non_void
].pure_integer
)
1807 return V_008F0C_BUF_NUM_FORMAT_UINT
;
1808 else if (desc
->channel
[first_non_void
].normalized
)
1809 return V_008F0C_BUF_NUM_FORMAT_UNORM
;
1811 return V_008F0C_BUF_NUM_FORMAT_USCALED
;
1813 case UTIL_FORMAT_TYPE_FLOAT
:
1815 return V_008F0C_BUF_NUM_FORMAT_FLOAT
;
1819 static unsigned si_is_vertex_format_supported(struct pipe_screen
*screen
,
1820 enum pipe_format format
,
1823 const struct util_format_description
*desc
;
1825 unsigned data_format
;
1827 assert((usage
& ~(PIPE_BIND_SHADER_IMAGE
|
1828 PIPE_BIND_SAMPLER_VIEW
|
1829 PIPE_BIND_VERTEX_BUFFER
)) == 0);
1831 desc
= util_format_description(format
);
1833 /* There are no native 8_8_8 or 16_16_16 data formats, and we currently
1834 * select 8_8_8_8 and 16_16_16_16 instead. This works reasonably well
1835 * for read-only access (with caveats surrounding bounds checks), but
1836 * obviously fails for write access which we have to implement for
1837 * shader images. Luckily, OpenGL doesn't expect this to be supported
1838 * anyway, and so the only impact is on PBO uploads / downloads, which
1839 * shouldn't be expected to be fast for GL_RGB anyway.
1841 if (desc
->block
.bits
== 3 * 8 ||
1842 desc
->block
.bits
== 3 * 16) {
1843 if (usage
& (PIPE_BIND_SHADER_IMAGE
| PIPE_BIND_SAMPLER_VIEW
)) {
1844 usage
&= ~(PIPE_BIND_SHADER_IMAGE
| PIPE_BIND_SAMPLER_VIEW
);
1850 first_non_void
= util_format_get_first_non_void_channel(format
);
1851 data_format
= si_translate_buffer_dataformat(screen
, desc
, first_non_void
);
1852 if (data_format
== V_008F0C_BUF_DATA_FORMAT_INVALID
)
1858 static bool si_is_colorbuffer_format_supported(enum pipe_format format
)
1860 return si_translate_colorformat(format
) != V_028C70_COLOR_INVALID
&&
1861 r600_translate_colorswap(format
, false) != ~0U;
1864 static bool si_is_zs_format_supported(enum pipe_format format
)
1866 return si_translate_dbformat(format
) != V_028040_Z_INVALID
;
1869 static boolean
si_is_format_supported(struct pipe_screen
*screen
,
1870 enum pipe_format format
,
1871 enum pipe_texture_target target
,
1872 unsigned sample_count
,
1875 unsigned retval
= 0;
1877 if (target
>= PIPE_MAX_TEXTURE_TYPES
) {
1878 R600_ERR("r600: unsupported texture type %d\n", target
);
1882 if (!util_format_is_supported(format
, usage
))
1885 if (sample_count
> 1) {
1886 if (!screen
->get_param(screen
, PIPE_CAP_TEXTURE_MULTISAMPLE
))
1889 if (usage
& PIPE_BIND_SHADER_IMAGE
)
1892 switch (sample_count
) {
1898 if (format
== PIPE_FORMAT_NONE
)
1907 if (usage
& (PIPE_BIND_SAMPLER_VIEW
|
1908 PIPE_BIND_SHADER_IMAGE
)) {
1909 if (target
== PIPE_BUFFER
) {
1910 retval
|= si_is_vertex_format_supported(
1911 screen
, format
, usage
& (PIPE_BIND_SAMPLER_VIEW
|
1912 PIPE_BIND_SHADER_IMAGE
));
1914 if (si_is_sampler_format_supported(screen
, format
))
1915 retval
|= usage
& (PIPE_BIND_SAMPLER_VIEW
|
1916 PIPE_BIND_SHADER_IMAGE
);
1920 if ((usage
& (PIPE_BIND_RENDER_TARGET
|
1921 PIPE_BIND_DISPLAY_TARGET
|
1924 PIPE_BIND_BLENDABLE
)) &&
1925 si_is_colorbuffer_format_supported(format
)) {
1927 (PIPE_BIND_RENDER_TARGET
|
1928 PIPE_BIND_DISPLAY_TARGET
|
1931 if (!util_format_is_pure_integer(format
) &&
1932 !util_format_is_depth_or_stencil(format
))
1933 retval
|= usage
& PIPE_BIND_BLENDABLE
;
1936 if ((usage
& PIPE_BIND_DEPTH_STENCIL
) &&
1937 si_is_zs_format_supported(format
)) {
1938 retval
|= PIPE_BIND_DEPTH_STENCIL
;
1941 if (usage
& PIPE_BIND_VERTEX_BUFFER
) {
1942 retval
|= si_is_vertex_format_supported(screen
, format
,
1943 PIPE_BIND_VERTEX_BUFFER
);
1946 if ((usage
& PIPE_BIND_LINEAR
) &&
1947 !util_format_is_compressed(format
) &&
1948 !(usage
& PIPE_BIND_DEPTH_STENCIL
))
1949 retval
|= PIPE_BIND_LINEAR
;
1951 return retval
== usage
;
1955 * framebuffer handling
1958 static void si_choose_spi_color_formats(struct r600_surface
*surf
,
1959 unsigned format
, unsigned swap
,
1960 unsigned ntype
, bool is_depth
)
1962 /* Alpha is needed for alpha-to-coverage.
1963 * Blending may be with or without alpha.
1965 unsigned normal
= 0; /* most optimal, may not support blending or export alpha */
1966 unsigned alpha
= 0; /* exports alpha, but may not support blending */
1967 unsigned blend
= 0; /* supports blending, but may not export alpha */
1968 unsigned blend_alpha
= 0; /* least optimal, supports blending and exports alpha */
1970 /* Choose the SPI color formats. These are required values for Stoney/RB+.
1971 * Other chips have multiple choices, though they are not necessarily better.
1974 case V_028C70_COLOR_5_6_5
:
1975 case V_028C70_COLOR_1_5_5_5
:
1976 case V_028C70_COLOR_5_5_5_1
:
1977 case V_028C70_COLOR_4_4_4_4
:
1978 case V_028C70_COLOR_10_11_11
:
1979 case V_028C70_COLOR_11_11_10
:
1980 case V_028C70_COLOR_8
:
1981 case V_028C70_COLOR_8_8
:
1982 case V_028C70_COLOR_8_8_8_8
:
1983 case V_028C70_COLOR_10_10_10_2
:
1984 case V_028C70_COLOR_2_10_10_10
:
1985 if (ntype
== V_028C70_NUMBER_UINT
)
1986 alpha
= blend
= blend_alpha
= normal
= V_028714_SPI_SHADER_UINT16_ABGR
;
1987 else if (ntype
== V_028C70_NUMBER_SINT
)
1988 alpha
= blend
= blend_alpha
= normal
= V_028714_SPI_SHADER_SINT16_ABGR
;
1990 alpha
= blend
= blend_alpha
= normal
= V_028714_SPI_SHADER_FP16_ABGR
;
1993 case V_028C70_COLOR_16
:
1994 case V_028C70_COLOR_16_16
:
1995 case V_028C70_COLOR_16_16_16_16
:
1996 if (ntype
== V_028C70_NUMBER_UNORM
||
1997 ntype
== V_028C70_NUMBER_SNORM
) {
1998 /* UNORM16 and SNORM16 don't support blending */
1999 if (ntype
== V_028C70_NUMBER_UNORM
)
2000 normal
= alpha
= V_028714_SPI_SHADER_UNORM16_ABGR
;
2002 normal
= alpha
= V_028714_SPI_SHADER_SNORM16_ABGR
;
2004 /* Use 32 bits per channel for blending. */
2005 if (format
== V_028C70_COLOR_16
) {
2006 if (swap
== V_028C70_SWAP_STD
) { /* R */
2007 blend
= V_028714_SPI_SHADER_32_R
;
2008 blend_alpha
= V_028714_SPI_SHADER_32_AR
;
2009 } else if (swap
== V_028C70_SWAP_ALT_REV
) /* A */
2010 blend
= blend_alpha
= V_028714_SPI_SHADER_32_AR
;
2013 } else if (format
== V_028C70_COLOR_16_16
) {
2014 if (swap
== V_028C70_SWAP_STD
) { /* RG */
2015 blend
= V_028714_SPI_SHADER_32_GR
;
2016 blend_alpha
= V_028714_SPI_SHADER_32_ABGR
;
2017 } else if (swap
== V_028C70_SWAP_ALT
) /* RA */
2018 blend
= blend_alpha
= V_028714_SPI_SHADER_32_AR
;
2021 } else /* 16_16_16_16 */
2022 blend
= blend_alpha
= V_028714_SPI_SHADER_32_ABGR
;
2023 } else if (ntype
== V_028C70_NUMBER_UINT
)
2024 alpha
= blend
= blend_alpha
= normal
= V_028714_SPI_SHADER_UINT16_ABGR
;
2025 else if (ntype
== V_028C70_NUMBER_SINT
)
2026 alpha
= blend
= blend_alpha
= normal
= V_028714_SPI_SHADER_SINT16_ABGR
;
2027 else if (ntype
== V_028C70_NUMBER_FLOAT
)
2028 alpha
= blend
= blend_alpha
= normal
= V_028714_SPI_SHADER_FP16_ABGR
;
2033 case V_028C70_COLOR_32
:
2034 if (swap
== V_028C70_SWAP_STD
) { /* R */
2035 blend
= normal
= V_028714_SPI_SHADER_32_R
;
2036 alpha
= blend_alpha
= V_028714_SPI_SHADER_32_AR
;
2037 } else if (swap
== V_028C70_SWAP_ALT_REV
) /* A */
2038 alpha
= blend
= blend_alpha
= normal
= V_028714_SPI_SHADER_32_AR
;
2043 case V_028C70_COLOR_32_32
:
2044 if (swap
== V_028C70_SWAP_STD
) { /* RG */
2045 blend
= normal
= V_028714_SPI_SHADER_32_GR
;
2046 alpha
= blend_alpha
= V_028714_SPI_SHADER_32_ABGR
;
2047 } else if (swap
== V_028C70_SWAP_ALT
) /* RA */
2048 alpha
= blend
= blend_alpha
= normal
= V_028714_SPI_SHADER_32_AR
;
2053 case V_028C70_COLOR_32_32_32_32
:
2054 case V_028C70_COLOR_8_24
:
2055 case V_028C70_COLOR_24_8
:
2056 case V_028C70_COLOR_X24_8_32_FLOAT
:
2057 alpha
= blend
= blend_alpha
= normal
= V_028714_SPI_SHADER_32_ABGR
;
2065 /* The DB->CB copy needs 32_ABGR. */
2067 alpha
= blend
= blend_alpha
= normal
= V_028714_SPI_SHADER_32_ABGR
;
2069 surf
->spi_shader_col_format
= normal
;
2070 surf
->spi_shader_col_format_alpha
= alpha
;
2071 surf
->spi_shader_col_format_blend
= blend
;
2072 surf
->spi_shader_col_format_blend_alpha
= blend_alpha
;
2075 static void si_initialize_color_surface(struct si_context
*sctx
,
2076 struct r600_surface
*surf
)
2078 struct r600_texture
*rtex
= (struct r600_texture
*)surf
->base
.texture
;
2079 unsigned color_info
, color_attrib
, color_view
;
2080 unsigned format
, swap
, ntype
, endian
;
2081 const struct util_format_description
*desc
;
2083 unsigned blend_clamp
= 0, blend_bypass
= 0;
2085 color_view
= S_028C6C_SLICE_START(surf
->base
.u
.tex
.first_layer
) |
2086 S_028C6C_SLICE_MAX(surf
->base
.u
.tex
.last_layer
);
2088 desc
= util_format_description(surf
->base
.format
);
2089 for (i
= 0; i
< 4; i
++) {
2090 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
2094 if (i
== 4 || desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_FLOAT
) {
2095 ntype
= V_028C70_NUMBER_FLOAT
;
2097 ntype
= V_028C70_NUMBER_UNORM
;
2098 if (desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
)
2099 ntype
= V_028C70_NUMBER_SRGB
;
2100 else if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
2101 if (desc
->channel
[i
].pure_integer
) {
2102 ntype
= V_028C70_NUMBER_SINT
;
2104 assert(desc
->channel
[i
].normalized
);
2105 ntype
= V_028C70_NUMBER_SNORM
;
2107 } else if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_UNSIGNED
) {
2108 if (desc
->channel
[i
].pure_integer
) {
2109 ntype
= V_028C70_NUMBER_UINT
;
2111 assert(desc
->channel
[i
].normalized
);
2112 ntype
= V_028C70_NUMBER_UNORM
;
2117 format
= si_translate_colorformat(surf
->base
.format
);
2118 if (format
== V_028C70_COLOR_INVALID
) {
2119 R600_ERR("Invalid CB format: %d, disabling CB.\n", surf
->base
.format
);
2121 assert(format
!= V_028C70_COLOR_INVALID
);
2122 swap
= r600_translate_colorswap(surf
->base
.format
, false);
2123 endian
= si_colorformat_endian_swap(format
);
2125 /* blend clamp should be set for all NORM/SRGB types */
2126 if (ntype
== V_028C70_NUMBER_UNORM
||
2127 ntype
== V_028C70_NUMBER_SNORM
||
2128 ntype
== V_028C70_NUMBER_SRGB
)
2131 /* set blend bypass according to docs if SINT/UINT or
2132 8/24 COLOR variants */
2133 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
2134 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
2135 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
2140 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
) {
2141 if (format
== V_028C70_COLOR_8
||
2142 format
== V_028C70_COLOR_8_8
||
2143 format
== V_028C70_COLOR_8_8_8_8
)
2144 surf
->color_is_int8
= true;
2145 else if (format
== V_028C70_COLOR_10_10_10_2
||
2146 format
== V_028C70_COLOR_2_10_10_10
)
2147 surf
->color_is_int10
= true;
2150 color_info
= S_028C70_FORMAT(format
) |
2151 S_028C70_COMP_SWAP(swap
) |
2152 S_028C70_BLEND_CLAMP(blend_clamp
) |
2153 S_028C70_BLEND_BYPASS(blend_bypass
) |
2154 S_028C70_SIMPLE_FLOAT(1) |
2155 S_028C70_ROUND_MODE(ntype
!= V_028C70_NUMBER_UNORM
&&
2156 ntype
!= V_028C70_NUMBER_SNORM
&&
2157 ntype
!= V_028C70_NUMBER_SRGB
&&
2158 format
!= V_028C70_COLOR_8_24
&&
2159 format
!= V_028C70_COLOR_24_8
) |
2160 S_028C70_NUMBER_TYPE(ntype
) |
2161 S_028C70_ENDIAN(endian
);
2163 /* Intensity is implemented as Red, so treat it that way. */
2164 color_attrib
= S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == PIPE_SWIZZLE_1
||
2165 util_format_is_intensity(surf
->base
.format
));
2167 if (rtex
->resource
.b
.b
.nr_samples
> 1) {
2168 unsigned log_samples
= util_logbase2(rtex
->resource
.b
.b
.nr_samples
);
2170 color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
2171 S_028C74_NUM_FRAGMENTS(log_samples
);
2173 if (rtex
->fmask
.size
) {
2174 color_info
|= S_028C70_COMPRESSION(1);
2175 unsigned fmask_bankh
= util_logbase2(rtex
->fmask
.bank_height
);
2177 if (sctx
->b
.chip_class
== SI
) {
2178 /* due to a hw bug, FMASK_BANK_HEIGHT must be set on SI too */
2179 color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
2184 surf
->cb_color_view
= color_view
;
2185 surf
->cb_color_info
= color_info
;
2186 surf
->cb_color_attrib
= color_attrib
;
2188 if (sctx
->b
.chip_class
>= VI
) {
2189 unsigned max_uncompressed_block_size
= 2;
2191 if (rtex
->resource
.b
.b
.nr_samples
> 1) {
2192 if (rtex
->surface
.bpe
== 1)
2193 max_uncompressed_block_size
= 0;
2194 else if (rtex
->surface
.bpe
== 2)
2195 max_uncompressed_block_size
= 1;
2198 surf
->cb_dcc_control
= S_028C78_MAX_UNCOMPRESSED_BLOCK_SIZE(max_uncompressed_block_size
) |
2199 S_028C78_INDEPENDENT_64B_BLOCKS(1);
2202 /* This must be set for fast clear to work without FMASK. */
2203 if (!rtex
->fmask
.size
&& sctx
->b
.chip_class
== SI
) {
2204 unsigned bankh
= util_logbase2(rtex
->surface
.bankh
);
2205 surf
->cb_color_attrib
|= S_028C74_FMASK_BANK_HEIGHT(bankh
);
2208 /* Determine pixel shader export format */
2209 si_choose_spi_color_formats(surf
, format
, swap
, ntype
, rtex
->is_depth
);
2211 surf
->color_initialized
= true;
2214 static void si_init_depth_surface(struct si_context
*sctx
,
2215 struct r600_surface
*surf
)
2217 struct r600_texture
*rtex
= (struct r600_texture
*)surf
->base
.texture
;
2218 unsigned level
= surf
->base
.u
.tex
.level
;
2219 struct radeon_surf_level
*levelinfo
= &rtex
->surface
.level
[level
];
2220 unsigned format
, stencil_format
;
2221 uint32_t z_info
, s_info
;
2223 format
= si_translate_dbformat(rtex
->db_render_format
);
2224 stencil_format
= rtex
->surface
.flags
& RADEON_SURF_SBUFFER
?
2225 V_028044_STENCIL_8
: V_028044_STENCIL_INVALID
;
2227 assert(format
!= V_028040_Z_INVALID
);
2228 if (format
== V_028040_Z_INVALID
)
2229 R600_ERR("Invalid DB format: %d, disabling DB.\n", rtex
->resource
.b
.b
.format
);
2231 surf
->db_depth_view
= S_028008_SLICE_START(surf
->base
.u
.tex
.first_layer
) |
2232 S_028008_SLICE_MAX(surf
->base
.u
.tex
.last_layer
);
2233 surf
->db_htile_data_base
= 0;
2234 surf
->db_htile_surface
= 0;
2236 assert(levelinfo
->nblk_x
% 8 == 0 && levelinfo
->nblk_y
% 8 == 0);
2238 surf
->db_depth_base
= (rtex
->resource
.gpu_address
+
2239 rtex
->surface
.level
[level
].offset
) >> 8;
2240 surf
->db_stencil_base
= (rtex
->resource
.gpu_address
+
2241 rtex
->surface
.stencil_level
[level
].offset
) >> 8;
2243 z_info
= S_028040_FORMAT(format
) |
2244 S_028040_NUM_SAMPLES(util_logbase2(rtex
->resource
.b
.b
.nr_samples
));
2245 s_info
= S_028044_FORMAT(stencil_format
);
2246 surf
->db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(!rtex
->tc_compatible_htile
);
2248 if (sctx
->b
.chip_class
>= CIK
) {
2249 struct radeon_info
*info
= &sctx
->screen
->b
.info
;
2250 unsigned index
= rtex
->surface
.tiling_index
[level
];
2251 unsigned stencil_index
= rtex
->surface
.stencil_tiling_index
[level
];
2252 unsigned macro_index
= rtex
->surface
.macro_tile_index
;
2253 unsigned tile_mode
= info
->si_tile_mode_array
[index
];
2254 unsigned stencil_tile_mode
= info
->si_tile_mode_array
[stencil_index
];
2255 unsigned macro_mode
= info
->cik_macrotile_mode_array
[macro_index
];
2257 surf
->db_depth_info
|=
2258 S_02803C_ARRAY_MODE(G_009910_ARRAY_MODE(tile_mode
)) |
2259 S_02803C_PIPE_CONFIG(G_009910_PIPE_CONFIG(tile_mode
)) |
2260 S_02803C_BANK_WIDTH(G_009990_BANK_WIDTH(macro_mode
)) |
2261 S_02803C_BANK_HEIGHT(G_009990_BANK_HEIGHT(macro_mode
)) |
2262 S_02803C_MACRO_TILE_ASPECT(G_009990_MACRO_TILE_ASPECT(macro_mode
)) |
2263 S_02803C_NUM_BANKS(G_009990_NUM_BANKS(macro_mode
));
2264 z_info
|= S_028040_TILE_SPLIT(G_009910_TILE_SPLIT(tile_mode
));
2265 s_info
|= S_028044_TILE_SPLIT(G_009910_TILE_SPLIT(stencil_tile_mode
));
2267 unsigned tile_mode_index
= si_tile_mode_index(rtex
, level
, false);
2268 z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
2269 tile_mode_index
= si_tile_mode_index(rtex
, level
, true);
2270 s_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
2273 surf
->db_depth_size
= S_028058_PITCH_TILE_MAX((levelinfo
->nblk_x
/ 8) - 1) |
2274 S_028058_HEIGHT_TILE_MAX((levelinfo
->nblk_y
/ 8) - 1);
2275 surf
->db_depth_slice
= S_02805C_SLICE_TILE_MAX((levelinfo
->nblk_x
*
2276 levelinfo
->nblk_y
) / 64 - 1);
2278 /* Only use HTILE for the first level. */
2279 if (rtex
->htile_buffer
&& !level
) {
2280 z_info
|= S_028040_TILE_SURFACE_ENABLE(1) |
2281 S_028040_ALLOW_EXPCLEAR(1);
2283 if (rtex
->surface
.flags
& RADEON_SURF_SBUFFER
) {
2284 /* Workaround: For a not yet understood reason, the
2285 * combination of MSAA, fast stencil clear and stencil
2286 * decompress messes with subsequent stencil buffer
2287 * uses. Problem was reproduced on Verde, Bonaire,
2288 * Tonga, and Carrizo.
2290 * Disabling EXPCLEAR works around the problem.
2292 * Check piglit's arb_texture_multisample-stencil-clear
2293 * test if you want to try changing this.
2295 if (rtex
->resource
.b
.b
.nr_samples
<= 1)
2296 s_info
|= S_028044_ALLOW_EXPCLEAR(1);
2297 } else if (!rtex
->tc_compatible_htile
) {
2298 /* Use all of the htile_buffer for depth if there's no stencil.
2299 * This must not be set when TC-compatible HTILE is enabled
2302 s_info
|= S_028044_TILE_STENCIL_DISABLE(1);
2305 surf
->db_htile_data_base
= rtex
->htile_buffer
->gpu_address
>> 8;
2306 surf
->db_htile_surface
= S_028ABC_FULL_CACHE(1);
2308 if (rtex
->tc_compatible_htile
) {
2309 surf
->db_htile_surface
|= S_028ABC_TC_COMPATIBLE(1);
2311 if (rtex
->resource
.b
.b
.nr_samples
<= 1)
2312 z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(5);
2313 else if (rtex
->resource
.b
.b
.nr_samples
<= 4)
2314 z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(3);
2316 z_info
|= S_028040_DECOMPRESS_ON_N_ZPLANES(2);
2320 surf
->db_z_info
= z_info
;
2321 surf
->db_stencil_info
= s_info
;
2323 surf
->depth_initialized
= true;
2326 static void si_dec_framebuffer_counters(const struct pipe_framebuffer_state
*state
)
2328 for (int i
= 0; i
< state
->nr_cbufs
; ++i
) {
2329 struct r600_surface
*surf
= NULL
;
2330 struct r600_texture
*rtex
;
2332 if (!state
->cbufs
[i
])
2334 surf
= (struct r600_surface
*)state
->cbufs
[i
];
2335 rtex
= (struct r600_texture
*)surf
->base
.texture
;
2337 p_atomic_dec(&rtex
->framebuffers_bound
);
2341 static void si_set_framebuffer_state(struct pipe_context
*ctx
,
2342 const struct pipe_framebuffer_state
*state
)
2344 struct si_context
*sctx
= (struct si_context
*)ctx
;
2345 struct pipe_constant_buffer constbuf
= {0};
2346 struct r600_surface
*surf
= NULL
;
2347 struct r600_texture
*rtex
;
2348 bool old_any_dst_linear
= sctx
->framebuffer
.any_dst_linear
;
2349 unsigned old_nr_samples
= sctx
->framebuffer
.nr_samples
;
2352 for (i
= 0; i
< sctx
->framebuffer
.state
.nr_cbufs
; i
++) {
2353 if (!sctx
->framebuffer
.state
.cbufs
[i
])
2356 rtex
= (struct r600_texture
*)sctx
->framebuffer
.state
.cbufs
[i
]->texture
;
2357 if (rtex
->dcc_gather_statistics
)
2358 vi_separate_dcc_stop_query(ctx
, rtex
);
2361 /* Only flush TC when changing the framebuffer state, because
2362 * the only client not using TC that can change textures is
2365 * Flush all CB and DB caches here because all buffers can be used
2366 * for write by both TC (with shader image stores) and CB/DB.
2368 sctx
->b
.flags
|= SI_CONTEXT_INV_VMEM_L1
|
2369 SI_CONTEXT_INV_GLOBAL_L2
|
2370 SI_CONTEXT_FLUSH_AND_INV_CB
|
2371 SI_CONTEXT_FLUSH_AND_INV_DB
|
2372 SI_CONTEXT_CS_PARTIAL_FLUSH
;
2374 /* Take the maximum of the old and new count. If the new count is lower,
2375 * dirtying is needed to disable the unbound colorbuffers.
2377 sctx
->framebuffer
.dirty_cbufs
|=
2378 (1 << MAX2(sctx
->framebuffer
.state
.nr_cbufs
, state
->nr_cbufs
)) - 1;
2379 sctx
->framebuffer
.dirty_zsbuf
|= sctx
->framebuffer
.state
.zsbuf
!= state
->zsbuf
;
2381 si_dec_framebuffer_counters(&sctx
->framebuffer
.state
);
2382 util_copy_framebuffer_state(&sctx
->framebuffer
.state
, state
);
2384 sctx
->framebuffer
.colorbuf_enabled_4bit
= 0;
2385 sctx
->framebuffer
.spi_shader_col_format
= 0;
2386 sctx
->framebuffer
.spi_shader_col_format_alpha
= 0;
2387 sctx
->framebuffer
.spi_shader_col_format_blend
= 0;
2388 sctx
->framebuffer
.spi_shader_col_format_blend_alpha
= 0;
2389 sctx
->framebuffer
.color_is_int8
= 0;
2390 sctx
->framebuffer
.color_is_int10
= 0;
2392 sctx
->framebuffer
.compressed_cb_mask
= 0;
2393 sctx
->framebuffer
.nr_samples
= util_framebuffer_get_num_samples(state
);
2394 sctx
->framebuffer
.log_samples
= util_logbase2(sctx
->framebuffer
.nr_samples
);
2395 sctx
->framebuffer
.any_dst_linear
= false;
2397 for (i
= 0; i
< state
->nr_cbufs
; i
++) {
2398 if (!state
->cbufs
[i
])
2401 surf
= (struct r600_surface
*)state
->cbufs
[i
];
2402 rtex
= (struct r600_texture
*)surf
->base
.texture
;
2404 if (!surf
->color_initialized
) {
2405 si_initialize_color_surface(sctx
, surf
);
2408 sctx
->framebuffer
.colorbuf_enabled_4bit
|= 0xf << (i
* 4);
2409 sctx
->framebuffer
.spi_shader_col_format
|=
2410 surf
->spi_shader_col_format
<< (i
* 4);
2411 sctx
->framebuffer
.spi_shader_col_format_alpha
|=
2412 surf
->spi_shader_col_format_alpha
<< (i
* 4);
2413 sctx
->framebuffer
.spi_shader_col_format_blend
|=
2414 surf
->spi_shader_col_format_blend
<< (i
* 4);
2415 sctx
->framebuffer
.spi_shader_col_format_blend_alpha
|=
2416 surf
->spi_shader_col_format_blend_alpha
<< (i
* 4);
2418 if (surf
->color_is_int8
)
2419 sctx
->framebuffer
.color_is_int8
|= 1 << i
;
2420 if (surf
->color_is_int10
)
2421 sctx
->framebuffer
.color_is_int10
|= 1 << i
;
2423 if (rtex
->fmask
.size
) {
2424 sctx
->framebuffer
.compressed_cb_mask
|= 1 << i
;
2427 if (rtex
->surface
.is_linear
)
2428 sctx
->framebuffer
.any_dst_linear
= true;
2430 r600_context_add_resource_size(ctx
, surf
->base
.texture
);
2432 p_atomic_inc(&rtex
->framebuffers_bound
);
2434 if (rtex
->dcc_gather_statistics
) {
2435 /* Dirty tracking must be enabled for DCC usage analysis. */
2436 sctx
->framebuffer
.compressed_cb_mask
|= 1 << i
;
2437 vi_separate_dcc_start_query(ctx
, rtex
);
2442 surf
= (struct r600_surface
*)state
->zsbuf
;
2443 rtex
= (struct r600_texture
*)surf
->base
.texture
;
2445 if (!surf
->depth_initialized
) {
2446 si_init_depth_surface(sctx
, surf
);
2448 r600_context_add_resource_size(ctx
, surf
->base
.texture
);
2451 si_update_poly_offset_state(sctx
);
2452 si_mark_atom_dirty(sctx
, &sctx
->cb_render_state
);
2453 si_mark_atom_dirty(sctx
, &sctx
->framebuffer
.atom
);
2455 if (sctx
->framebuffer
.any_dst_linear
!= old_any_dst_linear
)
2456 si_mark_atom_dirty(sctx
, &sctx
->msaa_config
);
2458 if (sctx
->framebuffer
.nr_samples
!= old_nr_samples
) {
2459 si_mark_atom_dirty(sctx
, &sctx
->msaa_config
);
2460 si_mark_atom_dirty(sctx
, &sctx
->db_render_state
);
2462 /* Set sample locations as fragment shader constants. */
2463 switch (sctx
->framebuffer
.nr_samples
) {
2465 constbuf
.user_buffer
= sctx
->b
.sample_locations_1x
;
2468 constbuf
.user_buffer
= sctx
->b
.sample_locations_2x
;
2471 constbuf
.user_buffer
= sctx
->b
.sample_locations_4x
;
2474 constbuf
.user_buffer
= sctx
->b
.sample_locations_8x
;
2477 constbuf
.user_buffer
= sctx
->b
.sample_locations_16x
;
2480 R600_ERR("Requested an invalid number of samples %i.\n",
2481 sctx
->framebuffer
.nr_samples
);
2484 constbuf
.buffer_size
= sctx
->framebuffer
.nr_samples
* 2 * 4;
2485 si_set_rw_buffer(sctx
, SI_PS_CONST_SAMPLE_POSITIONS
, &constbuf
);
2487 si_mark_atom_dirty(sctx
, &sctx
->msaa_sample_locs
.atom
);
2490 sctx
->need_check_render_feedback
= true;
2491 sctx
->do_update_shaders
= true;
2492 sctx
->framebuffer
.do_update_surf_dirtiness
= true;
2495 static void si_emit_framebuffer_state(struct si_context
*sctx
, struct r600_atom
*atom
)
2497 struct radeon_winsys_cs
*cs
= sctx
->b
.gfx
.cs
;
2498 struct pipe_framebuffer_state
*state
= &sctx
->framebuffer
.state
;
2499 unsigned i
, nr_cbufs
= state
->nr_cbufs
;
2500 struct r600_texture
*tex
= NULL
;
2501 struct r600_surface
*cb
= NULL
;
2502 unsigned cb_color_info
= 0;
2505 for (i
= 0; i
< nr_cbufs
; i
++) {
2506 const struct radeon_surf_level
*level_info
;
2507 unsigned pitch_tile_max
, slice_tile_max
, tile_mode_index
;
2508 unsigned cb_color_base
, cb_color_fmask
, cb_color_attrib
;
2509 unsigned cb_color_pitch
, cb_color_slice
, cb_color_fmask_slice
;
2511 if (!(sctx
->framebuffer
.dirty_cbufs
& (1 << i
)))
2514 cb
= (struct r600_surface
*)state
->cbufs
[i
];
2516 radeon_set_context_reg(cs
, R_028C70_CB_COLOR0_INFO
+ i
* 0x3C,
2517 S_028C70_FORMAT(V_028C70_COLOR_INVALID
));
2521 tex
= (struct r600_texture
*)cb
->base
.texture
;
2522 level_info
= &tex
->surface
.level
[cb
->base
.u
.tex
.level
];
2523 radeon_add_to_buffer_list(&sctx
->b
, &sctx
->b
.gfx
,
2524 &tex
->resource
, RADEON_USAGE_READWRITE
,
2525 tex
->resource
.b
.b
.nr_samples
> 1 ?
2526 RADEON_PRIO_COLOR_BUFFER_MSAA
:
2527 RADEON_PRIO_COLOR_BUFFER
);
2529 if (tex
->cmask_buffer
&& tex
->cmask_buffer
!= &tex
->resource
) {
2530 radeon_add_to_buffer_list(&sctx
->b
, &sctx
->b
.gfx
,
2531 tex
->cmask_buffer
, RADEON_USAGE_READWRITE
,
2535 if (tex
->dcc_separate_buffer
)
2536 radeon_add_to_buffer_list(&sctx
->b
, &sctx
->b
.gfx
,
2537 tex
->dcc_separate_buffer
,
2538 RADEON_USAGE_READWRITE
,
2541 /* Compute mutable surface parameters. */
2542 pitch_tile_max
= level_info
->nblk_x
/ 8 - 1;
2543 slice_tile_max
= level_info
->nblk_x
*
2544 level_info
->nblk_y
/ 64 - 1;
2545 tile_mode_index
= si_tile_mode_index(tex
, cb
->base
.u
.tex
.level
, false);
2547 cb_color_base
= (tex
->resource
.gpu_address
+ level_info
->offset
) >> 8;
2548 cb_color_pitch
= S_028C64_TILE_MAX(pitch_tile_max
);
2549 cb_color_slice
= S_028C68_TILE_MAX(slice_tile_max
);
2550 cb_color_attrib
= cb
->cb_color_attrib
|
2551 S_028C74_TILE_MODE_INDEX(tile_mode_index
);
2553 if (tex
->fmask
.size
) {
2554 if (sctx
->b
.chip_class
>= CIK
)
2555 cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(tex
->fmask
.pitch_in_pixels
/ 8 - 1);
2556 cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tex
->fmask
.tile_mode_index
);
2557 cb_color_fmask
= (tex
->resource
.gpu_address
+ tex
->fmask
.offset
) >> 8;
2558 cb_color_fmask_slice
= S_028C88_TILE_MAX(tex
->fmask
.slice_tile_max
);
2560 /* This must be set for fast clear to work without FMASK. */
2561 if (sctx
->b
.chip_class
>= CIK
)
2562 cb_color_pitch
|= S_028C64_FMASK_TILE_MAX(pitch_tile_max
);
2563 cb_color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index
);
2564 cb_color_fmask
= cb_color_base
;
2565 cb_color_fmask_slice
= S_028C88_TILE_MAX(slice_tile_max
);
2568 cb_color_info
= cb
->cb_color_info
| tex
->cb_color_info
;
2570 if (tex
->dcc_offset
&& cb
->base
.u
.tex
.level
< tex
->surface
.num_dcc_levels
) {
2571 bool is_msaa_resolve_dst
= state
->cbufs
[0] &&
2572 state
->cbufs
[0]->texture
->nr_samples
> 1 &&
2573 state
->cbufs
[1] == &cb
->base
&&
2574 state
->cbufs
[1]->texture
->nr_samples
<= 1;
2576 if (!is_msaa_resolve_dst
)
2577 cb_color_info
|= S_028C70_DCC_ENABLE(1);
2580 radeon_set_context_reg_seq(cs
, R_028C60_CB_COLOR0_BASE
+ i
* 0x3C,
2581 sctx
->b
.chip_class
>= VI
? 14 : 13);
2582 radeon_emit(cs
, cb_color_base
); /* R_028C60_CB_COLOR0_BASE */
2583 radeon_emit(cs
, cb_color_pitch
); /* R_028C64_CB_COLOR0_PITCH */
2584 radeon_emit(cs
, cb_color_slice
); /* R_028C68_CB_COLOR0_SLICE */
2585 radeon_emit(cs
, cb
->cb_color_view
); /* R_028C6C_CB_COLOR0_VIEW */
2586 radeon_emit(cs
, cb_color_info
); /* R_028C70_CB_COLOR0_INFO */
2587 radeon_emit(cs
, cb_color_attrib
); /* R_028C74_CB_COLOR0_ATTRIB */
2588 radeon_emit(cs
, cb
->cb_dcc_control
); /* R_028C78_CB_COLOR0_DCC_CONTROL */
2589 radeon_emit(cs
, tex
->cmask
.base_address_reg
); /* R_028C7C_CB_COLOR0_CMASK */
2590 radeon_emit(cs
, tex
->cmask
.slice_tile_max
); /* R_028C80_CB_COLOR0_CMASK_SLICE */
2591 radeon_emit(cs
, cb_color_fmask
); /* R_028C84_CB_COLOR0_FMASK */
2592 radeon_emit(cs
, cb_color_fmask_slice
); /* R_028C88_CB_COLOR0_FMASK_SLICE */
2593 radeon_emit(cs
, tex
->color_clear_value
[0]); /* R_028C8C_CB_COLOR0_CLEAR_WORD0 */
2594 radeon_emit(cs
, tex
->color_clear_value
[1]); /* R_028C90_CB_COLOR0_CLEAR_WORD1 */
2596 if (sctx
->b
.chip_class
>= VI
) /* R_028C94_CB_COLOR0_DCC_BASE */
2597 radeon_emit(cs
, ((!tex
->dcc_separate_buffer
? tex
->resource
.gpu_address
: 0) +
2599 tex
->surface
.level
[cb
->base
.u
.tex
.level
].dcc_offset
) >> 8);
2602 if (sctx
->framebuffer
.dirty_cbufs
& (1 << i
))
2603 radeon_set_context_reg(cs
, R_028C70_CB_COLOR0_INFO
+ i
* 0x3C, 0);
2606 if (state
->zsbuf
&& sctx
->framebuffer
.dirty_zsbuf
) {
2607 struct r600_surface
*zb
= (struct r600_surface
*)state
->zsbuf
;
2608 struct r600_texture
*rtex
= (struct r600_texture
*)zb
->base
.texture
;
2610 radeon_add_to_buffer_list(&sctx
->b
, &sctx
->b
.gfx
,
2611 &rtex
->resource
, RADEON_USAGE_READWRITE
,
2612 zb
->base
.texture
->nr_samples
> 1 ?
2613 RADEON_PRIO_DEPTH_BUFFER_MSAA
:
2614 RADEON_PRIO_DEPTH_BUFFER
);
2616 if (zb
->db_htile_data_base
) {
2617 radeon_add_to_buffer_list(&sctx
->b
, &sctx
->b
.gfx
,
2618 rtex
->htile_buffer
, RADEON_USAGE_READWRITE
,
2622 radeon_set_context_reg(cs
, R_028008_DB_DEPTH_VIEW
, zb
->db_depth_view
);
2623 radeon_set_context_reg(cs
, R_028014_DB_HTILE_DATA_BASE
, zb
->db_htile_data_base
);
2625 radeon_set_context_reg_seq(cs
, R_02803C_DB_DEPTH_INFO
, 9);
2626 radeon_emit(cs
, zb
->db_depth_info
); /* R_02803C_DB_DEPTH_INFO */
2627 radeon_emit(cs
, zb
->db_z_info
| /* R_028040_DB_Z_INFO */
2628 S_028040_ZRANGE_PRECISION(rtex
->depth_clear_value
!= 0));
2629 radeon_emit(cs
, zb
->db_stencil_info
); /* R_028044_DB_STENCIL_INFO */
2630 radeon_emit(cs
, zb
->db_depth_base
); /* R_028048_DB_Z_READ_BASE */
2631 radeon_emit(cs
, zb
->db_stencil_base
); /* R_02804C_DB_STENCIL_READ_BASE */
2632 radeon_emit(cs
, zb
->db_depth_base
); /* R_028050_DB_Z_WRITE_BASE */
2633 radeon_emit(cs
, zb
->db_stencil_base
); /* R_028054_DB_STENCIL_WRITE_BASE */
2634 radeon_emit(cs
, zb
->db_depth_size
); /* R_028058_DB_DEPTH_SIZE */
2635 radeon_emit(cs
, zb
->db_depth_slice
); /* R_02805C_DB_DEPTH_SLICE */
2637 radeon_set_context_reg_seq(cs
, R_028028_DB_STENCIL_CLEAR
, 2);
2638 radeon_emit(cs
, rtex
->stencil_clear_value
); /* R_028028_DB_STENCIL_CLEAR */
2639 radeon_emit(cs
, fui(rtex
->depth_clear_value
)); /* R_02802C_DB_DEPTH_CLEAR */
2641 radeon_set_context_reg(cs
, R_028ABC_DB_HTILE_SURFACE
, zb
->db_htile_surface
);
2642 } else if (sctx
->framebuffer
.dirty_zsbuf
) {
2643 radeon_set_context_reg_seq(cs
, R_028040_DB_Z_INFO
, 2);
2644 radeon_emit(cs
, S_028040_FORMAT(V_028040_Z_INVALID
)); /* R_028040_DB_Z_INFO */
2645 radeon_emit(cs
, S_028044_FORMAT(V_028044_STENCIL_INVALID
)); /* R_028044_DB_STENCIL_INFO */
2648 /* Framebuffer dimensions. */
2649 /* PA_SC_WINDOW_SCISSOR_TL is set in si_init_config() */
2650 radeon_set_context_reg(cs
, R_028208_PA_SC_WINDOW_SCISSOR_BR
,
2651 S_028208_BR_X(state
->width
) | S_028208_BR_Y(state
->height
));
2653 sctx
->framebuffer
.dirty_cbufs
= 0;
2654 sctx
->framebuffer
.dirty_zsbuf
= false;
2657 static void si_emit_msaa_sample_locs(struct si_context
*sctx
,
2658 struct r600_atom
*atom
)
2660 struct radeon_winsys_cs
*cs
= sctx
->b
.gfx
.cs
;
2661 unsigned nr_samples
= sctx
->framebuffer
.nr_samples
;
2663 /* Smoothing (only possible with nr_samples == 1) uses the same
2664 * sample locations as the MSAA it simulates.
2666 if (nr_samples
<= 1 && sctx
->smoothing_enabled
)
2667 nr_samples
= SI_NUM_SMOOTH_AA_SAMPLES
;
2669 /* On Polaris, the small primitive filter uses the sample locations
2670 * even when MSAA is off, so we need to make sure they're set to 0.
2672 if (sctx
->b
.family
>= CHIP_POLARIS10
)
2673 nr_samples
= MAX2(nr_samples
, 1);
2675 if (nr_samples
>= 1 &&
2676 (nr_samples
!= sctx
->msaa_sample_locs
.nr_samples
)) {
2677 sctx
->msaa_sample_locs
.nr_samples
= nr_samples
;
2678 cayman_emit_msaa_sample_locs(cs
, nr_samples
);
2681 if (sctx
->b
.family
>= CHIP_POLARIS10
) {
2682 struct si_state_rasterizer
*rs
= sctx
->queued
.named
.rasterizer
;
2683 unsigned small_prim_filter_cntl
=
2684 S_028830_SMALL_PRIM_FILTER_ENABLE(1) |
2685 S_028830_LINE_FILTER_DISABLE(1); /* line bug */
2687 /* The alternative of setting sample locations to 0 would
2688 * require a DB flush to avoid Z errors, see
2689 * https://bugs.freedesktop.org/show_bug.cgi?id=96908
2691 if (sctx
->framebuffer
.nr_samples
> 1 && rs
&& !rs
->multisample_enable
)
2692 small_prim_filter_cntl
&= C_028830_SMALL_PRIM_FILTER_ENABLE
;
2694 radeon_set_context_reg(cs
, R_028830_PA_SU_SMALL_PRIM_FILTER_CNTL
,
2695 small_prim_filter_cntl
);
2699 static void si_emit_msaa_config(struct si_context
*sctx
, struct r600_atom
*atom
)
2701 struct radeon_winsys_cs
*cs
= sctx
->b
.gfx
.cs
;
2702 unsigned num_tile_pipes
= sctx
->screen
->b
.info
.num_tile_pipes
;
2703 /* 33% faster rendering to linear color buffers */
2704 bool dst_is_linear
= sctx
->framebuffer
.any_dst_linear
;
2705 unsigned sc_mode_cntl_1
=
2706 S_028A4C_WALK_SIZE(dst_is_linear
) |
2707 S_028A4C_WALK_FENCE_ENABLE(!dst_is_linear
) |
2708 S_028A4C_WALK_FENCE_SIZE(num_tile_pipes
== 2 ? 2 : 3) |
2710 S_028A4C_WALK_ALIGN8_PRIM_FITS_ST(1) |
2711 S_028A4C_SUPERTILE_WALK_ORDER_ENABLE(1) |
2712 S_028A4C_TILE_WALK_ORDER_ENABLE(1) |
2713 S_028A4C_MULTI_SHADER_ENGINE_PRIM_DISCARD_ENABLE(1) |
2714 S_028A4C_FORCE_EOV_CNTDWN_ENABLE(1) |
2715 S_028A4C_FORCE_EOV_REZ_ENABLE(1);
2717 cayman_emit_msaa_config(cs
, sctx
->framebuffer
.nr_samples
,
2718 sctx
->ps_iter_samples
,
2719 sctx
->smoothing_enabled
? SI_NUM_SMOOTH_AA_SAMPLES
: 0,
2723 static void si_set_min_samples(struct pipe_context
*ctx
, unsigned min_samples
)
2725 struct si_context
*sctx
= (struct si_context
*)ctx
;
2727 if (sctx
->ps_iter_samples
== min_samples
)
2730 sctx
->ps_iter_samples
= min_samples
;
2731 sctx
->do_update_shaders
= true;
2733 if (sctx
->framebuffer
.nr_samples
> 1)
2734 si_mark_atom_dirty(sctx
, &sctx
->msaa_config
);
2742 * Build the sampler view descriptor for a buffer texture.
2743 * @param state 256-bit descriptor; only the high 128 bits are filled in
2746 si_make_buffer_descriptor(struct si_screen
*screen
, struct r600_resource
*buf
,
2747 enum pipe_format format
,
2748 unsigned offset
, unsigned size
,
2751 const struct util_format_description
*desc
;
2754 unsigned num_records
;
2755 unsigned num_format
, data_format
;
2757 desc
= util_format_description(format
);
2758 first_non_void
= util_format_get_first_non_void_channel(format
);
2759 stride
= desc
->block
.bits
/ 8;
2760 num_format
= si_translate_buffer_numformat(&screen
->b
.b
, desc
, first_non_void
);
2761 data_format
= si_translate_buffer_dataformat(&screen
->b
.b
, desc
, first_non_void
);
2763 num_records
= size
/ stride
;
2764 num_records
= MIN2(num_records
, (buf
->b
.b
.width0
- offset
) / stride
);
2766 if (screen
->b
.chip_class
>= VI
)
2767 num_records
*= stride
;
2770 state
[5] = S_008F04_STRIDE(stride
);
2771 state
[6] = num_records
;
2772 state
[7] = S_008F0C_DST_SEL_X(si_map_swizzle(desc
->swizzle
[0])) |
2773 S_008F0C_DST_SEL_Y(si_map_swizzle(desc
->swizzle
[1])) |
2774 S_008F0C_DST_SEL_Z(si_map_swizzle(desc
->swizzle
[2])) |
2775 S_008F0C_DST_SEL_W(si_map_swizzle(desc
->swizzle
[3])) |
2776 S_008F0C_NUM_FORMAT(num_format
) |
2777 S_008F0C_DATA_FORMAT(data_format
);
2781 * Build the sampler view descriptor for a texture.
2784 si_make_texture_descriptor(struct si_screen
*screen
,
2785 struct r600_texture
*tex
,
2787 enum pipe_texture_target target
,
2788 enum pipe_format pipe_format
,
2789 const unsigned char state_swizzle
[4],
2790 unsigned first_level
, unsigned last_level
,
2791 unsigned first_layer
, unsigned last_layer
,
2792 unsigned width
, unsigned height
, unsigned depth
,
2794 uint32_t *fmask_state
)
2796 struct pipe_resource
*res
= &tex
->resource
.b
.b
;
2797 const struct util_format_description
*desc
;
2798 unsigned char swizzle
[4];
2800 unsigned num_format
, data_format
, type
;
2803 desc
= util_format_description(pipe_format
);
2805 if (desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
) {
2806 const unsigned char swizzle_xxxx
[4] = {0, 0, 0, 0};
2807 const unsigned char swizzle_yyyy
[4] = {1, 1, 1, 1};
2808 const unsigned char swizzle_wwww
[4] = {3, 3, 3, 3};
2810 switch (pipe_format
) {
2811 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
2812 case PIPE_FORMAT_X32_S8X24_UINT
:
2813 case PIPE_FORMAT_X8Z24_UNORM
:
2814 util_format_compose_swizzles(swizzle_yyyy
, state_swizzle
, swizzle
);
2816 case PIPE_FORMAT_X24S8_UINT
:
2818 * X24S8 is implemented as an 8_8_8_8 data format, to
2819 * fix texture gathers. This affects at least
2820 * GL45-CTS.texture_cube_map_array.sampling on VI.
2822 util_format_compose_swizzles(swizzle_wwww
, state_swizzle
, swizzle
);
2825 util_format_compose_swizzles(swizzle_xxxx
, state_swizzle
, swizzle
);
2828 util_format_compose_swizzles(desc
->swizzle
, state_swizzle
, swizzle
);
2831 first_non_void
= util_format_get_first_non_void_channel(pipe_format
);
2833 switch (pipe_format
) {
2834 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
2835 num_format
= V_008F14_IMG_NUM_FORMAT_UNORM
;
2838 if (first_non_void
< 0) {
2839 if (util_format_is_compressed(pipe_format
)) {
2840 switch (pipe_format
) {
2841 case PIPE_FORMAT_DXT1_SRGB
:
2842 case PIPE_FORMAT_DXT1_SRGBA
:
2843 case PIPE_FORMAT_DXT3_SRGBA
:
2844 case PIPE_FORMAT_DXT5_SRGBA
:
2845 case PIPE_FORMAT_BPTC_SRGBA
:
2846 case PIPE_FORMAT_ETC2_SRGB8
:
2847 case PIPE_FORMAT_ETC2_SRGB8A1
:
2848 case PIPE_FORMAT_ETC2_SRGBA8
:
2849 num_format
= V_008F14_IMG_NUM_FORMAT_SRGB
;
2851 case PIPE_FORMAT_RGTC1_SNORM
:
2852 case PIPE_FORMAT_LATC1_SNORM
:
2853 case PIPE_FORMAT_RGTC2_SNORM
:
2854 case PIPE_FORMAT_LATC2_SNORM
:
2855 case PIPE_FORMAT_ETC2_R11_SNORM
:
2856 case PIPE_FORMAT_ETC2_RG11_SNORM
:
2857 /* implies float, so use SNORM/UNORM to determine
2858 whether data is signed or not */
2859 case PIPE_FORMAT_BPTC_RGB_FLOAT
:
2860 num_format
= V_008F14_IMG_NUM_FORMAT_SNORM
;
2863 num_format
= V_008F14_IMG_NUM_FORMAT_UNORM
;
2866 } else if (desc
->layout
== UTIL_FORMAT_LAYOUT_SUBSAMPLED
) {
2867 num_format
= V_008F14_IMG_NUM_FORMAT_UNORM
;
2869 num_format
= V_008F14_IMG_NUM_FORMAT_FLOAT
;
2871 } else if (desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
) {
2872 num_format
= V_008F14_IMG_NUM_FORMAT_SRGB
;
2874 num_format
= V_008F14_IMG_NUM_FORMAT_UNORM
;
2876 switch (desc
->channel
[first_non_void
].type
) {
2877 case UTIL_FORMAT_TYPE_FLOAT
:
2878 num_format
= V_008F14_IMG_NUM_FORMAT_FLOAT
;
2880 case UTIL_FORMAT_TYPE_SIGNED
:
2881 if (desc
->channel
[first_non_void
].normalized
)
2882 num_format
= V_008F14_IMG_NUM_FORMAT_SNORM
;
2883 else if (desc
->channel
[first_non_void
].pure_integer
)
2884 num_format
= V_008F14_IMG_NUM_FORMAT_SINT
;
2886 num_format
= V_008F14_IMG_NUM_FORMAT_SSCALED
;
2888 case UTIL_FORMAT_TYPE_UNSIGNED
:
2889 if (desc
->channel
[first_non_void
].normalized
)
2890 num_format
= V_008F14_IMG_NUM_FORMAT_UNORM
;
2891 else if (desc
->channel
[first_non_void
].pure_integer
)
2892 num_format
= V_008F14_IMG_NUM_FORMAT_UINT
;
2894 num_format
= V_008F14_IMG_NUM_FORMAT_USCALED
;
2899 data_format
= si_translate_texformat(&screen
->b
.b
, pipe_format
, desc
, first_non_void
);
2900 if (data_format
== ~0) {
2905 (res
->target
== PIPE_TEXTURE_CUBE
||
2906 res
->target
== PIPE_TEXTURE_CUBE_ARRAY
||
2907 res
->target
== PIPE_TEXTURE_3D
)) {
2908 /* For the purpose of shader images, treat cube maps and 3D
2909 * textures as 2D arrays. For 3D textures, the address
2910 * calculations for mipmaps are different, so we rely on the
2911 * caller to effectively disable mipmaps.
2913 type
= V_008F1C_SQ_RSRC_IMG_2D_ARRAY
;
2915 assert(res
->target
!= PIPE_TEXTURE_3D
|| (first_level
== 0 && last_level
== 0));
2917 type
= si_tex_dim(res
->target
, target
, res
->nr_samples
);
2920 if (type
== V_008F1C_SQ_RSRC_IMG_1D_ARRAY
) {
2922 depth
= res
->array_size
;
2923 } else if (type
== V_008F1C_SQ_RSRC_IMG_2D_ARRAY
||
2924 type
== V_008F1C_SQ_RSRC_IMG_2D_MSAA_ARRAY
) {
2925 if (sampler
|| res
->target
!= PIPE_TEXTURE_3D
)
2926 depth
= res
->array_size
;
2927 } else if (type
== V_008F1C_SQ_RSRC_IMG_CUBE
)
2928 depth
= res
->array_size
/ 6;
2931 state
[1] = (S_008F14_DATA_FORMAT_GFX6(data_format
) |
2932 S_008F14_NUM_FORMAT_GFX6(num_format
));
2933 state
[2] = (S_008F18_WIDTH(width
- 1) |
2934 S_008F18_HEIGHT(height
- 1) |
2935 S_008F18_PERF_MOD(4));
2936 state
[3] = (S_008F1C_DST_SEL_X(si_map_swizzle(swizzle
[0])) |
2937 S_008F1C_DST_SEL_Y(si_map_swizzle(swizzle
[1])) |
2938 S_008F1C_DST_SEL_Z(si_map_swizzle(swizzle
[2])) |
2939 S_008F1C_DST_SEL_W(si_map_swizzle(swizzle
[3])) |
2940 S_008F1C_BASE_LEVEL(res
->nr_samples
> 1 ?
2942 S_008F1C_LAST_LEVEL(res
->nr_samples
> 1 ?
2943 util_logbase2(res
->nr_samples
) :
2945 S_008F1C_POW2_PAD(res
->last_level
> 0) |
2946 S_008F1C_TYPE(type
));
2947 state
[4] = S_008F20_DEPTH(depth
- 1);
2948 state
[5] = (S_008F24_BASE_ARRAY(first_layer
) |
2949 S_008F24_LAST_ARRAY(last_layer
));
2953 if (tex
->dcc_offset
) {
2954 unsigned swap
= r600_translate_colorswap(pipe_format
, false);
2956 state
[6] = S_008F28_ALPHA_IS_ON_MSB(swap
<= 1);
2958 /* The last dword is unused by hw. The shader uses it to clear
2959 * bits in the first dword of sampler state.
2961 if (screen
->b
.chip_class
<= CIK
&& res
->nr_samples
<= 1) {
2962 if (first_level
== last_level
)
2963 state
[7] = C_008F30_MAX_ANISO_RATIO
;
2965 state
[7] = 0xffffffff;
2969 /* Initialize the sampler view for FMASK. */
2970 if (tex
->fmask
.size
) {
2971 uint32_t fmask_format
;
2973 va
= tex
->resource
.gpu_address
+ tex
->fmask
.offset
;
2975 switch (res
->nr_samples
) {
2977 fmask_format
= V_008F14_IMG_DATA_FORMAT_FMASK8_S2_F2
;
2980 fmask_format
= V_008F14_IMG_DATA_FORMAT_FMASK8_S4_F4
;
2983 fmask_format
= V_008F14_IMG_DATA_FORMAT_FMASK32_S8_F8
;
2987 fmask_format
= V_008F14_IMG_DATA_FORMAT_INVALID
;
2990 fmask_state
[0] = va
>> 8;
2991 fmask_state
[1] = S_008F14_BASE_ADDRESS_HI(va
>> 40) |
2992 S_008F14_DATA_FORMAT_GFX6(fmask_format
) |
2993 S_008F14_NUM_FORMAT_GFX6(V_008F14_IMG_NUM_FORMAT_UINT
);
2994 fmask_state
[2] = S_008F18_WIDTH(width
- 1) |
2995 S_008F18_HEIGHT(height
- 1);
2996 fmask_state
[3] = S_008F1C_DST_SEL_X(V_008F1C_SQ_SEL_X
) |
2997 S_008F1C_DST_SEL_Y(V_008F1C_SQ_SEL_X
) |
2998 S_008F1C_DST_SEL_Z(V_008F1C_SQ_SEL_X
) |
2999 S_008F1C_DST_SEL_W(V_008F1C_SQ_SEL_X
) |
3000 S_008F1C_TILING_INDEX(tex
->fmask
.tile_mode_index
) |
3001 S_008F1C_TYPE(si_tex_dim(res
->target
, target
, 0));
3002 fmask_state
[4] = S_008F20_DEPTH(depth
- 1) |
3003 S_008F20_PITCH_GFX6(tex
->fmask
.pitch_in_pixels
- 1);
3004 fmask_state
[5] = S_008F24_BASE_ARRAY(first_layer
) |
3005 S_008F24_LAST_ARRAY(last_layer
);
3012 * Create a sampler view.
3014 * @param ctx context
3015 * @param texture texture
3016 * @param state sampler view template
3017 * @param width0 width0 override (for compressed textures as int)
3018 * @param height0 height0 override (for compressed textures as int)
3019 * @param force_level set the base address to the level (for compressed textures)
3021 struct pipe_sampler_view
*
3022 si_create_sampler_view_custom(struct pipe_context
*ctx
,
3023 struct pipe_resource
*texture
,
3024 const struct pipe_sampler_view
*state
,
3025 unsigned width0
, unsigned height0
,
3026 unsigned force_level
)
3028 struct si_context
*sctx
= (struct si_context
*)ctx
;
3029 struct si_sampler_view
*view
= CALLOC_STRUCT(si_sampler_view
);
3030 struct r600_texture
*tmp
= (struct r600_texture
*)texture
;
3031 unsigned base_level
, first_level
, last_level
;
3032 unsigned char state_swizzle
[4];
3033 unsigned height
, depth
, width
;
3034 unsigned last_layer
= state
->u
.tex
.last_layer
;
3035 enum pipe_format pipe_format
;
3036 const struct radeon_surf_level
*surflevel
;
3041 /* initialize base object */
3042 view
->base
= *state
;
3043 view
->base
.texture
= NULL
;
3044 view
->base
.reference
.count
= 1;
3045 view
->base
.context
= ctx
;
3048 pipe_resource_reference(&view
->base
.texture
, texture
);
3050 if (state
->format
== PIPE_FORMAT_X24S8_UINT
||
3051 state
->format
== PIPE_FORMAT_S8X24_UINT
||
3052 state
->format
== PIPE_FORMAT_X32_S8X24_UINT
||
3053 state
->format
== PIPE_FORMAT_S8_UINT
)
3054 view
->is_stencil_sampler
= true;
3056 /* Buffer resource. */
3057 if (texture
->target
== PIPE_BUFFER
) {
3058 si_make_buffer_descriptor(sctx
->screen
,
3059 (struct r600_resource
*)texture
,
3061 state
->u
.buf
.offset
,
3067 state_swizzle
[0] = state
->swizzle_r
;
3068 state_swizzle
[1] = state
->swizzle_g
;
3069 state_swizzle
[2] = state
->swizzle_b
;
3070 state_swizzle
[3] = state
->swizzle_a
;
3073 first_level
= state
->u
.tex
.first_level
;
3074 last_level
= state
->u
.tex
.last_level
;
3077 depth
= texture
->depth0
;
3080 assert(force_level
== first_level
&&
3081 force_level
== last_level
);
3082 base_level
= force_level
;
3085 width
= u_minify(width
, force_level
);
3086 height
= u_minify(height
, force_level
);
3087 depth
= u_minify(depth
, force_level
);
3090 /* This is not needed if state trackers set last_layer correctly. */
3091 if (state
->target
== PIPE_TEXTURE_1D
||
3092 state
->target
== PIPE_TEXTURE_2D
||
3093 state
->target
== PIPE_TEXTURE_RECT
||
3094 state
->target
== PIPE_TEXTURE_CUBE
)
3095 last_layer
= state
->u
.tex
.first_layer
;
3097 /* Texturing with separate depth and stencil. */
3098 pipe_format
= state
->format
;
3100 /* Depth/stencil texturing sometimes needs separate texture. */
3101 if (tmp
->is_depth
&& !r600_can_sample_zs(tmp
, view
->is_stencil_sampler
)) {
3102 if (!tmp
->flushed_depth_texture
&&
3103 !r600_init_flushed_depth_texture(ctx
, texture
, NULL
)) {
3104 pipe_resource_reference(&view
->base
.texture
, NULL
);
3109 assert(tmp
->flushed_depth_texture
);
3111 /* Override format for the case where the flushed texture
3112 * contains only Z or only S.
3114 if (tmp
->flushed_depth_texture
->resource
.b
.b
.format
!= tmp
->resource
.b
.b
.format
)
3115 pipe_format
= tmp
->flushed_depth_texture
->resource
.b
.b
.format
;
3117 tmp
= tmp
->flushed_depth_texture
;
3120 surflevel
= tmp
->surface
.level
;
3122 if (tmp
->db_compatible
) {
3123 if (!view
->is_stencil_sampler
)
3124 pipe_format
= tmp
->db_render_format
;
3126 switch (pipe_format
) {
3127 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
3128 pipe_format
= PIPE_FORMAT_Z32_FLOAT
;
3130 case PIPE_FORMAT_X8Z24_UNORM
:
3131 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
3132 /* Z24 is always stored like this for DB
3135 pipe_format
= PIPE_FORMAT_Z24X8_UNORM
;
3137 case PIPE_FORMAT_X24S8_UINT
:
3138 case PIPE_FORMAT_S8X24_UINT
:
3139 case PIPE_FORMAT_X32_S8X24_UINT
:
3140 pipe_format
= PIPE_FORMAT_S8_UINT
;
3141 surflevel
= tmp
->surface
.stencil_level
;
3147 vi_dcc_disable_if_incompatible_format(&sctx
->b
, texture
,
3148 state
->u
.tex
.first_level
,
3151 si_make_texture_descriptor(sctx
->screen
, tmp
, true,
3152 state
->target
, pipe_format
, state_swizzle
,
3153 first_level
, last_level
,
3154 state
->u
.tex
.first_layer
, last_layer
,
3155 width
, height
, depth
,
3156 view
->state
, view
->fmask_state
);
3158 view
->base_level_info
= &surflevel
[base_level
];
3159 view
->base_level
= base_level
;
3160 view
->block_width
= util_format_get_blockwidth(pipe_format
);
3164 static struct pipe_sampler_view
*
3165 si_create_sampler_view(struct pipe_context
*ctx
,
3166 struct pipe_resource
*texture
,
3167 const struct pipe_sampler_view
*state
)
3169 return si_create_sampler_view_custom(ctx
, texture
, state
,
3170 texture
? texture
->width0
: 0,
3171 texture
? texture
->height0
: 0, 0);
3174 static void si_sampler_view_destroy(struct pipe_context
*ctx
,
3175 struct pipe_sampler_view
*state
)
3177 struct si_sampler_view
*view
= (struct si_sampler_view
*)state
;
3179 pipe_resource_reference(&state
->texture
, NULL
);
3183 static bool wrap_mode_uses_border_color(unsigned wrap
, bool linear_filter
)
3185 return wrap
== PIPE_TEX_WRAP_CLAMP_TO_BORDER
||
3186 wrap
== PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
||
3188 (wrap
== PIPE_TEX_WRAP_CLAMP
||
3189 wrap
== PIPE_TEX_WRAP_MIRROR_CLAMP
));
3192 static bool sampler_state_needs_border_color(const struct pipe_sampler_state
*state
)
3194 bool linear_filter
= state
->min_img_filter
!= PIPE_TEX_FILTER_NEAREST
||
3195 state
->mag_img_filter
!= PIPE_TEX_FILTER_NEAREST
;
3197 return (state
->border_color
.ui
[0] || state
->border_color
.ui
[1] ||
3198 state
->border_color
.ui
[2] || state
->border_color
.ui
[3]) &&
3199 (wrap_mode_uses_border_color(state
->wrap_s
, linear_filter
) ||
3200 wrap_mode_uses_border_color(state
->wrap_t
, linear_filter
) ||
3201 wrap_mode_uses_border_color(state
->wrap_r
, linear_filter
));
3204 static void *si_create_sampler_state(struct pipe_context
*ctx
,
3205 const struct pipe_sampler_state
*state
)
3207 struct si_context
*sctx
= (struct si_context
*)ctx
;
3208 struct r600_common_screen
*rscreen
= sctx
->b
.screen
;
3209 struct si_sampler_state
*rstate
= CALLOC_STRUCT(si_sampler_state
);
3210 unsigned border_color_type
, border_color_index
= 0;
3211 unsigned max_aniso
= rscreen
->force_aniso
>= 0 ? rscreen
->force_aniso
3212 : state
->max_anisotropy
;
3213 unsigned max_aniso_ratio
= r600_tex_aniso_filter(max_aniso
);
3219 if (!sampler_state_needs_border_color(state
))
3220 border_color_type
= V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
3221 else if (state
->border_color
.f
[0] == 0 &&
3222 state
->border_color
.f
[1] == 0 &&
3223 state
->border_color
.f
[2] == 0 &&
3224 state
->border_color
.f
[3] == 0)
3225 border_color_type
= V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
3226 else if (state
->border_color
.f
[0] == 0 &&
3227 state
->border_color
.f
[1] == 0 &&
3228 state
->border_color
.f
[2] == 0 &&
3229 state
->border_color
.f
[3] == 1)
3230 border_color_type
= V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_BLACK
;
3231 else if (state
->border_color
.f
[0] == 1 &&
3232 state
->border_color
.f
[1] == 1 &&
3233 state
->border_color
.f
[2] == 1 &&
3234 state
->border_color
.f
[3] == 1)
3235 border_color_type
= V_008F3C_SQ_TEX_BORDER_COLOR_OPAQUE_WHITE
;
3239 border_color_type
= V_008F3C_SQ_TEX_BORDER_COLOR_REGISTER
;
3241 /* Check if the border has been uploaded already. */
3242 for (i
= 0; i
< sctx
->border_color_count
; i
++)
3243 if (memcmp(&sctx
->border_color_table
[i
], &state
->border_color
,
3244 sizeof(state
->border_color
)) == 0)
3247 if (i
>= SI_MAX_BORDER_COLORS
) {
3248 /* Getting 4096 unique border colors is very unlikely. */
3249 fprintf(stderr
, "radeonsi: The border color table is full. "
3250 "Any new border colors will be just black. "
3251 "Please file a bug.\n");
3252 border_color_type
= V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
3254 if (i
== sctx
->border_color_count
) {
3255 /* Upload a new border color. */
3256 memcpy(&sctx
->border_color_table
[i
], &state
->border_color
,
3257 sizeof(state
->border_color
));
3258 util_memcpy_cpu_to_le32(&sctx
->border_color_map
[i
],
3259 &state
->border_color
,
3260 sizeof(state
->border_color
));
3261 sctx
->border_color_count
++;
3264 border_color_index
= i
;
3269 rstate
->magic
= SI_SAMPLER_STATE_MAGIC
;
3271 rstate
->val
[0] = (S_008F30_CLAMP_X(si_tex_wrap(state
->wrap_s
)) |
3272 S_008F30_CLAMP_Y(si_tex_wrap(state
->wrap_t
)) |
3273 S_008F30_CLAMP_Z(si_tex_wrap(state
->wrap_r
)) |
3274 S_008F30_MAX_ANISO_RATIO(max_aniso_ratio
) |
3275 S_008F30_DEPTH_COMPARE_FUNC(si_tex_compare(state
->compare_func
)) |
3276 S_008F30_FORCE_UNNORMALIZED(!state
->normalized_coords
) |
3277 S_008F30_ANISO_THRESHOLD(max_aniso_ratio
>> 1) |
3278 S_008F30_ANISO_BIAS(max_aniso_ratio
) |
3279 S_008F30_DISABLE_CUBE_WRAP(!state
->seamless_cube_map
) |
3280 S_008F30_COMPAT_MODE(sctx
->b
.chip_class
>= VI
));
3281 rstate
->val
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(state
->min_lod
, 0, 15), 8)) |
3282 S_008F34_MAX_LOD(S_FIXED(CLAMP(state
->max_lod
, 0, 15), 8)) |
3283 S_008F34_PERF_MIP(max_aniso_ratio
? max_aniso_ratio
+ 6 : 0));
3284 rstate
->val
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(state
->lod_bias
, -16, 16), 8)) |
3285 S_008F38_XY_MAG_FILTER(eg_tex_filter(state
->mag_img_filter
, max_aniso
)) |
3286 S_008F38_XY_MIN_FILTER(eg_tex_filter(state
->min_img_filter
, max_aniso
)) |
3287 S_008F38_MIP_FILTER(si_tex_mipfilter(state
->min_mip_filter
)) |
3288 S_008F38_MIP_POINT_PRECLAMP(1) |
3289 S_008F38_DISABLE_LSB_CEIL(1) |
3290 S_008F38_FILTER_PREC_FIX(1) |
3291 S_008F38_ANISO_OVERRIDE(sctx
->b
.chip_class
>= VI
));
3292 rstate
->val
[3] = S_008F3C_BORDER_COLOR_PTR(border_color_index
) |
3293 S_008F3C_BORDER_COLOR_TYPE(border_color_type
);
3297 static void si_set_sample_mask(struct pipe_context
*ctx
, unsigned sample_mask
)
3299 struct si_context
*sctx
= (struct si_context
*)ctx
;
3301 if (sctx
->sample_mask
.sample_mask
== (uint16_t)sample_mask
)
3304 sctx
->sample_mask
.sample_mask
= sample_mask
;
3305 si_mark_atom_dirty(sctx
, &sctx
->sample_mask
.atom
);
3308 static void si_emit_sample_mask(struct si_context
*sctx
, struct r600_atom
*atom
)
3310 struct radeon_winsys_cs
*cs
= sctx
->b
.gfx
.cs
;
3311 unsigned mask
= sctx
->sample_mask
.sample_mask
;
3313 /* Needed for line and polygon smoothing as well as for the Polaris
3314 * small primitive filter. We expect the state tracker to take care of
3317 assert(mask
== 0xffff || sctx
->framebuffer
.nr_samples
> 1 ||
3318 (mask
& 1 && sctx
->blitter
->running
));
3320 radeon_set_context_reg_seq(cs
, R_028C38_PA_SC_AA_MASK_X0Y0_X1Y0
, 2);
3321 radeon_emit(cs
, mask
| (mask
<< 16));
3322 radeon_emit(cs
, mask
| (mask
<< 16));
3325 static void si_delete_sampler_state(struct pipe_context
*ctx
, void *state
)
3328 struct si_sampler_state
*s
= state
;
3330 assert(s
->magic
== SI_SAMPLER_STATE_MAGIC
);
3337 * Vertex elements & buffers
3340 static void *si_create_vertex_elements(struct pipe_context
*ctx
,
3342 const struct pipe_vertex_element
*elements
)
3344 struct si_vertex_element
*v
= CALLOC_STRUCT(si_vertex_element
);
3345 bool used
[SI_NUM_VERTEX_BUFFERS
] = {};
3348 assert(count
<= SI_MAX_ATTRIBS
);
3353 v
->desc_list_byte_size
= align(count
* 16, SI_CPDMA_ALIGNMENT
);
3355 for (i
= 0; i
< count
; ++i
) {
3356 const struct util_format_description
*desc
;
3357 const struct util_format_channel_description
*channel
;
3358 unsigned data_format
, num_format
;
3360 unsigned vbo_index
= elements
[i
].vertex_buffer_index
;
3361 unsigned char swizzle
[4];
3363 if (vbo_index
>= SI_NUM_VERTEX_BUFFERS
) {
3368 if (!used
[vbo_index
]) {
3369 v
->first_vb_use_mask
|= 1 << i
;
3370 used
[vbo_index
] = true;
3373 desc
= util_format_description(elements
[i
].src_format
);
3374 first_non_void
= util_format_get_first_non_void_channel(elements
[i
].src_format
);
3375 data_format
= si_translate_buffer_dataformat(ctx
->screen
, desc
, first_non_void
);
3376 num_format
= si_translate_buffer_numformat(ctx
->screen
, desc
, first_non_void
);
3377 channel
= first_non_void
>= 0 ? &desc
->channel
[first_non_void
] : NULL
;
3378 memcpy(swizzle
, desc
->swizzle
, sizeof(swizzle
));
3380 v
->format_size
[i
] = desc
->block
.bits
/ 8;
3382 /* The hardware always treats the 2-bit alpha channel as
3383 * unsigned, so a shader workaround is needed.
3385 if (data_format
== V_008F0C_BUF_DATA_FORMAT_2_10_10_10
) {
3386 if (num_format
== V_008F0C_BUF_NUM_FORMAT_SNORM
) {
3387 v
->fix_fetch
[i
] = SI_FIX_FETCH_A2_SNORM
;
3388 } else if (num_format
== V_008F0C_BUF_NUM_FORMAT_SSCALED
) {
3389 v
->fix_fetch
[i
] = SI_FIX_FETCH_A2_SSCALED
;
3390 } else if (num_format
== V_008F0C_BUF_NUM_FORMAT_SINT
) {
3391 /* This isn't actually used in OpenGL. */
3392 v
->fix_fetch
[i
] = SI_FIX_FETCH_A2_SINT
;
3394 } else if (channel
&& channel
->type
== UTIL_FORMAT_TYPE_FIXED
) {
3395 if (desc
->swizzle
[3] == PIPE_SWIZZLE_1
)
3396 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGBX_32_FIXED
;
3398 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGBA_32_FIXED
;
3399 } else if (channel
&& channel
->size
== 32 && !channel
->pure_integer
) {
3400 if (channel
->type
== UTIL_FORMAT_TYPE_SIGNED
) {
3401 if (channel
->normalized
) {
3402 if (desc
->swizzle
[3] == PIPE_SWIZZLE_1
)
3403 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGBX_32_SNORM
;
3405 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGBA_32_SNORM
;
3407 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGBA_32_SSCALED
;
3409 } else if (channel
->type
== UTIL_FORMAT_TYPE_UNSIGNED
) {
3410 if (channel
->normalized
) {
3411 if (desc
->swizzle
[3] == PIPE_SWIZZLE_1
)
3412 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGBX_32_UNORM
;
3414 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGBA_32_UNORM
;
3416 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGBA_32_USCALED
;
3419 } else if (channel
&& channel
->size
== 64 &&
3420 channel
->type
== UTIL_FORMAT_TYPE_FLOAT
) {
3421 switch (desc
->nr_channels
) {
3424 v
->fix_fetch
[i
] = SI_FIX_FETCH_RG_64_FLOAT
;
3425 swizzle
[0] = PIPE_SWIZZLE_X
;
3426 swizzle
[1] = PIPE_SWIZZLE_Y
;
3427 swizzle
[2] = desc
->nr_channels
== 2 ? PIPE_SWIZZLE_Z
: PIPE_SWIZZLE_0
;
3428 swizzle
[3] = desc
->nr_channels
== 2 ? PIPE_SWIZZLE_W
: PIPE_SWIZZLE_0
;
3431 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGB_64_FLOAT
;
3432 swizzle
[0] = PIPE_SWIZZLE_X
; /* 3 loads */
3433 swizzle
[1] = PIPE_SWIZZLE_Y
;
3434 swizzle
[2] = PIPE_SWIZZLE_0
;
3435 swizzle
[3] = PIPE_SWIZZLE_0
;
3438 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGBA_64_FLOAT
;
3439 swizzle
[0] = PIPE_SWIZZLE_X
; /* 2 loads */
3440 swizzle
[1] = PIPE_SWIZZLE_Y
;
3441 swizzle
[2] = PIPE_SWIZZLE_Z
;
3442 swizzle
[3] = PIPE_SWIZZLE_W
;
3447 } else if (channel
&& desc
->nr_channels
== 3) {
3448 assert(desc
->swizzle
[0] == PIPE_SWIZZLE_X
);
3450 if (channel
->size
== 8) {
3451 if (channel
->pure_integer
)
3452 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGB_8_INT
;
3454 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGB_8
;
3455 } else if (channel
->size
== 16) {
3456 if (channel
->pure_integer
)
3457 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGB_16_INT
;
3459 v
->fix_fetch
[i
] = SI_FIX_FETCH_RGB_16
;
3463 v
->rsrc_word3
[i
] = S_008F0C_DST_SEL_X(si_map_swizzle(swizzle
[0])) |
3464 S_008F0C_DST_SEL_Y(si_map_swizzle(swizzle
[1])) |
3465 S_008F0C_DST_SEL_Z(si_map_swizzle(swizzle
[2])) |
3466 S_008F0C_DST_SEL_W(si_map_swizzle(swizzle
[3])) |
3467 S_008F0C_NUM_FORMAT(num_format
) |
3468 S_008F0C_DATA_FORMAT(data_format
);
3470 memcpy(v
->elements
, elements
, sizeof(struct pipe_vertex_element
) * count
);
3475 static void si_bind_vertex_elements(struct pipe_context
*ctx
, void *state
)
3477 struct si_context
*sctx
= (struct si_context
*)ctx
;
3478 struct si_vertex_element
*v
= (struct si_vertex_element
*)state
;
3480 sctx
->vertex_elements
= v
;
3481 sctx
->vertex_buffers_dirty
= true;
3482 sctx
->do_update_shaders
= true;
3485 static void si_delete_vertex_element(struct pipe_context
*ctx
, void *state
)
3487 struct si_context
*sctx
= (struct si_context
*)ctx
;
3489 if (sctx
->vertex_elements
== state
)
3490 sctx
->vertex_elements
= NULL
;
3494 static void si_set_vertex_buffers(struct pipe_context
*ctx
,
3495 unsigned start_slot
, unsigned count
,
3496 const struct pipe_vertex_buffer
*buffers
)
3498 struct si_context
*sctx
= (struct si_context
*)ctx
;
3499 struct pipe_vertex_buffer
*dst
= sctx
->vertex_buffer
+ start_slot
;
3502 assert(start_slot
+ count
<= ARRAY_SIZE(sctx
->vertex_buffer
));
3505 for (i
= 0; i
< count
; i
++) {
3506 const struct pipe_vertex_buffer
*src
= buffers
+ i
;
3507 struct pipe_vertex_buffer
*dsti
= dst
+ i
;
3509 if (unlikely(src
->user_buffer
)) {
3510 /* Zero-stride attribs only. */
3511 assert(src
->stride
== 0);
3513 /* Assume that the user_buffer comes from
3514 * gl_current_attrib, which implies it has
3515 * 4 * 8 bytes (for dvec4 attributes).
3517 * Use const_uploader to upload into VRAM directly.
3519 u_upload_data(sctx
->b
.b
.const_uploader
, 0, 32, 32,
3521 &dsti
->buffer_offset
,
3525 struct pipe_resource
*buf
= src
->buffer
;
3527 pipe_resource_reference(&dsti
->buffer
, buf
);
3528 dsti
->buffer_offset
= src
->buffer_offset
;
3529 dsti
->stride
= src
->stride
;
3530 r600_context_add_resource_size(ctx
, buf
);
3532 r600_resource(buf
)->bind_history
|= PIPE_BIND_VERTEX_BUFFER
;
3536 for (i
= 0; i
< count
; i
++) {
3537 pipe_resource_reference(&dst
[i
].buffer
, NULL
);
3540 sctx
->vertex_buffers_dirty
= true;
3543 static void si_set_index_buffer(struct pipe_context
*ctx
,
3544 const struct pipe_index_buffer
*ib
)
3546 struct si_context
*sctx
= (struct si_context
*)ctx
;
3549 struct pipe_resource
*buf
= ib
->buffer
;
3551 pipe_resource_reference(&sctx
->index_buffer
.buffer
, buf
);
3552 memcpy(&sctx
->index_buffer
, ib
, sizeof(*ib
));
3553 r600_context_add_resource_size(ctx
, buf
);
3555 r600_resource(buf
)->bind_history
|= PIPE_BIND_INDEX_BUFFER
;
3557 pipe_resource_reference(&sctx
->index_buffer
.buffer
, NULL
);
3565 static void si_set_tess_state(struct pipe_context
*ctx
,
3566 const float default_outer_level
[4],
3567 const float default_inner_level
[2])
3569 struct si_context
*sctx
= (struct si_context
*)ctx
;
3570 struct pipe_constant_buffer cb
;
3573 memcpy(array
, default_outer_level
, sizeof(float) * 4);
3574 memcpy(array
+4, default_inner_level
, sizeof(float) * 2);
3577 cb
.user_buffer
= NULL
;
3578 cb
.buffer_size
= sizeof(array
);
3580 si_upload_const_buffer(sctx
, (struct r600_resource
**)&cb
.buffer
,
3581 (void*)array
, sizeof(array
),
3584 si_set_rw_buffer(sctx
, SI_HS_CONST_DEFAULT_TESS_LEVELS
, &cb
);
3585 pipe_resource_reference(&cb
.buffer
, NULL
);
3588 static void si_texture_barrier(struct pipe_context
*ctx
, unsigned flags
)
3590 struct si_context
*sctx
= (struct si_context
*)ctx
;
3592 sctx
->b
.flags
|= SI_CONTEXT_INV_VMEM_L1
|
3593 SI_CONTEXT_INV_GLOBAL_L2
|
3594 SI_CONTEXT_FLUSH_AND_INV_CB
;
3595 sctx
->framebuffer
.do_update_surf_dirtiness
= true;
3598 /* This only ensures coherency for shader image/buffer stores. */
3599 static void si_memory_barrier(struct pipe_context
*ctx
, unsigned flags
)
3601 struct si_context
*sctx
= (struct si_context
*)ctx
;
3603 /* Subsequent commands must wait for all shader invocations to
3605 sctx
->b
.flags
|= SI_CONTEXT_PS_PARTIAL_FLUSH
|
3606 SI_CONTEXT_CS_PARTIAL_FLUSH
;
3608 if (flags
& PIPE_BARRIER_CONSTANT_BUFFER
)
3609 sctx
->b
.flags
|= SI_CONTEXT_INV_SMEM_L1
|
3610 SI_CONTEXT_INV_VMEM_L1
;
3612 if (flags
& (PIPE_BARRIER_VERTEX_BUFFER
|
3613 PIPE_BARRIER_SHADER_BUFFER
|
3614 PIPE_BARRIER_TEXTURE
|
3615 PIPE_BARRIER_IMAGE
|
3616 PIPE_BARRIER_STREAMOUT_BUFFER
|
3617 PIPE_BARRIER_GLOBAL_BUFFER
)) {
3618 /* As far as I can tell, L1 contents are written back to L2
3619 * automatically at end of shader, but the contents of other
3620 * L1 caches might still be stale. */
3621 sctx
->b
.flags
|= SI_CONTEXT_INV_VMEM_L1
;
3624 if (flags
& PIPE_BARRIER_INDEX_BUFFER
) {
3625 /* Indices are read through TC L2 since VI.
3628 if (sctx
->screen
->b
.chip_class
<= CIK
)
3629 sctx
->b
.flags
|= SI_CONTEXT_WRITEBACK_GLOBAL_L2
;
3632 if (flags
& PIPE_BARRIER_FRAMEBUFFER
)
3633 sctx
->b
.flags
|= SI_CONTEXT_FLUSH_AND_INV_CB
|
3634 SI_CONTEXT_FLUSH_AND_INV_DB
;
3636 if (flags
& (PIPE_BARRIER_FRAMEBUFFER
|
3637 PIPE_BARRIER_INDIRECT_BUFFER
))
3638 sctx
->b
.flags
|= SI_CONTEXT_WRITEBACK_GLOBAL_L2
;
3641 static void *si_create_blend_custom(struct si_context
*sctx
, unsigned mode
)
3643 struct pipe_blend_state blend
;
3645 memset(&blend
, 0, sizeof(blend
));
3646 blend
.independent_blend_enable
= true;
3647 blend
.rt
[0].colormask
= 0xf;
3648 return si_create_blend_state_mode(&sctx
->b
.b
, &blend
, mode
);
3651 static void si_need_gfx_cs_space(struct pipe_context
*ctx
, unsigned num_dw
,
3652 bool include_draw_vbo
)
3654 si_need_cs_space((struct si_context
*)ctx
);
3657 static void si_init_config(struct si_context
*sctx
);
3659 void si_init_state_functions(struct si_context
*sctx
)
3661 si_init_external_atom(sctx
, &sctx
->b
.render_cond_atom
, &sctx
->atoms
.s
.render_cond
);
3662 si_init_external_atom(sctx
, &sctx
->b
.streamout
.begin_atom
, &sctx
->atoms
.s
.streamout_begin
);
3663 si_init_external_atom(sctx
, &sctx
->b
.streamout
.enable_atom
, &sctx
->atoms
.s
.streamout_enable
);
3664 si_init_external_atom(sctx
, &sctx
->b
.scissors
.atom
, &sctx
->atoms
.s
.scissors
);
3665 si_init_external_atom(sctx
, &sctx
->b
.viewports
.atom
, &sctx
->atoms
.s
.viewports
);
3667 si_init_atom(sctx
, &sctx
->framebuffer
.atom
, &sctx
->atoms
.s
.framebuffer
, si_emit_framebuffer_state
);
3668 si_init_atom(sctx
, &sctx
->msaa_sample_locs
.atom
, &sctx
->atoms
.s
.msaa_sample_locs
, si_emit_msaa_sample_locs
);
3669 si_init_atom(sctx
, &sctx
->db_render_state
, &sctx
->atoms
.s
.db_render_state
, si_emit_db_render_state
);
3670 si_init_atom(sctx
, &sctx
->msaa_config
, &sctx
->atoms
.s
.msaa_config
, si_emit_msaa_config
);
3671 si_init_atom(sctx
, &sctx
->sample_mask
.atom
, &sctx
->atoms
.s
.sample_mask
, si_emit_sample_mask
);
3672 si_init_atom(sctx
, &sctx
->cb_render_state
, &sctx
->atoms
.s
.cb_render_state
, si_emit_cb_render_state
);
3673 si_init_atom(sctx
, &sctx
->blend_color
.atom
, &sctx
->atoms
.s
.blend_color
, si_emit_blend_color
);
3674 si_init_atom(sctx
, &sctx
->clip_regs
, &sctx
->atoms
.s
.clip_regs
, si_emit_clip_regs
);
3675 si_init_atom(sctx
, &sctx
->clip_state
.atom
, &sctx
->atoms
.s
.clip_state
, si_emit_clip_state
);
3676 si_init_atom(sctx
, &sctx
->stencil_ref
.atom
, &sctx
->atoms
.s
.stencil_ref
, si_emit_stencil_ref
);
3678 sctx
->b
.b
.create_blend_state
= si_create_blend_state
;
3679 sctx
->b
.b
.bind_blend_state
= si_bind_blend_state
;
3680 sctx
->b
.b
.delete_blend_state
= si_delete_blend_state
;
3681 sctx
->b
.b
.set_blend_color
= si_set_blend_color
;
3683 sctx
->b
.b
.create_rasterizer_state
= si_create_rs_state
;
3684 sctx
->b
.b
.bind_rasterizer_state
= si_bind_rs_state
;
3685 sctx
->b
.b
.delete_rasterizer_state
= si_delete_rs_state
;
3687 sctx
->b
.b
.create_depth_stencil_alpha_state
= si_create_dsa_state
;
3688 sctx
->b
.b
.bind_depth_stencil_alpha_state
= si_bind_dsa_state
;
3689 sctx
->b
.b
.delete_depth_stencil_alpha_state
= si_delete_dsa_state
;
3691 sctx
->custom_dsa_flush
= si_create_db_flush_dsa(sctx
);
3692 sctx
->custom_blend_resolve
= si_create_blend_custom(sctx
, V_028808_CB_RESOLVE
);
3693 sctx
->custom_blend_decompress
= si_create_blend_custom(sctx
, V_028808_CB_FMASK_DECOMPRESS
);
3694 sctx
->custom_blend_fastclear
= si_create_blend_custom(sctx
, V_028808_CB_ELIMINATE_FAST_CLEAR
);
3695 sctx
->custom_blend_dcc_decompress
= si_create_blend_custom(sctx
, V_028808_CB_DCC_DECOMPRESS
);
3697 sctx
->b
.b
.set_clip_state
= si_set_clip_state
;
3698 sctx
->b
.b
.set_stencil_ref
= si_set_stencil_ref
;
3700 sctx
->b
.b
.set_framebuffer_state
= si_set_framebuffer_state
;
3701 sctx
->b
.b
.get_sample_position
= cayman_get_sample_position
;
3703 sctx
->b
.b
.create_sampler_state
= si_create_sampler_state
;
3704 sctx
->b
.b
.delete_sampler_state
= si_delete_sampler_state
;
3706 sctx
->b
.b
.create_sampler_view
= si_create_sampler_view
;
3707 sctx
->b
.b
.sampler_view_destroy
= si_sampler_view_destroy
;
3709 sctx
->b
.b
.set_sample_mask
= si_set_sample_mask
;
3711 sctx
->b
.b
.create_vertex_elements_state
= si_create_vertex_elements
;
3712 sctx
->b
.b
.bind_vertex_elements_state
= si_bind_vertex_elements
;
3713 sctx
->b
.b
.delete_vertex_elements_state
= si_delete_vertex_element
;
3714 sctx
->b
.b
.set_vertex_buffers
= si_set_vertex_buffers
;
3715 sctx
->b
.b
.set_index_buffer
= si_set_index_buffer
;
3717 sctx
->b
.b
.texture_barrier
= si_texture_barrier
;
3718 sctx
->b
.b
.memory_barrier
= si_memory_barrier
;
3719 sctx
->b
.b
.set_min_samples
= si_set_min_samples
;
3720 sctx
->b
.b
.set_tess_state
= si_set_tess_state
;
3722 sctx
->b
.b
.set_active_query_state
= si_set_active_query_state
;
3723 sctx
->b
.set_occlusion_query_state
= si_set_occlusion_query_state
;
3724 sctx
->b
.save_qbo_state
= si_save_qbo_state
;
3725 sctx
->b
.need_gfx_cs_space
= si_need_gfx_cs_space
;
3727 sctx
->b
.b
.draw_vbo
= si_draw_vbo
;
3729 si_init_config(sctx
);
3732 static uint32_t si_get_bo_metadata_word1(struct r600_common_screen
*rscreen
)
3734 return (ATI_VENDOR_ID
<< 16) | rscreen
->info
.pci_id
;
3737 static void si_query_opaque_metadata(struct r600_common_screen
*rscreen
,
3738 struct r600_texture
*rtex
,
3739 struct radeon_bo_metadata
*md
)
3741 struct si_screen
*sscreen
= (struct si_screen
*)rscreen
;
3742 struct pipe_resource
*res
= &rtex
->resource
.b
.b
;
3743 static const unsigned char swizzle
[] = {
3749 uint32_t desc
[8], i
;
3750 bool is_array
= util_resource_is_array_texture(res
);
3752 /* DRM 2.x.x doesn't support this. */
3753 if (rscreen
->info
.drm_major
!= 3)
3756 assert(rtex
->dcc_separate_buffer
== NULL
);
3757 assert(rtex
->fmask
.size
== 0);
3759 /* Metadata image format format version 1:
3760 * [0] = 1 (metadata format identifier)
3761 * [1] = (VENDOR_ID << 16) | PCI_ID
3762 * [2:9] = image descriptor for the whole resource
3763 * [2] is always 0, because the base address is cleared
3764 * [9] is the DCC offset bits [39:8] from the beginning of
3766 * [10:10+LAST_LEVEL] = mipmap level offset bits [39:8] for each level
3769 md
->metadata
[0] = 1; /* metadata image format version 1 */
3771 /* TILE_MODE_INDEX is ambiguous without a PCI ID. */
3772 md
->metadata
[1] = si_get_bo_metadata_word1(rscreen
);
3774 si_make_texture_descriptor(sscreen
, rtex
, true,
3775 res
->target
, res
->format
,
3776 swizzle
, 0, res
->last_level
, 0,
3777 is_array
? res
->array_size
- 1 : 0,
3778 res
->width0
, res
->height0
, res
->depth0
,
3781 si_set_mutable_tex_desc_fields(rtex
, &rtex
->surface
.level
[0], 0, 0,
3782 rtex
->surface
.blk_w
, false, desc
);
3784 /* Clear the base address and set the relative DCC offset. */
3786 desc
[1] &= C_008F14_BASE_ADDRESS_HI
;
3787 desc
[7] = rtex
->dcc_offset
>> 8;
3789 /* Dwords [2:9] contain the image descriptor. */
3790 memcpy(&md
->metadata
[2], desc
, sizeof(desc
));
3792 /* Dwords [10:..] contain the mipmap level offsets. */
3793 for (i
= 0; i
<= res
->last_level
; i
++)
3794 md
->metadata
[10+i
] = rtex
->surface
.level
[i
].offset
>> 8;
3796 md
->size_metadata
= (11 + res
->last_level
) * 4;
3799 static void si_apply_opaque_metadata(struct r600_common_screen
*rscreen
,
3800 struct r600_texture
*rtex
,
3801 struct radeon_bo_metadata
*md
)
3803 uint32_t *desc
= &md
->metadata
[2];
3805 if (rscreen
->chip_class
< VI
)
3808 /* Return if DCC is enabled. The texture should be set up with it
3811 if (md
->size_metadata
>= 11 * 4 &&
3812 md
->metadata
[0] != 0 &&
3813 md
->metadata
[1] == si_get_bo_metadata_word1(rscreen
) &&
3814 G_008F28_COMPRESSION_EN(desc
[6])) {
3815 assert(rtex
->dcc_offset
== ((uint64_t)desc
[7] << 8));
3819 /* Disable DCC. These are always set by texture_from_handle and must
3822 rtex
->dcc_offset
= 0;
3825 void si_init_screen_state_functions(struct si_screen
*sscreen
)
3827 sscreen
->b
.b
.is_format_supported
= si_is_format_supported
;
3828 sscreen
->b
.query_opaque_metadata
= si_query_opaque_metadata
;
3829 sscreen
->b
.apply_opaque_metadata
= si_apply_opaque_metadata
;
3833 si_write_harvested_raster_configs(struct si_context
*sctx
,
3834 struct si_pm4_state
*pm4
,
3835 unsigned raster_config
,
3836 unsigned raster_config_1
)
3838 unsigned sh_per_se
= MAX2(sctx
->screen
->b
.info
.max_sh_per_se
, 1);
3839 unsigned num_se
= MAX2(sctx
->screen
->b
.info
.max_se
, 1);
3840 unsigned rb_mask
= sctx
->screen
->b
.info
.enabled_rb_mask
;
3841 unsigned num_rb
= MIN2(sctx
->screen
->b
.info
.num_render_backends
, 16);
3842 unsigned rb_per_pkr
= MIN2(num_rb
/ num_se
/ sh_per_se
, 2);
3843 unsigned rb_per_se
= num_rb
/ num_se
;
3844 unsigned se_mask
[4];
3847 se_mask
[0] = ((1 << rb_per_se
) - 1);
3848 se_mask
[1] = (se_mask
[0] << rb_per_se
);
3849 se_mask
[2] = (se_mask
[1] << rb_per_se
);
3850 se_mask
[3] = (se_mask
[2] << rb_per_se
);
3852 se_mask
[0] &= rb_mask
;
3853 se_mask
[1] &= rb_mask
;
3854 se_mask
[2] &= rb_mask
;
3855 se_mask
[3] &= rb_mask
;
3857 assert(num_se
== 1 || num_se
== 2 || num_se
== 4);
3858 assert(sh_per_se
== 1 || sh_per_se
== 2);
3859 assert(rb_per_pkr
== 1 || rb_per_pkr
== 2);
3861 /* XXX: I can't figure out what the *_XSEL and *_YSEL
3862 * fields are for, so I'm leaving them as their default
3865 for (se
= 0; se
< num_se
; se
++) {
3866 unsigned raster_config_se
= raster_config
;
3867 unsigned pkr0_mask
= ((1 << rb_per_pkr
) - 1) << (se
* rb_per_se
);
3868 unsigned pkr1_mask
= pkr0_mask
<< rb_per_pkr
;
3869 int idx
= (se
/ 2) * 2;
3871 if ((num_se
> 1) && (!se_mask
[idx
] || !se_mask
[idx
+ 1])) {
3872 raster_config_se
&= C_028350_SE_MAP
;
3874 if (!se_mask
[idx
]) {
3876 S_028350_SE_MAP(V_028350_RASTER_CONFIG_SE_MAP_3
);
3879 S_028350_SE_MAP(V_028350_RASTER_CONFIG_SE_MAP_0
);
3883 pkr0_mask
&= rb_mask
;
3884 pkr1_mask
&= rb_mask
;
3885 if (rb_per_se
> 2 && (!pkr0_mask
|| !pkr1_mask
)) {
3886 raster_config_se
&= C_028350_PKR_MAP
;
3890 S_028350_PKR_MAP(V_028350_RASTER_CONFIG_PKR_MAP_3
);
3893 S_028350_PKR_MAP(V_028350_RASTER_CONFIG_PKR_MAP_0
);
3897 if (rb_per_se
>= 2) {
3898 unsigned rb0_mask
= 1 << (se
* rb_per_se
);
3899 unsigned rb1_mask
= rb0_mask
<< 1;
3901 rb0_mask
&= rb_mask
;
3902 rb1_mask
&= rb_mask
;
3903 if (!rb0_mask
|| !rb1_mask
) {
3904 raster_config_se
&= C_028350_RB_MAP_PKR0
;
3908 S_028350_RB_MAP_PKR0(V_028350_RASTER_CONFIG_RB_MAP_3
);
3911 S_028350_RB_MAP_PKR0(V_028350_RASTER_CONFIG_RB_MAP_0
);
3915 if (rb_per_se
> 2) {
3916 rb0_mask
= 1 << (se
* rb_per_se
+ rb_per_pkr
);
3917 rb1_mask
= rb0_mask
<< 1;
3918 rb0_mask
&= rb_mask
;
3919 rb1_mask
&= rb_mask
;
3920 if (!rb0_mask
|| !rb1_mask
) {
3921 raster_config_se
&= C_028350_RB_MAP_PKR1
;
3925 S_028350_RB_MAP_PKR1(V_028350_RASTER_CONFIG_RB_MAP_3
);
3928 S_028350_RB_MAP_PKR1(V_028350_RASTER_CONFIG_RB_MAP_0
);
3934 /* GRBM_GFX_INDEX has a different offset on SI and CI+ */
3935 if (sctx
->b
.chip_class
< CIK
)
3936 si_pm4_set_reg(pm4
, GRBM_GFX_INDEX
,
3937 SE_INDEX(se
) | SH_BROADCAST_WRITES
|
3938 INSTANCE_BROADCAST_WRITES
);
3940 si_pm4_set_reg(pm4
, R_030800_GRBM_GFX_INDEX
,
3941 S_030800_SE_INDEX(se
) | S_030800_SH_BROADCAST_WRITES(1) |
3942 S_030800_INSTANCE_BROADCAST_WRITES(1));
3943 si_pm4_set_reg(pm4
, R_028350_PA_SC_RASTER_CONFIG
, raster_config_se
);
3946 /* GRBM_GFX_INDEX has a different offset on SI and CI+ */
3947 if (sctx
->b
.chip_class
< CIK
)
3948 si_pm4_set_reg(pm4
, GRBM_GFX_INDEX
,
3949 SE_BROADCAST_WRITES
| SH_BROADCAST_WRITES
|
3950 INSTANCE_BROADCAST_WRITES
);
3952 si_pm4_set_reg(pm4
, R_030800_GRBM_GFX_INDEX
,
3953 S_030800_SE_BROADCAST_WRITES(1) | S_030800_SH_BROADCAST_WRITES(1) |
3954 S_030800_INSTANCE_BROADCAST_WRITES(1));
3956 if ((num_se
> 2) && ((!se_mask
[0] && !se_mask
[1]) ||
3957 (!se_mask
[2] && !se_mask
[3]))) {
3958 raster_config_1
&= C_028354_SE_PAIR_MAP
;
3960 if (!se_mask
[0] && !se_mask
[1]) {
3962 S_028354_SE_PAIR_MAP(V_028354_RASTER_CONFIG_SE_PAIR_MAP_3
);
3965 S_028354_SE_PAIR_MAP(V_028354_RASTER_CONFIG_SE_PAIR_MAP_0
);
3969 si_pm4_set_reg(pm4
, R_028354_PA_SC_RASTER_CONFIG_1
, raster_config_1
);
3973 static void si_init_config(struct si_context
*sctx
)
3975 struct si_screen
*sscreen
= sctx
->screen
;
3976 unsigned num_rb
= MIN2(sctx
->screen
->b
.info
.num_render_backends
, 16);
3977 unsigned rb_mask
= sctx
->screen
->b
.info
.enabled_rb_mask
;
3978 unsigned raster_config
, raster_config_1
;
3979 uint64_t border_color_va
= sctx
->border_color_buffer
->gpu_address
;
3980 struct si_pm4_state
*pm4
= CALLOC_STRUCT(si_pm4_state
);
3985 si_pm4_cmd_begin(pm4
, PKT3_CONTEXT_CONTROL
);
3986 si_pm4_cmd_add(pm4
, CONTEXT_CONTROL_LOAD_ENABLE(1));
3987 si_pm4_cmd_add(pm4
, CONTEXT_CONTROL_SHADOW_ENABLE(1));
3988 si_pm4_cmd_end(pm4
, false);
3990 si_pm4_set_reg(pm4
, R_028A18_VGT_HOS_MAX_TESS_LEVEL
, fui(64));
3991 si_pm4_set_reg(pm4
, R_028A1C_VGT_HOS_MIN_TESS_LEVEL
, fui(0));
3993 /* FIXME calculate these values somehow ??? */
3994 si_pm4_set_reg(pm4
, R_028A54_VGT_GS_PER_ES
, SI_GS_PER_ES
);
3995 si_pm4_set_reg(pm4
, R_028A58_VGT_ES_PER_GS
, 0x40);
3996 si_pm4_set_reg(pm4
, R_028A5C_VGT_GS_PER_VS
, 0x2);
3998 si_pm4_set_reg(pm4
, R_028A8C_VGT_PRIMITIVEID_RESET
, 0x0);
3999 si_pm4_set_reg(pm4
, R_028B28_VGT_STRMOUT_DRAW_OPAQUE_OFFSET
, 0);
4001 si_pm4_set_reg(pm4
, R_028B98_VGT_STRMOUT_BUFFER_CONFIG
, 0x0);
4002 si_pm4_set_reg(pm4
, R_028AB8_VGT_VTX_CNT_EN
, 0x0);
4003 if (sctx
->b
.chip_class
< CIK
)
4004 si_pm4_set_reg(pm4
, R_008A14_PA_CL_ENHANCE
, S_008A14_NUM_CLIP_SEQ(3) |
4005 S_008A14_CLIP_VTX_REORDER_ENA(1));
4007 si_pm4_set_reg(pm4
, R_028BD4_PA_SC_CENTROID_PRIORITY_0
, 0x76543210);
4008 si_pm4_set_reg(pm4
, R_028BD8_PA_SC_CENTROID_PRIORITY_1
, 0xfedcba98);
4010 si_pm4_set_reg(pm4
, R_02882C_PA_SU_PRIM_FILTER_CNTL
, 0);
4012 switch (sctx
->screen
->b
.family
) {
4015 raster_config
= 0x2a00126a;
4016 raster_config_1
= 0x00000000;
4019 raster_config
= 0x0000124a;
4020 raster_config_1
= 0x00000000;
4023 raster_config
= 0x00000082;
4024 raster_config_1
= 0x00000000;
4027 raster_config
= 0x00000000;
4028 raster_config_1
= 0x00000000;
4031 raster_config
= 0x16000012;
4032 raster_config_1
= 0x00000000;
4035 raster_config
= 0x3a00161a;
4036 raster_config_1
= 0x0000002e;
4039 if (sscreen
->b
.info
.cik_macrotile_mode_array
[0] == 0x000000e8) {
4040 /* old kernels with old tiling config */
4041 raster_config
= 0x16000012;
4042 raster_config_1
= 0x0000002a;
4044 raster_config
= 0x3a00161a;
4045 raster_config_1
= 0x0000002e;
4048 case CHIP_POLARIS10
:
4049 raster_config
= 0x16000012;
4050 raster_config_1
= 0x0000002a;
4052 case CHIP_POLARIS11
:
4053 case CHIP_POLARIS12
:
4054 raster_config
= 0x16000012;
4055 raster_config_1
= 0x00000000;
4058 raster_config
= 0x16000012;
4059 raster_config_1
= 0x0000002a;
4063 raster_config
= 0x00000000;
4065 raster_config
= 0x00000002;
4066 raster_config_1
= 0x00000000;
4069 raster_config
= 0x00000002;
4070 raster_config_1
= 0x00000000;
4073 /* KV should be 0x00000002, but that causes problems with radeon */
4074 raster_config
= 0x00000000; /* 0x00000002 */
4075 raster_config_1
= 0x00000000;
4080 raster_config
= 0x00000000;
4081 raster_config_1
= 0x00000000;
4085 "radeonsi: Unknown GPU, using 0 for raster_config\n");
4086 raster_config
= 0x00000000;
4087 raster_config_1
= 0x00000000;
4091 /* Always use the default config when all backends are enabled
4092 * (or when we failed to determine the enabled backends).
4094 if (!rb_mask
|| util_bitcount(rb_mask
) >= num_rb
) {
4095 si_pm4_set_reg(pm4
, R_028350_PA_SC_RASTER_CONFIG
,
4097 if (sctx
->b
.chip_class
>= CIK
)
4098 si_pm4_set_reg(pm4
, R_028354_PA_SC_RASTER_CONFIG_1
,
4101 si_write_harvested_raster_configs(sctx
, pm4
, raster_config
, raster_config_1
);
4104 si_pm4_set_reg(pm4
, R_028204_PA_SC_WINDOW_SCISSOR_TL
, S_028204_WINDOW_OFFSET_DISABLE(1));
4105 si_pm4_set_reg(pm4
, R_028240_PA_SC_GENERIC_SCISSOR_TL
, S_028240_WINDOW_OFFSET_DISABLE(1));
4106 si_pm4_set_reg(pm4
, R_028244_PA_SC_GENERIC_SCISSOR_BR
,
4107 S_028244_BR_X(16384) | S_028244_BR_Y(16384));
4108 si_pm4_set_reg(pm4
, R_028030_PA_SC_SCREEN_SCISSOR_TL
, 0);
4109 si_pm4_set_reg(pm4
, R_028034_PA_SC_SCREEN_SCISSOR_BR
,
4110 S_028034_BR_X(16384) | S_028034_BR_Y(16384));
4112 si_pm4_set_reg(pm4
, R_02820C_PA_SC_CLIPRECT_RULE
, 0xFFFF);
4113 si_pm4_set_reg(pm4
, R_028230_PA_SC_EDGERULE
,
4114 S_028230_ER_TRI(0xA) |
4115 S_028230_ER_POINT(0xA) |
4116 S_028230_ER_RECT(0xA) |
4117 /* Required by DX10_DIAMOND_TEST_ENA: */
4118 S_028230_ER_LINE_LR(0x1A) |
4119 S_028230_ER_LINE_RL(0x26) |
4120 S_028230_ER_LINE_TB(0xA) |
4121 S_028230_ER_LINE_BT(0xA));
4122 /* PA_SU_HARDWARE_SCREEN_OFFSET must be 0 due to hw bug on SI */
4123 si_pm4_set_reg(pm4
, R_028234_PA_SU_HARDWARE_SCREEN_OFFSET
, 0);
4124 si_pm4_set_reg(pm4
, R_028820_PA_CL_NANINF_CNTL
, 0);
4125 si_pm4_set_reg(pm4
, R_028AC0_DB_SRESULTS_COMPARE_STATE0
, 0x0);
4126 si_pm4_set_reg(pm4
, R_028AC4_DB_SRESULTS_COMPARE_STATE1
, 0x0);
4127 si_pm4_set_reg(pm4
, R_028AC8_DB_PRELOAD_CONTROL
, 0x0);
4128 si_pm4_set_reg(pm4
, R_02800C_DB_RENDER_OVERRIDE
, 0);
4130 si_pm4_set_reg(pm4
, R_028400_VGT_MAX_VTX_INDX
, ~0);
4131 si_pm4_set_reg(pm4
, R_028404_VGT_MIN_VTX_INDX
, 0);
4132 si_pm4_set_reg(pm4
, R_028408_VGT_INDX_OFFSET
, 0);
4134 if (sctx
->b
.chip_class
>= CIK
) {
4135 /* If this is 0, Bonaire can hang even if GS isn't being used.
4136 * Other chips are unaffected. These are suboptimal values,
4137 * but we don't use on-chip GS.
4139 si_pm4_set_reg(pm4
, R_028A44_VGT_GS_ONCHIP_CNTL
,
4140 S_028A44_ES_VERTS_PER_SUBGRP(64) |
4141 S_028A44_GS_PRIMS_PER_SUBGRP(4));
4143 si_pm4_set_reg(pm4
, R_00B51C_SPI_SHADER_PGM_RSRC3_LS
, S_00B51C_CU_EN(0xffff));
4144 si_pm4_set_reg(pm4
, R_00B41C_SPI_SHADER_PGM_RSRC3_HS
, 0);
4145 si_pm4_set_reg(pm4
, R_00B31C_SPI_SHADER_PGM_RSRC3_ES
, S_00B31C_CU_EN(0xffff));
4146 si_pm4_set_reg(pm4
, R_00B21C_SPI_SHADER_PGM_RSRC3_GS
, S_00B21C_CU_EN(0xffff));
4148 if (sscreen
->b
.info
.num_good_compute_units
/
4149 (sscreen
->b
.info
.max_se
* sscreen
->b
.info
.max_sh_per_se
) <= 4) {
4150 /* Too few available compute units per SH. Disallowing
4151 * VS to run on CU0 could hurt us more than late VS
4152 * allocation would help.
4154 * LATE_ALLOC_VS = 2 is the highest safe number.
4156 si_pm4_set_reg(pm4
, R_00B118_SPI_SHADER_PGM_RSRC3_VS
, S_00B118_CU_EN(0xffff));
4157 si_pm4_set_reg(pm4
, R_00B11C_SPI_SHADER_LATE_ALLOC_VS
, S_00B11C_LIMIT(2));
4159 /* Set LATE_ALLOC_VS == 31. It should be less than
4160 * the number of scratch waves. Limitations:
4161 * - VS can't execute on CU0.
4162 * - If HS writes outputs to LDS, LS can't execute on CU0.
4164 si_pm4_set_reg(pm4
, R_00B118_SPI_SHADER_PGM_RSRC3_VS
, S_00B118_CU_EN(0xfffe));
4165 si_pm4_set_reg(pm4
, R_00B11C_SPI_SHADER_LATE_ALLOC_VS
, S_00B11C_LIMIT(31));
4168 si_pm4_set_reg(pm4
, R_00B01C_SPI_SHADER_PGM_RSRC3_PS
, S_00B01C_CU_EN(0xffff));
4171 if (sctx
->b
.chip_class
>= VI
) {
4172 unsigned vgt_tess_distribution
;
4174 si_pm4_set_reg(pm4
, R_028424_CB_DCC_CONTROL
,
4175 S_028424_OVERWRITE_COMBINER_MRT_SHARING_DISABLE(1) |
4176 S_028424_OVERWRITE_COMBINER_WATERMARK(4));
4177 if (sctx
->b
.family
< CHIP_POLARIS10
)
4178 si_pm4_set_reg(pm4
, R_028C58_VGT_VERTEX_REUSE_BLOCK_CNTL
, 30);
4179 si_pm4_set_reg(pm4
, R_028C5C_VGT_OUT_DEALLOC_CNTL
, 32);
4181 vgt_tess_distribution
=
4182 S_028B50_ACCUM_ISOLINE(32) |
4183 S_028B50_ACCUM_TRI(11) |
4184 S_028B50_ACCUM_QUAD(11) |
4185 S_028B50_DONUT_SPLIT(16);
4187 /* Testing with Unigine Heaven extreme tesselation yielded best results
4188 * with TRAP_SPLIT = 3.
4190 if (sctx
->b
.family
== CHIP_FIJI
||
4191 sctx
->b
.family
>= CHIP_POLARIS10
)
4192 vgt_tess_distribution
|= S_028B50_TRAP_SPLIT(3);
4194 si_pm4_set_reg(pm4
, R_028B50_VGT_TESS_DISTRIBUTION
, vgt_tess_distribution
);
4196 si_pm4_set_reg(pm4
, R_028C58_VGT_VERTEX_REUSE_BLOCK_CNTL
, 14);
4197 si_pm4_set_reg(pm4
, R_028C5C_VGT_OUT_DEALLOC_CNTL
, 16);
4200 if (sctx
->b
.family
== CHIP_STONEY
)
4201 si_pm4_set_reg(pm4
, R_028C40_PA_SC_SHADER_CONTROL
, 0);
4203 si_pm4_set_reg(pm4
, R_028080_TA_BC_BASE_ADDR
, border_color_va
>> 8);
4204 if (sctx
->b
.chip_class
>= CIK
)
4205 si_pm4_set_reg(pm4
, R_028084_TA_BC_BASE_ADDR_HI
, border_color_va
>> 40);
4206 si_pm4_add_bo(pm4
, sctx
->border_color_buffer
, RADEON_USAGE_READ
,
4207 RADEON_PRIO_BORDER_COLORS
);
4209 si_pm4_upload_indirect_buffer(sctx
, pm4
);
4210 sctx
->init_config
= pm4
;