About Social Code
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFaith Ekstrand <faith.ekstrand@collabora.com>2025-10-23 15:15:39 -0400
committerMarge Bot <marge-bot@fdo.invalid>2025-11-06 15:27:29 +0000
commit59a89cd762ebb5fa7c2e0da89f79e3baa0d90f97 (patch)
tree9f2ac73140114eabea169d39d53224922b5b0193
parent5c47ac640b21c40c30f29600997a9337ba399916 (diff)
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>
-rw-r--r--src/vulkan/runtime/vk_pipeline.c29
-rw-r--r--src/vulkan/runtime/vk_shader.c31
-rw-r--r--src/vulkan/runtime/vk_shader.h8
3 files changed, 49 insertions, 19 deletions
diff --git a/src/vulkan/runtime/vk_pipeline.c b/src/vulkan/runtime/vk_pipeline.c
index 63eb6b0333e..28b5fbfa48d 100644
--- a/src/vulkan/runtime/vk_pipeline.c
+++ b/src/vulkan/runtime/vk_pipeline.c
@@ -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;
diff --git a/src/vulkan/runtime/vk_shader.c b/src/vulkan/runtime/vk_shader.c
index e2fbce35759..6ba9d450905 100644
--- a/src/vulkan/runtime/vk_shader.c
+++ b/src/vulkan/runtime/vk_shader.c
@@ -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]);
diff --git a/src/vulkan/runtime/vk_shader.h b/src/vulkan/runtime/vk_shader.h
index 44595621caa..57e940b3bba 100644
--- a/src/vulkan/runtime/vk_shader.h
+++ b/src/vulkan/runtime/vk_shader.h
@@ -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,