Skip to content

Commit

Permalink
Improve Vulkan bindings for accessing function extension
Browse files Browse the repository at this point in the history
  • Loading branch information
xoofx committed Jun 25, 2024
1 parent d96857c commit eb0ff2b
Show file tree
Hide file tree
Showing 20 changed files with 4,013 additions and 1,998 deletions.
20 changes: 17 additions & 3 deletions src/codegen/XenoAtom.Interop.CodeGen/vulkan/VulkanGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,31 @@ private void ProcessVulkanFunction(CSharpMethod csFunction)

var cppFunction = (CppFunction)csFunction.CppElement!;

pfn.BaseTypes.Add(new CSharpFreeType("IvkFunctionPointer"));
pfn.BaseTypes.Add(new CSharpGenericTypeReference("IvkFunctionPointer", [pfn]));

var csProperty = new CSharpProperty(csFunction.Name + "_")
var csProperty = new CSharpProperty("Prototype")
{
ReturnType = new CSharpGenericTypeReference($"vkFunctionPointerPrototype", [pfn]),
GetBodyInlined = $"new(\"{csFunction.Name}\"u8)",
Visibility = CSharpVisibility.Public,
Modifiers = CSharpModifiers.Static,
};

csProperty.Comment = new CSharpFullComment()
{
Children =
{
new CSharpXmlComment("summary")
{
Children =
{
new CSharpTextComment($"Gets the prototype of the function `{csFunction.Name}`.")
}
}
}
};
var parent = (ICSharpContainer)csFunction.Parent!;
parent.Members.Insert(parent.Members.IndexOf(csFunction) + 1, csProperty);
pfn.Members.Add(csProperty);

// Extension functions are not part of the core API, so we should remove LibraryImport for them
var isExtensionFunction = IsFunctionPointerStruct(cppFunction);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ public partial struct VkIcdSurfaceImagePipe
/// <summary>
/// Typedefs for loader/ICD interface
/// </summary>
public readonly partial struct PFN_vk_icdNegotiateLoaderICDInterfaceVersion : IEquatable<vulkan.PFN_vk_icdNegotiateLoaderICDInterfaceVersion>, IvkFunctionPointer
public readonly partial struct PFN_vk_icdNegotiateLoaderICDInterfaceVersion : IEquatable<vulkan.PFN_vk_icdNegotiateLoaderICDInterfaceVersion>, IvkFunctionPointer<vulkan.PFN_vk_icdNegotiateLoaderICDInterfaceVersion>
{
public PFN_vk_icdNegotiateLoaderICDInterfaceVersion(delegate*unmanaged[Stdcall]<uint*, vulkan.VkResult> value) => this.Value = value;

Expand All @@ -305,6 +305,11 @@ public partial struct VkIcdSurfaceImagePipe

public static bool operator !=(PFN_vk_icdNegotiateLoaderICDInterfaceVersion left, PFN_vk_icdNegotiateLoaderICDInterfaceVersion right) => !left.Equals(right);

/// <summary>
/// Gets the prototype of the function `vk_icdNegotiateLoaderICDInterfaceVersion`.
/// </summary>
public static vkFunctionPointerPrototype<vulkan.PFN_vk_icdNegotiateLoaderICDInterfaceVersion> Prototype => new("vk_icdNegotiateLoaderICDInterfaceVersion"u8);

public vulkan.VkResult Invoke(uint* pVersion)
{
return Value(pVersion);
Expand All @@ -315,7 +320,7 @@ public vulkan.VkResult Invoke(uint* pVersion)
public bool IsNull => (nint)Value == 0;
}

public readonly partial struct PFN_vk_icdGetInstanceProcAddr : IEquatable<vulkan.PFN_vk_icdGetInstanceProcAddr>, IvkFunctionPointer
public readonly partial struct PFN_vk_icdGetInstanceProcAddr : IEquatable<vulkan.PFN_vk_icdGetInstanceProcAddr>, IvkFunctionPointer<vulkan.PFN_vk_icdGetInstanceProcAddr>
{
public PFN_vk_icdGetInstanceProcAddr(delegate*unmanaged[Stdcall]<vulkan.VkInstance, byte*, vulkan.PFN_vkVoidFunction> value) => this.Value = value;

Expand All @@ -337,6 +342,11 @@ public vulkan.VkResult Invoke(uint* pVersion)

public static bool operator !=(PFN_vk_icdGetInstanceProcAddr left, PFN_vk_icdGetInstanceProcAddr right) => !left.Equals(right);

/// <summary>
/// Gets the prototype of the function `vk_icdGetInstanceProcAddr`.
/// </summary>
public static vkFunctionPointerPrototype<vulkan.PFN_vk_icdGetInstanceProcAddr> Prototype => new("vk_icdGetInstanceProcAddr"u8);

public vulkan.PFN_vkVoidFunction Invoke(vulkan.VkInstance instance, byte* pName)
{
return Value(instance, pName);
Expand All @@ -347,7 +357,7 @@ public vulkan.PFN_vkVoidFunction Invoke(vulkan.VkInstance instance, byte* pName)
public bool IsNull => (nint)Value == 0;
}

public readonly partial struct PFN_vk_icdGetPhysicalDeviceProcAddr : IEquatable<vulkan.PFN_vk_icdGetPhysicalDeviceProcAddr>, IvkFunctionPointer
public readonly partial struct PFN_vk_icdGetPhysicalDeviceProcAddr : IEquatable<vulkan.PFN_vk_icdGetPhysicalDeviceProcAddr>, IvkFunctionPointer<vulkan.PFN_vk_icdGetPhysicalDeviceProcAddr>
{
public PFN_vk_icdGetPhysicalDeviceProcAddr(delegate*unmanaged[Stdcall]<vulkan.VkInstance, byte*, vulkan.PFN_vkVoidFunction> value) => this.Value = value;

Expand All @@ -369,6 +379,11 @@ public vulkan.PFN_vkVoidFunction Invoke(vulkan.VkInstance instance, byte* pName)

public static bool operator !=(PFN_vk_icdGetPhysicalDeviceProcAddr left, PFN_vk_icdGetPhysicalDeviceProcAddr right) => !left.Equals(right);

/// <summary>
/// Gets the prototype of the function `vk_icdGetPhysicalDeviceProcAddr`.
/// </summary>
public static vkFunctionPointerPrototype<vulkan.PFN_vk_icdGetPhysicalDeviceProcAddr> Prototype => new("vk_icdGetPhysicalDeviceProcAddr"u8);

public vulkan.PFN_vkVoidFunction Invoke(vulkan.VkInstance instance, byte* pName)
{
return Value(instance, pName);
Expand All @@ -379,7 +394,7 @@ public vulkan.PFN_vkVoidFunction Invoke(vulkan.VkInstance instance, byte* pName)
public bool IsNull => (nint)Value == 0;
}

public readonly partial struct PFN_vk_icdEnumerateAdapterPhysicalDevices : IEquatable<vulkan.PFN_vk_icdEnumerateAdapterPhysicalDevices>, IvkFunctionPointer
public readonly partial struct PFN_vk_icdEnumerateAdapterPhysicalDevices : IEquatable<vulkan.PFN_vk_icdEnumerateAdapterPhysicalDevices>, IvkFunctionPointer<vulkan.PFN_vk_icdEnumerateAdapterPhysicalDevices>
{
public PFN_vk_icdEnumerateAdapterPhysicalDevices(delegate*unmanaged[Stdcall]<vulkan.VkInstance, ulong, uint*, vulkan.VkPhysicalDevice*, vulkan.VkResult> value) => this.Value = value;

Expand All @@ -401,6 +416,11 @@ public vulkan.PFN_vkVoidFunction Invoke(vulkan.VkInstance instance, byte* pName)

public static bool operator !=(PFN_vk_icdEnumerateAdapterPhysicalDevices left, PFN_vk_icdEnumerateAdapterPhysicalDevices right) => !left.Equals(right);

/// <summary>
/// Gets the prototype of the function `vk_icdEnumerateAdapterPhysicalDevices`.
/// </summary>
public static vkFunctionPointerPrototype<vulkan.PFN_vk_icdEnumerateAdapterPhysicalDevices> Prototype => new("vk_icdEnumerateAdapterPhysicalDevices"u8);

public vulkan.VkResult Invoke(vulkan.VkInstance instance, ulong adapterLUID, uint* pPhysicalDeviceCount, vulkan.VkPhysicalDevice* pPhysicalDevices)
{
return Value(instance, adapterLUID, pPhysicalDeviceCount, pPhysicalDevices);
Expand All @@ -415,24 +435,16 @@ public vulkan.VkResult Invoke(vulkan.VkInstance instance, ulong adapterLUID, uin
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvStdcall) })]
public static partial vulkan.VkResult vk_icdNegotiateLoaderICDInterfaceVersion(uint* pVersion);

public static vkFunctionPointerPrototype<vulkan.PFN_vk_icdNegotiateLoaderICDInterfaceVersion> vk_icdNegotiateLoaderICDInterfaceVersion_ => new("vk_icdNegotiateLoaderICDInterfaceVersion"u8);

[global::System.Runtime.InteropServices.LibraryImport(LibraryName, EntryPoint = "vk_icdGetInstanceProcAddr")]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvStdcall) })]
public static partial vulkan.PFN_vkVoidFunction vk_icdGetInstanceProcAddr(vulkan.VkInstance instance, byte* pName);

public static vkFunctionPointerPrototype<vulkan.PFN_vk_icdGetInstanceProcAddr> vk_icdGetInstanceProcAddr_ => new("vk_icdGetInstanceProcAddr"u8);

[global::System.Runtime.InteropServices.LibraryImport(LibraryName, EntryPoint = "vk_icdGetPhysicalDeviceProcAddr")]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvStdcall) })]
public static partial vulkan.PFN_vkVoidFunction vk_icdGetPhysicalDeviceProcAddr(vulkan.VkInstance instance, byte* pName);

public static vkFunctionPointerPrototype<vulkan.PFN_vk_icdGetPhysicalDeviceProcAddr> vk_icdGetPhysicalDeviceProcAddr_ => new("vk_icdGetPhysicalDeviceProcAddr"u8);

[global::System.Runtime.InteropServices.LibraryImport(LibraryName, EntryPoint = "vk_icdEnumerateAdapterPhysicalDevices")]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvStdcall) })]
public static partial vulkan.VkResult vk_icdEnumerateAdapterPhysicalDevices(vulkan.VkInstance instance, ulong adapterLUID, uint* pPhysicalDeviceCount, vulkan.VkPhysicalDevice* pPhysicalDevices);

public static vkFunctionPointerPrototype<vulkan.PFN_vk_icdEnumerateAdapterPhysicalDevices> vk_icdEnumerateAdapterPhysicalDevices_ => new("vk_icdEnumerateAdapterPhysicalDevices"u8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ public partial struct VkEnumerateInstanceVersionChain
/// <summary>
/// Version negotiation functions
/// </summary>
public readonly partial struct PFN_vkNegotiateLoaderLayerInterfaceVersion : IEquatable<vulkan.PFN_vkNegotiateLoaderLayerInterfaceVersion>, IvkFunctionPointer
public readonly partial struct PFN_vkNegotiateLoaderLayerInterfaceVersion : IEquatable<vulkan.PFN_vkNegotiateLoaderLayerInterfaceVersion>, IvkFunctionPointer<vulkan.PFN_vkNegotiateLoaderLayerInterfaceVersion>
{
public PFN_vkNegotiateLoaderLayerInterfaceVersion(delegate*unmanaged[Stdcall]<vulkan.VkNegotiateLayerInterface*, vulkan.VkResult> value) => this.Value = value;

Expand All @@ -449,6 +449,11 @@ public partial struct VkEnumerateInstanceVersionChain

public static bool operator !=(PFN_vkNegotiateLoaderLayerInterfaceVersion left, PFN_vkNegotiateLoaderLayerInterfaceVersion right) => !left.Equals(right);

/// <summary>
/// Gets the prototype of the function `vkNegotiateLoaderLayerInterfaceVersion`.
/// </summary>
public static vkFunctionPointerPrototype<vulkan.PFN_vkNegotiateLoaderLayerInterfaceVersion> Prototype => new("vkNegotiateLoaderLayerInterfaceVersion"u8);

public vulkan.VkResult Invoke(vulkan.VkNegotiateLayerInterface* pVersionStruct)
{
return Value(pVersionStruct);
Expand Down Expand Up @@ -541,7 +546,5 @@ public vulkan.VkResult Invoke(vulkan.VkNegotiateLayerInterface* pVersionStruct)
[global::System.Runtime.InteropServices.LibraryImport(LibraryName, EntryPoint = "vkNegotiateLoaderLayerInterfaceVersion")]
[UnmanagedCallConv(CallConvs = new Type[] { typeof(CallConvStdcall) })]
public static partial vulkan.VkResult vkNegotiateLoaderLayerInterfaceVersion(vulkan.VkNegotiateLayerInterface* pVersionStruct);

public static vkFunctionPointerPrototype<vulkan.PFN_vkNegotiateLoaderLayerInterfaceVersion> vkNegotiateLoaderLayerInterfaceVersion_ => new("vkNegotiateLoaderLayerInterfaceVersion"u8);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ public partial struct VkAndroidHardwareBufferFormatProperties2ANDROID()
public vulkan.VkChromaLocation suggestedYChromaOffset;
}

public readonly partial struct PFN_vkCreateAndroidSurfaceKHR : IEquatable<vulkan.PFN_vkCreateAndroidSurfaceKHR>, IvkFunctionPointer
public readonly partial struct PFN_vkCreateAndroidSurfaceKHR : IEquatable<vulkan.PFN_vkCreateAndroidSurfaceKHR>, IvkFunctionPointer<vulkan.PFN_vkCreateAndroidSurfaceKHR>
{
public PFN_vkCreateAndroidSurfaceKHR(delegate*unmanaged[Stdcall]<vulkan.VkInstance, vulkan.VkAndroidSurfaceCreateInfoKHR*, vulkan.VkAllocationCallbacks*, vulkan.VkSurfaceKHR*, vulkan.VkResult> value) => this.Value = value;

Expand All @@ -337,6 +337,11 @@ public partial struct VkAndroidHardwareBufferFormatProperties2ANDROID()

public static bool operator !=(PFN_vkCreateAndroidSurfaceKHR left, PFN_vkCreateAndroidSurfaceKHR right) => !left.Equals(right);

/// <summary>
/// Gets the prototype of the function `vkCreateAndroidSurfaceKHR`.
/// </summary>
public static vkFunctionPointerPrototype<vulkan.PFN_vkCreateAndroidSurfaceKHR> Prototype => new("vkCreateAndroidSurfaceKHR"u8);

/// <summary>
/// Create a <see cref="T:VkSurfaceKHR"/> object for an Android native window
/// </summary>
Expand Down Expand Up @@ -386,7 +391,7 @@ public vulkan.VkResult Invoke(vulkan.VkInstance instance, in vulkan.VkAndroidSur
}
}

public readonly partial struct PFN_vkGetAndroidHardwareBufferPropertiesANDROID : IEquatable<vulkan.PFN_vkGetAndroidHardwareBufferPropertiesANDROID>, IvkFunctionPointer
public readonly partial struct PFN_vkGetAndroidHardwareBufferPropertiesANDROID : IEquatable<vulkan.PFN_vkGetAndroidHardwareBufferPropertiesANDROID>, IvkFunctionPointer<vulkan.PFN_vkGetAndroidHardwareBufferPropertiesANDROID>
{
public PFN_vkGetAndroidHardwareBufferPropertiesANDROID(delegate*unmanaged[Stdcall]<vulkan.VkDevice, vulkan.AHardwareBuffer, vulkan.VkAndroidHardwareBufferPropertiesANDROID*, vulkan.VkResult> value) => this.Value = value;

Expand All @@ -408,6 +413,11 @@ public vulkan.VkResult Invoke(vulkan.VkInstance instance, in vulkan.VkAndroidSur

public static bool operator !=(PFN_vkGetAndroidHardwareBufferPropertiesANDROID left, PFN_vkGetAndroidHardwareBufferPropertiesANDROID right) => !left.Equals(right);

/// <summary>
/// Gets the prototype of the function `vkGetAndroidHardwareBufferPropertiesANDROID`.
/// </summary>
public static vkFunctionPointerPrototype<vulkan.PFN_vkGetAndroidHardwareBufferPropertiesANDROID> Prototype => new("vkGetAndroidHardwareBufferPropertiesANDROID"u8);

/// <summary>
/// Get Properties of External Memory Android Hardware Buffers
/// </summary>
Expand All @@ -433,7 +443,7 @@ public vulkan.VkResult Invoke(vulkan.VkDevice device, vulkan.AHardwareBuffer buf
public bool IsNull => (nint)Value == 0;
}

public readonly partial struct PFN_vkGetMemoryAndroidHardwareBufferANDROID : IEquatable<vulkan.PFN_vkGetMemoryAndroidHardwareBufferANDROID>, IvkFunctionPointer
public readonly partial struct PFN_vkGetMemoryAndroidHardwareBufferANDROID : IEquatable<vulkan.PFN_vkGetMemoryAndroidHardwareBufferANDROID>, IvkFunctionPointer<vulkan.PFN_vkGetMemoryAndroidHardwareBufferANDROID>
{
public PFN_vkGetMemoryAndroidHardwareBufferANDROID(delegate*unmanaged[Stdcall]<vulkan.VkDevice, vulkan.VkMemoryGetAndroidHardwareBufferInfoANDROID*, vulkan.AHardwareBuffer*, vulkan.VkResult> value) => this.Value = value;

Expand All @@ -455,6 +465,11 @@ public vulkan.VkResult Invoke(vulkan.VkDevice device, vulkan.AHardwareBuffer buf

public static bool operator !=(PFN_vkGetMemoryAndroidHardwareBufferANDROID left, PFN_vkGetMemoryAndroidHardwareBufferANDROID right) => !left.Equals(right);

/// <summary>
/// Gets the prototype of the function `vkGetMemoryAndroidHardwareBufferANDROID`.
/// </summary>
public static vkFunctionPointerPrototype<vulkan.PFN_vkGetMemoryAndroidHardwareBufferANDROID> Prototype => new("vkGetMemoryAndroidHardwareBufferANDROID"u8);

/// <summary>
/// Get an Android hardware buffer for a memory object
/// </summary>
Expand Down Expand Up @@ -486,8 +501,6 @@ public vulkan.VkResult Invoke(vulkan.VkDevice device, vulkan.VkMemoryGetAndroidH

public static ReadOnlyMemoryUtf8 VK_KHR_ANDROID_SURFACE_EXTENSION_NAME => "VK_KHR_android_surface"u8;

public static vkFunctionPointerPrototype<vulkan.PFN_vkCreateAndroidSurfaceKHR> vkCreateAndroidSurfaceKHR_ => new("vkCreateAndroidSurfaceKHR"u8);

/// <summary>
/// Get Properties of External Memory Android Hardware Buffers
/// </summary>
Expand Down Expand Up @@ -528,8 +541,6 @@ public static vulkan.VkResult vkGetAndroidHardwareBufferPropertiesANDROID(vulkan
return vkGetAndroidHardwareBufferPropertiesANDROID(device, buffer, __pProperties_local);
}

public static vkFunctionPointerPrototype<vulkan.PFN_vkGetAndroidHardwareBufferPropertiesANDROID> vkGetAndroidHardwareBufferPropertiesANDROID_ => new("vkGetAndroidHardwareBufferPropertiesANDROID"u8);

/// <summary>
/// Get an Android hardware buffer for a memory object
/// </summary>
Expand Down Expand Up @@ -570,7 +581,5 @@ public static vulkan.VkResult vkGetMemoryAndroidHardwareBufferANDROID(vulkan.VkD
fixed (vulkan.AHardwareBuffer* __pBuffer_local = &pBuffer)
return vkGetMemoryAndroidHardwareBufferANDROID(device, __pInfo_local, __pBuffer_local);
}

public static vkFunctionPointerPrototype<vulkan.PFN_vkGetMemoryAndroidHardwareBufferANDROID> vkGetMemoryAndroidHardwareBufferANDROID_ => new("vkGetMemoryAndroidHardwareBufferANDROID"u8);
}
}
Loading

0 comments on commit eb0ff2b

Please sign in to comment.