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
);
289 const struct brw_vue_map
*fs_input_map
;
291 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
292 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_SBE
), sbe
);
294 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_SBE_SWIZ
), sbe
);
299 fs_input_map
= anv_pipeline_get_fs_input_map(pipeline
);
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;
423 sf
.PointWidthSource
= Vertex
;
427 struct GENX(3DSTATE_RASTER
) raster
= {
428 GENX(3DSTATE_RASTER_header
),
434 /* For details on 3DSTATE_RASTER multisample state, see the BSpec table
435 * "Multisample Modes State".
438 raster
.DXMultisampleRasterizationEnable
= true;
439 raster
.ForcedSampleCount
= FSC_NUMRASTSAMPLES_0
;
440 raster
.ForceMultisampling
= false;
442 raster
.MultisampleRasterizationMode
=
443 (ms_info
&& ms_info
->rasterizationSamples
> 1) ?
444 MSRASTMODE_ON_PATTERN
: MSRASTMODE_OFF_PIXEL
;
447 raster
.FrontWinding
= vk_to_gen_front_face
[rs_info
->frontFace
];
448 raster
.CullMode
= vk_to_gen_cullmode
[rs_info
->cullMode
];
449 raster
.FrontFaceFillMode
= vk_to_gen_fillmode
[rs_info
->polygonMode
];
450 raster
.BackFaceFillMode
= vk_to_gen_fillmode
[rs_info
->polygonMode
];
451 raster
.ScissorRectangleEnable
= true;
454 /* GEN9+ splits ViewportZClipTestEnable into near and far enable bits */
455 raster
.ViewportZFarClipTestEnable
= !pipeline
->depth_clamp_enable
;
456 raster
.ViewportZNearClipTestEnable
= !pipeline
->depth_clamp_enable
;
458 raster
.ViewportZClipTestEnable
= !pipeline
->depth_clamp_enable
;
461 raster
.GlobalDepthOffsetEnableSolid
= rs_info
->depthBiasEnable
;
462 raster
.GlobalDepthOffsetEnableWireframe
= rs_info
->depthBiasEnable
;
463 raster
.GlobalDepthOffsetEnablePoint
= rs_info
->depthBiasEnable
;
466 /* Gen7 requires that we provide the depth format in 3DSTATE_SF so that it
467 * can get the depth offsets correct.
469 if (subpass
->depth_stencil_attachment
< pass
->attachment_count
) {
471 pass
->attachments
[subpass
->depth_stencil_attachment
].format
;
472 assert(vk_format_is_depth_or_stencil(vk_format
));
473 if (vk_format_aspects(vk_format
) & VK_IMAGE_ASPECT_DEPTH_BIT
) {
474 enum isl_format isl_format
=
475 anv_get_isl_format(&pipeline
->device
->info
, vk_format
,
476 VK_IMAGE_ASPECT_DEPTH_BIT
,
477 VK_IMAGE_TILING_OPTIMAL
);
478 sf
.DepthBufferSurfaceFormat
=
479 isl_format_get_depth_format(isl_format
, false);
485 GENX(3DSTATE_SF_pack
)(NULL
, pipeline
->gen8
.sf
, &sf
);
486 GENX(3DSTATE_RASTER_pack
)(NULL
, pipeline
->gen8
.raster
, &raster
);
489 GENX(3DSTATE_SF_pack
)(NULL
, &pipeline
->gen7
.sf
, &sf
);
494 emit_ms_state(struct anv_pipeline
*pipeline
,
495 const VkPipelineMultisampleStateCreateInfo
*info
)
497 uint32_t samples
= 1;
498 uint32_t log2_samples
= 0;
500 /* From the Vulkan 1.0 spec:
501 * If pSampleMask is NULL, it is treated as if the mask has all bits
502 * enabled, i.e. no coverage is removed from fragments.
504 * 3DSTATE_SAMPLE_MASK.SampleMask is 16 bits.
507 uint32_t sample_mask
= 0xffff;
509 uint32_t sample_mask
= 0xff;
513 samples
= info
->rasterizationSamples
;
514 log2_samples
= __builtin_ffs(samples
) - 1;
517 if (info
&& info
->pSampleMask
)
518 sample_mask
&= info
->pSampleMask
[0];
520 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_MULTISAMPLE
), ms
) {
521 ms
.NumberofMultisamples
= log2_samples
;
524 /* The PRM says that this bit is valid only for DX9:
526 * SW can choose to set this bit only for DX9 API. DX10/OGL API's
527 * should not have any effect by setting or not setting this bit.
529 ms
.PixelPositionOffsetEnable
= false;
530 ms
.PixelLocation
= CENTER
;
532 ms
.PixelLocation
= PIXLOC_CENTER
;
536 GEN_SAMPLE_POS_1X(ms
.Sample
);
539 GEN_SAMPLE_POS_2X(ms
.Sample
);
542 GEN_SAMPLE_POS_4X(ms
.Sample
);
545 GEN_SAMPLE_POS_8X(ms
.Sample
);
553 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_SAMPLE_MASK
), sm
) {
554 sm
.SampleMask
= sample_mask
;
558 static const uint32_t vk_to_gen_logic_op
[] = {
559 [VK_LOGIC_OP_COPY
] = LOGICOP_COPY
,
560 [VK_LOGIC_OP_CLEAR
] = LOGICOP_CLEAR
,
561 [VK_LOGIC_OP_AND
] = LOGICOP_AND
,
562 [VK_LOGIC_OP_AND_REVERSE
] = LOGICOP_AND_REVERSE
,
563 [VK_LOGIC_OP_AND_INVERTED
] = LOGICOP_AND_INVERTED
,
564 [VK_LOGIC_OP_NO_OP
] = LOGICOP_NOOP
,
565 [VK_LOGIC_OP_XOR
] = LOGICOP_XOR
,
566 [VK_LOGIC_OP_OR
] = LOGICOP_OR
,
567 [VK_LOGIC_OP_NOR
] = LOGICOP_NOR
,
568 [VK_LOGIC_OP_EQUIVALENT
] = LOGICOP_EQUIV
,
569 [VK_LOGIC_OP_INVERT
] = LOGICOP_INVERT
,
570 [VK_LOGIC_OP_OR_REVERSE
] = LOGICOP_OR_REVERSE
,
571 [VK_LOGIC_OP_COPY_INVERTED
] = LOGICOP_COPY_INVERTED
,
572 [VK_LOGIC_OP_OR_INVERTED
] = LOGICOP_OR_INVERTED
,
573 [VK_LOGIC_OP_NAND
] = LOGICOP_NAND
,
574 [VK_LOGIC_OP_SET
] = LOGICOP_SET
,
577 static const uint32_t vk_to_gen_blend
[] = {
578 [VK_BLEND_FACTOR_ZERO
] = BLENDFACTOR_ZERO
,
579 [VK_BLEND_FACTOR_ONE
] = BLENDFACTOR_ONE
,
580 [VK_BLEND_FACTOR_SRC_COLOR
] = BLENDFACTOR_SRC_COLOR
,
581 [VK_BLEND_FACTOR_ONE_MINUS_SRC_COLOR
] = BLENDFACTOR_INV_SRC_COLOR
,
582 [VK_BLEND_FACTOR_DST_COLOR
] = BLENDFACTOR_DST_COLOR
,
583 [VK_BLEND_FACTOR_ONE_MINUS_DST_COLOR
] = BLENDFACTOR_INV_DST_COLOR
,
584 [VK_BLEND_FACTOR_SRC_ALPHA
] = BLENDFACTOR_SRC_ALPHA
,
585 [VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
] = BLENDFACTOR_INV_SRC_ALPHA
,
586 [VK_BLEND_FACTOR_DST_ALPHA
] = BLENDFACTOR_DST_ALPHA
,
587 [VK_BLEND_FACTOR_ONE_MINUS_DST_ALPHA
] = BLENDFACTOR_INV_DST_ALPHA
,
588 [VK_BLEND_FACTOR_CONSTANT_COLOR
] = BLENDFACTOR_CONST_COLOR
,
589 [VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR
]= BLENDFACTOR_INV_CONST_COLOR
,
590 [VK_BLEND_FACTOR_CONSTANT_ALPHA
] = BLENDFACTOR_CONST_ALPHA
,
591 [VK_BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA
]= BLENDFACTOR_INV_CONST_ALPHA
,
592 [VK_BLEND_FACTOR_SRC_ALPHA_SATURATE
] = BLENDFACTOR_SRC_ALPHA_SATURATE
,
593 [VK_BLEND_FACTOR_SRC1_COLOR
] = BLENDFACTOR_SRC1_COLOR
,
594 [VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR
] = BLENDFACTOR_INV_SRC1_COLOR
,
595 [VK_BLEND_FACTOR_SRC1_ALPHA
] = BLENDFACTOR_SRC1_ALPHA
,
596 [VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA
] = BLENDFACTOR_INV_SRC1_ALPHA
,
599 static const uint32_t vk_to_gen_blend_op
[] = {
600 [VK_BLEND_OP_ADD
] = BLENDFUNCTION_ADD
,
601 [VK_BLEND_OP_SUBTRACT
] = BLENDFUNCTION_SUBTRACT
,
602 [VK_BLEND_OP_REVERSE_SUBTRACT
] = BLENDFUNCTION_REVERSE_SUBTRACT
,
603 [VK_BLEND_OP_MIN
] = BLENDFUNCTION_MIN
,
604 [VK_BLEND_OP_MAX
] = BLENDFUNCTION_MAX
,
607 static const uint32_t vk_to_gen_compare_op
[] = {
608 [VK_COMPARE_OP_NEVER
] = PREFILTEROPNEVER
,
609 [VK_COMPARE_OP_LESS
] = PREFILTEROPLESS
,
610 [VK_COMPARE_OP_EQUAL
] = PREFILTEROPEQUAL
,
611 [VK_COMPARE_OP_LESS_OR_EQUAL
] = PREFILTEROPLEQUAL
,
612 [VK_COMPARE_OP_GREATER
] = PREFILTEROPGREATER
,
613 [VK_COMPARE_OP_NOT_EQUAL
] = PREFILTEROPNOTEQUAL
,
614 [VK_COMPARE_OP_GREATER_OR_EQUAL
] = PREFILTEROPGEQUAL
,
615 [VK_COMPARE_OP_ALWAYS
] = PREFILTEROPALWAYS
,
618 static const uint32_t vk_to_gen_stencil_op
[] = {
619 [VK_STENCIL_OP_KEEP
] = STENCILOP_KEEP
,
620 [VK_STENCIL_OP_ZERO
] = STENCILOP_ZERO
,
621 [VK_STENCIL_OP_REPLACE
] = STENCILOP_REPLACE
,
622 [VK_STENCIL_OP_INCREMENT_AND_CLAMP
] = STENCILOP_INCRSAT
,
623 [VK_STENCIL_OP_DECREMENT_AND_CLAMP
] = STENCILOP_DECRSAT
,
624 [VK_STENCIL_OP_INVERT
] = STENCILOP_INVERT
,
625 [VK_STENCIL_OP_INCREMENT_AND_WRAP
] = STENCILOP_INCR
,
626 [VK_STENCIL_OP_DECREMENT_AND_WRAP
] = STENCILOP_DECR
,
630 emit_ds_state(struct anv_pipeline
*pipeline
,
631 const VkPipelineDepthStencilStateCreateInfo
*info
,
632 const struct anv_render_pass
*pass
,
633 const struct anv_subpass
*subpass
)
636 # define depth_stencil_dw pipeline->gen7.depth_stencil_state
638 # define depth_stencil_dw pipeline->gen8.wm_depth_stencil
640 # define depth_stencil_dw pipeline->gen9.wm_depth_stencil
644 /* We're going to OR this together with the dynamic state. We need
645 * to make sure it's initialized to something useful.
647 memset(depth_stencil_dw
, 0, sizeof(depth_stencil_dw
));
651 /* VkBool32 depthBoundsTestEnable; // optional (depth_bounds_test) */
654 struct GENX(DEPTH_STENCIL_STATE
) depth_stencil
= {
656 struct GENX(3DSTATE_WM_DEPTH_STENCIL
) depth_stencil
= {
658 .DepthTestEnable
= info
->depthTestEnable
,
659 .DepthBufferWriteEnable
= info
->depthWriteEnable
,
660 .DepthTestFunction
= vk_to_gen_compare_op
[info
->depthCompareOp
],
661 .DoubleSidedStencilEnable
= true,
663 .StencilTestEnable
= info
->stencilTestEnable
,
664 .StencilBufferWriteEnable
= info
->stencilTestEnable
,
665 .StencilFailOp
= vk_to_gen_stencil_op
[info
->front
.failOp
],
666 .StencilPassDepthPassOp
= vk_to_gen_stencil_op
[info
->front
.passOp
],
667 .StencilPassDepthFailOp
= vk_to_gen_stencil_op
[info
->front
.depthFailOp
],
668 .StencilTestFunction
= vk_to_gen_compare_op
[info
->front
.compareOp
],
669 .BackfaceStencilFailOp
= vk_to_gen_stencil_op
[info
->back
.failOp
],
670 .BackfaceStencilPassDepthPassOp
= vk_to_gen_stencil_op
[info
->back
.passOp
],
671 .BackfaceStencilPassDepthFailOp
=vk_to_gen_stencil_op
[info
->back
.depthFailOp
],
672 .BackfaceStencilTestFunction
= vk_to_gen_compare_op
[info
->back
.compareOp
],
675 VkImageAspectFlags aspects
= 0;
676 if (subpass
->depth_stencil_attachment
!= VK_ATTACHMENT_UNUSED
) {
677 VkFormat depth_stencil_format
=
678 pass
->attachments
[subpass
->depth_stencil_attachment
].format
;
679 aspects
= vk_format_aspects(depth_stencil_format
);
682 /* The Vulkan spec requires that if either depth or stencil is not present,
683 * the pipeline is to act as if the test silently passes.
685 if (!(aspects
& VK_IMAGE_ASPECT_DEPTH_BIT
)) {
686 depth_stencil
.DepthBufferWriteEnable
= false;
687 depth_stencil
.DepthTestFunction
= PREFILTEROPALWAYS
;
690 if (!(aspects
& VK_IMAGE_ASPECT_STENCIL_BIT
)) {
691 depth_stencil
.StencilBufferWriteEnable
= false;
692 depth_stencil
.StencilTestFunction
= PREFILTEROPALWAYS
;
693 depth_stencil
.BackfaceStencilTestFunction
= PREFILTEROPALWAYS
;
696 /* From the Broadwell PRM:
698 * "If Depth_Test_Enable = 1 AND Depth_Test_func = EQUAL, the
699 * Depth_Write_Enable must be set to 0."
701 if (info
->depthTestEnable
&& info
->depthCompareOp
== VK_COMPARE_OP_EQUAL
)
702 depth_stencil
.DepthBufferWriteEnable
= false;
705 GENX(DEPTH_STENCIL_STATE_pack
)(NULL
, depth_stencil_dw
, &depth_stencil
);
707 GENX(3DSTATE_WM_DEPTH_STENCIL_pack
)(NULL
, depth_stencil_dw
, &depth_stencil
);
712 emit_cb_state(struct anv_pipeline
*pipeline
,
713 const VkPipelineColorBlendStateCreateInfo
*info
,
714 const VkPipelineMultisampleStateCreateInfo
*ms_info
)
716 struct anv_device
*device
= pipeline
->device
;
718 const uint32_t num_dwords
= GENX(BLEND_STATE_length
);
719 pipeline
->blend_state
=
720 anv_state_pool_alloc(&device
->dynamic_state_pool
, num_dwords
* 4, 64);
722 struct GENX(BLEND_STATE
) blend_state
= {
724 .AlphaToCoverageEnable
= ms_info
&& ms_info
->alphaToCoverageEnable
,
725 .AlphaToOneEnable
= ms_info
&& ms_info
->alphaToOneEnable
,
727 /* Make sure it gets zeroed */
728 .Entry
= { { 0, }, },
732 /* Default everything to disabled */
733 for (uint32_t i
= 0; i
< 8; i
++) {
734 blend_state
.Entry
[i
].WriteDisableAlpha
= true;
735 blend_state
.Entry
[i
].WriteDisableRed
= true;
736 blend_state
.Entry
[i
].WriteDisableGreen
= true;
737 blend_state
.Entry
[i
].WriteDisableBlue
= true;
740 uint32_t surface_count
= 0;
741 struct anv_pipeline_bind_map
*map
;
742 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
743 map
= &pipeline
->shaders
[MESA_SHADER_FRAGMENT
]->bind_map
;
744 surface_count
= map
->surface_count
;
747 bool has_writeable_rt
= false;
748 for (unsigned i
= 0; i
< surface_count
; i
++) {
749 struct anv_pipeline_binding
*binding
= &map
->surface_to_descriptor
[i
];
751 /* All color attachments are at the beginning of the binding table */
752 if (binding
->set
!= ANV_DESCRIPTOR_SET_COLOR_ATTACHMENTS
)
755 /* We can have at most 8 attachments */
758 if (binding
->index
>= info
->attachmentCount
)
761 assert(binding
->binding
== 0);
762 const VkPipelineColorBlendAttachmentState
*a
=
763 &info
->pAttachments
[binding
->index
];
765 blend_state
.Entry
[i
] = (struct GENX(BLEND_STATE_ENTRY
)) {
767 .AlphaToCoverageEnable
= ms_info
&& ms_info
->alphaToCoverageEnable
,
768 .AlphaToOneEnable
= ms_info
&& ms_info
->alphaToOneEnable
,
770 .LogicOpEnable
= info
->logicOpEnable
,
771 .LogicOpFunction
= vk_to_gen_logic_op
[info
->logicOp
],
772 .ColorBufferBlendEnable
= a
->blendEnable
,
773 .ColorClampRange
= COLORCLAMP_RTFORMAT
,
774 .PreBlendColorClampEnable
= true,
775 .PostBlendColorClampEnable
= true,
776 .SourceBlendFactor
= vk_to_gen_blend
[a
->srcColorBlendFactor
],
777 .DestinationBlendFactor
= vk_to_gen_blend
[a
->dstColorBlendFactor
],
778 .ColorBlendFunction
= vk_to_gen_blend_op
[a
->colorBlendOp
],
779 .SourceAlphaBlendFactor
= vk_to_gen_blend
[a
->srcAlphaBlendFactor
],
780 .DestinationAlphaBlendFactor
= vk_to_gen_blend
[a
->dstAlphaBlendFactor
],
781 .AlphaBlendFunction
= vk_to_gen_blend_op
[a
->alphaBlendOp
],
782 .WriteDisableAlpha
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_A_BIT
),
783 .WriteDisableRed
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_R_BIT
),
784 .WriteDisableGreen
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_G_BIT
),
785 .WriteDisableBlue
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_B_BIT
),
788 if (a
->srcColorBlendFactor
!= a
->srcAlphaBlendFactor
||
789 a
->dstColorBlendFactor
!= a
->dstAlphaBlendFactor
||
790 a
->colorBlendOp
!= a
->alphaBlendOp
) {
792 blend_state
.IndependentAlphaBlendEnable
= true;
794 blend_state
.Entry
[i
].IndependentAlphaBlendEnable
= true;
798 if (a
->colorWriteMask
!= 0)
799 has_writeable_rt
= true;
801 /* Our hardware applies the blend factor prior to the blend function
802 * regardless of what function is used. Technically, this means the
803 * hardware can do MORE than GL or Vulkan specify. However, it also
804 * means that, for MIN and MAX, we have to stomp the blend factor to
805 * ONE to make it a no-op.
807 if (a
->colorBlendOp
== VK_BLEND_OP_MIN
||
808 a
->colorBlendOp
== VK_BLEND_OP_MAX
) {
809 blend_state
.Entry
[i
].SourceBlendFactor
= BLENDFACTOR_ONE
;
810 blend_state
.Entry
[i
].DestinationBlendFactor
= BLENDFACTOR_ONE
;
812 if (a
->alphaBlendOp
== VK_BLEND_OP_MIN
||
813 a
->alphaBlendOp
== VK_BLEND_OP_MAX
) {
814 blend_state
.Entry
[i
].SourceAlphaBlendFactor
= BLENDFACTOR_ONE
;
815 blend_state
.Entry
[i
].DestinationAlphaBlendFactor
= BLENDFACTOR_ONE
;
820 struct GENX(BLEND_STATE_ENTRY
) *bs0
= &blend_state
.Entry
[0];
821 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS_BLEND
), blend
) {
822 blend
.AlphaToCoverageEnable
= blend_state
.AlphaToCoverageEnable
;
823 blend
.HasWriteableRT
= has_writeable_rt
;
824 blend
.ColorBufferBlendEnable
= bs0
->ColorBufferBlendEnable
;
825 blend
.SourceAlphaBlendFactor
= bs0
->SourceAlphaBlendFactor
;
826 blend
.DestinationAlphaBlendFactor
= bs0
->DestinationAlphaBlendFactor
;
827 blend
.SourceBlendFactor
= bs0
->SourceBlendFactor
;
828 blend
.DestinationBlendFactor
= bs0
->DestinationBlendFactor
;
829 blend
.AlphaTestEnable
= false;
830 blend
.IndependentAlphaBlendEnable
=
831 blend_state
.IndependentAlphaBlendEnable
;
834 (void)has_writeable_rt
;
837 GENX(BLEND_STATE_pack
)(NULL
, pipeline
->blend_state
.map
, &blend_state
);
838 if (!device
->info
.has_llc
)
839 anv_state_clflush(pipeline
->blend_state
);
841 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_BLEND_STATE_POINTERS
), bsp
) {
842 bsp
.BlendStatePointer
= pipeline
->blend_state
.offset
;
844 bsp
.BlendStatePointerValid
= true;
850 * Get the brw_vue_prog_data for the last stage which outputs VUEs.
852 static inline struct brw_vue_prog_data
*
853 get_last_vue_prog_data(struct anv_pipeline
*pipeline
)
855 for (int s
= MESA_SHADER_GEOMETRY
; s
>= 0; s
--) {
856 if (pipeline
->shaders
[s
])
857 return (struct brw_vue_prog_data
*) pipeline
->shaders
[s
]->prog_data
;
863 emit_3dstate_clip(struct anv_pipeline
*pipeline
,
864 const VkPipelineViewportStateCreateInfo
*vp_info
,
865 const VkPipelineRasterizationStateCreateInfo
*rs_info
)
867 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
869 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_CLIP
), clip
) {
870 clip
.ClipEnable
= true;
871 clip
.EarlyCullEnable
= true;
872 clip
.APIMode
= APIMODE_D3D
,
873 clip
.ViewportXYClipTestEnable
= true;
875 clip
.ClipMode
= CLIPMODE_NORMAL
;
877 clip
.TriangleStripListProvokingVertexSelect
= 0;
878 clip
.LineStripListProvokingVertexSelect
= 0;
879 clip
.TriangleFanProvokingVertexSelect
= 1;
881 clip
.MinimumPointWidth
= 0.125;
882 clip
.MaximumPointWidth
= 255.875;
883 clip
.MaximumVPIndex
= (vp_info
? vp_info
->viewportCount
: 1) - 1;
886 clip
.FrontWinding
= vk_to_gen_front_face
[rs_info
->frontFace
];
887 clip
.CullMode
= vk_to_gen_cullmode
[rs_info
->cullMode
];
888 clip
.ViewportZClipTestEnable
= !pipeline
->depth_clamp_enable
;
889 const struct brw_vue_prog_data
*last
= get_last_vue_prog_data(pipeline
);
891 clip
.UserClipDistanceClipTestEnableBitmask
= last
->clip_distance_mask
;
892 clip
.UserClipDistanceCullTestEnableBitmask
= last
->cull_distance_mask
;
895 clip
.NonPerspectiveBarycentricEnable
= wm_prog_data
?
896 (wm_prog_data
->barycentric_interp_modes
& 0x38) != 0 : 0;
902 emit_3dstate_streamout(struct anv_pipeline
*pipeline
,
903 const VkPipelineRasterizationStateCreateInfo
*rs_info
)
905 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_STREAMOUT
), so
) {
906 so
.RenderingDisable
= rs_info
->rasterizerDiscardEnable
;
910 static inline uint32_t
911 get_sampler_count(const struct anv_shader_bin
*bin
)
913 return DIV_ROUND_UP(bin
->bind_map
.sampler_count
, 4);
916 static inline uint32_t
917 get_binding_table_entry_count(const struct anv_shader_bin
*bin
)
919 return DIV_ROUND_UP(bin
->bind_map
.surface_count
, 32);
922 static inline struct anv_address
923 get_scratch_address(struct anv_pipeline
*pipeline
,
924 gl_shader_stage stage
,
925 const struct anv_shader_bin
*bin
)
927 return (struct anv_address
) {
928 .bo
= anv_scratch_pool_alloc(pipeline
->device
,
929 &pipeline
->device
->scratch_pool
,
930 stage
, bin
->prog_data
->total_scratch
),
935 static inline uint32_t
936 get_scratch_space(const struct anv_shader_bin
*bin
)
938 return ffs(bin
->prog_data
->total_scratch
/ 2048);
941 static inline uint32_t
942 get_urb_output_offset()
944 /* Skip the VUE header and position slots */
948 static inline uint32_t
949 get_urb_output_length(const struct anv_shader_bin
*bin
)
951 const struct brw_vue_prog_data
*prog_data
=
952 (const struct brw_vue_prog_data
*)bin
->prog_data
;
954 return (prog_data
->vue_map
.num_slots
+ 1) / 2 - get_urb_output_offset();
958 emit_3dstate_vs(struct anv_pipeline
*pipeline
)
960 const struct gen_device_info
*devinfo
= &pipeline
->device
->info
;
961 const struct brw_vs_prog_data
*vs_prog_data
= get_vs_prog_data(pipeline
);
962 const struct anv_shader_bin
*vs_bin
=
963 pipeline
->shaders
[MESA_SHADER_VERTEX
];
965 assert(anv_pipeline_has_stage(pipeline
, MESA_SHADER_VERTEX
));
967 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VS
), vs
) {
968 vs
.FunctionEnable
= true;
969 vs
.StatisticsEnable
= true;
970 vs
.KernelStartPointer
= vs_bin
->kernel
.offset
;
972 vs
.SIMD8DispatchEnable
=
973 vs_prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
;
976 assert(!vs_prog_data
->base
.base
.use_alt_mode
);
977 vs
.SingleVertexDispatch
= false;
978 vs
.VectorMaskEnable
= false;
979 vs
.SamplerCount
= get_sampler_count(vs_bin
);
980 vs
.BindingTableEntryCount
= get_binding_table_entry_count(vs_bin
);
981 vs
.FloatingPointMode
= IEEE754
;
982 vs
.IllegalOpcodeExceptionEnable
= false;
983 vs
.SoftwareExceptionEnable
= false;
984 vs
.MaximumNumberofThreads
= devinfo
->max_vs_threads
- 1;
985 vs
.VertexCacheDisable
= false;
987 vs
.VertexURBEntryReadLength
= vs_prog_data
->base
.urb_read_length
;
988 vs
.VertexURBEntryReadOffset
= 0;
989 vs
.DispatchGRFStartRegisterForURBData
=
990 vs_prog_data
->base
.base
.dispatch_grf_start_reg
;
993 vs
.VertexURBEntryOutputReadOffset
= get_urb_output_offset();
994 vs
.VertexURBEntryOutputLength
= get_urb_output_length(vs_bin
);
996 vs
.UserClipDistanceClipTestEnableBitmask
=
997 vs_prog_data
->base
.clip_distance_mask
;
998 vs
.UserClipDistanceCullTestEnableBitmask
=
999 vs_prog_data
->base
.cull_distance_mask
;
1002 vs
.PerThreadScratchSpace
= get_scratch_space(vs_bin
);
1003 vs
.ScratchSpaceBasePointer
=
1004 get_scratch_address(pipeline
, MESA_SHADER_VERTEX
, vs_bin
);
1009 emit_3dstate_hs_te_ds(struct anv_pipeline
*pipeline
)
1011 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_TESS_EVAL
)) {
1012 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_HS
), hs
);
1013 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_TE
), te
);
1014 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_DS
), ds
);
1018 const struct gen_device_info
*devinfo
= &pipeline
->device
->info
;
1019 const struct anv_shader_bin
*tcs_bin
=
1020 pipeline
->shaders
[MESA_SHADER_TESS_CTRL
];
1021 const struct anv_shader_bin
*tes_bin
=
1022 pipeline
->shaders
[MESA_SHADER_TESS_EVAL
];
1024 const struct brw_tcs_prog_data
*tcs_prog_data
= get_tcs_prog_data(pipeline
);
1025 const struct brw_tes_prog_data
*tes_prog_data
= get_tes_prog_data(pipeline
);
1027 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_HS
), hs
) {
1028 hs
.FunctionEnable
= true;
1029 hs
.StatisticsEnable
= true;
1030 hs
.KernelStartPointer
= tcs_bin
->kernel
.offset
;
1032 hs
.SamplerCount
= get_sampler_count(tcs_bin
);
1033 hs
.BindingTableEntryCount
= get_binding_table_entry_count(tcs_bin
);
1034 hs
.MaximumNumberofThreads
= devinfo
->max_tcs_threads
- 1;
1035 hs
.IncludeVertexHandles
= true;
1036 hs
.InstanceCount
= tcs_prog_data
->instances
- 1;
1038 hs
.VertexURBEntryReadLength
= 0;
1039 hs
.VertexURBEntryReadOffset
= 0;
1040 hs
.DispatchGRFStartRegisterForURBData
=
1041 tcs_prog_data
->base
.base
.dispatch_grf_start_reg
;
1043 hs
.PerThreadScratchSpace
= get_scratch_space(tcs_bin
);
1044 hs
.ScratchSpaceBasePointer
=
1045 get_scratch_address(pipeline
, MESA_SHADER_TESS_CTRL
, tcs_bin
);
1048 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_TE
), te
) {
1049 te
.Partitioning
= tes_prog_data
->partitioning
;
1050 te
.OutputTopology
= tes_prog_data
->output_topology
;
1051 te
.TEDomain
= tes_prog_data
->domain
;
1053 te
.MaximumTessellationFactorOdd
= 63.0;
1054 te
.MaximumTessellationFactorNotOdd
= 64.0;
1057 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_DS
), ds
) {
1058 ds
.FunctionEnable
= true;
1059 ds
.StatisticsEnable
= true;
1060 ds
.KernelStartPointer
= tes_bin
->kernel
.offset
;
1062 ds
.SamplerCount
= get_sampler_count(tes_bin
);
1063 ds
.BindingTableEntryCount
= get_binding_table_entry_count(tes_bin
);
1064 ds
.MaximumNumberofThreads
= devinfo
->max_tes_threads
- 1;
1066 ds
.ComputeWCoordinateEnable
=
1067 tes_prog_data
->domain
== BRW_TESS_DOMAIN_TRI
;
1069 ds
.PatchURBEntryReadLength
= tes_prog_data
->base
.urb_read_length
;
1070 ds
.PatchURBEntryReadOffset
= 0;
1071 ds
.DispatchGRFStartRegisterForURBData
=
1072 tes_prog_data
->base
.base
.dispatch_grf_start_reg
;
1075 ds
.VertexURBEntryOutputReadOffset
= 1;
1076 ds
.VertexURBEntryOutputLength
=
1077 (tes_prog_data
->base
.vue_map
.num_slots
+ 1) / 2 - 1;
1080 tes_prog_data
->base
.dispatch_mode
== DISPATCH_MODE_SIMD8
?
1081 DISPATCH_MODE_SIMD8_SINGLE_PATCH
:
1082 DISPATCH_MODE_SIMD4X2
;
1084 ds
.UserClipDistanceClipTestEnableBitmask
=
1085 tes_prog_data
->base
.clip_distance_mask
;
1086 ds
.UserClipDistanceCullTestEnableBitmask
=
1087 tes_prog_data
->base
.cull_distance_mask
;
1090 ds
.PerThreadScratchSpace
= get_scratch_space(tes_bin
);
1091 ds
.ScratchSpaceBasePointer
=
1092 get_scratch_address(pipeline
, MESA_SHADER_TESS_EVAL
, tes_bin
);
1097 emit_3dstate_gs(struct anv_pipeline
*pipeline
)
1099 const struct gen_device_info
*devinfo
= &pipeline
->device
->info
;
1100 const struct anv_shader_bin
*gs_bin
=
1101 pipeline
->shaders
[MESA_SHADER_GEOMETRY
];
1103 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_GEOMETRY
)) {
1104 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_GS
), gs
);
1108 const struct brw_gs_prog_data
*gs_prog_data
= get_gs_prog_data(pipeline
);
1110 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_GS
), gs
) {
1111 gs
.FunctionEnable
= true;
1112 gs
.StatisticsEnable
= true;
1113 gs
.KernelStartPointer
= gs_bin
->kernel
.offset
;
1114 gs
.DispatchMode
= gs_prog_data
->base
.dispatch_mode
;
1116 gs
.SingleProgramFlow
= false;
1117 gs
.VectorMaskEnable
= false;
1118 gs
.SamplerCount
= get_sampler_count(gs_bin
);
1119 gs
.BindingTableEntryCount
= get_binding_table_entry_count(gs_bin
);
1120 gs
.IncludeVertexHandles
= gs_prog_data
->base
.include_vue_handles
;
1121 gs
.IncludePrimitiveID
= gs_prog_data
->include_primitive_id
;
1124 /* Broadwell is weird. It needs us to divide by 2. */
1125 gs
.MaximumNumberofThreads
= devinfo
->max_gs_threads
/ 2 - 1;
1127 gs
.MaximumNumberofThreads
= devinfo
->max_gs_threads
- 1;
1130 gs
.OutputVertexSize
= gs_prog_data
->output_vertex_size_hwords
* 2 - 1;
1131 gs
.OutputTopology
= gs_prog_data
->output_topology
;
1132 gs
.VertexURBEntryReadLength
= gs_prog_data
->base
.urb_read_length
;
1133 gs
.ControlDataFormat
= gs_prog_data
->control_data_format
;
1134 gs
.ControlDataHeaderSize
= gs_prog_data
->control_data_header_size_hwords
;
1135 gs
.InstanceControl
= MAX2(gs_prog_data
->invocations
, 1) - 1;
1136 #if GEN_GEN >= 8 || GEN_IS_HASWELL
1137 gs
.ReorderMode
= TRAILING
;
1139 gs
.ReorderEnable
= true;
1143 gs
.ExpectedVertexCount
= gs_prog_data
->vertices_in
;
1144 gs
.StaticOutput
= gs_prog_data
->static_vertex_count
>= 0;
1145 gs
.StaticOutputVertexCount
= gs_prog_data
->static_vertex_count
>= 0 ?
1146 gs_prog_data
->static_vertex_count
: 0;
1149 gs
.VertexURBEntryReadOffset
= 0;
1150 gs
.VertexURBEntryReadLength
= gs_prog_data
->base
.urb_read_length
;
1151 gs
.DispatchGRFStartRegisterForURBData
=
1152 gs_prog_data
->base
.base
.dispatch_grf_start_reg
;
1155 gs
.VertexURBEntryOutputReadOffset
= get_urb_output_offset();
1156 gs
.VertexURBEntryOutputLength
= get_urb_output_length(gs_bin
);
1158 gs
.UserClipDistanceClipTestEnableBitmask
=
1159 gs_prog_data
->base
.clip_distance_mask
;
1160 gs
.UserClipDistanceCullTestEnableBitmask
=
1161 gs_prog_data
->base
.cull_distance_mask
;
1164 gs
.PerThreadScratchSpace
= get_scratch_space(gs_bin
);
1165 gs
.ScratchSpaceBasePointer
=
1166 get_scratch_address(pipeline
, MESA_SHADER_GEOMETRY
, gs_bin
);
1171 emit_3dstate_wm(struct anv_pipeline
*pipeline
, struct anv_subpass
*subpass
,
1172 const VkPipelineMultisampleStateCreateInfo
*multisample
)
1174 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
1176 MAYBE_UNUSED
uint32_t samples
=
1177 multisample
? multisample
->rasterizationSamples
: 1;
1179 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_WM
), wm
) {
1180 wm
.StatisticsEnable
= true;
1181 wm
.LineEndCapAntialiasingRegionWidth
= _05pixels
;
1182 wm
.LineAntialiasingRegionWidth
= _10pixels
;
1183 wm
.PointRasterizationRule
= RASTRULE_UPPER_RIGHT
;
1185 if (anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
1186 if (wm_prog_data
->early_fragment_tests
) {
1187 wm
.EarlyDepthStencilControl
= EDSC_PREPS
;
1188 } else if (wm_prog_data
->has_side_effects
) {
1189 wm
.EarlyDepthStencilControl
= EDSC_PSEXEC
;
1191 wm
.EarlyDepthStencilControl
= EDSC_NORMAL
;
1194 wm
.BarycentricInterpolationMode
=
1195 wm_prog_data
->barycentric_interp_modes
;
1198 /* FIXME: This needs a lot more work, cf gen7 upload_wm_state(). */
1199 wm
.ThreadDispatchEnable
= true;
1201 wm
.PixelShaderComputedDepthMode
= wm_prog_data
->computed_depth_mode
;
1202 wm
.PixelShaderUsesSourceDepth
= wm_prog_data
->uses_src_depth
;
1203 wm
.PixelShaderUsesSourceW
= wm_prog_data
->uses_src_w
;
1204 wm
.PixelShaderUsesInputCoverageMask
= wm_prog_data
->uses_sample_mask
;
1206 /* If the subpass has a depth or stencil self-dependency, then we
1207 * need to force the hardware to do the depth/stencil write *after*
1208 * fragment shader execution. Otherwise, the writes may hit memory
1209 * before we get around to fetching from the input attachment and we
1210 * may get the depth or stencil value from the current draw rather
1211 * than the previous one.
1213 wm
.PixelShaderKillsPixel
= subpass
->has_ds_self_dep
||
1214 wm_prog_data
->uses_kill
;
1217 wm
.MultisampleRasterizationMode
= MSRASTMODE_ON_PATTERN
;
1218 if (wm_prog_data
->persample_dispatch
) {
1219 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
1221 wm
.MultisampleDispatchMode
= MSDISPMODE_PERPIXEL
;
1224 wm
.MultisampleRasterizationMode
= MSRASTMODE_OFF_PIXEL
;
1225 wm
.MultisampleDispatchMode
= MSDISPMODE_PERSAMPLE
;
1233 is_dual_src_blend_factor(VkBlendFactor factor
)
1235 return factor
== VK_BLEND_FACTOR_SRC1_COLOR
||
1236 factor
== VK_BLEND_FACTOR_ONE_MINUS_SRC1_COLOR
||
1237 factor
== VK_BLEND_FACTOR_SRC1_ALPHA
||
1238 factor
== VK_BLEND_FACTOR_ONE_MINUS_SRC1_ALPHA
;
1242 emit_3dstate_ps(struct anv_pipeline
*pipeline
,
1243 const VkPipelineColorBlendStateCreateInfo
*blend
)
1245 MAYBE_UNUSED
const struct gen_device_info
*devinfo
= &pipeline
->device
->info
;
1246 const struct anv_shader_bin
*fs_bin
=
1247 pipeline
->shaders
[MESA_SHADER_FRAGMENT
];
1249 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
1250 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS
), ps
) {
1252 /* Even if no fragments are ever dispatched, gen7 hardware hangs if
1253 * we don't at least set the maximum number of threads.
1255 ps
.MaximumNumberofThreads
= devinfo
->max_wm_threads
- 1;
1261 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
1264 /* The hardware wedges if you have this bit set but don't turn on any dual
1265 * source blend factors.
1267 bool dual_src_blend
= false;
1268 if (wm_prog_data
->dual_src_blend
) {
1269 for (uint32_t i
= 0; i
< blend
->attachmentCount
; i
++) {
1270 const VkPipelineColorBlendAttachmentState
*bstate
=
1271 &blend
->pAttachments
[i
];
1273 if (bstate
->blendEnable
&&
1274 (is_dual_src_blend_factor(bstate
->srcColorBlendFactor
) ||
1275 is_dual_src_blend_factor(bstate
->dstColorBlendFactor
) ||
1276 is_dual_src_blend_factor(bstate
->srcAlphaBlendFactor
) ||
1277 is_dual_src_blend_factor(bstate
->dstAlphaBlendFactor
))) {
1278 dual_src_blend
= true;
1285 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS
), ps
) {
1286 ps
.KernelStartPointer0
= fs_bin
->kernel
.offset
;
1287 ps
.KernelStartPointer1
= 0;
1288 ps
.KernelStartPointer2
= fs_bin
->kernel
.offset
+
1289 wm_prog_data
->prog_offset_2
;
1290 ps
._8PixelDispatchEnable
= wm_prog_data
->dispatch_8
;
1291 ps
._16PixelDispatchEnable
= wm_prog_data
->dispatch_16
;
1292 ps
._32PixelDispatchEnable
= false;
1294 ps
.SingleProgramFlow
= false;
1295 ps
.VectorMaskEnable
= true;
1296 ps
.SamplerCount
= get_sampler_count(fs_bin
);
1297 ps
.BindingTableEntryCount
= get_binding_table_entry_count(fs_bin
);
1298 ps
.PushConstantEnable
= wm_prog_data
->base
.nr_params
> 0;
1299 ps
.PositionXYOffsetSelect
= wm_prog_data
->uses_pos_offset
?
1300 POSOFFSET_SAMPLE
: POSOFFSET_NONE
;
1302 ps
.AttributeEnable
= wm_prog_data
->num_varying_inputs
> 0;
1303 ps
.oMaskPresenttoRenderTarget
= wm_prog_data
->uses_omask
;
1304 ps
.DualSourceBlendEnable
= dual_src_blend
;
1308 /* Haswell requires the sample mask to be set in this packet as well
1309 * as in 3DSTATE_SAMPLE_MASK; the values should match.
1311 ps
.SampleMask
= 0xff;
1315 ps
.MaximumNumberofThreadsPerPSD
= 64 - 1;
1317 ps
.MaximumNumberofThreadsPerPSD
= 64 - 2;
1319 ps
.MaximumNumberofThreads
= devinfo
->max_wm_threads
- 1;
1322 ps
.DispatchGRFStartRegisterForConstantSetupData0
=
1323 wm_prog_data
->base
.dispatch_grf_start_reg
;
1324 ps
.DispatchGRFStartRegisterForConstantSetupData1
= 0;
1325 ps
.DispatchGRFStartRegisterForConstantSetupData2
=
1326 wm_prog_data
->dispatch_grf_start_reg_2
;
1328 ps
.PerThreadScratchSpace
= get_scratch_space(fs_bin
);
1329 ps
.ScratchSpaceBasePointer
=
1330 get_scratch_address(pipeline
, MESA_SHADER_FRAGMENT
, fs_bin
);
1336 emit_3dstate_ps_extra(struct anv_pipeline
*pipeline
,
1337 struct anv_subpass
*subpass
)
1339 const struct brw_wm_prog_data
*wm_prog_data
= get_wm_prog_data(pipeline
);
1341 if (!anv_pipeline_has_stage(pipeline
, MESA_SHADER_FRAGMENT
)) {
1342 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS_EXTRA
), ps
);
1346 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS_EXTRA
), ps
) {
1347 ps
.PixelShaderValid
= true;
1348 ps
.AttributeEnable
= wm_prog_data
->num_varying_inputs
> 0;
1349 ps
.oMaskPresenttoRenderTarget
= wm_prog_data
->uses_omask
;
1350 ps
.PixelShaderIsPerSample
= wm_prog_data
->persample_dispatch
;
1351 ps
.PixelShaderComputedDepthMode
= wm_prog_data
->computed_depth_mode
;
1352 ps
.PixelShaderUsesSourceDepth
= wm_prog_data
->uses_src_depth
;
1353 ps
.PixelShaderUsesSourceW
= wm_prog_data
->uses_src_w
;
1355 /* If the subpass has a depth or stencil self-dependency, then we need
1356 * to force the hardware to do the depth/stencil write *after* fragment
1357 * shader execution. Otherwise, the writes may hit memory before we get
1358 * around to fetching from the input attachment and we may get the depth
1359 * or stencil value from the current draw rather than the previous one.
1361 ps
.PixelShaderKillsPixel
= subpass
->has_ds_self_dep
||
1362 wm_prog_data
->uses_kill
;
1365 ps
.PixelShaderPullsBary
= wm_prog_data
->pulls_bary
;
1366 ps
.InputCoverageMaskState
= wm_prog_data
->uses_sample_mask
?
1367 ICMS_INNER_CONSERVATIVE
: ICMS_NONE
;
1369 ps
.PixelShaderUsesInputCoverageMask
= wm_prog_data
->uses_sample_mask
;
1375 emit_3dstate_vf_topology(struct anv_pipeline
*pipeline
)
1377 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VF_TOPOLOGY
), vft
) {
1378 vft
.PrimitiveTopologyType
= pipeline
->topology
;
1384 genX(graphics_pipeline_create
)(
1386 struct anv_pipeline_cache
* cache
,
1387 const VkGraphicsPipelineCreateInfo
* pCreateInfo
,
1388 const VkAllocationCallbacks
* pAllocator
,
1389 VkPipeline
* pPipeline
)
1391 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1392 ANV_FROM_HANDLE(anv_render_pass
, pass
, pCreateInfo
->renderPass
);
1393 struct anv_subpass
*subpass
= &pass
->subpasses
[pCreateInfo
->subpass
];
1394 struct anv_pipeline
*pipeline
;
1397 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
);
1399 pipeline
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*pipeline
), 8,
1400 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1401 if (pipeline
== NULL
)
1402 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1404 result
= anv_pipeline_init(pipeline
, device
, cache
,
1405 pCreateInfo
, pAllocator
);
1406 if (result
!= VK_SUCCESS
) {
1407 vk_free2(&device
->alloc
, pAllocator
, pipeline
);
1411 assert(pCreateInfo
->pVertexInputState
);
1412 emit_vertex_input(pipeline
, pCreateInfo
->pVertexInputState
);
1413 assert(pCreateInfo
->pRasterizationState
);
1414 emit_rs_state(pipeline
, pCreateInfo
->pRasterizationState
,
1415 pCreateInfo
->pMultisampleState
, pass
, subpass
);
1416 emit_ms_state(pipeline
, pCreateInfo
->pMultisampleState
);
1417 emit_ds_state(pipeline
, pCreateInfo
->pDepthStencilState
, pass
, subpass
);
1418 emit_cb_state(pipeline
, pCreateInfo
->pColorBlendState
,
1419 pCreateInfo
->pMultisampleState
);
1421 emit_urb_setup(pipeline
);
1423 emit_3dstate_clip(pipeline
, pCreateInfo
->pViewportState
,
1424 pCreateInfo
->pRasterizationState
);
1425 emit_3dstate_streamout(pipeline
, pCreateInfo
->pRasterizationState
);
1428 /* From gen7_vs_state.c */
1431 * From Graphics BSpec: 3D-Media-GPGPU Engine > 3D Pipeline Stages >
1432 * Geometry > Geometry Shader > State:
1434 * "Note: Because of corruption in IVB:GT2, software needs to flush the
1435 * whole fixed function pipeline when the GS enable changes value in
1438 * The hardware architects have clarified that in this context "flush the
1439 * whole fixed function pipeline" means to emit a PIPE_CONTROL with the "CS
1442 if (!brw
->is_haswell
&& !brw
->is_baytrail
)
1443 gen7_emit_vs_workaround_flush(brw
);
1446 emit_3dstate_vs(pipeline
);
1447 emit_3dstate_hs_te_ds(pipeline
);
1448 emit_3dstate_gs(pipeline
);
1449 emit_3dstate_sbe(pipeline
);
1450 emit_3dstate_wm(pipeline
, subpass
, pCreateInfo
->pMultisampleState
);
1451 emit_3dstate_ps(pipeline
, pCreateInfo
->pColorBlendState
);
1453 emit_3dstate_ps_extra(pipeline
, subpass
);
1454 emit_3dstate_vf_topology(pipeline
);
1457 *pPipeline
= anv_pipeline_to_handle(pipeline
);
1463 compute_pipeline_create(
1465 struct anv_pipeline_cache
* cache
,
1466 const VkComputePipelineCreateInfo
* pCreateInfo
,
1467 const VkAllocationCallbacks
* pAllocator
,
1468 VkPipeline
* pPipeline
)
1470 ANV_FROM_HANDLE(anv_device
, device
, _device
);
1471 const struct anv_physical_device
*physical_device
=
1472 &device
->instance
->physicalDevice
;
1473 const struct gen_device_info
*devinfo
= &physical_device
->info
;
1474 struct anv_pipeline
*pipeline
;
1477 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO
);
1479 pipeline
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*pipeline
), 8,
1480 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
1481 if (pipeline
== NULL
)
1482 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
1484 pipeline
->device
= device
;
1485 pipeline
->layout
= anv_pipeline_layout_from_handle(pCreateInfo
->layout
);
1487 pipeline
->blend_state
.map
= NULL
;
1489 result
= anv_reloc_list_init(&pipeline
->batch_relocs
,
1490 pAllocator
? pAllocator
: &device
->alloc
);
1491 if (result
!= VK_SUCCESS
) {
1492 vk_free2(&device
->alloc
, pAllocator
, pipeline
);
1495 pipeline
->batch
.next
= pipeline
->batch
.start
= pipeline
->batch_data
;
1496 pipeline
->batch
.end
= pipeline
->batch
.start
+ sizeof(pipeline
->batch_data
);
1497 pipeline
->batch
.relocs
= &pipeline
->batch_relocs
;
1499 /* When we free the pipeline, we detect stages based on the NULL status
1500 * of various prog_data pointers. Make them NULL by default.
1502 memset(pipeline
->shaders
, 0, sizeof(pipeline
->shaders
));
1504 pipeline
->active_stages
= 0;
1506 pipeline
->needs_data_cache
= false;
1508 assert(pCreateInfo
->stage
.stage
== VK_SHADER_STAGE_COMPUTE_BIT
);
1509 ANV_FROM_HANDLE(anv_shader_module
, module
, pCreateInfo
->stage
.module
);
1510 result
= anv_pipeline_compile_cs(pipeline
, cache
, pCreateInfo
, module
,
1511 pCreateInfo
->stage
.pName
,
1512 pCreateInfo
->stage
.pSpecializationInfo
);
1513 if (result
!= VK_SUCCESS
) {
1514 vk_free2(&device
->alloc
, pAllocator
, pipeline
);
1518 const struct brw_cs_prog_data
*cs_prog_data
= get_cs_prog_data(pipeline
);
1520 anv_pipeline_setup_l3_config(pipeline
, cs_prog_data
->base
.total_shared
> 0);
1522 uint32_t group_size
= cs_prog_data
->local_size
[0] *
1523 cs_prog_data
->local_size
[1] * cs_prog_data
->local_size
[2];
1524 uint32_t remainder
= group_size
& (cs_prog_data
->simd_size
- 1);
1527 pipeline
->cs_right_mask
= ~0u >> (32 - remainder
);
1529 pipeline
->cs_right_mask
= ~0u >> (32 - cs_prog_data
->simd_size
);
1531 const uint32_t vfe_curbe_allocation
=
1532 ALIGN(cs_prog_data
->push
.per_thread
.regs
* cs_prog_data
->threads
+
1533 cs_prog_data
->push
.cross_thread
.regs
, 2);
1535 const uint32_t subslices
= MAX2(physical_device
->subslice_total
, 1);
1537 const struct anv_shader_bin
*cs_bin
=
1538 pipeline
->shaders
[MESA_SHADER_COMPUTE
];
1540 anv_batch_emit(&pipeline
->batch
, GENX(MEDIA_VFE_STATE
), vfe
) {
1544 vfe
.GPGPUMode
= true;
1546 vfe
.MaximumNumberofThreads
=
1547 devinfo
->max_cs_threads
* subslices
- 1;
1548 vfe
.NumberofURBEntries
= GEN_GEN
<= 7 ? 0 : 2;
1549 vfe
.ResetGatewayTimer
= true;
1551 vfe
.BypassGatewayControl
= true;
1553 vfe
.URBEntryAllocationSize
= GEN_GEN
<= 7 ? 0 : 2;
1554 vfe
.CURBEAllocationSize
= vfe_curbe_allocation
;
1556 vfe
.PerThreadScratchSpace
= get_scratch_space(cs_bin
);
1557 vfe
.ScratchSpaceBasePointer
=
1558 get_scratch_address(pipeline
, MESA_SHADER_COMPUTE
, cs_bin
);
1561 struct GENX(INTERFACE_DESCRIPTOR_DATA
) desc
= {
1562 .KernelStartPointer
= cs_bin
->kernel
.offset
,
1564 .SamplerCount
= get_sampler_count(cs_bin
),
1565 .BindingTableEntryCount
= get_binding_table_entry_count(cs_bin
),
1566 .BarrierEnable
= cs_prog_data
->uses_barrier
,
1567 .SharedLocalMemorySize
=
1568 encode_slm_size(GEN_GEN
, cs_prog_data
->base
.total_shared
),
1571 .ConstantURBEntryReadOffset
= 0,
1573 .ConstantURBEntryReadLength
= cs_prog_data
->push
.per_thread
.regs
,
1574 #if GEN_GEN >= 8 || GEN_IS_HASWELL
1575 .CrossThreadConstantDataReadLength
=
1576 cs_prog_data
->push
.cross_thread
.regs
,
1579 .NumberofThreadsinGPGPUThreadGroup
= cs_prog_data
->threads
,
1581 GENX(INTERFACE_DESCRIPTOR_DATA_pack
)(NULL
,
1582 pipeline
->interface_descriptor_data
,
1585 *pPipeline
= anv_pipeline_to_handle(pipeline
);
1590 VkResult
genX(CreateGraphicsPipelines
)(
1592 VkPipelineCache pipelineCache
,
1594 const VkGraphicsPipelineCreateInfo
* pCreateInfos
,
1595 const VkAllocationCallbacks
* pAllocator
,
1596 VkPipeline
* pPipelines
)
1598 ANV_FROM_HANDLE(anv_pipeline_cache
, pipeline_cache
, pipelineCache
);
1600 VkResult result
= VK_SUCCESS
;
1603 for (i
= 0; i
< count
; i
++) {
1604 result
= genX(graphics_pipeline_create
)(_device
,
1607 pAllocator
, &pPipelines
[i
]);
1609 /* Bail out on the first error as it is not obvious what error should be
1610 * report upon 2 different failures. */
1611 if (result
!= VK_SUCCESS
)
1615 for (; i
< count
; i
++)
1616 pPipelines
[i
] = VK_NULL_HANDLE
;
1621 VkResult
genX(CreateComputePipelines
)(
1623 VkPipelineCache pipelineCache
,
1625 const VkComputePipelineCreateInfo
* pCreateInfos
,
1626 const VkAllocationCallbacks
* pAllocator
,
1627 VkPipeline
* pPipelines
)
1629 ANV_FROM_HANDLE(anv_pipeline_cache
, pipeline_cache
, pipelineCache
);
1631 VkResult result
= VK_SUCCESS
;
1634 for (i
= 0; i
< count
; i
++) {
1635 result
= compute_pipeline_create(_device
, pipeline_cache
,
1637 pAllocator
, &pPipelines
[i
]);
1639 /* Bail out on the first error as it is not obvious what error should be
1640 * report upon 2 different failures. */
1641 if (result
!= VK_SUCCESS
)
1645 for (; i
< count
; i
++)
1646 pPipelines
[i
] = VK_NULL_HANDLE
;