/// <summary> /// Creates a new <see cref="GpuResourceDesc"/> /// </summary> /// <param name="resourceFormat">The <see cref="GpuResourceFormat"/> describing the resource format and dimensions</param> /// <param name="gpuMemoryType">The type of GPU memory this resource will be on</param> /// <param name="initialState">The initial state of the resource</param> /// <param name="allocFlags">Any additional allocation flags passed to the allocator</param> /// <param name="clearValue">If this resource is a texture, the clear value for which it is optimised</param> /// <param name="heapFlags">Any additional flags used for creating or selecting the allocation heap</param> public GpuResourceDesc( GpuResourceFormat resourceFormat, GpuMemoryType gpuMemoryType, D3D12_RESOURCE_STATES initialState, GpuAllocFlags allocFlags = GpuAllocFlags.None, D3D12_CLEAR_VALUE?clearValue = null, D3D12_HEAP_FLAGS heapFlags = D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_NONE ) { ResourceFormat = resourceFormat; GpuMemoryType = gpuMemoryType; InitialState = initialState; AllocFlags = allocFlags; ClearValue = clearValue; HeapFlags = heapFlags; }
/// <summary> /// Allocates a new <see cref="IndexBuffer{TIndex}"/> /// </summary> /// <typeparam name="TIndex">The type of each index</typeparam> /// <param name="indexCount">The number of indices</param> /// <param name="type">The type of GPU memory to allocate in</param> /// <param name="flags">Any additional allocation flags passed to the allocator</param> /// <returns>A new <see cref="IndexBuffer{TIndex}"/></returns> public IndexBuffer <TIndex> AllocateIndexBuffer <TIndex>( uint indexCount, GpuMemoryType type, GpuAllocFlags flags = GpuAllocFlags.None ) where TIndex : unmanaged { Debug.Assert(type != GpuMemoryType.CpuReadOptimized); var desc = new GpuResourceDesc( GpuResourceFormat.Buffer((uint)sizeof(TIndex) * indexCount), type, type == GpuMemoryType.CpuWriteOptimized ? D3D12_RESOURCE_STATE_GENERIC_READ : D3D12_RESOURCE_STATE_INDEX_BUFFER, flags ); return(new IndexBuffer <TIndex>(Allocate(desc))); }
private AllocatorHeap CreateNewHeap(GpuMemoryType type) { D3D12_HEAP_PROPERTIES props = new((D3D12_HEAP_TYPE)type); D3D12_HEAP_DESC desc = new(InitialHeapSize, props); ComPtr <ID3D12Heap> heap = default; _device.Get()->CreateHeap(&desc, heap.Guid, ComPtr.GetVoidAddressOf(&heap)); var allocatorHeap = new AllocatorHeap { Heap = heap.Move(), FreeBlocks = new() }; allocatorHeap.FreeBlocks.Add(new HeapBlock { Offset = 0, Size = desc.SizeInBytes }); _heaps[type].Add(allocatorHeap); return(allocatorHeap); }
public T this[GpuMemoryType context] { get => Unsafe.Add(ref Default, (int)context - 1);