Skip to content

Commit

Permalink
Fixed bug with enum and method around ID3D12Device.CheckFeatureSuppor…
Browse files Browse the repository at this point in the history
…t and fixed memory for D3DX12SerializeVersionedRootSignature
David Hall committed Jan 16, 2025
1 parent 4904128 commit 507d69e
Showing 3 changed files with 132 additions and 67 deletions.
138 changes: 103 additions & 35 deletions PInvoke/Direct3D12/D3D12.Enum.cs
Original file line number Diff line number Diff line change
@@ -2177,7 +2177,8 @@ public enum D3D12_FEATURE
/// value is D3D12_FEATURE_DATA_D3D12_OPTIONS.
/// </para>
/// </summary>
D3D12_FEATURE_D3D12_OPTIONS,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS))]
D3D12_FEATURE_D3D12_OPTIONS = 0,

/// <summary>
/// <para>Value: 1
@@ -2187,64 +2188,74 @@ public enum D3D12_FEATURE
/// <note>This value has been superseded by the <b>D3D_FEATURE_DATA_ARCHITECTURE1</b> value. If your application targets Windows 10,
/// version 1703 (Creators' Update) or higher, then use the <b>D3D_FEATURE_DATA_ARCHITECTURE1</b> value instead.</note>
/// </summary>
D3D12_FEATURE_ARCHITECTURE,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_ARCHITECTURE))]
D3D12_FEATURE_ARCHITECTURE = 1,

/// <summary>
/// <para>Value: 2 Indicates a query for info about the feature levels supported. The corresponding data structure for this value is D3D12_FEATURE_DATA_FEATURE_LEVELS.</para>
/// </summary>
D3D12_FEATURE_FEATURE_LEVELS,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_FEATURE_LEVELS))]
D3D12_FEATURE_FEATURE_LEVELS = 2,

/// <summary>
/// <para>Value: 3
/// Indicates a query for the resources supported by the current graphics driver for a given format. The corresponding data
/// structure for this value is D3D12_FEATURE_DATA_FORMAT_SUPPORT.
/// </para>
/// </summary>
D3D12_FEATURE_FORMAT_SUPPORT,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_FORMAT_SUPPORT))]
D3D12_FEATURE_FORMAT_SUPPORT = 3,

/// <summary>
/// <para>Value: 4
/// Indicates a query for the image quality levels for a given format and sample count. The corresponding data structure for this
/// value is D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS.
/// </para>
/// </summary>
D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS))]
D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS = 4,

/// <summary>
/// <para>Value: 5 Indicates a query for the DXGI data format. The corresponding data structure for this value is D3D12_FEATURE_DATA_FORMAT_INFO.</para>
/// </summary>
D3D12_FEATURE_FORMAT_INFO,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_FORMAT_INFO))]
D3D12_FEATURE_FORMAT_INFO = 5,

/// <summary>
/// <para>Value: 6
/// Indicates a query for the GPU's virtual address space limitations. The corresponding data structure for this value is D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT.
/// </para>
/// </summary>
D3D12_FEATURE_GPU_VIRTUAL_ADDRESS_SUPPORT,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT))]
D3D12_FEATURE_GPU_VIRTUAL_ADDRESS_SUPPORT = 6,

/// <summary>
/// <para>Value: 7 Indicates a query for the supported shader model. The corresponding data structure for this value is D3D12_FEATURE_DATA_SHADER_MODEL.</para>
/// </summary>
D3D12_FEATURE_SHADER_MODEL,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_SHADER_MODEL))]
D3D12_FEATURE_SHADER_MODEL = 7,

/// <summary>
/// <para>Value: 8
/// Indicates a query for the level of support for HLSL 6.0 wave operations. The corresponding data structure for this value is D3D12_FEATURE_DATA_D3D12_OPTIONS1.
/// </para>
/// </summary>
D3D12_FEATURE_D3D12_OPTIONS1,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS1))]
D3D12_FEATURE_D3D12_OPTIONS1 = 8,

/// <summary>
/// <para>Value: 10
/// Indicates a query for the level of support for protected resource sessions. The corresponding data structure for this value is D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_SUPPORT.
/// </para>
/// </summary>
D3D12_FEATURE_PROTECTED_RESOURCE_SESSION_SUPPORT,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_SUPPORT))]
D3D12_FEATURE_PROTECTED_RESOURCE_SESSION_SUPPORT = 10,

/// <summary>
/// <para>Value: 12 Indicates a query for root signature version support. The corresponding data structure for this value is D3D12_FEATURE_DATA_ROOT_SIGNATURE.</para>
/// </summary>
D3D12_FEATURE_ROOT_SIGNATURE,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_ROOT_SIGNATURE))]
D3D12_FEATURE_ROOT_SIGNATURE = 12,

/// <summary>
/// <para>Value: 16
@@ -2254,80 +2265,91 @@ public enum D3D12_FEATURE
/// <note>This value supersedes the <b>D3D_FEATURE_DATA_ARCHITECTURE</b> value. If your application targets Windows 10, version 1703
/// (Creators' Update) or higher, then use <b>D3D_FEATURE_DATA_ARCHITECTURE1</b>.</note>
/// </summary>
D3D12_FEATURE_ARCHITECTURE1,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_ARCHITECTURE1))]
D3D12_FEATURE_ARCHITECTURE1 = 16,

/// <summary>
/// <para>Value: 18
/// Indicates a query for the level of support for depth-bounds tests and programmable sample positions. The corresponding data
/// structure for this value is D3D12_FEATURE_DATA_D3D12_OPTIONS2.
/// </para>
/// </summary>
D3D12_FEATURE_D3D12_OPTIONS2,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS2))]
D3D12_FEATURE_D3D12_OPTIONS2 = 18,

/// <summary>
/// <para>Value: 19 Indicates a query for the level of support for shader caching. The corresponding data structure for this value is D3D12_FEATURE_DATA_SHADER_CACHE.</para>
/// </summary>
D3D12_FEATURE_SHADER_CACHE,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_SHADER_CACHE))]
D3D12_FEATURE_SHADER_CACHE = 19,

/// <summary>
/// <para>Value: 20
/// Indicates a query for the adapter's support for prioritization of different command queue types. The corresponding data
/// structure for this value is D3D12_FEATURE_DATA_COMMAND_QUEUE_PRIORITY.
/// </para>
/// </summary>
D3D12_FEATURE_COMMAND_QUEUE_PRIORITY,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_COMMAND_QUEUE_PRIORITY))]
D3D12_FEATURE_COMMAND_QUEUE_PRIORITY = 20,

/// <summary>
/// <para>Value: 21
/// Indicates a query for the level of support for timestamp queries, format-casting, immediate write, view instancing, and
/// barycentrics. The corresponding data structure for this value is D3D12_FEATURE_DATA_D3D12_OPTIONS3.
/// </para>
/// </summary>
D3D12_FEATURE_D3D12_OPTIONS3,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS3))]
D3D12_FEATURE_D3D12_OPTIONS3 = 21,

/// <summary>
/// <para>Value: 22
/// Indicates a query for whether or not the adapter supports creating heaps from existing system memory. The corresponding data
/// structure for this value is D3D12_FEATURE_DATA_EXISTING_HEAPS.
/// </para>
/// </summary>
D3D12_FEATURE_EXISTING_HEAPS,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_EXISTING_HEAPS))]
D3D12_FEATURE_EXISTING_HEAPS = 22,

/// <summary>
/// <para>Value: 23
/// Indicates a query for the level of support for 64KB-aligned MSAA textures, cross-API sharing, and native 16-bit shader
/// operations. The corresponding data structure for this value is D3D12_FEATURE_DATA_D3D12_OPTIONS4.
/// </para>
/// </summary>
D3D12_FEATURE_D3D12_OPTIONS4,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS4))]
D3D12_FEATURE_D3D12_OPTIONS4 = 23,

/// <summary>
/// <para>Value: 24
/// Indicates a query for the level of support for heap serialization. The corresponding data structure for this value is D3D12_FEATURE_DATA_SERIALIZATION.
/// </para>
/// </summary>
D3D12_FEATURE_SERIALIZATION,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_SERIALIZATION))]
D3D12_FEATURE_SERIALIZATION = 24,

/// <summary>
/// <para>Value: 25
/// Indicates a query for the level of support for the sharing of resources between different adapters—for example, multiple GPUs.
/// The corresponding data structure for this value is D3D12_FEATURE_DATA_CROSS_NODE.
/// </para>
/// </summary>
D3D12_FEATURE_CROSS_NODE,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_CROSS_NODE))]
D3D12_FEATURE_CROSS_NODE = 25,

/// <summary>
/// <para>Value: 27
/// Starting with Windows 10, version 1809 (10.0; Build 17763), indicates a query for the level of support for render passes, ray
/// tracing, and shader-resource view tier 3 tiled resources. The corresponding data structure for this value is D3D12_FEATURE_DATA_D3D12_OPTIONS5.
/// </para>
/// </summary>
D3D12_FEATURE_D3D12_OPTIONS5,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS5))]
D3D12_FEATURE_D3D12_OPTIONS5 = 27,

/// <summary>
/// <para>Starting with Windows 11 (Build 10.0.22000.194). The corresponding data structure for this value is D3D12_FEATURE_DATA_DISPLAYABLE.</para>
/// </summary>
D3D12_FEATURE_DISPLAYABLE,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_DISPLAYABLE))]
D3D12_FEATURE_DISPLAYABLE = 28,

/// <summary>
/// <para>Value: 30
@@ -2336,12 +2358,14 @@ public enum D3D12_FEATURE
/// </para>
/// <para>For more info, see Variable-rate shading (VRS), and the Direct3D 12 background processing spec.</para>
/// </summary>
D3D12_FEATURE_D3D12_OPTIONS6,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS6))]
D3D12_FEATURE_D3D12_OPTIONS6 = 30,

/// <summary>
/// <para>Value: 31 Indicates a query for the level of support for metacommands. The corresponding data structure for this value is D3D12_FEATURE_DATA_QUERY_META_COMMAND.</para>
/// </summary>
D3D12_FEATURE_QUERY_META_COMMAND,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_QUERY_META_COMMAND))]
D3D12_FEATURE_QUERY_META_COMMAND = 31,

/// <summary>
/// <para>Value: 32
@@ -2350,31 +2374,35 @@ public enum D3D12_FEATURE
/// </para>
/// <para>For more info, see the Mesh shader and Sampler feedback specs.</para>
/// </summary>
D3D12_FEATURE_D3D12_OPTIONS7,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS7))]
D3D12_FEATURE_D3D12_OPTIONS7 = 32,

/// <summary>
/// <para>Value: 33
/// Starting with Windows 10, version 2004 (10.0; Build 19041), indicates a query to retrieve the count of protected resource
/// session types. The corresponding data structure for this value is D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_TYPE_COUNT.
/// </para>
/// </summary>
D3D12_FEATURE_PROTECTED_RESOURCE_SESSION_TYPE_COUNT,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_TYPE_COUNT))]
D3D12_FEATURE_PROTECTED_RESOURCE_SESSION_TYPE_COUNT = 33,

/// <summary>
/// <para>Value: 34
/// Starting with Windows 10, version 2004 (10.0; Build 19041), indicates a query to retrieve the list of protected resource session
/// types. The corresponding data structure for this value is D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_TYPES.
/// </para>
/// </summary>
D3D12_FEATURE_PROTECTED_RESOURCE_SESSION_TYPES,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_PROTECTED_RESOURCE_SESSION_TYPES))]
D3D12_FEATURE_PROTECTED_RESOURCE_SESSION_TYPES = 34,

/// <summary>
/// <para>Value: 36
/// Starting with Windows 11 (Build 10.0.22000.194), indicates whether or not unaligned block-compressed textures are supported. The
/// corresponding data structure for this value is D3D12_FEATURE_DATA_D3D12_OPTIONS8.
/// </para>
/// </summary>
D3D12_FEATURE_D3D12_OPTIONS8,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS8))]
D3D12_FEATURE_D3D12_OPTIONS8 = 36,

/// <summary>
/// <para>Value: 37
@@ -2384,23 +2412,63 @@ public enum D3D12_FEATURE
/// this value is D3D12_FEATURE_DATA_D3D12_OPTIONS9.
/// </para>
/// </summary>
D3D12_FEATURE_D3D12_OPTIONS9,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS9))]
D3D12_FEATURE_D3D12_OPTIONS9 = 37,

/// <summary>
/// <para>
/// Starting with Windows 11 (Build 10.0.22000.194), indicates whether or not the SUM combiner can be used, and whether or not
/// SV_ShadingRate can be set from a mesh shader. The corresponding data structure for this value is D3D12_FEATURE_DATA_D3D12_OPTIONS10.
/// </para>
/// </summary>
D3D12_FEATURE_D3D12_OPTIONS10,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS10))]
D3D12_FEATURE_D3D12_OPTIONS10 = 39,

/// <summary>
/// <para>
/// Starting with Windows 11 (Build 10.0.22000.194), indicates whether or not 64-bit integer atomics on resources in descriptor
/// heaps are supported. The corresponding data structure for this value is D3D12_FEATURE_DATA_D3D12_OPTIONS11.
/// </para>
/// </summary>
D3D12_FEATURE_D3D12_OPTIONS11,
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS11))]
D3D12_FEATURE_D3D12_OPTIONS11 = 40,

/// <summary/>
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS12))]
D3D12_FEATURE_D3D12_OPTIONS12 = 41,

/// <summary/>
[CorrespondingType(typeof(D3D12_FEATURE_DATA_D3D12_OPTIONS13))]
D3D12_FEATURE_D3D12_OPTIONS13 = 42,

/// <summary/>
D3D12_FEATURE_D3D12_OPTIONS14 = 43,

/// <summary/>
D3D12_FEATURE_D3D12_OPTIONS15 = 44,

/// <summary/>
D3D12_FEATURE_D3D12_OPTIONS16 = 45,

/// <summary/>
D3D12_FEATURE_D3D12_OPTIONS17 = 46,

/// <summary/>
D3D12_FEATURE_D3D12_OPTIONS18 = 47,

/// <summary/>
D3D12_FEATURE_D3D12_OPTIONS19 = 48,

/// <summary/>
D3D12_FEATURE_D3D12_OPTIONS20 = 49,

/// <summary/>
D3D12_FEATURE_PREDICATION = 50,

/// <summary/>
D3D12_FEATURE_PLACED_RESOURCE_SUPPORT_INFO = 51,

/// <summary/>
D3D12_FEATURE_HARDWARE_COPY = 52,

/// <summary/>
D3D12_FEATURE_D3D12_OPTIONS21 = 53
}

/// <summary>Specifies fence options.</summary>
16 changes: 10 additions & 6 deletions PInvoke/Direct3D12/D3D12.Interface1.cs
Original file line number Diff line number Diff line change
@@ -5687,7 +5687,7 @@ HRESULT SetResidencyPriority(int NumObjects, [In, MarshalAs(UnmanagedType.LPArra
/// <typeparam name="T">The type of the structure associated with <paramref name="Feature"/>.</typeparam>
/// <param name="device">The <see cref="ID3D12Device"/> instance.</param>
/// <param name="Feature">
/// A constant from the <c>D3D12_FEATURE</c> enumeration describing the feature(s) that you want to query for support.
/// A constant from the <c>D3D12_FEATURE</c> enumeration describing the feature(s) that you want to query for support. If not supplied, it is derived from <typeparamref name="T"/>.
/// </param>
/// <param name="pFeatureSupportData">
/// A reference to a data structure that corresponds to the value of the <i>Feature</i> parameter. To determine the corresponding data
@@ -5717,10 +5717,12 @@ HRESULT SetResidencyPriority(int NumObjects, [In, MarshalAs(UnmanagedType.LPArra
/// </code>
/// </para>
/// </remarks>
public static HRESULT CheckFeatureSupport<T>(this ID3D12Device device, D3D12_FEATURE Feature, ref T pFeatureSupportData) where T : struct
public static HRESULT CheckFeatureSupport<T>(this ID3D12Device device, ref T pFeatureSupportData, D3D12_FEATURE? Feature = null) where T : struct
{
if (!CorrespondingTypeAttribute.CanGet<T, D3D12_FEATURE>(Feature, out var f))
return HRESULT.E_INVALIDARG;
using SafeCoTaskMemStruct<T> mem = new(pFeatureSupportData);
var hr = device.CheckFeatureSupport(Feature, mem, mem.Size);
var hr = device.CheckFeatureSupport(f, mem, mem.Size);
pFeatureSupportData = mem.Value;
return hr;
}
@@ -5729,7 +5731,7 @@ public static HRESULT CheckFeatureSupport<T>(this ID3D12Device device, D3D12_FEA
/// <typeparam name="T">The type of the structure associated with <paramref name="Feature"/>.</typeparam>
/// <param name="device">The <see cref="ID3D12Device"/> instance.</param>
/// <param name="Feature">
/// A constant from the <c>D3D12_FEATURE</c> enumeration describing the feature(s) that you want to query for support.
/// A constant from the <c>D3D12_FEATURE</c> enumeration describing the feature(s) that you want to query for support. If not supplied, it is derived from <typeparamref name="T"/>.
/// </param>
/// <param name="pFeatureSupportData">
/// A reference to a data structure that corresponds to the value of the <i>Feature</i> parameter. To determine the corresponding data
@@ -5759,10 +5761,12 @@ public static HRESULT CheckFeatureSupport<T>(this ID3D12Device device, D3D12_FEA
/// </code>
/// </para>
/// </remarks>
public static HRESULT CheckFeatureSupport<T>(this ID3D12Device device, D3D12_FEATURE Feature, in T? pFeatureSupportData) where T : struct
public static HRESULT CheckFeatureSupport<T>(this ID3D12Device device, in T? pFeatureSupportData, D3D12_FEATURE? Feature = null) where T : struct
{
if (!CorrespondingTypeAttribute.CanGet<T, D3D12_FEATURE>(Feature, out var f))
return HRESULT.E_INVALIDARG;
using SafeCoTaskMemStruct<T> mem = pFeatureSupportData;
return device.CheckFeatureSupport(Feature, mem, mem.Size);
return device.CheckFeatureSupport(f, mem, mem.Size);
}

/// <summary>Creates a command allocator object.</summary>
45 changes: 19 additions & 26 deletions PInvoke/Direct3D12/D3D12.cs
Original file line number Diff line number Diff line change
@@ -2155,32 +2155,32 @@ private static HRESULT D3DX12SerializeVersionedRootSignature(in D3D12_VERSIONED_
HRESULT hr = HRESULT.S_OK;
D3D12_ROOT_SIGNATURE_DESC1 desc_1_1 = pRootSignatureDesc.Desc_1_1;

SizeT ParametersSize = Marshal.SizeOf(typeof(D3D12_ROOT_PARAMETER)) * desc_1_1.NumParameters;
SafeHeapBlock pParameters = (ParametersSize > 0) ? HeapAlloc(GetProcessHeap(), 0, ParametersSize) : SafeHeapBlock.Null;
if (ParametersSize > 0 && pParameters.IsInvalid)
SafeNativeArray<D3D12_ROOT_PARAMETER> pParameters_1_0 = new((int)desc_1_1.NumParameters);
if (desc_1_1.NumParameters > 0 && pParameters_1_0.IsInvalid)
{
hr = HRESULT.E_OUTOFMEMORY;
}

var pParameters_1_0 = pParameters.AsSpan<D3D12_ROOT_PARAMETER>((int)desc_1_1.NumParameters);

if (hr.Succeeded)
{
for (int n = 0; n < desc_1_1.NumParameters; n++)
{
pParameters_1_0[n].ParameterType = desc_1_1.pParameters[n].ParameterType;
pParameters_1_0[n].ShaderVisibility = desc_1_1.pParameters[n].ShaderVisibility;
D3D12_ROOT_PARAMETER p_1_0 = new()
{
ParameterType = desc_1_1.pParameters[n].ParameterType,
ShaderVisibility = desc_1_1.pParameters[n].ShaderVisibility
};

switch (desc_1_1.pParameters[n].ParameterType)
{
case D3D12_ROOT_PARAMETER_TYPE.D3D12_ROOT_PARAMETER_TYPE_32BIT_CONSTANTS:
pParameters_1_0[n].Constants = desc_1_1.pParameters[n].Constants;
p_1_0.Constants = desc_1_1.pParameters[n].Constants;
break;

case D3D12_ROOT_PARAMETER_TYPE.D3D12_ROOT_PARAMETER_TYPE_CBV:
case D3D12_ROOT_PARAMETER_TYPE.D3D12_ROOT_PARAMETER_TYPE_SRV:
case D3D12_ROOT_PARAMETER_TYPE.D3D12_ROOT_PARAMETER_TYPE_UAV:
pParameters_1_0[n].Descriptor = desc_1_1.pParameters[n].Descriptor;
p_1_0.Descriptor = desc_1_1.pParameters[n].Descriptor;
break;

case D3D12_ROOT_PARAMETER_TYPE.D3D12_ROOT_PARAMETER_TYPE_DESCRIPTOR_TABLE:
@@ -2203,7 +2203,7 @@ private static HRESULT D3DX12SerializeVersionedRootSignature(in D3D12_VERSIONED_
}
}

D3D12_ROOT_DESCRIPTOR_TABLE table_1_0 = pParameters_1_0[n].DescriptorTable;
D3D12_ROOT_DESCRIPTOR_TABLE table_1_0 = p_1_0.DescriptorTable;
table_1_0.NumDescriptorRanges = table_1_1.NumDescriptorRanges;
table_1_0.pDescriptorRanges = pDescriptorRanges; // _1_0;
}
@@ -2212,23 +2212,20 @@ private static HRESULT D3DX12SerializeVersionedRootSignature(in D3D12_VERSIONED_
default:
break;
}
pParameters_1_0[n] = p_1_0;
}
}

Span<D3D12_STATIC_SAMPLER_DESC> pStaticSamplers = default;
SafeHeapBlock ppSamplers = SafeHeapBlock.Null;
SafeNativeArray<D3D12_STATIC_SAMPLER_DESC>? pStaticSamplers = null;
if (desc_1_1.NumStaticSamplers > 0 && pRootSignatureDesc.Version == D3D_ROOT_SIGNATURE_VERSION.D3D_ROOT_SIGNATURE_VERSION_1_2)
{
SizeT SamplersSize = Marshal.SizeOf(typeof(D3D12_STATIC_SAMPLER_DESC)) * desc_1_1.NumStaticSamplers;
ppSamplers = HeapAlloc(GetProcessHeap(), 0, SamplersSize);

if (ppSamplers.IsInvalid)
pStaticSamplers = new((int)desc_1_1.NumStaticSamplers);
if (pStaticSamplers.IsInvalid)
{
hr = HRESULT.E_OUTOFMEMORY;
}
else
{
pStaticSamplers = ppSamplers.AsSpan<D3D12_STATIC_SAMPLER_DESC>((int)desc_1_1.NumStaticSamplers);
D3D12_ROOT_SIGNATURE_DESC2 desc_1_2 = pRootSignatureDesc.Desc_1_2;
for (int n = 0; n < desc_1_1.NumStaticSamplers; ++n)
{
@@ -2244,7 +2241,7 @@ private static HRESULT D3DX12SerializeVersionedRootSignature(in D3D12_VERSIONED_

if (hr.Succeeded)
{
D3D12_ROOT_SIGNATURE_DESC desc_1_0 = new(desc_1_1.NumParameters, pParameters, desc_1_1.NumStaticSamplers, pStaticSamplers == default ? (IntPtr)desc_1_1.pStaticSamplers : ppSamplers, desc_1_1.Flags);
D3D12_ROOT_SIGNATURE_DESC desc_1_0 = new(desc_1_1.NumParameters, pParameters_1_0, desc_1_1.NumStaticSamplers, pStaticSamplers ?? (IntPtr)desc_1_1.pStaticSamplers, desc_1_1.Flags);
hr = D3D12SerializeRootSignature(desc_1_0, D3D_ROOT_SIGNATURE_VERSION.D3D_ROOT_SIGNATURE_VERSION_1, out ppBlob, ppErrorBlob);
}

@@ -2268,20 +2265,16 @@ private static HRESULT D3DX12SerializeVersionedRootSignature(in D3D12_VERSIONED_
HRESULT hr = HRESULT.S_OK;
D3D12_ROOT_SIGNATURE_DESC1 desc_1_1 = pRootSignatureDesc.Desc_1_1;

Span<D3D12_STATIC_SAMPLER_DESC> pStaticSamplers = default;
SafeHeapBlock ppStaticSamplers = SafeHeapBlock.Null;
SafeNativeArray<D3D12_STATIC_SAMPLER_DESC>? pStaticSamplers = default;
if (desc_1_1.NumStaticSamplers > 0)
{
SizeT SamplersSize = Marshal.SizeOf(typeof(D3D12_STATIC_SAMPLER_DESC)) * desc_1_1.NumStaticSamplers;
ppStaticSamplers = HeapAlloc(GetProcessHeap(), 0, SamplersSize);

if (ppStaticSamplers.IsInvalid)
pStaticSamplers = new((int)desc_1_1.NumStaticSamplers);
if (pStaticSamplers.IsInvalid)
{
hr = HRESULT.E_OUTOFMEMORY;
}
else
{
pStaticSamplers = ppStaticSamplers.AsSpan<D3D12_STATIC_SAMPLER_DESC>((int)desc_1_1.NumStaticSamplers);
D3D12_ROOT_SIGNATURE_DESC2 desc_1_2 = pRootSignatureDesc.Desc_1_2;
for (int n = 0; n < desc_1_1.NumStaticSamplers; ++n)
{
@@ -2298,7 +2291,7 @@ private static HRESULT D3DX12SerializeVersionedRootSignature(in D3D12_VERSIONED_
if (hr.Succeeded)
{
D3D12_VERSIONED_ROOT_SIGNATURE_DESC desc = new(desc_1_1);
if (pStaticSamplers != default) desc.Desc_1_1.pStaticSamplers = ppStaticSamplers;
if (pStaticSamplers != null) desc.Desc_1_1.pStaticSamplers = pStaticSamplers;
hr = D3D12SerializeVersionedRootSignature(desc, out ppBlob, ppErrorBlob);
}

0 comments on commit 507d69e

Please sign in to comment.