Optimal VkCmdResolveImage pipeline stage flags?

I’m setting up image resolve for MSAA textures. This code works correctly with no validation errors, but I’m not sure what pipeline stages are optimal for the image layout transitions? This is following rendering, prior to presenting the image:

void GPUCommandBuffer::ResolveImage(shared_ptr<RenderTexture> src, shared_ptr<RenderTexture> dst)
{
	BindResource(src);
	BindResource(dst);
	Assert(src->samples > 1);
	Assert(dst->samples < 2);
	Assert(src->format == dst->format);
	VkImageResolve region = {};
	region.extent.width = src->size.x;
	region.extent.height = src->size.y;
	region.extent.depth = 1;
	region.srcSubresource.layerCount = 1;
	switch (src->format)
	{
	case VK_FORMAT_D16_UNORM:
	case VK_FORMAT_X8_D24_UNORM_PACK32:
	case VK_FORMAT_D32_SFLOAT:
		region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT;
		break;
	case VK_FORMAT_S8_UINT:
	case VK_FORMAT_D16_UNORM_S8_UINT:
	case VK_FORMAT_D24_UNORM_S8_UINT:
	case VK_FORMAT_D32_SFLOAT_S8_UINT:
		region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT;
		break;
	default:
		region.srcSubresource.aspectMask = VK_IMAGE_ASPECT_COLOR_BIT;
	}
	region.dstSubresource = region.srcSubresource;

	TransitionImageLayout(src, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);
	TransitionImageLayout(dst, VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT);

	vkCmdResolveImage(commandbuffer, src->GetHandle(), src->GetLayout(), dst->GetHandle(), dst->GetLayout(), 1, &region);
}

Not sure what you mean. There’s not much of a choice. Basically only one appropriate flag. VK_PIPELINE_STAGE_2_RESOLVE_BIT or VK_PIPELINE_STAGE_TRANSFER_BIT. Or VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, which obviously is the less optimal option.

Though if you cared about optimality, you would avoid vkCmdResolveImage.

What would the alternative be?

To use a resolve attachment in the subpass that created the image you’re resolving. Unless you generated the multisample image through storage image writes or something, there’s not much reason to use vkCmdResolveImage.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.