Skip to content

Commit

Permalink
Vulkan: Show first layer in case of layered rendering (#2500)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Qining authored Dec 20, 2018
1 parent 4abc25d commit 32360eb
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 34 deletions.
19 changes: 19 additions & 0 deletions gapis/api/vulkan/api/image.api
Original file line number Diff line number Diff line change
Expand Up @@ -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
// ----------------------------------------------------------------------------
Expand Down
10 changes: 5 additions & 5 deletions gapis/api/vulkan/api/renderpass_framebuffer.api
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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: {
Expand Down
81 changes: 52 additions & 29 deletions gapis/api/vulkan/read_framebuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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()
Expand All @@ -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 &&
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions gapis/api/vulkan/vulkan.api
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 32360eb

Please sign in to comment.