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); } }
/// <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(); }
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); } }
public GpuDescriptorHandle GetGpuDescriptorHandle(CpuDescriptorHandle descriptor) { if (!DescriptorHeap.Description.Flags.HasFlag(DescriptorHeapFlags.ShaderVisible)) { throw new InvalidOperationException(); } return(DescriptorHeap.GetGPUDescriptorHandleForHeapStart() + (descriptor.Ptr - DescriptorHeap.GetCPUDescriptorHandleForHeapStart().Ptr)); }