From 06dd8d95423cf38e9a35c399a36c7387cd6f6a48 Mon Sep 17 00:00:00 2001 From: Qining Lu Date: Wed, 19 Dec 2018 12:02:17 -0500 Subject: [PATCH] Vulkan: Show first layer in case of layered rendering In cases of layered rendering at vkQueueSubmit, show the first layer in the framebuffer view. This is the last bit to support VK_KHR_maintenance1 extension --- gapis/api/vulkan/api/image.api | 19 +++++ .../api/vulkan/api/renderpass_framebuffer.api | 10 +-- gapis/api/vulkan/read_framebuffer.go | 81 ++++++++++++------- gapis/api/vulkan/vulkan.api | 1 + 4 files changed, 77 insertions(+), 34 deletions(-) diff --git a/gapis/api/vulkan/api/image.api b/gapis/api/vulkan/api/image.api index a982a1b459..fea001dd34 100644 --- a/gapis/api/vulkan/api/image.api +++ b/gapis/api/vulkan/api/image.api @@ -745,6 +745,25 @@ sub void transitionImageLayout(ref!ImageObject img, VkImageSubresourceRange rng, } } +sub void transitionImageViewLayout( + ref!ImageViewObject view, + VkImageLayout oldLayout, + VkImageLayout newLayout) { + if is2DView3DImage(view) { + rng := VkImageSubresourceRange( + aspectMask: view.SubresourceRange.aspectMask, + baseMipLevel: view.SubresourceRange.baseMipLevel, + levelCount: view.SubresourceRange.levelCount, + baseArrayLayer: 0, + layerCount: 1) + transitionImageLayout( + view.Image, rng, oldLayout, newLayout) + } else { + transitionImageLayout( + view.Image, view.SubresourceRange, oldLayout, newLayout) + } +} + // ---------------------------------------------------------------------------- // Vulkan 1.1 Commands // ---------------------------------------------------------------------------- diff --git a/gapis/api/vulkan/api/renderpass_framebuffer.api b/gapis/api/vulkan/api/renderpass_framebuffer.api index 7ae748e0a2..ca140858a9 100644 --- a/gapis/api/vulkan/api/renderpass_framebuffer.api +++ b/gapis/api/vulkan/api/renderpass_framebuffer.api @@ -331,20 +331,20 @@ sub void dovkCmdNextSubpass(ref!vkCmdNextSubpassArgs Unused) { subpass := ldi.RenderPass.SubpassDescriptions[ldi.LastSubpass] for _ , _ , a in subpass.InputAttachments { attachment := ldi.Framebuffer.ImageAttachments[a.Attachment] - transitionImageLayout(attachment.Image, attachment.SubresourceRange, VK_IMAGE_LAYOUT_UNDEFINED, a.Layout) + transitionImageViewLayout(attachment, VK_IMAGE_LAYOUT_UNDEFINED, a.Layout) } for _ , _ , a in subpass.ColorAttachments { attachment := ldi.Framebuffer.ImageAttachments[a.Attachment] - transitionImageLayout(attachment.Image, attachment.SubresourceRange, VK_IMAGE_LAYOUT_UNDEFINED, a.Layout) + transitionImageViewLayout(attachment, VK_IMAGE_LAYOUT_UNDEFINED, a.Layout) } for _ , _ , a in subpass.ResolveAttachments { attachment := ldi.Framebuffer.ImageAttachments[a.Attachment] - transitionImageLayout(attachment.Image, attachment.SubresourceRange, VK_IMAGE_LAYOUT_UNDEFINED, a.Layout) + transitionImageViewLayout(attachment, VK_IMAGE_LAYOUT_UNDEFINED, a.Layout) } if subpass.DepthStencilAttachment != null { dsRef := subpass.DepthStencilAttachment attachment := ldi.Framebuffer.ImageAttachments[dsRef.Attachment] - transitionImageLayout(attachment.Image, attachment.SubresourceRange, VK_IMAGE_LAYOUT_UNDEFINED, dsRef.Layout) + transitionImageViewLayout(attachment, VK_IMAGE_LAYOUT_UNDEFINED, dsRef.Layout) } } popAndPushMarkerForNextSubpass(ldi.LastSubpass) @@ -433,7 +433,7 @@ sub void storeImageAttachment(u32 attachmentID) { desc := ldi.RenderPass.AttachmentDescriptions[attachmentID] if attachment.Image != null { if desc.initialLayout != desc.finalLayout { - transitionImageLayout(attachment.Image, attachment.SubresourceRange, VK_IMAGE_LAYOUT_UNDEFINED, desc.finalLayout) + transitionImageViewLayout(attachment, VK_IMAGE_LAYOUT_UNDEFINED, desc.finalLayout) } switch desc.storeOp { case VK_ATTACHMENT_STORE_OP_STORE: { diff --git a/gapis/api/vulkan/read_framebuffer.go b/gapis/api/vulkan/read_framebuffer.go index 80aea7b600..ca9cfc4a30 100644 --- a/gapis/api/vulkan/read_framebuffer.go +++ b/gapis/api/vulkan/read_framebuffer.go @@ -204,8 +204,8 @@ func postImageData(ctx context.Context, level, imgWidth, imgHeight, - reqWidth, - reqHeight uint32, + requestWidth, + requestHeight uint32, checkImage func(*image.Data) error, out transform.Writer, res replay.Result) { @@ -239,10 +239,41 @@ func postImageData(ctx context.Context, return } - queue := imageObject.Aspects().Get(aspect).Layers().Get(0).Levels().Get(0).LastBoundQueue() + resolveSrcDepth := int32(0) + blitSrcDepth := int32(0) + copySrcDepth := int32(0) + + if imageObject.Info().ImageType() == VkImageType_VK_IMAGE_TYPE_3D { + resolveSrcDepth = int32(layer) + blitSrcDepth = int32(layer) + copySrcDepth = int32(layer) + layer = 0 + } + resolveSrcLayer := layer + blitSrcLayer := layer + copySrcLayer := layer + if imageObject.Info().Samples() != VkSampleCountFlagBits_VK_SAMPLE_COUNT_1_BIT { + resolveSrcLayer = layer + blitSrcDepth = 0 + blitSrcLayer = 0 + copySrcDepth = 0 + copySrcLayer = 0 + } + doBlit := !(requestWidth == imgWidth && requestHeight == imgHeight) + if doBlit { + copySrcDepth = 0 + copySrcLayer = 0 + } + + origLayout := imageObject.Aspects().Get(aspect).Layers().Get(layer).Levels().Get(level).Layout() + + queue := imageObject.Aspects().Get(aspect).Layers().Get(layer).Levels().Get(level).LastBoundQueue() if queue.IsNil() { - res(nil, &service.ErrDataUnavailable{Reason: messages.ErrMessage("The target image object has not been bound with a vkQueue")}) - return + queue = imageObject.LastBoundQueue() + if queue.IsNil() { + res(nil, &service.ErrDataUnavailable{Reason: messages.ErrMessage("The target image object has not been bound with a vkQueue")}) + return + } } vkQueue := queue.VulkanHandle() @@ -251,9 +282,6 @@ func postImageData(ctx context.Context, vkPhysicalDevice := device.PhysicalDevice() physicalDevice := GetState(s).PhysicalDevices().Get(vkPhysicalDevice) - requestWidth := reqWidth - requestHeight := reqHeight - if properties, ok := physicalDevice.QueueFamilyProperties().Lookup(queue.Family()); ok { if properties.QueueFlags()&VkQueueFlags(VkQueueFlagBits_VK_QUEUE_GRAPHICS_BIT) == 0 { if imageObject.Info().Samples() == VkSampleCountFlagBits_VK_SAMPLE_COUNT_1_BIT && @@ -446,12 +474,12 @@ func postImageData(ctx context.Context, 0, // bufferImageHeight NewVkImageSubresourceLayers(a, // imageSubresource VkImageAspectFlags(aspect), // aspectMask - 0, // mipLevel - 0, // baseArrayLayer + level, // mipLevel + copySrcLayer, // baseArrayLayer 1, // layerCount ), - MakeVkOffset3D(a), // imageOffset - NewVkExtent3D(a, requestWidth, requestHeight, 1), // imageExtent + NewVkOffset3D(a, int32(0), int32(0), copySrcDepth), // imageOffset + NewVkExtent3D(a, requestWidth, requestHeight, 1), // imageExtent ) bufferImageCopyData := MustAllocData(ctx, s, bufferImageCopy) @@ -590,9 +618,9 @@ func postImageData(ctx context.Context, VkAccessFlagBits_VK_ACCESS_TRANSFER_WRITE_BIT| VkAccessFlagBits_VK_ACCESS_TRANSFER_READ_BIT, ), - VkAccessFlags(VkAccessFlagBits_VK_ACCESS_TRANSFER_READ_BIT), // dstAccessMask - imageObject.Aspects().Get(aspect).Layers().Get(layer).Levels().Get(level).Layout(), // oldLayout - VkImageLayout_VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // newLayout + VkAccessFlags(VkAccessFlagBits_VK_ACCESS_TRANSFER_READ_BIT), // dstAccessMask + origLayout, // oldLayout + VkImageLayout_VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // newLayout 0xFFFFFFFF, // srcQueueFamilyIndex 0xFFFFFFFF, // dstQueueFamilyIndex imageObject.VulkanHandle(), // image @@ -616,8 +644,8 @@ func postImageData(ctx context.Context, VkAccessFlagBits_VK_ACCESS_SHADER_WRITE_BIT| VkAccessFlagBits_VK_ACCESS_TRANSFER_WRITE_BIT| VkAccessFlagBits_VK_ACCESS_TRANSFER_READ_BIT), - VkImageLayout_VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // oldLayout - imageObject.Aspects().Get(aspect).Layers().Get(layer).Levels().Get(level).Layout(), // newLayout + VkImageLayout_VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, // oldLayout + origLayout, // newLayout 0xFFFFFFFF, // srcQueueFamilyIndex 0xFFFFFFFF, // dstQueueFamilyIndex imageObject.VulkanHandle(), // image @@ -636,12 +664,12 @@ func postImageData(ctx context.Context, NewVkImageSubresourceLayers(a, // srcSubresource VkImageAspectFlags(aspect), // aspectMask 0, // mipLevel - 0, // baseArrayLayer + blitSrcLayer, // baseArrayLayer 1, // layerCount ), NewVkOffset3Dː2ᵃ(a, // srcOffsets - MakeVkOffset3D(a), - NewVkOffset3D(a, int32(imgWidth), int32(imgHeight), 1), + NewVkOffset3D(a, int32(0), int32(0), blitSrcDepth), + NewVkOffset3D(a, int32(imgWidth), int32(imgHeight), blitSrcDepth+int32(1)), ), NewVkImageSubresourceLayers(a, // dstSubresource VkImageAspectFlags(aspect), // aspectMask @@ -661,10 +689,10 @@ func postImageData(ctx context.Context, NewVkImageSubresourceLayers(a, // srcSubresource VkImageAspectFlags(aspect), // aspectMask 0, // mipLevel - 0, // baseArrayLayer + resolveSrcLayer, // baseArrayLayer 1, // layerCount ), - MakeVkOffset3D(a), // srcOffset + NewVkOffset3D(a, int32(0), int32(0), resolveSrcDepth), // srcOffset NewVkImageSubresourceLayers(a, // dstSubresource VkImageAspectFlags(aspect), // aspectMask 0, // mipLevel @@ -914,15 +942,10 @@ func postImageData(ctx context.Context, filter = VkFilter_VK_FILTER_NEAREST } - doBlit := true - copySrc := stagingImageID - - if requestWidth == imgWidth && requestHeight == imgHeight { - doBlit = false - copySrc = blitSrcImage - } + copySrc := blitSrcImage if doBlit { + copySrc = stagingImageID writeEach(ctx, out, cb.VkCmdBlitImage( commandBufferID, diff --git a/gapis/api/vulkan/vulkan.api b/gapis/api/vulkan/vulkan.api index 3ce142f881..e4f3b3ec43 100644 --- a/gapis/api/vulkan/vulkan.api +++ b/gapis/api/vulkan/vulkan.api @@ -211,6 +211,7 @@ sub ref!ExtensionSet supportedDeviceExtensions() { supported.ExtensionNames["VK_KHR_shader_draw_parameters"] = true supported.ExtensionNames["VK_KHR_relaxed_block_layout"] = true supported.ExtensionNames["VK_KHR_16bit_storage"] = true + supported.ExtensionNames["VK_KHR_maintenance1"] = true return supported }