@@ -54,17 +54,17 @@ private void createRenderPass() {
5454 if (colorAttachmentInfo != null ) {
5555 VkAttachmentDescription colorAttachment = attachments .get (i );
5656 colorAttachment .format (colorAttachmentInfo .format )
57- .samples (VK_SAMPLE_COUNT_1_BIT )
58- .loadOp (colorAttachmentInfo .loadOp )
59- .storeOp (colorAttachmentInfo .storeOp )
60- .stencilLoadOp (VK_ATTACHMENT_LOAD_OP_DONT_CARE )
61- .stencilStoreOp (VK_ATTACHMENT_STORE_OP_DONT_CARE )
62- .initialLayout (VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL )
63- .finalLayout (colorAttachmentInfo .finalLayout );
57+ .samples (VK_SAMPLE_COUNT_1_BIT )
58+ .loadOp (colorAttachmentInfo .loadOp )
59+ .storeOp (colorAttachmentInfo .storeOp )
60+ .stencilLoadOp (VK_ATTACHMENT_LOAD_OP_DONT_CARE )
61+ .stencilStoreOp (VK_ATTACHMENT_STORE_OP_DONT_CARE )
62+ .initialLayout (VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL )
63+ .finalLayout (colorAttachmentInfo .finalLayout );
6464
6565 VkAttachmentReference colorAttachmentRef = attachmentRefs .get (0 )
66- .attachment (0 )
67- .layout (VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL );
66+ .attachment (0 )
67+ .layout (VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL );
6868
6969 subpass .colorAttachmentCount (1 );
7070 subpass .pColorAttachments (VkAttachmentReference .calloc (1 , stack ).put (0 , colorAttachmentRef ));
@@ -76,49 +76,49 @@ private void createRenderPass() {
7676 if (depthAttachmentInfo != null ) {
7777 VkAttachmentDescription depthAttachment = attachments .get (i );
7878 depthAttachment .format (depthAttachmentInfo .format )
79- .samples (VK_SAMPLE_COUNT_1_BIT )
80- .loadOp (depthAttachmentInfo .loadOp )
81- .storeOp (depthAttachmentInfo .storeOp )
82- .stencilLoadOp (VK_ATTACHMENT_LOAD_OP_DONT_CARE )
83- .stencilStoreOp (VK_ATTACHMENT_STORE_OP_DONT_CARE )
84- .initialLayout (VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL )
85- .finalLayout (depthAttachmentInfo .finalLayout );
79+ .samples (VK_SAMPLE_COUNT_1_BIT )
80+ .loadOp (depthAttachmentInfo .loadOp )
81+ .storeOp (depthAttachmentInfo .storeOp )
82+ .stencilLoadOp (VK_ATTACHMENT_LOAD_OP_DONT_CARE )
83+ .stencilStoreOp (VK_ATTACHMENT_STORE_OP_DONT_CARE )
84+ .initialLayout (VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL )
85+ .finalLayout (depthAttachmentInfo .finalLayout );
8686
8787 VkAttachmentReference depthAttachmentRef = attachmentRefs .get (1 )
88- .attachment (1 )
89- .layout (VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL );
88+ .attachment (1 )
89+ .layout (VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL );
9090
9191 subpass .pDepthStencilAttachment (depthAttachmentRef );
9292 }
9393
9494 VkRenderPassCreateInfo renderPassInfo = VkRenderPassCreateInfo .calloc (stack );
9595 renderPassInfo .sType$Default ()
96- .pAttachments (attachments )
97- .pSubpasses (subpass );
96+ .pAttachments (attachments )
97+ .pSubpasses (subpass );
9898
9999 //Layout transition subpass depency
100100 switch (colorAttachmentInfo .finalLayout ) {
101101 case VK_IMAGE_LAYOUT_PRESENT_SRC_KHR -> {
102102 VkSubpassDependency .Buffer subpassDependencies = VkSubpassDependency .calloc (1 , stack );
103103 subpassDependencies .get (0 )
104- .srcSubpass (VK_SUBPASS_EXTERNAL )
105- .dstSubpass (0 )
106- .srcStageMask (VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT )
107- .dstStageMask (VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT )
108- .srcAccessMask (0 )
109- .dstAccessMask (0 );
104+ .srcSubpass (VK_SUBPASS_EXTERNAL )
105+ .dstSubpass (0 )
106+ .srcStageMask (VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT )
107+ .dstStageMask (VK_PIPELINE_STAGE_BOTTOM_OF_PIPE_BIT )
108+ .srcAccessMask (0 )
109+ .dstAccessMask (0 );
110110
111111 renderPassInfo .pDependencies (subpassDependencies );
112112 }
113113 case VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL -> {
114114 VkSubpassDependency .Buffer subpassDependencies = VkSubpassDependency .calloc (1 , stack );
115115 subpassDependencies .get (0 )
116- .srcSubpass (0 )
117- .dstSubpass (VK_SUBPASS_EXTERNAL )
118- .srcStageMask (VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT )
119- .dstStageMask (VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT )
120- .srcAccessMask (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT )
121- .dstAccessMask (VK_ACCESS_SHADER_READ_BIT );
116+ .srcSubpass (0 )
117+ .dstSubpass (VK_SUBPASS_EXTERNAL )
118+ .srcStageMask (VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT )
119+ .dstStageMask (VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT )
120+ .srcAccessMask (VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT )
121+ .dstAccessMask (VK_ACCESS_SHADER_READ_BIT );
122122
123123 renderPassInfo .pDependencies (subpassDependencies );
124124 }
@@ -137,11 +137,17 @@ private void createRenderPass() {
137137 public void beginRenderPass (VkCommandBuffer commandBuffer , long framebufferId , MemoryStack stack ) {
138138
139139 if (colorAttachmentInfo != null
140- && framebuffer .getColorAttachment ().getCurrentLayout () != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL )
141- framebuffer .getColorAttachment ().transitionImageLayout (stack , commandBuffer , VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL );
140+ && framebuffer .getColorAttachment ().getCurrentLayout () != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL )
141+ {
142+ framebuffer .getColorAttachment ()
143+ .transitionImageLayout (stack , commandBuffer , VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL );
144+ }
142145 if (depthAttachmentInfo != null
143- && framebuffer .getDepthAttachment ().getCurrentLayout () != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL )
144- framebuffer .getDepthAttachment ().transitionImageLayout (stack , commandBuffer , VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL );
146+ && framebuffer .getDepthAttachment ().getCurrentLayout () != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL )
147+ {
148+ framebuffer .getDepthAttachment ()
149+ .transitionImageLayout (stack , commandBuffer , VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL );
150+ }
145151
146152 VkRenderPassBeginInfo renderPassInfo = VkRenderPassBeginInfo .calloc (stack );
147153 renderPassInfo .sType$Default ();
@@ -167,6 +173,22 @@ public void beginRenderPass(VkCommandBuffer commandBuffer, long framebufferId, M
167173 public void endRenderPass (VkCommandBuffer commandBuffer ) {
168174 if (Vulkan .DYNAMIC_RENDERING ) {
169175 KHRDynamicRendering .vkCmdEndRenderingKHR (commandBuffer );
176+
177+ try (MemoryStack stack = MemoryStack .stackPush ()) {
178+ if (colorAttachmentInfo != null
179+ && framebuffer .getColorAttachment ().getCurrentLayout () != this .colorAttachmentInfo .finalLayout )
180+ {
181+ framebuffer .getColorAttachment ()
182+ .transitionImageLayout (stack , commandBuffer , this .colorAttachmentInfo .finalLayout );
183+ }
184+ if (depthAttachmentInfo != null
185+ && framebuffer .getDepthAttachment ().getCurrentLayout () != this .depthAttachmentInfo .finalLayout )
186+ {
187+ framebuffer .getDepthAttachment ()
188+ .transitionImageLayout (stack , commandBuffer , this .depthAttachmentInfo .finalLayout );
189+ }
190+ }
191+
170192 }
171193 else {
172194 vkCmdEndRenderPass (commandBuffer );
@@ -182,12 +204,25 @@ public void endRenderPass(VkCommandBuffer commandBuffer) {
182204 }
183205
184206 public void beginDynamicRendering (VkCommandBuffer commandBuffer , MemoryStack stack ) {
207+ if (colorAttachmentInfo != null
208+ && framebuffer .getColorAttachment ().getCurrentLayout () != VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL )
209+ {
210+ framebuffer .getColorAttachment ()
211+ .transitionImageLayout (stack , commandBuffer , VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL );
212+ }
213+ if (depthAttachmentInfo != null
214+ && framebuffer .getDepthAttachment ().getCurrentLayout () != VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL )
215+ {
216+ framebuffer .getDepthAttachment ()
217+ .transitionImageLayout (stack , commandBuffer , VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL );
218+ }
219+
185220 VkRect2D renderArea = VkRect2D .malloc (stack );
186221 renderArea .offset ().set (0 , 0 );
187222 renderArea .extent ().set (framebuffer .getWidth (), framebuffer .getHeight ());
188223
189224 VkClearValue .Buffer clearValues = VkClearValue .malloc (2 , stack );
190- clearValues .get (0 ).color ().float32 (stack . floats ( 0.0f , 0.0f , 0.0f , 1.0f ) );
225+ clearValues .get (0 ).color ().float32 (VRenderSystem . clearColor );
191226 clearValues .get (1 ).depthStencil ().set (1.0f , 0 );
192227
193228 VkRenderingInfo renderingInfo = VkRenderingInfo .calloc (stack );
@@ -208,7 +243,7 @@ public void beginDynamicRendering(VkCommandBuffer commandBuffer, MemoryStack sta
208243 renderingInfo .pColorAttachments (colorAttachment );
209244 }
210245
211- //Depth attachment
246+ // Depth attachment
212247 if (depthAttachmentInfo != null ) {
213248 VkRenderingAttachmentInfo depthAttachment = VkRenderingAttachmentInfo .calloc (stack );
214249 depthAttachment .sType (KHRDynamicRendering .VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_INFO_KHR );
0 commit comments