diff --git a/src/ComputeSharp.Graphics/Commands/CommandList.cs b/src/ComputeSharp.Graphics/Commands/CommandList.cs index 3514e5d4..993ece90 100644 --- a/src/ComputeSharp.Graphics/Commands/CommandList.cs +++ b/src/ComputeSharp.Graphics/Commands/CommandList.cs @@ -57,6 +57,11 @@ namespace ComputeSharp.Graphics.Commands /// public readonly D3D12_COMMAND_LIST_TYPE D3D12CommandListType => this.d3D12CommandListType; + /// + /// Gets the object in use by the current instance. + /// + public readonly ID3D12GraphicsCommandList* D3D12GraphicsCommandList => this.d3D12GraphicsCommandList.Get(); + /// /// Detaches the object in use by the current instance. /// @@ -78,125 +83,6 @@ namespace ComputeSharp.Graphics.Commands return (ID3D12CommandList**)this.d3D12GraphicsCommandList.GetAddressOf(); } - /// - /// Copies a memory region from one resource to another. - /// - /// The destination to write to. - /// The starting offset to write the destination resource from. - /// The source to read from. - /// The starting offset to read the source resource from. - /// The total number of bytes to copy from one resource to another. - public readonly void CopyBufferRegion(ID3D12Resource* d3D12ResourceDestination, ulong destinationOffset, ID3D12Resource* d3D12ResourceSource, ulong sourceOffset, ulong numBytes) - { - this.d3D12GraphicsCommandList.Get()->CopyBufferRegion(d3D12ResourceDestination, destinationOffset, d3D12ResourceSource, sourceOffset, numBytes); - } - - /// - /// Copies a texture memory region from one resource (a buffer) to another (a texture). - /// - /// The destination (a texture) to write to. - /// The horizontal offset in the destination texture. - /// The vertical offset in the destination texture. - /// The depthwise offset in the destination texture. - /// The source (a buffer) to read from. - /// The value describing . - - public readonly void CopyTextureRegion( - ID3D12Resource* d3D12ResourceDestination, - uint x, - uint y, - ushort z, - ID3D12Resource* d3D12ResourceSource, - D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintSource) - { - this.d3D12GraphicsCommandList.Get()->CopyTextureRegion(d3D12ResourceDestination, x, y, z, d3D12ResourceSource, d3D12PlacedSubresourceFootprintSource); - } - - /// - /// Copies a texture memory region from one resource (a texture) to another (a buffer). - /// - /// The destination (a buffer) to write to. - /// The value describing . - /// The source (a texture) to read from. - /// The horizontal offset in the destination texture. - /// The vertical offset in the destination texture. - /// The depthwise offset in the destination texture. - /// The width of the memory area to read from. - /// The height of the memory area to read from. - /// The depth of the memory area to read from. - public readonly void CopyTextureRegion( - ID3D12Resource* d3D12ResourceDestination, - D3D12_PLACED_SUBRESOURCE_FOOTPRINT* d3D12PlacedSubresourceFootprintDestination, - ID3D12Resource* d3D12ResourceSource, - uint x, - uint y, - ushort z, - uint width, - uint height, - ushort depth) - { - this.d3D12GraphicsCommandList.Get()->CopyTextureRegion(d3D12ResourceDestination, d3D12PlacedSubresourceFootprintDestination, d3D12ResourceSource, x, y, z, width, height, depth); - } - - /// - /// Creates a resource barrier to transition a resource to a specific state. - /// - /// The to change state for. - /// The starting value for the transition. - /// The destnation value for the transition. - public readonly void ResourceBarrier( - ID3D12Resource* d3D12Resource, - D3D12_RESOURCE_STATES d3D12ResourceStatesBefore, - D3D12_RESOURCE_STATES d3D12ResourceStatesAfter) - { - D3D12_RESOURCE_BARRIER d3D12ResourceBarrier = D3D12_RESOURCE_BARRIER.InitTransition(d3D12Resource, d3D12ResourceStatesBefore, d3D12ResourceStatesAfter); - - this.d3D12GraphicsCommandList.Get()->ResourceBarrier(1, &d3D12ResourceBarrier); - } - - /// - /// Binds an input constant buffer to the first root parameter. - /// - /// The input buffer with the constant data to bind. - public readonly unsafe void SetComputeRoot32BitConstants(ReadOnlySpan data) - { - fixed (uint* p = data) - { - this.d3D12GraphicsCommandList.Get()->SetComputeRoot32BitConstants(0, (uint)data.Length, p, 0); - } - } - - /// - /// Binds an input value to a specified root parameter. - /// - /// The root parameter index to bind to the input resource. - /// The input value to bind. - public readonly void SetComputeRootDescriptorTable(int rootParameterIndex, D3D12_GPU_DESCRIPTOR_HANDLE d3D12GpuDescriptorHandle) - { - this.d3D12GraphicsCommandList.Get()->SetComputeRootDescriptorTable((uint)rootParameterIndex, d3D12GpuDescriptorHandle); - } - - /// - /// Sets a given object ready to be executed. - /// - /// The input to setup. - public readonly void SetPipelineData(PipelineData pipelineData) - { - this.d3D12GraphicsCommandList.Get()->SetComputeRootSignature(pipelineData.D3D12RootSignature); - this.d3D12GraphicsCommandList.Get()->SetPipelineState(pipelineData.D3D12PipelineState); - } - - /// - /// Dispatches the pending shader using the specified thread group values. - /// - /// The number of thread groups to schedule for the X axis. - /// The number of thread groups to schedule for the Y axis. - /// The number of thread groups to schedule for the Z axis. - public readonly void Dispatch(int threadGroupCountX, int threadGroupCountY, int threadGroupCountZ) - { - this.d3D12GraphicsCommandList.Get()->Dispatch((uint)threadGroupCountX, (uint)threadGroupCountY, (uint)threadGroupCountZ); - } - /// /// Executes the commands in the current commands list, and waits for completion. /// diff --git a/src/ComputeSharp.Graphics/Extensions/ID3D12GraphicsCommandListExtensions.cs b/src/ComputeSharp.Graphics/Extensions/ID3D12GraphicsCommandListExtensions.cs index bdd20afa..517eac57 100644 --- a/src/ComputeSharp.Graphics/Extensions/ID3D12GraphicsCommandListExtensions.cs +++ b/src/ComputeSharp.Graphics/Extensions/ID3D12GraphicsCommandListExtensions.cs @@ -1,4 +1,5 @@ -using TerraFX.Interop; +using System; +using TerraFX.Interop; namespace ComputeSharp.Graphics.Extensions { @@ -65,5 +66,36 @@ namespace ComputeSharp.Graphics.Extensions d3D12GraphicsCommandList.CopyTextureRegion(&d3D12TextureCopyLocationDestination, 0, 0, 0, &d3D12TextureCopyLocationSource, &d3D12Box); } + + /// + /// Creates a resource barrier to transition a resource to a specific state. + /// + /// The instance in use. + /// The to change state for. + /// The starting value for the transition. + /// The destnation value for the transition. + public static void ResourceBarrier( + this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList, + ID3D12Resource* d3D12Resource, + D3D12_RESOURCE_STATES d3D12ResourceStatesBefore, + D3D12_RESOURCE_STATES d3D12ResourceStatesAfter) + { + D3D12_RESOURCE_BARRIER d3D12ResourceBarrier = D3D12_RESOURCE_BARRIER.InitTransition(d3D12Resource, d3D12ResourceStatesBefore, d3D12ResourceStatesAfter); + + d3D12GraphicsCommandList.ResourceBarrier(1, &d3D12ResourceBarrier); + } + + /// + /// Binds an input constant buffer to the first root parameter. + /// + /// The instance in use. + /// The input buffer with the constant data to bind. + public static void SetComputeRoot32BitConstants(this ref ID3D12GraphicsCommandList d3D12GraphicsCommandList, ReadOnlySpan data) + { + fixed (uint* p = data) + { + d3D12GraphicsCommandList.SetComputeRoot32BitConstants(0, (uint)data.Length, p, 0); + } + } } } diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Buffer{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Buffer{T}.cs index 4147ce48..9ae22599 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/Buffer{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/Buffer{T}.cs @@ -71,13 +71,13 @@ namespace ComputeSharp.Resources switch (resourceType) { case ResourceType.Constant: - device.D3D12Device->CreateConstantBufferView(this.d3D12Resource, SizeInBytes, D3D12CpuDescriptorHandle); + device.D3D12Device->CreateConstantBufferView(this.d3D12Resource.Get(), SizeInBytes, D3D12CpuDescriptorHandle); break; case ResourceType.ReadOnly: - device.D3D12Device->CreateShaderResourceView(this.d3D12Resource, (uint)length, elementSizeInBytes, D3D12CpuDescriptorHandle); + device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, D3D12CpuDescriptorHandle); break; case ResourceType.ReadWrite: - device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource, (uint)length, elementSizeInBytes, D3D12CpuDescriptorHandle); + device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), (uint)length, elementSizeInBytes, D3D12CpuDescriptorHandle); break; } } diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/StructuredBuffer{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/StructuredBuffer{T}.cs index 56e90cae..6bbcaa70 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/StructuredBuffer{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/StructuredBuffer{T}.cs @@ -62,7 +62,7 @@ namespace ComputeSharp.Resources using (CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY)) { - copyCommandList.CopyBufferRegion(d3D12Resource.Get(), 0, D3D12Resource, (ulong)byteOffset, (ulong)byteLength); + copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(d3D12Resource.Get(), 0, D3D12Resource, (ulong)byteOffset, (ulong)byteLength); copyCommandList.ExecuteAndWaitForCompletion(); } @@ -108,7 +108,7 @@ namespace ComputeSharp.Resources using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY); - copyCommandList.CopyBufferRegion(destination.D3D12Resource, byteDestinationOffset, D3D12Resource, byteOffset, byteLength); + copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(destination.D3D12Resource, byteDestinationOffset, D3D12Resource, byteOffset, byteLength); copyCommandList.ExecuteAndWaitForCompletion(); } @@ -157,7 +157,7 @@ namespace ComputeSharp.Resources using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY); - copyCommandList.CopyBufferRegion(D3D12Resource, (ulong)byteOffset, d3D12Resource.Get(), 0, (ulong)byteLength); + copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, (ulong)byteOffset, d3D12Resource.Get(), 0, (ulong)byteLength); copyCommandList.ExecuteAndWaitForCompletion(); } } @@ -190,7 +190,7 @@ namespace ComputeSharp.Resources using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY); - copyCommandList.CopyBufferRegion(D3D12Resource, byteOffset, source.D3D12Resource, byteSourceOffset, byteLength); + copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, byteOffset, source.D3D12Resource, byteSourceOffset, byteLength); copyCommandList.ExecuteAndWaitForCompletion(); } @@ -209,7 +209,7 @@ namespace ComputeSharp.Resources // Directly copy the input buffer using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY); - copyCommandList.CopyBufferRegion(D3D12Resource, 0, source.D3D12Resource, 0,(ulong)SizeInBytes); + copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, 0, source.D3D12Resource, 0,(ulong)SizeInBytes); copyCommandList.ExecuteAndWaitForCompletion(); } else CopyFromWithCpuBuffer(source); diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs index ca562175..fe45f36d 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/Texture2D{T}.cs @@ -94,10 +94,10 @@ namespace ComputeSharp.Resources switch (resourceType) { case ResourceType.ReadOnly: - device.D3D12Device->CreateShaderResourceView(this.d3D12Resource, DXGIFormatHelper.GetForType(), D3D12_SRV_DIMENSION_TEXTURE2D, D3D12CpuDescriptorHandle); + device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType(), D3D12_SRV_DIMENSION_TEXTURE2D, D3D12CpuDescriptorHandle); break; case ResourceType.ReadWrite: - device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource, DXGIFormatHelper.GetForType(), D3D12_UAV_DIMENSION_TEXTURE2D, D3D12CpuDescriptorHandle); + device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType(), D3D12_UAV_DIMENSION_TEXTURE2D, D3D12CpuDescriptorHandle); break; } } @@ -159,10 +159,10 @@ namespace ComputeSharp.Resources { if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); } - copyCommandList.CopyTextureRegion( + copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( d3D12Resource.Get(), &d3D12PlacedSubresourceFootprint, D3D12Resource, @@ -175,7 +175,7 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -232,10 +232,10 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); } - copyCommandList.CopyTextureRegion( + copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( destination.D3D12Resource, &d3D12PlacedSubresourceFootprint, D3D12Resource, @@ -248,7 +248,7 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -302,10 +302,10 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); } - copyCommandList.CopyTextureRegion( + copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( D3D12Resource, (uint)x, (uint)y, @@ -315,7 +315,7 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -359,10 +359,10 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); } - copyCommandList.CopyTextureRegion( + copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( D3D12Resource, (uint)x, (uint)y, @@ -372,7 +372,7 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); diff --git a/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs b/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs index 38ab5e29..240f0fcb 100644 --- a/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/Abstract/Texture3D{T}.cs @@ -98,10 +98,10 @@ namespace ComputeSharp.Resources switch (resourceType) { case ResourceType.ReadOnly: - device.D3D12Device->CreateShaderResourceView(this.d3D12Resource, DXGIFormatHelper.GetForType(), D3D12_SRV_DIMENSION_TEXTURE3D, D3D12CpuDescriptorHandle); + device.D3D12Device->CreateShaderResourceView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType(), D3D12_SRV_DIMENSION_TEXTURE3D, D3D12CpuDescriptorHandle); break; case ResourceType.ReadWrite: - device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource, DXGIFormatHelper.GetForType(), D3D12_UAV_DIMENSION_TEXTURE3D, D3D12CpuDescriptorHandle); + device.D3D12Device->CreateUnorderedAccessView(this.d3D12Resource.Get(), DXGIFormatHelper.GetForType(), D3D12_UAV_DIMENSION_TEXTURE3D, D3D12CpuDescriptorHandle); break; } } @@ -173,10 +173,10 @@ namespace ComputeSharp.Resources { if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); } - copyCommandList.CopyTextureRegion( + copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( d3D12Resource.Get(), &d3D12PlacedSubresourceFootprint, D3D12Resource, @@ -189,7 +189,7 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -254,10 +254,10 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_SOURCE); } - copyCommandList.CopyTextureRegion( + copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( destination.D3D12Resource, &d3D12PlacedSubresourceFootprint, D3D12Resource, @@ -270,7 +270,7 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_SOURCE, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -331,10 +331,10 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); } - copyCommandList.CopyTextureRegion( + copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( D3D12Resource, (uint)x, (uint)y, @@ -344,7 +344,7 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); @@ -394,10 +394,10 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, this.d3D12ResourceState, D3D12_RESOURCE_STATE_COPY_DEST); } - copyCommandList.CopyTextureRegion( + copyCommandList.D3D12GraphicsCommandList->CopyTextureRegion( D3D12Resource, (uint)x, (uint)y, @@ -407,7 +407,7 @@ namespace ComputeSharp.Resources if (copyCommandList.D3D12CommandListType == D3D12_COMMAND_LIST_TYPE_COMPUTE) { - copyCommandList.ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); + copyCommandList.D3D12GraphicsCommandList->ResourceBarrier(D3D12Resource, D3D12_RESOURCE_STATE_COPY_DEST, this.d3D12ResourceState); } copyCommandList.ExecuteAndWaitForCompletion(); diff --git a/src/ComputeSharp.Graphics/Resources/ConstantBuffer{T}.cs b/src/ComputeSharp.Graphics/Resources/ConstantBuffer{T}.cs index 5143c260..5274b1f3 100644 --- a/src/ComputeSharp.Graphics/Resources/ConstantBuffer{T}.cs +++ b/src/ComputeSharp.Graphics/Resources/ConstantBuffer{T}.cs @@ -143,7 +143,7 @@ namespace ComputeSharp // Directly copy the input buffer, if possible using CommandList copyCommandList = new(GraphicsDevice, D3D12_COMMAND_LIST_TYPE_COPY); - copyCommandList.CopyBufferRegion(D3D12Resource, 0, source.D3D12Resource, 0,(ulong)SizeInBytes); + copyCommandList.D3D12GraphicsCommandList->CopyBufferRegion(D3D12Resource, 0, source.D3D12Resource, 0,(ulong)SizeInBytes); copyCommandList.ExecuteAndWaitForCompletion(); } else CopyFromWithCpuBuffer(source); diff --git a/src/ComputeSharp.Shaders/ShaderRunner{T}.cs b/src/ComputeSharp.Shaders/ShaderRunner{T}.cs index 5a1198c7..6efd7e14 100644 --- a/src/ComputeSharp.Shaders/ShaderRunner{T}.cs +++ b/src/ComputeSharp.Shaders/ShaderRunner{T}.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Runtime.CompilerServices; using ComputeSharp.Core.Extensions; using ComputeSharp.Graphics.Commands; +using ComputeSharp.Graphics.Extensions; using ComputeSharp.Shaders.Extensions; using ComputeSharp.Shaders.Renderer; using ComputeSharp.Shaders.Translation; @@ -55,7 +56,7 @@ namespace ComputeSharp.Shaders /// The number of threads in each thread group for the Y axis. /// The number of threads in each thread group for the Z axis. /// The input instance representing the compute shader to run. - public static void Run( + public static unsafe void Run( GraphicsDevice device, int x, int y, @@ -93,20 +94,21 @@ namespace ComputeSharp.Shaders // Create the commands list and set the pipeline state using CommandList commandList = new(device, D3D12_COMMAND_LIST_TYPE_COMPUTE); - commandList.SetPipelineData(pipelineData); + commandList.D3D12GraphicsCommandList->SetComputeRootSignature(pipelineData.D3D12RootSignature); + commandList.D3D12GraphicsCommandList->SetPipelineState(pipelineData.D3D12PipelineState); // Extract the dispatch data for the shader invocation using DispatchData dispatchData = shaderData.Loader.GetDispatchData(device, in shader, x, y, z); // Initialize the loop targets and the captured values - commandList.SetComputeRoot32BitConstants(dispatchData.Variables); + commandList.D3D12GraphicsCommandList->SetComputeRoot32BitConstants(dispatchData.Variables); ReadOnlySpan resources = dispatchData.Resources; for (int i = 0; i < resources.Length; i++) { // Load the captured buffers - commandList.SetComputeRootDescriptorTable(i + 1, resources[i]); + commandList.D3D12GraphicsCommandList->SetComputeRootDescriptorTable((uint)i + 1, resources[i]); } // Calculate the dispatch values @@ -116,7 +118,7 @@ namespace ComputeSharp.Shaders groupsZ = Math.DivRem(z, threadsZ, out int modZ) + (modZ == 0 ? 0 : 1); // Dispatch and wait for completion - commandList.Dispatch(groupsX, groupsY, groupsZ); + commandList.D3D12GraphicsCommandList->Dispatch((uint)groupsX, (uint)groupsY, (uint)groupsZ); commandList.ExecuteAndWaitForCompletion(); }