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 DEALINGS
28 #include "libresoc_private.h"
29 #include "libresoc_shader.h"
32 #include "vk_format.h"
33 #include "util/debug.h"
35 VkResult
libresoc_create_shaders(struct libresoc_pipeline
*pipeline
,
36 struct libresoc_device
*device
,
37 const VkPipelineShaderStageCreateInfo
**pStages
,
38 const VkPipelineCreateFlags flags
)
40 struct libresoc_shader_module
*modules
[MESA_SHADER_STAGES
] = { 0, };
41 nir_shader
*nir
[MESA_SHADER_STAGES
] = {0};
43 for (unsigned i
= 0; i
< MESA_SHADER_STAGES
; ++i
) {
45 modules
[i
] = libresoc_shader_module_from_handle(pStages
[i
]->module
);
46 pipeline
->active_stages
|= mesa_to_vk_shader_stage(i
);
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;
58 nir
[i
] = libresoc_shader_compile_to_nir(device
, modules
[i
],
59 stage
? stage
->pName
: "main", i
,
60 stage
? stage
->pSpecializationInfo
: NULL
,
62 subgroup_size
, ballot_bit_size
);
64 /* We don't want to alter meta shaders IR directly so clone it
67 if (nir
[i
]->info
.name
) {
68 nir
[i
] = nir_shader_clone(NULL
, nir
[i
]);
77 libresoc_pipeline_init(struct libresoc_pipeline
*pipeline
,
78 struct libresoc_device
*device
,
79 const VkGraphicsPipelineCreateInfo
*pCreateInfo
)
82 pipeline
->device
= device
;
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
];
90 result
= libresoc_create_shaders(pipeline
, device
, pStages
,
92 if (result
!= VK_SUCCESS
)
95 //TODO: add more code as required
100 libresoc_graphics_pipeline_create(
102 VkPipelineCache _cache
,
103 const VkGraphicsPipelineCreateInfo
*pCreateInfo
,
104 const VkAllocationCallbacks
*pAllocator
,
105 VkPipeline
*pPipeline
)
107 LIBRESOC_FROM_HANDLE(libresoc_device
, device
, _device
);
108 struct libresoc_pipeline
*pipeline
;
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
);
116 vk_object_base_init(&device
->vk
, &pipeline
->base
,
117 VK_OBJECT_TYPE_PIPELINE
);
119 result
= libresoc_pipeline_init(pipeline
, device
,
121 if (result
!= VK_SUCCESS
) {
122 //libresoc_pipeline_destroy(device, pipeline, pAllocator);
126 *pPipeline
= libresoc_pipeline_to_handle(pipeline
);
131 VkResult
libresoc_CreateGraphicsPipelines(
133 VkPipelineCache pipelineCache
,
135 const VkGraphicsPipelineCreateInfo
* pCreateInfos
,
136 const VkAllocationCallbacks
* pAllocator
,
137 VkPipeline
* pPipelines
)
139 VkResult result
= VK_SUCCESS
;
142 for (; i
< count
; i
++) {
144 r
= libresoc_graphics_pipeline_create(_device
,
147 pAllocator
, &pPipelines
[i
]);
148 if (r
!= VK_SUCCESS
) {
150 pPipelines
[i
] = VK_NULL_HANDLE
;
152 if (pCreateInfos
[i
].flags
& VK_PIPELINE_CREATE_EARLY_RETURN_ON_FAILURE_BIT_EXT
)
157 for (; i
< count
; ++i
)
158 pPipelines
[i
] = VK_NULL_HANDLE
;
163 VkResult
libresoc_CreateComputePipelines(
165 VkPipelineCache pipelineCache
,
167 const VkComputePipelineCreateInfo
* pCreateInfos
,
168 const VkAllocationCallbacks
* pAllocator
,
169 VkPipeline
* pPipelines
)
171 VkResult result
= VK_SUCCESS
;
177 void libresoc_DestroyPipeline(
179 VkPipeline _pipeline
,
180 const VkAllocationCallbacks
* pAllocator
)