forked from MoonsideGames/Refresh
				
			Compare commits
	
		
			No commits in common. "2f9c8aed3b86f917ee3514ec5d907424c1240409" and "89ba9c52ff38b3b6c0c1b757f74a63ea533f679e" have entirely different histories. 
		
	
	
		
			2f9c8aed3b
			...
			89ba9c52ff
		
	
		| 
						 | 
				
			
			@ -463,7 +463,6 @@ typedef struct Refresh_TextureCreateInfo
 | 
			
		|||
	uint32_t depth;
 | 
			
		||||
	uint8_t isCube;
 | 
			
		||||
	uint32_t levelCount;
 | 
			
		||||
	Refresh_SampleCount sampleCount;
 | 
			
		||||
	Refresh_TextureFormat format;
 | 
			
		||||
	Refresh_TextureUsageFlags usageFlags;
 | 
			
		||||
} Refresh_TextureCreateInfo;
 | 
			
		||||
| 
						 | 
				
			
			@ -552,6 +551,7 @@ typedef struct Refresh_ColorAttachmentInfo
 | 
			
		|||
	uint32_t depth;
 | 
			
		||||
	uint32_t layer;
 | 
			
		||||
	uint32_t level;
 | 
			
		||||
	Refresh_SampleCount sampleCount;
 | 
			
		||||
	Refresh_Vec4 clearColor; /* Can be ignored by RenderPass */
 | 
			
		||||
	Refresh_LoadOp loadOp;
 | 
			
		||||
	Refresh_StoreOp storeOp;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -758,21 +758,20 @@ typedef struct VulkanTexture
 | 
			
		|||
	uint32_t depth;
 | 
			
		||||
	uint32_t layerCount;
 | 
			
		||||
	uint32_t levelCount;
 | 
			
		||||
	Refresh_SampleCount sampleCount;
 | 
			
		||||
	VkFormat format;
 | 
			
		||||
	VulkanResourceAccessType resourceAccessType;
 | 
			
		||||
	VkImageUsageFlags usageFlags;
 | 
			
		||||
 | 
			
		||||
	VkImageAspectFlags aspectFlags;
 | 
			
		||||
 | 
			
		||||
	struct VulkanTexture *msaaTex;
 | 
			
		||||
 | 
			
		||||
	SDL_atomic_t referenceCount;
 | 
			
		||||
} VulkanTexture;
 | 
			
		||||
 | 
			
		||||
typedef struct VulkanRenderTarget
 | 
			
		||||
{
 | 
			
		||||
	VkImageView view;
 | 
			
		||||
	VulkanTexture *multisampleTexture;
 | 
			
		||||
	VkSampleCountFlags multisampleCount;
 | 
			
		||||
} VulkanRenderTarget;
 | 
			
		||||
 | 
			
		||||
typedef struct VulkanFramebuffer
 | 
			
		||||
| 
						 | 
				
			
			@ -1201,10 +1200,11 @@ static inline void FramebufferHashArray_Remove(
 | 
			
		|||
 | 
			
		||||
typedef struct RenderTargetHash
 | 
			
		||||
{
 | 
			
		||||
	VulkanTexture *texture;
 | 
			
		||||
	Refresh_Texture *texture;
 | 
			
		||||
	uint32_t depth;
 | 
			
		||||
	uint32_t layer;
 | 
			
		||||
	uint32_t level;
 | 
			
		||||
	Refresh_SampleCount sampleCount;
 | 
			
		||||
} RenderTargetHash;
 | 
			
		||||
 | 
			
		||||
typedef struct RenderTargetHashMap
 | 
			
		||||
| 
						 | 
				
			
			@ -1244,6 +1244,11 @@ static inline uint8_t RenderTargetHash_Compare(
 | 
			
		|||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (a->sampleCount != b->sampleCount)
 | 
			
		||||
	{
 | 
			
		||||
		return 0;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return 1;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3063,15 +3068,6 @@ static void VULKAN_INTERNAL_DestroyTexture(
 | 
			
		|||
		NULL
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	/* destroy the msaa texture, if there is one */
 | 
			
		||||
	if (texture->msaaTex != NULL)
 | 
			
		||||
	{
 | 
			
		||||
		VULKAN_INTERNAL_DestroyTexture(
 | 
			
		||||
			renderer,
 | 
			
		||||
			texture->msaaTex
 | 
			
		||||
		);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	SDL_free(texture);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -3090,6 +3086,18 @@ static void VULKAN_INTERNAL_DestroyRenderTarget(
 | 
			
		|||
		NULL
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	/* The texture is not owned by the RenderTarget
 | 
			
		||||
	 * so we don't free it here
 | 
			
		||||
	 * But the multisampleTexture is!
 | 
			
		||||
	 */
 | 
			
		||||
	if (renderTarget->multisampleTexture != NULL)
 | 
			
		||||
	{
 | 
			
		||||
		VULKAN_INTERNAL_DestroyTexture(
 | 
			
		||||
			renderer,
 | 
			
		||||
			renderTarget->multisampleTexture
 | 
			
		||||
		);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	SDL_free(renderTarget);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -4597,13 +4605,11 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
 | 
			
		|||
		swapchainData->textures[i].isCube = 0;
 | 
			
		||||
		swapchainData->textures[i].layerCount = 1;
 | 
			
		||||
		swapchainData->textures[i].levelCount = 1;
 | 
			
		||||
		swapchainData->textures[i].sampleCount = REFRESH_SAMPLECOUNT_1;
 | 
			
		||||
		swapchainData->textures[i].usageFlags =
 | 
			
		||||
			VK_IMAGE_USAGE_TRANSFER_DST_BIT |
 | 
			
		||||
			VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
 | 
			
		||||
		swapchainData->textures[i].aspectFlags = VK_IMAGE_ASPECT_COLOR_BIT;
 | 
			
		||||
		swapchainData->textures[i].resourceAccessType = RESOURCE_ACCESS_NONE;
 | 
			
		||||
		swapchainData->textures[i].msaaTex = NULL;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	SDL_stack_free(swapchainImages);
 | 
			
		||||
| 
						 | 
				
			
			@ -5211,8 +5217,8 @@ static VulkanTexture* VULKAN_INTERNAL_CreateTexture(
 | 
			
		|||
	uint32_t height,
 | 
			
		||||
	uint32_t depth,
 | 
			
		||||
	uint32_t isCube,
 | 
			
		||||
	VkSampleCountFlagBits samples,
 | 
			
		||||
	uint32_t levelCount,
 | 
			
		||||
	Refresh_SampleCount sampleCount,
 | 
			
		||||
	VkFormat format,
 | 
			
		||||
	VkImageAspectFlags aspectMask,
 | 
			
		||||
	VkImageUsageFlags imageUsageFlags
 | 
			
		||||
| 
						 | 
				
			
			@ -5255,7 +5261,7 @@ static VulkanTexture* VULKAN_INTERNAL_CreateTexture(
 | 
			
		|||
	imageCreateInfo.extent.depth = depth;
 | 
			
		||||
	imageCreateInfo.mipLevels = levelCount;
 | 
			
		||||
	imageCreateInfo.arrayLayers = layerCount;
 | 
			
		||||
	imageCreateInfo.samples = RefreshToVK_SampleCount[sampleCount];
 | 
			
		||||
	imageCreateInfo.samples = samples;
 | 
			
		||||
	imageCreateInfo.tiling = VK_IMAGE_TILING_OPTIMAL;
 | 
			
		||||
	imageCreateInfo.usage = imageUsageFlags;
 | 
			
		||||
	imageCreateInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
 | 
			
		||||
| 
						 | 
				
			
			@ -5382,11 +5388,9 @@ static VulkanTexture* VULKAN_INTERNAL_CreateTexture(
 | 
			
		|||
	texture->format = format;
 | 
			
		||||
	texture->levelCount = levelCount;
 | 
			
		||||
	texture->layerCount = layerCount;
 | 
			
		||||
	texture->sampleCount = sampleCount;
 | 
			
		||||
	texture->resourceAccessType = RESOURCE_ACCESS_NONE;
 | 
			
		||||
	texture->usageFlags = imageUsageFlags;
 | 
			
		||||
	texture->aspectFlags = aspectMask;
 | 
			
		||||
	texture->msaaTex = NULL;
 | 
			
		||||
 | 
			
		||||
	SDL_AtomicSet(&texture->referenceCount, 0);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -5395,22 +5399,27 @@ static VulkanTexture* VULKAN_INTERNAL_CreateTexture(
 | 
			
		|||
 | 
			
		||||
static VulkanRenderTarget* VULKAN_INTERNAL_CreateRenderTarget(
 | 
			
		||||
	VulkanRenderer *renderer,
 | 
			
		||||
	VulkanTexture *texture,
 | 
			
		||||
	Refresh_Texture *texture,
 | 
			
		||||
	uint32_t depth,
 | 
			
		||||
	uint32_t layer,
 | 
			
		||||
	uint32_t level
 | 
			
		||||
	uint32_t level,
 | 
			
		||||
	Refresh_SampleCount multisampleCount
 | 
			
		||||
) {
 | 
			
		||||
	VkResult vulkanResult;
 | 
			
		||||
	VulkanRenderTarget *renderTarget = (VulkanRenderTarget*) SDL_malloc(sizeof(VulkanRenderTarget));
 | 
			
		||||
	VulkanTexture *vulkanTexture = (VulkanTexture*) texture;
 | 
			
		||||
	VkImageViewCreateInfo imageViewCreateInfo;
 | 
			
		||||
	VkComponentMapping swizzle = IDENTITY_SWIZZLE;
 | 
			
		||||
	VkImageAspectFlags aspectFlags = 0;
 | 
			
		||||
 | 
			
		||||
	if (IsDepthFormat(texture->format))
 | 
			
		||||
	renderTarget->multisampleTexture = NULL;
 | 
			
		||||
	renderTarget->multisampleCount = 1;
 | 
			
		||||
 | 
			
		||||
	if (IsDepthFormat(vulkanTexture->format))
 | 
			
		||||
	{
 | 
			
		||||
		aspectFlags |= VK_IMAGE_ASPECT_DEPTH_BIT;
 | 
			
		||||
 | 
			
		||||
		if (IsStencilFormat(texture->format))
 | 
			
		||||
		if (IsStencilFormat(vulkanTexture->format))
 | 
			
		||||
		{
 | 
			
		||||
			aspectFlags |= VK_IMAGE_ASPECT_STENCIL_BIT;
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -5420,22 +5429,48 @@ static VulkanRenderTarget* VULKAN_INTERNAL_CreateRenderTarget(
 | 
			
		|||
		aspectFlags |= VK_IMAGE_ASPECT_COLOR_BIT;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* create resolve target for multisample */
 | 
			
		||||
	if (multisampleCount > REFRESH_SAMPLECOUNT_1)
 | 
			
		||||
	{
 | 
			
		||||
		/* Find a compatible sample count to use */
 | 
			
		||||
		multisampleCount = VULKAN_INTERNAL_GetMaxMultiSampleCount(
 | 
			
		||||
			renderer,
 | 
			
		||||
			multisampleCount
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		renderTarget->multisampleTexture =
 | 
			
		||||
			VULKAN_INTERNAL_CreateTexture(
 | 
			
		||||
				renderer,
 | 
			
		||||
				vulkanTexture->dimensions.width,
 | 
			
		||||
				vulkanTexture->dimensions.height,
 | 
			
		||||
				1,
 | 
			
		||||
				0,
 | 
			
		||||
				RefreshToVK_SampleCount[multisampleCount],
 | 
			
		||||
				1,
 | 
			
		||||
				vulkanTexture->format,
 | 
			
		||||
				aspectFlags,
 | 
			
		||||
				VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_TRANSFER_DST_BIT
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
		renderTarget->multisampleCount = RefreshToVK_SampleCount[multisampleCount];
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/* create framebuffer compatible views for RenderTarget */
 | 
			
		||||
	imageViewCreateInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
 | 
			
		||||
	imageViewCreateInfo.pNext = NULL;
 | 
			
		||||
	imageViewCreateInfo.flags = 0;
 | 
			
		||||
	imageViewCreateInfo.image = texture->image;
 | 
			
		||||
	imageViewCreateInfo.format = texture->format;
 | 
			
		||||
	imageViewCreateInfo.image = vulkanTexture->image;
 | 
			
		||||
	imageViewCreateInfo.format = vulkanTexture->format;
 | 
			
		||||
	imageViewCreateInfo.components = swizzle;
 | 
			
		||||
	imageViewCreateInfo.subresourceRange.aspectMask = aspectFlags;
 | 
			
		||||
	imageViewCreateInfo.subresourceRange.baseMipLevel = level;
 | 
			
		||||
	imageViewCreateInfo.subresourceRange.levelCount = 1;
 | 
			
		||||
	imageViewCreateInfo.subresourceRange.baseArrayLayer = 0;
 | 
			
		||||
	if (texture->is3D)
 | 
			
		||||
	if (vulkanTexture->is3D)
 | 
			
		||||
	{
 | 
			
		||||
		imageViewCreateInfo.subresourceRange.baseArrayLayer = depth;
 | 
			
		||||
	}
 | 
			
		||||
	else if (texture->isCube)
 | 
			
		||||
	else if (vulkanTexture->isCube)
 | 
			
		||||
	{
 | 
			
		||||
		imageViewCreateInfo.subresourceRange.baseArrayLayer = layer;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -5464,10 +5499,11 @@ static VulkanRenderTarget* VULKAN_INTERNAL_CreateRenderTarget(
 | 
			
		|||
 | 
			
		||||
static VulkanRenderTarget* VULKAN_INTERNAL_FetchRenderTarget(
 | 
			
		||||
	VulkanRenderer *renderer,
 | 
			
		||||
	VulkanTexture *texture,
 | 
			
		||||
	Refresh_Texture *texture,
 | 
			
		||||
	uint32_t depth,
 | 
			
		||||
	uint32_t layer,
 | 
			
		||||
	uint32_t level
 | 
			
		||||
	uint32_t level,
 | 
			
		||||
	Refresh_SampleCount sampleCount
 | 
			
		||||
) {
 | 
			
		||||
	RenderTargetHash hash;
 | 
			
		||||
	VulkanRenderTarget *renderTarget;
 | 
			
		||||
| 
						 | 
				
			
			@ -5476,6 +5512,7 @@ static VulkanRenderTarget* VULKAN_INTERNAL_FetchRenderTarget(
 | 
			
		|||
	hash.depth = depth;
 | 
			
		||||
	hash.layer = layer;
 | 
			
		||||
	hash.level = level;
 | 
			
		||||
	hash.sampleCount = sampleCount;
 | 
			
		||||
 | 
			
		||||
	SDL_LockMutex(renderer->renderTargetFetchLock);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -5491,7 +5528,8 @@ static VulkanRenderTarget* VULKAN_INTERNAL_FetchRenderTarget(
 | 
			
		|||
			texture,
 | 
			
		||||
			depth,
 | 
			
		||||
			layer,
 | 
			
		||||
			level
 | 
			
		||||
			level,
 | 
			
		||||
			sampleCount
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		RenderTargetHash_Insert(
 | 
			
		||||
| 
						 | 
				
			
			@ -5522,21 +5560,31 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
 | 
			
		|||
	VkSubpassDescription subpass;
 | 
			
		||||
	VkRenderPass renderPass;
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
	uint8_t multisampling = 0;
 | 
			
		||||
 | 
			
		||||
	uint32_t attachmentDescriptionCount = 0;
 | 
			
		||||
	uint32_t colorAttachmentReferenceCount = 0;
 | 
			
		||||
	uint32_t resolveReferenceCount = 0;
 | 
			
		||||
 | 
			
		||||
	VulkanRenderTarget *renderTarget;
 | 
			
		||||
	VulkanTexture *texture;
 | 
			
		||||
	VulkanTexture *msaaTexture = NULL;
 | 
			
		||||
 | 
			
		||||
	for (i = 0; i < colorAttachmentCount; i += 1)
 | 
			
		||||
	{
 | 
			
		||||
		texture = (VulkanTexture*) colorAttachmentInfos[i].texture;
 | 
			
		||||
 | 
			
		||||
		if (texture->msaaTex != NULL)
 | 
			
		||||
		renderTarget = VULKAN_INTERNAL_FetchRenderTarget(
 | 
			
		||||
			renderer,
 | 
			
		||||
			colorAttachmentInfos[i].texture,
 | 
			
		||||
			colorAttachmentInfos[i].depth,
 | 
			
		||||
			colorAttachmentInfos[i].layer,
 | 
			
		||||
			colorAttachmentInfos[i].level,
 | 
			
		||||
			colorAttachmentInfos[i].sampleCount
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		if (renderTarget->multisampleCount > VK_SAMPLE_COUNT_1_BIT)
 | 
			
		||||
		{
 | 
			
		||||
			msaaTexture = texture->msaaTex;
 | 
			
		||||
			multisampling = 1;
 | 
			
		||||
 | 
			
		||||
			/* Transition the multisample attachment */
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -5546,12 +5594,12 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
 | 
			
		|||
				RESOURCE_ACCESS_COLOR_ATTACHMENT_WRITE,
 | 
			
		||||
				VK_IMAGE_ASPECT_COLOR_BIT,
 | 
			
		||||
				0,
 | 
			
		||||
				msaaTexture->layerCount,
 | 
			
		||||
				renderTarget->multisampleTexture->layerCount,
 | 
			
		||||
				0,
 | 
			
		||||
				msaaTexture->levelCount,
 | 
			
		||||
				renderTarget->multisampleTexture->levelCount,
 | 
			
		||||
				0,
 | 
			
		||||
				msaaTexture->image,
 | 
			
		||||
				&msaaTexture->resourceAccessType
 | 
			
		||||
				renderTarget->multisampleTexture->image,
 | 
			
		||||
				&renderTarget->multisampleTexture->resourceAccessType
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
			/* Resolve attachment and multisample attachment */
 | 
			
		||||
| 
						 | 
				
			
			@ -5583,10 +5631,8 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
 | 
			
		|||
			resolveReferenceCount += 1;
 | 
			
		||||
 | 
			
		||||
			attachmentDescriptions[attachmentDescriptionCount].flags = 0;
 | 
			
		||||
			attachmentDescriptions[attachmentDescriptionCount].format = msaaTexture->format;
 | 
			
		||||
			attachmentDescriptions[attachmentDescriptionCount].samples = RefreshToVK_SampleCount[
 | 
			
		||||
				msaaTexture->sampleCount
 | 
			
		||||
			];
 | 
			
		||||
			attachmentDescriptions[attachmentDescriptionCount].format = texture->format;
 | 
			
		||||
			attachmentDescriptions[attachmentDescriptionCount].samples = renderTarget->multisampleCount;
 | 
			
		||||
			attachmentDescriptions[attachmentDescriptionCount].loadOp = RefreshToVK_LoadOp[
 | 
			
		||||
				colorAttachmentInfos[i].loadOp
 | 
			
		||||
			];
 | 
			
		||||
| 
						 | 
				
			
			@ -5655,13 +5701,21 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
 | 
			
		|||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		renderTarget = VULKAN_INTERNAL_FetchRenderTarget(
 | 
			
		||||
			renderer,
 | 
			
		||||
			depthStencilAttachmentInfo->texture,
 | 
			
		||||
			depthStencilAttachmentInfo->depth,
 | 
			
		||||
			depthStencilAttachmentInfo->layer,
 | 
			
		||||
			depthStencilAttachmentInfo->level,
 | 
			
		||||
			REFRESH_SAMPLECOUNT_1
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		texture = (VulkanTexture*) depthStencilAttachmentInfo->texture;
 | 
			
		||||
 | 
			
		||||
		attachmentDescriptions[attachmentDescriptionCount].flags = 0;
 | 
			
		||||
		attachmentDescriptions[attachmentDescriptionCount].format = texture->format;
 | 
			
		||||
		attachmentDescriptions[attachmentDescriptionCount].samples = RefreshToVK_SampleCount[
 | 
			
		||||
			texture->sampleCount
 | 
			
		||||
		];
 | 
			
		||||
		attachmentDescriptions[attachmentDescriptionCount].samples =
 | 
			
		||||
			VK_SAMPLE_COUNT_1_BIT;
 | 
			
		||||
		attachmentDescriptions[attachmentDescriptionCount].loadOp = RefreshToVK_LoadOp[
 | 
			
		||||
			depthStencilAttachmentInfo->loadOp
 | 
			
		||||
		];
 | 
			
		||||
| 
						 | 
				
			
			@ -5690,7 +5744,7 @@ static VkRenderPass VULKAN_INTERNAL_CreateRenderPass(
 | 
			
		|||
		attachmentDescriptionCount += 1;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (msaaTexture != NULL)
 | 
			
		||||
	if (multisampling)
 | 
			
		||||
	{
 | 
			
		||||
		subpass.pResolveAttachments = resolveReferences;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -5843,9 +5897,8 @@ static VkRenderPass VULKAN_INTERNAL_CreateTransientRenderPass(
 | 
			
		|||
			renderer,
 | 
			
		||||
			attachmentInfo.depthStencilFormat
 | 
			
		||||
		);
 | 
			
		||||
		attachmentDescriptions[attachmentDescriptionCount].samples = RefreshToVK_SampleCount[
 | 
			
		||||
			sampleCount
 | 
			
		||||
		];
 | 
			
		||||
		attachmentDescriptions[attachmentDescriptionCount].samples =
 | 
			
		||||
			VK_SAMPLE_COUNT_1_BIT; /* FIXME: do these take multisamples? */
 | 
			
		||||
		attachmentDescriptions[attachmentDescriptionCount].loadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
 | 
			
		||||
		attachmentDescriptions[attachmentDescriptionCount].storeOp = VK_ATTACHMENT_STORE_OP_DONT_CARE;
 | 
			
		||||
		attachmentDescriptions[attachmentDescriptionCount].stencilLoadOp = VK_ATTACHMENT_LOAD_OP_DONT_CARE;
 | 
			
		||||
| 
						 | 
				
			
			@ -6547,11 +6600,9 @@ static Refresh_Texture* VULKAN_CreateTexture(
 | 
			
		|||
		VK_IMAGE_USAGE_TRANSFER_SRC_BIT
 | 
			
		||||
	);
 | 
			
		||||
	VkImageAspectFlags imageAspectFlags;
 | 
			
		||||
	uint8_t isDepthFormat = IsRefreshDepthFormat(textureCreateInfo->format);
 | 
			
		||||
	VkFormat format;
 | 
			
		||||
	VulkanTexture *result;
 | 
			
		||||
 | 
			
		||||
	if (isDepthFormat)
 | 
			
		||||
	if (IsRefreshDepthFormat(textureCreateInfo->format))
 | 
			
		||||
	{
 | 
			
		||||
		format = RefreshToVK_DepthFormat(renderer, textureCreateInfo->format);
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -6580,7 +6631,7 @@ static Refresh_Texture* VULKAN_CreateTexture(
 | 
			
		|||
		imageUsageFlags |= VK_IMAGE_USAGE_STORAGE_BIT;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (isDepthFormat)
 | 
			
		||||
	if (IsDepthFormat(format))
 | 
			
		||||
	{
 | 
			
		||||
		imageAspectFlags = VK_IMAGE_ASPECT_DEPTH_BIT;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -6594,41 +6645,18 @@ static Refresh_Texture* VULKAN_CreateTexture(
 | 
			
		|||
		imageAspectFlags = VK_IMAGE_ASPECT_COLOR_BIT;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	result = VULKAN_INTERNAL_CreateTexture(
 | 
			
		||||
	return (Refresh_Texture*) VULKAN_INTERNAL_CreateTexture(
 | 
			
		||||
		renderer,
 | 
			
		||||
		textureCreateInfo->width,
 | 
			
		||||
		textureCreateInfo->height,
 | 
			
		||||
		textureCreateInfo->depth,
 | 
			
		||||
		textureCreateInfo->isCube,
 | 
			
		||||
		VK_SAMPLE_COUNT_1_BIT,
 | 
			
		||||
		textureCreateInfo->levelCount,
 | 
			
		||||
		isDepthFormat ?
 | 
			
		||||
			textureCreateInfo->sampleCount : /* depth textures do not have a separate msaaTex */
 | 
			
		||||
			REFRESH_SAMPLECOUNT_1,
 | 
			
		||||
		format,
 | 
			
		||||
		imageAspectFlags,
 | 
			
		||||
		imageUsageFlags
 | 
			
		||||
	);
 | 
			
		||||
 | 
			
		||||
	/* create the MSAA texture for color attachments, if needed */
 | 
			
		||||
	if (	result != NULL &&
 | 
			
		||||
		!isDepthFormat &&
 | 
			
		||||
		textureCreateInfo->sampleCount > REFRESH_SAMPLECOUNT_1	)
 | 
			
		||||
	{
 | 
			
		||||
		result->msaaTex = VULKAN_INTERNAL_CreateTexture(
 | 
			
		||||
			renderer,
 | 
			
		||||
			textureCreateInfo->width,
 | 
			
		||||
			textureCreateInfo->height,
 | 
			
		||||
			textureCreateInfo->depth,
 | 
			
		||||
			textureCreateInfo->isCube,
 | 
			
		||||
			textureCreateInfo->levelCount,
 | 
			
		||||
			textureCreateInfo->sampleCount,
 | 
			
		||||
			format,
 | 
			
		||||
			imageAspectFlags,
 | 
			
		||||
			imageUsageFlags
 | 
			
		||||
		);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	return (Refresh_Texture*) result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static Refresh_Buffer* VULKAN_CreateBuffer(
 | 
			
		||||
| 
						 | 
				
			
			@ -7814,7 +7842,7 @@ static void VULKAN_QueueDestroyTexture(
 | 
			
		|||
	Refresh_Texture *texture
 | 
			
		||||
) {
 | 
			
		||||
	VulkanRenderer *renderer = (VulkanRenderer*) driverData;
 | 
			
		||||
	VulkanTexture* vulkanTexture = (VulkanTexture*) texture;
 | 
			
		||||
	VulkanTexture* vulkanTexture = (VulkanTexture*)texture;
 | 
			
		||||
 | 
			
		||||
	SDL_LockMutex(renderer->disposeLock);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -7961,7 +7989,6 @@ static VkRenderPass VULKAN_INTERNAL_FetchRenderPass(
 | 
			
		|||
	VkRenderPass renderPass;
 | 
			
		||||
	RenderPassHash hash;
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
	VulkanTexture *texture;
 | 
			
		||||
 | 
			
		||||
	SDL_LockMutex(renderer->renderPassFetchLock);
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -7973,15 +8000,9 @@ static VkRenderPass VULKAN_INTERNAL_FetchRenderPass(
 | 
			
		|||
		hash.colorTargetDescriptions[i].storeOp = colorAttachmentInfos[i].storeOp;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	hash.colorAttachmentSampleCount = REFRESH_SAMPLECOUNT_1;
 | 
			
		||||
	if (colorAttachmentCount > 0)
 | 
			
		||||
	{
 | 
			
		||||
		texture = (VulkanTexture*) colorAttachmentInfos[0].texture;
 | 
			
		||||
		if (texture->msaaTex != NULL)
 | 
			
		||||
		{
 | 
			
		||||
			hash.colorAttachmentSampleCount = texture->msaaTex->sampleCount;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	hash.colorAttachmentSampleCount = (colorAttachmentCount > 0) ?
 | 
			
		||||
		colorAttachmentInfos[0].sampleCount :
 | 
			
		||||
		REFRESH_SAMPLECOUNT_1;
 | 
			
		||||
 | 
			
		||||
	hash.colorAttachmentCount = colorAttachmentCount;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -8048,7 +8069,6 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer(
 | 
			
		|||
	VkResult result;
 | 
			
		||||
	VkImageView imageViewAttachments[2 * MAX_COLOR_TARGET_BINDINGS + 1];
 | 
			
		||||
	FramebufferHash hash;
 | 
			
		||||
	VulkanTexture *texture;
 | 
			
		||||
	VulkanRenderTarget *renderTarget;
 | 
			
		||||
	uint32_t attachmentCount = 0;
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
| 
						 | 
				
			
			@ -8065,32 +8085,23 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer(
 | 
			
		|||
 | 
			
		||||
	for (i = 0; i < colorAttachmentCount; i += 1)
 | 
			
		||||
	{
 | 
			
		||||
		texture = (VulkanTexture*) colorAttachmentInfos[i].texture;
 | 
			
		||||
 | 
			
		||||
		renderTarget = VULKAN_INTERNAL_FetchRenderTarget(
 | 
			
		||||
			renderer,
 | 
			
		||||
			texture,
 | 
			
		||||
			colorAttachmentInfos[i].texture,
 | 
			
		||||
			colorAttachmentInfos[i].depth,
 | 
			
		||||
			colorAttachmentInfos[i].layer,
 | 
			
		||||
			colorAttachmentInfos[i].level
 | 
			
		||||
			colorAttachmentInfos[i].level,
 | 
			
		||||
			colorAttachmentInfos[i].sampleCount
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		hash.colorAttachmentViews[i] = (
 | 
			
		||||
			renderTarget->view
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		if (texture->msaaTex != NULL)
 | 
			
		||||
		if (renderTarget->multisampleTexture != NULL)
 | 
			
		||||
		{
 | 
			
		||||
			renderTarget = VULKAN_INTERNAL_FetchRenderTarget(
 | 
			
		||||
				renderer,
 | 
			
		||||
				texture->msaaTex,
 | 
			
		||||
				colorAttachmentInfos[i].depth,
 | 
			
		||||
				colorAttachmentInfos[i].layer,
 | 
			
		||||
				colorAttachmentInfos[i].level
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
			hash.colorMultiSampleAttachmentViews[i] = (
 | 
			
		||||
				renderTarget->view
 | 
			
		||||
				renderTarget->multisampleTexture->view
 | 
			
		||||
			);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -8101,13 +8112,13 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer(
 | 
			
		|||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		texture = (VulkanTexture*) depthStencilAttachmentInfo->texture;
 | 
			
		||||
		renderTarget = VULKAN_INTERNAL_FetchRenderTarget(
 | 
			
		||||
			renderer,
 | 
			
		||||
			texture,
 | 
			
		||||
			depthStencilAttachmentInfo->texture,
 | 
			
		||||
			depthStencilAttachmentInfo->depth,
 | 
			
		||||
			depthStencilAttachmentInfo->layer,
 | 
			
		||||
			depthStencilAttachmentInfo->level
 | 
			
		||||
			depthStencilAttachmentInfo->level,
 | 
			
		||||
			REFRESH_SAMPLECOUNT_1
 | 
			
		||||
		);
 | 
			
		||||
		hash.depthStencilAttachmentView = renderTarget->view;
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -8134,14 +8145,13 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer(
 | 
			
		|||
 | 
			
		||||
	for (i = 0; i < colorAttachmentCount; i += 1)
 | 
			
		||||
	{
 | 
			
		||||
		texture = (VulkanTexture*) colorAttachmentInfos[i].texture;
 | 
			
		||||
 | 
			
		||||
		renderTarget = VULKAN_INTERNAL_FetchRenderTarget(
 | 
			
		||||
			renderer,
 | 
			
		||||
			texture,
 | 
			
		||||
			colorAttachmentInfos[i].texture,
 | 
			
		||||
			colorAttachmentInfos[i].depth,
 | 
			
		||||
			colorAttachmentInfos[i].layer,
 | 
			
		||||
			colorAttachmentInfos[i].level
 | 
			
		||||
			colorAttachmentInfos[i].level,
 | 
			
		||||
			colorAttachmentInfos[i].sampleCount
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		imageViewAttachments[attachmentCount] =
 | 
			
		||||
| 
						 | 
				
			
			@ -8149,18 +8159,10 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer(
 | 
			
		|||
 | 
			
		||||
		attachmentCount += 1;
 | 
			
		||||
 | 
			
		||||
		if (texture->msaaTex != NULL)
 | 
			
		||||
		if (renderTarget->multisampleTexture != NULL)
 | 
			
		||||
		{
 | 
			
		||||
			renderTarget = VULKAN_INTERNAL_FetchRenderTarget(
 | 
			
		||||
				renderer,
 | 
			
		||||
				texture->msaaTex,
 | 
			
		||||
				colorAttachmentInfos[i].depth,
 | 
			
		||||
				colorAttachmentInfos[i].layer,
 | 
			
		||||
				colorAttachmentInfos[i].level
 | 
			
		||||
			);
 | 
			
		||||
 | 
			
		||||
			imageViewAttachments[attachmentCount] =
 | 
			
		||||
				renderTarget->view;
 | 
			
		||||
				renderTarget->multisampleTexture->view;
 | 
			
		||||
 | 
			
		||||
			attachmentCount += 1;
 | 
			
		||||
		}
 | 
			
		||||
| 
						 | 
				
			
			@ -8168,13 +8170,13 @@ static VulkanFramebuffer* VULKAN_INTERNAL_FetchFramebuffer(
 | 
			
		|||
 | 
			
		||||
	if (depthStencilAttachmentInfo != NULL)
 | 
			
		||||
	{
 | 
			
		||||
		texture = (VulkanTexture*) depthStencilAttachmentInfo->texture;
 | 
			
		||||
		renderTarget = VULKAN_INTERNAL_FetchRenderTarget(
 | 
			
		||||
			renderer,
 | 
			
		||||
			texture,
 | 
			
		||||
			depthStencilAttachmentInfo->texture,
 | 
			
		||||
			depthStencilAttachmentInfo->depth,
 | 
			
		||||
			depthStencilAttachmentInfo->layer,
 | 
			
		||||
			depthStencilAttachmentInfo->level
 | 
			
		||||
			depthStencilAttachmentInfo->level,
 | 
			
		||||
			REFRESH_SAMPLECOUNT_1
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		imageViewAttachments[attachmentCount] = renderTarget->view;
 | 
			
		||||
| 
						 | 
				
			
			@ -8301,7 +8303,6 @@ static void VULKAN_BeginRenderPass(
 | 
			
		|||
	VkClearValue *clearValues;
 | 
			
		||||
	uint32_t clearCount = colorAttachmentCount;
 | 
			
		||||
	uint32_t multisampleAttachmentCount = 0;
 | 
			
		||||
	uint32_t totalColorAttachmentCount = 0;
 | 
			
		||||
	uint32_t i;
 | 
			
		||||
	VkImageAspectFlags depthAspectFlags;
 | 
			
		||||
	Refresh_Viewport defaultViewport;
 | 
			
		||||
| 
						 | 
				
			
			@ -8387,7 +8388,7 @@ static void VULKAN_BeginRenderPass(
 | 
			
		|||
			&texture->resourceAccessType
 | 
			
		||||
		);
 | 
			
		||||
 | 
			
		||||
		if (texture->msaaTex != NULL)
 | 
			
		||||
		if (colorAttachmentInfos[i].sampleCount > REFRESH_SAMPLECOUNT_1)
 | 
			
		||||
		{
 | 
			
		||||
			clearCount += 1;
 | 
			
		||||
			multisampleAttachmentCount += 1;
 | 
			
		||||
| 
						 | 
				
			
			@ -8401,8 +8402,9 @@ static void VULKAN_BeginRenderPass(
 | 
			
		|||
		texture = (VulkanTexture*) depthStencilAttachmentInfo->texture;
 | 
			
		||||
		depthAspectFlags = VK_IMAGE_ASPECT_DEPTH_BIT;
 | 
			
		||||
 | 
			
		||||
		if (IsStencilFormat(texture->format))
 | 
			
		||||
		{
 | 
			
		||||
		if (IsStencilFormat(
 | 
			
		||||
			texture->format
 | 
			
		||||
		)) {
 | 
			
		||||
			depthAspectFlags |= VK_IMAGE_ASPECT_STENCIL_BIT;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -8429,31 +8431,28 @@ static void VULKAN_BeginRenderPass(
 | 
			
		|||
 | 
			
		||||
	clearValues = SDL_stack_alloc(VkClearValue, clearCount);
 | 
			
		||||
 | 
			
		||||
	totalColorAttachmentCount = colorAttachmentCount + multisampleAttachmentCount;
 | 
			
		||||
 | 
			
		||||
	for (i = 0; i < totalColorAttachmentCount; i += 1)
 | 
			
		||||
	for (i = 0; i < colorAttachmentCount + multisampleAttachmentCount; i += 1)
 | 
			
		||||
	{
 | 
			
		||||
		clearValues[i].color.float32[0] = colorAttachmentInfos[i].clearColor.x;
 | 
			
		||||
		clearValues[i].color.float32[1] = colorAttachmentInfos[i].clearColor.y;
 | 
			
		||||
		clearValues[i].color.float32[2] = colorAttachmentInfos[i].clearColor.z;
 | 
			
		||||
		clearValues[i].color.float32[3] = colorAttachmentInfos[i].clearColor.w;
 | 
			
		||||
 | 
			
		||||
		texture = (VulkanTexture*) colorAttachmentInfos[i].texture;
 | 
			
		||||
		if (texture->msaaTex != NULL)
 | 
			
		||||
		if (colorAttachmentInfos[i].sampleCount > REFRESH_SAMPLECOUNT_1)
 | 
			
		||||
		{
 | 
			
		||||
			clearValues[i+1].color.float32[0] = colorAttachmentInfos[i].clearColor.x;
 | 
			
		||||
			clearValues[i+1].color.float32[1] = colorAttachmentInfos[i].clearColor.y;
 | 
			
		||||
			clearValues[i+1].color.float32[2] = colorAttachmentInfos[i].clearColor.z;
 | 
			
		||||
			clearValues[i+1].color.float32[3] = colorAttachmentInfos[i].clearColor.w;
 | 
			
		||||
			i += 1;
 | 
			
		||||
			clearValues[i].color.float32[0] = colorAttachmentInfos[i].clearColor.x;
 | 
			
		||||
			clearValues[i].color.float32[1] = colorAttachmentInfos[i].clearColor.y;
 | 
			
		||||
			clearValues[i].color.float32[2] = colorAttachmentInfos[i].clearColor.z;
 | 
			
		||||
			clearValues[i].color.float32[3] = colorAttachmentInfos[i].clearColor.w;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (depthStencilAttachmentInfo != NULL)
 | 
			
		||||
	{
 | 
			
		||||
		clearValues[totalColorAttachmentCount].depthStencil.depth =
 | 
			
		||||
		clearValues[colorAttachmentCount].depthStencil.depth =
 | 
			
		||||
			depthStencilAttachmentInfo->depthStencilClearValue.depth;
 | 
			
		||||
		clearValues[totalColorAttachmentCount].depthStencil.stencil =
 | 
			
		||||
		clearValues[colorAttachmentCount].depthStencil.stencil =
 | 
			
		||||
			depthStencilAttachmentInfo->depthStencilClearValue.stencil;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue