Add Allocator initialization to GraphicsDevice
このコミットが含まれているのは:
1 親
3e758e5c0e
コミット
9188404345
7ファイル変更
+53
-14
検索条件に一致するファイルはありません
@@ -43,6 +43,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.Tests.NativeLi
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ComputeSharp.SwapChain", "samples\ComputeSharp.SwapChain\ComputeSharp.SwapChain.csproj", "{E7C9247D-016B-4819-AF9F-0E9B3591E04B}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TerraFX.Interop.D3D12MemoryAllocator", "..\terrafx.interop.d3d12memoryallocator\sources\Interop\D3D12MemoryAllocator\TerraFX.Interop.D3D12MemoryAllocator.csproj", "{DB64E751-125D-44E2-8EA9-F5B085714007}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
samples\ComputeSharp.Sample.Shared\ComputeSharp.Sample.Shared.projitems*{7048deea-0a6f-46a0-b951-b682a8f1cb75}*SharedItemsImports = 5
|
||||
@@ -152,6 +154,14 @@ Global
|
||||
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{E7C9247D-016B-4819-AF9F-0E9B3591E04B}.Release|x64.Build.0 = Release|Any CPU
|
||||
{DB64E751-125D-44E2-8EA9-F5B085714007}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DB64E751-125D-44E2-8EA9-F5B085714007}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DB64E751-125D-44E2-8EA9-F5B085714007}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{DB64E751-125D-44E2-8EA9-F5B085714007}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{DB64E751-125D-44E2-8EA9-F5B085714007}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DB64E751-125D-44E2-8EA9-F5B085714007}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DB64E751-125D-44E2-8EA9-F5B085714007}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{DB64E751-125D-44E2-8EA9-F5B085714007}.Release|x64.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -72,12 +72,18 @@ namespace ComputeSharp
|
||||
/// </summary>
|
||||
private ulong nextD3D12CopyFenceValue = 1;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="Allocator"/> in use associated to the current device.
|
||||
/// </summary>
|
||||
internal Allocator* allocator;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="GraphicsDevice"/> instance for the input <see cref="ID3D12Device"/>.
|
||||
/// </summary>
|
||||
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> to use for the new <see cref="GraphicsDevice"/> instance.</param>
|
||||
/// <param name="dxgiAdapter">The <see cref="IDXGIAdapter"/> that <paramref name="d3D12Device"/> was created from.</param>
|
||||
/// <param name="dxgiDescription1">The available info for the new <see cref="GraphicsDevice"/> instance.</param>
|
||||
internal GraphicsDevice(ComPtr<ID3D12Device> d3D12Device, DXGI_ADAPTER_DESC1* dxgiDescription1)
|
||||
internal GraphicsDevice(ComPtr<ID3D12Device> d3D12Device, IDXGIAdapter* dxgiAdapter, DXGI_ADAPTER_DESC1* dxgiDescription1)
|
||||
{
|
||||
this.d3D12Device = d3D12Device;
|
||||
this.d3D12ComputeCommandQueue = d3D12Device.Get()->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE_COMPUTE);
|
||||
@@ -103,6 +109,15 @@ namespace ComputeSharp
|
||||
var d3D12Architecture1Data = d3D12Device.Get()->CheckFeatureSupport<D3D12_FEATURE_DATA_ARCHITECTURE1>(D3D12_FEATURE_ARCHITECTURE1);
|
||||
|
||||
IsCacheCoherentUMA = d3D12Architecture1Data.CacheCoherentUMA != 0;
|
||||
|
||||
ALLOCATOR_DESC allocatorDesc = default;
|
||||
allocatorDesc.pDevice = d3D12Device.Get();
|
||||
allocatorDesc.pAdapter = dxgiAdapter;
|
||||
|
||||
fixed (Allocator** allocator = &this.allocator)
|
||||
{
|
||||
D3D12MemoryAllocator.CreateAllocator(&allocatorDesc, allocator).Assert();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -317,6 +332,12 @@ namespace ComputeSharp
|
||||
this.copyCommandAllocatorPool.Dispose();
|
||||
this.shaderResourceViewDescriptorAllocator.Dispose();
|
||||
|
||||
if (this.allocator != null)
|
||||
{
|
||||
this.allocator->Release();
|
||||
this.allocator = null;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -141,7 +141,7 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
FX.__uuidof<ID3D12Device>(),
|
||||
d3D12Device.GetVoidAddressOf()).Assert();
|
||||
|
||||
this.graphicsDevice = GetOrCreateDevice(d3D12Device.Move(), &dxgiDescription1);
|
||||
this.graphicsDevice = GetOrCreateDevice(d3D12Device.Move(), (IDXGIAdapter*)dxgiAdapter1.Get(), &dxgiDescription1);
|
||||
this.isCompleted = true;
|
||||
|
||||
return true;
|
||||
@@ -182,7 +182,7 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
FX.__uuidof<ID3D12Device>(),
|
||||
d3D12Device.GetVoidAddressOf()).Assert();
|
||||
|
||||
this.graphicsDevice = GetOrCreateDevice(d3D12Device.Move(), &dxgiDescription1);
|
||||
this.graphicsDevice = GetOrCreateDevice(d3D12Device.Move(), (IDXGIAdapter*)dxgiAdapter1.Get(), &dxgiDescription1);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -25,9 +25,10 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
/// Retrieves a <see cref="GraphicsDevice"/> instance for an <see cref="ID3D12Device"/> object.
|
||||
/// </summary>
|
||||
/// <param name="d3D12Device">The <see cref="ID3D12Device"/> to use to get a <see cref="GraphicsDevice"/> instance.</param>
|
||||
/// <param name="dxgiAdapter">The <see cref="IDXGIAdapter"/> that <paramref name="d3D12Device"/> was created from.</param>
|
||||
/// <param name="dxgiDescription1">The available info for the <see cref="GraphicsDevice"/> instance.</param>
|
||||
/// <returns>A <see cref="GraphicsDevice"/> instance for the input device.</returns>
|
||||
private static unsafe GraphicsDevice GetOrCreateDevice(ComPtr<ID3D12Device> d3D12Device, DXGI_ADAPTER_DESC1* dxgiDescription1)
|
||||
private static unsafe GraphicsDevice GetOrCreateDevice(ComPtr<ID3D12Device> d3D12Device, IDXGIAdapter* dxgiAdapter, DXGI_ADAPTER_DESC1* dxgiDescription1)
|
||||
{
|
||||
lock (DevicesCache)
|
||||
{
|
||||
@@ -35,7 +36,7 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
|
||||
if (!DevicesCache.TryGetValue(luid, out GraphicsDevice? device))
|
||||
{
|
||||
device = new GraphicsDevice(d3D12Device, dxgiDescription1);
|
||||
device = new GraphicsDevice(d3D12Device, dxgiAdapter, dxgiDescription1);
|
||||
|
||||
DevicesCache.Add(luid, device);
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
{
|
||||
DXGI_ADAPTER_DESC1 dxgiDescription1;
|
||||
|
||||
return TryGetDefaultDevice(null, &dxgiDescription1) || TryGetWarpDevice(null, &dxgiDescription1);
|
||||
return TryGetDefaultDevice(null, null, &dxgiDescription1) || TryGetWarpDevice(null, null, &dxgiDescription1);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -46,7 +46,7 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
{
|
||||
DXGI_ADAPTER_DESC1 dxgiDescription1;
|
||||
|
||||
_ = TryGetDefaultDevice(null, &dxgiDescription1) || TryGetWarpDevice(null, &dxgiDescription1);
|
||||
_ = TryGetDefaultDevice(null, null, &dxgiDescription1) || TryGetWarpDevice(null, null, &dxgiDescription1);
|
||||
|
||||
return Luid.FromLUID(dxgiDescription1.AdapterLuid);
|
||||
}
|
||||
@@ -59,13 +59,14 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
public static unsafe GraphicsDevice GetDefaultDevice()
|
||||
{
|
||||
using ComPtr<ID3D12Device> d3D12Device = default;
|
||||
using ComPtr<IDXGIAdapter> dxgiAdapter = default;
|
||||
|
||||
DXGI_ADAPTER_DESC1 dxgiDescription1;
|
||||
|
||||
if (TryGetDefaultDevice(d3D12Device.GetAddressOf(), &dxgiDescription1) ||
|
||||
TryGetWarpDevice(d3D12Device.GetAddressOf(), &dxgiDescription1))
|
||||
if (TryGetDefaultDevice(d3D12Device.GetAddressOf(), dxgiAdapter.GetAddressOf(), &dxgiDescription1) ||
|
||||
TryGetWarpDevice(d3D12Device.GetAddressOf(), dxgiAdapter.GetAddressOf(), &dxgiDescription1))
|
||||
{
|
||||
return GetOrCreateDevice(d3D12Device.Move(), &dxgiDescription1);
|
||||
return GetOrCreateDevice(d3D12Device.Move(), dxgiAdapter.Get(), &dxgiDescription1);
|
||||
}
|
||||
|
||||
return ThrowHelper.ThrowNotSupportedException<GraphicsDevice>("There isn't a supported GPU device on the current machine");
|
||||
@@ -75,9 +76,10 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
/// Tries to check or create a default <see cref="ID3D12Device"/> object.
|
||||
/// </summary>
|
||||
/// <param name="d3D12Device">A pointer to the <see cref="ID3D12Device"/> object to create, or <see langword="null"/>.</param>
|
||||
/// <param name="dxgiAdapter">A pointer to the <see cref="IDXGIAdapter"/> object used to create <paramref name="d3D12Device"/>, or <see langword="null"/>.</param>
|
||||
/// <param name="dxgiDescription1">A pointer to the <see cref="DXGI_ADAPTER_DESC1"/> value for the device found.</param>
|
||||
/// <returns>Whether a default device was found with the requested feature level.</returns>
|
||||
private static unsafe bool TryGetDefaultDevice(ID3D12Device** d3D12Device, DXGI_ADAPTER_DESC1* dxgiDescription1)
|
||||
private static unsafe bool TryGetDefaultDevice(ID3D12Device** d3D12Device, IDXGIAdapter** dxgiAdapter, DXGI_ADAPTER_DESC1* dxgiDescription1)
|
||||
{
|
||||
using ComPtr<IDXGIFactory4> dxgiFactory4 = default;
|
||||
|
||||
@@ -116,6 +118,8 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
|
||||
if (FX.SUCCEEDED(createDeviceResult))
|
||||
{
|
||||
dxgiAdapter1.CopyTo(dxgiAdapter);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -125,9 +129,10 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
/// Tries to check or create a warp <see cref="ID3D12Device"/> object.
|
||||
/// </summary>
|
||||
/// <param name="d3D12Device">A pointer to the <see cref="ID3D12Device"/> object to create, or <see langword="null"/>.</param>
|
||||
/// <param name="dxgiAdapter">A pointer to the <see cref="IDXGIAdapter"/> object used to create <paramref name="d3D12Device"/>, or <see langword="null"/>.</param>
|
||||
/// <param name="dxgiDescription1">A pointer to the <see cref="DXGI_ADAPTER_DESC1"/> value for the device found.</param>
|
||||
/// <returns>Whether a warp device was created successfully.</returns>
|
||||
private static unsafe bool TryGetWarpDevice(ID3D12Device** d3D12Device, DXGI_ADAPTER_DESC1* dxgiDescription1)
|
||||
private static unsafe bool TryGetWarpDevice(ID3D12Device** d3D12Device, IDXGIAdapter** dxgiAdapter, DXGI_ADAPTER_DESC1* dxgiDescription1)
|
||||
{
|
||||
using ComPtr<IDXGIFactory4> dxgiFactory4 = default;
|
||||
|
||||
@@ -147,6 +152,8 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
FX.__uuidof<ID3D12Device>(),
|
||||
(void**)d3D12Device);
|
||||
|
||||
dxgiAdapter1.CopyTo(dxgiAdapter);
|
||||
|
||||
return FX.SUCCEEDED(createDeviceResult);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ using ComputeSharp.__Internals;
|
||||
using ComputeSharp.Shaders.Translation.Models;
|
||||
using TerraFX.Interop;
|
||||
|
||||
#pragma warning disable CS0618
|
||||
#pragma warning disable CS0419, CS0618
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation
|
||||
{
|
||||
|
||||
@@ -10,7 +10,7 @@ using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop;
|
||||
using static TerraFX.Interop.D3D12_DESCRIPTOR_RANGE_TYPE;
|
||||
|
||||
#pragma warning disable CS0618, CS8618
|
||||
#pragma warning disable CS0419, CS0618, CS8618
|
||||
|
||||
namespace ComputeSharp.Shaders.Translation
|
||||
{
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする