private void VerifyDeviceExtensionsAvailable(Vk vk, PhysicalDevice physicalDevice, List <string> extensions, ref List <string> layers) { var copy = extensions.ToList(); uint propertyCount = 0; vk.EnumerateDeviceExtensionProperties(physicalDevice, (byte *)null, ref propertyCount, null).ThrowCode(); var properties = (ExtensionProperties *)SilkMarshal.Allocate((int)(propertyCount * sizeof(ExtensionProperties))); vk.EnumerateDeviceExtensionProperties(physicalDevice, (byte *)null, ref propertyCount, properties).ThrowCode(); for (int i = 0; i < propertyCount; i++) { var name = SilkMarshal.PtrToString((nint)properties[i].ExtensionName); copy.Remove(name); } foreach (var ext in copy) { if (ext == KhrSynchronization2.ExtensionName) { layers.Add("VK_LAYER_KHRONOS_synchronization2"); Console.WriteLine("Attempting to enable VK_LAYER_KHRONOS_synchronization2"); } Console.WriteLine($"Missing {ext}"); } }
private void VerifyInstanceExtensionsAvailable(Vk vk, List <string> extensions) { var copy = extensions.ToList(); uint propertyCount = 0; vk.EnumerateInstanceExtensionProperties((byte *)null, ref propertyCount, null).ThrowCode(); var properties = (ExtensionProperties *)SilkMarshal.Allocate((int)(propertyCount * sizeof(ExtensionProperties))); vk.EnumerateInstanceExtensionProperties((byte *)null, ref propertyCount, properties).ThrowCode(); for (int i = 0; i < propertyCount; i++) { var name = SilkMarshal.PtrToString((nint)properties[i].ExtensionName); copy.Remove(name); } foreach (var ext in copy) { Console.WriteLine($"Missing {ext}"); extensions.Remove(ext); } }
internal unsafe VulkanPhysicalDevice(Vk vk, VulkanContext context, PhysicalDevice physicalDevice) : base(vk) { if (context.Instance is null) { throw new NullReferenceException(nameof(context.Instance)); } _Context = context; _PhysicalDevice = physicalDevice; VK.GetPhysicalDeviceProperties(this, out PhysicalDeviceProperties properties); APIVersion = properties.ApiVersion; DriverVersion = properties.DriverVersion; VendorID = properties.VendorID; DeviceID = properties.DeviceID; Type = properties.DeviceType; Name = SilkMarshal.PtrToString((nint)properties.DeviceName); SwapChainSupportDetails = GetSwapChainSupport(); _Extensions = GetExtensions(); }
public unsafe GLAPI() { // validate dependency or throw GL = AutomataWindow.Instance.GetOpenGLContext(); string version = SilkMarshal.PtrToString((nint)GL.GetString(StringName.Version)); Log.Information(string.Format(_LogFormat, $"OpenGL version {version}")); // configure debug callback GL.GetInteger(GetPName.ContextFlags, out int flags); if (!((ContextFlags)flags).HasFlag(ContextFlags.Debug)) { return; } GL.Enable(EnableCap.DebugOutput); GL.Enable(EnableCap.DebugOutputSynchronous); GL.DebugMessageCallback(DebugOutputCallback, (void *)null !); GL.DebugMessageControl(DebugSource.DontCare, DebugType.DontCare, DebugSeverity.DontCare, 0, (uint *)null !, true); }
private static unsafe void CheckInstanceLayersPresent(string[] enabledInstanceLayers) { uint instanceLayerCount = 0; AssertVulkan(Vk.EnumerateInstanceLayerProperties(ref instanceLayerCount, null)); Span <LayerProperties> props = stackalloc LayerProperties[(int)instanceLayerCount]; AssertVulkan(Vk.EnumerateInstanceLayerProperties(ref instanceLayerCount, ref props[0])); List <string> names = new(); foreach (LayerProperties prop in props) { names.Add(SilkMarshal.PtrToString((nint)prop.LayerName)); } foreach (string layer in enabledInstanceLayers) { if (!names.Contains(layer)) { Console.Error.WriteLine("WARNING: Layer not present! Name: '" + layer + "'"); } } }
private static unsafe void CheckInstanceExtensionsPresent(byte **enabledInstanceExtensions, int enabledInstanceExtensionCount) { uint instanceExtensionCount = 0; AssertVulkan(Vk.EnumerateInstanceExtensionProperties((byte *)null, ref instanceExtensionCount, null)); Span <ExtensionProperties> properties = stackalloc ExtensionProperties[(int)instanceExtensionCount]; AssertVulkan(Vk.EnumerateInstanceExtensionProperties((byte *)null, ref instanceExtensionCount, ref properties[0])); List <string> names = new(); foreach (ExtensionProperties prop in properties) { names.Add(SilkMarshal.PtrToString((nint)prop.ExtensionName)); } for (int i = 0; i < enabledInstanceExtensionCount; i++) { string name = SilkMarshal.PtrToString((nint)enabledInstanceExtensions[i]); if (!names.Contains(name)) { Console.Error.WriteLine("WARNING: Extension not present! Name: '" + name + "'"); } } }
public static unsafe Func <string, nint> GetLoader(bool alwaysPresent, out nint loaderPtr, out nint ctxLoaderPtr) { var wrapper = new nint[2]; var theDelegate = (LoaderDelegate)Loader; // The wrapper array is so the delegates can use eachothers resources without having to worry about // modifications outside of the delegate's scope. wrapper[0] = loaderPtr = SilkMarshal.DelegateToPtr(theDelegate); wrapper[1] = ctxLoaderPtr = SilkMarshal.DelegateToPtr((ContextLoaderDelegate)((_, x) => theDelegate(x))); return(x => theDelegate((byte *)SilkMarshal.StringToPtr(x))); nint Loader(byte *x) => SilkMarshal.PtrToString((nint)x) switch { "alcIsExtensionPresent" or "alIsExtensionPresent" => alwaysPresent ? (nint)(delegate * unmanaged[Cdecl] < byte *, int >) & AlwaysOne : (nint)(delegate * unmanaged[Cdecl] < byte *, int >) & AlwaysZero, "alGetProcAddress" => wrapper[0], "alcGetProcAddress" => wrapper[1], "alGetEnumValue" => (nint)(delegate * unmanaged[Cdecl] < byte *, int >) & AlwaysZero, _ => 0 }; }
private static unsafe bool CheckDeviceExtensionsPresent(string[] deviceExtensions, PhysicalDevice physicalDevice) { uint deviceExtensionCount = 0; AssertVulkan(Vk.EnumerateDeviceExtensionProperties(physicalDevice, (byte *)null, ref deviceExtensionCount, null)); Span <ExtensionProperties> props = stackalloc ExtensionProperties[(int)deviceExtensionCount]; AssertVulkan(Vk.EnumerateDeviceExtensionProperties(physicalDevice, (byte *)null, ref deviceExtensionCount, ref props[0])); List <string> names = new(); foreach (ExtensionProperties prop in props) { names.Add(SilkMarshal.PtrToString((nint)prop.ExtensionName)); } foreach (string extension in deviceExtensions) { if (!names.Contains(extension)) { Console.Error.WriteLine("WARNING: Extension not present. Name: " + extension + "."); return(false); } } return(true); }