2 * Copyright 2010 Jerome Glisse <glisse@freedesktop.org>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * - fix mask for depth control & cull for query
29 #include <pipe/p_defines.h>
30 #include <pipe/p_state.h>
31 #include <pipe/p_context.h>
32 #include <tgsi/tgsi_scan.h>
33 #include <tgsi/tgsi_parse.h>
34 #include <tgsi/tgsi_util.h>
35 #include <util/u_double_list.h>
36 #include <util/u_pack_color.h>
37 #include <util/u_memory.h>
38 #include <util/u_inlines.h>
39 #include <util/u_framebuffer.h>
40 #include "util/u_transfer.h"
41 #include <pipebuffer/pb_buffer.h>
44 #include "r600_resource.h"
45 #include "r600_shader.h"
46 #include "r600_pipe.h"
47 #include "r600_state_inlines.h"
49 void r600_polygon_offset_update(struct r600_pipe_context
*rctx
)
51 struct r600_pipe_state state
;
53 state
.id
= R600_PIPE_STATE_POLYGON_OFFSET
;
55 if (rctx
->rasterizer
&& rctx
->framebuffer
.zsbuf
) {
56 float offset_units
= rctx
->rasterizer
->offset_units
;
57 unsigned offset_db_fmt_cntl
= 0, depth
;
59 switch (rctx
->framebuffer
.zsbuf
->texture
->format
) {
60 case PIPE_FORMAT_Z24X8_UNORM
:
61 case PIPE_FORMAT_Z24_UNORM_S8_USCALED
:
65 case PIPE_FORMAT_Z32_FLOAT
:
68 offset_db_fmt_cntl
|= S_028DF8_POLY_OFFSET_DB_IS_FLOAT_FMT(1);
70 case PIPE_FORMAT_Z16_UNORM
:
77 /* FIXME some of those reg can be computed with cso */
78 offset_db_fmt_cntl
|= S_028DF8_POLY_OFFSET_NEG_NUM_DB_BITS(depth
);
79 r600_pipe_state_add_reg(&state
,
80 R_028E00_PA_SU_POLY_OFFSET_FRONT_SCALE
,
81 fui(rctx
->rasterizer
->offset_scale
), 0xFFFFFFFF, NULL
);
82 r600_pipe_state_add_reg(&state
,
83 R_028E04_PA_SU_POLY_OFFSET_FRONT_OFFSET
,
84 fui(offset_units
), 0xFFFFFFFF, NULL
);
85 r600_pipe_state_add_reg(&state
,
86 R_028E08_PA_SU_POLY_OFFSET_BACK_SCALE
,
87 fui(rctx
->rasterizer
->offset_scale
), 0xFFFFFFFF, NULL
);
88 r600_pipe_state_add_reg(&state
,
89 R_028E0C_PA_SU_POLY_OFFSET_BACK_OFFSET
,
90 fui(offset_units
), 0xFFFFFFFF, NULL
);
91 r600_pipe_state_add_reg(&state
,
92 R_028DF8_PA_SU_POLY_OFFSET_DB_FMT_CNTL
,
93 offset_db_fmt_cntl
, 0xFFFFFFFF, NULL
);
94 r600_context_pipe_state_set(&rctx
->ctx
, &state
);
98 static void r600_set_blend_color(struct pipe_context
*ctx
,
99 const struct pipe_blend_color
*state
)
101 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
102 struct r600_pipe_state
*rstate
= CALLOC_STRUCT(r600_pipe_state
);
107 rstate
->id
= R600_PIPE_STATE_BLEND_COLOR
;
108 r600_pipe_state_add_reg(rstate
, R_028414_CB_BLEND_RED
, fui(state
->color
[0]), 0xFFFFFFFF, NULL
);
109 r600_pipe_state_add_reg(rstate
, R_028418_CB_BLEND_GREEN
, fui(state
->color
[1]), 0xFFFFFFFF, NULL
);
110 r600_pipe_state_add_reg(rstate
, R_02841C_CB_BLEND_BLUE
, fui(state
->color
[2]), 0xFFFFFFFF, NULL
);
111 r600_pipe_state_add_reg(rstate
, R_028420_CB_BLEND_ALPHA
, fui(state
->color
[3]), 0xFFFFFFFF, NULL
);
112 free(rctx
->states
[R600_PIPE_STATE_BLEND_COLOR
]);
113 rctx
->states
[R600_PIPE_STATE_BLEND_COLOR
] = rstate
;
114 r600_context_pipe_state_set(&rctx
->ctx
, rstate
);
117 static void *r600_create_blend_state(struct pipe_context
*ctx
,
118 const struct pipe_blend_state
*state
)
120 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
121 struct r600_pipe_blend
*blend
= CALLOC_STRUCT(r600_pipe_blend
);
122 struct r600_pipe_state
*rstate
;
123 u32 color_control
= 0, target_mask
;
128 rstate
= &blend
->rstate
;
130 rstate
->id
= R600_PIPE_STATE_BLEND
;
134 /* R600 does not support per-MRT blends */
135 if (rctx
->family
> CHIP_R600
)
136 color_control
|= S_028808_PER_MRT_BLEND(1);
137 if (state
->logicop_enable
) {
138 color_control
|= (state
->logicop_func
<< 16) | (state
->logicop_func
<< 20);
140 color_control
|= (0xcc << 16);
142 /* we pretend 8 buffer are used, CB_SHADER_MASK will disable unused one */
143 if (state
->independent_blend_enable
) {
144 for (int i
= 0; i
< 8; i
++) {
145 if (state
->rt
[i
].blend_enable
) {
146 color_control
|= S_028808_TARGET_BLEND_ENABLE(1 << i
);
148 target_mask
|= (state
->rt
[i
].colormask
<< (4 * i
));
151 for (int i
= 0; i
< 8; i
++) {
152 if (state
->rt
[0].blend_enable
) {
153 color_control
|= S_028808_TARGET_BLEND_ENABLE(1 << i
);
155 target_mask
|= (state
->rt
[0].colormask
<< (4 * i
));
158 blend
->cb_target_mask
= target_mask
;
159 /* MULTIWRITE_ENABLE is controlled by r600_pipe_shader_ps(). */
160 r600_pipe_state_add_reg(rstate
, R_028808_CB_COLOR_CONTROL
,
161 color_control
, 0xFFFFFFFD, NULL
);
163 for (int i
= 0; i
< 8; i
++) {
164 /* state->rt entries > 0 only written if independent blending */
165 const int j
= state
->independent_blend_enable
? i
: 0;
167 unsigned eqRGB
= state
->rt
[j
].rgb_func
;
168 unsigned srcRGB
= state
->rt
[j
].rgb_src_factor
;
169 unsigned dstRGB
= state
->rt
[j
].rgb_dst_factor
;
171 unsigned eqA
= state
->rt
[j
].alpha_func
;
172 unsigned srcA
= state
->rt
[j
].alpha_src_factor
;
173 unsigned dstA
= state
->rt
[j
].alpha_dst_factor
;
176 if (!state
->rt
[j
].blend_enable
)
179 bc
|= S_028804_COLOR_COMB_FCN(r600_translate_blend_function(eqRGB
));
180 bc
|= S_028804_COLOR_SRCBLEND(r600_translate_blend_factor(srcRGB
));
181 bc
|= S_028804_COLOR_DESTBLEND(r600_translate_blend_factor(dstRGB
));
183 if (srcA
!= srcRGB
|| dstA
!= dstRGB
|| eqA
!= eqRGB
) {
184 bc
|= S_028804_SEPARATE_ALPHA_BLEND(1);
185 bc
|= S_028804_ALPHA_COMB_FCN(r600_translate_blend_function(eqA
));
186 bc
|= S_028804_ALPHA_SRCBLEND(r600_translate_blend_factor(srcA
));
187 bc
|= S_028804_ALPHA_DESTBLEND(r600_translate_blend_factor(dstA
));
190 /* R600 does not support per-MRT blends */
191 if (rctx
->family
> CHIP_R600
)
192 r600_pipe_state_add_reg(rstate
, R_028780_CB_BLEND0_CONTROL
+ i
* 4, bc
, 0xFFFFFFFF, NULL
);
194 r600_pipe_state_add_reg(rstate
, R_028804_CB_BLEND_CONTROL
, bc
, 0xFFFFFFFF, NULL
);
199 static void *r600_create_dsa_state(struct pipe_context
*ctx
,
200 const struct pipe_depth_stencil_alpha_state
*state
)
202 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
203 struct r600_pipe_dsa
*dsa
= CALLOC_STRUCT(r600_pipe_dsa
);
204 unsigned db_depth_control
, alpha_test_control
, alpha_ref
, db_shader_control
;
205 unsigned stencil_ref_mask
, stencil_ref_mask_bf
, db_render_override
, db_render_control
;
206 struct r600_pipe_state
*rstate
;
212 rstate
= &dsa
->rstate
;
214 rstate
->id
= R600_PIPE_STATE_DSA
;
215 /* depth TODO some of those db_shader_control field depend on shader adjust mask & add it to shader */
216 db_shader_control
= S_02880C_Z_ORDER(V_02880C_EARLY_Z_THEN_LATE_Z
);
217 stencil_ref_mask
= 0;
218 stencil_ref_mask_bf
= 0;
219 db_depth_control
= S_028800_Z_ENABLE(state
->depth
.enabled
) |
220 S_028800_Z_WRITE_ENABLE(state
->depth
.writemask
) |
221 S_028800_ZFUNC(state
->depth
.func
);
224 if (state
->stencil
[0].enabled
) {
225 db_depth_control
|= S_028800_STENCIL_ENABLE(1);
226 db_depth_control
|= S_028800_STENCILFUNC(r600_translate_ds_func(state
->stencil
[0].func
));
227 db_depth_control
|= S_028800_STENCILFAIL(r600_translate_stencil_op(state
->stencil
[0].fail_op
));
228 db_depth_control
|= S_028800_STENCILZPASS(r600_translate_stencil_op(state
->stencil
[0].zpass_op
));
229 db_depth_control
|= S_028800_STENCILZFAIL(r600_translate_stencil_op(state
->stencil
[0].zfail_op
));
232 stencil_ref_mask
= S_028430_STENCILMASK(state
->stencil
[0].valuemask
) |
233 S_028430_STENCILWRITEMASK(state
->stencil
[0].writemask
);
234 if (state
->stencil
[1].enabled
) {
235 db_depth_control
|= S_028800_BACKFACE_ENABLE(1);
236 db_depth_control
|= S_028800_STENCILFUNC_BF(r600_translate_ds_func(state
->stencil
[1].func
));
237 db_depth_control
|= S_028800_STENCILFAIL_BF(r600_translate_stencil_op(state
->stencil
[1].fail_op
));
238 db_depth_control
|= S_028800_STENCILZPASS_BF(r600_translate_stencil_op(state
->stencil
[1].zpass_op
));
239 db_depth_control
|= S_028800_STENCILZFAIL_BF(r600_translate_stencil_op(state
->stencil
[1].zfail_op
));
240 stencil_ref_mask_bf
= S_028434_STENCILMASK_BF(state
->stencil
[1].valuemask
) |
241 S_028434_STENCILWRITEMASK_BF(state
->stencil
[1].writemask
);
246 alpha_test_control
= 0;
248 if (state
->alpha
.enabled
) {
249 alpha_test_control
= S_028410_ALPHA_FUNC(state
->alpha
.func
);
250 alpha_test_control
|= S_028410_ALPHA_TEST_ENABLE(1);
251 alpha_ref
= fui(state
->alpha
.ref_value
);
253 dsa
->alpha_ref
= alpha_ref
;
256 db_render_control
= 0;
257 db_render_override
= S_028D10_FORCE_HIZ_ENABLE(V_028D10_FORCE_DISABLE
) |
258 S_028D10_FORCE_HIS_ENABLE0(V_028D10_FORCE_DISABLE
) |
259 S_028D10_FORCE_HIS_ENABLE1(V_028D10_FORCE_DISABLE
);
260 /* TODO db_render_override depends on query */
261 r600_pipe_state_add_reg(rstate
, R_028028_DB_STENCIL_CLEAR
, 0x00000000, 0xFFFFFFFF, NULL
);
262 r600_pipe_state_add_reg(rstate
, R_02802C_DB_DEPTH_CLEAR
, 0x3F800000, 0xFFFFFFFF, NULL
);
263 r600_pipe_state_add_reg(rstate
, R_028410_SX_ALPHA_TEST_CONTROL
, alpha_test_control
, 0xFFFFFFFF, NULL
);
264 r600_pipe_state_add_reg(rstate
,
265 R_028430_DB_STENCILREFMASK
, stencil_ref_mask
,
266 0xFFFFFFFF & C_028430_STENCILREF
, NULL
);
267 r600_pipe_state_add_reg(rstate
,
268 R_028434_DB_STENCILREFMASK_BF
, stencil_ref_mask_bf
,
269 0xFFFFFFFF & C_028434_STENCILREF_BF
, NULL
);
270 r600_pipe_state_add_reg(rstate
, R_0286E0_SPI_FOG_FUNC_SCALE
, 0x00000000, 0xFFFFFFFF, NULL
);
271 r600_pipe_state_add_reg(rstate
, R_0286E4_SPI_FOG_FUNC_BIAS
, 0x00000000, 0xFFFFFFFF, NULL
);
272 r600_pipe_state_add_reg(rstate
, R_0286DC_SPI_FOG_CNTL
, 0x00000000, 0xFFFFFFFF, NULL
);
273 r600_pipe_state_add_reg(rstate
, R_028800_DB_DEPTH_CONTROL
, db_depth_control
, 0xFFFFFFFF, NULL
);
274 /* The DB_SHADER_CONTROL mask is 0xFFFFFFBC since Z_EXPORT_ENABLE,
275 * STENCIL_EXPORT_ENABLE and KILL_ENABLE are controlled by
276 * r600_pipe_shader_ps().*/
277 r600_pipe_state_add_reg(rstate
, R_02880C_DB_SHADER_CONTROL
, db_shader_control
, 0xFFFFFFBC, NULL
);
278 r600_pipe_state_add_reg(rstate
, R_028D0C_DB_RENDER_CONTROL
, db_render_control
, 0xFFFFFFFF, NULL
);
279 r600_pipe_state_add_reg(rstate
, R_028D10_DB_RENDER_OVERRIDE
, db_render_override
, 0xFFFFFFFF, NULL
);
280 r600_pipe_state_add_reg(rstate
, R_028D2C_DB_SRESULTS_COMPARE_STATE1
, 0x00000000, 0xFFFFFFFF, NULL
);
281 r600_pipe_state_add_reg(rstate
, R_028D30_DB_PRELOAD_CONTROL
, 0x00000000, 0xFFFFFFFF, NULL
);
282 r600_pipe_state_add_reg(rstate
, R_028D44_DB_ALPHA_TO_MASK
, 0x0000AA00, 0xFFFFFFFF, NULL
);
287 static void *r600_create_rs_state(struct pipe_context
*ctx
,
288 const struct pipe_rasterizer_state
*state
)
290 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
291 struct r600_pipe_rasterizer
*rs
= CALLOC_STRUCT(r600_pipe_rasterizer
);
292 struct r600_pipe_state
*rstate
;
294 unsigned prov_vtx
= 1, polygon_dual_mode
;
301 rstate
= &rs
->rstate
;
302 rs
->flatshade
= state
->flatshade
;
303 rs
->sprite_coord_enable
= state
->sprite_coord_enable
;
305 clip_rule
= state
->scissor
? 0xAAAA : 0xFFFF;
307 rs
->offset_units
= state
->offset_units
;
308 rs
->offset_scale
= state
->offset_scale
* 12.0f
;
310 rstate
->id
= R600_PIPE_STATE_RASTERIZER
;
311 if (state
->flatshade_first
)
313 tmp
= S_0286D4_FLAT_SHADE_ENA(1);
314 if (state
->sprite_coord_enable
) {
315 tmp
|= S_0286D4_PNT_SPRITE_ENA(1) |
316 S_0286D4_PNT_SPRITE_OVRD_X(2) |
317 S_0286D4_PNT_SPRITE_OVRD_Y(3) |
318 S_0286D4_PNT_SPRITE_OVRD_Z(0) |
319 S_0286D4_PNT_SPRITE_OVRD_W(1);
320 if (state
->sprite_coord_mode
!= PIPE_SPRITE_COORD_UPPER_LEFT
) {
321 tmp
|= S_0286D4_PNT_SPRITE_TOP_1(1);
324 r600_pipe_state_add_reg(rstate
, R_0286D4_SPI_INTERP_CONTROL_0
, tmp
, 0xFFFFFFFF, NULL
);
326 polygon_dual_mode
= (state
->fill_front
!= PIPE_POLYGON_MODE_FILL
||
327 state
->fill_back
!= PIPE_POLYGON_MODE_FILL
);
328 r600_pipe_state_add_reg(rstate
, R_028814_PA_SU_SC_MODE_CNTL
,
329 S_028814_PROVOKING_VTX_LAST(prov_vtx
) |
330 S_028814_CULL_FRONT((state
->cull_face
& PIPE_FACE_FRONT
) ? 1 : 0) |
331 S_028814_CULL_BACK((state
->cull_face
& PIPE_FACE_BACK
) ? 1 : 0) |
332 S_028814_FACE(!state
->front_ccw
) |
333 S_028814_POLY_OFFSET_FRONT_ENABLE(state
->offset_tri
) |
334 S_028814_POLY_OFFSET_BACK_ENABLE(state
->offset_tri
) |
335 S_028814_POLY_OFFSET_PARA_ENABLE(state
->offset_tri
) |
336 S_028814_POLY_MODE(polygon_dual_mode
) |
337 S_028814_POLYMODE_FRONT_PTYPE(r600_translate_fill(state
->fill_front
)) |
338 S_028814_POLYMODE_BACK_PTYPE(r600_translate_fill(state
->fill_back
)), 0xFFFFFFFF, NULL
);
339 r600_pipe_state_add_reg(rstate
, R_02881C_PA_CL_VS_OUT_CNTL
,
340 S_02881C_USE_VTX_POINT_SIZE(state
->point_size_per_vertex
) |
341 S_02881C_VS_OUT_MISC_VEC_ENA(state
->point_size_per_vertex
), 0xFFFFFFFF, NULL
);
342 r600_pipe_state_add_reg(rstate
, R_028820_PA_CL_NANINF_CNTL
, 0x00000000, 0xFFFFFFFF, NULL
);
343 /* point size 12.4 fixed point */
344 tmp
= (unsigned)(state
->point_size
* 8.0);
345 r600_pipe_state_add_reg(rstate
, R_028A00_PA_SU_POINT_SIZE
, S_028A00_HEIGHT(tmp
) | S_028A00_WIDTH(tmp
), 0xFFFFFFFF, NULL
);
346 r600_pipe_state_add_reg(rstate
, R_028A04_PA_SU_POINT_MINMAX
, 0x80000000, 0xFFFFFFFF, NULL
);
348 tmp
= (unsigned)state
->line_width
* 8;
349 r600_pipe_state_add_reg(rstate
, R_028A08_PA_SU_LINE_CNTL
, S_028A08_WIDTH(tmp
), 0xFFFFFFFF, NULL
);
351 r600_pipe_state_add_reg(rstate
, R_028A0C_PA_SC_LINE_STIPPLE
, 0x00000005, 0xFFFFFFFF, NULL
);
352 r600_pipe_state_add_reg(rstate
, R_028A48_PA_SC_MPASS_PS_CNTL
, 0x00000000, 0xFFFFFFFF, NULL
);
353 r600_pipe_state_add_reg(rstate
, R_028C00_PA_SC_LINE_CNTL
, 0x00000400, 0xFFFFFFFF, NULL
);
355 r600_pipe_state_add_reg(rstate
, R_028C08_PA_SU_VTX_CNTL
,
356 S_028C08_PIX_CENTER_HALF(state
->gl_rasterization_rules
),
359 r600_pipe_state_add_reg(rstate
, R_028C0C_PA_CL_GB_VERT_CLIP_ADJ
, 0x3F800000, 0xFFFFFFFF, NULL
);
360 r600_pipe_state_add_reg(rstate
, R_028C10_PA_CL_GB_VERT_DISC_ADJ
, 0x3F800000, 0xFFFFFFFF, NULL
);
361 r600_pipe_state_add_reg(rstate
, R_028C14_PA_CL_GB_HORZ_CLIP_ADJ
, 0x3F800000, 0xFFFFFFFF, NULL
);
362 r600_pipe_state_add_reg(rstate
, R_028C18_PA_CL_GB_HORZ_DISC_ADJ
, 0x3F800000, 0xFFFFFFFF, NULL
);
363 r600_pipe_state_add_reg(rstate
, R_028DFC_PA_SU_POLY_OFFSET_CLAMP
, 0x00000000, 0xFFFFFFFF, NULL
);
364 r600_pipe_state_add_reg(rstate
, R_02820C_PA_SC_CLIPRECT_RULE
, clip_rule
, 0xFFFFFFFF, NULL
);
369 static void *r600_create_sampler_state(struct pipe_context
*ctx
,
370 const struct pipe_sampler_state
*state
)
372 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
373 struct r600_pipe_state
*rstate
= CALLOC_STRUCT(r600_pipe_state
);
375 unsigned aniso_flag_offset
= state
->max_anisotropy
> 1 ? 4 : 0;
377 if (rstate
== NULL
) {
381 rstate
->id
= R600_PIPE_STATE_SAMPLER
;
382 util_pack_color(state
->border_color
, PIPE_FORMAT_B8G8R8A8_UNORM
, &uc
);
383 r600_pipe_state_add_reg(rstate
, R_03C000_SQ_TEX_SAMPLER_WORD0_0
,
384 S_03C000_CLAMP_X(r600_tex_wrap(state
->wrap_s
)) |
385 S_03C000_CLAMP_Y(r600_tex_wrap(state
->wrap_t
)) |
386 S_03C000_CLAMP_Z(r600_tex_wrap(state
->wrap_r
)) |
387 S_03C000_XY_MAG_FILTER(r600_tex_filter(state
->mag_img_filter
) | aniso_flag_offset
) |
388 S_03C000_XY_MIN_FILTER(r600_tex_filter(state
->min_img_filter
) | aniso_flag_offset
) |
389 S_03C000_MIP_FILTER(r600_tex_mipfilter(state
->min_mip_filter
)) |
390 S_03C000_MAX_ANISO(r600_tex_aniso_filter(state
->max_anisotropy
)) |
391 S_03C000_DEPTH_COMPARE_FUNCTION(r600_tex_compare(state
->compare_func
)) |
392 S_03C000_BORDER_COLOR_TYPE(uc
.ui
? V_03C000_SQ_TEX_BORDER_COLOR_REGISTER
: 0), 0xFFFFFFFF, NULL
);
393 r600_pipe_state_add_reg(rstate
, R_03C004_SQ_TEX_SAMPLER_WORD1_0
,
394 S_03C004_MIN_LOD(S_FIXED(CLAMP(state
->min_lod
, 0, 15), 6)) |
395 S_03C004_MAX_LOD(S_FIXED(CLAMP(state
->max_lod
, 0, 15), 6)) |
396 S_03C004_LOD_BIAS(S_FIXED(CLAMP(state
->lod_bias
, -16, 16), 6)), 0xFFFFFFFF, NULL
);
397 r600_pipe_state_add_reg(rstate
, R_03C008_SQ_TEX_SAMPLER_WORD2_0
, S_03C008_TYPE(1), 0xFFFFFFFF, NULL
);
399 r600_pipe_state_add_reg(rstate
, R_00A400_TD_PS_SAMPLER0_BORDER_RED
, fui(state
->border_color
[0]), 0xFFFFFFFF, NULL
);
400 r600_pipe_state_add_reg(rstate
, R_00A404_TD_PS_SAMPLER0_BORDER_GREEN
, fui(state
->border_color
[1]), 0xFFFFFFFF, NULL
);
401 r600_pipe_state_add_reg(rstate
, R_00A408_TD_PS_SAMPLER0_BORDER_BLUE
, fui(state
->border_color
[2]), 0xFFFFFFFF, NULL
);
402 r600_pipe_state_add_reg(rstate
, R_00A40C_TD_PS_SAMPLER0_BORDER_ALPHA
, fui(state
->border_color
[3]), 0xFFFFFFFF, NULL
);
407 static struct pipe_sampler_view
*r600_create_sampler_view(struct pipe_context
*ctx
,
408 struct pipe_resource
*texture
,
409 const struct pipe_sampler_view
*state
)
411 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
412 struct r600_pipe_sampler_view
*resource
= CALLOC_STRUCT(r600_pipe_sampler_view
);
413 struct r600_pipe_state
*rstate
;
414 const struct util_format_description
*desc
;
415 struct r600_resource_texture
*tmp
;
416 struct r600_resource
*rbuffer
;
417 unsigned format
, endian
;
418 uint32_t word4
= 0, yuv_format
= 0, pitch
= 0;
419 unsigned char swizzle
[4], array_mode
= 0, tile_type
= 0;
420 struct r600_bo
*bo
[2];
421 unsigned height
, depth
;
423 if (resource
== NULL
)
425 rstate
= &resource
->state
;
427 /* initialize base object */
428 resource
->base
= *state
;
429 resource
->base
.texture
= NULL
;
430 pipe_reference(NULL
, &texture
->reference
);
431 resource
->base
.texture
= texture
;
432 resource
->base
.reference
.count
= 1;
433 resource
->base
.context
= ctx
;
435 swizzle
[0] = state
->swizzle_r
;
436 swizzle
[1] = state
->swizzle_g
;
437 swizzle
[2] = state
->swizzle_b
;
438 swizzle
[3] = state
->swizzle_a
;
439 format
= r600_translate_texformat(ctx
->screen
, state
->format
,
441 &word4
, &yuv_format
);
445 desc
= util_format_description(state
->format
);
447 R600_ERR("unknow format %d\n", state
->format
);
449 tmp
= (struct r600_resource_texture
*)texture
;
450 if (tmp
->depth
&& !tmp
->is_flushing_texture
) {
451 r600_texture_depth_flush(ctx
, texture
, TRUE
);
452 tmp
= tmp
->flushed_depth_texture
;
454 endian
= r600_colorformat_endian_swap(format
);
456 if (tmp
->force_int_type
) {
457 word4
&= C_038010_NUM_FORMAT_ALL
;
458 word4
|= S_038010_NUM_FORMAT_ALL(V_038010_SQ_NUM_FORMAT_INT
);
460 rbuffer
= &tmp
->resource
;
463 pitch
= align(tmp
->pitch_in_blocks
[0] * util_format_get_blockwidth(state
->format
), 8);
464 array_mode
= tmp
->array_mode
[0];
465 tile_type
= tmp
->tile_type
;
467 height
= texture
->height0
;
468 depth
= texture
->depth0
;
469 if (texture
->target
== PIPE_TEXTURE_1D_ARRAY
) {
471 depth
= texture
->array_size
;
472 } else if (texture
->target
== PIPE_TEXTURE_2D_ARRAY
) {
473 depth
= texture
->array_size
;
476 r600_pipe_state_add_reg(rstate
, R_038000_RESOURCE0_WORD0
,
477 S_038000_DIM(r600_tex_dim(texture
->target
)) |
478 S_038000_TILE_MODE(array_mode
) |
479 S_038000_TILE_TYPE(tile_type
) |
480 S_038000_PITCH((pitch
/ 8) - 1) |
481 S_038000_TEX_WIDTH(texture
->width0
- 1), 0xFFFFFFFF, NULL
);
482 r600_pipe_state_add_reg(rstate
, R_038004_RESOURCE0_WORD1
,
483 S_038004_TEX_HEIGHT(height
- 1) |
484 S_038004_TEX_DEPTH(depth
- 1) |
485 S_038004_DATA_FORMAT(format
), 0xFFFFFFFF, NULL
);
486 r600_pipe_state_add_reg(rstate
, R_038008_RESOURCE0_WORD2
,
487 (tmp
->offset
[0] + r600_bo_offset(bo
[0])) >> 8, 0xFFFFFFFF, bo
[0]);
488 r600_pipe_state_add_reg(rstate
, R_03800C_RESOURCE0_WORD3
,
489 (tmp
->offset
[1] + r600_bo_offset(bo
[1])) >> 8, 0xFFFFFFFF, bo
[1]);
490 r600_pipe_state_add_reg(rstate
, R_038010_RESOURCE0_WORD4
,
492 S_038010_SRF_MODE_ALL(V_038010_SRF_MODE_ZERO_CLAMP_MINUS_ONE
) |
493 S_038010_REQUEST_SIZE(1) |
494 S_038010_ENDIAN_SWAP(endian
) |
495 S_038010_BASE_LEVEL(state
->u
.tex
.first_level
), 0xFFFFFFFF, NULL
);
496 r600_pipe_state_add_reg(rstate
, R_038014_RESOURCE0_WORD5
,
497 S_038014_LAST_LEVEL(state
->u
.tex
.last_level
) |
498 S_038014_BASE_ARRAY(state
->u
.tex
.first_layer
) |
499 S_038014_LAST_ARRAY(state
->u
.tex
.last_layer
), 0xFFFFFFFF, NULL
);
500 r600_pipe_state_add_reg(rstate
, R_038018_RESOURCE0_WORD6
,
501 S_038018_TYPE(V_038010_SQ_TEX_VTX_VALID_TEXTURE
) |
502 S_038018_MAX_ANISO(4 /* max 16 samples */), 0xFFFFFFFF, NULL
);
504 return &resource
->base
;
507 static void r600_set_vs_sampler_view(struct pipe_context
*ctx
, unsigned count
,
508 struct pipe_sampler_view
**views
)
510 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
511 struct r600_pipe_sampler_view
**resource
= (struct r600_pipe_sampler_view
**)views
;
513 for (int i
= 0; i
< count
; i
++) {
515 r600_context_pipe_state_set_vs_resource(&rctx
->ctx
, &resource
[i
]->state
,
516 i
+ R600_MAX_CONST_BUFFERS
);
521 static void r600_set_ps_sampler_view(struct pipe_context
*ctx
, unsigned count
,
522 struct pipe_sampler_view
**views
)
524 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
525 struct r600_pipe_sampler_view
**resource
= (struct r600_pipe_sampler_view
**)views
;
528 for (i
= 0; i
< count
; i
++) {
529 if (&rctx
->ps_samplers
.views
[i
]->base
!= views
[i
]) {
531 r600_context_pipe_state_set_ps_resource(&rctx
->ctx
, &resource
[i
]->state
,
532 i
+ R600_MAX_CONST_BUFFERS
);
534 r600_context_pipe_state_set_ps_resource(&rctx
->ctx
, NULL
,
535 i
+ R600_MAX_CONST_BUFFERS
);
537 pipe_sampler_view_reference(
538 (struct pipe_sampler_view
**)&rctx
->ps_samplers
.views
[i
],
543 for (i
= count
; i
< NUM_TEX_UNITS
; i
++) {
544 if (rctx
->ps_samplers
.views
[i
]) {
545 r600_context_pipe_state_set_ps_resource(&rctx
->ctx
, NULL
,
546 i
+ R600_MAX_CONST_BUFFERS
);
547 pipe_sampler_view_reference((struct pipe_sampler_view
**)&rctx
->ps_samplers
.views
[i
], NULL
);
550 rctx
->ps_samplers
.n_views
= count
;
553 static void r600_bind_ps_sampler(struct pipe_context
*ctx
, unsigned count
, void **states
)
555 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
556 struct r600_pipe_state
**rstates
= (struct r600_pipe_state
**)states
;
558 memcpy(rctx
->ps_samplers
.samplers
, states
, sizeof(void*) * count
);
559 rctx
->ps_samplers
.n_samplers
= count
;
561 for (int i
= 0; i
< count
; i
++) {
562 r600_context_pipe_state_set_ps_sampler(&rctx
->ctx
, rstates
[i
], i
);
566 static void r600_bind_vs_sampler(struct pipe_context
*ctx
, unsigned count
, void **states
)
568 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
569 struct r600_pipe_state
**rstates
= (struct r600_pipe_state
**)states
;
571 for (int i
= 0; i
< count
; i
++) {
572 r600_context_pipe_state_set_vs_sampler(&rctx
->ctx
, rstates
[i
], i
);
576 static void r600_set_clip_state(struct pipe_context
*ctx
,
577 const struct pipe_clip_state
*state
)
579 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
580 struct r600_pipe_state
*rstate
= CALLOC_STRUCT(r600_pipe_state
);
586 rstate
->id
= R600_PIPE_STATE_CLIP
;
587 for (int i
= 0; i
< state
->nr
; i
++) {
588 r600_pipe_state_add_reg(rstate
,
589 R_028E20_PA_CL_UCP0_X
+ i
* 16,
590 fui(state
->ucp
[i
][0]), 0xFFFFFFFF, NULL
);
591 r600_pipe_state_add_reg(rstate
,
592 R_028E24_PA_CL_UCP0_Y
+ i
* 16,
593 fui(state
->ucp
[i
][1]) , 0xFFFFFFFF, NULL
);
594 r600_pipe_state_add_reg(rstate
,
595 R_028E28_PA_CL_UCP0_Z
+ i
* 16,
596 fui(state
->ucp
[i
][2]), 0xFFFFFFFF, NULL
);
597 r600_pipe_state_add_reg(rstate
,
598 R_028E2C_PA_CL_UCP0_W
+ i
* 16,
599 fui(state
->ucp
[i
][3]), 0xFFFFFFFF, NULL
);
601 r600_pipe_state_add_reg(rstate
, R_028810_PA_CL_CLIP_CNTL
,
602 S_028810_PS_UCP_MODE(3) | ((1 << state
->nr
) - 1) |
603 S_028810_ZCLIP_NEAR_DISABLE(state
->depth_clamp
) |
604 S_028810_ZCLIP_FAR_DISABLE(state
->depth_clamp
), 0xFFFFFFFF, NULL
);
606 free(rctx
->states
[R600_PIPE_STATE_CLIP
]);
607 rctx
->states
[R600_PIPE_STATE_CLIP
] = rstate
;
608 r600_context_pipe_state_set(&rctx
->ctx
, rstate
);
611 static void r600_set_polygon_stipple(struct pipe_context
*ctx
,
612 const struct pipe_poly_stipple
*state
)
616 static void r600_set_sample_mask(struct pipe_context
*pipe
, unsigned sample_mask
)
620 static void r600_set_scissor_state(struct pipe_context
*ctx
,
621 const struct pipe_scissor_state
*state
)
623 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
624 struct r600_pipe_state
*rstate
= CALLOC_STRUCT(r600_pipe_state
);
630 rstate
->id
= R600_PIPE_STATE_SCISSOR
;
631 tl
= S_028240_TL_X(state
->minx
) | S_028240_TL_Y(state
->miny
) | S_028240_WINDOW_OFFSET_DISABLE(1);
632 br
= S_028244_BR_X(state
->maxx
) | S_028244_BR_Y(state
->maxy
);
633 r600_pipe_state_add_reg(rstate
,
634 R_028210_PA_SC_CLIPRECT_0_TL
, tl
,
636 r600_pipe_state_add_reg(rstate
,
637 R_028214_PA_SC_CLIPRECT_0_BR
, br
,
639 r600_pipe_state_add_reg(rstate
,
640 R_028218_PA_SC_CLIPRECT_1_TL
, tl
,
642 r600_pipe_state_add_reg(rstate
,
643 R_02821C_PA_SC_CLIPRECT_1_BR
, br
,
645 r600_pipe_state_add_reg(rstate
,
646 R_028220_PA_SC_CLIPRECT_2_TL
, tl
,
648 r600_pipe_state_add_reg(rstate
,
649 R_028224_PA_SC_CLIPRECT_2_BR
, br
,
651 r600_pipe_state_add_reg(rstate
,
652 R_028228_PA_SC_CLIPRECT_3_TL
, tl
,
654 r600_pipe_state_add_reg(rstate
,
655 R_02822C_PA_SC_CLIPRECT_3_BR
, br
,
658 free(rctx
->states
[R600_PIPE_STATE_SCISSOR
]);
659 rctx
->states
[R600_PIPE_STATE_SCISSOR
] = rstate
;
660 r600_context_pipe_state_set(&rctx
->ctx
, rstate
);
663 static void r600_set_stencil_ref(struct pipe_context
*ctx
,
664 const struct pipe_stencil_ref
*state
)
666 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
667 struct r600_pipe_state
*rstate
= CALLOC_STRUCT(r600_pipe_state
);
673 rctx
->stencil_ref
= *state
;
674 rstate
->id
= R600_PIPE_STATE_STENCIL_REF
;
675 tmp
= S_028430_STENCILREF(state
->ref_value
[0]);
676 r600_pipe_state_add_reg(rstate
,
677 R_028430_DB_STENCILREFMASK
, tmp
,
678 ~C_028430_STENCILREF
, NULL
);
679 tmp
= S_028434_STENCILREF_BF(state
->ref_value
[1]);
680 r600_pipe_state_add_reg(rstate
,
681 R_028434_DB_STENCILREFMASK_BF
, tmp
,
682 ~C_028434_STENCILREF_BF
, NULL
);
684 free(rctx
->states
[R600_PIPE_STATE_STENCIL_REF
]);
685 rctx
->states
[R600_PIPE_STATE_STENCIL_REF
] = rstate
;
686 r600_context_pipe_state_set(&rctx
->ctx
, rstate
);
689 static void r600_set_viewport_state(struct pipe_context
*ctx
,
690 const struct pipe_viewport_state
*state
)
692 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
693 struct r600_pipe_state
*rstate
= CALLOC_STRUCT(r600_pipe_state
);
698 rctx
->viewport
= *state
;
699 rstate
->id
= R600_PIPE_STATE_VIEWPORT
;
700 r600_pipe_state_add_reg(rstate
, R_0282D0_PA_SC_VPORT_ZMIN_0
, 0x00000000, 0xFFFFFFFF, NULL
);
701 r600_pipe_state_add_reg(rstate
, R_0282D4_PA_SC_VPORT_ZMAX_0
, 0x3F800000, 0xFFFFFFFF, NULL
);
702 r600_pipe_state_add_reg(rstate
, R_02843C_PA_CL_VPORT_XSCALE_0
, fui(state
->scale
[0]), 0xFFFFFFFF, NULL
);
703 r600_pipe_state_add_reg(rstate
, R_028444_PA_CL_VPORT_YSCALE_0
, fui(state
->scale
[1]), 0xFFFFFFFF, NULL
);
704 r600_pipe_state_add_reg(rstate
, R_02844C_PA_CL_VPORT_ZSCALE_0
, fui(state
->scale
[2]), 0xFFFFFFFF, NULL
);
705 r600_pipe_state_add_reg(rstate
, R_028440_PA_CL_VPORT_XOFFSET_0
, fui(state
->translate
[0]), 0xFFFFFFFF, NULL
);
706 r600_pipe_state_add_reg(rstate
, R_028448_PA_CL_VPORT_YOFFSET_0
, fui(state
->translate
[1]), 0xFFFFFFFF, NULL
);
707 r600_pipe_state_add_reg(rstate
, R_028450_PA_CL_VPORT_ZOFFSET_0
, fui(state
->translate
[2]), 0xFFFFFFFF, NULL
);
708 r600_pipe_state_add_reg(rstate
, R_028818_PA_CL_VTE_CNTL
, 0x0000043F, 0xFFFFFFFF, NULL
);
710 free(rctx
->states
[R600_PIPE_STATE_VIEWPORT
]);
711 rctx
->states
[R600_PIPE_STATE_VIEWPORT
] = rstate
;
712 r600_context_pipe_state_set(&rctx
->ctx
, rstate
);
715 static void r600_cb(struct r600_pipe_context
*rctx
, struct r600_pipe_state
*rstate
,
716 const struct pipe_framebuffer_state
*state
, int cb
)
718 struct r600_resource_texture
*rtex
;
719 struct r600_resource
*rbuffer
;
720 struct r600_surface
*surf
;
721 unsigned level
= state
->cbufs
[cb
]->u
.tex
.level
;
722 unsigned pitch
, slice
;
724 unsigned format
, swap
, ntype
, endian
;
726 const struct util_format_description
*desc
;
727 struct r600_bo
*bo
[3];
730 surf
= (struct r600_surface
*)state
->cbufs
[cb
];
731 rtex
= (struct r600_resource_texture
*)state
->cbufs
[cb
]->texture
;
733 if (rtex
->depth
&& !rtex
->is_flushing_texture
) {
734 r600_texture_depth_flush(&rctx
->context
, state
->cbufs
[cb
]->texture
, TRUE
);
735 rtex
= rtex
->flushed_depth_texture
;
738 rbuffer
= &rtex
->resource
;
743 /* XXX quite sure for dx10+ hw don't need any offset hacks */
744 offset
= r600_texture_get_offset(rtex
,
745 level
, state
->cbufs
[cb
]->u
.tex
.first_layer
);
746 pitch
= rtex
->pitch_in_blocks
[level
] / 8 - 1;
747 slice
= rtex
->pitch_in_blocks
[level
] * surf
->aligned_height
/ 64 - 1;
748 desc
= util_format_description(surf
->base
.format
);
750 for (i
= 0; i
< 4; i
++) {
751 if (desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_VOID
) {
755 ntype
= V_0280A0_NUMBER_UNORM
;
756 if (desc
->colorspace
== UTIL_FORMAT_COLORSPACE_SRGB
)
757 ntype
= V_0280A0_NUMBER_SRGB
;
758 else if (desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_SIGNED
)
759 ntype
= V_0280A0_NUMBER_SNORM
;
761 format
= r600_translate_colorformat(surf
->base
.format
);
762 swap
= r600_translate_colorswap(surf
->base
.format
);
763 if(rbuffer
->b
.b
.b
.usage
== PIPE_USAGE_STAGING
) {
764 endian
= ENDIAN_NONE
;
766 endian
= r600_colorformat_endian_swap(format
);
769 /* disable when gallium grows int textures */
770 if ((format
== FMT_32_32_32_32
|| format
== FMT_16_16_16_16
) && rtex
->force_int_type
)
771 ntype
= V_0280A0_NUMBER_UINT
;
773 color_info
= S_0280A0_FORMAT(format
) |
774 S_0280A0_COMP_SWAP(swap
) |
775 S_0280A0_ARRAY_MODE(rtex
->array_mode
[level
]) |
776 S_0280A0_BLEND_CLAMP(1) |
777 S_0280A0_NUMBER_TYPE(ntype
) |
778 S_0280A0_ENDIAN(endian
);
780 /* EXPORT_NORM is an optimzation that can be enabled for better
781 * performance in certain cases
783 if (rctx
->family
< CHIP_RV770
) {
784 /* EXPORT_NORM can be enabled if:
785 * - 11-bit or smaller UNORM/SNORM/SRGB
786 * - BLEND_CLAMP is enabled
787 * - BLEND_FLOAT32 is disabled
789 if (desc
->colorspace
!= UTIL_FORMAT_COLORSPACE_ZS
&&
790 (desc
->channel
[i
].size
< 12 &&
791 desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_FLOAT
&&
792 ntype
!= V_0280A0_NUMBER_UINT
&&
793 ntype
!= V_0280A0_NUMBER_SINT
) &&
794 G_0280A0_BLEND_CLAMP(color_info
) &&
795 !G_0280A0_BLEND_FLOAT32(color_info
))
796 color_info
|= S_0280A0_SOURCE_FORMAT(V_0280A0_EXPORT_NORM
);
798 /* EXPORT_NORM can be enabled if:
799 * - 11-bit or smaller UNORM/SNORM/SRGB
800 * - 16-bit or smaller FLOAT
802 if (desc
->colorspace
!= UTIL_FORMAT_COLORSPACE_ZS
&&
803 ((desc
->channel
[i
].size
< 12 &&
804 desc
->channel
[i
].type
!= UTIL_FORMAT_TYPE_FLOAT
&&
805 ntype
!= V_0280A0_NUMBER_UINT
&& ntype
!= V_0280A0_NUMBER_SINT
) ||
806 (desc
->channel
[i
].size
< 17 &&
807 desc
->channel
[i
].type
== UTIL_FORMAT_TYPE_FLOAT
)))
808 color_info
|= S_0280A0_SOURCE_FORMAT(V_0280A0_EXPORT_NORM
);
811 r600_pipe_state_add_reg(rstate
,
812 R_028040_CB_COLOR0_BASE
+ cb
* 4,
813 (offset
+ r600_bo_offset(bo
[0])) >> 8, 0xFFFFFFFF, bo
[0]);
814 r600_pipe_state_add_reg(rstate
,
815 R_0280A0_CB_COLOR0_INFO
+ cb
* 4,
816 color_info
, 0xFFFFFFFF, bo
[0]);
817 r600_pipe_state_add_reg(rstate
,
818 R_028060_CB_COLOR0_SIZE
+ cb
* 4,
819 S_028060_PITCH_TILE_MAX(pitch
) |
820 S_028060_SLICE_TILE_MAX(slice
),
822 r600_pipe_state_add_reg(rstate
,
823 R_028080_CB_COLOR0_VIEW
+ cb
* 4,
824 0x00000000, 0xFFFFFFFF, NULL
);
825 r600_pipe_state_add_reg(rstate
,
826 R_0280E0_CB_COLOR0_FRAG
+ cb
* 4,
827 r600_bo_offset(bo
[1]) >> 8, 0xFFFFFFFF, bo
[1]);
828 r600_pipe_state_add_reg(rstate
,
829 R_0280C0_CB_COLOR0_TILE
+ cb
* 4,
830 r600_bo_offset(bo
[2]) >> 8, 0xFFFFFFFF, bo
[2]);
831 r600_pipe_state_add_reg(rstate
,
832 R_028100_CB_COLOR0_MASK
+ cb
* 4,
833 0x00000000, 0xFFFFFFFF, NULL
);
836 static void r600_db(struct r600_pipe_context
*rctx
, struct r600_pipe_state
*rstate
,
837 const struct pipe_framebuffer_state
*state
)
839 struct r600_resource_texture
*rtex
;
840 struct r600_resource
*rbuffer
;
841 struct r600_surface
*surf
;
843 unsigned pitch
, slice
, format
;
846 if (state
->zsbuf
== NULL
)
849 level
= state
->zsbuf
->u
.tex
.level
;
851 surf
= (struct r600_surface
*)state
->zsbuf
;
852 rtex
= (struct r600_resource_texture
*)state
->zsbuf
->texture
;
854 rbuffer
= &rtex
->resource
;
856 /* XXX quite sure for dx10+ hw don't need any offset hacks */
857 offset
= r600_texture_get_offset((struct r600_resource_texture
*)state
->zsbuf
->texture
,
858 level
, state
->zsbuf
->u
.tex
.first_layer
);
859 pitch
= rtex
->pitch_in_blocks
[level
] / 8 - 1;
860 slice
= rtex
->pitch_in_blocks
[level
] * surf
->aligned_height
/ 64 - 1;
861 format
= r600_translate_dbformat(state
->zsbuf
->texture
->format
);
863 r600_pipe_state_add_reg(rstate
, R_02800C_DB_DEPTH_BASE
,
864 (offset
+ r600_bo_offset(rbuffer
->bo
)) >> 8, 0xFFFFFFFF, rbuffer
->bo
);
865 r600_pipe_state_add_reg(rstate
, R_028000_DB_DEPTH_SIZE
,
866 S_028000_PITCH_TILE_MAX(pitch
) | S_028000_SLICE_TILE_MAX(slice
),
868 r600_pipe_state_add_reg(rstate
, R_028004_DB_DEPTH_VIEW
, 0x00000000, 0xFFFFFFFF, NULL
);
869 r600_pipe_state_add_reg(rstate
, R_028010_DB_DEPTH_INFO
,
870 S_028010_ARRAY_MODE(rtex
->array_mode
[level
]) | S_028010_FORMAT(format
),
871 0xFFFFFFFF, rbuffer
->bo
);
872 r600_pipe_state_add_reg(rstate
, R_028D34_DB_PREFETCH_LIMIT
,
873 (surf
->aligned_height
/ 8) - 1, 0xFFFFFFFF, NULL
);
876 static void r600_set_framebuffer_state(struct pipe_context
*ctx
,
877 const struct pipe_framebuffer_state
*state
)
879 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
880 struct r600_pipe_state
*rstate
= CALLOC_STRUCT(r600_pipe_state
);
881 u32 shader_mask
, tl
, br
, shader_control
, target_mask
;
886 r600_context_flush_dest_caches(&rctx
->ctx
);
887 rctx
->ctx
.num_dest_buffers
= state
->nr_cbufs
;
889 /* unreference old buffer and reference new one */
890 rstate
->id
= R600_PIPE_STATE_FRAMEBUFFER
;
892 util_copy_framebuffer_state(&rctx
->framebuffer
, state
);
895 for (int i
= 0; i
< state
->nr_cbufs
; i
++) {
896 r600_cb(rctx
, rstate
, state
, i
);
899 r600_db(rctx
, rstate
, state
);
900 rctx
->ctx
.num_dest_buffers
++;
903 target_mask
= 0x00000000;
904 target_mask
= 0xFFFFFFFF;
907 for (int i
= 0; i
< state
->nr_cbufs
; i
++) {
908 target_mask
^= 0xf << (i
* 4);
909 shader_mask
|= 0xf << (i
* 4);
910 shader_control
|= 1 << i
;
912 tl
= S_028240_TL_X(0) | S_028240_TL_Y(0) | S_028240_WINDOW_OFFSET_DISABLE(1);
913 br
= S_028244_BR_X(state
->width
) | S_028244_BR_Y(state
->height
);
915 r600_pipe_state_add_reg(rstate
,
916 R_028030_PA_SC_SCREEN_SCISSOR_TL
, tl
,
918 r600_pipe_state_add_reg(rstate
,
919 R_028034_PA_SC_SCREEN_SCISSOR_BR
, br
,
921 r600_pipe_state_add_reg(rstate
,
922 R_028204_PA_SC_WINDOW_SCISSOR_TL
, tl
,
924 r600_pipe_state_add_reg(rstate
,
925 R_028208_PA_SC_WINDOW_SCISSOR_BR
, br
,
927 r600_pipe_state_add_reg(rstate
,
928 R_028240_PA_SC_GENERIC_SCISSOR_TL
, tl
,
930 r600_pipe_state_add_reg(rstate
,
931 R_028244_PA_SC_GENERIC_SCISSOR_BR
, br
,
933 r600_pipe_state_add_reg(rstate
,
934 R_028250_PA_SC_VPORT_SCISSOR_0_TL
, tl
,
936 r600_pipe_state_add_reg(rstate
,
937 R_028254_PA_SC_VPORT_SCISSOR_0_BR
, br
,
939 r600_pipe_state_add_reg(rstate
,
940 R_028200_PA_SC_WINDOW_OFFSET
, 0x00000000,
942 if (rctx
->family
>= CHIP_RV770
) {
943 r600_pipe_state_add_reg(rstate
,
944 R_028230_PA_SC_EDGERULE
, 0xAAAAAAAA,
948 r600_pipe_state_add_reg(rstate
, R_0287A0_CB_SHADER_CONTROL
,
949 shader_control
, 0xFFFFFFFF, NULL
);
950 r600_pipe_state_add_reg(rstate
, R_028238_CB_TARGET_MASK
,
951 0x00000000, target_mask
, NULL
);
952 r600_pipe_state_add_reg(rstate
, R_02823C_CB_SHADER_MASK
,
953 shader_mask
, 0xFFFFFFFF, NULL
);
954 r600_pipe_state_add_reg(rstate
, R_028C04_PA_SC_AA_CONFIG
,
955 0x00000000, 0xFFFFFFFF, NULL
);
956 r600_pipe_state_add_reg(rstate
, R_028C1C_PA_SC_AA_SAMPLE_LOCS_MCTX
,
957 0x00000000, 0xFFFFFFFF, NULL
);
958 r600_pipe_state_add_reg(rstate
, R_028C20_PA_SC_AA_SAMPLE_LOCS_8S_WD1_MCTX
,
959 0x00000000, 0xFFFFFFFF, NULL
);
960 r600_pipe_state_add_reg(rstate
, R_028C30_CB_CLRCMP_CONTROL
,
961 0x01000000, 0xFFFFFFFF, NULL
);
962 r600_pipe_state_add_reg(rstate
, R_028C34_CB_CLRCMP_SRC
,
963 0x00000000, 0xFFFFFFFF, NULL
);
964 r600_pipe_state_add_reg(rstate
, R_028C38_CB_CLRCMP_DST
,
965 0x000000FF, 0xFFFFFFFF, NULL
);
966 r600_pipe_state_add_reg(rstate
, R_028C3C_CB_CLRCMP_MSK
,
967 0xFFFFFFFF, 0xFFFFFFFF, NULL
);
968 r600_pipe_state_add_reg(rstate
, R_028C48_PA_SC_AA_MASK
,
969 0xFFFFFFFF, 0xFFFFFFFF, NULL
);
971 free(rctx
->states
[R600_PIPE_STATE_FRAMEBUFFER
]);
972 rctx
->states
[R600_PIPE_STATE_FRAMEBUFFER
] = rstate
;
973 r600_context_pipe_state_set(&rctx
->ctx
, rstate
);
976 r600_polygon_offset_update(rctx
);
980 static void r600_texture_barrier(struct pipe_context
*ctx
)
982 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
984 r600_context_flush_all(&rctx
->ctx
, S_0085F0_TC_ACTION_ENA(1) | S_0085F0_CB_ACTION_ENA(1) |
985 S_0085F0_CB0_DEST_BASE_ENA(1) | S_0085F0_CB1_DEST_BASE_ENA(1) |
986 S_0085F0_CB2_DEST_BASE_ENA(1) | S_0085F0_CB3_DEST_BASE_ENA(1) |
987 S_0085F0_CB4_DEST_BASE_ENA(1) | S_0085F0_CB5_DEST_BASE_ENA(1) |
988 S_0085F0_CB6_DEST_BASE_ENA(1) | S_0085F0_CB7_DEST_BASE_ENA(1));
991 void r600_init_state_functions(struct r600_pipe_context
*rctx
)
993 rctx
->context
.create_blend_state
= r600_create_blend_state
;
994 rctx
->context
.create_depth_stencil_alpha_state
= r600_create_dsa_state
;
995 rctx
->context
.create_fs_state
= r600_create_shader_state
;
996 rctx
->context
.create_rasterizer_state
= r600_create_rs_state
;
997 rctx
->context
.create_sampler_state
= r600_create_sampler_state
;
998 rctx
->context
.create_sampler_view
= r600_create_sampler_view
;
999 rctx
->context
.create_vertex_elements_state
= r600_create_vertex_elements
;
1000 rctx
->context
.create_vs_state
= r600_create_shader_state
;
1001 rctx
->context
.bind_blend_state
= r600_bind_blend_state
;
1002 rctx
->context
.bind_depth_stencil_alpha_state
= r600_bind_dsa_state
;
1003 rctx
->context
.bind_fragment_sampler_states
= r600_bind_ps_sampler
;
1004 rctx
->context
.bind_fs_state
= r600_bind_ps_shader
;
1005 rctx
->context
.bind_rasterizer_state
= r600_bind_rs_state
;
1006 rctx
->context
.bind_vertex_elements_state
= r600_bind_vertex_elements
;
1007 rctx
->context
.bind_vertex_sampler_states
= r600_bind_vs_sampler
;
1008 rctx
->context
.bind_vs_state
= r600_bind_vs_shader
;
1009 rctx
->context
.delete_blend_state
= r600_delete_state
;
1010 rctx
->context
.delete_depth_stencil_alpha_state
= r600_delete_state
;
1011 rctx
->context
.delete_fs_state
= r600_delete_ps_shader
;
1012 rctx
->context
.delete_rasterizer_state
= r600_delete_rs_state
;
1013 rctx
->context
.delete_sampler_state
= r600_delete_state
;
1014 rctx
->context
.delete_vertex_elements_state
= r600_delete_vertex_element
;
1015 rctx
->context
.delete_vs_state
= r600_delete_vs_shader
;
1016 rctx
->context
.set_blend_color
= r600_set_blend_color
;
1017 rctx
->context
.set_clip_state
= r600_set_clip_state
;
1018 rctx
->context
.set_constant_buffer
= r600_set_constant_buffer
;
1019 rctx
->context
.set_fragment_sampler_views
= r600_set_ps_sampler_view
;
1020 rctx
->context
.set_framebuffer_state
= r600_set_framebuffer_state
;
1021 rctx
->context
.set_polygon_stipple
= r600_set_polygon_stipple
;
1022 rctx
->context
.set_sample_mask
= r600_set_sample_mask
;
1023 rctx
->context
.set_scissor_state
= r600_set_scissor_state
;
1024 rctx
->context
.set_stencil_ref
= r600_set_stencil_ref
;
1025 rctx
->context
.set_vertex_buffers
= r600_set_vertex_buffers
;
1026 rctx
->context
.set_index_buffer
= r600_set_index_buffer
;
1027 rctx
->context
.set_vertex_sampler_views
= r600_set_vs_sampler_view
;
1028 rctx
->context
.set_viewport_state
= r600_set_viewport_state
;
1029 rctx
->context
.sampler_view_destroy
= r600_sampler_view_destroy
;
1030 rctx
->context
.redefine_user_buffer
= u_default_redefine_user_buffer
;
1031 rctx
->context
.texture_barrier
= r600_texture_barrier
;
1034 void r600_init_config(struct r600_pipe_context
*rctx
)
1049 int num_ps_stack_entries
;
1050 int num_vs_stack_entries
;
1051 int num_gs_stack_entries
;
1052 int num_es_stack_entries
;
1053 enum radeon_family family
;
1054 struct r600_pipe_state
*rstate
= &rctx
->config
;
1057 family
= r600_get_family(rctx
->radeon
);
1069 num_ps_threads
= 136;
1070 num_vs_threads
= 48;
1073 num_ps_stack_entries
= 128;
1074 num_vs_stack_entries
= 128;
1075 num_gs_stack_entries
= 0;
1076 num_es_stack_entries
= 0;
1085 num_ps_threads
= 144;
1086 num_vs_threads
= 40;
1089 num_ps_stack_entries
= 40;
1090 num_vs_stack_entries
= 40;
1091 num_gs_stack_entries
= 32;
1092 num_es_stack_entries
= 16;
1104 num_ps_threads
= 136;
1105 num_vs_threads
= 48;
1108 num_ps_stack_entries
= 40;
1109 num_vs_stack_entries
= 40;
1110 num_gs_stack_entries
= 32;
1111 num_es_stack_entries
= 16;
1119 num_ps_threads
= 136;
1120 num_vs_threads
= 48;
1123 num_ps_stack_entries
= 40;
1124 num_vs_stack_entries
= 40;
1125 num_gs_stack_entries
= 32;
1126 num_es_stack_entries
= 16;
1134 num_ps_threads
= 188;
1135 num_vs_threads
= 60;
1138 num_ps_stack_entries
= 256;
1139 num_vs_stack_entries
= 256;
1140 num_gs_stack_entries
= 0;
1141 num_es_stack_entries
= 0;
1150 num_ps_threads
= 188;
1151 num_vs_threads
= 60;
1154 num_ps_stack_entries
= 128;
1155 num_vs_stack_entries
= 128;
1156 num_gs_stack_entries
= 0;
1157 num_es_stack_entries
= 0;
1165 num_ps_threads
= 144;
1166 num_vs_threads
= 48;
1169 num_ps_stack_entries
= 128;
1170 num_vs_stack_entries
= 128;
1171 num_gs_stack_entries
= 0;
1172 num_es_stack_entries
= 0;
1176 rstate
->id
= R600_PIPE_STATE_CONFIG
;
1188 tmp
|= S_008C00_VC_ENABLE(1);
1191 tmp
|= S_008C00_DX9_CONSTS(0);
1192 tmp
|= S_008C00_ALU_INST_PREFER_VECTOR(1);
1193 tmp
|= S_008C00_PS_PRIO(ps_prio
);
1194 tmp
|= S_008C00_VS_PRIO(vs_prio
);
1195 tmp
|= S_008C00_GS_PRIO(gs_prio
);
1196 tmp
|= S_008C00_ES_PRIO(es_prio
);
1197 r600_pipe_state_add_reg(rstate
, R_008C00_SQ_CONFIG
, tmp
, 0xFFFFFFFF, NULL
);
1199 /* SQ_GPR_RESOURCE_MGMT_1 */
1201 tmp
|= S_008C04_NUM_PS_GPRS(num_ps_gprs
);
1202 tmp
|= S_008C04_NUM_VS_GPRS(num_vs_gprs
);
1203 tmp
|= S_008C04_NUM_CLAUSE_TEMP_GPRS(num_temp_gprs
);
1204 r600_pipe_state_add_reg(rstate
, R_008C04_SQ_GPR_RESOURCE_MGMT_1
, tmp
, 0xFFFFFFFF, NULL
);
1206 /* SQ_GPR_RESOURCE_MGMT_2 */
1208 tmp
|= S_008C08_NUM_GS_GPRS(num_gs_gprs
);
1209 tmp
|= S_008C08_NUM_GS_GPRS(num_es_gprs
);
1210 r600_pipe_state_add_reg(rstate
, R_008C08_SQ_GPR_RESOURCE_MGMT_2
, tmp
, 0xFFFFFFFF, NULL
);
1212 /* SQ_THREAD_RESOURCE_MGMT */
1214 tmp
|= S_008C0C_NUM_PS_THREADS(num_ps_threads
);
1215 tmp
|= S_008C0C_NUM_VS_THREADS(num_vs_threads
);
1216 tmp
|= S_008C0C_NUM_GS_THREADS(num_gs_threads
);
1217 tmp
|= S_008C0C_NUM_ES_THREADS(num_es_threads
);
1218 r600_pipe_state_add_reg(rstate
, R_008C0C_SQ_THREAD_RESOURCE_MGMT
, tmp
, 0xFFFFFFFF, NULL
);
1220 /* SQ_STACK_RESOURCE_MGMT_1 */
1222 tmp
|= S_008C10_NUM_PS_STACK_ENTRIES(num_ps_stack_entries
);
1223 tmp
|= S_008C10_NUM_VS_STACK_ENTRIES(num_vs_stack_entries
);
1224 r600_pipe_state_add_reg(rstate
, R_008C10_SQ_STACK_RESOURCE_MGMT_1
, tmp
, 0xFFFFFFFF, NULL
);
1226 /* SQ_STACK_RESOURCE_MGMT_2 */
1228 tmp
|= S_008C14_NUM_GS_STACK_ENTRIES(num_gs_stack_entries
);
1229 tmp
|= S_008C14_NUM_ES_STACK_ENTRIES(num_es_stack_entries
);
1230 r600_pipe_state_add_reg(rstate
, R_008C14_SQ_STACK_RESOURCE_MGMT_2
, tmp
, 0xFFFFFFFF, NULL
);
1232 r600_pipe_state_add_reg(rstate
, R_009714_VC_ENHANCE
, 0x00000000, 0xFFFFFFFF, NULL
);
1233 r600_pipe_state_add_reg(rstate
, R_028350_SX_MISC
, 0x00000000, 0xFFFFFFFF, NULL
);
1235 if (family
>= CHIP_RV770
) {
1236 r600_pipe_state_add_reg(rstate
, R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ
, 0x00004000, 0xFFFFFFFF, NULL
);
1237 r600_pipe_state_add_reg(rstate
, R_009508_TA_CNTL_AUX
, 0x07000002, 0xFFFFFFFF, NULL
);
1238 r600_pipe_state_add_reg(rstate
, R_009830_DB_DEBUG
, 0x00000000, 0xFFFFFFFF, NULL
);
1239 r600_pipe_state_add_reg(rstate
, R_009838_DB_WATERMARKS
, 0x00420204, 0xFFFFFFFF, NULL
);
1240 r600_pipe_state_add_reg(rstate
, R_0286C8_SPI_THREAD_GROUPING
, 0x00000000, 0xFFFFFFFF, NULL
);
1241 r600_pipe_state_add_reg(rstate
, R_028A4C_PA_SC_MODE_CNTL
, 0x00514002, 0xFFFFFFFF, NULL
);
1243 r600_pipe_state_add_reg(rstate
, R_008D8C_SQ_DYN_GPR_CNTL_PS_FLUSH_REQ
, 0x00000000, 0xFFFFFFFF, NULL
);
1244 r600_pipe_state_add_reg(rstate
, R_009508_TA_CNTL_AUX
, 0x07000003, 0xFFFFFFFF, NULL
);
1245 r600_pipe_state_add_reg(rstate
, R_009830_DB_DEBUG
, 0x82000000, 0xFFFFFFFF, NULL
);
1246 r600_pipe_state_add_reg(rstate
, R_009838_DB_WATERMARKS
, 0x01020204, 0xFFFFFFFF, NULL
);
1247 r600_pipe_state_add_reg(rstate
, R_0286C8_SPI_THREAD_GROUPING
, 0x00000001, 0xFFFFFFFF, NULL
);
1248 r600_pipe_state_add_reg(rstate
, R_028A4C_PA_SC_MODE_CNTL
, 0x00004012, 0xFFFFFFFF, NULL
);
1250 r600_pipe_state_add_reg(rstate
, R_0288A8_SQ_ESGS_RING_ITEMSIZE
, 0x00000000, 0xFFFFFFFF, NULL
);
1251 r600_pipe_state_add_reg(rstate
, R_0288AC_SQ_GSVS_RING_ITEMSIZE
, 0x00000000, 0xFFFFFFFF, NULL
);
1252 r600_pipe_state_add_reg(rstate
, R_0288B0_SQ_ESTMP_RING_ITEMSIZE
, 0x00000000, 0xFFFFFFFF, NULL
);
1253 r600_pipe_state_add_reg(rstate
, R_0288B4_SQ_GSTMP_RING_ITEMSIZE
, 0x00000000, 0xFFFFFFFF, NULL
);
1254 r600_pipe_state_add_reg(rstate
, R_0288B8_SQ_VSTMP_RING_ITEMSIZE
, 0x00000000, 0xFFFFFFFF, NULL
);
1255 r600_pipe_state_add_reg(rstate
, R_0288BC_SQ_PSTMP_RING_ITEMSIZE
, 0x00000000, 0xFFFFFFFF, NULL
);
1256 r600_pipe_state_add_reg(rstate
, R_0288C0_SQ_FBUF_RING_ITEMSIZE
, 0x00000000, 0xFFFFFFFF, NULL
);
1257 r600_pipe_state_add_reg(rstate
, R_0288C4_SQ_REDUC_RING_ITEMSIZE
, 0x00000000, 0xFFFFFFFF, NULL
);
1258 r600_pipe_state_add_reg(rstate
, R_0288C8_SQ_GS_VERT_ITEMSIZE
, 0x00000000, 0xFFFFFFFF, NULL
);
1259 r600_pipe_state_add_reg(rstate
, R_028A10_VGT_OUTPUT_PATH_CNTL
, 0x00000000, 0xFFFFFFFF, NULL
);
1260 r600_pipe_state_add_reg(rstate
, R_028A14_VGT_HOS_CNTL
, 0x00000000, 0xFFFFFFFF, NULL
);
1261 r600_pipe_state_add_reg(rstate
, R_028A18_VGT_HOS_MAX_TESS_LEVEL
, 0x00000000, 0xFFFFFFFF, NULL
);
1262 r600_pipe_state_add_reg(rstate
, R_028A1C_VGT_HOS_MIN_TESS_LEVEL
, 0x00000000, 0xFFFFFFFF, NULL
);
1263 r600_pipe_state_add_reg(rstate
, R_028A20_VGT_HOS_REUSE_DEPTH
, 0x00000000, 0xFFFFFFFF, NULL
);
1264 r600_pipe_state_add_reg(rstate
, R_028A24_VGT_GROUP_PRIM_TYPE
, 0x00000000, 0xFFFFFFFF, NULL
);
1265 r600_pipe_state_add_reg(rstate
, R_028A28_VGT_GROUP_FIRST_DECR
, 0x00000000, 0xFFFFFFFF, NULL
);
1266 r600_pipe_state_add_reg(rstate
, R_028A2C_VGT_GROUP_DECR
, 0x00000000, 0xFFFFFFFF, NULL
);
1267 r600_pipe_state_add_reg(rstate
, R_028A30_VGT_GROUP_VECT_0_CNTL
, 0x00000000, 0xFFFFFFFF, NULL
);
1268 r600_pipe_state_add_reg(rstate
, R_028A34_VGT_GROUP_VECT_1_CNTL
, 0x00000000, 0xFFFFFFFF, NULL
);
1269 r600_pipe_state_add_reg(rstate
, R_028A38_VGT_GROUP_VECT_0_FMT_CNTL
, 0x00000000, 0xFFFFFFFF, NULL
);
1270 r600_pipe_state_add_reg(rstate
, R_028A3C_VGT_GROUP_VECT_1_FMT_CNTL
, 0x00000000, 0xFFFFFFFF, NULL
);
1271 r600_pipe_state_add_reg(rstate
, R_028A40_VGT_GS_MODE
, 0x00000000, 0xFFFFFFFF, NULL
);
1272 r600_pipe_state_add_reg(rstate
, R_028AB0_VGT_STRMOUT_EN
, 0x00000000, 0xFFFFFFFF, NULL
);
1273 r600_pipe_state_add_reg(rstate
, R_028AB4_VGT_REUSE_OFF
, 0x00000001, 0xFFFFFFFF, NULL
);
1274 r600_pipe_state_add_reg(rstate
, R_028AB8_VGT_VTX_CNT_EN
, 0x00000000, 0xFFFFFFFF, NULL
);
1275 r600_pipe_state_add_reg(rstate
, R_028B20_VGT_STRMOUT_BUFFER_EN
, 0x00000000, 0xFFFFFFFF, NULL
);
1277 r600_pipe_state_add_reg(rstate
, R_02840C_VGT_MULTI_PRIM_IB_RESET_INDX
, 0x00000000, 0xFFFFFFFF, NULL
);
1278 r600_pipe_state_add_reg(rstate
, R_028A84_VGT_PRIMITIVEID_EN
, 0x00000000, 0xFFFFFFFF, NULL
);
1279 r600_pipe_state_add_reg(rstate
, R_028A94_VGT_MULTI_PRIM_IB_RESET_EN
, 0x00000000, 0xFFFFFFFF, NULL
);
1280 r600_pipe_state_add_reg(rstate
, R_028AA0_VGT_INSTANCE_STEP_RATE_0
, 0x00000000, 0xFFFFFFFF, NULL
);
1281 r600_pipe_state_add_reg(rstate
, R_028AA4_VGT_INSTANCE_STEP_RATE_1
, 0x00000000, 0xFFFFFFFF, NULL
);
1282 r600_context_pipe_state_set(&rctx
->ctx
, rstate
);
1285 void r600_pipe_shader_ps(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
1287 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
1288 struct r600_pipe_state
*rstate
= &shader
->rstate
;
1289 struct r600_shader
*rshader
= &shader
->shader
;
1290 unsigned i
, exports_ps
, num_cout
, spi_ps_in_control_0
, spi_input_z
, spi_ps_in_control_1
, db_shader_control
;
1291 int pos_index
= -1, face_index
= -1;
1295 for (i
= 0; i
< rshader
->ninput
; i
++) {
1296 if (rshader
->input
[i
].name
== TGSI_SEMANTIC_POSITION
)
1298 if (rshader
->input
[i
].name
== TGSI_SEMANTIC_FACE
)
1302 db_shader_control
= 0;
1303 for (i
= 0; i
< rshader
->noutput
; i
++) {
1304 if (rshader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
)
1305 db_shader_control
|= S_02880C_Z_EXPORT_ENABLE(1);
1306 if (rshader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
)
1307 db_shader_control
|= S_02880C_STENCIL_REF_EXPORT_ENABLE(1);
1309 if (rshader
->uses_kill
)
1310 db_shader_control
|= S_02880C_KILL_ENABLE(1);
1314 for (i
= 0; i
< rshader
->noutput
; i
++) {
1315 if (rshader
->output
[i
].name
== TGSI_SEMANTIC_POSITION
||
1316 rshader
->output
[i
].name
== TGSI_SEMANTIC_STENCIL
)
1318 else if (rshader
->output
[i
].name
== TGSI_SEMANTIC_COLOR
) {
1322 exports_ps
|= S_028854_EXPORT_COLORS(num_cout
);
1324 /* always at least export 1 component per pixel */
1328 spi_ps_in_control_0
= S_0286CC_NUM_INTERP(rshader
->ninput
) |
1329 S_0286CC_PERSP_GRADIENT_ENA(1);
1331 if (pos_index
!= -1) {
1332 spi_ps_in_control_0
|= (S_0286CC_POSITION_ENA(1) |
1333 S_0286CC_POSITION_CENTROID(rshader
->input
[pos_index
].centroid
) |
1334 S_0286CC_POSITION_ADDR(rshader
->input
[pos_index
].gpr
) |
1335 S_0286CC_BARYC_SAMPLE_CNTL(1));
1339 spi_ps_in_control_1
= 0;
1340 if (face_index
!= -1) {
1341 spi_ps_in_control_1
|= S_0286D0_FRONT_FACE_ENA(1) |
1342 S_0286D0_FRONT_FACE_ADDR(rshader
->input
[face_index
].gpr
);
1345 r600_pipe_state_add_reg(rstate
, R_0286CC_SPI_PS_IN_CONTROL_0
, spi_ps_in_control_0
, 0xFFFFFFFF, NULL
);
1346 r600_pipe_state_add_reg(rstate
, R_0286D0_SPI_PS_IN_CONTROL_1
, spi_ps_in_control_1
, 0xFFFFFFFF, NULL
);
1347 r600_pipe_state_add_reg(rstate
, R_0286D8_SPI_INPUT_Z
, spi_input_z
, 0xFFFFFFFF, NULL
);
1348 r600_pipe_state_add_reg(rstate
,
1349 R_028840_SQ_PGM_START_PS
,
1350 r600_bo_offset(shader
->bo
) >> 8, 0xFFFFFFFF, shader
->bo
);
1351 r600_pipe_state_add_reg(rstate
,
1352 R_028850_SQ_PGM_RESOURCES_PS
,
1353 S_028868_NUM_GPRS(rshader
->bc
.ngpr
) |
1354 S_028868_STACK_SIZE(rshader
->bc
.nstack
),
1356 r600_pipe_state_add_reg(rstate
,
1357 R_028854_SQ_PGM_EXPORTS_PS
,
1358 exports_ps
, 0xFFFFFFFF, NULL
);
1359 r600_pipe_state_add_reg(rstate
,
1360 R_0288CC_SQ_PGM_CF_OFFSET_PS
,
1361 0x00000000, 0xFFFFFFFF, NULL
);
1362 r600_pipe_state_add_reg(rstate
, R_028808_CB_COLOR_CONTROL
,
1363 S_028808_MULTIWRITE_ENABLE(!!rshader
->fs_write_all
),
1364 S_028808_MULTIWRITE_ENABLE(1),
1366 /* only set some bits here, the other bits are set in the dsa state */
1367 r600_pipe_state_add_reg(rstate
, R_02880C_DB_SHADER_CONTROL
,
1369 S_02880C_Z_EXPORT_ENABLE(1) |
1370 S_02880C_STENCIL_REF_EXPORT_ENABLE(1) |
1371 S_02880C_KILL_ENABLE(1),
1374 r600_pipe_state_add_reg(rstate
,
1375 R_03E200_SQ_LOOP_CONST_0
, 0x01000FFF,
1379 void r600_pipe_shader_vs(struct pipe_context
*ctx
, struct r600_pipe_shader
*shader
)
1381 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
1382 struct r600_pipe_state
*rstate
= &shader
->rstate
;
1383 struct r600_shader
*rshader
= &shader
->shader
;
1384 unsigned spi_vs_out_id
[10];
1387 /* clear previous register */
1390 /* so far never got proper semantic id from tgsi */
1391 /* FIXME better to move this in config things so they get emited
1392 * only one time per cs
1394 for (i
= 0; i
< 10; i
++) {
1395 spi_vs_out_id
[i
] = 0;
1397 for (i
= 0; i
< 32; i
++) {
1398 tmp
= i
<< ((i
& 3) * 8);
1399 spi_vs_out_id
[i
/ 4] |= tmp
;
1401 for (i
= 0; i
< 10; i
++) {
1402 r600_pipe_state_add_reg(rstate
,
1403 R_028614_SPI_VS_OUT_ID_0
+ i
* 4,
1404 spi_vs_out_id
[i
], 0xFFFFFFFF, NULL
);
1407 r600_pipe_state_add_reg(rstate
,
1408 R_0286C4_SPI_VS_OUT_CONFIG
,
1409 S_0286C4_VS_EXPORT_COUNT(rshader
->noutput
- 2),
1411 r600_pipe_state_add_reg(rstate
,
1412 R_028868_SQ_PGM_RESOURCES_VS
,
1413 S_028868_NUM_GPRS(rshader
->bc
.ngpr
) |
1414 S_028868_STACK_SIZE(rshader
->bc
.nstack
),
1416 r600_pipe_state_add_reg(rstate
,
1417 R_0288D0_SQ_PGM_CF_OFFSET_VS
,
1418 0x00000000, 0xFFFFFFFF, NULL
);
1419 r600_pipe_state_add_reg(rstate
,
1420 R_028858_SQ_PGM_START_VS
,
1421 r600_bo_offset(shader
->bo
) >> 8, 0xFFFFFFFF, shader
->bo
);
1423 r600_pipe_state_add_reg(rstate
,
1424 R_03E200_SQ_LOOP_CONST_0
+ (32 * 4), 0x01000FFF,
1428 void r600_fetch_shader(struct pipe_context
*ctx
,
1429 struct r600_vertex_element
*ve
)
1431 struct r600_pipe_state
*rstate
;
1432 struct r600_pipe_context
*rctx
= (struct r600_pipe_context
*)ctx
;
1434 rstate
= &ve
->rstate
;
1435 rstate
->id
= R600_PIPE_STATE_FETCH_SHADER
;
1437 r600_pipe_state_add_reg(rstate
, R_0288A4_SQ_PGM_RESOURCES_FS
,
1438 0x00000000, 0xFFFFFFFF, NULL
);
1439 r600_pipe_state_add_reg(rstate
, R_0288DC_SQ_PGM_CF_OFFSET_FS
,
1440 0x00000000, 0xFFFFFFFF, NULL
);
1441 r600_pipe_state_add_reg(rstate
, R_028894_SQ_PGM_START_FS
,
1442 r600_bo_offset(ve
->fetch_shader
) >> 8,
1443 0xFFFFFFFF, ve
->fetch_shader
);
1446 void *r600_create_db_flush_dsa(struct r600_pipe_context
*rctx
)
1448 struct pipe_depth_stencil_alpha_state dsa
;
1449 struct r600_pipe_state
*rstate
;
1450 boolean quirk
= false;
1452 if (rctx
->family
== CHIP_RV610
|| rctx
->family
== CHIP_RV630
||
1453 rctx
->family
== CHIP_RV620
|| rctx
->family
== CHIP_RV635
)
1456 memset(&dsa
, 0, sizeof(dsa
));
1459 dsa
.depth
.enabled
= 1;
1460 dsa
.depth
.func
= PIPE_FUNC_LEQUAL
;
1461 dsa
.stencil
[0].enabled
= 1;
1462 dsa
.stencil
[0].func
= PIPE_FUNC_ALWAYS
;
1463 dsa
.stencil
[0].zpass_op
= PIPE_STENCIL_OP_KEEP
;
1464 dsa
.stencil
[0].zfail_op
= PIPE_STENCIL_OP_INCR
;
1465 dsa
.stencil
[0].writemask
= 0xff;
1468 rstate
= rctx
->context
.create_depth_stencil_alpha_state(&rctx
->context
, &dsa
);
1469 r600_pipe_state_add_reg(rstate
,
1470 R_02880C_DB_SHADER_CONTROL
,
1472 S_02880C_DUAL_EXPORT_ENABLE(1), NULL
);
1473 r600_pipe_state_add_reg(rstate
,
1474 R_028D0C_DB_RENDER_CONTROL
,
1475 S_028D0C_DEPTH_COPY_ENABLE(1) |
1476 S_028D0C_STENCIL_COPY_ENABLE(1) |
1477 S_028D0C_COPY_CENTROID(1),
1478 S_028D0C_DEPTH_COPY_ENABLE(1) |
1479 S_028D0C_STENCIL_COPY_ENABLE(1) |
1480 S_028D0C_COPY_CENTROID(1), NULL
);
1484 void r600_pipe_init_buffer_resource(struct r600_pipe_context
*rctx
,
1485 struct r600_pipe_state
*rstate
,
1486 struct r600_resource
*rbuffer
,
1487 unsigned offset
, unsigned stride
)
1489 rstate
->id
= R600_PIPE_STATE_RESOURCE
;
1491 r600_pipe_state_add_reg(rstate
, R_038000_RESOURCE0_WORD0
,
1492 offset
, 0xFFFFFFFF, rbuffer
->bo
);
1493 r600_pipe_state_add_reg(rstate
, R_038004_RESOURCE0_WORD1
,
1494 rbuffer
->bo_size
- offset
- 1, 0xFFFFFFFF, NULL
);
1495 r600_pipe_state_add_reg(rstate
, R_038008_RESOURCE0_WORD2
,
1496 S_038008_ENDIAN_SWAP(r600_endian_swap(32)) |
1497 S_038008_STRIDE(stride
), 0xFFFFFFFF, NULL
);
1498 r600_pipe_state_add_reg(rstate
, R_03800C_RESOURCE0_WORD3
,
1499 0x00000000, 0xFFFFFFFF, NULL
);
1500 r600_pipe_state_add_reg(rstate
, R_038010_RESOURCE0_WORD4
,
1501 0x00000000, 0xFFFFFFFF, NULL
);
1502 r600_pipe_state_add_reg(rstate
, R_038014_RESOURCE0_WORD5
,
1503 0x00000000, 0xFFFFFFFF, NULL
);
1504 r600_pipe_state_add_reg(rstate
, R_038018_RESOURCE0_WORD6
,
1505 0xC0000000, 0xFFFFFFFF, NULL
);
1508 void r600_pipe_mod_buffer_resource(struct r600_pipe_state
*rstate
,
1509 struct r600_resource
*rbuffer
,
1510 unsigned offset
, unsigned stride
)
1513 r600_pipe_state_mod_reg_bo(rstate
, offset
, rbuffer
->bo
);
1514 r600_pipe_state_mod_reg(rstate
, rbuffer
->bo_size
- offset
- 1);
1515 r600_pipe_state_mod_reg(rstate
, S_038008_ENDIAN_SWAP(r600_endian_swap(32)) |
1516 S_038008_STRIDE(stride
));