Code style improvements
このコミットが含まれているのは:
1 親
145fc5817e
コミット
3c050dbad4
8ファイル変更
+68
-159
検索条件に一致するファイルはありません
@@ -0,0 +1,30 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using HRESULT = System.Int32;
|
||||
|
||||
namespace ComputeSharp.Graphics.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
[DebuggerStepThrough]
|
||||
internal static class HResultExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws a <see cref="Win32Exception"/> if <paramref name="result"/> represents an error.
|
||||
/// </summary>
|
||||
/// <param name="result">The input <see cref="HRESULT"/> to check.</param>
|
||||
/// <exception cref="Win32Exception">Thrown if <paramref name="result"/> represents an error.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void Assert(this HRESULT result)
|
||||
{
|
||||
if (result < 0)
|
||||
{
|
||||
static void Throw(HRESULT result) => throw new Win32Exception(result);
|
||||
|
||||
Throw(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,9 +55,7 @@ namespace ComputeSharp.Graphics.Commands
|
||||
{
|
||||
if (this.d3d12CommandAllocatorQueue.TryDequeue(out *&d3D12CommandAllocator))
|
||||
{
|
||||
int result = d3D12CommandAllocator.Get()->Reset();
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
d3D12CommandAllocator.Get()->Reset().Assert();
|
||||
|
||||
return d3D12CommandAllocator.Move();
|
||||
}
|
||||
|
||||
@@ -35,12 +35,10 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
d3d12CommandQueueDesc.NodeMask = 0;
|
||||
Guid d3d12CommandQueueDescGuid = FX.IID_ID3D12CommandQueue;
|
||||
|
||||
int result = d3d12device.CreateCommandQueue(
|
||||
d3d12device.CreateCommandQueue(
|
||||
&d3d12CommandQueueDesc,
|
||||
&d3d12CommandQueueDescGuid,
|
||||
d3D12CommandQueue.GetVoidAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
d3D12CommandQueue.GetVoidAddressOf()).Assert();
|
||||
|
||||
return d3D12CommandQueue.Move();
|
||||
}
|
||||
@@ -57,13 +55,11 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
|
||||
Guid d3D12FenceGuid = FX.IID_ID3D12Fence;
|
||||
|
||||
int result = d3d12device.CreateFence(
|
||||
d3d12device.CreateFence(
|
||||
0,
|
||||
D3D12_FENCE_FLAG_NONE,
|
||||
&d3D12FenceGuid,
|
||||
d3d12Fence.GetVoidAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
d3d12Fence.GetVoidAddressOf()).Assert();
|
||||
|
||||
return d3d12Fence.Move();
|
||||
}
|
||||
@@ -86,12 +82,10 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
d3d12DescriptorHeapDesc.NodeMask = 0;
|
||||
Guid d3d12DescriptorHeapDescGuid = FX.IID_ID3D12DescriptorHeap;
|
||||
|
||||
int result = d3d12device.CreateDescriptorHeap(
|
||||
d3d12device.CreateDescriptorHeap(
|
||||
&d3d12DescriptorHeapDesc,
|
||||
&d3d12DescriptorHeapDescGuid,
|
||||
d3d12DescriptorHeap.GetVoidAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
d3d12DescriptorHeap.GetVoidAddressOf()).Assert();
|
||||
|
||||
return d3d12DescriptorHeap.Move();
|
||||
}
|
||||
@@ -121,16 +115,14 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Buffer(width, d3D12ResourceFlags);
|
||||
Guid d3D12ResourceGuid = FX.IID_ID3D12Resource;
|
||||
|
||||
int result = d3d12device.CreateCommittedResource(
|
||||
d3d12device.CreateCommittedResource(
|
||||
&d3D12HeapProperties,
|
||||
D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_NONE,
|
||||
&d3D12ResourceDescription,
|
||||
d3D12ResourceStates,
|
||||
null,
|
||||
&d3D12ResourceGuid,
|
||||
d3D12Resource.GetVoidAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
d3D12Resource.GetVoidAddressOf()).Assert();
|
||||
|
||||
return d3D12Resource.Move();
|
||||
}
|
||||
@@ -150,12 +142,10 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
|
||||
Guid d3D12CommandAllocatorGuid = FX.IID_ID3D12CommandAllocator;
|
||||
|
||||
int result = d3d12device.CreateCommandAllocator(
|
||||
d3d12device.CreateCommandAllocator(
|
||||
d3d12CommandListType,
|
||||
&d3D12CommandAllocatorGuid,
|
||||
d3D12CommandAllocator.GetVoidAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
d3D12CommandAllocator.GetVoidAddressOf()).Assert();
|
||||
|
||||
return d3D12CommandAllocator.Move();
|
||||
}
|
||||
@@ -176,15 +166,13 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
|
||||
Guid d3D12GraphicsCommandListGuid = FX.IID_ID3D12GraphicsCommandList;
|
||||
|
||||
int result = d3d12device.CreateCommandList(
|
||||
d3d12device.CreateCommandList(
|
||||
0,
|
||||
d3d12CommandListType,
|
||||
d3D12CommandAllocator,
|
||||
null,
|
||||
&d3D12GraphicsCommandListGuid,
|
||||
d3d12GraphicsCommandList.GetVoidAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
d3d12GraphicsCommandList.GetVoidAddressOf()).Assert();
|
||||
|
||||
return d3d12GraphicsCommandList.Move();
|
||||
}
|
||||
@@ -202,9 +190,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
{
|
||||
TFeature feature;
|
||||
|
||||
int result = d3d12device.CheckFeatureSupport(d3d12feature, &feature, (uint)sizeof(TFeature));
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
d3d12device.CheckFeatureSupport(d3d12feature, &feature, (uint)sizeof(TFeature)).Assert();
|
||||
|
||||
return feature;
|
||||
}
|
||||
|
||||
@@ -19,9 +19,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
{
|
||||
IntPtr ptr;
|
||||
|
||||
int result = d3d12resource.Map(0, null, (void**)&ptr);
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
d3d12resource.Map(0, null, (void**)&ptr).Assert();
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
@@ -178,16 +178,12 @@ namespace ComputeSharp.Graphics
|
||||
// Execute the command list and signal to the target fence
|
||||
d3D12CommandQueue->ExecuteCommandLists(1, commandList.GetD3D12CommandListAddressOf());
|
||||
|
||||
int result = d3D12CommandQueue->Signal(d3D12Fence, d3D12FenceValue);
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
d3D12CommandQueue->Signal(d3D12Fence, d3D12FenceValue).Assert();
|
||||
|
||||
// If the fence value hasn't been reached, wait until the operation completes
|
||||
if (d3D12FenceValue > d3D12Fence->GetCompletedValue())
|
||||
{
|
||||
result = d3D12Fence->SetEventOnCompletion(d3D12FenceValue, default);
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
d3D12Fence->SetEventOnCompletion(d3D12FenceValue, default).Assert();
|
||||
}
|
||||
|
||||
// Enqueue the command allocator pool so that it can be reused later
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Graphics.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// Helper methods to efficiently throw exceptions.
|
||||
/// </summary>
|
||||
[DebuggerStepThrough]
|
||||
internal static class ThrowHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// Throws a <see cref="Win32Exception"/> if <paramref name="result"/> represents an error.
|
||||
/// </summary>
|
||||
/// <param name="result">The input <see cref="HRESULT"/> to check.</param>
|
||||
/// <exception cref="Win32Exception">Thrown if <paramref name="result"/> represents an error.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static void ThrowIfFailed(int result)
|
||||
{
|
||||
if (result < 0)
|
||||
{
|
||||
static void Throw(int result) => throw new Win32Exception(result);
|
||||
|
||||
Throw(result);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a <see cref="Win32Exception"/> if <paramref name="result"/> represents an error.
|
||||
/// </summary>
|
||||
/// <param name="result">The input <see cref="HRESULT"/> to check.</param>
|
||||
/// <param name="d3d3blobError">A <see cref="ID3DBlob"/> pointer representing an error message.</param>
|
||||
/// <exception cref="Win32Exception">Thrown if <paramref name="result"/> represents an error.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void ThrowIfFailed(int result, ID3DBlob* d3d3blobError)
|
||||
{
|
||||
if (result < 0)
|
||||
{
|
||||
// Gets an exception with an optional message with more info.
|
||||
// The input buffer transfers ownership and is disposed on return.
|
||||
static Win32Exception GetException(int result, ID3DBlob* d3d3blobError)
|
||||
{
|
||||
if (d3d3blobError is null) return new Win32Exception(result);
|
||||
|
||||
char* p = (char*)d3d3blobError->GetBufferPointer();
|
||||
int length = checked((int)unchecked(d3d3blobError->GetBufferSize() / sizeof(char)));
|
||||
string message = new(p, 0, length);
|
||||
|
||||
d3d3blobError->Release();
|
||||
|
||||
return new Win32Exception(result, message);
|
||||
}
|
||||
|
||||
static void Throw(int result, ID3DBlob* d3d3blobError) => throw GetException(result, d3d3blobError);
|
||||
|
||||
Throw(result, d3d3blobError);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws a <see cref="Win32Exception"/> if <paramref name="result"/> represents an error.
|
||||
/// </summary>
|
||||
/// <param name="result">The input <see cref="HRESULT"/> to check.</param>
|
||||
/// <param name="d3d3blobError">A <see cref="IDxcBlob"/> pointer representing an error message.</param>
|
||||
/// <exception cref="Win32Exception">Thrown if <paramref name="result"/> represents an error.</exception>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe void ThrowIfFailed(int result, IDxcBlob* d3d3blobError)
|
||||
{
|
||||
ThrowIfFailed(result, (ID3DBlob*)d3d3blobError);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,8 +28,6 @@ namespace ComputeSharp.Shaders.Extensions
|
||||
using ComPtr<ID3DBlob> d3D3BlobError = default;
|
||||
using ComPtr<ID3D12RootSignature> d3D12RootSignature = default;
|
||||
|
||||
int result;
|
||||
|
||||
fixed (D3D12_DESCRIPTOR_RANGE1* d3D12DescriptorRange1 = d3D12DescriptorRanges1)
|
||||
{
|
||||
D3D12_ROOT_PARAMETER1* d3D12RootParameters1 = stackalloc D3D12_ROOT_PARAMETER1[d3D12DescriptorRanges1.Length];
|
||||
@@ -52,24 +50,20 @@ namespace ComputeSharp.Shaders.Extensions
|
||||
|
||||
// Serialize the root signature from the data just computed. When this is done
|
||||
// we just work with the resulting blobs, so the input data can be unpinned.
|
||||
result = FX.D3D12SerializeVersionedRootSignature(
|
||||
FX.D3D12SerializeVersionedRootSignature(
|
||||
&d3d12VersionedRootSignatureDescription,
|
||||
d3D3Blob.GetAddressOf(),
|
||||
d3D3BlobError.GetAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result, d3D3BlobError);
|
||||
d3D3BlobError.GetAddressOf()).Assert();
|
||||
}
|
||||
|
||||
Guid d3D12RootSignatureGuid = FX.IID_ID3D12RootSignature;
|
||||
|
||||
result = d3d12device.CreateRootSignature(
|
||||
d3d12device.CreateRootSignature(
|
||||
0,
|
||||
d3D3Blob.Get()->GetBufferPointer(),
|
||||
d3D3Blob.Get()->GetBufferSize(),
|
||||
&d3D12RootSignatureGuid,
|
||||
d3D12RootSignature.GetVoidAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
d3D12RootSignature.GetVoidAddressOf()).Assert();
|
||||
|
||||
return d3D12RootSignature.Move();
|
||||
}
|
||||
@@ -97,12 +91,10 @@ namespace ComputeSharp.Shaders.Extensions
|
||||
d3d12ComputePipelineStateDescription.Flags = D3D12_PIPELINE_STATE_FLAG_NONE;
|
||||
Guid d3d12ComputePipelineStateGuid = FX.IID_ID3D12PipelineState;
|
||||
|
||||
int result = d3d12device.CreateComputePipelineState(
|
||||
d3d12device.CreateComputePipelineState(
|
||||
&d3d12ComputePipelineStateDescription,
|
||||
&d3d12ComputePipelineStateGuid,
|
||||
d3D12PipelineState.GetVoidAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
d3D12PipelineState.GetVoidAddressOf()).Assert();
|
||||
|
||||
return d3D12PipelineState.Move();
|
||||
}
|
||||
|
||||
@@ -43,17 +43,10 @@ namespace ComputeSharp.Shaders.Translation
|
||||
Guid dxcLibraryCLGuid = FX.CLSID_DxcLibrary;
|
||||
Guid dxcLibraryGuid = FX.IID_IDxcLibrary;
|
||||
|
||||
int result = FX.DxcCreateInstance(&dxcCompilerCLGuid, &dxcCompilerGuid, dxcCompiler.GetVoidAddressOf());
|
||||
FX.DxcCreateInstance(&dxcCompilerCLGuid, &dxcCompilerGuid, dxcCompiler.GetVoidAddressOf()).Assert();
|
||||
FX.DxcCreateInstance(&dxcLibraryCLGuid, &dxcLibraryGuid, dxcLibrary.GetVoidAddressOf()).Assert();
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
|
||||
result = FX.DxcCreateInstance(&dxcLibraryCLGuid, &dxcLibraryGuid, dxcLibrary.GetVoidAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
|
||||
result = dxcLibrary.Get()->CreateIncludeHandler(dxcIncludeHandler.GetAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
dxcLibrary.Get()->CreateIncludeHandler(dxcIncludeHandler.GetAddressOf()).Assert();
|
||||
|
||||
DxcCompiler = dxcCompiler;
|
||||
DxcLibrary = dxcLibrary;
|
||||
@@ -72,14 +65,14 @@ namespace ComputeSharp.Shaders.Translation
|
||||
using ComPtr<IDxcOperationResult> dxcOperationResult = default;
|
||||
using ComPtr<IDxcBlob> dxcBlobBytecode = default;
|
||||
|
||||
int result;
|
||||
|
||||
// Get the encoded blob from the source code
|
||||
fixed (char* p = source)
|
||||
{
|
||||
result = DxcLibrary.Get()->CreateBlobWithEncodingOnHeapCopy(p, (uint)source.Length * 2, 1200, dxcBlobEncoding.GetAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
DxcLibrary.Get()->CreateBlobWithEncodingOnHeapCopy(
|
||||
p,
|
||||
(uint)source.Length * 2,
|
||||
1200,
|
||||
dxcBlobEncoding.GetAddressOf()).Assert();
|
||||
}
|
||||
|
||||
// Try to compile the new compute shader
|
||||
@@ -89,7 +82,7 @@ namespace ComputeSharp.Shaders.Translation
|
||||
{
|
||||
char nullTerminator = '\0';
|
||||
|
||||
result = DxcCompiler.Get()->Compile(
|
||||
DxcCompiler.Get()->Compile(
|
||||
dxcBlobEncoding.Upcast<IDxcBlobEncoding, IDxcBlob>().Get(),
|
||||
(ushort*)&nullTerminator,
|
||||
(ushort*)entryPoint,
|
||||
@@ -99,23 +92,17 @@ namespace ComputeSharp.Shaders.Translation
|
||||
null,
|
||||
0,
|
||||
DxcIncludeHandler.Get(),
|
||||
dxcOperationResult.GetAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
dxcOperationResult.GetAddressOf()).Assert();
|
||||
}
|
||||
|
||||
int status;
|
||||
|
||||
result = dxcOperationResult.Get()->GetStatus(&status);
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
dxcOperationResult.Get()->GetStatus(&status).Assert();
|
||||
|
||||
// The compilation was successful, so we can extract the shader bytecode
|
||||
if (status == 0)
|
||||
{
|
||||
result = dxcOperationResult.Get()->GetResult(dxcBlobBytecode.GetAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
dxcOperationResult.Get()->GetResult(dxcBlobBytecode.GetAddressOf()).Assert();
|
||||
|
||||
return dxcBlobBytecode.Move();
|
||||
}
|
||||
@@ -134,17 +121,13 @@ namespace ComputeSharp.Shaders.Translation
|
||||
{
|
||||
using ComPtr<IDxcBlobEncoding> dxcBlobEncodingError = default;
|
||||
|
||||
int result = dxcOperationResult.Get()->GetErrorBuffer(dxcBlobEncodingError.GetAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
dxcOperationResult.Get()->GetErrorBuffer(dxcBlobEncodingError.GetAddressOf()).Assert();
|
||||
|
||||
using ComPtr<IDxcBlobUtf16> dxcBlobUtf16Error = default;
|
||||
|
||||
result = DxcLibrary.Get()->GetBlobAsUtf16(
|
||||
DxcLibrary.Get()->GetBlobAsUtf16(
|
||||
dxcBlobEncodingError.Upcast<IDxcBlobEncoding, IDxcBlob>().Get(),
|
||||
dxcBlobUtf16Error.Upcast<IDxcBlobUtf16, IDxcBlobEncoding>().GetAddressOf());
|
||||
|
||||
ThrowHelper.ThrowIfFailed(result);
|
||||
dxcBlobUtf16Error.Upcast<IDxcBlobUtf16, IDxcBlobEncoding>().GetAddressOf()).Assert();
|
||||
|
||||
string message = new string(
|
||||
(char*)dxcBlobUtf16Error.Get()->GetStringPointer(),
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする