From 3ce1db339d9e8fe313cdaaa212834a21b4b737d4 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Mon, 19 Sep 2022 16:56:14 -0500 Subject: [PATCH] vulkan: Add a helper for gathering pipeline robustness This is useful for implementing VK_EXT_pipeline_robustness because it automatically gathers all the bits from everywhere for you. Reviewed-by: Iago Toral Quiroga Reviewed-by: Lionel Landwerlin Part-of: --- src/vulkan/runtime/vk_pipeline.c | 72 ++++++++++++++++++++++++++++++++ src/vulkan/runtime/vk_pipeline.h | 13 ++++++ 2 files changed, 85 insertions(+) diff --git a/src/vulkan/runtime/vk_pipeline.c b/src/vulkan/runtime/vk_pipeline.c index e4183f38ed3..8b7f9209acd 100644 --- a/src/vulkan/runtime/vk_pipeline.c +++ b/src/vulkan/runtime/vk_pipeline.c @@ -23,6 +23,7 @@ #include "vk_pipeline.h" +#include "vk_device.h" #include "vk_log.h" #include "vk_nir.h" #include "vk_shader_module.h" @@ -203,3 +204,74 @@ vk_pipeline_hash_shader_stage(const VkPipelineShaderStageCreateInfo *info, _mesa_sha1_final(&ctx, stage_sha1); } + +static VkPipelineRobustnessBufferBehaviorEXT +vk_device_default_robust_buffer_behavior(const struct vk_device *device) +{ + if (device->enabled_features.robustBufferAccess2) { + return VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_ROBUST_BUFFER_ACCESS_2_EXT; + } else if (device->enabled_features.robustBufferAccess) { + return VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_ROBUST_BUFFER_ACCESS_EXT; + } else { + return VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DISABLED_EXT; + } +} + +static VkPipelineRobustnessImageBehaviorEXT +vk_device_default_robust_image_behavior(const struct vk_device *device) +{ + if (device->enabled_features.robustImageAccess2) { + return VK_PIPELINE_ROBUSTNESS_IMAGE_BEHAVIOR_ROBUST_IMAGE_ACCESS_2_EXT; + } else if (device->enabled_features.robustImageAccess) { + return VK_PIPELINE_ROBUSTNESS_IMAGE_BEHAVIOR_ROBUST_IMAGE_ACCESS_EXT; + } else { + return VK_PIPELINE_ROBUSTNESS_IMAGE_BEHAVIOR_DISABLED_EXT; + } +} + +void +vk_pipeline_robustness_state_fill(const struct vk_device *device, + struct vk_pipeline_robustness_state *rs, + const void *pipeline_pNext, + const void *shader_stage_pNext) +{ + rs->uniform_buffers = VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DEVICE_DEFAULT_EXT; + rs->storage_buffers = VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DEVICE_DEFAULT_EXT; + rs->vertex_inputs = VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DEVICE_DEFAULT_EXT; + rs->images = VK_PIPELINE_ROBUSTNESS_IMAGE_BEHAVIOR_DEVICE_DEFAULT_EXT; + + const VkPipelineRobustnessCreateInfoEXT *shader_info = + vk_find_struct_const(shader_stage_pNext, + PIPELINE_ROBUSTNESS_CREATE_INFO_EXT); + if (shader_info) { + rs->storage_buffers = shader_info->storageBuffers; + rs->uniform_buffers = shader_info->uniformBuffers; + rs->vertex_inputs = shader_info->vertexInputs; + rs->images = shader_info->images; + } else { + const VkPipelineRobustnessCreateInfoEXT *pipeline_info = + vk_find_struct_const(pipeline_pNext, + PIPELINE_ROBUSTNESS_CREATE_INFO_EXT); + if (pipeline_info) { + rs->storage_buffers = pipeline_info->storageBuffers; + rs->uniform_buffers = pipeline_info->uniformBuffers; + rs->vertex_inputs = pipeline_info->vertexInputs; + rs->images = pipeline_info->images; + } + } + + if (rs->storage_buffers == + VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DEVICE_DEFAULT_EXT) + rs->storage_buffers = vk_device_default_robust_buffer_behavior(device); + + if (rs->uniform_buffers == + VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DEVICE_DEFAULT_EXT) + rs->uniform_buffers = vk_device_default_robust_buffer_behavior(device); + + if (rs->vertex_inputs == + VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DEVICE_DEFAULT_EXT) + rs->vertex_inputs = vk_device_default_robust_buffer_behavior(device); + + if (rs->images == VK_PIPELINE_ROBUSTNESS_IMAGE_BEHAVIOR_DEVICE_DEFAULT_EXT) + rs->images = vk_device_default_robust_image_behavior(device); +} diff --git a/src/vulkan/runtime/vk_pipeline.h b/src/vulkan/runtime/vk_pipeline.h index e4ead1a2bf5..76a8d58fad6 100644 --- a/src/vulkan/runtime/vk_pipeline.h +++ b/src/vulkan/runtime/vk_pipeline.h @@ -62,6 +62,19 @@ void vk_pipeline_hash_shader_stage(const VkPipelineShaderStageCreateInfo *info, unsigned char *stage_sha1); +struct vk_pipeline_robustness_state { + VkPipelineRobustnessBufferBehaviorEXT storage_buffers; + VkPipelineRobustnessBufferBehaviorEXT uniform_buffers; + VkPipelineRobustnessBufferBehaviorEXT vertex_inputs; + VkPipelineRobustnessImageBehaviorEXT images; +}; + +void +vk_pipeline_robustness_state_fill(const struct vk_device *device, + struct vk_pipeline_robustness_state *rs, + const void *pipeline_pNext, + const void *shader_stage_pNext); + #ifdef __cplusplus } #endif