2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
28 #include "tu_private.h"
30 #include "main/menums.h"
32 #include "nir/nir_builder.h"
33 #include "spirv/nir_spirv.h"
34 #include "util/debug.h"
35 #include "util/mesa-sha1.h"
36 #include "util/u_atomic.h"
37 #include "vk_format.h"
42 struct tu_pipeline_builder
44 struct tu_device
*device
;
45 struct tu_pipeline_cache
*cache
;
46 const VkAllocationCallbacks
*alloc
;
47 const VkGraphicsPipelineCreateInfo
*create_info
;
51 tu_pipeline_builder_create_pipeline(struct tu_pipeline_builder
*builder
,
52 struct tu_pipeline
**out_pipeline
)
54 struct tu_device
*dev
= builder
->device
;
56 struct tu_pipeline
*pipeline
=
57 vk_zalloc2(&dev
->alloc
, builder
->alloc
, sizeof(*pipeline
), 8,
58 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT
);
60 return VK_ERROR_OUT_OF_HOST_MEMORY
;
62 tu_cs_init(&pipeline
->cs
, TU_CS_MODE_SUB_STREAM
, 2048);
64 /* reserve the space now such that tu_cs_begin_sub_stream never fails */
65 VkResult result
= tu_cs_reserve_space(dev
, &pipeline
->cs
, 2048);
66 if (result
!= VK_SUCCESS
) {
67 vk_free2(&dev
->alloc
, builder
->alloc
, pipeline
);
71 *out_pipeline
= pipeline
;
77 tu_pipeline_finish(struct tu_pipeline
*pipeline
,
78 struct tu_device
*dev
,
79 const VkAllocationCallbacks
*alloc
)
81 tu_cs_finish(dev
, &pipeline
->cs
);
85 tu_pipeline_builder_build(struct tu_pipeline_builder
*builder
,
86 struct tu_pipeline
**pipeline
)
88 VkResult result
= tu_pipeline_builder_create_pipeline(builder
, pipeline
);
89 if (result
!= VK_SUCCESS
)
92 /* we should have reserved enough space upfront such that the CS never
95 assert((*pipeline
)->cs
.bo_count
== 1);
101 tu_pipeline_builder_init_graphics(
102 struct tu_pipeline_builder
*builder
,
103 struct tu_device
*dev
,
104 struct tu_pipeline_cache
*cache
,
105 const VkGraphicsPipelineCreateInfo
*create_info
,
106 const VkAllocationCallbacks
*alloc
)
108 *builder
= (struct tu_pipeline_builder
) {
111 .create_info
= create_info
,
117 tu_CreateGraphicsPipelines(VkDevice device
,
118 VkPipelineCache pipelineCache
,
120 const VkGraphicsPipelineCreateInfo
*pCreateInfos
,
121 const VkAllocationCallbacks
*pAllocator
,
122 VkPipeline
*pPipelines
)
124 TU_FROM_HANDLE(tu_device
, dev
, device
);
125 TU_FROM_HANDLE(tu_pipeline_cache
, cache
, pipelineCache
);
127 for (uint32_t i
= 0; i
< count
; i
++) {
128 struct tu_pipeline_builder builder
;
129 tu_pipeline_builder_init_graphics(&builder
, dev
, cache
,
130 &pCreateInfos
[i
], pAllocator
);
132 struct tu_pipeline
*pipeline
;
133 VkResult result
= tu_pipeline_builder_build(&builder
, &pipeline
);
135 if (result
!= VK_SUCCESS
) {
136 for (uint32_t j
= 0; j
< i
; j
++) {
137 tu_DestroyPipeline(device
, pPipelines
[j
], pAllocator
);
138 pPipelines
[j
] = VK_NULL_HANDLE
;
144 pPipelines
[i
] = tu_pipeline_to_handle(pipeline
);
151 tu_compute_pipeline_create(VkDevice _device
,
152 VkPipelineCache _cache
,
153 const VkComputePipelineCreateInfo
*pCreateInfo
,
154 const VkAllocationCallbacks
*pAllocator
,
155 VkPipeline
*pPipeline
)
161 tu_CreateComputePipelines(VkDevice _device
,
162 VkPipelineCache pipelineCache
,
164 const VkComputePipelineCreateInfo
*pCreateInfos
,
165 const VkAllocationCallbacks
*pAllocator
,
166 VkPipeline
*pPipelines
)
168 VkResult result
= VK_SUCCESS
;
171 for (; i
< count
; i
++) {
173 r
= tu_compute_pipeline_create(_device
, pipelineCache
, &pCreateInfos
[i
],
174 pAllocator
, &pPipelines
[i
]);
175 if (r
!= VK_SUCCESS
) {
177 pPipelines
[i
] = VK_NULL_HANDLE
;
185 tu_DestroyPipeline(VkDevice _device
,
186 VkPipeline _pipeline
,
187 const VkAllocationCallbacks
*pAllocator
)
189 TU_FROM_HANDLE(tu_device
, dev
, _device
);
190 TU_FROM_HANDLE(tu_pipeline
, pipeline
, _pipeline
);
195 tu_pipeline_finish(pipeline
, dev
, pAllocator
);
196 vk_free2(&dev
->alloc
, pAllocator
, pipeline
);