Minor code refactoring
このコミットが含まれているのは:
1 親
ecce9a6e06
コミット
265a5d53b2
3ファイル変更
+25
-18
検索条件に一致するファイルはありません
@@ -1,4 +1,4 @@
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using System;
|
||||
using TerraFX.Interop;
|
||||
|
||||
@@ -50,7 +50,7 @@ namespace ComputeSharp.Graphics
|
||||
/// <param name="device">The <see cref="ID3D12Device"/> instance to use</param>
|
||||
public DescriptorAllocator2(ID3D12Device* device)
|
||||
{
|
||||
D3D12DescriptorHeap = D3D12Helper.CreateDescriptorHeap(device, DescriptorsPerHeap);
|
||||
D3D12DescriptorHeap = device->CreateDescriptorHeap(DescriptorsPerHeap);
|
||||
|
||||
this.allocationLock = new object();
|
||||
this.descriptorSize = device->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE.D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);
|
||||
|
||||
+17
-10
@@ -4,10 +4,10 @@ using System.Runtime.InteropServices;
|
||||
using TerraFX.Interop;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Graphics.Helpers
|
||||
namespace ComputeSharp.Graphics.Extensions
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see langword="class"/> with helper methods to perform some D3D12 operations.
|
||||
/// A <see langword="class"/> with extensions for the <see cref="ID3D12Device"/> type.
|
||||
/// </summary>
|
||||
internal static unsafe class D3D12Helper
|
||||
{
|
||||
@@ -18,7 +18,7 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
/// <param name="type">The type of command queue to create.</param>
|
||||
/// <returns>A pointer to the newly allocated <see cref="ID3D12CommandQueue"/> instance.</returns>
|
||||
/// <exception cref="Exception">Thrown when the creation of the command queue fails.</exception>
|
||||
public static ID3D12CommandQueue* CreateCommandQueue(ID3D12Device* d3d12device, D3D12_COMMAND_LIST_TYPE type)
|
||||
public static ID3D12CommandQueue* CreateCommandQueue(this ref ID3D12Device d3d12device, D3D12_COMMAND_LIST_TYPE type)
|
||||
{
|
||||
D3D12_COMMAND_QUEUE_DESC d3d12CommandQueueDesc;
|
||||
d3d12CommandQueueDesc.Type = D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_COMPUTE;
|
||||
@@ -28,7 +28,7 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
Guid d3d12CommandQueueDescGuid = FX.IID_ID3D12CommandQueue;
|
||||
ID3D12CommandQueue* commandQueue;
|
||||
|
||||
int result = d3d12device->CreateCommandQueue(
|
||||
int result = d3d12device.CreateCommandQueue(
|
||||
&d3d12CommandQueueDesc,
|
||||
&d3d12CommandQueueDescGuid,
|
||||
(void**)&commandQueue);
|
||||
@@ -44,12 +44,12 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
/// <param name="d3d12device">The target <see cref="ID3D12Device"/> to use to create the fence.</param>
|
||||
/// <returns>A pointer to the newly allocated <see cref="ID3D12Fence"/> instance.</returns>
|
||||
/// <exception cref="Exception">Thrown when the creation of the command queue fails.</exception>
|
||||
public static ID3D12Fence* CreateFence(ID3D12Device* d3d12device)
|
||||
public static ID3D12Fence* CreateFence(this ref ID3D12Device d3d12device)
|
||||
{
|
||||
Guid d3D12FenceGuid = FX.IID_ID3D12Fence;
|
||||
ID3D12Fence* d3d12Fence;
|
||||
|
||||
int result = d3d12device->CreateFence(
|
||||
int result = d3d12device.CreateFence(
|
||||
0,
|
||||
D3D12_FENCE_FLAGS.D3D12_FENCE_FLAG_NONE,
|
||||
&d3D12FenceGuid,
|
||||
@@ -67,7 +67,7 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
/// <param name="descriptorsCount">The number of descriptors to allocate.</param>
|
||||
/// <returns>A pointer to the newly allocated <see cref="ID3D12DescriptorHeap"/> instance.</returns>
|
||||
/// <exception cref="Exception">Thrown when the creation of the command queue fails.</exception>
|
||||
public static ID3D12DescriptorHeap* CreateDescriptorHeap(ID3D12Device* d3d12device, uint descriptorsCount)
|
||||
public static ID3D12DescriptorHeap* CreateDescriptorHeap(this ref ID3D12Device d3d12device, uint descriptorsCount)
|
||||
{
|
||||
D3D12_DESCRIPTOR_HEAP_DESC d3d12DescriptorHeapDesc;
|
||||
d3d12DescriptorHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE.D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV;
|
||||
@@ -77,7 +77,7 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
Guid d3d12DescriptorHeapDescGuid = FX.IID_ID3D12DescriptorHeap;
|
||||
ID3D12DescriptorHeap* d3d12DescriptorHeap;
|
||||
|
||||
int result = d3d12device->CreateDescriptorHeap(
|
||||
int result = d3d12device.CreateDescriptorHeap(
|
||||
&d3d12DescriptorHeapDesc,
|
||||
&d3d12DescriptorHeapDescGuid,
|
||||
(void**)&d3d12DescriptorHeap);
|
||||
@@ -87,13 +87,20 @@ namespace ComputeSharp.Graphics.Helpers
|
||||
return d3d12DescriptorHeap;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks the feature support of a given type for a given device.
|
||||
/// </summary>
|
||||
/// <typeparam name="TFeature">The type of feature support data to retrieve.</typeparam>
|
||||
/// <param name="d3d12device">The target <see cref="ID3D12Device"/> to use to check features for.</param>
|
||||
/// <param name="d3d12feature">The type of features to check.</param>
|
||||
/// <returns>A <see typeparamref="TFeature"/> value with the features data.</returns>
|
||||
[Pure]
|
||||
public static unsafe TFeature CheckFeatureSupport<TFeature>(ID3D12Device* d3d12device, D3D12_FEATURE d3d12feature)
|
||||
public static unsafe TFeature CheckFeatureSupport<TFeature>(this ref ID3D12Device d3d12device, D3D12_FEATURE d3d12feature)
|
||||
where TFeature : unmanaged
|
||||
{
|
||||
TFeature feature;
|
||||
|
||||
int result = d3d12device->CheckFeatureSupport(d3d12feature, &feature, (uint)sizeof(TFeature));
|
||||
int result = d3d12device.CheckFeatureSupport(d3d12feature, &feature, (uint)sizeof(TFeature));
|
||||
|
||||
if (FX.FAILED(result)) Marshal.ThrowExceptionForHR(result);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using ComputeSharp.Core.Interop;
|
||||
using ComputeSharp.Graphics.Commands;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using ComputeSharp.Graphics.Extensions;
|
||||
using TerraFX.Interop;
|
||||
|
||||
namespace ComputeSharp.Graphics
|
||||
@@ -68,10 +68,10 @@ namespace ComputeSharp.Graphics
|
||||
internal GraphicsDevice2(ID3D12Device* d3d12device, DXGI_ADAPTER_DESC1* dxgiDescription1)
|
||||
{
|
||||
D3D12Device = d3d12device;
|
||||
D3D12ComputeCommandQueue = D3D12Helper.CreateCommandQueue(d3d12device, D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_COMPUTE);
|
||||
D3D12CopyCommandQueue = D3D12Helper.CreateCommandQueue(d3d12device, D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_COPY);
|
||||
D3D12ComputeFence = D3D12Helper.CreateFence(d3d12device);
|
||||
D3D12CopyFence = D3D12Helper.CreateFence(d3d12device);
|
||||
D3D12ComputeCommandQueue = d3d12device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_COMPUTE);
|
||||
D3D12CopyCommandQueue = d3d12device->CreateCommandQueue(D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_COPY);
|
||||
D3D12ComputeFence = d3d12device->CreateFence();
|
||||
D3D12CopyFence = d3d12device->CreateFence();
|
||||
ComputeCommandAllocatorPool = new CommandAllocatorPool2(D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_COMPUTE);
|
||||
CopyCommandAllocatorPool = new CommandAllocatorPool2(D3D12_COMMAND_LIST_TYPE.D3D12_COMMAND_LIST_TYPE_COPY);
|
||||
ShaderResourceViewDescriptorAllocator = new DescriptorAllocator2(d3d12device);
|
||||
@@ -79,7 +79,7 @@ namespace ComputeSharp.Graphics
|
||||
Name = new string((char*)dxgiDescription1->Description);
|
||||
MemorySize = dxgiDescription1->DedicatedVideoMemory;
|
||||
|
||||
var d3D12Options1Data = D3D12Helper.CheckFeatureSupport<D3D12_FEATURE_DATA_D3D12_OPTIONS1>(d3d12device, D3D12_FEATURE.D3D12_FEATURE_D3D12_OPTIONS1);
|
||||
var d3D12Options1Data = d3d12device->CheckFeatureSupport<D3D12_FEATURE_DATA_D3D12_OPTIONS1>(D3D12_FEATURE.D3D12_FEATURE_D3D12_OPTIONS1);
|
||||
|
||||
ComputeUnits = d3D12Options1Data.TotalLaneCount;
|
||||
WavefrontSize = d3D12Options1Data.WaveLaneCountMin;
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする