@@ -1492,7 +1492,7 @@ pl_graphics_create_texture_view(plDevice* ptDevice, const plTextureViewDesc* ptV
14921492{
14931493 plTextureHandle tHandle = pl__get_new_texture_handle (ptDevice );
14941494 plTexture * ptOriginalTexture = pl_graphics_get_texture (ptDevice , ptViewDesc -> tTexture );
1495- plTexture * ptNewTexture = pl_graphics_get_texture (ptDevice , ptViewDesc -> tTexture );
1495+ plTexture * ptNewTexture = pl_graphics_get_texture (ptDevice , tHandle );
14961496 ptNewTexture -> tDesc = ptOriginalTexture -> tDesc ;
14971497 ptNewTexture -> tDesc .tType = ptViewDesc -> tType ;
14981498 ptNewTexture -> tDesc .pcDebugName = ptViewDesc -> pcDebugName ;
@@ -1531,6 +1531,7 @@ pl_graphics_create_texture_view(plDevice* ptDevice, const plTextureViewDesc* ptV
15311531 };
15321532 PL_VULKAN (vkCreateImageView (ptDevice -> tLogicalDevice , & tViewInfo , gptGraphics -> ptAllocationCallbacks , & ptNewVulkanTexture -> tImageView ));
15331533 ptNewVulkanTexture -> bOriginalView = false;
1534+ ptNewVulkanTexture -> tImage = ptOldVulkanTexture -> tImage ;
15341535 return tHandle ;
15351536}
15361537
@@ -1950,25 +1951,10 @@ pl_graphics_create_shader(plDevice* ptDevice, const plShaderDesc* ptDescription)
19501951 .pDynamicStates = tDynamicStateEnables
19511952 };
19521953
1953- VkRenderingInputAttachmentIndexInfo tRenderingInputAttachmentIndexInfo = {
1954- .sType = VK_STRUCTURE_TYPE_RENDERING_INPUT_ATTACHMENT_INDEX_INFO ,
1955- .colorAttachmentCount = ptDescription -> uColorInputAttachmentCount ,
1956- .pColorAttachmentInputIndices = ptDescription -> auColorInputAttachmentIndices ,
1957- .pDepthInputAttachmentIndex = & ptDescription -> uDepthInputAttachmentIndex ,
1958- .pStencilInputAttachmentIndex = & ptDescription -> uDepthInputAttachmentIndex ,
1959- };
1960-
1961- VkRenderingAttachmentLocationInfo tRenderingAttachmentLocationInfo = {
1962- .sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_LOCATION_INFO ,
1963- .colorAttachmentCount = ptDescription -> uColorAttachmentCount ,
1964- .pColorAttachmentLocations = ptDescription -> uColorAttachmentCount > 0 ? ptDescription -> auColorAttachmentIndices : NULL ,
1965- .pNext = ptDescription -> uColorInputAttachmentCount > 0 ? & tRenderingInputAttachmentIndexInfo : NULL
1966- };
1967-
19681954 // New create info to define color, depth and stencil attachments at pipeline create time
19691955 VkPipelineRenderingCreateInfo tPipelineRenderingCreateInfo = {
19701956 .sType = VK_STRUCTURE_TYPE_PIPELINE_RENDERING_CREATE_INFO ,
1971- .pNext = ptDescription -> uColorAttachmentCount > 0 ? & tRenderingAttachmentLocationInfo : tRenderingAttachmentLocationInfo . pNext ,
1957+ .pNext = NULL ,
19721958 .colorAttachmentCount = ptDescription -> tRenderAttachmentFormatInfo .uColorCount ,
19731959 .pColorAttachmentFormats = atColorAttachmentFormats ,
19741960 .depthAttachmentFormat = ptDescription -> tRenderAttachmentFormatInfo .tDepthFormat == 0 ? 0 : pl__vulkan_format (ptDescription -> tRenderAttachmentFormatInfo .tDepthFormat ),
@@ -1987,7 +1973,7 @@ pl_graphics_create_shader(plDevice* ptDevice, const plShaderDesc* ptDescription)
19871973 .pColorBlendState = & tColorBlending ,
19881974 .pDynamicState = & tDynamicState ,
19891975 .layout = tVulkanShader .tPipelineLayout ,
1990- .subpass = ptShader -> tDesc . uSubpassIndex ,
1976+ .subpass = 0 ,
19911977 .basePipelineHandle = VK_NULL_HANDLE ,
19921978 .pDepthStencilState = & tDepthStencil ,
19931979 .pNext = & tPipelineRenderingCreateInfo
@@ -2071,17 +2057,6 @@ pl_graphics_begin_command_recording(plCommandBuffer* ptCommandBuffer)
20712057 PL_VULKAN (vkBeginCommandBuffer (ptCommandBuffer -> tCmdBuffer , & tBeginInfo ));
20722058}
20732059
2074- void
2075- pl_graphics_set_attachment_mapping (plCommandBuffer * ptCmdBuffer , uint32_t uCount , const uint32_t * puColorAttachmentIndices )
2076- {
2077- VkRenderingAttachmentLocationInfo tVkRenderingInputAttachmentIndexInfo = {
2078- .sType = VK_STRUCTURE_TYPE_RENDERING_ATTACHMENT_LOCATION_INFO ,
2079- .colorAttachmentCount = uCount ,
2080- .pColorAttachmentLocations = puColorAttachmentIndices ,
2081- };
2082- vkCmdSetRenderingAttachmentLocations (ptCmdBuffer -> tCmdBuffer , & tVkRenderingInputAttachmentIndexInfo );
2083- }
2084-
20852060void
20862061pl_graphics_change_texture_role (plCommandBuffer * ptCmdBuffer , plTextureHandle tTexture , plPassResourceRole tOldRole ,
20872062 plPassResourceAccess tOldAccess , plPassResourceRole tNewRole , plPassResourceAccess tNewAccess )
@@ -2099,7 +2074,7 @@ pl_graphics_change_texture_role(plCommandBuffer* ptCmdBuffer, plTextureHandle tT
20992074 VkImageSubresourceRange tRange = {
21002075 .baseMipLevel = 0 ,
21012076 .levelCount = 1 ,
2102- .baseArrayLayer = 0 ,
2077+ .baseArrayLayer = ptTexture -> tView . uBaseLayer ,
21032078 .layerCount = 1 ,
21042079 .aspectMask = tImageAspectFlags
21052080 };
@@ -2126,6 +2101,7 @@ pl_graphics_change_texture_role(plCommandBuffer* ptCmdBuffer, plTextureHandle tT
21262101 if (tOldRole == PL_PASS_RESOURCE_ROLE_NONE && tOldAccess == PL_PASS_RESOURCE_ACCESS_NONE )
21272102 {
21282103 tBarrier .oldLayout = VK_IMAGE_LAYOUT_UNDEFINED ;
2104+ tBarrier .srcStageMask |= VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT ;
21292105 bPreviousConfigValid = true;
21302106 }
21312107
@@ -2187,6 +2163,22 @@ pl_graphics_change_texture_role(plCommandBuffer* ptCmdBuffer, plTextureHandle tT
21872163 bPreviousConfigValid = true;
21882164 }
21892165
2166+ if (tOldRole == PL_PASS_RESOURCE_ROLE_STORAGE && tOldAccess == PL_PASS_RESOURCE_ACCESS_WRITE )
2167+ {
2168+
2169+ if (bDepthStencil )
2170+ {
2171+ }
2172+ else
2173+ {
2174+ tBarrier .newLayout = VK_IMAGE_LAYOUT_GENERAL ;
2175+ tBarrier .srcAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT ;
2176+ tBarrier .srcStageMask |= VK_PIPELINE_STAGE_2_RESOLVE_BIT | VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT ;
2177+ bPreviousConfigValid = true;
2178+ }
2179+
2180+ }
2181+
21902182 // new layout stuff
21912183 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
21922184
@@ -2262,6 +2254,40 @@ pl_graphics_change_texture_role(plCommandBuffer* ptCmdBuffer, plTextureHandle tT
22622254 bNextConfigValid = true;
22632255 }
22642256
2257+ if (tNewRole == PL_PASS_RESOURCE_ROLE_ATTACHMENT && tNewAccess == PL_PASS_RESOURCE_ACCESS_READ )
2258+ {
2259+
2260+ if (bDepthStencil )
2261+ {
2262+ tBarrier .newLayout = VK_IMAGE_LAYOUT_DEPTH_STENCIL_ATTACHMENT_OPTIMAL ;
2263+ tBarrier .dstAccessMask |= VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | VK_ACCESS_2_DEPTH_STENCIL_ATTACHMENT_READ_BIT ;
2264+ tBarrier .dstStageMask |= VK_PIPELINE_STAGE_2_LATE_FRAGMENT_TESTS_BIT | VK_PIPELINE_STAGE_2_EARLY_FRAGMENT_TESTS_BIT ;
2265+ }
2266+ else
2267+ {
2268+ tBarrier .newLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL ;
2269+ tBarrier .dstAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT | VK_ACCESS_2_COLOR_ATTACHMENT_READ_BIT ;
2270+ tBarrier .dstStageMask |= VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT ;
2271+ }
2272+ bNextConfigValid = true;
2273+ }
2274+
2275+ if (tNewRole == PL_PASS_RESOURCE_ROLE_STORAGE && tNewAccess == PL_PASS_RESOURCE_ACCESS_WRITE )
2276+ {
2277+
2278+ if (bDepthStencil )
2279+ {
2280+ }
2281+ else
2282+ {
2283+ tBarrier .newLayout = VK_IMAGE_LAYOUT_GENERAL ;
2284+ tBarrier .dstAccessMask |= VK_ACCESS_2_COLOR_ATTACHMENT_WRITE_BIT ;
2285+ tBarrier .dstStageMask |= VK_PIPELINE_STAGE_2_RESOLVE_BIT | VK_PIPELINE_STAGE_2_COLOR_ATTACHMENT_OUTPUT_BIT ;
2286+ bNextConfigValid = true;
2287+ }
2288+
2289+ }
2290+
22652291 PL_ASSERT (bPreviousConfigValid );
22662292 PL_ASSERT (bNextConfigValid );
22672293
@@ -2803,6 +2829,13 @@ pl_graphics_begin_render_pass(plCommandBuffer* ptCmdBuffer, plRenderInfo tInfo,
28032829 atColorAttachments [i ].imageLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL ;
28042830 if (tInfo .atColorAttachments [i ].tUsage == PL_TEXTURE_USAGE_INPUT_ATTACHMENT )
28052831 atColorAttachments [i ].imageLayout = VK_IMAGE_LAYOUT_RENDERING_LOCAL_READ ;
2832+
2833+ if (tInfo .atColorAttachments [i ].tResolveTexture .uIndex > 0 )
2834+ {
2835+ atColorAttachments [i ].resolveMode = VK_RESOLVE_MODE_AVERAGE_BIT ;
2836+ atColorAttachments [i ].resolveImageView = ptDevice -> sbtTexturesHot [tInfo .atColorAttachments [i ].tResolveTexture .uIndex ].tImageView ;
2837+ atColorAttachments [i ].resolveImageLayout = VK_IMAGE_LAYOUT_GENERAL ;
2838+ }
28062839 uColorAttachmentCount ++ ;
28072840 }
28082841
@@ -6311,7 +6344,7 @@ pl__garbage_collect(plDevice* ptDevice)
63116344 plVulkanTexture * ptVulkanResource = & ptDevice -> sbtTexturesHot [iResourceIndex ];
63126345 vkDestroyImageView (ptDevice -> tLogicalDevice , ptDevice -> sbtTexturesHot [iResourceIndex ].tImageView , gptGraphics -> ptAllocationCallbacks );
63136346 ptDevice -> sbtTexturesHot [iResourceIndex ].tImageView = VK_NULL_HANDLE ;
6314- if (ptDevice -> sbtTexturesHot [iResourceIndex ].bOriginalView )
6347+ if (ptDevice -> sbtTexturesHot [iResourceIndex ].bOriginalView && ! ptDevice -> sbtTexturesHot [ iResourceIndex ]. bSwapchain )
63156348 {
63166349 vkDestroyImage (ptDevice -> tLogicalDevice , ptVulkanResource -> tImage , gptGraphics -> ptAllocationCallbacks );
63176350 ptVulkanResource -> tImage = VK_NULL_HANDLE ;
0 commit comments