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 "genX_pipeline_util.h"
32 genX(graphics_pipeline_create
)(
34 struct anv_pipeline_cache
* cache
,
35 const VkGraphicsPipelineCreateInfo
* pCreateInfo
,
36 const VkAllocationCallbacks
* pAllocator
,
37 VkPipeline
* pPipeline
)
39 ANV_FROM_HANDLE(anv_device
, device
, _device
);
40 ANV_FROM_HANDLE(anv_render_pass
, pass
, pCreateInfo
->renderPass
);
41 struct anv_subpass
*subpass
= &pass
->subpasses
[pCreateInfo
->subpass
];
42 struct anv_pipeline
*pipeline
;
45 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO
);
47 pipeline
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*pipeline
), 8,
48 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
50 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
52 result
= anv_pipeline_init(pipeline
, device
, cache
,
53 pCreateInfo
, pAllocator
);
54 if (result
!= VK_SUCCESS
) {
55 vk_free2(&device
->alloc
, pAllocator
, pipeline
);
59 assert(pCreateInfo
->pVertexInputState
);
60 emit_vertex_input(pipeline
, pCreateInfo
->pVertexInputState
);
61 assert(pCreateInfo
->pRasterizationState
);
62 emit_rs_state(pipeline
, pCreateInfo
->pRasterizationState
,
63 pCreateInfo
->pMultisampleState
, pass
, subpass
);
64 emit_ms_state(pipeline
, pCreateInfo
->pMultisampleState
);
65 emit_ds_state(pipeline
, pCreateInfo
->pDepthStencilState
, pass
, subpass
);
66 emit_cb_state(pipeline
, pCreateInfo
->pColorBlendState
,
67 pCreateInfo
->pMultisampleState
);
69 emit_urb_setup(pipeline
);
71 emit_3dstate_clip(pipeline
, pCreateInfo
->pViewportState
,
72 pCreateInfo
->pRasterizationState
);
73 emit_3dstate_streamout(pipeline
, pCreateInfo
->pRasterizationState
);
76 /* From gen7_vs_state.c */
79 * From Graphics BSpec: 3D-Media-GPGPU Engine > 3D Pipeline Stages >
80 * Geometry > Geometry Shader > State:
82 * "Note: Because of corruption in IVB:GT2, software needs to flush the
83 * whole fixed function pipeline when the GS enable changes value in
86 * The hardware architects have clarified that in this context "flush the
87 * whole fixed function pipeline" means to emit a PIPE_CONTROL with the "CS
90 if (!brw
->is_haswell
&& !brw
->is_baytrail
)
91 gen7_emit_vs_workaround_flush(brw
);
94 emit_3dstate_vs(pipeline
);
95 emit_3dstate_gs(pipeline
);
96 emit_3dstate_sbe(pipeline
);
97 emit_3dstate_wm(pipeline
, pCreateInfo
->pMultisampleState
);
98 emit_3dstate_ps(pipeline
);
100 emit_3dstate_ps_extra(pipeline
);
101 emit_3dstate_vf_topology(pipeline
);
104 *pPipeline
= anv_pipeline_to_handle(pipeline
);
110 compute_pipeline_create(
112 struct anv_pipeline_cache
* cache
,
113 const VkComputePipelineCreateInfo
* pCreateInfo
,
114 const VkAllocationCallbacks
* pAllocator
,
115 VkPipeline
* pPipeline
)
117 ANV_FROM_HANDLE(anv_device
, device
, _device
);
118 const struct anv_physical_device
*physical_device
=
119 &device
->instance
->physicalDevice
;
120 const struct gen_device_info
*devinfo
= &physical_device
->info
;
121 struct anv_pipeline
*pipeline
;
124 assert(pCreateInfo
->sType
== VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO
);
126 pipeline
= vk_alloc2(&device
->alloc
, pAllocator
, sizeof(*pipeline
), 8,
127 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
128 if (pipeline
== NULL
)
129 return vk_error(VK_ERROR_OUT_OF_HOST_MEMORY
);
131 pipeline
->device
= device
;
132 pipeline
->layout
= anv_pipeline_layout_from_handle(pCreateInfo
->layout
);
134 pipeline
->blend_state
.map
= NULL
;
136 result
= anv_reloc_list_init(&pipeline
->batch_relocs
,
137 pAllocator
? pAllocator
: &device
->alloc
);
138 if (result
!= VK_SUCCESS
) {
139 vk_free2(&device
->alloc
, pAllocator
, pipeline
);
142 pipeline
->batch
.next
= pipeline
->batch
.start
= pipeline
->batch_data
;
143 pipeline
->batch
.end
= pipeline
->batch
.start
+ sizeof(pipeline
->batch_data
);
144 pipeline
->batch
.relocs
= &pipeline
->batch_relocs
;
146 /* When we free the pipeline, we detect stages based on the NULL status
147 * of various prog_data pointers. Make them NULL by default.
149 memset(pipeline
->shaders
, 0, sizeof(pipeline
->shaders
));
151 pipeline
->active_stages
= 0;
153 pipeline
->needs_data_cache
= false;
155 assert(pCreateInfo
->stage
.stage
== VK_SHADER_STAGE_COMPUTE_BIT
);
156 ANV_FROM_HANDLE(anv_shader_module
, module
, pCreateInfo
->stage
.module
);
157 result
= anv_pipeline_compile_cs(pipeline
, cache
, pCreateInfo
, module
,
158 pCreateInfo
->stage
.pName
,
159 pCreateInfo
->stage
.pSpecializationInfo
);
160 if (result
!= VK_SUCCESS
) {
161 vk_free2(&device
->alloc
, pAllocator
, pipeline
);
165 const struct brw_cs_prog_data
*cs_prog_data
= get_cs_prog_data(pipeline
);
167 anv_pipeline_setup_l3_config(pipeline
, cs_prog_data
->base
.total_shared
> 0);
169 uint32_t group_size
= cs_prog_data
->local_size
[0] *
170 cs_prog_data
->local_size
[1] * cs_prog_data
->local_size
[2];
171 uint32_t remainder
= group_size
& (cs_prog_data
->simd_size
- 1);
174 pipeline
->cs_right_mask
= ~0u >> (32 - remainder
);
176 pipeline
->cs_right_mask
= ~0u >> (32 - cs_prog_data
->simd_size
);
178 const uint32_t vfe_curbe_allocation
=
179 ALIGN(cs_prog_data
->push
.per_thread
.regs
* cs_prog_data
->threads
+
180 cs_prog_data
->push
.cross_thread
.regs
, 2);
182 const uint32_t subslices
= MAX2(physical_device
->subslice_total
, 1);
184 anv_batch_emit(&pipeline
->batch
, GENX(MEDIA_VFE_STATE
), vfe
) {
185 vfe
.ScratchSpaceBasePointer
= (struct anv_address
) {
186 .bo
= anv_scratch_pool_alloc(device
, &device
->scratch_pool
,
188 cs_prog_data
->base
.total_scratch
),
191 vfe
.PerThreadScratchSpace
= ffs(cs_prog_data
->base
.total_scratch
/ 2048);
195 vfe
.GPGPUMode
= true;
197 vfe
.MaximumNumberofThreads
=
198 devinfo
->max_cs_threads
* subslices
- 1;
199 vfe
.NumberofURBEntries
= GEN_GEN
<= 7 ? 0 : 2;
200 vfe
.ResetGatewayTimer
= true;
202 vfe
.BypassGatewayControl
= true;
204 vfe
.URBEntryAllocationSize
= GEN_GEN
<= 7 ? 0 : 2;
205 vfe
.CURBEAllocationSize
= vfe_curbe_allocation
;
208 *pPipeline
= anv_pipeline_to_handle(pipeline
);
213 VkResult
genX(CreateGraphicsPipelines
)(
215 VkPipelineCache pipelineCache
,
217 const VkGraphicsPipelineCreateInfo
* pCreateInfos
,
218 const VkAllocationCallbacks
* pAllocator
,
219 VkPipeline
* pPipelines
)
221 ANV_FROM_HANDLE(anv_pipeline_cache
, pipeline_cache
, pipelineCache
);
223 VkResult result
= VK_SUCCESS
;
226 for (; i
< count
; i
++) {
227 result
= genX(graphics_pipeline_create
)(_device
,
230 pAllocator
, &pPipelines
[i
]);
231 if (result
!= VK_SUCCESS
) {
232 for (unsigned j
= 0; j
< i
; j
++) {
233 anv_DestroyPipeline(_device
, pPipelines
[j
], pAllocator
);
243 VkResult
genX(CreateComputePipelines
)(
245 VkPipelineCache pipelineCache
,
247 const VkComputePipelineCreateInfo
* pCreateInfos
,
248 const VkAllocationCallbacks
* pAllocator
,
249 VkPipeline
* pPipelines
)
251 ANV_FROM_HANDLE(anv_pipeline_cache
, pipeline_cache
, pipelineCache
);
253 VkResult result
= VK_SUCCESS
;
256 for (; i
< count
; i
++) {
257 result
= compute_pipeline_create(_device
, pipeline_cache
,
259 pAllocator
, &pPipelines
[i
]);
260 if (result
!= VK_SUCCESS
) {
261 for (unsigned j
= 0; j
< i
; j
++) {
262 anv_DestroyPipeline(_device
, pPipelines
[j
], pAllocator
);