/// <inheritdoc cref="ID3D12CommandAllocatorPool.GetCommandAllocator"/> /// <param name="d3D12CommandListType">The type of command allocator to rent.</param> internal ComPtr <ID3D12CommandAllocator> GetCommandAllocator(D3D12_COMMAND_LIST_TYPE d3D12CommandListType) { return(d3D12CommandListType switch { D3D12_COMMAND_LIST_TYPE_COMPUTE => this.computeCommandAllocatorPool.GetCommandAllocator(this.d3D12Device, this.d3D12ComputeFence), D3D12_COMMAND_LIST_TYPE_COPY => this.copyCommandAllocatorPool.GetCommandAllocator(this.d3D12Device, this.d3D12CopyFence), _ => ThrowHelper.ThrowArgumentException <ComPtr <ID3D12CommandAllocator> >() });
/// <summary> /// Reads the contents of the specified range from the current <see cref="Texture2D{T}"/> instance and writes them into a target <see cref="Texture2D{T}"/> instance. /// </summary> /// <param name="destination">The target <see cref="Texture2D{T}"/> instance to write data to.</param> /// <param name="destinationOffsetX">The horizontal offset within <paramref name="destination"/>.</param> /// <param name="destinationOffsetY">The vertical offset within <paramref name="destination"/>.</param> /// <param name="sourceOffsetX">The horizontal offset in the source texture.</param> /// <param name="sourceOffsetY">The vertical offset in the source texture.</param> /// <param name="width">The width of the memory area to copy.</param> /// <param name="height">The height of the memory area to copy.</param> internal void CopyTo(Texture2D <T> destination, int sourceOffsetX, int sourceOffsetY, int destinationOffsetX, int destinationOffsetY, int width, int height) { GraphicsDevice.ThrowIfDisposed(); ThrowIfDisposed(); destination.ThrowIfDeviceMismatch(GraphicsDevice); destination.ThrowIfDisposed(); Guard.IsInRange(sourceOffsetX, 0, Width, nameof(sourceOffsetX)); Guard.IsInRange(sourceOffsetY, 0, Height, nameof(sourceOffsetY)); Guard.IsInRange(destinationOffsetX, 0, destination.Width, nameof(destinationOffsetX)); Guard.IsInRange(destinationOffsetY, 0, destination.Height, nameof(destinationOffsetY)); Guard.IsBetweenOrEqualTo(width, 1, Width, nameof(width)); Guard.IsBetweenOrEqualTo(height, 1, Height, nameof(height)); Guard.IsBetweenOrEqualTo(width, 1, destination.Width, nameof(width)); Guard.IsBetweenOrEqualTo(height, 1, destination.Height, nameof(height)); Guard.IsBetweenOrEqualTo(destinationOffsetX + width, 1, destination.Width, nameof(destinationOffsetX)); Guard.IsBetweenOrEqualTo(destinationOffsetY + height, 1, destination.Height, nameof(destinationOffsetY)); Guard.IsLessThanOrEqualTo(sourceOffsetX + width, Width, nameof(sourceOffsetX)); Guard.IsLessThanOrEqualTo(sourceOffsetY + height, Height, nameof(sourceOffsetY)); D3D12_COMMAND_LIST_TYPE d3D12CommandListType = this.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE || destination.d3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE ? D3D12_COMMAND_LIST_TYPE_COMPUTE : D3D12_COMMAND_LIST_TYPE_COPY; using CommandList copyCommandList = new(GraphicsDevice, d3D12CommandListType); if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, destination.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); } copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( d3D12ResourceDestination: destination.D3D12Resource, (uint)destinationOffsetX, (uint)destinationOffsetY, destinationZ: 0, d3D12ResourceSource: D3D12Resource, (uint)sourceOffsetX, (uint)sourceOffsetY, sourceZ: 0, (uint)width, (uint)height, 1); if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); copyCommandList.D3D12GraphicsCommandList->TransitionBarrier(destination.D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, destination.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); }
/// <summary> /// Creates a new <see cref="CommandList"/> instance with the specified parameters. /// </summary> /// <param name="device">The target <see cref="GraphicsDevice"/> instance to use.</param> /// <param name="d3D12CommandListType">The type of command list to create.</param> public CommandList(GraphicsDevice device, D3D12_COMMAND_LIST_TYPE d3D12CommandListType) { this.device = device; this.d3D12CommandListType = d3D12CommandListType; this.d3D12CommandAllocator = device.GetCommandAllocator(d3D12CommandListType); this.d3D12GraphicsCommandList = device.D3D12Device->CreateCommandList(d3D12CommandListType, this.d3D12CommandAllocator); // Set the heap descriptor if the command list is not for copy operations if (d3D12CommandListType is not D3D12_COMMAND_LIST_TYPE_COPY) { device.SetDescriptorHeapForCommandList(this.d3D12GraphicsCommandList); } }
public virtual int CreateCommandAllocator( D3D12_COMMAND_LIST_TYPE type, ref Guid riid, out IntPtr ppCommandAllocator ) { var fp = GetFunctionPointer(9); if (m_CreateCommandAllocatorFunc == null) { m_CreateCommandAllocatorFunc = (CreateCommandAllocatorFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(CreateCommandAllocatorFunc)); } return(m_CreateCommandAllocatorFunc(m_ptr, type, ref riid, out ppCommandAllocator)); }
/// <summary> /// Creates a new <see cref="CommandList"/> instance with the specified parameters. /// </summary> /// <param name="device">The target <see cref="GraphicsDevice"/> instance to use.</param> /// <param name="d3D12PipelineState">The <see cref="ID3D12PipelineState"/> instance to use for the new command list.</param> public CommandList(GraphicsDevice device, ID3D12PipelineState *d3D12PipelineState) { this.device = device; this.d3D12CommandListType = D3D12_COMMAND_LIST_TYPE_COMPUTE; Unsafe.SkipInit(out this.d3D12GraphicsCommandList); Unsafe.SkipInit(out this.d3D12CommandAllocator); device.GetCommandListAndAllocator( d3D12PipelineState, out *(ID3D12GraphicsCommandList **)Unsafe.AsPointer(ref this.d3D12GraphicsCommandList), out *(ID3D12CommandAllocator **)Unsafe.AsPointer(ref this.d3D12CommandAllocator)); // Set the heap descriptor for the command list device.SetDescriptorHeapForCommandList(this.d3D12GraphicsCommandList); }
public virtual int CreateCommandList1( uint nodeMask, D3D12_COMMAND_LIST_TYPE type, D3D12_COMMAND_LIST_FLAGS flags, ref Guid riid, out IntPtr ppCommandList ) { var fp = GetFunctionPointer(51); if (m_CreateCommandList1Func == null) { m_CreateCommandList1Func = (CreateCommandList1Func)Marshal.GetDelegateForFunctionPointer(fp, typeof(CreateCommandList1Func)); } return(m_CreateCommandList1Func(m_ptr, nodeMask, type, flags, ref riid, out ppCommandList)); }
public virtual int CreateCommandList( uint nodeMask, D3D12_COMMAND_LIST_TYPE type, ID3D12CommandAllocator pCommandAllocator, ID3D12PipelineState pInitialState, ref Guid riid, out IntPtr ppCommandList ) { var fp = GetFunctionPointer(12); if (m_CreateCommandListFunc == null) { m_CreateCommandListFunc = (CreateCommandListFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(CreateCommandListFunc)); } return(m_CreateCommandListFunc(m_ptr, nodeMask, type, pCommandAllocator != null ? pCommandAllocator.Ptr : IntPtr.Zero, pInitialState != null ? pInitialState.Ptr : IntPtr.Zero, ref riid, out ppCommandList)); }
/// <summary> /// Creates a new <see cref="CommandList"/> instance with the specified parameters. /// </summary> /// <param name="device">The target <see cref="GraphicsDevice"/> instance to use.</param> /// <param name="d3D12CommandListType">The type of command list to create.</param> public CommandList(GraphicsDevice device, D3D12_COMMAND_LIST_TYPE d3D12CommandListType) { this.device = device; this.d3D12CommandListType = d3D12CommandListType; Unsafe.SkipInit(out this.d3D12GraphicsCommandList); Unsafe.SkipInit(out this.d3D12CommandAllocator); device.GetCommandListAndAllocator( d3D12CommandListType, out *(ID3D12GraphicsCommandList **)Unsafe.AsPointer(ref this.d3D12GraphicsCommandList), out *(ID3D12CommandAllocator **)Unsafe.AsPointer(ref this.d3D12CommandAllocator)); // Set the heap descriptor if the command list is not for copy operations if (d3D12CommandListType is not D3D12_COMMAND_LIST_TYPE_COPY) { device.SetDescriptorHeapForCommandList(this.d3D12GraphicsCommandList); } }
public int CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE type, [NativeTypeName("const IID &")] Guid *riid, [NativeTypeName("void **")] void **ppCommandAllocator) { return(((delegate * unmanaged <ID3D12Device *, D3D12_COMMAND_LIST_TYPE, Guid *, void **, int>)(lpVtbl[9]))((ID3D12Device *)Unsafe.AsPointer(ref this), type, riid, ppCommandAllocator)); }
public int CreateCommandList([NativeTypeName("UINT")] uint nodeMask, D3D12_COMMAND_LIST_TYPE type, [NativeTypeName("ID3D12CommandAllocator *")] ID3D12CommandAllocator *pCommandAllocator, [NativeTypeName("ID3D12PipelineState *")] ID3D12PipelineState *pInitialState, [NativeTypeName("const IID &")] Guid *riid, [NativeTypeName("void **")] void **ppCommandList) { return(((delegate * unmanaged <ID3D12Device *, uint, D3D12_COMMAND_LIST_TYPE, ID3D12CommandAllocator *, ID3D12PipelineState *, Guid *, void **, int>)(lpVtbl[12]))((ID3D12Device *)Unsafe.AsPointer(ref this), nodeMask, type, pCommandAllocator, pInitialState, riid, ppCommandList)); }
public int CreateCommandList1([NativeTypeName("UINT")] uint nodeMask, D3D12_COMMAND_LIST_TYPE type, D3D12_COMMAND_LIST_FLAGS flags, [NativeTypeName("const IID &")] Guid *riid, void **ppCommandList) { return(((delegate * unmanaged <ID3D12Device8 *, uint, D3D12_COMMAND_LIST_TYPE, D3D12_COMMAND_LIST_FLAGS, Guid *, void **, int>)(lpVtbl[51]))((ID3D12Device8 *)Unsafe.AsPointer(ref this), nodeMask, type, flags, riid, ppCommandList)); }
/// <summary> /// Creates a new <see cref="Texture2D{T}"/> instance with the specified parameters. /// </summary> /// <param name="device">The <see cref="ComputeSharp.GraphicsDevice"/> associated with the current instance.</param> /// <param name="height">The height of the texture.</param> /// <param name="width">The width of the texture.</param> /// <param name="resourceType">The resource type for the current texture.</param> /// <param name="allocationMode">The allocation mode to use for the new resource.</param> /// <param name="d3D12FormatSupport">The format support for the current texture type.</param> private protected Texture2D(GraphicsDevice device, int width, int height, ResourceType resourceType, AllocationMode allocationMode, D3D12_FORMAT_SUPPORT1 d3D12FormatSupport) { device.ThrowIfDisposed(); Guard.IsBetweenOrEqualTo(width, 1, FX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(width)); Guard.IsBetweenOrEqualTo(height, 1, FX.D3D12_REQ_TEXTURE2D_U_OR_V_DIMENSION, nameof(height)); if (!device.D3D12Device->IsDxgiFormatSupported(DXGIFormatHelper.GetForType <T>(), d3D12FormatSupport)) { UnsupportedTextureTypeException.ThrowForTexture2D <T>(); } GraphicsDevice = device; if (device.IsCacheCoherentUMA) { this.d3D12Resource = device.D3D12Device->CreateCommittedResource( resourceType, allocationMode, DXGIFormatHelper.GetForType <T>(), (uint)width, (uint)height, true, out this.d3D12ResourceState); } else { this.allocation = device.Allocator->CreateResource( resourceType, allocationMode, DXGIFormatHelper.GetForType <T>(), (uint)width, (uint)height, out this.d3D12ResourceState); this.d3D12Resource = new ComPtr <ID3D12Resource>(this.allocation.Get()->GetResource()); } this.d3D12CommandListType = this.d3D12ResourceState == D3D12_RESOURCE_STATE_COMMON ? D3D12_COMMAND_LIST_TYPE_COPY : D3D12_COMMAND_LIST_TYPE_COMPUTE; device.D3D12Device->GetCopyableFootprint( DXGIFormatHelper.GetForType <T>(), (uint)width, (uint)height, out this.d3D12PlacedSubresourceFootprint, out _, out _); device.RentShaderResourceViewDescriptorHandles(out D3D12CpuDescriptorHandle, out D3D12GpuDescriptorHandle); switch (resourceType) { case ResourceType.ReadOnly: device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType <T>(), D3D12_SRV_DIMENSION_TEXTURE2D, D3D12CpuDescriptorHandle); break; case ResourceType.ReadWrite: device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType <T>(), D3D12_UAV_DIMENSION_TEXTURE2D, D3D12CpuDescriptorHandle); break; } this.d3D12Resource.Get()->SetName(this); }
/// <summary> /// Creates a new <see cref="ID3D12CommandAllocatorPool"/> instance with the specified values. /// </summary> /// <param name="d3D12CommandListType">The command list type to use.</param> public ID3D12CommandAllocatorPool(D3D12_COMMAND_LIST_TYPE d3D12CommandListType) { this.d3D12CommandListType = d3D12CommandListType; this.d3D12CommandAllocatorQueue = new(); }
/// <summary> /// Creates a new <see cref="ID3D12CommandListPool"/> instance with the specified parameters. /// </summary> /// <param name="d3D12CommandListType">The command list type to use.</param> public ID3D12CommandListPool(D3D12_COMMAND_LIST_TYPE d3D12CommandListType) { this.d3D12CommandListType = d3D12CommandListType; this.d3D12CommandListBundleQueue = new Queue <D3D12CommandListBundle>(); }