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
30 #include "anv_private.h"
32 #include "gen8_pack.h"
33 #include "gen9_pack.h"
35 #include "genX_pipeline_util.h"
38 emit_vertex_input(struct anv_pipeline
*pipeline
,
39 const VkPipelineVertexInputStateCreateInfo
*info
,
40 const struct anv_graphics_pipeline_create_info
*extra
)
42 static_assert(ANV_GEN
>= 8, "should be compiling this for gen < 8");
45 if (extra
&& extra
->disable_vs
) {
46 /* If the VS is disabled, just assume the user knows what they're
47 * doing and apply the layout blindly. This can only come from
48 * meta, so this *should* be safe.
51 for (uint32_t i
= 0; i
< info
->vertexAttributeDescriptionCount
; i
++)
52 elements
|= (1 << info
->pVertexAttributeDescriptions
[i
].location
);
54 /* Pull inputs_read out of the VS prog data */
55 uint64_t inputs_read
= pipeline
->vs_prog_data
.inputs_read
;
56 assert((inputs_read
& ((1 << VERT_ATTRIB_GENERIC0
) - 1)) == 0);
57 elements
= inputs_read
>> VERT_ATTRIB_GENERIC0
;
60 const uint32_t num_dwords
= 1 + __builtin_popcount(elements
) * 2;
64 p
= anv_batch_emitn(&pipeline
->batch
, num_dwords
,
65 GENX(3DSTATE_VERTEX_ELEMENTS
));
66 memset(p
+ 1, 0, (num_dwords
- 1) * 4);
69 for (uint32_t i
= 0; i
< info
->vertexAttributeDescriptionCount
; i
++) {
70 const VkVertexInputAttributeDescription
*desc
=
71 &info
->pVertexAttributeDescriptions
[i
];
72 enum isl_format format
= anv_get_isl_format(desc
->format
,
73 VK_IMAGE_ASPECT_COLOR_BIT
,
74 VK_IMAGE_TILING_LINEAR
);
76 assert(desc
->binding
< 32);
78 if ((elements
& (1 << desc
->location
)) == 0)
79 continue; /* Binding unused */
81 uint32_t slot
= __builtin_popcount(elements
& ((1 << desc
->location
) - 1));
83 struct GENX(VERTEX_ELEMENT_STATE
) element
= {
84 .VertexBufferIndex
= desc
->binding
,
86 .SourceElementFormat
= format
,
87 .EdgeFlagEnable
= false,
88 .SourceElementOffset
= desc
->offset
,
89 .Component0Control
= vertex_element_comp_control(format
, 0),
90 .Component1Control
= vertex_element_comp_control(format
, 1),
91 .Component2Control
= vertex_element_comp_control(format
, 2),
92 .Component3Control
= vertex_element_comp_control(format
, 3),
94 GENX(VERTEX_ELEMENT_STATE_pack
)(NULL
, &p
[1 + slot
* 2], &element
);
96 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VF_INSTANCING
),
97 .InstancingEnable
= pipeline
->instancing_enable
[desc
->binding
],
98 .VertexElementIndex
= slot
,
99 /* Vulkan so far doesn't have an instance divisor, so
100 * this is always 1 (ignored if not instancing). */
101 .InstanceDataStepRate
= 1);
104 const uint32_t id_slot
= __builtin_popcount(elements
);
105 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VF_SGVS
),
106 .VertexIDEnable
= pipeline
->vs_prog_data
.uses_vertexid
,
107 .VertexIDComponentNumber
= 2,
108 .VertexIDElementOffset
= id_slot
,
109 .InstanceIDEnable
= pipeline
->vs_prog_data
.uses_instanceid
,
110 .InstanceIDComponentNumber
= 3,
111 .InstanceIDElementOffset
= id_slot
);
115 emit_ia_state(struct anv_pipeline
*pipeline
,
116 const VkPipelineInputAssemblyStateCreateInfo
*info
,
117 const struct anv_graphics_pipeline_create_info
*extra
)
119 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VF_TOPOLOGY
),
120 .PrimitiveTopologyType
= pipeline
->topology
);
124 emit_rs_state(struct anv_pipeline
*pipeline
,
125 const VkPipelineRasterizationStateCreateInfo
*info
,
126 const struct anv_graphics_pipeline_create_info
*extra
)
128 struct GENX(3DSTATE_SF
) sf
= {
129 GENX(3DSTATE_SF_header
),
130 .ViewportTransformEnable
= !(extra
&& extra
->disable_viewport
),
131 .TriangleStripListProvokingVertexSelect
= 0,
132 .LineStripListProvokingVertexSelect
= 0,
133 .TriangleFanProvokingVertexSelect
= 0,
134 .PointWidthSource
= pipeline
->writes_point_size
? Vertex
: State
,
138 /* FINISHME: VkBool32 rasterizerDiscardEnable; */
140 GENX(3DSTATE_SF_pack
)(NULL
, pipeline
->gen8
.sf
, &sf
);
142 struct GENX(3DSTATE_RASTER
) raster
= {
143 GENX(3DSTATE_RASTER_header
),
144 .FrontWinding
= vk_to_gen_front_face
[info
->frontFace
],
145 .CullMode
= vk_to_gen_cullmode
[info
->cullMode
],
146 .FrontFaceFillMode
= vk_to_gen_fillmode
[info
->polygonMode
],
147 .BackFaceFillMode
= vk_to_gen_fillmode
[info
->polygonMode
],
148 .ScissorRectangleEnable
= !(extra
&& extra
->disable_scissor
),
150 .ViewportZClipTestEnable
= true,
152 /* GEN9+ splits ViewportZClipTestEnable into near and far enable bits */
153 .ViewportZFarClipTestEnable
= true,
154 .ViewportZNearClipTestEnable
= true,
158 GENX(3DSTATE_RASTER_pack
)(NULL
, pipeline
->gen8
.raster
, &raster
);
162 emit_cb_state(struct anv_pipeline
*pipeline
,
163 const VkPipelineColorBlendStateCreateInfo
*info
,
164 const VkPipelineMultisampleStateCreateInfo
*ms_info
)
166 struct anv_device
*device
= pipeline
->device
;
168 uint32_t num_dwords
= GENX(BLEND_STATE_length
);
169 pipeline
->blend_state
=
170 anv_state_pool_alloc(&device
->dynamic_state_pool
, num_dwords
* 4, 64);
172 struct GENX(BLEND_STATE
) blend_state
= {
173 .AlphaToCoverageEnable
= ms_info
&& ms_info
->alphaToCoverageEnable
,
174 .AlphaToOneEnable
= ms_info
&& ms_info
->alphaToOneEnable
,
177 for (uint32_t i
= 0; i
< info
->attachmentCount
; i
++) {
178 const VkPipelineColorBlendAttachmentState
*a
= &info
->pAttachments
[i
];
180 if (a
->srcColorBlendFactor
!= a
->srcAlphaBlendFactor
||
181 a
->dstColorBlendFactor
!= a
->dstAlphaBlendFactor
||
182 a
->colorBlendOp
!= a
->alphaBlendOp
) {
183 blend_state
.IndependentAlphaBlendEnable
= true;
186 blend_state
.Entry
[i
] = (struct GENX(BLEND_STATE_ENTRY
)) {
187 .LogicOpEnable
= info
->logicOpEnable
,
188 .LogicOpFunction
= vk_to_gen_logic_op
[info
->logicOp
],
189 .ColorBufferBlendEnable
= a
->blendEnable
,
190 .PreBlendSourceOnlyClampEnable
= false,
191 .ColorClampRange
= COLORCLAMP_RTFORMAT
,
192 .PreBlendColorClampEnable
= true,
193 .PostBlendColorClampEnable
= true,
194 .SourceBlendFactor
= vk_to_gen_blend
[a
->srcColorBlendFactor
],
195 .DestinationBlendFactor
= vk_to_gen_blend
[a
->dstColorBlendFactor
],
196 .ColorBlendFunction
= vk_to_gen_blend_op
[a
->colorBlendOp
],
197 .SourceAlphaBlendFactor
= vk_to_gen_blend
[a
->srcAlphaBlendFactor
],
198 .DestinationAlphaBlendFactor
= vk_to_gen_blend
[a
->dstAlphaBlendFactor
],
199 .AlphaBlendFunction
= vk_to_gen_blend_op
[a
->alphaBlendOp
],
200 .WriteDisableAlpha
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_A_BIT
),
201 .WriteDisableRed
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_R_BIT
),
202 .WriteDisableGreen
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_G_BIT
),
203 .WriteDisableBlue
= !(a
->colorWriteMask
& VK_COLOR_COMPONENT_B_BIT
),
206 /* Our hardware applies the blend factor prior to the blend function
207 * regardless of what function is used. Technically, this means the
208 * hardware can do MORE than GL or Vulkan specify. However, it also
209 * means that, for MIN and MAX, we have to stomp the blend factor to
210 * ONE to make it a no-op.
212 if (a
->colorBlendOp
== VK_BLEND_OP_MIN
||
213 a
->colorBlendOp
== VK_BLEND_OP_MAX
) {
214 blend_state
.Entry
[i
].SourceBlendFactor
= BLENDFACTOR_ONE
;
215 blend_state
.Entry
[i
].DestinationBlendFactor
= BLENDFACTOR_ONE
;
217 if (a
->alphaBlendOp
== VK_BLEND_OP_MIN
||
218 a
->alphaBlendOp
== VK_BLEND_OP_MAX
) {
219 blend_state
.Entry
[i
].SourceAlphaBlendFactor
= BLENDFACTOR_ONE
;
220 blend_state
.Entry
[i
].DestinationAlphaBlendFactor
= BLENDFACTOR_ONE
;
224 GENX(BLEND_STATE_pack
)(NULL
, pipeline
->blend_state
.map
, &blend_state
);
225 if (!device
->info
.has_llc
)
226 anv_state_clflush(pipeline
->blend_state
);
228 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_BLEND_STATE_POINTERS
),
229 .BlendStatePointer
= pipeline
->blend_state
.offset
,
230 .BlendStatePointerValid
= true);
234 emit_ds_state(struct anv_pipeline
*pipeline
,
235 const VkPipelineDepthStencilStateCreateInfo
*info
)
237 uint32_t *dw
= ANV_GEN
== 8 ?
238 pipeline
->gen8
.wm_depth_stencil
: pipeline
->gen9
.wm_depth_stencil
;
241 /* We're going to OR this together with the dynamic state. We need
242 * to make sure it's initialized to something useful.
244 memset(pipeline
->gen8
.wm_depth_stencil
, 0,
245 sizeof(pipeline
->gen8
.wm_depth_stencil
));
246 memset(pipeline
->gen9
.wm_depth_stencil
, 0,
247 sizeof(pipeline
->gen9
.wm_depth_stencil
));
251 /* VkBool32 depthBoundsTestEnable; // optional (depth_bounds_test) */
253 struct GENX(3DSTATE_WM_DEPTH_STENCIL
) wm_depth_stencil
= {
254 .DepthTestEnable
= info
->depthTestEnable
,
255 .DepthBufferWriteEnable
= info
->depthWriteEnable
,
256 .DepthTestFunction
= vk_to_gen_compare_op
[info
->depthCompareOp
],
257 .DoubleSidedStencilEnable
= true,
259 .StencilTestEnable
= info
->stencilTestEnable
,
260 .StencilFailOp
= vk_to_gen_stencil_op
[info
->front
.failOp
],
261 .StencilPassDepthPassOp
= vk_to_gen_stencil_op
[info
->front
.passOp
],
262 .StencilPassDepthFailOp
= vk_to_gen_stencil_op
[info
->front
.depthFailOp
],
263 .StencilTestFunction
= vk_to_gen_compare_op
[info
->front
.compareOp
],
264 .BackfaceStencilFailOp
= vk_to_gen_stencil_op
[info
->back
.failOp
],
265 .BackfaceStencilPassDepthPassOp
= vk_to_gen_stencil_op
[info
->back
.passOp
],
266 .BackfaceStencilPassDepthFailOp
=vk_to_gen_stencil_op
[info
->back
.depthFailOp
],
267 .BackfaceStencilTestFunction
= vk_to_gen_compare_op
[info
->back
.compareOp
],
270 GENX(3DSTATE_WM_DEPTH_STENCIL_pack
)(NULL
, dw
, &wm_depth_stencil
);
274 genX(graphics_pipeline_create
)(
276 const VkGraphicsPipelineCreateInfo
* pCreateInfo
,
277 const struct anv_graphics_pipeline_create_info
*extra
,
278 const VkAllocationCallbacks
* pAllocator
,
279 VkPipeline
* pPipeline
)
281 ANV_FROM_HANDLE(anv_device
, device
, _device
);
282 struct anv_pipeline
*pipeline
;
284 uint32_t offset
, length
;
286 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
);
288 pipeline
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*pipeline
), 8,
289 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
290 if (pipeline
== NULL
)
291 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
293 result
= anv_pipeline_init(pipeline
, device
, pCreateInfo
, extra
, pAllocator
);
294 if (result
!= VK_SUCCESS
) {
295 anv_free2(&device
->alloc
, pAllocator
, pipeline
);
299 assert(pCreateInfo
->pVertexInputState
);
300 emit_vertex_input(pipeline
, pCreateInfo
->pVertexInputState
, extra
);
301 assert(pCreateInfo
->pInputAssemblyState
);
302 emit_ia_state(pipeline
, pCreateInfo
->pInputAssemblyState
, extra
);
303 assert(pCreateInfo
->pRasterizationState
);
304 emit_rs_state(pipeline
, pCreateInfo
->pRasterizationState
, extra
);
305 emit_ds_state(pipeline
, pCreateInfo
->pDepthStencilState
);
306 emit_cb_state(pipeline
, pCreateInfo
->pColorBlendState
,
307 pCreateInfo
->pMultisampleState
);
309 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VF_STATISTICS
),
310 .StatisticsEnable
= true);
311 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_HS
), .Enable
= false);
312 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_TE
), .TEEnable
= false);
313 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_DS
), .FunctionEnable
= false);
314 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_STREAMOUT
), .SOFunctionEnable
= false);
316 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PUSH_CONSTANT_ALLOC_VS
),
317 .ConstantBufferOffset
= 0,
318 .ConstantBufferSize
= 4);
319 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PUSH_CONSTANT_ALLOC_GS
),
320 .ConstantBufferOffset
= 4,
321 .ConstantBufferSize
= 4);
322 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PUSH_CONSTANT_ALLOC_PS
),
323 .ConstantBufferOffset
= 8,
324 .ConstantBufferSize
= 4);
326 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_WM_CHROMAKEY
),
327 .ChromaKeyKillEnable
= false);
328 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_AA_LINE_PARAMETERS
));
330 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_CLIP
),
332 .ViewportXYClipTestEnable
= !(extra
&& extra
->disable_viewport
),
333 .MinimumPointWidth
= 0.125,
334 .MaximumPointWidth
= 255.875);
336 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_WM
),
337 .StatisticsEnable
= true,
338 .LineEndCapAntialiasingRegionWidth
= _05pixels
,
339 .LineAntialiasingRegionWidth
= _10pixels
,
340 .EarlyDepthStencilControl
= NORMAL
,
341 .ForceThreadDispatchEnable
= NORMAL
,
342 .PointRasterizationRule
= RASTRULE_UPPER_RIGHT
,
343 .BarycentricInterpolationMode
=
344 pipeline
->wm_prog_data
.barycentric_interp_modes
);
346 uint32_t samples
= 1;
347 uint32_t log2_samples
= __builtin_ffs(samples
) - 1;
348 bool enable_sampling
= samples
> 1 ? true : false;
350 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_MULTISAMPLE
),
351 .PixelPositionOffsetEnable
= enable_sampling
,
352 .PixelLocation
= CENTER
,
353 .NumberofMultisamples
= log2_samples
);
355 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_SAMPLE_MASK
),
356 .SampleMask
= 0xffff);
358 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_URB_VS
),
359 .VSURBStartingAddress
= pipeline
->urb
.vs_start
,
360 .VSURBEntryAllocationSize
= pipeline
->urb
.vs_size
- 1,
361 .VSNumberofURBEntries
= pipeline
->urb
.nr_vs_entries
);
363 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_URB_GS
),
364 .GSURBStartingAddress
= pipeline
->urb
.gs_start
,
365 .GSURBEntryAllocationSize
= pipeline
->urb
.gs_size
- 1,
366 .GSNumberofURBEntries
= pipeline
->urb
.nr_gs_entries
);
368 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_URB_HS
),
369 .HSURBStartingAddress
= pipeline
->urb
.vs_start
,
370 .HSURBEntryAllocationSize
= 0,
371 .HSNumberofURBEntries
= 0);
373 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_URB_DS
),
374 .DSURBStartingAddress
= pipeline
->urb
.vs_start
,
375 .DSURBEntryAllocationSize
= 0,
376 .DSNumberofURBEntries
= 0);
378 const struct brw_gs_prog_data
*gs_prog_data
= &pipeline
->gs_prog_data
;
380 length
= (gs_prog_data
->base
.vue_map
.num_slots
+ 1) / 2 - offset
;
382 if (pipeline
->gs_kernel
== NO_KERNEL
)
383 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_GS
), .Enable
= false);
385 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_GS
),
386 .SingleProgramFlow
= false,
387 .KernelStartPointer
= pipeline
->gs_kernel
,
388 .VectorMaskEnable
= Dmask
,
390 .BindingTableEntryCount
= 0,
391 .ExpectedVertexCount
= pipeline
->gs_vertex_count
,
393 .ScratchSpaceBasePointer
= pipeline
->scratch_start
[MESA_SHADER_GEOMETRY
],
394 .PerThreadScratchSpace
= ffs(gs_prog_data
->base
.base
.total_scratch
/ 2048),
396 .OutputVertexSize
= gs_prog_data
->output_vertex_size_hwords
* 2 - 1,
397 .OutputTopology
= gs_prog_data
->output_topology
,
398 .VertexURBEntryReadLength
= gs_prog_data
->base
.urb_read_length
,
399 .IncludeVertexHandles
= gs_prog_data
->base
.include_vue_handles
,
400 .DispatchGRFStartRegisterForURBData
=
401 gs_prog_data
->base
.base
.dispatch_grf_start_reg
,
403 .MaximumNumberofThreads
= device
->info
.max_gs_threads
/ 2 - 1,
404 .ControlDataHeaderSize
= gs_prog_data
->control_data_header_size_hwords
,
405 .DispatchMode
= gs_prog_data
->base
.dispatch_mode
,
406 .StatisticsEnable
= true,
407 .IncludePrimitiveID
= gs_prog_data
->include_primitive_id
,
408 .ReorderMode
= TRAILING
,
411 .ControlDataFormat
= gs_prog_data
->control_data_format
,
413 .StaticOutput
= gs_prog_data
->static_vertex_count
>= 0,
414 .StaticOutputVertexCount
=
415 gs_prog_data
->static_vertex_count
>= 0 ?
416 gs_prog_data
->static_vertex_count
: 0,
418 /* FIXME: mesa sets this based on ctx->Transform.ClipPlanesEnabled:
419 * UserClipDistanceClipTestEnableBitmask_3DSTATE_GS(v)
420 * UserClipDistanceCullTestEnableBitmask(v)
423 .VertexURBEntryOutputReadOffset
= offset
,
424 .VertexURBEntryOutputLength
= length
);
426 const struct brw_vue_prog_data
*vue_prog_data
= &pipeline
->vs_prog_data
.base
;
427 /* Skip the VUE header and position slots */
429 length
= (vue_prog_data
->vue_map
.num_slots
+ 1) / 2 - offset
;
431 uint32_t vs_start
= pipeline
->vs_simd8
!= NO_KERNEL
? pipeline
->vs_simd8
:
434 if (vs_start
== NO_KERNEL
|| (extra
&& extra
->disable_vs
))
435 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VS
),
436 .FunctionEnable
= false,
437 /* Even if VS is disabled, SBE still gets the amount of
438 * vertex data to read from this field. */
439 .VertexURBEntryOutputReadOffset
= offset
,
440 .VertexURBEntryOutputLength
= length
);
442 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_VS
),
443 .KernelStartPointer
= vs_start
,
444 .SingleVertexDispatch
= Multiple
,
445 .VectorMaskEnable
= Dmask
,
447 .BindingTableEntryCount
=
448 vue_prog_data
->base
.binding_table
.size_bytes
/ 4,
449 .ThreadDispatchPriority
= Normal
,
450 .FloatingPointMode
= IEEE754
,
451 .IllegalOpcodeExceptionEnable
= false,
452 .AccessesUAV
= false,
453 .SoftwareExceptionEnable
= false,
455 .ScratchSpaceBasePointer
= pipeline
->scratch_start
[MESA_SHADER_VERTEX
],
456 .PerThreadScratchSpace
= ffs(vue_prog_data
->base
.total_scratch
/ 2048),
458 .DispatchGRFStartRegisterForURBData
=
459 vue_prog_data
->base
.dispatch_grf_start_reg
,
460 .VertexURBEntryReadLength
= vue_prog_data
->urb_read_length
,
461 .VertexURBEntryReadOffset
= 0,
463 .MaximumNumberofThreads
= device
->info
.max_vs_threads
- 1,
464 .StatisticsEnable
= false,
465 .SIMD8DispatchEnable
= pipeline
->vs_simd8
!= NO_KERNEL
,
466 .VertexCacheDisable
= false,
467 .FunctionEnable
= true,
469 .VertexURBEntryOutputReadOffset
= offset
,
470 .VertexURBEntryOutputLength
= length
,
471 .UserClipDistanceClipTestEnableBitmask
= 0,
472 .UserClipDistanceCullTestEnableBitmask
= 0);
474 const struct brw_wm_prog_data
*wm_prog_data
= &pipeline
->wm_prog_data
;
476 /* TODO: We should clean this up. Among other things, this is mostly
477 * shared with other gens.
479 const struct brw_vue_map
*fs_input_map
;
480 if (pipeline
->gs_kernel
== NO_KERNEL
)
481 fs_input_map
= &vue_prog_data
->vue_map
;
483 fs_input_map
= &gs_prog_data
->base
.vue_map
;
485 struct GENX(3DSTATE_SBE_SWIZ
) swiz
= {
486 GENX(3DSTATE_SBE_SWIZ_header
),
489 int max_source_attr
= 0;
490 for (int attr
= 0; attr
< VARYING_SLOT_MAX
; attr
++) {
491 int input_index
= wm_prog_data
->urb_setup
[attr
];
496 /* We have to subtract two slots to accout for the URB entry output
497 * read offset in the VS and GS stages.
499 int source_attr
= fs_input_map
->varying_to_slot
[attr
] - 2;
500 max_source_attr
= MAX2(max_source_attr
, source_attr
);
502 if (input_index
>= 16)
505 swiz
.Attribute
[input_index
].SourceAttribute
= source_attr
;
508 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_SBE
),
509 .AttributeSwizzleEnable
= true,
510 .ForceVertexURBEntryReadLength
= false,
511 .ForceVertexURBEntryReadOffset
= false,
512 .VertexURBEntryReadLength
= DIV_ROUND_UP(max_source_attr
+ 1, 2),
513 .PointSpriteTextureCoordinateOrigin
= UPPERLEFT
,
514 .NumberofSFOutputAttributes
=
515 wm_prog_data
->num_varying_inputs
,
518 .Attribute0ActiveComponentFormat
= ACF_XYZW
,
519 .Attribute1ActiveComponentFormat
= ACF_XYZW
,
520 .Attribute2ActiveComponentFormat
= ACF_XYZW
,
521 .Attribute3ActiveComponentFormat
= ACF_XYZW
,
522 .Attribute4ActiveComponentFormat
= ACF_XYZW
,
523 .Attribute5ActiveComponentFormat
= ACF_XYZW
,
524 .Attribute6ActiveComponentFormat
= ACF_XYZW
,
525 .Attribute7ActiveComponentFormat
= ACF_XYZW
,
526 .Attribute8ActiveComponentFormat
= ACF_XYZW
,
527 .Attribute9ActiveComponentFormat
= ACF_XYZW
,
528 .Attribute10ActiveComponentFormat
= ACF_XYZW
,
529 .Attribute11ActiveComponentFormat
= ACF_XYZW
,
530 .Attribute12ActiveComponentFormat
= ACF_XYZW
,
531 .Attribute13ActiveComponentFormat
= ACF_XYZW
,
532 .Attribute14ActiveComponentFormat
= ACF_XYZW
,
533 .Attribute15ActiveComponentFormat
= ACF_XYZW
,
534 /* wow, much field, very attribute */
535 .Attribute16ActiveComponentFormat
= ACF_XYZW
,
536 .Attribute17ActiveComponentFormat
= ACF_XYZW
,
537 .Attribute18ActiveComponentFormat
= ACF_XYZW
,
538 .Attribute19ActiveComponentFormat
= ACF_XYZW
,
539 .Attribute20ActiveComponentFormat
= ACF_XYZW
,
540 .Attribute21ActiveComponentFormat
= ACF_XYZW
,
541 .Attribute22ActiveComponentFormat
= ACF_XYZW
,
542 .Attribute23ActiveComponentFormat
= ACF_XYZW
,
543 .Attribute24ActiveComponentFormat
= ACF_XYZW
,
544 .Attribute25ActiveComponentFormat
= ACF_XYZW
,
545 .Attribute26ActiveComponentFormat
= ACF_XYZW
,
546 .Attribute27ActiveComponentFormat
= ACF_XYZW
,
547 .Attribute28ActiveComponentFormat
= ACF_XYZW
,
548 .Attribute29ActiveComponentFormat
= ACF_XYZW
,
549 .Attribute28ActiveComponentFormat
= ACF_XYZW
,
550 .Attribute29ActiveComponentFormat
= ACF_XYZW
,
551 .Attribute30ActiveComponentFormat
= ACF_XYZW
,
555 uint32_t *dw
= anv_batch_emit_dwords(&pipeline
->batch
,
556 GENX(3DSTATE_SBE_SWIZ_length
));
557 GENX(3DSTATE_SBE_SWIZ_pack
)(&pipeline
->batch
, dw
, &swiz
);
559 const int num_thread_bias
= ANV_GEN
== 8 ? 2 : 1;
560 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS
),
561 .KernelStartPointer0
= pipeline
->ps_ksp0
,
563 .SingleProgramFlow
= false,
564 .VectorMaskEnable
= true,
567 .ScratchSpaceBasePointer
= pipeline
->scratch_start
[MESA_SHADER_FRAGMENT
],
568 .PerThreadScratchSpace
= ffs(wm_prog_data
->base
.total_scratch
/ 2048),
570 .MaximumNumberofThreadsPerPSD
= 64 - num_thread_bias
,
571 .PositionXYOffsetSelect
= wm_prog_data
->uses_pos_offset
?
572 POSOFFSET_SAMPLE
: POSOFFSET_NONE
,
573 .PushConstantEnable
= wm_prog_data
->base
.nr_params
> 0,
574 ._8PixelDispatchEnable
= pipeline
->ps_simd8
!= NO_KERNEL
,
575 ._16PixelDispatchEnable
= pipeline
->ps_simd16
!= NO_KERNEL
,
576 ._32PixelDispatchEnable
= false,
578 .DispatchGRFStartRegisterForConstantSetupData0
= pipeline
->ps_grf_start0
,
579 .DispatchGRFStartRegisterForConstantSetupData1
= 0,
580 .DispatchGRFStartRegisterForConstantSetupData2
= pipeline
->ps_grf_start2
,
582 .KernelStartPointer1
= 0,
583 .KernelStartPointer2
= pipeline
->ps_ksp2
);
585 bool per_sample_ps
= false;
586 anv_batch_emit(&pipeline
->batch
, GENX(3DSTATE_PS_EXTRA
),
587 .PixelShaderValid
= true,
588 .PixelShaderKillsPixel
= wm_prog_data
->uses_kill
,
589 .PixelShaderComputedDepthMode
= wm_prog_data
->computed_depth_mode
,
590 .AttributeEnable
= wm_prog_data
->num_varying_inputs
> 0,
591 .oMaskPresenttoRenderTarget
= wm_prog_data
->uses_omask
,
592 .PixelShaderIsPerSample
= per_sample_ps
,
594 .PixelShaderPullsBary
= wm_prog_data
->pulls_bary
,
595 .InputCoverageMaskState
= ICMS_NONE
599 *pPipeline
= anv_pipeline_to_handle(pipeline
);
604 VkResult
genX(compute_pipeline_create
)(
606 const VkComputePipelineCreateInfo
* pCreateInfo
,
607 const VkAllocationCallbacks
* pAllocator
,
608 VkPipeline
* pPipeline
)
610 ANV_FROM_HANDLE(anv_device
, device
, _device
);
611 struct anv_pipeline
*pipeline
;
614 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO
);
616 pipeline
= anv_alloc2(&device
->alloc
, pAllocator
, sizeof(*pipeline
), 8,
617 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
618 if (pipeline
== NULL
)
619 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
621 pipeline
->device
= device
;
622 pipeline
->layout
= anv_pipeline_layout_from_handle(pCreateInfo
->layout
);
624 pipeline
->blend_state
.map
= NULL
;
626 result
= anv_reloc_list_init(&pipeline
->batch_relocs
,
627 pAllocator
? pAllocator
: &device
->alloc
);
628 if (result
!= VK_SUCCESS
) {
629 anv_free2(&device
->alloc
, pAllocator
, pipeline
);
632 pipeline
->batch
.next
= pipeline
->batch
.start
= pipeline
->batch_data
;
633 pipeline
->batch
.end
= pipeline
->batch
.start
+ sizeof(pipeline
->batch_data
);
634 pipeline
->batch
.relocs
= &pipeline
->batch_relocs
;
636 anv_state_stream_init(&pipeline
->program_stream
,
637 &device
->instruction_block_pool
);
639 /* When we free the pipeline, we detect stages based on the NULL status
640 * of various prog_data pointers. Make them NULL by default.
642 memset(pipeline
->prog_data
, 0, sizeof(pipeline
->prog_data
));
643 memset(pipeline
->scratch_start
, 0, sizeof(pipeline
->scratch_start
));
645 pipeline
->vs_simd8
= NO_KERNEL
;
646 pipeline
->vs_vec4
= NO_KERNEL
;
647 pipeline
->gs_kernel
= NO_KERNEL
;
649 pipeline
->active_stages
= 0;
650 pipeline
->total_scratch
= 0;
652 assert(pCreateInfo
->stage
.stage
== VK_SHADER_STAGE_COMPUTE_BIT
);
653 ANV_FROM_HANDLE(anv_shader_module
, module
, pCreateInfo
->stage
.module
);
654 anv_pipeline_compile_cs(pipeline
, pCreateInfo
, module
,
655 pCreateInfo
->stage
.pName
);
657 pipeline
->use_repclear
= false;
659 const struct brw_cs_prog_data
*cs_prog_data
= &pipeline
->cs_prog_data
;
661 anv_batch_emit(&pipeline
->batch
, GENX(MEDIA_VFE_STATE
),
662 .ScratchSpaceBasePointer
= pipeline
->scratch_start
[MESA_SHADER_COMPUTE
],
663 .PerThreadScratchSpace
= ffs(cs_prog_data
->base
.total_scratch
/ 2048),
664 .ScratchSpaceBasePointerHigh
= 0,
667 .MaximumNumberofThreads
= device
->info
.max_cs_threads
- 1,
668 .NumberofURBEntries
= 2,
669 .ResetGatewayTimer
= true,
671 .BypassGatewayControl
= true,
673 .URBEntryAllocationSize
= 2,
674 .CURBEAllocationSize
= 0);
676 struct brw_cs_prog_data
*prog_data
= &pipeline
->cs_prog_data
;
677 uint32_t group_size
= prog_data
->local_size
[0] *
678 prog_data
->local_size
[1] * prog_data
->local_size
[2];
679 pipeline
->cs_thread_width_max
= DIV_ROUND_UP(group_size
, prog_data
->simd_size
);
680 uint32_t remainder
= group_size
& (prog_data
->simd_size
- 1);
683 pipeline
->cs_right_mask
= ~0u >> (32 - remainder
);
685 pipeline
->cs_right_mask
= ~0u >> (32 - prog_data
->simd_size
);
688 *pPipeline
= anv_pipeline_to_handle(pipeline
);