internal static SwapchainKhr[] CreateSharedKhr(Device parent, SwapchainCreateInfoKhr[] createInfos, ref AllocationCallbacks?allocator) { int count = createInfos?.Length ?? 0; var nativeCreateInfos = stackalloc SwapchainCreateInfoKhr.Native[count]; for (int i = 0; i < count; i++) { createInfos[i].ToNative(out nativeCreateInfos[i]); } AllocationCallbacks.Native nativeAllocator; allocator?.ToNative(&nativeAllocator); long * handles = stackalloc long[count]; Result result = vkCreateSharedSwapchainsKHR(parent, count, nativeCreateInfos, allocator.HasValue ? &nativeAllocator : null, handles); for (int i = 0; i < count; i++) { nativeCreateInfos[i].Free(); } VulkanException.ThrowForInvalidResult(result); var swapchains = new SwapchainKhr[count]; for (int i = 0; i < count; i++) { swapchains[i] = new SwapchainKhr(parent, handles[i], ref allocator); } return(swapchains); }
internal DebugReportCallbackExt(Instance parent, ref DebugReportCallbackCreateInfoExt createInfo, ref AllocationCallbacks?allocator) { Parent = parent; Allocator = allocator; Func <DebugReportCallbackInfo, bool> createInfoCallback = createInfo.Callback; IntPtr callbackHandle = IntPtr.Zero; if (createInfoCallback != null) { _callback = (flags, objectType, @object, location, messageCode, layerPrefix, message, userData) => createInfoCallback(new DebugReportCallbackInfo { Flags = flags, ObjectType = objectType, Object = @object, Location = location, MessageCode = messageCode, LayerPrefix = Interop.String.FromPointer(layerPrefix), Message = Interop.String.FromPointer(message), UserData = userData }); callbackHandle = Interop.GetFunctionPointerForDelegate(_callback); } createInfo.ToNative(out DebugReportCallbackCreateInfoExt.Native nativeCreateInfo, callbackHandle); long handle; Result result = vkCreateDebugReportCallbackEXT(Parent)(Parent, &nativeCreateInfo, NativeAllocator, &handle); VulkanException.ThrowForInvalidResult(result); Handle = handle; }
/// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static void AcquireAndroid(this Queue queue, Image image, int nativeFenceFd, Semaphore semaphore, Fence fence) { Result result = vkAcquireImageANDROID(queue)(queue, image, nativeFenceFd, semaphore, fence); VulkanException.ThrowForInvalidResult(result); }
/// <summary> /// Set the power state of a display. /// </summary> /// <param name="device">The display whose power state is modified.</param> /// <param name="display">A logical device associated with <paramref name="display"/>.</param> /// <param name="displayPowerInfo">Specifies the new power state of <paramref name="display"/>.</param> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static void DisplayPowerControlExt(this Device device, DisplayKhr display, DisplayPowerInfoExt displayPowerInfo) { displayPowerInfo.Prepare(); Result result = vkDisplayPowerControlEXT(device)(device, display, &displayPowerInfo); VulkanException.ThrowForInvalidResult(result); }
/// <summary> /// Query present capabilities from other physical devices. /// <para> /// A logical device that represents multiple physical devices may support presenting from /// images on more than one physical device, or combining images from multiple physical devices. /// </para> /// </summary> /// <param name="device">The logical device.</param> /// <returns>Structure that is filled with the logical device's capabilities.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static DeviceGroupPresentCapabilitiesKhx GetGroupPresentCapabilitiesKhx(this Device device) { DeviceGroupPresentCapabilitiesKhx capabilities; Result result = vkGetDeviceGroupPresentCapabilitiesKHX(device)(device, &capabilities); VulkanException.ThrowForInvalidResult(result); return(capabilities); }
/// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static int GetSwapchainGrallocUsageAndroid(this Device device, Format format, int imageUsage) { int usage; Result result = vkGetSwapchainGrallocUsageANDROID(device)(device, format, imageUsage, &usage); VulkanException.ThrowForInvalidResult(result); return(usage); }
/// <summary> /// Get a POSIX file descriptor for a memory object. /// </summary> /// <param name="memory">The memory object from which the handle will be exported.</param> /// <param name="handleType">The type of handle requested.</param> /// <returns>A file descriptor representing the underlying resources of the device memory object.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static int GetFdKhx(this DeviceMemory memory, ExternalMemoryHandleTypesKhx handleType) { int fd; Result result = vkGetMemoryFdKHX(memory.Parent, memory, handleType, &fd); VulkanException.ThrowForInvalidResult(result); return(fd); }
/// <summary> /// Query surface capabilities. /// </summary> /// <param name="physicalDevice"> /// The physical device that will be associated with the swapchain to be created, as /// described for <see cref="Khr.DeviceExtensions.CreateSwapchainKhr"/>. /// </param> /// <param name="surface">The surface that will be associated with the swapchain.</param> /// <returns>The structure in which the capabilities are returned.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static SurfaceCapabilities2Ext GetSurfaceCapabilities2Ext(this PhysicalDevice physicalDevice, SurfaceKhr surface) { SurfaceCapabilities2Ext capabilities; Result result = vkGetPhysicalDeviceSurfaceCapabilities2EXT(physicalDevice, surface, &capabilities); VulkanException.ThrowForInvalidResult(result); return(capabilities); }
/// <summary> /// Obtain the RC duration of the PE's display. /// </summary> /// <param name="swapchain">The swapchain to obtain the refresh duration for.</param> /// <returns>An instance of the <see cref="RefreshCycleDurationGoogle"/> structure.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static RefreshCycleDurationGoogle GetRefreshCycleDurationGoogle(this SwapchainKhr swapchain) { RefreshCycleDurationGoogle properties; Result result = vkGetRefreshCycleDurationGOOGLE(swapchain)(swapchain.Parent, swapchain, &properties); VulkanException.ThrowForInvalidResult(result); return(properties); }
/// <summary> /// Query present capabilities for a surface. /// <para>Some surfaces may not be capable of using all the device group present modes.</para> /// </summary> /// <param name="device">The logical device.</param> /// <param name="surface">The surface.</param> /// <returns> /// A value that is filled with the supported device group present modes for the surface. /// </returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static DeviceGroupPresentModesKhx GetGroupSurfacePresentModesKhx(this Device device, SurfaceKhr surface) { DeviceGroupPresentModesKhx modes; Result result = vkGetDeviceGroupSurfacePresentModesKHX(device)(device, surface, &modes); VulkanException.ThrowForInvalidResult(result); return(modes); }
/// <summary> /// Get a Windows HANDLE for a semaphore. /// </summary> /// <param name="semaphore">The semaphore from which state will be exported.</param> /// <param name="handleType">The type of handle requested.</param> /// <returns>The Windows handle representing the semaphore state.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static IntPtr GetWin32HandleKhx(this Semaphore semaphore, ExternalSemaphoreHandleTypesKhx handleType) { IntPtr handle; Result result = vkGetSemaphoreWin32HandleKHX(semaphore.Parent, semaphore, handleType, &handle); VulkanException.ThrowForInvalidResult(result); return(handle); }
/// <summary> /// Query capabilities of a mode and plane combination. /// <para> /// Applications that wish to present directly to a display must select which layer, or /// "plane" of the display they wish to target, and a mode to use with the display. /// </para> /// <para>Each display supports at least one plane.</para> /// </summary> /// <param name="planeIndex"> /// The plane which the application intends to use with the display, and is less than the /// number of display planes supported by the device. /// </param> /// <returns>The structure in which the capabilities are returned.</returns> public DisplayPlaneCapabilitiesKhr GetDisplayPlaneCapabilities(int planeIndex) { DisplayPlaneCapabilitiesKhr capabilities; Result result = vkGetDisplayPlaneCapabilitiesKHR(Parent.Parent, this, planeIndex, &capabilities); VulkanException.ThrowForInvalidResult(result); return(capabilities); }
/// <summary> /// Get a Windows HANDLE for a memory object. /// </summary> /// <param name="memory">The memory object from which the handle will be exported.</param> /// <param name="handleType">The type of handle requested.</param> /// <returns>The Windows handle representing the underlying resources of the device memory object.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static IntPtr GetWin32HandleKhx(this DeviceMemory memory, ExternalMemoryHandleTypesKhx handleType) { IntPtr handle; Result result = vkGetMemoryWin32HandleKHX(memory.Parent, memory, handleType, &handle); VulkanException.ThrowForInvalidResult(result); return(handle); }
/// <summary> /// Get a POSIX file descriptor handle for a semaphore. /// </summary> /// <param name="semaphore">The semaphore from which state will be exported.</param> /// <param name="handleType">The type of handle requested.</param> /// <returns>The file descriptor representing the semaphore state.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static int GetFdKhx(this Semaphore semaphore, ExternalSemaphoreHandleTypesKhx handleType) { int fd; Result result = vkGetSemaphoreFdKHX(semaphore.Parent, semaphore, handleType, &fd); VulkanException.ThrowForInvalidResult(result); return(fd); }
/// <summary> /// Query the current value of a surface counter. /// <para> /// The requested counters become active when the first presentation command for the /// associated swapchain is processed by the presentation engine. /// </para> /// </summary> /// <param name="swapchain">The swapchain from which to query the counter value.</param> /// <param name="counter">The counter to query.</param> /// <returns>The current value of the counter.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static long GetCounterExt(this SwapchainKhr swapchain, SurfaceCountersExt counter) { long counterValue; Result result = vkGetSwapchainCounterEXT(swapchain.Parent, swapchain, counter, &counterValue); VulkanException.ThrowForInvalidResult(result); return(counterValue); }
/// <summary> /// Retrieve the index of the next available presentable image. /// </summary> /// <param name="timeout"> /// Indicates how long the function waits, in nanoseconds, if no image is available. /// <para> /// If timeout is 0, the command will not block, but will either succeed or throw with <see /// cref="Result.NotReady"/>. If timeout is -1, the function will not return until an image /// is acquired from the presentation engine. Other values for timeout will cause the /// function to return when an image becomes available, or when the specified number of /// nanoseconds have passed (in which case it will return throw with <see /// cref="Result.Timeout"/>). An error can also cause the command to return early. /// </para> /// </param> /// <param name="semaphore"> /// <c>null</c> or a semaphore to signal. <paramref name="semaphore"/> and <paramref /// name="fence"/> must not both be equal to <c>null</c>. /// </param> /// <param name="fence"> /// <c>null</c> or a fence to signal. <paramref name="semaphore"/> and <paramref /// name="fence"/> must not both be equal to <c>null</c>. /// </param> /// <returns>The index of the next available presentable image.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public int AcquireNextImage(long timeout = ~0, Semaphore semaphore = null, Fence fence = null) { int nextImageIndex; Result result = vkAcquireNextImageKHR(Parent, this, timeout, semaphore, fence, &nextImageIndex); VulkanException.ThrowForInvalidResult(result); return(nextImageIndex); }
/// <summary> /// Query the <see cref="DisplayKhr"/> corresponding to an X11 RandR Output. /// <para> /// When acquiring displays from an X11 server, an application may also wish to enumerate and /// identify them using a native handle rather than a <see cref="DisplayKhr"/> handle. /// </para> /// </summary> /// <param name="physicalDevice">The physical device to query the display handle on.</param> /// <param name="dpy">A connection to the X11 server from which <paramref name="rrOutput"/> was queried.</param> /// <param name="rrOutput">An X11 RandR output ID.</param> /// <returns>The corresponding <see cref="DisplayKhr"/> handle.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static DisplayKhr GetRandROutputDisplayExt(this PhysicalDevice physicalDevice, IntPtr dpy, IntPtr rrOutput) { long handle; Result result = vkGetRandROutputDisplayEXT(physicalDevice, &dpy, rrOutput, &handle); VulkanException.ThrowForInvalidResult(result); return(new DisplayKhr(physicalDevice, handle)); }
/// <summary> /// Get properties of external memory Win32 handles. /// <para> /// Windows memory handles compatible with Vulkan may also be created by non-Vulkan APIs /// using methods beyond the scope of this specification. /// </para> /// </summary> /// <param name="device">The logical device that will be importing <paramref name="handle"/>.</param> /// <param name="handleType">The type of the handle <paramref name="handle"/>.</param> /// <param name="handle">the handle which will be imported.</param> /// <returns>Properties of <paramref name="handle"/>.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static MemoryWin32HandlePropertiesKhx GetMemoryWin32HandlePropertiesKhx(this Device device, ExternalMemoryHandleTypesKhx handleType, IntPtr handle) { MemoryWin32HandlePropertiesKhx properties; Result result = vkGetMemoryWin32HandlePropertiesKHX(device, handleType, handle, &properties); VulkanException.ThrowForInvalidResult(result); return(properties); }
/// <summary> /// Get properties of external memory file descriptors. /// <para> /// POSIX file descriptor memory handles compatible with Vulkan may also be created by /// non-Vulkan APIs using methods beyond the scope of this specification. /// </para> /// </summary> /// <param name="device">The logical device that will be importing <paramref name="fd"/>.</param> /// <param name="handleType">The type of the handle <paramref name="fd"/>.</param> /// <param name="fd">The handle which will be imported.</param> /// <returns>Properties of the handle <paramref name="fd"/>.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static MemoryFdPropertiesKhx GetMemoryFdPropertiesKhx(this Device device, ExternalMemoryHandleTypesKhx handleType, int fd) { MemoryFdPropertiesKhx properties; Result result = vkGetMemoryFdPropertiesKHX(device)(device, handleType, fd, &properties); VulkanException.ThrowForInvalidResult(result); return(properties); }
/// <summary> /// Get properties of external memory host pointer. /// </summary> /// <param name="device">The logical device that will be importing <paramref name="hostPointer"/>.</param> /// <param name="handleType">The type of the handle <paramref name="hostPointer"/>.</param> /// <param name="hostPointer">The host pointer to import from.</param> /// <returns>Properties of external memory host pointer.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static MemoryHostPointerPropertiesExt GetMemoryHostPointerPropertiesExt(this Device device, ExternalMemoryHandleTypesKhr handleType, IntPtr hostPointer) { MemoryHostPointerPropertiesExt properties; Result result = vkGetMemoryHostPointerPropertiesEXT(device)(device, handleType, hostPointer, &properties); VulkanException.ThrowForInvalidResult(result); return(properties); }
/// <summary> /// Retrieve the index of the next available presentable image. /// </summary> /// <param name="device">The device associated with <see cref="AcquireNextImageInfoKhx.Swapchain"/>.</param> /// <param name="acquireInfo">Structure containing parameters of the acquire.</param> /// <returns>The index of the next image to use.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static int AcquireNextImage2Khx(this Device device, AcquireNextImageInfoKhx acquireInfo) { int index; acquireInfo.Prepare(); Result result = vkAcquireNextImage2KHX(device)(device, &acquireInfo, &index); VulkanException.ThrowForInvalidResult(result); return(index); }
/// <summary> /// Give a user-friendly name to an object. /// <para> /// Applications may change the name associated with an object simply by calling <see /// cref="DebugMarkerSetObjectNameExt"/> again with a new string. To remove a previously set /// name, name should be set to an empty string. /// </para> /// </summary> /// <param name="device">The device that created the object.</param> /// <param name="nameInfo">Specifies the parameters of the name to set on the object.</param> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static void DebugMarkerSetObjectNameExt(this Device device, DebugMarkerObjectNameInfoExt nameInfo) { int nameByteCount = Interop.String.GetMaxByteCount(nameInfo.ObjectName); byte* nameBytes = stackalloc byte[nameByteCount]; Interop.String.ToPointer(nameInfo.ObjectName, nameBytes, nameByteCount); nameInfo.ToNative(out DebugMarkerObjectNameInfoExt.Native nativeNameInfo, nameBytes); Result result = vkDebugMarkerSetObjectNameEXT(device)(device, &nativeNameInfo); VulkanException.ThrowForInvalidResult(result); }
internal DisplayModeKhr(DisplayKhr parent, DisplayModeCreateInfoKhr *createInfo, ref AllocationCallbacks?allocator) { Parent = parent; Allocator = allocator; long handle; Result result = vkCreateDisplayModeKHR(Parent.Parent, Parent, createInfo, NativeAllocator, &handle); VulkanException.ThrowForInvalidResult(result); Handle = handle; }
/// <summary> /// Import a semaphore from a Windows HANDLE. /// </summary> /// <param name="device">The logical device that created the semaphore.</param> /// <returns>Structure specifying the semaphore and import parameters.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static ImportSemaphoreWin32HandleInfoKhr ImportSemaphoreWin32HandleKhr(this Device device) { ImportSemaphoreWin32HandleInfoKhr.Native nativeInfo; Result result = vkImportSemaphoreWin32HandleKHR(device)(device, &nativeInfo); VulkanException.ThrowForInvalidResult(result); var semaphore = new Semaphore(nativeInfo.Semaphore, device); ImportSemaphoreWin32HandleInfoKhr.FromNative(ref nativeInfo, semaphore, out var info); return(info); }
/// <exception cref="VulkanException">Vulkan returns an error code.</exception> public void UnregisterObjects(ObjectEntryTypeNvx[] objectEntryTypes, int[] objectIndices) { fixed(ObjectEntryTypeNvx *objEntryTypesPtr = objectEntryTypes) fixed(int *objIndicesPtr = objectIndices) { Result result = vkUnregisterObjectsNVX(this)(Parent, this, objectEntryTypes?.Length ?? 0, objEntryTypesPtr, objIndicesPtr); VulkanException.ThrowForInvalidResult(result); } }
/// <summary> /// Import a semaphore from a POSIX file descriptor. /// </summary> /// <param name="device">The logical device that created the semaphore.</param> /// <returns>Structure specifying the semaphore and import parameters.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static ImportSemaphoreFdInfoKhx ImportSemaphoreFdKhx(this Device device) { ImportSemaphoreFdInfoKhx.Native nativeInfo; Result result = vkImportSemaphoreFdKHX(device)(device, &nativeInfo); VulkanException.ThrowForInvalidResult(result); var semaphore = new Semaphore(nativeInfo.Semaphore, device); ImportSemaphoreFdInfoKhx.FromNative(ref nativeInfo, semaphore, out var info); return(info); }
internal SamplerYcbcrConversionKhr(Device parent, SamplerYcbcrConversionCreateInfoKhr *createInfo, ref AllocationCallbacks?allocator) { Parent = parent; Allocator = allocator; long handle; Result result = vkCreateSamplerYcbcrConversionKHR(Parent)(Parent, createInfo, NativeAllocator, &handle); VulkanException.ThrowForInvalidResult(result); Handle = handle; }
/// <summary> /// Determine image capabilities compatible with external memory handle types. /// </summary> /// <param name="physicalDevice">The physical device from which to query the image capabilities.</param> /// <param name="format">The image format, corresponding to <see cref="ImageCreateInfo.Format"/>.</param> /// <param name="type">The image type, corresponding to <see cref="ImageCreateInfo.ImageType"/>.</param> /// <param name="tiling">The image tiling, corresponding to <see cref="ImageCreateInfo.Tiling"/>.</param> /// <param name="usage">The intended usage of the image, corresponding to <see cref="ImageCreateInfo.Usage"/>.</param> /// <param name="flags"> /// A bitmask describing additional parameters of the image, corresponding to <see cref="ImageCreateInfo.Flags"/>. /// </param> /// <param name="externalHandleType"> /// Either one of the bits from <see cref="ExternalMemoryHandleTypesNV"/>, or 0. /// </param> /// <returns>The structure in which capabilities are returned.</returns> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public static ExternalImageFormatPropertiesNV GetExternalImageFormatPropertiesNV(this PhysicalDevice physicalDevice, Format format, ImageType type, ImageTiling tiling, ImageUsages usage, ImageCreateFlags flags, ExternalMemoryHandleTypesNV externalHandleType) { ExternalImageFormatPropertiesNV properties; Result result = vkGetPhysicalDeviceExternalImageFormatPropertiesNV(physicalDevice, format, type, tiling, usage, flags, externalHandleType, &properties); VulkanException.ThrowForInvalidResult(result); return(properties); }
/// <summary> /// Combine the data stores of validation caches. /// </summary> /// <param name="srcCaches"> /// An array of validation cache handles, which will be merged into this cache. /// </param> /// <exception cref="VulkanException">Vulkan returns an error code.</exception> public void Merge(ValidationCacheExt[] srcCaches) { int srcCacheCount = srcCaches?.Length ?? 0; long *srcCacheHandles = stackalloc long[srcCacheCount]; for (int i = 0; i < srcCacheCount; i++) { srcCacheHandles[i] = srcCacheHandles[i]; } Result result = vkMergeValidationCachesEXT(Parent)(Parent, this, srcCacheCount, srcCacheHandles); VulkanException.ThrowForInvalidResult(result); }
internal SurfaceKhr(Instance parent, DisplaySurfaceCreateInfoKhr *createInfo, ref AllocationCallbacks?allocator) { Parent = parent; Allocator = allocator; long handle; createInfo->Prepare(); Result result = vkCreateDisplayPlaneSurfaceKHR(Parent, createInfo, NativeAllocator, &handle); VulkanException.ThrowForInvalidResult(result); Handle = handle; }