Exemplo n.º 1
0
        public ResourceGroupDescription(DescriptorSetLayoutBuilder descriptorSetLayout, EffectConstantBufferDescription constantBufferReflection) : this()
        {
            DescriptorSetLayout      = descriptorSetLayout;
            ConstantBufferReflection = constantBufferReflection;

            // We combine both hash for DescriptorSet and cbuffer itself (if it exists)
            Hash = descriptorSetLayout.Hash;
            if (constantBufferReflection != null)
            {
                ObjectId.Combine(ref Hash, ref constantBufferReflection.Hash, out Hash);
            }
        }
Exemplo n.º 2
0
        public static EffectDescriptorSetReflection New(GraphicsDevice graphicsDevice, EffectBytecode effectBytecode, List <string> effectDescriptorSetSlots, string defaultSetSlot)
        {
            // Find resource groups
            // TODO: We should precompute most of that at compile time in BytecodeReflection
            // just waiting for format to be more stable
            var descriptorSetLayouts = new EffectDescriptorSetReflection {
                DefaultSetSlot = defaultSetSlot
            };

            foreach (var effectDescriptorSetSlot in effectDescriptorSetSlots)
            {
                // Find all resources related to this slot name
                // NOTE: Ordering is mirrored by GLSL layout in Vulkan
                var  descriptorSetLayoutBuilder = new DescriptorSetLayoutBuilder();
                bool hasBindings = false;
                foreach (var resourceBinding in effectBytecode.Reflection.ResourceBindings
                         .Where(x => x.ResourceGroup == effectDescriptorSetSlot || (effectDescriptorSetSlot == defaultSetSlot && (x.ResourceGroup == null || x.ResourceGroup == "Globals")))
                         .GroupBy(x => new { Key = x.KeyInfo.Key, Class = x.Class, Type = x.Type, ElementType = x.ElementType.Type, SlotCount = x.SlotCount, LogicalGroup = x.LogicalGroup })
                         .OrderBy(x => x.Key.Class == EffectParameterClass.ConstantBuffer ? 0 : 1)) // Note: Putting cbuffer first for now
                {
                    SamplerState samplerState = null;
                    if (resourceBinding.Key.Class == EffectParameterClass.Sampler)
                    {
                        var matchingSamplerState = effectBytecode.Reflection.SamplerStates.FirstOrDefault(x => x.Key == resourceBinding.Key.Key);
                        if (matchingSamplerState != null)
                        {
                            samplerState = SamplerState.New(graphicsDevice, matchingSamplerState.Description);
                        }
                    }
                    hasBindings = true;

                    descriptorSetLayoutBuilder.AddBinding(resourceBinding.Key.Key, resourceBinding.Key.LogicalGroup, resourceBinding.Key.Class, resourceBinding.Key.Type, resourceBinding.Key.ElementType, resourceBinding.Key.SlotCount, samplerState);
                }

                descriptorSetLayouts.AddLayout(effectDescriptorSetSlot, hasBindings ? descriptorSetLayoutBuilder : null);
            }

            return(descriptorSetLayouts);
        }
        private DescriptorSetLayout(GraphicsDevice device, DescriptorSetLayoutBuilder builder)
        {
            BindingOffsets = new int[builder.ElementCount];
            int currentBindingOffset = 0;

            foreach (var entry in builder.Entries)
            {
                // We will both setup BindingOffsets and increment SamplerCount/SrvCount at the same time
                if (entry.Class == EffectParameterClass.Sampler)
                {
                    for (int i = 0; i < entry.ArraySize; ++i)
                    {
                        BindingOffsets[currentBindingOffset++] = entry.ImmutableSampler != null ? -1 : SamplerCount++ *device.SamplerHandleIncrementSize;
                    }
                }
                else
                {
                    for (int i = 0; i < entry.ArraySize; ++i)
                    {
                        BindingOffsets[currentBindingOffset++] = SrvCount++ *device.SrvHandleIncrementSize;
                    }
                }
            }
        }
Exemplo n.º 4
0
 public LayoutEntry(string name, DescriptorSetLayoutBuilder layout)
 {
     Name   = name;
     Layout = layout;
 }
Exemplo n.º 5
0
 public void AddLayout(string descriptorSetName, DescriptorSetLayoutBuilder descriptorSetLayoutBuilder)
 {
     Layouts.Add(new LayoutEntry(descriptorSetName, descriptorSetLayoutBuilder));
 }
Exemplo n.º 6
0
 private DescriptorSetLayout(GraphicsDevice device, DescriptorSetLayoutBuilder builder)
 {
     ElementCount = builder.ElementCount;
     Entries      = builder.Entries.ToArray();
 }
Exemplo n.º 7
0
 public static DescriptorSetLayout New(GraphicsDevice device, DescriptorSetLayoutBuilder builder)
 {
     return(new DescriptorSetLayout(device, builder));
 }
 public static void ProcessResources(this ParameterCollectionLayout parameterCollectionLayout, DescriptorSetLayoutBuilder layout)
 {
     foreach (var layoutEntry in layout.Entries)
     {
         parameterCollectionLayout.LayoutParameterKeyInfos.Add(new ParameterKeyInfo(layoutEntry.Key, parameterCollectionLayout.ResourceCount++));
     }
 }
Exemplo n.º 9
0
 private DescriptorSetLayout(GraphicsDevice device, DescriptorSetLayoutBuilder builder) : base(device)
 {
     this.Builder = builder;
     Recreate();
 }