-
Notifications
You must be signed in to change notification settings - Fork 134
/
state.go
209 lines (175 loc) · 7.2 KB
/
state.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
// Copyright (C) 2017 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package vulkan
import (
"fmt"
"github.com/google/gapid/gapis/api"
)
func (st *State) getFramebufferAttachmentCount() (uint32, error) {
if st.LastSubmission() == LastSubmissionType_SUBMIT {
lastQueue := st.LastBoundQueue()
if lastQueue.IsNil() {
return 0, fmt.Errorf("No previous queue submission")
}
lastDrawInfo, ok := st.LastDrawInfos().Lookup(lastQueue.VulkanHandle())
if !ok {
return 0, fmt.Errorf("There have been no previous draws")
}
if lastDrawInfo.Framebuffer().IsNil() || !st.Framebuffers().Contains(lastDrawInfo.Framebuffer().VulkanHandle()) {
return 0, fmt.Errorf("framebuffer is not bound")
}
if lastDrawInfo.Framebuffer().RenderPass().IsNil() {
return 0, fmt.Errorf("Renderpass is not bound")
}
return uint32(lastDrawInfo.Framebuffer().RenderPass().AttachmentDescriptions().Len()), nil
}
return st.LastPresentInfo().PresentImageCount(), nil
}
func (st *State) getSubmitAttachmentInfo(attachment uint32) (w, h uint32,
f VkFormat, attachmentIndex uint32,
canResize bool,
attachmentType api.FramebufferAttachmentType,
err error) {
returnError := func(format_str string, e ...interface{}) (w, h uint32,
f VkFormat, attachmentIndex uint32,
canResize bool,
attachmentType api.FramebufferAttachmentType,
err error) {
return 0, 0, VkFormat_VK_FORMAT_UNDEFINED, 0, true, api.FramebufferAttachmentType_OutputColor, fmt.Errorf(format_str, e...)
}
lastQueue := st.LastBoundQueue()
if lastQueue.IsNil() {
return returnError("No previous queue submission")
}
lastDrawInfo, ok := st.LastDrawInfos().Lookup(lastQueue.VulkanHandle())
if !ok {
return returnError("There have been no previous draws")
}
if lastDrawInfo.Framebuffer().IsNil() || !st.Framebuffers().Contains(lastDrawInfo.Framebuffer().VulkanHandle()) {
return returnError("Attachment %d is not bound", attachment)
}
if lastDrawInfo.Framebuffer().RenderPass().IsNil() {
return returnError("Attachment %d is not bound to any renderpass", attachment)
}
lastSubpass := lastDrawInfo.LastSubpass()
subpassDesc := lastDrawInfo.Framebuffer().RenderPass().SubpassDescriptions().Get(lastSubpass)
// Search for index in color attachments
for _, attIndex := range subpassDesc.ColorAttachments().Keys() {
attRef := subpassDesc.ColorAttachments().Get(attIndex)
if attachment == attRef.Attachment() {
if colorAttachment, ok := lastDrawInfo.FramebufferAttachments().Lookup(attachment); ok && !colorAttachment.IsNil() {
colorImg := colorAttachment.Image()
// This can occur if we destroy the image-view, we remove it from the framebuffer,
// but may not unbind the framebuffer.
if !colorImg.IsNil() {
return colorImg.Info().Extent().Width(),
colorImg.Info().Extent().Height(),
colorImg.Info().Fmt(),
attRef.Attachment(), true,
api.FramebufferAttachmentType_OutputColor, nil
}
}
}
}
// Search for index in input attachments
for _, attIndex := range subpassDesc.InputAttachments().Keys() {
attRef := subpassDesc.InputAttachments().Get(attIndex)
if attachment == attRef.Attachment() {
if inputAttachment, ok := lastDrawInfo.FramebufferAttachments().Lookup(attachment); ok && !inputAttachment.IsNil() {
inputImg := inputAttachment.Image()
if (VkImageAspectFlagBits(inputImg.ImageAspect()) & VkImageAspectFlagBits_VK_IMAGE_ASPECT_COLOR_BIT) != 0 {
if !inputImg.IsNil() {
return inputImg.Info().Extent().Width(),
inputImg.Info().Extent().Height(),
inputImg.Info().Fmt(),
attRef.Attachment(), true,
api.FramebufferAttachmentType_InputColor, nil
}
}
if (VkImageAspectFlagBits(inputImg.ImageAspect()) & VkImageAspectFlagBits_VK_IMAGE_ASPECT_DEPTH_BIT) != 0 {
if !inputImg.IsNil() {
return inputImg.Info().Extent().Width(),
inputImg.Info().Extent().Height(),
inputImg.Info().Fmt(),
attRef.Attachment(), true,
api.FramebufferAttachmentType_InputDepth, nil
}
}
}
}
}
// See if index corresponds to depth attachment
if !subpassDesc.DepthStencilAttachment().IsNil() && attachment == subpassDesc.DepthStencilAttachment().Attachment() {
if depthAttachment, ok := lastDrawInfo.FramebufferAttachments().Lookup(attachment); ok && !depthAttachment.IsNil() {
depthImg := depthAttachment.Image()
// This can occur if we destroy the image-view, we remove it from the framebuffer,
// but may not unbind the framebuffer.
if !depthImg.IsNil() {
return depthImg.Info().Extent().Width(),
depthImg.Info().Extent().Height(),
depthImg.Info().Fmt(),
subpassDesc.DepthStencilAttachment().Attachment(), true,
api.FramebufferAttachmentType_OutputDepth, nil
}
}
}
// Ignore resolve attachments
return returnError("Attachment %d is not bound", attachment)
}
func (st *State) getPresentAttachmentInfo(attachment uint32) (w, h uint32,
f VkFormat,
attachmentIndex uint32,
canResize bool,
attachmentType api.FramebufferAttachmentType,
err error) {
returnError := func(format_str string, e ...interface{}) (w, h uint32,
f VkFormat,
attachmentIndex uint32,
canResize bool,
attachmentType api.FramebufferAttachmentType,
err error) {
return 0, 0, VkFormat_VK_FORMAT_UNDEFINED, 0, false, api.FramebufferAttachmentType_OutputColor, fmt.Errorf(format_str, e...)
}
if st.LastPresentInfo().PresentImageCount() <= attachment {
return returnError("Swapchain does not contain image %v", attachment)
}
colorImg := st.LastPresentInfo().PresentImages().Get(attachment)
if !colorImg.IsNil() {
queue := st.Queues().Get(st.LastPresentInfo().Queue())
vkDevice := queue.Device()
device := st.Devices().Get(vkDevice)
vkPhysicalDevice := device.PhysicalDevice()
physicalDevice := st.PhysicalDevices().Get(vkPhysicalDevice)
if properties, ok := physicalDevice.QueueFamilyProperties().Lookup(queue.Family()); ok {
if properties.QueueFlags()&VkQueueFlags(VkQueueFlagBits_VK_QUEUE_GRAPHICS_BIT) != 0 {
return colorImg.Info().Extent().Width(),
colorImg.Info().Extent().Height(),
colorImg.Info().Fmt(), attachment, true,
api.FramebufferAttachmentType_OutputColor, nil
}
return colorImg.Info().Extent().Width(),
colorImg.Info().Extent().Height(),
colorImg.Info().Fmt(), attachment, false,
api.FramebufferAttachmentType_OutputColor, nil
}
return returnError("Last present queue does not exist", attachment)
}
return returnError("Swapchain attachment %d does not exist", attachment)
}
func (st *State) getFramebufferAttachmentInfo(attachment uint32) (uint32, uint32, VkFormat, uint32, bool, api.FramebufferAttachmentType, error) {
if st.LastSubmission() == LastSubmissionType_SUBMIT {
return st.getSubmitAttachmentInfo(attachment)
}
return st.getPresentAttachmentInfo(attachment)
}