Пример #1
0
        public void Initialize(AmtDescriptorSetLayout layout)
        {
            // TODO : create a dictionary to find which location to bind
            //PipelineResources = layout.PipelineResources;

            var computeResources = new AmtPipelineLayoutStageResource(MgShaderStageFlagBits.COMPUTE_BIT, layout, Locator);

            Compute = new AmtDescriptorSetBindingMap(computeResources);

            var vertResources = new AmtPipelineLayoutStageResource(MgShaderStageFlagBits.VERTEX_BIT, layout, Locator);

            Vertex = new AmtDescriptorSetBindingMap(vertResources);

            var fragResources = new AmtPipelineLayoutStageResource(MgShaderStageFlagBits.FRAGMENT_BIT, layout, Locator);

            Fragment = new AmtDescriptorSetBindingMap(fragResources);
        }
Пример #2
0
        public void UpdateDescriptorSets(MgWriteDescriptorSet[] pDescriptorWrites, MgCopyDescriptorSet[] pDescriptorCopies)
        {
            if (pDescriptorWrites != null)
            {
                foreach (var desc in pDescriptorWrites)
                {
                    var localSet = (AmtDescriptorSet)desc.DstSet;
                    if (localSet == null)
                    {
                        throw new ArgumentNullException(nameof(desc.DstSet));
                    }

                    var x = desc.DstBinding;                     // SHOULD ALWAYS BE ZERO

                    int arrayElement = (int)desc.DstArrayElement;

                    // TODO: what do we do about multiple descriptors
                    var count = (int)desc.DescriptorCount;

                    AmtDescriptorSetUpdateKey result;
                    if (localSet.Locator.TryGetValue(desc.DstBinding, out result))
                    {
                        foreach (var mask in new[] {
                            MgShaderStageFlagBits.COMPUTE_BIT,
                            MgShaderStageFlagBits.VERTEX_BIT,
                            MgShaderStageFlagBits.FRAGMENT_BIT
                        })
                        {
                            AmtDescriptorSetBindingMap map = null;
                            uint bindingOffset             = 0;
                            uint samplerOffset             = 0;
                            if ((result.Stage & mask) == MgShaderStageFlagBits.COMPUTE_BIT)
                            {
                                map           = localSet.Compute;
                                bindingOffset = result.ComputeOffset;
                                samplerOffset = result.ComputeSamplerIndex;
                            }
                            else if ((result.Stage & mask) == MgShaderStageFlagBits.VERTEX_BIT)
                            {
                                map           = localSet.Vertex;
                                bindingOffset = result.VertexOffset;
                                samplerOffset = result.VertexSamplerIndex;
                            }
                            else if ((result.Stage & mask) == MgShaderStageFlagBits.FRAGMENT_BIT)
                            {
                                map           = localSet.Fragment;
                                bindingOffset = result.FragmentOffset;
                                samplerOffset = result.FragmentSamplerIndex;
                            }

                            if (map != null)
                            {
                                switch (desc.DescriptorType)
                                {
                                //case MgDescriptorType.SAMPLER:
                                case MgDescriptorType.COMBINED_IMAGE_SAMPLER:
                                case MgDescriptorType.SAMPLED_IMAGE:

                                    for (int i = 0; i < count; ++i)
                                    {
                                        MgDescriptorImageInfo info = desc.ImageInfo[i];

                                        var localSampler = (AmtSampler)info.Sampler;
                                        var localView    = (IAmtImageView)info.ImageView;

                                        var imageIndex = bindingOffset + i;
                                        map.Textures[imageIndex].Texture = localView.GetTexture();

                                        var samplerIndex = samplerOffset + i;
                                        map.SamplerStates[samplerIndex].Sampler = localSampler.Sampler;
                                    }

                                    break;

                                case MgDescriptorType.UNIFORM_BUFFER:
                                case MgDescriptorType.UNIFORM_BUFFER_DYNAMIC:
                                case MgDescriptorType.STORAGE_BUFFER:
                                case MgDescriptorType.STORAGE_BUFFER_DYNAMIC:
                                    // HOPEFULLY DESCRIPTOR SETS ARE GROUPED BY COMMON TYPES
                                    for (int i = 0; i < count; ++i)
                                    {
                                        var info = desc.BufferInfo[i];

                                        var buf = (AmtBuffer)info.Buffer;

                                        ulong totalOffset = buf.BoundMemoryOffset + info.Offset;

                                        Debug.Assert(totalOffset <= nuint.MaxValue);

                                        var index = bindingOffset + i;
                                        map.Buffers[index].Buffer            = buf.VertexBuffer;
                                        map.Buffers[index].BoundMemoryOffset = (nuint)totalOffset;
                                    }
                                    break;

                                default:
                                    throw new NotSupportedException();
                                }
                            }
                        }
                    }
                }
            }
        }