From ca33c319e5d2195ec8510cd8d0c29f3e0f01beba Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Tue, 30 Aug 2022 09:12:30 +0200 Subject: [PATCH] v3dv: implement VK_KHR_zero_initialize_workgroup_memory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This only requires that we call the relevant lowering pass in NIR. Reviewed-by: Alejandro PiƱeiro Part-of: --- docs/features.txt | 2 +- src/broadcom/compiler/vir.c | 15 ++++ src/broadcom/vulkan/v3dv_device.c | 122 +++++++++++++++--------------- 3 files changed, 78 insertions(+), 61 deletions(-) diff --git a/docs/features.txt b/docs/features.txt index 0f8c5247939..f0a60011469 100644 --- a/docs/features.txt +++ b/docs/features.txt @@ -481,7 +481,7 @@ Vulkan 1.3 -- all DONE: anv, radv, lvp VK_KHR_shader_non_semantic_info DONE (anv, radv, tu, v3dv, vn) VK_KHR_shader_terminate_invocation DONE (anv, lvp, radv, tu, vn) VK_KHR_synchronization2 DONE (anv, lvp, panvk, radv, tu) - VK_KHR_zero_initialize_workgroup_memory DONE (anv, lvp, radv, tu, vn) + VK_KHR_zero_initialize_workgroup_memory DONE (anv, lvp, radv, tu, v3dv, vn) VK_EXT_4444_formats DONE (anv, lvp, radv, tu, v3dv, vn) VK_EXT_extended_dynamic_state DONE (anv, lvp, radv, tu, vn) VK_EXT_extended_dynamic_state2 DONE (anv, lvp, radv, tu, vn) diff --git a/src/broadcom/compiler/vir.c b/src/broadcom/compiler/vir.c index 67ff66f2285..8c4307a0455 100644 --- a/src/broadcom/compiler/vir.c +++ b/src/broadcom/compiler/vir.c @@ -652,6 +652,21 @@ v3d_lower_nir(struct v3d_compile *c) NIR_PASS(_, c->s, nir_lower_tex, &tex_options); NIR_PASS(_, c->s, nir_lower_system_values); + + if (c->s->info.zero_initialize_shared_memory && + c->s->info.shared_size > 0) { + /* All our BOs allocate full pages, so the underlying allocation + * for shared memory will always be a multiple of 4KB. This + * ensures that we can do an exact number of full chunk_size + * writes to initialize the memory independently of the actual + * shared_size used by the shader, which is a requirement of + * the initialization pass. + */ + const unsigned chunk_size = 16; /* max single store size */ + NIR_PASS(_, c->s, nir_zero_initialize_shared_memory, + ALIGN(c->s->info.shared_size, chunk_size), chunk_size); + } + NIR_PASS(_, c->s, nir_lower_compute_system_values, NULL); NIR_PASS(_, c->s, nir_lower_vars_to_scratch, diff --git a/src/broadcom/vulkan/v3dv_device.c b/src/broadcom/vulkan/v3dv_device.c index fb7579dd213..071cf18f051 100644 --- a/src/broadcom/vulkan/v3dv_device.c +++ b/src/broadcom/vulkan/v3dv_device.c @@ -118,69 +118,70 @@ get_device_extensions(const struct v3dv_physical_device *device, struct vk_device_extension_table *ext) { *ext = (struct vk_device_extension_table) { - .KHR_8bit_storage = true, - .KHR_16bit_storage = true, - .KHR_bind_memory2 = true, - .KHR_buffer_device_address = true, - .KHR_copy_commands2 = true, - .KHR_create_renderpass2 = true, - .KHR_dedicated_allocation = true, - .KHR_device_group = true, - .KHR_driver_properties = true, - .KHR_descriptor_update_template = true, - .KHR_depth_stencil_resolve = true, - .KHR_external_fence = true, - .KHR_external_fence_fd = true, - .KHR_external_memory = true, - .KHR_external_memory_fd = true, - .KHR_external_semaphore = true, - .KHR_external_semaphore_fd = true, - .KHR_format_feature_flags2 = true, - .KHR_get_memory_requirements2 = true, - .KHR_image_format_list = true, - .KHR_imageless_framebuffer = true, - .KHR_performance_query = device->caps.perfmon, - .KHR_relaxed_block_layout = true, - .KHR_maintenance1 = true, - .KHR_maintenance2 = true, - .KHR_maintenance3 = true, - .KHR_maintenance4 = true, - .KHR_multiview = true, - .KHR_pipeline_executable_properties = true, - .KHR_separate_depth_stencil_layouts = true, - .KHR_shader_float_controls = true, - .KHR_shader_non_semantic_info = true, - .KHR_sampler_mirror_clamp_to_edge = true, - .KHR_spirv_1_4 = true, - .KHR_storage_buffer_storage_class = true, - .KHR_timeline_semaphore = true, - .KHR_uniform_buffer_standard_layout = true, + .KHR_8bit_storage = true, + .KHR_16bit_storage = true, + .KHR_bind_memory2 = true, + .KHR_buffer_device_address = true, + .KHR_copy_commands2 = true, + .KHR_create_renderpass2 = true, + .KHR_dedicated_allocation = true, + .KHR_device_group = true, + .KHR_driver_properties = true, + .KHR_descriptor_update_template = true, + .KHR_depth_stencil_resolve = true, + .KHR_external_fence = true, + .KHR_external_fence_fd = true, + .KHR_external_memory = true, + .KHR_external_memory_fd = true, + .KHR_external_semaphore = true, + .KHR_external_semaphore_fd = true, + .KHR_format_feature_flags2 = true, + .KHR_get_memory_requirements2 = true, + .KHR_image_format_list = true, + .KHR_imageless_framebuffer = true, + .KHR_performance_query = device->caps.perfmon, + .KHR_relaxed_block_layout = true, + .KHR_maintenance1 = true, + .KHR_maintenance2 = true, + .KHR_maintenance3 = true, + .KHR_maintenance4 = true, + .KHR_multiview = true, + .KHR_pipeline_executable_properties = true, + .KHR_separate_depth_stencil_layouts = true, + .KHR_shader_float_controls = true, + .KHR_shader_non_semantic_info = true, + .KHR_sampler_mirror_clamp_to_edge = true, + .KHR_spirv_1_4 = true, + .KHR_storage_buffer_storage_class = true, + .KHR_timeline_semaphore = true, + .KHR_uniform_buffer_standard_layout = true, #ifdef V3DV_USE_WSI_PLATFORM - .KHR_swapchain = true, - .KHR_swapchain_mutable_format = true, - .KHR_incremental_present = true, + .KHR_swapchain = true, + .KHR_swapchain_mutable_format = true, + .KHR_incremental_present = true, #endif - .KHR_variable_pointers = true, - .KHR_vulkan_memory_model = true, - .EXT_4444_formats = true, - .EXT_color_write_enable = true, - .EXT_custom_border_color = true, - .EXT_inline_uniform_block = true, - .EXT_external_memory_dma_buf = true, - .EXT_host_query_reset = true, - .EXT_image_drm_format_modifier = true, - .EXT_index_type_uint8 = true, - .EXT_line_rasterization = true, - .EXT_physical_device_drm = true, - .EXT_pipeline_creation_cache_control = true, - .EXT_pipeline_creation_feedback = true, - .EXT_private_data = true, - .EXT_provoking_vertex = true, - .EXT_separate_stencil_usage = true, - .EXT_texel_buffer_alignment = true, - .EXT_vertex_attribute_divisor = true, + .KHR_variable_pointers = true, + .KHR_vulkan_memory_model = true, + .KHR_zero_initialize_workgroup_memory = true, + .EXT_4444_formats = true, + .EXT_color_write_enable = true, + .EXT_custom_border_color = true, + .EXT_inline_uniform_block = true, + .EXT_external_memory_dma_buf = true, + .EXT_host_query_reset = true, + .EXT_image_drm_format_modifier = true, + .EXT_index_type_uint8 = true, + .EXT_line_rasterization = true, + .EXT_physical_device_drm = true, + .EXT_pipeline_creation_cache_control = true, + .EXT_pipeline_creation_feedback = true, + .EXT_private_data = true, + .EXT_provoking_vertex = true, + .EXT_separate_stencil_usage = true, + .EXT_texel_buffer_alignment = true, + .EXT_vertex_attribute_divisor = true, #ifdef ANDROID - .ANDROID_native_buffer = true, + .ANDROID_native_buffer = true, #endif }; } @@ -1119,6 +1120,7 @@ v3dv_GetPhysicalDeviceFeatures2(VkPhysicalDevice physicalDevice, .pipelineCreationCacheControl = true, .privateData = true, .maintenance4 = true, + .shaderZeroInitializeWorkgroupMemory = true, }; VkPhysicalDeviceVulkan12Features vk12 = {