2 * Mesa 3-D graphics library
4 * Copyright (C) 2012-2014 LunarG, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Chia-I Wu <olv@lunarg.com>
28 #include "genhw/genhw.h"
29 #include "util/u_dual_blend.h"
30 #include "util/u_framebuffer.h"
31 #include "util/u_half.h"
33 #include "ilo_format.h"
34 #include "ilo_image.h"
35 #include "ilo_state_3d.h"
36 #include "../ilo_shader.h"
39 fs_init_cso_gen6(const struct ilo_dev
*dev
,
40 const struct ilo_shader_state
*fs
,
41 struct ilo_shader_cso
*cso
)
43 int start_grf
, input_count
, sampler_count
, max_threads
;
44 uint32_t dw2
, dw4
, dw5
, dw6
;
46 ILO_DEV_ASSERT(dev
, 6, 6);
48 start_grf
= ilo_shader_get_kernel_param(fs
, ILO_KERNEL_URB_DATA_START_REG
);
49 input_count
= ilo_shader_get_kernel_param(fs
, ILO_KERNEL_INPUT_COUNT
);
50 sampler_count
= ilo_shader_get_kernel_param(fs
, ILO_KERNEL_SAMPLER_COUNT
);
52 /* see brwCreateContext() */
53 max_threads
= (dev
->gt
== 2) ? 80 : 40;
55 dw2
= (true) ? 0 : GEN6_THREADDISP_FP_MODE_ALT
;
56 dw2
|= ((sampler_count
+ 3) / 4) << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT
;
58 dw4
= start_grf
<< GEN6_WM_DW4_URB_GRF_START0__SHIFT
|
59 0 << GEN6_WM_DW4_URB_GRF_START1__SHIFT
|
60 0 << GEN6_WM_DW4_URB_GRF_START2__SHIFT
;
62 dw5
= (max_threads
- 1) << GEN6_WM_DW5_MAX_THREADS__SHIFT
;
65 * From the Sandy Bridge PRM, volume 2 part 1, page 275:
67 * "This bit (Pixel Shader Kill Pixel), if ENABLED, indicates that the
68 * PS kernel or color calculator has the ability to kill (discard)
69 * pixels or samples, other than due to depth or stencil testing.
70 * This bit is required to be ENABLED in the following situations:
72 * The API pixel shader program contains "killpix" or "discard"
73 * instructions, or other code in the pixel shader kernel that can
74 * cause the final pixel mask to differ from the pixel mask received
77 * A sampler with chroma key enabled with kill pixel mode is used by
80 * Any render target has Alpha Test Enable or AlphaToCoverage Enable
83 * The pixel shader kernel generates and outputs oMask.
85 * Note: As ClipDistance clipping is fully supported in hardware and
86 * therefore not via PS instructions, there should be no need to
87 * ENABLE this bit due to ClipDistance clipping."
89 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_USE_KILL
))
90 dw5
|= GEN6_WM_DW5_PS_KILL_PIXEL
;
93 * From the Sandy Bridge PRM, volume 2 part 1, page 275:
95 * "If a NULL Depth Buffer is selected, the Pixel Shader Computed Depth
96 * field must be set to disabled."
98 * TODO This is not checked yet.
100 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_OUTPUT_Z
))
101 dw5
|= GEN6_WM_DW5_PS_COMPUTE_DEPTH
;
103 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_INPUT_Z
))
104 dw5
|= GEN6_WM_DW5_PS_USE_DEPTH
;
106 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_INPUT_W
))
107 dw5
|= GEN6_WM_DW5_PS_USE_W
;
110 * TODO set this bit only when
112 * a) fs writes colors and color is not masked, or
113 * b) fs writes depth, or
117 dw5
|= GEN6_WM_DW5_PS_DISPATCH_ENABLE
;
119 assert(!ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_DISPATCH_16_OFFSET
));
120 dw5
|= GEN6_PS_DISPATCH_8
<< GEN6_WM_DW5_PS_DISPATCH_MODE__SHIFT
;
122 dw6
= input_count
<< GEN6_WM_DW6_SF_ATTR_COUNT__SHIFT
|
123 GEN6_POSOFFSET_NONE
<< GEN6_WM_DW6_PS_POSOFFSET__SHIFT
;
125 STATIC_ASSERT(Elements(cso
->payload
) >= 4);
126 cso
->payload
[0] = dw2
;
127 cso
->payload
[1] = dw4
;
128 cso
->payload
[2] = dw5
;
129 cso
->payload
[3] = dw6
;
133 fs_get_wm_gen7(const struct ilo_dev
*dev
,
134 const struct ilo_shader_state
*fs
)
138 ILO_DEV_ASSERT(dev
, 7, 7.5);
143 * TODO set this bit only when
145 * a) fs writes colors and color is not masked, or
146 * b) fs writes depth, or
149 dw
|= GEN7_WM_DW1_PS_DISPATCH_ENABLE
;
152 * From the Ivy Bridge PRM, volume 2 part 1, page 278:
154 * "This bit (Pixel Shader Kill Pixel), if ENABLED, indicates that
155 * the PS kernel or color calculator has the ability to kill
156 * (discard) pixels or samples, other than due to depth or stencil
157 * testing. This bit is required to be ENABLED in the following
160 * - The API pixel shader program contains "killpix" or "discard"
161 * instructions, or other code in the pixel shader kernel that
162 * can cause the final pixel mask to differ from the pixel mask
163 * received on dispatch.
165 * - A sampler with chroma key enabled with kill pixel mode is used
166 * by the pixel shader.
168 * - Any render target has Alpha Test Enable or AlphaToCoverage
171 * - The pixel shader kernel generates and outputs oMask.
173 * Note: As ClipDistance clipping is fully supported in hardware
174 * and therefore not via PS instructions, there should be no need
175 * to ENABLE this bit due to ClipDistance clipping."
177 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_USE_KILL
))
178 dw
|= GEN7_WM_DW1_PS_KILL_PIXEL
;
180 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_OUTPUT_Z
))
181 dw
|= GEN7_PSCDEPTH_ON
<< GEN7_WM_DW1_PSCDEPTH__SHIFT
;
183 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_INPUT_Z
))
184 dw
|= GEN7_WM_DW1_PS_USE_DEPTH
;
186 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_INPUT_W
))
187 dw
|= GEN7_WM_DW1_PS_USE_W
;
193 fs_init_cso_gen7(const struct ilo_dev
*dev
,
194 const struct ilo_shader_state
*fs
,
195 struct ilo_shader_cso
*cso
)
197 int start_grf
, sampler_count
, max_threads
;
198 uint32_t dw2
, dw4
, dw5
;
200 ILO_DEV_ASSERT(dev
, 7, 7.5);
202 start_grf
= ilo_shader_get_kernel_param(fs
, ILO_KERNEL_URB_DATA_START_REG
);
203 sampler_count
= ilo_shader_get_kernel_param(fs
, ILO_KERNEL_SAMPLER_COUNT
);
205 dw2
= (true) ? 0 : GEN6_THREADDISP_FP_MODE_ALT
;
206 dw2
|= ((sampler_count
+ 3) / 4) << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT
;
208 dw4
= GEN6_POSOFFSET_NONE
<< GEN7_PS_DW4_POSOFFSET__SHIFT
;
210 /* see brwCreateContext() */
211 switch (ilo_dev_gen(dev
)) {
213 max_threads
= (dev
->gt
== 3) ? 408 : (dev
->gt
== 2) ? 204 : 102;
214 dw4
|= (max_threads
- 1) << GEN75_PS_DW4_MAX_THREADS__SHIFT
;
215 dw4
|= 1 << GEN75_PS_DW4_SAMPLE_MASK__SHIFT
;
219 max_threads
= (dev
->gt
== 2) ? 172 : 48;
220 dw4
|= (max_threads
- 1) << GEN7_PS_DW4_MAX_THREADS__SHIFT
;
224 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_PCB_CBUF0_SIZE
))
225 dw4
|= GEN7_PS_DW4_PUSH_CONSTANT_ENABLE
;
227 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_INPUT_COUNT
))
228 dw4
|= GEN7_PS_DW4_ATTR_ENABLE
;
230 assert(!ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_DISPATCH_16_OFFSET
));
231 dw4
|= GEN6_PS_DISPATCH_8
<< GEN7_PS_DW4_DISPATCH_MODE__SHIFT
;
233 dw5
= start_grf
<< GEN7_PS_DW5_URB_GRF_START0__SHIFT
|
234 0 << GEN7_PS_DW5_URB_GRF_START1__SHIFT
|
235 0 << GEN7_PS_DW5_URB_GRF_START2__SHIFT
;
237 STATIC_ASSERT(Elements(cso
->payload
) >= 4);
238 cso
->payload
[0] = dw2
;
239 cso
->payload
[1] = dw4
;
240 cso
->payload
[2] = dw5
;
241 cso
->payload
[3] = fs_get_wm_gen7(dev
, fs
);
245 fs_get_psx_gen8(const struct ilo_dev
*dev
,
246 const struct ilo_shader_state
*fs
)
250 ILO_DEV_ASSERT(dev
, 8, 8);
252 dw
= GEN8_PSX_DW1_VALID
;
254 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_USE_KILL
))
255 dw
|= GEN8_PSX_DW1_KILL_PIXEL
;
256 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_OUTPUT_Z
))
257 dw
|= GEN7_PSCDEPTH_ON
<< GEN8_PSX_DW1_PSCDEPTH__SHIFT
;
258 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_INPUT_Z
))
259 dw
|= GEN8_PSX_DW1_USE_DEPTH
;
260 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_INPUT_W
))
261 dw
|= GEN8_PSX_DW1_USE_W
;
262 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_INPUT_COUNT
))
263 dw
|= GEN8_PSX_DW1_ATTR_ENABLE
;
269 fs_init_cso_gen8(const struct ilo_dev
*dev
,
270 const struct ilo_shader_state
*fs
,
271 struct ilo_shader_cso
*cso
)
273 int start_grf
, sampler_count
;
274 uint32_t dw3
, dw6
, dw7
;
276 ILO_DEV_ASSERT(dev
, 8, 8);
278 start_grf
= ilo_shader_get_kernel_param(fs
, ILO_KERNEL_URB_DATA_START_REG
);
279 sampler_count
= ilo_shader_get_kernel_param(fs
, ILO_KERNEL_SAMPLER_COUNT
);
281 dw3
= (true) ? 0 : GEN6_THREADDISP_FP_MODE_ALT
;
282 dw3
|= ((sampler_count
+ 3) / 4) << GEN6_THREADDISP_SAMPLER_COUNT__SHIFT
;
285 dw6
= (64 - 2) << GEN8_PS_DW6_MAX_THREADS__SHIFT
|
286 GEN6_POSOFFSET_NONE
<< GEN8_PS_DW6_POSOFFSET__SHIFT
;
287 if (ilo_shader_get_kernel_param(fs
, ILO_KERNEL_PCB_CBUF0_SIZE
))
288 dw6
|= GEN8_PS_DW6_PUSH_CONSTANT_ENABLE
;
290 assert(!ilo_shader_get_kernel_param(fs
, ILO_KERNEL_FS_DISPATCH_16_OFFSET
));
291 dw6
|= GEN6_PS_DISPATCH_8
<< GEN8_PS_DW6_DISPATCH_MODE__SHIFT
;
293 dw7
= start_grf
<< GEN8_PS_DW7_URB_GRF_START0__SHIFT
|
294 0 << GEN8_PS_DW7_URB_GRF_START1__SHIFT
|
295 0 << GEN8_PS_DW7_URB_GRF_START2__SHIFT
;
297 STATIC_ASSERT(Elements(cso
->payload
) >= 4);
298 cso
->payload
[0] = dw3
;
299 cso
->payload
[1] = dw6
;
300 cso
->payload
[2] = dw7
;
301 cso
->payload
[3] = fs_get_psx_gen8(dev
, fs
);
305 ilo_gpe_init_fs_cso(const struct ilo_dev
*dev
,
306 const struct ilo_shader_state
*fs
,
307 struct ilo_shader_cso
*cso
)
309 if (ilo_dev_gen(dev
) >= ILO_GEN(8))
310 fs_init_cso_gen8(dev
, fs
, cso
);
311 else if (ilo_dev_gen(dev
) >= ILO_GEN(7))
312 fs_init_cso_gen7(dev
, fs
, cso
);
314 fs_init_cso_gen6(dev
, fs
, cso
);
318 * Translate a pipe logicop to the matching hardware logicop.
321 gen6_translate_pipe_logicop(unsigned logicop
)
324 case PIPE_LOGICOP_CLEAR
: return GEN6_LOGICOP_CLEAR
;
325 case PIPE_LOGICOP_NOR
: return GEN6_LOGICOP_NOR
;
326 case PIPE_LOGICOP_AND_INVERTED
: return GEN6_LOGICOP_AND_INVERTED
;
327 case PIPE_LOGICOP_COPY_INVERTED
: return GEN6_LOGICOP_COPY_INVERTED
;
328 case PIPE_LOGICOP_AND_REVERSE
: return GEN6_LOGICOP_AND_REVERSE
;
329 case PIPE_LOGICOP_INVERT
: return GEN6_LOGICOP_INVERT
;
330 case PIPE_LOGICOP_XOR
: return GEN6_LOGICOP_XOR
;
331 case PIPE_LOGICOP_NAND
: return GEN6_LOGICOP_NAND
;
332 case PIPE_LOGICOP_AND
: return GEN6_LOGICOP_AND
;
333 case PIPE_LOGICOP_EQUIV
: return GEN6_LOGICOP_EQUIV
;
334 case PIPE_LOGICOP_NOOP
: return GEN6_LOGICOP_NOOP
;
335 case PIPE_LOGICOP_OR_INVERTED
: return GEN6_LOGICOP_OR_INVERTED
;
336 case PIPE_LOGICOP_COPY
: return GEN6_LOGICOP_COPY
;
337 case PIPE_LOGICOP_OR_REVERSE
: return GEN6_LOGICOP_OR_REVERSE
;
338 case PIPE_LOGICOP_OR
: return GEN6_LOGICOP_OR
;
339 case PIPE_LOGICOP_SET
: return GEN6_LOGICOP_SET
;
341 assert(!"unknown logicop function");
342 return GEN6_LOGICOP_CLEAR
;
347 * Translate a pipe blend function to the matching hardware blend function.
350 gen6_translate_pipe_blend(unsigned blend
)
353 case PIPE_BLEND_ADD
: return GEN6_BLENDFUNCTION_ADD
;
354 case PIPE_BLEND_SUBTRACT
: return GEN6_BLENDFUNCTION_SUBTRACT
;
355 case PIPE_BLEND_REVERSE_SUBTRACT
: return GEN6_BLENDFUNCTION_REVERSE_SUBTRACT
;
356 case PIPE_BLEND_MIN
: return GEN6_BLENDFUNCTION_MIN
;
357 case PIPE_BLEND_MAX
: return GEN6_BLENDFUNCTION_MAX
;
359 assert(!"unknown blend function");
360 return GEN6_BLENDFUNCTION_ADD
;
365 * Translate a pipe blend factor to the matching hardware blend factor.
368 gen6_translate_pipe_blendfactor(unsigned blendfactor
)
370 switch (blendfactor
) {
371 case PIPE_BLENDFACTOR_ONE
: return GEN6_BLENDFACTOR_ONE
;
372 case PIPE_BLENDFACTOR_SRC_COLOR
: return GEN6_BLENDFACTOR_SRC_COLOR
;
373 case PIPE_BLENDFACTOR_SRC_ALPHA
: return GEN6_BLENDFACTOR_SRC_ALPHA
;
374 case PIPE_BLENDFACTOR_DST_ALPHA
: return GEN6_BLENDFACTOR_DST_ALPHA
;
375 case PIPE_BLENDFACTOR_DST_COLOR
: return GEN6_BLENDFACTOR_DST_COLOR
;
376 case PIPE_BLENDFACTOR_SRC_ALPHA_SATURATE
: return GEN6_BLENDFACTOR_SRC_ALPHA_SATURATE
;
377 case PIPE_BLENDFACTOR_CONST_COLOR
: return GEN6_BLENDFACTOR_CONST_COLOR
;
378 case PIPE_BLENDFACTOR_CONST_ALPHA
: return GEN6_BLENDFACTOR_CONST_ALPHA
;
379 case PIPE_BLENDFACTOR_SRC1_COLOR
: return GEN6_BLENDFACTOR_SRC1_COLOR
;
380 case PIPE_BLENDFACTOR_SRC1_ALPHA
: return GEN6_BLENDFACTOR_SRC1_ALPHA
;
381 case PIPE_BLENDFACTOR_ZERO
: return GEN6_BLENDFACTOR_ZERO
;
382 case PIPE_BLENDFACTOR_INV_SRC_COLOR
: return GEN6_BLENDFACTOR_INV_SRC_COLOR
;
383 case PIPE_BLENDFACTOR_INV_SRC_ALPHA
: return GEN6_BLENDFACTOR_INV_SRC_ALPHA
;
384 case PIPE_BLENDFACTOR_INV_DST_ALPHA
: return GEN6_BLENDFACTOR_INV_DST_ALPHA
;
385 case PIPE_BLENDFACTOR_INV_DST_COLOR
: return GEN6_BLENDFACTOR_INV_DST_COLOR
;
386 case PIPE_BLENDFACTOR_INV_CONST_COLOR
: return GEN6_BLENDFACTOR_INV_CONST_COLOR
;
387 case PIPE_BLENDFACTOR_INV_CONST_ALPHA
: return GEN6_BLENDFACTOR_INV_CONST_ALPHA
;
388 case PIPE_BLENDFACTOR_INV_SRC1_COLOR
: return GEN6_BLENDFACTOR_INV_SRC1_COLOR
;
389 case PIPE_BLENDFACTOR_INV_SRC1_ALPHA
: return GEN6_BLENDFACTOR_INV_SRC1_ALPHA
;
391 assert(!"unknown blend factor");
392 return GEN6_BLENDFACTOR_ONE
;
397 * Translate a pipe stencil op to the matching hardware stencil op.
400 gen6_translate_pipe_stencil_op(unsigned stencil_op
)
402 switch (stencil_op
) {
403 case PIPE_STENCIL_OP_KEEP
: return GEN6_STENCILOP_KEEP
;
404 case PIPE_STENCIL_OP_ZERO
: return GEN6_STENCILOP_ZERO
;
405 case PIPE_STENCIL_OP_REPLACE
: return GEN6_STENCILOP_REPLACE
;
406 case PIPE_STENCIL_OP_INCR
: return GEN6_STENCILOP_INCRSAT
;
407 case PIPE_STENCIL_OP_DECR
: return GEN6_STENCILOP_DECRSAT
;
408 case PIPE_STENCIL_OP_INCR_WRAP
: return GEN6_STENCILOP_INCR
;
409 case PIPE_STENCIL_OP_DECR_WRAP
: return GEN6_STENCILOP_DECR
;
410 case PIPE_STENCIL_OP_INVERT
: return GEN6_STENCILOP_INVERT
;
412 assert(!"unknown stencil op");
413 return GEN6_STENCILOP_KEEP
;
418 gen6_blend_factor_dst_alpha_forced_one(int factor
)
421 case GEN6_BLENDFACTOR_DST_ALPHA
:
422 return GEN6_BLENDFACTOR_ONE
;
423 case GEN6_BLENDFACTOR_INV_DST_ALPHA
:
424 case GEN6_BLENDFACTOR_SRC_ALPHA_SATURATE
:
425 return GEN6_BLENDFACTOR_ZERO
;
432 blend_get_rt_blend_enable_gen6(const struct ilo_dev
*dev
,
433 const struct pipe_rt_blend_state
*rt
,
434 bool dst_alpha_forced_one
)
436 int rgb_src
, rgb_dst
, a_src
, a_dst
;
439 ILO_DEV_ASSERT(dev
, 6, 7.5);
441 if (!rt
->blend_enable
)
444 rgb_src
= gen6_translate_pipe_blendfactor(rt
->rgb_src_factor
);
445 rgb_dst
= gen6_translate_pipe_blendfactor(rt
->rgb_dst_factor
);
446 a_src
= gen6_translate_pipe_blendfactor(rt
->alpha_src_factor
);
447 a_dst
= gen6_translate_pipe_blendfactor(rt
->alpha_dst_factor
);
449 if (dst_alpha_forced_one
) {
450 rgb_src
= gen6_blend_factor_dst_alpha_forced_one(rgb_src
);
451 rgb_dst
= gen6_blend_factor_dst_alpha_forced_one(rgb_dst
);
452 a_src
= gen6_blend_factor_dst_alpha_forced_one(a_src
);
453 a_dst
= gen6_blend_factor_dst_alpha_forced_one(a_dst
);
456 dw
= GEN6_RT_DW0_BLEND_ENABLE
|
457 gen6_translate_pipe_blend(rt
->alpha_func
) << 26 |
460 gen6_translate_pipe_blend(rt
->rgb_func
) << 11 |
464 if (rt
->rgb_func
!= rt
->alpha_func
||
465 rgb_src
!= a_src
|| rgb_dst
!= a_dst
)
466 dw
|= GEN6_RT_DW0_INDEPENDENT_ALPHA_ENABLE
;
472 blend_get_rt_blend_enable_gen8(const struct ilo_dev
*dev
,
473 const struct pipe_rt_blend_state
*rt
,
474 bool dst_alpha_forced_one
,
475 bool *independent_alpha
)
477 int rgb_src
, rgb_dst
, a_src
, a_dst
;
480 ILO_DEV_ASSERT(dev
, 8, 8);
482 if (!rt
->blend_enable
) {
483 *independent_alpha
= false;
487 rgb_src
= gen6_translate_pipe_blendfactor(rt
->rgb_src_factor
);
488 rgb_dst
= gen6_translate_pipe_blendfactor(rt
->rgb_dst_factor
);
489 a_src
= gen6_translate_pipe_blendfactor(rt
->alpha_src_factor
);
490 a_dst
= gen6_translate_pipe_blendfactor(rt
->alpha_dst_factor
);
492 if (dst_alpha_forced_one
) {
493 rgb_src
= gen6_blend_factor_dst_alpha_forced_one(rgb_src
);
494 rgb_dst
= gen6_blend_factor_dst_alpha_forced_one(rgb_dst
);
495 a_src
= gen6_blend_factor_dst_alpha_forced_one(a_src
);
496 a_dst
= gen6_blend_factor_dst_alpha_forced_one(a_dst
);
499 dw
= GEN8_RT_DW0_BLEND_ENABLE
|
502 gen6_translate_pipe_blend(rt
->rgb_func
) << 18 |
505 gen6_translate_pipe_blend(rt
->alpha_func
) << 5;
507 *independent_alpha
= (rt
->rgb_func
!= rt
->alpha_func
||
515 blend_init_cso_gen6(const struct ilo_dev
*dev
,
516 const struct pipe_blend_state
*state
,
517 struct ilo_blend_state
*blend
,
520 const struct pipe_rt_blend_state
*rt
= &state
->rt
[index
];
521 struct ilo_blend_cso
*cso
= &blend
->cso
[index
];
523 ILO_DEV_ASSERT(dev
, 6, 7.5);
526 cso
->payload
[1] = GEN6_RT_DW1_COLORCLAMP_RTFORMAT
|
527 GEN6_RT_DW1_PRE_BLEND_CLAMP
|
528 GEN6_RT_DW1_POST_BLEND_CLAMP
;
530 if (!(rt
->colormask
& PIPE_MASK_A
))
531 cso
->payload
[1] |= GEN6_RT_DW1_WRITE_DISABLES_A
;
532 if (!(rt
->colormask
& PIPE_MASK_R
))
533 cso
->payload
[1] |= GEN6_RT_DW1_WRITE_DISABLES_R
;
534 if (!(rt
->colormask
& PIPE_MASK_G
))
535 cso
->payload
[1] |= GEN6_RT_DW1_WRITE_DISABLES_G
;
536 if (!(rt
->colormask
& PIPE_MASK_B
))
537 cso
->payload
[1] |= GEN6_RT_DW1_WRITE_DISABLES_B
;
540 * From the Sandy Bridge PRM, volume 2 part 1, page 365:
542 * "Color Buffer Blending and Logic Ops must not be enabled
543 * simultaneously, or behavior is UNDEFINED."
545 * Since state->logicop_enable takes precedence over rt->blend_enable,
546 * no special care is needed.
548 if (state
->logicop_enable
) {
550 cso
->dw_blend_dst_alpha_forced_one
= 0;
552 cso
->dw_blend
= blend_get_rt_blend_enable_gen6(dev
, rt
, false);
553 cso
->dw_blend_dst_alpha_forced_one
=
554 blend_get_rt_blend_enable_gen6(dev
, rt
, true);
559 blend_init_cso_gen8(const struct ilo_dev
*dev
,
560 const struct pipe_blend_state
*state
,
561 struct ilo_blend_state
*blend
,
564 const struct pipe_rt_blend_state
*rt
= &state
->rt
[index
];
565 struct ilo_blend_cso
*cso
= &blend
->cso
[index
];
566 bool independent_alpha
= false;
568 ILO_DEV_ASSERT(dev
, 8, 8);
571 cso
->payload
[1] = GEN8_RT_DW1_COLORCLAMP_RTFORMAT
|
572 GEN8_RT_DW1_PRE_BLEND_CLAMP
|
573 GEN8_RT_DW1_POST_BLEND_CLAMP
;
575 if (!(rt
->colormask
& PIPE_MASK_A
))
576 cso
->payload
[0] |= GEN8_RT_DW0_WRITE_DISABLES_A
;
577 if (!(rt
->colormask
& PIPE_MASK_R
))
578 cso
->payload
[0] |= GEN8_RT_DW0_WRITE_DISABLES_R
;
579 if (!(rt
->colormask
& PIPE_MASK_G
))
580 cso
->payload
[0] |= GEN8_RT_DW0_WRITE_DISABLES_G
;
581 if (!(rt
->colormask
& PIPE_MASK_B
))
582 cso
->payload
[0] |= GEN8_RT_DW0_WRITE_DISABLES_B
;
584 if (state
->logicop_enable
) {
586 cso
->dw_blend_dst_alpha_forced_one
= 0;
590 cso
->dw_blend
= blend_get_rt_blend_enable_gen8(dev
, rt
, false, &tmp
[0]);
591 cso
->dw_blend_dst_alpha_forced_one
=
592 blend_get_rt_blend_enable_gen8(dev
, rt
, true, &tmp
[1]);
594 if (tmp
[0] || tmp
[1])
595 independent_alpha
= true;
598 return independent_alpha
;
602 blend_get_logicop_enable_gen6(const struct ilo_dev
*dev
,
603 const struct pipe_blend_state
*state
)
605 ILO_DEV_ASSERT(dev
, 6, 7.5);
607 if (!state
->logicop_enable
)
610 return GEN6_RT_DW1_LOGICOP_ENABLE
|
611 gen6_translate_pipe_logicop(state
->logicop_func
) << 18;
615 blend_get_logicop_enable_gen8(const struct ilo_dev
*dev
,
616 const struct pipe_blend_state
*state
)
618 ILO_DEV_ASSERT(dev
, 8, 8);
620 if (!state
->logicop_enable
)
623 return GEN8_RT_DW1_LOGICOP_ENABLE
|
624 gen6_translate_pipe_logicop(state
->logicop_func
) << 27;
628 blend_get_alpha_mod_gen6(const struct ilo_dev
*dev
,
629 const struct pipe_blend_state
*state
,
634 ILO_DEV_ASSERT(dev
, 6, 7.5);
636 if (state
->alpha_to_coverage
) {
637 dw
|= GEN6_RT_DW1_ALPHA_TO_COVERAGE
;
638 if (ilo_dev_gen(dev
) >= ILO_GEN(7))
639 dw
|= GEN6_RT_DW1_ALPHA_TO_COVERAGE_DITHER
;
642 * From the Sandy Bridge PRM, volume 2 part 1, page 378:
644 * "If Dual Source Blending is enabled, this bit (AlphaToOne Enable)
647 if (state
->alpha_to_one
&& !dual_blend
)
648 dw
|= GEN6_RT_DW1_ALPHA_TO_ONE
;
654 blend_get_alpha_mod_gen8(const struct ilo_dev
*dev
,
655 const struct pipe_blend_state
*state
,
660 ILO_DEV_ASSERT(dev
, 8, 8);
662 if (state
->alpha_to_coverage
) {
663 dw
|= GEN8_BLEND_DW0_ALPHA_TO_COVERAGE
|
664 GEN8_BLEND_DW0_ALPHA_TO_COVERAGE_DITHER
;
667 if (state
->alpha_to_one
&& !dual_blend
)
668 dw
|= GEN8_BLEND_DW0_ALPHA_TO_ONE
;
674 blend_get_ps_blend_gen8(const struct ilo_dev
*dev
, uint32_t rt_dw0
)
676 int rgb_src
, rgb_dst
, a_src
, a_dst
;
679 ILO_DEV_ASSERT(dev
, 8, 8);
681 if (!(rt_dw0
& GEN8_RT_DW0_BLEND_ENABLE
))
684 a_src
= GEN_EXTRACT(rt_dw0
, GEN8_RT_DW0_SRC_ALPHA_FACTOR
);
685 a_dst
= GEN_EXTRACT(rt_dw0
, GEN8_RT_DW0_DST_ALPHA_FACTOR
);
686 rgb_src
= GEN_EXTRACT(rt_dw0
, GEN8_RT_DW0_SRC_COLOR_FACTOR
);
687 rgb_dst
= GEN_EXTRACT(rt_dw0
, GEN8_RT_DW0_DST_COLOR_FACTOR
);
689 dw
= GEN8_PS_BLEND_DW1_BLEND_ENABLE
;
690 dw
|= GEN_SHIFT32(a_src
, GEN8_PS_BLEND_DW1_SRC_ALPHA_FACTOR
);
691 dw
|= GEN_SHIFT32(a_dst
, GEN8_PS_BLEND_DW1_DST_ALPHA_FACTOR
);
692 dw
|= GEN_SHIFT32(rgb_src
, GEN8_PS_BLEND_DW1_SRC_COLOR_FACTOR
);
693 dw
|= GEN_SHIFT32(rgb_dst
, GEN8_PS_BLEND_DW1_DST_COLOR_FACTOR
);
695 if (a_src
!= rgb_src
|| a_dst
!= rgb_dst
)
696 dw
|= GEN8_PS_BLEND_DW1_INDEPENDENT_ALPHA_ENABLE
;
702 ilo_gpe_init_blend(const struct ilo_dev
*dev
,
703 const struct pipe_blend_state
*state
,
704 struct ilo_blend_state
*blend
)
708 ILO_DEV_ASSERT(dev
, 6, 8);
710 blend
->dual_blend
= (util_blend_state_is_dual(state
, 0) &&
711 state
->rt
[0].blend_enable
&&
712 !state
->logicop_enable
);
713 blend
->alpha_to_coverage
= state
->alpha_to_coverage
;
715 if (ilo_dev_gen(dev
) >= ILO_GEN(8)) {
716 bool independent_alpha
;
718 blend
->dw_alpha_mod
=
719 blend_get_alpha_mod_gen8(dev
, state
, blend
->dual_blend
);
720 blend
->dw_logicop
= blend_get_logicop_enable_gen8(dev
, state
);
721 blend
->dw_shared
= (state
->dither
) ? GEN8_BLEND_DW0_DITHER_ENABLE
: 0;
723 independent_alpha
= blend_init_cso_gen8(dev
, state
, blend
, 0);
724 if (independent_alpha
)
725 blend
->dw_shared
|= GEN8_BLEND_DW0_INDEPENDENT_ALPHA_ENABLE
;
727 blend
->dw_ps_blend
= blend_get_ps_blend_gen8(dev
,
728 blend
->cso
[0].dw_blend
);
729 blend
->dw_ps_blend_dst_alpha_forced_one
= blend_get_ps_blend_gen8(dev
,
730 blend
->cso
[0].dw_blend_dst_alpha_forced_one
);
732 if (state
->independent_blend_enable
) {
733 for (i
= 1; i
< Elements(blend
->cso
); i
++) {
734 independent_alpha
= blend_init_cso_gen8(dev
, state
, blend
, i
);
735 if (independent_alpha
)
736 blend
->dw_shared
|= GEN8_BLEND_DW0_INDEPENDENT_ALPHA_ENABLE
;
739 for (i
= 1; i
< Elements(blend
->cso
); i
++)
740 blend
->cso
[i
] = blend
->cso
[0];
743 blend
->dw_alpha_mod
=
744 blend_get_alpha_mod_gen6(dev
, state
, blend
->dual_blend
);
745 blend
->dw_logicop
= blend_get_logicop_enable_gen6(dev
, state
);
746 blend
->dw_shared
= (state
->dither
) ? GEN6_RT_DW1_DITHER_ENABLE
: 0;
748 blend
->dw_ps_blend
= 0;
749 blend
->dw_ps_blend_dst_alpha_forced_one
= 0;
751 blend_init_cso_gen6(dev
, state
, blend
, 0);
752 if (state
->independent_blend_enable
) {
753 for (i
= 1; i
< Elements(blend
->cso
); i
++)
754 blend_init_cso_gen6(dev
, state
, blend
, i
);
756 for (i
= 1; i
< Elements(blend
->cso
); i
++)
757 blend
->cso
[i
] = blend
->cso
[0];
763 * Translate a pipe DSA test function to the matching hardware compare
767 gen6_translate_dsa_func(unsigned func
)
770 case PIPE_FUNC_NEVER
: return GEN6_COMPAREFUNCTION_NEVER
;
771 case PIPE_FUNC_LESS
: return GEN6_COMPAREFUNCTION_LESS
;
772 case PIPE_FUNC_EQUAL
: return GEN6_COMPAREFUNCTION_EQUAL
;
773 case PIPE_FUNC_LEQUAL
: return GEN6_COMPAREFUNCTION_LEQUAL
;
774 case PIPE_FUNC_GREATER
: return GEN6_COMPAREFUNCTION_GREATER
;
775 case PIPE_FUNC_NOTEQUAL
: return GEN6_COMPAREFUNCTION_NOTEQUAL
;
776 case PIPE_FUNC_GEQUAL
: return GEN6_COMPAREFUNCTION_GEQUAL
;
777 case PIPE_FUNC_ALWAYS
: return GEN6_COMPAREFUNCTION_ALWAYS
;
779 assert(!"unknown depth/stencil/alpha test function");
780 return GEN6_COMPAREFUNCTION_NEVER
;
785 dsa_get_stencil_enable_gen6(const struct ilo_dev
*dev
,
786 const struct pipe_stencil_state
*stencil0
,
787 const struct pipe_stencil_state
*stencil1
)
791 ILO_DEV_ASSERT(dev
, 6, 7.5);
793 if (!stencil0
->enabled
)
797 * From the Sandy Bridge PRM, volume 2 part 1, page 359:
799 * "If the Depth Buffer is either undefined or does not have a surface
800 * format of D32_FLOAT_S8X24_UINT or D24_UNORM_S8_UINT and separate
801 * stencil buffer is disabled, Stencil Test Enable must be DISABLED"
803 * From the Sandy Bridge PRM, volume 2 part 1, page 370:
805 * "This field (Stencil Test Enable) cannot be enabled if
806 * Surface Format in 3DSTATE_DEPTH_BUFFER is set to D16_UNORM."
808 * TODO We do not check these yet.
810 dw
= GEN6_ZS_DW0_STENCIL_TEST_ENABLE
|
811 gen6_translate_dsa_func(stencil0
->func
) << 28 |
812 gen6_translate_pipe_stencil_op(stencil0
->fail_op
) << 25 |
813 gen6_translate_pipe_stencil_op(stencil0
->zfail_op
) << 22 |
814 gen6_translate_pipe_stencil_op(stencil0
->zpass_op
) << 19;
815 if (stencil0
->writemask
)
816 dw
|= GEN6_ZS_DW0_STENCIL_WRITE_ENABLE
;
818 if (stencil1
->enabled
) {
819 dw
|= GEN6_ZS_DW0_STENCIL1_ENABLE
|
820 gen6_translate_dsa_func(stencil1
->func
) << 12 |
821 gen6_translate_pipe_stencil_op(stencil1
->fail_op
) << 9 |
822 gen6_translate_pipe_stencil_op(stencil1
->zfail_op
) << 6 |
823 gen6_translate_pipe_stencil_op(stencil1
->zpass_op
) << 3;
824 if (stencil1
->writemask
)
825 dw
|= GEN6_ZS_DW0_STENCIL_WRITE_ENABLE
;
832 dsa_get_stencil_enable_gen8(const struct ilo_dev
*dev
,
833 const struct pipe_stencil_state
*stencil0
,
834 const struct pipe_stencil_state
*stencil1
)
838 ILO_DEV_ASSERT(dev
, 8, 8);
840 if (!stencil0
->enabled
)
843 dw
= gen6_translate_pipe_stencil_op(stencil0
->fail_op
) << 29 |
844 gen6_translate_pipe_stencil_op(stencil0
->zfail_op
) << 26 |
845 gen6_translate_pipe_stencil_op(stencil0
->zpass_op
) << 23 |
846 gen6_translate_dsa_func(stencil0
->func
) << 8 |
847 GEN8_ZS_DW1_STENCIL_TEST_ENABLE
;
848 if (stencil0
->writemask
)
849 dw
|= GEN8_ZS_DW1_STENCIL_WRITE_ENABLE
;
851 if (stencil1
->enabled
) {
852 dw
|= gen6_translate_dsa_func(stencil1
->func
) << 20 |
853 gen6_translate_pipe_stencil_op(stencil1
->fail_op
) << 17 |
854 gen6_translate_pipe_stencil_op(stencil1
->zfail_op
) << 14 |
855 gen6_translate_pipe_stencil_op(stencil1
->zpass_op
) << 11 |
856 GEN8_ZS_DW1_STENCIL1_ENABLE
;
857 if (stencil1
->writemask
)
858 dw
|= GEN8_ZS_DW1_STENCIL_WRITE_ENABLE
;
865 dsa_get_depth_enable_gen6(const struct ilo_dev
*dev
,
866 const struct pipe_depth_state
*state
)
870 ILO_DEV_ASSERT(dev
, 6, 7.5);
873 * From the Sandy Bridge PRM, volume 2 part 1, page 360:
875 * "Enabling the Depth Test function without defining a Depth Buffer is
878 * From the Sandy Bridge PRM, volume 2 part 1, page 375:
880 * "A Depth Buffer must be defined before enabling writes to it, or
881 * operation is UNDEFINED."
883 * TODO We do not check these yet.
885 if (state
->enabled
) {
886 dw
= GEN6_ZS_DW2_DEPTH_TEST_ENABLE
|
887 gen6_translate_dsa_func(state
->func
) << 27;
889 dw
= GEN6_COMPAREFUNCTION_ALWAYS
<< 27;
892 if (state
->writemask
)
893 dw
|= GEN6_ZS_DW2_DEPTH_WRITE_ENABLE
;
899 dsa_get_depth_enable_gen8(const struct ilo_dev
*dev
,
900 const struct pipe_depth_state
*state
)
904 ILO_DEV_ASSERT(dev
, 8, 8);
906 if (state
->enabled
) {
907 dw
= GEN8_ZS_DW1_DEPTH_TEST_ENABLE
|
908 gen6_translate_dsa_func(state
->func
) << 5;
910 dw
= GEN6_COMPAREFUNCTION_ALWAYS
<< 5;
913 if (state
->writemask
)
914 dw
|= GEN8_ZS_DW1_DEPTH_WRITE_ENABLE
;
920 dsa_get_alpha_enable_gen6(const struct ilo_dev
*dev
,
921 const struct pipe_alpha_state
*state
)
925 ILO_DEV_ASSERT(dev
, 6, 7.5);
930 /* this will be ORed to BLEND_STATE */
931 dw
= GEN6_RT_DW1_ALPHA_TEST_ENABLE
|
932 gen6_translate_dsa_func(state
->func
) << 13;
938 dsa_get_alpha_enable_gen8(const struct ilo_dev
*dev
,
939 const struct pipe_alpha_state
*state
)
943 ILO_DEV_ASSERT(dev
, 8, 8);
948 /* this will be ORed to BLEND_STATE */
949 dw
= GEN8_BLEND_DW0_ALPHA_TEST_ENABLE
|
950 gen6_translate_dsa_func(state
->func
) << 24;
956 ilo_gpe_init_dsa(const struct ilo_dev
*dev
,
957 const struct pipe_depth_stencil_alpha_state
*state
,
958 struct ilo_dsa_state
*dsa
)
960 ILO_DEV_ASSERT(dev
, 6, 8);
962 STATIC_ASSERT(Elements(dsa
->payload
) >= 3);
964 if (ilo_dev_gen(dev
) >= ILO_GEN(8)) {
965 const uint32_t dw_stencil
= dsa_get_stencil_enable_gen8(dev
,
966 &state
->stencil
[0], &state
->stencil
[1]);
967 const uint32_t dw_depth
= dsa_get_depth_enable_gen8(dev
, &state
->depth
);
969 assert(!(dw_stencil
& dw_depth
));
970 dsa
->payload
[0] = dw_stencil
| dw_depth
;
972 dsa
->dw_blend_alpha
= dsa_get_alpha_enable_gen8(dev
, &state
->alpha
);
973 dsa
->dw_ps_blend_alpha
= (state
->alpha
.enabled
) ?
974 GEN8_PS_BLEND_DW1_ALPHA_TEST_ENABLE
: 0;
976 dsa
->payload
[0] = dsa_get_stencil_enable_gen6(dev
,
977 &state
->stencil
[0], &state
->stencil
[1]);
978 dsa
->payload
[2] = dsa_get_depth_enable_gen6(dev
, &state
->depth
);
980 dsa
->dw_blend_alpha
= dsa_get_alpha_enable_gen6(dev
, &state
->alpha
);
981 dsa
->dw_ps_blend_alpha
= 0;
984 dsa
->payload
[1] = state
->stencil
[0].valuemask
<< 24 |
985 state
->stencil
[0].writemask
<< 16 |
986 state
->stencil
[1].valuemask
<< 8 |
987 state
->stencil
[1].writemask
;
989 dsa
->alpha_ref
= float_to_ubyte(state
->alpha
.ref_value
);
993 fb_set_blend_caps(const struct ilo_dev
*dev
,
994 enum pipe_format format
,
995 struct ilo_fb_blend_caps
*caps
)
997 const struct util_format_description
*desc
=
998 util_format_description(format
);
999 const int ch
= util_format_get_first_non_void_channel(format
);
1001 memset(caps
, 0, sizeof(*caps
));
1003 if (format
== PIPE_FORMAT_NONE
|| desc
->is_mixed
)
1006 caps
->is_unorm
= (ch
>= 0 && desc
->channel
[ch
].normalized
&&
1007 desc
->channel
[ch
].type
== UTIL_FORMAT_TYPE_UNSIGNED
&&
1008 desc
->colorspace
== UTIL_FORMAT_COLORSPACE_RGB
);
1009 caps
->is_integer
= util_format_is_pure_integer(format
);
1012 * From the Sandy Bridge PRM, volume 2 part 1, page 365:
1014 * "Logic Ops are only supported on *_UNORM surfaces (excluding _SRGB
1015 * variants), otherwise Logic Ops must be DISABLED."
1017 * According to the classic driver, this is lifted on Gen8+.
1019 caps
->can_logicop
= (ilo_dev_gen(dev
) >= ILO_GEN(8) || caps
->is_unorm
);
1021 /* no blending for pure integer formats */
1022 caps
->can_blend
= !caps
->is_integer
;
1025 * From the Sandy Bridge PRM, volume 2 part 1, page 382:
1027 * "Alpha Test can only be enabled if Pixel Shader outputs a float
1030 caps
->can_alpha_test
= !caps
->is_integer
;
1032 caps
->dst_alpha_forced_one
=
1033 (ilo_format_translate_render(dev
, format
) !=
1034 ilo_format_translate_color(dev
, format
));
1037 if (caps
->dst_alpha_forced_one
) {
1038 enum pipe_format render_format
;
1041 case PIPE_FORMAT_B8G8R8X8_UNORM
:
1042 render_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
1045 render_format
= PIPE_FORMAT_NONE
;
1049 assert(ilo_format_translate_render(dev
, format
) ==
1050 ilo_format_translate_color(dev
, render_format
));
1055 ilo_gpe_set_fb(const struct ilo_dev
*dev
,
1056 const struct pipe_framebuffer_state
*state
,
1057 struct ilo_fb_state
*fb
)
1059 const struct pipe_surface
*first_surf
= NULL
;
1062 ILO_DEV_ASSERT(dev
, 6, 8);
1064 util_copy_framebuffer_state(&fb
->state
, state
);
1066 fb
->has_integer_rt
= false;
1067 for (i
= 0; i
< state
->nr_cbufs
; i
++) {
1068 if (state
->cbufs
[i
]) {
1069 fb_set_blend_caps(dev
, state
->cbufs
[i
]->format
, &fb
->blend_caps
[i
]);
1071 fb
->has_integer_rt
|= fb
->blend_caps
[i
].is_integer
;
1074 first_surf
= state
->cbufs
[i
];
1076 fb_set_blend_caps(dev
, PIPE_FORMAT_NONE
, &fb
->blend_caps
[i
]);
1080 if (!first_surf
&& state
->zsbuf
)
1081 first_surf
= state
->zsbuf
;
1083 fb
->num_samples
= (first_surf
) ? first_surf
->texture
->nr_samples
: 1;
1084 if (!fb
->num_samples
)
1085 fb
->num_samples
= 1;
1088 const struct ilo_surface_cso
*cso
=
1089 (const struct ilo_surface_cso
*) state
->zsbuf
;
1091 fb
->has_hiz
= cso
->u
.zs
.hiz_bo
;
1092 fb
->depth_offset_format
=
1093 ilo_state_zs_get_depth_format(&cso
->u
.zs
, dev
);
1095 fb
->has_hiz
= false;
1096 fb
->depth_offset_format
= GEN6_ZFORMAT_D32_FLOAT
;
1100 * The PRMs list several restrictions when the framebuffer has more than
1101 * one surface. It seems they are actually lifted on GEN6+.