@nonDispatchHandle type u64 VkFramebuffer
@nonDispatchHandle type u64 VkRenderPass
@nonDispatchHandle type u64 VkPipelineCache
+@nonDispatchHandle type u64 VkSwapchainKHR
/////////////
VK_DYNAMIC_STATE_STENCIL_REFERENCE = 0x00000008,
}
+//////////////////
+// Extensions //
+//////////////////
+
+@extension("VK_EXT_KHR_swapchain")
+enum VkSurfaceTransformKHR {
+ VK_SURFACE_TRANSFORM_NONE_KHR = 0x00000000,
+ VK_SURFACE_TRANSFORM_ROT90_KHR = 0x00000001,
+ VK_SURFACE_TRANSFORM_ROT180_KHR = 0x00000002,
+ VK_SURFACE_TRANSFORM_ROT270_KHR = 0x00000003,
+ VK_SURFACE_TRANSFORM_HMIRROR_KHR = 0x00000004,
+ VK_SURFACE_TRANSFORM_HMIRROR_ROT90_KHR = 0x00000005,
+ VK_SURFACE_TRANSFORM_HMIRROR_ROT180_KHR = 0x00000006,
+ VK_SURFACE_TRANSFORM_HMIRROR_ROT270_KHR = 0x00000007,
+ VK_SURFACE_TRANSFORM_INHERIT_KHR = 0x00000008,
+}
+
+@extension("VK_EXT_KHR_swapchain")
+enum VkPlatformKHR {
+ VK_PLATFORM_WIN32_KHR = 0x00000000,
+ VK_PLATFORM_X11_KHR = 0x00000001,
+ VK_PLATFORM_XCB_KHR = 0x00000002,
+ VK_PLATFORM_ANDROID_KHR = 0x00000003,
+ VK_PLATFORM_WAYLAND_KHR = 0x00000004,
+ VK_PLATFORM_MIR_KHR = 0x00000005,
+}
+
+@extension("VK_EXT_KHR_device_swapchain")
+enum VkPresentModeKHR {
+ VK_PRESENT_MODE_IMMEDIATE_KHR = 0x00000000,
+ VK_PRESENT_MODE_MAILBOX_KHR = 0x00000001,
+ VK_PRESENT_MODE_FIFO_KHR = 0x00000002,
+}
+
+@extension("VK_EXT_KHR_device_swapchain")
+enum VkColorSpaceKHR {
+ VK_COLORSPACE_SRGB_NONLINEAR_KHR = 0x00000000,
+}
/////////////////
// Bitfields //
VK_STENCIL_FACE_BACK_BIT = 0x00000002, /// Back face
}
+//////////////////
+// Extensions //
+//////////////////
+
+@extension("VK_EXT_KHR_swapchain")
+bitfield VkSurfaceTransformFlagsKHR {
+ VK_SURFACE_TRANSFORM_NONE_BIT_KHR = 0x00000001,
+ VK_SURFACE_TRANSFORM_ROT90_BIT_KHR = 0x00000002,
+ VK_SURFACE_TRANSFORM_ROT180_BIT_KHR = 0x00000004,
+ VK_SURFACE_TRANSFORM_ROT270_BIT_KHR = 0x00000008,
+ VK_SURFACE_TRANSFORM_HMIRROR_BIT_KHR = 0x00000010,
+ VK_SURFACE_TRANSFORM_HMIRROR_ROT90_BIT_KHR = 0x00000020,
+ VK_SURFACE_TRANSFORM_HMIRROR_ROT180_BIT_KHR = 0x00000040,
+ VK_SURFACE_TRANSFORM_HMIRROR_ROT270_BIT_KHR = 0x00000080,
+ VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR = 0x00000100,
+}
//////////////////
// Structures //
u32 z
}
+//////////////////
+// Extensions //
+//////////////////
+
+@extension("VK_EXT_KHR_device_swapchain")
+class VkSurfacePropertiesKHR {
+ u32 minImageCount
+ u32 maxImageCount
+ VkExtent2D currentExtent
+ VkExtent2D minImageExtent
+ VkExtent2D maxImageExtent
+ VkSurfaceTransformFlagsKHR supportedTransforms
+ VkSurfaceTransformKHR currentTransform
+ u32 maxImageArraySize
+ VkImageUsageFlags supportedUsageFlags
+}
+
+@extension("VK_EXT_KHR_device_swapchain")
+class VkSurfaceFormatKHR {
+ VkFormat format
+ VkColorSpaceKHR colorSpace
+}
+
+@extension("VK_EXT_KHR_device_swapchain")
+class VkSwapchainCreateInfoKHR {
+ VkStructureType sType
+ const void* pNext
+ const VkSurfaceDescriptionKHR* pSurfaceDescription
+ u32 minImageCount
+ VkFormat imageFormat
+ VkColorSpaceKHR imageColorSpace
+ VkExtent2D imageExtent
+ VkImageUsageFlags imageUsageFlags
+ VkSurfaceTransformKHR preTransform
+ u32 imageArraySize
+ VkSharingMode sharingMode
+ u32 queueFamilyCount
+ const u32* pQueueFamilyIndices
+ VkPresentModeKHR presentMode
+ VkSwapchainKHR oldSwapchain
+ VkBool32 clipped
+}
+
+@extension("VK_EXT_KHR_device_swapchain")
+class VkPresentInfoKHR {
+ VkStructureType sType
+ const void* pNext
+ u32 swapchainCount
+ const VkSwapchainKHR* swapchains
+ const u32* imageIndices
+}
+
+@extension("VK_EXT_KHR_swapchain")
+class VkSurfaceDescriptionKHR {
+ VkStructureType sType
+ const void* pNext
+}
+
+@extension("VK_EXT_KHR_swapchain")
+class VkSurfaceDescriptionWindowKHR {
+ VkStructureType sType
+ const void* pNext
+ VkPlatformKHR platform
+ void* pPlatformHandle
+ void* pPlatformWindow
+}
////////////////
// Commands //
}
}
+////////////////
+// Extensions //
+////////////////
+
+@extension("VK_EXT_KHR_device_swapchain")
+cmd VkResult vkGetSurfacePropertiesKHR(
+ VkDevice device,
+ const VkSurfaceDescriptionKHR* pSurfaceDescription,
+ VkSurfacePropertiesKHR* pSurfaceProperties) {
+ deviceObject := GetDevice(device)
+
+ surfaceProperties := ?
+ pSurfaceProperties[0] = surfaceProperties
+
+ return ?
+}
+
+@extension("VK_EXT_KHR_device_swapchain")
+cmd VkResult vkGetSurfaceFormatsKHR(
+ VkDevice device,
+ const VkSurfaceDescriptionKHR* pSurfaceDescription,
+ u32* pCount,
+ VkSurfaceFormatKHR* pSurfaceFormats) {
+ deviceObject := GetDevice(device)
+
+ count := as!u32(?)
+ pCount[0] = count
+ surfaceFormats := pSurfaceFormats[0:count]
+
+ for i in (0 .. count) {
+ surfaceFormat := ?
+ surfaceFormats[i] = surfaceFormat
+ }
+
+ return ?
+}
+
+@extension("VK_EXT_KHR_device_swapchain")
+cmd VkResult vkGetSurfacePresentModesKHR(
+ VkDevice device,
+ const VkSurfaceDescriptionKHR* pSurfaceDescription,
+ u32* pCount,
+ VkPresentModeKHR* pPresentModes) {
+ deviceObject := GetDevice(device)
+
+ count := as!u32(?)
+ pCount[0] = count
+ presentModes := pPresentModes[0:count]
+
+ for i in (0 .. count) {
+ presentMode := ?
+ presentModes[i] = presentMode
+ }
+
+ return ?
+}
+
+@extension("VK_EXT_KHR_device_swapchain")
+cmd VkResult vkCreateSwapchainKHR(
+ VkDevice device,
+ const VkSwapchainCreateInfoKHR* pCreateInfo,
+ VkSwapchainKHR* pSwapchain) {
+ //assert(pCreateInfo.sType == VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR)
+ deviceObject := GetDevice(device)
+
+ swapchain := ?
+ pSwapchain[0] = swapchain
+ State.Swapchains[swapchain] = new!SwapchainObject(device: device)
+
+ return ?
+}
+
+@extension("VK_EXT_KHR_device_swapchain")
+cmd VkResult vkDestroySwapchainKHR(
+ VkDevice device,
+ VkSwapchainKHR swapchain) {
+ deviceObject := GetDevice(device)
+ swapchainObject := GetSwapchain(swapchain)
+ assert(swapchainObject.device == device)
+
+ State.Swapchains[swapchain] = null
+
+ return ?
+}
+
+@extension("VK_EXT_KHR_device_swapchain")
+cmd VkResult vkGetSwapchainImagesKHR(
+ VkDevice device,
+ VkSwapchainKHR swapchain,
+ u32* pCount,
+ VkImage* pSwapchainImages) {
+ deviceObject := GetDevice(device)
+
+ count := as!u32(?)
+ pCount[0] = count
+ swapchainImages := pSwapchainImages[0:count]
+
+ for i in (0 .. count) {
+ swapchainImage := ?
+ swapchainImages[i] = swapchainImage
+ if !(swapchainImage in State.Images) {
+ State.Images[swapchainImage] = new!ImageObject(device: device)
+ }
+ }
+
+ return ?
+}
+
+@extension("VK_EXT_KHR_device_swapchain")
+cmd VkResult vkAcquireNextImageKHR(
+ VkDevice device,
+ VkSwapchainKHR swapchain,
+ u64 timeout,
+ VkSemaphore semaphore,
+ u32* pImageIndex) {
+ deviceObject := GetDevice(device)
+ swapchainObject := GetSwapchain(swapchain)
+
+ imageIndex := ?
+ pImageIndex[0] = imageIndex
+
+ return ?
+}
+
+@extension("VK_EXT_KHR_device_swapchain")
+cmd VkResult vkQueuePresentKHR(
+ VkQueue queue,
+ VkPresentInfoKHR* pPresentInfo) {
+ queueObject := GetQueue(queue)
+
+ presentInfo := ?
+ pPresentInfo[0] = presentInfo
+
+ return ?
+}
+
+@extension("VK_EXT_KHR_swapchain")
+cmd VkResult vkGetPhysicalDeviceSurfaceSupportKHR(
+ VkPhysicalDevice physicalDevice,
+ u32 queueFamilyIndex,
+ const VkSurfaceDescriptionKHR* pSurfaceDescription,
+ VkBool32* pSupported) {
+ physicalDeviceObject := GetPhysicalDevice(physicalDevice)
+
+ supported := ?
+ pSupported[0] = supported
+
+ return ?
+}
////////////////
// Validation //
map!(VkRenderPass, ref!RenderPassObject) RenderPasses
map!(VkPipelineCache, ref!PipelineCacheObject) PipelineCaches
map!(VkCmdPool, ref!CmdPoolObject) CmdPools
+ map!(VkSwapchainKHR, ref!SwapchainObject) Swapchains
}
@internal class InstanceObject {
VkDevice device
}
+@internal class SwapchainObject {
+ VkDevice device
+}
+
macro ref!InstanceObject GetInstance(VkInstance instance) {
assert(instance in State.Instances)
return State.Instances[instance]
assert(cmdPool in State.CmdPools)
return State.CmdPools[cmdPool]
}
+
+macro ref!SwapchainObject GetSwapchain(VkSwapchainKHR swapchain) {
+ assert(swapchain in State.Swapchains)
+ return State.Swapchains[swapchain]
+}
};
template <typename TEntry, size_t N>
-const TEntry* FindProcEntry(const TEntry(&table)[N], const char* name) {
+const TEntry* FindProcEntry(const TEntry (&table)[N], const char* name) {
auto entry = std::lower_bound(
table, table + N, name,
[](const TEntry& e, const char* n) { return strcmp(e.name, n) < 0; });
{"vkGetPhysicalDeviceProperties", reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceProperties)},
{"vkGetPhysicalDeviceQueueFamilyProperties", reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceQueueFamilyProperties)},
{"vkGetPhysicalDeviceSparseImageFormatProperties", reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSparseImageFormatProperties)},
+ {"vkGetPhysicalDeviceSurfaceSupportKHR", reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceSupportKHR)},
// clang-format on
};
const NameProcEntry kDeviceProcTbl[] = {
// clang-format off
+ {"vkAcquireNextImageKHR", reinterpret_cast<PFN_vkVoidFunction>(vkAcquireNextImageKHR)},
{"vkAllocDescriptorSets", reinterpret_cast<PFN_vkVoidFunction>(vkAllocDescriptorSets)},
{"vkAllocMemory", reinterpret_cast<PFN_vkVoidFunction>(vkAllocMemory)},
{"vkBeginCommandBuffer", reinterpret_cast<PFN_vkVoidFunction>(vkBeginCommandBuffer)},
{"vkCreateSemaphore", reinterpret_cast<PFN_vkVoidFunction>(vkCreateSemaphore)},
{"vkCreateShader", reinterpret_cast<PFN_vkVoidFunction>(vkCreateShader)},
{"vkCreateShaderModule", reinterpret_cast<PFN_vkVoidFunction>(vkCreateShaderModule)},
+ {"vkCreateSwapchainKHR", reinterpret_cast<PFN_vkVoidFunction>(vkCreateSwapchainKHR)},
{"vkDestroyBuffer", reinterpret_cast<PFN_vkVoidFunction>(vkDestroyBuffer)},
{"vkDestroyBufferView", reinterpret_cast<PFN_vkVoidFunction>(vkDestroyBufferView)},
{"vkDestroyCommandBuffer", reinterpret_cast<PFN_vkVoidFunction>(vkDestroyCommandBuffer)},
{"vkDestroySemaphore", reinterpret_cast<PFN_vkVoidFunction>(vkDestroySemaphore)},
{"vkDestroyShader", reinterpret_cast<PFN_vkVoidFunction>(vkDestroyShader)},
{"vkDestroyShaderModule", reinterpret_cast<PFN_vkVoidFunction>(vkDestroyShaderModule)},
+ {"vkDestroySwapchainKHR", reinterpret_cast<PFN_vkVoidFunction>(vkDestroySwapchainKHR)},
{"vkDeviceWaitIdle", reinterpret_cast<PFN_vkVoidFunction>(vkDeviceWaitIdle)},
{"vkEndCommandBuffer", reinterpret_cast<PFN_vkVoidFunction>(vkEndCommandBuffer)},
{"vkFlushMappedMemoryRanges", reinterpret_cast<PFN_vkVoidFunction>(vkFlushMappedMemoryRanges)},
{"vkGetPipelineCacheSize", reinterpret_cast<PFN_vkVoidFunction>(vkGetPipelineCacheSize)},
{"vkGetQueryPoolResults", reinterpret_cast<PFN_vkVoidFunction>(vkGetQueryPoolResults)},
{"vkGetRenderAreaGranularity", reinterpret_cast<PFN_vkVoidFunction>(vkGetRenderAreaGranularity)},
+ {"vkGetSurfaceFormatsKHR", reinterpret_cast<PFN_vkVoidFunction>(vkGetSurfaceFormatsKHR)},
+ {"vkGetSurfacePresentModesKHR", reinterpret_cast<PFN_vkVoidFunction>(vkGetSurfacePresentModesKHR)},
+ {"vkGetSurfacePropertiesKHR", reinterpret_cast<PFN_vkVoidFunction>(vkGetSurfacePropertiesKHR)},
+ {"vkGetSwapchainImagesKHR", reinterpret_cast<PFN_vkVoidFunction>(vkGetSwapchainImagesKHR)},
{"vkInvalidateMappedMemoryRanges", reinterpret_cast<PFN_vkVoidFunction>(vkInvalidateMappedMemoryRanges)},
{"vkMapMemory", reinterpret_cast<PFN_vkVoidFunction>(vkMapMemory)},
{"vkMergePipelineCaches", reinterpret_cast<PFN_vkVoidFunction>(vkMergePipelineCaches)},
{"vkQueueBindSparseBufferMemory", reinterpret_cast<PFN_vkVoidFunction>(vkQueueBindSparseBufferMemory)},
{"vkQueueBindSparseImageMemory", reinterpret_cast<PFN_vkVoidFunction>(vkQueueBindSparseImageMemory)},
{"vkQueueBindSparseImageOpaqueMemory", reinterpret_cast<PFN_vkVoidFunction>(vkQueueBindSparseImageOpaqueMemory)},
+ {"vkQueuePresentKHR", reinterpret_cast<PFN_vkVoidFunction>(vkQueuePresentKHR)},
{"vkQueueSignalSemaphore", reinterpret_cast<PFN_vkVoidFunction>(vkQueueSignalSemaphore)},
{"vkQueueSubmit", reinterpret_cast<PFN_vkVoidFunction>(vkQueueSubmit)},
{"vkQueueWaitIdle", reinterpret_cast<PFN_vkVoidFunction>(vkQueueWaitIdle)},
{"vkGetPhysicalDeviceProperties", offsetof(InstanceVtbl, GetPhysicalDeviceProperties)},
{"vkGetPhysicalDeviceQueueFamilyProperties", offsetof(InstanceVtbl, GetPhysicalDeviceQueueFamilyProperties)},
{"vkGetPhysicalDeviceSparseImageFormatProperties", offsetof(InstanceVtbl, GetPhysicalDeviceSparseImageFormatProperties)},
+ {"vkGetPhysicalDeviceSurfaceSupportKHR", offsetof(InstanceVtbl, GetPhysicalDeviceSurfaceSupportKHR)},
// clang-format on
};
const NameOffsetEntry kDeviceOffsetTbl[] = {
// clang-format off
+ {"vkAcquireNextImageKHR", offsetof(DeviceVtbl, AcquireNextImageKHR)},
{"vkAllocDescriptorSets", offsetof(DeviceVtbl, AllocDescriptorSets)},
{"vkAllocMemory", offsetof(DeviceVtbl, AllocMemory)},
{"vkBeginCommandBuffer", offsetof(DeviceVtbl, BeginCommandBuffer)},
{"vkCreateSemaphore", offsetof(DeviceVtbl, CreateSemaphore)},
{"vkCreateShader", offsetof(DeviceVtbl, CreateShader)},
{"vkCreateShaderModule", offsetof(DeviceVtbl, CreateShaderModule)},
+ {"vkCreateSwapchainKHR", offsetof(DeviceVtbl, CreateSwapchainKHR)},
{"vkDestroyBuffer", offsetof(DeviceVtbl, DestroyBuffer)},
{"vkDestroyBufferView", offsetof(DeviceVtbl, DestroyBufferView)},
{"vkDestroyCommandBuffer", offsetof(DeviceVtbl, DestroyCommandBuffer)},
{"vkDestroySemaphore", offsetof(DeviceVtbl, DestroySemaphore)},
{"vkDestroyShader", offsetof(DeviceVtbl, DestroyShader)},
{"vkDestroyShaderModule", offsetof(DeviceVtbl, DestroyShaderModule)},
+ {"vkDestroySwapchainKHR", offsetof(DeviceVtbl, DestroySwapchainKHR)},
{"vkDeviceWaitIdle", offsetof(DeviceVtbl, DeviceWaitIdle)},
{"vkEndCommandBuffer", offsetof(DeviceVtbl, EndCommandBuffer)},
{"vkFlushMappedMemoryRanges", offsetof(DeviceVtbl, FlushMappedMemoryRanges)},
{"vkGetPipelineCacheSize", offsetof(DeviceVtbl, GetPipelineCacheSize)},
{"vkGetQueryPoolResults", offsetof(DeviceVtbl, GetQueryPoolResults)},
{"vkGetRenderAreaGranularity", offsetof(DeviceVtbl, GetRenderAreaGranularity)},
+ {"vkGetSurfaceFormatsKHR", offsetof(DeviceVtbl, GetSurfaceFormatsKHR)},
+ {"vkGetSurfacePresentModesKHR", offsetof(DeviceVtbl, GetSurfacePresentModesKHR)},
+ {"vkGetSurfacePropertiesKHR", offsetof(DeviceVtbl, GetSurfacePropertiesKHR)},
+ {"vkGetSwapchainImagesKHR", offsetof(DeviceVtbl, GetSwapchainImagesKHR)},
{"vkInvalidateMappedMemoryRanges", offsetof(DeviceVtbl, InvalidateMappedMemoryRanges)},
{"vkMapMemory", offsetof(DeviceVtbl, MapMemory)},
{"vkMergePipelineCaches", offsetof(DeviceVtbl, MergePipelineCaches)},
{"vkQueueBindSparseBufferMemory", offsetof(DeviceVtbl, QueueBindSparseBufferMemory)},
{"vkQueueBindSparseImageMemory", offsetof(DeviceVtbl, QueueBindSparseImageMemory)},
{"vkQueueBindSparseImageOpaqueMemory", offsetof(DeviceVtbl, QueueBindSparseImageOpaqueMemory)},
+ {"vkQueuePresentKHR", offsetof(DeviceVtbl, QueuePresentKHR)},
{"vkQueueSignalSemaphore", offsetof(DeviceVtbl, QueueSignalSemaphore)},
{"vkQueueSubmit", offsetof(DeviceVtbl, QueueSubmit)},
{"vkQueueWaitIdle", offsetof(DeviceVtbl, QueueWaitIdle)},
// bootstrapping
if (strcmp(name, "vkGetDeviceProcAddr") == 0)
return reinterpret_cast<PFN_vkVoidFunction>(vkGetDeviceProcAddr);
- // special-case extension functions until they can be auto-generated
- if (strcmp(name, "vkGetPhysicalDeviceSurfaceSupportKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(
- vkGetPhysicalDeviceSurfaceSupportKHR);
return nullptr;
}
const NameProcEntry* entry = FindProcEntry(kDeviceProcTbl, name);
if (entry)
return entry->proc;
- // special-case extension functions until they can be auto-generated
- if (strcmp(name, "vkGetSurfacePropertiesKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkGetSurfacePropertiesKHR);
- if (strcmp(name, "vkGetSurfaceFormatsKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkGetSurfaceFormatsKHR);
- if (strcmp(name, "vkGetSurfacePresentModesKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(
- vkGetSurfacePresentModesKHR);
- if (strcmp(name, "vkCreateSwapchainKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkCreateSwapchainKHR);
- if (strcmp(name, "vkDestroySwapchainKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySwapchainKHR);
- if (strcmp(name, "vkGetSwapchainImagesKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkGetSwapchainImagesKHR);
- if (strcmp(name, "vkAcquireNextImageKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkAcquireNextImageKHR);
- if (strcmp(name, "vkQueuePresentKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkQueuePresentKHR);
return nullptr;
}
const NameOffsetEntry* entry = FindProcEntry(kInstanceOffsetTbl, name);
if (entry)
offset = entry->offset;
- else if (strcmp(name, "vkGetPhysicalDeviceSurfaceSupportKHR") == 0)
- offset = offsetof(InstanceVtbl, GetPhysicalDeviceSurfaceSupportKHR);
else
return nullptr;
const unsigned char* base = reinterpret_cast<const unsigned char*>(vtbl);
return *reinterpret_cast<PFN_vkVoidFunction*>(
- const_cast<unsigned char*>(base) + offset);
+ const_cast<unsigned char*>(base) + offset);
}
PFN_vkVoidFunction GetSpecificDeviceProcAddr(const DeviceVtbl* vtbl,
const NameOffsetEntry* entry = FindProcEntry(kDeviceOffsetTbl, name);
if (entry)
offset = entry->offset;
- else if (strcmp(name, "vkGetSurfacePropertiesKHR") == 0)
- offset = offsetof(DeviceVtbl, GetSurfacePropertiesKHR);
- else if (strcmp(name, "vkGetSurfaceFormatsKHR") == 0)
- offset = offsetof(DeviceVtbl, GetSurfaceFormatsKHR);
- else if (strcmp(name, "vkGetSurfacePresentModesKHR") == 0)
- offset = offsetof(DeviceVtbl, GetSurfacePresentModesKHR);
- else if (strcmp(name, "vkCreateSwapchainKHR") == 0)
- offset = offsetof(DeviceVtbl, CreateSwapchainKHR);
- else if (strcmp(name, "vkDestroySwapchainKHR") == 0)
- offset = offsetof(DeviceVtbl, DestroySwapchainKHR);
- else if (strcmp(name, "vkGetSwapchainImagesKHR") == 0)
- offset = offsetof(DeviceVtbl, GetSwapchainImagesKHR);
- else if (strcmp(name, "vkAcquireNextImageKHR") == 0)
- offset = offsetof(DeviceVtbl, AcquireNextImageKHR);
- else if (strcmp(name, "vkQueuePresentKHR") == 0)
- offset = offsetof(DeviceVtbl, QueuePresentKHR);
else
return nullptr;
const unsigned char* base = reinterpret_cast<const unsigned char*>(vtbl);
return *reinterpret_cast<PFN_vkVoidFunction*>(
- const_cast<unsigned char*>(base) + offset);
+ const_cast<unsigned char*>(base) + offset);
}
bool LoadInstanceVtbl(VkInstance instance,
ALOGE("missing instance proc: %s", "vkGetPhysicalDeviceSparseImageFormatProperties");
success = false;
}
+ vtbl.GetPhysicalDeviceSurfaceSupportKHR = reinterpret_cast<PFN_vkGetPhysicalDeviceSurfaceSupportKHR>(get_proc_addr(instance, "vkGetPhysicalDeviceSurfaceSupportKHR"));
// clang-format on
return success;
}
ALOGE("missing device proc: %s", "vkCmdExecuteCommands");
success = false;
}
+ vtbl.GetSurfacePropertiesKHR = reinterpret_cast<PFN_vkGetSurfacePropertiesKHR>(get_proc_addr(device, "vkGetSurfacePropertiesKHR"));
+ if (UNLIKELY(!vtbl.GetSurfacePropertiesKHR)) {
+ ALOGE("missing device proc: %s", "vkGetSurfacePropertiesKHR");
+ success = false;
+ }
+ vtbl.GetSurfaceFormatsKHR = reinterpret_cast<PFN_vkGetSurfaceFormatsKHR>(get_proc_addr(device, "vkGetSurfaceFormatsKHR"));
+ if (UNLIKELY(!vtbl.GetSurfaceFormatsKHR)) {
+ ALOGE("missing device proc: %s", "vkGetSurfaceFormatsKHR");
+ success = false;
+ }
+ vtbl.GetSurfacePresentModesKHR = reinterpret_cast<PFN_vkGetSurfacePresentModesKHR>(get_proc_addr(device, "vkGetSurfacePresentModesKHR"));
+ if (UNLIKELY(!vtbl.GetSurfacePresentModesKHR)) {
+ ALOGE("missing device proc: %s", "vkGetSurfacePresentModesKHR");
+ success = false;
+ }
+ vtbl.CreateSwapchainKHR = reinterpret_cast<PFN_vkCreateSwapchainKHR>(get_proc_addr(device, "vkCreateSwapchainKHR"));
+ if (UNLIKELY(!vtbl.CreateSwapchainKHR)) {
+ ALOGE("missing device proc: %s", "vkCreateSwapchainKHR");
+ success = false;
+ }
+ vtbl.DestroySwapchainKHR = reinterpret_cast<PFN_vkDestroySwapchainKHR>(get_proc_addr(device, "vkDestroySwapchainKHR"));
+ if (UNLIKELY(!vtbl.DestroySwapchainKHR)) {
+ ALOGE("missing device proc: %s", "vkDestroySwapchainKHR");
+ success = false;
+ }
+ vtbl.GetSwapchainImagesKHR = reinterpret_cast<PFN_vkGetSwapchainImagesKHR>(get_proc_addr(device, "vkGetSwapchainImagesKHR"));
+ if (UNLIKELY(!vtbl.GetSwapchainImagesKHR)) {
+ ALOGE("missing device proc: %s", "vkGetSwapchainImagesKHR");
+ success = false;
+ }
+ vtbl.AcquireNextImageKHR = reinterpret_cast<PFN_vkAcquireNextImageKHR>(get_proc_addr(device, "vkAcquireNextImageKHR"));
+ if (UNLIKELY(!vtbl.AcquireNextImageKHR)) {
+ ALOGE("missing device proc: %s", "vkAcquireNextImageKHR");
+ success = false;
+ }
+ vtbl.QueuePresentKHR = reinterpret_cast<PFN_vkQueuePresentKHR>(get_proc_addr(device, "vkQueuePresentKHR"));
+ if (UNLIKELY(!vtbl.QueuePresentKHR)) {
+ ALOGE("missing device proc: %s", "vkQueuePresentKHR");
+ success = false;
+ }
vtbl.GetSwapchainGrallocUsageANDROID = reinterpret_cast<PFN_vkGetSwapchainGrallocUsageANDROID>(get_proc_addr(device, "vkGetSwapchainGrallocUsageANDROID"));
if (UNLIKELY(!vtbl.GetSwapchainGrallocUsageANDROID)) {
// TODO(jessehall): temporarily make this optional, until drivers have been updated
};
¶
template <typename TEntry, size_t N>
-const TEntry* FindProcEntry(const TEntry(&table)[N], const char* name) {
+const TEntry* FindProcEntry(const TEntry (&table)[N], const char* name) {
auto entry = std::lower_bound(
table, table + N, name,
[](const TEntry& e, const char* n) { return strcmp(e.name, n) < 0; });
// vkGetDeviceProcAddr must be available at the global/instance level for bootstrapping
if (strcmp(name, "vkGetDeviceProcAddr") == 0)
return reinterpret_cast<PFN_vkVoidFunction>(vkGetDeviceProcAddr);
- // special-case extension functions until they can be auto-generated
- if (strcmp(name, "vkGetPhysicalDeviceSurfaceSupportKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkGetPhysicalDeviceSurfaceSupportKHR);
return nullptr;
}
¶
const NameProcEntry* entry = FindProcEntry(kDeviceProcTbl, name);
if (entry)
return entry->proc;
- // special-case extension functions until they can be auto-generated
- if (strcmp(name, "vkGetSurfacePropertiesKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkGetSurfacePropertiesKHR);
- if (strcmp(name, "vkGetSurfaceFormatsKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkGetSurfaceFormatsKHR);
- if (strcmp(name, "vkGetSurfacePresentModesKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkGetSurfacePresentModesKHR);
- if (strcmp(name, "vkCreateSwapchainKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkCreateSwapchainKHR);
- if (strcmp(name, "vkDestroySwapchainKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkDestroySwapchainKHR);
- if (strcmp(name, "vkGetSwapchainImagesKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkGetSwapchainImagesKHR);
- if (strcmp(name, "vkAcquireNextImageKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkAcquireNextImageKHR);
- if (strcmp(name, "vkQueuePresentKHR") == 0)
- return reinterpret_cast<PFN_vkVoidFunction>(vkQueuePresentKHR);
return nullptr;
}
¶
const NameOffsetEntry* entry = FindProcEntry(kInstanceOffsetTbl, name);
if (entry)
offset = entry->offset;
- else if (strcmp(name, "vkGetPhysicalDeviceSurfaceSupportKHR") == 0)
- offset = offsetof(InstanceVtbl, GetPhysicalDeviceSurfaceSupportKHR);
else
return nullptr;
const unsigned char* base = reinterpret_cast<const unsigned char*>(vtbl);
const NameOffsetEntry* entry = FindProcEntry(kDeviceOffsetTbl, name);
if (entry)
offset = entry->offset;
- else if (strcmp(name, "vkGetSurfacePropertiesKHR") == 0)
- offset = offsetof(DeviceVtbl, GetSurfacePropertiesKHR);
- else if (strcmp(name, "vkGetSurfaceFormatsKHR") == 0)
- offset = offsetof(DeviceVtbl, GetSurfaceFormatsKHR);
- else if (strcmp(name, "vkGetSurfacePresentModesKHR") == 0)
- offset = offsetof(DeviceVtbl, GetSurfacePresentModesKHR);
- else if (strcmp(name, "vkCreateSwapchainKHR") == 0)
- offset = offsetof(DeviceVtbl, CreateSwapchainKHR);
- else if (strcmp(name, "vkDestroySwapchainKHR") == 0)
- offset = offsetof(DeviceVtbl, DestroySwapchainKHR);
- else if (strcmp(name, "vkGetSwapchainImagesKHR") == 0)
- offset = offsetof(DeviceVtbl, GetSwapchainImagesKHR);
- else if (strcmp(name, "vkAcquireNextImageKHR") == 0)
- offset = offsetof(DeviceVtbl, AcquireNextImageKHR);
- else if (strcmp(name, "vkQueuePresentKHR") == 0)
- offset = offsetof(DeviceVtbl, QueuePresentKHR);
else
return nullptr;
const unsigned char* base = reinterpret_cast<const unsigned char*>(vtbl);
{{range $f := AllCommands $}}
{{if eq (Macro "Vtbl" $f) "Instance"}}
{{if not (eq (Macro "FunctionName" $f) "vkGetInstanceProcAddr")}}
+ {{if not (GetAnnotation $f "extension")}}
vtbl.{{TrimPrefix "vk" (Macro "FunctionName" $f)}} = §
reinterpret_cast<{{Macro "FunctionPtrName" $f}}>(§
get_proc_addr(instance, "{{Macro "FunctionName" $f}}"));
ALOGE("missing instance proc: %s", "{{Macro "FunctionName" $f}}");
success = false;
}
+ {{end}}
+ {{end}}
+ {{end}}
+ {{end}}
+ {{range $f := AllCommands $}}
+ {{if eq (Macro "Vtbl" $f) "Instance"}}
+ {{if (GetAnnotation $f "extension")}}
+ vtbl.{{TrimPrefix "vk" (Macro "FunctionName" $f)}} = §
+ reinterpret_cast<{{Macro "FunctionPtrName" $f}}>(§
+ get_proc_addr(instance, "{{Macro "FunctionName" $f}}"));
{{end}}
{{end}}
{{end}}
if (strcmp(name, "vkCreateDevice") == 0) {
return reinterpret_cast<PFN_vkVoidFunction>(Noop);
}
+ // WSI extensions are not in the driver so return the loader functions
+ if (strcmp(name, "vkGetSurfacePropertiesKHR") == 0) {
+ return reinterpret_cast<PFN_vkVoidFunction>(GetSurfacePropertiesKHR);
+ }
+ if (strcmp(name, "vkGetSurfaceFormatsKHR") == 0) {
+ return reinterpret_cast<PFN_vkVoidFunction>(GetSurfaceFormatsKHR);
+ }
+ if (strcmp(name, "vkGetSurfacePresentModesKHR") == 0) {
+ return reinterpret_cast<PFN_vkVoidFunction>(GetSurfacePresentModesKHR);
+ }
+ if (strcmp(name, "vkCreateSwapchainKHR") == 0) {
+ return reinterpret_cast<PFN_vkVoidFunction>(CreateSwapchainKHR);
+ }
+ if (strcmp(name, "vkDestroySwapchainKHR") == 0) {
+ return reinterpret_cast<PFN_vkVoidFunction>(DestroySwapchainKHR);
+ }
+ if (strcmp(name, "vkGetSwapchainImagesKHR") == 0) {
+ return reinterpret_cast<PFN_vkVoidFunction>(GetSwapchainImagesKHR);
+ }
+ if (strcmp(name, "vkAcquireNextImageKHR") == 0) {
+ return reinterpret_cast<PFN_vkVoidFunction>(AcquireNextImageKHR);
+ }
+ if (strcmp(name, "vkQueuePresentKHR") == 0) {
+ return reinterpret_cast<PFN_vkVoidFunction>(QueuePresentKHR);
+ }
if (!device)
return GetGlobalDeviceProcAddr(name);
Device* loader_device = reinterpret_cast<Device*>(GetVtbl(device)->device);
}
dispatch->vtbl = &device->vtbl_storage;
- device->vtbl_storage.GetSurfacePropertiesKHR = GetSurfacePropertiesKHR;
- device->vtbl_storage.GetSurfaceFormatsKHR = GetSurfaceFormatsKHR;
- device->vtbl_storage.GetSurfacePresentModesKHR = GetSurfacePresentModesKHR;
- device->vtbl_storage.CreateSwapchainKHR = CreateSwapchainKHR;
- device->vtbl_storage.DestroySwapchainKHR = DestroySwapchainKHR;
- device->vtbl_storage.GetSwapchainImagesKHR = GetSwapchainImagesKHR;
- device->vtbl_storage.AcquireNextImageKHR = AcquireNextImageKHR;
- device->vtbl_storage.QueuePresentKHR = QueuePresentKHR;
-
void* base_object = static_cast<void*>(drv_device);
void* next_object = base_object;
VkLayerLinkedListElem* next_element;
"vkCreateDevice"));
layer_createDevice(pdev, create_info, &drv_device);
+ // TODO(mlentine) : This is needed to use WSI layer validation. Remove this
+ // when new version of layer initialization exits.
+ if (!LoadDeviceVtbl(static_cast<VkDevice>(base_object),
+ static_cast<VkDevice>(next_object), next_get_proc_addr,
+ device->vtbl_storage)) {
+ DestroyDevice(device);
+ return VK_ERROR_INITIALIZATION_FAILED;
+ }
+
*out_device = drv_device;
return VK_SUCCESS;
}