Skip to content

Commit 6983188

Browse files
committed
Upd wrappers.
1 parent 546c2f4 commit 6983188

File tree

5 files changed

+138
-108
lines changed

5 files changed

+138
-108
lines changed

moltenVK/vk_mvk_moltenvk.h

+131-27
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,43 @@
2121
#ifdef __cplusplus
2222
extern "C" {
2323
#endif // __cplusplus
24-
25-
#include <vulkan/vulkan.h>
2624

2725

28-
#define VK_MVK_MOLTENVK_SPEC_VERSION 1
26+
#ifdef __OBJC__
27+
#import <Metal/Metal.h>
28+
#import <IOSurface/IOSurfaceRef.h>
29+
#endif
30+
31+
32+
#define VK_MVK_MOLTENVK_SPEC_VERSION 3
2933
#define VK_MVK_MOLTENVK_EXTENSION_NAME "VK_MVK_moltenvk"
3034

3135
/** MoltenVK configuration settings. */
3236
typedef struct {
33-
VkBool32 supportLargeQueryPools; /**< Metal allows only 8192 occlusion queries per MTLBuffer. If enabled, MoltenVK allocates a MTLBuffer for each query pool, allowing each query pool to support 8192 queries, which may slow performance or cause unexpected behaviour if the query pool is not established prior to a Metal renderpass, or if the query pool is changed within a Metal renderpass. If disabled, one MTLBuffer will be shared by all query pools, which improves performance, but limits the total device queries to 8192. Default is false. */
34-
VkBool32 imageFlipY; /**< If enabled, images will be flipped on the Y-axis, as Vulkan coordinate system is inverse of OpenGL. Default is false. */
37+
VkBool32 debugMode; /**< If enabled, several debugging capabilities will be enabled. Shader code will be logged during Runtime Shader Conversion. Improves support for Xcode GPU Frame Capture. Default is false. */
3538
VkBool32 shaderConversionFlipVertexY; /**< If enabled, MSL vertex shader code created during Runtime Shader Conversion will flip the Y-axis of each vertex, as Vulkan coordinate system is inverse of OpenGL. Default is true. */
36-
VkBool32 shaderConversionLogging; /**< If enabled, both SPIR-V and MSL code will be logged during Runtime Shader Conversion. Default is false. */
37-
VkBool32 performanceTracking; /**< If enabled, per-frame performance statistics are tracked, and can be retrieved via the API. Default is false. */
39+
VkBool32 supportLargeQueryPools; /**< Metal allows only 8192 occlusion queries per MTLBuffer. If enabled, MoltenVK allocates a MTLBuffer for each query pool, allowing each query pool to support 8192 queries, which may slow performance or cause unexpected behaviour if the query pool is not established prior to a Metal renderpass, or if the query pool is changed within a Metal renderpass. If disabled, one MTLBuffer will be shared by all query pools, which improves performance, but limits the total device queries to 8192. Default is false. */
40+
VkBool32 performanceTracking; /**< If enabled, per-frame performance statistics are tracked, optionally logged, and can be retrieved via the vkGetSwapchainPerformanceMVK() function, and various shader compilation performance statistics are tracked, logged, and can be retrieved via the vkGetShaderCompilationPerformanceMVK() function. Default is false. */
3841
uint32_t performanceLoggingFrameCount; /**< If non-zero, performance statistics will be periodically logged to the console, on a repeating cycle of this many frames per swapchain. The performanceTracking capability must also be enabled. Default is zero, indicating no logging. */
3942
} MVKDeviceConfiguration;
4043

4144
/** Features provided by the current implementation of Metal on the current device. */
4245
typedef struct {
43-
VkBool32 indirectDrawing; /**< Draw calls support parameters held in a GPU buffer. */
44-
VkBool32 baseVertexInstanceDrawing; /**< Draw calls support specifiying the base vertex and instance. */
45-
VkBool32 dynamicMTLBuffers; /**< Dynamic MTLBuffers supported for setting vertex, fragment, and compute bytes. */
46-
uint32_t maxPerStageBufferCount; /**< The total number of per-stage Metal buffers available for shader uniform content and attributes. */
47-
uint32_t maxPerStageTextureCount; /**< The total number of per-stage Metal textures available for shader uniform content. */
48-
uint32_t maxPerStageSamplerCount; /**< The total number of per-stage Metal samplers available for shader uniform content. */
49-
VkDeviceSize maxMTLBufferSize; /**< The max size of a MTLBuffer (in bytes). */
50-
VkDeviceSize mtlBufferAlignment; /**< The alignment used when allocating memory for MTLBuffers. */
51-
VkDeviceSize maxQueryBufferSize; /**< The maximum size of an occlusion query buffer (in bytes). */
46+
float mslVersion; /**< The version of the Metal Shading Language available on this device. */
47+
VkBool32 indirectDrawing; /**< If true, draw calls support parameters held in a GPU buffer. */
48+
VkBool32 baseVertexInstanceDrawing; /**< If true, draw calls support specifiying the base vertex and instance. */
49+
VkBool32 dynamicMTLBuffers; /**< If true, dynamic MTLBuffers for setting vertex, fragment, and compute bytes are supported. */
50+
VkBool32 shaderSpecialization; /**< If true, shader specialization (aka Metal function constants) is supported. */
51+
VkBool32 ioSurfaces; /**< If true, VkImages can be underlaid by IOSurfaces via the vkUseIOSurfaceMVK() function, to support inter-process image transfers. */
52+
VkBool32 texelBuffers; /**< If true, texel buffers are supported, allowing the contents of a buffer to be interpreted as an image via a VkBufferView. */
53+
VkBool32 depthClipMode; /**< If true, the device supports both depth clipping and depth clamping per the depthClampEnable flag of VkPipelineRasterizationStateCreateInfo in VkGraphicsPipelineCreateInfo. */
54+
uint32_t maxPerStageBufferCount; /**< The total number of per-stage Metal buffers available for shader uniform content and attributes. */
55+
uint32_t maxPerStageTextureCount; /**< The total number of per-stage Metal textures available for shader uniform content. */
56+
uint32_t maxPerStageSamplerCount; /**< The total number of per-stage Metal samplers available for shader uniform content. */
57+
VkDeviceSize maxMTLBufferSize; /**< The max size of a MTLBuffer (in bytes). */
58+
VkDeviceSize mtlBufferAlignment; /**< The alignment used when allocating memory for MTLBuffers. Must be PoT. */
59+
VkDeviceSize maxQueryBufferSize; /**< The maximum size of an occlusion query buffer (in bytes). */
60+
VkSampleCountFlags supportedSampleCounts; /**< A bitmask identifying the sample counts supported by the device. */
5261
} MVKPhysicalDeviceMetalFeatures;
5362

5463
/** MoltenVK swapchain performance statistics. */
@@ -58,16 +67,44 @@ typedef struct {
5867
double averageFramesPerSecond; /**< The rolling average number of frames per second. This is simply the inverse of the averageFrameInterval value. */
5968
} MVKSwapchainPerformance;
6069

70+
/** MoltenVK performance of a particular type of shader compilation event. */
71+
typedef struct {
72+
uint32_t count; /**< The number of compilation events of this type. */
73+
double averageInterval; /**< The average time interval consumed by the compilation event, in seconds. */
74+
double minimumInterval; /**< The minimum time interval consumed by the compilation event, in seconds. */
75+
double maximumInterval; /**< The maximum time interval consumed by the compilation event, in seconds. */
76+
} MVKShaderCompilationEventPerformance;
77+
78+
/** MoltenVK performance of shader compilation events for a VkDevice. */
79+
typedef struct {
80+
MVKShaderCompilationEventPerformance spirvToMSL; /** Convert SPIR-V to MSL source code. */
81+
MVKShaderCompilationEventPerformance mslCompile; /** Compile MSL source code into a MTLLibrary. */
82+
MVKShaderCompilationEventPerformance mslLoad; /** Load pre-compiled MSL code into a MTLLibrary. */
83+
MVKShaderCompilationEventPerformance functionRetrieval; /** Retrieve a MTLFunction from a MTLLibrary. */
84+
MVKShaderCompilationEventPerformance functionSpecialization; /** Specialize a retrieved MTLFunction. */
85+
MVKShaderCompilationEventPerformance pipelineCompile; /** Compile MTLFunctions into a pipeline. */
86+
} MVKShaderCompilationPerformance;
87+
6188

6289
#pragma mark -
6390
#pragma mark Function types
6491

6592
typedef VkResult (VKAPI_PTR *PFN_vkActivateMoltenVKLicenseMVK)(const char* licenseID, const char* licenseKey, VkBool32 acceptLicenseTermsAndConditions);
6693
typedef VkResult (VKAPI_PTR *PFN_vkActivateMoltenVKLicensesMVK)();
67-
typedef VkResult (VKAPI_PTR *PFN_vkGetMoltenVKDeviceConfigurationMVK)(VkDevice device, MVKDeviceConfiguration* pConfiguration);
94+
typedef void (VKAPI_PTR *PFN_vkGetMoltenVKDeviceConfigurationMVK)(VkDevice device, MVKDeviceConfiguration* pConfiguration);
6895
typedef VkResult (VKAPI_PTR *PFN_vkSetMoltenVKDeviceConfigurationMVK)(VkDevice device, MVKDeviceConfiguration* pConfiguration);
69-
typedef VkResult (VKAPI_PTR *PFN_vkGetPhysicalDeviceMetalFeaturesMVK)(VkPhysicalDevice physicalDevice, MVKPhysicalDeviceMetalFeatures* pMetalFeatures);
70-
typedef VkResult (VKAPI_PTR *PFN_vkGetSwapchainPerformanceMVK)(VkDevice device, VkSwapchainKHR swapchain, MVKSwapchainPerformance* pSwapchainPerf);
96+
typedef void (VKAPI_PTR *PFN_vkGetPhysicalDeviceMetalFeaturesMVK)(VkPhysicalDevice physicalDevice, MVKPhysicalDeviceMetalFeatures* pMetalFeatures);
97+
typedef void (VKAPI_PTR *PFN_vkGetSwapchainPerformanceMVK)(VkDevice device, VkSwapchainKHR swapchain, MVKSwapchainPerformance* pSwapchainPerf);
98+
typedef void (VKAPI_PTR *PFN_vkGetShaderCompilationPerformanceMVK)(VkDevice device, MVKShaderCompilationPerformance* pShaderCompPerf);
99+
typedef void (VKAPI_PTR *PFN_vkGetVersionStringsMVK)(char* pMoltenVersionStringBuffer, uint32_t moltenVersionStringBufferLength, char* pVulkanVersionStringBuffer, uint32_t vulkanVersionStringBufferLength);
100+
101+
#ifdef __OBJC__
102+
typedef void (VKAPI_PTR *PFN_vkGetMTLDeviceMVK)(VkPhysicalDevice physicalDevice, id<MTLDevice>* pMTLDevice);
103+
typedef VkResult (VKAPI_PTR *PFN_vkSetMTLTextureMVK)(VkImage image, id<MTLTexture> mtlTexture);
104+
typedef void (VKAPI_PTR *PFN_vkGetMTLTextureMVK)(VkImage image, id<MTLTexture>* pMTLTexture);
105+
typedef VkResult (VKAPI_PTR *PFN_vkUseIOSurfaceMVK)(VkImage image, IOSurfaceRef ioSurface);
106+
typedef void (VKAPI_PTR *PFN_vkGetIOSurfaceMVK)(VkImage image, IOSurfaceRef* pIOSurface);
107+
#endif // __OBJC__
71108

72109

73110
#pragma mark -
@@ -179,7 +216,7 @@ static inline void vkActivateMoltenVKLicensesMVK() {
179216
* to retrieve the current configuration, make changes, and call
180217
* vkSetMoltenVKDeviceConfigurationMVK() to update all of the values.
181218
*/
182-
VKAPI_ATTR VkResult VKAPI_CALL vkGetMoltenVKDeviceConfigurationMVK(
219+
VKAPI_ATTR void VKAPI_CALL vkGetMoltenVKDeviceConfigurationMVK(
183220
VkDevice device,
184221
MVKDeviceConfiguration* pConfiguration);
185222

@@ -199,32 +236,99 @@ VKAPI_ATTR VkResult VKAPI_CALL vkSetMoltenVKDeviceConfigurationMVK(
199236
* Populates the pMetalFeatures structure with the Metal-specific features
200237
* supported by the specified physical device.
201238
*/
202-
VKAPI_ATTR VkResult VKAPI_CALL vkGetPhysicalDeviceMetalFeaturesMVK(
239+
VKAPI_ATTR void VKAPI_CALL vkGetPhysicalDeviceMetalFeaturesMVK(
203240
VkPhysicalDevice physicalDevice,
204241
MVKPhysicalDeviceMetalFeatures* pMetalFeatures);
205242

206243
/**
207244
* Populates the specified MVKSwapchainPerformance structure with
208245
* the current performance statistics for the specified swapchain.
209246
*/
210-
VKAPI_ATTR VkResult VKAPI_CALL vkGetSwapchainPerformanceMVK(
247+
VKAPI_ATTR void VKAPI_CALL vkGetSwapchainPerformanceMVK(
211248
VkDevice device,
212249
VkSwapchainKHR swapchain,
213250
MVKSwapchainPerformance* pSwapchainPerf);
214251

252+
/**
253+
* Populates the specified MVKShaderCompilationPerformance structure with the
254+
* current shader compilation performance statistics for the specified device.
255+
*/
256+
VKAPI_ATTR void VKAPI_CALL vkGetShaderCompilationPerformanceMVK(
257+
VkDevice device,
258+
MVKShaderCompilationPerformance* pShaderCompPerf);
259+
215260
/**
216261
* Returns a human readable version of the MoltenVK and Vulkan versions.
217262
*
218263
* This function is provided as a convenience for reporting. Use the MLN_VERSION,
219264
* VK_API_VERSION_1_0, and VK_HEADER_VERSION macros for programmatically accessing
220265
* the corresponding version numbers.
221266
*/
222-
VKAPI_ATTR VkResult VKAPI_CALL vkGetVersionStringsMVK(
223-
char* pMoltenVersionStringBuffer,
224-
uint32_t moltenVersionStringBufferLength,
225-
char* pVulkanVersionStringBuffer,
226-
uint32_t vulkanVersionStringBufferLength);
267+
VKAPI_ATTR void VKAPI_CALL vkGetVersionStringsMVK(
268+
char* pMoltenVersionStringBuffer,
269+
uint32_t moltenVersionStringBufferLength,
270+
char* pVulkanVersionStringBuffer,
271+
uint32_t vulkanVersionStringBufferLength);
272+
273+
274+
#ifdef __OBJC__
275+
276+
/** Returns, in the pMTLDevice pointer, the MTLDevice used by the VkPhysicalDevice. */
277+
VKAPI_ATTR void VKAPI_CALL vkGetMTLDeviceMVK(
278+
VkPhysicalDevice physicalDevice,
279+
id<MTLDevice>* pMTLDevice);
280+
281+
/**
282+
* Sets the VkImage to use the specified MTLTexture.
283+
*
284+
* Any differences in the properties of mtlTexture and this image will modify the
285+
* properties of this image.
286+
*
287+
* If a MTLTexture has already been created for this image, it will be destroyed.
288+
*
289+
* Returns VK_SUCCESS.
290+
*/
291+
VKAPI_ATTR VkResult VKAPI_CALL vkSetMTLTextureMVK(
292+
VkImage image,
293+
id<MTLTexture> mtlTexture);
294+
295+
/** Returns, in the pMTLTexture pointer, the MTLTexture currently underlaying the VkImage. */
296+
VKAPI_ATTR void VKAPI_CALL vkGetMTLTextureMVK(
297+
VkImage image,
298+
id<MTLTexture>* pMTLTexture);
299+
300+
/**
301+
* Indicates that a VkImage should use an IOSurface to underlay the Metal texture.
302+
*
303+
* If ioSurface is not null, it will be used as the IOSurface, and any differences
304+
* in the properties of that IOSurface will modify the properties of this image.
305+
*
306+
* If ioSurface is null, this image will create and use an IOSurface
307+
* whose properties are compatible with the properties of this image.
308+
*
309+
* If a MTLTexture has already been created for this image, it will be destroyed.
310+
*
311+
* Returns:
312+
* - VK_SUCCESS.
313+
* - VK_ERROR_FEATURE_NOT_PRESENT if IOSurfaces are not supported on the platform.
314+
* - VK_ERROR_INITIALIZATION_FAILED if ioSurface is specified and is not compatible with this VkImage.
315+
*/
316+
VKAPI_ATTR VkResult VKAPI_CALL vkUseIOSurfaceMVK(
317+
VkImage image,
318+
IOSurfaceRef ioSurface);
319+
320+
321+
/**
322+
* Returns, in the pIOSurface pointer, the IOSurface currently underlaying the VkImage,
323+
* as set by the useIOSurfaceMVK() function, or returns null if the VkImage is not using
324+
* an IOSurface, or if the platform does not support IOSurfaces.
325+
*/
326+
VKAPI_ATTR void VKAPI_CALL vkGetIOSurfaceMVK(
327+
VkImage image,
328+
IOSurfaceRef* pIOSurface);
329+
227330

331+
#endif // __OBJC__
228332

229333
#endif // VK_NO_PROTOTYPES
230334

vk_bridge.c

-18
Original file line numberDiff line numberDiff line change
@@ -1292,24 +1292,6 @@ VkBool32 callVkGetPhysicalDeviceWaylandPresentationSupportKHR(
12921292
}
12931293
#endif /* VK_USE_PLATFORM_WAYLAND_KHR */
12941294

1295-
#ifdef VK_USE_PLATFORM_MIR_KHR
1296-
VkResult callVkCreateMirSurfaceKHR(
1297-
VkInstance instance,
1298-
const VkMirSurfaceCreateInfoKHR* pCreateInfo,
1299-
const VkAllocationCallbacks* pAllocator,
1300-
VkSurfaceKHR* pSurface) {
1301-
return vgo_vkCreateMirSurfaceKHR(instance, pCreateInfo, pAllocator, pSurface);
1302-
}
1303-
1304-
VkBool32 callVkGetPhysicalDeviceMirPresentationSupportKHR(
1305-
VkPhysicalDevice physicalDevice,
1306-
uint32_t queueFamilyIndex,
1307-
MirConnection* connection) {
1308-
return vgo_vkGetPhysicalDeviceMirPresentationSupportKHR(physicalDevice,
1309-
queueFamilyIndex, connection);
1310-
}
1311-
#endif /* VK_USE_PLATFORM_MIR_KHR */
1312-
13131295
#ifdef VK_USE_PLATFORM_ANDROID_KHR
13141296
VkResult callVkCreateAndroidSurfaceKHR(
13151297
VkInstance instance,

vk_bridge.h

-13
Original file line numberDiff line numberDiff line change
@@ -947,19 +947,6 @@ VkBool32 callVkGetPhysicalDeviceWaylandPresentationSupportKHR(
947947
struct wl_display* display);
948948
#endif /* VK_USE_PLATFORM_WAYLAND_KHR */
949949

950-
#ifdef VK_USE_PLATFORM_MIR_KHR
951-
VkResult callVkCreateMirSurfaceKHR(
952-
VkInstance instance,
953-
const VkMirSurfaceCreateInfoKHR* pCreateInfo,
954-
const VkAllocationCallbacks* pAllocator,
955-
VkSurfaceKHR* pSurface);
956-
957-
VkBool32 callVkGetPhysicalDeviceMirPresentationSupportKHR(
958-
VkPhysicalDevice physicalDevice,
959-
uint32_t queueFamilyIndex,
960-
MirConnection* connection);
961-
#endif /* VK_USE_PLATFORM_MIR_KHR */
962-
963950
#ifdef VK_USE_PLATFORM_ANDROID_KHR
964951
VkResult callVkCreateAndroidSurfaceKHR(
965952
VkInstance instance,

vk_wrapper_android.c

-25
Original file line numberDiff line numberDiff line change
@@ -370,35 +370,10 @@ PFN_vkGetDisplayPlaneCapabilitiesKHR vgo_vkGetDisplayPlaneCapabilitiesKHR;
370370
PFN_vkCreateDisplayPlaneSurfaceKHR vgo_vkCreateDisplayPlaneSurfaceKHR;
371371
PFN_vkCreateSharedSwapchainsKHR vgo_vkCreateSharedSwapchainsKHR;
372372

373-
#ifdef VK_USE_PLATFORM_XLIB_KHR
374-
PFN_vkCreateXlibSurfaceKHR vgo_vkCreateXlibSurfaceKHR;
375-
PFN_vkGetPhysicalDeviceXlibPresentationSupportKHR vgo_vkGetPhysicalDeviceXlibPresentationSupportKHR;
376-
#endif
377-
378-
#ifdef VK_USE_PLATFORM_XCB_KHR
379-
PFN_vkCreateXcbSurfaceKHR vgo_vkCreateXcbSurfaceKHR;
380-
PFN_vkGetPhysicalDeviceXcbPresentationSupportKHR vgo_vkGetPhysicalDeviceXcbPresentationSupportKHR;
381-
#endif
382-
383-
#ifdef VK_USE_PLATFORM_WAYLAND_KHR
384-
PFN_vkCreateWaylandSurfaceKHR vgo_vkCreateWaylandSurfaceKHR;
385-
PFN_vkGetPhysicalDeviceWaylandPresentationSupportKHR vgo_vkGetPhysicalDeviceWaylandPresentationSupportKHR;
386-
#endif
387-
388-
#ifdef VK_USE_PLATFORM_MIR_KHR
389-
PFN_vkCreateMirSurfaceKHR vgo_vkCreateMirSurfaceKHR;
390-
PFN_vkGetPhysicalDeviceMirPresentationSupportKHR vgo_vkGetPhysicalDeviceMirPresentationSupportKHR;
391-
#endif
392-
393373
#ifdef VK_USE_PLATFORM_ANDROID_KHR
394374
PFN_vkCreateAndroidSurfaceKHR vgo_vkCreateAndroidSurfaceKHR;
395375
#endif
396376

397-
#ifdef VK_USE_PLATFORM_WIN32_KHR
398-
PFN_vkCreateWin32SurfaceKHR vgo_vkCreateWin32SurfaceKHR;
399-
PFN_vkGetPhysicalDeviceWin32PresentationSupportKHR vgo_vkGetPhysicalDeviceWin32PresentationSupportKHR;
400-
#endif
401-
402377
PFN_vkCreateDebugReportCallbackEXT vgo_vkCreateDebugReportCallbackEXT;
403378
PFN_vkDestroyDebugReportCallbackEXT vgo_vkDestroyDebugReportCallbackEXT;
404379
PFN_vkDebugReportMessageEXT vgo_vkDebugReportMessageEXT;

0 commit comments

Comments
 (0)