Exemple #1
0
        void SetupDescriptorSet()
        {
            var allocInfo = new MgDescriptorSetAllocateInfo
            {
                DescriptorPool     = mDescriptorPool,
                DescriptorSetCount = 1,
                SetLayouts         = new[] { mDescriptorSetLayout },
            };

            IMgDescriptorSet[] dSets;
            var err = mConfiguration.Device.AllocateDescriptorSets(allocInfo, out dSets);

            mDescriptorSet = dSets[0];

            Debug.Assert(err == Result.SUCCESS);
            mConfiguration.Device.UpdateDescriptorSets(
                new []
            {
                new MgWriteDescriptorSet
                {
                    DstSet          = mDescriptorSet,
                    DescriptorCount = 1,
                    DescriptorType  = MgDescriptorType.UNIFORM_BUFFER,
                    BufferInfo      = new MgDescriptorBufferInfo[]
                    {
                        uniformDataVS.descriptor,
                    },
                    DstBinding = 0,
                },
            }, null);
        }
Exemple #2
0
        void setupDescriptorSet()
        {
            var allocInfo = new MgDescriptorSetAllocateInfo
            {
                DescriptorPool     = mDescriptorPool,
                DescriptorSetCount = 1,
                SetLayouts         = new IMgDescriptorSetLayout[] { mDescriptorSetLayout },
            };

            var device = mManager.Configuration.Device;

            Debug.Assert(device != null);

            var err = device.AllocateDescriptorSets(allocInfo, out mDescriptorSets);

            Debug.Assert(err == Result.SUCCESS);

            var writeDescriptorSets = new []
            {
                // Binding 0 : Vertex shader uniform buffer
                new MgWriteDescriptorSet
                {
                    DstSet          = mDescriptorSets[0],
                    DescriptorType  = MgDescriptorType.UNIFORM_BUFFER,
                    DstBinding      = 0,
                    DescriptorCount = 1,
                    BufferInfo      = new []
                    {
                        uniformBufferVS.Descriptor,
                    }
                },
                // Binding 1 : Fragment shader texture sampler
                new MgWriteDescriptorSet
                {
                    DstSet          = mDescriptorSets[0],
                    DescriptorType  = MgDescriptorType.COMBINED_IMAGE_SAMPLER,
                    DstBinding      = 1,
                    DescriptorCount = 1,
                    ImageInfo       = new []
                    {
                        texture.descriptor,
                    }
                },
            };

            device.UpdateDescriptorSets(writeDescriptorSets, null);
        }
Exemple #3
0
        public Result AllocateDescriptorSets(MgDescriptorSetAllocateInfo pAllocateInfo, out IMgDescriptorSet[] pDescriptorSets)
        {
            if (pAllocateInfo == null)
            {
                throw new ArgumentNullException(nameof(pAllocateInfo));
            }

            var pool = (AmtDescriptorPool)pAllocateInfo.DescriptorPool;

            if (pool == null)
            {
                throw new ArgumentNullException(nameof(pAllocateInfo.DescriptorPool));
            }

            var noOfSetsRequested = pAllocateInfo.SetLayouts.Length;

            if (pool.RemainingSets < noOfSetsRequested)
            {
                throw new InvalidOperationException();
            }

            pDescriptorSets = new AmtDescriptorSet[noOfSetsRequested];

            for (int i = 0; i < noOfSetsRequested; ++i)
            {
                var setLayout = (AmtDescriptorSetLayout)pAllocateInfo.SetLayouts[i];

                AmtDescriptorSet dSet;
                if (!pool.TryTake(out dSet))
                {
                    throw new InvalidOperationException();
                }
                // copy here
                dSet.Initialize(setLayout);
                pDescriptorSets[i] = dSet;
            }

            return(Result.SUCCESS);
        }
Exemple #4
0
        public Result Allocate(MgDescriptorSetAllocateInfo pAllocateInfo, out IMgDescriptorSet[] pDescriptorSets)
        {
            if (pAllocateInfo == null)
            {
                throw new ArgumentNullException(nameof(pAllocateInfo));
            }

            var parentPool = (IGLNextDescriptorPool)pAllocateInfo.DescriptorPool;

            var highestBinding  = 0U;
            var sortedResources = new List <GLDescriptorPoolResourceInfo>();

            var output = new List <IMgDescriptorSet>();

            for (var i = 0; i < pAllocateInfo.DescriptorSetCount; i += 1)
            {
                var bSetLayout = (IGLDescriptorSetLayout)pAllocateInfo.SetLayouts[i];

                sortedResources.Clear();
                foreach (var uniform in bSetLayout.Uniforms)
                {
                    highestBinding = Math.Max(highestBinding, uniform.Binding);
                    GLPoolResourceTicket ticket;
                    switch (uniform.DescriptorType)
                    {
                    case MgDescriptorType.COMBINED_IMAGE_SAMPLER:
                        if (parentPool.CombinedImageSamplers.Allocate(uniform.DescriptorCount, out ticket))
                        {
                            sortedResources.Add(
                                new GLDescriptorPoolResourceInfo
                            {
                                Binding         = uniform.Binding,
                                DescriptorCount = uniform.DescriptorCount,
                                GroupType       = GLDescriptorBindingGroup.CombinedImageSampler,
                                Ticket          = ticket,
                            }
                                );
                        }
                        else
                        {
                            // VK_ERROR_FRAGMENTED_POOL = -12
                            pDescriptorSets = null;
                            return(Result.ERROR_OUT_OF_HOST_MEMORY);
                        }
                        break;

                    case MgDescriptorType.STORAGE_BUFFER:
                        if (parentPool.StorageBuffers.Allocate(uniform.DescriptorCount, out ticket))
                        {
                            sortedResources.Add(
                                new GLDescriptorPoolResourceInfo
                            {
                                Binding         = uniform.Binding,
                                DescriptorCount = uniform.DescriptorCount,
                                GroupType       = GLDescriptorBindingGroup.StorageBuffer,
                                Ticket          = ticket,
                            }
                                );
                        }
                        else
                        {
                            // VK_ERROR_FRAGMENTED_POOL = -12
                            pDescriptorSets = null;
                            return(Result.ERROR_OUT_OF_HOST_MEMORY);
                        }
                        break;

                    case MgDescriptorType.UNIFORM_BUFFER:
                        if (parentPool.UniformBuffers.Allocate(uniform.DescriptorCount, out ticket))
                        {
                            sortedResources.Add(
                                new GLDescriptorPoolResourceInfo
                            {
                                Binding         = uniform.Binding,
                                DescriptorCount = uniform.DescriptorCount,
                                GroupType       = GLDescriptorBindingGroup.UniformBuffer,
                                Ticket          = ticket,
                            }
                                );
                        }
                        else
                        {
                            // VK_ERROR_FRAGMENTED_POOL = -12
                            pDescriptorSets = null;
                            return(Result.ERROR_OUT_OF_HOST_MEMORY);
                        }
                        break;
                    }
                }

                // COUNT
                var count = highestBinding + 1;

                var resources = new GLDescriptorPoolResourceInfo[count];
                foreach (var res in sortedResources)
                {
                    resources[res.Binding] = res;
                }

                IGLDescriptorSet item;
                if (parentPool.TryTake(out item))
                {
                    item.Initialize(resources);
                    parentPool.AllocatedSets.Add(item.Key, item);
                    output.Add(item);
                }
                else
                {
                    // TOO MANY DESCRIPTOR SETS FOR POOL
                    pDescriptorSets = null;
                    return(Result.ERROR_OUT_OF_HOST_MEMORY);
                }
            }

            pDescriptorSets = output.ToArray();
            return(Result.SUCCESS);
        }
Exemple #5
0
        public Result AllocateDescriptorSets(MgDescriptorSetAllocateInfo pAllocateInfo, out IMgDescriptorSet[] pDescriptorSets)
        {
            IGLDescriptorSetAllocator allocator = null;

            return(allocator.AllocateDescriptorSets(pAllocateInfo, out pDescriptorSets));
        }
Exemple #6
0
 public Result AllocateDescriptorSets(MgDescriptorSetAllocateInfo pAllocateInfo, out IMgDescriptorSet[] pDescriptorSets)
 {
     return(mEntrypoint.DescriptorSet.Allocate(pAllocateInfo, out pDescriptorSets));
 }
Exemple #7
0
 public Result AllocateDescriptorSets(MgDescriptorSetAllocateInfo pAllocateInfo, out IMgDescriptorSet[] pDescriptorSets)
 {
     throw new NotImplementedException();
 }
Exemple #8
0
        // Allocate one region of memory for the uniform buffer
        private void InitializeUniforms()
        {
            MgBufferCreateInfo pCreateInfo = new MgBufferCreateInfo
            {
                Usage = MgBufferUsageFlagBits.UNIFORM_BUFFER_BIT,
                Size  = MaxBytesPerFrame,
            };
            IMgBuffer buffer;
            var       err = mConfiguration.Device.CreateBuffer(pCreateInfo, null, out buffer);

            Debug.Assert(err == Result.SUCCESS);
            //dynamicConstantBuffer = device.CreateBuffer(MaxBytesPerFrame, (MTLResourceOptions)0);
            //dynamicConstantBuffer.Label = "UniformBuffer";

            MgMemoryRequirements uniformsMemReqs;

            mConfiguration.Device.GetBufferMemoryRequirements(buffer, out uniformsMemReqs);

            const MgMemoryPropertyFlagBits uniformPropertyFlags = MgMemoryPropertyFlagBits.HOST_COHERENT_BIT;

            uint uniformMemoryTypeIndex;

            mConfiguration.Partition.GetMemoryType(
                uniformsMemReqs.MemoryTypeBits, uniformPropertyFlags, out uniformMemoryTypeIndex);

            var uniformMemAlloc = new MgMemoryAllocateInfo
            {
                MemoryTypeIndex = uniformMemoryTypeIndex,
                AllocationSize  = uniformsMemReqs.Size,
            };

            IMgDeviceMemory deviceMemory;
            var             result = mConfiguration.Device.AllocateMemory(uniformMemAlloc, null, out deviceMemory);

            Debug.Assert(result == Result.SUCCESS);

            buffer.BindBufferMemory(mConfiguration.Device, deviceMemory, 0);

            mUniforms = new BufferInfo
            {
                Buffer       = buffer,
                DeviceMemory = deviceMemory,
                Offset       = 0,
                Length       = MaxBytesPerFrame,
            };

            IMgDescriptorSetLayout pSetLayout;
            var dslCreateInfo = new MgDescriptorSetLayoutCreateInfo
            {
                Bindings = new MgDescriptorSetLayoutBinding[]
                {
                    new MgDescriptorSetLayoutBinding
                    {
                        Binding         = 0,
                        DescriptorCount = 1,
                        DescriptorType  = MgDescriptorType.UNIFORM_BUFFER_DYNAMIC,
                        StageFlags      = MgShaderStageFlagBits.VERTEX_BIT,
                    },
                },
            };

            err = mConfiguration.Device.CreateDescriptorSetLayout(dslCreateInfo, null, out pSetLayout);

            var poolCreateInfo = new Magnesium.MgDescriptorPoolCreateInfo
            {
                MaxSets   = 1,
                PoolSizes = new MgDescriptorPoolSize[] {
                    new MgDescriptorPoolSize
                    {
                        DescriptorCount = 1,
                        Type            = MgDescriptorType.COMBINED_IMAGE_SAMPLER,
                    },
                },
            };

            err = mConfiguration.Device.CreateDescriptorPool(poolCreateInfo, null, out mDescriptorPool);

            IMgDescriptorSet[]          dSets;
            MgDescriptorSetAllocateInfo pAllocateInfo = new MgDescriptorSetAllocateInfo
            {
                DescriptorPool     = mDescriptorPool,
                DescriptorSetCount = 1,
                SetLayouts         = new IMgDescriptorSetLayout[]
                {
                    pSetLayout,
                },
            };

            mConfiguration.Device.AllocateDescriptorSets(pAllocateInfo, out dSets);
            mUniformDescriptorSet = dSets[0];

            MgWriteDescriptorSet[] writes = new MgWriteDescriptorSet[]
            {
                new MgWriteDescriptorSet
                {
                    DescriptorCount = 1,
                    DescriptorType  = MgDescriptorType.UNIFORM_BUFFER_DYNAMIC,
                    DstSet          = mUniformDescriptorSet,
                    BufferInfo      = new MgDescriptorBufferInfo[]
                    {
                        new MgDescriptorBufferInfo
                        {
                            Buffer = mUniforms.Buffer,
                            Offset = mUniforms.Offset,
                            Range  = mUniforms.Length,
                        },
                    },
                    DstBinding = 0,
                }
            };
            mConfiguration.Device.UpdateDescriptorSets(writes, null);


            mSetLayout = pSetLayout;
        }