2 * Copyright 2012 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
24 * Christian König <christian.koenig@amd.com>
27 #include "util/u_memory.h"
28 #include "util/u_framebuffer.h"
29 #include "util/u_blitter.h"
30 #include "util/u_helpers.h"
31 #include "util/u_math.h"
32 #include "util/u_pack_color.h"
33 #include "util/u_upload_mgr.h"
34 #include "util/u_format_s3tc.h"
35 #include "tgsi/tgsi_parse.h"
36 #include "radeonsi_pipe.h"
37 #include "radeonsi_shader.h"
39 #include "../radeon/r600_cs.h"
42 static uint32_t cik_num_banks(uint32_t nbanks
)
46 return V_02803C_ADDR_SURF_2_BANK
;
48 return V_02803C_ADDR_SURF_4_BANK
;
51 return V_02803C_ADDR_SURF_8_BANK
;
53 return V_02803C_ADDR_SURF_16_BANK
;
58 static unsigned cik_tile_split(unsigned tile_split
)
62 tile_split
= V_028040_ADDR_SURF_TILE_SPLIT_64B
;
65 tile_split
= V_028040_ADDR_SURF_TILE_SPLIT_128B
;
68 tile_split
= V_028040_ADDR_SURF_TILE_SPLIT_256B
;
71 tile_split
= V_028040_ADDR_SURF_TILE_SPLIT_512B
;
75 tile_split
= V_028040_ADDR_SURF_TILE_SPLIT_1KB
;
78 tile_split
= V_028040_ADDR_SURF_TILE_SPLIT_2KB
;
81 tile_split
= V_028040_ADDR_SURF_TILE_SPLIT_4KB
;
87 static unsigned cik_macro_tile_aspect(unsigned macro_tile_aspect
)
89 switch (macro_tile_aspect
) {
92 macro_tile_aspect
= V_02803C_ADDR_SURF_MACRO_ASPECT_1
;
95 macro_tile_aspect
= V_02803C_ADDR_SURF_MACRO_ASPECT_2
;
98 macro_tile_aspect
= V_02803C_ADDR_SURF_MACRO_ASPECT_4
;
101 macro_tile_aspect
= V_02803C_ADDR_SURF_MACRO_ASPECT_8
;
104 return macro_tile_aspect
;
107 static unsigned cik_bank_wh(unsigned bankwh
)
112 bankwh
= V_02803C_ADDR_SURF_BANK_WIDTH_1
;
115 bankwh
= V_02803C_ADDR_SURF_BANK_WIDTH_2
;
118 bankwh
= V_02803C_ADDR_SURF_BANK_WIDTH_4
;
121 bankwh
= V_02803C_ADDR_SURF_BANK_WIDTH_8
;
127 static unsigned cik_db_pipe_config(unsigned tile_pipes
,
130 unsigned pipe_config
;
132 switch (tile_pipes
) {
134 pipe_config
= V_02803C_X_ADDR_SURF_P8_32X32_16X16
;
139 pipe_config
= V_02803C_X_ADDR_SURF_P4_16X16
;
141 pipe_config
= V_02803C_X_ADDR_SURF_P4_8X16
;
144 pipe_config
= V_02803C_ADDR_SURF_P2
;
151 * inferred framebuffer and blender state
153 static void si_update_fb_blend_state(struct r600_context
*rctx
)
155 struct si_pm4_state
*pm4
;
156 struct si_state_blend
*blend
= rctx
->queued
.named
.blend
;
162 pm4
= si_pm4_alloc_state(rctx
);
166 mask
= (1ULL << ((unsigned)rctx
->framebuffer
.nr_cbufs
* 4)) - 1;
167 mask
&= blend
->cb_target_mask
;
168 si_pm4_set_reg(pm4
, R_028238_CB_TARGET_MASK
, mask
);
170 si_pm4_set_state(rctx
, fb_blend
, pm4
);
177 static uint32_t si_translate_blend_function(int blend_func
)
179 switch (blend_func
) {
181 return V_028780_COMB_DST_PLUS_SRC
;
182 case PIPE_BLEND_SUBTRACT
:
183 return V_028780_COMB_SRC_MINUS_DST
;
184 case PIPE_BLEND_REVERSE_SUBTRACT
:
185 return V_028780_COMB_DST_MINUS_SRC
;
187 return V_028780_COMB_MIN_DST_SRC
;
189 return V_028780_COMB_MAX_DST_SRC
;
191 R600_ERR("Unknown blend function %d\n", blend_func
);
198 static uint32_t si_translate_blend_factor(int blend_fact
)
200 switch (blend_fact
) {
201 case PIPE_BLENDFACTOR_ONE
:
202 return V_028780_BLEND_ONE
;
203 case PIPE_BLENDFACTOR_SRC_COLOR
:
204 return V_028780_BLEND_SRC_COLOR
;
205 case PIPE_BLENDFACTOR_SRC_ALPHA
:
206 return V_028780_BLEND_SRC_ALPHA
;
207 case PIPE_BLENDFACTOR_DST_ALPHA
:
208 return V_028780_BLEND_DST_ALPHA
;
209 case PIPE_BLENDFACTOR_DST_COLOR
:
210 return V_028780_BLEND_DST_COLOR
;
211 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
:
212 return V_028780_BLEND_SRC_ALPHA_SATURATE
;
213 case PIPE_BLENDFACTOR_CONST_COLOR
:
214 return V_028780_BLEND_CONSTANT_COLOR
;
215 case PIPE_BLENDFACTOR_CONST_ALPHA
:
216 return V_028780_BLEND_CONSTANT_ALPHA
;
217 case PIPE_BLENDFACTOR_ZERO
:
218 return V_028780_BLEND_ZERO
;
219 case PIPE_BLENDFACTOR_INV_SRC_COLOR
:
220 return V_028780_BLEND_ONE_MINUS_SRC_COLOR
;
221 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
:
222 return V_028780_BLEND_ONE_MINUS_SRC_ALPHA
;
223 case PIPE_BLENDFACTOR_INV_DST_ALPHA
:
224 return V_028780_BLEND_ONE_MINUS_DST_ALPHA
;
225 case PIPE_BLENDFACTOR_INV_DST_COLOR
:
226 return V_028780_BLEND_ONE_MINUS_DST_COLOR
;
227 case PIPE_BLENDFACTOR_INV_CONST_COLOR
:
228 return V_028780_BLEND_ONE_MINUS_CONSTANT_COLOR
;
229 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
:
230 return V_028780_BLEND_ONE_MINUS_CONSTANT_ALPHA
;
231 case PIPE_BLENDFACTOR_SRC1_COLOR
:
232 return V_028780_BLEND_SRC1_COLOR
;
233 case PIPE_BLENDFACTOR_SRC1_ALPHA
:
234 return V_028780_BLEND_SRC1_ALPHA
;
235 case PIPE_BLENDFACTOR_INV_SRC1_COLOR
:
236 return V_028780_BLEND_INV_SRC1_COLOR
;
237 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA
:
238 return V_028780_BLEND_INV_SRC1_ALPHA
;
240 R600_ERR("Bad blend factor %d not supported!\n", blend_fact
);
247 static void *si_create_blend_state_mode(struct pipe_context
*ctx
,
248 const struct pipe_blend_state
*state
,
251 struct si_state_blend
*blend
= CALLOC_STRUCT(si_state_blend
);
252 struct si_pm4_state
*pm4
= &blend
->pm4
;
254 uint32_t color_control
;
259 blend
->alpha_to_one
= state
->alpha_to_one
;
261 color_control
= S_028808_MODE(mode
);
262 if (state
->logicop_enable
) {
263 color_control
|= S_028808_ROP3(state
->logicop_func
| (state
->logicop_func
<< 4));
265 color_control
|= S_028808_ROP3(0xcc);
267 si_pm4_set_reg(pm4
, R_028808_CB_COLOR_CONTROL
, color_control
);
269 si_pm4_set_reg(pm4
, R_028B70_DB_ALPHA_TO_MASK
,
270 S_028B70_ALPHA_TO_MASK_ENABLE(state
->alpha_to_coverage
) |
271 S_028B70_ALPHA_TO_MASK_OFFSET0(2) |
272 S_028B70_ALPHA_TO_MASK_OFFSET1(2) |
273 S_028B70_ALPHA_TO_MASK_OFFSET2(2) |
274 S_028B70_ALPHA_TO_MASK_OFFSET3(2));
276 blend
->cb_target_mask
= 0;
277 for (int i
= 0; i
< 8; i
++) {
278 /* state->rt entries > 0 only written if independent blending */
279 const int j
= state
->independent_blend_enable
? i
: 0;
281 unsigned eqRGB
= state
->rt
[j
].rgb_func
;
282 unsigned srcRGB
= state
->rt
[j
].rgb_src_factor
;
283 unsigned dstRGB
= state
->rt
[j
].rgb_dst_factor
;
284 unsigned eqA
= state
->rt
[j
].alpha_func
;
285 unsigned srcA
= state
->rt
[j
].alpha_src_factor
;
286 unsigned dstA
= state
->rt
[j
].alpha_dst_factor
;
288 unsigned blend_cntl
= 0;
290 /* we pretend 8 buffer are used, CB_SHADER_MASK will disable unused one */
291 blend
->cb_target_mask
|= state
->rt
[j
].colormask
<< (4 * i
);
293 if (!state
->rt
[j
].blend_enable
) {
294 si_pm4_set_reg(pm4
, R_028780_CB_BLEND0_CONTROL
+ i
* 4, blend_cntl
);
298 blend_cntl
|= S_028780_ENABLE(1);
299 blend_cntl
|= S_028780_COLOR_COMB_FCN(si_translate_blend_function(eqRGB
));
300 blend_cntl
|= S_028780_COLOR_SRCBLEND(si_translate_blend_factor(srcRGB
));
301 blend_cntl
|= S_028780_COLOR_DESTBLEND(si_translate_blend_factor(dstRGB
));
303 if (srcA
!= srcRGB
|| dstA
!= dstRGB
|| eqA
!= eqRGB
) {
304 blend_cntl
|= S_028780_SEPARATE_ALPHA_BLEND(1);
305 blend_cntl
|= S_028780_ALPHA_COMB_FCN(si_translate_blend_function(eqA
));
306 blend_cntl
|= S_028780_ALPHA_SRCBLEND(si_translate_blend_factor(srcA
));
307 blend_cntl
|= S_028780_ALPHA_DESTBLEND(si_translate_blend_factor(dstA
));
309 si_pm4_set_reg(pm4
, R_028780_CB_BLEND0_CONTROL
+ i
* 4, blend_cntl
);
315 static void *si_create_blend_state(struct pipe_context
*ctx
,
316 const struct pipe_blend_state
*state
)
318 return si_create_blend_state_mode(ctx
, state
, V_028808_CB_NORMAL
);
321 static void si_bind_blend_state(struct pipe_context
*ctx
, void *state
)
323 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
324 si_pm4_bind_state(rctx
, blend
, (struct si_state_blend
*)state
);
325 si_update_fb_blend_state(rctx
);
328 static void si_delete_blend_state(struct pipe_context
*ctx
, void *state
)
330 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
331 si_pm4_delete_state(rctx
, blend
, (struct si_state_blend
*)state
);
334 static void si_set_blend_color(struct pipe_context
*ctx
,
335 const struct pipe_blend_color
*state
)
337 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
338 struct si_pm4_state
*pm4
= si_pm4_alloc_state(rctx
);
343 si_pm4_set_reg(pm4
, R_028414_CB_BLEND_RED
, fui(state
->color
[0]));
344 si_pm4_set_reg(pm4
, R_028418_CB_BLEND_GREEN
, fui(state
->color
[1]));
345 si_pm4_set_reg(pm4
, R_02841C_CB_BLEND_BLUE
, fui(state
->color
[2]));
346 si_pm4_set_reg(pm4
, R_028420_CB_BLEND_ALPHA
, fui(state
->color
[3]));
348 si_pm4_set_state(rctx
, blend_color
, pm4
);
352 * Clipping, scissors and viewport
355 static void si_set_clip_state(struct pipe_context
*ctx
,
356 const struct pipe_clip_state
*state
)
358 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
359 struct si_pm4_state
*pm4
= si_pm4_alloc_state(rctx
);
360 struct pipe_constant_buffer cb
;
365 for (int i
= 0; i
< 6; i
++) {
366 si_pm4_set_reg(pm4
, R_0285BC_PA_CL_UCP_0_X
+ i
* 16,
367 fui(state
->ucp
[i
][0]));
368 si_pm4_set_reg(pm4
, R_0285C0_PA_CL_UCP_0_Y
+ i
* 16,
369 fui(state
->ucp
[i
][1]));
370 si_pm4_set_reg(pm4
, R_0285C4_PA_CL_UCP_0_Z
+ i
* 16,
371 fui(state
->ucp
[i
][2]));
372 si_pm4_set_reg(pm4
, R_0285C8_PA_CL_UCP_0_W
+ i
* 16,
373 fui(state
->ucp
[i
][3]));
377 cb
.user_buffer
= state
->ucp
;
378 cb
.buffer_offset
= 0;
379 cb
.buffer_size
= 4*4*8;
380 ctx
->set_constant_buffer(ctx
, PIPE_SHADER_VERTEX
, 1, &cb
);
381 pipe_resource_reference(&cb
.buffer
, NULL
);
383 si_pm4_set_state(rctx
, clip
, pm4
);
386 static void si_set_scissor_states(struct pipe_context
*ctx
,
388 unsigned num_scissors
,
389 const struct pipe_scissor_state
*state
)
391 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
392 struct si_pm4_state
*pm4
= si_pm4_alloc_state(rctx
);
398 tl
= S_028240_TL_X(state
->minx
) | S_028240_TL_Y(state
->miny
);
399 br
= S_028244_BR_X(state
->maxx
) | S_028244_BR_Y(state
->maxy
);
400 si_pm4_set_reg(pm4
, R_028210_PA_SC_CLIPRECT_0_TL
, tl
);
401 si_pm4_set_reg(pm4
, R_028214_PA_SC_CLIPRECT_0_BR
, br
);
402 si_pm4_set_reg(pm4
, R_028218_PA_SC_CLIPRECT_1_TL
, tl
);
403 si_pm4_set_reg(pm4
, R_02821C_PA_SC_CLIPRECT_1_BR
, br
);
404 si_pm4_set_reg(pm4
, R_028220_PA_SC_CLIPRECT_2_TL
, tl
);
405 si_pm4_set_reg(pm4
, R_028224_PA_SC_CLIPRECT_2_BR
, br
);
406 si_pm4_set_reg(pm4
, R_028228_PA_SC_CLIPRECT_3_TL
, tl
);
407 si_pm4_set_reg(pm4
, R_02822C_PA_SC_CLIPRECT_3_BR
, br
);
409 si_pm4_set_state(rctx
, scissor
, pm4
);
412 static void si_set_viewport_states(struct pipe_context
*ctx
,
414 unsigned num_viewports
,
415 const struct pipe_viewport_state
*state
)
417 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
418 struct si_state_viewport
*viewport
= CALLOC_STRUCT(si_state_viewport
);
419 struct si_pm4_state
*pm4
= &viewport
->pm4
;
421 if (viewport
== NULL
)
424 viewport
->viewport
= *state
;
425 si_pm4_set_reg(pm4
, R_0282D0_PA_SC_VPORT_ZMIN_0
, 0x00000000);
426 si_pm4_set_reg(pm4
, R_0282D4_PA_SC_VPORT_ZMAX_0
, 0x3F800000);
427 si_pm4_set_reg(pm4
, R_02843C_PA_CL_VPORT_XSCALE_0
, fui(state
->scale
[0]));
428 si_pm4_set_reg(pm4
, R_028440_PA_CL_VPORT_XOFFSET_0
, fui(state
->translate
[0]));
429 si_pm4_set_reg(pm4
, R_028444_PA_CL_VPORT_YSCALE_0
, fui(state
->scale
[1]));
430 si_pm4_set_reg(pm4
, R_028448_PA_CL_VPORT_YOFFSET_0
, fui(state
->translate
[1]));
431 si_pm4_set_reg(pm4
, R_02844C_PA_CL_VPORT_ZSCALE_0
, fui(state
->scale
[2]));
432 si_pm4_set_reg(pm4
, R_028450_PA_CL_VPORT_ZOFFSET_0
, fui(state
->translate
[2]));
433 si_pm4_set_reg(pm4
, R_028818_PA_CL_VTE_CNTL
, 0x0000043F);
435 si_pm4_set_state(rctx
, viewport
, viewport
);
439 * inferred state between framebuffer and rasterizer
441 static void si_update_fb_rs_state(struct r600_context
*rctx
)
443 struct si_state_rasterizer
*rs
= rctx
->queued
.named
.rasterizer
;
444 struct si_pm4_state
*pm4
;
445 unsigned offset_db_fmt_cntl
= 0, depth
;
448 if (!rs
|| !rctx
->framebuffer
.zsbuf
)
451 offset_units
= rctx
->queued
.named
.rasterizer
->offset_units
;
452 switch (rctx
->framebuffer
.zsbuf
->texture
->format
) {
453 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
454 case PIPE_FORMAT_X8Z24_UNORM
:
455 case PIPE_FORMAT_Z24X8_UNORM
:
456 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
458 offset_units
*= 2.0f
;
460 case PIPE_FORMAT_Z32_FLOAT
:
461 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
463 offset_units
*= 1.0f
;
464 offset_db_fmt_cntl
|= S_028B78_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
466 case PIPE_FORMAT_Z16_UNORM
:
468 offset_units
*= 4.0f
;
474 pm4
= si_pm4_alloc_state(rctx
);
479 /* FIXME some of those reg can be computed with cso */
480 offset_db_fmt_cntl
|= S_028B78_POLY_OFFSET_NEG_NUM_DB_BITS(depth
);
481 si_pm4_set_reg(pm4
, R_028B80_PA_SU_POLY_OFFSET_FRONT_SCALE
,
482 fui(rctx
->queued
.named
.rasterizer
->offset_scale
));
483 si_pm4_set_reg(pm4
, R_028B84_PA_SU_POLY_OFFSET_FRONT_OFFSET
, fui(offset_units
));
484 si_pm4_set_reg(pm4
, R_028B88_PA_SU_POLY_OFFSET_BACK_SCALE
,
485 fui(rctx
->queued
.named
.rasterizer
->offset_scale
));
486 si_pm4_set_reg(pm4
, R_028B8C_PA_SU_POLY_OFFSET_BACK_OFFSET
, fui(offset_units
));
487 si_pm4_set_reg(pm4
, R_028B78_PA_SU_POLY_OFFSET_DB_FMT_CNTL
, offset_db_fmt_cntl
);
489 si_pm4_set_state(rctx
, fb_rs
, pm4
);
496 static uint32_t si_translate_fill(uint32_t func
)
499 case PIPE_POLYGON_MODE_FILL
:
500 return V_028814_X_DRAW_TRIANGLES
;
501 case PIPE_POLYGON_MODE_LINE
:
502 return V_028814_X_DRAW_LINES
;
503 case PIPE_POLYGON_MODE_POINT
:
504 return V_028814_X_DRAW_POINTS
;
507 return V_028814_X_DRAW_POINTS
;
511 static void *si_create_rs_state(struct pipe_context
*ctx
,
512 const struct pipe_rasterizer_state
*state
)
514 struct si_state_rasterizer
*rs
= CALLOC_STRUCT(si_state_rasterizer
);
515 struct si_pm4_state
*pm4
= &rs
->pm4
;
517 unsigned prov_vtx
= 1, polygon_dual_mode
;
519 float psize_min
, psize_max
;
525 rs
->two_side
= state
->light_twoside
;
526 rs
->multisample_enable
= state
->multisample
;
527 rs
->clip_plane_enable
= state
->clip_plane_enable
;
528 rs
->line_stipple_enable
= state
->line_stipple_enable
;
530 polygon_dual_mode
= (state
->fill_front
!= PIPE_POLYGON_MODE_FILL
||
531 state
->fill_back
!= PIPE_POLYGON_MODE_FILL
);
533 if (state
->flatshade_first
)
536 rs
->flatshade
= state
->flatshade
;
537 rs
->sprite_coord_enable
= state
->sprite_coord_enable
;
538 rs
->pa_sc_line_stipple
= state
->line_stipple_enable
?
539 S_028A0C_LINE_PATTERN(state
->line_stipple_pattern
) |
540 S_028A0C_REPEAT_COUNT(state
->line_stipple_factor
) : 0;
541 rs
->pa_su_sc_mode_cntl
=
542 S_028814_PROVOKING_VTX_LAST(prov_vtx
) |
543 S_028814_CULL_FRONT(state
->rasterizer_discard
|| (state
->cull_face
& PIPE_FACE_FRONT
) ? 1 : 0) |
544 S_028814_CULL_BACK(state
->rasterizer_discard
|| (state
->cull_face
& PIPE_FACE_BACK
) ? 1 : 0) |
545 S_028814_FACE(!state
->front_ccw
) |
546 S_028814_POLY_OFFSET_FRONT_ENABLE(state
->offset_tri
) |
547 S_028814_POLY_OFFSET_BACK_ENABLE(state
->offset_tri
) |
548 S_028814_POLY_OFFSET_PARA_ENABLE(state
->offset_tri
) |
549 S_028814_POLY_MODE(polygon_dual_mode
) |
550 S_028814_POLYMODE_FRONT_PTYPE(si_translate_fill(state
->fill_front
)) |
551 S_028814_POLYMODE_BACK_PTYPE(si_translate_fill(state
->fill_back
));
552 rs
->pa_cl_clip_cntl
=
553 S_028810_PS_UCP_MODE(3) |
554 S_028810_ZCLIP_NEAR_DISABLE(!state
->depth_clip
) |
555 S_028810_ZCLIP_FAR_DISABLE(!state
->depth_clip
) |
556 S_028810_DX_RASTERIZATION_KILL(state
->rasterizer_discard
) |
557 S_028810_DX_LINEAR_ATTR_CLIP_ENA(1);
559 clip_rule
= state
->scissor
? 0xAAAA : 0xFFFF;
562 rs
->offset_units
= state
->offset_units
;
563 rs
->offset_scale
= state
->offset_scale
* 12.0f
;
565 tmp
= S_0286D4_FLAT_SHADE_ENA(1);
566 if (state
->sprite_coord_enable
) {
567 tmp
|= S_0286D4_PNT_SPRITE_ENA(1) |
568 S_0286D4_PNT_SPRITE_OVRD_X(V_0286D4_SPI_PNT_SPRITE_SEL_S
) |
569 S_0286D4_PNT_SPRITE_OVRD_Y(V_0286D4_SPI_PNT_SPRITE_SEL_T
) |
570 S_0286D4_PNT_SPRITE_OVRD_Z(V_0286D4_SPI_PNT_SPRITE_SEL_0
) |
571 S_0286D4_PNT_SPRITE_OVRD_W(V_0286D4_SPI_PNT_SPRITE_SEL_1
);
572 if (state
->sprite_coord_mode
!= PIPE_SPRITE_COORD_UPPER_LEFT
) {
573 tmp
|= S_0286D4_PNT_SPRITE_TOP_1(1);
576 si_pm4_set_reg(pm4
, R_0286D4_SPI_INTERP_CONTROL_0
, tmp
);
578 si_pm4_set_reg(pm4
, R_028820_PA_CL_NANINF_CNTL
, 0x00000000);
579 /* point size 12.4 fixed point */
580 tmp
= (unsigned)(state
->point_size
* 8.0);
581 si_pm4_set_reg(pm4
, R_028A00_PA_SU_POINT_SIZE
, S_028A00_HEIGHT(tmp
) | S_028A00_WIDTH(tmp
));
583 if (state
->point_size_per_vertex
) {
584 psize_min
= util_get_min_point_size(state
);
587 /* Force the point size to be as if the vertex output was disabled. */
588 psize_min
= state
->point_size
;
589 psize_max
= state
->point_size
;
591 /* Divide by two, because 0.5 = 1 pixel. */
592 si_pm4_set_reg(pm4
, R_028A04_PA_SU_POINT_MINMAX
,
593 S_028A04_MIN_SIZE(r600_pack_float_12p4(psize_min
/2)) |
594 S_028A04_MAX_SIZE(r600_pack_float_12p4(psize_max
/2)));
596 tmp
= (unsigned)state
->line_width
* 8;
597 si_pm4_set_reg(pm4
, R_028A08_PA_SU_LINE_CNTL
, S_028A08_WIDTH(tmp
));
598 si_pm4_set_reg(pm4
, R_028A48_PA_SC_MODE_CNTL_0
,
599 S_028A48_LINE_STIPPLE_ENABLE(state
->line_stipple_enable
) |
600 S_028A48_MSAA_ENABLE(state
->multisample
));
602 si_pm4_set_reg(pm4
, R_028BE4_PA_SU_VTX_CNTL
,
603 S_028BE4_PIX_CENTER(state
->half_pixel_center
) |
604 S_028BE4_QUANT_MODE(V_028BE4_X_16_8_FIXED_POINT_1_256TH
));
605 si_pm4_set_reg(pm4
, R_028BE8_PA_CL_GB_VERT_CLIP_ADJ
, 0x3F800000);
606 si_pm4_set_reg(pm4
, R_028BEC_PA_CL_GB_VERT_DISC_ADJ
, 0x3F800000);
607 si_pm4_set_reg(pm4
, R_028BF0_PA_CL_GB_HORZ_CLIP_ADJ
, 0x3F800000);
608 si_pm4_set_reg(pm4
, R_028BF4_PA_CL_GB_HORZ_DISC_ADJ
, 0x3F800000);
610 si_pm4_set_reg(pm4
, R_028B7C_PA_SU_POLY_OFFSET_CLAMP
, fui(state
->offset_clamp
));
611 si_pm4_set_reg(pm4
, R_02820C_PA_SC_CLIPRECT_RULE
, clip_rule
);
616 static void si_bind_rs_state(struct pipe_context
*ctx
, void *state
)
618 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
619 struct si_state_rasterizer
*rs
= (struct si_state_rasterizer
*)state
;
625 rctx
->sprite_coord_enable
= rs
->sprite_coord_enable
;
626 rctx
->pa_sc_line_stipple
= rs
->pa_sc_line_stipple
;
627 rctx
->pa_su_sc_mode_cntl
= rs
->pa_su_sc_mode_cntl
;
629 si_pm4_bind_state(rctx
, rasterizer
, rs
);
630 si_update_fb_rs_state(rctx
);
633 static void si_delete_rs_state(struct pipe_context
*ctx
, void *state
)
635 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
636 si_pm4_delete_state(rctx
, rasterizer
, (struct si_state_rasterizer
*)state
);
640 * infeered state between dsa and stencil ref
642 static void si_update_dsa_stencil_ref(struct r600_context
*rctx
)
644 struct si_pm4_state
*pm4
= si_pm4_alloc_state(rctx
);
645 struct pipe_stencil_ref
*ref
= &rctx
->stencil_ref
;
646 struct si_state_dsa
*dsa
= rctx
->queued
.named
.dsa
;
651 si_pm4_set_reg(pm4
, R_028430_DB_STENCILREFMASK
,
652 S_028430_STENCILTESTVAL(ref
->ref_value
[0]) |
653 S_028430_STENCILMASK(dsa
->valuemask
[0]) |
654 S_028430_STENCILWRITEMASK(dsa
->writemask
[0]) |
655 S_028430_STENCILOPVAL(1));
656 si_pm4_set_reg(pm4
, R_028434_DB_STENCILREFMASK_BF
,
657 S_028434_STENCILTESTVAL_BF(ref
->ref_value
[1]) |
658 S_028434_STENCILMASK_BF(dsa
->valuemask
[1]) |
659 S_028434_STENCILWRITEMASK_BF(dsa
->writemask
[1]) |
660 S_028434_STENCILOPVAL_BF(1));
662 si_pm4_set_state(rctx
, dsa_stencil_ref
, pm4
);
665 static void si_set_pipe_stencil_ref(struct pipe_context
*ctx
,
666 const struct pipe_stencil_ref
*state
)
668 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
669 rctx
->stencil_ref
= *state
;
670 si_update_dsa_stencil_ref(rctx
);
678 static uint32_t si_translate_stencil_op(int s_op
)
681 case PIPE_STENCIL_OP_KEEP
:
682 return V_02842C_STENCIL_KEEP
;
683 case PIPE_STENCIL_OP_ZERO
:
684 return V_02842C_STENCIL_ZERO
;
685 case PIPE_STENCIL_OP_REPLACE
:
686 return V_02842C_STENCIL_REPLACE_TEST
;
687 case PIPE_STENCIL_OP_INCR
:
688 return V_02842C_STENCIL_ADD_CLAMP
;
689 case PIPE_STENCIL_OP_DECR
:
690 return V_02842C_STENCIL_SUB_CLAMP
;
691 case PIPE_STENCIL_OP_INCR_WRAP
:
692 return V_02842C_STENCIL_ADD_WRAP
;
693 case PIPE_STENCIL_OP_DECR_WRAP
:
694 return V_02842C_STENCIL_SUB_WRAP
;
695 case PIPE_STENCIL_OP_INVERT
:
696 return V_02842C_STENCIL_INVERT
;
698 R600_ERR("Unknown stencil op %d", s_op
);
705 static void *si_create_dsa_state(struct pipe_context
*ctx
,
706 const struct pipe_depth_stencil_alpha_state
*state
)
708 struct si_state_dsa
*dsa
= CALLOC_STRUCT(si_state_dsa
);
709 struct si_pm4_state
*pm4
= &dsa
->pm4
;
710 unsigned db_depth_control
;
711 unsigned db_render_override
, db_render_control
;
712 uint32_t db_stencil_control
= 0;
718 dsa
->valuemask
[0] = state
->stencil
[0].valuemask
;
719 dsa
->valuemask
[1] = state
->stencil
[1].valuemask
;
720 dsa
->writemask
[0] = state
->stencil
[0].writemask
;
721 dsa
->writemask
[1] = state
->stencil
[1].writemask
;
723 db_depth_control
= S_028800_Z_ENABLE(state
->depth
.enabled
) |
724 S_028800_Z_WRITE_ENABLE(state
->depth
.writemask
) |
725 S_028800_ZFUNC(state
->depth
.func
);
728 if (state
->stencil
[0].enabled
) {
729 db_depth_control
|= S_028800_STENCIL_ENABLE(1);
730 db_depth_control
|= S_028800_STENCILFUNC(state
->stencil
[0].func
);
731 db_stencil_control
|= S_02842C_STENCILFAIL(si_translate_stencil_op(state
->stencil
[0].fail_op
));
732 db_stencil_control
|= S_02842C_STENCILZPASS(si_translate_stencil_op(state
->stencil
[0].zpass_op
));
733 db_stencil_control
|= S_02842C_STENCILZFAIL(si_translate_stencil_op(state
->stencil
[0].zfail_op
));
735 if (state
->stencil
[1].enabled
) {
736 db_depth_control
|= S_028800_BACKFACE_ENABLE(1);
737 db_depth_control
|= S_028800_STENCILFUNC_BF(state
->stencil
[1].func
);
738 db_stencil_control
|= S_02842C_STENCILFAIL_BF(si_translate_stencil_op(state
->stencil
[1].fail_op
));
739 db_stencil_control
|= S_02842C_STENCILZPASS_BF(si_translate_stencil_op(state
->stencil
[1].zpass_op
));
740 db_stencil_control
|= S_02842C_STENCILZFAIL_BF(si_translate_stencil_op(state
->stencil
[1].zfail_op
));
745 if (state
->alpha
.enabled
) {
746 dsa
->alpha_func
= state
->alpha
.func
;
747 dsa
->alpha_ref
= state
->alpha
.ref_value
;
749 si_pm4_set_reg(pm4
, R_00B030_SPI_SHADER_USER_DATA_PS_0
+
750 SI_SGPR_ALPHA_REF
* 4, fui(dsa
->alpha_ref
));
752 dsa
->alpha_func
= PIPE_FUNC_ALWAYS
;
756 db_render_control
= 0;
757 db_render_override
= S_02800C_FORCE_HIZ_ENABLE(V_02800C_FORCE_DISABLE
) |
758 S_02800C_FORCE_HIS_ENABLE0(V_02800C_FORCE_DISABLE
) |
759 S_02800C_FORCE_HIS_ENABLE1(V_02800C_FORCE_DISABLE
);
760 /* TODO db_render_override depends on query */
761 si_pm4_set_reg(pm4
, R_028020_DB_DEPTH_BOUNDS_MIN
, 0x00000000);
762 si_pm4_set_reg(pm4
, R_028024_DB_DEPTH_BOUNDS_MAX
, 0x00000000);
763 si_pm4_set_reg(pm4
, R_028028_DB_STENCIL_CLEAR
, 0x00000000);
764 si_pm4_set_reg(pm4
, R_02802C_DB_DEPTH_CLEAR
, 0x3F800000);
765 //si_pm4_set_reg(pm4, R_028410_SX_ALPHA_TEST_CONTROL, alpha_test_control);
766 si_pm4_set_reg(pm4
, R_028800_DB_DEPTH_CONTROL
, db_depth_control
);
767 si_pm4_set_reg(pm4
, R_028000_DB_RENDER_CONTROL
, db_render_control
);
768 si_pm4_set_reg(pm4
, R_02800C_DB_RENDER_OVERRIDE
, db_render_override
);
769 si_pm4_set_reg(pm4
, R_02842C_DB_STENCIL_CONTROL
, db_stencil_control
);
770 si_pm4_set_reg(pm4
, R_028AC0_DB_SRESULTS_COMPARE_STATE0
, 0x0);
771 si_pm4_set_reg(pm4
, R_028AC4_DB_SRESULTS_COMPARE_STATE1
, 0x0);
772 si_pm4_set_reg(pm4
, R_028AC8_DB_PRELOAD_CONTROL
, 0x0);
773 dsa
->db_render_override
= db_render_override
;
778 static void si_bind_dsa_state(struct pipe_context
*ctx
, void *state
)
780 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
781 struct si_state_dsa
*dsa
= state
;
786 si_pm4_bind_state(rctx
, dsa
, dsa
);
787 si_update_dsa_stencil_ref(rctx
);
790 static void si_delete_dsa_state(struct pipe_context
*ctx
, void *state
)
792 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
793 si_pm4_delete_state(rctx
, dsa
, (struct si_state_dsa
*)state
);
796 static void *si_create_db_flush_dsa(struct r600_context
*rctx
, bool copy_depth
,
797 bool copy_stencil
, int sample
)
799 struct pipe_depth_stencil_alpha_state dsa
;
800 struct si_state_dsa
*state
;
802 memset(&dsa
, 0, sizeof(dsa
));
804 state
= rctx
->b
.b
.create_depth_stencil_alpha_state(&rctx
->b
.b
, &dsa
);
805 if (copy_depth
|| copy_stencil
) {
806 si_pm4_set_reg(&state
->pm4
, R_028000_DB_RENDER_CONTROL
,
807 S_028000_DEPTH_COPY(copy_depth
) |
808 S_028000_STENCIL_COPY(copy_stencil
) |
809 S_028000_COPY_CENTROID(1) |
810 S_028000_COPY_SAMPLE(sample
));
812 si_pm4_set_reg(&state
->pm4
, R_028000_DB_RENDER_CONTROL
,
813 S_028000_DEPTH_COMPRESS_DISABLE(1) |
814 S_028000_STENCIL_COMPRESS_DISABLE(1));
815 si_pm4_set_reg(&state
->pm4
, R_02800C_DB_RENDER_OVERRIDE
,
816 S_02800C_FORCE_HIZ_ENABLE(V_02800C_FORCE_DISABLE
) |
817 S_02800C_FORCE_HIS_ENABLE0(V_02800C_FORCE_DISABLE
) |
818 S_02800C_FORCE_HIS_ENABLE1(V_02800C_FORCE_DISABLE
) |
819 S_02800C_DISABLE_TILE_RATE_TILES(1));
828 static uint32_t si_translate_colorformat(enum pipe_format format
)
830 const struct util_format_description
*desc
= util_format_description(format
);
832 #define HAS_SIZE(x,y,z,w) \
833 (desc->channel[0].size == (x) && desc->channel[1].size == (y) && \
834 desc->channel[2].size == (z) && desc->channel[3].size == (w))
836 if (format
== PIPE_FORMAT_R11G11B10_FLOAT
) /* isn't plain */
837 return V_028C70_COLOR_10_11_11
;
839 if (desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
)
840 return V_028C70_COLOR_INVALID
;
842 switch (desc
->nr_channels
) {
844 switch (desc
->channel
[0].size
) {
846 return V_028C70_COLOR_8
;
848 return V_028C70_COLOR_16
;
850 return V_028C70_COLOR_32
;
854 if (desc
->channel
[0].size
== desc
->channel
[1].size
) {
855 switch (desc
->channel
[0].size
) {
857 return V_028C70_COLOR_8_8
;
859 return V_028C70_COLOR_16_16
;
861 return V_028C70_COLOR_32_32
;
863 } else if (HAS_SIZE(8,24,0,0)) {
864 return V_028C70_COLOR_24_8
;
865 } else if (HAS_SIZE(24,8,0,0)) {
866 return V_028C70_COLOR_8_24
;
870 if (HAS_SIZE(5,6,5,0)) {
871 return V_028C70_COLOR_5_6_5
;
872 } else if (HAS_SIZE(32,8,24,0)) {
873 return V_028C70_COLOR_X24_8_32_FLOAT
;
877 if (desc
->channel
[0].size
== desc
->channel
[1].size
&&
878 desc
->channel
[0].size
== desc
->channel
[2].size
&&
879 desc
->channel
[0].size
== desc
->channel
[3].size
) {
880 switch (desc
->channel
[0].size
) {
882 return V_028C70_COLOR_4_4_4_4
;
884 return V_028C70_COLOR_8_8_8_8
;
886 return V_028C70_COLOR_16_16_16_16
;
888 return V_028C70_COLOR_32_32_32_32
;
890 } else if (HAS_SIZE(5,5,5,1)) {
891 return V_028C70_COLOR_1_5_5_5
;
892 } else if (HAS_SIZE(10,10,10,2)) {
893 return V_028C70_COLOR_2_10_10_10
;
897 return V_028C70_COLOR_INVALID
;
900 static uint32_t si_translate_colorswap(enum pipe_format format
)
902 const struct util_format_description
*desc
= util_format_description(format
);
904 #define HAS_SWIZZLE(chan,swz) (desc->swizzle[chan] == UTIL_FORMAT_SWIZZLE_##swz)
906 if (format
== PIPE_FORMAT_R11G11B10_FLOAT
) /* isn't plain */
907 return V_028C70_SWAP_STD
;
909 if (desc
->layout
!= UTIL_FORMAT_LAYOUT_PLAIN
)
912 switch (desc
->nr_channels
) {
914 if (HAS_SWIZZLE(0,X
))
915 return V_028C70_SWAP_STD
; /* X___ */
916 else if (HAS_SWIZZLE(3,X
))
917 return V_028C70_SWAP_ALT_REV
; /* ___X */
920 if ((HAS_SWIZZLE(0,X
) && HAS_SWIZZLE(1,Y
)) ||
921 (HAS_SWIZZLE(0,X
) && HAS_SWIZZLE(1,NONE
)) ||
922 (HAS_SWIZZLE(0,NONE
) && HAS_SWIZZLE(1,Y
)))
923 return V_028C70_SWAP_STD
; /* XY__ */
924 else if ((HAS_SWIZZLE(0,Y
) && HAS_SWIZZLE(1,X
)) ||
925 (HAS_SWIZZLE(0,Y
) && HAS_SWIZZLE(1,NONE
)) ||
926 (HAS_SWIZZLE(0,NONE
) && HAS_SWIZZLE(1,X
)))
927 return V_028C70_SWAP_STD_REV
; /* YX__ */
928 else if (HAS_SWIZZLE(0,X
) && HAS_SWIZZLE(3,Y
))
929 return V_028C70_SWAP_ALT
; /* X__Y */
932 if (HAS_SWIZZLE(0,X
))
933 return V_028C70_SWAP_STD
; /* XYZ */
934 else if (HAS_SWIZZLE(0,Z
))
935 return V_028C70_SWAP_STD_REV
; /* ZYX */
938 /* check the middle channels, the 1st and 4th channel can be NONE */
939 if (HAS_SWIZZLE(1,Y
) && HAS_SWIZZLE(2,Z
))
940 return V_028C70_SWAP_STD
; /* XYZW */
941 else if (HAS_SWIZZLE(1,Z
) && HAS_SWIZZLE(2,Y
))
942 return V_028C70_SWAP_STD_REV
; /* WZYX */
943 else if (HAS_SWIZZLE(1,Y
) && HAS_SWIZZLE(2,X
))
944 return V_028C70_SWAP_ALT
; /* ZYXW */
945 else if (HAS_SWIZZLE(1,X
) && HAS_SWIZZLE(2,Y
))
946 return V_028C70_SWAP_ALT_REV
; /* WXYZ */
952 static uint32_t si_colorformat_endian_swap(uint32_t colorformat
)
954 if (R600_BIG_ENDIAN
) {
955 switch(colorformat
) {
957 case V_028C70_COLOR_8
:
958 return V_028C70_ENDIAN_NONE
;
960 /* 16-bit buffers. */
961 case V_028C70_COLOR_5_6_5
:
962 case V_028C70_COLOR_1_5_5_5
:
963 case V_028C70_COLOR_4_4_4_4
:
964 case V_028C70_COLOR_16
:
965 case V_028C70_COLOR_8_8
:
966 return V_028C70_ENDIAN_8IN16
;
968 /* 32-bit buffers. */
969 case V_028C70_COLOR_8_8_8_8
:
970 case V_028C70_COLOR_2_10_10_10
:
971 case V_028C70_COLOR_8_24
:
972 case V_028C70_COLOR_24_8
:
973 case V_028C70_COLOR_16_16
:
974 return V_028C70_ENDIAN_8IN32
;
976 /* 64-bit buffers. */
977 case V_028C70_COLOR_16_16_16_16
:
978 return V_028C70_ENDIAN_8IN16
;
980 case V_028C70_COLOR_32_32
:
981 return V_028C70_ENDIAN_8IN32
;
983 /* 128-bit buffers. */
984 case V_028C70_COLOR_32_32_32_32
:
985 return V_028C70_ENDIAN_8IN32
;
987 return V_028C70_ENDIAN_NONE
; /* Unsupported. */
990 return V_028C70_ENDIAN_NONE
;
994 /* Returns the size in bits of the widest component of a CB format */
995 static unsigned si_colorformat_max_comp_size(uint32_t colorformat
)
997 switch(colorformat
) {
998 case V_028C70_COLOR_4_4_4_4
:
1001 case V_028C70_COLOR_1_5_5_5
:
1002 case V_028C70_COLOR_5_5_5_1
:
1005 case V_028C70_COLOR_5_6_5
:
1008 case V_028C70_COLOR_8
:
1009 case V_028C70_COLOR_8_8
:
1010 case V_028C70_COLOR_8_8_8_8
:
1013 case V_028C70_COLOR_10_10_10_2
:
1014 case V_028C70_COLOR_2_10_10_10
:
1017 case V_028C70_COLOR_10_11_11
:
1018 case V_028C70_COLOR_11_11_10
:
1021 case V_028C70_COLOR_16
:
1022 case V_028C70_COLOR_16_16
:
1023 case V_028C70_COLOR_16_16_16_16
:
1026 case V_028C70_COLOR_8_24
:
1027 case V_028C70_COLOR_24_8
:
1030 case V_028C70_COLOR_32
:
1031 case V_028C70_COLOR_32_32
:
1032 case V_028C70_COLOR_32_32_32_32
:
1033 case V_028C70_COLOR_X24_8_32_FLOAT
:
1037 assert(!"Unknown maximum component size");
1041 static uint32_t si_translate_dbformat(enum pipe_format format
)
1044 case PIPE_FORMAT_Z16_UNORM
:
1045 return V_028040_Z_16
;
1046 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
1047 case PIPE_FORMAT_X8Z24_UNORM
:
1048 case PIPE_FORMAT_Z24X8_UNORM
:
1049 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
1050 return V_028040_Z_24
; /* deprecated on SI */
1051 case PIPE_FORMAT_Z32_FLOAT
:
1052 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
1053 return V_028040_Z_32_FLOAT
;
1055 return V_028040_Z_INVALID
;
1060 * Texture translation
1063 static uint32_t si_translate_texformat(struct pipe_screen
*screen
,
1064 enum pipe_format format
,
1065 const struct util_format_description
*desc
,
1068 struct r600_screen
*rscreen
= (struct r600_screen
*)screen
;
1069 bool enable_s3tc
= rscreen
->b
.info
.drm_minor
>= 31;
1070 boolean uniform
= TRUE
;
1073 /* Colorspace (return non-RGB formats directly). */
1074 switch (desc
->colorspace
) {
1075 /* Depth stencil formats */
1076 case UTIL_FORMAT_COLORSPACE_ZS
:
1078 case PIPE_FORMAT_Z16_UNORM
:
1079 return V_008F14_IMG_DATA_FORMAT_16
;
1080 case PIPE_FORMAT_X24S8_UINT
:
1081 case PIPE_FORMAT_Z24X8_UNORM
:
1082 case PIPE_FORMAT_Z24_UNORM_S8_UINT
:
1083 return V_008F14_IMG_DATA_FORMAT_8_24
;
1084 case PIPE_FORMAT_X8Z24_UNORM
:
1085 case PIPE_FORMAT_S8X24_UINT
:
1086 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
1087 return V_008F14_IMG_DATA_FORMAT_24_8
;
1088 case PIPE_FORMAT_S8_UINT
:
1089 return V_008F14_IMG_DATA_FORMAT_8
;
1090 case PIPE_FORMAT_Z32_FLOAT
:
1091 return V_008F14_IMG_DATA_FORMAT_32
;
1092 case PIPE_FORMAT_X32_S8X24_UINT
:
1093 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
1094 return V_008F14_IMG_DATA_FORMAT_X24_8_32
;
1099 case UTIL_FORMAT_COLORSPACE_YUV
:
1100 goto out_unknown
; /* TODO */
1102 case UTIL_FORMAT_COLORSPACE_SRGB
:
1103 if (desc
->nr_channels
!= 4 && desc
->nr_channels
!= 1)
1111 if (desc
->layout
== UTIL_FORMAT_LAYOUT_RGTC
) {
1116 case PIPE_FORMAT_RGTC1_SNORM
:
1117 case PIPE_FORMAT_LATC1_SNORM
:
1118 case PIPE_FORMAT_RGTC1_UNORM
:
1119 case PIPE_FORMAT_LATC1_UNORM
:
1120 return V_008F14_IMG_DATA_FORMAT_BC4
;
1121 case PIPE_FORMAT_RGTC2_SNORM
:
1122 case PIPE_FORMAT_LATC2_SNORM
:
1123 case PIPE_FORMAT_RGTC2_UNORM
:
1124 case PIPE_FORMAT_LATC2_UNORM
:
1125 return V_008F14_IMG_DATA_FORMAT_BC5
;
1131 if (desc
->layout
== UTIL_FORMAT_LAYOUT_S3TC
) {
1136 if (!util_format_s3tc_enabled
) {
1141 case PIPE_FORMAT_DXT1_RGB
:
1142 case PIPE_FORMAT_DXT1_RGBA
:
1143 case PIPE_FORMAT_DXT1_SRGB
:
1144 case PIPE_FORMAT_DXT1_SRGBA
:
1145 return V_008F14_IMG_DATA_FORMAT_BC1
;
1146 case PIPE_FORMAT_DXT3_RGBA
:
1147 case PIPE_FORMAT_DXT3_SRGBA
:
1148 return V_008F14_IMG_DATA_FORMAT_BC2
;
1149 case PIPE_FORMAT_DXT5_RGBA
:
1150 case PIPE_FORMAT_DXT5_SRGBA
:
1151 return V_008F14_IMG_DATA_FORMAT_BC3
;
1157 if (format
== PIPE_FORMAT_R9G9B9E5_FLOAT
) {
1158 return V_008F14_IMG_DATA_FORMAT_5_9_9_9
;
1159 } else if (format
== PIPE_FORMAT_R11G11B10_FLOAT
) {
1160 return V_008F14_IMG_DATA_FORMAT_10_11_11
;
1163 /* R8G8Bx_SNORM - TODO CxV8U8 */
1165 /* See whether the components are of the same size. */
1166 for (i
= 1; i
< desc
->nr_channels
; i
++) {
1167 uniform
= uniform
&& desc
->channel
[0].size
== desc
->channel
[i
].size
;
1170 /* Non-uniform formats. */
1172 switch(desc
->nr_channels
) {
1174 if (desc
->channel
[0].size
== 5 &&
1175 desc
->channel
[1].size
== 6 &&
1176 desc
->channel
[2].size
== 5) {
1177 return V_008F14_IMG_DATA_FORMAT_5_6_5
;
1181 if (desc
->channel
[0].size
== 5 &&
1182 desc
->channel
[1].size
== 5 &&
1183 desc
->channel
[2].size
== 5 &&
1184 desc
->channel
[3].size
== 1) {
1185 return V_008F14_IMG_DATA_FORMAT_1_5_5_5
;
1187 if (desc
->channel
[0].size
== 10 &&
1188 desc
->channel
[1].size
== 10 &&
1189 desc
->channel
[2].size
== 10 &&
1190 desc
->channel
[3].size
== 2) {
1191 return V_008F14_IMG_DATA_FORMAT_2_10_10_10
;
1198 if (first_non_void
< 0 || first_non_void
> 3)
1201 /* uniform formats */
1202 switch (desc
->channel
[first_non_void
].size
) {
1204 switch (desc
->nr_channels
) {
1205 #if 0 /* Not supported for render targets */
1207 return V_008F14_IMG_DATA_FORMAT_4_4
;
1210 return V_008F14_IMG_DATA_FORMAT_4_4_4_4
;
1214 switch (desc
->nr_channels
) {
1216 return V_008F14_IMG_DATA_FORMAT_8
;
1218 return V_008F14_IMG_DATA_FORMAT_8_8
;
1220 return V_008F14_IMG_DATA_FORMAT_8_8_8_8
;
1224 switch (desc
->nr_channels
) {
1226 return V_008F14_IMG_DATA_FORMAT_16
;
1228 return V_008F14_IMG_DATA_FORMAT_16_16
;
1230 return V_008F14_IMG_DATA_FORMAT_16_16_16_16
;
1234 switch (desc
->nr_channels
) {
1236 return V_008F14_IMG_DATA_FORMAT_32
;
1238 return V_008F14_IMG_DATA_FORMAT_32_32
;
1239 #if 0 /* Not supported for render targets */
1241 return V_008F14_IMG_DATA_FORMAT_32_32_32
;
1244 return V_008F14_IMG_DATA_FORMAT_32_32_32_32
;
1249 /* R600_ERR("Unable to handle texformat %d %s\n", format, util_format_name(format)); */
1253 static unsigned si_tex_wrap(unsigned wrap
)
1257 case PIPE_TEX_WRAP_REPEAT
:
1258 return V_008F30_SQ_TEX_WRAP
;
1259 case PIPE_TEX_WRAP_CLAMP
:
1260 return V_008F30_SQ_TEX_CLAMP_HALF_BORDER
;
1261 case PIPE_TEX_WRAP_CLAMP_TO_EDGE
:
1262 return V_008F30_SQ_TEX_CLAMP_LAST_TEXEL
;
1263 case PIPE_TEX_WRAP_CLAMP_TO_BORDER
:
1264 return V_008F30_SQ_TEX_CLAMP_BORDER
;
1265 case PIPE_TEX_WRAP_MIRROR_REPEAT
:
1266 return V_008F30_SQ_TEX_MIRROR
;
1267 case PIPE_TEX_WRAP_MIRROR_CLAMP
:
1268 return V_008F30_SQ_TEX_MIRROR_ONCE_HALF_BORDER
;
1269 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_EDGE
:
1270 return V_008F30_SQ_TEX_MIRROR_ONCE_LAST_TEXEL
;
1271 case PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
:
1272 return V_008F30_SQ_TEX_MIRROR_ONCE_BORDER
;
1276 static unsigned si_tex_filter(unsigned filter
)
1280 case PIPE_TEX_FILTER_NEAREST
:
1281 return V_008F38_SQ_TEX_XY_FILTER_POINT
;
1282 case PIPE_TEX_FILTER_LINEAR
:
1283 return V_008F38_SQ_TEX_XY_FILTER_BILINEAR
;
1287 static unsigned si_tex_mipfilter(unsigned filter
)
1290 case PIPE_TEX_MIPFILTER_NEAREST
:
1291 return V_008F38_SQ_TEX_Z_FILTER_POINT
;
1292 case PIPE_TEX_MIPFILTER_LINEAR
:
1293 return V_008F38_SQ_TEX_Z_FILTER_LINEAR
;
1295 case PIPE_TEX_MIPFILTER_NONE
:
1296 return V_008F38_SQ_TEX_Z_FILTER_NONE
;
1300 static unsigned si_tex_compare(unsigned compare
)
1304 case PIPE_FUNC_NEVER
:
1305 return V_008F30_SQ_TEX_DEPTH_COMPARE_NEVER
;
1306 case PIPE_FUNC_LESS
:
1307 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESS
;
1308 case PIPE_FUNC_EQUAL
:
1309 return V_008F30_SQ_TEX_DEPTH_COMPARE_EQUAL
;
1310 case PIPE_FUNC_LEQUAL
:
1311 return V_008F30_SQ_TEX_DEPTH_COMPARE_LESSEQUAL
;
1312 case PIPE_FUNC_GREATER
:
1313 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATER
;
1314 case PIPE_FUNC_NOTEQUAL
:
1315 return V_008F30_SQ_TEX_DEPTH_COMPARE_NOTEQUAL
;
1316 case PIPE_FUNC_GEQUAL
:
1317 return V_008F30_SQ_TEX_DEPTH_COMPARE_GREATEREQUAL
;
1318 case PIPE_FUNC_ALWAYS
:
1319 return V_008F30_SQ_TEX_DEPTH_COMPARE_ALWAYS
;
1323 static unsigned si_tex_dim(unsigned dim
, unsigned nr_samples
)
1327 case PIPE_TEXTURE_1D
:
1328 return V_008F1C_SQ_RSRC_IMG_1D
;
1329 case PIPE_TEXTURE_1D_ARRAY
:
1330 return V_008F1C_SQ_RSRC_IMG_1D_ARRAY
;
1331 case PIPE_TEXTURE_2D
:
1332 case PIPE_TEXTURE_RECT
:
1333 return nr_samples
> 1 ? V_008F1C_SQ_RSRC_IMG_2D_MSAA
:
1334 V_008F1C_SQ_RSRC_IMG_2D
;
1335 case PIPE_TEXTURE_2D_ARRAY
:
1336 return nr_samples
> 1 ? V_008F1C_SQ_RSRC_IMG_2D_MSAA_ARRAY
:
1337 V_008F1C_SQ_RSRC_IMG_2D_ARRAY
;
1338 case PIPE_TEXTURE_3D
:
1339 return V_008F1C_SQ_RSRC_IMG_3D
;
1340 case PIPE_TEXTURE_CUBE
:
1341 return V_008F1C_SQ_RSRC_IMG_CUBE
;
1346 * Format support testing
1349 static bool si_is_sampler_format_supported(struct pipe_screen
*screen
, enum pipe_format format
)
1351 return si_translate_texformat(screen
, format
, util_format_description(format
),
1352 util_format_get_first_non_void_channel(format
)) != ~0U;
1355 static uint32_t si_translate_vertexformat(struct pipe_screen
*screen
,
1356 enum pipe_format format
,
1357 const struct util_format_description
*desc
,
1360 unsigned type
= desc
->channel
[first_non_void
].type
;
1363 if (type
== UTIL_FORMAT_TYPE_FIXED
)
1364 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
1366 /* See whether the components are of the same size. */
1367 for (i
= 0; i
< desc
->nr_channels
; i
++) {
1368 if (desc
->channel
[first_non_void
].size
!= desc
->channel
[i
].size
)
1369 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
1372 switch (desc
->channel
[first_non_void
].size
) {
1374 switch (desc
->nr_channels
) {
1376 return V_008F0C_BUF_DATA_FORMAT_8
;
1378 return V_008F0C_BUF_DATA_FORMAT_8_8
;
1381 return V_008F0C_BUF_DATA_FORMAT_8_8_8_8
;
1385 switch (desc
->nr_channels
) {
1387 return V_008F0C_BUF_DATA_FORMAT_16
;
1389 return V_008F0C_BUF_DATA_FORMAT_16_16
;
1392 return V_008F0C_BUF_DATA_FORMAT_16_16_16_16
;
1396 /* From the Southern Islands ISA documentation about MTBUF:
1397 * 'Memory reads of data in memory that is 32 or 64 bits do not
1398 * undergo any format conversion.'
1400 if (type
!= UTIL_FORMAT_TYPE_FLOAT
&&
1401 !desc
->channel
[first_non_void
].pure_integer
)
1402 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
1404 switch (desc
->nr_channels
) {
1406 return V_008F0C_BUF_DATA_FORMAT_32
;
1408 return V_008F0C_BUF_DATA_FORMAT_32_32
;
1410 return V_008F0C_BUF_DATA_FORMAT_32_32_32
;
1412 return V_008F0C_BUF_DATA_FORMAT_32_32_32_32
;
1417 return V_008F0C_BUF_DATA_FORMAT_INVALID
;
1420 static bool si_is_vertex_format_supported(struct pipe_screen
*screen
, enum pipe_format format
)
1422 const struct util_format_description
*desc
;
1424 unsigned data_format
;
1426 desc
= util_format_description(format
);
1427 first_non_void
= util_format_get_first_non_void_channel(format
);
1428 data_format
= si_translate_vertexformat(screen
, format
, desc
, first_non_void
);
1429 return data_format
!= V_008F0C_BUF_DATA_FORMAT_INVALID
;
1432 static bool si_is_colorbuffer_format_supported(enum pipe_format format
)
1434 return si_translate_colorformat(format
) != V_028C70_COLOR_INVALID
&&
1435 si_translate_colorswap(format
) != ~0U;
1438 static bool si_is_zs_format_supported(enum pipe_format format
)
1440 return si_translate_dbformat(format
) != V_028040_Z_INVALID
;
1443 boolean
si_is_format_supported(struct pipe_screen
*screen
,
1444 enum pipe_format format
,
1445 enum pipe_texture_target target
,
1446 unsigned sample_count
,
1449 struct r600_screen
*rscreen
= (struct r600_screen
*)screen
;
1450 unsigned retval
= 0;
1452 if (target
>= PIPE_MAX_TEXTURE_TYPES
) {
1453 R600_ERR("r600: unsupported texture type %d\n", target
);
1457 if (!util_format_is_supported(format
, usage
))
1460 if (sample_count
> 1) {
1461 if (HAVE_LLVM
< 0x0304 || rscreen
->b
.chip_class
!= SI
)
1464 switch (sample_count
) {
1474 if ((usage
& PIPE_BIND_SAMPLER_VIEW
) &&
1475 si_is_sampler_format_supported(screen
, format
)) {
1476 retval
|= PIPE_BIND_SAMPLER_VIEW
;
1479 if ((usage
& (PIPE_BIND_RENDER_TARGET
|
1480 PIPE_BIND_DISPLAY_TARGET
|
1482 PIPE_BIND_SHARED
)) &&
1483 si_is_colorbuffer_format_supported(format
)) {
1485 (PIPE_BIND_RENDER_TARGET
|
1486 PIPE_BIND_DISPLAY_TARGET
|
1491 if ((usage
& PIPE_BIND_DEPTH_STENCIL
) &&
1492 si_is_zs_format_supported(format
)) {
1493 retval
|= PIPE_BIND_DEPTH_STENCIL
;
1496 if ((usage
& PIPE_BIND_VERTEX_BUFFER
) &&
1497 si_is_vertex_format_supported(screen
, format
)) {
1498 retval
|= PIPE_BIND_VERTEX_BUFFER
;
1501 if (usage
& PIPE_BIND_TRANSFER_READ
)
1502 retval
|= PIPE_BIND_TRANSFER_READ
;
1503 if (usage
& PIPE_BIND_TRANSFER_WRITE
)
1504 retval
|= PIPE_BIND_TRANSFER_WRITE
;
1506 return retval
== usage
;
1509 static unsigned si_tile_mode_index(struct r600_texture
*rtex
, unsigned level
, bool stencil
)
1511 unsigned tile_mode_index
= 0;
1514 tile_mode_index
= rtex
->surface
.stencil_tiling_index
[level
];
1516 tile_mode_index
= rtex
->surface
.tiling_index
[level
];
1518 return tile_mode_index
;
1522 * framebuffer handling
1525 static void si_cb(struct r600_context
*rctx
, struct si_pm4_state
*pm4
,
1526 const struct pipe_framebuffer_state
*state
, int cb
)
1528 struct r600_texture
*rtex
;
1529 struct r600_surface
*surf
;
1530 unsigned level
= state
->cbufs
[cb
]->u
.tex
.level
;
1531 unsigned pitch
, slice
;
1532 unsigned color_info
, color_attrib
;
1533 unsigned tile_mode_index
;
1534 unsigned format
, swap
, ntype
, endian
;
1536 const struct util_format_description
*desc
;
1538 unsigned blend_clamp
= 0, blend_bypass
= 0;
1539 unsigned max_comp_size
;
1541 surf
= (struct r600_surface
*)state
->cbufs
[cb
];
1542 rtex
= (struct r600_texture
*)state
->cbufs
[cb
]->texture
;
1544 offset
= rtex
->surface
.level
[level
].offset
;
1545 if (rtex
->surface
.level
[level
].mode
< RADEON_SURF_MODE_1D
) {
1546 offset
+= rtex
->surface
.level
[level
].slice_size
*
1547 state
->cbufs
[cb
]->u
.tex
.first_layer
;
1549 pitch
= (rtex
->surface
.level
[level
].nblk_x
) / 8 - 1;
1550 slice
= (rtex
->surface
.level
[level
].nblk_x
* rtex
->surface
.level
[level
].nblk_y
) / 64;
1555 tile_mode_index
= si_tile_mode_index(rtex
, level
, false);
1557 desc
= util_format_description(surf
->base
.format
);
1558 for (i
= 0; i
< 4; i
++) {
1559 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
1563 if (i
== 4 || desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_FLOAT
) {
1564 ntype
= V_028C70_NUMBER_FLOAT
;
1566 ntype
= V_028C70_NUMBER_UNORM
;
1567 if (desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
)
1568 ntype
= V_028C70_NUMBER_SRGB
;
1569 else if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
) {
1570 if (desc
->channel
[i
].pure_integer
) {
1571 ntype
= V_028C70_NUMBER_SINT
;
1573 assert(desc
->channel
[i
].normalized
);
1574 ntype
= V_028C70_NUMBER_SNORM
;
1576 } else if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_UNSIGNED
) {
1577 if (desc
->channel
[i
].pure_integer
) {
1578 ntype
= V_028C70_NUMBER_UINT
;
1580 assert(desc
->channel
[i
].normalized
);
1581 ntype
= V_028C70_NUMBER_UNORM
;
1586 format
= si_translate_colorformat(surf
->base
.format
);
1587 if (format
== V_028C70_COLOR_INVALID
) {
1588 R600_ERR("Invalid CB format: %d, disabling CB.\n", surf
->base
.format
);
1590 assert(format
!= V_028C70_COLOR_INVALID
);
1591 swap
= si_translate_colorswap(surf
->base
.format
);
1592 if (rtex
->resource
.b
.b
.usage
== PIPE_USAGE_STAGING
) {
1593 endian
= V_028C70_ENDIAN_NONE
;
1595 endian
= si_colorformat_endian_swap(format
);
1598 /* blend clamp should be set for all NORM/SRGB types */
1599 if (ntype
== V_028C70_NUMBER_UNORM
||
1600 ntype
== V_028C70_NUMBER_SNORM
||
1601 ntype
== V_028C70_NUMBER_SRGB
)
1604 /* set blend bypass according to docs if SINT/UINT or
1605 8/24 COLOR variants */
1606 if (ntype
== V_028C70_NUMBER_UINT
|| ntype
== V_028C70_NUMBER_SINT
||
1607 format
== V_028C70_COLOR_8_24
|| format
== V_028C70_COLOR_24_8
||
1608 format
== V_028C70_COLOR_X24_8_32_FLOAT
) {
1613 color_info
= S_028C70_FORMAT(format
) |
1614 S_028C70_COMP_SWAP(swap
) |
1615 S_028C70_BLEND_CLAMP(blend_clamp
) |
1616 S_028C70_BLEND_BYPASS(blend_bypass
) |
1617 S_028C70_NUMBER_TYPE(ntype
) |
1618 S_028C70_ENDIAN(endian
);
1620 color_attrib
= S_028C74_TILE_MODE_INDEX(tile_mode_index
) |
1621 S_028C74_FORCE_DST_ALPHA_1(desc
->swizzle
[3] == UTIL_FORMAT_SWIZZLE_1
);
1623 if (rtex
->resource
.b
.b
.nr_samples
> 1) {
1624 unsigned log_samples
= util_logbase2(rtex
->resource
.b
.b
.nr_samples
);
1626 color_attrib
|= S_028C74_NUM_SAMPLES(log_samples
) |
1627 S_028C74_NUM_FRAGMENTS(log_samples
);
1629 if (rtex
->fmask
.size
) {
1630 color_info
|= S_028C70_COMPRESSION(1);
1631 unsigned fmask_bankh
= util_logbase2(rtex
->fmask
.bank_height
);
1633 /* due to a bug in the hw, FMASK_BANK_HEIGHT must be set on SI too */
1634 color_attrib
|= S_028C74_FMASK_TILE_MODE_INDEX(rtex
->fmask
.tile_mode_index
) |
1635 S_028C74_FMASK_BANK_HEIGHT(fmask_bankh
);
1639 if (rtex
->cmask
.size
) {
1640 color_info
|= S_028C70_FAST_CLEAR(1);
1643 offset
+= r600_resource_va(rctx
->b
.b
.screen
, state
->cbufs
[cb
]->texture
);
1646 /* FIXME handle enabling of CB beyond BASE8 which has different offset */
1647 si_pm4_add_bo(pm4
, &rtex
->resource
, RADEON_USAGE_READWRITE
);
1648 si_pm4_set_reg(pm4
, R_028C60_CB_COLOR0_BASE
+ cb
* 0x3C, offset
);
1649 si_pm4_set_reg(pm4
, R_028C64_CB_COLOR0_PITCH
+ cb
* 0x3C, S_028C64_TILE_MAX(pitch
));
1650 si_pm4_set_reg(pm4
, R_028C68_CB_COLOR0_SLICE
+ cb
* 0x3C, S_028C68_TILE_MAX(slice
));
1652 if (rtex
->surface
.level
[level
].mode
< RADEON_SURF_MODE_1D
) {
1653 si_pm4_set_reg(pm4
, R_028C6C_CB_COLOR0_VIEW
+ cb
* 0x3C, 0x00000000);
1655 si_pm4_set_reg(pm4
, R_028C6C_CB_COLOR0_VIEW
+ cb
* 0x3C,
1656 S_028C6C_SLICE_START(state
->cbufs
[cb
]->u
.tex
.first_layer
) |
1657 S_028C6C_SLICE_MAX(state
->cbufs
[cb
]->u
.tex
.last_layer
));
1659 si_pm4_set_reg(pm4
, R_028C70_CB_COLOR0_INFO
+ cb
* 0x3C, color_info
);
1660 si_pm4_set_reg(pm4
, R_028C74_CB_COLOR0_ATTRIB
+ cb
* 0x3C, color_attrib
);
1662 if (rtex
->cmask
.size
) {
1663 si_pm4_set_reg(pm4
, R_028C7C_CB_COLOR0_CMASK
+ cb
* 0x3C,
1664 offset
+ (rtex
->cmask
.offset
>> 8));
1665 si_pm4_set_reg(pm4
, R_028C80_CB_COLOR0_CMASK_SLICE
+ cb
* 0x3C,
1666 S_028C80_TILE_MAX(rtex
->cmask
.slice_tile_max
));
1668 if (rtex
->fmask
.size
) {
1669 si_pm4_set_reg(pm4
, R_028C84_CB_COLOR0_FMASK
+ cb
* 0x3C,
1670 offset
+ (rtex
->fmask
.offset
>> 8));
1671 si_pm4_set_reg(pm4
, R_028C88_CB_COLOR0_FMASK_SLICE
+ cb
* 0x3C,
1672 S_028C88_TILE_MAX(rtex
->fmask
.slice_tile_max
));
1675 /* set CB_COLOR1_INFO for possible dual-src blending */
1676 if (state
->nr_cbufs
== 1) {
1678 si_pm4_set_reg(pm4
, R_028C70_CB_COLOR0_INFO
+ 1 * 0x3C, color_info
);
1681 /* Determine pixel shader export format */
1682 max_comp_size
= si_colorformat_max_comp_size(format
);
1683 if (ntype
== V_028C70_NUMBER_SRGB
||
1684 ((ntype
== V_028C70_NUMBER_UNORM
|| ntype
== V_028C70_NUMBER_SNORM
) &&
1685 max_comp_size
<= 10) ||
1686 (ntype
== V_028C70_NUMBER_FLOAT
&& max_comp_size
<= 16)) {
1687 rctx
->export_16bpc
|= 1 << cb
;
1688 /* set SPI_SHADER_COL_FORMAT for possible dual-src blending */
1689 if (state
->nr_cbufs
== 1)
1690 rctx
->export_16bpc
|= 1 << 1;
1694 static void si_db(struct r600_context
*rctx
, struct si_pm4_state
*pm4
,
1695 const struct pipe_framebuffer_state
*state
)
1697 struct r600_screen
*rscreen
= rctx
->screen
;
1698 struct r600_texture
*rtex
;
1699 struct r600_surface
*surf
;
1700 unsigned level
, pitch
, slice
, format
, tile_mode_index
, array_mode
;
1701 unsigned macro_aspect
, tile_split
, stile_split
, bankh
, bankw
, nbanks
, pipe_config
;
1702 uint32_t z_info
, s_info
, db_depth_info
;
1703 uint64_t z_offs
, s_offs
;
1705 if (state
->zsbuf
== NULL
) {
1706 si_pm4_set_reg(pm4
, R_028040_DB_Z_INFO
, S_028040_FORMAT(V_028040_Z_INVALID
));
1707 si_pm4_set_reg(pm4
, R_028044_DB_STENCIL_INFO
, S_028044_FORMAT(V_028044_STENCIL_INVALID
));
1711 surf
= (struct r600_surface
*)state
->zsbuf
;
1712 level
= surf
->base
.u
.tex
.level
;
1713 rtex
= (struct r600_texture
*)surf
->base
.texture
;
1715 format
= si_translate_dbformat(rtex
->resource
.b
.b
.format
);
1717 if (format
== V_028040_Z_INVALID
) {
1718 R600_ERR("Invalid DB format: %d, disabling DB.\n", rtex
->resource
.b
.b
.format
);
1720 assert(format
!= V_028040_Z_INVALID
);
1722 s_offs
= z_offs
= r600_resource_va(rctx
->b
.b
.screen
, surf
->base
.texture
);
1723 z_offs
+= rtex
->surface
.level
[level
].offset
;
1724 s_offs
+= rtex
->surface
.stencil_level
[level
].offset
;
1729 pitch
= (rtex
->surface
.level
[level
].nblk_x
/ 8) - 1;
1730 slice
= (rtex
->surface
.level
[level
].nblk_x
* rtex
->surface
.level
[level
].nblk_y
) / 64;
1735 db_depth_info
= S_02803C_ADDR5_SWIZZLE_MASK(1);
1737 z_info
= S_028040_FORMAT(format
);
1738 if (rtex
->resource
.b
.b
.nr_samples
> 1) {
1739 z_info
|= S_028040_NUM_SAMPLES(util_logbase2(rtex
->resource
.b
.b
.nr_samples
));
1742 if (rtex
->surface
.flags
& RADEON_SURF_SBUFFER
)
1743 s_info
= S_028044_FORMAT(V_028044_STENCIL_8
);
1745 s_info
= S_028044_FORMAT(V_028044_STENCIL_INVALID
);
1747 if (rctx
->b
.chip_class
>= CIK
) {
1748 switch (rtex
->surface
.level
[level
].mode
) {
1749 case RADEON_SURF_MODE_2D
:
1750 array_mode
= V_02803C_ARRAY_2D_TILED_THIN1
;
1752 case RADEON_SURF_MODE_1D
:
1753 case RADEON_SURF_MODE_LINEAR_ALIGNED
:
1754 case RADEON_SURF_MODE_LINEAR
:
1756 array_mode
= V_02803C_ARRAY_1D_TILED_THIN1
;
1759 tile_split
= rtex
->surface
.tile_split
;
1760 stile_split
= rtex
->surface
.stencil_tile_split
;
1761 macro_aspect
= rtex
->surface
.mtilea
;
1762 bankw
= rtex
->surface
.bankw
;
1763 bankh
= rtex
->surface
.bankh
;
1764 tile_split
= cik_tile_split(tile_split
);
1765 stile_split
= cik_tile_split(stile_split
);
1766 macro_aspect
= cik_macro_tile_aspect(macro_aspect
);
1767 bankw
= cik_bank_wh(bankw
);
1768 bankh
= cik_bank_wh(bankh
);
1769 nbanks
= cik_num_banks(rscreen
->b
.tiling_info
.num_banks
);
1770 pipe_config
= cik_db_pipe_config(rscreen
->b
.info
.r600_num_tile_pipes
,
1771 rscreen
->b
.info
.r600_num_backends
);
1773 db_depth_info
|= S_02803C_ARRAY_MODE(array_mode
) |
1774 S_02803C_PIPE_CONFIG(pipe_config
) |
1775 S_02803C_BANK_WIDTH(bankw
) |
1776 S_02803C_BANK_HEIGHT(bankh
) |
1777 S_02803C_MACRO_TILE_ASPECT(macro_aspect
) |
1778 S_02803C_NUM_BANKS(nbanks
);
1779 z_info
|= S_028040_TILE_SPLIT(tile_split
);
1780 s_info
|= S_028044_TILE_SPLIT(stile_split
);
1782 tile_mode_index
= si_tile_mode_index(rtex
, level
, false);
1783 z_info
|= S_028040_TILE_MODE_INDEX(tile_mode_index
);
1784 tile_mode_index
= si_tile_mode_index(rtex
, level
, true);
1785 s_info
|= S_028044_TILE_MODE_INDEX(tile_mode_index
);
1788 si_pm4_set_reg(pm4
, R_028008_DB_DEPTH_VIEW
,
1789 S_028008_SLICE_START(state
->zsbuf
->u
.tex
.first_layer
) |
1790 S_028008_SLICE_MAX(state
->zsbuf
->u
.tex
.last_layer
));
1792 si_pm4_set_reg(pm4
, R_02803C_DB_DEPTH_INFO
, db_depth_info
);
1793 si_pm4_set_reg(pm4
, R_028040_DB_Z_INFO
, z_info
);
1794 si_pm4_set_reg(pm4
, R_028044_DB_STENCIL_INFO
, s_info
);
1796 si_pm4_add_bo(pm4
, &rtex
->resource
, RADEON_USAGE_READWRITE
);
1797 si_pm4_set_reg(pm4
, R_028048_DB_Z_READ_BASE
, z_offs
);
1798 si_pm4_set_reg(pm4
, R_02804C_DB_STENCIL_READ_BASE
, s_offs
);
1799 si_pm4_set_reg(pm4
, R_028050_DB_Z_WRITE_BASE
, z_offs
);
1800 si_pm4_set_reg(pm4
, R_028054_DB_STENCIL_WRITE_BASE
, s_offs
);
1802 si_pm4_set_reg(pm4
, R_028058_DB_DEPTH_SIZE
, S_028058_PITCH_TILE_MAX(pitch
));
1803 si_pm4_set_reg(pm4
, R_02805C_DB_DEPTH_SLICE
, S_02805C_SLICE_TILE_MAX(slice
));
1806 #define FILL_SREG(s0x, s0y, s1x, s1y, s2x, s2y, s3x, s3y) \
1807 (((s0x) & 0xf) | (((s0y) & 0xf) << 4) | \
1808 (((s1x) & 0xf) << 8) | (((s1y) & 0xf) << 12) | \
1809 (((s2x) & 0xf) << 16) | (((s2y) & 0xf) << 20) | \
1810 (((s3x) & 0xf) << 24) | (((s3y) & 0xf) << 28))
1813 * There are two locations (-4, 4), (4, -4). */
1814 static uint32_t sample_locs_2x
[] = {
1815 FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
1816 FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
1817 FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
1818 FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
1820 static unsigned max_dist_2x
= 4;
1822 * There are 4 locations: (-2, -2), (2, 2), (-6, 6), (6, -6). */
1823 static uint32_t sample_locs_4x
[] = {
1824 FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
1825 FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
1826 FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
1827 FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
1829 static unsigned max_dist_4x
= 6;
1830 /* Cayman/SI 8xMSAA */
1831 static uint32_t cm_sample_locs_8x
[] = {
1832 FILL_SREG(-2, -5, 3, -4, -1, 5, -6, -2),
1833 FILL_SREG(-2, -5, 3, -4, -1, 5, -6, -2),
1834 FILL_SREG(-2, -5, 3, -4, -1, 5, -6, -2),
1835 FILL_SREG(-2, -5, 3, -4, -1, 5, -6, -2),
1836 FILL_SREG( 6, 0, 0, 0, -5, 3, 4, 4),
1837 FILL_SREG( 6, 0, 0, 0, -5, 3, 4, 4),
1838 FILL_SREG( 6, 0, 0, 0, -5, 3, 4, 4),
1839 FILL_SREG( 6, 0, 0, 0, -5, 3, 4, 4),
1841 static unsigned cm_max_dist_8x
= 8;
1842 /* Cayman/SI 16xMSAA */
1843 static uint32_t cm_sample_locs_16x
[] = {
1844 FILL_SREG(-7, -3, 7, 3, 1, -5, -5, 5),
1845 FILL_SREG(-7, -3, 7, 3, 1, -5, -5, 5),
1846 FILL_SREG(-7, -3, 7, 3, 1, -5, -5, 5),
1847 FILL_SREG(-7, -3, 7, 3, 1, -5, -5, 5),
1848 FILL_SREG(-3, -7, 3, 7, 5, -1, -1, 1),
1849 FILL_SREG(-3, -7, 3, 7, 5, -1, -1, 1),
1850 FILL_SREG(-3, -7, 3, 7, 5, -1, -1, 1),
1851 FILL_SREG(-3, -7, 3, 7, 5, -1, -1, 1),
1852 FILL_SREG(-8, -6, 4, 2, 2, -8, -2, 6),
1853 FILL_SREG(-8, -6, 4, 2, 2, -8, -2, 6),
1854 FILL_SREG(-8, -6, 4, 2, 2, -8, -2, 6),
1855 FILL_SREG(-8, -6, 4, 2, 2, -8, -2, 6),
1856 FILL_SREG(-4, -2, 0, 4, 6, -4, -6, 0),
1857 FILL_SREG(-4, -2, 0, 4, 6, -4, -6, 0),
1858 FILL_SREG(-4, -2, 0, 4, 6, -4, -6, 0),
1859 FILL_SREG(-4, -2, 0, 4, 6, -4, -6, 0),
1861 static unsigned cm_max_dist_16x
= 8;
1863 static void si_get_sample_position(struct pipe_context
*ctx
,
1864 unsigned sample_count
,
1865 unsigned sample_index
,
1872 switch (sample_count
) {
1875 out_value
[0] = out_value
[1] = 0.5;
1878 offset
= 4 * (sample_index
* 2);
1879 val
.idx
= (sample_locs_2x
[0] >> offset
) & 0xf;
1880 out_value
[0] = (float)(val
.idx
+ 8) / 16.0f
;
1881 val
.idx
= (sample_locs_2x
[0] >> (offset
+ 4)) & 0xf;
1882 out_value
[1] = (float)(val
.idx
+ 8) / 16.0f
;
1885 offset
= 4 * (sample_index
* 2);
1886 val
.idx
= (sample_locs_4x
[0] >> offset
) & 0xf;
1887 out_value
[0] = (float)(val
.idx
+ 8) / 16.0f
;
1888 val
.idx
= (sample_locs_4x
[0] >> (offset
+ 4)) & 0xf;
1889 out_value
[1] = (float)(val
.idx
+ 8) / 16.0f
;
1892 offset
= 4 * (sample_index
% 4 * 2);
1893 index
= (sample_index
/ 4) * 4;
1894 val
.idx
= (cm_sample_locs_8x
[index
] >> offset
) & 0xf;
1895 out_value
[0] = (float)(val
.idx
+ 8) / 16.0f
;
1896 val
.idx
= (cm_sample_locs_8x
[index
] >> (offset
+ 4)) & 0xf;
1897 out_value
[1] = (float)(val
.idx
+ 8) / 16.0f
;
1900 offset
= 4 * (sample_index
% 4 * 2);
1901 index
= (sample_index
/ 4) * 4;
1902 val
.idx
= (cm_sample_locs_16x
[index
] >> offset
) & 0xf;
1903 out_value
[0] = (float)(val
.idx
+ 8) / 16.0f
;
1904 val
.idx
= (cm_sample_locs_16x
[index
] >> (offset
+ 4)) & 0xf;
1905 out_value
[1] = (float)(val
.idx
+ 8) / 16.0f
;
1910 static void si_set_msaa_state(struct r600_context
*rctx
, struct si_pm4_state
*pm4
, int nr_samples
)
1912 unsigned max_dist
= 0;
1914 switch (nr_samples
) {
1919 si_pm4_set_reg(pm4
, R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0
, sample_locs_2x
[0]);
1920 si_pm4_set_reg(pm4
, R_028C08_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_0
, sample_locs_2x
[1]);
1921 si_pm4_set_reg(pm4
, R_028C18_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_0
, sample_locs_2x
[2]);
1922 si_pm4_set_reg(pm4
, R_028C28_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_0
, sample_locs_2x
[3]);
1923 max_dist
= max_dist_2x
;
1926 si_pm4_set_reg(pm4
, R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0
, sample_locs_4x
[0]);
1927 si_pm4_set_reg(pm4
, R_028C08_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_0
, sample_locs_4x
[1]);
1928 si_pm4_set_reg(pm4
, R_028C18_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_0
, sample_locs_4x
[2]);
1929 si_pm4_set_reg(pm4
, R_028C28_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_0
, sample_locs_4x
[3]);
1930 max_dist
= max_dist_4x
;
1933 si_pm4_set_reg(pm4
, R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0
, cm_sample_locs_8x
[0]);
1934 si_pm4_set_reg(pm4
, R_028BFC_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_1
, cm_sample_locs_8x
[4]);
1935 si_pm4_set_reg(pm4
, R_028C00_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_2
, 0);
1936 si_pm4_set_reg(pm4
, R_028C04_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_3
, 0);
1937 si_pm4_set_reg(pm4
, R_028C08_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_0
, cm_sample_locs_8x
[1]);
1938 si_pm4_set_reg(pm4
, R_028C0C_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_1
, cm_sample_locs_8x
[5]);
1939 si_pm4_set_reg(pm4
, R_028C10_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_2
, 0);
1940 si_pm4_set_reg(pm4
, R_028C14_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_3
, 0);
1941 si_pm4_set_reg(pm4
, R_028C18_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_0
, cm_sample_locs_8x
[2]);
1942 si_pm4_set_reg(pm4
, R_028C1C_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_1
, cm_sample_locs_8x
[6]);
1943 si_pm4_set_reg(pm4
, R_028C20_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_2
, 0);
1944 si_pm4_set_reg(pm4
, R_028C24_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_3
, 0);
1945 si_pm4_set_reg(pm4
, R_028C28_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_0
, cm_sample_locs_8x
[3]);
1946 si_pm4_set_reg(pm4
, R_028C2C_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_1
, cm_sample_locs_8x
[7]);
1947 max_dist
= cm_max_dist_8x
;
1950 si_pm4_set_reg(pm4
, R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0
, cm_sample_locs_16x
[0]);
1951 si_pm4_set_reg(pm4
, R_028BFC_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_1
, cm_sample_locs_16x
[4]);
1952 si_pm4_set_reg(pm4
, R_028C00_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_2
, cm_sample_locs_16x
[8]);
1953 si_pm4_set_reg(pm4
, R_028C04_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_3
, cm_sample_locs_16x
[12]);
1954 si_pm4_set_reg(pm4
, R_028C08_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_0
, cm_sample_locs_16x
[1]);
1955 si_pm4_set_reg(pm4
, R_028C0C_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_1
, cm_sample_locs_16x
[5]);
1956 si_pm4_set_reg(pm4
, R_028C10_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_2
, cm_sample_locs_16x
[9]);
1957 si_pm4_set_reg(pm4
, R_028C14_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y0_3
, cm_sample_locs_16x
[13]);
1958 si_pm4_set_reg(pm4
, R_028C18_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_0
, cm_sample_locs_16x
[2]);
1959 si_pm4_set_reg(pm4
, R_028C1C_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_1
, cm_sample_locs_16x
[6]);
1960 si_pm4_set_reg(pm4
, R_028C20_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_2
, cm_sample_locs_16x
[10]);
1961 si_pm4_set_reg(pm4
, R_028C24_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y1_3
, cm_sample_locs_16x
[14]);
1962 si_pm4_set_reg(pm4
, R_028C28_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_0
, cm_sample_locs_16x
[3]);
1963 si_pm4_set_reg(pm4
, R_028C2C_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_1
, cm_sample_locs_16x
[7]);
1964 si_pm4_set_reg(pm4
, R_028C30_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_2
, cm_sample_locs_16x
[11]);
1965 si_pm4_set_reg(pm4
, R_028C34_PA_SC_AA_SAMPLE_LOCS_PIXEL_X1Y1_3
, cm_sample_locs_16x
[15]);
1966 max_dist
= cm_max_dist_16x
;
1970 if (nr_samples
> 1) {
1971 unsigned log_samples
= util_logbase2(nr_samples
);
1973 si_pm4_set_reg(pm4
, R_028BDC_PA_SC_LINE_CNTL
,
1974 S_028BDC_LAST_PIXEL(1) |
1975 S_028BDC_EXPAND_LINE_WIDTH(1));
1976 si_pm4_set_reg(pm4
, R_028BE0_PA_SC_AA_CONFIG
,
1977 S_028BE0_MSAA_NUM_SAMPLES(log_samples
) |
1978 S_028BE0_MAX_SAMPLE_DIST(max_dist
) |
1979 S_028BE0_MSAA_EXPOSED_SAMPLES(log_samples
));
1981 si_pm4_set_reg(pm4
, R_028804_DB_EQAA
,
1982 S_028804_MAX_ANCHOR_SAMPLES(log_samples
) |
1983 S_028804_PS_ITER_SAMPLES(log_samples
) |
1984 S_028804_MASK_EXPORT_NUM_SAMPLES(log_samples
) |
1985 S_028804_ALPHA_TO_MASK_NUM_SAMPLES(log_samples
) |
1986 S_028804_HIGH_QUALITY_INTERSECTIONS(1) |
1987 S_028804_STATIC_ANCHOR_ASSOCIATIONS(1));
1989 si_pm4_set_reg(pm4
, R_028BDC_PA_SC_LINE_CNTL
, S_028BDC_LAST_PIXEL(1));
1990 si_pm4_set_reg(pm4
, R_028BE0_PA_SC_AA_CONFIG
, 0);
1992 si_pm4_set_reg(pm4
, R_028804_DB_EQAA
,
1993 S_028804_HIGH_QUALITY_INTERSECTIONS(1) |
1994 S_028804_STATIC_ANCHOR_ASSOCIATIONS(1));
1998 static void si_set_framebuffer_state(struct pipe_context
*ctx
,
1999 const struct pipe_framebuffer_state
*state
)
2001 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2002 struct si_pm4_state
*pm4
= si_pm4_alloc_state(rctx
);
2004 int tl_x
, tl_y
, br_x
, br_y
, nr_samples
, i
;
2009 if (rctx
->framebuffer
.nr_cbufs
) {
2010 rctx
->b
.flags
|= R600_CONTEXT_FLUSH_AND_INV_CB
|
2011 R600_CONTEXT_FLUSH_AND_INV_CB_META
;
2013 if (rctx
->framebuffer
.zsbuf
) {
2014 rctx
->b
.flags
|= R600_CONTEXT_FLUSH_AND_INV_DB
;
2017 util_copy_framebuffer_state(&rctx
->framebuffer
, state
);
2020 rctx
->export_16bpc
= 0;
2021 rctx
->fb_compressed_cb_mask
= 0;
2022 for (i
= 0; i
< state
->nr_cbufs
; i
++) {
2023 struct r600_texture
*rtex
=
2024 (struct r600_texture
*)state
->cbufs
[i
]->texture
;
2026 si_cb(rctx
, pm4
, state
, i
);
2028 if (rtex
->fmask
.size
|| rtex
->cmask
.size
) {
2029 rctx
->fb_compressed_cb_mask
|= 1 << i
;
2032 for (; i
< 8; i
++) {
2033 si_pm4_set_reg(pm4
, R_028C70_CB_COLOR0_INFO
+ i
* 0x3C,
2034 S_028C70_FORMAT(V_028C70_COLOR_INVALID
));
2037 assert(!(rctx
->export_16bpc
& ~0xff));
2038 si_db(rctx
, pm4
, state
);
2042 br_x
= state
->width
;
2043 br_y
= state
->height
;
2045 tl
= S_028240_TL_X(tl_x
) | S_028240_TL_Y(tl_y
);
2046 br
= S_028244_BR_X(br_x
) | S_028244_BR_Y(br_y
);
2048 si_pm4_set_reg(pm4
, R_028240_PA_SC_GENERIC_SCISSOR_TL
, tl
);
2049 si_pm4_set_reg(pm4
, R_028244_PA_SC_GENERIC_SCISSOR_BR
, br
);
2050 si_pm4_set_reg(pm4
, R_028250_PA_SC_VPORT_SCISSOR_0_TL
, tl
);
2051 si_pm4_set_reg(pm4
, R_028254_PA_SC_VPORT_SCISSOR_0_BR
, br
);
2052 si_pm4_set_reg(pm4
, R_028030_PA_SC_SCREEN_SCISSOR_TL
, tl
);
2053 si_pm4_set_reg(pm4
, R_028034_PA_SC_SCREEN_SCISSOR_BR
, br
);
2054 si_pm4_set_reg(pm4
, R_028204_PA_SC_WINDOW_SCISSOR_TL
, tl
);
2055 si_pm4_set_reg(pm4
, R_028208_PA_SC_WINDOW_SCISSOR_BR
, br
);
2056 si_pm4_set_reg(pm4
, R_028200_PA_SC_WINDOW_OFFSET
, 0x00000000);
2057 si_pm4_set_reg(pm4
, R_028230_PA_SC_EDGERULE
, 0xAAAAAAAA);
2059 if (state
->nr_cbufs
)
2060 nr_samples
= state
->cbufs
[0]->texture
->nr_samples
;
2061 else if (state
->zsbuf
)
2062 nr_samples
= state
->zsbuf
->texture
->nr_samples
;
2066 si_set_msaa_state(rctx
, pm4
, nr_samples
);
2067 rctx
->fb_log_samples
= util_logbase2(nr_samples
);
2068 rctx
->fb_cb0_is_integer
= state
->nr_cbufs
&&
2069 util_format_is_pure_integer(state
->cbufs
[0]->format
);
2071 si_pm4_set_state(rctx
, framebuffer
, pm4
);
2072 si_update_fb_rs_state(rctx
);
2073 si_update_fb_blend_state(rctx
);
2080 /* Compute the key for the hw shader variant */
2081 static INLINE
void si_shader_selector_key(struct pipe_context
*ctx
,
2082 struct si_pipe_shader_selector
*sel
,
2083 union si_shader_key
*key
)
2085 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2086 memset(key
, 0, sizeof(*key
));
2088 if (sel
->type
== PIPE_SHADER_VERTEX
) {
2090 if (!rctx
->vertex_elements
)
2093 for (i
= 0; i
< rctx
->vertex_elements
->count
; ++i
)
2094 key
->vs
.instance_divisors
[i
] = rctx
->vertex_elements
->elements
[i
].instance_divisor
;
2096 if (rctx
->queued
.named
.rasterizer
->clip_plane_enable
& 0xf0)
2097 key
->vs
.ucps_enabled
|= 0x2;
2098 if (rctx
->queued
.named
.rasterizer
->clip_plane_enable
& 0xf)
2099 key
->vs
.ucps_enabled
|= 0x1;
2100 } else if (sel
->type
== PIPE_SHADER_FRAGMENT
) {
2101 if (sel
->fs_write_all
)
2102 key
->ps
.nr_cbufs
= rctx
->framebuffer
.nr_cbufs
;
2103 key
->ps
.export_16bpc
= rctx
->export_16bpc
;
2105 if (rctx
->queued
.named
.rasterizer
) {
2106 key
->ps
.color_two_side
= rctx
->queued
.named
.rasterizer
->two_side
;
2107 key
->ps
.flatshade
= rctx
->queued
.named
.rasterizer
->flatshade
;
2109 if (rctx
->queued
.named
.blend
) {
2110 key
->ps
.alpha_to_one
= rctx
->queued
.named
.blend
->alpha_to_one
&&
2111 rctx
->queued
.named
.rasterizer
->multisample_enable
&&
2112 !rctx
->fb_cb0_is_integer
;
2115 if (rctx
->queued
.named
.dsa
) {
2116 key
->ps
.alpha_func
= rctx
->queued
.named
.dsa
->alpha_func
;
2118 /* Alpha-test should be disabled if colorbuffer 0 is integer. */
2119 if (rctx
->framebuffer
.nr_cbufs
&&
2120 rctx
->framebuffer
.cbufs
[0] &&
2121 util_format_is_pure_integer(rctx
->framebuffer
.cbufs
[0]->texture
->format
))
2122 key
->ps
.alpha_func
= PIPE_FUNC_ALWAYS
;
2124 key
->ps
.alpha_func
= PIPE_FUNC_ALWAYS
;
2129 /* Select the hw shader variant depending on the current state.
2130 * (*dirty) is set to 1 if current variant was changed */
2131 int si_shader_select(struct pipe_context
*ctx
,
2132 struct si_pipe_shader_selector
*sel
,
2135 union si_shader_key key
;
2136 struct si_pipe_shader
* shader
= NULL
;
2139 si_shader_selector_key(ctx
, sel
, &key
);
2141 /* Check if we don't need to change anything.
2142 * This path is also used for most shaders that don't need multiple
2143 * variants, it will cost just a computation of the key and this
2145 if (likely(sel
->current
&& memcmp(&sel
->current
->key
, &key
, sizeof(key
)) == 0)) {
2149 /* lookup if we have other variants in the list */
2150 if (sel
->num_shaders
> 1) {
2151 struct si_pipe_shader
*p
= sel
->current
, *c
= p
->next_variant
;
2153 while (c
&& memcmp(&c
->key
, &key
, sizeof(key
)) != 0) {
2155 c
= c
->next_variant
;
2159 p
->next_variant
= c
->next_variant
;
2164 if (unlikely(!shader
)) {
2165 shader
= CALLOC(1, sizeof(struct si_pipe_shader
));
2166 shader
->selector
= sel
;
2169 r
= si_pipe_shader_create(ctx
, shader
);
2171 R600_ERR("Failed to build shader variant (type=%u) %d\n",
2173 sel
->current
= NULL
;
2178 /* We don't know the value of fs_write_all property until we built
2179 * at least one variant, so we may need to recompute the key (include
2180 * rctx->framebuffer.nr_cbufs) after building first variant. */
2181 if (sel
->type
== PIPE_SHADER_FRAGMENT
&&
2182 sel
->num_shaders
== 0 &&
2183 shader
->shader
.fs_write_all
) {
2184 sel
->fs_write_all
= 1;
2185 si_shader_selector_key(ctx
, sel
, &shader
->key
);
2194 shader
->next_variant
= sel
->current
;
2195 sel
->current
= shader
;
2200 static void *si_create_shader_state(struct pipe_context
*ctx
,
2201 const struct pipe_shader_state
*state
,
2202 unsigned pipe_shader_type
)
2204 struct si_pipe_shader_selector
*sel
= CALLOC_STRUCT(si_pipe_shader_selector
);
2207 sel
->type
= pipe_shader_type
;
2208 sel
->tokens
= tgsi_dup_tokens(state
->tokens
);
2209 sel
->so
= state
->stream_output
;
2211 r
= si_shader_select(ctx
, sel
, NULL
);
2220 static void *si_create_fs_state(struct pipe_context
*ctx
,
2221 const struct pipe_shader_state
*state
)
2223 return si_create_shader_state(ctx
, state
, PIPE_SHADER_FRAGMENT
);
2226 static void *si_create_vs_state(struct pipe_context
*ctx
,
2227 const struct pipe_shader_state
*state
)
2229 return si_create_shader_state(ctx
, state
, PIPE_SHADER_VERTEX
);
2232 static void si_bind_vs_shader(struct pipe_context
*ctx
, void *state
)
2234 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2235 struct si_pipe_shader_selector
*sel
= state
;
2237 if (rctx
->vs_shader
== sel
)
2240 rctx
->vs_shader
= sel
;
2242 if (sel
&& sel
->current
) {
2243 si_pm4_bind_state(rctx
, vs
, sel
->current
->pm4
);
2244 rctx
->b
.streamout
.stride_in_dw
= sel
->so
.stride
;
2246 si_pm4_bind_state(rctx
, vs
, rctx
->dummy_pixel_shader
->pm4
);
2249 rctx
->b
.flags
|= R600_CONTEXT_INV_SHADER_CACHE
;
2252 static void si_bind_ps_shader(struct pipe_context
*ctx
, void *state
)
2254 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2255 struct si_pipe_shader_selector
*sel
= state
;
2257 if (rctx
->ps_shader
== sel
)
2260 rctx
->ps_shader
= sel
;
2262 if (sel
&& sel
->current
)
2263 si_pm4_bind_state(rctx
, ps
, sel
->current
->pm4
);
2265 si_pm4_bind_state(rctx
, ps
, rctx
->dummy_pixel_shader
->pm4
);
2267 rctx
->b
.flags
|= R600_CONTEXT_INV_SHADER_CACHE
;
2270 static void si_delete_shader_selector(struct pipe_context
*ctx
,
2271 struct si_pipe_shader_selector
*sel
)
2273 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2274 struct si_pipe_shader
*p
= sel
->current
, *c
;
2277 c
= p
->next_variant
;
2278 si_pm4_delete_state(rctx
, vs
, p
->pm4
);
2279 si_pipe_shader_destroy(ctx
, p
);
2288 static void si_delete_vs_shader(struct pipe_context
*ctx
, void *state
)
2290 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2291 struct si_pipe_shader_selector
*sel
= (struct si_pipe_shader_selector
*)state
;
2293 if (rctx
->vs_shader
== sel
) {
2294 rctx
->vs_shader
= NULL
;
2297 si_delete_shader_selector(ctx
, sel
);
2300 static void si_delete_ps_shader(struct pipe_context
*ctx
, void *state
)
2302 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2303 struct si_pipe_shader_selector
*sel
= (struct si_pipe_shader_selector
*)state
;
2305 if (rctx
->ps_shader
== sel
) {
2306 rctx
->ps_shader
= NULL
;
2309 si_delete_shader_selector(ctx
, sel
);
2316 static struct pipe_sampler_view
*si_create_sampler_view(struct pipe_context
*ctx
,
2317 struct pipe_resource
*texture
,
2318 const struct pipe_sampler_view
*state
)
2320 struct si_pipe_sampler_view
*view
= CALLOC_STRUCT(si_pipe_sampler_view
);
2321 struct r600_texture
*tmp
= (struct r600_texture
*)texture
;
2322 const struct util_format_description
*desc
;
2323 unsigned format
, num_format
;
2325 unsigned char state_swizzle
[4], swizzle
[4];
2326 unsigned height
, depth
, width
;
2327 enum pipe_format pipe_format
= state
->format
;
2328 struct radeon_surface_level
*surflevel
;
2335 /* initialize base object */
2336 view
->base
= *state
;
2337 view
->base
.texture
= NULL
;
2338 pipe_reference(NULL
, &texture
->reference
);
2339 view
->base
.texture
= texture
;
2340 view
->base
.reference
.count
= 1;
2341 view
->base
.context
= ctx
;
2343 state_swizzle
[0] = state
->swizzle_r
;
2344 state_swizzle
[1] = state
->swizzle_g
;
2345 state_swizzle
[2] = state
->swizzle_b
;
2346 state_swizzle
[3] = state
->swizzle_a
;
2348 surflevel
= tmp
->surface
.level
;
2350 /* Texturing with separate depth and stencil. */
2351 if (tmp
->is_depth
&& !tmp
->is_flushing_texture
) {
2352 switch (pipe_format
) {
2353 case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT
:
2354 pipe_format
= PIPE_FORMAT_Z32_FLOAT
;
2356 case PIPE_FORMAT_X8Z24_UNORM
:
2357 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
2358 /* Z24 is always stored like this. */
2359 pipe_format
= PIPE_FORMAT_Z24X8_UNORM
;
2361 case PIPE_FORMAT_X24S8_UINT
:
2362 case PIPE_FORMAT_S8X24_UINT
:
2363 case PIPE_FORMAT_X32_S8X24_UINT
:
2364 pipe_format
= PIPE_FORMAT_S8_UINT
;
2365 surflevel
= tmp
->surface
.stencil_level
;
2371 desc
= util_format_description(pipe_format
);
2373 if (desc
->colorspace
== UTIL_FORMAT_COLORSPACE_ZS
) {
2374 const unsigned char swizzle_xxxx
[4] = {0, 0, 0, 0};
2375 const unsigned char swizzle_yyyy
[4] = {1, 1, 1, 1};
2377 switch (pipe_format
) {
2378 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
2379 case PIPE_FORMAT_X24S8_UINT
:
2380 case PIPE_FORMAT_X32_S8X24_UINT
:
2381 case PIPE_FORMAT_X8Z24_UNORM
:
2382 util_format_compose_swizzles(swizzle_yyyy
, state_swizzle
, swizzle
);
2385 util_format_compose_swizzles(swizzle_xxxx
, state_swizzle
, swizzle
);
2388 util_format_compose_swizzles(desc
->swizzle
, state_swizzle
, swizzle
);
2391 first_non_void
= util_format_get_first_non_void_channel(pipe_format
);
2393 switch (pipe_format
) {
2394 case PIPE_FORMAT_S8_UINT_Z24_UNORM
:
2395 num_format
= V_008F14_IMG_NUM_FORMAT_UNORM
;
2398 if (first_non_void
< 0) {
2399 if (util_format_is_compressed(pipe_format
)) {
2400 switch (pipe_format
) {
2401 case PIPE_FORMAT_DXT1_SRGB
:
2402 case PIPE_FORMAT_DXT1_SRGBA
:
2403 case PIPE_FORMAT_DXT3_SRGBA
:
2404 case PIPE_FORMAT_DXT5_SRGBA
:
2405 num_format
= V_008F14_IMG_NUM_FORMAT_SRGB
;
2407 case PIPE_FORMAT_RGTC1_SNORM
:
2408 case PIPE_FORMAT_LATC1_SNORM
:
2409 case PIPE_FORMAT_RGTC2_SNORM
:
2410 case PIPE_FORMAT_LATC2_SNORM
:
2411 num_format
= V_008F14_IMG_NUM_FORMAT_SNORM
;
2414 num_format
= V_008F14_IMG_NUM_FORMAT_UNORM
;
2418 num_format
= V_008F14_IMG_NUM_FORMAT_FLOAT
;
2420 } else if (desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
) {
2421 num_format
= V_008F14_IMG_NUM_FORMAT_SRGB
;
2423 num_format
= V_008F14_IMG_NUM_FORMAT_UNORM
;
2425 switch (desc
->channel
[first_non_void
].type
) {
2426 case UTIL_FORMAT_TYPE_FLOAT
:
2427 num_format
= V_008F14_IMG_NUM_FORMAT_FLOAT
;
2429 case UTIL_FORMAT_TYPE_SIGNED
:
2430 if (desc
->channel
[first_non_void
].normalized
)
2431 num_format
= V_008F14_IMG_NUM_FORMAT_SNORM
;
2432 else if (desc
->channel
[first_non_void
].pure_integer
)
2433 num_format
= V_008F14_IMG_NUM_FORMAT_SINT
;
2435 num_format
= V_008F14_IMG_NUM_FORMAT_SSCALED
;
2437 case UTIL_FORMAT_TYPE_UNSIGNED
:
2438 if (desc
->channel
[first_non_void
].normalized
)
2439 num_format
= V_008F14_IMG_NUM_FORMAT_UNORM
;
2440 else if (desc
->channel
[first_non_void
].pure_integer
)
2441 num_format
= V_008F14_IMG_NUM_FORMAT_UINT
;
2443 num_format
= V_008F14_IMG_NUM_FORMAT_USCALED
;
2448 format
= si_translate_texformat(ctx
->screen
, pipe_format
, desc
, first_non_void
);
2453 view
->resource
= &tmp
->resource
;
2455 /* not supported any more */
2456 //endian = si_colorformat_endian_swap(format);
2458 width
= surflevel
[0].npix_x
;
2459 height
= surflevel
[0].npix_y
;
2460 depth
= surflevel
[0].npix_z
;
2461 pitch
= surflevel
[0].nblk_x
* util_format_get_blockwidth(pipe_format
);
2463 if (texture
->target
== PIPE_TEXTURE_1D_ARRAY
) {
2465 depth
= texture
->array_size
;
2466 } else if (texture
->target
== PIPE_TEXTURE_2D_ARRAY
) {
2467 depth
= texture
->array_size
;
2470 va
= r600_resource_va(ctx
->screen
, texture
);
2471 va
+= surflevel
[0].offset
;
2472 va
+= tmp
->mipmap_shift
* surflevel
[texture
->last_level
].slice_size
;
2473 view
->state
[0] = va
>> 8;
2474 view
->state
[1] = (S_008F14_BASE_ADDRESS_HI(va
>> 40) |
2475 S_008F14_DATA_FORMAT(format
) |
2476 S_008F14_NUM_FORMAT(num_format
));
2477 view
->state
[2] = (S_008F18_WIDTH(width
- 1) |
2478 S_008F18_HEIGHT(height
- 1));
2479 view
->state
[3] = (S_008F1C_DST_SEL_X(si_map_swizzle(swizzle
[0])) |
2480 S_008F1C_DST_SEL_Y(si_map_swizzle(swizzle
[1])) |
2481 S_008F1C_DST_SEL_Z(si_map_swizzle(swizzle
[2])) |
2482 S_008F1C_DST_SEL_W(si_map_swizzle(swizzle
[3])) |
2483 S_008F1C_BASE_LEVEL(texture
->nr_samples
> 1 ?
2484 0 : state
->u
.tex
.first_level
- tmp
->mipmap_shift
) |
2485 S_008F1C_LAST_LEVEL(texture
->nr_samples
> 1 ?
2486 util_logbase2(texture
->nr_samples
) :
2487 state
->u
.tex
.last_level
- tmp
->mipmap_shift
) |
2488 S_008F1C_TILING_INDEX(si_tile_mode_index(tmp
, 0, false)) |
2489 S_008F1C_POW2_PAD(texture
->last_level
> 0) |
2490 S_008F1C_TYPE(si_tex_dim(texture
->target
, texture
->nr_samples
)));
2491 view
->state
[4] = (S_008F20_DEPTH(depth
- 1) | S_008F20_PITCH(pitch
- 1));
2492 view
->state
[5] = (S_008F24_BASE_ARRAY(state
->u
.tex
.first_layer
) |
2493 S_008F24_LAST_ARRAY(state
->u
.tex
.last_layer
));
2497 /* Initialize the sampler view for FMASK. */
2498 if (tmp
->fmask
.size
) {
2499 uint64_t va
= r600_resource_va(ctx
->screen
, texture
) + tmp
->fmask
.offset
;
2500 uint32_t fmask_format
;
2502 switch (texture
->nr_samples
) {
2504 fmask_format
= V_008F14_IMG_DATA_FORMAT_FMASK8_S2_F2
;
2507 fmask_format
= V_008F14_IMG_DATA_FORMAT_FMASK8_S4_F4
;
2510 fmask_format
= V_008F14_IMG_DATA_FORMAT_FMASK32_S8_F8
;
2514 fmask_format
= V_008F14_IMG_DATA_FORMAT_INVALID
;
2517 view
->fmask_state
[0] = va
>> 8;
2518 view
->fmask_state
[1] = S_008F14_BASE_ADDRESS_HI(va
>> 40) |
2519 S_008F14_DATA_FORMAT(fmask_format
) |
2520 S_008F14_NUM_FORMAT(V_008F14_IMG_NUM_FORMAT_UINT
);
2521 view
->fmask_state
[2] = S_008F18_WIDTH(width
- 1) |
2522 S_008F18_HEIGHT(height
- 1);
2523 view
->fmask_state
[3] = S_008F1C_DST_SEL_X(V_008F1C_SQ_SEL_X
) |
2524 S_008F1C_DST_SEL_Y(V_008F1C_SQ_SEL_X
) |
2525 S_008F1C_DST_SEL_Z(V_008F1C_SQ_SEL_X
) |
2526 S_008F1C_DST_SEL_W(V_008F1C_SQ_SEL_X
) |
2527 S_008F1C_TILING_INDEX(tmp
->fmask
.tile_mode_index
) |
2528 S_008F1C_TYPE(si_tex_dim(texture
->target
, 0));
2529 view
->fmask_state
[4] = S_008F20_DEPTH(depth
- 1) |
2530 S_008F20_PITCH(tmp
->fmask
.pitch
- 1);
2531 view
->fmask_state
[5] = S_008F24_BASE_ARRAY(state
->u
.tex
.first_layer
) |
2532 S_008F24_LAST_ARRAY(state
->u
.tex
.last_layer
);
2533 view
->fmask_state
[6] = 0;
2534 view
->fmask_state
[7] = 0;
2540 static void si_sampler_view_destroy(struct pipe_context
*ctx
,
2541 struct pipe_sampler_view
*state
)
2543 struct r600_pipe_sampler_view
*resource
= (struct r600_pipe_sampler_view
*)state
;
2545 pipe_resource_reference(&state
->texture
, NULL
);
2549 static bool wrap_mode_uses_border_color(unsigned wrap
, bool linear_filter
)
2551 return wrap
== PIPE_TEX_WRAP_CLAMP_TO_BORDER
||
2552 wrap
== PIPE_TEX_WRAP_MIRROR_CLAMP_TO_BORDER
||
2554 (wrap
== PIPE_TEX_WRAP_CLAMP
||
2555 wrap
== PIPE_TEX_WRAP_MIRROR_CLAMP
));
2558 static bool sampler_state_needs_border_color(const struct pipe_sampler_state
*state
)
2560 bool linear_filter
= state
->min_img_filter
!= PIPE_TEX_FILTER_NEAREST
||
2561 state
->mag_img_filter
!= PIPE_TEX_FILTER_NEAREST
;
2563 return (state
->border_color
.ui
[0] || state
->border_color
.ui
[1] ||
2564 state
->border_color
.ui
[2] || state
->border_color
.ui
[3]) &&
2565 (wrap_mode_uses_border_color(state
->wrap_s
, linear_filter
) ||
2566 wrap_mode_uses_border_color(state
->wrap_t
, linear_filter
) ||
2567 wrap_mode_uses_border_color(state
->wrap_r
, linear_filter
));
2570 static void *si_create_sampler_state(struct pipe_context
*ctx
,
2571 const struct pipe_sampler_state
*state
)
2573 struct si_pipe_sampler_state
*rstate
= CALLOC_STRUCT(si_pipe_sampler_state
);
2574 unsigned aniso_flag_offset
= state
->max_anisotropy
> 1 ? 2 : 0;
2575 unsigned border_color_type
;
2577 if (rstate
== NULL
) {
2581 if (sampler_state_needs_border_color(state
))
2582 border_color_type
= V_008F3C_SQ_TEX_BORDER_COLOR_REGISTER
;
2584 border_color_type
= V_008F3C_SQ_TEX_BORDER_COLOR_TRANS_BLACK
;
2586 rstate
->val
[0] = (S_008F30_CLAMP_X(si_tex_wrap(state
->wrap_s
)) |
2587 S_008F30_CLAMP_Y(si_tex_wrap(state
->wrap_t
)) |
2588 S_008F30_CLAMP_Z(si_tex_wrap(state
->wrap_r
)) |
2589 (state
->max_anisotropy
& 0x7) << 9 | /* XXX */
2590 S_008F30_DEPTH_COMPARE_FUNC(si_tex_compare(state
->compare_func
)) |
2591 S_008F30_FORCE_UNNORMALIZED(!state
->normalized_coords
) |
2592 aniso_flag_offset
<< 16 | /* XXX */
2593 S_008F30_DISABLE_CUBE_WRAP(!state
->seamless_cube_map
));
2594 rstate
->val
[1] = (S_008F34_MIN_LOD(S_FIXED(CLAMP(state
->min_lod
, 0, 15), 8)) |
2595 S_008F34_MAX_LOD(S_FIXED(CLAMP(state
->max_lod
, 0, 15), 8)));
2596 rstate
->val
[2] = (S_008F38_LOD_BIAS(S_FIXED(CLAMP(state
->lod_bias
, -16, 16), 8)) |
2597 S_008F38_XY_MAG_FILTER(si_tex_filter(state
->mag_img_filter
)) |
2598 S_008F38_XY_MIN_FILTER(si_tex_filter(state
->min_img_filter
)) |
2599 S_008F38_MIP_FILTER(si_tex_mipfilter(state
->min_mip_filter
)));
2600 rstate
->val
[3] = S_008F3C_BORDER_COLOR_TYPE(border_color_type
);
2602 if (border_color_type
== V_008F3C_SQ_TEX_BORDER_COLOR_REGISTER
) {
2603 memcpy(rstate
->border_color
, state
->border_color
.ui
,
2604 sizeof(rstate
->border_color
));
2610 /* XXX consider moving this function to si_descriptors.c for gcc to inline
2611 * the si_set_sampler_view calls. LTO might help too. */
2612 static void si_set_sampler_views(struct pipe_context
*ctx
,
2613 unsigned shader
, unsigned start
,
2615 struct pipe_sampler_view
**views
)
2617 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2618 struct r600_textures_info
*samplers
= &rctx
->samplers
[shader
];
2619 struct si_pipe_sampler_view
**rviews
= (struct si_pipe_sampler_view
**)views
;
2622 if (shader
!= PIPE_SHADER_VERTEX
&& shader
!= PIPE_SHADER_FRAGMENT
)
2627 for (i
= 0; i
< count
; i
++) {
2629 struct r600_texture
*rtex
=
2630 (struct r600_texture
*)views
[i
]->texture
;
2632 if (rtex
->is_depth
&& !rtex
->is_flushing_texture
) {
2633 samplers
->depth_texture_mask
|= 1 << i
;
2635 samplers
->depth_texture_mask
&= ~(1 << i
);
2637 if (rtex
->cmask
.size
|| rtex
->fmask
.size
) {
2638 samplers
->compressed_colortex_mask
|= 1 << i
;
2640 samplers
->compressed_colortex_mask
&= ~(1 << i
);
2643 si_set_sampler_view(rctx
, shader
, i
, views
[i
], rviews
[i
]->state
);
2645 if (rtex
->fmask
.size
) {
2646 si_set_sampler_view(rctx
, shader
, FMASK_TEX_OFFSET
+ i
,
2647 views
[i
], rviews
[i
]->fmask_state
);
2649 si_set_sampler_view(rctx
, shader
, FMASK_TEX_OFFSET
+ i
,
2653 samplers
->depth_texture_mask
&= ~(1 << i
);
2654 samplers
->compressed_colortex_mask
&= ~(1 << i
);
2655 si_set_sampler_view(rctx
, shader
, i
, NULL
, NULL
);
2656 si_set_sampler_view(rctx
, shader
, FMASK_TEX_OFFSET
+ i
,
2660 for (; i
< samplers
->n_views
; i
++) {
2661 samplers
->depth_texture_mask
&= ~(1 << i
);
2662 samplers
->compressed_colortex_mask
&= ~(1 << i
);
2663 si_set_sampler_view(rctx
, shader
, i
, NULL
, NULL
);
2664 si_set_sampler_view(rctx
, shader
, FMASK_TEX_OFFSET
+ i
,
2668 samplers
->n_views
= count
;
2669 rctx
->b
.flags
|= R600_CONTEXT_INV_TEX_CACHE
;
2672 static struct si_pm4_state
*si_set_sampler_states(struct r600_context
*rctx
, unsigned count
,
2674 struct r600_textures_info
*samplers
,
2675 unsigned user_data_reg
)
2677 struct si_pipe_sampler_state
**rstates
= (struct si_pipe_sampler_state
**)states
;
2678 struct si_pm4_state
*pm4
= si_pm4_alloc_state(rctx
);
2679 uint32_t *border_color_table
= NULL
;
2685 rctx
->b
.flags
|= R600_CONTEXT_INV_TEX_CACHE
;
2687 si_pm4_sh_data_begin(pm4
);
2688 for (i
= 0; i
< count
; i
++) {
2690 G_008F3C_BORDER_COLOR_TYPE(rstates
[i
]->val
[3]) ==
2691 V_008F3C_SQ_TEX_BORDER_COLOR_REGISTER
) {
2692 if (!rctx
->border_color_table
||
2693 ((rctx
->border_color_offset
+ count
- i
) &
2694 C_008F3C_BORDER_COLOR_PTR
)) {
2695 r600_resource_reference(&rctx
->border_color_table
, NULL
);
2696 rctx
->border_color_offset
= 0;
2698 rctx
->border_color_table
=
2699 r600_resource_create_custom(&rctx
->screen
->b
.b
,
2704 if (!border_color_table
) {
2705 border_color_table
=
2706 rctx
->b
.ws
->buffer_map(rctx
->border_color_table
->cs_buf
,
2707 rctx
->b
.rings
.gfx
.cs
,
2708 PIPE_TRANSFER_WRITE
|
2709 PIPE_TRANSFER_UNSYNCHRONIZED
);
2712 for (j
= 0; j
< 4; j
++) {
2713 border_color_table
[4 * rctx
->border_color_offset
+ j
] =
2714 util_le32_to_cpu(rstates
[i
]->border_color
[j
]);
2717 rstates
[i
]->val
[3] &= C_008F3C_BORDER_COLOR_PTR
;
2718 rstates
[i
]->val
[3] |= S_008F3C_BORDER_COLOR_PTR(rctx
->border_color_offset
++);
2721 for (j
= 0; j
< Elements(rstates
[i
]->val
); ++j
) {
2722 si_pm4_sh_data_add(pm4
, rstates
[i
] ? rstates
[i
]->val
[j
] : 0);
2725 si_pm4_sh_data_end(pm4
, user_data_reg
, SI_SGPR_SAMPLER
);
2727 if (border_color_table
) {
2728 uint64_t va_offset
=
2729 r600_resource_va(&rctx
->screen
->b
.b
,
2730 (void*)rctx
->border_color_table
);
2732 si_pm4_set_reg(pm4
, R_028080_TA_BC_BASE_ADDR
, va_offset
>> 8);
2733 if (rctx
->b
.chip_class
>= CIK
)
2734 si_pm4_set_reg(pm4
, R_028084_TA_BC_BASE_ADDR_HI
, va_offset
>> 40);
2735 rctx
->b
.ws
->buffer_unmap(rctx
->border_color_table
->cs_buf
);
2736 si_pm4_add_bo(pm4
, rctx
->border_color_table
, RADEON_USAGE_READ
);
2739 memcpy(samplers
->samplers
, states
, sizeof(void*) * count
);
2742 samplers
->n_samplers
= count
;
2746 static void si_bind_vs_sampler_states(struct pipe_context
*ctx
, unsigned count
, void **states
)
2748 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2749 struct si_pm4_state
*pm4
;
2751 pm4
= si_set_sampler_states(rctx
, count
, states
, &rctx
->samplers
[PIPE_SHADER_VERTEX
],
2752 R_00B130_SPI_SHADER_USER_DATA_VS_0
);
2753 si_pm4_set_state(rctx
, vs_sampler
, pm4
);
2756 static void si_bind_ps_sampler_states(struct pipe_context
*ctx
, unsigned count
, void **states
)
2758 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2759 struct si_pm4_state
*pm4
;
2761 pm4
= si_set_sampler_states(rctx
, count
, states
, &rctx
->samplers
[PIPE_SHADER_FRAGMENT
],
2762 R_00B030_SPI_SHADER_USER_DATA_PS_0
);
2763 si_pm4_set_state(rctx
, ps_sampler
, pm4
);
2767 static void si_bind_sampler_states(struct pipe_context
*ctx
, unsigned shader
,
2768 unsigned start
, unsigned count
,
2774 case PIPE_SHADER_VERTEX
:
2775 si_bind_vs_sampler_states(ctx
, count
, states
);
2777 case PIPE_SHADER_FRAGMENT
:
2778 si_bind_ps_sampler_states(ctx
, count
, states
);
2787 static void si_set_sample_mask(struct pipe_context
*ctx
, unsigned sample_mask
)
2789 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2790 struct si_pm4_state
*pm4
= si_pm4_alloc_state(rctx
);
2791 uint16_t mask
= sample_mask
;
2796 si_pm4_set_reg(pm4
, R_028C38_PA_SC_AA_MASK_X0Y0_X1Y0
, mask
| (mask
<< 16));
2797 si_pm4_set_reg(pm4
, R_028C3C_PA_SC_AA_MASK_X0Y1_X1Y1
, mask
| (mask
<< 16));
2799 si_pm4_set_state(rctx
, sample_mask
, pm4
);
2802 static void si_delete_sampler_state(struct pipe_context
*ctx
, void *state
)
2808 * Vertex elements & buffers
2811 static void *si_create_vertex_elements(struct pipe_context
*ctx
,
2813 const struct pipe_vertex_element
*elements
)
2815 struct si_vertex_element
*v
= CALLOC_STRUCT(si_vertex_element
);
2818 assert(count
< PIPE_MAX_ATTRIBS
);
2823 for (i
= 0; i
< count
; ++i
) {
2824 const struct util_format_description
*desc
;
2825 unsigned data_format
, num_format
;
2828 desc
= util_format_description(elements
[i
].src_format
);
2829 first_non_void
= util_format_get_first_non_void_channel(elements
[i
].src_format
);
2830 data_format
= si_translate_vertexformat(ctx
->screen
, elements
[i
].src_format
,
2831 desc
, first_non_void
);
2833 switch (desc
->channel
[first_non_void
].type
) {
2834 case UTIL_FORMAT_TYPE_FIXED
:
2835 num_format
= V_008F0C_BUF_NUM_FORMAT_USCALED
; /* XXX */
2837 case UTIL_FORMAT_TYPE_SIGNED
:
2838 if (desc
->channel
[first_non_void
].normalized
)
2839 num_format
= V_008F0C_BUF_NUM_FORMAT_SNORM
;
2840 else if (desc
->channel
[first_non_void
].pure_integer
)
2841 num_format
= V_008F0C_BUF_NUM_FORMAT_SINT
;
2843 num_format
= V_008F0C_BUF_NUM_FORMAT_SSCALED
;
2845 case UTIL_FORMAT_TYPE_UNSIGNED
:
2846 if (desc
->channel
[first_non_void
].normalized
)
2847 num_format
= V_008F0C_BUF_NUM_FORMAT_UNORM
;
2848 else if (desc
->channel
[first_non_void
].pure_integer
)
2849 num_format
= V_008F0C_BUF_NUM_FORMAT_UINT
;
2851 num_format
= V_008F0C_BUF_NUM_FORMAT_USCALED
;
2853 case UTIL_FORMAT_TYPE_FLOAT
:
2855 num_format
= V_008F14_IMG_NUM_FORMAT_FLOAT
;
2858 v
->rsrc_word3
[i
] = S_008F0C_DST_SEL_X(si_map_swizzle(desc
->swizzle
[0])) |
2859 S_008F0C_DST_SEL_Y(si_map_swizzle(desc
->swizzle
[1])) |
2860 S_008F0C_DST_SEL_Z(si_map_swizzle(desc
->swizzle
[2])) |
2861 S_008F0C_DST_SEL_W(si_map_swizzle(desc
->swizzle
[3])) |
2862 S_008F0C_NUM_FORMAT(num_format
) |
2863 S_008F0C_DATA_FORMAT(data_format
);
2865 memcpy(v
->elements
, elements
, sizeof(struct pipe_vertex_element
) * count
);
2870 static void si_bind_vertex_elements(struct pipe_context
*ctx
, void *state
)
2872 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2873 struct si_vertex_element
*v
= (struct si_vertex_element
*)state
;
2875 rctx
->vertex_elements
= v
;
2878 static void si_delete_vertex_element(struct pipe_context
*ctx
, void *state
)
2880 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2882 if (rctx
->vertex_elements
== state
)
2883 rctx
->vertex_elements
= NULL
;
2887 static void si_set_vertex_buffers(struct pipe_context
*ctx
, unsigned start_slot
, unsigned count
,
2888 const struct pipe_vertex_buffer
*buffers
)
2890 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2892 util_set_vertex_buffers_count(rctx
->vertex_buffer
, &rctx
->nr_vertex_buffers
, buffers
, start_slot
, count
);
2895 static void si_set_index_buffer(struct pipe_context
*ctx
,
2896 const struct pipe_index_buffer
*ib
)
2898 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2901 pipe_resource_reference(&rctx
->index_buffer
.buffer
, ib
->buffer
);
2902 memcpy(&rctx
->index_buffer
, ib
, sizeof(*ib
));
2904 pipe_resource_reference(&rctx
->index_buffer
.buffer
, NULL
);
2911 static void si_set_polygon_stipple(struct pipe_context
*ctx
,
2912 const struct pipe_poly_stipple
*state
)
2916 static void si_texture_barrier(struct pipe_context
*ctx
)
2918 struct r600_context
*rctx
= (struct r600_context
*)ctx
;
2920 rctx
->b
.flags
|= R600_CONTEXT_INV_TEX_CACHE
|
2921 R600_CONTEXT_FLUSH_AND_INV_CB
;
2924 static void *si_create_blend_custom(struct r600_context
*rctx
, unsigned mode
)
2926 struct pipe_blend_state blend
;
2928 memset(&blend
, 0, sizeof(blend
));
2929 blend
.independent_blend_enable
= true;
2930 blend
.rt
[0].colormask
= 0xf;
2931 return si_create_blend_state_mode(&rctx
->b
.b
, &blend
, mode
);
2934 static struct pipe_surface
*r600_create_surface(struct pipe_context
*pipe
,
2935 struct pipe_resource
*texture
,
2936 const struct pipe_surface
*surf_tmpl
)
2938 struct r600_texture
*rtex
= (struct r600_texture
*)texture
;
2939 struct r600_surface
*surface
= CALLOC_STRUCT(r600_surface
);
2940 unsigned level
= surf_tmpl
->u
.tex
.level
;
2942 if (surface
== NULL
)
2945 assert(surf_tmpl
->u
.tex
.first_layer
<= util_max_layer(texture
, surf_tmpl
->u
.tex
.level
));
2946 assert(surf_tmpl
->u
.tex
.last_layer
<= util_max_layer(texture
, surf_tmpl
->u
.tex
.level
));
2947 assert(surf_tmpl
->u
.tex
.first_layer
== surf_tmpl
->u
.tex
.last_layer
);
2949 pipe_reference_init(&surface
->base
.reference
, 1);
2950 pipe_resource_reference(&surface
->base
.texture
, texture
);
2951 surface
->base
.context
= pipe
;
2952 surface
->base
.format
= surf_tmpl
->format
;
2953 surface
->base
.width
= rtex
->surface
.level
[level
].npix_x
;
2954 surface
->base
.height
= rtex
->surface
.level
[level
].npix_y
;
2955 surface
->base
.texture
= texture
;
2956 surface
->base
.u
.tex
.first_layer
= surf_tmpl
->u
.tex
.first_layer
;
2957 surface
->base
.u
.tex
.last_layer
= surf_tmpl
->u
.tex
.last_layer
;
2958 surface
->base
.u
.tex
.level
= level
;
2960 return &surface
->base
;
2963 static void r600_surface_destroy(struct pipe_context
*pipe
,
2964 struct pipe_surface
*surface
)
2966 pipe_resource_reference(&surface
->texture
, NULL
);
2970 static boolean
si_dma_copy(struct pipe_context
*ctx
,
2971 struct pipe_resource
*dst
,
2973 unsigned dst_x
, unsigned dst_y
, unsigned dst_z
,
2974 struct pipe_resource
*src
,
2976 const struct pipe_box
*src_box
)
2978 /* XXX implement this or share evergreen_dma_blit with r600g */
2982 void si_init_state_functions(struct r600_context
*rctx
)
2986 rctx
->b
.b
.create_blend_state
= si_create_blend_state
;
2987 rctx
->b
.b
.bind_blend_state
= si_bind_blend_state
;
2988 rctx
->b
.b
.delete_blend_state
= si_delete_blend_state
;
2989 rctx
->b
.b
.set_blend_color
= si_set_blend_color
;
2991 rctx
->b
.b
.create_rasterizer_state
= si_create_rs_state
;
2992 rctx
->b
.b
.bind_rasterizer_state
= si_bind_rs_state
;
2993 rctx
->b
.b
.delete_rasterizer_state
= si_delete_rs_state
;
2995 rctx
->b
.b
.create_depth_stencil_alpha_state
= si_create_dsa_state
;
2996 rctx
->b
.b
.bind_depth_stencil_alpha_state
= si_bind_dsa_state
;
2997 rctx
->b
.b
.delete_depth_stencil_alpha_state
= si_delete_dsa_state
;
2999 for (i
= 0; i
< 8; i
++) {
3000 rctx
->custom_dsa_flush_depth_stencil
[i
] = si_create_db_flush_dsa(rctx
, true, true, i
);
3001 rctx
->custom_dsa_flush_depth
[i
] = si_create_db_flush_dsa(rctx
, true, false, i
);
3002 rctx
->custom_dsa_flush_stencil
[i
] = si_create_db_flush_dsa(rctx
, false, true, i
);
3004 rctx
->custom_dsa_flush_inplace
= si_create_db_flush_dsa(rctx
, false, false, 0);
3005 rctx
->custom_blend_resolve
= si_create_blend_custom(rctx
, V_028808_CB_RESOLVE
);
3006 rctx
->custom_blend_decompress
= si_create_blend_custom(rctx
, V_028808_CB_FMASK_DECOMPRESS
);
3008 rctx
->b
.b
.set_clip_state
= si_set_clip_state
;
3009 rctx
->b
.b
.set_scissor_states
= si_set_scissor_states
;
3010 rctx
->b
.b
.set_viewport_states
= si_set_viewport_states
;
3011 rctx
->b
.b
.set_stencil_ref
= si_set_pipe_stencil_ref
;
3013 rctx
->b
.b
.set_framebuffer_state
= si_set_framebuffer_state
;
3014 rctx
->b
.b
.get_sample_position
= si_get_sample_position
;
3016 rctx
->b
.b
.create_vs_state
= si_create_vs_state
;
3017 rctx
->b
.b
.create_fs_state
= si_create_fs_state
;
3018 rctx
->b
.b
.bind_vs_state
= si_bind_vs_shader
;
3019 rctx
->b
.b
.bind_fs_state
= si_bind_ps_shader
;
3020 rctx
->b
.b
.delete_vs_state
= si_delete_vs_shader
;
3021 rctx
->b
.b
.delete_fs_state
= si_delete_ps_shader
;
3023 rctx
->b
.b
.create_sampler_state
= si_create_sampler_state
;
3024 rctx
->b
.b
.bind_sampler_states
= si_bind_sampler_states
;
3025 rctx
->b
.b
.delete_sampler_state
= si_delete_sampler_state
;
3027 rctx
->b
.b
.create_sampler_view
= si_create_sampler_view
;
3028 rctx
->b
.b
.set_sampler_views
= si_set_sampler_views
;
3029 rctx
->b
.b
.sampler_view_destroy
= si_sampler_view_destroy
;
3031 rctx
->b
.b
.set_sample_mask
= si_set_sample_mask
;
3033 rctx
->b
.b
.create_vertex_elements_state
= si_create_vertex_elements
;
3034 rctx
->b
.b
.bind_vertex_elements_state
= si_bind_vertex_elements
;
3035 rctx
->b
.b
.delete_vertex_elements_state
= si_delete_vertex_element
;
3036 rctx
->b
.b
.set_vertex_buffers
= si_set_vertex_buffers
;
3037 rctx
->b
.b
.set_index_buffer
= si_set_index_buffer
;
3039 rctx
->b
.b
.texture_barrier
= si_texture_barrier
;
3040 rctx
->b
.b
.set_polygon_stipple
= si_set_polygon_stipple
;
3041 rctx
->b
.b
.create_surface
= r600_create_surface
;
3042 rctx
->b
.b
.surface_destroy
= r600_surface_destroy
;
3043 rctx
->b
.dma_copy
= si_dma_copy
;
3045 rctx
->b
.b
.draw_vbo
= si_draw_vbo
;
3048 void si_init_config(struct r600_context
*rctx
)
3050 struct si_pm4_state
*pm4
= si_pm4_alloc_state(rctx
);
3055 si_cmd_context_control(pm4
);
3057 si_pm4_set_reg(pm4
, R_028A4C_PA_SC_MODE_CNTL_1
, 0x0);
3059 si_pm4_set_reg(pm4
, R_028A10_VGT_OUTPUT_PATH_CNTL
, 0x0);
3060 si_pm4_set_reg(pm4
, R_028A14_VGT_HOS_CNTL
, 0x0);
3061 si_pm4_set_reg(pm4
, R_028A18_VGT_HOS_MAX_TESS_LEVEL
, 0x0);
3062 si_pm4_set_reg(pm4
, R_028A1C_VGT_HOS_MIN_TESS_LEVEL
, 0x0);
3063 si_pm4_set_reg(pm4
, R_028A20_VGT_HOS_REUSE_DEPTH
, 0x0);
3064 si_pm4_set_reg(pm4
, R_028A24_VGT_GROUP_PRIM_TYPE
, 0x0);
3065 si_pm4_set_reg(pm4
, R_028A28_VGT_GROUP_FIRST_DECR
, 0x0);
3066 si_pm4_set_reg(pm4
, R_028A2C_VGT_GROUP_DECR
, 0x0);
3067 si_pm4_set_reg(pm4
, R_028A30_VGT_GROUP_VECT_0_CNTL
, 0x0);
3068 si_pm4_set_reg(pm4
, R_028A34_VGT_GROUP_VECT_1_CNTL
, 0x0);
3069 si_pm4_set_reg(pm4
, R_028A38_VGT_GROUP_VECT_0_FMT_CNTL
, 0x0);
3070 si_pm4_set_reg(pm4
, R_028A3C_VGT_GROUP_VECT_1_FMT_CNTL
, 0x0);
3071 si_pm4_set_reg(pm4
, R_028A40_VGT_GS_MODE
, 0x0);
3072 si_pm4_set_reg(pm4
, R_028A84_VGT_PRIMITIVEID_EN
, 0x0);
3073 si_pm4_set_reg(pm4
, R_028A8C_VGT_PRIMITIVEID_RESET
, 0x0);
3074 si_pm4_set_reg(pm4
, R_028B28_VGT_STRMOUT_DRAW_OPAQUE_OFFSET
, 0);
3075 si_pm4_set_reg(pm4
, R_028B94_VGT_STRMOUT_CONFIG
, 0x0);
3076 si_pm4_set_reg(pm4
, R_028B98_VGT_STRMOUT_BUFFER_CONFIG
, 0x0);
3077 if (rctx
->b
.chip_class
== SI
) {
3078 si_pm4_set_reg(pm4
, R_028AA8_IA_MULTI_VGT_PARAM
,
3079 S_028AA8_SWITCH_ON_EOP(1) |
3080 S_028AA8_PARTIAL_VS_WAVE_ON(1) |
3081 S_028AA8_PRIMGROUP_SIZE(63));
3083 si_pm4_set_reg(pm4
, R_028AB4_VGT_REUSE_OFF
, 0x00000000);
3084 si_pm4_set_reg(pm4
, R_028AB8_VGT_VTX_CNT_EN
, 0x0);
3085 if (rctx
->b
.chip_class
< CIK
)
3086 si_pm4_set_reg(pm4
, R_008A14_PA_CL_ENHANCE
, S_008A14_NUM_CLIP_SEQ(3) |
3087 S_008A14_CLIP_VTX_REORDER_ENA(1));
3089 si_pm4_set_reg(pm4
, R_028B54_VGT_SHADER_STAGES_EN
, 0);
3090 si_pm4_set_reg(pm4
, R_028BD4_PA_SC_CENTROID_PRIORITY_0
, 0x76543210);
3091 si_pm4_set_reg(pm4
, R_028BD8_PA_SC_CENTROID_PRIORITY_1
, 0xfedcba98);
3093 si_pm4_set_reg(pm4
, R_02882C_PA_SU_PRIM_FILTER_CNTL
, 0);
3095 if (rctx
->b
.chip_class
>= CIK
) {
3096 switch (rctx
->screen
->b
.family
) {
3098 si_pm4_set_reg(pm4
, R_028350_PA_SC_RASTER_CONFIG
, 0x16000012);
3099 si_pm4_set_reg(pm4
, R_028354_PA_SC_RASTER_CONFIG_1
, 0x00000000);
3106 si_pm4_set_reg(pm4
, R_028350_PA_SC_RASTER_CONFIG
, 0x00000000);
3107 si_pm4_set_reg(pm4
, R_028354_PA_SC_RASTER_CONFIG_1
, 0x00000000);
3111 switch (rctx
->screen
->b
.family
) {
3114 si_pm4_set_reg(pm4
, R_028350_PA_SC_RASTER_CONFIG
, 0x2a00126a);
3117 si_pm4_set_reg(pm4
, R_028350_PA_SC_RASTER_CONFIG
, 0x0000124a);
3120 si_pm4_set_reg(pm4
, R_028350_PA_SC_RASTER_CONFIG
, 0x00000082);
3123 si_pm4_set_reg(pm4
, R_028350_PA_SC_RASTER_CONFIG
, 0x00000000);
3126 si_pm4_set_reg(pm4
, R_028350_PA_SC_RASTER_CONFIG
, 0x00000000);
3131 si_pm4_set_state(rctx
, init
, pm4
);