Ejemplo n.º 1
0
        void setupDescriptorSetLayout()
        {
            var bindings = VkDescriptorSetLayoutBinding.Alloc(2);
            {
                // Binding 0 : Vertex shader uniform buffer
                bindings[0].binding         = 0;
                bindings[0].descriptorType  = VkDescriptorType.UniformBuffer;
                bindings[0].descriptorCount = 1;
                bindings[0].stageFlags      = VkShaderStageFlagBits.Vertex;
                // Binding 1 : Fragment shader image sampler
                bindings[1].binding         = 1;
                bindings[1].descriptorType  = VkDescriptorType.CombinedImageSampler;
                bindings[1].descriptorCount = 1;
                bindings[1].stageFlags      = VkShaderStageFlagBits.Fragment;
            }

            {
                var info = VkDescriptorSetLayoutCreateInfo.Alloc();
                info[0].bindings.count   = 2;
                info[0].bindings.pointer = bindings;
                VkDescriptorSetLayout layout;
                vkCreateDescriptorSetLayout(device, info, null, &layout);
                this.layout = layout;
            }

            {
                VkDescriptorSetLayout layout = this.layout;
                var info = VkPipelineLayoutCreateInfo.Alloc();
                info[0].setLayouts = layout;
                VkPipelineLayout pipelineLayout;
                vkCreatePipelineLayout(device, info, null, &pipelineLayout);
                this.pipelineLayout = pipelineLayout;
            }
        }
Ejemplo n.º 2
0
        void setupDescriptorSetLayout()
        {
            // Binding 0 : Vertex shader uniform buffer
            VkDescriptorSetLayoutBinding setLayoutBinding = new VkDescriptorSetLayoutBinding()
            {
                descriptorType  = VkDescriptorType.UniformBuffer,
                stageFlags      = VkShaderStageFlags.Vertex,
                binding         = 0,
                descriptorCount = 1
            };

            VkDescriptorSetLayoutCreateInfo descriptorLayout = VkDescriptorSetLayoutCreateInfo.New();

            descriptorLayout.pBindings    = &setLayoutBinding;
            descriptorLayout.bindingCount = 1;

            descriptorSetLayout.Count = 1;
            Util.CheckResult(vkCreateDescriptorSetLayout(Device, &descriptorLayout, null, (VkDescriptorSetLayout *)descriptorSetLayout.GetAddress(0)));

            VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo = VkPipelineLayoutCreateInfo.New();

            pPipelineLayoutCreateInfo.setLayoutCount = 1;
            pPipelineLayoutCreateInfo.pSetLayouts    = (VkDescriptorSetLayout *)descriptorSetLayout.Data.ToPointer();

            Util.CheckResult(vkCreatePipelineLayout(Device, &pPipelineLayoutCreateInfo, null, out pipelineLayout));
        }
Ejemplo n.º 3
0
        public VkShaderResourceBindingSlots(VkDevice device, ShaderResourceDescription[] resources)
        {
            Resources = resources;
            VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCI = VkDescriptorSetLayoutCreateInfo.New();

            descriptorSetLayoutCI.bindingCount = (uint)resources.Length;

            VkDescriptorSetLayoutBinding *bindings = stackalloc VkDescriptorSetLayoutBinding[resources.Length];

            for (int i = 0; i < resources.Length; i++)
            {
                ShaderResourceDescription desc = resources[i];
                bindings[i].binding         = (uint)i;
                bindings[i].descriptorType  = MapDescriptorType(desc.Type);
                bindings[i].descriptorCount = 1;
                bindings[i].stageFlags      = MapStageFlags(desc.Stages);
            }
            descriptorSetLayoutCI.pBindings = bindings;

            vkCreateDescriptorSetLayout(device, ref descriptorSetLayoutCI, null, out VkDescriptorSetLayout descriptorSetLayout);
            DescriptorSetLayout = descriptorSetLayout;

            VkPipelineLayoutCreateInfo pipelineLayoutCI = VkPipelineLayoutCreateInfo.New();

            pipelineLayoutCI.setLayoutCount = 1;
            pipelineLayoutCI.pSetLayouts    = &descriptorSetLayout;
            VkResult result = vkCreatePipelineLayout(device, ref pipelineLayoutCI, null, out VkPipelineLayout layout);

            CheckResult(result);
            PipelineLayout = layout;
        }
Ejemplo n.º 4
0
        private static VkDescriptorSetLayout CreateDescriptorLayout(VkDevice device, uint textureCount)
        {
            VkDescriptorSetLayoutBinding samplerLayoutBinding = new VkDescriptorSetLayoutBinding();

            samplerLayoutBinding.binding            = 0;
            samplerLayoutBinding.descriptorCount    = textureCount;
            samplerLayoutBinding.descriptorType     = VkDescriptorType.CombinedImageSampler;
            samplerLayoutBinding.pImmutableSamplers = null;
            samplerLayoutBinding.stageFlags         = VkShaderStageFlags.Fragment;

            VkDescriptorSetLayoutBinding uboLayoutBinding = new VkDescriptorSetLayoutBinding();

            uboLayoutBinding.binding         = 1;
            uboLayoutBinding.descriptorCount = 1;
            uboLayoutBinding.descriptorType  = VkDescriptorType.UniformBuffer;
            uboLayoutBinding.stageFlags      = VkShaderStageFlags.Vertex;

            VkDescriptorSetLayoutBinding[] bindings = new VkDescriptorSetLayoutBinding[2];
            bindings[0] = samplerLayoutBinding;
            bindings[1] = uboLayoutBinding;

            VkDescriptorSetLayoutCreateInfo layoutInfo = VkDescriptorSetLayoutCreateInfo.New();

            layoutInfo.bindingCount = (uint)bindings.Length;

            fixed(VkDescriptorSetLayoutBinding *ptr = bindings)
            layoutInfo.pBindings = ptr;

            VkDescriptorSetLayout descriptorSetLayout = VkDescriptorSetLayout.Null;

            Assert(vkCreateDescriptorSetLayout(device, &layoutInfo, null, &descriptorSetLayout));
            return(descriptorSetLayout);
        }
Ejemplo n.º 5
0
        void setupDescriptorSetLayout()
        {
            FixedArray2<VkDescriptorSetLayoutBinding> setLayoutBindings = new FixedArray2<VkDescriptorSetLayoutBinding>(
                // Binding 0 : Vertex shader uniform buffer
                Initializers.descriptorSetLayoutBinding(
                    VkDescriptorType.UniformBuffer,
                    VkShaderStageFlags.Vertex,
                    0),
                // Binding 1 : Fragment shader image sampler
                Initializers.descriptorSetLayoutBinding(
                    VkDescriptorType.CombinedImageSampler,
                    VkShaderStageFlags.Fragment,
                    1));

            VkDescriptorSetLayoutCreateInfo descriptorLayout =
                Initializers.descriptorSetLayoutCreateInfo(
                    &setLayoutBindings.First,
                    setLayoutBindings.Count);

            Util.CheckResult(vkCreateDescriptorSetLayout(device, &descriptorLayout, null, out descriptorSetLayout));

            var dsl = descriptorSetLayout;
            VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo =
                Initializers.pipelineLayoutCreateInfo(
                    &dsl,
                    1);

            Util.CheckResult(vkCreatePipelineLayout(device, &pPipelineLayoutCreateInfo, null, out pipelineLayout));
        }
Ejemplo n.º 6
0
        public VkResourceLayout(VkGraphicsDevice gd, ref ResourceLayoutDescription description)
        {
            _gd = gd;
            VkDescriptorSetLayoutCreateInfo dslCI = VkDescriptorSetLayoutCreateInfo.New();

            ResourceLayoutElementDescription[] elements = description.Elements;
            _descriptorTypes = new VkDescriptorType[elements.Length];
            VkDescriptorSetLayoutBinding *bindings = stackalloc VkDescriptorSetLayoutBinding[elements.Length];

            for (uint i = 0; i < elements.Length; i++)
            {
                bindings[i].binding         = i;
                bindings[i].descriptorCount = 1;
                VkDescriptorType descriptorType = VkFormats.VdToVkDescriptorType(elements[i].Kind);
                bindings[i].descriptorType = descriptorType;
                bindings[i].stageFlags     = VkFormats.VdToVkShaderStages(elements[i].Stages);

                _descriptorTypes[i] = descriptorType;
            }

            dslCI.bindingCount = (uint)elements.Length;
            dslCI.pBindings    = bindings;

            VkResult result = vkCreateDescriptorSetLayout(_gd.Device, ref dslCI, null, out _dsl);

            CheckResult(result);
        }
        void setupDescriptorSetLayout()
        {
            var bindings = new VkDescriptorSetLayoutBinding[] {
                // layout (binding = 0) uniform UboView
                new VkDescriptorSetLayoutBinding(0, VkDescriptorType.UniformBuffer, 1, VkShaderStageFlagBits.Vertex),
                // layout (binding = 1) uniform UboInstance
                new VkDescriptorSetLayoutBinding(1, VkDescriptorType.UniformBufferDynamic, 1, VkShaderStageFlagBits.Vertex),
                // no matching uniform sampler2D in shader.
                new VkDescriptorSetLayoutBinding(2, VkDescriptorType.CombinedImageSampler, 1, VkShaderStageFlagBits.Fragment),
            };

            var descriptorLayoutInfo = new VkDescriptorSetLayoutCreateInfo();

            descriptorLayoutInfo.sType    = DescriptorSetLayoutCreateInfo;
            descriptorLayoutInfo.bindings = bindings;

            VkDescriptorSetLayout layout;

            vkCreateDescriptorSetLayout(device, &descriptorLayoutInfo, null, &layout);
            this.descriptorSetLayout = layout;

            VkPipelineLayoutCreateInfo info = new VkPipelineLayoutCreateInfo();

            info.sType      = PipelineLayoutCreateInfo;
            info.setLayouts = layout;

            VkPipelineLayout pipelineLayout;

            vkCreatePipelineLayout(device, &info, null, &pipelineLayout);
            this.pipelineLayout = pipelineLayout;
        }
        private VkDescriptorSetLayout CreateDescriptorSetLayout()
        {
            VkDescriptorSetLayoutBinding *bindings = stackalloc VkDescriptorSetLayoutBinding[2];

            bindings[0] = new VkDescriptorSetLayoutBinding
            {
                binding         = 0,
                descriptorType  = VkDescriptorType.UniformBuffer,
                descriptorCount = 1,
                stageFlags      = VkShaderStageFlags.Vertex
            };
            bindings[1] = new VkDescriptorSetLayoutBinding
            {
                binding         = 1,
                descriptorType  = VkDescriptorType.CombinedImageSampler,
                descriptorCount = 1,
                stageFlags      = VkShaderStageFlags.Fragment
            };
            var createInfo = new VkDescriptorSetLayoutCreateInfo
            {
                sType        = VkStructureType.DescriptorSetLayoutCreateInfo,
                pNext        = null,
                bindingCount = 2,
                pBindings    = bindings
            };
            VkDescriptorSetLayout layout;

            vkCreateDescriptorSetLayout(Context.Device, &createInfo, null, out layout).CheckResult();
            return(layout);
        }
        /// <summary>
        /// Builds the descriptor set layout
        /// </summary>
        /// <returns>The layout</returns>
        public DescriptorSetLayout Build()
        {
            try
            {
                var bindings = _bindings.Values.ToArray();
                unsafe
                {
                    fixed(VkDescriptorSetLayoutBinding *pBindings = bindings)
                    {
                        var info = new VkDescriptorSetLayoutCreateInfo()
                        {
                            SType        = VkStructureType.DescriptorSetLayoutCreateInfo,
                            PNext        = IntPtr.Zero,
                            Flags        = _flags,
                            BindingCount = (uint)bindings.Length,
                            PBindings    = pBindings
                        };

                        return(new DescriptorSetLayout(_device, info));
                    }
                }
            }
            finally
            {
                foreach (var pin in _pins)
                {
                    pin.Free();
                }
                _pins.Clear();
            }
        }
Ejemplo n.º 10
0
        VkDescriptorSetLayout CreateDescriptorSetLayout(VkDevice device)
        {
            /*
             * layout (set = 0, binding = 0) uniform AreaUB
             * {
             * float width;
             * float height;
             * } area;
             */
            var info = new VkDescriptorSetLayoutCreateInfo {
                sType = VkStructureType.DescriptorSetLayoutCreateInfo
            };

            info.bindings = new VkDescriptorSetLayoutBinding(
                binding: 0,
                descriptorType: VkDescriptorType.UniformBuffer, // uniform
                descriptorCount: 1,                             // single variable, not array.
                stageFlags: VkShaderStageFlagBits.Vertex);      // in a vertex shader.

            //return device.CreateDescriptorSetLayout(ref info);
            VkDescriptorSetLayout layout;

            vkAPI.vkCreateDescriptorSetLayout(device, &info, null, &layout).Check();
            info.Free();

            return(layout);
        }
Ejemplo n.º 11
0
        internal static unsafe VkDescriptorSetLayout CreateNativeDescriptorSetLayout(GraphicsDevice device, IList <DescriptorSetLayoutBuilder.Entry> entries, out uint[] typeCounts)
        {
            var bindings          = new VkDescriptorSetLayoutBinding[entries.Count];
            var immutableSamplers = new VkSampler[entries.Count];

            int usedBindingCount = 0;

            typeCounts = new uint[DescriptorTypeCount];

            fixed(VkSampler *immutableSamplersPointer = &immutableSamplers[0])
            {
                for (int i = 0; i < entries.Count; i++)
                {
                    var entry = entries[i];

                    // TODO VULKAN: Special case for unused bindings in PipelineState. Handle more nicely.
                    if (entry.ArraySize == 0)
                    {
                        continue;
                    }

                    bindings[usedBindingCount] = new VkDescriptorSetLayoutBinding
                    {
                        descriptorType  = VulkanConvertExtensions.ConvertDescriptorType(entry.Class, entry.Type),
                        stageFlags      = VkShaderStageFlags.All, // TODO VULKAN: Filter?
                        binding         = (uint)i,
                        descriptorCount = (uint)entry.ArraySize
                    };

                    if (entry.ImmutableSampler != null)
                    {
                        // TODO VULKAN: Handle immutable samplers for DescriptorCount > 1
                        if (entry.ArraySize > 1)
                        {
                            throw new NotImplementedException();
                        }

                        // Remember this, so we can choose the right VkDescriptorType in DescriptorSet.SetShaderResourceView
                        immutableSamplers[i] = entry.ImmutableSampler.NativeSampler;
                        //bindings[i].VkDescriptorType = VkDescriptorType.CombinedImageSampler;
                        bindings[usedBindingCount].pImmutableSamplers = immutableSamplersPointer + i;
                    }

                    typeCounts[(int)bindings[usedBindingCount].descriptorType] += bindings[usedBindingCount].descriptorCount;

                    usedBindingCount++;
                }

                var createInfo = new VkDescriptorSetLayoutCreateInfo
                {
                    sType        = VkStructureType.DescriptorSetLayoutCreateInfo,
                    bindingCount = (uint)usedBindingCount,
                    pBindings    = usedBindingCount > 0 ? (VkDescriptorSetLayoutBinding *)Core.Interop.Fixed(bindings) : null,
                };

                vkCreateDescriptorSetLayout(device.NativeDevice, &createInfo, null, out var descriptorSetLayout);
                return(descriptorSetLayout);
            }
        }
        public VkDescriptorSetLayout CreateDescriptorSetLayout(VkDevice device, VkDescriptorSetLayoutBinding[] bindings)
        {
            VkDescriptorSetLayout layout      = null;
            var descriptorSetLayoutCreateInfo = new VkDescriptorSetLayoutCreateInfo();

            descriptorSetLayoutCreateInfo.bindings = bindings;
            VulkanAPI.vkCreateDescriptorSetLayout(device, ref descriptorSetLayoutCreateInfo, out layout);
            m_descLayouts.Add(layout);
            return(layout);
        }
Ejemplo n.º 13
0
        public static VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo(
            VkDescriptorSetLayoutBinding *pBindings,
            uint bindingCount)
        {
            VkDescriptorSetLayoutCreateInfo descriptorSetLayoutCreateInfo = VkDescriptorSetLayoutCreateInfo.New();

            descriptorSetLayoutCreateInfo.pBindings    = pBindings;
            descriptorSetLayoutCreateInfo.bindingCount = bindingCount;
            return(descriptorSetLayoutCreateInfo);
        }
Ejemplo n.º 14
0
 public override void Activate()
 {
     if (state != ActivableState.Activated)
     {
         VkDescriptorSetLayoutCreateInfo info = new VkDescriptorSetLayoutCreateInfo(Flags, (uint)Bindings.Count, Bindings.Pin());
         Utils.CheckResult(vkCreateDescriptorSetLayout(Dev.VkDev, ref info, IntPtr.Zero, out handle));
         Bindings.Unpin();
     }
     base.Activate();
 }
        private void PrepareDescriptor(VkDevice device)
        {
            // 定数バッファを1つだけ持つものを作る.
            VkDescriptorPoolSize descriptorPoolSize = new VkDescriptorPoolSize()
            {
                descriptorCount = 1,
                type            = VkDescriptorType.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
            };
            var descriptorPoolCreateInfo = new VkDescriptorPoolCreateInfo()
            {
                poolSizes = new[] { descriptorPoolSize },
                maxSets   = 1,
                flags     = VkDescriptorPoolCreateFlags.VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
            };

            VulkanAPI.vkCreateDescriptorPool(device, ref descriptorPoolCreateInfo, out m_descriptorPool);

            // ディスクリプタセットレイアウトの作成.
            // 今は定数バッファを1つ持つだけのものを作成.
            var descriptorLayoutBinding = new VkDescriptorSetLayoutBinding();

            descriptorLayoutBinding.binding         = 0;
            descriptorLayoutBinding.descriptorCount = 1;
            descriptorLayoutBinding.descriptorType  = VkDescriptorType.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
            descriptorLayoutBinding.stageFlags      = VkShaderStageFlagBits.VK_SHADER_STAGE_VERTEX_BIT;

            var descriptorSetLayoutCreateInfo = new VkDescriptorSetLayoutCreateInfo();

            descriptorSetLayoutCreateInfo.bindings = new[] { descriptorLayoutBinding };
            VulkanAPI.vkCreateDescriptorSetLayout(device, ref descriptorSetLayoutCreateInfo, out m_descriptorSetLayout);

            // ディスクリプタセットを作成.
            VkDescriptorSet[] descriptorSets;
            var descriptorSetAllocateInfo = new VkDescriptorSetAllocateInfo(m_descriptorPool, new[] { m_descriptorSetLayout });

            VulkanAPI.vkAllocateDescriptorSets(device, ref descriptorSetAllocateInfo, out descriptorSets);
            m_descriptorSet = descriptorSets[0];

            // ディスクリプタを更新.
            // 定数バッファ1つを持つレイアウトでディスクリプタを作る.
            VkDescriptorBufferInfo descUniformBufferInfo = new VkDescriptorBufferInfo();

            descUniformBufferInfo.buffer = m_uniformBuffer;
            descUniformBufferInfo.range  = Marshal.SizeOf <Transform>();
            var descriptor = new VkWriteDescriptorSet();

            descriptor.descriptorCount = 1;
            descriptor.descriptorType  = VkDescriptorType.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
            descriptor.pBufferInfo     = new[] { descUniformBufferInfo };
            descriptor.dstBinding      = 0;
            descriptor.dstSet          = m_descriptorSet;
            VulkanAPI.vkUpdateDescriptorSets(device, new[] { descriptor }, null);
        }
Ejemplo n.º 16
0
 public DescriptorSetLayout(Device dev, VkDescriptorSetLayoutCreateInfo info)
 {
     Device          = dev;
     _descriptorData = new Dictionary <uint, DescriptorData>((int)info.BindingCount);
     unsafe
     {
         for (var i = 0; i < info.BindingCount; i++)
         {
             _descriptorData.Add(info.PBindings[i].Binding, new DescriptorData(info.PBindings[i]));
         }
         Handle = dev.Handle.CreateDescriptorSetLayout(&info, dev.Instance.AllocationCallbacks);
     }
 }
Ejemplo n.º 17
0
        public SoftwareDescriptorSet(SoftwareDescriptorPool descriptorPool, SoftwareDescriptorSetLayout layout)
        {
            this.m_descriptorPool      = descriptorPool;
            this.m_descriptorSetLayout = layout;
            this.m_createInfo          = layout.m_createInfo;

            m_Bindings   = new VkDescriptorSetLayoutBinding[m_createInfo.bindingCount];
            m_BufferInfo = new VkDescriptorBufferInfo[m_createInfo.bindingCount];
            m_ImageInfo  = new VkDescriptorImageInfo[m_createInfo.bindingCount];

            for (int i = 0; i < m_createInfo.bindingCount; i++)
            {
                m_Bindings[i] = m_createInfo.pBindings[i];
            }
        }
Ejemplo n.º 18
0
        void CreateDescriptorSetLayout()
        {
            var uboLayoutBinding = new VkDescriptorSetLayoutBinding();

            uboLayoutBinding.binding         = 0;
            uboLayoutBinding.descriptorType  = VkDescriptorType.UniformBuffer;
            uboLayoutBinding.descriptorCount = 1;
            uboLayoutBinding.stageFlags      = VkShaderStageFlags.VertexBit;

            var info = new VkDescriptorSetLayoutCreateInfo();

            info.bindings = new List <VkDescriptorSetLayoutBinding> {
                uboLayoutBinding
            };

            descriptorSetLayout = new VkDescriptorSetLayout(device, info);
        }
Ejemplo n.º 19
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));
                }
            }
        }
Ejemplo n.º 20
0
        void setupDescriptorSetLayout()
        {
            VkDescriptorSetLayoutBinding setLayoutBindings =
                // Binding 0 : Vertex shader uniform buffer
                Initializers.descriptorSetLayoutBinding(
                    VkDescriptorType.UniformBuffer,
                    VkShaderStageFlags.Vertex,
                    0);

            VkDescriptorSetLayoutCreateInfo descriptorLayout =
                Initializers.descriptorSetLayoutCreateInfo(
                    &setLayoutBindings,
                    1);

            Util.CheckResult(vkCreateDescriptorSetLayout(device, &descriptorLayout, null, out descriptorSetLayout));

            var dsl = descriptorSetLayout;
            VkPipelineLayoutCreateInfo pipelineLayoutCreateInfo =
                Initializers.pipelineLayoutCreateInfo(
                    &dsl,
                    1);

            // Define push constant
            // Example uses six light positions as push constants
            // 6 * 4 * 4 = 96 bytes
            // Spec requires a minimum of 128 bytes, bigger values
            // need to be checked against maxPushConstantsSize
            // But even at only 128 bytes, lots of stuff can fit
            // inside push constants
            VkPushConstantRange pushConstantRange =
                Initializers.pushConstantRange(
                    VkShaderStageFlags.Vertex,
                    pushConstants.Count * (uint)sizeof(Vector4),
                    0);

            // Push constant ranges are part of the pipeline layout
            pipelineLayoutCreateInfo.pushConstantRangeCount = 1;
            pipelineLayoutCreateInfo.pPushConstantRanges    = &pushConstantRange;

            Util.CheckResult(vkCreatePipelineLayout(device, &pipelineLayoutCreateInfo, null, out pipelineLayout));
        }
        void setupDescriptorSetLayout()
        {
            FixedArray2 <VkDescriptorSetLayoutBinding> setLayoutBindings = new FixedArray2 <VkDescriptorSetLayoutBinding>(
                Initializers.descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, VK_SHADER_STAGE_VERTEX_BIT, 0),
                Initializers.descriptorSetLayoutBinding(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, VK_SHADER_STAGE_FRAGMENT_BIT, 1));

            VkDescriptorSetLayoutCreateInfo descriptorLayout =
                Initializers.descriptorSetLayoutCreateInfo(
                    &setLayoutBindings.First,
                    setLayoutBindings.Count);

            Util.CheckResult(vkCreateDescriptorSetLayout(device, &descriptorLayout, null, out descriptorSetLayout));

            var dsl = descriptorSetLayout;
            VkPipelineLayoutCreateInfo pPipelineLayoutCreateInfo =
                Initializers.pipelineLayoutCreateInfo(
                    &dsl,
                    1);

            Util.CheckResult(vkCreatePipelineLayout(device, &pPipelineLayoutCreateInfo, null, out pipelineLayout));
        }
Ejemplo n.º 22
0
        public unsafe DescriptorLayout(Device device, List <DescriptorBindingInfo> bindings)
        {
            _device   = device;
            _bindings = bindings;

            var vulkanBindings = new NativeList <VkDescriptorSetLayoutBinding>();

            foreach (var binding in bindings)
            {
                vulkanBindings.Add(new VkDescriptorSetLayoutBinding
                {
                    binding         = binding.Index,
                    descriptorType  = binding.DescriptorType,
                    descriptorCount = binding.DescriptorCounts,
                    stageFlags      = binding.ShaderStageFlags
                });
            }

            var createInfo = new VkDescriptorSetLayoutCreateInfo
            {
                sType        = VkStructureType.DescriptorSetLayoutCreateInfo,
                bindingCount = vulkanBindings.Count,
                pBindings    = (VkDescriptorSetLayoutBinding *)vulkanBindings.Data.ToPointer()
            };

            VkDescriptorSetLayout layout;

            if (VulkanNative.vkCreateDescriptorSetLayout(
                    device.Handle,
                    &createInfo,
                    null,
                    &layout
                    ) != VkResult.Success)
            {
                throw new Exception("failed to create descriptor set layout");
            }
            _handle = layout;
        }
Ejemplo n.º 23
0
        public unsafe DescriptorSetLayout Build()
        {
            if (!needRebuild)
            {
                return(this);
            }

            needRebuild = false;

            Destroy(true);

            bindings = new VkDescriptorSetLayoutBinding[Bindings.Count];
            for (int i = 0; i < Bindings.Count; i++)
            {
                bindings[i] = new VkDescriptorSetLayoutBinding
                {
                    descriptorType  = Bindings[i].descriptorType,
                    stageFlags      = Bindings[i].stageFlags,
                    binding         = Bindings[i].binding,
                    descriptorCount = Bindings[i].descriptorCount
                };
            }

            var descriptorSetLayoutCreateInfo = new VkDescriptorSetLayoutCreateInfo
            {
                sType = VkStructureType.DescriptorSetLayoutCreateInfo
            };

            descriptorSetLayoutCreateInfo.pBindings    = (VkDescriptorSetLayoutBinding *)Utilities.AsPointer(ref bindings[0]);
            descriptorSetLayoutCreateInfo.bindingCount = (uint)bindings.Length;

            descriptorSetLayout = Device.CreateDescriptorSetLayout(ref descriptorSetLayoutCreateInfo);

            descriptorResourceCounts = new DescriptorResourceCounts();
            foreach (var binding in bindings)
            {
                int index = binding.descriptorType switch
                {
Ejemplo n.º 24
0
        void setupDescriptorSetLayout()
        {
            var bindings = new VkDescriptorSetLayoutBinding[2];

            // Binding 0 : Vertex shader uniform buffer
            bindings[0] = new VkDescriptorSetLayoutBinding();
            bindings[0].descriptorType  = VkDescriptorType.UniformBuffer;
            bindings[0].stageFlags      = VkShaderStageFlagBits.Vertex;
            bindings[0].binding         = 0;
            bindings[0].descriptorCount = 1;
            // Binding 1 : Fragment shader combined sampler
            bindings[1] = new VkDescriptorSetLayoutBinding();
            bindings[1].descriptorType  = VkDescriptorType.CombinedImageSampler;
            bindings[1].stageFlags      = VkShaderStageFlagBits.Fragment;
            bindings[1].binding         = 1;
            bindings[1].descriptorCount = 1;

            var descriptorLayout = VkDescriptorSetLayoutCreateInfo.Alloc();

            descriptorLayout->bindings = bindings;

            VkDescriptorSetLayout dsl;

            vkCreateDescriptorSetLayout(device, descriptorLayout, null, &dsl);
            this.descriptorSetLayout = dsl;

            var info = new VkPipelineLayoutCreateInfo();

            info.sType      = PipelineLayoutCreateInfo;
            info.setLayouts = dsl;

            {
                VkPipelineLayout layout;
                vkCreatePipelineLayout(device, &info, null, &layout);
                this.pipelineLayout = layout;
            }
        }
Ejemplo n.º 25
0
 public static extern VkResult CreateDescriptorSetLayout(
     VkDevice device,
     ref VkDescriptorSetLayoutCreateInfo pCreateInfo,
     IntPtr pAllocator,
     out VkDescriptorSetLayout pSetLayout
     );
Ejemplo n.º 26
0
        public VkResourceLayout(VkGraphicsDevice gd, ref ResourceLayoutDescription description)
            : base(ref description)
        {
            _gd = gd;
            VkDescriptorSetLayoutCreateInfo dslCI = VkDescriptorSetLayoutCreateInfo.New();

            ResourceLayoutElementDescription[] elements = description.Elements;
            _descriptorTypes = new VkDescriptorType[elements.Length];
            VkDescriptorSetLayoutBinding *bindings = stackalloc VkDescriptorSetLayoutBinding[elements.Length];

            uint uniformBufferCount = 0;
            uint sampledImageCount  = 0;
            uint samplerCount       = 0;
            uint storageBufferCount = 0;
            uint storageImageCount  = 0;

            for (uint i = 0; i < elements.Length; i++)
            {
                bindings[i].binding         = i;
                bindings[i].descriptorCount = 1;
                VkDescriptorType descriptorType = VkFormats.VdToVkDescriptorType(elements[i].Kind, elements[i].Options);
                bindings[i].descriptorType = descriptorType;
                bindings[i].stageFlags     = VkFormats.VdToVkShaderStages(elements[i].Stages);
                if ((elements[i].Options & ResourceLayoutElementOptions.DynamicBinding) != 0)
                {
                    DynamicBufferCount += 1;
                }

                _descriptorTypes[i] = descriptorType;

                switch (descriptorType)
                {
                case VkDescriptorType.Sampler:
                    samplerCount += 1;
                    break;

                case VkDescriptorType.SampledImage:
                    sampledImageCount += 1;
                    break;

                case VkDescriptorType.StorageImage:
                    storageImageCount += 1;
                    break;

                case VkDescriptorType.UniformBuffer:
                    uniformBufferCount += 1;
                    break;

                case VkDescriptorType.StorageBuffer:
                    storageBufferCount += 1;
                    break;
                }
            }

            DescriptorResourceCounts = new DescriptorResourceCounts(
                uniformBufferCount,
                sampledImageCount,
                samplerCount,
                storageBufferCount,
                storageImageCount);

            dslCI.bindingCount = (uint)elements.Length;
            dslCI.pBindings    = bindings;

            VkResult result = vkCreateDescriptorSetLayout(_gd.Device, ref dslCI, null, out _dsl);

            CheckResult(result);
        }
        private VkDescriptorSetLayout CreateVulkanDescriptorSetLayout()
        {
            VkDescriptorSetLayout vulkanDescriptorSetLayout;

            var descriptorSetLayoutBindings = Array.Empty <VkDescriptorSetLayoutBinding>();

            var descriptorSetLayoutCreateInfo = new VkDescriptorSetLayoutCreateInfo {
                sType = VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO,
            };

            var resources       = Resources;
            var resourcesLength = resources.Length;

            var descriptorSetLayoutBindingsIndex = 0;

            if (resourcesLength != 0)
            {
                descriptorSetLayoutBindings = new VkDescriptorSetLayoutBinding[resourcesLength];

                for (var resourceIndex = 0; resourceIndex < resourcesLength; resourceIndex++)
                {
                    var resource = resources[resourceIndex];

                    switch (resource.Kind)
                    {
                    case GraphicsPipelineResourceKind.ConstantBuffer:
                    {
                        var stageFlags = GetVulkanShaderStageFlags(resource.ShaderVisibility);

                        descriptorSetLayoutBindings[descriptorSetLayoutBindingsIndex] = new VkDescriptorSetLayoutBinding {
                            binding         = unchecked ((uint)descriptorSetLayoutBindingsIndex),
                            descriptorType  = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
                            descriptorCount = 1,
                            stageFlags      = stageFlags,
                        };

                        descriptorSetLayoutBindingsIndex++;
                        break;
                    }

                    case GraphicsPipelineResourceKind.Texture:
                    {
                        var stageFlags = GetVulkanShaderStageFlags(resource.ShaderVisibility);

                        descriptorSetLayoutBindings[descriptorSetLayoutBindingsIndex] = new VkDescriptorSetLayoutBinding {
                            binding         = unchecked ((uint)descriptorSetLayoutBindingsIndex),
                            descriptorType  = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
                            descriptorCount = 1,
                            stageFlags      = stageFlags,
                        };

                        descriptorSetLayoutBindingsIndex++;
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                }

                fixed(VkDescriptorSetLayoutBinding *pDescriptorSetLayoutBindings = descriptorSetLayoutBindings)
                {
                    descriptorSetLayoutCreateInfo.bindingCount = unchecked ((uint)descriptorSetLayoutBindings.Length);
                    descriptorSetLayoutCreateInfo.pBindings    = pDescriptorSetLayoutBindings;

                    ThrowExternalExceptionIfNotSuccess(vkCreateDescriptorSetLayout(Device.VulkanDevice, &descriptorSetLayoutCreateInfo, pAllocator: null, (ulong *)&vulkanDescriptorSetLayout), nameof(vkCreateDescriptorSetLayout));
                }
            }
            else
            {
                vulkanDescriptorSetLayout = VK_NULL_HANDLE;
            }

            return(vulkanDescriptorSetLayout);
Ejemplo n.º 28
0
 public SoftwareDescriptorSetLayout(SoftwareDevice device, VkDescriptorSetLayoutCreateInfo createInfo)
 {
     this.m_device     = device;
     this.m_createInfo = createInfo;
 }
Ejemplo n.º 29
0
 public override VkResult CreateDescriptorSetLayout(VkDescriptorSetLayoutCreateInfo pCreateInfo, out VkDescriptorSetLayout pSetLayout)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 30
0
 public abstract VkResult CreateDescriptorSetLayout(VkDescriptorSetLayoutCreateInfo pCreateInfo, out VkDescriptorSetLayout pSetLayout);