コード例 #1
0
        public CpuDescriptorHandle AllocateSlot(int slot)
        {
            lock (allocatorLock)
            {
                if (slot < 0 || slot > TotalDescriptorCount - 1)
                {
                    throw new ArgumentOutOfRangeException(nameof(slot), "Slot must be between 0 and the total descriptor count - 1.");
                }

                CpuDescriptorHandle cpuDescriptorHandle = DescriptorHeap.GetCPUDescriptorHandleForHeapStart() + slot * DescriptorHandleIncrementSize;

                return(cpuDescriptorHandle);
            }
        }
コード例 #2
0
        /// <summary>
        /// Creates a new <see cref="DescriptorAllocator"/> instance with the specified parameters
        /// </summary>
        /// <param name="device">The <see cref="GraphicsDevice"/> instance to use</param>
        public DescriptorAllocator(GraphicsDevice device)
        {
            DescriptorSize = device.NativeDevice.GetDescriptorHandleIncrementSize(DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView);

            DescriptorHeapDescription descriptorHeapDescription = new DescriptorHeapDescription
            {
                DescriptorCount = DescriptorsPerHeap,
                Flags           = DescriptorHeapFlags.ShaderVisible,
                Type            = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView
            };

            DescriptorHeap = device.NativeDevice.CreateDescriptorHeap(descriptorHeapDescription);

            _RemainingHandles = DescriptorsPerHeap;
            _CurrentCpuHandle = DescriptorHeap.GetCPUDescriptorHandleForHeapStart();
            _CurrentGpuHandle = DescriptorHeap.GetGPUDescriptorHandleForHeapStart();
        }
コード例 #3
0
        public CpuDescriptorHandle Allocate(int count)
        {
            lock (allocatorLock)
            {
                if (count < 1 || count > DescriptorCapacity)
                {
                    throw new ArgumentOutOfRangeException(nameof(count), "Count must be between 1 and the total descriptor count.");
                }

                if (CurrentDescriptorCount + count > DescriptorCapacity)
                {
                    Reset();
                }

                CpuDescriptorHandle descriptor = DescriptorHeap.GetCPUDescriptorHandleForHeapStart() + CurrentDescriptorCount * DescriptorHandleIncrementSize;

                CurrentDescriptorCount += count;

                return(descriptor);
            }
        }
コード例 #4
0
        public GpuDescriptorHandle GetGpuDescriptorHandle(CpuDescriptorHandle descriptor)
        {
            if (!DescriptorHeap.Description.Flags.HasFlag(DescriptorHeapFlags.ShaderVisible))
            {
                throw new InvalidOperationException();
            }

            return(DescriptorHeap.GetGPUDescriptorHandleForHeapStart() + (descriptor.Ptr - DescriptorHeap.GetCPUDescriptorHandleForHeapStart().Ptr));
        }