Merge pull request #38 from Sergio0694/feature_vortice-windows

Switched to Vortice.Windows packages
このコミットが含まれているのは:
Sergio Pedri authored and GitHub committed 2019-08-28 13:46:36 +02:00
コミット 3bdd467f04
25ファイル変更
+137 -228

検索条件に一致するファイルはありません

バイナリ
ファイルの表示
バイナリファイルは表示されません。
バイナリ
ファイルの表示
バイナリファイルは表示されません。
バイナリ
ファイルの表示
バイナリファイルは表示されません。
バイナリ
ファイルの表示
バイナリファイルは表示されません。
+3 -3
ファイルの表示
@@ -1,5 +1,5 @@
using System;
using SharpDX.Direct3D12;
using Vortice.DirectX.Direct3D12;
namespace ComputeSharp.Graphics.Buffers.Abstract
{
@@ -28,9 +28,9 @@ namespace ComputeSharp.Graphics.Buffers.Abstract
internal IntPtr MappedResource { get; private set; }
/// <summary>
/// Gets the <see cref="Resource"/> object currently mapped
/// Gets the <see cref="ID3D12Resource"/> object currently mapped
/// </summary>
protected internal Resource? NativeResource { get; set; }
protected internal ID3D12Resource? NativeResource { get; set; }
/// <summary>
/// Gets the <see cref="CpuDescriptorHandle"/> instance for the current resource
+1 -1
ファイルの表示
@@ -2,7 +2,7 @@
using System.Runtime.CompilerServices;
using ComputeSharp.Graphics.Buffers.Enums;
using ComputeSharp.Graphics.Helpers;
using SharpDX.Direct3D12;
using Vortice.DirectX.Direct3D12;
using CommandList = ComputeSharp.Graphics.Commands.CommandList;
namespace ComputeSharp.Graphics.Buffers.Abstract
+5 -5
ファイルの表示
@@ -3,7 +3,7 @@ using System.Diagnostics.Contracts;
using System.Runtime.CompilerServices;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Buffers.Enums;
using SharpDX.Direct3D12;
using Vortice.DirectX.Direct3D12;
namespace ComputeSharp.Graphics.Buffers
{
@@ -112,8 +112,8 @@ namespace ComputeSharp.Graphics.Buffers
ShaderResourceViewDescription description = new ShaderResourceViewDescription
{
Shader4ComponentMapping = 5768,
Dimension = ShaderResourceViewDimension.Buffer,
Buffer = { ElementCount = Size, StructureByteStride = ElementSizeInBytes }
ViewDimension = ShaderResourceViewDimension.Buffer,
Buffer = { NumElements = Size, StructureByteStride = ElementSizeInBytes }
};
GraphicsDevice.NativeDevice.CreateShaderResourceView(NativeResource, description, cpuHandle);
@@ -132,8 +132,8 @@ namespace ComputeSharp.Graphics.Buffers
UnorderedAccessViewDescription description = new UnorderedAccessViewDescription
{
Dimension = UnorderedAccessViewDimension.Buffer,
Buffer = { ElementCount = Size, StructureByteStride = ElementSizeInBytes }
ViewDimension = UnorderedAccessViewDimension.Buffer,
Buffer = { NumElements = Size, StructureByteStride = ElementSizeInBytes }
};
GraphicsDevice.NativeDevice.CreateUnorderedAccessView(NativeResource, null, description, cpuHandle);
+1 -1
ファイルの表示
@@ -7,7 +7,7 @@ using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Buffers.Enums;
using ComputeSharp.Graphics.Helpers;
using SharpDX.Direct3D12;
using Vortice.DirectX.Direct3D12;
using CommandList = ComputeSharp.Graphics.Commands.CommandList;
namespace ComputeSharp
+1 -1
ファイルの表示
@@ -1,5 +1,5 @@
using System;
using SharpDX.Direct3D12;
using Vortice.DirectX.Direct3D12;
namespace ComputeSharp.Graphics.Commands.Abstract
{
+12 -12
ファイルの表示
@@ -2,29 +2,29 @@
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using ComputeSharp.Graphics.Commands.Abstract;
using SharpDX.Direct3D12;
using Vortice.DirectX.Direct3D12;
namespace ComputeSharp.Graphics.Commands
{
/// <summary>
/// A <see langword="class"/> that acts as a pool to get new <see cref="CommandAllocator"/> instances wheen needed
/// A <see langword="class"/> that acts as a pool to get new <see cref="ID3D12CommandAllocator"/> instances wheen needed
/// </summary>
internal sealed class CommandAllocatorPool : CommandController
{
/// <summary>
/// The queue of currently pooled <see cref="CommandAllocator"/> instances
/// The queue of currently pooled <see cref="ID3D12CommandAllocator"/> instances
/// </summary>
private readonly Queue<(CommandAllocator CommandAllocator, long FenceValue)> CommandAllocatorQueue = new Queue<(CommandAllocator, long)>();
private readonly Queue<(ID3D12CommandAllocator CommandAllocator, long FenceValue)> CommandAllocatorQueue = new Queue<(ID3D12CommandAllocator, long)>();
/// <inheritdoc/>
public CommandAllocatorPool(GraphicsDevice device, CommandListType commandListType) : base(device, commandListType) { }
/// <summary>
/// Adds a new <see cref="CommandAllocator"/> item to the internal pool queue
/// Adds a new <see cref="ID3D12CommandAllocator"/> item to the internal pool queue
/// </summary>
/// <param name="commandAllocator">The input <see cref="CommandAllocator"/> to enqueue</param>
/// <param name="fenceValue">The fence value for the input <see cref="CommandAllocator"/></param>
public void Enqueue(CommandAllocator commandAllocator, long fenceValue)
/// <param name="commandAllocator">The input <see cref="ID3D12CommandAllocator"/> to enqueue</param>
/// <param name="fenceValue">The fence value for the input <see cref="ID3D12CommandAllocator"/></param>
public void Enqueue(ID3D12CommandAllocator commandAllocator, long fenceValue)
{
lock (CommandAllocatorQueue)
{
@@ -33,16 +33,16 @@ namespace ComputeSharp.Graphics.Commands
}
/// <summary>
/// Gets a new or reused <see cref="CommandAllocator"/> item to use to issue GPU commands
/// Gets a new or reused <see cref="ID3D12CommandAllocator"/> item to use to issue GPU commands
/// </summary>
[Pure]
public CommandAllocator GetCommandAllocator()
public ID3D12CommandAllocator GetCommandAllocator()
{
lock (CommandAllocatorQueue)
{
if (CommandAllocatorQueue.Count > 0)
{
(CommandAllocator commandAllocator, long fenceValue) = CommandAllocatorQueue.Peek();
(ID3D12CommandAllocator commandAllocator, long fenceValue) = CommandAllocatorQueue.Peek();
long completedValue = CommandListType switch
{
@@ -70,7 +70,7 @@ namespace ComputeSharp.Graphics.Commands
{
lock (CommandAllocatorQueue)
{
foreach ((CommandAllocator commandAllocator, long _) in CommandAllocatorQueue)
foreach ((ID3D12CommandAllocator commandAllocator, long _) in CommandAllocatorQueue)
{
commandAllocator.Dispose();
}
+8 -8
ファイルの表示
@@ -1,7 +1,7 @@
using System;
using ComputeSharp.Graphics.Buffers.Abstract;
using ComputeSharp.Graphics.Commands.Abstract;
using SharpDX.Direct3D12;
using Vortice.DirectX.Direct3D12;
namespace ComputeSharp.Graphics.Commands
{
@@ -22,23 +22,23 @@ namespace ComputeSharp.Graphics.Commands
};
NativeCommandList = GraphicsDevice.NativeDevice.CreateCommandList(CommandListType, CommandAllocator, null);
// Set the heap descriptor if the command list is for copy operations
// Set the heap descriptor if the command list is not for copy operations
if (CommandListType != CommandListType.Copy)
{
NativeCommandList.SetDescriptorHeaps(GraphicsDevice.ShaderResourceViewAllocator.DescriptorHeap);
NativeCommandList.SetDescriptorHeaps(1, new[] { GraphicsDevice.ShaderResourceViewAllocator.DescriptorHeap });
}
}
/// <summary>
/// Gets the <see cref="SharpDX.Direct3D12.CommandAllocator"/> object in use by the current instance
/// Gets the <see cref="ID3D12CommandAllocator"/> object in use by the current instance
/// </summary>
public CommandAllocator CommandAllocator { get; }
public ID3D12CommandAllocator CommandAllocator { get; }
/// <summary>
/// Gets the <see cref="GraphicsCommandList"/> object in use by the current instance
/// Gets the <see cref="ID3D12GraphicsCommandList"/> object in use by the current instance
/// </summary>
public GraphicsCommandList NativeCommandList { get; }
public ID3D12GraphicsCommandList NativeCommandList { get; }
/// <summary>
/// Copies a memory region from one resource to another
@@ -71,7 +71,7 @@ namespace ComputeSharp.Graphics.Commands
public void SetPipelineState(PipelineState pipelineState)
{
NativeCommandList.SetComputeRootSignature(pipelineState.RootSignature);
NativeCommandList.PipelineState = pipelineState.NativePipelineState;
NativeCommandList.SetPipelineState(pipelineState.NativePipelineState);
}
/// <summary>
+6 -12
ファイルの表示
@@ -1,4 +1,4 @@
using SharpDX.Direct3D12;
using Vortice.DirectX.Direct3D12;
namespace ComputeSharp.Graphics.Commands
{
@@ -11,25 +11,19 @@ namespace ComputeSharp.Graphics.Commands
/// Creates a new <see cref="PipelineState"/> instance with the specified parameters
/// </summary>
/// <param name="device">The <see cref="GraphicsDevice"/> to use</param>
/// <param name="rootSignature">The <see cref="SharpDX.Direct3D12.RootSignature"/> value for the current shader</param>
/// <param name="rootSignature">The <see cref="ID3D12RootSignature"/> value for the current shader</param>
/// <param name="computeShader">The bytecode for the compute shader to run</param>
public PipelineState(GraphicsDevice device, RootSignature rootSignature, ShaderBytecode computeShader)
public PipelineState(GraphicsDevice device, ID3D12RootSignature rootSignature, ShaderBytecode computeShader)
{
RootSignaturePointer = rootSignature;
RootSignature = rootSignature;
ComputeShader = computeShader;
RootSignature = RootSignaturePointer;
NativePipelineState = device.NativeDevice.CreateComputePipelineState(this);
}
/// <summary>
/// Gets the <see cref="SharpDX.Direct3D12.RootSignature"/> value for the current shader
/// Gets the <see cref="ID3D12PipelineState"/> instance for the current <see cref="PipelineState"/> object
/// </summary>
public RootSignature RootSignature { get; }
/// <summary>
/// Gets the <see cref="SharpDX.Direct3D12.PipelineState"/> instance for the current <see cref="PipelineState"/> object
/// </summary>
public SharpDX.Direct3D12.PipelineState NativePipelineState { get; }
public ID3D12PipelineState NativePipelineState { get; }
}
}
+1 -1
ファイルの表示
@@ -8,8 +8,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="SharpDX.Direct3D12" Version="4.2.0" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Version="4.6.0-preview8.19405.3" />
<PackageReference Include="Vortice.DirectX.Direct3D12" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
+7 -7
ファイルの表示
@@ -1,5 +1,5 @@
using System;
using SharpDX.Direct3D12;
using Vortice.DirectX.Direct3D12;
namespace ComputeSharp.Graphics
{
@@ -56,14 +56,14 @@ namespace ComputeSharp.Graphics
DescriptorHeap = device.NativeDevice.CreateDescriptorHeap(descriptorHeapDescription);
_RemainingHandles = DescriptorsPerHeap;
_CurrentCpuHandle = DescriptorHeap.CPUDescriptorHandleForHeapStart;
_CurrentGpuHandle = DescriptorHeap.GPUDescriptorHandleForHeapStart;
_CurrentCpuHandle = DescriptorHeap.GetCPUDescriptorHandleForHeapStart();
_CurrentGpuHandle = DescriptorHeap.GetGPUDescriptorHandleForHeapStart();
}
/// <summary>
/// Gets the <see cref="SharpDX.Direct3D12.DescriptorHeap"/> object in use for the current <see cref="DescriptorAllocator"/> instance
/// Gets the <see cref="ID3D12DescriptorHeap"/> object in use for the current <see cref="DescriptorAllocator"/> instance
/// </summary>
public DescriptorHeap DescriptorHeap { get; }
public ID3D12DescriptorHeap DescriptorHeap { get; }
/// <summary>
/// Allocates a new CPU and GPU handle pair to use in a memory buffer
@@ -76,8 +76,8 @@ namespace ComputeSharp.Graphics
if (_RemainingHandles == 0)
{
_RemainingHandles = DescriptorHeap.Description.DescriptorCount;
_CurrentCpuHandle = DescriptorHeap.CPUDescriptorHandleForHeapStart;
_CurrentGpuHandle = DescriptorHeap.GPUDescriptorHandleForHeapStart;
_CurrentCpuHandle = DescriptorHeap.GetCPUDescriptorHandleForHeapStart();
_CurrentGpuHandle = DescriptorHeap.GetGPUDescriptorHandleForHeapStart();
}
CpuDescriptorHandle cpuDescriptorHandle = _CurrentCpuHandle;
+33 -34
ファイルの表示
@@ -1,11 +1,10 @@
using System;
using System.Threading;
using ComputeSharp.Graphics.Commands;
using SharpDX.Direct3D;
using SharpDX.Direct3D12;
using SharpDX.DXGI;
using Vortice.DirectX.Direct3D;
using Vortice.DirectX.Direct3D12;
using Vortice.DirectX.DXGI;
using CommandList = ComputeSharp.Graphics.Commands.CommandList;
using Device = SharpDX.Direct3D12.Device;
namespace ComputeSharp.Graphics
{
@@ -15,9 +14,9 @@ namespace ComputeSharp.Graphics
public sealed class GraphicsDevice : IDisposable
{
/// <summary>
/// Gets the <see cref="SharpDX.Direct3D.FeatureLevel"/> value that needs to be supported by GPUs mapped to a <see cref="GraphicsDevice"/> instance
/// Gets the <see cref="FeatureLevel"/> value that needs to be supported by GPUs mapped to a <see cref="GraphicsDevice"/> instance
/// </summary>
public const FeatureLevel FeatureLevel = SharpDX.Direct3D.FeatureLevel.Level_12_1;
public const FeatureLevel FeatureLevel = Vortice.DirectX.Direct3D.FeatureLevel.Level_12_1;
/// <summary>
/// The <see cref="System.Threading.AutoResetEvent"/> instance used to wait for completion when executing commands
@@ -25,26 +24,26 @@ namespace ComputeSharp.Graphics
private readonly AutoResetEvent AutoResetEvent = new AutoResetEvent(false);
/// <summary>
/// The <see cref="CommandQueue"/> instance to use for compute operations
/// The <see cref="ID3D12CommandQueue"/> instance to use for compute operations
/// </summary>
private readonly CommandQueue NativeComputeCommandQueue;
private readonly ID3D12CommandQueue NativeComputeCommandQueue;
/// <summary>
/// The <see cref="CommandQueue"/> instance to use for copy operations
/// The <see cref="ID3D12CommandQueue"/> instance to use for copy operations
/// </summary>
private readonly CommandQueue NativeCopyCommandQueue;
private readonly ID3D12CommandQueue NativeCopyCommandQueue;
/// <summary>
/// The <see cref="CommandQueue"/> instance to use for direct operations
/// The <see cref="ID3D12CommandQueue"/> instance to use for direct operations
/// </summary>
private readonly CommandQueue NativeDirectCommandQueue;
private readonly ID3D12CommandQueue NativeDirectCommandQueue;
/// <summary>
/// Creates a new <see cref="GraphicsDevice"/> instance for the input <see cref="Device"/>
/// Creates a new <see cref="GraphicsDevice"/> instance for the input <see cref="ID3D12Device"/>
/// </summary>
/// <param name="device">The <see cref="Device"/> to use for the new <see cref="GraphicsDevice"/> instance</param>
/// <param name="device">The <see cref="ID3D12Device"/> to use for the new <see cref="GraphicsDevice"/> instance</param>
/// <param name="description">The available info for the new <see cref="GraphicsDevice"/> instance</param>
public GraphicsDevice(Device device, AdapterDescription description)
public GraphicsDevice(ID3D12Device device, AdapterDescription description)
{
NativeDevice = device;
Description = description;
@@ -58,9 +57,9 @@ namespace ComputeSharp.Graphics
CopyAllocatorPool = new CommandAllocatorPool(this, CommandListType.Copy);
DirectAllocatorPool = new CommandAllocatorPool(this, CommandListType.Direct);
NativeComputeFence = NativeDevice.CreateFence(0, FenceFlags.None);
NativeCopyFence = NativeDevice.CreateFence(0, FenceFlags.None);
NativeDirectFence = NativeDevice.CreateFence(0, FenceFlags.None);
NativeComputeFence = NativeDevice.CreateFence(0);
NativeCopyFence = NativeDevice.CreateFence(0);
NativeDirectFence = NativeDevice.CreateFence(0);
ShaderResourceViewAllocator = new DescriptorAllocator(this);
}
@@ -76,9 +75,9 @@ namespace ComputeSharp.Graphics
public int WavefrontSize { get; }
/// <summary>
/// Gets the <see cref="Device"/> object wrapped by the current instance
/// Gets the <see cref="ID3D12Device"/> object wrapped by the current instance
/// </summary>
internal Device NativeDevice { get; }
internal ID3D12Device NativeDevice { get; }
/// <summary>
/// Gets the <see cref="DescriptorAllocator"/> object for the current instance, used when allocating new buffers
@@ -101,19 +100,19 @@ namespace ComputeSharp.Graphics
internal CommandAllocatorPool DirectAllocatorPool { get; }
/// <summary>
/// Gets the <see cref="Fence"/> instance used for compute operations
/// Gets the <see cref="ID3D12Fence"/> instance used for compute operations
/// </summary>
internal Fence NativeComputeFence { get; }
internal ID3D12Fence NativeComputeFence { get; }
/// <summary>
/// Gets the <see cref="Fence"/> instance used for copy operations
/// Gets the <see cref="ID3D12Fence"/> instance used for copy operations
/// </summary>
internal Fence NativeCopyFence { get; }
internal ID3D12Fence NativeCopyFence { get; }
/// <summary>
/// Gets the <see cref="Fence"/> instance used for direct operations
/// Gets the <see cref="ID3D12Fence"/> instance used for direct operations
/// </summary>
internal Fence NativeDirectFence { get; }
internal ID3D12Fence NativeDirectFence { get; }
/// <summary>
/// Gets the next fence value for compute operations
@@ -131,13 +130,13 @@ namespace ComputeSharp.Graphics
internal long NextDirectFenceValue { get; private set; } = 1;
/// <summary>
/// Creates a <see cref="RootSignature"/> instance from a description
/// Creates a <see cref="ID3D12RootSignature"/> instance from a description
/// </summary>
/// <param name="rootSignatureDescription">A <see cref="RootSignatureDescription"/> instance with the info for the new <see cref="RootSignature"/> object to create</param>
/// <returns>A new <see cref="RootSignature"/> instance to use in a compute shader</returns>
internal RootSignature CreateRootSignature(RootSignatureDescription rootSignatureDescription)
/// <param name="rootSignatureDescription">A <see cref="VersionedRootSignatureDescription"/> instance with the info for the new <see cref="ID3D12RootSignature"/> object to create</param>
/// <returns>A new <see cref="ID3D12RootSignature"/> instance to use in a compute shader</returns>
internal ID3D12RootSignature CreateRootSignature(VersionedRootSignatureDescription rootSignatureDescription)
{
return NativeDevice.CreateRootSignature(rootSignatureDescription.Serialize());
return NativeDevice.CreateRootSignature(rootSignatureDescription);
}
/// <summary>
@@ -146,7 +145,7 @@ namespace ComputeSharp.Graphics
/// <param name="commandList">The input <see cref="CommandList"/> to execute</param>
internal void ExecuteCommandList(CommandList commandList)
{
Fence fence = commandList.CommandListType switch
ID3D12Fence fence = commandList.CommandListType switch
{
CommandListType.Direct => NativeDirectFence,
CommandListType.Compute => NativeComputeFence,
@@ -173,8 +172,8 @@ namespace ComputeSharp.Graphics
private long GetFenceValueForCommandList(CommandList commandList)
{
CommandAllocatorPool commandAllocatorPool;
CommandQueue commandQueue;
Fence fence;
ID3D12CommandQueue commandQueue;
ID3D12Fence fence;
long fenceValue;
switch (commandList.CommandListType)
+22 -20
ファイルの表示
@@ -1,7 +1,8 @@
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using SharpDX.DXGI;
using Device = SharpDX.Direct3D12.Device;
using Vortice.DirectX.Direct3D;
using Vortice.DirectX.Direct3D12;
using Vortice.DirectX.DXGI;
namespace ComputeSharp.Graphics.Helpers
{
@@ -13,28 +14,29 @@ namespace ComputeSharp.Graphics.Helpers
/// <summary>
/// Gets a collection of all the supported devices on the current machine
/// </summary>
/// <returns>The collection of <see cref="Device"/> objects with support for DX12.1</returns>
/// <returns>The collection of <see cref="ID3D12Device"/> objects with support for DX12.1</returns>
[Pure]
public static IReadOnlyList<(Device, AdapterDescription)> QueryAllSupportedDevices()
public static IReadOnlyList<(ID3D12Device, AdapterDescription)> QueryAllSupportedDevices()
{
using Factory factory = new Factory1();
List<(Device, AdapterDescription)> devices = new List<(Device, AdapterDescription)>();
foreach (Adapter adapter in factory.Adapters)
if (!DXGI.CreateDXGIFactory1(out IDXGIFactory1 factory).Success) return new (ID3D12Device, AdapterDescription)[0];
try
{
if (adapter.Description.DedicatedVideoMemory == 0) continue;
try
{
Device device = new Device(adapter, GraphicsDevice.FeatureLevel);
devices.Add((device, adapter.Description));
}
catch
{
// Unsupported device
}
}
List<(ID3D12Device, AdapterDescription)> devices = new List<(ID3D12Device, AdapterDescription)>();
return devices;
foreach (IDXGIAdapter1 adapter in factory.EnumAdapters1())
{
if (adapter.Description.DedicatedVideoMemory == 0) continue;
if (D3D12.D3D12CreateDevice(adapter, FeatureLevel.Level_12_1, out ID3D12Device device).Success)
devices.Add((device, adapter.Description));
}
return devices;
}
finally
{
// Explicit using statement
factory?.Dispose();
}
}
}
}
+1 -9
ファイルの表示
@@ -8,24 +8,16 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DotNetDxc" Version="1.2.0-alpha">
<ExcludeAssets>native</ExcludeAssets>
</PackageReference>
<PackageReference Include="ICSharpCode.Decompiler" Version="5.0.0.5066-preview4" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.3.0-beta2-final" />
<PackageReference Include="Stubble.Core" Version="1.4.12" />
<PackageReference Include="Vortice.Dxc" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ComputeSharp.Graphics\ComputeSharp.Graphics.csproj" />
</ItemGroup>
<ItemGroup>
<Content Include="..\..\lib\win-x64\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Renderer\Templates\ShaderTemplate.mustache">
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
+3 -3
ファイルの表示
@@ -8,7 +8,7 @@ using ComputeSharp.Graphics.Buffers.Extensions;
using ComputeSharp.Shaders.Renderer;
using ComputeSharp.Shaders.Renderer.Models;
using ComputeSharp.Shaders.Translation;
using SharpDX.Direct3D12;
using Vortice.DirectX.Direct3D12;
using CommandList = ComputeSharp.Graphics.Commands.CommandList;
using PipelineState = ComputeSharp.Graphics.Commands.PipelineState;
@@ -95,8 +95,8 @@ namespace ComputeSharp.Shaders
}
// Create the root signature for the pipeline and get the pipeline state
RootSignatureDescription rootSignatureDescription = new RootSignatureDescription(RootSignatureFlags.None, shaderData.Loader.RootParameters);
RootSignature rootSignature = device.CreateRootSignature(rootSignatureDescription);
VersionedRootSignatureDescription rootSignatureDescription = new VersionedRootSignatureDescription(new RootSignatureDescription1(RootSignatureFlags.None, shaderData.Loader.RootParameters));
ID3D12RootSignature rootSignature = device.CreateRootSignature(rootSignatureDescription);
PipelineState pipelineState = new PipelineState(device, rootSignature, shaderData.Bytecode);
// Create the commands list and set the pipeline state
+2 -15
ファイルの表示
@@ -38,16 +38,6 @@ namespace ComputeSharp.Shaders.Translation
/// </summary>
private readonly Dictionary<string, CSharpDecompiler> Decompilers = new Dictionary<string, CSharpDecompiler>();
/// <summary>
/// The available <see cref="PEFile"/> instances for the loaded assemblies
/// </summary>
private readonly IReadOnlyList<PEFile> PEFiles;
/// <summary>
/// The mapping of <see cref="PEFile"/> and <see cref="TypeDefinition"/> values for the discovered <see cref="Type"/> instances
/// </summary>
private readonly Dictionary<Type, (PEFile PEFile, TypeDefinition TypeDefinition)> TypeDefinitions = new Dictionary<Type, (PEFile, TypeDefinition)>();
/// <summary>
/// The incremental <see cref="Compilation"/> instance for the shader assembly
/// </summary>
@@ -80,9 +70,6 @@ namespace ComputeSharp.Shaders.Translation
}).ToArray();
}
// Load and store all the available PEFile instances
PEFiles = assemblyPaths.Select(p => new PEFile(p)).ToArray();
// Ceate an incremental shader assembly with the available references
IEnumerable<PortableExecutableReference> metadataReferences = assemblyPaths.Select(p => MetadataReference.CreateFromFile(p));
_Compilation = CSharpCompilation.Create("ShaderAssembly").WithReferences(metadataReferences);
@@ -211,10 +198,10 @@ namespace ComputeSharp.Shaders.Translation
List<FieldDeclarationSyntax> parsedFields = new List<FieldDeclarationSyntax>();
// Local function to recursively extract all the nested fields
void ParseNestedFields(string source)
void ParseNestedFields(string typeSource)
{
// Find the field declarations
Match match = NestedClosureFieldRegex.Match(source);
Match match = NestedClosureFieldRegex.Match(typeSource);
if (!match.Success) return;
// Load the nested closure type
+7 -55
ファイルの表示
@@ -1,12 +1,12 @@
using System;
using System.Diagnostics.Contracts;
using DotNetDxc;
using SharpDX.Direct3D12;
using Vortice.DirectX.Direct3D12;
using Vortice.Dxc;
namespace ComputeSharp.Shaders.Translation
{
/// <summary>
/// A <see langword="class"/> that uses the <see cref="HlslDxcLib"/> APIs to compile compute shaders
/// A <see langword="class"/> that uses the <see cref="DxcCompiler"/> APIs to compile compute shaders
/// </summary>
internal sealed class ShaderCompiler
{
@@ -15,25 +15,10 @@ namespace ComputeSharp.Shaders.Translation
/// </summary>
public static ShaderCompiler Instance { get; } = new ShaderCompiler();
/// <summary>
/// The <see cref="IDxcCompiler"/> instance to use to create new HLSL shaders
/// </summary>
private readonly IDxcCompiler Compiler;
/// <summary>
/// The <see cref="IDxcLibrary"/> instance to use to create the bytecode for HLSL sources
/// </summary>
private readonly IDxcLibrary Library;
/// <summary>
/// Creates a new <see cref="ShaderCompiler"/> instance
/// </summary>
private ShaderCompiler()
{
HlslDxcLib.DxcCreateInstanceFn = DefaultDxcLib.GetDxcCreateInstanceFn();
Compiler = HlslDxcLib.CreateDxcCompiler();
Library = HlslDxcLib.CreateDxcLibrary();
}
private readonly IDxcLibrary Library = Dxc.CreateDxcLibrary();
/// <summary>
/// Compiles a new HLSL shader from the input source code
@@ -43,53 +28,20 @@ namespace ComputeSharp.Shaders.Translation
[Pure]
public ShaderBytecode CompileShader(string source)
{
const uint CP_UTF16 = 1200;
IDxcBlobEncoding sourceBlob = Library.CreateBlobWithEncodingOnHeapCopy(source, (uint)(source.Length * 2), CP_UTF16);
IDxcOperationResult result = Compiler.Compile(sourceBlob, "", "CSMain", "cs_6_1", new[] { "-Zpr" }, 1, null, 0, Library.CreateIncludeHandler());
var result = DxcCompiler.Compile(DxcShaderStage.ComputeShader, source, "CSMain", string.Empty, new DxcCompilerOptions { ShaderModel = DxcShaderModel.Model6_1 });
// Get the compiled bytecode in case of success
if (result.GetStatus() == 0)
{
IDxcBlob blob = result.GetResult();
byte[] bytecode = GetBytesFromBlob(blob);
byte[] bytecode = Dxc.GetBytesFromBlob(blob);
return bytecode;
}
// Compile error
string resultText = GetStringFromBlob(Library, result.GetErrors());
string resultText = Dxc.GetStringFromBlob(Library, result.GetErrors());
throw new Exception(resultText);
}
/// <summary>
/// Reads the buffer content from an input <see cref="IDxcBlob"/> instance
/// </summary>
/// <param name="blob">The input <see cref="IDxcBlob"/> instance to read data from</param>
/// <returns>The read bytes buffer, as an array</returns>
[Pure]
private static unsafe byte[] GetBytesFromBlob(IDxcBlob blob)
{
byte* pMem = (byte*)blob.GetBufferPointer();
uint size = blob.GetBufferSize();
byte[] result = new byte[size];
new Span<byte>(pMem, (int)size).CopyTo(result.AsSpan());
return result;
}
/// <summary>
/// Reads a <see cref="string"/> value from an input <see cref="IDxcBlob"/> instance
/// </summary>
/// <param name="library">The source <see cref="IDxcLibrary"/> to use to load the data</param>
/// <param name="blob">The input <see cref="IDxcBlob"/> instance to read data from</param>
/// <returns>The resulting <see cref="string"/> read from the input data buffer</returns>
[Pure]
private static unsafe string GetStringFromBlob(IDxcLibrary library, IDxcBlob blob)
{
blob = library.GetBlobAstUf16(blob);
return new string(blob.GetBufferPointer(), 0, (int)(blob.GetBufferSize() / 2));
}
}
}
+10 -10
ファイルの表示
@@ -11,7 +11,7 @@ using ComputeSharp.Shaders.Renderer.Models.Fields.Abstract;
using ComputeSharp.Shaders.Translation.Models;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using SharpDX.Direct3D12;
using Vortice.DirectX.Direct3D12;
#pragma warning disable CS8618 // Non-nullable field is uninitialized
@@ -58,16 +58,16 @@ namespace ComputeSharp.Shaders.Translation
public Type ShaderType { get; }
/// <summary>
/// The <see cref="List{T}"/> of <see cref="DescriptorRange"/> items that are required to load the captured values
/// The <see cref="List{T}"/> of <see cref="DescriptorRange1"/> items that are required to load the captured values
/// </summary>
private readonly List<DescriptorRange> DescriptorRanges = new List<DescriptorRange>();
private readonly List<DescriptorRange1> DescriptorRanges = new List<DescriptorRange1>();
private RootParameter[] _RootParameters;
private RootParameter1[] _RootParameters;
/// <summary>
/// Gets the <see cref="RootParameter"/> array for the current shader
/// Gets the <see cref="RootParameter1"/> array for the current shader
/// </summary>
public RootParameter[] RootParameters => _RootParameters ??= DescriptorRanges.Select(range => new RootParameter(ShaderVisibility.All, range)).ToArray();
public RootParameter1[] RootParameters => _RootParameters ??= DescriptorRanges.Select(range => new RootParameter1(new RootDescriptorTable1(range), ShaderVisibility.All)).ToArray();
/// <summary>
/// The <see cref="List{T}"/> of <see cref="ReadableMember"/> instances mapping the captured buffers in the current shader
@@ -162,7 +162,7 @@ namespace ComputeSharp.Shaders.Translation
if (shaderFields.Any(fieldInfo => fieldInfo.IsStatic)) throw new InvalidOperationException("Empty shader body");
// Descriptor for the buffer for captured scalar/vector variables
DescriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, _ConstantBuffersCount++));
DescriptorRanges.Add(new DescriptorRange1(DescriptorRangeType.ConstantBufferView, 1, _ConstantBuffersCount++));
// Inspect the captured fields
foreach (FieldInfo fieldInfo in shaderFields)
@@ -185,7 +185,7 @@ namespace ComputeSharp.Shaders.Translation
// Constant buffer
if (HlslKnownTypes.IsConstantBufferType(fieldType))
{
DescriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ConstantBufferView, 1, _ConstantBuffersCount));
DescriptorRanges.Add(new DescriptorRange1(DescriptorRangeType.ConstantBufferView, 1, _ConstantBuffersCount));
// Track the buffer field
_BufferMembers.Add((memberInfo, parents));
@@ -196,7 +196,7 @@ namespace ComputeSharp.Shaders.Translation
else if (HlslKnownTypes.IsReadOnlyBufferType(fieldType))
{
// Root parameter for a readonly buffer
DescriptorRanges.Add(new DescriptorRange(DescriptorRangeType.ShaderResourceView, 1, _ReadOnlyBuffersCount));
DescriptorRanges.Add(new DescriptorRange1(DescriptorRangeType.ShaderResourceView, 1, _ReadOnlyBuffersCount));
// Track the buffer field
_BufferMembers.Add((memberInfo, parents));
@@ -207,7 +207,7 @@ namespace ComputeSharp.Shaders.Translation
else if (HlslKnownTypes.IsReadWriteBufferType(fieldType))
{
// Root parameter for a read write buffer
DescriptorRanges.Add(new DescriptorRange(DescriptorRangeType.UnorderedAccessView, 1, _ReadWriteBuffersCount));
DescriptorRanges.Add(new DescriptorRange1(DescriptorRangeType.UnorderedAccessView, 1, _ReadWriteBuffersCount));
// Track the buffer field
_BufferMembers.Add((memberInfo, parents));
+2 -2
ファイルの表示
@@ -17,12 +17,12 @@
<repository type="git" url="https://github.com/Sergio0694/ComputeSharp.git" branch="master" commit="25aaf474ea73096dc7da8086d2b1748d43200436" />
<dependencies>
<dependency id="Microsoft.Windows.SDK.Contracts" version="10.0.18362.2002-preview" />
<dependency id="SharpDX.Direct3D12" version="4.2.0" />
<dependency id="System.Runtime.CompilerServices.Unsafe" version="4.6.0-preview8.19405.3" />
<dependency id="DotNetDxc" version="1.2.0-alpha" />
<dependency id="Vortice.DirectX.Direct3D12" version="1.0.0" />
<dependency id="ICSharpCode.Decompiler" version="5.0.0.5066-preview4" />
<dependency id="Microsoft.CodeAnalysis.CSharp" version="3.3.0-beta2-final" />
<dependency id="Stubble.Core" version="1.4.12" />
<dependency id="Vortice.Dxc" version="1.0.0" />
</dependencies>
</metadata>
</package>
+6 -26
ファイルの表示
@@ -1,7 +1,6 @@
using System;
using System.Diagnostics.Contracts;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace ComputeSharp
@@ -17,7 +16,7 @@ namespace ComputeSharp
/// <param name="array">The input <see cref="Vector2"/> array</param>
/// <returns>A <see cref="Span{T}"/> with items of type <see cref="Float2"/>, mapping the original array</returns>
[Pure]
public static Span<Float2> AsFloat2Span(this Vector2[] array) => array.AsSpan().As<Vector2, Float2>();
public static Span<Float2> AsFloat2Span(this Vector2[] array) => MemoryMarshal.Cast<Vector2, Float2>(array);
/// <summary>
/// Converts a <see cref="Vector2"/> <see cref="Span{T}"/> into a <see cref="Span{T}"/> with items of type <see cref="Float2"/>
@@ -25,7 +24,7 @@ namespace ComputeSharp
/// <param name="span">The input <see cref="Vector2"/> <see cref="Span{T}"/></param>
/// <returns>A <see cref="Span{T}"/> with items of type <see cref="Float2"/>, mapping the original <see cref="Span{T}"/></returns>
[Pure]
public static Span<Float2> AsFloat2Span(this Span<Vector2> span) => span.As<Vector2, Float2>();
public static Span<Float2> AsFloat2Span(this Span<Vector2> span) => MemoryMarshal.Cast<Vector2, Float2>(span);
/// <summary>
/// Converts a <see cref="Vector3"/> array into a <see cref="Span{T}"/> with items of type <see cref="Float3"/>
@@ -33,7 +32,7 @@ namespace ComputeSharp
/// <param name="array">The input <see cref="Vector3"/> array</param>
/// <returns>A <see cref="Span{T}"/> with items of type <see cref="Float3"/>, mapping the original array</returns>
[Pure]
public static Span<Float3> AsFloat3Span(this Vector3[] array) => array.AsSpan().As<Vector3, Float3>();
public static Span<Float3> AsFloat3Span(this Vector3[] array) => MemoryMarshal.Cast<Vector3, Float3>(array);
/// <summary>
/// Converts a <see cref="Vector3"/> <see cref="Span{T}"/> into a <see cref="Span{T}"/> with items of type <see cref="Float3"/>
@@ -41,7 +40,7 @@ namespace ComputeSharp
/// <param name="span">The input <see cref="Vector3"/> <see cref="Span{T}"/></param>
/// <returns>A <see cref="Span{T}"/> with items of type <see cref="Float3"/>, mapping the original <see cref="Span{T}"/></returns>
[Pure]
public static Span<Float3> AsFloat3Span(this Span<Vector3> span) => span.As<Vector3, Float3>();
public static Span<Float3> AsFloat3Span(this Span<Vector3> span) => MemoryMarshal.Cast<Vector3, Float3>(span);
/// <summary>
/// Converts a <see cref="Vector4"/> array into a <see cref="Span{T}"/> with items of type <see cref="Float4"/>
@@ -49,7 +48,7 @@ namespace ComputeSharp
/// <param name="array">The input <see cref="Vector4"/> array</param>
/// <returns>A <see cref="Span{T}"/> with items of type <see cref="Float4"/>, mapping the original array</returns>
[Pure]
public static Span<Float4> AsFloat4Span(this Vector4[] array) => array.AsSpan().As<Vector4, Float4>();
public static Span<Float4> AsFloat4Span(this Vector4[] array) => MemoryMarshal.Cast<Vector4, Float4>(array);
/// <summary>
/// Converts a <see cref="Vector4"/> <see cref="Span{T}"/> into a <see cref="Span{T}"/> with items of type <see cref="Float4"/>
@@ -57,25 +56,6 @@ namespace ComputeSharp
/// <param name="span">The input <see cref="Vector4"/> <see cref="Span{T}"/></param>
/// <returns>A <see cref="Span{T}"/> with items of type <see cref="Float4"/>, mapping the original <see cref="Span{T}"/></returns>
[Pure]
public static Span<Float4> AsFloat4Span(this Span<Vector4> span) => span.As<Vector4, Float4>();
/// <summary>
/// Converts a <see cref="Span{T}"/> value with items of type <typeparamref name="TFrom"/> to one with items of type <typeparamref name="TTo"/>
/// </summary>
/// <typeparam name="TFrom">The type of the input items</typeparam>
/// <typeparam name="TTo">The type of items to convert to</typeparam>
/// <param name="span">The input <see cref="Span{T}"/></param>
/// <returns>A <see cref="Span{T}"/> with items of type <typeparamref name="TTo"/></returns>
[Pure]
private static Span<TTo> As<TFrom, TTo>(this Span<TFrom> span)
where TFrom : unmanaged
where TTo : unmanaged
{
if (span.Length == 0) return Span<TTo>.Empty;
ref TTo r0 = ref Unsafe.As<TFrom, TTo>(ref span.GetPinnableReference());
return MemoryMarshal.CreateSpan(ref r0, span.Length);
}
public static Span<Float4> AsFloat4Span(this Span<Vector4> span) => MemoryMarshal.Cast<Vector4, Float4>(span);
}
}
+3 -3
ファイルの表示
@@ -4,8 +4,8 @@ using System.Diagnostics.Contracts;
using System.Linq;
using ComputeSharp.Graphics;
using ComputeSharp.Graphics.Helpers;
using SharpDX.DXGI;
using Device = SharpDX.Direct3D12.Device;
using Vortice.DirectX.Direct3D12;
using Vortice.DirectX.DXGI;
namespace ComputeSharp
{
@@ -42,6 +42,6 @@ namespace ComputeSharp
public static IEnumerable<GraphicsDevice> EnumerateDevices() => _Devices.Select(device => new GraphicsDevice(device.Device, device.Description));
// The loaded collection of supported devices
private static IReadOnlyList<(Device Device, AdapterDescription Description)> _Devices;
private static IReadOnlyList<(ID3D12Device Device, AdapterDescription Description)> _Devices;
}
}
+3
ファイルの表示
@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
</configuration>