From 24d9a80247605ac2c2377f6806df8c51e6e13b94 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Tue, 27 Sep 2022 13:02:45 +0200 Subject: [PATCH] v3dv: implement VK_EXT_pipeline_robustness MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Alejandro Piñeiro Part-of: --- docs/features.txt | 1 + docs/relnotes/new_features.txt | 1 + src/broadcom/compiler/v3d_compiler.h | 3 +- .../compiler/v3d_nir_lower_robust_access.c | 26 +++++++--- src/broadcom/compiler/vir.c | 2 +- src/broadcom/vulkan/v3dv_device.c | 21 ++++++++ src/broadcom/vulkan/v3dv_pipeline.c | 57 ++++++++++++---------- src/broadcom/vulkan/v3dv_private.h | 5 +- 8 files changed, 81 insertions(+), 35 deletions(-) diff --git a/docs/features.txt b/docs/features.txt index bb100a1..f9cd93c 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -570,6 +570,7 @@ Khronos extensions that are not part of any Vulkan version: VK_EXT_non_seamless_cube_map DONE (anv, lvp, radv, tu) VK_EXT_pci_bus_info DONE (anv, radv) VK_EXT_physical_device_drm DONE (anv, radv, tu, v3dv, vn) + VK_EXT_pipeline_robustness DONE (v3dv) VK_EXT_post_depth_coverage DONE (anv/gfx10+, lvp, radv/gfx10+) VK_EXT_primitive_topology_list_restart DONE (anv, lvp, radv, tu, v3dv, vn) VK_EXT_primitives_generated_query DONE (anv, lvp, radv, tu, vn) diff --git a/docs/relnotes/new_features.txt b/docs/relnotes/new_features.txt index ac9c239..91c722e 100644 --- a/docs/relnotes/new_features.txt +++ b/docs/relnotes/new_features.txt @@ -12,3 +12,4 @@ GL_NV_shader_atomic_float on llvmpipe VK_EXT_image_robustness on v3dv VK_EXT_extended_dynamic_state3 on lavapipe VK_EXT_extended_dynamic_state3 on RADV +VK_EXT_pipeline_robustness on v3dv diff --git a/src/broadcom/compiler/v3d_compiler.h b/src/broadcom/compiler/v3d_compiler.h index b41c361..3879f61 100644 --- a/src/broadcom/compiler/v3d_compiler.h +++ b/src/broadcom/compiler/v3d_compiler.h @@ -404,7 +404,8 @@ struct v3d_key { uint8_t num_samplers_used; uint8_t ucp_enables; bool is_last_geometry_stage; - bool robust_buffer_access; + bool robust_uniform_access; + bool robust_storage_access; bool robust_image_access; enum v3d_execution_environment environment; diff --git a/src/broadcom/compiler/v3d_nir_lower_robust_access.c b/src/broadcom/compiler/v3d_nir_lower_robust_access.c index 4786c26..e445557 100644 --- a/src/broadcom/compiler/v3d_nir_lower_robust_access.c +++ b/src/broadcom/compiler/v3d_nir_lower_robust_access.c @@ -148,12 +148,23 @@ lower_buffer_instr(nir_builder *b, nir_instr *instr, void *_state) switch (intr->intrinsic) { case nir_intrinsic_load_ubo: + if (c->key->robust_uniform_access) { + lower_buffer_load(c, b, intr); + return true; + } + return false; case nir_intrinsic_load_ssbo: - lower_buffer_load(c, b, intr); - return true; + if (c->key->robust_storage_access) { + lower_buffer_load(c, b, intr); + return true; + } + return false; case nir_intrinsic_store_ssbo: - lower_buffer_store(c, b, intr); - return true; + if (c->key->robust_storage_access) { + lower_buffer_store(c, b, intr); + return true; + } + return false; case nir_intrinsic_ssbo_atomic_add: case nir_intrinsic_ssbo_atomic_imin: case nir_intrinsic_ssbo_atomic_umin: @@ -164,8 +175,11 @@ lower_buffer_instr(nir_builder *b, nir_instr *instr, void *_state) case nir_intrinsic_ssbo_atomic_xor: case nir_intrinsic_ssbo_atomic_exchange: case nir_intrinsic_ssbo_atomic_comp_swap: - lower_buffer_atomic(c, b, intr); - return true; + if (c->key->robust_storage_access) { + lower_buffer_atomic(c, b, intr); + return true; + } + return false; case nir_intrinsic_store_shared: case nir_intrinsic_load_shared: case nir_intrinsic_shared_atomic_add: diff --git a/src/broadcom/compiler/vir.c b/src/broadcom/compiler/vir.c index eff8a49..0f4b31a 100644 --- a/src/broadcom/compiler/vir.c +++ b/src/broadcom/compiler/vir.c @@ -1594,7 +1594,7 @@ v3d_attempt_compile(struct v3d_compile *c) NIR_PASS(_, c->s, nir_lower_idiv, &idiv_options); NIR_PASS(_, c->s, nir_lower_alu); - if (c->key->robust_buffer_access) { + if (c->key->robust_uniform_access || c->key->robust_storage_access) { /* v3d_nir_lower_robust_buffer_access assumes constant buffer * indices on ubo/ssbo intrinsics so run copy propagation and * constant folding passes before we run the lowering to warrant diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c index bdc5d88..25bdc4a 100644 --- a/src/broadcom/vulkan/v3dv_device.c +++ b/src/broadcom/vulkan/v3dv_device.c @@ -183,6 +183,7 @@ get_device_extensions(const struct v3dv_physical_device *device, .EXT_physical_device_drm = true, .EXT_pipeline_creation_cache_control = true, .EXT_pipeline_creation_feedback = true, + .EXT_pipeline_robustness = true, .EXT_primitive_topology_list_restart = true, .EXT_private_data = true, .EXT_provoking_vertex = true, @@ -1376,6 +1377,13 @@ v3dv_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, break; } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_ROBUSTNESS_FEATURES_EXT: { + VkPhysicalDevicePipelineRobustnessFeaturesEXT *features = + (void *) ext; + features->pipelineRobustness = true; + break; + } + default: v3dv_debug_ignored_stype(ext->sType); break; @@ -1778,6 +1786,19 @@ v3dv_GetPhysicalDeviceProperties2(VkPhysicalDevice physicalDevice, sizeof(props->shaderModuleIdentifierAlgorithmUUID)); break; } + case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PIPELINE_ROBUSTNESS_PROPERTIES_EXT: { + VkPhysicalDevicePipelineRobustnessPropertiesEXT *props = + (VkPhysicalDevicePipelineRobustnessPropertiesEXT *)ext; + props->defaultRobustnessStorageBuffers = + VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DEVICE_DEFAULT_EXT; + props->defaultRobustnessUniformBuffers = + VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DEVICE_DEFAULT_EXT; + props->defaultRobustnessVertexInputs = + VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DEVICE_DEFAULT_EXT; + props->defaultRobustnessImages = + VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_DEVICE_DEFAULT_EXT; + break; + } default: v3dv_debug_ignored_stype(ext->sType); break; diff --git a/src/broadcom/vulkan/v3dv_pipeline.c b/src/broadcom/vulkan/v3dv_pipeline.c index 1526677..058ed0e 100644 --- a/src/broadcom/vulkan/v3dv_pipeline.c +++ b/src/broadcom/vulkan/v3dv_pipeline.c @@ -920,9 +920,7 @@ shader_debug_output(const char *message, void *data) static void pipeline_populate_v3d_key(struct v3d_key *key, const struct v3dv_pipeline_stage *p_stage, - uint32_t ucp_enables, - bool robust_buffer_access, - bool robust_image_access) + uint32_t ucp_enables) { assert(p_stage->pipeline->shared_data && p_stage->pipeline->shared_data->maps[p_stage->stage]); @@ -986,8 +984,18 @@ pipeline_populate_v3d_key(struct v3d_key *key, */ key->ucp_enables = ucp_enables; - key->robust_buffer_access = robust_buffer_access; - key->robust_image_access = robust_image_access; + const VkPipelineRobustnessBufferBehaviorEXT robust_buffer_enabled = + VK_PIPELINE_ROBUSTNESS_BUFFER_BEHAVIOR_ROBUST_BUFFER_ACCESS_EXT; + + const VkPipelineRobustnessImageBehaviorEXT robust_image_enabled = + VK_PIPELINE_ROBUSTNESS_IMAGE_BEHAVIOR_ROBUST_IMAGE_ACCESS_EXT; + + key->robust_uniform_access = + p_stage->robustness.uniform_buffers == robust_buffer_enabled; + key->robust_storage_access = + p_stage->robustness.storage_buffers == robust_buffer_enabled; + key->robust_image_access = + p_stage->robustness.images == robust_image_enabled; key->environment = V3D_ENVIRONMENT_VULKAN; } @@ -1041,9 +1049,7 @@ pipeline_populate_v3d_fs_key(struct v3d_fs_key *key, struct v3dv_device *device = p_stage->pipeline->device; assert(device); - const bool rba = device->vk.enabled_features.robustBufferAccess; - const bool ria = device->vk.enabled_features.robustImageAccess; - pipeline_populate_v3d_key(&key->base, p_stage, ucp_enables, rba, ria); + pipeline_populate_v3d_key(&key->base, p_stage, ucp_enables); const VkPipelineInputAssemblyStateCreateInfo *ia_info = pCreateInfo->pInputAssemblyState; @@ -1163,9 +1169,7 @@ pipeline_populate_v3d_gs_key(struct v3d_gs_key *key, memset(key, 0, sizeof(*key)); - const bool rba = device->vk.enabled_features.robustBufferAccess; - const bool ria = device->vk.enabled_features.robustImageAccess; - pipeline_populate_v3d_key(&key->base, p_stage, 0, rba, ria); + pipeline_populate_v3d_key(&key->base, p_stage, 0); struct v3dv_pipeline *pipeline = p_stage->pipeline; @@ -1208,10 +1212,7 @@ pipeline_populate_v3d_vs_key(struct v3d_vs_key *key, assert(device); memset(key, 0, sizeof(*key)); - - const bool rba = device->vk.enabled_features.robustBufferAccess; - const bool ria = device->vk.enabled_features.robustImageAccess; - pipeline_populate_v3d_key(&key->base, p_stage, 0, rba, ria); + pipeline_populate_v3d_key(&key->base, p_stage, 0); struct v3dv_pipeline *pipeline = p_stage->pipeline; @@ -1334,6 +1335,7 @@ pipeline_stage_create_binning(const struct v3dv_pipeline_stage *src, p_stage->program_id = src->program_id; p_stage->spec_info = src->spec_info; p_stage->feedback = (VkPipelineCreationFeedback) { 0 }; + p_stage->robustness = src->robustness; memcpy(p_stage->shader_sha1, src->shader_sha1, 20); return p_stage; @@ -1874,9 +1876,6 @@ pipeline_populate_graphics_key(struct v3dv_pipeline *pipeline, memset(key, 0, sizeof(*key)); - key->robust_buffer_access = device->vk.enabled_features.robustBufferAccess; - key->robust_image_access = device->vk.enabled_features.robustImageAccess; - const bool raster_enabled = !pCreateInfo->pRasterizationState->rasterizerDiscardEnable; @@ -1969,8 +1968,6 @@ pipeline_populate_compute_key(struct v3dv_pipeline *pipeline, * example, which already flags compute shaders. */ memset(key, 0, sizeof(*key)); - key->robust_buffer_access = device->vk.enabled_features.robustBufferAccess; - key->robust_image_access = device->vk.enabled_features.robustImageAccess; } static struct v3dv_pipeline_shared_data * @@ -2225,6 +2222,7 @@ pipeline_add_multiview_gs(struct v3dv_pipeline *pipeline, p_stage->nir = nir; pipeline_compute_sha1_from_nir(p_stage); p_stage->program_id = p_atomic_inc_return(&physical_device->next_program_id); + p_stage->robustness = pipeline->stages[BROADCOM_SHADER_VERTEX]->robustness; pipeline->has_gs = true; pipeline->stages[BROADCOM_SHADER_GEOMETRY] = p_stage; @@ -2302,7 +2300,11 @@ pipeline_compile_graphics(struct v3dv_pipeline *pipeline, p_stage->module = vk_shader_module_from_handle(sinfo->module); p_stage->spec_info = sinfo->pSpecializationInfo; - vk_pipeline_hash_shader_stage(&pCreateInfo->pStages[i], NULL, + vk_pipeline_robustness_state_fill(&device->vk, &p_stage->robustness, + pCreateInfo->pNext, sinfo->pNext); + + vk_pipeline_hash_shader_stage(&pCreateInfo->pStages[i], + &p_stage->robustness, p_stage->shader_sha1); pipeline->active_stages |= sinfo->stage; @@ -2345,6 +2347,8 @@ pipeline_compile_graphics(struct v3dv_pipeline *pipeline, p_stage->entrypoint = "main"; p_stage->module = 0; p_stage->nir = b.shader; + vk_pipeline_robustness_state_fill(&device->vk, &p_stage->robustness, + NULL, NULL); pipeline_compute_sha1_from_nir(p_stage); p_stage->program_id = p_atomic_inc_return(&physical_device->next_program_id); @@ -3086,7 +3090,12 @@ pipeline_compile_compute(struct v3dv_pipeline *pipeline, p_stage->spec_info = sinfo->pSpecializationInfo; p_stage->feedback = (VkPipelineCreationFeedback) { 0 }; - vk_pipeline_hash_shader_stage(&info->stage, NULL, p_stage->shader_sha1); + vk_pipeline_robustness_state_fill(&device->vk, &p_stage->robustness, + info->pNext, sinfo->pNext); + + vk_pipeline_hash_shader_stage(&info->stage, + &p_stage->robustness, + p_stage->shader_sha1); p_stage->nir = NULL; @@ -3139,9 +3148,7 @@ pipeline_compile_compute(struct v3dv_pipeline *pipeline, struct v3d_key key; memset(&key, 0, sizeof(key)); - const bool rba = pipeline->device->vk.enabled_features.robustBufferAccess; - const bool ria = pipeline->device->vk.enabled_features.robustImageAccess; - pipeline_populate_v3d_key(&key, p_stage, 0, rba, ria); + pipeline_populate_v3d_key(&key, p_stage, 0); pipeline->shared_data->variants[BROADCOM_SHADER_COMPUTE] = pipeline_compile_shader_variant(p_stage, &key, sizeof(key), alloc, &result); diff --git a/src/broadcom/vulkan/v3dv_private.h b/src/broadcom/vulkan/v3dv_private.h index 4d87ad7..c61c278 100644 --- a/src/broadcom/vulkan/v3dv_private.h +++ b/src/broadcom/vulkan/v3dv_private.h @@ -50,6 +50,7 @@ #include "vk_command_buffer.h" #include "vk_command_pool.h" #include "vk_queue.h" +#include "vk_pipeline.h" #include @@ -312,8 +313,6 @@ struct v3dv_meta_texel_buffer_copy_pipeline { }; struct v3dv_pipeline_key { - bool robust_buffer_access; - bool robust_image_access; uint8_t topology; uint8_t logicop_func; bool msaa; @@ -1705,6 +1704,8 @@ struct v3dv_pipeline_stage { uint32_t program_id; VkPipelineCreationFeedback feedback; + + struct vk_pipeline_robustness_state robustness; }; /* We are using the descriptor pool entry for two things: -- 2.7.4