blob: 17b254eb6aa7bc5122114e9b38e070ea153c282a [file] [log] [blame]
Greg Daniel164a9f02016-02-22 09:56:40 -05001/*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "vk/GrVkInterface.h"
jvanverthfd7bd452016-03-25 06:29:52 -07009#include "vk/GrVkBackendContext.h"
jvanverthd2497f32016-03-18 12:39:05 -070010#include "vk/GrVkUtil.h"
Greg Daniel164a9f02016-02-22 09:56:40 -050011
12GrVkInterface::GrVkInterface() {
13}
14
15#define GET_PROC(F) functions->f ## F = (PFN_vk ## F) vkGetInstanceProcAddr(instance, "vk" #F)
jvanverthd2497f32016-03-18 12:39:05 -070016#define GET_PROC_LOCAL(inst, F) PFN_vk ## F F = (PFN_vk ## F) vkGetInstanceProcAddr(inst, "vk" #F)
jvanverth633b3562016-03-23 11:01:22 -070017#define GET_DEV_PROC(F) functions->f ## F = (PFN_vk ## F) vkGetDeviceProcAddr(device, "vk" #F)
Greg Daniel164a9f02016-02-22 09:56:40 -050018
halcanary9d524f22016-03-29 09:03:52 -070019const GrVkInterface* GrVkCreateInterface(VkInstance instance, VkDevice device,
jvanverthfd7bd452016-03-25 06:29:52 -070020 uint32_t extensionFlags) {
jvanverthd2497f32016-03-18 12:39:05 -070021
Greg Daniel164a9f02016-02-22 09:56:40 -050022 GrVkInterface* interface = new GrVkInterface();
23 GrVkInterface::Functions* functions = &interface->fFunctions;
24
25 GET_PROC(CreateInstance);
26 GET_PROC(DestroyInstance);
27 GET_PROC(EnumeratePhysicalDevices);
28 GET_PROC(GetPhysicalDeviceFeatures);
29 GET_PROC(GetPhysicalDeviceFormatProperties);
30 GET_PROC(GetPhysicalDeviceImageFormatProperties);
31 GET_PROC(GetPhysicalDeviceProperties);
32 GET_PROC(GetPhysicalDeviceQueueFamilyProperties);
33 GET_PROC(GetPhysicalDeviceMemoryProperties);
34 GET_PROC(CreateDevice);
35 GET_PROC(DestroyDevice);
36 GET_PROC(EnumerateInstanceExtensionProperties);
37 GET_PROC(EnumerateDeviceExtensionProperties);
38 GET_PROC(EnumerateInstanceLayerProperties);
39 GET_PROC(EnumerateDeviceLayerProperties);
jvanverth633b3562016-03-23 11:01:22 -070040 GET_DEV_PROC(GetDeviceQueue);
41 GET_DEV_PROC(QueueSubmit);
42 GET_DEV_PROC(QueueWaitIdle);
43 GET_DEV_PROC(DeviceWaitIdle);
44 GET_DEV_PROC(AllocateMemory);
45 GET_DEV_PROC(FreeMemory);
46 GET_DEV_PROC(MapMemory);
47 GET_DEV_PROC(UnmapMemory);
48 GET_DEV_PROC(FlushMappedMemoryRanges);
49 GET_DEV_PROC(InvalidateMappedMemoryRanges);
50 GET_DEV_PROC(GetDeviceMemoryCommitment);
51 GET_DEV_PROC(BindBufferMemory);
52 GET_DEV_PROC(BindImageMemory);
53 GET_DEV_PROC(GetBufferMemoryRequirements);
54 GET_DEV_PROC(GetImageMemoryRequirements);
55 GET_DEV_PROC(GetImageSparseMemoryRequirements);
Greg Daniel164a9f02016-02-22 09:56:40 -050056 GET_PROC(GetPhysicalDeviceSparseImageFormatProperties);
jvanverth633b3562016-03-23 11:01:22 -070057 GET_DEV_PROC(QueueBindSparse);
58 GET_DEV_PROC(CreateFence);
59 GET_DEV_PROC(DestroyFence);
60 GET_DEV_PROC(ResetFences);
61 GET_DEV_PROC(GetFenceStatus);
62 GET_DEV_PROC(WaitForFences);
63 GET_DEV_PROC(CreateSemaphore);
64 GET_DEV_PROC(DestroySemaphore);
65 GET_DEV_PROC(CreateEvent);
66 GET_DEV_PROC(DestroyEvent);
67 GET_DEV_PROC(GetEventStatus);
68 GET_DEV_PROC(SetEvent);
69 GET_DEV_PROC(ResetEvent);
70 GET_DEV_PROC(CreateQueryPool);
71 GET_DEV_PROC(DestroyQueryPool);
72 GET_DEV_PROC(GetQueryPoolResults);
73 GET_DEV_PROC(CreateBuffer);
74 GET_DEV_PROC(DestroyBuffer);
75 GET_DEV_PROC(CreateBufferView);
76 GET_DEV_PROC(DestroyBufferView);
77 GET_DEV_PROC(CreateImage);
78 GET_DEV_PROC(DestroyImage);
79 GET_DEV_PROC(GetImageSubresourceLayout);
80 GET_DEV_PROC(CreateImageView);
81 GET_DEV_PROC(DestroyImageView);
82 GET_DEV_PROC(CreateShaderModule);
83 GET_DEV_PROC(DestroyShaderModule);
84 GET_DEV_PROC(CreatePipelineCache);
85 GET_DEV_PROC(DestroyPipelineCache);
86 GET_DEV_PROC(GetPipelineCacheData);
87 GET_DEV_PROC(MergePipelineCaches);
88 GET_DEV_PROC(CreateGraphicsPipelines);
89 GET_DEV_PROC(CreateComputePipelines);
90 GET_DEV_PROC(DestroyPipeline);
91 GET_DEV_PROC(CreatePipelineLayout);
92 GET_DEV_PROC(DestroyPipelineLayout);
93 GET_DEV_PROC(CreateSampler);
94 GET_DEV_PROC(DestroySampler);
95 GET_DEV_PROC(CreateDescriptorSetLayout);
96 GET_DEV_PROC(DestroyDescriptorSetLayout);
97 GET_DEV_PROC(CreateDescriptorPool);
98 GET_DEV_PROC(DestroyDescriptorPool);
99 GET_DEV_PROC(ResetDescriptorPool);
100 GET_DEV_PROC(AllocateDescriptorSets);
101 GET_DEV_PROC(FreeDescriptorSets);
102 GET_DEV_PROC(UpdateDescriptorSets);
103 GET_DEV_PROC(CreateFramebuffer);
104 GET_DEV_PROC(DestroyFramebuffer);
105 GET_DEV_PROC(CreateRenderPass);
106 GET_DEV_PROC(DestroyRenderPass);
107 GET_DEV_PROC(GetRenderAreaGranularity);
108 GET_DEV_PROC(CreateCommandPool);
109 GET_DEV_PROC(DestroyCommandPool);
110 GET_DEV_PROC(ResetCommandPool);
111 GET_DEV_PROC(AllocateCommandBuffers);
112 GET_DEV_PROC(FreeCommandBuffers);
113 GET_DEV_PROC(BeginCommandBuffer);
114 GET_DEV_PROC(EndCommandBuffer);
115 GET_DEV_PROC(ResetCommandBuffer);
116 GET_DEV_PROC(CmdBindPipeline);
117 GET_DEV_PROC(CmdSetViewport);
118 GET_DEV_PROC(CmdSetScissor);
119 GET_DEV_PROC(CmdSetLineWidth);
120 GET_DEV_PROC(CmdSetDepthBias);
121 GET_DEV_PROC(CmdSetBlendConstants);
122 GET_DEV_PROC(CmdSetDepthBounds);
123 GET_DEV_PROC(CmdSetStencilCompareMask);
124 GET_DEV_PROC(CmdSetStencilWriteMask);
125 GET_DEV_PROC(CmdSetStencilReference);
126 GET_DEV_PROC(CmdBindDescriptorSets);
127 GET_DEV_PROC(CmdBindIndexBuffer);
128 GET_DEV_PROC(CmdBindVertexBuffers);
129 GET_DEV_PROC(CmdDraw);
130 GET_DEV_PROC(CmdDrawIndexed);
131 GET_DEV_PROC(CmdDrawIndirect);
132 GET_DEV_PROC(CmdDrawIndexedIndirect);
133 GET_DEV_PROC(CmdDispatch);
134 GET_DEV_PROC(CmdDispatchIndirect);
135 GET_DEV_PROC(CmdCopyBuffer);
136 GET_DEV_PROC(CmdCopyImage);
137 GET_DEV_PROC(CmdBlitImage);
138 GET_DEV_PROC(CmdCopyBufferToImage);
139 GET_DEV_PROC(CmdCopyImageToBuffer);
140 GET_DEV_PROC(CmdUpdateBuffer);
141 GET_DEV_PROC(CmdFillBuffer);
142 GET_DEV_PROC(CmdClearColorImage);
143 GET_DEV_PROC(CmdClearDepthStencilImage);
144 GET_DEV_PROC(CmdClearAttachments);
145 GET_DEV_PROC(CmdResolveImage);
146 GET_DEV_PROC(CmdSetEvent);
147 GET_DEV_PROC(CmdResetEvent);
148 GET_DEV_PROC(CmdWaitEvents);
149 GET_DEV_PROC(CmdPipelineBarrier);
150 GET_DEV_PROC(CmdBeginQuery);
151 GET_DEV_PROC(CmdEndQuery);
152 GET_DEV_PROC(CmdResetQueryPool);
153 GET_DEV_PROC(CmdWriteTimestamp);
154 GET_DEV_PROC(CmdCopyQueryPoolResults);
155 GET_DEV_PROC(CmdPushConstants);
156 GET_DEV_PROC(CmdBeginRenderPass);
157 GET_DEV_PROC(CmdNextSubpass);
158 GET_DEV_PROC(CmdEndRenderPass);
159 GET_DEV_PROC(CmdExecuteCommands);
Greg Daniel164a9f02016-02-22 09:56:40 -0500160
jvanverthfd7bd452016-03-25 06:29:52 -0700161 if (extensionFlags & kEXT_debug_report_GrVkExtensionFlag) {
jvanverthd2497f32016-03-18 12:39:05 -0700162 GET_PROC(CreateDebugReportCallbackEXT);
163 GET_PROC(DebugReportMessageEXT);
164 GET_PROC(DestroyDebugReportCallbackEXT);
165 }
166
Greg Daniel164a9f02016-02-22 09:56:40 -0500167 return interface;
168}
169
170#define RETURN_FALSE_INTERFACE \
171 if (kIsDebug) { SkDebugf("%s:%d GrVkInterface::validate() failed.\n", __FILE__, __LINE__); } \
172 return false;
173
174bool GrVkInterface::validate() const {
175 // functions that are always required
176 if (NULL == fFunctions.fCreateInstance ||
177 NULL == fFunctions.fDestroyInstance ||
178 NULL == fFunctions.fEnumeratePhysicalDevices ||
179 NULL == fFunctions.fGetPhysicalDeviceFeatures ||
180 NULL == fFunctions.fGetPhysicalDeviceFormatProperties ||
181 NULL == fFunctions.fGetPhysicalDeviceImageFormatProperties ||
182 NULL == fFunctions.fGetPhysicalDeviceProperties ||
183 NULL == fFunctions.fGetPhysicalDeviceQueueFamilyProperties ||
184 NULL == fFunctions.fGetPhysicalDeviceMemoryProperties ||
185 NULL == fFunctions.fCreateDevice ||
186 NULL == fFunctions.fDestroyDevice ||
187 NULL == fFunctions.fEnumerateInstanceExtensionProperties ||
188 NULL == fFunctions.fEnumerateDeviceExtensionProperties ||
189 NULL == fFunctions.fEnumerateInstanceLayerProperties ||
190 NULL == fFunctions.fEnumerateDeviceLayerProperties ||
191 NULL == fFunctions.fGetDeviceQueue ||
192 NULL == fFunctions.fQueueSubmit ||
193 NULL == fFunctions.fQueueWaitIdle ||
194 NULL == fFunctions.fDeviceWaitIdle ||
195 NULL == fFunctions.fAllocateMemory ||
196 NULL == fFunctions.fFreeMemory ||
197 NULL == fFunctions.fMapMemory ||
198 NULL == fFunctions.fUnmapMemory ||
199 NULL == fFunctions.fFlushMappedMemoryRanges ||
200 NULL == fFunctions.fInvalidateMappedMemoryRanges ||
201 NULL == fFunctions.fGetDeviceMemoryCommitment ||
202 NULL == fFunctions.fBindBufferMemory ||
203 NULL == fFunctions.fBindImageMemory ||
204 NULL == fFunctions.fGetBufferMemoryRequirements ||
205 NULL == fFunctions.fGetImageMemoryRequirements ||
206 NULL == fFunctions.fGetImageSparseMemoryRequirements ||
207 NULL == fFunctions.fGetPhysicalDeviceSparseImageFormatProperties ||
208 NULL == fFunctions.fQueueBindSparse ||
209 NULL == fFunctions.fCreateFence ||
210 NULL == fFunctions.fDestroyFence ||
211 NULL == fFunctions.fResetFences ||
212 NULL == fFunctions.fGetFenceStatus ||
213 NULL == fFunctions.fWaitForFences ||
214 NULL == fFunctions.fCreateSemaphore ||
215 NULL == fFunctions.fDestroySemaphore ||
216 NULL == fFunctions.fCreateEvent ||
217 NULL == fFunctions.fDestroyEvent ||
218 NULL == fFunctions.fGetEventStatus ||
219 NULL == fFunctions.fSetEvent ||
220 NULL == fFunctions.fResetEvent ||
221 NULL == fFunctions.fCreateQueryPool ||
222 NULL == fFunctions.fDestroyQueryPool ||
223 NULL == fFunctions.fGetQueryPoolResults ||
224 NULL == fFunctions.fCreateBuffer ||
225 NULL == fFunctions.fDestroyBuffer ||
226 NULL == fFunctions.fCreateBufferView ||
227 NULL == fFunctions.fDestroyBufferView ||
228 NULL == fFunctions.fCreateImage ||
229 NULL == fFunctions.fDestroyImage ||
230 NULL == fFunctions.fGetImageSubresourceLayout ||
231 NULL == fFunctions.fCreateImageView ||
232 NULL == fFunctions.fDestroyImageView ||
233 NULL == fFunctions.fCreateShaderModule ||
234 NULL == fFunctions.fDestroyShaderModule ||
235 NULL == fFunctions.fCreatePipelineCache ||
236 NULL == fFunctions.fDestroyPipelineCache ||
237 NULL == fFunctions.fGetPipelineCacheData ||
238 NULL == fFunctions.fMergePipelineCaches ||
239 NULL == fFunctions.fCreateGraphicsPipelines ||
240 NULL == fFunctions.fCreateComputePipelines ||
241 NULL == fFunctions.fDestroyPipeline ||
242 NULL == fFunctions.fCreatePipelineLayout ||
243 NULL == fFunctions.fDestroyPipelineLayout ||
244 NULL == fFunctions.fCreateSampler ||
245 NULL == fFunctions.fDestroySampler ||
246 NULL == fFunctions.fCreateDescriptorSetLayout ||
247 NULL == fFunctions.fDestroyDescriptorSetLayout ||
248 NULL == fFunctions.fCreateDescriptorPool ||
249 NULL == fFunctions.fDestroyDescriptorPool ||
250 NULL == fFunctions.fResetDescriptorPool ||
251 NULL == fFunctions.fAllocateDescriptorSets ||
252 NULL == fFunctions.fFreeDescriptorSets ||
253 NULL == fFunctions.fUpdateDescriptorSets ||
254 NULL == fFunctions.fCreateFramebuffer ||
255 NULL == fFunctions.fDestroyFramebuffer ||
256 NULL == fFunctions.fCreateRenderPass ||
257 NULL == fFunctions.fDestroyRenderPass ||
258 NULL == fFunctions.fGetRenderAreaGranularity ||
259 NULL == fFunctions.fCreateCommandPool ||
260 NULL == fFunctions.fDestroyCommandPool ||
261 NULL == fFunctions.fResetCommandPool ||
262 NULL == fFunctions.fAllocateCommandBuffers ||
263 NULL == fFunctions.fFreeCommandBuffers ||
264 NULL == fFunctions.fBeginCommandBuffer ||
265 NULL == fFunctions.fEndCommandBuffer ||
266 NULL == fFunctions.fResetCommandBuffer ||
267 NULL == fFunctions.fCmdBindPipeline ||
268 NULL == fFunctions.fCmdSetViewport ||
269 NULL == fFunctions.fCmdSetScissor ||
270 NULL == fFunctions.fCmdSetLineWidth ||
271 NULL == fFunctions.fCmdSetDepthBias ||
272 NULL == fFunctions.fCmdSetBlendConstants ||
273 NULL == fFunctions.fCmdSetDepthBounds ||
274 NULL == fFunctions.fCmdSetStencilCompareMask ||
275 NULL == fFunctions.fCmdSetStencilWriteMask ||
276 NULL == fFunctions.fCmdSetStencilReference ||
277 NULL == fFunctions.fCmdBindDescriptorSets ||
278 NULL == fFunctions.fCmdBindIndexBuffer ||
279 NULL == fFunctions.fCmdBindVertexBuffers ||
280 NULL == fFunctions.fCmdDraw ||
281 NULL == fFunctions.fCmdDrawIndexed ||
282 NULL == fFunctions.fCmdDrawIndirect ||
283 NULL == fFunctions.fCmdDrawIndexedIndirect ||
284 NULL == fFunctions.fCmdDispatch ||
285 NULL == fFunctions.fCmdDispatchIndirect ||
286 NULL == fFunctions.fCmdCopyBuffer ||
287 NULL == fFunctions.fCmdCopyImage ||
288 NULL == fFunctions.fCmdBlitImage ||
289 NULL == fFunctions.fCmdCopyBufferToImage ||
290 NULL == fFunctions.fCmdCopyImageToBuffer ||
291 NULL == fFunctions.fCmdUpdateBuffer ||
292 NULL == fFunctions.fCmdFillBuffer ||
293 NULL == fFunctions.fCmdClearColorImage ||
294 NULL == fFunctions.fCmdClearDepthStencilImage ||
295 NULL == fFunctions.fCmdClearAttachments ||
296 NULL == fFunctions.fCmdResolveImage ||
297 NULL == fFunctions.fCmdSetEvent ||
298 NULL == fFunctions.fCmdResetEvent ||
299 NULL == fFunctions.fCmdWaitEvents ||
300 NULL == fFunctions.fCmdPipelineBarrier ||
301 NULL == fFunctions.fCmdBeginQuery ||
302 NULL == fFunctions.fCmdEndQuery ||
303 NULL == fFunctions.fCmdResetQueryPool ||
304 NULL == fFunctions.fCmdWriteTimestamp ||
305 NULL == fFunctions.fCmdCopyQueryPoolResults ||
306 NULL == fFunctions.fCmdPushConstants ||
307 NULL == fFunctions.fCmdBeginRenderPass ||
308 NULL == fFunctions.fCmdNextSubpass ||
309 NULL == fFunctions.fCmdEndRenderPass ||
jvanverthe50f3e72016-03-28 07:03:06 -0700310 NULL == fFunctions.fCmdExecuteCommands ||
jvanverthe50f3e72016-03-28 07:03:06 -0700311 NULL == fFunctions.fCreateDebugReportCallbackEXT ||
312 NULL == fFunctions.fDebugReportMessageEXT ||
313 NULL == fFunctions.fDestroyDebugReportCallbackEXT) {
314
Greg Daniel164a9f02016-02-22 09:56:40 -0500315 return false;
316 }
317 return true;
318}