Ejemplo n.º 1
0
        private void Recreate()
        {
            NativeDescriptorPool = GraphicsDevice.descriptorPools.GetObject();

            allocatedTypeCounts = new uint[DescriptorSetLayout.DescriptorTypeCount];
            allocatedSetCount   = 0;
        }
Ejemplo n.º 2
0
        public DescriptorSet(DescriptorSetLayout resLayout)
        {
            resLayout.Build();

            descriptorPool = Graphics.DescriptorPoolManager.GetPool(ref resLayout.descriptorResourceCounts, Swapchain.IMAGE_COUNT);
            resourceLayout = resLayout;

            unsafe
            {
                var setLayouts = stackalloc VkDescriptorSetLayout[3] {
                    resLayout.Handle, resLayout.Handle, resLayout.Handle
                };

                var descriptorSetAllocateInfo = new VkDescriptorSetAllocateInfo
                {
                    sType              = VkStructureType.DescriptorSetAllocateInfo,
                    descriptorPool     = descriptorPool,
                    pSetLayouts        = setLayouts,
                    descriptorSetCount = Swapchain.IMAGE_COUNT
                };

                Device.AllocateDescriptorSets(ref descriptorSetAllocateInfo, (VkDescriptorSet *)descriptorSet.Data);
            }

            bindedRes = new IBindableResource[resLayout.NumBindings];

            for (int i = 0; i < Swapchain.IMAGE_COUNT; i++)
            {
                writeDescriptorSets[i] = new VkWriteDescriptorSet[resLayout.NumBindings];
            }
        }
Ejemplo n.º 3
0
 public static VkResult vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, ReadOnlySpan <VkDescriptorSet> descriptorSets)
 {
     fixed(VkDescriptorSet *descriptorSetsPtr = descriptorSets)
     {
         return(vkFreeDescriptorSets(device, descriptorPool, (uint)descriptorSets.Length, descriptorSetsPtr));
     }
 }
Ejemplo n.º 4
0
        public DescriptorPool(Device device) : base(device)
        {
            HeapPool = new(device);
            HeapPool.Create();

            pool = HeapPool.handle;
        }
Ejemplo n.º 5
0
        private static VkDescriptorPool CreateDescriptorPool(VkDevice device, uint swapchainImageCount, uint textureCount)
        {
            VkDescriptorPoolSize[] sizes = new VkDescriptorPoolSize[2];
            sizes[0] = new VkDescriptorPoolSize();
            sizes[0].descriptorCount = swapchainImageCount * textureCount;
            sizes[0].type            = VkDescriptorType.CombinedImageSampler;

            sizes[1] = new VkDescriptorPoolSize();
            sizes[1].descriptorCount = swapchainImageCount * 1;
            sizes[1].type            = VkDescriptorType.UniformBuffer;

            VkDescriptorPoolCreateInfo createInfo = VkDescriptorPoolCreateInfo.New();

            createInfo.poolSizeCount = 2;

            fixed(VkDescriptorPoolSize *ptr = sizes)
            createInfo.pPoolSizes = ptr;

            createInfo.maxSets = swapchainImageCount;

            VkDescriptorPool pool = VkDescriptorPool.Null;

            Assert(vkCreateDescriptorPool(device, &createInfo, null, &pool));
            return(pool);
        }
Ejemplo n.º 6
0
 public PoolInfo(VkDescriptorPool pool, uint totalSets, uint descriptorCount)
 {
     Pool          = pool;
     RemainingSets = totalSets;
     for (int i = 0; i < MAX_DESCRIPTOR_COUNT; i++)
     {
         RemainingCount[i] = descriptorCount;
     }
 }
 public PoolInfo(VkDescriptorPool pool, uint totalSets, DescriptorResourceCounts counts)
 {
     Pool               = pool;
     RemainingSets      = totalSets;
     UniformBufferCount = counts.UniformBufferCount;
     SampledImageCount  = counts.SampledImageCount;
     SamplerCount       = counts.SamplerCount;
     StorageBufferCount = counts.StorageBufferCount;
     StorageImageCount  = counts.StorageImageCount;
 }
Ejemplo n.º 8
0
 public PoolInfo(VkDescriptorPool pool, uint totalSets, uint descriptorCount)
 {
     Pool               = pool;
     RemainingSets      = totalSets;
     UniformBufferCount = descriptorCount;
     SampledImageCount  = descriptorCount;
     SamplerCount       = descriptorCount;
     StorageBufferCount = descriptorCount;
     StorageImageCount  = descriptorCount;
 }
Ejemplo n.º 9
0
        public void Reset()
        {
            GraphicsDevice.descriptorPools.RecycleObject(GraphicsDevice.NextFenceValue, NativeDescriptorPool);
            NativeDescriptorPool = GraphicsDevice.descriptorPools.GetObject();

            allocatedSetCount = 0;
            for (int i = 0; i < DescriptorSetLayout.DescriptorTypeCount; i++)
            {
                allocatedTypeCounts[i] = 0;
            }
        }
Ejemplo n.º 10
0
        public static VkDescriptorSetAllocateInfo descriptorSetAllocateInfo(
            VkDescriptorPool descriptorPool,
            VkDescriptorSetLayout *pSetLayouts,
            uint descriptorSetCount)
        {
            VkDescriptorSetAllocateInfo descriptorSetAllocateInfo = VkDescriptorSetAllocateInfo.New();

            descriptorSetAllocateInfo.descriptorPool     = descriptorPool;
            descriptorSetAllocateInfo.pSetLayouts        = pSetLayouts;
            descriptorSetAllocateInfo.descriptorSetCount = descriptorSetCount;
            return(descriptorSetAllocateInfo);
        }
Ejemplo n.º 11
0
 public void Free(VkDescriptorPool pool, ref DescriptorResourceCounts counts, uint count = 1)
 {
     lock (_lock)
     {
         foreach (PoolInfo poolInfo in _pools)
         {
             if (poolInfo.Pool == pool)
             {
                 poolInfo.Free(ref counts, count);
             }
         }
     }
 }
Ejemplo n.º 12
0
        public unsafe DescriptorAllocationToken Allocate(DescriptorResourceCounts counts, VkDescriptorSetLayout setLayout)
        {
            VkDescriptorPool            pool = GetPool(counts);
            VkDescriptorSetAllocateInfo dsAI = VkDescriptorSetAllocateInfo.New();

            dsAI.descriptorSetCount = 1;
            dsAI.pSetLayouts        = &setLayout;
            dsAI.descriptorPool     = pool;
            VkResult result = vkAllocateDescriptorSets(_gd.Device, ref dsAI, out VkDescriptorSet set);

            VulkanUtil.CheckResult(result);

            return(new DescriptorAllocationToken(set, pool));
        }
Ejemplo n.º 13
0
        void CreateDescriptorPool()
        {
            var poolSize = new VkDescriptorPoolSize();

            poolSize.type            = VkDescriptorType.UniformBuffer;
            poolSize.descriptorCount = 1;

            var info = new VkDescriptorPoolCreateInfo();

            info.poolSizes = new List <VkDescriptorPoolSize> {
                poolSize
            };
            info.maxSets = 1;

            descriptorPool = new VkDescriptorPool(device, info);
        }
Ejemplo n.º 14
0
        public DescriptorSet(DescriptorSetLayout resLayout, params IBindableResource[] bindables)
        {
            resLayout.Build();

            descriptorPool = Graphics.DescriptorPoolManager.GetPool(ref resLayout.descriptorResourceCounts, Swapchain.IMAGE_COUNT);
            resourceLayout = resLayout;

            unsafe
            {
                var setLayouts = stackalloc VkDescriptorSetLayout[3] {
                    resLayout.Handle, resLayout.Handle, resLayout.Handle
                };
                var descriptorSetAllocateInfo = new VkDescriptorSetAllocateInfo
                {
                    sType              = VkStructureType.DescriptorSetAllocateInfo,
                    descriptorPool     = descriptorPool,
                    pSetLayouts        = setLayouts,
                    descriptorSetCount = Swapchain.IMAGE_COUNT
                };

                Device.AllocateDescriptorSets(ref descriptorSetAllocateInfo, (VkDescriptorSet *)descriptorSet.Data);
            }

            bindedRes = new IBindableResource[resLayout.NumBindings];

            System.Diagnostics.Debug.Assert(bindables.Length == resLayout.NumBindings);

            for (int i = 0; i < Swapchain.IMAGE_COUNT; i++)
            {
                writeDescriptorSets[i] = new VkWriteDescriptorSet[resLayout.NumBindings];
            }

            for (uint i = 0; i < resLayout.NumBindings; i++)
            {
                BindResource(i, bindables[i]);
            }

            UpdateSets();
        }
Ejemplo n.º 15
0
        protected override void InitializePermanent()
        {
            var cube = GeometricPrimitive.Box(1.0f, 1.0f, 1.0f);

            _cubeTexture  = Content.LoadVulkanImage("IndustryForgedDark512.ktx");
            _cubeVertices = ToDispose(VulkanBuffer.Vertex(Context, cube.Vertices));
            _cubeIndices  = ToDispose(VulkanBuffer.Index(Context, cube.Indices));
            var sampler = CreateSampler();

            _sampler = sampler;
            ToDispose(new ActionDisposable(() =>
            {
                vkDestroySampler(Context.Device, sampler, null);
            }));
            _uniformBuffer = ToDispose(VulkanBuffer.DynamicUniform <WorldViewProjection>(Context, 1));
            var descriptorSetLayout = CreateDescriptorSetLayout();

            _descriptorSetLayout = descriptorSetLayout;
            ToDispose(new ActionDisposable(() =>
            {
                vkDestroyDescriptorSetLayout(Context.Device, descriptorSetLayout, null);
            }));
            var pipelineLayout = CreatePipelineLayout();

            _pipelineLayout = pipelineLayout;
            ToDispose(new ActionDisposable(() =>
            {
                vkDestroyPipelineLayout(Context.Device, pipelineLayout, null);
            }));
            var descriptorPool = CreateDescriptorPool();

            _descriptorPool = descriptorPool;
            ToDispose(new ActionDisposable(() =>
            {
                vkDestroyDescriptorPool(Context.Device, descriptorPool, null);
            }));
            _descriptorSet = CreateDescriptorSet(_descriptorPool); // Will be freed when pool is destroyed.
        }
Ejemplo n.º 16
0
        void CreateDescriptorPool()
        {
            var size1 = new VkDescriptorPoolSize();

            size1.type            = VkDescriptorType.UniformBuffer;
            size1.descriptorCount = 1;

            var size2 = new VkDescriptorPoolSize();

            size2.type            = VkDescriptorType.CombinedImageSampler;
            size2.descriptorCount = 1;

            var poolSizes = new List <VkDescriptorPoolSize> {
                size1, size2
            };

            var info = new VkDescriptorPoolCreateInfo();

            info.poolSizes = poolSizes;
            info.maxSets   = 1;

            descriptorPool = new VkDescriptorPool(device, info);
        }
Ejemplo n.º 17
0
 public DescriptorAllocationToken(VkDescriptorSet set, VkDescriptorPool pool)
 {
     Set  = set;
     Pool = pool;
 }
Ejemplo n.º 18
0
 public abstract VkResult CreateDescriptorPool(VkDescriptorPoolCreateInfo pCreateinfo, out VkDescriptorPool pDescriptorPool);
Ejemplo n.º 19
0
        public static VkResult vkCreateDescriptorPool(VkDevice device, VkDescriptorPoolCreateInfo pCreateinfo, VkAllocationCallbacks pAllocator, out VkDescriptorPool pDescriptorPool)
        {
            VkPreconditions.CheckNull(device, nameof(device));

            return(GetDevice(device).CreateDescriptorPool(pCreateinfo, out pDescriptorPool));
        }
Ejemplo n.º 20
0
        public static void vkDestroyDescriptorPool(VkDevice device, VkDescriptorPool descriptorPool, VkAllocationCallbacks pAllocator)
        {
            VkPreconditions.CheckNull(device, nameof(device));

            GetDevice(device).DestroyDescriptorPool(descriptorPool);
        }
Ejemplo n.º 21
0
 public static VkResult vkFreeDescriptorSets(VkDevice device, VkDescriptorPool descriptorPool, VkDescriptorSet descriptorSet)
 {
     return(vkFreeDescriptorSets(device, descriptorPool, 1, &descriptorSet));
 }
Ejemplo n.º 22
0
        public unsafe DescriptorPool(DescriptorLayout layout, uint maxSets)
        {
            _device  = layout.Device;
            _layout  = layout;
            _maxSets = maxSets;

            var poolSizes = new List <VkDescriptorPoolSize>();

            foreach (var binding in layout.Bindings)
            {
                var poolSizeIndex = poolSizes.FindIndex(
                    p => p.type == binding.DescriptorType
                    );
                if (poolSizeIndex == -1)
                {
                    poolSizes.Add(new VkDescriptorPoolSize
                    {
                        type            = binding.DescriptorType,
                        descriptorCount = binding.DescriptorCounts
                    });
                }
                else
                {
                    poolSizes[poolSizeIndex] = new VkDescriptorPoolSize
                    {
                        type            = binding.DescriptorType,
                        descriptorCount = (
                            poolSizes[poolSizeIndex].descriptorCount +
                            binding.DescriptorCounts
                            )
                    };
                }
            }

            var vulkanPoolSizes = new NativeList <VkDescriptorPoolSize>();

            foreach (var p in poolSizes)
            {
                vulkanPoolSizes.Add(p);
            }

            var createInfo = new VkDescriptorPoolCreateInfo
            {
                sType         = VkStructureType.DescriptorPoolCreateInfo,
                maxSets       = maxSets,
                poolSizeCount = vulkanPoolSizes.Count,
                pPoolSizes    = (VkDescriptorPoolSize *)vulkanPoolSizes.Data.ToPointer()
            };

            VkDescriptorPool descriptorPool;

            if (VulkanNative.vkCreateDescriptorPool(
                    _device.Handle,
                    &createInfo,
                    null,
                    &descriptorPool
                    ) != VkResult.Success)
            {
                throw new Exception("failed to create descriptor pool");
            }
            _handle = descriptorPool;
        }
Ejemplo n.º 23
0
 public static extern VkResult ResetDescriptorPool(
     VkDevice device,
     VkDescriptorPool descriptorPool,
     VkDescriptorPoolResetFlags flags
     );
Ejemplo n.º 24
0
 public static extern void DestroyDescriptorPool(
     VkDevice device,
     VkDescriptorPool descriptorPool,
     IntPtr pAllocator
     );
Ejemplo n.º 25
0
 public static extern VkResult CreateDescriptorPool(
     VkDevice device,
     ref VkDescriptorPoolCreateInfo pCreateInfo,
     IntPtr pAllocator,
     out VkDescriptorPool pDescriptorPool
     );
Ejemplo n.º 26
0
 public override VkResult CreateDescriptorPool(VkDescriptorPoolCreateInfo pCreateinfo, out VkDescriptorPool pDescriptorPool)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 27
0
 public override void DestroyDescriptorPool(VkDescriptorPool descriptorPool)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 28
0
 public abstract void DestroyDescriptorPool(VkDescriptorPool descriptorPool);
Ejemplo n.º 29
0
 public static extern VkResult FreeDescriptorSets(
     VkDevice device,
     VkDescriptorPool descriptorPool,
     uint descriptorSetCount,
     IntPtr pDescriptorSets
     );
        private VkDescriptorPool CreateVulkanDescriptorPool()
        {
            VkDescriptorPool vulkanDescriptorPool = VK_NULL_HANDLE;
            var vulkanDescriptorPoolSizes         = Array.Empty <VkDescriptorPoolSize>();

            var descriptorPoolCreateInfo = new VkDescriptorPoolCreateInfo {
                sType   = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO,
                flags   = (uint)VK_DESCRIPTOR_POOL_CREATE_FREE_DESCRIPTOR_SET_BIT,
                maxSets = 1,
            };

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

            if (resourcesLength != 0)
            {
                var vulkanDescriptorPoolSizesCount = 0;
                var constantBufferCount            = 0;
                var textureCount = 0;

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

                    switch (resource.Kind)
                    {
                    case GraphicsPipelineResourceKind.ConstantBuffer:
                    {
                        if (constantBufferCount == 0)
                        {
                            vulkanDescriptorPoolSizesCount++;
                        }
                        constantBufferCount++;
                        break;
                    }

                    case GraphicsPipelineResourceKind.Texture:
                    {
                        if (textureCount == 0)
                        {
                            vulkanDescriptorPoolSizesCount++;
                        }
                        textureCount++;
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                }

                vulkanDescriptorPoolSizes = new VkDescriptorPoolSize[vulkanDescriptorPoolSizesCount];
                var vulkanDescriptorPoolSizesIndex = 0;

                if (constantBufferCount != 0)
                {
                    vulkanDescriptorPoolSizes[vulkanDescriptorPoolSizesIndex] = new VkDescriptorPoolSize {
                        type            = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
                        descriptorCount = unchecked ((uint)constantBufferCount),
                    };
                    vulkanDescriptorPoolSizesIndex++;
                }

                if (textureCount != 0)
                {
                    vulkanDescriptorPoolSizes[vulkanDescriptorPoolSizesIndex] = new VkDescriptorPoolSize {
                        type            = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
                        descriptorCount = unchecked ((uint)textureCount),
                    };
                    vulkanDescriptorPoolSizesIndex++;
                }

                fixed(VkDescriptorPoolSize *pVulkanDescriptorPoolSizes = vulkanDescriptorPoolSizes)
                {
                    descriptorPoolCreateInfo.poolSizeCount = unchecked ((uint)vulkanDescriptorPoolSizes.Length);
                    descriptorPoolCreateInfo.pPoolSizes    = pVulkanDescriptorPoolSizes;

                    ThrowExternalExceptionIfNotSuccess(vkCreateDescriptorPool(Device.VulkanDevice, &descriptorPoolCreateInfo, pAllocator: null, (ulong *)&vulkanDescriptorPool), nameof(vkCreateDescriptorPool));
                }
            }

            return(vulkanDescriptorPool);
        }