Beispiel #1
0
        void CreateLayout(PipelineLayoutCreateInfo mInfo)
        {
            VkPipelineLayoutCreateInfo info = new VkPipelineLayoutCreateInfo();

            info.sType = VkStructureType.PipelineLayoutCreateInfo;

            NativeArray <VkDescriptorSetLayout> layoutsMarshalled = null;

            if (mInfo.setLayouts != null)
            {
                layoutsMarshalled = new NativeArray <VkDescriptorSetLayout>(mInfo.setLayouts.Count);
                for (int i = 0; i < mInfo.setLayouts.Count; i++)
                {
                    layoutsMarshalled[i] = mInfo.setLayouts[i].Native;
                }
                info.setLayoutCount = (uint)layoutsMarshalled.Count;
                info.pSetLayouts    = layoutsMarshalled.Address;
            }

            var pushConstantsMarshalled = new MarshalledArray <VkPushConstantRange>(mInfo.pushConstantRanges);

            info.pushConstantRangeCount = (uint)pushConstantsMarshalled.Count;
            info.pPushConstantRanges    = pushConstantsMarshalled.Address;

            using (layoutsMarshalled)
                using (pushConstantsMarshalled) {
                    var result = Device.Commands.createPipelineLayout(Device.Native, ref info, Device.Instance.AllocationCallbacks, out pipelineLayout);
                    if (result != VkResult.Success)
                    {
                        throw new PipelineLayoutException(string.Format("Error creating pipeline layout: {0}", result));
                    }
                }
        }
        internal VkPipelineColorBlendStateCreateInfo GetNative(DisposableList <IDisposable> marshalled)
        {
            var result = new VkPipelineColorBlendStateCreateInfo();

            result.sType           = VkStructureType.PipelineColorBlendStateCreateInfo;
            result.logicOpEnable   = logicOpEnable ? 1u : 0u;
            result.logicOp         = logicOp;
            result.attachmentCount = (uint)this.attachments.Count;

            var attachments = new VkPipelineColorBlendAttachmentState[this.attachments.Count];

            for (int i = 0; i < attachments.Length; i++)
            {
                attachments[i] = this.attachments[i].GetNative();
            }

            var attachMarshalled = new MarshalledArray <VkPipelineColorBlendAttachmentState>(attachments);

            result.attachmentCount = (uint)attachMarshalled.Count;
            result.pAttachments    = attachMarshalled.Address;

            if (blendConstants != null)
            {
                result.blendConstants_0 = blendConstants[0];
                result.blendConstants_1 = blendConstants[1];
                result.blendConstants_2 = blendConstants[2];
                result.blendConstants_3 = blendConstants[3];
            }

            marshalled.Add(attachMarshalled);

            return(result);
        }
Beispiel #3
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));
                            }
                        }
        }
Beispiel #4
0
        static void GetExtensions()
        {
            availableExtensions = new List <Extension>();

            uint exCount = 0;

            enumerateExtensionProperties(null, ref exCount, IntPtr.Zero);

            using (var extensionsMarshalled = new MarshalledArray <VkExtensionProperties>((int)exCount)) {
                enumerateExtensionProperties(null, ref exCount, extensionsMarshalled.Address);

                for (int i = 0; i < exCount; i++)
                {
                    var extension = extensionsMarshalled[i];
                    availableExtensions.Add(new Extension(extension));
                }
            }
            extensionsReadOnly = availableExtensions.AsReadOnly();
        }
Beispiel #5
0
        static void GetLayers()
        {
            availableLayers = new List <Layer>();

            uint lCount = 0;

            enumerateLayerProperties(ref lCount, IntPtr.Zero);

            using (var layersMarshalled = new MarshalledArray <VkLayerProperties>((int)lCount)) {
                enumerateLayerProperties(ref lCount, layersMarshalled.Address);

                for (int i = 0; i < lCount; i++)
                {
                    var layer = layersMarshalled[i];
                    availableLayers.Add(new Layer(layer));
                }
            }
            layersReadOnly = availableLayers.AsReadOnly();
        }
Beispiel #6
0
        void CreateDescriptorSetLayout(DescriptorSetLayoutCreateInfo mInfo)
        {
            var info = new VkDescriptorSetLayoutCreateInfo();

            info.sType = VkStructureType.DescriptorSetLayoutCreateInfo;

            var bindingsMarshalled = new MarshalledArray <VkDescriptorSetLayoutBinding>(mInfo.bindings);

            info.bindingCount = (uint)bindingsMarshalled.Count;
            info.pBindings    = bindingsMarshalled.Address;

            using (bindingsMarshalled) {
                var result = Device.Commands.createDescriptorSetLayout(Device.Native, ref info, Device.Instance.AllocationCallbacks, out descriptorSetLayout);
                if (result != VkResult.Success)
                {
                    throw new DescriptorSetLayoutException(string.Format("Error creating description set layout: {0}", result));
                }
            }
        }
        void GetDeviceExtensions()
        {
            List <Extension> availableExtensions = new List <Extension>();
            uint             count = 0;

            Instance.Commands.getExtensions(physicalDevice, null, ref count, IntPtr.Zero);
            var props = new MarshalledArray <VkExtensionProperties>((int)count);

            Instance.Commands.getExtensions(physicalDevice, null, ref count, props.Address);

            using (props) {
                for (int i = 0; i < count; i++)
                {
                    var ex = props[i];
                    availableExtensions.Add(new Extension(ex));
                }
            }

            AvailableExtensions = availableExtensions.AsReadOnly();
        }
Beispiel #8
0
        static internal VkPipeline[] CreatePipelinesInternal(Device device, ComputePipelineCreateInfo[] mInfos, VkPipelineCache cache)
        {
            int count            = mInfos.Length;
            var infosMarshalled  = new MarshalledArray <VkComputePipelineCreateInfo>(count);
            var pipelineResults  = new VkPipeline[count];
            var marshalledArrays = new DisposableList <IDisposable>(count);

            for (int i = 0; i < count; i++)
            {
                var mInfo = mInfos[i];
                VkComputePipelineCreateInfo info = new VkComputePipelineCreateInfo();
                info.sType = VkStructureType.ComputePipelineCreateInfo;
                info.flags = mInfo.flags;

                info.stage = mInfo.stage.GetNative(marshalledArrays);

                info.layout = mInfo.layout.Native;
                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.createComputePipelines(
                            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);
                    }
        }
        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);
        }
        internal VkPipelineVertexInputStateCreateInfo GetNative(DisposableList <IDisposable> marshalled)
        {
            var result = new VkPipelineVertexInputStateCreateInfo();

            result.sType = VkStructureType.PipelineVertexInputStateCreateInfo;

            var attMarshalled = new MarshalledArray <VkVertexInputAttributeDescription>(vertexAttributeDescriptions);

            result.vertexAttributeDescriptionCount = (uint)attMarshalled.Count;
            result.pVertexAttributeDescriptions    = attMarshalled.Address;

            var bindMarshalled = new MarshalledArray <VkVertexInputBindingDescription>(vertexBindingDescriptions);

            result.vertexBindingDescriptionCount = (uint)bindMarshalled.Count;
            result.pVertexBindingDescriptions    = bindMarshalled.Address;

            marshalled.Add(attMarshalled);
            marshalled.Add(bindMarshalled);

            return(result);
        }
        internal VkPipelineViewportStateCreateInfo GetNative(DisposableList <IDisposable> marshalled)
        {
            var result = new VkPipelineViewportStateCreateInfo();

            result.sType = VkStructureType.PipelineViewportStateCreateInfo;

            var viewportMarshalled = new MarshalledArray <VkViewport>(viewports);

            result.viewportCount = (uint)viewportMarshalled.Count;
            result.pViewports    = viewportMarshalled.Address;

            var scissorMarshalled = new MarshalledArray <VkRect2D>(scissors);

            result.scissorCount = (uint)scissorMarshalled.Count;
            result.pScissors    = scissorMarshalled.Address;

            marshalled.Add(viewportMarshalled);
            marshalled.Add(scissorMarshalled);

            return(result);
        }
Beispiel #12
0
        void GetSparseRequirements()
        {
            sparseRequirements = new List <VkSparseImageMemoryRequirements>();

            uint count = 0;

            Device.Commands.getImageSparseRequirements(Device.Native, image, ref count, IntPtr.Zero);
            var sparseRequirementsNative = new MarshalledArray <VkSparseImageMemoryRequirements>((int)count);

            Device.Commands.getImageSparseRequirements(Device.Native, image, ref count, sparseRequirementsNative.Address);

            using (sparseRequirementsNative) {
                for (int i = 0; i < count; i++)
                {
                    var requirement = sparseRequirementsNative[i];
                    sparseRequirements.Add(requirement);
                }
            }

            SparseRequirements = sparseRequirements.AsReadOnly();
        }
        void GetQueueProperties()
        {
            List <QueueFamily> queueFamilies = new List <QueueFamily>();
            uint count = 0;

            Instance.Commands.getQueueFamilyProperties(physicalDevice, ref count, IntPtr.Zero);
            var props = new MarshalledArray <VkQueueFamilyProperties>((int)count);

            Instance.Commands.getQueueFamilyProperties(physicalDevice, ref count, props.Address);

            using (props) {
                for (int i = 0; i < count; i++)
                {
                    var queueFamily = props[i];
                    var fam         = new QueueFamily(queueFamily, this, (uint)i);
                    queueFamilies.Add(fam);
                }
            }

            QueueFamilies = queueFamilies.AsReadOnly();
        }
        public List <VkSparseImageFormatProperties> GetSparseImageFormatProperties(VkFormat format, VkImageType type, VkSampleCountFlags samples, VkImageUsageFlags usage, VkImageTiling tiling)
        {
            var result = new List <VkSparseImageFormatProperties>();

            uint count = 0;

            Instance.Commands.getPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage, tiling, ref count, IntPtr.Zero);
            var resultNative = new MarshalledArray <VkSparseImageFormatProperties>((int)count);

            Instance.Commands.getPhysicalDeviceSparseImageFormatProperties(physicalDevice, format, type, samples, usage, tiling, ref count, resultNative.Address);

            using (resultNative) {
                for (int i = 0; i < count; i++)
                {
                    var prop = resultNative[i];
                    result.Add(prop);
                }
            }

            return(result);
        }
        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);
                    }
        }