public DescriptorHeapPool(GraphicsDevice device, DescriptorHeapType heapType, int size) { Device = device; HeapType = heapType; Size = size; Stride = device.NativeDevice.GetDescriptorHandleIncrementSize(heapType); }
public ID3D12DescriptorHeap RequestNewHeap(DescriptorHeapType type, int descriptorCount) { lock (_heapAllocationLock) { var flags = DescriptorHeapFlags.None; if (type == DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView || type == DescriptorHeapType.Sampler) { flags = DescriptorHeapFlags.ShaderVisible; } var heapDescription = new DescriptorHeapDescription { Type = type, DescriptorCount = descriptorCount, Flags = flags, NodeMask = 0, }; var heap = D3D12Device.CreateDescriptorHeap(heapDescription); _descriptorHeapPool.Add(heap); return(heap); } }
/// <summary> /// Initializes a new instance of the <see cref="DescriptorHeapDescription"/> struct. /// </summary> /// <param name="type">The heap type.</param> /// <param name="descriptorCount">The descriptor count.</param> /// <param name="flags">The optional heap flags.</param> /// <param name="nodeMask">Multi GPU node mask.</param> public DescriptorHeapDescription(DescriptorHeapType type, int descriptorCount, DescriptorHeapFlags flags = DescriptorHeapFlags.None, int nodeMask = 0) { Type = type; DescriptorCount = descriptorCount; Flags = flags; NodeMask = nodeMask; }
public DescriptorAllocator(D3D12GraphicsDevice device, DescriptorHeapType type) { Device = device; Type = type; IsShaderVisible = type == DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView || type == DescriptorHeapType.Sampler; }
// @TODO - need to implmenent this again /* * public Boolean CopyBuffer(H1GpuResource dest, H1GpuResource src) * { * H1GpuResource destDX12 = dest; * H1GpuResource srcDX12 = src; * if (destDX12 == null || srcDX12 == null) * return false; * * TransitionResource(dest, H1ResourceStates.CopyDestination); * TransitionResource(src, H1ResourceStates.CopySource); * FlushResourceBarriers(); // execute accumulated barriers * * m_CommandList.CopyResource(destDX12.GpuResource, srcDX12.GpuResource); * * return true; * } * * public Boolean CopyBufferRegion(H1GpuResource dest, Int64 destOffset, H1GpuResource src, Int64 srcOffset, Int64 numBytes) * { * H1GpuResource destDX12 = dest; * H1GpuResource srcDX12 = src; * if (destDX12 == null || srcDX12 == null) * return false; * * TransitionResource(dest, H1ResourceStates.CopyDestination); * FlushResourceBarriers(); * m_CommandList.CopyBufferRegion(destDX12.GpuResource, destOffset, srcDX12.GpuResource, srcOffset, numBytes); * * return true; * } * * public Boolean CopySubresource(H1GpuResource dest, Int32 destSubIndex, H1GpuResource src, Int32 srcSubIndex) * { * H1GpuResource destDX12 = dest; * H1GpuResource srcDX12 = src; * if (destDX12 == null || srcDX12 == null) * return false; * * FlushResourceBarriers(); * * TextureCopyLocation destLocation = new TextureCopyLocation( * destDX12.GpuResource, * destSubIndex); * * TextureCopyLocation srcLocation = new TextureCopyLocation( * srcDX12.GpuResource, * srcSubIndex); * * m_CommandList.CopyTextureRegion(destLocation, 0, 0, 0, srcLocation, null); * * return true; * } * * public Boolean WriteBuffer(H1GpuResource dest, Int64 destOffset, IntPtr bufferData, Int64 numBytes) * { * // allocate temporary space from cpu-linear allocator * H1GpuResAllocInfo tempSpace = CpuLinearAllocator.Allocate(numBytes, 512); * // copy the data ptr to the temporary space * SharpDX.Utilities.CopyMemory(tempSpace.DataPtr, bufferData, Convert.ToInt32(MathCommon.H1Methods.DivideByMultiple(numBytes, 16))); * * // copy from cpu-memory to gpu-memory * CopyBufferRegion(dest, destOffset, tempSpace.BufferRef, tempSpace.Offset, numBytes); * * return true; * } */ public Boolean SetDescriptorHeap(DescriptorHeapType type, DescriptorHeap heap) { Int32 toIndex = Convert.ToInt32(type); if (m_CurrDescriptorHeaps[toIndex] != heap) { m_CurrDescriptorHeaps[toIndex] = heap; BindDescriptorHeaps(); // update binded descriptor heaps } return(true); }
public DescriptorSet(GraphicsDevice device, int descriptorCount, DescriptorHeapType descriptorHeapType = DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView) { if (descriptorCount < 1) { throw new ArgumentOutOfRangeException(nameof(descriptorCount)); } GraphicsDevice = device; DescriptorHeapType = descriptorHeapType; DescriptorCapacity = descriptorCount; DescriptorAllocator = GetDescriptorAllocator(); StartCpuDescriptorHandle = DescriptorAllocator.Allocate(DescriptorCapacity); }
public DescriptorAllocator(GraphicsDevice device, DescriptorHeapType descriptorHeapType, int descriptorCount = DescriptorsPerHeap, DescriptorHeapFlags descriptorHeapFlags = DescriptorHeapFlags.None) { if (descriptorCount < 1 || descriptorCount > DescriptorsPerHeap) { throw new ArgumentOutOfRangeException(nameof(descriptorCount), $"Descriptor count must be between 1 and {DescriptorsPerHeap}."); } DescriptorHandleIncrementSize = device.NativeDevice.GetDescriptorHandleIncrementSize((Vortice.Direct3D12.DescriptorHeapType)descriptorHeapType); DescriptorHeapDescription descriptorHeapDescription = new DescriptorHeapDescription((Vortice.Direct3D12.DescriptorHeapType)descriptorHeapType, descriptorCount, descriptorHeapFlags); DescriptorHeap = device.NativeDevice.CreateDescriptorHeap(descriptorHeapDescription); TotalDescriptorCount = descriptorCount; }
/// <summary> /// The RequestNewHeap /// </summary> /// <param name="type">The <see cref="DescriptorHeapType"/></param> /// <returns>The <see cref="DescriptorHeap"/></returns> protected static DescriptorHeap RequestNewHeap(DescriptorHeapType type) { lock (_AllocationMutex) { DescriptorHeapDescription desc = new DescriptorHeapDescription { Type = type, DescriptorCount = _NumDescriptorsPerHeap, Flags = DescriptorHeapFlags.None, NodeMask = 1 }; var heap = Globals.Device.CreateDescriptorHeap(desc); Debug.Assert(heap != null); _DescriptorHeapPool.Add(heap); return(heap); } }
public DescriptorTablePool(Device device, DescriptorHeapType heapType, int maxEntries) { _maxEntries = maxEntries; var flags = heapType == DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView ? DescriptorHeapFlags.ShaderVisible : DescriptorHeapFlags.None; _descriptorHeap = AddDisposable(device.CreateDescriptorHeap(new DescriptorHeapDescription { Type = heapType, Flags = flags, DescriptorCount = maxEntries })); _incrementSize = device.GetDescriptorHandleIncrementSize(heapType); _entries = new Dictionary <int, DescriptorTablePoolEntry>(); }
protected DescriptorHeap RequestNewHeap(H1DescriptorHeapType type) { DescriptorHeapType typeInDX12 = H1RHIDefinitionHelper.ConvertToDescriptorHeapType(type); // @TODO - need to be thread-safe DescriptorHeapDescription desc = new DescriptorHeapDescription(); desc.Type = typeInDX12; desc.DescriptorCount = NumDescriptorsPerHeap; // this part is none, but for usage in command context, you need to create new descriptor for shader-visible by UserDescriptorHeap or DynamicDescriptorHeap desc.Flags = DescriptorHeapFlags.None; desc.NodeMask = 1; DescriptorHeap newHeap = m_Device.CreateDescriptorHeap(desc); m_DescriptorHeapPool.Add(newHeap); return(newHeap); }
public D3D12TextureView(DX12GraphicsDevice graphicsDevice, int descriptorCount, DescriptorHeapFlags descriptorHeapFlags, DescriptorHeapType descriptorHeapType) { var descriptorHeapDescription = new DescriptorHeapDescription { DescriptorCount = descriptorCount, Flags = descriptorHeapFlags, Type = descriptorHeapType }; if (descriptorHeapType == DescriptorHeapType.RenderTargetView) { _rtvDescriptorHeap = graphicsDevice.CreateDescriptorHeap(descriptorHeapDescription); } else if (descriptorHeapType == DescriptorHeapType.ConstantBufferViewShaderResourceViewUnorderedAccessView) { _dsvDescriptorHeap = graphicsDevice.CreateDescriptorHeap(descriptorHeapDescription); } }
public DescriptorAllocator(GraphicsDevice device, DescriptorHeapType descriptorHeapType) { this.device = device; this.descriptorHeapType = descriptorHeapType; this.descriptorSize = device.NativeDevice.GetDescriptorHandleIncrementSize(descriptorHeapType); }
public HeapPool(GraphicsDevice graphicsDevice, int heapSize, DescriptorHeapType heapType) : base(graphicsDevice) { this.heapSize = heapSize; this.heapType = heapType; }
public ID3D12DescriptorHeap CreateDescriptorHeap(ID3D12Device5 pDevice, int count, DescriptorHeapType type, bool shaderVisible) { DescriptorHeapDescription desc = new DescriptorHeapDescription(); desc.DescriptorCount = count; desc.Type = type; desc.Flags = shaderVisible ? DescriptorHeapFlags.ShaderVisible : DescriptorHeapFlags.None; ID3D12DescriptorHeap pHeap; pHeap = pDevice.CreateDescriptorHeap(desc); return(pHeap); }
/// <summary> /// The CopyAndBindStaleTables /// </summary> /// <param name="type">The <see cref="DescriptorHeapType"/></param> /// <param name="descriptorSize">The <see cref="uint"/></param> /// <param name="destHandleStart">The <see cref="DescriptorHandle"/></param> /// <param name="setFunction">The <see cref="CommandListSetFunc"/></param> public void CopyAndBindStaleTables(DescriptorHeapType type, uint descriptorSize, DescriptorHandle destHandleStart, CommandListSetFunc setFunction) { uint staleParamCount = 0; var tableSize = new int[MaxNumDescriptorTables]; var rootIndices = new int[MaxNumDescriptorTables]; var needSpace = 0; int rootIndex; var staleParams = StaleRootParamsBitMap; while (BitScanner.BitScanForward(staleParams, out rootIndex)) { rootIndices[staleParamCount] = rootIndex; staleParams ^= (uint)(1 << (int)rootIndex); Debug.Assert(BitScanner.BitScanReverse(RootDescriptorTable[rootIndex].AssignedHandleBitMap, out var maxSetHandle), "Root entry marked as stale but has no stale descriptors"); needSpace += maxSetHandle + 1; tableSize[staleParamCount] = maxSetHandle + 1; staleParamCount++; } Debug.Assert(staleParamCount <= MaxNumDescriptorTables, "We're only equipped to handle so many descriptor tables"); StaleRootParamsBitMap = 0; const uint maxdescriptorPerCopy = 16; var numDestDescriptorRanges = 0; var destDescriptorRangeStarts = new CpuDescriptorHandle[maxdescriptorPerCopy]; var destDescriptorRangeSizes = new int[maxdescriptorPerCopy]; var numSrcDescriptorRanges = 0; var srcDescriptorRangeStarts = new CpuDescriptorHandle[maxdescriptorPerCopy]; var srcDescriptorRangeSizes = new int[maxdescriptorPerCopy]; for (uint idx = 0; idx < staleParamCount; idx++) { rootIndex = rootIndices[idx]; setFunction?.Invoke((int)rootIndex, destHandleStart.GPUHandle); var rootDescTable = RootDescriptorTable[rootIndex]; var srcHandles = rootDescTable.TableStart; UInt64 setHandles = rootDescTable.AssignedHandleBitMap; var curDest = destHandleStart.CPUHandle; destHandleStart += (int)(tableSize[idx] * descriptorSize); while (BitScanner.BitScanForward64(setHandles, out var skipCount)) { setHandles >>= skipCount; srcHandles += skipCount; curDest.Ptr += skipCount * descriptorSize; BitScanner.BitScanForward64(~setHandles, out var descriptorCount); setHandles >>= descriptorCount; if (numSrcDescriptorRanges + descriptorCount > maxdescriptorPerCopy) { Globals.Device.CopyDescriptors(numDestDescriptorRanges, destDescriptorRangeStarts, destDescriptorRangeSizes, numSrcDescriptorRanges, srcDescriptorRangeStarts, srcDescriptorRangeSizes, type); numSrcDescriptorRanges = 0; numDestDescriptorRanges = 0; } destDescriptorRangeStarts[numDestDescriptorRanges] = curDest; destDescriptorRangeSizes[numDestDescriptorRanges] = descriptorCount; numDestDescriptorRanges++; for (int jdx = 0; jdx < descriptorCount; jdx++) { srcDescriptorRangeStarts[numSrcDescriptorRanges] = Marshal.PtrToStructure <CpuDescriptorHandle>(rootDescTable.TableStart + jdx * Marshal.SizeOf <CpuDescriptorHandle>()); srcDescriptorRangeSizes[numSrcDescriptorRanges] = 1; numSrcDescriptorRanges++; } srcHandles += descriptorCount; curDest.Ptr += descriptorCount; } } Globals.Device.CopyDescriptors(numDestDescriptorRanges, destDescriptorRangeStarts, destDescriptorRangeSizes, numSrcDescriptorRanges, srcDescriptorRangeStarts, srcDescriptorRangeSizes, type); }
/// <summary> /// Initializes a new instance of the <see cref="DescriptorAllocator"/> class. /// </summary> /// <param name="type">The <see cref="DescriptorHeapType"/></param> public DescriptorAllocator(DescriptorHeapType type) { _Type = type; }
private ID3D12DescriptorHeap CreateDescriptorHeap(ID3D12Device device, int count, DescriptorHeapType type, bool shaderVisible) { DescriptorHeapDescription desc = new DescriptorHeapDescription(); desc.DescriptorCount = count; desc.Flags = shaderVisible ? DescriptorHeapFlags.ShaderVisible : DescriptorHeapFlags.None; desc.Type = type; return(device.CreateDescriptorHeap(desc)); }
public DescriptorAllocator(GraphicsDevice device, DescriptorHeapType heapType) : base(device) { HeapType = heapType; Stride = device.NativeDevice.GetDescriptorHandleIncrementSize(heapType); }
public DescriptorHandle AllocateDescriptor(DescriptorHeapType type, int count = 1) { return(_descriptorAllocator[(int)type].Allocate(count)); }
/// <summary> /// The AllocateDescriptor /// </summary> /// <param name="type">The <see cref="DescriptorHeapType"/></param> /// <param name="count">The <see cref="int"/></param> /// <returns>The <see cref="CpuDescriptorHandle"/></returns> public static CpuDescriptorHandle AllocateDescriptor(DescriptorHeapType type, int count = 1) { return(DescriptorAllocators[(int)type].Allocate(count)); }