Added few more stubs so that control reaches to DestroyDevice().
[mesa.git] / src / libre-soc / vulkan / libresoc_pipeline.c
1 /*
2 * Copyright © 2016 Red Hat.
3 * Copyright © 2016 Bas Nieuwenhuizen
4 *
5 * based in part on anv driver which is:
6 * Copyright © 2015 Intel Corporation
7 *
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:
14 *
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
17 * Software.
18 *
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 DEALINGS
25 * IN THE SOFTWARE.
26 */
27
28 #include "libresoc_private.h"
29 #include "libresoc_shader.h"
30 #include "vk_util.h"
31
32 #include "vk_format.h"
33 #include "util/debug.h"
34
35 VkResult libresoc_create_shaders(struct libresoc_pipeline *pipeline,
36 struct libresoc_device *device,
37 const VkPipelineShaderStageCreateInfo **pStages,
38 const VkPipelineCreateFlags flags)
39 {
40 struct libresoc_shader_module *modules[MESA_SHADER_STAGES] = { 0, };
41 nir_shader *nir[MESA_SHADER_STAGES] = {0};
42
43 for (unsigned i = 0; i < MESA_SHADER_STAGES; ++i) {
44 if (pStages[i]) {
45 modules[i] = libresoc_shader_module_from_handle(pStages[i]->module);
46 pipeline->active_stages |= mesa_to_vk_shader_stage(i);
47 }
48 }
49
50
51 for (unsigned i = 0; i < MESA_SHADER_STAGES; ++i) {
52 const VkPipelineShaderStageCreateInfo *stage = pStages[i];
53 unsigned subgroup_size = 64, ballot_bit_size = 64;
54
55 if (!modules[i])
56 continue;
57
58 nir[i] = libresoc_shader_compile_to_nir(device, modules[i],
59 stage ? stage->pName : "main", i,
60 stage ? stage->pSpecializationInfo : NULL,
61 flags,
62 subgroup_size, ballot_bit_size);
63
64 /* We don't want to alter meta shaders IR directly so clone it
65 * first.
66 */
67 if (nir[i]->info.name) {
68 nir[i] = nir_shader_clone(NULL, nir[i]);
69 }
70
71 }
72
73
74 return VK_SUCCESS;
75 }
76 static VkResult
77 libresoc_pipeline_init(struct libresoc_pipeline *pipeline,
78 struct libresoc_device *device,
79 const VkGraphicsPipelineCreateInfo *pCreateInfo)
80 {
81 VkResult result;
82 pipeline->device = device;
83
84 const VkPipelineShaderStageCreateInfo *pStages[MESA_SHADER_STAGES] = { 0, };
85 for (uint32_t i = 0; i < pCreateInfo->stageCount; i++) {
86 gl_shader_stage stage = ffs(pCreateInfo->pStages[i].stage) - 1;
87 pStages[stage] = &pCreateInfo->pStages[i];
88 }
89
90 result = libresoc_create_shaders(pipeline, device, pStages,
91 pCreateInfo->flags);
92 if (result != VK_SUCCESS)
93 return result;
94
95 //TODO: add more code as required
96 return result;
97 }
98
99 VkResult
100 libresoc_graphics_pipeline_create(
101 VkDevice _device,
102 VkPipelineCache _cache,
103 const VkGraphicsPipelineCreateInfo *pCreateInfo,
104 const VkAllocationCallbacks *pAllocator,
105 VkPipeline *pPipeline)
106 {
107 LIBRESOC_FROM_HANDLE(libresoc_device, device, _device);
108 struct libresoc_pipeline *pipeline;
109 VkResult result;
110
111 pipeline = vk_zalloc2(&device->vk.alloc, pAllocator, sizeof(*pipeline), 8,
112 VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
113 if (pipeline == NULL)
114 return vk_error(device->instance, VK_ERROR_OUT_OF_HOST_MEMORY);
115
116 vk_object_base_init(&device->vk, &pipeline->base,
117 VK_OBJECT_TYPE_PIPELINE);
118
119 result = libresoc_pipeline_init(pipeline, device,
120 pCreateInfo);
121 if (result != VK_SUCCESS) {
122 //libresoc_pipeline_destroy(device, pipeline, pAllocator);
123 return result;
124 }
125
126 *pPipeline = libresoc_pipeline_to_handle(pipeline);
127
128 return VK_SUCCESS;
129 }
130
131 VkResult libresoc_CreateGraphicsPipelines(
132 VkDevice _device,
133 VkPipelineCache pipelineCache,
134 uint32_t count,
135 const VkGraphicsPipelineCreateInfo* pCreateInfos,
136 const VkAllocationCallbacks* pAllocator,
137 VkPipeline* pPipelines)
138 {
139 VkResult result = VK_SUCCESS;
140 unsigned i = 0;
141
142 for (; i < count; i++) {
143 VkResult r;
144 r = libresoc_graphics_pipeline_create(_device,
145 pipelineCache,
146 &pCreateInfos[i],
147 pAllocator, &pPipelines[i]);
148 if (r != VK_SUCCESS) {
149 result = r;
150 pPipelines[i] = VK_NULL_HANDLE;
151
152 if (pCreateInfos[i].flags & VK_PIPELINE_CREATE_EARLY_RETURN_ON_FAILURE_BIT_EXT)
153 break;
154 }
155 }
156
157 for (; i < count; ++i)
158 pPipelines[i] = VK_NULL_HANDLE;
159
160 return result;
161 }
162
163 VkResult libresoc_CreateComputePipelines(
164 VkDevice _device,
165 VkPipelineCache pipelineCache,
166 uint32_t count,
167 const VkComputePipelineCreateInfo* pCreateInfos,
168 const VkAllocationCallbacks* pAllocator,
169 VkPipeline* pPipelines)
170 {
171 VkResult result = VK_SUCCESS;
172 //FIXME: stub
173
174 return result;
175 }
176
177 void libresoc_DestroyPipeline(
178 VkDevice _device,
179 VkPipeline _pipeline,
180 const VkAllocationCallbacks* pAllocator)
181 {
182 //FIXME: stub
183 }