Remove incorrect assert

An assert in Framebuffer::setAttachment() was checking that the
attachment was null before it being assigned, but there is no
such requirement in the Vulkan spec. The assert was removed.

Also fixed an issue where the attachments were set at command
recording time, for some reason, instead of command execution time.

A corresponding issue was logged in VK-GL-CTS:
https://gitlab.khronos.org/Tracker/vk-gl-cts/-/issues/3999

Tests: dEQP-VK.imageless_framebuffer.*
Bug: b/248611054
Change-Id: Ibd74dce59a315df0cfb25879d9e495f675f4b01c
Reviewed-on: https://swiftshader-review.googlesource.com/c/SwiftShader/+/68528
Presubmit-Ready: Alexis Hétu <sugoi@google.com>
Tested-by: Alexis Hétu <sugoi@google.com>
Kokoro-Result: kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Alexis Hétu <sugoi@google.com>
diff --git a/src/Vulkan/VkCommandBuffer.cpp b/src/Vulkan/VkCommandBuffer.cpp
index 4e32760..73f4e32 100644
--- a/src/Vulkan/VkCommandBuffer.cpp
+++ b/src/Vulkan/VkCommandBuffer.cpp
@@ -43,20 +43,32 @@
 {
 public:
 	CmdBeginRenderPass(vk::RenderPass *renderPass, vk::Framebuffer *framebuffer, VkRect2D renderArea,
-	                   uint32_t clearValueCount, const VkClearValue *pClearValues)
+	                   uint32_t clearValueCount, const VkClearValue *pClearValues,
+	                   const VkRenderPassAttachmentBeginInfo *attachmentInfo)
 	    : renderPass(renderPass)
 	    , framebuffer(framebuffer)
 	    , renderArea(renderArea)
 	    , clearValueCount(clearValueCount)
+	    , attachmentCount(attachmentInfo ? attachmentInfo->attachmentCount : 0)
+	    , attachments(nullptr)
 	{
 		// FIXME(b/119409619): use an allocator here so we can control all memory allocations
 		clearValues = new VkClearValue[clearValueCount];
 		memcpy(clearValues, pClearValues, clearValueCount * sizeof(VkClearValue));
+		if(attachmentCount > 0)
+		{
+			attachments = new vk::ImageView *[attachmentCount];
+			for(uint32_t i = 0; i < attachmentCount; i++)
+			{
+				attachments[i] = vk::Cast(attachmentInfo->pAttachments[i]);
+			}
+		}
 	}
 
 	~CmdBeginRenderPass() override
 	{
 		delete[] clearValues;
+		delete[] attachments;
 	}
 
 	void execute(vk::CommandBuffer::ExecutionState &executionState) override
@@ -65,6 +77,11 @@
 		executionState.renderPassFramebuffer = framebuffer;
 		executionState.subpassIndex = 0;
 
+		for(uint32_t i = 0; i < attachmentCount; i++)
+		{
+			framebuffer->setAttachment(attachments[i], i);
+		}
+
 		// Vulkan specifies that the attachments' `loadOp` gets executed "at the beginning of the subpass where it is first used."
 		// Since we don't discard any contents between subpasses, this is equivalent to executing it at the start of the renderpass.
 		framebuffer->executeLoadOp(executionState.renderPass, clearValueCount, clearValues, renderArea);
@@ -78,6 +95,8 @@
 	const VkRect2D renderArea;
 	const uint32_t clearValueCount;
 	VkClearValue *clearValues;
+	uint32_t attachmentCount;
+	vk::ImageView **attachments;
 };
 
 class CmdNextSubpass : public vk::CommandBuffer::Command
@@ -1820,14 +1839,7 @@
 {
 	ASSERT(state == RECORDING);
 
-	if(attachmentInfo)
-	{
-		for(uint32_t i = 0; i < attachmentInfo->attachmentCount; i++)
-		{
-			framebuffer->setAttachment(vk::Cast(attachmentInfo->pAttachments[i]), i);
-		}
-	}
-	addCommand<::CmdBeginRenderPass>(renderPass, framebuffer, renderArea, clearValueCount, clearValues);
+	addCommand<::CmdBeginRenderPass>(renderPass, framebuffer, renderArea, clearValueCount, clearValues, attachmentInfo);
 }
 
 void CommandBuffer::nextSubpass(VkSubpassContents contents)
diff --git a/src/Vulkan/VkFramebuffer.cpp b/src/Vulkan/VkFramebuffer.cpp
index 3d1ed92..ac06f88 100644
--- a/src/Vulkan/VkFramebuffer.cpp
+++ b/src/Vulkan/VkFramebuffer.cpp
@@ -164,7 +164,6 @@
 void Framebuffer::setAttachment(ImageView *imageView, uint32_t index)
 {
 	ASSERT(index < attachmentCount);
-	ASSERT(attachments[index] == nullptr);
 	attachments[index] = imageView;
 }