Exemplo n.º 1
0
 public Instance(InstanceCreateInfo info)
 {
     if (info == null)
     {
         throw new ArgumentNullException(nameof(info));
     }
     Init(info);
 }
Exemplo n.º 2
0
        public Instance(InstanceCreateInfo info, VkAllocationCallbacks callbacks)
        {
            if (info == null)
            {
                throw new ArgumentNullException(nameof(info));
            }

            alloc = Marshal.AllocHGlobal(Marshal.SizeOf <VkAllocationCallbacks>());
            Marshal.StructureToPtr(callbacks, alloc, false);

            Init(info);
        }
Exemplo n.º 3
0
        void CreateInstance(InstanceCreateInfo mInfo)
        {
            InteropString appName    = null;
            InteropString engineName = null;
            Marshalled <VkApplicationInfo> appInfoMarshalled = null;

            var extensionsMarshalled = new NativeStringArray(mInfo.extensions);
            var layersMarshalled     = new NativeStringArray(mInfo.layers);

            var info = new VkInstanceCreateInfo();

            info.sType = VkStructureType.InstanceCreateInfo;
            info.enabledExtensionCount   = (uint)extensionsMarshalled.Count;
            info.ppEnabledExtensionNames = extensionsMarshalled.Address;
            info.enabledLayerCount       = (uint)layersMarshalled.Count;
            info.ppEnabledLayerNames     = layersMarshalled.Address;

            if (mInfo.applicationInfo != null)
            {
                var appInfo = new VkApplicationInfo();
                appInfo.sType              = VkStructureType.ApplicationInfo;
                appInfo.apiVersion         = mInfo.applicationInfo.apiVersion;
                appInfo.engineVersion      = mInfo.applicationInfo.engineVersion;
                appInfo.applicationVersion = mInfo.applicationInfo.applicationVersion;

                appName = new InteropString(mInfo.applicationInfo.applicationName);
                appInfo.pApplicationName = appName.Address;

                engineName          = new InteropString(mInfo.applicationInfo.engineName);
                appInfo.pEngineName = engineName.Address;

                appInfoMarshalled     = new Marshalled <VkApplicationInfo>(appInfo);
                info.pApplicationInfo = appInfoMarshalled.Address;
            }

            using (appName) //appName, engineName, and appInfoMarshalled may be null
                using (engineName)
                    using (appInfoMarshalled)
                        using (extensionsMarshalled)
                            using (layersMarshalled) {
                                var result = createInstance(ref info, alloc, out instance);
                                if (result != VkResult.Success)
                                {
                                    throw new InstanceException(string.Format("Error creating instance: {0}", result));
                                }
                            }
        }
Exemplo n.º 4
0
        void Init(InstanceCreateInfo mInfo)
        {
            if (!GLFW.GLFW.VulkanSupported())
            {
                throw new InstanceException("Vulkan not supported");
            }
            if (!initialized)
            {
                Init();
            }

            if (mInfo.extensions == null)
            {
                extensions = new List <string>();
            }
            else
            {
                extensions = new List <string>(mInfo.extensions);
            }

            if (mInfo.layers == null)
            {
                layers = new List <string>();
            }
            else
            {
                layers = new List <string>(mInfo.layers);
            }

            CreateInstance(mInfo);

            Extensions = extensions.AsReadOnly();
            Layers     = layers.AsReadOnly();

            Vulkan.Load(ref getProcAddrDel, instance);

            Commands = new InstanceCommands(this);

            GetPhysicalDevices();
        }