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 "vk_format_info.h"
34 vertex_element_comp_control(enum isl_format format
, unsigned comp
)
38 case 0: bits
= isl_format_layouts
[format
].channels
.r
.bits
; break;
39 case 1: bits
= isl_format_layouts
[format
].channels
.g
.bits
; break;
40 case 2: bits
= isl_format_layouts
[format
].channels
.b
.bits
; break;
41 case 3: bits
= isl_format_layouts
[format
].channels
.a
.bits
; break;
42 default: unreachable("Invalid component");
46 * Take in account hardware restrictions when dealing with 64-bit floats.
48 * From Broadwell spec, command reference structures, page 586:
49 * "When SourceElementFormat is set to one of the *64*_PASSTHRU formats,
50 * 64-bit components are stored * in the URB without any conversion. In
51 * this case, vertex elements must be written as 128 or 256 bits, with
52 * VFCOMP_STORE_0 being used to pad the output as required. E.g., if
53 * R64_PASSTHRU is used to copy a 64-bit Red component into the URB,
54 * Component 1 must be specified as VFCOMP_STORE_0 (with Components 2,3
55 * set to VFCOMP_NOSTORE) in order to output a 128-bit vertex element, or
56 * Components 1-3 must be specified as VFCOMP_STORE_0 in order to output
57 * a 256-bit vertex element. Likewise, use of R64G64B64_PASSTHRU requires
58 * Component 3 to be specified as VFCOMP_STORE_0 in order to output a
59 * 256-bit vertex element."
62 return VFCOMP_STORE_SRC
;
63 } else if (comp
>= 2 &&
64 !isl_format_layouts
[format
].channels
.b
.bits
&&
65 isl_format_layouts
[format
].channels
.r
.type
== ISL_RAW
) {
66 /* When emitting 64-bit attributes, we need to write either 128 or 256
67 * bit chunks, using VFCOMP_NOSTORE when not writing the chunk, and
68 * VFCOMP_STORE_0 to pad the written chunk */
69 return VFCOMP_NOSTORE
;
70 } else if (comp
< 3 ||
71 isl_format_layouts
[format
].channels
.r
.type
== ISL_RAW
) {
72 /* Note we need to pad with value 0, not 1, due hardware restrictions
73 * (see comment above) */
74 return VFCOMP_STORE_0
;
75 } else if (isl_format_layouts
[format
].channels
.r
.type
== ISL_UINT
||
76 isl_format_layouts
[format
].channels
.r
.type
== ISL_SINT
) {
78 return VFCOMP_STORE_1_INT
;
81 return VFCOMP_STORE_1_FP
;
86 emit_vertex_input(struct anv_pipeline
*pipeline
,
87 const VkPipelineVertexInputStateCreateInfo
*info
)
89 const struct brw_vs_prog_data
*vs_prog_data
= get_vs_prog_data(pipeline
);
91 /* Pull inputs_read out of the VS prog data */
92 const uint64_t inputs_read
= vs_prog_data
->inputs_read
;
93 const uint64_t double_inputs_read
= vs_prog_data
->double_inputs_read
;
94 assert((inputs_read
& ((1 << VERT_ATTRIB_GENERIC0
) - 1)) == 0);
95 const uint32_t elements
= inputs_read
>> VERT_ATTRIB_GENERIC0
;
96 const uint32_t elements_double
= double_inputs_read
>> VERT_ATTRIB_GENERIC0
;
99 /* On BDW+, we only need to allocate space for base ids. Setting up
100 * the actual vertex and instance id is a separate packet.
102 const bool needs_svgs_elem
= vs_prog_data
->uses_basevertex
||
103 vs_prog_data
->uses_baseinstance
;
105 /* On Haswell and prior, vertex and instance id are created by using the
106 * ComponentControl fields, so we need an element for any of them.
108 const bool needs_svgs_elem
= vs_prog_data
->uses_vertexid
||
109 vs_prog_data
->uses_instanceid
||
110 vs_prog_data
->uses_basevertex
||
111 vs_prog_data
->uses_baseinstance
;
114 uint32_t elem_count
= __builtin_popcount(elements
) -
115 __builtin_popcount(elements_double
) / 2;
117 uint32_t total_elems
= elem_count
+ needs_svgs_elem
;
118 if (total_elems
== 0)
123 const uint32_t num_dwords
= 1 + total_elems
* 2;
124 p
= anv_batch_emitn(&pipeline
->batch
, num_dwords
,
125 GENX(3DSTATE_VERTEX_ELEMENTS
));
126 memset(p
+ 1, 0, (num_dwords
- 1) * 4);
128 for (uint32_t i
= 0; i
< info
->vertexAttributeDescriptionCount
; i
++) {
129 const VkVertexInputAttributeDescription
*desc
=
130 &info
->pVertexAttributeDescriptions
[i
];
131 enum isl_format format
= anv_get_isl_format(&pipeline
->device
->info
,
133 VK_IMAGE_ASPECT_COLOR_BIT
,
134 VK_IMAGE_TILING_LINEAR
);
136 assert(desc
->binding
< 32);
138 if ((elements
& (1 << desc
->location
)) == 0)
139 continue; /* Binding unused */
142 __builtin_popcount(elements
& ((1 << desc
->location
) - 1)) -
143 DIV_ROUND_UP(__builtin_popcount(elements_double
&
144 ((1 << desc
->location
) -1)), 2);
146 struct GENX(VERTEX_ELEMENT_STATE
) element
= {
147 .VertexBufferIndex
= desc
->binding
,
149 .SourceElementFormat
= format
,
150 .EdgeFlagEnable
= false,
151 .SourceElementOffset
= desc
->offset
,
152 .Component0Control
= vertex_element_comp_control(format
, 0),
153 .Component1Control
= vertex_element_comp_control(format
, 1),
154 .Component2Control
= vertex_element_comp_control(format
, 2),
155 .Component3Control
= vertex_element_comp_control(format
, 3),
157 GENX(VERTEX_ELEMENT_STATE_pack
)(NULL
, &p
[1 + slot
* 2], &element
);
160 /* On Broadwell and later, we have a separate VF_INSTANCING packet
161 * that controls instancing. On Haswell and prior, that's part of
162 * VERTEX_BUFFER_STATE which we emit later.
164 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VF_INSTANCING
), vfi
) {
165 vfi
.InstancingEnable
= pipeline
->instancing_enable
[desc
->binding
];
166 vfi
.VertexElementIndex
= slot
;
167 /* Vulkan so far doesn't have an instance divisor, so
168 * this is always 1 (ignored if not instancing). */
169 vfi
.InstanceDataStepRate
= 1;
174 const uint32_t id_slot
= elem_count
;
175 if (needs_svgs_elem
) {
176 /* From the Broadwell PRM for the 3D_Vertex_Component_Control enum:
177 * "Within a VERTEX_ELEMENT_STATE structure, if a Component
178 * Control field is set to something other than VFCOMP_STORE_SRC,
179 * no higher-numbered Component Control fields may be set to
182 * This means, that if we have BaseInstance, we need BaseVertex as
183 * well. Just do all or nothing.
185 uint32_t base_ctrl
= (vs_prog_data
->uses_basevertex
||
186 vs_prog_data
->uses_baseinstance
) ?
187 VFCOMP_STORE_SRC
: VFCOMP_STORE_0
;
189 struct GENX(VERTEX_ELEMENT_STATE
) element
= {
190 .VertexBufferIndex
= 32, /* Reserved for this */
192 .SourceElementFormat
= ISL_FORMAT_R32G32_UINT
,
193 .Component0Control
= base_ctrl
,
194 .Component1Control
= base_ctrl
,
196 .Component2Control
= VFCOMP_STORE_0
,
197 .Component3Control
= VFCOMP_STORE_0
,
199 .Component2Control
= VFCOMP_STORE_VID
,
200 .Component3Control
= VFCOMP_STORE_IID
,
203 GENX(VERTEX_ELEMENT_STATE_pack
)(NULL
, &p
[1 + id_slot
* 2], &element
);
207 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VF_SGVS
), sgvs
) {
208 sgvs
.VertexIDEnable
= vs_prog_data
->uses_vertexid
;
209 sgvs
.VertexIDComponentNumber
= 2;
210 sgvs
.VertexIDElementOffset
= id_slot
;
211 sgvs
.InstanceIDEnable
= vs_prog_data
->uses_instanceid
;
212 sgvs
.InstanceIDComponentNumber
= 3;
213 sgvs
.InstanceIDElementOffset
= id_slot
;
219 genX(emit_urb_setup
)(struct anv_device
*device
, struct anv_batch
*batch
,
220 const struct gen_l3_config
*l3_config
,
221 VkShaderStageFlags active_stages
,
222 const unsigned entry_size
[4])
224 const struct gen_device_info
*devinfo
= &device
->info
;
226 const unsigned push_constant_kb
= devinfo
->gt
== 3 ? 32 : 16;
228 const unsigned push_constant_kb
= GEN_GEN
>= 8 ? 32 : 16;
231 const unsigned urb_size_kb
= gen_get_l3_config_urb_size(devinfo
, l3_config
);
235 gen_get_urb_config(devinfo
,
236 1024 * push_constant_kb
, 1024 * urb_size_kb
,
238 VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT
,
239 active_stages
& VK_SHADER_STAGE_GEOMETRY_BIT
,
240 entry_size
, entries
, start
);
242 #if GEN_GEN == 7 && !GEN_IS_HASWELL
243 /* From the IVB PRM Vol. 2, Part 1, Section 3.2.1:
245 * "A PIPE_CONTROL with Post-Sync Operation set to 1h and a depth stall
246 * needs to be sent just prior to any 3DSTATE_VS, 3DSTATE_URB_VS,
247 * 3DSTATE_CONSTANT_VS, 3DSTATE_BINDING_TABLE_POINTER_VS,
248 * 3DSTATE_SAMPLER_STATE_POINTER_VS command. Only one PIPE_CONTROL
249 * needs to be sent before any combination of VS associated 3DSTATE."
251 anv_batch_emit(batch
, GEN7_PIPE_CONTROL
, pc
) {
252 pc
.DepthStallEnable
= true;
253 pc
.PostSyncOperation
= WriteImmediateData
;
254 pc
.Address
= (struct anv_address
) { &device
->workaround_bo
, 0 };
258 for (int i
= 0; i
<= MESA_SHADER_GEOMETRY
; i
++) {
259 anv_batch_emit(batch
, GENX(3DSTATE_URB_VS
), urb
) {
260 urb
._3DCommandSubOpcode
+= i
;
261 urb
.VSURBStartingAddress
= start
[i
];
262 urb
.VSURBEntryAllocationSize
= entry_size
[i
] - 1;
263 urb
.VSNumberofURBEntries
= entries
[i
];
269 emit_urb_setup(struct anv_pipeline
*pipeline
)
271 unsigned entry_size
[4];
272 for (int i
= MESA_SHADER_VERTEX
; i
<= MESA_SHADER_GEOMETRY
; i
++) {
273 const struct brw_vue_prog_data
*prog_data
=
274 !anv_pipeline_has_stage(pipeline
, i
) ? NULL
:
275 (const struct brw_vue_prog_data
*) pipeline
->shaders
[i
]->prog_data
;
277 entry_size
[i
] = prog_data
? prog_data
->urb_entry_size
: 1;
280 genX(emit_urb_setup
)(pipeline
->device
, &pipeline
->batch
,
281 pipeline
->urb
.l3_config
,
282 pipeline
->active_stages
, entry_size
);
286 emit_3dstate_sbe(struct anv_pipeline
*pipeline
)
288 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
290 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
291 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_SBE
), sbe
);
293 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_SBE_SWIZ
), sbe
);
298 const struct brw_vue_map
*fs_input_map
=
299 &anv_pipeline_get_last_vue_prog_data(pipeline
)->vue_map
;
301 struct GENX(3DSTATE_SBE
) sbe
= {
302 GENX(3DSTATE_SBE_header
),
303 .AttributeSwizzleEnable
= true,
304 .PointSpriteTextureCoordinateOrigin
= UPPERLEFT
,
305 .NumberofSFOutputAttributes
= wm_prog_data
->num_varying_inputs
,
306 .ConstantInterpolationEnable
= wm_prog_data
->flat_inputs
,
310 for (unsigned i
= 0; i
< 32; i
++)
311 sbe
.AttributeActiveComponentFormat
[i
] = ACF_XYZW
;
315 /* On Broadwell, they broke 3DSTATE_SBE into two packets */
316 struct GENX(3DSTATE_SBE_SWIZ
) swiz
= {
317 GENX(3DSTATE_SBE_SWIZ_header
),
323 /* Skip the VUE header and position slots by default */
324 unsigned urb_entry_read_offset
= 1;
325 int max_source_attr
= 0;
326 for (int attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
327 int input_index
= wm_prog_data
->urb_setup
[attr
];
332 /* gl_Layer is stored in the VUE header */
333 if (attr
== VARYING_SLOT_LAYER
) {
334 urb_entry_read_offset
= 0;
338 if (attr
== VARYING_SLOT_PNTC
) {
339 sbe
.PointSpriteTextureCoordinateEnable
= 1 << input_index
;
343 const int slot
= fs_input_map
->varying_to_slot
[attr
];
345 if (input_index
>= 16)
349 /* This attribute does not exist in the VUE--that means that the
350 * vertex shader did not write to it. It could be that it's a
351 * regular varying read by the fragment shader but not written by
352 * the vertex shader or it's gl_PrimitiveID. In the first case the
353 * value is undefined, in the second it needs to be
356 swiz
.Attribute
[input_index
].ConstantSource
= PRIM_ID
;
357 swiz
.Attribute
[input_index
].ComponentOverrideX
= true;
358 swiz
.Attribute
[input_index
].ComponentOverrideY
= true;
359 swiz
.Attribute
[input_index
].ComponentOverrideZ
= true;
360 swiz
.Attribute
[input_index
].ComponentOverrideW
= true;
362 /* We have to subtract two slots to accout for the URB entry output
363 * read offset in the VS and GS stages.
366 const int source_attr
= slot
- 2 * urb_entry_read_offset
;
367 max_source_attr
= MAX2(max_source_attr
, source_attr
);
368 swiz
.Attribute
[input_index
].SourceAttribute
= source_attr
;
372 sbe
.VertexURBEntryReadOffset
= urb_entry_read_offset
;
373 sbe
.VertexURBEntryReadLength
= DIV_ROUND_UP(max_source_attr
+ 1, 2);
375 sbe
.ForceVertexURBEntryReadOffset
= true;
376 sbe
.ForceVertexURBEntryReadLength
= true;
379 uint32_t *dw
= anv_batch_emit_dwords(&pipeline
->batch
,
380 GENX(3DSTATE_SBE_length
));
381 GENX(3DSTATE_SBE_pack
)(&pipeline
->batch
, dw
, &sbe
);
384 dw
= anv_batch_emit_dwords(&pipeline
->batch
, GENX(3DSTATE_SBE_SWIZ_length
));
385 GENX(3DSTATE_SBE_SWIZ_pack
)(&pipeline
->batch
, dw
, &swiz
);
389 static const uint32_t vk_to_gen_cullmode
[] = {
390 [VK_CULL_MODE_NONE
] = CULLMODE_NONE
,
391 [VK_CULL_MODE_FRONT_BIT
] = CULLMODE_FRONT
,
392 [VK_CULL_MODE_BACK_BIT
] = CULLMODE_BACK
,
393 [VK_CULL_MODE_FRONT_AND_BACK
] = CULLMODE_BOTH
396 static const uint32_t vk_to_gen_fillmode
[] = {
397 [VK_POLYGON_MODE_FILL
] = FILL_MODE_SOLID
,
398 [VK_POLYGON_MODE_LINE
] = FILL_MODE_WIREFRAME
,
399 [VK_POLYGON_MODE_POINT
] = FILL_MODE_POINT
,
402 static const uint32_t vk_to_gen_front_face
[] = {
403 [VK_FRONT_FACE_COUNTER_CLOCKWISE
] = 1,
404 [VK_FRONT_FACE_CLOCKWISE
] = 0
408 emit_rs_state(struct anv_pipeline
*pipeline
,
409 const VkPipelineRasterizationStateCreateInfo
*rs_info
,
410 const VkPipelineMultisampleStateCreateInfo
*ms_info
,
411 const struct anv_render_pass
*pass
,
412 const struct anv_subpass
*subpass
)
414 struct GENX(3DSTATE_SF
) sf
= {
415 GENX(3DSTATE_SF_header
),
418 sf
.ViewportTransformEnable
= true;
419 sf
.StatisticsEnable
= true;
420 sf
.TriangleStripListProvokingVertexSelect
= 0;
421 sf
.LineStripListProvokingVertexSelect
= 0;
422 sf
.TriangleFanProvokingVertexSelect
= 1;
424 const struct brw_vue_prog_data
*last_vue_prog_data
=
425 anv_pipeline_get_last_vue_prog_data(pipeline
);
427 if (last_vue_prog_data
->vue_map
.slots_valid
& VARYING_BIT_PSIZ
) {
428 sf
.PointWidthSource
= Vertex
;
430 sf
.PointWidthSource
= State
;
435 struct GENX(3DSTATE_RASTER
) raster
= {
436 GENX(3DSTATE_RASTER_header
),
442 /* For details on 3DSTATE_RASTER multisample state, see the BSpec table
443 * "Multisample Modes State".
446 raster
.DXMultisampleRasterizationEnable
= true;
447 raster
.ForcedSampleCount
= FSC_NUMRASTSAMPLES_0
;
448 raster
.ForceMultisampling
= false;
450 raster
.MultisampleRasterizationMode
=
451 (ms_info
&& ms_info
->rasterizationSamples
> 1) ?
452 MSRASTMODE_ON_PATTERN
: MSRASTMODE_OFF_PIXEL
;
455 raster
.FrontWinding
= vk_to_gen_front_face
[rs_info
->frontFace
];
456 raster
.CullMode
= vk_to_gen_cullmode
[rs_info
->cullMode
];
457 raster
.FrontFaceFillMode
= vk_to_gen_fillmode
[rs_info
->polygonMode
];
458 raster
.BackFaceFillMode
= vk_to_gen_fillmode
[rs_info
->polygonMode
];
459 raster
.ScissorRectangleEnable
= true;
462 /* GEN9+ splits ViewportZClipTestEnable into near and far enable bits */
463 raster
.ViewportZFarClipTestEnable
= !pipeline
->depth_clamp_enable
;
464 raster
.ViewportZNearClipTestEnable
= !pipeline
->depth_clamp_enable
;
466 raster
.ViewportZClipTestEnable
= !pipeline
->depth_clamp_enable
;
469 raster
.GlobalDepthOffsetEnableSolid
= rs_info
->depthBiasEnable
;
470 raster
.GlobalDepthOffsetEnableWireframe
= rs_info
->depthBiasEnable
;
471 raster
.GlobalDepthOffsetEnablePoint
= rs_info
->depthBiasEnable
;
474 /* Gen7 requires that we provide the depth format in 3DSTATE_SF so that it
475 * can get the depth offsets correct.
477 if (subpass
->depth_stencil_attachment
< pass
->attachment_count
) {
479 pass
->attachments
[subpass
->depth_stencil_attachment
].format
;
480 assert(vk_format_is_depth_or_stencil(vk_format
));
481 if (vk_format_aspects(vk_format
) & VK_IMAGE_ASPECT_DEPTH_BIT
) {
482 enum isl_format isl_format
=
483 anv_get_isl_format(&pipeline
->device
->info
, vk_format
,
484 VK_IMAGE_ASPECT_DEPTH_BIT
,
485 VK_IMAGE_TILING_OPTIMAL
);
486 sf
.DepthBufferSurfaceFormat
=
487 isl_format_get_depth_format(isl_format
, false);
493 GENX(3DSTATE_SF_pack
)(NULL
, pipeline
->gen8
.sf
, &sf
);
494 GENX(3DSTATE_RASTER_pack
)(NULL
, pipeline
->gen8
.raster
, &raster
);
497 GENX(3DSTATE_SF_pack
)(NULL
, &pipeline
->gen7
.sf
, &sf
);
502 emit_ms_state(struct anv_pipeline
*pipeline
,
503 const VkPipelineMultisampleStateCreateInfo
*info
)
505 uint32_t samples
= 1;
506 uint32_t log2_samples
= 0;
508 /* From the Vulkan 1.0 spec:
509 * If pSampleMask is NULL, it is treated as if the mask has all bits
510 * enabled, i.e. no coverage is removed from fragments.
512 * 3DSTATE_SAMPLE_MASK.SampleMask is 16 bits.
515 uint32_t sample_mask
= 0xffff;
517 uint32_t sample_mask
= 0xff;
521 samples
= info
->rasterizationSamples
;
522 log2_samples
= __builtin_ffs(samples
) - 1;
525 if (info
&& info
->pSampleMask
)
526 sample_mask
&= info
->pSampleMask
[0];
528 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_MULTISAMPLE
), ms
) {
529 ms
.NumberofMultisamples
= log2_samples
;
532 /* The PRM says that this bit is valid only for DX9:
534 * SW can choose to set this bit only for DX9 API. DX10/OGL API's
535 * should not have any effect by setting or not setting this bit.
537 ms
.PixelPositionOffsetEnable
= false;
538 ms
.PixelLocation
= CENTER
;
540 ms
.PixelLocation
= PIXLOC_CENTER
;
544 GEN_SAMPLE_POS_1X(ms
.Sample
);
547 GEN_SAMPLE_POS_2X(ms
.Sample
);
550 GEN_SAMPLE_POS_4X(ms
.Sample
);
553 GEN_SAMPLE_POS_8X(ms
.Sample
);
561 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_SAMPLE_MASK
), sm
) {
562 sm
.SampleMask
= sample_mask
;
566 static const uint32_t vk_to_gen_logic_op
[] = {
567 [VK_LOGIC_OP_COPY
] = LOGICOP_COPY
,
568 [VK_LOGIC_OP_CLEAR
] = LOGICOP_CLEAR
,
569 [VK_LOGIC_OP_AND
] = LOGICOP_AND
,
570 [VK_LOGIC_OP_AND_REVERSE
] = LOGICOP_AND_REVERSE
,
571 [VK_LOGIC_OP_AND_INVERTED
] = LOGICOP_AND_INVERTED
,
572 [VK_LOGIC_OP_NO_OP
] = LOGICOP_NOOP
,
573 [VK_LOGIC_OP_XOR
] = LOGICOP_XOR
,
574 [VK_LOGIC_OP_OR
] = LOGICOP_OR
,
575 [VK_LOGIC_OP_NOR
] = LOGICOP_NOR
,
576 [VK_LOGIC_OP_EQUIVALENT
] = LOGICOP_EQUIV
,
577 [VK_LOGIC_OP_INVERT
] = LOGICOP_INVERT
,
578 [VK_LOGIC_OP_OR_REVERSE
] = LOGICOP_OR_REVERSE
,
579 [VK_LOGIC_OP_COPY_INVERTED
] = LOGICOP_COPY_INVERTED
,
580 [VK_LOGIC_OP_OR_INVERTED
] = LOGICOP_OR_INVERTED
,
581 [VK_LOGIC_OP_NAND
] = LOGICOP_NAND
,
582 [VK_LOGIC_OP_SET
] = LOGICOP_SET
,
585 static const uint32_t vk_to_gen_blend
[] = {
586 [VK_BLEND_FACTOR_ZERO
] = BLENDFACTOR_ZERO
,
587 [VK_BLEND_FACTOR_ONE
] = BLENDFACTOR_ONE
,
588 [VK_BLEND_FACTOR_SRC_COLOR
] = BLENDFACTOR_SRC_COLOR
,
589 [VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR
] = BLENDFACTOR_INV_SRC_COLOR
,
590 [VK_BLEND_FACTOR_DST_COLOR
] = BLENDFACTOR_DST_COLOR
,
591 [VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR
] = BLENDFACTOR_INV_DST_COLOR
,
592 [VK_BLEND_FACTOR_SRC_ALPHA
] = BLENDFACTOR_SRC_ALPHA
,
593 [VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
] = BLENDFACTOR_INV_SRC_ALPHA
,
594 [VK_BLEND_FACTOR_DST_ALPHA
] = BLENDFACTOR_DST_ALPHA
,
595 [VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA
] = BLENDFACTOR_INV_DST_ALPHA
,
596 [VK_BLEND_FACTOR_CONSTANT_COLOR
] = BLENDFACTOR_CONST_COLOR
,
597 [VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR
]= BLENDFACTOR_INV_CONST_COLOR
,
598 [VK_BLEND_FACTOR_CONSTANT_ALPHA
] = BLENDFACTOR_CONST_ALPHA
,
599 [VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA
]= BLENDFACTOR_INV_CONST_ALPHA
,
600 [VK_BLEND_FACTOR_SRC_ALPHA_SATURATE
] = BLENDFACTOR_SRC_ALPHA_SATURATE
,
601 [VK_BLEND_FACTOR_SRC1_COLOR
] = BLENDFACTOR_SRC1_COLOR
,
602 [VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR
] = BLENDFACTOR_INV_SRC1_COLOR
,
603 [VK_BLEND_FACTOR_SRC1_ALPHA
] = BLENDFACTOR_SRC1_ALPHA
,
604 [VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA
] = BLENDFACTOR_INV_SRC1_ALPHA
,
607 static const uint32_t vk_to_gen_blend_op
[] = {
608 [VK_BLEND_OP_ADD
] = BLENDFUNCTION_ADD
,
609 [VK_BLEND_OP_SUBTRACT
] = BLENDFUNCTION_SUBTRACT
,
610 [VK_BLEND_OP_REVERSE_SUBTRACT
] = BLENDFUNCTION_REVERSE_SUBTRACT
,
611 [VK_BLEND_OP_MIN
] = BLENDFUNCTION_MIN
,
612 [VK_BLEND_OP_MAX
] = BLENDFUNCTION_MAX
,
615 static const uint32_t vk_to_gen_compare_op
[] = {
616 [VK_COMPARE_OP_NEVER
] = PREFILTEROPNEVER
,
617 [VK_COMPARE_OP_LESS
] = PREFILTEROPLESS
,
618 [VK_COMPARE_OP_EQUAL
] = PREFILTEROPEQUAL
,
619 [VK_COMPARE_OP_LESS_OR_EQUAL
] = PREFILTEROPLEQUAL
,
620 [VK_COMPARE_OP_GREATER
] = PREFILTEROPGREATER
,
621 [VK_COMPARE_OP_NOT_EQUAL
] = PREFILTEROPNOTEQUAL
,
622 [VK_COMPARE_OP_GREATER_OR_EQUAL
] = PREFILTEROPGEQUAL
,
623 [VK_COMPARE_OP_ALWAYS
] = PREFILTEROPALWAYS
,
626 static const uint32_t vk_to_gen_stencil_op
[] = {
627 [VK_STENCIL_OP_KEEP
] = STENCILOP_KEEP
,
628 [VK_STENCIL_OP_ZERO
] = STENCILOP_ZERO
,
629 [VK_STENCIL_OP_REPLACE
] = STENCILOP_REPLACE
,
630 [VK_STENCIL_OP_INCREMENT_AND_CLAMP
] = STENCILOP_INCRSAT
,
631 [VK_STENCIL_OP_DECREMENT_AND_CLAMP
] = STENCILOP_DECRSAT
,
632 [VK_STENCIL_OP_INVERT
] = STENCILOP_INVERT
,
633 [VK_STENCIL_OP_INCREMENT_AND_WRAP
] = STENCILOP_INCR
,
634 [VK_STENCIL_OP_DECREMENT_AND_WRAP
] = STENCILOP_DECR
,
638 emit_ds_state(struct anv_pipeline
*pipeline
,
639 const VkPipelineDepthStencilStateCreateInfo
*info
,
640 const struct anv_render_pass
*pass
,
641 const struct anv_subpass
*subpass
)
644 # define depth_stencil_dw pipeline->gen7.depth_stencil_state
646 # define depth_stencil_dw pipeline->gen8.wm_depth_stencil
648 # define depth_stencil_dw pipeline->gen9.wm_depth_stencil
652 /* We're going to OR this together with the dynamic state. We need
653 * to make sure it's initialized to something useful.
655 memset(depth_stencil_dw
, 0, sizeof(depth_stencil_dw
));
659 /* VkBool32 depthBoundsTestEnable; // optional (depth_bounds_test) */
662 struct GENX(DEPTH_STENCIL_STATE
) depth_stencil
= {
664 struct GENX(3DSTATE_WM_DEPTH_STENCIL
) depth_stencil
= {
666 .DepthTestEnable
= info
->depthTestEnable
,
667 .DepthBufferWriteEnable
= info
->depthWriteEnable
,
668 .DepthTestFunction
= vk_to_gen_compare_op
[info
->depthCompareOp
],
669 .DoubleSidedStencilEnable
= true,
671 .StencilTestEnable
= info
->stencilTestEnable
,
672 .StencilBufferWriteEnable
= info
->stencilTestEnable
,
673 .StencilFailOp
= vk_to_gen_stencil_op
[info
->front
.failOp
],
674 .StencilPassDepthPassOp
= vk_to_gen_stencil_op
[info
->front
.passOp
],
675 .StencilPassDepthFailOp
= vk_to_gen_stencil_op
[info
->front
.depthFailOp
],
676 .StencilTestFunction
= vk_to_gen_compare_op
[info
->front
.compareOp
],
677 .BackfaceStencilFailOp
= vk_to_gen_stencil_op
[info
->back
.failOp
],
678 .BackfaceStencilPassDepthPassOp
= vk_to_gen_stencil_op
[info
->back
.passOp
],
679 .BackfaceStencilPassDepthFailOp
=vk_to_gen_stencil_op
[info
->back
.depthFailOp
],
680 .BackfaceStencilTestFunction
= vk_to_gen_compare_op
[info
->back
.compareOp
],
683 VkImageAspectFlags aspects
= 0;
684 if (subpass
->depth_stencil_attachment
!= VK_ATTACHMENT_UNUSED
) {
685 VkFormat depth_stencil_format
=
686 pass
->attachments
[subpass
->depth_stencil_attachment
].format
;
687 aspects
= vk_format_aspects(depth_stencil_format
);
690 /* The Vulkan spec requires that if either depth or stencil is not present,
691 * the pipeline is to act as if the test silently passes.
693 if (!(aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
)) {
694 depth_stencil
.DepthBufferWriteEnable
= false;
695 depth_stencil
.DepthTestFunction
= PREFILTEROPALWAYS
;
698 if (!(aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
)) {
699 depth_stencil
.StencilBufferWriteEnable
= false;
700 depth_stencil
.StencilTestFunction
= PREFILTEROPALWAYS
;
701 depth_stencil
.BackfaceStencilTestFunction
= PREFILTEROPALWAYS
;
704 /* From the Broadwell PRM:
706 * "If Depth_Test_Enable = 1 AND Depth_Test_func = EQUAL, the
707 * Depth_Write_Enable must be set to 0."
709 if (info
->depthTestEnable
&& info
->depthCompareOp
== VK_COMPARE_OP_EQUAL
)
710 depth_stencil
.DepthBufferWriteEnable
= false;
713 GENX(DEPTH_STENCIL_STATE_pack
)(NULL
, depth_stencil_dw
, &depth_stencil
);
715 GENX(3DSTATE_WM_DEPTH_STENCIL_pack
)(NULL
, depth_stencil_dw
, &depth_stencil
);
720 emit_cb_state(struct anv_pipeline
*pipeline
,
721 const VkPipelineColorBlendStateCreateInfo
*info
,
722 const VkPipelineMultisampleStateCreateInfo
*ms_info
)
724 struct anv_device
*device
= pipeline
->device
;
726 const uint32_t num_dwords
= GENX(BLEND_STATE_length
);
727 pipeline
->blend_state
=
728 anv_state_pool_alloc(&device
->dynamic_state_pool
, num_dwords
* 4, 64);
730 struct GENX(BLEND_STATE
) blend_state
= {
732 .AlphaToCoverageEnable
= ms_info
&& ms_info
->alphaToCoverageEnable
,
733 .AlphaToOneEnable
= ms_info
&& ms_info
->alphaToOneEnable
,
735 /* Make sure it gets zeroed */
736 .Entry
= { { 0, }, },
740 /* Default everything to disabled */
741 for (uint32_t i
= 0; i
< 8; i
++) {
742 blend_state
.Entry
[i
].WriteDisableAlpha
= true;
743 blend_state
.Entry
[i
].WriteDisableRed
= true;
744 blend_state
.Entry
[i
].WriteDisableGreen
= true;
745 blend_state
.Entry
[i
].WriteDisableBlue
= true;
748 uint32_t surface_count
= 0;
749 struct anv_pipeline_bind_map
*map
;
750 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
751 map
= &pipeline
->shaders
[MESA_SHADER_FRAGMENT
]->bind_map
;
752 surface_count
= map
->surface_count
;
755 bool has_writeable_rt
= false;
756 for (unsigned i
= 0; i
< surface_count
; i
++) {
757 struct anv_pipeline_binding
*binding
= &map
->surface_to_descriptor
[i
];
759 /* All color attachments are at the beginning of the binding table */
760 if (binding
->set
!= ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS
)
763 /* We can have at most 8 attachments */
766 if (binding
->index
>= info
->attachmentCount
)
769 assert(binding
->binding
== 0);
770 const VkPipelineColorBlendAttachmentState
*a
=
771 &info
->pAttachments
[binding
->index
];
773 blend_state
.Entry
[i
] = (struct GENX(BLEND_STATE_ENTRY
)) {
775 .AlphaToCoverageEnable
= ms_info
&& ms_info
->alphaToCoverageEnable
,
776 .AlphaToOneEnable
= ms_info
&& ms_info
->alphaToOneEnable
,
778 .LogicOpEnable
= info
->logicOpEnable
,
779 .LogicOpFunction
= vk_to_gen_logic_op
[info
->logicOp
],
780 .ColorBufferBlendEnable
= a
->blendEnable
,
781 .ColorClampRange
= COLORCLAMP_RTFORMAT
,
782 .PreBlendColorClampEnable
= true,
783 .PostBlendColorClampEnable
= true,
784 .SourceBlendFactor
= vk_to_gen_blend
[a
->srcColorBlendFactor
],
785 .DestinationBlendFactor
= vk_to_gen_blend
[a
->dstColorBlendFactor
],
786 .ColorBlendFunction
= vk_to_gen_blend_op
[a
->colorBlendOp
],
787 .SourceAlphaBlendFactor
= vk_to_gen_blend
[a
->srcAlphaBlendFactor
],
788 .DestinationAlphaBlendFactor
= vk_to_gen_blend
[a
->dstAlphaBlendFactor
],
789 .AlphaBlendFunction
= vk_to_gen_blend_op
[a
->alphaBlendOp
],
790 .WriteDisableAlpha
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_A_BIT
),
791 .WriteDisableRed
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_R_BIT
),
792 .WriteDisableGreen
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_G_BIT
),
793 .WriteDisableBlue
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_B_BIT
),
796 if (a
->srcColorBlendFactor
!= a
->srcAlphaBlendFactor
||
797 a
->dstColorBlendFactor
!= a
->dstAlphaBlendFactor
||
798 a
->colorBlendOp
!= a
->alphaBlendOp
) {
800 blend_state
.IndependentAlphaBlendEnable
= true;
802 blend_state
.Entry
[i
].IndependentAlphaBlendEnable
= true;
806 if (a
->colorWriteMask
!= 0)
807 has_writeable_rt
= true;
809 /* Our hardware applies the blend factor prior to the blend function
810 * regardless of what function is used. Technically, this means the
811 * hardware can do MORE than GL or Vulkan specify. However, it also
812 * means that, for MIN and MAX, we have to stomp the blend factor to
813 * ONE to make it a no-op.
815 if (a
->colorBlendOp
== VK_BLEND_OP_MIN
||
816 a
->colorBlendOp
== VK_BLEND_OP_MAX
) {
817 blend_state
.Entry
[i
].SourceBlendFactor
= BLENDFACTOR_ONE
;
818 blend_state
.Entry
[i
].DestinationBlendFactor
= BLENDFACTOR_ONE
;
820 if (a
->alphaBlendOp
== VK_BLEND_OP_MIN
||
821 a
->alphaBlendOp
== VK_BLEND_OP_MAX
) {
822 blend_state
.Entry
[i
].SourceAlphaBlendFactor
= BLENDFACTOR_ONE
;
823 blend_state
.Entry
[i
].DestinationAlphaBlendFactor
= BLENDFACTOR_ONE
;
828 struct GENX(BLEND_STATE_ENTRY
) *bs0
= &blend_state
.Entry
[0];
829 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS_BLEND
), blend
) {
830 blend
.AlphaToCoverageEnable
= blend_state
.AlphaToCoverageEnable
;
831 blend
.HasWriteableRT
= has_writeable_rt
;
832 blend
.ColorBufferBlendEnable
= bs0
->ColorBufferBlendEnable
;
833 blend
.SourceAlphaBlendFactor
= bs0
->SourceAlphaBlendFactor
;
834 blend
.DestinationAlphaBlendFactor
= bs0
->DestinationAlphaBlendFactor
;
835 blend
.SourceBlendFactor
= bs0
->SourceBlendFactor
;
836 blend
.DestinationBlendFactor
= bs0
->DestinationBlendFactor
;
837 blend
.AlphaTestEnable
= false;
838 blend
.IndependentAlphaBlendEnable
=
839 blend_state
.IndependentAlphaBlendEnable
;
842 (void)has_writeable_rt
;
845 GENX(BLEND_STATE_pack
)(NULL
, pipeline
->blend_state
.map
, &blend_state
);
846 if (!device
->info
.has_llc
)
847 anv_state_clflush(pipeline
->blend_state
);
849 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_BLEND_STATE_POINTERS
), bsp
) {
850 bsp
.BlendStatePointer
= pipeline
->blend_state
.offset
;
852 bsp
.BlendStatePointerValid
= true;
858 emit_3dstate_clip(struct anv_pipeline
*pipeline
,
859 const VkPipelineViewportStateCreateInfo
*vp_info
,
860 const VkPipelineRasterizationStateCreateInfo
*rs_info
)
862 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
864 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_CLIP
), clip
) {
865 clip
.ClipEnable
= true;
866 clip
.EarlyCullEnable
= true;
867 clip
.APIMode
= APIMODE_D3D
,
868 clip
.ViewportXYClipTestEnable
= true;
870 clip
.ClipMode
= CLIPMODE_NORMAL
;
872 clip
.TriangleStripListProvokingVertexSelect
= 0;
873 clip
.LineStripListProvokingVertexSelect
= 0;
874 clip
.TriangleFanProvokingVertexSelect
= 1;
876 clip
.MinimumPointWidth
= 0.125;
877 clip
.MaximumPointWidth
= 255.875;
878 clip
.MaximumVPIndex
= (vp_info
? vp_info
->viewportCount
: 1) - 1;
881 clip
.FrontWinding
= vk_to_gen_front_face
[rs_info
->frontFace
];
882 clip
.CullMode
= vk_to_gen_cullmode
[rs_info
->cullMode
];
883 clip
.ViewportZClipTestEnable
= !pipeline
->depth_clamp_enable
;
884 const struct brw_vue_prog_data
*last
=
885 anv_pipeline_get_last_vue_prog_data(pipeline
);
887 clip
.UserClipDistanceClipTestEnableBitmask
= last
->clip_distance_mask
;
888 clip
.UserClipDistanceCullTestEnableBitmask
= last
->cull_distance_mask
;
891 clip
.NonPerspectiveBarycentricEnable
= wm_prog_data
?
892 (wm_prog_data
->barycentric_interp_modes
& 0x38) != 0 : 0;
898 emit_3dstate_streamout(struct anv_pipeline
*pipeline
,
899 const VkPipelineRasterizationStateCreateInfo
*rs_info
)
901 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_STREAMOUT
), so
) {
902 so
.RenderingDisable
= rs_info
->rasterizerDiscardEnable
;
906 static inline uint32_t
907 get_sampler_count(const struct anv_shader_bin
*bin
)
909 return DIV_ROUND_UP(bin
->bind_map
.sampler_count
, 4);
912 static inline uint32_t
913 get_binding_table_entry_count(const struct anv_shader_bin
*bin
)
915 return DIV_ROUND_UP(bin
->bind_map
.surface_count
, 32);
918 static inline struct anv_address
919 get_scratch_address(struct anv_pipeline
*pipeline
,
920 gl_shader_stage stage
,
921 const struct anv_shader_bin
*bin
)
923 return (struct anv_address
) {
924 .bo
= anv_scratch_pool_alloc(pipeline
->device
,
925 &pipeline
->device
->scratch_pool
,
926 stage
, bin
->prog_data
->total_scratch
),
931 static inline uint32_t
932 get_scratch_space(const struct anv_shader_bin
*bin
)
934 return ffs(bin
->prog_data
->total_scratch
/ 2048);
937 static inline uint32_t
938 get_urb_output_offset()
940 /* Skip the VUE header and position slots */
944 static inline uint32_t
945 get_urb_output_length(const struct anv_shader_bin
*bin
)
947 const struct brw_vue_prog_data
*prog_data
=
948 (const struct brw_vue_prog_data
*)bin
->prog_data
;
950 return (prog_data
->vue_map
.num_slots
+ 1) / 2 - get_urb_output_offset();
954 emit_3dstate_vs(struct anv_pipeline
*pipeline
)
956 const struct gen_device_info
*devinfo
= &pipeline
->device
->info
;
957 const struct brw_vs_prog_data
*vs_prog_data
= get_vs_prog_data(pipeline
);
958 const struct anv_shader_bin
*vs_bin
=
959 pipeline
->shaders
[MESA_SHADER_VERTEX
];
961 assert(anv_pipeline_has_stage(pipeline
, MESA_SHADER_VERTEX
));
963 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VS
), vs
) {
964 vs
.FunctionEnable
= true;
965 vs
.StatisticsEnable
= true;
966 vs
.KernelStartPointer
= vs_bin
->kernel
.offset
;
968 vs
.SIMD8DispatchEnable
=
969 vs_prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
;
972 assert(!vs_prog_data
->base
.base
.use_alt_mode
);
973 vs
.SingleVertexDispatch
= false;
974 vs
.VectorMaskEnable
= false;
975 vs
.SamplerCount
= get_sampler_count(vs_bin
);
976 vs
.BindingTableEntryCount
= get_binding_table_entry_count(vs_bin
);
977 vs
.FloatingPointMode
= IEEE754
;
978 vs
.IllegalOpcodeExceptionEnable
= false;
979 vs
.SoftwareExceptionEnable
= false;
980 vs
.MaximumNumberofThreads
= devinfo
->max_vs_threads
- 1;
981 vs
.VertexCacheDisable
= false;
983 vs
.VertexURBEntryReadLength
= vs_prog_data
->base
.urb_read_length
;
984 vs
.VertexURBEntryReadOffset
= 0;
985 vs
.DispatchGRFStartRegisterForURBData
=
986 vs_prog_data
->base
.base
.dispatch_grf_start_reg
;
989 vs
.VertexURBEntryOutputReadOffset
= get_urb_output_offset();
990 vs
.VertexURBEntryOutputLength
= get_urb_output_length(vs_bin
);
992 vs
.UserClipDistanceClipTestEnableBitmask
=
993 vs_prog_data
->base
.clip_distance_mask
;
994 vs
.UserClipDistanceCullTestEnableBitmask
=
995 vs_prog_data
->base
.cull_distance_mask
;
998 vs
.PerThreadScratchSpace
= get_scratch_space(vs_bin
);
999 vs
.ScratchSpaceBasePointer
=
1000 get_scratch_address(pipeline
, MESA_SHADER_VERTEX
, vs_bin
);
1005 emit_3dstate_hs_te_ds(struct anv_pipeline
*pipeline
)
1007 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_TESS_EVAL
)) {
1008 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_HS
), hs
);
1009 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_TE
), te
);
1010 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_DS
), ds
);
1014 const struct gen_device_info
*devinfo
= &pipeline
->device
->info
;
1015 const struct anv_shader_bin
*tcs_bin
=
1016 pipeline
->shaders
[MESA_SHADER_TESS_CTRL
];
1017 const struct anv_shader_bin
*tes_bin
=
1018 pipeline
->shaders
[MESA_SHADER_TESS_EVAL
];
1020 const struct brw_tcs_prog_data
*tcs_prog_data
= get_tcs_prog_data(pipeline
);
1021 const struct brw_tes_prog_data
*tes_prog_data
= get_tes_prog_data(pipeline
);
1023 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_HS
), hs
) {
1024 hs
.FunctionEnable
= true;
1025 hs
.StatisticsEnable
= true;
1026 hs
.KernelStartPointer
= tcs_bin
->kernel
.offset
;
1028 hs
.SamplerCount
= get_sampler_count(tcs_bin
);
1029 hs
.BindingTableEntryCount
= get_binding_table_entry_count(tcs_bin
);
1030 hs
.MaximumNumberofThreads
= devinfo
->max_tcs_threads
- 1;
1031 hs
.IncludeVertexHandles
= true;
1032 hs
.InstanceCount
= tcs_prog_data
->instances
- 1;
1034 hs
.VertexURBEntryReadLength
= 0;
1035 hs
.VertexURBEntryReadOffset
= 0;
1036 hs
.DispatchGRFStartRegisterForURBData
=
1037 tcs_prog_data
->base
.base
.dispatch_grf_start_reg
;
1039 hs
.PerThreadScratchSpace
= get_scratch_space(tcs_bin
);
1040 hs
.ScratchSpaceBasePointer
=
1041 get_scratch_address(pipeline
, MESA_SHADER_TESS_CTRL
, tcs_bin
);
1044 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_TE
), te
) {
1045 te
.Partitioning
= tes_prog_data
->partitioning
;
1046 te
.OutputTopology
= tes_prog_data
->output_topology
;
1047 te
.TEDomain
= tes_prog_data
->domain
;
1049 te
.MaximumTessellationFactorOdd
= 63.0;
1050 te
.MaximumTessellationFactorNotOdd
= 64.0;
1053 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_DS
), ds
) {
1054 ds
.FunctionEnable
= true;
1055 ds
.StatisticsEnable
= true;
1056 ds
.KernelStartPointer
= tes_bin
->kernel
.offset
;
1058 ds
.SamplerCount
= get_sampler_count(tes_bin
);
1059 ds
.BindingTableEntryCount
= get_binding_table_entry_count(tes_bin
);
1060 ds
.MaximumNumberofThreads
= devinfo
->max_tes_threads
- 1;
1062 ds
.ComputeWCoordinateEnable
=
1063 tes_prog_data
->domain
== BRW_TESS_DOMAIN_TRI
;
1065 ds
.PatchURBEntryReadLength
= tes_prog_data
->base
.urb_read_length
;
1066 ds
.PatchURBEntryReadOffset
= 0;
1067 ds
.DispatchGRFStartRegisterForURBData
=
1068 tes_prog_data
->base
.base
.dispatch_grf_start_reg
;
1071 ds
.VertexURBEntryOutputReadOffset
= 1;
1072 ds
.VertexURBEntryOutputLength
=
1073 (tes_prog_data
->base
.vue_map
.num_slots
+ 1) / 2 - 1;
1076 tes_prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
?
1077 DISPATCH_MODE_SIMD8_SINGLE_PATCH
:
1078 DISPATCH_MODE_SIMD4X2
;
1080 ds
.UserClipDistanceClipTestEnableBitmask
=
1081 tes_prog_data
->base
.clip_distance_mask
;
1082 ds
.UserClipDistanceCullTestEnableBitmask
=
1083 tes_prog_data
->base
.cull_distance_mask
;
1086 ds
.PerThreadScratchSpace
= get_scratch_space(tes_bin
);
1087 ds
.ScratchSpaceBasePointer
=
1088 get_scratch_address(pipeline
, MESA_SHADER_TESS_EVAL
, tes_bin
);
1093 emit_3dstate_gs(struct anv_pipeline
*pipeline
)
1095 const struct gen_device_info
*devinfo
= &pipeline
->device
->info
;
1096 const struct anv_shader_bin
*gs_bin
=
1097 pipeline
->shaders
[MESA_SHADER_GEOMETRY
];
1099 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_GEOMETRY
)) {
1100 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_GS
), gs
);
1104 const struct brw_gs_prog_data
*gs_prog_data
= get_gs_prog_data(pipeline
);
1106 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_GS
), gs
) {
1107 gs
.FunctionEnable
= true;
1108 gs
.StatisticsEnable
= true;
1109 gs
.KernelStartPointer
= gs_bin
->kernel
.offset
;
1110 gs
.DispatchMode
= gs_prog_data
->base
.dispatch_mode
;
1112 gs
.SingleProgramFlow
= false;
1113 gs
.VectorMaskEnable
= false;
1114 gs
.SamplerCount
= get_sampler_count(gs_bin
);
1115 gs
.BindingTableEntryCount
= get_binding_table_entry_count(gs_bin
);
1116 gs
.IncludeVertexHandles
= gs_prog_data
->base
.include_vue_handles
;
1117 gs
.IncludePrimitiveID
= gs_prog_data
->include_primitive_id
;
1120 /* Broadwell is weird. It needs us to divide by 2. */
1121 gs
.MaximumNumberofThreads
= devinfo
->max_gs_threads
/ 2 - 1;
1123 gs
.MaximumNumberofThreads
= devinfo
->max_gs_threads
- 1;
1126 gs
.OutputVertexSize
= gs_prog_data
->output_vertex_size_hwords
* 2 - 1;
1127 gs
.OutputTopology
= gs_prog_data
->output_topology
;
1128 gs
.VertexURBEntryReadLength
= gs_prog_data
->base
.urb_read_length
;
1129 gs
.ControlDataFormat
= gs_prog_data
->control_data_format
;
1130 gs
.ControlDataHeaderSize
= gs_prog_data
->control_data_header_size_hwords
;
1131 gs
.InstanceControl
= MAX2(gs_prog_data
->invocations
, 1) - 1;
1132 #if GEN_GEN >= 8 || GEN_IS_HASWELL
1133 gs
.ReorderMode
= TRAILING
;
1135 gs
.ReorderEnable
= true;
1139 gs
.ExpectedVertexCount
= gs_prog_data
->vertices_in
;
1140 gs
.StaticOutput
= gs_prog_data
->static_vertex_count
>= 0;
1141 gs
.StaticOutputVertexCount
= gs_prog_data
->static_vertex_count
>= 0 ?
1142 gs_prog_data
->static_vertex_count
: 0;
1145 gs
.VertexURBEntryReadOffset
= 0;
1146 gs
.VertexURBEntryReadLength
= gs_prog_data
->base
.urb_read_length
;
1147 gs
.DispatchGRFStartRegisterForURBData
=
1148 gs_prog_data
->base
.base
.dispatch_grf_start_reg
;
1151 gs
.VertexURBEntryOutputReadOffset
= get_urb_output_offset();
1152 gs
.VertexURBEntryOutputLength
= get_urb_output_length(gs_bin
);
1154 gs
.UserClipDistanceClipTestEnableBitmask
=
1155 gs_prog_data
->base
.clip_distance_mask
;
1156 gs
.UserClipDistanceCullTestEnableBitmask
=
1157 gs_prog_data
->base
.cull_distance_mask
;
1160 gs
.PerThreadScratchSpace
= get_scratch_space(gs_bin
);
1161 gs
.ScratchSpaceBasePointer
=
1162 get_scratch_address(pipeline
, MESA_SHADER_GEOMETRY
, gs_bin
);
1167 emit_3dstate_wm(struct anv_pipeline
*pipeline
, struct anv_subpass
*subpass
,
1168 const VkPipelineMultisampleStateCreateInfo
*multisample
)
1170 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
1172 MAYBE_UNUSED
uint32_t samples
=
1173 multisample
? multisample
->rasterizationSamples
: 1;
1175 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_WM
), wm
) {
1176 wm
.StatisticsEnable
= true;
1177 wm
.LineEndCapAntialiasingRegionWidth
= _05pixels
;
1178 wm
.LineAntialiasingRegionWidth
= _10pixels
;
1179 wm
.PointRasterizationRule
= RASTRULE_UPPER_RIGHT
;
1181 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
1182 if (wm_prog_data
->early_fragment_tests
) {
1183 wm
.EarlyDepthStencilControl
= EDSC_PREPS
;
1184 } else if (wm_prog_data
->has_side_effects
) {
1185 wm
.EarlyDepthStencilControl
= EDSC_PSEXEC
;
1187 wm
.EarlyDepthStencilControl
= EDSC_NORMAL
;
1190 wm
.BarycentricInterpolationMode
=
1191 wm_prog_data
->barycentric_interp_modes
;
1194 /* FIXME: This needs a lot more work, cf gen7 upload_wm_state(). */
1195 wm
.ThreadDispatchEnable
= true;
1197 wm
.PixelShaderComputedDepthMode
= wm_prog_data
->computed_depth_mode
;
1198 wm
.PixelShaderUsesSourceDepth
= wm_prog_data
->uses_src_depth
;
1199 wm
.PixelShaderUsesSourceW
= wm_prog_data
->uses_src_w
;
1200 wm
.PixelShaderUsesInputCoverageMask
= wm_prog_data
->uses_sample_mask
;
1202 /* If the subpass has a depth or stencil self-dependency, then we
1203 * need to force the hardware to do the depth/stencil write *after*
1204 * fragment shader execution. Otherwise, the writes may hit memory
1205 * before we get around to fetching from the input attachment and we
1206 * may get the depth or stencil value from the current draw rather
1207 * than the previous one.
1209 wm
.PixelShaderKillsPixel
= subpass
->has_ds_self_dep
||
1210 wm_prog_data
->uses_kill
;
1213 wm
.MultisampleRasterizationMode
= MSRASTMODE_ON_PATTERN
;
1214 if (wm_prog_data
->persample_dispatch
) {
1215 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
1217 wm
.MultisampleDispatchMode
= MSDISPMODE_PERPIXEL
;
1220 wm
.MultisampleRasterizationMode
= MSRASTMODE_OFF_PIXEL
;
1221 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
1229 is_dual_src_blend_factor(VkBlendFactor factor
)
1231 return factor
== VK_BLEND_FACTOR_SRC1_COLOR
||
1232 factor
== VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR
||
1233 factor
== VK_BLEND_FACTOR_SRC1_ALPHA
||
1234 factor
== VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA
;
1238 emit_3dstate_ps(struct anv_pipeline
*pipeline
,
1239 const VkPipelineColorBlendStateCreateInfo
*blend
)
1241 MAYBE_UNUSED
const struct gen_device_info
*devinfo
= &pipeline
->device
->info
;
1242 const struct anv_shader_bin
*fs_bin
=
1243 pipeline
->shaders
[MESA_SHADER_FRAGMENT
];
1245 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
1246 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS
), ps
) {
1248 /* Even if no fragments are ever dispatched, gen7 hardware hangs if
1249 * we don't at least set the maximum number of threads.
1251 ps
.MaximumNumberofThreads
= devinfo
->max_wm_threads
- 1;
1257 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
1260 /* The hardware wedges if you have this bit set but don't turn on any dual
1261 * source blend factors.
1263 bool dual_src_blend
= false;
1264 if (wm_prog_data
->dual_src_blend
) {
1265 for (uint32_t i
= 0; i
< blend
->attachmentCount
; i
++) {
1266 const VkPipelineColorBlendAttachmentState
*bstate
=
1267 &blend
->pAttachments
[i
];
1269 if (bstate
->blendEnable
&&
1270 (is_dual_src_blend_factor(bstate
->srcColorBlendFactor
) ||
1271 is_dual_src_blend_factor(bstate
->dstColorBlendFactor
) ||
1272 is_dual_src_blend_factor(bstate
->srcAlphaBlendFactor
) ||
1273 is_dual_src_blend_factor(bstate
->dstAlphaBlendFactor
))) {
1274 dual_src_blend
= true;
1281 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS
), ps
) {
1282 ps
.KernelStartPointer0
= fs_bin
->kernel
.offset
;
1283 ps
.KernelStartPointer1
= 0;
1284 ps
.KernelStartPointer2
= fs_bin
->kernel
.offset
+
1285 wm_prog_data
->prog_offset_2
;
1286 ps
._8PixelDispatchEnable
= wm_prog_data
->dispatch_8
;
1287 ps
._16PixelDispatchEnable
= wm_prog_data
->dispatch_16
;
1288 ps
._32PixelDispatchEnable
= false;
1290 ps
.SingleProgramFlow
= false;
1291 ps
.VectorMaskEnable
= true;
1292 ps
.SamplerCount
= get_sampler_count(fs_bin
);
1293 ps
.BindingTableEntryCount
= get_binding_table_entry_count(fs_bin
);
1294 ps
.PushConstantEnable
= wm_prog_data
->base
.nr_params
> 0;
1295 ps
.PositionXYOffsetSelect
= wm_prog_data
->uses_pos_offset
?
1296 POSOFFSET_SAMPLE
: POSOFFSET_NONE
;
1298 ps
.AttributeEnable
= wm_prog_data
->num_varying_inputs
> 0;
1299 ps
.oMaskPresenttoRenderTarget
= wm_prog_data
->uses_omask
;
1300 ps
.DualSourceBlendEnable
= dual_src_blend
;
1304 /* Haswell requires the sample mask to be set in this packet as well
1305 * as in 3DSTATE_SAMPLE_MASK; the values should match.
1307 ps
.SampleMask
= 0xff;
1311 ps
.MaximumNumberofThreadsPerPSD
= 64 - 1;
1313 ps
.MaximumNumberofThreadsPerPSD
= 64 - 2;
1315 ps
.MaximumNumberofThreads
= devinfo
->max_wm_threads
- 1;
1318 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
1319 wm_prog_data
->base
.dispatch_grf_start_reg
;
1320 ps
.DispatchGRFStartRegisterForConstantSetupData1
= 0;
1321 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
1322 wm_prog_data
->dispatch_grf_start_reg_2
;
1324 ps
.PerThreadScratchSpace
= get_scratch_space(fs_bin
);
1325 ps
.ScratchSpaceBasePointer
=
1326 get_scratch_address(pipeline
, MESA_SHADER_FRAGMENT
, fs_bin
);
1331 has_color_buffer_write_enabled(const struct anv_pipeline
*pipeline
)
1333 const struct anv_shader_bin
*shader_bin
=
1334 pipeline
->shaders
[MESA_SHADER_FRAGMENT
];
1338 const struct anv_pipeline_bind_map
*bind_map
= &shader_bin
->bind_map
;
1339 for (int i
= 0; i
< bind_map
->surface_count
; i
++) {
1340 if (bind_map
->surface_to_descriptor
[i
].set
!=
1341 ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS
)
1343 if (bind_map
->surface_to_descriptor
[i
].index
!= UINT8_MAX
)
1352 emit_3dstate_ps_extra(struct anv_pipeline
*pipeline
,
1353 struct anv_subpass
*subpass
)
1355 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
1357 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
1358 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS_EXTRA
), ps
);
1362 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS_EXTRA
), ps
) {
1363 ps
.PixelShaderValid
= true;
1364 ps
.AttributeEnable
= wm_prog_data
->num_varying_inputs
> 0;
1365 ps
.oMaskPresenttoRenderTarget
= wm_prog_data
->uses_omask
;
1366 ps
.PixelShaderIsPerSample
= wm_prog_data
->persample_dispatch
;
1367 ps
.PixelShaderComputedDepthMode
= wm_prog_data
->computed_depth_mode
;
1368 ps
.PixelShaderUsesSourceDepth
= wm_prog_data
->uses_src_depth
;
1369 ps
.PixelShaderUsesSourceW
= wm_prog_data
->uses_src_w
;
1371 /* If the subpass has a depth or stencil self-dependency, then we need
1372 * to force the hardware to do the depth/stencil write *after* fragment
1373 * shader execution. Otherwise, the writes may hit memory before we get
1374 * around to fetching from the input attachment and we may get the depth
1375 * or stencil value from the current draw rather than the previous one.
1377 ps
.PixelShaderKillsPixel
= subpass
->has_ds_self_dep
||
1378 wm_prog_data
->uses_kill
;
1380 /* The stricter cross-primitive coherency guarantees that the hardware
1381 * gives us with the "Accesses UAV" bit set for at least one shader stage
1382 * and the "UAV coherency required" bit set on the 3DPRIMITIVE command are
1383 * redundant within the current image, atomic counter and SSBO GL APIs,
1384 * which all have very loose ordering and coherency requirements and
1385 * generally rely on the application to insert explicit barriers when a
1386 * shader invocation is expected to see the memory writes performed by the
1387 * invocations of some previous primitive. Regardless of the value of
1388 * "UAV coherency required", the "Accesses UAV" bits will implicitly cause
1389 * an in most cases useless DC flush when the lowermost stage with the bit
1390 * set finishes execution.
1392 * It would be nice to disable it, but in some cases we can't because on
1393 * Gen8+ it also has an influence on rasterization via the PS UAV-only
1394 * signal (which could be set independently from the coherency mechanism
1395 * in the 3DSTATE_WM command on Gen7), and because in some cases it will
1396 * determine whether the hardware skips execution of the fragment shader
1397 * or not via the ThreadDispatchEnable signal. However if we know that
1398 * GEN8_PS_BLEND_HAS_WRITEABLE_RT is going to be set and
1399 * GEN8_PSX_PIXEL_SHADER_NO_RT_WRITE is not set it shouldn't make any
1400 * difference so we may just disable it here.
1402 * Gen8 hardware tries to compute ThreadDispatchEnable for us but doesn't
1403 * take into account KillPixels when no depth or stencil writes are
1404 * enabled. In order for occlusion queries to work correctly with no
1405 * attachments, we need to force-enable here.
1407 if ((wm_prog_data
->has_side_effects
|| wm_prog_data
->uses_kill
) &&
1408 !has_color_buffer_write_enabled(pipeline
))
1409 ps
.PixelShaderHasUAV
= true;
1412 ps
.PixelShaderPullsBary
= wm_prog_data
->pulls_bary
;
1413 ps
.InputCoverageMaskState
= wm_prog_data
->uses_sample_mask
?
1414 ICMS_INNER_CONSERVATIVE
: ICMS_NONE
;
1416 ps
.PixelShaderUsesInputCoverageMask
= wm_prog_data
->uses_sample_mask
;
1422 emit_3dstate_vf_topology(struct anv_pipeline
*pipeline
)
1424 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VF_TOPOLOGY
), vft
) {
1425 vft
.PrimitiveTopologyType
= pipeline
->topology
;
1431 genX(graphics_pipeline_create
)(
1433 struct anv_pipeline_cache
* cache
,
1434 const VkGraphicsPipelineCreateInfo
* pCreateInfo
,
1435 const VkAllocationCallbacks
* pAllocator
,
1436 VkPipeline
* pPipeline
)
1438 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1439 ANV_FROM_HANDLE(anv_render_pass
, pass
, pCreateInfo
->renderPass
);
1440 struct anv_subpass
*subpass
= &pass
->subpasses
[pCreateInfo
->subpass
];
1441 struct anv_pipeline
*pipeline
;
1444 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
);
1446 pipeline
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*pipeline
), 8,
1447 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1448 if (pipeline
== NULL
)
1449 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1451 result
= anv_pipeline_init(pipeline
, device
, cache
,
1452 pCreateInfo
, pAllocator
);
1453 if (result
!= VK_SUCCESS
) {
1454 vk_free2(&device
->alloc
, pAllocator
, pipeline
);
1458 assert(pCreateInfo
->pVertexInputState
);
1459 emit_vertex_input(pipeline
, pCreateInfo
->pVertexInputState
);
1460 assert(pCreateInfo
->pRasterizationState
);
1461 emit_rs_state(pipeline
, pCreateInfo
->pRasterizationState
,
1462 pCreateInfo
->pMultisampleState
, pass
, subpass
);
1463 emit_ms_state(pipeline
, pCreateInfo
->pMultisampleState
);
1464 emit_ds_state(pipeline
, pCreateInfo
->pDepthStencilState
, pass
, subpass
);
1465 emit_cb_state(pipeline
, pCreateInfo
->pColorBlendState
,
1466 pCreateInfo
->pMultisampleState
);
1468 emit_urb_setup(pipeline
);
1470 emit_3dstate_clip(pipeline
, pCreateInfo
->pViewportState
,
1471 pCreateInfo
->pRasterizationState
);
1472 emit_3dstate_streamout(pipeline
, pCreateInfo
->pRasterizationState
);
1475 /* From gen7_vs_state.c */
1478 * From Graphics BSpec: 3D-Media-GPGPU Engine > 3D Pipeline Stages >
1479 * Geometry > Geometry Shader > State:
1481 * "Note: Because of corruption in IVB:GT2, software needs to flush the
1482 * whole fixed function pipeline when the GS enable changes value in
1485 * The hardware architects have clarified that in this context "flush the
1486 * whole fixed function pipeline" means to emit a PIPE_CONTROL with the "CS
1489 if (!brw
->is_haswell
&& !brw
->is_baytrail
)
1490 gen7_emit_vs_workaround_flush(brw
);
1493 emit_3dstate_vs(pipeline
);
1494 emit_3dstate_hs_te_ds(pipeline
);
1495 emit_3dstate_gs(pipeline
);
1496 emit_3dstate_sbe(pipeline
);
1497 emit_3dstate_wm(pipeline
, subpass
, pCreateInfo
->pMultisampleState
);
1498 emit_3dstate_ps(pipeline
, pCreateInfo
->pColorBlendState
);
1500 emit_3dstate_ps_extra(pipeline
, subpass
);
1501 emit_3dstate_vf_topology(pipeline
);
1504 *pPipeline
= anv_pipeline_to_handle(pipeline
);
1510 compute_pipeline_create(
1512 struct anv_pipeline_cache
* cache
,
1513 const VkComputePipelineCreateInfo
* pCreateInfo
,
1514 const VkAllocationCallbacks
* pAllocator
,
1515 VkPipeline
* pPipeline
)
1517 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1518 const struct anv_physical_device
*physical_device
=
1519 &device
->instance
->physicalDevice
;
1520 const struct gen_device_info
*devinfo
= &physical_device
->info
;
1521 struct anv_pipeline
*pipeline
;
1524 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO
);
1526 pipeline
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*pipeline
), 8,
1527 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1528 if (pipeline
== NULL
)
1529 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1531 pipeline
->device
= device
;
1532 pipeline
->layout
= anv_pipeline_layout_from_handle(pCreateInfo
->layout
);
1534 pipeline
->blend_state
.map
= NULL
;
1536 result
= anv_reloc_list_init(&pipeline
->batch_relocs
,
1537 pAllocator
? pAllocator
: &device
->alloc
);
1538 if (result
!= VK_SUCCESS
) {
1539 vk_free2(&device
->alloc
, pAllocator
, pipeline
);
1542 pipeline
->batch
.next
= pipeline
->batch
.start
= pipeline
->batch_data
;
1543 pipeline
->batch
.end
= pipeline
->batch
.start
+ sizeof(pipeline
->batch_data
);
1544 pipeline
->batch
.relocs
= &pipeline
->batch_relocs
;
1546 /* When we free the pipeline, we detect stages based on the NULL status
1547 * of various prog_data pointers. Make them NULL by default.
1549 memset(pipeline
->shaders
, 0, sizeof(pipeline
->shaders
));
1551 pipeline
->active_stages
= 0;
1553 pipeline
->needs_data_cache
= false;
1555 assert(pCreateInfo
->stage
.stage
== VK_SHADER_STAGE_COMPUTE_BIT
);
1556 ANV_FROM_HANDLE(anv_shader_module
, module
, pCreateInfo
->stage
.module
);
1557 result
= anv_pipeline_compile_cs(pipeline
, cache
, pCreateInfo
, module
,
1558 pCreateInfo
->stage
.pName
,
1559 pCreateInfo
->stage
.pSpecializationInfo
);
1560 if (result
!= VK_SUCCESS
) {
1561 vk_free2(&device
->alloc
, pAllocator
, pipeline
);
1565 const struct brw_cs_prog_data
*cs_prog_data
= get_cs_prog_data(pipeline
);
1567 anv_pipeline_setup_l3_config(pipeline
, cs_prog_data
->base
.total_shared
> 0);
1569 uint32_t group_size
= cs_prog_data
->local_size
[0] *
1570 cs_prog_data
->local_size
[1] * cs_prog_data
->local_size
[2];
1571 uint32_t remainder
= group_size
& (cs_prog_data
->simd_size
- 1);
1574 pipeline
->cs_right_mask
= ~0u >> (32 - remainder
);
1576 pipeline
->cs_right_mask
= ~0u >> (32 - cs_prog_data
->simd_size
);
1578 const uint32_t vfe_curbe_allocation
=
1579 ALIGN(cs_prog_data
->push
.per_thread
.regs
* cs_prog_data
->threads
+
1580 cs_prog_data
->push
.cross_thread
.regs
, 2);
1582 const uint32_t subslices
= MAX2(physical_device
->subslice_total
, 1);
1584 const struct anv_shader_bin
*cs_bin
=
1585 pipeline
->shaders
[MESA_SHADER_COMPUTE
];
1587 anv_batch_emit(&pipeline
->batch
, GENX(MEDIA_VFE_STATE
), vfe
) {
1591 vfe
.GPGPUMode
= true;
1593 vfe
.MaximumNumberofThreads
=
1594 devinfo
->max_cs_threads
* subslices
- 1;
1595 vfe
.NumberofURBEntries
= GEN_GEN
<= 7 ? 0 : 2;
1596 vfe
.ResetGatewayTimer
= true;
1598 vfe
.BypassGatewayControl
= true;
1600 vfe
.URBEntryAllocationSize
= GEN_GEN
<= 7 ? 0 : 2;
1601 vfe
.CURBEAllocationSize
= vfe_curbe_allocation
;
1603 vfe
.PerThreadScratchSpace
= get_scratch_space(cs_bin
);
1604 vfe
.ScratchSpaceBasePointer
=
1605 get_scratch_address(pipeline
, MESA_SHADER_COMPUTE
, cs_bin
);
1608 struct GENX(INTERFACE_DESCRIPTOR_DATA
) desc
= {
1609 .KernelStartPointer
= cs_bin
->kernel
.offset
,
1611 .SamplerCount
= get_sampler_count(cs_bin
),
1612 .BindingTableEntryCount
= get_binding_table_entry_count(cs_bin
),
1613 .BarrierEnable
= cs_prog_data
->uses_barrier
,
1614 .SharedLocalMemorySize
=
1615 encode_slm_size(GEN_GEN
, cs_prog_data
->base
.total_shared
),
1618 .ConstantURBEntryReadOffset
= 0,
1620 .ConstantURBEntryReadLength
= cs_prog_data
->push
.per_thread
.regs
,
1621 #if GEN_GEN >= 8 || GEN_IS_HASWELL
1622 .CrossThreadConstantDataReadLength
=
1623 cs_prog_data
->push
.cross_thread
.regs
,
1626 .NumberofThreadsinGPGPUThreadGroup
= cs_prog_data
->threads
,
1628 GENX(INTERFACE_DESCRIPTOR_DATA_pack
)(NULL
,
1629 pipeline
->interface_descriptor_data
,
1632 *pPipeline
= anv_pipeline_to_handle(pipeline
);
1637 VkResult
genX(CreateGraphicsPipelines
)(
1639 VkPipelineCache pipelineCache
,
1641 const VkGraphicsPipelineCreateInfo
* pCreateInfos
,
1642 const VkAllocationCallbacks
* pAllocator
,
1643 VkPipeline
* pPipelines
)
1645 ANV_FROM_HANDLE(anv_pipeline_cache
, pipeline_cache
, pipelineCache
);
1647 VkResult result
= VK_SUCCESS
;
1650 for (i
= 0; i
< count
; i
++) {
1651 result
= genX(graphics_pipeline_create
)(_device
,
1654 pAllocator
, &pPipelines
[i
]);
1656 /* Bail out on the first error as it is not obvious what error should be
1657 * report upon 2 different failures. */
1658 if (result
!= VK_SUCCESS
)
1662 for (; i
< count
; i
++)
1663 pPipelines
[i
] = VK_NULL_HANDLE
;
1668 VkResult
genX(CreateComputePipelines
)(
1670 VkPipelineCache pipelineCache
,
1672 const VkComputePipelineCreateInfo
* pCreateInfos
,
1673 const VkAllocationCallbacks
* pAllocator
,
1674 VkPipeline
* pPipelines
)
1676 ANV_FROM_HANDLE(anv_pipeline_cache
, pipeline_cache
, pipelineCache
);
1678 VkResult result
= VK_SUCCESS
;
1681 for (i
= 0; i
< count
; i
++) {
1682 result
= compute_pipeline_create(_device
, pipeline_cache
,
1684 pAllocator
, &pPipelines
[i
]);
1686 /* Bail out on the first error as it is not obvious what error should be
1687 * report upon 2 different failures. */
1688 if (result
!= VK_SUCCESS
)
1692 for (; i
< count
; i
++)
1693 pPipelines
[i
] = VK_NULL_HANDLE
;