Added runtime checks for D3D12_HEAP_FLAGS support
このコミットが含まれているのは:
1 親
44bb962610
コミット
7ae74ea94d
2ファイル変更
+70
-7
検索条件に一致するファイルはありません
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Diagnostics.Contracts;
|
||||
using ComputeSharp.Core.Extensions;
|
||||
using ComputeSharp.Graphics.Helpers;
|
||||
using Microsoft.Toolkit.Diagnostics;
|
||||
using TerraFX.Interop;
|
||||
using static TerraFX.Interop.D3D12_COMMAND_QUEUE_FLAGS;
|
||||
@@ -11,7 +12,6 @@ using static TerraFX.Interop.D3D12_DESCRIPTOR_HEAP_TYPE;
|
||||
using static TerraFX.Interop.D3D12_FEATURE;
|
||||
using static TerraFX.Interop.D3D12_FENCE_FLAGS;
|
||||
using static TerraFX.Interop.D3D12_MEMORY_POOL;
|
||||
using static TerraFX.Interop.D3D12_HEAP_FLAGS;
|
||||
using static TerraFX.Interop.D3D12_HEAP_TYPE;
|
||||
using static TerraFX.Interop.D3D12_RESOURCE_FLAGS;
|
||||
using static TerraFX.Interop.D3D12_RESOURCE_STATES;
|
||||
@@ -112,7 +112,6 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
ulong sizeInBytes,
|
||||
bool isCacheCoherentUMA)
|
||||
{
|
||||
D3D12_HEAP_FLAGS d3D12HeapFlags = allocationMode == AllocationMode.Default ? D3D12_HEAP_FLAG_CREATE_NOT_ZEROED : D3D12_HEAP_FLAG_NONE;
|
||||
(D3D12_HEAP_TYPE d3D12HeapType,
|
||||
D3D12_RESOURCE_FLAGS d3D12ResourceFlags,
|
||||
D3D12_RESOURCE_STATES d3D12ResourceStates) = resourceType switch
|
||||
@@ -148,7 +147,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
|
||||
d3D12Device.CreateCommittedResource(
|
||||
&d3D12HeapProperties,
|
||||
d3D12HeapFlags,
|
||||
D3D12FeatureHelper.GetD3D12HeapFlags(allocationMode),
|
||||
&d3D12ResourceDescription,
|
||||
d3D12ResourceStates,
|
||||
null,
|
||||
@@ -180,7 +179,6 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
bool isCacheCoherentUMA,
|
||||
out D3D12_RESOURCE_STATES d3D12ResourceStates)
|
||||
{
|
||||
D3D12_HEAP_FLAGS d3D12HeapFlags = allocationMode == AllocationMode.Default ? D3D12_HEAP_FLAG_CREATE_NOT_ZEROED : D3D12_HEAP_FLAG_NONE;
|
||||
D3D12_RESOURCE_FLAGS d3D12ResourceFlags;
|
||||
|
||||
(d3D12ResourceFlags, d3D12ResourceStates) = resourceType switch
|
||||
@@ -213,7 +211,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
|
||||
d3D12Device.CreateCommittedResource(
|
||||
&d3D12HeapProperties,
|
||||
d3D12HeapFlags,
|
||||
D3D12FeatureHelper.GetD3D12HeapFlags(allocationMode),
|
||||
&d3D12ResourceDescription,
|
||||
d3D12ResourceStates,
|
||||
null,
|
||||
@@ -247,7 +245,6 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
bool isCacheCoherentUMA,
|
||||
out D3D12_RESOURCE_STATES d3D12ResourceStates)
|
||||
{
|
||||
D3D12_HEAP_FLAGS d3D12HeapFlags = allocationMode == AllocationMode.Default ? D3D12_HEAP_FLAG_CREATE_NOT_ZEROED : D3D12_HEAP_FLAG_NONE;
|
||||
D3D12_RESOURCE_FLAGS d3D12ResourceFlags;
|
||||
|
||||
(d3D12ResourceFlags, d3D12ResourceStates) = resourceType switch
|
||||
@@ -280,7 +277,7 @@ namespace ComputeSharp.Graphics.Extensions
|
||||
|
||||
d3D12Device.CreateCommittedResource(
|
||||
&d3D12HeapProperties,
|
||||
d3D12HeapFlags,
|
||||
D3D12FeatureHelper.GetD3D12HeapFlags(allocationMode),
|
||||
&d3D12ResourceDescription,
|
||||
d3D12ResourceStates,
|
||||
null,
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.Contracts;
|
||||
using System.Runtime.CompilerServices;
|
||||
using TerraFX.Interop;
|
||||
using static TerraFX.Interop.D3D12_FEATURE;
|
||||
using FX = TerraFX.Interop.Windows;
|
||||
|
||||
namespace ComputeSharp.Graphics.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// A helper <see langword="class"/> exposing some runtime or OS dependent D3D12 features.
|
||||
/// </summary>
|
||||
internal static class D3D12FeatureHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// The currently supported <see cref="D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_CREATE_NOT_ZEROED"/> flag (or fallback).
|
||||
/// </summary>
|
||||
private static readonly D3D12_HEAP_FLAGS D3D12_HEAP_FLAG_CREATE_NOT_ZEROED = GetD3D12_HEAP_FLAG_CREATE_NOT_ZEROED();
|
||||
|
||||
/// <summary>
|
||||
/// Gets the <see cref="D3D12_HEAP_FLAGS"/> value for a given <see cref="AllocationMode"/> setting.
|
||||
/// </summary>
|
||||
/// <param name="allocationMode">The allocation mode to use for creating new resources.</param>
|
||||
/// <returns>The <see cref="D3D12_HEAP_FLAGS"/> matching <paramref name="allocationMode"/> that is currently supported</returns>
|
||||
[Pure]
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static D3D12_HEAP_FLAGS GetD3D12HeapFlags(AllocationMode allocationMode)
|
||||
{
|
||||
if (allocationMode == AllocationMode.Default)
|
||||
{
|
||||
return D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
|
||||
}
|
||||
|
||||
return D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_NONE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes the <see cref="D3D12_HEAP_FLAG_CREATE_NOT_ZEROED"/> field.
|
||||
/// </summary>
|
||||
/// <returns>The currently supported <see cref="D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_CREATE_NOT_ZEROED"/> flag.</returns>
|
||||
private static unsafe D3D12_HEAP_FLAGS GetD3D12_HEAP_FLAG_CREATE_NOT_ZEROED()
|
||||
{
|
||||
lock (DeviceHelper.DevicesCache)
|
||||
{
|
||||
foreach (KeyValuePair<Luid, GraphicsDevice> pair in DeviceHelper.DevicesCache)
|
||||
{
|
||||
D3D12_FEATURE_DATA_D3D12_OPTIONS7 d3D12Options7;
|
||||
|
||||
int result = pair.Value.D3D12Device->CheckFeatureSupport(
|
||||
D3D12_FEATURE_D3D12_OPTIONS7,
|
||||
&d3D12Options7,
|
||||
(uint)sizeof(D3D12_FEATURE_DATA_D3D12_OPTIONS7));
|
||||
|
||||
if (result == FX.S_OK)
|
||||
{
|
||||
return D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_CREATE_NOT_ZEROED;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return D3D12_HEAP_FLAGS.D3D12_HEAP_FLAG_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
新しいイシューから参照
ユーザーをブロックする