(id api.CmdID, width, height, bufferIdx uint32, res replay.Result)
| 114 | } |
| 115 | |
| 116 | func (t *readFramebuffer) Color(id api.CmdID, width, height, bufferIdx uint32, res replay.Result) { |
| 117 | t.injections[id] = append(t.injections[id], func(ctx context.Context, cmd api.Cmd, out transform.Writer) { |
| 118 | s := out.State() |
| 119 | c := GetState(s) |
| 120 | |
| 121 | cb := CommandBuilder{Thread: cmd.Thread(), Arena: s.Arena} |
| 122 | |
| 123 | // TODO: Figure out a better way to select the framebuffer here. |
| 124 | if GetState(s).LastSubmission() == LastSubmissionType_SUBMIT { |
| 125 | lastQueue := c.LastBoundQueue() |
| 126 | if lastQueue.IsNil() { |
| 127 | res(nil, &service.ErrDataUnavailable{Reason: messages.ErrMessage("No previous queue submission")}) |
| 128 | return |
| 129 | } |
| 130 | |
| 131 | lastDrawInfo, ok := c.LastDrawInfos().Lookup(lastQueue.VulkanHandle()) |
| 132 | if !ok { |
| 133 | res(nil, &service.ErrDataUnavailable{Reason: messages.ErrMessage("There have been no previous draws")}) |
| 134 | return |
| 135 | } |
| 136 | if lastDrawInfo.Framebuffer().IsNil() { |
| 137 | res(nil, &service.ErrDataUnavailable{Reason: messages.ErrMessage("There has been no framebuffer")}) |
| 138 | return |
| 139 | } |
| 140 | |
| 141 | imageView, ok := lastDrawInfo.Framebuffer().ImageAttachments().Lookup(bufferIdx) |
| 142 | if !ok { |
| 143 | res(nil, &service.ErrDataUnavailable{Reason: messages.ErrMessage("There has been no attchment in the framebuffer")}) |
| 144 | return |
| 145 | } |
| 146 | if imageView.IsNil() { |
| 147 | res(nil, &service.ErrDataUnavailable{Reason: messages.ErrMessage("Invalid attachment in the framebuffer, the attachment VkImageView might have been destroyed")}) |
| 148 | return |
| 149 | } |
| 150 | // Imageviews that are used in framebuffer attachments must contains |
| 151 | // only one mip level. |
| 152 | level := imageView.SubresourceRange().BaseMipLevel() |
| 153 | // There might be multiple layers, currently we only support the |
| 154 | // first one. |
| 155 | // TODO: support multi-layer rendering. |
| 156 | layer := imageView.SubresourceRange().BaseArrayLayer() |
| 157 | imageObject := imageView.Image() |
| 158 | if imageObject.IsNil() { |
| 159 | res(nil, &service.ErrDataUnavailable{Reason: messages.ErrMessage("Invalid attachment in the framebuffer, the attachment VkImage might have been destroyed")}) |
| 160 | return |
| 161 | } |
| 162 | w, h, form := lastDrawInfo.Framebuffer().Width(), lastDrawInfo.Framebuffer().Height(), imageView.Fmt() |
| 163 | postImageData(ctx, cb, s, imageObject, form, VkImageAspectFlagBits_VK_IMAGE_ASPECT_COLOR_BIT, layer, level, w, h, width, height, nil, out, res) |
| 164 | } else { |
| 165 | imageObject := GetState(s).LastPresentInfo().PresentImages().Get(bufferIdx) |
| 166 | if imageObject.IsNil() { |
| 167 | res(nil, &service.ErrDataUnavailable{Reason: messages.ErrMessage("Could not find imageObject")}) |
| 168 | return |
| 169 | } |
| 170 | w, h, form := imageObject.Info().Extent().Width(), imageObject.Info().Extent().Height(), imageObject.Info().Fmt() |
| 171 | // There might be multiple layers for an image created by swapchain |
| 172 | // but currently we only support layer 0. |
| 173 | // TODO: support multi-layer swapchain images. |
no test coverage detected