void GetDeviceFeatures()
 {
     using (var feat = new Marshalled <VkPhysicalDeviceFeatures>()) {
         Instance.Commands.getFeatures(physicalDevice, feat.Address);
         features = feat.Value;
     }
 }
 void GetDeviceProperties()
 {
     using (var prop = new Marshalled <VkPhysicalDeviceProperties>()) {
         Instance.Commands.getProperties(physicalDevice, prop.Address);
         Properties = new PhysicalDeviceProperties(prop.Value);
     }
 }
 public VkImageFormatProperties GetImageFormatProperties(VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags)
 {
     using (var prop = new Marshalled <VkImageFormatProperties>()) {
         Instance.Commands.getPhysicalDeviceImageFormatProperties(physicalDevice, format, type, tiling, usage, flags, prop.Address);
         return(prop.Value);
     }
 }
 public VkFormatProperties GetFormatProperties(VkFormat format)
 {
     using (var prop = new Marshalled <VkFormatProperties>()) {
         Instance.Commands.getPhysicalDeviceFormatProperties(physicalDevice, format, prop.Address);
         return(prop.Value);
     }
 }
 void GetMemoryProperties()
 {
     using (var prop = new Marshalled <VkPhysicalDeviceMemoryProperties>()) {
         Instance.Commands.getMemoryProperties(physicalDevice, prop.Address);
         memoryProperties = prop.Value;
     }
 }
Example #6
0
        void CreateDevice(DeviceCreateInfo mInfo)
        {
            var extensionsMarshalled = new NativeStringArray(mInfo.extensions);
            MarshalledArray <VkDeviceQueueCreateInfo> queueInfos           = null;
            DisposableList <NativeArray <float> >     prioritiesMarshalled = null;
            Marshalled <VkPhysicalDeviceFeatures>     features             = new Marshalled <VkPhysicalDeviceFeatures>(mInfo.features);

            var info = new VkDeviceCreateInfo();

            info.sType = VkStructureType.DeviceCreateInfo;
            info.enabledExtensionCount   = (uint)extensionsMarshalled.Count;
            info.ppEnabledExtensionNames = extensionsMarshalled.Address;
            info.pEnabledFeatures        = features.Address;

            if (mInfo.queueCreateInfos != null)
            {
                int length = mInfo.queueCreateInfos.Count;
                info.queueCreateInfoCount = (uint)length;
                queueInfos           = new MarshalledArray <VkDeviceQueueCreateInfo>(length);
                prioritiesMarshalled = new DisposableList <NativeArray <float> >(length);

                for (int i = 0; i < length; i++)
                {
                    var mi    = mInfo.queueCreateInfos[i];
                    var qInfo = new VkDeviceQueueCreateInfo();
                    qInfo.sType = VkStructureType.DeviceQueueCreateInfo;

                    var priorityMarshalled = new NativeArray <float>(mi.priorities);
                    prioritiesMarshalled.Add(priorityMarshalled);
                    qInfo.pQueuePriorities = priorityMarshalled.Address;
                    qInfo.queueCount       = mi.queueCount;
                    qInfo.queueFamilyIndex = mi.queueFamilyIndex;

                    queueInfos[i] = qInfo;
                }

                info.pQueueCreateInfos = queueInfos.Address;
            }

            using (extensionsMarshalled)
                using (queueInfos)
                    using (features)
                        using (prioritiesMarshalled) {
                            var result = Instance.Commands.createDevice(PhysicalDevice.Native, ref info, Instance.AllocationCallbacks, out device);
                            if (result != VkResult.Success)
                            {
                                throw new DeviceException(string.Format("Error creating device: {0}", result));
                            }
                        }
        }
Example #7
0
        internal VkCommandBufferBeginInfo GetNative(DisposableList <IDisposable> marshalled)
        {
            VkCommandBufferBeginInfo info = new VkCommandBufferBeginInfo();

            info.sType = VkStructureType.CommandBufferBeginInfo;
            info.flags = flags;

            if (inheritanceInfo != null)
            {
                var inheritanceInfoMarshalled = new Marshalled <VkCommandBufferInheritanceInfo>(inheritanceInfo.GetNative());
                info.pInheritanceInfo = inheritanceInfoMarshalled.Address;
                marshalled.Add(inheritanceInfoMarshalled);
            }

            return(info);
        }
Example #8
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));
                                }
                            }
        }
        internal IntPtr GetNative(DisposableList <IDisposable> marshalled)
        {
            var entriesMarshalled = new MarshalledArray <VkSpecializationMapEntry>(mapEntries);
            var dataMarshalled    = new PinnedArray <byte>(data);

            marshalled.Add(entriesMarshalled);
            marshalled.Add(dataMarshalled);

            var info = new VkSpecializationInfo();

            info.mapEntryCount = (uint)entriesMarshalled.Count;
            info.pMapEntries   = entriesMarshalled.Address;
            info.dataSize      = (uint)dataMarshalled.Count;
            info.pData         = dataMarshalled.Address;

            var infoMarshalled = new Marshalled <VkSpecializationInfo>(info);

            marshalled.Add(infoMarshalled);

            return(infoMarshalled.Address);
        }
        static internal VkPipeline[] CreatePipelinesInternal(Device device, GraphicsPipelineCreateInfo[] mInfos, VkPipelineCache cache)
        {
            int count            = mInfos.Length;
            var infosMarshalled  = new MarshalledArray <VkGraphicsPipelineCreateInfo>(count);
            var pipelineResults  = new VkPipeline[count];
            var marshalledArrays = new DisposableList <IDisposable>(count);

            for (int i = 0; i < count; i++)
            {
                VkGraphicsPipelineCreateInfo info = new VkGraphicsPipelineCreateInfo();
                var mInfo = mInfos[i];

                info.sType = VkStructureType.GraphicsPipelineCreateInfo;
                info.flags = mInfo.flags;

                int stagesCount      = mInfo.stages.Count;
                var stagesMarshalled = new MarshalledArray <VkPipelineShaderStageCreateInfo>(stagesCount);
                for (int j = 0; j < stagesCount; j++)
                {
                    stagesMarshalled[j] = mInfo.stages[j].GetNative(marshalledArrays);
                }

                info.stageCount = (uint)stagesCount;
                info.pStages    = stagesMarshalled.Address;

                marshalledArrays.Add(stagesMarshalled);

                if (mInfo.vertexInputState != null)
                {
                    var m = new Marshalled <VkPipelineVertexInputStateCreateInfo>(mInfo.vertexInputState.GetNative(marshalledArrays));
                    info.pVertexInputState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.inputAssemblyState != null)
                {
                    var m = new Marshalled <VkPipelineInputAssemblyStateCreateInfo>(mInfo.inputAssemblyState.GetNative());
                    info.pInputAssemblyState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.tessellationState != null)
                {
                    var m = new Marshalled <VkPipelineTessellationStateCreateInfo>(mInfo.tessellationState.GetNative());
                    info.pTessellationState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.viewportState != null)
                {
                    var m = new Marshalled <VkPipelineViewportStateCreateInfo>(mInfo.viewportState.GetNative(marshalledArrays));
                    info.pViewportState = m.Address;
                }

                if (mInfo.rasterizationState != null)
                {
                    var m = new Marshalled <VkPipelineRasterizationStateCreateInfo>(mInfo.rasterizationState.GetNative());
                    info.pRasterizationState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.multisampleState != null)
                {
                    var m = new Marshalled <VkPipelineMultisampleStateCreateInfo>(mInfo.multisampleState.GetNative());
                    info.pMultisampleState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.depthStencilState != null)
                {
                    var m = new Marshalled <VkPipelineDepthStencilStateCreateInfo>(mInfo.depthStencilState.GetNative());
                    info.pDepthStencilState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.colorBlendState != null)
                {
                    var m = new Marshalled <VkPipelineColorBlendStateCreateInfo>(mInfo.colorBlendState.GetNative(marshalledArrays));
                    info.pColorBlendState = m.Address;
                    marshalledArrays.Add(m);
                }

                if (mInfo.dynamicState != null)
                {
                    var m = new Marshalled <VkPipelineDynamicStateCreateInfo>(mInfo.dynamicState.GetNative(marshalledArrays));
                    info.pDynamicState = m.Address;
                    marshalledArrays.Add(m);
                }

                info.layout = mInfo.layout.Native;

                if (mInfo.renderPass != null)
                {
                    info.renderPass = mInfo.renderPass.Native;
                }

                info.subpass = mInfo.subpass;
                if (mInfo.basePipelineHandle != null)
                {
                    info.basePipelineHandle = mInfo.basePipelineHandle.Native;
                }
                info.basePipelineIndex = mInfo.basePipelineIndex;

                infosMarshalled[i] = info;
            }

            using (infosMarshalled)
                using (marshalledArrays)
                    using (var pipelinesMarshalled = new PinnedArray <VkPipeline>(pipelineResults)) {
                        var result = device.Commands.createGraphicsPiplines(
                            device.Native, cache,
                            (uint)count, infosMarshalled.Address,
                            device.Instance.AllocationCallbacks, pipelinesMarshalled.Address);

                        if (result != VkResult.Success)
                        {
                            throw new PipelineException(string.Format("Error creating pipeline: {0}", result));
                        }
                        return(pipelineResults);
                    }
        }