blob: bb0991943bd35c8af967c84a939318a216bc6711 [file] [log] [blame]
/*
* Copyright (c) 2015-2019 The Khronos Group Inc.
* Copyright (c) 2015-2019 Valve Corporation
* Copyright (c) 2015-2019 LunarG, 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.
*
* Author: Courtney Goeltzenleuchter <courtney@LunarG.com>
* Author: David Pinedo <david@lunarg.com>
* Author: Mark Lobodzinski <mark@lunarg.com>
* Author: Rene Lindsay <rene@lunarg.com>
* Author: Jeremy Kniager <jeremyk@lunarg.com>
* Author: Shannon McPherson <shannon@lunarg.com>
* Author: Bob Ellison <bob@lunarg.com>
*/
#ifdef __GNUC__
#ifndef _POSIX_C_SOURCE
#define _POSIX_C_SOURCE 200809L
#endif
#else
#define strndup(p, n) strdup(p)
#endif
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <fcntl.h>
#include <io.h>
#endif // _WIN32
#if defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_XCB_KHR)
#include <X11/Xutil.h>
#endif
#if defined(VK_USE_PLATFORM_MACOS_MVK)
#include "metal_view.h"
#endif
#include <vulkan/vulkan.h>
#define ERR(err) fprintf(stderr, "%s:%d: failed with %s\n", __FILE__, __LINE__, VkResultString(err));
#ifdef _WIN32
#define strdup _strdup
// Returns nonzero if the console is used only for this process. Will return
// zero if another process (such as cmd.exe) is also attached.
static int ConsoleIsExclusive(void) {
DWORD pids[2];
DWORD num_pids = GetConsoleProcessList(pids, ARRAYSIZE(pids));
return num_pids <= 1;
}
#define WAIT_FOR_CONSOLE_DESTROY \
do { \
if (ConsoleIsExclusive()) Sleep(INFINITE); \
} while (0)
#else
#define WAIT_FOR_CONSOLE_DESTROY
#endif
#define ERR_EXIT(err) \
do { \
ERR(err); \
fflush(stdout); \
fflush(stderr); \
WAIT_FOR_CONSOLE_DESTROY; \
exit(-1); \
} while (0)
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#define MAX_QUEUE_TYPES 5
#define APP_SHORT_NAME "vulkaninfo"
static bool html_output = false;
static bool human_readable_output = true;
static bool json_output = false;
static uint32_t selected_gpu = 0;
struct VkStructureHeader {
VkStructureType sType;
void *pNext;
};
struct pNextChainBuildingBlockInfo {
VkStructureType sType;
uint32_t mem_size;
};
struct LayerExtensionList {
VkLayerProperties layer_properties;
uint32_t extension_count;
VkExtensionProperties *extension_properties;
};
struct AppInstance;
struct SurfaceExtensionNode {
struct SurfaceExtensionNode *next;
const char *name;
void (*create_window)(struct AppInstance *);
VkSurfaceKHR (*create_surface)(struct AppInstance *);
void (*destroy_window)(struct AppInstance *);
VkSurfaceKHR surface;
VkBool32 supports_present;
};
struct AppInstance {
VkInstance instance;
uint32_t instance_version;
uint32_t vulkan_major;
uint32_t vulkan_minor;
uint32_t vulkan_patch;
uint32_t global_layer_count;
struct LayerExtensionList *global_layers;
uint32_t global_extension_count;
VkExtensionProperties *global_extensions; // Instance Extensions
const char **inst_extensions;
uint32_t inst_extensions_count;
// Functions from vkGetInstanceProcAddress
PFN_vkGetPhysicalDeviceSurfaceSupportKHR vkGetPhysicalDeviceSurfaceSupportKHR;
PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR vkGetPhysicalDeviceSurfaceCapabilitiesKHR;
PFN_vkGetPhysicalDeviceSurfaceFormatsKHR vkGetPhysicalDeviceSurfaceFormatsKHR;
PFN_vkGetPhysicalDeviceSurfaceFormats2KHR vkGetPhysicalDeviceSurfaceFormats2KHR;
PFN_vkGetPhysicalDeviceSurfacePresentModesKHR vkGetPhysicalDeviceSurfacePresentModesKHR;
PFN_vkGetPhysicalDeviceProperties2KHR vkGetPhysicalDeviceProperties2KHR;
PFN_vkGetPhysicalDeviceFormatProperties2KHR vkGetPhysicalDeviceFormatProperties2KHR;
PFN_vkGetPhysicalDeviceQueueFamilyProperties2KHR vkGetPhysicalDeviceQueueFamilyProperties2KHR;
PFN_vkGetPhysicalDeviceFeatures2KHR vkGetPhysicalDeviceFeatures2KHR;
PFN_vkGetPhysicalDeviceMemoryProperties2KHR vkGetPhysicalDeviceMemoryProperties2KHR;
PFN_vkGetPhysicalDeviceSurfaceCapabilities2KHR vkGetPhysicalDeviceSurfaceCapabilities2KHR;
PFN_vkGetPhysicalDeviceSurfaceCapabilities2EXT vkGetPhysicalDeviceSurfaceCapabilities2EXT;
struct SurfaceExtensionNode *surface_ext_infos_root;
int width, height;
#ifdef VK_USE_PLATFORM_WIN32_KHR
HINSTANCE h_instance; // Windows Instance
HWND h_wnd; // window handle
#endif
#ifdef VK_USE_PLATFORM_XCB_KHR
xcb_connection_t *xcb_connection;
xcb_screen_t *xcb_screen;
xcb_window_t xcb_window;
#endif
#ifdef VK_USE_PLATFORM_XLIB_KHR
Display *xlib_display;
Window xlib_window;
#endif
#ifdef VK_USE_PLATFORM_ANDROID_KHR // TODO
struct ANativeWindow *window;
#endif
#ifdef VK_USE_PLATFORM_MACOS_MVK
void *window;
#endif
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
struct wl_display *wayland_display;
struct wl_surface *wayland_surface;
#endif
};
struct MemResSupport {
struct MemImageSupport {
bool regular_supported, sparse_supported, transient_supported;
VkFormat format;
uint32_t regular_memtypes, sparse_memtypes, transient_memtypes;
} image[2][1 + 7];
// TODO: buffers
};
struct AppGpu {
uint32_t id;
VkPhysicalDevice obj;
VkPhysicalDeviceProperties props;
VkPhysicalDeviceProperties2KHR props2;
uint32_t queue_count;
VkQueueFamilyProperties *queue_props;
VkQueueFamilyProperties2KHR *queue_props2;
VkDeviceQueueCreateInfo *queue_reqs;
struct AppInstance *inst;
VkPhysicalDeviceMemoryProperties memory_props;
VkPhysicalDeviceMemoryProperties2KHR memory_props2;
struct MemResSupport mem_type_res_support;
VkPhysicalDeviceFeatures features;
VkPhysicalDeviceFeatures2KHR features2;
VkPhysicalDevice limits;
uint32_t device_extension_count;
VkExtensionProperties *device_extensions;
VkDevice dev;
VkPhysicalDeviceFeatures enabled_features;
};
// return most severe flag only
static const char *DebugReportFlagString(const VkDebugReportFlagsEXT flags) {
switch (flags) {
case VK_DEBUG_REPORT_ERROR_BIT_EXT:
return "ERROR";
case VK_DEBUG_REPORT_WARNING_BIT_EXT:
return "WARNING";
case VK_DEBUG_REPORT_PERFORMANCE_WARNING_BIT_EXT:
return "PERF";
case VK_DEBUG_REPORT_INFORMATION_BIT_EXT:
return "INFO";
case VK_DEBUG_REPORT_DEBUG_BIT_EXT:
return "DEBUG";
default:
return "UNKNOWN";
}
}
static VKAPI_ATTR VkBool32 VKAPI_CALL DbgCallback(VkDebugReportFlagsEXT msgFlags, VkDebugReportObjectTypeEXT objType,
uint64_t srcObject, size_t location, int32_t msgCode, const char *pLayerPrefix,
const char *pMsg, void *pUserData) {
fprintf(stderr, "%s: [%s] Code %d : %s\n", DebugReportFlagString(msgFlags), pLayerPrefix, msgCode, pMsg);
fflush(stderr);
// True is reserved for layer developers, and MAY mean calls are not distributed down the layer chain after validation error.
// False SHOULD always be returned by apps:
return VK_FALSE;
}
static const char *VkResultString(VkResult err) {
switch (err) {
#define STR(r) \
case r: \
return #r
STR(VK_SUCCESS);
STR(VK_NOT_READY);
STR(VK_TIMEOUT);
STR(VK_EVENT_SET);
STR(VK_EVENT_RESET);
STR(VK_INCOMPLETE);
STR(VK_ERROR_OUT_OF_HOST_MEMORY);
STR(VK_ERROR_OUT_OF_DEVICE_MEMORY);
STR(VK_ERROR_INITIALIZATION_FAILED);
STR(VK_ERROR_DEVICE_LOST);
STR(VK_ERROR_MEMORY_MAP_FAILED);
STR(VK_ERROR_LAYER_NOT_PRESENT);
STR(VK_ERROR_EXTENSION_NOT_PRESENT);
STR(VK_ERROR_FEATURE_NOT_PRESENT);
STR(VK_ERROR_INCOMPATIBLE_DRIVER);
STR(VK_ERROR_TOO_MANY_OBJECTS);
STR(VK_ERROR_FORMAT_NOT_SUPPORTED);
STR(VK_ERROR_FRAGMENTED_POOL);
STR(VK_ERROR_OUT_OF_POOL_MEMORY);
STR(VK_ERROR_INVALID_EXTERNAL_HANDLE);
STR(VK_ERROR_SURFACE_LOST_KHR);
STR(VK_ERROR_NATIVE_WINDOW_IN_USE_KHR);
STR(VK_SUBOPTIMAL_KHR);
STR(VK_ERROR_OUT_OF_DATE_KHR);
STR(VK_ERROR_INCOMPATIBLE_DISPLAY_KHR);
STR(VK_ERROR_VALIDATION_FAILED_EXT);
STR(VK_ERROR_INVALID_SHADER_NV);
STR(VK_ERROR_INVALID_DRM_FORMAT_MODIFIER_PLANE_LAYOUT_EXT);
STR(VK_ERROR_FRAGMENTATION_EXT);
STR(VK_ERROR_NOT_PERMITTED_EXT);
#undef STR
default:
return "UNKNOWN_RESULT";
}
}
static const char *VkPhysicalDeviceTypeString(VkPhysicalDeviceType type) {
switch (type) {
#define STR(r) \
case VK_PHYSICAL_DEVICE_TYPE_##r: \
return #r
STR(OTHER);
STR(INTEGRATED_GPU);
STR(DISCRETE_GPU);
STR(VIRTUAL_GPU);
STR(CPU);
#undef STR
default:
return "UNKNOWN_DEVICE";
}
}
static const char *VkTilingString(const VkImageTiling tiling) {
switch (tiling) {
#define STR(r) \
case VK_IMAGE_TILING_##r: \
return #r
STR(OPTIMAL);
STR(LINEAR);
STR(DRM_FORMAT_MODIFIER_EXT);
#undef STR
default:
return "UNKNOWN_TILING";
}
}
static const char *VkFormatString(VkFormat fmt) {
switch (fmt) {
#define STR(r) \
case VK_FORMAT_##r: \
return #r
STR(UNDEFINED);
STR(R4G4_UNORM_PACK8);
STR(R4G4B4A4_UNORM_PACK16);
STR(B4G4R4A4_UNORM_PACK16);
STR(R5G6B5_UNORM_PACK16);
STR(B5G6R5_UNORM_PACK16);
STR(R5G5B5A1_UNORM_PACK16);
STR(B5G5R5A1_UNORM_PACK16);
STR(A1R5G5B5_UNORM_PACK16);
STR(R8_UNORM);
STR(R8_SNORM);
STR(R8_USCALED);
STR(R8_SSCALED);
STR(R8_UINT);
STR(R8_SINT);
STR(R8_SRGB);
STR(R8G8_UNORM);
STR(R8G8_SNORM);
STR(R8G8_USCALED);
STR(R8G8_SSCALED);
STR(R8G8_UINT);
STR(R8G8_SINT);
STR(R8G8_SRGB);
STR(R8G8B8_UNORM);
STR(R8G8B8_SNORM);
STR(R8G8B8_USCALED);
STR(R8G8B8_SSCALED);
STR(R8G8B8_UINT);
STR(R8G8B8_SINT);
STR(R8G8B8_SRGB);
STR(B8G8R8_UNORM);
STR(B8G8R8_SNORM);
STR(B8G8R8_USCALED);
STR(B8G8R8_SSCALED);
STR(B8G8R8_UINT);
STR(B8G8R8_SINT);
STR(B8G8R8_SRGB);
STR(R8G8B8A8_UNORM);
STR(R8G8B8A8_SNORM);
STR(R8G8B8A8_USCALED);
STR(R8G8B8A8_SSCALED);
STR(R8G8B8A8_UINT);
STR(R8G8B8A8_SINT);
STR(R8G8B8A8_SRGB);
STR(B8G8R8A8_UNORM);
STR(B8G8R8A8_SNORM);
STR(B8G8R8A8_USCALED);
STR(B8G8R8A8_SSCALED);
STR(B8G8R8A8_UINT);
STR(B8G8R8A8_SINT);
STR(B8G8R8A8_SRGB);
STR(A8B8G8R8_UNORM_PACK32);
STR(A8B8G8R8_SNORM_PACK32);
STR(A8B8G8R8_USCALED_PACK32);
STR(A8B8G8R8_SSCALED_PACK32);
STR(A8B8G8R8_UINT_PACK32);
STR(A8B8G8R8_SINT_PACK32);
STR(A8B8G8R8_SRGB_PACK32);
STR(A2R10G10B10_UNORM_PACK32);
STR(A2R10G10B10_SNORM_PACK32);
STR(A2R10G10B10_USCALED_PACK32);
STR(A2R10G10B10_SSCALED_PACK32);
STR(A2R10G10B10_UINT_PACK32);
STR(A2R10G10B10_SINT_PACK32);
STR(A2B10G10R10_UNORM_PACK32);
STR(A2B10G10R10_SNORM_PACK32);
STR(A2B10G10R10_USCALED_PACK32);
STR(A2B10G10R10_SSCALED_PACK32);
STR(A2B10G10R10_UINT_PACK32);
STR(A2B10G10R10_SINT_PACK32);
STR(R16_UNORM);
STR(R16_SNORM);
STR(R16_USCALED);
STR(R16_SSCALED);
STR(R16_UINT);
STR(R16_SINT);
STR(R16_SFLOAT);
STR(R16G16_UNORM);
STR(R16G16_SNORM);
STR(R16G16_USCALED);
STR(R16G16_SSCALED);
STR(R16G16_UINT);
STR(R16G16_SINT);
STR(R16G16_SFLOAT);
STR(R16G16B16_UNORM);
STR(R16G16B16_SNORM);
STR(R16G16B16_USCALED);
STR(R16G16B16_SSCALED);
STR(R16G16B16_UINT);
STR(R16G16B16_SINT);
STR(R16G16B16_SFLOAT);
STR(R16G16B16A16_UNORM);
STR(R16G16B16A16_SNORM);
STR(R16G16B16A16_USCALED);
STR(R16G16B16A16_SSCALED);
STR(R16G16B16A16_UINT);
STR(R16G16B16A16_SINT);
STR(R16G16B16A16_SFLOAT);
STR(R32_UINT);
STR(R32_SINT);
STR(R32_SFLOAT);
STR(R32G32_UINT);
STR(R32G32_SINT);
STR(R32G32_SFLOAT);
STR(R32G32B32_UINT);
STR(R32G32B32_SINT);
STR(R32G32B32_SFLOAT);
STR(R32G32B32A32_UINT);
STR(R32G32B32A32_SINT);
STR(R32G32B32A32_SFLOAT);
STR(R64_UINT);
STR(R64_SINT);
STR(R64_SFLOAT);
STR(R64G64_UINT);
STR(R64G64_SINT);
STR(R64G64_SFLOAT);
STR(R64G64B64_UINT);
STR(R64G64B64_SINT);
STR(R64G64B64_SFLOAT);
STR(R64G64B64A64_UINT);
STR(R64G64B64A64_SINT);
STR(R64G64B64A64_SFLOAT);
STR(B10G11R11_UFLOAT_PACK32);
STR(E5B9G9R9_UFLOAT_PACK32);
STR(D16_UNORM);
STR(X8_D24_UNORM_PACK32);
STR(D32_SFLOAT);
STR(S8_UINT);
STR(D16_UNORM_S8_UINT);
STR(D24_UNORM_S8_UINT);
STR(D32_SFLOAT_S8_UINT);
STR(BC1_RGB_UNORM_BLOCK);
STR(BC1_RGB_SRGB_BLOCK);
STR(BC1_RGBA_UNORM_BLOCK);
STR(BC1_RGBA_SRGB_BLOCK);
STR(BC2_UNORM_BLOCK);
STR(BC2_SRGB_BLOCK);
STR(BC3_UNORM_BLOCK);
STR(BC3_SRGB_BLOCK);
STR(BC4_UNORM_BLOCK);
STR(BC4_SNORM_BLOCK);
STR(BC5_UNORM_BLOCK);
STR(BC5_SNORM_BLOCK);
STR(BC6H_UFLOAT_BLOCK);
STR(BC6H_SFLOAT_BLOCK);
STR(BC7_UNORM_BLOCK);
STR(BC7_SRGB_BLOCK);
STR(ETC2_R8G8B8_UNORM_BLOCK);
STR(ETC2_R8G8B8_SRGB_BLOCK);
STR(ETC2_R8G8B8A1_UNORM_BLOCK);
STR(ETC2_R8G8B8A1_SRGB_BLOCK);
STR(ETC2_R8G8B8A8_UNORM_BLOCK);
STR(ETC2_R8G8B8A8_SRGB_BLOCK);
STR(EAC_R11_UNORM_BLOCK);
STR(EAC_R11_SNORM_BLOCK);
STR(EAC_R11G11_UNORM_BLOCK);
STR(EAC_R11G11_SNORM_BLOCK);
STR(ASTC_4x4_UNORM_BLOCK);
STR(ASTC_4x4_SRGB_BLOCK);
STR(ASTC_5x4_UNORM_BLOCK);
STR(ASTC_5x4_SRGB_BLOCK);
STR(ASTC_5x5_UNORM_BLOCK);
STR(ASTC_5x5_SRGB_BLOCK);
STR(ASTC_6x5_UNORM_BLOCK);
STR(ASTC_6x5_SRGB_BLOCK);
STR(ASTC_6x6_UNORM_BLOCK);
STR(ASTC_6x6_SRGB_BLOCK);
STR(ASTC_8x5_UNORM_BLOCK);
STR(ASTC_8x5_SRGB_BLOCK);
STR(ASTC_8x6_UNORM_BLOCK);
STR(ASTC_8x6_SRGB_BLOCK);
STR(ASTC_8x8_UNORM_BLOCK);
STR(ASTC_8x8_SRGB_BLOCK);
STR(ASTC_10x5_UNORM_BLOCK);
STR(ASTC_10x5_SRGB_BLOCK);
STR(ASTC_10x6_UNORM_BLOCK);
STR(ASTC_10x6_SRGB_BLOCK);
STR(ASTC_10x8_UNORM_BLOCK);
STR(ASTC_10x8_SRGB_BLOCK);
STR(ASTC_10x10_UNORM_BLOCK);
STR(ASTC_10x10_SRGB_BLOCK);
STR(ASTC_12x10_UNORM_BLOCK);
STR(ASTC_12x10_SRGB_BLOCK);
STR(ASTC_12x12_UNORM_BLOCK);
STR(ASTC_12x12_SRGB_BLOCK);
STR(G8B8G8R8_422_UNORM);
STR(B8G8R8G8_422_UNORM);
STR(G8_B8_R8_3PLANE_420_UNORM);
STR(G8_B8R8_2PLANE_420_UNORM);
STR(G8_B8_R8_3PLANE_422_UNORM);
STR(G8_B8R8_2PLANE_422_UNORM);
STR(G8_B8_R8_3PLANE_444_UNORM);
STR(R10X6_UNORM_PACK16);
STR(R10X6G10X6_UNORM_2PACK16);
STR(R10X6G10X6B10X6A10X6_UNORM_4PACK16);
STR(G10X6B10X6G10X6R10X6_422_UNORM_4PACK16);
STR(B10X6G10X6R10X6G10X6_422_UNORM_4PACK16);
STR(G10X6_B10X6_R10X6_3PLANE_420_UNORM_3PACK16);
STR(G10X6_B10X6R10X6_2PLANE_420_UNORM_3PACK16);
STR(G10X6_B10X6_R10X6_3PLANE_422_UNORM_3PACK16);
STR(G10X6_B10X6R10X6_2PLANE_422_UNORM_3PACK16);
STR(G10X6_B10X6_R10X6_3PLANE_444_UNORM_3PACK16);
STR(R12X4_UNORM_PACK16);
STR(R12X4G12X4_UNORM_2PACK16);
STR(R12X4G12X4B12X4A12X4_UNORM_4PACK16);
STR(G12X4B12X4G12X4R12X4_422_UNORM_4PACK16);
STR(B12X4G12X4R12X4G12X4_422_UNORM_4PACK16);
STR(G12X4_B12X4_R12X4_3PLANE_420_UNORM_3PACK16);
STR(G12X4_B12X4R12X4_2PLANE_420_UNORM_3PACK16);
STR(G12X4_B12X4_R12X4_3PLANE_422_UNORM_3PACK16);
STR(G12X4_B12X4R12X4_2PLANE_422_UNORM_3PACK16);
STR(G12X4_B12X4_R12X4_3PLANE_444_UNORM_3PACK16);
STR(G16B16G16R16_422_UNORM);
STR(B16G16R16G16_422_UNORM);
STR(G16_B16_R16_3PLANE_420_UNORM);
STR(G16_B16R16_2PLANE_420_UNORM);
STR(G16_B16_R16_3PLANE_422_UNORM);
STR(G16_B16R16_2PLANE_422_UNORM);
STR(G16_B16_R16_3PLANE_444_UNORM);
STR(PVRTC1_2BPP_UNORM_BLOCK_IMG);
STR(PVRTC1_4BPP_UNORM_BLOCK_IMG);
STR(PVRTC2_2BPP_UNORM_BLOCK_IMG);
STR(PVRTC2_4BPP_UNORM_BLOCK_IMG);
STR(PVRTC1_2BPP_SRGB_BLOCK_IMG);
STR(PVRTC1_4BPP_SRGB_BLOCK_IMG);
STR(PVRTC2_2BPP_SRGB_BLOCK_IMG);
STR(PVRTC2_4BPP_SRGB_BLOCK_IMG);
#undef STR
default:
return "UNKNOWN_FORMAT";
}
}
#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_WIN32_KHR) || \
defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_WAYLAND_KHR)
static const char *VkPresentModeString(VkPresentModeKHR mode) {
switch (mode) {
#define STR(r) \
case VK_PRESENT_MODE_##r: \
return #r
STR(IMMEDIATE_KHR);
STR(MAILBOX_KHR);
STR(FIFO_KHR);
STR(FIFO_RELAXED_KHR);
STR(SHARED_DEMAND_REFRESH_KHR);
STR(SHARED_CONTINUOUS_REFRESH_KHR);
#undef STR
default:
return "UNKNOWN_FORMAT";
}
}
#endif
static bool CheckExtensionEnabled(const char *extension_to_check, const char **extension_list, uint32_t extension_count) {
for (uint32_t i = 0; i < extension_count; ++i) {
if (!strncmp(extension_to_check, extension_list[i], VK_MAX_EXTENSION_NAME_SIZE)) {
return true;
}
}
return false;
}
static bool CheckPhysicalDeviceExtensionIncluded(const char *extension_to_check, VkExtensionProperties *extension_list,
uint32_t extension_count) {
for (uint32_t i = 0; i < extension_count; ++i) {
if (!strncmp(extension_to_check, extension_list[i].extensionName, VK_MAX_EXTENSION_NAME_SIZE)) {
return true;
}
}
return false;
}
static void buildpNextChain(struct VkStructureHeader *first, const struct pNextChainBuildingBlockInfo *chain_info,
uint32_t chain_info_len) {
struct VkStructureHeader *place = first;
for (uint32_t i = 0; i < chain_info_len; i++) {
place->pNext = malloc(chain_info[i].mem_size);
if (!place->pNext) {
ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
}
memset(place->pNext, 0, chain_info[i].mem_size);
place = place->pNext;
place->sType = chain_info[i].sType;
}
place->pNext = NULL;
}
static void freepNextChain(struct VkStructureHeader *first) {
struct VkStructureHeader *place = first;
struct VkStructureHeader *next = NULL;
while (place) {
next = place->pNext;
free(place);
place = next;
}
}
static void ExtractVersion(uint32_t version, uint32_t *major, uint32_t *minor, uint32_t *patch) {
*major = version >> 22;
*minor = (version >> 12) & 0x3ff;
*patch = version & 0xfff;
}
static void AppGetPhysicalDeviceLayerExtensions(struct AppGpu *gpu, char *layer_name, uint32_t *extension_count,
VkExtensionProperties **extension_properties) {
VkResult err;
uint32_t ext_count = 0;
VkExtensionProperties *ext_ptr = NULL;
/* repeat get until VK_INCOMPLETE goes away */
do {
err = vkEnumerateDeviceExtensionProperties(gpu->obj, layer_name, &ext_count, NULL);
if (err) ERR_EXIT(err);
if (ext_ptr) {
free(ext_ptr);
}
ext_ptr = malloc(ext_count * sizeof(VkExtensionProperties));
err = vkEnumerateDeviceExtensionProperties(gpu->obj, layer_name, &ext_count, ext_ptr);
} while (err == VK_INCOMPLETE);
if (err) ERR_EXIT(err);
*extension_count = ext_count;
*extension_properties = ext_ptr;
}
static void AppGetGlobalLayerExtensions(char *layer_name, uint32_t *extension_count, VkExtensionProperties **extension_properties) {
VkResult err;
uint32_t ext_count = 0;
VkExtensionProperties *ext_ptr = NULL;
/* repeat get until VK_INCOMPLETE goes away */
do {
// gets the extension count if the last parameter is NULL
err = vkEnumerateInstanceExtensionProperties(layer_name, &ext_count, NULL);
if (err) ERR_EXIT(err);
if (ext_ptr) {
free(ext_ptr);
}
ext_ptr = malloc(ext_count * sizeof(VkExtensionProperties));
// gets the extension properties if the last parameter is not NULL
err = vkEnumerateInstanceExtensionProperties(layer_name, &ext_count, ext_ptr);
} while (err == VK_INCOMPLETE);
if (err) ERR_EXIT(err);
*extension_count = ext_count;
*extension_properties = ext_ptr;
}
/* Gets a list of layer and instance extensions */
static void AppGetInstanceExtensions(struct AppInstance *inst) {
VkResult err;
uint32_t count = 0;
/* Scan layers */
VkLayerProperties *global_layer_properties = NULL;
struct LayerExtensionList *global_layers = NULL;
do {
err = vkEnumerateInstanceLayerProperties(&count, NULL);
if (err) ERR_EXIT(err);
if (global_layer_properties) {
free(global_layer_properties);
}
global_layer_properties = malloc(sizeof(VkLayerProperties) * count);
assert(global_layer_properties);
if (global_layers) {
free(global_layers);
}
global_layers = malloc(sizeof(struct LayerExtensionList) * count);
assert(global_layers);
err = vkEnumerateInstanceLayerProperties(&count, global_layer_properties);
} while (err == VK_INCOMPLETE);
if (err) ERR_EXIT(err);
inst->global_layer_count = count;
inst->global_layers = global_layers;
for (uint32_t i = 0; i < inst->global_layer_count; ++i) {
VkLayerProperties *src_info = &global_layer_properties[i];
struct LayerExtensionList *dst_info = &inst->global_layers[i];
memcpy(&dst_info->layer_properties, src_info, sizeof(VkLayerProperties));
// Save away layer extension info for report
// Gets layer extensions, if first parameter is not NULL
AppGetGlobalLayerExtensions(src_info->layerName, &dst_info->extension_count, &dst_info->extension_properties);
}
free(global_layer_properties);
// Collect global extensions
inst->global_extension_count = 0;
// Gets instance extensions, if no layer was specified in the first
// paramteter
AppGetGlobalLayerExtensions(NULL, &inst->global_extension_count, &inst->global_extensions);
}
// Prints opening code for html output file
void PrintHtmlHeader(FILE *out) {
fprintf(out, "<!doctype html>\n");
fprintf(out, "<html lang='en'>\n");
fprintf(out, "\t<head>\n");
fprintf(out, "\t\t<title>vulkaninfo</title>\n");
fprintf(out, "\t\t<style>\n");
fprintf(out, "\t\thtml {\n");
fprintf(out, "\t\t\tbackground-color: #0b1e48;\n");
fprintf(out, "\t\t\tbackground-image: url(\"https://vulkan.lunarg.com/img/bg-starfield.jpg\");\n");
fprintf(out, "\t\t\tbackground-position: center;\n");
fprintf(out, "\t\t\t-webkit-background-size: cover;\n");
fprintf(out, "\t\t\t-moz-background-size: cover;\n");
fprintf(out, "\t\t\t-o-background-size: cover;\n");
fprintf(out, "\t\t\tbackground-size: cover;\n");
fprintf(out, "\t\t\tbackground-attachment: fixed;\n");
fprintf(out, "\t\t\tbackground-repeat: no-repeat;\n");
fprintf(out, "\t\t\theight: 100%%;\n");
fprintf(out, "\t\t}\n");
fprintf(out, "\t\t#header {\n");
fprintf(out, "\t\t\tz-index: -1;\n");
fprintf(out, "\t\t}\n");
fprintf(out, "\t\t#header>img {\n");
fprintf(out, "\t\t\tposition: absolute;\n");
fprintf(out, "\t\t\twidth: 160px;\n");
fprintf(out, "\t\t\tmargin-left: -280px;\n");
fprintf(out, "\t\t\ttop: -10px;\n");
fprintf(out, "\t\t\tleft: 50%%;\n");
fprintf(out, "\t\t}\n");
fprintf(out, "\t\t#header>h1 {\n");
fprintf(out, "\t\t\tfont-family: Arial, \"Helvetica Neue\", Helvetica, sans-serif;\n");
fprintf(out, "\t\t\tfont-size: 44px;\n");
fprintf(out, "\t\t\tfont-weight: 200;\n");
fprintf(out, "\t\t\ttext-shadow: 4px 4px 5px #000;\n");
fprintf(out, "\t\t\tcolor: #eee;\n");
fprintf(out, "\t\t\tposition: absolute;\n");
fprintf(out, "\t\t\twidth: 400px;\n");
fprintf(out, "\t\t\tmargin-left: -80px;\n");
fprintf(out, "\t\t\ttop: 8px;\n");
fprintf(out, "\t\t\tleft: 50%%;\n");
fprintf(out, "\t\t}\n");
fprintf(out, "\t\tbody {\n");
fprintf(out, "\t\t\tfont-family: Consolas, monaco, monospace;\n");
fprintf(out, "\t\t\tfont-size: 14px;\n");
fprintf(out, "\t\t\tline-height: 20px;\n");
fprintf(out, "\t\t\tcolor: #eee;\n");
fprintf(out, "\t\t\theight: 100%%;\n");
fprintf(out, "\t\t\tmargin: 0;\n");
fprintf(out, "\t\t\toverflow: hidden;\n");
fprintf(out, "\t\t}\n");
fprintf(out, "\t\t#wrapper {\n");
fprintf(out, "\t\t\tbackground-color: rgba(0, 0, 0, 0.7);\n");
fprintf(out, "\t\t\tborder: 1px solid #446;\n");
fprintf(out, "\t\t\tbox-shadow: 0px 0px 10px #000;\n");
fprintf(out, "\t\t\tpadding: 8px 12px;\n\n");
fprintf(out, "\t\t\tdisplay: inline-block;\n");
fprintf(out, "\t\t\tposition: absolute;\n");
fprintf(out, "\t\t\ttop: 80px;\n");
fprintf(out, "\t\t\tbottom: 25px;\n");
fprintf(out, "\t\t\tleft: 50px;\n");
fprintf(out, "\t\t\tright: 50px;\n");
fprintf(out, "\t\t\toverflow: auto;\n");
fprintf(out, "\t\t}\n");
fprintf(out, "\t\tdetails>details {\n");
fprintf(out, "\t\t\tmargin-left: 22px;\n");
fprintf(out, "\t\t}\n");
fprintf(out, "\t\tdetails>summary:only-child::-webkit-details-marker {\n");
fprintf(out, "\t\t\tdisplay: none;\n");
fprintf(out, "\t\t}\n");
fprintf(out, "\t\t.var, .type, .val {\n");
fprintf(out, "\t\t\tdisplay: inline;\n");
fprintf(out, "\t\t}\n");
fprintf(out, "\t\t.var {\n");
fprintf(out, "\t\t}\n");
fprintf(out, "\t\t.type {\n");
fprintf(out, "\t\t\tcolor: #acf;\n");
fprintf(out, "\t\t\tmargin: 0 12px;\n");
fprintf(out, "\t\t}\n");
fprintf(out, "\t\t.val {\n");
fprintf(out, "\t\t\tcolor: #afa;\n");
fprintf(out, "\t\t\tbackground: #222;\n");
fprintf(out, "\t\t\ttext-align: right;\n");
fprintf(out, "\t\t}\n");
fprintf(out, "\t\t</style>\n");
fprintf(out, "\t</head>\n");
fprintf(out, "\t<body>\n");
fprintf(out, "\t\t<div id='header'>\n");
fprintf(out, "\t\t\t<h1>vulkaninfo</h1>\n");
fprintf(out, "\t\t</div>\n");
fprintf(out, "\t\t<div id='wrapper'>\n");
}
// Prints closing code for html output file
void PrintHtmlFooter(FILE *out) {
fprintf(out, "\t\t</div>\n");
fprintf(out, "\t</body>\n");
fprintf(out, "</html>");
}
// Prints opening code for json output file
void PrintJsonHeader(const int vulkan_major, const int vulkan_minor, const int vulkan_patch) {
printf("{\n");
printf("\t\"$schema\": \"https://schema.khronos.org/vulkan/devsim_1_0_0.json#\",\n");
printf("\t\"comments\": {\n");
printf("\t\t\"desc\": \"JSON configuration file describing GPU %u. Generated using the vulkaninfo program.\",\n", selected_gpu);
printf("\t\t\"vulkanApiVersion\": \"%d.%d.%d\"\n", vulkan_major, vulkan_minor, vulkan_patch);
printf("\t}");
}
// Checks if current argument specifies json output, interprets/updates gpu selection
bool CheckForJsonOption(const char *arg) {
if (strncmp("--json", arg, 6) == 0 || strcmp(arg, "-j") == 0) {
if (strlen(arg) > 7 && strncmp("--json=", arg, 7) == 0) {
selected_gpu = strtol(arg + 7, NULL, 10);
}
human_readable_output = false;
json_output = true;
return true;
} else {
return false;
}
}
static void AppCompileInstanceExtensionsToEnable(struct AppInstance *inst) {
// Get all supported Instance extensions (excl. layer-provided ones)
inst->inst_extensions_count = inst->global_extension_count;
inst->inst_extensions = malloc(sizeof(char *) * inst->inst_extensions_count);
if (!inst->inst_extensions) ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
for (uint32_t i = 0; i < inst->global_extension_count; ++i) {
inst->inst_extensions[i] = inst->global_extensions[i].extensionName;
}
}
static void AppLoadInstanceCommands(struct AppInstance *inst) {
#define LOAD_INSTANCE_VK_CMD(cmd) inst->cmd = (PFN_##cmd)vkGetInstanceProcAddr(inst->instance, #cmd)
LOAD_INSTANCE_VK_CMD(vkGetPhysicalDeviceSurfaceSupportKHR);
LOAD_INSTANCE_VK_CMD(vkGetPhysicalDeviceSurfaceCapabilitiesKHR);
LOAD_INSTANCE_VK_CMD(vkGetPhysicalDeviceSurfaceFormatsKHR);
LOAD_INSTANCE_VK_CMD(vkGetPhysicalDeviceSurfaceFormats2KHR);
LOAD_INSTANCE_VK_CMD(vkGetPhysicalDeviceSurfacePresentModesKHR);
LOAD_INSTANCE_VK_CMD(vkGetPhysicalDeviceProperties2KHR);
LOAD_INSTANCE_VK_CMD(vkGetPhysicalDeviceFormatProperties2KHR);
LOAD_INSTANCE_VK_CMD(vkGetPhysicalDeviceQueueFamilyProperties2KHR);
LOAD_INSTANCE_VK_CMD(vkGetPhysicalDeviceFeatures2KHR);
LOAD_INSTANCE_VK_CMD(vkGetPhysicalDeviceMemoryProperties2KHR);
LOAD_INSTANCE_VK_CMD(vkGetPhysicalDeviceSurfaceCapabilities2KHR);
LOAD_INSTANCE_VK_CMD(vkGetPhysicalDeviceSurfaceCapabilities2EXT);
#undef LOAD_INSTANCE_VK_CMD
}
static void AppCreateInstance(struct AppInstance *inst) {
PFN_vkEnumerateInstanceVersion enumerate_instance_version =
(PFN_vkEnumerateInstanceVersion)vkGetInstanceProcAddr(NULL, "vkEnumerateInstanceVersion");
if (!enumerate_instance_version) {
inst->instance_version = VK_API_VERSION_1_0;
} else {
const VkResult err = enumerate_instance_version(&inst->instance_version);
if (err) ERR_EXIT(err);
}
inst->vulkan_major = VK_VERSION_MAJOR(inst->instance_version);
inst->vulkan_minor = VK_VERSION_MINOR(inst->instance_version);
inst->vulkan_patch = VK_VERSION_PATCH(VK_HEADER_VERSION);
AppGetInstanceExtensions(inst);
const VkDebugReportCallbackCreateInfoEXT dbg_info = {.sType = VK_STRUCTURE_TYPE_DEBUG_REPORT_CALLBACK_CREATE_INFO_EXT,
.flags = VK_DEBUG_REPORT_ERROR_BIT_EXT | VK_DEBUG_REPORT_WARNING_BIT_EXT,
.pfnCallback = DbgCallback};
const VkApplicationInfo app_info = {.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO,
.pApplicationName = APP_SHORT_NAME,
.applicationVersion = 1,
.apiVersion = VK_API_VERSION_1_0};
AppCompileInstanceExtensionsToEnable(inst);
const VkInstanceCreateInfo inst_info = {.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO,
.pNext = &dbg_info,
.pApplicationInfo = &app_info,
.enabledExtensionCount = inst->inst_extensions_count,
.ppEnabledExtensionNames = inst->inst_extensions};
VkResult err = vkCreateInstance(&inst_info, NULL, &inst->instance);
if (err == VK_ERROR_INCOMPATIBLE_DRIVER) {
fprintf(stderr, "Cannot create Vulkan instance.\n");
fprintf(stderr,
"This problem is often caused by a faulty installation of the Vulkan driver or attempting to use a GPU that does "
"not support Vulkan.\n");
ERR_EXIT(err);
} else if (err) {
ERR_EXIT(err);
}
AppLoadInstanceCommands(inst);
inst->surface_ext_infos_root = NULL;
}
static void AppDestroyInstance(struct AppInstance *inst) {
free(inst->global_extensions);
for (uint32_t i = 0; i < inst->global_layer_count; ++i) {
free(inst->global_layers[i].extension_properties);
}
free(inst->global_layers);
free((char **)inst->inst_extensions);
vkDestroyInstance(inst->instance, NULL);
}
static void AppGpuInit(struct AppGpu *gpu, struct AppInstance *inst, uint32_t id, VkPhysicalDevice obj) {
uint32_t i;
memset(gpu, 0, sizeof(*gpu));
gpu->id = id;
gpu->obj = obj;
gpu->inst = inst;
vkGetPhysicalDeviceProperties(gpu->obj, &gpu->props);
if (CheckExtensionEnabled(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
struct pNextChainBuildingBlockInfo chain_info[] = {
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_PROPERTIES_EXT,
.mem_size = sizeof(VkPhysicalDeviceBlendOperationAdvancedPropertiesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_POINT_CLIPPING_PROPERTIES_KHR,
.mem_size = sizeof(VkPhysicalDevicePointClippingPropertiesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PUSH_DESCRIPTOR_PROPERTIES_KHR,
.mem_size = sizeof(VkPhysicalDevicePushDescriptorPropertiesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DISCARD_RECTANGLE_PROPERTIES_EXT,
.mem_size = sizeof(VkPhysicalDeviceDiscardRectanglePropertiesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_PROPERTIES_KHR,
.mem_size = sizeof(VkPhysicalDeviceMultiviewPropertiesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MAINTENANCE_3_PROPERTIES_KHR,
.mem_size = sizeof(VkPhysicalDeviceMaintenance3PropertiesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ID_PROPERTIES_KHR, .mem_size = sizeof(VkPhysicalDeviceIDPropertiesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES_KHR,
.mem_size = sizeof(VkPhysicalDeviceDriverPropertiesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT_CONTROLS_PROPERTIES_KHR,
.mem_size = sizeof(VkPhysicalDeviceFloatControlsPropertiesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PCI_BUS_INFO_PROPERTIES_EXT,
.mem_size = sizeof(VkPhysicalDevicePCIBusInfoPropertiesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_PROPERTIES_EXT,
.mem_size = sizeof(VkPhysicalDeviceTransformFeedbackPropertiesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_DENSITY_MAP_PROPERTIES_EXT,
.mem_size = sizeof(VkPhysicalDeviceFragmentDensityMapPropertiesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_PROPERTIES_EXT,
.mem_size = sizeof(VkPhysicalDeviceDescriptorIndexingPropertiesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DEPTH_STENCIL_RESOLVE_PROPERTIES_KHR,
.mem_size = sizeof(VkPhysicalDeviceDepthStencilResolvePropertiesKHR)}};
uint32_t chain_info_len = ARRAY_SIZE(chain_info);
gpu->props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2_KHR;
buildpNextChain((struct VkStructureHeader *)&gpu->props2, chain_info, chain_info_len);
inst->vkGetPhysicalDeviceProperties2KHR(gpu->obj, &gpu->props2);
}
/* get queue count */
vkGetPhysicalDeviceQueueFamilyProperties(gpu->obj, &gpu->queue_count, NULL);
gpu->queue_props = malloc(sizeof(gpu->queue_props[0]) * gpu->queue_count);
if (!gpu->queue_props) {
ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
}
vkGetPhysicalDeviceQueueFamilyProperties(gpu->obj, &gpu->queue_count, gpu->queue_props);
if (CheckExtensionEnabled(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
gpu->queue_props2 = malloc(sizeof(gpu->queue_props2[0]) * gpu->queue_count);
if (!gpu->queue_props2) {
ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
}
for (i = 0; i < gpu->queue_count; ++i) {
gpu->queue_props2[i].sType = VK_STRUCTURE_TYPE_QUEUE_FAMILY_PROPERTIES_2_KHR;
gpu->queue_props2[i].pNext = NULL;
}
inst->vkGetPhysicalDeviceQueueFamilyProperties2KHR(gpu->obj, &gpu->queue_count, gpu->queue_props2);
}
/* set up queue requests */
gpu->queue_reqs = malloc(sizeof(*gpu->queue_reqs) * gpu->queue_count);
if (!gpu->queue_reqs) {
ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
}
for (i = 0; i < gpu->queue_count; ++i) {
float *queue_priorities = NULL;
if (CheckExtensionEnabled(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
queue_priorities = malloc(gpu->queue_props2[i].queueFamilyProperties.queueCount * sizeof(float));
} else {
queue_priorities = malloc(gpu->queue_props[i].queueCount * sizeof(float));
}
if (!queue_priorities) {
ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
}
if (CheckExtensionEnabled(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
memset(queue_priorities, 0, gpu->queue_props2[i].queueFamilyProperties.queueCount * sizeof(float));
} else {
memset(queue_priorities, 0, gpu->queue_props[i].queueCount * sizeof(float));
}
gpu->queue_reqs[i].sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO;
gpu->queue_reqs[i].pNext = NULL;
gpu->queue_reqs[i].flags = 0;
gpu->queue_reqs[i].queueFamilyIndex = i;
if (CheckExtensionEnabled(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
gpu->queue_reqs[i].queueCount = gpu->queue_props2[i].queueFamilyProperties.queueCount;
} else {
gpu->queue_reqs[i].queueCount = gpu->queue_props[i].queueCount;
}
gpu->queue_reqs[i].pQueuePriorities = queue_priorities;
}
vkGetPhysicalDeviceMemoryProperties(gpu->obj, &gpu->memory_props);
vkGetPhysicalDeviceFeatures(gpu->obj, &gpu->features);
if (CheckExtensionEnabled(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
struct pNextChainBuildingBlockInfo mem_prop_chain_info[] = {
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_BUDGET_PROPERTIES_EXT,
.mem_size = sizeof(VkPhysicalDeviceMemoryBudgetPropertiesEXT)}};
uint32_t mem_prop_chain_info_len = ARRAY_SIZE(mem_prop_chain_info);
gpu->memory_props2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PROPERTIES_2_KHR;
buildpNextChain((struct VkStructureHeader *)&gpu->memory_props2, mem_prop_chain_info, mem_prop_chain_info_len);
inst->vkGetPhysicalDeviceMemoryProperties2KHR(gpu->obj, &gpu->memory_props2);
struct pNextChainBuildingBlockInfo chain_info[] = {
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_8BIT_STORAGE_FEATURES_KHR,
.mem_size = sizeof(VkPhysicalDevice8BitStorageFeaturesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_16BIT_STORAGE_FEATURES_KHR,
.mem_size = sizeof(VkPhysicalDevice16BitStorageFeaturesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES_KHR,
.mem_size = sizeof(VkPhysicalDeviceSamplerYcbcrConversionFeaturesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VARIABLE_POINTER_FEATURES_KHR,
.mem_size = sizeof(VkPhysicalDeviceVariablePointerFeaturesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BLEND_OPERATION_ADVANCED_FEATURES_EXT,
.mem_size = sizeof(VkPhysicalDeviceBlendOperationAdvancedFeaturesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MULTIVIEW_FEATURES_KHR,
.mem_size = sizeof(VkPhysicalDeviceMultiviewFeaturesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FLOAT16_INT8_FEATURES_KHR,
.mem_size = sizeof(VkPhysicalDeviceFloat16Int8FeaturesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SHADER_ATOMIC_INT64_FEATURES_KHR,
.mem_size = sizeof(VkPhysicalDeviceShaderAtomicInt64FeaturesKHR)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_TRANSFORM_FEEDBACK_FEATURES_EXT,
.mem_size = sizeof(VkPhysicalDeviceTransformFeedbackFeaturesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SCALAR_BLOCK_LAYOUT_FEATURES_EXT,
.mem_size = sizeof(VkPhysicalDeviceScalarBlockLayoutFeaturesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FRAGMENT_DENSITY_MAP_FEATURES_EXT,
.mem_size = sizeof(VkPhysicalDeviceFragmentDensityMapFeaturesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_MEMORY_PRIORITY_FEATURES_EXT,
.mem_size = sizeof(VkPhysicalDeviceMemoryPriorityFeaturesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_BUFFER_ADDRESS_FEATURES_EXT,
.mem_size = sizeof(VkPhysicalDeviceBufferAddressFeaturesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DESCRIPTOR_INDEXING_FEATURES_EXT,
.mem_size = sizeof(VkPhysicalDeviceDescriptorIndexingFeaturesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_YCBCR_IMAGE_ARRAYS_FEATURES_EXT,
.mem_size = sizeof(VkPhysicalDeviceYcbcrImageArraysFeaturesEXT)},
{.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_HOST_QUERY_RESET_FEATURES_EXT,
.mem_size = sizeof(VkPhysicalDeviceHostQueryResetFeaturesEXT)}};
uint32_t chain_info_len = ARRAY_SIZE(chain_info);
gpu->features2.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2_KHR;
buildpNextChain((struct VkStructureHeader *)&gpu->features2, chain_info, chain_info_len);
inst->vkGetPhysicalDeviceFeatures2KHR(gpu->obj, &gpu->features2);
}
AppGetPhysicalDeviceLayerExtensions(gpu, NULL, &gpu->device_extension_count, &gpu->device_extensions);
const float queue_priority = 1.0f;
const VkDeviceQueueCreateInfo q_ci = {.sType = VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO,
.queueFamilyIndex = 0, // just pick the first one and hope for the best
.queueCount = 1,
.pQueuePriorities = &queue_priority};
VkPhysicalDeviceFeatures features = {0};
// if (gpu->features.sparseBinding ) features.sparseBinding = VK_TRUE;
gpu->enabled_features = features;
const VkDeviceCreateInfo device_ci = {.sType = VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO,
.queueCreateInfoCount = 1,
.pQueueCreateInfos = &q_ci,
// TODO: relevant extensions
.pEnabledFeatures = &gpu->enabled_features};
VkResult err = vkCreateDevice(gpu->obj, &device_ci, NULL, &gpu->dev);
if (err) ERR_EXIT(err);
const VkFormat color_format = VK_FORMAT_R8G8B8A8_UNORM;
const VkFormat formats[] = {
color_format, VK_FORMAT_D16_UNORM, VK_FORMAT_X8_D24_UNORM_PACK32, VK_FORMAT_D32_SFLOAT,
VK_FORMAT_S8_UINT, VK_FORMAT_D16_UNORM_S8_UINT, VK_FORMAT_D24_UNORM_S8_UINT, VK_FORMAT_D32_SFLOAT_S8_UINT};
assert(ARRAY_SIZE(gpu->mem_type_res_support.image[0]) == ARRAY_SIZE(formats));
const VkImageUsageFlags usages[] = {0, VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT};
const VkImageCreateFlags flagss[] = {0, VK_IMAGE_CREATE_SPARSE_BINDING_BIT};
for (size_t fmt_i = 0; fmt_i < ARRAY_SIZE(formats); ++fmt_i) {
for (VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL; tiling <= VK_IMAGE_TILING_LINEAR; ++tiling) {
gpu->mem_type_res_support.image[tiling][fmt_i].format = formats[fmt_i];
gpu->mem_type_res_support.image[tiling][fmt_i].regular_supported = true;
gpu->mem_type_res_support.image[tiling][fmt_i].sparse_supported = true;
gpu->mem_type_res_support.image[tiling][fmt_i].transient_supported = true;
VkFormatProperties fmt_props;
vkGetPhysicalDeviceFormatProperties(gpu->obj, formats[fmt_i], &fmt_props);
if ((tiling == VK_IMAGE_TILING_OPTIMAL && fmt_props.optimalTilingFeatures == 0) ||
(tiling == VK_IMAGE_TILING_LINEAR && fmt_props.linearTilingFeatures == 0)) {
gpu->mem_type_res_support.image[tiling][fmt_i].regular_supported = false;
gpu->mem_type_res_support.image[tiling][fmt_i].sparse_supported = false;
gpu->mem_type_res_support.image[tiling][fmt_i].transient_supported = false;
continue;
}
for (size_t u_i = 0; u_i < ARRAY_SIZE(usages); ++u_i) {
for (size_t flg_i = 0; flg_i < ARRAY_SIZE(flagss); ++flg_i) {
VkImageCreateInfo image_ci = {
.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO,
.flags = flagss[flg_i],
.imageType = VK_IMAGE_TYPE_2D,
.format = formats[fmt_i],
.extent = {8, 8, 1},
.mipLevels = 1,
.arrayLayers = 1,
.samples = VK_SAMPLE_COUNT_1_BIT,
.tiling = tiling,
.usage = usages[u_i],
};
if ((image_ci.flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) &&
(image_ci.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) {
continue;
}
if (image_ci.usage == 0 || (image_ci.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) {
if (image_ci.format == color_format)
image_ci.usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
else
image_ci.usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
}
if (!gpu->enabled_features.sparseBinding && (image_ci.flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT)) {
gpu->mem_type_res_support.image[tiling][fmt_i].sparse_supported = false;
continue;
}
VkImageFormatProperties img_props;
err = vkGetPhysicalDeviceImageFormatProperties(gpu->obj, image_ci.format, image_ci.imageType, image_ci.tiling,
image_ci.usage, image_ci.flags, &img_props);
uint32_t *memtypes;
bool *support;
if (image_ci.flags == 0 && !(image_ci.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) {
memtypes = &gpu->mem_type_res_support.image[tiling][fmt_i].regular_memtypes;
support = &gpu->mem_type_res_support.image[tiling][fmt_i].regular_supported;
} else if ((image_ci.flags & VK_IMAGE_CREATE_SPARSE_BINDING_BIT) &&
!(image_ci.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) {
memtypes = &gpu->mem_type_res_support.image[tiling][fmt_i].sparse_memtypes;
support = &gpu->mem_type_res_support.image[tiling][fmt_i].sparse_supported;
} else if (image_ci.flags == 0 && (image_ci.usage & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT)) {
memtypes = &gpu->mem_type_res_support.image[tiling][fmt_i].transient_memtypes;
support = &gpu->mem_type_res_support.image[tiling][fmt_i].transient_supported;
} else {
assert(false);
}
if (err == VK_ERROR_FORMAT_NOT_SUPPORTED) {
*support = false;
} else {
if (err) ERR_EXIT(err);
VkImage dummy_img;
err = vkCreateImage(gpu->dev, &image_ci, NULL, &dummy_img);
if (err) ERR_EXIT(err);
VkMemoryRequirements mem_req;
vkGetImageMemoryRequirements(gpu->dev, dummy_img, &mem_req);
*memtypes = mem_req.memoryTypeBits;
vkDestroyImage(gpu->dev, dummy_img, NULL);
}
}
}
}
}
// TODO buffer - memory type compatibility
}
static void AppGpuDestroy(struct AppGpu *gpu) {
vkDestroyDevice(gpu->dev, NULL);
free(gpu->device_extensions);
if (CheckExtensionEnabled(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
freepNextChain(gpu->features2.pNext);
}
for (uint32_t i = 0; i < gpu->queue_count; ++i) {
free((void *)gpu->queue_reqs[i].pQueuePriorities);
}
free(gpu->queue_reqs);
free(gpu->queue_props);
if (CheckExtensionEnabled(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
free(gpu->queue_props2);
freepNextChain(gpu->props2.pNext);
}
}
//-----------------------------------------------------------
//---------------------------Win32---------------------------
#ifdef VK_USE_PLATFORM_WIN32_KHR
// MS-Windows event handling function:
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return (DefWindowProc(hWnd, uMsg, wParam, lParam)); }
static void AppCreateWin32Window(struct AppInstance *inst) {
inst->h_instance = GetModuleHandle(NULL);
WNDCLASSEX win_class;
// Initialize the window class structure:
win_class.cbSize = sizeof(WNDCLASSEX);
win_class.style = CS_HREDRAW | CS_VREDRAW;
win_class.lpfnWndProc = WndProc;
win_class.cbClsExtra = 0;
win_class.cbWndExtra = 0;
win_class.hInstance = inst->h_instance;
win_class.hIcon = LoadIcon(NULL, IDI_APPLICATION);
win_class.hCursor = LoadCursor(NULL, IDC_ARROW);
win_class.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
win_class.lpszMenuName = NULL;
win_class.lpszClassName = APP_SHORT_NAME;
win_class.hInstance = inst->h_instance;
win_class.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
// Register window class:
if (!RegisterClassEx(&win_class)) {
// It didn't work, so try to give a useful error:
fprintf(stderr, "Failed to register the window class!\n");
exit(1);
}
// Create window with the registered class:
RECT wr = {0, 0, inst->width, inst->height};
AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, FALSE);
inst->h_wnd = CreateWindowEx(0,
APP_SHORT_NAME, // class name
APP_SHORT_NAME, // app name
// WS_VISIBLE | WS_SYSMENU |
WS_OVERLAPPEDWINDOW, // window style
100, 100, // x/y coords
wr.right - wr.left, // width
wr.bottom - wr.top, // height
NULL, // handle to parent
NULL, // handle to menu
inst->h_instance, // hInstance
NULL); // no extra parameters
if (!inst->h_wnd) {
// It didn't work, so try to give a useful error:
fprintf(stderr, "Failed to create a window!\n");
exit(1);
}
}
static VkSurfaceKHR AppCreateWin32Surface(struct AppInstance *inst) {
VkWin32SurfaceCreateInfoKHR createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_WIN32_SURFACE_CREATE_INFO_KHR;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.hinstance = inst->h_instance;
createInfo.hwnd = inst->h_wnd;
VkSurfaceKHR surface;
VkResult err = vkCreateWin32SurfaceKHR(inst->instance, &createInfo, NULL, &surface);
if (err) ERR_EXIT(err);
return surface;
}
static void AppDestroyWin32Window(struct AppInstance *inst) { DestroyWindow(inst->h_wnd); }
#endif // VK_USE_PLATFORM_WIN32_KHR
//-----------------------------------------------------------
#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_WIN32_KHR) || \
defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_WAYLAND_KHR) || defined(VK_USE_PLATFORM_ANDROID_KHR)
static void AppDestroySurface(struct AppInstance *inst, VkSurfaceKHR surface) { // same for all platforms
vkDestroySurfaceKHR(inst->instance, surface, NULL);
}
#endif
//----------------------------XCB----------------------------
#ifdef VK_USE_PLATFORM_XCB_KHR
static void AppCreateXcbWindow(struct AppInstance *inst) {
//--Init Connection--
const xcb_setup_t *setup;
xcb_screen_iterator_t iter;
int scr;
// API guarantees non-null xcb_connection
inst->xcb_connection = xcb_connect(NULL, &scr);
int conn_error = xcb_connection_has_error(inst->xcb_connection);
if (conn_error) {
fprintf(stderr, "XCB failed to connect to the X server due to error:%d.\n", conn_error);
fflush(stderr);
inst->xcb_connection = NULL;
}
setup = xcb_get_setup(inst->xcb_connection);
iter = xcb_setup_roots_iterator(setup);
while (scr-- > 0) {
xcb_screen_next(&iter);
}
inst->xcb_screen = iter.data;
//-------------------
inst->xcb_window = xcb_generate_id(inst->xcb_connection);
xcb_create_window(inst->xcb_connection, XCB_COPY_FROM_PARENT, inst->xcb_window, inst->xcb_screen->root, 0, 0, inst->width,
inst->height, 0, XCB_WINDOW_CLASS_INPUT_OUTPUT, inst->xcb_screen->root_visual, 0, NULL);
xcb_intern_atom_cookie_t cookie = xcb_intern_atom(inst->xcb_connection, 1, 12, "WM_PROTOCOLS");
xcb_intern_atom_reply_t *reply = xcb_intern_atom_reply(inst->xcb_connection, cookie, 0);
free(reply);
}
static VkSurfaceKHR AppCreateXcbSurface(struct AppInstance *inst) {
if (!inst->xcb_connection) {
ERR_EXIT(VK_ERROR_INITIALIZATION_FAILED);
}
VkXcbSurfaceCreateInfoKHR xcb_createInfo;
xcb_createInfo.sType = VK_STRUCTURE_TYPE_XCB_SURFACE_CREATE_INFO_KHR;
xcb_createInfo.pNext = NULL;
xcb_createInfo.flags = 0;
xcb_createInfo.connection = inst->xcb_connection;
xcb_createInfo.window = inst->xcb_window;
VkSurfaceKHR surface;
VkResult err = vkCreateXcbSurfaceKHR(inst->instance, &xcb_createInfo, NULL, &surface);
if (err) ERR_EXIT(err);
return surface;
}
static void AppDestroyXcbWindow(struct AppInstance *inst) {
if (!inst->xcb_connection) {
return; // Nothing to destroy
}
xcb_destroy_window(inst->xcb_connection, inst->xcb_window);
xcb_disconnect(inst->xcb_connection);
}
#endif // VK_USE_PLATFORM_XCB_KHR
//-----------------------------------------------------------
//----------------------------XLib---------------------------
#ifdef VK_USE_PLATFORM_XLIB_KHR
static void AppCreateXlibWindow(struct AppInstance *inst) {
long visualMask = VisualScreenMask;
int numberOfVisuals;
inst->xlib_display = XOpenDisplay(NULL);
if (inst->xlib_display == NULL) {
fprintf(stderr, "XLib failed to connect to the X server.\nExiting ...\n");
exit(1);
}
XVisualInfo vInfoTemplate = {};
vInfoTemplate.screen = DefaultScreen(inst->xlib_display);
XVisualInfo *visualInfo = XGetVisualInfo(inst->xlib_display, visualMask, &vInfoTemplate, &numberOfVisuals);
inst->xlib_window = XCreateWindow(inst->xlib_display, RootWindow(inst->xlib_display, vInfoTemplate.screen), 0, 0, inst->width,
inst->height, 0, visualInfo->depth, InputOutput, visualInfo->visual, 0, NULL);
XSync(inst->xlib_display, false);
XFree(visualInfo);
}
static VkSurfaceKHR AppCreateXlibSurface(struct AppInstance *inst) {
VkXlibSurfaceCreateInfoKHR createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.dpy = inst->xlib_display;
createInfo.window = inst->xlib_window;
VkSurfaceKHR surface;
VkResult err = vkCreateXlibSurfaceKHR(inst->instance, &createInfo, NULL, &surface);
if (err) ERR_EXIT(err);
return surface;
}
static void AppDestroyXlibWindow(struct AppInstance *inst) {
XDestroyWindow(inst->xlib_display, inst->xlib_window);
XCloseDisplay(inst->xlib_display);
}
#endif // VK_USE_PLATFORM_XLIB_KHR
//-----------------------------------------------------------
#ifdef VK_USE_PLATFORM_MACOS_MVK
static void AppCreateMacOSWindow(struct AppInstance *inst) {
inst->window = CreateMetalView(inst->width, inst->height);
if (inst->window == NULL) {
fprintf(stderr, "Could not create a native Metal view.\nExiting...\n");
exit(1);
}
}
static VkSurfaceKHR AppCreateMacOSSurface(struct AppInstance *inst) {
VkMacOSSurfaceCreateInfoMVK createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_MACOS_SURFACE_CREATE_INFO_MVK;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.pView = inst->window;
VkSurfaceKHR surface;
VkResult err = vkCreateMacOSSurfaceMVK(inst->instance, &createInfo, NULL, &surface);
if (err) ERR_EXIT(err);
return surface;
}
static void AppDestroyMacOSWindow(struct AppInstance *inst) { DestroyMetalView(inst->window); }
#endif // VK_USE_PLATFORM_MACOS_MVK
//-----------------------------------------------------------
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
static void wayland_registry_global(void *data, struct wl_registry *registry, uint32_t id, const char *interface,
uint32_t version) {
struct AppInstance *inst = (struct AppInstance *)data;
if (strcmp(interface, "wl_compositor") == 0) {
struct wl_compositor *compositor = (struct wl_compositor *)wl_registry_bind(registry, id, &wl_compositor_interface, 1);
inst->wayland_surface = wl_compositor_create_surface(compositor);
}
}
static void wayland_registry_global_remove(void *data, struct wl_registry *registry, uint32_t id) {}
static const struct wl_registry_listener wayland_registry_listener = {wayland_registry_global, wayland_registry_global_remove};
static void AppCreateWaylandWindow(struct AppInstance *inst) {
inst->wayland_display = wl_display_connect(NULL);
struct wl_registry *registry = wl_display_get_registry(inst->wayland_display);
wl_registry_add_listener(wl_display_get_registry(inst->wayland_display), &wayland_registry_listener, inst);
wl_display_roundtrip(inst->wayland_display);
wl_registry_destroy(registry);
}
static VkSurfaceKHR AppCreateWaylandSurface(struct AppInstance *inst) {
VkWaylandSurfaceCreateInfoKHR createInfo;
createInfo.sType = VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR;
createInfo.pNext = NULL;
createInfo.flags = 0;
createInfo.display = inst->wayland_display;
createInfo.surface = inst->wayland_surface;
VkSurfaceKHR surface;
VkResult err = vkCreateWaylandSurfaceKHR(inst->instance, &createInfo, NULL, &surface);
if (err) ERR_EXIT(err);
return surface;
}
static void AppDestroyWaylandWindow(struct AppInstance *inst) { wl_display_disconnect(inst->wayland_display); }
#endif // VK_USE_PLATFORM_WAYLAND_KHR
#if defined(VK_USE_PLATFORM_XCB_KHR) || defined(VK_USE_PLATFORM_XLIB_KHR) || defined(VK_USE_PLATFORM_WIN32_KHR) || \
defined(VK_USE_PLATFORM_MACOS_MVK) || defined(VK_USE_PLATFORM_WAYLAND_KHR)
static int AppDumpSurfaceFormats(struct AppInstance *inst, struct AppGpu *gpu, VkSurfaceKHR surface, FILE *out) {
// Get the list of VkFormat's that are supported
VkResult err;
uint32_t format_count = 0;
VkSurfaceFormatKHR *surf_formats = NULL;
VkSurfaceFormat2KHR *surf_formats2 = NULL;
const VkPhysicalDeviceSurfaceInfo2KHR surface_info2 = {.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR,
.surface = surface};
if (CheckExtensionEnabled(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
err = inst->vkGetPhysicalDeviceSurfaceFormats2KHR(gpu->obj, &surface_info2, &format_count, NULL);
if (err) ERR_EXIT(err);
surf_formats2 = (VkSurfaceFormat2KHR *)malloc(format_count * sizeof(VkSurfaceFormat2KHR));
if (!surf_formats2) ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
for (uint32_t i = 0; i < format_count; ++i) {
surf_formats2[i].sType = VK_STRUCTURE_TYPE_SURFACE_FORMAT_2_KHR;
surf_formats2[i].pNext = NULL;
}
err = inst->vkGetPhysicalDeviceSurfaceFormats2KHR(gpu->obj, &surface_info2, &format_count, surf_formats2);
if (err) ERR_EXIT(err);
} else {
err = inst->vkGetPhysicalDeviceSurfaceFormatsKHR(gpu->obj, surface, &format_count, NULL);
if (err) ERR_EXIT(err);
surf_formats = (VkSurfaceFormatKHR *)malloc(format_count * sizeof(VkSurfaceFormatKHR));
if (!surf_formats) ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
err = inst->vkGetPhysicalDeviceSurfaceFormatsKHR(gpu->obj, surface, &format_count, surf_formats);
if (err) ERR_EXIT(err);
}
if (html_output) {
fprintf(out, "\t\t\t\t\t<details><summary>Formats: count = <span class='val'>%d</span></summary>", format_count);
if (format_count > 0) {
fprintf(out, "\n");
} else {
fprintf(out, "</details>\n");
}
} else if (human_readable_output) {
printf("Formats:\t\tcount = %d\n", format_count);
}
for (uint32_t i = 0; i < format_count; ++i) {
if (html_output) {
if (CheckExtensionEnabled(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
fprintf(out, "\t\t\t\t\t\t<details><summary><span class='type'>%s</span></summary></details>\n",
VkFormatString(surf_formats2[i].surfaceFormat.format));
} else {
fprintf(out, "\t\t\t\t\t\t<details><summary><span class='type'>%s</span></summary></details>\n",
VkFormatString(surf_formats[i].format));
}
} else if (human_readable_output) {
if (CheckExtensionEnabled(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
printf("\t%s\n", VkFormatString(surf_formats2[i].surfaceFormat.format));
} else {
printf("\t%s\n", VkFormatString(surf_formats[i].format));
}
}
}
if (format_count > 0 && html_output) {
fprintf(out, "\t\t\t\t\t</details>\n");
}
fflush(out);
fflush(stdout);
if (CheckExtensionEnabled(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
free(surf_formats2);
} else {
free(surf_formats);
}
return format_count;
}
static int AppDumpSurfacePresentModes(struct AppInstance *inst, struct AppGpu *gpu, VkSurfaceKHR surface, FILE *out) {
// Get the list of VkPresentMode's that are supported:
VkResult err;
uint32_t present_mode_count = 0;
err = inst->vkGetPhysicalDeviceSurfacePresentModesKHR(gpu->obj, surface, &present_mode_count, NULL);
if (err) ERR_EXIT(err);
VkPresentModeKHR *surf_present_modes = (VkPresentModeKHR *)malloc(present_mode_count * sizeof(VkPresentModeKHR));
if (!surf_present_modes) ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
err = inst->vkGetPhysicalDeviceSurfacePresentModesKHR(gpu->obj, surface, &present_mode_count, surf_present_modes);
if (err) ERR_EXIT(err);
if (html_output) {
fprintf(out, "\t\t\t\t\t<details><summary>Present Modes: count = <span class='val'>%d</span></summary>",
present_mode_count);
if (present_mode_count > 0) {
fprintf(out, "\n");
} else {
fprintf(out, "</details>");
}
} else if (human_readable_output) {
printf("Present Modes:\t\tcount = %d\n", present_mode_count);
}
for (uint32_t i = 0; i < present_mode_count; ++i) {
if (html_output) {
fprintf(out, "\t\t\t\t\t\t<details><summary><span class='type'>%s</span></summary></details>\n",
VkPresentModeString(surf_present_modes[i]));
} else if (human_readable_output) {
printf("\t%s\n", VkPresentModeString(surf_present_modes[i]));
}
}
if (present_mode_count > 0 && html_output) {
fprintf(out, "\t\t\t\t\t</details>\n");
}
fflush(out);
fflush(stdout);
free(surf_present_modes);
return present_mode_count;
}
static void AppDumpSurfaceCapabilities(struct AppInstance *inst, struct AppGpu *gpu, VkSurfaceKHR surface, FILE *out) {
if (CheckExtensionEnabled(VK_KHR_SURFACE_EXTENSION_NAME, gpu->inst->inst_extensions, gpu->inst->inst_extensions_count)) {
VkSurfaceCapabilitiesKHR surface_capabilities;
VkResult err;
err = inst->vkGetPhysicalDeviceSurfaceCapabilitiesKHR(gpu->obj, surface, &surface_capabilities);
if (err) ERR_EXIT(err);
if (html_output) {
fprintf(out, "\t\t\t\t\t<details><summary>VkSurfaceCapabilitiesKHR</summary>\n");
fprintf(out, "\t\t\t\t\t\t<details><summary>minImageCount = <span class='val'>%u</span></summary></details>\n",
surface_capabilities.minImageCount);
fprintf(out, "\t\t\t\t\t\t<details><summary>maxImageCount = <span class='val'>%u</span></summary></details>\n",
surface_capabilities.maxImageCount);
fprintf(out, "\t\t\t\t\t\t<details><summary>currentExtent</summary>\n");
fprintf(out, "\t\t\t\t\t\t\t<details><summary>width = <span class='val'>%u</span></summary></details>\n",
surface_capabilities.currentExtent.width);
fprintf(out, "\t\t\t\t\t\t\t<details><summary>height = <span class='val'>%u</span></summary></details>\n",
surface_capabilities.currentExtent.height);
fprintf(out, "\t\t\t\t\t\t</details>\n");
fprintf(out, "\t\t\t\t\t\t<details><summary>minImageExtent</summary>\n");
fprintf(out, "\t\t\t\t\t\t\t<details><summary>width = <span class='val'>%u</span></summary></details>\n",
surface_capabilities.minImageExtent.width);
fprintf(out, "\t\t\t\t\t\t\t<details><summary>height = <span class='val'>%u</span></summary></details>\n",
surface_capabilities.minImageExtent.height);
fprintf(out, "\t\t\t\t\t\t</details>\n");
fprintf(out, "\t\t\t\t\t\t<details><summary>maxImageExtent</summary>\n");
fprintf(out, "\t\t\t\t\t\t\t<details><summary>width = <span class='val'>%u</span></summary></details>\n",
surface_capabilities.maxImageExtent.width);
fprintf(out, "\t\t\t\t\t\t\t<details><summary>height = <span class='val'>%u</span></summary></details>\n",
surface_capabilities.maxImageExtent.height);
fprintf(out, "\t\t\t\t\t\t</details>\n");
fprintf(out, "\t\t\t\t\t\t<details><summary>maxImageArrayLayers = <span class='val'>%u</span></summary></details>\n",
surface_capabilities.maxImageArrayLayers);
fprintf(out, "\t\t\t\t\t\t<details><summary>supportedTransform</summary>\n");
if (surface_capabilities.supportedTransforms == 0) {
fprintf(out, "\t\t\t\t\t\t\t<details><summary>None</summary></details>\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR</span></summary></details>\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR</span></summary></details>\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR</span></summary></details>\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR</span></summary></details>\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR</span></summary></details>\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR</span></summary></details>\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR</span></summary></details>\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR</span></summary></details>\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR</span></summary></details>\n");
}
fprintf(out, "\t\t\t\t\t\t</details>\n");
fprintf(out, "\t\t\t\t\t\t<details><summary>currentTransform</summary>\n");
if (surface_capabilities.currentTransform == 0) {
fprintf(out, "\t\t\t\t\t\t\t<details><summary>None</summary></details>\n");
}
if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR</span></summary></details>\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR</span></summary></details>\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR</span></summary></details>\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR</span></summary></details>\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR</span></summary></details>\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR</span></summary></details>\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR</span></summary></details>\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR</span></summary></details>\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR</span></summary></details>\n");
}
fprintf(out, "\t\t\t\t\t\t</details>\n");
fprintf(out, "\t\t\t\t\t\t<details><summary>supportedCompositeAlpha</summary>\n");
if (surface_capabilities.supportedCompositeAlpha == 0) {
fprintf(out, "\t\t\t\t\t\t\t<details><summary>None</summary></details>\n");
}
if (surface_capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR</span></summary></details>\n");
}
if (surface_capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR</span></summary></details>\n");
}
if (surface_capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR</span></summary></details>\n");
}
if (surface_capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR</span></summary></details>\n");
}
fprintf(out, "\t\t\t\t\t\t</details>\n");
fprintf(out, "\t\t\t\t\t\t<details><summary>supportedUsageFlags</summary>\n");
if (surface_capabilities.supportedUsageFlags == 0) {
fprintf(out, "\t\t\t\t\t\t\t<details><summary>None</summary></details>\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_TRANSFER_SRC_BIT</span></summary></details>\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_TRANSFER_DST_BIT</span></summary></details>\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT) {
fprintf(
out,
"\t\t\t\t\t\t\t<details><summary><span class='type'>VK_IMAGE_USAGE_SAMPLED_BIT</span></summary></details>\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_STORAGE_BIT) {
fprintf(
out,
"\t\t\t\t\t\t\t<details><summary><span class='type'>VK_IMAGE_USAGE_STORAGE_BIT</span></summary></details>\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT</span></summary></details>\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT</span></summary></details>\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT</span></summary></details>\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT</span></summary></details>\n");
}
fprintf(out, "\t\t\t\t\t\t</details>\n");
} else if (human_readable_output) {
printf("VkSurfaceCapabilitiesKHR:\n");
printf("\tminImageCount = %u\n", surface_capabilities.minImageCount);
printf("\tmaxImageCount = %u\n", surface_capabilities.maxImageCount);
printf("\tcurrentExtent:\n");
printf("\t\twidth = %u\n", surface_capabilities.currentExtent.width);
printf("\t\theight = %u\n", surface_capabilities.currentExtent.height);
printf("\tminImageExtent:\n");
printf("\t\twidth = %u\n", surface_capabilities.minImageExtent.width);
printf("\t\theight = %u\n", surface_capabilities.minImageExtent.height);
printf("\tmaxImageExtent:\n");
printf("\t\twidth = %u\n", surface_capabilities.maxImageExtent.width);
printf("\t\theight = %u\n", surface_capabilities.maxImageExtent.height);
printf("\tmaxImageArrayLayers = %u\n", surface_capabilities.maxImageArrayLayers);
printf("\tsupportedTransform:\n");
if (surface_capabilities.supportedTransforms == 0) {
printf("\t\tNone\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR\n");
}
if (surface_capabilities.supportedTransforms & VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_INHERIT_BIT_KHR\n");
}
printf("\tcurrentTransform:\n");
if (surface_capabilities.currentTransform == 0) {
printf("\t\tNone\n");
}
if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_ROTATE_90_BIT_KHR\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_ROTATE_180_BIT_KHR\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_ROTATE_270_BIT_KHR\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_BIT_KHR\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_90_BIT_KHR\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_180_BIT_KHR\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_HORIZONTAL_MIRROR_ROTATE_270_BIT_KHR\n");
} else if (surface_capabilities.currentTransform & VK_SURFACE_TRANSFORM_INHERIT_BIT_KHR) {
printf("\t\tVK_SURFACE_TRANSFORM_INHERIT_BIT_KHR\n");
}
printf("\tsupportedCompositeAlpha:\n");
if (surface_capabilities.supportedCompositeAlpha == 0) {
printf("\t\tNone\n");
}
if (surface_capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR) {
printf("\t\tVK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR\n");
}
if (surface_capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR) {
printf("\t\tVK_COMPOSITE_ALPHA_PRE_MULTIPLIED_BIT_KHR\n");
}
if (surface_capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR) {
printf("\t\tVK_COMPOSITE_ALPHA_POST_MULTIPLIED_BIT_KHR\n");
}
if (surface_capabilities.supportedCompositeAlpha & VK_COMPOSITE_ALPHA_INHERIT_BIT_KHR) {
printf("\t\tVK_COMPOSITE_ALPHA_INHERIT_BIT_KHR\n");
}
printf("\tsupportedUsageFlags:\n");
if (surface_capabilities.supportedUsageFlags == 0) {
printf("\t\tNone\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) {
printf("\t\tVK_IMAGE_USAGE_TRANSFER_SRC_BIT\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) {
printf("\t\tVK_IMAGE_USAGE_TRANSFER_DST_BIT\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT) {
printf("\t\tVK_IMAGE_USAGE_SAMPLED_BIT\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_STORAGE_BIT) {
printf("\t\tVK_IMAGE_USAGE_STORAGE_BIT\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
printf("\t\tVK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
printf("\t\tVK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) {
printf("\t\tVK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT\n");
}
if (surface_capabilities.supportedUsageFlags & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) {
printf("\t\tVK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT\n");
}
}
// Get additional surface capability information from vkGetPhysicalDeviceSurfaceCapabilities2EXT
if (CheckExtensionEnabled(VK_EXT_DISPLAY_SURFACE_COUNTER_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
VkSurfaceCapabilities2EXT surface_capabilities2_ext = {VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_EXT};
err = inst->vkGetPhysicalDeviceSurfaceCapabilities2EXT(gpu->obj, surface, &surface_capabilities2_ext);
if (err) ERR_EXIT(err);
if (html_output) {
fprintf(out, "\t\t\t\t\t\t<details><summary>VkSurfaceCapabilities2EXT</summary>\n");
fprintf(out, "\t\t\t\t\t\t\t<details><summary>supportedSurfaceCounters</summary>\n");
if (surface_capabilities2_ext.supportedSurfaceCounters == 0) {
fprintf(out, "\t\t\t\t\t\t\t\t<details><summary>None</summary></details>\n");
}
if (surface_capabilities2_ext.supportedSurfaceCounters & VK_SURFACE_COUNTER_VBLANK_EXT) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_SURFACE_COUNTER_VBLANK_EXT</span></summary></details>\n");
}
fprintf(out, "\t\t\t\t\t\t\t</details>\n");
fprintf(out, "\t\t\t\t\t\t</details>\n");
} else if (human_readable_output) {
printf("VkSurfaceCapabilities2EXT:\n");
printf("\tsupportedSurfaceCounters:\n");
if (surface_capabilities2_ext.supportedSurfaceCounters == 0) {
printf("\t\tNone\n");
}
if (surface_capabilities2_ext.supportedSurfaceCounters & VK_SURFACE_COUNTER_VBLANK_EXT) {
printf("\t\tVK_SURFACE_COUNTER_VBLANK_EXT\n");
}
}
}
// Get additional surface capability information from vkGetPhysicalDeviceSurfaceCapabilities2KHR
if (CheckExtensionEnabled(VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
VkSurfaceCapabilities2KHR surface_capabilities2;
struct pNextChainBuildingBlockInfo sur_cap2_chain_info[] = {
{.sType = VK_STRUCTURE_TYPE_SHARED_PRESENT_SURFACE_CAPABILITIES_KHR,
.mem_size = sizeof(VkSharedPresentSurfaceCapabilitiesKHR)}};
uint32_t sur_cap2_chain_info_len = ARRAY_SIZE(sur_cap2_chain_info);
surface_capabilities2.sType = VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_2_KHR;
buildpNextChain((struct VkStructureHeader *)&surface_capabilities2, sur_cap2_chain_info, sur_cap2_chain_info_len);
VkPhysicalDeviceSurfaceInfo2KHR surface_info;
surface_info.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SURFACE_INFO_2_KHR;
surface_info.pNext = NULL;
surface_info.surface = surface;
err = inst->vkGetPhysicalDeviceSurfaceCapabilities2KHR(gpu->obj, &surface_info, &surface_capabilities2);
if (err) ERR_EXIT(err);
void *place = surface_capabilities2.pNext;
while (place) {
struct VkStructureHeader *work = (struct VkStructureHeader *)place;
if (work->sType == VK_STRUCTURE_TYPE_SHARED_PRESENT_SURFACE_CAPABILITIES_KHR &&
CheckExtensionEnabled(VK_KHR_SHARED_PRESENTABLE_IMAGE_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
VkSharedPresentSurfaceCapabilitiesKHR *shared_surface_capabilities =
(VkSharedPresentSurfaceCapabilitiesKHR *)place;
if (html_output) {
fprintf(out, "\t\t\t\t\t\t<details><summary>VkSharedPresentSurfaceCapabilitiesKHR</summary>\n");
fprintf(out, "\t\t\t\t\t\t\t<details><summary>sharedPresentSupportedUsageFlags</summary>\n");
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags == 0) {
fprintf(out, "\t\t\t\t\t\t\t\t<details><summary>None</summary></details>\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_TRANSFER_SRC_BIT</span></summary></details>\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_TRANSFER_DST_BIT</span></summary></details>\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_SAMPLED_BIT</span></summary></details>\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_STORAGE_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_STORAGE_BIT</span></summary></details>\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT</span></summary></details>\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags &
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT</span></summary></details>\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags &
VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT</span></summary></details>\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) {
fprintf(out,
"\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT</span></summary></details>\n");
}
fprintf(out, "\t\t\t\t\t\t\t</details>\n");
fprintf(out, "\t\t\t\t\t\t</details>\n");
} else if (human_readable_output) {
printf("VkSharedPresentSurfaceCapabilitiesKHR:\n");
printf("\tsharedPresentSupportedUsageFlags:\n");
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags == 0) {
printf("\t\tNone\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_SRC_BIT) {
printf("\t\tVK_IMAGE_USAGE_TRANSFER_SRC_BIT\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_TRANSFER_DST_BIT) {
printf("\t\tVK_IMAGE_USAGE_TRANSFER_DST_BIT\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_SAMPLED_BIT) {
printf("\t\tVK_IMAGE_USAGE_SAMPLED_BIT\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_STORAGE_BIT) {
printf("\t\tVK_IMAGE_USAGE_STORAGE_BIT\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT) {
printf("\t\tVK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags &
VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT) {
printf("\t\tVK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags &
VK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT) {
printf("\t\tVK_IMAGE_USAGE_TRANSIENT_ATTACHMENT_BIT\n");
}
if (shared_surface_capabilities->sharedPresentSupportedUsageFlags & VK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT) {
printf("\t\tVK_IMAGE_USAGE_INPUT_ATTACHMENT_BIT\n");
}
}
} else if (work->sType == VK_STRUCTURE_TYPE_SURFACE_PROTECTED_CAPABILITIES_KHR &&
CheckExtensionEnabled(VK_KHR_SURFACE_PROTECTED_CAPABILITIES_EXTENSION_NAME, gpu->inst->inst_extensions,
gpu->inst->inst_extensions_count)) {
VkSurfaceProtectedCapabilitiesKHR *protected_surface_capabilities = (VkSurfaceProtectedCapabilitiesKHR *)place;
if (html_output) {
fprintf(out, "\t\t\t\t\t\t<details><summary>VkSurfaceProtectedCapabilities</summary>\n");
fprintf(out,
"\t\t\t\t\t\t\t<details><summary>supportsProtected = <span class='val'>%" PRIuLEAST32
"</span></summary></details>\n",
protected_surface_capabilities->supportsProtected);
fprintf(out, "\t\t\t\t\t\t</details>\n");
} else if (human_readable_output) {
printf("VkSurfaceProtectedCapabilities\n");
printf("\tsupportsProtected = %" PRIuLEAST32 "\n", protected_surface_capabilities->supportsProtected);
}
}
place = work->pNext;
}
}
if (html_output) {
fprintf(out, "\t\t\t\t\t</details>\n");
}
}
}
static void AppDumpSurfaceExtension(struct AppInstance *inst, struct AppGpu *gpus, uint32_t gpu_count,
struct SurfaceExtensionNode *surface_extension, int *format_count, int *present_mode_count,
FILE *out) {
if (!CheckExtensionEnabled(surface_extension->name, inst->inst_extensions, inst->inst_extensions_count)) {
return;
}
for (uint32_t i = 0; i < gpu_count; ++i) {
if (html_output) {
fprintf(out, "\t\t\t\t<details><summary>GPU id : <span class='val'>%u</span> (%s)</summary>\n", i,
gpus[i].props.deviceName);
fprintf(out, "\t\t\t\t\t<details><summary>Surface type : <span class='type'>%s</span></summary></details>\n",
surface_extension->name);
} else if (human_readable_output) {
printf("GPU id : %u (%s)\n", i, gpus[i].props.deviceName);
printf("Surface type : %s\n", surface_extension->name);
}
*format_count += AppDumpSurfaceFormats(inst, &gpus[i], surface_extension->surface, out);
*present_mode_count += AppDumpSurfacePresentModes(inst, &gpus[i], surface_extension->surface, out);
AppDumpSurfaceCapabilities(inst, &gpus[i], surface_extension->surface, out);
if (html_output) {
fprintf(out, "\t\t\t\t</details>\n");
} else if (human_readable_output) {
printf("\n");
}
}
}
#endif
static void AppDevDumpFormatProps(const struct AppGpu *gpu, VkFormat fmt, bool *first_in_list, FILE *out) {
VkFormatProperties props;
vkGetPhysicalDeviceFormatProperties(gpu->obj, fmt, &props);
struct {
const char *name;
VkFlags flags;
} features[3];
features[0].name = "linearTiling FormatFeatureFlags";
features[0].flags = props.linearTilingFeatures;
features[1].name = "optimalTiling FormatFeatureFlags";
features[1].flags = props.optimalTilingFeatures;
features[2].name = "bufferFeatures FormatFeatureFlags";
features[2].flags = props.bufferFeatures;
if (html_output) {
fprintf(out, "\t\t\t\t\t\t<details><summary><span class='type'>FORMAT_%s</span></summary>\n", VkFormatString(fmt));
} else if (human_readable_output) {
printf("\nFORMAT_%s:", VkFormatString(fmt));
}
for (uint32_t i = 0; i < ARRAY_SIZE(features); ++i) {
if (html_output) {
fprintf(out, "\t\t\t\t\t\t\t<details open><summary>%s</summary>\n", features[i].name);
if (features[i].flags == 0) {
fprintf(out, "\t\t\t\t\t\t\t\t<details><summary>None</summary></details>\n");
} else {
fprintf(
out, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
((features[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) ? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_SAMPLED_IMAGE_"
"BIT</span></summary></details>\n"
: ""), // 0x0001
((features[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) ? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_STORAGE_IMAGE_"
"BIT</span></summary></details>\n"
: ""), // 0x0002
((features[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT)
? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT</span></summary></details>\n"
: ""), // 0x0004
((features[i].flags & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT)
? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT</span></summary></details>\n"
: ""), // 0x0008
((features[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT)
? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT</span></summary></details>\n"
: ""), // 0x0010
((features[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT)
? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT</span></summary></details>\n"
: ""), // 0x0020
((features[i].flags & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) ? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_VERTEX_BUFFER_"
"BIT</span></summary></details>\n"
: ""), // 0x0040
((features[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) ? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_COLOR_"
"ATTACHMENT_BIT</span></summary></details>\n"
: ""), // 0x0080
((features[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT)
? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT</span></summary></details>\n"
: ""), // 0x0100
((features[i].flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT</span></summary></details>\n"
: ""), // 0x0200
((features[i].flags & VK_FORMAT_FEATURE_BLIT_SRC_BIT) ? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_BLIT_SRC_BIT</"
"span></summary></details>\n"
: ""), // 0x0400
((features[i].flags & VK_FORMAT_FEATURE_BLIT_DST_BIT) ? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_BLIT_DST_BIT</"
"span></summary></details>\n"
: ""), // 0x0800
((features[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT)
? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT</span></summary></details>\n"
: ""), // 0x1000
((features[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG)
? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG</span></summary></details>\n"
: ""), // 0x2000
((features[i].flags & VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR) ? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_TRANSFER_"
"SRC_BIT_KHR</span></summary></details>\n"
: ""), // 0x4000
((features[i].flags & VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR) ? "\t\t\t\t\t\t\t\t<details><summary><span "
"class='type'>VK_FORMAT_FEATURE_TRANSFER_"
"DST_BIT_KHR</span></summary></details>\n"
: "")); // 0x8000
}
fprintf(out, "\t\t\t\t\t\t\t</details>\n");
} else if (human_readable_output) {
printf("\n\t%s:", features[i].name);
if (features[i].flags == 0) {
printf("\n\t\tNone");
} else {
printf(
"%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
((features[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT) ? "\n\t\tVK_FORMAT_FEATURE_SAMPLED_IMAGE_BIT"
: ""), // 0x0001
((features[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_BIT) ? "\n\t\tVK_FORMAT_FEATURE_STORAGE_IMAGE_BIT"
: ""), // 0x0002
((features[i].flags & VK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT)
? "\n\t\tVK_FORMAT_FEATURE_STORAGE_IMAGE_ATOMIC_BIT"
: ""), // 0x0004
((features[i].flags & VK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT)
? "\n\t\tVK_FORMAT_FEATURE_UNIFORM_TEXEL_BUFFER_BIT"
: ""), // 0x0008
((features[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT)
? "\n\t\tVK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_BIT"
: ""), // 0x0010
((features[i].flags & VK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT)
? "\n\t\tVK_FORMAT_FEATURE_STORAGE_TEXEL_BUFFER_ATOMIC_BIT"
: ""), // 0x0020
((features[i].flags & VK_FORMAT_FEATURE_VERTEX_BUFFER_BIT) ? "\n\t\tVK_FORMAT_FEATURE_VERTEX_BUFFER_BIT"
: ""), // 0x0040
((features[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT) ? "\n\t\tVK_FORMAT_FEATURE_COLOR_ATTACHMENT_BIT"
: ""), // 0x0080
((features[i].flags & VK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT)
? "\n\t\tVK_FORMAT_FEATURE_COLOR_ATTACHMENT_BLEND_BIT"
: ""), // 0x0100
((features[i].flags & VK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT)
? "\n\t\tVK_FORMAT_FEATURE_DEPTH_STENCIL_ATTACHMENT_BIT"
: ""), // 0x0200
((features[i].flags & VK_FORMAT_FEATURE_BLIT_SRC_BIT) ? "\n\t\tVK_FORMAT_FEATURE_BLIT_SRC_BIT" : ""), // 0x0400
((features[i].flags & VK_FORMAT_FEATURE_BLIT_DST_BIT) ? "\n\t\tVK_FORMAT_FEATURE_BLIT_DST_BIT" : ""), // 0x0800
((features[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT)
? "\n\t\tVK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_LINEAR_BIT"
: ""), // 0x1000
((features[i].flags & VK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG)
? "\n\t\tVK_FORMAT_FEATURE_SAMPLED_IMAGE_FILTER_CUBIC_BIT_IMG"
: ""), // 0x2000
((features[i].flags & VK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR) ? "\n\t\tVK_FORMAT_FEATURE_TRANSFER_SRC_BIT_KHR"
: ""), // 0x4000
((features[i].flags & VK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR) ? "\n\t\tVK_FORMAT_FEATURE_TRANSFER_DST_BIT_KHR"
: "")); // 0x8000
}
}
}
if (html_output) {
fprintf(out, "\t\t\t\t\t\t</details>\n");
} else if (human_readable_output) {
printf("\n");
}
if (json_output && (props.linearTilingFeatures || props.optimalTilingFeatures || props.bufferFeatures)) {
if (!(*first_in_list)) {
printf(",");
} else {
*first_in_list = false;
}
printf("\n");
printf("\t\t{\n");
printf("\t\t\t\"formatID\": %d,\n", fmt);
printf("\t\t\t\"linearTilingFeatures\": %u,\n", props.linearTilingFeatures);
printf("\t\t\t\"optimalTilingFeatures\": %u,\n", props.optimalTilingFeatures);
printf("\t\t\t\"bufferFeatures\": %u\n", props.bufferFeatures);
printf("\t\t}");
}
}
/* This structure encodes all the format ranges to be queried.
* It ensures that a format is not queried if the instance
* doesn't support it (either through the instance version or
* through extensions).
*/
static struct FormatRange {
// the Vulkan standard version that supports this format range, or 0 if non-standard
uint32_t minimum_instance_version;
// The name of the extension that supports this format range, or NULL if the range
// is only part of the standard
char *extension_name;
// The first and last supported formats within this range.
VkFormat first_format;
VkFormat last_format;
} supported_format_ranges[] = {
{
// Standard formats in Vulkan 1.0
VK_MAKE_VERSION(1, 0, 0),
NULL,
VK_FORMAT_BEGIN_RANGE,
VK_FORMAT_END_RANGE,
},
{
// YCBCR extension, standard in Vulkan 1.1
VK_MAKE_VERSION(1, 1, 0),
VK_KHR_SAMPLER_YCBCR_CONVERSION_EXTENSION_NAME,
VK_FORMAT_G8B8G8R8_422_UNORM,
VK_FORMAT_G16_B16_R16_3PLANE_444_UNORM,
},
{
// PVRTC extension, not standardized
0,
VK_IMG_FORMAT_PVRTC_EXTENSION_NAME,
VK_FORMAT_PVRTC1_2BPP_UNORM_BLOCK_IMG,
VK_FORMAT_PVRTC2_4BPP_SRGB_BLOCK_IMG,
},
};
// Helper function to determine whether a format range is currently supported.
bool FormatRangeSupported(const struct FormatRange *format_range, const struct AppGpu *gpu) {
// True if standard and supported by both this instance and this GPU
if (format_range->minimum_instance_version > 0 && gpu->inst->instance_version >= format_range->minimum_instance_version &&
gpu->props.apiVersion >= format_range->minimum_instance_version) {
return true;
}
// True if this extension is present
if (format_range->extension_name != NULL) {
return CheckExtensionEnabled(format_range->extension_name, gpu->inst->inst_extensions, gpu->inst->inst_extensions_count);
}
// Otherwise, not supported.
return false;
}
bool FormatPropsEq(const VkFormatProperties *props1, const VkFormatProperties *props2) {
if (props1->bufferFeatures == props2->bufferFeatures && props1->linearTilingFeatures == props2->linearTilingFeatures &&
props1->optimalTilingFeatures == props2->optimalTilingFeatures) {
return true;
} else {
return false;
}
}
struct PropFormats {
VkFormatProperties props;
uint32_t format_count;
uint32_t format_reserve;
VkFormat *formats;
};
void FormatPropsShortenedDump(const struct AppGpu *gpu) {
const VkFormatProperties unsupported_prop = {0};
uint32_t unique_props_count = 1;
uint32_t unique_props_reserve = 50;
struct PropFormats *prop_map = malloc(sizeof(struct PropFormats) * unique_props_reserve);
if (!prop_map) ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
prop_map[0].props = unsupported_prop;
prop_map[0].format_count = 0;
prop_map[0].format_reserve = 20;
prop_map[0].formats = malloc(sizeof(VkFormat) * prop_map[0].format_reserve);
if (!prop_map[0].formats) ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
for (uint32_t ri = 0; ri < ARRAY_SIZE(supported_format_ranges); ++ri) {
struct FormatRange format_range = supported_format_ranges[ri];
if (FormatRangeSupported(&format_range, gpu)) {
for (VkFormat fmt = format_range.first_format; fmt <= format_range.last_format; ++fmt) {
VkFormatProperties props;
vkGetPhysicalDeviceFormatProperties(gpu->obj, fmt, &props);
uint32_t formats_prop_i = 0;
for (; formats_prop_i < unique_props_count; ++formats_prop_i) {
if (FormatPropsEq(&prop_map[formats_prop_i].props, &props)) break;
}
if (formats_prop_i < unique_props_count) {
struct PropFormats *propFormats = &prop_map[formats_prop_i];
++propFormats->format_count;
if (propFormats->format_count > propFormats->format_reserve) {
propFormats->format_reserve *= 2;
propFormats->formats = realloc(propFormats->formats, sizeof(VkFormat) * propFormats->format_reserve);
if (!propFormats->formats) ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
}
propFormats->formats[propFormats->format_count - 1] = fmt;
} else {
assert(formats_prop_i == unique_props_count);
++unique_props_count;
if (unique_props_count > unique_props_reserve) {
unique_props_reserve *= 2;
prop_map = realloc(prop_map, sizeof(struct PropFormats) * unique_props_reserve);
if (!prop_map) ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);
}
struct PropFormats *propFormats = &prop_map[formats_prop_i];
propFormats->props = props;
propFormats->format_count = 1;
propFormats->format_reserve = 20;
propFormats->formats = malloc(sizeof(VkFormat) * propFormats->format_reserve);
if (!propFormats->formats) ERR_EXIT(VK_ERROR_OUT_OF_HOST_MEMORY);