2 * Copyright © 2015 Intel Corporation
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 #include "anv_private.h"
26 #include "genxml/gen_macros.h"
27 #include "genxml/genX_pack.h"
29 #include "common/gen_l3_config.h"
30 #include "common/gen_sample_positions.h"
31 #include "nir/nir_xfb_info.h"
33 #include "vk_format_info.h"
36 vertex_element_comp_control(enum isl_format format
, unsigned comp
)
40 case 0: bits
= isl_format_layouts
[format
].channels
.r
.bits
; break;
41 case 1: bits
= isl_format_layouts
[format
].channels
.g
.bits
; break;
42 case 2: bits
= isl_format_layouts
[format
].channels
.b
.bits
; break;
43 case 3: bits
= isl_format_layouts
[format
].channels
.a
.bits
; break;
44 default: unreachable("Invalid component");
48 * Take in account hardware restrictions when dealing with 64-bit floats.
50 * From Broadwell spec, command reference structures, page 586:
51 * "When SourceElementFormat is set to one of the *64*_PASSTHRU formats,
52 * 64-bit components are stored * in the URB without any conversion. In
53 * this case, vertex elements must be written as 128 or 256 bits, with
54 * VFCOMP_STORE_0 being used to pad the output as required. E.g., if
55 * R64_PASSTHRU is used to copy a 64-bit Red component into the URB,
56 * Component 1 must be specified as VFCOMP_STORE_0 (with Components 2,3
57 * set to VFCOMP_NOSTORE) in order to output a 128-bit vertex element, or
58 * Components 1-3 must be specified as VFCOMP_STORE_0 in order to output
59 * a 256-bit vertex element. Likewise, use of R64G64B64_PASSTHRU requires
60 * Component 3 to be specified as VFCOMP_STORE_0 in order to output a
61 * 256-bit vertex element."
64 return VFCOMP_STORE_SRC
;
65 } else if (comp
>= 2 &&
66 !isl_format_layouts
[format
].channels
.b
.bits
&&
67 isl_format_layouts
[format
].channels
.r
.type
== ISL_RAW
) {
68 /* When emitting 64-bit attributes, we need to write either 128 or 256
69 * bit chunks, using VFCOMP_NOSTORE when not writing the chunk, and
70 * VFCOMP_STORE_0 to pad the written chunk */
71 return VFCOMP_NOSTORE
;
72 } else if (comp
< 3 ||
73 isl_format_layouts
[format
].channels
.r
.type
== ISL_RAW
) {
74 /* Note we need to pad with value 0, not 1, due hardware restrictions
75 * (see comment above) */
76 return VFCOMP_STORE_0
;
77 } else if (isl_format_layouts
[format
].channels
.r
.type
== ISL_UINT
||
78 isl_format_layouts
[format
].channels
.r
.type
== ISL_SINT
) {
80 return VFCOMP_STORE_1_INT
;
83 return VFCOMP_STORE_1_FP
;
88 emit_vertex_input(struct anv_pipeline
*pipeline
,
89 const VkPipelineVertexInputStateCreateInfo
*info
)
91 const struct brw_vs_prog_data
*vs_prog_data
= get_vs_prog_data(pipeline
);
93 /* Pull inputs_read out of the VS prog data */
94 const uint64_t inputs_read
= vs_prog_data
->inputs_read
;
95 const uint64_t double_inputs_read
=
96 vs_prog_data
->double_inputs_read
& inputs_read
;
97 assert((inputs_read
& ((1 << VERT_ATTRIB_GENERIC0
) - 1)) == 0);
98 const uint32_t elements
= inputs_read
>> VERT_ATTRIB_GENERIC0
;
99 const uint32_t elements_double
= double_inputs_read
>> VERT_ATTRIB_GENERIC0
;
100 const bool needs_svgs_elem
= vs_prog_data
->uses_vertexid
||
101 vs_prog_data
->uses_instanceid
||
102 vs_prog_data
->uses_firstvertex
||
103 vs_prog_data
->uses_baseinstance
;
105 uint32_t elem_count
= __builtin_popcount(elements
) -
106 __builtin_popcount(elements_double
) / 2;
108 const uint32_t total_elems
=
109 MAX2(1, elem_count
+ needs_svgs_elem
+ vs_prog_data
->uses_drawid
);
113 const uint32_t num_dwords
= 1 + total_elems
* 2;
114 p
= anv_batch_emitn(&pipeline
->batch
, num_dwords
,
115 GENX(3DSTATE_VERTEX_ELEMENTS
));
119 for (uint32_t i
= 0; i
< total_elems
; i
++) {
120 /* The SKL docs for VERTEX_ELEMENT_STATE say:
122 * "All elements must be valid from Element[0] to the last valid
123 * element. (I.e. if Element[2] is valid then Element[1] and
124 * Element[0] must also be valid)."
126 * The SKL docs for 3D_Vertex_Component_Control say:
128 * "Don't store this component. (Not valid for Component 0, but can
129 * be used for Component 1-3)."
131 * So we can't just leave a vertex element blank and hope for the best.
132 * We have to tell the VF hardware to put something in it; so we just
133 * store a bunch of zero.
135 * TODO: Compact vertex elements so we never end up with holes.
137 struct GENX(VERTEX_ELEMENT_STATE
) element
= {
139 .Component0Control
= VFCOMP_STORE_0
,
140 .Component1Control
= VFCOMP_STORE_0
,
141 .Component2Control
= VFCOMP_STORE_0
,
142 .Component3Control
= VFCOMP_STORE_0
,
144 GENX(VERTEX_ELEMENT_STATE_pack
)(NULL
, &p
[1 + i
* 2], &element
);
147 for (uint32_t i
= 0; i
< info
->vertexAttributeDescriptionCount
; i
++) {
148 const VkVertexInputAttributeDescription
*desc
=
149 &info
->pVertexAttributeDescriptions
[i
];
150 enum isl_format format
= anv_get_isl_format(&pipeline
->device
->info
,
152 VK_IMAGE_ASPECT_COLOR_BIT
,
153 VK_IMAGE_TILING_LINEAR
);
155 assert(desc
->binding
< MAX_VBS
);
157 if ((elements
& (1 << desc
->location
)) == 0)
158 continue; /* Binding unused */
161 __builtin_popcount(elements
& ((1 << desc
->location
) - 1)) -
162 DIV_ROUND_UP(__builtin_popcount(elements_double
&
163 ((1 << desc
->location
) -1)), 2);
165 struct GENX(VERTEX_ELEMENT_STATE
) element
= {
166 .VertexBufferIndex
= desc
->binding
,
168 .SourceElementFormat
= format
,
169 .EdgeFlagEnable
= false,
170 .SourceElementOffset
= desc
->offset
,
171 .Component0Control
= vertex_element_comp_control(format
, 0),
172 .Component1Control
= vertex_element_comp_control(format
, 1),
173 .Component2Control
= vertex_element_comp_control(format
, 2),
174 .Component3Control
= vertex_element_comp_control(format
, 3),
176 GENX(VERTEX_ELEMENT_STATE_pack
)(NULL
, &p
[1 + slot
* 2], &element
);
179 /* On Broadwell and later, we have a separate VF_INSTANCING packet
180 * that controls instancing. On Haswell and prior, that's part of
181 * VERTEX_BUFFER_STATE which we emit later.
183 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VF_INSTANCING
), vfi
) {
184 vfi
.InstancingEnable
= pipeline
->vb
[desc
->binding
].instanced
;
185 vfi
.VertexElementIndex
= slot
;
186 vfi
.InstanceDataStepRate
=
187 pipeline
->vb
[desc
->binding
].instance_divisor
;
192 const uint32_t id_slot
= elem_count
;
193 if (needs_svgs_elem
) {
194 /* From the Broadwell PRM for the 3D_Vertex_Component_Control enum:
195 * "Within a VERTEX_ELEMENT_STATE structure, if a Component
196 * Control field is set to something other than VFCOMP_STORE_SRC,
197 * no higher-numbered Component Control fields may be set to
200 * This means, that if we have BaseInstance, we need BaseVertex as
201 * well. Just do all or nothing.
203 uint32_t base_ctrl
= (vs_prog_data
->uses_firstvertex
||
204 vs_prog_data
->uses_baseinstance
) ?
205 VFCOMP_STORE_SRC
: VFCOMP_STORE_0
;
207 struct GENX(VERTEX_ELEMENT_STATE
) element
= {
208 .VertexBufferIndex
= ANV_SVGS_VB_INDEX
,
210 .SourceElementFormat
= ISL_FORMAT_R32G32_UINT
,
211 .Component0Control
= base_ctrl
,
212 .Component1Control
= base_ctrl
,
214 .Component2Control
= VFCOMP_STORE_0
,
215 .Component3Control
= VFCOMP_STORE_0
,
217 .Component2Control
= VFCOMP_STORE_VID
,
218 .Component3Control
= VFCOMP_STORE_IID
,
221 GENX(VERTEX_ELEMENT_STATE_pack
)(NULL
, &p
[1 + id_slot
* 2], &element
);
225 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VF_SGVS
), sgvs
) {
226 sgvs
.VertexIDEnable
= vs_prog_data
->uses_vertexid
;
227 sgvs
.VertexIDComponentNumber
= 2;
228 sgvs
.VertexIDElementOffset
= id_slot
;
229 sgvs
.InstanceIDEnable
= vs_prog_data
->uses_instanceid
;
230 sgvs
.InstanceIDComponentNumber
= 3;
231 sgvs
.InstanceIDElementOffset
= id_slot
;
235 const uint32_t drawid_slot
= elem_count
+ needs_svgs_elem
;
236 if (vs_prog_data
->uses_drawid
) {
237 struct GENX(VERTEX_ELEMENT_STATE
) element
= {
238 .VertexBufferIndex
= ANV_DRAWID_VB_INDEX
,
240 .SourceElementFormat
= ISL_FORMAT_R32_UINT
,
241 .Component0Control
= VFCOMP_STORE_SRC
,
242 .Component1Control
= VFCOMP_STORE_0
,
243 .Component2Control
= VFCOMP_STORE_0
,
244 .Component3Control
= VFCOMP_STORE_0
,
246 GENX(VERTEX_ELEMENT_STATE_pack
)(NULL
,
247 &p
[1 + drawid_slot
* 2],
251 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VF_INSTANCING
), vfi
) {
252 vfi
.VertexElementIndex
= drawid_slot
;
259 genX(emit_urb_setup
)(struct anv_device
*device
, struct anv_batch
*batch
,
260 const struct gen_l3_config
*l3_config
,
261 VkShaderStageFlags active_stages
,
262 const unsigned entry_size
[4])
264 const struct gen_device_info
*devinfo
= &device
->info
;
266 const unsigned push_constant_kb
= devinfo
->gt
== 3 ? 32 : 16;
268 const unsigned push_constant_kb
= GEN_GEN
>= 8 ? 32 : 16;
271 const unsigned urb_size_kb
= gen_get_l3_config_urb_size(devinfo
, l3_config
);
275 gen_get_urb_config(devinfo
,
276 1024 * push_constant_kb
, 1024 * urb_size_kb
,
278 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT
,
279 active_stages
& VK_SHADER_STAGE_GEOMETRY_BIT
,
280 entry_size
, entries
, start
);
282 #if GEN_GEN == 7 && !GEN_IS_HASWELL
283 /* From the IVB PRM Vol. 2, Part 1, Section 3.2.1:
285 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth stall
286 * needs to be sent just prior to any 3DSTATE_VS, 3DSTATE_URB_VS,
287 * 3DSTATE_CONSTANT_VS, 3DSTATE_BINDING_TABLE_POINTER_VS,
288 * 3DSTATE_SAMPLER_STATE_POINTER_VS command. Only one PIPE_CONTROL
289 * needs to be sent before any combination of VS associated 3DSTATE."
291 anv_batch_emit(batch
, GEN7_PIPE_CONTROL
, pc
) {
292 pc
.DepthStallEnable
= true;
293 pc
.PostSyncOperation
= WriteImmediateData
;
294 pc
.Address
= (struct anv_address
) { &device
->workaround_bo
, 0 };
298 for (int i
= 0; i
<= MESA_SHADER_GEOMETRY
; i
++) {
299 anv_batch_emit(batch
, GENX(3DSTATE_URB_VS
), urb
) {
300 urb
._3DCommandSubOpcode
+= i
;
301 urb
.VSURBStartingAddress
= start
[i
];
302 urb
.VSURBEntryAllocationSize
= entry_size
[i
] - 1;
303 urb
.VSNumberofURBEntries
= entries
[i
];
309 emit_urb_setup(struct anv_pipeline
*pipeline
)
311 unsigned entry_size
[4];
312 for (int i
= MESA_SHADER_VERTEX
; i
<= MESA_SHADER_GEOMETRY
; i
++) {
313 const struct brw_vue_prog_data
*prog_data
=
314 !anv_pipeline_has_stage(pipeline
, i
) ? NULL
:
315 (const struct brw_vue_prog_data
*) pipeline
->shaders
[i
]->prog_data
;
317 entry_size
[i
] = prog_data
? prog_data
->urb_entry_size
: 1;
320 genX(emit_urb_setup
)(pipeline
->device
, &pipeline
->batch
,
321 pipeline
->urb
.l3_config
,
322 pipeline
->active_stages
, entry_size
);
326 emit_3dstate_sbe(struct anv_pipeline
*pipeline
)
328 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
330 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
331 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_SBE
), sbe
);
333 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_SBE_SWIZ
), sbe
);
338 const struct brw_vue_map
*fs_input_map
=
339 &anv_pipeline_get_last_vue_prog_data(pipeline
)->vue_map
;
341 struct GENX(3DSTATE_SBE
) sbe
= {
342 GENX(3DSTATE_SBE_header
),
343 .AttributeSwizzleEnable
= true,
344 .PointSpriteTextureCoordinateOrigin
= UPPERLEFT
,
345 .NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
,
346 .ConstantInterpolationEnable
= wm_prog_data
->flat_inputs
,
350 for (unsigned i
= 0; i
< 32; i
++)
351 sbe
.AttributeActiveComponentFormat
[i
] = ACF_XYZW
;
355 /* On Broadwell, they broke 3DSTATE_SBE into two packets */
356 struct GENX(3DSTATE_SBE_SWIZ
) swiz
= {
357 GENX(3DSTATE_SBE_SWIZ_header
),
363 /* Skip the VUE header and position slots by default */
364 unsigned urb_entry_read_offset
= 1;
365 int max_source_attr
= 0;
366 for (int attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
367 int input_index
= wm_prog_data
->urb_setup
[attr
];
372 /* gl_Layer is stored in the VUE header */
373 if (attr
== VARYING_SLOT_LAYER
) {
374 urb_entry_read_offset
= 0;
378 if (attr
== VARYING_SLOT_PNTC
) {
379 sbe
.PointSpriteTextureCoordinateEnable
= 1 << input_index
;
383 const int slot
= fs_input_map
->varying_to_slot
[attr
];
385 if (input_index
>= 16)
389 /* This attribute does not exist in the VUE--that means that the
390 * vertex shader did not write to it. It could be that it's a
391 * regular varying read by the fragment shader but not written by
392 * the vertex shader or it's gl_PrimitiveID. In the first case the
393 * value is undefined, in the second it needs to be
396 swiz
.Attribute
[input_index
].ConstantSource
= PRIM_ID
;
397 swiz
.Attribute
[input_index
].ComponentOverrideX
= true;
398 swiz
.Attribute
[input_index
].ComponentOverrideY
= true;
399 swiz
.Attribute
[input_index
].ComponentOverrideZ
= true;
400 swiz
.Attribute
[input_index
].ComponentOverrideW
= true;
402 /* We have to subtract two slots to accout for the URB entry output
403 * read offset in the VS and GS stages.
405 const int source_attr
= slot
- 2 * urb_entry_read_offset
;
406 assert(source_attr
>= 0 && source_attr
< 32);
407 max_source_attr
= MAX2(max_source_attr
, source_attr
);
408 swiz
.Attribute
[input_index
].SourceAttribute
= source_attr
;
412 sbe
.VertexURBEntryReadOffset
= urb_entry_read_offset
;
413 sbe
.VertexURBEntryReadLength
= DIV_ROUND_UP(max_source_attr
+ 1, 2);
415 sbe
.ForceVertexURBEntryReadOffset
= true;
416 sbe
.ForceVertexURBEntryReadLength
= true;
419 uint32_t *dw
= anv_batch_emit_dwords(&pipeline
->batch
,
420 GENX(3DSTATE_SBE_length
));
423 GENX(3DSTATE_SBE_pack
)(&pipeline
->batch
, dw
, &sbe
);
426 dw
= anv_batch_emit_dwords(&pipeline
->batch
, GENX(3DSTATE_SBE_SWIZ_length
));
429 GENX(3DSTATE_SBE_SWIZ_pack
)(&pipeline
->batch
, dw
, &swiz
);
433 static const uint32_t vk_to_gen_cullmode
[] = {
434 [VK_CULL_MODE_NONE
] = CULLMODE_NONE
,
435 [VK_CULL_MODE_FRONT_BIT
] = CULLMODE_FRONT
,
436 [VK_CULL_MODE_BACK_BIT
] = CULLMODE_BACK
,
437 [VK_CULL_MODE_FRONT_AND_BACK
] = CULLMODE_BOTH
440 static const uint32_t vk_to_gen_fillmode
[] = {
441 [VK_POLYGON_MODE_FILL
] = FILL_MODE_SOLID
,
442 [VK_POLYGON_MODE_LINE
] = FILL_MODE_WIREFRAME
,
443 [VK_POLYGON_MODE_POINT
] = FILL_MODE_POINT
,
446 static const uint32_t vk_to_gen_front_face
[] = {
447 [VK_FRONT_FACE_COUNTER_CLOCKWISE
] = 1,
448 [VK_FRONT_FACE_CLOCKWISE
] = 0
451 static VkLineRasterizationModeEXT
452 vk_line_rasterization_mode(const VkPipelineRasterizationLineStateCreateInfoEXT
*line_info
,
453 const VkPipelineMultisampleStateCreateInfo
*ms_info
)
455 VkLineRasterizationModeEXT line_mode
=
456 line_info
? line_info
->lineRasterizationMode
:
457 VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT
;
459 if (line_mode
== VK_LINE_RASTERIZATION_MODE_DEFAULT_EXT
) {
460 if (ms_info
&& ms_info
->rasterizationSamples
> 1) {
461 return VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT
;
463 return VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT
;
470 /** Returns the final polygon mode for rasterization
472 * This function takes into account polygon mode, primitive topology and the
473 * different shader stages which might generate their own type of primitives.
476 anv_raster_polygon_mode(struct anv_pipeline
*pipeline
,
477 const VkPipelineInputAssemblyStateCreateInfo
*ia_info
,
478 const VkPipelineRasterizationStateCreateInfo
*rs_info
)
480 /* Points always override everything. This saves us from having to handle
481 * rs_info->polygonMode in all of the line cases below.
483 if (rs_info
->polygonMode
== VK_POLYGON_MODE_POINT
)
484 return VK_POLYGON_MODE_POINT
;
486 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_GEOMETRY
)) {
487 switch (get_gs_prog_data(pipeline
)->output_topology
) {
488 case _3DPRIM_POINTLIST
:
489 return VK_POLYGON_MODE_POINT
;
491 case _3DPRIM_LINELIST
:
492 case _3DPRIM_LINESTRIP
:
493 case _3DPRIM_LINELOOP
:
494 return VK_POLYGON_MODE_LINE
;
496 case _3DPRIM_TRILIST
:
498 case _3DPRIM_TRISTRIP
:
499 case _3DPRIM_RECTLIST
:
500 case _3DPRIM_QUADLIST
:
501 case _3DPRIM_QUADSTRIP
:
502 case _3DPRIM_POLYGON
:
503 return rs_info
->polygonMode
;
505 unreachable("Unsupported GS output topology");
506 } else if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_TESS_EVAL
)) {
507 switch (get_tes_prog_data(pipeline
)->output_topology
) {
508 case BRW_TESS_OUTPUT_TOPOLOGY_POINT
:
509 return VK_POLYGON_MODE_POINT
;
511 case BRW_TESS_OUTPUT_TOPOLOGY_LINE
:
512 return VK_POLYGON_MODE_LINE
;
514 case BRW_TESS_OUTPUT_TOPOLOGY_TRI_CW
:
515 case BRW_TESS_OUTPUT_TOPOLOGY_TRI_CCW
:
516 return rs_info
->polygonMode
;
518 unreachable("Unsupported TCS output topology");
520 switch (ia_info
->topology
) {
521 case VK_PRIMITIVE_TOPOLOGY_POINT_LIST
:
522 return VK_POLYGON_MODE_POINT
;
524 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST
:
525 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP
:
526 case VK_PRIMITIVE_TOPOLOGY_LINE_LIST_WITH_ADJACENCY
:
527 case VK_PRIMITIVE_TOPOLOGY_LINE_STRIP_WITH_ADJACENCY
:
528 return VK_POLYGON_MODE_LINE
;
530 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST
:
531 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP
:
532 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_FAN
:
533 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_LIST_WITH_ADJACENCY
:
534 case VK_PRIMITIVE_TOPOLOGY_TRIANGLE_STRIP_WITH_ADJACENCY
:
535 return rs_info
->polygonMode
;
538 unreachable("Unsupported primitive topology");
545 gen7_ms_rast_mode(struct anv_pipeline
*pipeline
,
546 const VkPipelineInputAssemblyStateCreateInfo
*ia_info
,
547 const VkPipelineRasterizationStateCreateInfo
*rs_info
,
548 const VkPipelineMultisampleStateCreateInfo
*ms_info
)
550 const VkPipelineRasterizationLineStateCreateInfoEXT
*line_info
=
551 vk_find_struct_const(rs_info
->pNext
,
552 PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT
);
554 VkPolygonMode raster_mode
=
555 anv_raster_polygon_mode(pipeline
, ia_info
, rs_info
);
556 if (raster_mode
== VK_POLYGON_MODE_LINE
) {
557 switch (vk_line_rasterization_mode(line_info
, ms_info
)) {
558 case VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT
:
559 return MSRASTMODE_ON_PATTERN
;
561 case VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT
:
562 case VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT
:
563 return MSRASTMODE_OFF_PIXEL
;
566 unreachable("Unsupported line rasterization mode");
569 return (ms_info
&& ms_info
->rasterizationSamples
> 1) ?
570 MSRASTMODE_ON_PATTERN
: MSRASTMODE_OFF_PIXEL
;
576 emit_rs_state(struct anv_pipeline
*pipeline
,
577 const VkPipelineInputAssemblyStateCreateInfo
*ia_info
,
578 const VkPipelineRasterizationStateCreateInfo
*rs_info
,
579 const VkPipelineMultisampleStateCreateInfo
*ms_info
,
580 const VkPipelineRasterizationLineStateCreateInfoEXT
*line_info
,
581 const struct anv_render_pass
*pass
,
582 const struct anv_subpass
*subpass
)
584 struct GENX(3DSTATE_SF
) sf
= {
585 GENX(3DSTATE_SF_header
),
588 sf
.ViewportTransformEnable
= true;
589 sf
.StatisticsEnable
= true;
590 sf
.TriangleStripListProvokingVertexSelect
= 0;
591 sf
.LineStripListProvokingVertexSelect
= 0;
592 sf
.TriangleFanProvokingVertexSelect
= 1;
593 sf
.VertexSubPixelPrecisionSelect
= _8Bit
;
594 sf
.AALineDistanceMode
= true;
597 sf
.LineStippleEnable
= line_info
&& line_info
->stippledLineEnable
;
600 const struct brw_vue_prog_data
*last_vue_prog_data
=
601 anv_pipeline_get_last_vue_prog_data(pipeline
);
603 if (last_vue_prog_data
->vue_map
.slots_valid
& VARYING_BIT_PSIZ
) {
604 sf
.PointWidthSource
= Vertex
;
606 sf
.PointWidthSource
= State
;
611 struct GENX(3DSTATE_RASTER
) raster
= {
612 GENX(3DSTATE_RASTER_header
),
618 VkPolygonMode raster_mode
=
619 anv_raster_polygon_mode(pipeline
, ia_info
, rs_info
);
620 VkLineRasterizationModeEXT line_mode
=
621 vk_line_rasterization_mode(line_info
, ms_info
);
623 /* For details on 3DSTATE_RASTER multisample state, see the BSpec table
624 * "Multisample Modes State".
627 if (raster_mode
== VK_POLYGON_MODE_LINE
) {
628 /* Unfortunately, configuring our line rasterization hardware on gen8
629 * and later is rather painful. Instead of giving us bits to tell the
630 * hardware what line mode to use like we had on gen7, we now have an
631 * arcane combination of API Mode and MSAA enable bits which do things
632 * in a table which are expected to magically put the hardware into the
633 * right mode for your API. Sadly, Vulkan isn't any of the APIs the
634 * hardware people thought of so nothing works the way you want it to.
636 * Look at the table titled "Multisample Rasterization Modes" in Vol 7
637 * of the Skylake PRM for more details.
640 case VK_LINE_RASTERIZATION_MODE_RECTANGULAR_EXT
:
641 raster
.APIMode
= DX100
;
642 raster
.DXMultisampleRasterizationEnable
= true;
645 case VK_LINE_RASTERIZATION_MODE_BRESENHAM_EXT
:
646 case VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT
:
647 raster
.APIMode
= DX9OGL
;
648 raster
.DXMultisampleRasterizationEnable
= false;
652 unreachable("Unsupported line rasterization mode");
655 raster
.APIMode
= DX100
;
656 raster
.DXMultisampleRasterizationEnable
= true;
659 /* NOTE: 3DSTATE_RASTER::ForcedSampleCount affects the BDW and SKL PMA fix
660 * computations. If we ever set this bit to a different value, they will
661 * need to be updated accordingly.
663 raster
.ForcedSampleCount
= FSC_NUMRASTSAMPLES_0
;
664 raster
.ForceMultisampling
= false;
666 raster
.MultisampleRasterizationMode
=
667 gen7_ms_rast_mode(pipeline
, ia_info
, rs_info
, ms_info
);
670 if (raster_mode
== VK_POLYGON_MODE_LINE
&&
671 line_mode
== VK_LINE_RASTERIZATION_MODE_RECTANGULAR_SMOOTH_EXT
)
672 raster
.AntialiasingEnable
= true;
674 raster
.FrontWinding
= vk_to_gen_front_face
[rs_info
->frontFace
];
675 raster
.CullMode
= vk_to_gen_cullmode
[rs_info
->cullMode
];
676 raster
.FrontFaceFillMode
= vk_to_gen_fillmode
[rs_info
->polygonMode
];
677 raster
.BackFaceFillMode
= vk_to_gen_fillmode
[rs_info
->polygonMode
];
678 raster
.ScissorRectangleEnable
= true;
681 /* GEN9+ splits ViewportZClipTestEnable into near and far enable bits */
682 raster
.ViewportZFarClipTestEnable
= pipeline
->depth_clip_enable
;
683 raster
.ViewportZNearClipTestEnable
= pipeline
->depth_clip_enable
;
685 raster
.ViewportZClipTestEnable
= pipeline
->depth_clip_enable
;
688 raster
.GlobalDepthOffsetEnableSolid
= rs_info
->depthBiasEnable
;
689 raster
.GlobalDepthOffsetEnableWireframe
= rs_info
->depthBiasEnable
;
690 raster
.GlobalDepthOffsetEnablePoint
= rs_info
->depthBiasEnable
;
693 /* Gen7 requires that we provide the depth format in 3DSTATE_SF so that it
694 * can get the depth offsets correct.
696 if (subpass
->depth_stencil_attachment
) {
698 pass
->attachments
[subpass
->depth_stencil_attachment
->attachment
].format
;
699 assert(vk_format_is_depth_or_stencil(vk_format
));
700 if (vk_format_aspects(vk_format
) & VK_IMAGE_ASPECT_DEPTH_BIT
) {
701 enum isl_format isl_format
=
702 anv_get_isl_format(&pipeline
->device
->info
, vk_format
,
703 VK_IMAGE_ASPECT_DEPTH_BIT
,
704 VK_IMAGE_TILING_OPTIMAL
);
705 sf
.DepthBufferSurfaceFormat
=
706 isl_format_get_depth_format(isl_format
, false);
712 GENX(3DSTATE_SF_pack
)(NULL
, pipeline
->gen8
.sf
, &sf
);
713 GENX(3DSTATE_RASTER_pack
)(NULL
, pipeline
->gen8
.raster
, &raster
);
716 GENX(3DSTATE_SF_pack
)(NULL
, &pipeline
->gen7
.sf
, &sf
);
721 emit_ms_state(struct anv_pipeline
*pipeline
,
722 const VkPipelineMultisampleStateCreateInfo
*info
)
724 uint32_t samples
= 1;
725 uint32_t log2_samples
= 0;
727 /* From the Vulkan 1.0 spec:
728 * If pSampleMask is NULL, it is treated as if the mask has all bits
729 * enabled, i.e. no coverage is removed from fragments.
731 * 3DSTATE_SAMPLE_MASK.SampleMask is 16 bits.
734 uint32_t sample_mask
= 0xffff;
736 uint32_t sample_mask
= 0xff;
740 samples
= info
->rasterizationSamples
;
741 log2_samples
= __builtin_ffs(samples
) - 1;
744 if (info
&& info
->pSampleMask
)
745 sample_mask
&= info
->pSampleMask
[0];
747 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_MULTISAMPLE
), ms
) {
748 ms
.NumberofMultisamples
= log2_samples
;
750 ms
.PixelLocation
= CENTER
;
752 /* The PRM says that this bit is valid only for DX9:
754 * SW can choose to set this bit only for DX9 API. DX10/OGL API's
755 * should not have any effect by setting or not setting this bit.
757 ms
.PixelPositionOffsetEnable
= false;
762 GEN_SAMPLE_POS_1X(ms
.Sample
);
765 GEN_SAMPLE_POS_2X(ms
.Sample
);
768 GEN_SAMPLE_POS_4X(ms
.Sample
);
771 GEN_SAMPLE_POS_8X(ms
.Sample
);
779 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_SAMPLE_MASK
), sm
) {
780 sm
.SampleMask
= sample_mask
;
784 static const uint32_t vk_to_gen_logic_op
[] = {
785 [VK_LOGIC_OP_COPY
] = LOGICOP_COPY
,
786 [VK_LOGIC_OP_CLEAR
] = LOGICOP_CLEAR
,
787 [VK_LOGIC_OP_AND
] = LOGICOP_AND
,
788 [VK_LOGIC_OP_AND_REVERSE
] = LOGICOP_AND_REVERSE
,
789 [VK_LOGIC_OP_AND_INVERTED
] = LOGICOP_AND_INVERTED
,
790 [VK_LOGIC_OP_NO_OP
] = LOGICOP_NOOP
,
791 [VK_LOGIC_OP_XOR
] = LOGICOP_XOR
,
792 [VK_LOGIC_OP_OR
] = LOGICOP_OR
,
793 [VK_LOGIC_OP_NOR
] = LOGICOP_NOR
,
794 [VK_LOGIC_OP_EQUIVALENT
] = LOGICOP_EQUIV
,
795 [VK_LOGIC_OP_INVERT
] = LOGICOP_INVERT
,
796 [VK_LOGIC_OP_OR_REVERSE
] = LOGICOP_OR_REVERSE
,
797 [VK_LOGIC_OP_COPY_INVERTED
] = LOGICOP_COPY_INVERTED
,
798 [VK_LOGIC_OP_OR_INVERTED
] = LOGICOP_OR_INVERTED
,
799 [VK_LOGIC_OP_NAND
] = LOGICOP_NAND
,
800 [VK_LOGIC_OP_SET
] = LOGICOP_SET
,
803 static const uint32_t vk_to_gen_blend
[] = {
804 [VK_BLEND_FACTOR_ZERO
] = BLENDFACTOR_ZERO
,
805 [VK_BLEND_FACTOR_ONE
] = BLENDFACTOR_ONE
,
806 [VK_BLEND_FACTOR_SRC_COLOR
] = BLENDFACTOR_SRC_COLOR
,
807 [VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR
] = BLENDFACTOR_INV_SRC_COLOR
,
808 [VK_BLEND_FACTOR_DST_COLOR
] = BLENDFACTOR_DST_COLOR
,
809 [VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR
] = BLENDFACTOR_INV_DST_COLOR
,
810 [VK_BLEND_FACTOR_SRC_ALPHA
] = BLENDFACTOR_SRC_ALPHA
,
811 [VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
] = BLENDFACTOR_INV_SRC_ALPHA
,
812 [VK_BLEND_FACTOR_DST_ALPHA
] = BLENDFACTOR_DST_ALPHA
,
813 [VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA
] = BLENDFACTOR_INV_DST_ALPHA
,
814 [VK_BLEND_FACTOR_CONSTANT_COLOR
] = BLENDFACTOR_CONST_COLOR
,
815 [VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR
]= BLENDFACTOR_INV_CONST_COLOR
,
816 [VK_BLEND_FACTOR_CONSTANT_ALPHA
] = BLENDFACTOR_CONST_ALPHA
,
817 [VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA
]= BLENDFACTOR_INV_CONST_ALPHA
,
818 [VK_BLEND_FACTOR_SRC_ALPHA_SATURATE
] = BLENDFACTOR_SRC_ALPHA_SATURATE
,
819 [VK_BLEND_FACTOR_SRC1_COLOR
] = BLENDFACTOR_SRC1_COLOR
,
820 [VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR
] = BLENDFACTOR_INV_SRC1_COLOR
,
821 [VK_BLEND_FACTOR_SRC1_ALPHA
] = BLENDFACTOR_SRC1_ALPHA
,
822 [VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA
] = BLENDFACTOR_INV_SRC1_ALPHA
,
825 static const uint32_t vk_to_gen_blend_op
[] = {
826 [VK_BLEND_OP_ADD
] = BLENDFUNCTION_ADD
,
827 [VK_BLEND_OP_SUBTRACT
] = BLENDFUNCTION_SUBTRACT
,
828 [VK_BLEND_OP_REVERSE_SUBTRACT
] = BLENDFUNCTION_REVERSE_SUBTRACT
,
829 [VK_BLEND_OP_MIN
] = BLENDFUNCTION_MIN
,
830 [VK_BLEND_OP_MAX
] = BLENDFUNCTION_MAX
,
833 static const uint32_t vk_to_gen_compare_op
[] = {
834 [VK_COMPARE_OP_NEVER
] = PREFILTEROPNEVER
,
835 [VK_COMPARE_OP_LESS
] = PREFILTEROPLESS
,
836 [VK_COMPARE_OP_EQUAL
] = PREFILTEROPEQUAL
,
837 [VK_COMPARE_OP_LESS_OR_EQUAL
] = PREFILTEROPLEQUAL
,
838 [VK_COMPARE_OP_GREATER
] = PREFILTEROPGREATER
,
839 [VK_COMPARE_OP_NOT_EQUAL
] = PREFILTEROPNOTEQUAL
,
840 [VK_COMPARE_OP_GREATER_OR_EQUAL
] = PREFILTEROPGEQUAL
,
841 [VK_COMPARE_OP_ALWAYS
] = PREFILTEROPALWAYS
,
844 static const uint32_t vk_to_gen_stencil_op
[] = {
845 [VK_STENCIL_OP_KEEP
] = STENCILOP_KEEP
,
846 [VK_STENCIL_OP_ZERO
] = STENCILOP_ZERO
,
847 [VK_STENCIL_OP_REPLACE
] = STENCILOP_REPLACE
,
848 [VK_STENCIL_OP_INCREMENT_AND_CLAMP
] = STENCILOP_INCRSAT
,
849 [VK_STENCIL_OP_DECREMENT_AND_CLAMP
] = STENCILOP_DECRSAT
,
850 [VK_STENCIL_OP_INVERT
] = STENCILOP_INVERT
,
851 [VK_STENCIL_OP_INCREMENT_AND_WRAP
] = STENCILOP_INCR
,
852 [VK_STENCIL_OP_DECREMENT_AND_WRAP
] = STENCILOP_DECR
,
855 /* This function sanitizes the VkStencilOpState by looking at the compare ops
856 * and trying to determine whether or not a given stencil op can ever actually
857 * occur. Stencil ops which can never occur are set to VK_STENCIL_OP_KEEP.
858 * This function returns true if, after sanitation, any of the stencil ops are
859 * set to something other than VK_STENCIL_OP_KEEP.
862 sanitize_stencil_face(VkStencilOpState
*face
,
863 VkCompareOp depthCompareOp
)
865 /* If compareOp is ALWAYS then the stencil test will never fail and failOp
866 * will never happen. Set failOp to KEEP in this case.
868 if (face
->compareOp
== VK_COMPARE_OP_ALWAYS
)
869 face
->failOp
= VK_STENCIL_OP_KEEP
;
871 /* If compareOp is NEVER or depthCompareOp is NEVER then one of the depth
872 * or stencil tests will fail and passOp will never happen.
874 if (face
->compareOp
== VK_COMPARE_OP_NEVER
||
875 depthCompareOp
== VK_COMPARE_OP_NEVER
)
876 face
->passOp
= VK_STENCIL_OP_KEEP
;
878 /* If compareOp is NEVER or depthCompareOp is ALWAYS then either the
879 * stencil test will fail or the depth test will pass. In either case,
880 * depthFailOp will never happen.
882 if (face
->compareOp
== VK_COMPARE_OP_NEVER
||
883 depthCompareOp
== VK_COMPARE_OP_ALWAYS
)
884 face
->depthFailOp
= VK_STENCIL_OP_KEEP
;
886 return face
->failOp
!= VK_STENCIL_OP_KEEP
||
887 face
->depthFailOp
!= VK_STENCIL_OP_KEEP
||
888 face
->passOp
!= VK_STENCIL_OP_KEEP
;
891 /* Intel hardware is fairly sensitive to whether or not depth/stencil writes
892 * are enabled. In the presence of discards, it's fairly easy to get into the
893 * non-promoted case which means a fairly big performance hit. From the Iron
894 * Lake PRM, Vol 2, pt. 1, section 8.4.3.2, "Early Depth Test Cases":
896 * "Non-promoted depth (N) is active whenever the depth test can be done
897 * early but it cannot determine whether or not to write source depth to
898 * the depth buffer, therefore the depth write must be performed post pixel
899 * shader. This includes cases where the pixel shader can kill pixels,
900 * including via sampler chroma key, as well as cases where the alpha test
901 * function is enabled, which kills pixels based on a programmable alpha
902 * test. In this case, even if the depth test fails, the pixel cannot be
903 * killed if a stencil write is indicated. Whether or not the stencil write
904 * happens depends on whether or not the pixel is killed later. In these
905 * cases if stencil test fails and stencil writes are off, the pixels can
906 * also be killed early. If stencil writes are enabled, the pixels must be
907 * treated as Computed depth (described above)."
909 * The same thing as mentioned in the stencil case can happen in the depth
910 * case as well if it thinks it writes depth but, thanks to the depth test
911 * being GL_EQUAL, the write doesn't actually matter. A little extra work
912 * up-front to try and disable depth and stencil writes can make a big
915 * Unfortunately, the way depth and stencil testing is specified, there are
916 * many case where, regardless of depth/stencil writes being enabled, nothing
917 * actually gets written due to some other bit of state being set. This
918 * function attempts to "sanitize" the depth stencil state and disable writes
919 * and sometimes even testing whenever possible.
922 sanitize_ds_state(VkPipelineDepthStencilStateCreateInfo
*state
,
923 bool *stencilWriteEnable
,
924 VkImageAspectFlags ds_aspects
)
926 *stencilWriteEnable
= state
->stencilTestEnable
;
928 /* If the depth test is disabled, we won't be writing anything. Make sure we
929 * treat the test as always passing later on as well.
931 * Also, the Vulkan spec requires that if either depth or stencil is not
932 * present, the pipeline is to act as if the test silently passes. In that
933 * case we won't write either.
935 if (!state
->depthTestEnable
|| !(ds_aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
)) {
936 state
->depthWriteEnable
= false;
937 state
->depthCompareOp
= VK_COMPARE_OP_ALWAYS
;
940 if (!(ds_aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
)) {
941 *stencilWriteEnable
= false;
942 state
->front
.compareOp
= VK_COMPARE_OP_ALWAYS
;
943 state
->back
.compareOp
= VK_COMPARE_OP_ALWAYS
;
946 /* If the stencil test is enabled and always fails, then we will never get
947 * to the depth test so we can just disable the depth test entirely.
949 if (state
->stencilTestEnable
&&
950 state
->front
.compareOp
== VK_COMPARE_OP_NEVER
&&
951 state
->back
.compareOp
== VK_COMPARE_OP_NEVER
) {
952 state
->depthTestEnable
= false;
953 state
->depthWriteEnable
= false;
956 /* If depthCompareOp is EQUAL then the value we would be writing to the
957 * depth buffer is the same as the value that's already there so there's no
958 * point in writing it.
960 if (state
->depthCompareOp
== VK_COMPARE_OP_EQUAL
)
961 state
->depthWriteEnable
= false;
963 /* If the stencil ops are such that we don't actually ever modify the
964 * stencil buffer, we should disable writes.
966 if (!sanitize_stencil_face(&state
->front
, state
->depthCompareOp
) &&
967 !sanitize_stencil_face(&state
->back
, state
->depthCompareOp
))
968 *stencilWriteEnable
= false;
970 /* If the depth test always passes and we never write out depth, that's the
971 * same as if the depth test is disabled entirely.
973 if (state
->depthCompareOp
== VK_COMPARE_OP_ALWAYS
&&
974 !state
->depthWriteEnable
)
975 state
->depthTestEnable
= false;
977 /* If the stencil test always passes and we never write out stencil, that's
978 * the same as if the stencil test is disabled entirely.
980 if (state
->front
.compareOp
== VK_COMPARE_OP_ALWAYS
&&
981 state
->back
.compareOp
== VK_COMPARE_OP_ALWAYS
&&
982 !*stencilWriteEnable
)
983 state
->stencilTestEnable
= false;
987 emit_ds_state(struct anv_pipeline
*pipeline
,
988 const VkPipelineDepthStencilStateCreateInfo
*pCreateInfo
,
989 const struct anv_render_pass
*pass
,
990 const struct anv_subpass
*subpass
)
993 # define depth_stencil_dw pipeline->gen7.depth_stencil_state
995 # define depth_stencil_dw pipeline->gen8.wm_depth_stencil
997 # define depth_stencil_dw pipeline->gen9.wm_depth_stencil
1000 if (pCreateInfo
== NULL
) {
1001 /* We're going to OR this together with the dynamic state. We need
1002 * to make sure it's initialized to something useful.
1004 pipeline
->writes_stencil
= false;
1005 pipeline
->stencil_test_enable
= false;
1006 pipeline
->writes_depth
= false;
1007 pipeline
->depth_test_enable
= false;
1008 memset(depth_stencil_dw
, 0, sizeof(depth_stencil_dw
));
1012 VkImageAspectFlags ds_aspects
= 0;
1013 if (subpass
->depth_stencil_attachment
) {
1014 VkFormat depth_stencil_format
=
1015 pass
->attachments
[subpass
->depth_stencil_attachment
->attachment
].format
;
1016 ds_aspects
= vk_format_aspects(depth_stencil_format
);
1019 VkPipelineDepthStencilStateCreateInfo info
= *pCreateInfo
;
1020 sanitize_ds_state(&info
, &pipeline
->writes_stencil
, ds_aspects
);
1021 pipeline
->stencil_test_enable
= info
.stencilTestEnable
;
1022 pipeline
->writes_depth
= info
.depthWriteEnable
;
1023 pipeline
->depth_test_enable
= info
.depthTestEnable
;
1025 /* VkBool32 depthBoundsTestEnable; // optional (depth_bounds_test) */
1028 struct GENX(DEPTH_STENCIL_STATE
) depth_stencil
= {
1030 struct GENX(3DSTATE_WM_DEPTH_STENCIL
) depth_stencil
= {
1032 .DepthTestEnable
= info
.depthTestEnable
,
1033 .DepthBufferWriteEnable
= info
.depthWriteEnable
,
1034 .DepthTestFunction
= vk_to_gen_compare_op
[info
.depthCompareOp
],
1035 .DoubleSidedStencilEnable
= true,
1037 .StencilTestEnable
= info
.stencilTestEnable
,
1038 .StencilFailOp
= vk_to_gen_stencil_op
[info
.front
.failOp
],
1039 .StencilPassDepthPassOp
= vk_to_gen_stencil_op
[info
.front
.passOp
],
1040 .StencilPassDepthFailOp
= vk_to_gen_stencil_op
[info
.front
.depthFailOp
],
1041 .StencilTestFunction
= vk_to_gen_compare_op
[info
.front
.compareOp
],
1042 .BackfaceStencilFailOp
= vk_to_gen_stencil_op
[info
.back
.failOp
],
1043 .BackfaceStencilPassDepthPassOp
= vk_to_gen_stencil_op
[info
.back
.passOp
],
1044 .BackfaceStencilPassDepthFailOp
=vk_to_gen_stencil_op
[info
.back
.depthFailOp
],
1045 .BackfaceStencilTestFunction
= vk_to_gen_compare_op
[info
.back
.compareOp
],
1049 GENX(DEPTH_STENCIL_STATE_pack
)(NULL
, depth_stencil_dw
, &depth_stencil
);
1051 GENX(3DSTATE_WM_DEPTH_STENCIL_pack
)(NULL
, depth_stencil_dw
, &depth_stencil
);
1056 is_dual_src_blend_factor(VkBlendFactor factor
)
1058 return factor
== VK_BLEND_FACTOR_SRC1_COLOR
||
1059 factor
== VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR
||
1060 factor
== VK_BLEND_FACTOR_SRC1_ALPHA
||
1061 factor
== VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA
;
1065 emit_cb_state(struct anv_pipeline
*pipeline
,
1066 const VkPipelineColorBlendStateCreateInfo
*info
,
1067 const VkPipelineMultisampleStateCreateInfo
*ms_info
)
1069 struct anv_device
*device
= pipeline
->device
;
1070 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
1072 struct GENX(BLEND_STATE
) blend_state
= {
1074 .AlphaToCoverageEnable
= ms_info
&& ms_info
->alphaToCoverageEnable
,
1075 .AlphaToOneEnable
= ms_info
&& ms_info
->alphaToOneEnable
,
1079 uint32_t surface_count
= 0;
1080 struct anv_pipeline_bind_map
*map
;
1081 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
1082 map
= &pipeline
->shaders
[MESA_SHADER_FRAGMENT
]->bind_map
;
1083 surface_count
= map
->surface_count
;
1086 const uint32_t num_dwords
= GENX(BLEND_STATE_length
) +
1087 GENX(BLEND_STATE_ENTRY_length
) * surface_count
;
1088 pipeline
->blend_state
=
1089 anv_state_pool_alloc(&device
->dynamic_state_pool
, num_dwords
* 4, 64);
1091 bool has_writeable_rt
= false;
1092 uint32_t *state_pos
= pipeline
->blend_state
.map
;
1093 state_pos
+= GENX(BLEND_STATE_length
);
1095 struct GENX(BLEND_STATE_ENTRY
) bs0
= { 0 };
1097 for (unsigned i
= 0; i
< surface_count
; i
++) {
1098 struct anv_pipeline_binding
*binding
= &map
->surface_to_descriptor
[i
];
1100 /* All color attachments are at the beginning of the binding table */
1101 if (binding
->set
!= ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS
)
1104 /* We can have at most 8 attachments */
1107 if (info
== NULL
|| binding
->index
>= info
->attachmentCount
) {
1108 /* Default everything to disabled */
1109 struct GENX(BLEND_STATE_ENTRY
) entry
= {
1110 .WriteDisableAlpha
= true,
1111 .WriteDisableRed
= true,
1112 .WriteDisableGreen
= true,
1113 .WriteDisableBlue
= true,
1115 GENX(BLEND_STATE_ENTRY_pack
)(NULL
, state_pos
, &entry
);
1116 state_pos
+= GENX(BLEND_STATE_ENTRY_length
);
1120 assert(binding
->binding
== 0);
1121 const VkPipelineColorBlendAttachmentState
*a
=
1122 &info
->pAttachments
[binding
->index
];
1124 struct GENX(BLEND_STATE_ENTRY
) entry
= {
1126 .AlphaToCoverageEnable
= ms_info
&& ms_info
->alphaToCoverageEnable
,
1127 .AlphaToOneEnable
= ms_info
&& ms_info
->alphaToOneEnable
,
1129 .LogicOpEnable
= info
->logicOpEnable
,
1130 .LogicOpFunction
= vk_to_gen_logic_op
[info
->logicOp
],
1131 .ColorBufferBlendEnable
= a
->blendEnable
,
1132 .ColorClampRange
= COLORCLAMP_RTFORMAT
,
1133 .PreBlendColorClampEnable
= true,
1134 .PostBlendColorClampEnable
= true,
1135 .SourceBlendFactor
= vk_to_gen_blend
[a
->srcColorBlendFactor
],
1136 .DestinationBlendFactor
= vk_to_gen_blend
[a
->dstColorBlendFactor
],
1137 .ColorBlendFunction
= vk_to_gen_blend_op
[a
->colorBlendOp
],
1138 .SourceAlphaBlendFactor
= vk_to_gen_blend
[a
->srcAlphaBlendFactor
],
1139 .DestinationAlphaBlendFactor
= vk_to_gen_blend
[a
->dstAlphaBlendFactor
],
1140 .AlphaBlendFunction
= vk_to_gen_blend_op
[a
->alphaBlendOp
],
1141 .WriteDisableAlpha
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_A_BIT
),
1142 .WriteDisableRed
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_R_BIT
),
1143 .WriteDisableGreen
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_G_BIT
),
1144 .WriteDisableBlue
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_B_BIT
),
1147 if (a
->srcColorBlendFactor
!= a
->srcAlphaBlendFactor
||
1148 a
->dstColorBlendFactor
!= a
->dstAlphaBlendFactor
||
1149 a
->colorBlendOp
!= a
->alphaBlendOp
) {
1151 blend_state
.IndependentAlphaBlendEnable
= true;
1153 entry
.IndependentAlphaBlendEnable
= true;
1157 /* The Dual Source Blending documentation says:
1159 * "If SRC1 is included in a src/dst blend factor and
1160 * a DualSource RT Write message is not used, results
1161 * are UNDEFINED. (This reflects the same restriction in DX APIs,
1162 * where undefined results are produced if “o1” is not written
1163 * by a PS – there are no default values defined)."
1165 * There is no way to gracefully fix this undefined situation
1166 * so we just disable the blending to prevent possible issues.
1168 if (!wm_prog_data
->dual_src_blend
&&
1169 (is_dual_src_blend_factor(a
->srcColorBlendFactor
) ||
1170 is_dual_src_blend_factor(a
->dstColorBlendFactor
) ||
1171 is_dual_src_blend_factor(a
->srcAlphaBlendFactor
) ||
1172 is_dual_src_blend_factor(a
->dstAlphaBlendFactor
))) {
1173 vk_debug_report(&device
->instance
->debug_report_callbacks
,
1174 VK_DEBUG_REPORT_WARNING_BIT_EXT
,
1175 VK_DEBUG_REPORT_OBJECT_TYPE_DEVICE_EXT
,
1176 (uint64_t)(uintptr_t)device
,
1178 "Enabled dual-src blend factors without writing both targets "
1179 "in the shader. Disabling blending to avoid GPU hangs.");
1180 entry
.ColorBufferBlendEnable
= false;
1183 if (a
->colorWriteMask
!= 0)
1184 has_writeable_rt
= true;
1186 /* Our hardware applies the blend factor prior to the blend function
1187 * regardless of what function is used. Technically, this means the
1188 * hardware can do MORE than GL or Vulkan specify. However, it also
1189 * means that, for MIN and MAX, we have to stomp the blend factor to
1190 * ONE to make it a no-op.
1192 if (a
->colorBlendOp
== VK_BLEND_OP_MIN
||
1193 a
->colorBlendOp
== VK_BLEND_OP_MAX
) {
1194 entry
.SourceBlendFactor
= BLENDFACTOR_ONE
;
1195 entry
.DestinationBlendFactor
= BLENDFACTOR_ONE
;
1197 if (a
->alphaBlendOp
== VK_BLEND_OP_MIN
||
1198 a
->alphaBlendOp
== VK_BLEND_OP_MAX
) {
1199 entry
.SourceAlphaBlendFactor
= BLENDFACTOR_ONE
;
1200 entry
.DestinationAlphaBlendFactor
= BLENDFACTOR_ONE
;
1202 GENX(BLEND_STATE_ENTRY_pack
)(NULL
, state_pos
, &entry
);
1203 state_pos
+= GENX(BLEND_STATE_ENTRY_length
);
1211 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS_BLEND
), blend
) {
1212 blend
.AlphaToCoverageEnable
= blend_state
.AlphaToCoverageEnable
;
1213 blend
.HasWriteableRT
= has_writeable_rt
;
1214 blend
.ColorBufferBlendEnable
= bs0
.ColorBufferBlendEnable
;
1215 blend
.SourceAlphaBlendFactor
= bs0
.SourceAlphaBlendFactor
;
1216 blend
.DestinationAlphaBlendFactor
= bs0
.DestinationAlphaBlendFactor
;
1217 blend
.SourceBlendFactor
= bs0
.SourceBlendFactor
;
1218 blend
.DestinationBlendFactor
= bs0
.DestinationBlendFactor
;
1219 blend
.AlphaTestEnable
= false;
1220 blend
.IndependentAlphaBlendEnable
=
1221 blend_state
.IndependentAlphaBlendEnable
;
1224 (void)has_writeable_rt
;
1227 GENX(BLEND_STATE_pack
)(NULL
, pipeline
->blend_state
.map
, &blend_state
);
1229 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_BLEND_STATE_POINTERS
), bsp
) {
1230 bsp
.BlendStatePointer
= pipeline
->blend_state
.offset
;
1232 bsp
.BlendStatePointerValid
= true;
1238 emit_3dstate_clip(struct anv_pipeline
*pipeline
,
1239 const VkPipelineInputAssemblyStateCreateInfo
*ia_info
,
1240 const VkPipelineViewportStateCreateInfo
*vp_info
,
1241 const VkPipelineRasterizationStateCreateInfo
*rs_info
)
1243 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
1244 (void) wm_prog_data
;
1245 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_CLIP
), clip
) {
1246 clip
.ClipEnable
= true;
1247 clip
.StatisticsEnable
= true;
1248 clip
.EarlyCullEnable
= true;
1249 clip
.APIMode
= APIMODE_D3D
;
1250 clip
.GuardbandClipTestEnable
= true;
1252 /* Only enable the XY clip test when the final polygon rasterization
1253 * mode is VK_POLYGON_MODE_FILL. We want to leave it disabled for
1254 * points and lines so we get "pop-free" clipping.
1256 VkPolygonMode raster_mode
=
1257 anv_raster_polygon_mode(pipeline
, ia_info
, rs_info
);
1258 clip
.ViewportXYClipTestEnable
= (raster_mode
== VK_POLYGON_MODE_FILL
);
1261 clip
.VertexSubPixelPrecisionSelect
= _8Bit
;
1264 clip
.ClipMode
= CLIPMODE_NORMAL
;
1266 clip
.TriangleStripListProvokingVertexSelect
= 0;
1267 clip
.LineStripListProvokingVertexSelect
= 0;
1268 clip
.TriangleFanProvokingVertexSelect
= 1;
1270 clip
.MinimumPointWidth
= 0.125;
1271 clip
.MaximumPointWidth
= 255.875;
1273 const struct brw_vue_prog_data
*last
=
1274 anv_pipeline_get_last_vue_prog_data(pipeline
);
1276 /* From the Vulkan 1.0.45 spec:
1278 * "If the last active vertex processing stage shader entry point's
1279 * interface does not include a variable decorated with
1280 * ViewportIndex, then the first viewport is used."
1282 if (vp_info
&& (last
->vue_map
.slots_valid
& VARYING_BIT_VIEWPORT
)) {
1283 clip
.MaximumVPIndex
= vp_info
->viewportCount
- 1;
1285 clip
.MaximumVPIndex
= 0;
1288 /* From the Vulkan 1.0.45 spec:
1290 * "If the last active vertex processing stage shader entry point's
1291 * interface does not include a variable decorated with Layer, then
1292 * the first layer is used."
1294 clip
.ForceZeroRTAIndexEnable
=
1295 !(last
->vue_map
.slots_valid
& VARYING_BIT_LAYER
);
1298 clip
.FrontWinding
= vk_to_gen_front_face
[rs_info
->frontFace
];
1299 clip
.CullMode
= vk_to_gen_cullmode
[rs_info
->cullMode
];
1300 clip
.ViewportZClipTestEnable
= pipeline
->depth_clip_enable
;
1301 clip
.UserClipDistanceClipTestEnableBitmask
= last
->clip_distance_mask
;
1302 clip
.UserClipDistanceCullTestEnableBitmask
= last
->cull_distance_mask
;
1304 clip
.NonPerspectiveBarycentricEnable
= wm_prog_data
?
1305 (wm_prog_data
->barycentric_interp_modes
&
1306 BRW_BARYCENTRIC_NONPERSPECTIVE_BITS
) != 0 : 0;
1312 emit_3dstate_streamout(struct anv_pipeline
*pipeline
,
1313 const VkPipelineRasterizationStateCreateInfo
*rs_info
)
1316 const struct brw_vue_prog_data
*prog_data
=
1317 anv_pipeline_get_last_vue_prog_data(pipeline
);
1318 const struct brw_vue_map
*vue_map
= &prog_data
->vue_map
;
1321 nir_xfb_info
*xfb_info
;
1322 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_GEOMETRY
))
1323 xfb_info
= pipeline
->shaders
[MESA_SHADER_GEOMETRY
]->xfb_info
;
1324 else if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_TESS_EVAL
))
1325 xfb_info
= pipeline
->shaders
[MESA_SHADER_TESS_EVAL
]->xfb_info
;
1327 xfb_info
= pipeline
->shaders
[MESA_SHADER_VERTEX
]->xfb_info
;
1329 pipeline
->xfb_used
= xfb_info
? xfb_info
->buffers_written
: 0;
1331 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_STREAMOUT
), so
) {
1332 so
.RenderingDisable
= rs_info
->rasterizerDiscardEnable
;
1336 so
.SOFunctionEnable
= true;
1337 so
.SOStatisticsEnable
= true;
1339 const VkPipelineRasterizationStateStreamCreateInfoEXT
*stream_info
=
1340 vk_find_struct_const(rs_info
, PIPELINE_RASTERIZATION_STATE_STREAM_CREATE_INFO_EXT
);
1341 so
.RenderStreamSelect
= stream_info
?
1342 stream_info
->rasterizationStream
: 0;
1344 so
.Buffer0SurfacePitch
= xfb_info
->buffers
[0].stride
;
1345 so
.Buffer1SurfacePitch
= xfb_info
->buffers
[1].stride
;
1346 so
.Buffer2SurfacePitch
= xfb_info
->buffers
[2].stride
;
1347 so
.Buffer3SurfacePitch
= xfb_info
->buffers
[3].stride
;
1349 int urb_entry_read_offset
= 0;
1350 int urb_entry_read_length
=
1351 (prog_data
->vue_map
.num_slots
+ 1) / 2 - urb_entry_read_offset
;
1353 /* We always read the whole vertex. This could be reduced at some
1354 * point by reading less and offsetting the register index in the
1357 so
.Stream0VertexReadOffset
= urb_entry_read_offset
;
1358 so
.Stream0VertexReadLength
= urb_entry_read_length
- 1;
1359 so
.Stream1VertexReadOffset
= urb_entry_read_offset
;
1360 so
.Stream1VertexReadLength
= urb_entry_read_length
- 1;
1361 so
.Stream2VertexReadOffset
= urb_entry_read_offset
;
1362 so
.Stream2VertexReadLength
= urb_entry_read_length
- 1;
1363 so
.Stream3VertexReadOffset
= urb_entry_read_offset
;
1364 so
.Stream3VertexReadLength
= urb_entry_read_length
- 1;
1366 #endif /* GEN_GEN >= 8 */
1371 struct GENX(SO_DECL
) so_decl
[MAX_XFB_STREAMS
][128];
1372 int next_offset
[MAX_XFB_BUFFERS
] = {0, 0, 0, 0};
1373 int decls
[MAX_XFB_STREAMS
] = {0, 0, 0, 0};
1375 memset(so_decl
, 0, sizeof(so_decl
));
1377 for (unsigned i
= 0; i
< xfb_info
->output_count
; i
++) {
1378 const nir_xfb_output_info
*output
= &xfb_info
->outputs
[i
];
1379 unsigned buffer
= output
->buffer
;
1380 unsigned stream
= xfb_info
->buffer_to_stream
[buffer
];
1382 /* Our hardware is unusual in that it requires us to program SO_DECLs
1383 * for fake "hole" components, rather than simply taking the offset
1384 * for each real varying. Each hole can have size 1, 2, 3, or 4; we
1385 * program as many size = 4 holes as we can, then a final hole to
1386 * accommodate the final 1, 2, or 3 remaining.
1388 int hole_dwords
= (output
->offset
- next_offset
[buffer
]) / 4;
1389 while (hole_dwords
> 0) {
1390 so_decl
[stream
][decls
[stream
]++] = (struct GENX(SO_DECL
)) {
1392 .OutputBufferSlot
= buffer
,
1393 .ComponentMask
= (1 << MIN2(hole_dwords
, 4)) - 1,
1398 int varying
= output
->location
;
1399 uint8_t component_mask
= output
->component_mask
;
1400 /* VARYING_SLOT_PSIZ contains three scalar fields packed together:
1401 * - VARYING_SLOT_LAYER in VARYING_SLOT_PSIZ.y
1402 * - VARYING_SLOT_VIEWPORT in VARYING_SLOT_PSIZ.z
1403 * - VARYING_SLOT_PSIZ in VARYING_SLOT_PSIZ.w
1405 if (varying
== VARYING_SLOT_LAYER
) {
1406 varying
= VARYING_SLOT_PSIZ
;
1407 component_mask
= 1 << 1; // SO_DECL_COMPMASK_Y
1408 } else if (varying
== VARYING_SLOT_VIEWPORT
) {
1409 varying
= VARYING_SLOT_PSIZ
;
1410 component_mask
= 1 << 2; // SO_DECL_COMPMASK_Z
1411 } else if (varying
== VARYING_SLOT_PSIZ
) {
1412 component_mask
= 1 << 3; // SO_DECL_COMPMASK_W
1415 next_offset
[buffer
] = output
->offset
+
1416 __builtin_popcount(component_mask
) * 4;
1418 so_decl
[stream
][decls
[stream
]++] = (struct GENX(SO_DECL
)) {
1419 .OutputBufferSlot
= buffer
,
1420 .RegisterIndex
= vue_map
->varying_to_slot
[varying
],
1421 .ComponentMask
= component_mask
,
1426 for (unsigned s
= 0; s
< MAX_XFB_STREAMS
; s
++)
1427 max_decls
= MAX2(max_decls
, decls
[s
]);
1429 uint8_t sbs
[MAX_XFB_STREAMS
] = { };
1430 for (unsigned b
= 0; b
< MAX_XFB_BUFFERS
; b
++) {
1431 if (xfb_info
->buffers_written
& (1 << b
))
1432 sbs
[xfb_info
->buffer_to_stream
[b
]] |= 1 << b
;
1435 uint32_t *dw
= anv_batch_emitn(&pipeline
->batch
, 3 + 2 * max_decls
,
1436 GENX(3DSTATE_SO_DECL_LIST
),
1437 .StreamtoBufferSelects0
= sbs
[0],
1438 .StreamtoBufferSelects1
= sbs
[1],
1439 .StreamtoBufferSelects2
= sbs
[2],
1440 .StreamtoBufferSelects3
= sbs
[3],
1441 .NumEntries0
= decls
[0],
1442 .NumEntries1
= decls
[1],
1443 .NumEntries2
= decls
[2],
1444 .NumEntries3
= decls
[3]);
1446 for (int i
= 0; i
< max_decls
; i
++) {
1447 GENX(SO_DECL_ENTRY_pack
)(NULL
, dw
+ 3 + i
* 2,
1448 &(struct GENX(SO_DECL_ENTRY
)) {
1449 .Stream0Decl
= so_decl
[0][i
],
1450 .Stream1Decl
= so_decl
[1][i
],
1451 .Stream2Decl
= so_decl
[2][i
],
1452 .Stream3Decl
= so_decl
[3][i
],
1456 #endif /* GEN_GEN >= 8 */
1460 get_sampler_count(const struct anv_shader_bin
*bin
)
1462 uint32_t count_by_4
= DIV_ROUND_UP(bin
->bind_map
.sampler_count
, 4);
1464 /* We can potentially have way more than 32 samplers and that's ok.
1465 * However, the 3DSTATE_XS packets only have 3 bits to specify how
1466 * many to pre-fetch and all values above 4 are marked reserved.
1468 return MIN2(count_by_4
, 4);
1472 get_binding_table_entry_count(const struct anv_shader_bin
*bin
)
1474 return DIV_ROUND_UP(bin
->bind_map
.surface_count
, 32);
1477 static struct anv_address
1478 get_scratch_address(struct anv_pipeline
*pipeline
,
1479 gl_shader_stage stage
,
1480 const struct anv_shader_bin
*bin
)
1482 return (struct anv_address
) {
1483 .bo
= anv_scratch_pool_alloc(pipeline
->device
,
1484 &pipeline
->device
->scratch_pool
,
1485 stage
, bin
->prog_data
->total_scratch
),
1491 get_scratch_space(const struct anv_shader_bin
*bin
)
1493 return ffs(bin
->prog_data
->total_scratch
/ 2048);
1497 emit_3dstate_vs(struct anv_pipeline
*pipeline
)
1499 const struct gen_device_info
*devinfo
= &pipeline
->device
->info
;
1500 const struct brw_vs_prog_data
*vs_prog_data
= get_vs_prog_data(pipeline
);
1501 const struct anv_shader_bin
*vs_bin
=
1502 pipeline
->shaders
[MESA_SHADER_VERTEX
];
1504 assert(anv_pipeline_has_stage(pipeline
, MESA_SHADER_VERTEX
));
1506 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VS
), vs
) {
1508 vs
.StatisticsEnable
= true;
1509 vs
.KernelStartPointer
= vs_bin
->kernel
.offset
;
1511 vs
.SIMD8DispatchEnable
=
1512 vs_prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
;
1515 assert(!vs_prog_data
->base
.base
.use_alt_mode
);
1517 vs
.SingleVertexDispatch
= false;
1519 vs
.VectorMaskEnable
= false;
1521 * Incorrect TDL's SSP address shift in SARB for 16:6 & 18:8 modes.
1522 * Disable the Sampler state prefetch functionality in the SARB by
1523 * programming 0xB000[30] to '1'.
1525 vs
.SamplerCount
= GEN_GEN
== 11 ? 0 : get_sampler_count(vs_bin
);
1526 /* Gen 11 workarounds table #2056 WABTPPrefetchDisable suggests to
1527 * disable prefetching of binding tables on A0 and B0 steppings.
1528 * TODO: Revisit this WA on newer steppings.
1530 vs
.BindingTableEntryCount
= GEN_GEN
== 11 ? 0 : get_binding_table_entry_count(vs_bin
);
1531 vs
.FloatingPointMode
= IEEE754
;
1532 vs
.IllegalOpcodeExceptionEnable
= false;
1533 vs
.SoftwareExceptionEnable
= false;
1534 vs
.MaximumNumberofThreads
= devinfo
->max_vs_threads
- 1;
1536 if (GEN_GEN
== 9 && devinfo
->gt
== 4 &&
1537 anv_pipeline_has_stage(pipeline
, MESA_SHADER_TESS_EVAL
)) {
1538 /* On Sky Lake GT4, we have experienced some hangs related to the VS
1539 * cache and tessellation. It is unknown exactly what is happening
1540 * but the Haswell docs for the "VS Reference Count Full Force Miss
1541 * Enable" field of the "Thread Mode" register refer to a HSW bug in
1542 * which the VUE handle reference count would overflow resulting in
1543 * internal reference counting bugs. My (Jason's) best guess is that
1544 * this bug cropped back up on SKL GT4 when we suddenly had more
1545 * threads in play than any previous gen9 hardware.
1547 * What we do know for sure is that setting this bit when
1548 * tessellation shaders are in use fixes a GPU hang in Batman: Arkham
1549 * City when playing with DXVK (https://bugs.freedesktop.org/107280).
1550 * Disabling the vertex cache with tessellation shaders should only
1551 * have a minor performance impact as the tessellation shaders are
1552 * likely generating and processing far more geometry than the vertex
1555 vs
.VertexCacheDisable
= true;
1558 vs
.VertexURBEntryReadLength
= vs_prog_data
->base
.urb_read_length
;
1559 vs
.VertexURBEntryReadOffset
= 0;
1560 vs
.DispatchGRFStartRegisterForURBData
=
1561 vs_prog_data
->base
.base
.dispatch_grf_start_reg
;
1564 vs
.UserClipDistanceClipTestEnableBitmask
=
1565 vs_prog_data
->base
.clip_distance_mask
;
1566 vs
.UserClipDistanceCullTestEnableBitmask
=
1567 vs_prog_data
->base
.cull_distance_mask
;
1570 vs
.PerThreadScratchSpace
= get_scratch_space(vs_bin
);
1571 vs
.ScratchSpaceBasePointer
=
1572 get_scratch_address(pipeline
, MESA_SHADER_VERTEX
, vs_bin
);
1577 emit_3dstate_hs_te_ds(struct anv_pipeline
*pipeline
,
1578 const VkPipelineTessellationStateCreateInfo
*tess_info
)
1580 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_TESS_EVAL
)) {
1581 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_HS
), hs
);
1582 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_TE
), te
);
1583 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_DS
), ds
);
1587 const struct gen_device_info
*devinfo
= &pipeline
->device
->info
;
1588 const struct anv_shader_bin
*tcs_bin
=
1589 pipeline
->shaders
[MESA_SHADER_TESS_CTRL
];
1590 const struct anv_shader_bin
*tes_bin
=
1591 pipeline
->shaders
[MESA_SHADER_TESS_EVAL
];
1593 const struct brw_tcs_prog_data
*tcs_prog_data
= get_tcs_prog_data(pipeline
);
1594 const struct brw_tes_prog_data
*tes_prog_data
= get_tes_prog_data(pipeline
);
1596 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_HS
), hs
) {
1598 hs
.StatisticsEnable
= true;
1599 hs
.KernelStartPointer
= tcs_bin
->kernel
.offset
;
1601 hs
.SamplerCount
= GEN_GEN
== 11 ? 0 : get_sampler_count(tcs_bin
);
1602 /* Gen 11 workarounds table #2056 WABTPPrefetchDisable */
1603 hs
.BindingTableEntryCount
= GEN_GEN
== 11 ? 0 : get_binding_table_entry_count(tcs_bin
);
1604 hs
.MaximumNumberofThreads
= devinfo
->max_tcs_threads
- 1;
1605 hs
.IncludeVertexHandles
= true;
1606 hs
.InstanceCount
= tcs_prog_data
->instances
- 1;
1608 hs
.VertexURBEntryReadLength
= 0;
1609 hs
.VertexURBEntryReadOffset
= 0;
1610 hs
.DispatchGRFStartRegisterForURBData
=
1611 tcs_prog_data
->base
.base
.dispatch_grf_start_reg
;
1613 hs
.PerThreadScratchSpace
= get_scratch_space(tcs_bin
);
1614 hs
.ScratchSpaceBasePointer
=
1615 get_scratch_address(pipeline
, MESA_SHADER_TESS_CTRL
, tcs_bin
);
1618 hs
.DispatchMode
= tcs_prog_data
->base
.dispatch_mode
;
1619 hs
.IncludePrimitiveID
= tcs_prog_data
->include_primitive_id
;
1623 const VkPipelineTessellationDomainOriginStateCreateInfo
*domain_origin_state
=
1624 tess_info
? vk_find_struct_const(tess_info
, PIPELINE_TESSELLATION_DOMAIN_ORIGIN_STATE_CREATE_INFO
) : NULL
;
1626 VkTessellationDomainOrigin uv_origin
=
1627 domain_origin_state
? domain_origin_state
->domainOrigin
:
1628 VK_TESSELLATION_DOMAIN_ORIGIN_UPPER_LEFT
;
1630 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_TE
), te
) {
1631 te
.Partitioning
= tes_prog_data
->partitioning
;
1633 if (uv_origin
== VK_TESSELLATION_DOMAIN_ORIGIN_LOWER_LEFT
) {
1634 te
.OutputTopology
= tes_prog_data
->output_topology
;
1636 /* When the origin is upper-left, we have to flip the winding order */
1637 if (tes_prog_data
->output_topology
== OUTPUT_TRI_CCW
) {
1638 te
.OutputTopology
= OUTPUT_TRI_CW
;
1639 } else if (tes_prog_data
->output_topology
== OUTPUT_TRI_CW
) {
1640 te
.OutputTopology
= OUTPUT_TRI_CCW
;
1642 te
.OutputTopology
= tes_prog_data
->output_topology
;
1646 te
.TEDomain
= tes_prog_data
->domain
;
1648 te
.MaximumTessellationFactorOdd
= 63.0;
1649 te
.MaximumTessellationFactorNotOdd
= 64.0;
1652 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_DS
), ds
) {
1654 ds
.StatisticsEnable
= true;
1655 ds
.KernelStartPointer
= tes_bin
->kernel
.offset
;
1657 ds
.SamplerCount
= GEN_GEN
== 11 ? 0 : get_sampler_count(tes_bin
);
1658 /* Gen 11 workarounds table #2056 WABTPPrefetchDisable */
1659 ds
.BindingTableEntryCount
= GEN_GEN
== 11 ? 0 : get_binding_table_entry_count(tes_bin
);
1660 ds
.MaximumNumberofThreads
= devinfo
->max_tes_threads
- 1;
1662 ds
.ComputeWCoordinateEnable
=
1663 tes_prog_data
->domain
== BRW_TESS_DOMAIN_TRI
;
1665 ds
.PatchURBEntryReadLength
= tes_prog_data
->base
.urb_read_length
;
1666 ds
.PatchURBEntryReadOffset
= 0;
1667 ds
.DispatchGRFStartRegisterForURBData
=
1668 tes_prog_data
->base
.base
.dispatch_grf_start_reg
;
1673 tes_prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
?
1674 DISPATCH_MODE_SIMD8_SINGLE_PATCH
:
1675 DISPATCH_MODE_SIMD4X2
;
1677 assert(tes_prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
);
1678 ds
.DispatchMode
= DISPATCH_MODE_SIMD8_SINGLE_PATCH
;
1681 ds
.UserClipDistanceClipTestEnableBitmask
=
1682 tes_prog_data
->base
.clip_distance_mask
;
1683 ds
.UserClipDistanceCullTestEnableBitmask
=
1684 tes_prog_data
->base
.cull_distance_mask
;
1687 ds
.PerThreadScratchSpace
= get_scratch_space(tes_bin
);
1688 ds
.ScratchSpaceBasePointer
=
1689 get_scratch_address(pipeline
, MESA_SHADER_TESS_EVAL
, tes_bin
);
1694 emit_3dstate_gs(struct anv_pipeline
*pipeline
)
1696 const struct gen_device_info
*devinfo
= &pipeline
->device
->info
;
1697 const struct anv_shader_bin
*gs_bin
=
1698 pipeline
->shaders
[MESA_SHADER_GEOMETRY
];
1700 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_GEOMETRY
)) {
1701 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_GS
), gs
);
1705 const struct brw_gs_prog_data
*gs_prog_data
= get_gs_prog_data(pipeline
);
1707 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_GS
), gs
) {
1709 gs
.StatisticsEnable
= true;
1710 gs
.KernelStartPointer
= gs_bin
->kernel
.offset
;
1711 gs
.DispatchMode
= gs_prog_data
->base
.dispatch_mode
;
1713 gs
.SingleProgramFlow
= false;
1714 gs
.VectorMaskEnable
= false;
1716 gs
.SamplerCount
= GEN_GEN
== 11 ? 0 : get_sampler_count(gs_bin
);
1717 /* Gen 11 workarounds table #2056 WABTPPrefetchDisable */
1718 gs
.BindingTableEntryCount
= GEN_GEN
== 11 ? 0 : get_binding_table_entry_count(gs_bin
);
1719 gs
.IncludeVertexHandles
= gs_prog_data
->base
.include_vue_handles
;
1720 gs
.IncludePrimitiveID
= gs_prog_data
->include_primitive_id
;
1723 /* Broadwell is weird. It needs us to divide by 2. */
1724 gs
.MaximumNumberofThreads
= devinfo
->max_gs_threads
/ 2 - 1;
1726 gs
.MaximumNumberofThreads
= devinfo
->max_gs_threads
- 1;
1729 gs
.OutputVertexSize
= gs_prog_data
->output_vertex_size_hwords
* 2 - 1;
1730 gs
.OutputTopology
= gs_prog_data
->output_topology
;
1731 gs
.VertexURBEntryReadLength
= gs_prog_data
->base
.urb_read_length
;
1732 gs
.ControlDataFormat
= gs_prog_data
->control_data_format
;
1733 gs
.ControlDataHeaderSize
= gs_prog_data
->control_data_header_size_hwords
;
1734 gs
.InstanceControl
= MAX2(gs_prog_data
->invocations
, 1) - 1;
1735 gs
.ReorderMode
= TRAILING
;
1738 gs
.ExpectedVertexCount
= gs_prog_data
->vertices_in
;
1739 gs
.StaticOutput
= gs_prog_data
->static_vertex_count
>= 0;
1740 gs
.StaticOutputVertexCount
= gs_prog_data
->static_vertex_count
>= 0 ?
1741 gs_prog_data
->static_vertex_count
: 0;
1744 gs
.VertexURBEntryReadOffset
= 0;
1745 gs
.VertexURBEntryReadLength
= gs_prog_data
->base
.urb_read_length
;
1746 gs
.DispatchGRFStartRegisterForURBData
=
1747 gs_prog_data
->base
.base
.dispatch_grf_start_reg
;
1750 gs
.UserClipDistanceClipTestEnableBitmask
=
1751 gs_prog_data
->base
.clip_distance_mask
;
1752 gs
.UserClipDistanceCullTestEnableBitmask
=
1753 gs_prog_data
->base
.cull_distance_mask
;
1756 gs
.PerThreadScratchSpace
= get_scratch_space(gs_bin
);
1757 gs
.ScratchSpaceBasePointer
=
1758 get_scratch_address(pipeline
, MESA_SHADER_GEOMETRY
, gs_bin
);
1763 has_color_buffer_write_enabled(const struct anv_pipeline
*pipeline
,
1764 const VkPipelineColorBlendStateCreateInfo
*blend
)
1766 const struct anv_shader_bin
*shader_bin
=
1767 pipeline
->shaders
[MESA_SHADER_FRAGMENT
];
1771 const struct anv_pipeline_bind_map
*bind_map
= &shader_bin
->bind_map
;
1772 for (int i
= 0; i
< bind_map
->surface_count
; i
++) {
1773 struct anv_pipeline_binding
*binding
= &bind_map
->surface_to_descriptor
[i
];
1775 if (binding
->set
!= ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS
)
1778 if (binding
->index
== UINT32_MAX
)
1781 if (blend
&& blend
->pAttachments
[binding
->index
].colorWriteMask
!= 0)
1789 emit_3dstate_wm(struct anv_pipeline
*pipeline
, struct anv_subpass
*subpass
,
1790 const VkPipelineInputAssemblyStateCreateInfo
*ia
,
1791 const VkPipelineRasterizationStateCreateInfo
*raster
,
1792 const VkPipelineColorBlendStateCreateInfo
*blend
,
1793 const VkPipelineMultisampleStateCreateInfo
*multisample
,
1794 const VkPipelineRasterizationLineStateCreateInfoEXT
*line
)
1796 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
1798 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_WM
), wm
) {
1799 wm
.StatisticsEnable
= true;
1800 wm
.LineEndCapAntialiasingRegionWidth
= _05pixels
;
1801 wm
.LineAntialiasingRegionWidth
= _10pixels
;
1802 wm
.PointRasterizationRule
= RASTRULE_UPPER_RIGHT
;
1804 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
1805 if (wm_prog_data
->early_fragment_tests
) {
1806 wm
.EarlyDepthStencilControl
= EDSC_PREPS
;
1807 } else if (wm_prog_data
->has_side_effects
) {
1808 wm
.EarlyDepthStencilControl
= EDSC_PSEXEC
;
1810 wm
.EarlyDepthStencilControl
= EDSC_NORMAL
;
1814 /* Gen8 hardware tries to compute ThreadDispatchEnable for us but
1815 * doesn't take into account KillPixels when no depth or stencil
1816 * writes are enabled. In order for occlusion queries to work
1817 * correctly with no attachments, we need to force-enable PS thread
1820 * The BDW docs are pretty clear that that this bit isn't validated
1821 * and probably shouldn't be used in production:
1823 * "This must always be set to Normal. This field should not be
1824 * tested for functional validation."
1826 * Unfortunately, however, the other mechanism we have for doing this
1827 * is 3DSTATE_PS_EXTRA::PixelShaderHasUAV which causes hangs on BDW.
1828 * Given two bad options, we choose the one which works.
1830 if ((wm_prog_data
->has_side_effects
|| wm_prog_data
->uses_kill
) &&
1831 !has_color_buffer_write_enabled(pipeline
, blend
))
1832 wm
.ForceThreadDispatchEnable
= ForceON
;
1835 wm
.BarycentricInterpolationMode
=
1836 wm_prog_data
->barycentric_interp_modes
;
1839 wm
.PixelShaderComputedDepthMode
= wm_prog_data
->computed_depth_mode
;
1840 wm
.PixelShaderUsesSourceDepth
= wm_prog_data
->uses_src_depth
;
1841 wm
.PixelShaderUsesSourceW
= wm_prog_data
->uses_src_w
;
1842 wm
.PixelShaderUsesInputCoverageMask
= wm_prog_data
->uses_sample_mask
;
1844 /* If the subpass has a depth or stencil self-dependency, then we
1845 * need to force the hardware to do the depth/stencil write *after*
1846 * fragment shader execution. Otherwise, the writes may hit memory
1847 * before we get around to fetching from the input attachment and we
1848 * may get the depth or stencil value from the current draw rather
1849 * than the previous one.
1851 wm
.PixelShaderKillsPixel
= subpass
->has_ds_self_dep
||
1852 wm_prog_data
->uses_kill
;
1854 if (wm
.PixelShaderComputedDepthMode
!= PSCDEPTH_OFF
||
1855 wm_prog_data
->has_side_effects
||
1856 wm
.PixelShaderKillsPixel
||
1857 has_color_buffer_write_enabled(pipeline
, blend
))
1858 wm
.ThreadDispatchEnable
= true;
1860 if (multisample
&& multisample
->rasterizationSamples
> 1) {
1861 if (wm_prog_data
->persample_dispatch
) {
1862 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
1864 wm
.MultisampleDispatchMode
= MSDISPMODE_PERPIXEL
;
1867 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
1869 wm
.MultisampleRasterizationMode
=
1870 gen7_ms_rast_mode(pipeline
, ia
, raster
, multisample
);
1873 wm
.LineStippleEnable
= line
&& line
->stippledLineEnable
;
1879 emit_3dstate_ps(struct anv_pipeline
*pipeline
,
1880 const VkPipelineColorBlendStateCreateInfo
*blend
,
1881 const VkPipelineMultisampleStateCreateInfo
*multisample
)
1883 UNUSED
const struct gen_device_info
*devinfo
= &pipeline
->device
->info
;
1884 const struct anv_shader_bin
*fs_bin
=
1885 pipeline
->shaders
[MESA_SHADER_FRAGMENT
];
1887 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
1888 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS
), ps
) {
1890 /* Even if no fragments are ever dispatched, gen7 hardware hangs if
1891 * we don't at least set the maximum number of threads.
1893 ps
.MaximumNumberofThreads
= devinfo
->max_wm_threads
- 1;
1899 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
1902 /* The hardware wedges if you have this bit set but don't turn on any dual
1903 * source blend factors.
1905 bool dual_src_blend
= false;
1906 if (wm_prog_data
->dual_src_blend
&& blend
) {
1907 for (uint32_t i
= 0; i
< blend
->attachmentCount
; i
++) {
1908 const VkPipelineColorBlendAttachmentState
*bstate
=
1909 &blend
->pAttachments
[i
];
1911 if (bstate
->blendEnable
&&
1912 (is_dual_src_blend_factor(bstate
->srcColorBlendFactor
) ||
1913 is_dual_src_blend_factor(bstate
->dstColorBlendFactor
) ||
1914 is_dual_src_blend_factor(bstate
->srcAlphaBlendFactor
) ||
1915 is_dual_src_blend_factor(bstate
->dstAlphaBlendFactor
))) {
1916 dual_src_blend
= true;
1923 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS
), ps
) {
1924 ps
._8PixelDispatchEnable
= wm_prog_data
->dispatch_8
;
1925 ps
._16PixelDispatchEnable
= wm_prog_data
->dispatch_16
;
1926 ps
._32PixelDispatchEnable
= wm_prog_data
->dispatch_32
;
1928 /* From the Sky Lake PRM 3DSTATE_PS::32 Pixel Dispatch Enable:
1930 * "When NUM_MULTISAMPLES = 16 or FORCE_SAMPLE_COUNT = 16, SIMD32
1931 * Dispatch must not be enabled for PER_PIXEL dispatch mode."
1933 * Since 16x MSAA is first introduced on SKL, we don't need to apply
1934 * the workaround on any older hardware.
1936 if (GEN_GEN
>= 9 && !wm_prog_data
->persample_dispatch
&&
1937 multisample
&& multisample
->rasterizationSamples
== 16) {
1938 assert(ps
._8PixelDispatchEnable
|| ps
._16PixelDispatchEnable
);
1939 ps
._32PixelDispatchEnable
= false;
1942 ps
.KernelStartPointer0
= fs_bin
->kernel
.offset
+
1943 brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 0);
1944 ps
.KernelStartPointer1
= fs_bin
->kernel
.offset
+
1945 brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 1);
1946 ps
.KernelStartPointer2
= fs_bin
->kernel
.offset
+
1947 brw_wm_prog_data_prog_offset(wm_prog_data
, ps
, 2);
1949 ps
.SingleProgramFlow
= false;
1950 ps
.VectorMaskEnable
= GEN_GEN
>= 8;
1952 ps
.SamplerCount
= GEN_GEN
== 11 ? 0 : get_sampler_count(fs_bin
);
1953 /* Gen 11 workarounds table #2056 WABTPPrefetchDisable */
1954 ps
.BindingTableEntryCount
= GEN_GEN
== 11 ? 0 : get_binding_table_entry_count(fs_bin
);
1955 ps
.PushConstantEnable
= wm_prog_data
->base
.nr_params
> 0 ||
1956 wm_prog_data
->base
.ubo_ranges
[0].length
;
1957 ps
.PositionXYOffsetSelect
= wm_prog_data
->uses_pos_offset
?
1958 POSOFFSET_SAMPLE
: POSOFFSET_NONE
;
1960 ps
.AttributeEnable
= wm_prog_data
->num_varying_inputs
> 0;
1961 ps
.oMaskPresenttoRenderTarget
= wm_prog_data
->uses_omask
;
1962 ps
.DualSourceBlendEnable
= dual_src_blend
;
1966 /* Haswell requires the sample mask to be set in this packet as well
1967 * as in 3DSTATE_SAMPLE_MASK; the values should match.
1969 ps
.SampleMask
= 0xff;
1973 ps
.MaximumNumberofThreadsPerPSD
= 64 - 1;
1975 ps
.MaximumNumberofThreadsPerPSD
= 64 - 2;
1977 ps
.MaximumNumberofThreads
= devinfo
->max_wm_threads
- 1;
1980 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
1981 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 0);
1982 ps
.DispatchGRFStartRegisterForConstantSetupData1
=
1983 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 1);
1984 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
1985 brw_wm_prog_data_dispatch_grf_start_reg(wm_prog_data
, ps
, 2);
1987 ps
.PerThreadScratchSpace
= get_scratch_space(fs_bin
);
1988 ps
.ScratchSpaceBasePointer
=
1989 get_scratch_address(pipeline
, MESA_SHADER_FRAGMENT
, fs_bin
);
1995 emit_3dstate_ps_extra(struct anv_pipeline
*pipeline
,
1996 struct anv_subpass
*subpass
,
1997 const VkPipelineColorBlendStateCreateInfo
*blend
)
1999 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
2001 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
2002 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS_EXTRA
), ps
);
2006 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS_EXTRA
), ps
) {
2007 ps
.PixelShaderValid
= true;
2008 ps
.AttributeEnable
= wm_prog_data
->num_varying_inputs
> 0;
2009 ps
.oMaskPresenttoRenderTarget
= wm_prog_data
->uses_omask
;
2010 ps
.PixelShaderIsPerSample
= wm_prog_data
->persample_dispatch
;
2011 ps
.PixelShaderComputedDepthMode
= wm_prog_data
->computed_depth_mode
;
2012 ps
.PixelShaderUsesSourceDepth
= wm_prog_data
->uses_src_depth
;
2013 ps
.PixelShaderUsesSourceW
= wm_prog_data
->uses_src_w
;
2015 /* If the subpass has a depth or stencil self-dependency, then we need
2016 * to force the hardware to do the depth/stencil write *after* fragment
2017 * shader execution. Otherwise, the writes may hit memory before we get
2018 * around to fetching from the input attachment and we may get the depth
2019 * or stencil value from the current draw rather than the previous one.
2021 ps
.PixelShaderKillsPixel
= subpass
->has_ds_self_dep
||
2022 wm_prog_data
->uses_kill
;
2025 ps
.PixelShaderComputesStencil
= wm_prog_data
->computed_stencil
;
2026 ps
.PixelShaderPullsBary
= wm_prog_data
->pulls_bary
;
2028 ps
.InputCoverageMaskState
= ICMS_NONE
;
2029 if (wm_prog_data
->uses_sample_mask
) {
2030 if (wm_prog_data
->post_depth_coverage
)
2031 ps
.InputCoverageMaskState
= ICMS_DEPTH_COVERAGE
;
2033 ps
.InputCoverageMaskState
= ICMS_INNER_CONSERVATIVE
;
2036 ps
.PixelShaderUsesInputCoverageMask
= wm_prog_data
->uses_sample_mask
;
2042 emit_3dstate_vf_topology(struct anv_pipeline
*pipeline
)
2044 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VF_TOPOLOGY
), vft
) {
2045 vft
.PrimitiveTopologyType
= pipeline
->topology
;
2051 emit_3dstate_vf_statistics(struct anv_pipeline
*pipeline
)
2053 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VF_STATISTICS
), vfs
) {
2054 vfs
.StatisticsEnable
= true;
2059 compute_kill_pixel(struct anv_pipeline
*pipeline
,
2060 const VkPipelineMultisampleStateCreateInfo
*ms_info
,
2061 const struct anv_subpass
*subpass
)
2063 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
2064 pipeline
->kill_pixel
= false;
2068 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
2070 /* This computes the KillPixel portion of the computation for whether or
2071 * not we want to enable the PMA fix on gen8 or gen9. It's given by this
2072 * chunk of the giant formula:
2074 * (3DSTATE_PS_EXTRA::PixelShaderKillsPixels ||
2075 * 3DSTATE_PS_EXTRA::oMask Present to RenderTarget ||
2076 * 3DSTATE_PS_BLEND::AlphaToCoverageEnable ||
2077 * 3DSTATE_PS_BLEND::AlphaTestEnable ||
2078 * 3DSTATE_WM_CHROMAKEY::ChromaKeyKillEnable)
2080 * 3DSTATE_WM_CHROMAKEY::ChromaKeyKillEnable is always false and so is
2081 * 3DSTATE_PS_BLEND::AlphaTestEnable since Vulkan doesn't have a concept
2084 pipeline
->kill_pixel
=
2085 subpass
->has_ds_self_dep
|| wm_prog_data
->uses_kill
||
2086 wm_prog_data
->uses_omask
||
2087 (ms_info
&& ms_info
->alphaToCoverageEnable
);
2091 genX(graphics_pipeline_create
)(
2093 struct anv_pipeline_cache
* cache
,
2094 const VkGraphicsPipelineCreateInfo
* pCreateInfo
,
2095 const VkAllocationCallbacks
* pAllocator
,
2096 VkPipeline
* pPipeline
)
2098 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2099 ANV_FROM_HANDLE(anv_render_pass
, pass
, pCreateInfo
->renderPass
);
2100 struct anv_subpass
*subpass
= &pass
->subpasses
[pCreateInfo
->subpass
];
2101 struct anv_pipeline
*pipeline
;
2104 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
);
2106 /* Use the default pipeline cache if none is specified */
2107 if (cache
== NULL
&& device
->instance
->pipeline_cache_enabled
)
2108 cache
= &device
->default_pipeline_cache
;
2110 pipeline
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*pipeline
), 8,
2111 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2112 if (pipeline
== NULL
)
2113 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2115 result
= anv_pipeline_init(pipeline
, device
, cache
,
2116 pCreateInfo
, pAllocator
);
2117 if (result
!= VK_SUCCESS
) {
2118 vk_free2(&device
->alloc
, pAllocator
, pipeline
);
2122 const VkPipelineRasterizationLineStateCreateInfoEXT
*line_info
=
2123 vk_find_struct_const(pCreateInfo
->pRasterizationState
->pNext
,
2124 PIPELINE_RASTERIZATION_LINE_STATE_CREATE_INFO_EXT
);
2126 assert(pCreateInfo
->pVertexInputState
);
2127 emit_vertex_input(pipeline
, pCreateInfo
->pVertexInputState
);
2128 assert(pCreateInfo
->pRasterizationState
);
2129 emit_rs_state(pipeline
, pCreateInfo
->pInputAssemblyState
,
2130 pCreateInfo
->pRasterizationState
,
2131 pCreateInfo
->pMultisampleState
,
2132 line_info
, pass
, subpass
);
2133 emit_ms_state(pipeline
, pCreateInfo
->pMultisampleState
);
2134 emit_ds_state(pipeline
, pCreateInfo
->pDepthStencilState
, pass
, subpass
);
2135 emit_cb_state(pipeline
, pCreateInfo
->pColorBlendState
,
2136 pCreateInfo
->pMultisampleState
);
2137 compute_kill_pixel(pipeline
, pCreateInfo
->pMultisampleState
, subpass
);
2139 emit_urb_setup(pipeline
);
2141 emit_3dstate_clip(pipeline
,
2142 pCreateInfo
->pInputAssemblyState
,
2143 pCreateInfo
->pViewportState
,
2144 pCreateInfo
->pRasterizationState
);
2145 emit_3dstate_streamout(pipeline
, pCreateInfo
->pRasterizationState
);
2148 /* From gen7_vs_state.c */
2151 * From Graphics BSpec: 3D-Media-GPGPU Engine > 3D Pipeline Stages >
2152 * Geometry > Geometry Shader > State:
2154 * "Note: Because of corruption in IVB:GT2, software needs to flush the
2155 * whole fixed function pipeline when the GS enable changes value in
2158 * The hardware architects have clarified that in this context "flush the
2159 * whole fixed function pipeline" means to emit a PIPE_CONTROL with the "CS
2162 if (!device
->info
.is_haswell
&& !device
->info
.is_baytrail
)
2163 gen7_emit_vs_workaround_flush(brw
);
2166 emit_3dstate_vs(pipeline
);
2167 emit_3dstate_hs_te_ds(pipeline
, pCreateInfo
->pTessellationState
);
2168 emit_3dstate_gs(pipeline
);
2169 emit_3dstate_sbe(pipeline
);
2170 emit_3dstate_wm(pipeline
, subpass
,
2171 pCreateInfo
->pInputAssemblyState
,
2172 pCreateInfo
->pRasterizationState
,
2173 pCreateInfo
->pColorBlendState
,
2174 pCreateInfo
->pMultisampleState
, line_info
);
2175 emit_3dstate_ps(pipeline
, pCreateInfo
->pColorBlendState
,
2176 pCreateInfo
->pMultisampleState
);
2178 emit_3dstate_ps_extra(pipeline
, subpass
, pCreateInfo
->pColorBlendState
);
2179 emit_3dstate_vf_topology(pipeline
);
2181 emit_3dstate_vf_statistics(pipeline
);
2183 *pPipeline
= anv_pipeline_to_handle(pipeline
);
2185 return pipeline
->batch
.status
;
2189 compute_pipeline_create(
2191 struct anv_pipeline_cache
* cache
,
2192 const VkComputePipelineCreateInfo
* pCreateInfo
,
2193 const VkAllocationCallbacks
* pAllocator
,
2194 VkPipeline
* pPipeline
)
2196 ANV_FROM_HANDLE(anv_device
, device
, _device
);
2197 const struct anv_physical_device
*physical_device
=
2198 &device
->instance
->physicalDevice
;
2199 const struct gen_device_info
*devinfo
= &physical_device
->info
;
2200 struct anv_pipeline
*pipeline
;
2203 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO
);
2205 /* Use the default pipeline cache if none is specified */
2206 if (cache
== NULL
&& device
->instance
->pipeline_cache_enabled
)
2207 cache
= &device
->default_pipeline_cache
;
2209 pipeline
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*pipeline
), 8,
2210 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
2211 if (pipeline
== NULL
)
2212 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
2214 pipeline
->device
= device
;
2216 pipeline
->blend_state
.map
= NULL
;
2218 result
= anv_reloc_list_init(&pipeline
->batch_relocs
,
2219 pAllocator
? pAllocator
: &device
->alloc
);
2220 if (result
!= VK_SUCCESS
) {
2221 vk_free2(&device
->alloc
, pAllocator
, pipeline
);
2224 pipeline
->batch
.next
= pipeline
->batch
.start
= pipeline
->batch_data
;
2225 pipeline
->batch
.end
= pipeline
->batch
.start
+ sizeof(pipeline
->batch_data
);
2226 pipeline
->batch
.relocs
= &pipeline
->batch_relocs
;
2227 pipeline
->batch
.status
= VK_SUCCESS
;
2229 pipeline
->mem_ctx
= ralloc_context(NULL
);
2230 pipeline
->flags
= pCreateInfo
->flags
;
2232 /* When we free the pipeline, we detect stages based on the NULL status
2233 * of various prog_data pointers. Make them NULL by default.
2235 memset(pipeline
->shaders
, 0, sizeof(pipeline
->shaders
));
2236 pipeline
->num_executables
= 0;
2238 pipeline
->needs_data_cache
= false;
2240 assert(pCreateInfo
->stage
.stage
== VK_SHADER_STAGE_COMPUTE_BIT
);
2241 pipeline
->active_stages
|= VK_SHADER_STAGE_COMPUTE_BIT
;
2242 ANV_FROM_HANDLE(anv_shader_module
, module
, pCreateInfo
->stage
.module
);
2243 result
= anv_pipeline_compile_cs(pipeline
, cache
, pCreateInfo
, module
,
2244 pCreateInfo
->stage
.pName
,
2245 pCreateInfo
->stage
.pSpecializationInfo
);
2246 if (result
!= VK_SUCCESS
) {
2247 ralloc_free(pipeline
->mem_ctx
);
2248 vk_free2(&device
->alloc
, pAllocator
, pipeline
);
2252 const struct brw_cs_prog_data
*cs_prog_data
= get_cs_prog_data(pipeline
);
2254 anv_pipeline_setup_l3_config(pipeline
, cs_prog_data
->base
.total_shared
> 0);
2256 uint32_t group_size
= cs_prog_data
->local_size
[0] *
2257 cs_prog_data
->local_size
[1] * cs_prog_data
->local_size
[2];
2258 uint32_t remainder
= group_size
& (cs_prog_data
->simd_size
- 1);
2261 pipeline
->cs_right_mask
= ~0u >> (32 - remainder
);
2263 pipeline
->cs_right_mask
= ~0u >> (32 - cs_prog_data
->simd_size
);
2265 const uint32_t vfe_curbe_allocation
=
2266 ALIGN(cs_prog_data
->push
.per_thread
.regs
* cs_prog_data
->threads
+
2267 cs_prog_data
->push
.cross_thread
.regs
, 2);
2269 const uint32_t subslices
= MAX2(physical_device
->subslice_total
, 1);
2271 const struct anv_shader_bin
*cs_bin
=
2272 pipeline
->shaders
[MESA_SHADER_COMPUTE
];
2274 anv_batch_emit(&pipeline
->batch
, GENX(MEDIA_VFE_STATE
), vfe
) {
2278 vfe
.GPGPUMode
= true;
2280 vfe
.MaximumNumberofThreads
=
2281 devinfo
->max_cs_threads
* subslices
- 1;
2282 vfe
.NumberofURBEntries
= GEN_GEN
<= 7 ? 0 : 2;
2284 vfe
.ResetGatewayTimer
= true;
2287 vfe
.BypassGatewayControl
= true;
2289 vfe
.URBEntryAllocationSize
= GEN_GEN
<= 7 ? 0 : 2;
2290 vfe
.CURBEAllocationSize
= vfe_curbe_allocation
;
2292 if (cs_bin
->prog_data
->total_scratch
) {
2294 /* Broadwell's Per Thread Scratch Space is in the range [0, 11]
2295 * where 0 = 1k, 1 = 2k, 2 = 4k, ..., 11 = 2M.
2297 vfe
.PerThreadScratchSpace
=
2298 ffs(cs_bin
->prog_data
->total_scratch
) - 11;
2299 } else if (GEN_IS_HASWELL
) {
2300 /* Haswell's Per Thread Scratch Space is in the range [0, 10]
2301 * where 0 = 2k, 1 = 4k, 2 = 8k, ..., 10 = 2M.
2303 vfe
.PerThreadScratchSpace
=
2304 ffs(cs_bin
->prog_data
->total_scratch
) - 12;
2306 /* IVB and BYT use the range [0, 11] to mean [1kB, 12kB]
2307 * where 0 = 1kB, 1 = 2kB, 2 = 3kB, ..., 11 = 12kB.
2309 vfe
.PerThreadScratchSpace
=
2310 cs_bin
->prog_data
->total_scratch
/ 1024 - 1;
2312 vfe
.ScratchSpaceBasePointer
=
2313 get_scratch_address(pipeline
, MESA_SHADER_COMPUTE
, cs_bin
);
2317 struct GENX(INTERFACE_DESCRIPTOR_DATA
) desc
= {
2318 .KernelStartPointer
= cs_bin
->kernel
.offset
,
2320 .SamplerCount
= GEN_GEN
== 11 ? 0 : get_sampler_count(cs_bin
),
2321 /* Gen 11 workarounds table #2056 WABTPPrefetchDisable
2323 * We add 1 because the CS indirect parameters buffer isn't accounted
2324 * for in bind_map.surface_count.
2326 .BindingTableEntryCount
= GEN_GEN
== 11 ? 0 : 1 + MIN2(cs_bin
->bind_map
.surface_count
, 30),
2327 .BarrierEnable
= cs_prog_data
->uses_barrier
,
2328 .SharedLocalMemorySize
=
2329 encode_slm_size(GEN_GEN
, cs_prog_data
->base
.total_shared
),
2332 .ConstantURBEntryReadOffset
= 0,
2334 .ConstantURBEntryReadLength
= cs_prog_data
->push
.per_thread
.regs
,
2335 #if GEN_GEN >= 8 || GEN_IS_HASWELL
2336 .CrossThreadConstantDataReadLength
=
2337 cs_prog_data
->push
.cross_thread
.regs
,
2340 .NumberofThreadsinGPGPUThreadGroup
= cs_prog_data
->threads
,
2342 GENX(INTERFACE_DESCRIPTOR_DATA_pack
)(NULL
,
2343 pipeline
->interface_descriptor_data
,
2346 *pPipeline
= anv_pipeline_to_handle(pipeline
);
2348 return pipeline
->batch
.status
;
2351 VkResult
genX(CreateGraphicsPipelines
)(
2353 VkPipelineCache pipelineCache
,
2355 const VkGraphicsPipelineCreateInfo
* pCreateInfos
,
2356 const VkAllocationCallbacks
* pAllocator
,
2357 VkPipeline
* pPipelines
)
2359 ANV_FROM_HANDLE(anv_pipeline_cache
, pipeline_cache
, pipelineCache
);
2361 VkResult result
= VK_SUCCESS
;
2364 for (i
= 0; i
< count
; i
++) {
2365 result
= genX(graphics_pipeline_create
)(_device
,
2368 pAllocator
, &pPipelines
[i
]);
2370 /* Bail out on the first error as it is not obvious what error should be
2371 * report upon 2 different failures. */
2372 if (result
!= VK_SUCCESS
)
2376 for (; i
< count
; i
++)
2377 pPipelines
[i
] = VK_NULL_HANDLE
;
2382 VkResult
genX(CreateComputePipelines
)(
2384 VkPipelineCache pipelineCache
,
2386 const VkComputePipelineCreateInfo
* pCreateInfos
,
2387 const VkAllocationCallbacks
* pAllocator
,
2388 VkPipeline
* pPipelines
)
2390 ANV_FROM_HANDLE(anv_pipeline_cache
, pipeline_cache
, pipelineCache
);
2392 VkResult result
= VK_SUCCESS
;
2395 for (i
= 0; i
< count
; i
++) {
2396 result
= compute_pipeline_create(_device
, pipeline_cache
,
2398 pAllocator
, &pPipelines
[i
]);
2400 /* Bail out on the first error as it is not obvious what error should be
2401 * report upon 2 different failures. */
2402 if (result
!= VK_SUCCESS
)
2406 for (; i
< count
; i
++)
2407 pPipelines
[i
] = VK_NULL_HANDLE
;