From 3cfec22d8c47343ff982c6d7ea9b5ade09ef0615 Mon Sep 17 00:00:00 2001 From: Sergio Pedri Date: Mon, 23 Nov 2020 22:22:36 +0100 Subject: [PATCH] Updated TerraFX, code refactoring --- nuget.config | 6 ++++++ .../ComputeSharp.Core.csproj | 2 +- .../Extensions/ID3D12DeviceExtensions.cs | 21 ++++++------------- .../Helpers/DeviceHelper.Enumerator.cs | 10 +++------ .../Helpers/DeviceHelper.cs | 14 +++---------- .../Extensions/ID3D12DeviceExtensions.cs | 7 ++----- .../Translation/ShaderCompiler.cs | 6 ++---- 7 files changed, 23 insertions(+), 43 deletions(-) create mode 100644 nuget.config diff --git a/nuget.config b/nuget.config new file mode 100644 index 00000000..817ced4c --- /dev/null +++ b/nuget.config @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/ComputeSharp.Core/ComputeSharp.Core.csproj b/src/ComputeSharp.Core/ComputeSharp.Core.csproj index eb0e9816..52b26454 100644 --- a/src/ComputeSharp.Core/ComputeSharp.Core.csproj +++ b/src/ComputeSharp.Core/ComputeSharp.Core.csproj @@ -7,7 +7,7 @@ - + diff --git a/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs b/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs index a106aeca..910f86b2 100644 --- a/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs +++ b/src/ComputeSharp.Graphics/Extensions/ID3D12DeviceExtensions.cs @@ -39,11 +39,10 @@ namespace ComputeSharp.Graphics.Extensions d3d12CommandQueueDesc.Priority = (int)D3D12_COMMAND_QUEUE_PRIORITY_NORMAL; d3d12CommandQueueDesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE; d3d12CommandQueueDesc.NodeMask = 0; - Guid d3d12CommandQueueDescGuid = FX.IID_ID3D12CommandQueue; d3d12device.CreateCommandQueue( &d3d12CommandQueueDesc, - &d3d12CommandQueueDescGuid, + FX.__uuidof(), d3D12CommandQueue.GetVoidAddressOf()).Assert(); return d3D12CommandQueue.Move(); @@ -59,12 +58,10 @@ namespace ComputeSharp.Graphics.Extensions { using ComPtr d3d12Fence = default; - Guid d3D12FenceGuid = FX.IID_ID3D12Fence; - d3d12device.CreateFence( 0, D3D12_FENCE_FLAG_NONE, - &d3D12FenceGuid, + FX.__uuidof(), d3d12Fence.GetVoidAddressOf()).Assert(); return d3d12Fence.Move(); @@ -86,11 +83,10 @@ namespace ComputeSharp.Graphics.Extensions d3d12DescriptorHeapDesc.NumDescriptors = descriptorsCount; d3d12DescriptorHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE; d3d12DescriptorHeapDesc.NodeMask = 0; - Guid d3d12DescriptorHeapDescGuid = FX.IID_ID3D12DescriptorHeap; d3d12device.CreateDescriptorHeap( &d3d12DescriptorHeapDesc, - &d3d12DescriptorHeapDescGuid, + FX.__uuidof< ID3D12DescriptorHeap>(), d3d12DescriptorHeap.GetVoidAddressOf()).Assert(); return d3d12DescriptorHeap.Move(); @@ -129,7 +125,6 @@ namespace ComputeSharp.Graphics.Extensions d3D12HeapProperties.CreationNodeMask = 1; d3D12HeapProperties.VisibleNodeMask = 1; D3D12_RESOURCE_DESC d3D12ResourceDescription = D3D12_RESOURCE_DESC.Buffer(sizeInBytes, d3D12ResourceFlags); - Guid d3D12ResourceGuid = FX.IID_ID3D12Resource; d3D12Device.CreateCommittedResource( &d3D12HeapProperties, @@ -137,7 +132,7 @@ namespace ComputeSharp.Graphics.Extensions &d3D12ResourceDescription, d3D12ResourceStates, null, - &d3D12ResourceGuid, + FX.__uuidof(), d3D12Resource.GetVoidAddressOf()).Assert(); return d3D12Resource.Move(); @@ -156,11 +151,9 @@ namespace ComputeSharp.Graphics.Extensions { using ComPtr d3D12CommandAllocator = default; - Guid d3D12CommandAllocatorGuid = FX.IID_ID3D12CommandAllocator; - d3d12device.CreateCommandAllocator( d3d12CommandListType, - &d3D12CommandAllocatorGuid, + FX.__uuidof(), d3D12CommandAllocator.GetVoidAddressOf()).Assert(); return d3D12CommandAllocator.Move(); @@ -180,14 +173,12 @@ namespace ComputeSharp.Graphics.Extensions { using ComPtr d3d12GraphicsCommandList = default; - Guid d3D12GraphicsCommandListGuid = FX.IID_ID3D12GraphicsCommandList; - d3d12device.CreateCommandList( 0, d3d12CommandListType, d3D12CommandAllocator, null, - &d3D12GraphicsCommandListGuid, + FX.__uuidof(), d3d12GraphicsCommandList.GetVoidAddressOf()).Assert(); return d3d12GraphicsCommandList.Move(); diff --git a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.Enumerator.cs b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.Enumerator.cs index cb008818..76f73c32 100644 --- a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.Enumerator.cs +++ b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.Enumerator.cs @@ -95,11 +95,9 @@ namespace ComputeSharp.Graphics.Helpers { this.isInitialized = true; - Guid dxgiFactory4Guid = FX.IID_IDXGIFactory4; - fixed (IDXGIFactory4** dxgiFactory4 = this.dxgiFactory4) { - FX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, &dxgiFactory4Guid, (void**)dxgiFactory4).Assert(); + FX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, FX.__uuidof(), (void**)dxgiFactory4).Assert(); } } @@ -124,12 +122,10 @@ namespace ComputeSharp.Graphics.Helpers if (dxgiDescription1.DedicatedVideoMemory == 0) continue; - Guid d3d12DeviceGuid = FX.IID_ID3D12Device; - HRESULT createDeviceResult = FX.D3D12CreateDevice( dxgiAdapter1.Upcast().Get(), D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_12_0, - &d3d12DeviceGuid, + FX.__uuidof(), null); if (FX.SUCCEEDED(createDeviceResult) && @@ -140,7 +136,7 @@ namespace ComputeSharp.Graphics.Helpers FX.D3D12CreateDevice( dxgiAdapter1.Upcast().Get(), D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_12_0, - &d3d12DeviceGuid, + FX.__uuidof(), d3d12device.GetVoidAddressOf()).Assert(); this.graphicsDevice = GetOrCreateDevice(d3d12device.Move(), &dxgiDescription1); diff --git a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs index 2f9dbb7e..67fc7188 100644 --- a/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs +++ b/src/ComputeSharp.Graphics/Helpers/DeviceHelper.cs @@ -70,11 +70,9 @@ namespace ComputeSharp.Graphics.Helpers { using ComPtr dxgiFactory4 = default; - Guid dxgiFactory4Guid = FX.IID_IDXGIFactory4; - EnableDebugMode(); - FX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, &dxgiFactory4Guid, dxgiFactory4.GetVoidAddressOf()).Assert(); + FX.CreateDXGIFactory2(IDXGIFactoryCreationFlags, FX.__uuidof(), dxgiFactory4.GetVoidAddressOf()).Assert(); uint i = 0; @@ -95,12 +93,10 @@ namespace ComputeSharp.Graphics.Helpers if (dxgiDescription1->DedicatedVideoMemory == 0) continue; - Guid d3d12DeviceGuid = FX.IID_ID3D12Device; - HRESULT createDeviceResult = FX.D3D12CreateDevice( dxgiAdapter1.Upcast().Get(), D3D_FEATURE_LEVEL.D3D_FEATURE_LEVEL_12_0, - &d3d12DeviceGuid, + FX.__uuidof(), (void**)d3d12device); if (FX.SUCCEEDED(createDeviceResult)) @@ -129,14 +125,10 @@ namespace ComputeSharp.Graphics.Helpers using ComPtr d3D12Debug = default; using ComPtr d3D12Debug1 = default; - Guid d3D12DebugGuid = FX.IID_ID3D12Debug; - - FX.D3D12GetDebugInterface(&d3D12DebugGuid, d3D12Debug.GetVoidAddressOf()).Assert(); + FX.D3D12GetDebugInterface(FX.__uuidof(), d3D12Debug.GetVoidAddressOf()).Assert(); d3D12Debug.Get()->EnableDebugLayer(); - Guid d3D12Debug1Guid = FX.IID_ID3D12Debug1; - if (FX.SUCCEEDED(d3D12Debug.CopyTo(d3D12Debug1.GetAddressOf()))) { d3D12Debug1.Get()->SetEnableGPUBasedValidation(FX.TRUE); diff --git a/src/ComputeSharp.Shaders/Extensions/ID3D12DeviceExtensions.cs b/src/ComputeSharp.Shaders/Extensions/ID3D12DeviceExtensions.cs index 937ea9c9..7ac82bf7 100644 --- a/src/ComputeSharp.Shaders/Extensions/ID3D12DeviceExtensions.cs +++ b/src/ComputeSharp.Shaders/Extensions/ID3D12DeviceExtensions.cs @@ -50,13 +50,11 @@ namespace ComputeSharp.Shaders.Extensions d3D3BlobError.GetAddressOf()).Assert(); } - Guid d3D12RootSignatureGuid = FX.IID_ID3D12RootSignature; - d3d12device.CreateRootSignature( 0, d3D3Blob.Get()->GetBufferPointer(), d3D3Blob.Get()->GetBufferSize(), - &d3D12RootSignatureGuid, + FX.__uuidof(), d3D12RootSignature.GetVoidAddressOf()).Assert(); return d3D12RootSignature.Move(); @@ -83,11 +81,10 @@ namespace ComputeSharp.Shaders.Extensions d3d12ComputePipelineStateDescription.NodeMask = 0; d3d12ComputePipelineStateDescription.CachedPSO = default; d3d12ComputePipelineStateDescription.Flags = D3D12_PIPELINE_STATE_FLAG_NONE; - Guid d3d12ComputePipelineStateGuid = FX.IID_ID3D12PipelineState; d3d12device.CreateComputePipelineState( &d3d12ComputePipelineStateDescription, - &d3d12ComputePipelineStateGuid, + FX.__uuidof(), d3D12PipelineState.GetVoidAddressOf()).Assert(); return d3D12PipelineState.Move(); diff --git a/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs b/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs index 3c3cdbaf..d6c63147 100644 --- a/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs +++ b/src/ComputeSharp.Shaders/Translation/ShaderCompiler.cs @@ -39,12 +39,10 @@ namespace ComputeSharp.Shaders.Translation using ComPtr dxcIncludeHandler = default; Guid dxcCompilerCLGuid = FX.CLSID_DxcCompiler; - Guid dxcCompilerGuid = FX.IID_IDxcCompiler; Guid dxcLibraryCLGuid = FX.CLSID_DxcLibrary; - Guid dxcLibraryGuid = FX.IID_IDxcLibrary; - FX.DxcCreateInstance(&dxcCompilerCLGuid, &dxcCompilerGuid, dxcCompiler.GetVoidAddressOf()).Assert(); - FX.DxcCreateInstance(&dxcLibraryCLGuid, &dxcLibraryGuid, dxcLibrary.GetVoidAddressOf()).Assert(); + FX.DxcCreateInstance(&dxcCompilerCLGuid, FX.__uuidof(), dxcCompiler.GetVoidAddressOf()).Assert(); + FX.DxcCreateInstance(&dxcLibraryCLGuid, FX.__uuidof(), dxcLibrary.GetVoidAddressOf()).Assert(); dxcLibrary.Get()->CreateIncludeHandler(dxcIncludeHandler.GetAddressOf()).Assert();