Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to read_framebuffer to allow compute presentation. #1833

Merged
merged 1 commit into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion gapis/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ type API interface {
after []uint64,
state *GlobalState,
thread uint64,
attachment FramebufferAttachment) (width, height, index uint32, format *image.Format, err error)
attachment FramebufferAttachment) (info FramebufferAttachmentInfo, err error)

// Context returns the active context for the given state.
Context(state *GlobalState, thread uint64) Context
Expand All @@ -55,6 +55,20 @@ type API interface {
CreateCmd(name string) Cmd
}

// FramebufferAttachmentInfo describes a framebuffer at a given point in the trace
type FramebufferAttachmentInfo struct {
// Width in texels of the framebuffer
Width uint32
// Height in texels of the framebuffer
Height uint32
// Framebuffer index
Index uint32
// Format of the image
Format *image.Format
// CanResize is true if this can be efficiently resized during replay.
CanResize bool
}

// ID is an API identifier
type ID id.ID

Expand Down
19 changes: 9 additions & 10 deletions gapis/api/gles/gles.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"fmt"
"strings"

"github.com/google/gapid/core/image"
"github.com/google/gapid/core/log"
"github.com/google/gapid/core/stream"
"github.com/google/gapid/gapis/api"
Expand Down Expand Up @@ -193,7 +192,7 @@ func (API) GetFramebufferAttachmentInfo(
after []uint64,
state *api.GlobalState,
thread uint64,
attachment api.FramebufferAttachment) (width, height, index uint32, format *image.Format, err error) {
attachment api.FramebufferAttachment) (inf api.FramebufferAttachmentInfo, err error) {

return GetFramebufferAttachmentInfoByID(state, thread, attachment, 0)
}
Expand All @@ -205,45 +204,45 @@ func GetFramebufferAttachmentInfoByID(
state *api.GlobalState,
thread uint64,
attachment api.FramebufferAttachment,
fb FramebufferId) (width, height, index uint32, format *image.Format, err error) {
fb FramebufferId) (inf api.FramebufferAttachmentInfo, err error) {

s := GetState(state)

if fb == 0 {
c := s.GetContext(thread)
if c == nil {
return 0, 0, 0, nil, fmt.Errorf("No context bound")
return api.FramebufferAttachmentInfo{}, fmt.Errorf("No context bound")
}
if !c.Other.Initialized {
return 0, 0, 0, nil, fmt.Errorf("Context not initialized")
return api.FramebufferAttachmentInfo{}, fmt.Errorf("Context not initialized")
}
fb = c.Bound.DrawFramebuffer.GetID()
}

glAtt, err := attachmentToEnum(attachment)
if err != nil {
return 0, 0, 0, nil, err
return api.FramebufferAttachmentInfo{}, err
}

fbai, err := s.getFramebufferAttachmentInfo(thread, fb, glAtt)
if fbai.format == 0 {
return 0, 0, 0, nil, fmt.Errorf("No format set")
return api.FramebufferAttachmentInfo{}, fmt.Errorf("No format set")
}
if err != nil {
return 0, 0, 0, nil, err
return api.FramebufferAttachmentInfo{}, err
}
fmt, ty := getUnsizedFormatAndType(fbai.format)
f, err := getImageFormat(fmt, ty)
if err != nil {
return 0, 0, 0, nil, err
return api.FramebufferAttachmentInfo{}, err
}
switch {
case attachment.IsDepth():
f = filterUncompressedImageFormat(f, stream.Channel.IsDepth)
case attachment.IsStencil():
f = filterUncompressedImageFormat(f, stream.Channel.IsStencil)
}
return fbai.width, fbai.height, 0, f, nil
return api.FramebufferAttachmentInfo{fbai.width, fbai.height, 0, f, true}, nil
}

// Context returns the active context for the given state and thread.
Expand Down
4 changes: 2 additions & 2 deletions gapis/api/gvr/gvr.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ func (API) GetFramebufferAttachmentInfo(
after []uint64,
state *api.GlobalState,
thread uint64,
attachment api.FramebufferAttachment) (width, height, index uint32, format *image.Format, err error) {
attachment api.FramebufferAttachment) (inf api.FramebufferAttachmentInfo, err error) {

fb, err := getFramebuffer(ctx, api.CmdID(after[0]))
if err != nil {
return 0, 0, 0, nil, err
return api.FramebufferAttachmentInfo{}, err
}
return gles.GetFramebufferAttachmentInfoByID(state, thread, attachment, fb)
}
Expand Down
4 changes: 2 additions & 2 deletions gapis/api/test/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ func (API) GetFramebufferAttachmentInfo(
after []uint64,
state *api.GlobalState,
thread uint64,
attachment api.FramebufferAttachment) (width, height, index uint32, format *image.Format, err error) {
return 0, 0, 0, nil, nil
attachment api.FramebufferAttachment) (api.FramebufferAttachmentInfo, err error) {
return api.FramebufferAttachmentInfo{}, nil
}

func (API) Context(*api.GlobalState, uint64) api.Context { return nil }
Expand Down
4 changes: 2 additions & 2 deletions gapis/api/testcmd/cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ func (API) GetFramebufferAttachmentInfo(
after []uint64,
state *api.GlobalState,
thread uint64,
attachment api.FramebufferAttachment) (width, height, index uint32, format *image.Format, err error) {
return 0, 0, 0, nil, nil
attachment api.FramebufferAttachment) (api.FramebufferAttachmentInfo, err error) {
return api.FramebufferAttachmentInfo{}, nil
}
func (API) Context(*api.GlobalState, uint64) api.Context { return nil }
func (API) CreateCmd(name string) api.Cmd {
Expand Down
123 changes: 74 additions & 49 deletions gapis/api/vulkan/read_framebuffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,27 @@ func postImageData(ctx context.Context,
device := GetState(s).Devices.Get(vkDevice)
vkPhysicalDevice := device.PhysicalDevice
physicalDevice := GetState(s).PhysicalDevices.Get(vkPhysicalDevice)
// Rendered image should always has a graphics-capable queue bound, if none
// of such a queue found for this image or the bound queue does not have
// graphics capability, throw error messages and return.

requestWidth := reqWidth
requestHeight := reqHeight

if queue == nil {
res(nil, &service.ErrDataUnavailable{Reason: messages.ErrMessage("The target image object has not been bound with a vkQueue")})
return
}
if properties, ok := physicalDevice.QueueFamilyProperties.Lookup(queue.Family); ok {
if properties.QueueFlags&VkQueueFlags(VkQueueFlagBits_VK_QUEUE_GRAPHICS_BIT) == 0 {
res(nil, &service.ErrDataUnavailable{Reason: messages.ErrMessage("The bound vkQueue does not have VK_QUEUE_GRAPHICS_BIT capability")})
return
if imageObject.Info.Samples == VkSampleCountFlagBits_VK_SAMPLE_COUNT_1_BIT &&
aspect == VkImageAspectFlagBits_VK_IMAGE_ASPECT_COLOR_BIT {
// If this is on the compute queue, we cannot do a blit operation,
// We can however do it on the CPU afterwards, or let the
// client deal with it
requestWidth = imgWidth
requestHeight = imgHeight
} else {
res(nil, &service.ErrDataUnavailable{Reason: messages.ErrMessage("Unhandled: Reading a multisampled or depth image on the compute queue")})
return
}
}
} else {
res(nil, &service.ErrDataUnavailable{Reason: messages.ErrMessage("Not found the properties information of the bound vkQueue")})
Expand Down Expand Up @@ -273,13 +283,13 @@ func postImageData(ctx context.Context,
}
}

bufferSize := uint64(formatOfImgRes.Size(int(reqWidth), int(reqHeight), 1))
bufferSize := uint64(formatOfImgRes.Size(int(requestWidth), int(requestHeight), 1))
// For the depth aspect of VK_FORMAT_X8_D24_UNORM_PACK32 and
// VK_FORMAT_D24_UNORM_S8_UINT format, each depth element requires 4 bytes in
// the buffer when used in buffer image copy.
if aspect == VkImageAspectFlagBits_VK_IMAGE_ASPECT_DEPTH_BIT && (vkFormat == VkFormat_VK_FORMAT_X8_D24_UNORM_PACK32 || vkFormat == VkFormat_VK_FORMAT_D24_UNORM_S8_UINT) {
r32Fmt, _ := getImageFormatFromVulkanFormat(VkFormat_VK_FORMAT_R32_UINT)
bufferSize = uint64(r32Fmt.Size(int(reqWidth), int(reqHeight), 1))
bufferSize = uint64(r32Fmt.Size(int(requestWidth), int(requestHeight), 1))
}

// Data and info for destination buffer creation
Expand Down Expand Up @@ -315,8 +325,8 @@ func postImageData(ctx context.Context,
ImageType: VkImageType_VK_IMAGE_TYPE_2D,
Fmt: vkFormat,
Extent: VkExtent3D{
Width: reqWidth,
Height: reqHeight,
Width: requestWidth,
Height: requestHeight,
Depth: 1,
},
MipLevels: 1,
Expand Down Expand Up @@ -413,7 +423,7 @@ func postImageData(ctx context.Context,
LayerCount: 1,
},
ImageOffset: VkOffset3D{X: 0, Y: 0, Z: 0},
ImageExtent: VkExtent3D{Width: reqWidth, Height: reqHeight, Depth: 1},
ImageExtent: VkExtent3D{Width: requestWidth, Height: requestHeight, Depth: 1},
}
bufferImageCopyData := MustAllocData(ctx, s, bufferImageCopy)

Expand Down Expand Up @@ -629,8 +639,8 @@ func postImageData(ctx context.Context,
Z: 0,
},
{
X: int32(reqWidth),
Y: int32(reqHeight),
X: int32(requestWidth),
Y: int32(requestHeight),
Z: 1,
},
},
Expand Down Expand Up @@ -906,36 +916,60 @@ func postImageData(ctx context.Context,
if aspect != VkImageAspectFlagBits_VK_IMAGE_ASPECT_COLOR_BIT {
filter = VkFilter_VK_FILTER_NEAREST
}

doBlit := true
copySrc := stagingImageId

if requestWidth == imgWidth && requestHeight == imgHeight {
doBlit = false
copySrc = blitSrcImage
}

if doBlit {
writeEach(ctx, out,
cb.VkCmdBlitImage(
commandBufferId,
blitSrcImage,
VkImageLayout_VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
stagingImageId,
VkImageLayout_VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
1,
imageBlitData.Ptr(),
filter,
).AddRead(imageBlitData.Data()),
// Set the blit image to transfer src
cb.VkCmdPipelineBarrier(
commandBufferId,
VkPipelineStageFlags(VkPipelineStageFlagBits_VK_PIPELINE_STAGE_ALL_COMMANDS_BIT),
VkPipelineStageFlags(VkPipelineStageFlagBits_VK_PIPELINE_STAGE_ALL_COMMANDS_BIT),
VkDependencyFlags(0),
0,
memory.Nullptr,
0,
memory.Nullptr,
1,
stagingImageToSrcBarrierData.Ptr(),
).AddRead(
stagingImageToSrcBarrierData.Data(),
),
)
}

writeEach(ctx, out,
cb.VkCmdBlitImage(
cb.VkCmdCopyImageToBuffer(
commandBufferId,
blitSrcImage,
copySrc,
VkImageLayout_VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
stagingImageId,
VkImageLayout_VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL,
bufferId,
1,
imageBlitData.Ptr(),
filter,
).AddRead(imageBlitData.Data()),
bufferImageCopyData.Ptr(),
).AddRead(
bufferImageCopyData.Data(),
),
)

// Change the layout of staging image and attachment image, copy staging image to buffer,
// end command buffer
writeEach(ctx, out,
cb.VkCmdPipelineBarrier(
commandBufferId,
VkPipelineStageFlags(VkPipelineStageFlagBits_VK_PIPELINE_STAGE_ALL_COMMANDS_BIT),
VkPipelineStageFlags(VkPipelineStageFlagBits_VK_PIPELINE_STAGE_ALL_COMMANDS_BIT),
VkDependencyFlags(0),
0,
memory.Nullptr,
0,
memory.Nullptr,
1,
stagingImageToSrcBarrierData.Ptr(),
).AddRead(
stagingImageToSrcBarrierData.Data(),
),
// Reset the image, and end the command buffer.
cb.VkCmdPipelineBarrier(
commandBufferId,
VkPipelineStageFlags(VkPipelineStageFlagBits_VK_PIPELINE_STAGE_ALL_COMMANDS_BIT),
Expand All @@ -950,20 +984,11 @@ func postImageData(ctx context.Context,
).AddRead(
attachmentImageResetLayoutBarrierData.Data(),
),
cb.VkCmdCopyImageToBuffer(
commandBufferId,
stagingImageId,
VkImageLayout_VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL,
bufferId,
1,
bufferImageCopyData.Ptr(),
).AddRead(
bufferImageCopyData.Data(),
),
cb.VkEndCommandBuffer(
commandBufferId,
VkResult_VK_SUCCESS,
))
),
)

// Submit all the commands above, wait until finish.
writeEach(ctx, out,
Expand Down Expand Up @@ -1036,7 +1061,7 @@ func postImageData(ctx context.Context,
}

// Flip the image in Y axis
rowSizeInBytes := uint64(formatOfImgRes.Size(int(reqWidth), 1, 1))
rowSizeInBytes := uint64(formatOfImgRes.Size(int(requestWidth), 1, 1))
top := uint64(0)
bottom := bufferSize - rowSizeInBytes
var temp = make([]byte, rowSizeInBytes)
Expand All @@ -1055,8 +1080,8 @@ func postImageData(ctx context.Context,

img := &image.Data{
Bytes: bytes,
Width: uint32(reqWidth),
Height: uint32(reqHeight),
Width: uint32(requestWidth),
Height: uint32(requestHeight),
Depth: 1,
Format: formatOfImgRes,
}
Expand Down
Loading