Selaa lähdekoodia

Fixing an issue with VulkanFramebuffer: Tightly packed color attachments now provide indices to the original positions, so they may be correctly used in masks and similar

BearishSun 9 vuotta sitten
vanhempi
sitoutus
2f7bfb64ef

+ 1 - 0
Source/BansheeVulkanRenderAPI/Include/BsVulkanFramebuffer.h

@@ -58,6 +58,7 @@ namespace bs
 		VulkanImage* image = nullptr;
 		UINT32 baseLayer = 0;
 		VkImageLayout finalLayout = VK_IMAGE_LAYOUT_UNDEFINED;
+		UINT32 index = 0;
 	};
 
 	/** Vulkan frame buffer containing one or multiple color surfaces, and an optional depth surface. */

+ 4 - 2
Source/BansheeVulkanRenderAPI/Source/BsVulkanCommandBuffer.cpp

@@ -699,7 +699,9 @@ namespace bs
 			UINT32 numColorAttachments = mFramebuffer->getNumColorAttachments();
 			for (UINT32 i = 0; i < numColorAttachments; i++)
 			{
-				if (((1 << i) & targetMask) == 0)
+				const VulkanFramebufferAttachment& attachment = mFramebuffer->getColorAttachment(i);
+
+				if (((1 << attachment.index) & targetMask) == 0)
 					continue;
 
 				attachments[attachmentIdx].aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
@@ -711,7 +713,7 @@ namespace bs
 				colorValue.float32[2] = color.b;
 				colorValue.float32[3] = color.a;
 
-				UINT32 curBaseLayer = mFramebuffer->getColorAttachment(i).baseLayer;
+				UINT32 curBaseLayer = attachment.baseLayer;
 				if (attachmentIdx == 0)
 					baseLayer = curBaseLayer;
 				else

+ 5 - 2
Source/BansheeVulkanRenderAPI/Source/BsVulkanFramebuffer.cpp

@@ -61,6 +61,7 @@ namespace bs
 			mColorAttachments[attachmentIdx].baseLayer = desc.color[i].baseLayer;
 			mColorAttachments[attachmentIdx].image = desc.color[i].image;
 			mColorAttachments[attachmentIdx].finalLayout = attachmentDesc.finalLayout;
+			mColorAttachments[attachmentIdx].index = i;
 
 			VkAttachmentReference& ref = mColorReferences[attachmentIdx];
 			ref.attachment = attachmentIdx;
@@ -89,6 +90,7 @@ namespace bs
 			mDepthStencilAttachment.baseLayer = desc.depth.baseLayer;
 			mDepthStencilAttachment.image = desc.depth.image;
 			mDepthStencilAttachment.finalLayout = attachmentDesc.finalLayout;
+			mDepthStencilAttachment.index = 0;
 
 			VkAttachmentReference& ref = mDepthReference;
 			ref.attachment = attachmentIdx;
@@ -179,10 +181,11 @@ namespace bs
 	{
 		for (UINT32 i = 0; i < mNumColorAttachments; i++)
 		{
+			const VulkanFramebufferAttachment& attachment = mColorAttachments[i];
 			VkAttachmentDescription& attachmentDesc = mAttachments[i];
 			VkAttachmentReference& attachmentRef = mColorReferences[i];
 
-			if (loadMask.isSet((RenderSurfaceMaskBits)i))
+			if (loadMask.isSet((RenderSurfaceMaskBits)attachment.index))
 			{
 				attachmentDesc.loadOp = VK_ATTACHMENT_LOAD_OP_LOAD;
 				attachmentDesc.initialLayout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;
@@ -193,7 +196,7 @@ namespace bs
 				attachmentDesc.initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
 			}
 
-			if(readMask.isSet((RenderSurfaceMaskBits)i))
+			if(readMask.isSet((RenderSurfaceMaskBits)attachment.index))
 				attachmentRef.layout = VK_IMAGE_LAYOUT_GENERAL;
 			else
 				attachmentRef.layout = VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL;