vulkan: pre-compute the default robustness state in the device

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/41029>
This commit is contained in:
Samuel Pitoiset 2026-04-17 15:36:53 +02:00 committed by Marge Bot
parent 5828ebeb70
commit b7a8b09b21
3 changed files with 38 additions and 32 deletions

View file

@ -131,6 +131,30 @@ vk_device_memory_report_init(struct vk_device *device,
return VK_SUCCESS;
}
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;
}
}
VkResult
vk_device_init(struct vk_device *device,
struct vk_physical_device *physical_device,
@ -271,6 +295,15 @@ vk_device_init(struct vk_device *device,
if (result != VK_SUCCESS)
return result;
device->robustness_state = (struct vk_pipeline_robustness_state) {
.uniform_buffers = vk_device_default_robust_buffer_behavior(device),
.storage_buffers = vk_device_default_robust_buffer_behavior(device),
.vertex_inputs = vk_device_default_robust_buffer_behavior(device),
.images = vk_device_default_robust_image_behavior(device),
.null_uniform_buffer_descriptor = device->enabled_features.nullDescriptor,
.null_storage_buffer_descriptor = device->enabled_features.nullDescriptor,
};
device->disable_lto = false;
return VK_SUCCESS;

View file

@ -28,6 +28,7 @@
#include "vk_extensions.h"
#include "vk_object.h"
#include "vk_physical_device_features.h"
#include "vk_pipeline.h"
#include "util/list.h"
#include "util/simple_mtx.h"
@ -318,6 +319,8 @@ struct vk_device {
struct vk_device_memory_report *memory_reports;
uint32_t memory_report_count;
struct vk_pipeline_robustness_state robustness_state;
};
VK_DEFINE_HANDLE_CASTS(vk_device, base, VkDevice,

View file

@ -328,44 +328,14 @@ vk_pipeline_hash_shader_stage(VkPipelineCreateFlags2KHR pipeline_flags,
_mesa_blake3_compute(blake_hash, sizeof(blake_hash), stage_blake3);
}
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 = (struct vk_pipeline_robustness_state) {
.uniform_buffers = vk_device_default_robust_buffer_behavior(device),
.storage_buffers = vk_device_default_robust_buffer_behavior(device),
.vertex_inputs = vk_device_default_robust_buffer_behavior(device),
.images = vk_device_default_robust_image_behavior(device),
.null_uniform_buffer_descriptor = device->enabled_features.nullDescriptor,
.null_storage_buffer_descriptor = device->enabled_features.nullDescriptor,
};
/* Use the device robustness state by default. */
*rs = device->robustness_state;
const VkPipelineRobustnessCreateInfoEXT *shader_info =
vk_find_struct_const(shader_stage_pNext,