Repository: godot
Issue: Vulkan Validation:  vkCmdBeginRenderPass: Hazard WRITE_AFTER_READ in subpass 0 for attachment 0 image layout transition
Labels: bug,topic:rendering

### Godot version

Godot Engine v4.0.dev.calinou.795cd2eb3 ([`795cd2eb3`](https://github.com/godotengine/godot/commits/795cd2eb3))

### System information

Linux, Elementary OS 5.1, Intel(R) HD Graphics 4400 (HSW GT2), Vulkan API 1.2.182

### Issue description

(Previous error repeated *many* times.)

This new error seems to occur after clicking a  MeshInstance3D node in tree.

```
ERROR: VALIDATION - Message Id Number: 1261721012 | Message Id Name: SYNC-HAZARD-WRITE_AFTER_READ
        Validation Error: [ SYNC-HAZARD-WRITE_AFTER_READ ] Object 0: handle = 0x1dad3d000000354b, type = VK_OBJECT_TYPE_RENDER_PASS; | MessageID = 0x4b3455b4 | vkCmdBeginRenderPass: Hazard WRITE_AFTER_READ in subpass 0 for attachment 0 image layout transition (old_layout: VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, new_layout: VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL). Access info (usage: SYNC_IMAGE_LAYOUT_TRANSITION, prior_usage: SYNC_FRAGMENT_SHADER_SHADER_STORAGE_READ, read_barriers: VK_PIPELINE_STAGE_2_DRAW_INDIRECT_BIT_KHR|VK_PIPELINE_STAGE_2_VERTEX_SHADER_BIT_KHR|VK_PIPELINE_STAGE_2_TESSELLATION_CONTROL_SHADER_BIT_KHR|VK_PIPELINE_STAGE_2_TESSELLATION_EVALUATION_SHADER_BIT_KHR|VK_PIPELINE_STAGE_2_GEOMETRY_SHADER_BIT_KHR|VK_PIPELINE_STAGE_2_FRAGMENT_SHADER_BIT_KHR|VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT_KHR|VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT_KHR|VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT_KHR|VK_PIPELINE_STAGE_2_COMPUTE_SHADER_BIT_KHR|VK_PIPELINE_STAGE_2_BOTTOM_OF_PIPE_BIT_KHR|VK_PIPELINE_STAGE_2_TASK_SHADER_BIT_NV|VK_PIPELINE_STAGE_2_MESH_SHADER_BIT_NV|VK_PIPELINE_STAGE_2_RAY_TRACING_SHADER_BIT_KHR|VK_PIPELINE_STAGE_2_FRAGMENT_SHADING_RATE_ATTACHMENT_BIT_KHR|VK_PIPELINE_STAGE_2_TRANSFORM_FEEDBACK_BIT_EXT|VK_PIPELINE_STAGE_2_COPY_BIT_KHR|VK_PIPELINE_STAGE_2_RESOLVE_BIT_KHR|VK_PIPELINE_STAGE_2_BLIT_BIT_KHR|VK_PIPELINE_STAGE_2_CLEAR_BIT_KHR|VK_PIPELINE_STAGE_2_INDEX_INPUT_BIT_KHR|VK_PIPELINE_STAGE_2_VERTEX_ATTRIBUTE_INPUT_BIT_KHR, command: vkCmdDrawIndexed, seq_no: 684,reset_no: 157).
        Objects - 1
                Object[0] - VK_OBJECT_TYPE_RENDER_PASS, Handle 2138432468280161611
```

```
#0  VulkanContext::_debug_messenger_callback (messageSeverity=VK_DEBUG_UTILS_MESSAGE_SEVERITY_ERROR_BIT_EXT, messageType=0x2, pCallbackData=0x7fffffffae80, pUserData=0x55555f0317b0) at drivers/vulkan/vulkan_context.cpp:53
#1  0x00007fffe93ff5de in debug_log_msg (layer_prefix=0x7fffe9a10799 "Validation", text_vuid=<optimized out>, message=<optimized out>, objects=..., msg_flags=<optimizedout>, debug_data=<optimized out>) at /root/sdk-build/1.2.182.0/source/Vulkan-ValidationLayers/layers/vk_layer_logging.h:475
#2  LogMsgLocked (debug_data=<optimized out>, msg_flags=msg_flags@entry=0x8, objects=..., vuid_text="SYNC-HAZARD-WRITE_AFTER_READ", err_msg=<optimized out>) at /root/sdk-build/1.2.182.0/source/Vulkan-ValidationLayers/layers/vk_layer_logging.h:735
#3  0x00007fffe9464417 in ValidationObject::LogError<VkRenderPass_T*> (this=0x55555f968790, src_object=<optimized out>, vuid_text="SYNC-HAZARD-WRITE_AFTER_READ", format=0x7fffe9c19200 "%s: Hazard %s in subpass %u for attachment %u image layout transition (old_layout: %s, new_layout: %s). Access info %s.") at /root/sdk-build/1.2.182.0/source/Vulkan-ValidationLayers/layers/generated/chassis.h:3310
#4  0x00007fffe97596bd in AccessContext::ValidateLayoutTransitions (this=this@entry=0x7fffffffb5e0, ex_context=..., rp_state=..., render_area=..., subpass=subpass@entry=0x0, attachment_views=std::vector of length 1, capacity 1 = {...}, func_name=0x7fffe9a12116 "vkCmdBeginRenderPass") at /root/sdk-build/1.2.182.0/source/Vulkan-ValidationLayers/layers/synchronization_validation.cpp:1004
#5  0x00007fffe975a2e0 in SyncOpBeginRenderPass::Validate (this=this@entry=0x7fffffffb730, cb_context=...) at /root/sdk-build/1.2.182.0/source/Vulkan-ValidationLayers/layers/synchronization_validation.cpp:5757
#6  0x00007fffe975a4c2 in SyncValidator::ValidateBeginRenderPass (this=0x55555f968790, commandBuffer=<optimized out>, pRenderPassBegin=0x7fffffffb970, pSubpassBeginInfo=pSubpassBeginInfo@entry=0x7fffffffb830, cmd=cmd@entry=CMD_BEGINRENDERPASS, cmd_name=cmd_name@entry=0x0) at /root/sdk-build/1.2.182.0/source/Vulkan-ValidationLayers/layers/synchronization_validation.cpp:3372
#7  0x00007fffe975a65a in SyncValidator::PreCallValidateCmdBeginRenderPass (this=<optimized out>, commandBuffer=<optimized out>, pRenderPassBegin=<optimized out>, contents=<optimized out>) at /root/sdk-build/1.2.182.0/source/Vulkan-ValidationLayers/layers/synchronization_validation.cpp:3382
#8  0x00007fffe929c09f in vulkan_layer_chassis::CmdBeginRenderPass (commandBuffer=0x55555f9f6130, pRenderPassBegin=0x7fffffffb970, contents=VK_SUBPASS_CONTENTS_INLINE) at /root/sdk-build/1.2.182.0/source/Vulkan-ValidationLayers/layers/generated/chassis.cpp:3667
#9  0x000055555879ceaa in RenderingDeviceVulkan::_draw_list_render_pass_begin (this=0x55555f7b0090, framebuffer=0x555564f18960, p_initial_color_action=RenderingDevice::INITIAL_ACTION_DROP, p_final_color_action=RenderingDevice::FINAL_ACTION_DISCARD, p_initial_depth_action=RenderingDevice::INITIAL_ACTION_CLEAR, p_final_depth_action=RenderingDevice::FINAL_ACTION_CONTINUE, p_clear_colors=..., p_clear_depth=1, p_clear_stencil=0x0, viewport_offset=..., viewport_size=..., vkframebuffer=0x5fc9c2000000354c, render_pass=0x1dad3d000000354b, command_buffer=0x55555f9f6130, subpass_contents=VK_SUBPASS_CONTENTS_INLINE, p_storage_textures=...) at drivers/vulkan/rendering_device_vulkan.cpp:6892
#10 0x000055555879db84 in RenderingDeviceVulkan::draw_list_begin (this=0x55555f7b0090, p_framebuffer=..., p_initial_color_action=RenderingDevice::INITIAL_ACTION_DROP, p_final_color_action=RenderingDevice::FINAL_ACTION_DISCARD, p_initial_depth_action=RenderingDevice::INITIAL_ACTION_CLEAR, p_final_depth_action=RenderingDevice::FINAL_ACTION_CONTINUE, p_clear_color_values=..., p_clear_depth=1, p_clear_stencil=0x0, p_region=..., p_storage_textures=...) at drivers/vulkan/rendering_device_vulkan.cpp:7014
#11 0x000055555ab2bdea in RendererSceneRenderRD::_pre_opaque_render (this=0x5555607a0720, p_render_data=0x7fffffffc210, p_use_ssao=0x0, p_use_gi=0x0, p_normal_roughness_buffer=..., p_voxel_gi_buffer=...) at servers/rendering/renderer_rd/renderer_scene_render_rd.cpp:4456
#12 0x000055555abe2ce1 in RendererSceneRenderImplementation::RenderForwardClustered::_render_scene (this=0x5555607a0720, p_render_data=0x7fffffffc210, p_default_bg_color=...) at servers/rendering/renderer_rd/forward_clustered/render_forward_clustered.cpp:1443
#13 0x000055555ab2d41d in RendererSceneRenderRD::render_scene (this=0x5555607a0720, p_render_buffers=..., p_camera_data=0x7fffffffc9b0, p_instances=..., p_lights=..., p_reflection_probes=..., p_voxel_gi_instances=..., p_decals=..., p_lightmaps=..., p_fog_volumes=..., p_environment=..., p_camera_effects=..., p_shadow_atlas=..., p_occluder_debug_tex=..., p_reflection_atlas=..., p_reflection_probe=..., p_reflection_probe_pass=0xffffffff, p_screen_lod_threshold=0.00147492625, p_render_shadows=0x55555fa733e8, p_render_shadow_count=0x4, p_render_sdfgi_regions=0x55555fa7b3f0, p_render_sdfgi_region_count=0x0, p_sdfgi_update_data=0x55555fa7b930, r_render_info=0x55556b8008d0) at servers/rendering/renderer_rd/renderer_scene_render_rd.cpp:4684
#14 0x000055555adeb32e in RendererSceneCull::_render_scene (this=0x55555fa723a0, p_camera_data=0x7fffffffc9b0, p_render_buffers=..., p_environment=..., p_force_camera_effects=..., p_visible_layers=0xf0fffff, p_scenario=..., p_viewport=..., p_shadow_atlas=..., p_reflection_probe=..., p_reflection_probe_pass=0xffffffff, p_screen_lod_threshold=0.00147492625, p_using_shadows=0x1, r_render_info=0x55556b8008d0) at servers/rendering/renderer_scene_cull.cpp:3204
#15 0x000055555ade6c02 in RendererSceneCull::render_camera (this=0x55555fa723a0, p_render_buffers=..., p_camera=..., p_scenario=..., p_viewport=..., p_viewport_size=..., p_screen_lod_threshold=0.00147492625, p_shadow_atlas=..., p_xr_interface=..., r_render_info=0x55556b8008d0) at servers/rendering/renderer_scene_cull.cpp:2498
#16 0x000055555ae0fb5d in RendererViewport::_draw_3d (this=0x55555fa72300, p_viewport=0x55556b8007d0) at servers/rendering/renderer_viewport.cpp:120
#17 0x000055555ae1012a in RendererViewport::_draw_viewport (this=0x55555fa72300, p_viewport=0x55556b8007d0) at servers/rendering/renderer_viewport.cpp:179
#18 0x000055555ae12af4 in RendererViewport::draw_viewports (this=0x55555fa72300) at servers/rendering/renderer_viewport.cpp:608
#19 0x000055555aa65b7e in RenderingServerDefault::_draw (this=0x55555fa3cfa0, p_swap_buffers=0x1, frame_step=13.38227133333295) at servers/rendering/rendering_server_default.cpp:97
#20 0x000055555aa678ac in RenderingServerDefault::draw (this=0x55555fa3cfa0, p_swap_buffers=0x1, frame_step=13.38227133333295) at servers/rendering/rendering_server_default.cpp:379
#21 0x00005555576d8ca7 in Main::iteration () at main/main.cpp:2662
#22 0x00005555576928b6 in OS_LinuxBSD::run (this=0x7fffffffd540) at platform/linuxbsd/os_linuxbsd.cpp:342
#23 0x000055555768eded in main (argc=0x7, argv=0x7fffffffda38) at platform/linuxbsd/godot_linuxbsd.cpp:58
```


### Steps to reproduce

[vulk-previews-issue-repro-bb.zip](https://github.com/godotengine/godot/files/7465498/vulk-previews-issue-repro-bb.zip)


### Minimal reproduction project

_No response_