Пример #1
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);
        }
        /// <summary>
        /// Adds the given binding descriptor
        /// </summary>
        /// <param name="binding">Binding to add</param>
        /// <param name="type">Binding type</param>
        /// <param name="arraySize">Binding's array size</param>
        /// <param name="flags">Shader stages</param>
        /// <param name="immutableSamplers">Immutable samplers for the binding</param>
        /// <returns>this</returns>
        public DescriptorSetLayoutBuilder Add(uint binding, VkDescriptorType type, uint arraySize,
                                              VkShaderStageFlag flags, params Sampler[] immutableSamplers)
        {
            Debug.Assert(immutableSamplers.Length == 0 || type == VkDescriptorType.CombinedImageSampler ||
                         type == VkDescriptorType.Sampler, "Can't use immutable samplers on non-sampler type");
            var samplersRewrite = immutableSamplers.Select(x =>
            {
                x.AssertValid();
                return(x.Handle);
            }).ToArray();

            if (samplersRewrite.Length > 0)
            {
                _pins.Add(GCHandle.Alloc(samplersRewrite, GCHandleType.Pinned));
            }
            unsafe
            {
                _bindings.Add(binding, new VkDescriptorSetLayoutBinding()
                {
                    Binding            = binding,
                    DescriptorType     = type,
                    DescriptorCount    = arraySize,
                    StageFlags         = flags,
                    PImmutableSamplers =
                        (VkSampler *)(samplersRewrite.Length > 0
                            ? Marshal.UnsafeAddrOfPinnedArrayElement(samplersRewrite, 0)
                            : IntPtr.Zero).ToPointer()
                });
            }
            return(this);
        }
Пример #3
0
 public DescriptorSetLayoutBinding(uint binding, VkDescriptorType type, VkShaderStageFlags stageFlags, uint descriptorCount = 1)
 {
     descriptorType       = type;
     this.binding         = binding;
     this.descriptorCount = descriptorCount;
     this.stageFlags      = stageFlags;
     pImmutableSamplers   = null;
 }
Пример #4
0
 public VkDescriptorSetLayoutBinding(uint _binding, VkShaderStageFlags _stageFlags, VkDescriptorType _descriptorType, uint _descriptorCount = 1)
 {
     binding            = _binding;
     descriptorType     = _descriptorType;
     descriptorCount    = _descriptorCount;
     stageFlags         = _stageFlags;
     pImmutableSamplers = (IntPtr)0;
 }
        public VkResourceSet(VkGraphicsDevice gd, ref ResourceSetDescription description)
            : base(ref description)
        {
            _gd = gd;
            VkResourceLayout vkLayout = Util.AssertSubtype <ResourceLayout, VkResourceLayout>(description.Layout);

            VkDescriptorSetLayout dsl = vkLayout.DescriptorSetLayout;

            _descriptorCounts          = vkLayout.DescriptorResourceCounts;
            _descriptorAllocationToken = _gd.DescriptorPoolManager.Allocate(_descriptorCounts, dsl);

            BindableResource[] boundResources        = description.BoundResources;
            uint descriptorWriteCount                = (uint)boundResources.Length;
            VkWriteDescriptorSet *  descriptorWrites = stackalloc VkWriteDescriptorSet[(int)descriptorWriteCount];
            VkDescriptorBufferInfo *bufferInfos      = stackalloc VkDescriptorBufferInfo[(int)descriptorWriteCount];
            VkDescriptorImageInfo * imageInfos       = stackalloc VkDescriptorImageInfo[(int)descriptorWriteCount];

            for (int i = 0; i < descriptorWriteCount; i++)
            {
                VkDescriptorType type = vkLayout.DescriptorTypes[i];

                descriptorWrites[i].sType           = VkStructureType.WriteDescriptorSet;
                descriptorWrites[i].descriptorCount = 1;
                descriptorWrites[i].descriptorType  = type;
                descriptorWrites[i].dstBinding      = (uint)i;
                descriptorWrites[i].dstSet          = _descriptorAllocationToken.Set;

                if (type == VkDescriptorType.UniformBuffer || type == VkDescriptorType.StorageBuffer)
                {
                    VkBuffer vkBuffer = Util.AssertSubtype <BindableResource, VkBuffer>(boundResources[i]);
                    bufferInfos[i].buffer           = vkBuffer.DeviceBuffer;
                    bufferInfos[i].range            = vkBuffer.SizeInBytes;
                    descriptorWrites[i].pBufferInfo = &bufferInfos[i];
                }
                else if (type == VkDescriptorType.SampledImage)
                {
                    VkTextureView textureView = Util.AssertSubtype <BindableResource, VkTextureView>(boundResources[i]);
                    imageInfos[i].imageView        = textureView.ImageView;
                    imageInfos[i].imageLayout      = VkImageLayout.ShaderReadOnlyOptimal;
                    descriptorWrites[i].pImageInfo = &imageInfos[i];
                }
                else if (type == VkDescriptorType.StorageImage)
                {
                    VkTextureView textureView = Util.AssertSubtype <BindableResource, VkTextureView>(boundResources[i]);
                    imageInfos[i].imageView        = textureView.ImageView;
                    imageInfos[i].imageLayout      = VkImageLayout.General;
                    descriptorWrites[i].pImageInfo = &imageInfos[i];
                }
                else if (type == VkDescriptorType.Sampler)
                {
                    VkSampler sampler = Util.AssertSubtype <BindableResource, VkSampler>(boundResources[i]);
                    imageInfos[i].sampler          = sampler.DeviceSampler;
                    descriptorWrites[i].pImageInfo = &imageInfos[i];
                }
            }

            vkUpdateDescriptorSets(_gd.Device, descriptorWriteCount, descriptorWrites, 0, null);
        }
Пример #6
0
        public VkResourceSet(VkGraphicsDevice gd, ref ResourceSetDescription description)
        {
            _gd = gd;
            VkResourceLayout vkLayout = Util.AssertSubtype <ResourceLayout, VkResourceLayout>(description.Layout);

            VkDescriptorSetAllocateInfo dsAI = VkDescriptorSetAllocateInfo.New();

            dsAI.descriptorSetCount = 1;
            VkDescriptorSetLayout dsl = vkLayout.DescriptorSetLayout;

            dsAI.pSetLayouts    = &dsl;
            dsAI.descriptorPool = _gd.SharedDescriptorPool;
            VkResult result = vkAllocateDescriptorSets(_gd.Device, ref dsAI, out _descriptorSet);

            CheckResult(result);

            BindableResource[] boundResources        = description.BoundResources;
            uint descriptorWriteCount                = (uint)boundResources.Length;
            VkWriteDescriptorSet *  descriptorWrites = stackalloc VkWriteDescriptorSet[(int)descriptorWriteCount];
            VkDescriptorBufferInfo *bufferInfos      = stackalloc VkDescriptorBufferInfo[(int)descriptorWriteCount];
            VkDescriptorImageInfo * imageInfos       = stackalloc VkDescriptorImageInfo[(int)descriptorWriteCount];

            for (int i = 0; i < descriptorWriteCount; i++)
            {
                VkDescriptorType type = vkLayout.DescriptorTypes[i];

                descriptorWrites[i].sType           = VkStructureType.WriteDescriptorSet;
                descriptorWrites[i].descriptorCount = 1;
                descriptorWrites[i].descriptorType  = type;
                descriptorWrites[i].dstBinding      = (uint)i;
                descriptorWrites[i].dstSet          = _descriptorSet;

                if (type == VkDescriptorType.UniformBuffer)
                {
                    VkUniformBuffer uniformBuffer = Util.AssertSubtype <BindableResource, VkUniformBuffer>(boundResources[i]);
                    bufferInfos[i].buffer           = uniformBuffer.DeviceBuffer;
                    bufferInfos[i].range            = uniformBuffer.SizeInBytes;
                    descriptorWrites[i].pBufferInfo = &bufferInfos[i];
                }
                else if (type == VkDescriptorType.SampledImage)
                {
                    VkTextureView textureView = Util.AssertSubtype <BindableResource, VkTextureView>(boundResources[i]);
                    imageInfos[i].imageView        = textureView.ImageView;
                    imageInfos[i].imageLayout      = VkImageLayout.ShaderReadOnlyOptimal;
                    descriptorWrites[i].pImageInfo = &imageInfos[i];
                }
                else if (type == VkDescriptorType.Sampler)
                {
                    VkSampler sampler = Util.AssertSubtype <BindableResource, VkSampler>(boundResources[i]);
                    imageInfos[i].sampler          = sampler.DeviceSampler;
                    descriptorWrites[i].pImageInfo = &imageInfos[i];
                }
            }

            vkUpdateDescriptorSets(_gd.Device, descriptorWriteCount, descriptorWrites, 0, null);
        }
Пример #7
0
        public static VkDescriptorPoolSize descriptorPoolSize(
            VkDescriptorType type,
            uint descriptorCount)
        {
            VkDescriptorPoolSize descriptorPoolSize = new VkDescriptorPoolSize();

            descriptorPoolSize.type            = type;
            descriptorPoolSize.descriptorCount = descriptorCount;
            return(descriptorPoolSize);
        }
 public DescriptorBindingInfo(
     uint index,
     VkDescriptorType descriptorType,
     uint descriptorCounts,
     VkShaderStageFlags shaderStageFlags
     )
 {
     Index            = index;
     DescriptorType   = descriptorType;
     DescriptorCounts = descriptorCounts;
     ShaderStageFlags = shaderStageFlags;
 }
Пример #9
0
 public VkImageViewHandleInfoNVX(
     VulkanHandle <VkImageView> imageView = default,
     VkDescriptorType descriptorType      = default,
     VulkanHandle <VkSampler> sampler     = default
     )
 {
     sType          = TYPE;
     pNext          = null;
     ImageView      = imageView;
     DescriptorType = descriptorType;
     Sampler        = sampler;
 }
Пример #10
0
 public unsafe VkWriteDescriptorSet(uint binding, VkDescriptorSet dstSet, VkDescriptorType type,
                                    ref VkDescriptorBufferInfo bufferInfo, uint descriptorCount = 1)
 {
     this.sType            = VkStructureType.WriteDescriptorSet;
     this.pNext            = null;
     this.dstSet           = dstSet;
     this.descriptorType   = type;
     this.dstBinding       = binding;
     this.pBufferInfo      = (VkDescriptorBufferInfo *)Unsafe.AsPointer(ref bufferInfo);
     this.descriptorCount  = descriptorCount;
     this.pImageInfo       = null;
     this.pTexelBufferView = null;
     this.dstArrayElement  = 0;
 }
Пример #11
0
        public static VkDescriptorSetLayoutBinding descriptorSetLayoutBinding(
            VkDescriptorType type,
            VkShaderStageFlags stageFlags,
            uint binding,
            uint descriptorCount = 1)
        {
            VkDescriptorSetLayoutBinding setLayoutBinding = new VkDescriptorSetLayoutBinding();

            setLayoutBinding.descriptorType  = type;
            setLayoutBinding.stageFlags      = stageFlags;
            setLayoutBinding.binding         = binding;
            setLayoutBinding.descriptorCount = descriptorCount;
            return(setLayoutBinding);
        }
Пример #12
0
 public unsafe VkWriteDescriptorSet(uint binding,
                                    VkDescriptorSet dstSet,
                                    VkDescriptorType type, VkWriteDescriptorSetInlineUniformBlockEXT *inlineUniformBlockEXT)
 {
     this.sType            = VkStructureType.WriteDescriptorSet;
     this.pNext            = inlineUniformBlockEXT;
     this.dstSet           = dstSet;
     this.descriptorType   = type;
     this.dstBinding       = binding;
     this.descriptorCount  = inlineUniformBlockEXT->dataSize;
     this.pBufferInfo      = null;
     this.pTexelBufferView = null;
     this.pImageInfo       = null;
     this.dstArrayElement  = 0;
 }
Пример #13
0
        public static VkWriteDescriptorSet writeDescriptorSet(
            VkDescriptorSet dstSet,
            VkDescriptorType type,
            uint binding,
            VkDescriptorImageInfo *imageInfo,
            uint descriptorCount = 1)
        {
            VkWriteDescriptorSet writeDescriptorSet = VkWriteDescriptorSet.New();

            writeDescriptorSet.dstSet          = dstSet;
            writeDescriptorSet.descriptorType  = type;
            writeDescriptorSet.dstBinding      = binding;
            writeDescriptorSet.pImageInfo      = imageInfo;
            writeDescriptorSet.descriptorCount = descriptorCount;
            return(writeDescriptorSet);
        }
Пример #14
0
 public VkDescriptorSetLayoutBinding(uint _binding, VkShaderStageFlags _stageFlags, VkDescriptorType _descriptorType, uint _descriptorCount = 1)
 {
     binding = _binding;
     this._descriptorType = (int)_descriptorType;
     descriptorCount      = _descriptorCount;
     this._stageFlags     = (uint)_stageFlags;
     _pImmutableSamplers  = IntPtr.Zero;
 }
Пример #15
0
 public VkDescriptorPoolSize(VkDescriptorType descriptorType, uint count = 1)
 {
     this._type      = (int)descriptorType;
     descriptorCount = count;
 }
Пример #16
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);
        }
Пример #17
0
 internal DescriptorData(VkDescriptorSetLayoutBinding b)
 {
     Type   = b.DescriptorType;
     Count  = b.DescriptorCount;
     Stages = b.StageFlags;
 }
Пример #18
0
        /// <summary>
        /// Create a new material data based off of the pass material also adds the new data to the cache
        /// </summary>
        /// <param name="material"></param>
        /// <returns></returns>

        public static MaterialInfo CreateMaterialData(Material material, ShaderMapping mapping = null)
        {
            // fetch the shadermapping for this materials shader
            if (mapping == null && material != null)
            {
                mapping = ShaderMappingIO.ReadFromJsonFile(material.shader);
                if (mapping == null) // if we fail to find a mapping try and load the default
                {
                    mapping = ShaderMappingIO.ReadFromJsonFile(ShaderMappingIO.GetPathForShaderMappingFile("Default"));
                }
            }

            MaterialInfo matdata = new MaterialInfo
            {
                id = material != null?material.GetInstanceID() : 0,
                         mapping = mapping
            };

            // process uniforms
            UniformMappedData[] uniformDatas = mapping.GetUniformDatasFromMaterial(material);

            foreach (UniformMappedData uniData in uniformDatas)
            {
                VkDescriptorType descriptorType  = VkDescriptorType.VK_DESCRIPTOR_TYPE_MAX_ENUM;
                uint             descriptorCount = 1;

                if (uniData.mapping.uniformType == UniformMapping.UniformType.Texture2DUniform)
                {
                    Texture tex = uniData.data as Texture;
                    if (tex == null)
                    {
                        continue;
                    }

                    // get imagedata for the texture
                    ImageData imageData = TextureConverter.GetOrCreateImageData(tex);
                    // get descriptor for the image data
                    DescriptorImageData descriptorImage = GetOrCreateDescriptorImageData(imageData, uniData.mapping.vsgBindingIndex);
                    matdata.imageDescriptors.Add(descriptorImage);

                    descriptorType = VkDescriptorType.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
                }
                else if (uniData.mapping.uniformType == UniformMapping.UniformType.Texture2DArrayUniform)
                {
                    Texture2DArray tex = uniData.data as Texture2DArray;
                    if (tex == null)
                    {
                        continue;
                    }
                    ImageData[]         imageDatas      = TextureConverter.GetOrCreateImageData(tex);
                    DescriptorImageData descriptorImage = GetOrCreateDescriptorImageData(imageDatas, uniData.mapping.vsgBindingIndex);
                    matdata.imageDescriptors.Add(descriptorImage);

                    descriptorType  = VkDescriptorType.VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER;
                    descriptorCount = (uint)imageDatas.Length;
                }
                else if (uniData.mapping.uniformType == UniformMapping.UniformType.FloatUniform)
                {
                    float value = (float)uniData.data;
                    if (value == float.NaN)
                    {
                        continue;
                    }

                    // get descriptor for the image data
                    DescriptorFloatUniformData descriptorFloat = new DescriptorFloatUniformData
                    {
                        id      = material.GetInstanceID(),
                        binding = uniData.mapping.vsgBindingIndex,
                        value   = value
                    };
                    matdata.floatDescriptors.Add(descriptorFloat);

                    descriptorType = VkDescriptorType.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
                }
                else if (uniData.mapping.uniformType == UniformMapping.UniformType.Vec4Uniform || uniData.mapping.uniformType == UniformMapping.UniformType.ColorUniform)
                {
                    Vector4 vector = Vector4.zero;
                    if (uniData.mapping.uniformType == UniformMapping.UniformType.Vec4Uniform)
                    {
                        vector = (Vector4)uniData.data;
                    }
                    if (uniData.mapping.uniformType == UniformMapping.UniformType.ColorUniform)
                    {
                        Color color = (Color)uniData.data;
                        vector = new Vector4(color.r, color.g, color.b, color.a);
                    }
                    if (vector == null)
                    {
                        continue;
                    }

                    // get descriptor for the image data
                    DescriptorVectorUniformData descriptorVector = new DescriptorVectorUniformData
                    {
                        id      = material.GetInstanceID(),
                        binding = uniData.mapping.vsgBindingIndex,
                        value   = NativeUtils.ToNative(vector)
                    };

                    matdata.vectorDescriptors.Add(descriptorVector);

                    descriptorType = VkDescriptorType.VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER;
                }

                if (descriptorType == VkDescriptorType.VK_DESCRIPTOR_TYPE_MAX_ENUM)
                {
                    continue;
                }

                // add any custom defines related to the texture
                if (uniData.mapping.vsgDefines != null && uniData.mapping.vsgDefines.Count > 0)
                {
                    matdata.customDefines.AddRange(uniData.mapping.vsgDefines);
                }

                // create the descriptor binding to match the descriptor image
                VkDescriptorSetLayoutBinding descriptorBinding = new VkDescriptorSetLayoutBinding
                {
                    binding            = (uint)uniData.mapping.vsgBindingIndex,
                    descriptorType     = descriptorType,
                    descriptorCount    = descriptorCount,
                    stageFlags         = uniData.mapping.stages,
                    pImmutableSamplers = System.IntPtr.Zero
                };
                matdata.descriptorBindings.Add(descriptorBinding);
            }

            if (material != null)
            {
                string rendertype = material.GetTag("RenderType", true, "Opaque");
                matdata.useAlpha = rendertype.Contains("Transparent") ? 1 : 0;
                if (matdata.useAlpha == 1)
                {
                    matdata.customDefines.Add("VSG_BLEND");
                }

                string lightmode = material.GetTag("LightMode", true, "ForwardBase");
                if (lightmode != "Always")
                {
                    matdata.customDefines.Add("VSG_LIGHTING");
                }
            }

            // lastly process shaders now we know the defines etc it will use
            string customDefinesStr = string.Join(",", matdata.customDefines.ToArray());

            matdata.shaderStages = GetOrCreateShaderStagesInfo(mapping.shaders.ToArray(), customDefinesStr, null);

            // add to the cache (double check it doesn't exist already)
            if (material != null && !_materialDataCache.ContainsKey(matdata.id))
            {
                _materialDataCache[matdata.id] = matdata;
            }

            return(matdata);
        }
Пример #19
0
        public VkResourceSet(VkGraphicsDevice gd, ref ResourceSetDescription description)
            : base(ref description)
        {
            _gd      = gd;
            RefCount = new ResourceRefCount(DisposeCore);
            VkResourceLayout vkLayout = Util.AssertSubtype <ResourceLayout, VkResourceLayout>(description.Layout);

            VkDescriptorSetLayout dsl = vkLayout.DescriptorSetLayout;

            _descriptorCounts          = vkLayout.DescriptorResourceCounts;
            _descriptorAllocationToken = _gd.DescriptorPoolManager.Allocate(_descriptorCounts, dsl);

            BindableResource[] boundResources        = description.BoundResources;
            uint descriptorWriteCount                = (uint)boundResources.Length;
            VkWriteDescriptorSet *  descriptorWrites = stackalloc VkWriteDescriptorSet[(int)descriptorWriteCount];
            VkDescriptorBufferInfo *bufferInfos      = stackalloc VkDescriptorBufferInfo[(int)descriptorWriteCount];
            VkDescriptorImageInfo * imageInfos       = stackalloc VkDescriptorImageInfo[(int)descriptorWriteCount];

            for (int i = 0; i < descriptorWriteCount; i++)
            {
                VkDescriptorType type = vkLayout.DescriptorTypes[i];

                descriptorWrites[i].sType           = VkStructureType.WriteDescriptorSet;
                descriptorWrites[i].descriptorCount = 1;
                descriptorWrites[i].descriptorType  = type;
                descriptorWrites[i].dstBinding      = (uint)i;
                descriptorWrites[i].dstSet          = _descriptorAllocationToken.Set;

                if (type == VkDescriptorType.UniformBuffer || type == VkDescriptorType.UniformBufferDynamic ||
                    type == VkDescriptorType.StorageBuffer || type == VkDescriptorType.StorageBufferDynamic)
                {
                    DeviceBufferRange range          = Util.GetBufferRange(boundResources[i], 0);
                    VkBuffer          rangedVkBuffer = Util.AssertSubtype <DeviceBuffer, VkBuffer>(range.Buffer);
                    bufferInfos[i].buffer           = rangedVkBuffer.DeviceBuffer;
                    bufferInfos[i].offset           = range.Offset;
                    bufferInfos[i].range            = range.SizeInBytes;
                    descriptorWrites[i].pBufferInfo = &bufferInfos[i];
                    _refCounts.Add(rangedVkBuffer.RefCount);
                }
                else if (type == VkDescriptorType.SampledImage)
                {
                    TextureView   texView   = Util.GetTextureView(_gd, boundResources[i]);
                    VkTextureView vkTexView = Util.AssertSubtype <TextureView, VkTextureView>(texView);
                    imageInfos[i].imageView        = vkTexView.ImageView;
                    imageInfos[i].imageLayout      = VkImageLayout.ShaderReadOnlyOptimal;
                    descriptorWrites[i].pImageInfo = &imageInfos[i];
                    _sampledTextures.Add(Util.AssertSubtype <Texture, VkTexture>(texView.Target));
                    _refCounts.Add(vkTexView.RefCount);
                }
                else if (type == VkDescriptorType.StorageImage)
                {
                    TextureView   texView   = Util.GetTextureView(_gd, boundResources[i]);
                    VkTextureView vkTexView = Util.AssertSubtype <TextureView, VkTextureView>(texView);
                    imageInfos[i].imageView        = vkTexView.ImageView;
                    imageInfos[i].imageLayout      = VkImageLayout.General;
                    descriptorWrites[i].pImageInfo = &imageInfos[i];
                    _storageImages.Add(Util.AssertSubtype <Texture, VkTexture>(texView.Target));
                    _refCounts.Add(vkTexView.RefCount);
                }
                else if (type == VkDescriptorType.Sampler)
                {
                    VkSampler sampler = Util.AssertSubtype <BindableResource, VkSampler>(boundResources[i]);
                    imageInfos[i].sampler          = sampler.DeviceSampler;
                    descriptorWrites[i].pImageInfo = &imageInfos[i];
                    _refCounts.Add(sampler.RefCount);
                }
            }

            vkUpdateDescriptorSets(_gd.Device, descriptorWriteCount, descriptorWrites, 0, null);
        }
Пример #20
0
 public VkDescriptorPoolSize(VkDescriptorType descriptorType, uint count = 1)
 {
     type            = descriptorType;
     descriptorCount = count;
 }
 /// <summary>
 /// Adds the given single element binding descriptor
 /// </summary>
 /// <param name="binding">Binding to add</param>
 /// <param name="type">Binding type</param>
 /// <param name="flags">Shader stages</param>
 /// <param name="immutableSampler">Immutable sampler for the binding</param>
 /// <returns>this</returns>
 public DescriptorSetLayoutBuilder Add(uint binding, VkDescriptorType type, VkShaderStageFlag flags,
                                       Sampler immutableSampler = null)
 {
     return(Add(binding, type, 1, flags, immutableSampler != null ? new[] { immutableSampler } : new Sampler[0]));
 }
 /// <summary>
 /// VkDescriptorPoolSize - Structure specifying descriptor pool size
 /// </summary>
 /// <param name="type">type is the type of descriptor</param>
 /// <param name="descriptorCount">descriptorCount is the number of descriptors of that type to
 /// allocate.
 /// If type is VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT then
 /// descriptorCount is the number of bytes to allocate for descriptors
 /// of this type</param>
 public VkDescriptorPoolSize(VkDescriptorType type, UInt32 descriptorCount)
 {
     this.type            = type;
     this.descriptorCount = descriptorCount;
 }
 /// <summary>
 /// VkDescriptorSetLayoutBinding - Structure specifying a descriptor set layout binding
 /// </summary>
 /// <param name="binding">binding is the binding number of this entry and corresponds to a
 /// resource of the same binding number in the shader stages</param>
 /// <param name="descriptorType">descriptorType is a VkDescriptorType specifying which type
 /// of resource descriptors are used for this binding</param>
 /// <param name="descriptorCount">descriptorCount is the number of descriptors contained in the
 /// binding, accessed in a shader as an array
 /// , except if descriptorType is
 /// VK_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK_EXT in which case
 /// descriptorCount is the size in bytes of the inline uniform block
 /// .
 /// If descriptorCount is zero this binding entry is reserved and the
 /// resource must not be accessed from any stage via this binding within
 /// any pipeline using the set layout</param>
 /// <param name="stageFlags">stageFlags member is a bitmask of VkShaderStageFlagBits
 /// specifying which pipeline shader stages can access a resource for this
 /// binding.
 /// VK_SHADER_STAGE_ALL is a shorthand specifying that all defined
 /// shader stages, including any additional stages defined by extensions,
 /// can access the resource</param>
 public VkDescriptorSetLayoutBinding(UInt32 binding, VkDescriptorType descriptorType, UInt32 descriptorCount, VkShaderStageFlagBits stageFlags)
 {
     this.binding            = binding; this.descriptorType = descriptorType;
     this.descriptorCount    = descriptorCount; this.stageFlags = stageFlags;
     this.pImmutableSamplers = null;
 }