Ejemplo n.º 1
0
        internal unsafe SharpVulkan.DescriptorSet AllocateDescriptorSet(DescriptorSetLayout descriptorSetLayout)
        {
            // Keep track of descriptor pool usage
            bool isPoolExhausted = ++allocatedSetCount > GraphicsDevice.MaxDescriptorSetCount;

            for (int i = 0; i < DescriptorSetLayout.DescriptorTypeCount; i++)
            {
                allocatedTypeCounts[i] += descriptorSetLayout.TypeCounts[i];
                if (allocatedTypeCounts[i] > GraphicsDevice.MaxDescriptorTypeCounts[i])
                {
                    isPoolExhausted = true;
                    break;
                }
            }

            if (isPoolExhausted)
            {
                return(SharpVulkan.DescriptorSet.Null);
            }

            // Allocate new descriptor set
            var nativeLayoutCopy = descriptorSetLayout.NativeLayout;
            var allocateInfo     = new DescriptorSetAllocateInfo
            {
                StructureType      = StructureType.DescriptorSetAllocateInfo,
                DescriptorPool     = NativeDescriptorPool,
                DescriptorSetCount = 1,
                SetLayouts         = new IntPtr(&nativeLayoutCopy)
            };

            SharpVulkan.DescriptorSet descriptorSet;
            GraphicsDevice.NativeDevice.AllocateDescriptorSets(ref allocateInfo, &descriptorSet);
            return(descriptorSet);
        }
Ejemplo n.º 2
0
        private DescriptorSet(GraphicsDevice graphicsDevice, DescriptorPool pool, DescriptorSetLayout desc)
        {
            if (pool.SrvOffset + desc.SrvCount > pool.SrvCount || pool.SamplerOffset + desc.SamplerCount > pool.SamplerCount)
            {
                // Eearly exit if OOM, IsValid should return false (TODO: different mechanism?)
                Device         = null;
                BindingOffsets = null;
                Description    = null;
                SrvStart       = new CpuDescriptorHandle();
                SamplerStart   = new CpuDescriptorHandle();
                return;
            }

            Device         = graphicsDevice;
            BindingOffsets = desc.BindingOffsets;
            Description    = desc;

            // Store start CpuDescriptorHandle
            SrvStart     = desc.SrvCount > 0 ? (pool.SrvStart + graphicsDevice.SrvHandleIncrementSize * pool.SrvOffset) : new CpuDescriptorHandle();
            SamplerStart = desc.SamplerCount > 0 ? (pool.SamplerStart + graphicsDevice.SamplerHandleIncrementSize * pool.SamplerOffset) : new CpuDescriptorHandle();

            // Allocation is done, bump offsets
            // TODO D3D12 thread safety?
            pool.SrvOffset     += desc.SrvCount;
            pool.SamplerOffset += desc.SamplerCount;
        }
Ejemplo n.º 3
0
 private DescriptorSet(GraphicsDevice graphicsDevice, DescriptorPool pool, DescriptorSetLayout desc)
 {
     this.HeapObjects           = pool.Entries;
     this.DescriptorStartOffset = pool.Allocate(desc.ElementCount);
 }
Ejemplo n.º 4
0
 public static DescriptorSet New(GraphicsDevice graphicsDevice, DescriptorPool pool, DescriptorSetLayout desc)
 {
     return(new DescriptorSet(graphicsDevice, pool, desc));
 }
Ejemplo n.º 5
0
 private DescriptorSet(GraphicsDevice graphicsDevice, DescriptorPool pool, DescriptorSetLayout desc)
 {
     GraphicsDevice      = graphicsDevice;
     NativeDescriptorSet = pool.AllocateDescriptorSet(desc);
 }