vulkan/runtime: Add a vk_compile_shaders() helper

This is just a wrapper around ops->compile() for now but we'll extend it
in the next commit to add some validation.

Acked-by: Eric R. Smith <eric.smith@collabora.com>
Reviewed-by: Lars-Ivar Hesselberg Simonsen <lars-ivar.simonsen@arm.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36647>
This commit is contained in:
Faith Ekstrand 2025-10-23 15:15:39 -04:00 committed by Marge Bot
parent 5c47ac640b
commit 59a89cd762
3 changed files with 49 additions and 19 deletions

View file

@ -1778,12 +1778,12 @@ vk_graphics_pipeline_compile_shaders(struct vk_device *device,
* returns, we own the shaders but not the NIR in infos.
*/
struct vk_shader *shaders[MESA_VK_MAX_GRAPHICS_PIPELINE_STAGES];
result = ops->compile(device,
compile_info->partition[p + 1] - compile_info->partition[p],
&infos[compile_info->partition[p]],
compile_info->state, &device->enabled_features,
&device->alloc,
&shaders[compile_info->partition[p]]);
result = vk_compile_shaders(device,
compile_info->partition[p + 1] - compile_info->partition[p],
&infos[compile_info->partition[p]],
compile_info->state, &device->enabled_features,
&device->alloc,
&shaders[compile_info->partition[p]]);
if (result != VK_SUCCESS)
return result;
@ -2406,8 +2406,9 @@ vk_pipeline_compile_compute_stage(struct vk_device *device,
};
struct vk_shader *shader;
result = ops->compile(device, 1, &compile_info, NULL,
&device->enabled_features, &device->alloc, &shader);
result = vk_compile_shaders(device, 1, &compile_info,
NULL, &device->enabled_features,
&device->alloc, &shader);
if (result != VK_SUCCESS)
return result;
@ -3188,9 +3189,9 @@ vk_pipeline_compile_rt_shader(struct vk_device *device,
};
struct vk_shader *shader;
VkResult result = ops->compile(device, 1, &compile_info,
NULL, &device->enabled_features,
&device->alloc, &shader);
VkResult result = vk_compile_shaders(device, 1, &compile_info,
NULL, &device->enabled_features,
&device->alloc, &shader);
if (result != VK_SUCCESS)
return result;
@ -3305,9 +3306,9 @@ vk_pipeline_compile_rt_shader_group(struct vk_device *device,
}
struct vk_shader *shaders[3];
VkResult result = ops->compile(device, stage_count, compile_info,
NULL, &device->enabled_features,
&device->alloc, shaders);
VkResult result = vk_compile_shaders(device, stage_count, compile_info,
NULL, &device->enabled_features,
&device->alloc, shaders);
if (result != VK_SUCCESS)
return result;

View file

@ -139,6 +139,26 @@ vk_shader_cmp_rt_stages(mesa_shader_stage a, mesa_shader_stage b)
return stage_order[a] - stage_order[b];
}
VkResult
vk_compile_shaders(struct vk_device *device,
uint32_t shader_count,
struct vk_shader_compile_info *infos,
const struct vk_graphics_pipeline_state *state,
const struct vk_features *enabled_features,
const VkAllocationCallbacks* pAllocator,
struct vk_shader **shaders_out)
{
const struct vk_device_shader_ops *ops = device->shader_ops;
VkResult result;
result = ops->compile(device, shader_count, infos, state,
enabled_features, pAllocator, shaders_out);
if (result != VK_SUCCESS)
return result;
return VK_SUCCESS;
}
struct stage_idx {
mesa_shader_stage stage;
uint32_t idx;
@ -451,7 +471,6 @@ vk_common_CreateShadersEXT(VkDevice _device,
VkShaderEXT *pShaders)
{
VK_FROM_HANDLE(vk_device, device, _device);
const struct vk_device_shader_ops *ops = device->shader_ops;
VkResult first_fail_or_success = VK_SUCCESS;
/* From the Vulkan 1.3.274 spec:
@ -525,8 +544,9 @@ vk_common_CreateShadersEXT(VkDevice _device,
vk_info, &vk_robustness_disabled, nir);
struct vk_shader *shader;
result = ops->compile(device, 1, &info, NULL /* state */,
NULL /* features */, pAllocator, &shader);
result = vk_compile_shaders(device, 1, &info,
NULL /* state */, NULL /* features */,
pAllocator, &shader);
if (result != VK_SUCCESS)
break;
@ -572,8 +592,9 @@ vk_common_CreateShadersEXT(VkDevice _device,
if (result == VK_SUCCESS) {
struct vk_shader *shaders[VK_MAX_LINKED_SHADER_STAGES];
result = ops->compile(device, linked_count, infos, NULL /* state */,
NULL /* features */, pAllocator, shaders);
result = vk_compile_shaders(device, linked_count, infos,
NULL /* state */, NULL /* features */,
pAllocator, shaders);
if (result == VK_SUCCESS) {
for (uint32_t l = 0; l < linked_count; l++)
pShaders[linked[l].idx] = vk_shader_to_handle(shaders[l]);

View file

@ -192,6 +192,14 @@ void vk_shader_free(struct vk_device *device,
const VkAllocationCallbacks *alloc,
struct vk_shader *shader);
VkResult vk_compile_shaders(struct vk_device *device,
uint32_t shader_count,
struct vk_shader_compile_info *infos,
const struct vk_graphics_pipeline_state *state,
const struct vk_features *enabled_features,
const VkAllocationCallbacks* pAllocator,
struct vk_shader **shaders_out);
static inline void
vk_shader_destroy(struct vk_device *device,
struct vk_shader *shader,