Lot of Dxgi, D3D11 and D3D12 goodies.

This commit is contained in:
Amer Koleci
2022-09-20 18:04:11 +02:00
parent 2fcf8a7e94
commit 5b96182652
29 changed files with 1978 additions and 30 deletions

View File

@@ -786,6 +786,13 @@ public static class Program
{ "NUM_D3D12_GPU_BASED_VALIDATION_SHADER_PATCH_MODES", "Count" }, { "NUM_D3D12_GPU_BASED_VALIDATION_SHADER_PATCH_MODES", "Count" },
{ "D3D12_MESSAGE_CALLBACK_IGNORE_FILTERS", "IgnoreFilters" }, { "D3D12_MESSAGE_CALLBACK_IGNORE_FILTERS", "IgnoreFilters" },
{ "D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS", "AS" }, { "D3D12_PIPELINE_STATE_SUBOBJECT_TYPE_AS", "AS" },
// D2D1
{ "D2D1_BUFFER_PRECISION_8BPC_UNORM", "Precision8BitUnorm" },
{ "D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB", "Precision8BitUnormSrgb" },
{ "D2D1_BUFFER_PRECISION_16BPC_UNORM", "Precision16BitUnorm" },
{ "D2D1_BUFFER_PRECISION_16BPC_FLOAT", "Precision16BitFloat" },
{ "D2D1_BUFFER_PRECISION_32BPC_FLOAT", "Precision32BitFloat" },
}; };
private static readonly Dictionary<string, bool> s_generatedEnums = new() private static readonly Dictionary<string, bool> s_generatedEnums = new()
@@ -818,17 +825,18 @@ public static class Program
"PF" // D3D_PF_ "PF" // D3D_PF_
}; };
private static readonly Dictionary<string, string> s_typesNameRemap = new() private static readonly Dictionary<string, string> s_typesNameRemap = new()
{ {
// Generated // Generated
{ "DXGI_MAP", "MapFlags" }, { "DXGI_MAP", "MapFlags" },
{ "DXGI_ENUM_MODES", "EnumModesFlags" }, { "DXGI_ENUM_MODES", "EnumModesFlags" },
{ "DXGI_MWA", "WindowAssociationFlags" }, { "DXGI_MWA", "WindowAssociationFlags" },
{ "DXGI_PRESENT", "PresentFlags" },
// D3D11 // D3D11
{ "D3D11_RLDO_FLAGS", "ReportLiveDeviceObjectFlags" }, { "D3D11_RLDO_FLAGS", "ReportLiveDeviceObjectFlags" },
{ "D3D11_1_CREATE_DEVICE_CONTEXT_STATE_FLAG", "CreateDeviceContextStateFlags" }, { "D3D11_1_CREATE_DEVICE_CONTEXT_STATE_FLAG", "CreateDeviceContextStateFlags" },
{ "D3D11_QUERY", "QueryType" },
// D3D12 // D3D12
{ "D3D12_RLDO_FLAGS", "ReportLiveDeviceObjectFlags" }, { "D3D12_RLDO_FLAGS", "ReportLiveDeviceObjectFlags" },
@@ -868,10 +876,19 @@ public static class Program
{ "D3D11_TEXTURE2D_DESC::BindFlags", "D3D11_BIND_FLAG" }, { "D3D11_TEXTURE2D_DESC::BindFlags", "D3D11_BIND_FLAG" },
{ "D3D11_TEXTURE2D_DESC::CPUAccessFlags", "D3D11_CPU_ACCESS_FLAG" }, { "D3D11_TEXTURE2D_DESC::CPUAccessFlags", "D3D11_CPU_ACCESS_FLAG" },
{ "D3D11_TEXTURE2D_DESC::MiscFlags", "D3D11_RESOURCE_MISC_FLAG" }, { "D3D11_TEXTURE2D_DESC::MiscFlags", "D3D11_RESOURCE_MISC_FLAG" },
{ "D3D11_TEXTURE2D_DESC1::BindFlags", "D3D11_BIND_FLAG" },
{ "D3D11_TEXTURE2D_DESC1::CPUAccessFlags", "D3D11_CPU_ACCESS_FLAG" },
{ "D3D11_TEXTURE2D_DESC1::MiscFlags", "D3D11_RESOURCE_MISC_FLAG" },
{ "D3D11_TEXTURE3D_DESC::BindFlags", "D3D11_BIND_FLAG" }, { "D3D11_TEXTURE3D_DESC::BindFlags", "D3D11_BIND_FLAG" },
{ "D3D11_TEXTURE3D_DESC::CPUAccessFlags", "D3D11_CPU_ACCESS_FLAG" }, { "D3D11_TEXTURE3D_DESC::CPUAccessFlags", "D3D11_CPU_ACCESS_FLAG" },
{ "D3D11_TEXTURE3D_DESC::MiscFlags", "D3D11_RESOURCE_MISC_FLAG" }, { "D3D11_TEXTURE3D_DESC::MiscFlags", "D3D11_RESOURCE_MISC_FLAG" },
{ "D3D11_TEXTURE3D_DESC1::BindFlags", "D3D11_BIND_FLAG" },
{ "D3D11_TEXTURE3D_DESC1::CPUAccessFlags", "D3D11_CPU_ACCESS_FLAG" },
{ "D3D11_TEXTURE3D_DESC1::MiscFlags", "D3D11_RESOURCE_MISC_FLAG" },
{ "D3D11_QUERY_DESC::MiscFlags", "D3D11_QUERY_MISC_FLAG" },
{ "D3D11_QUERY_DESC1::MiscFlags", "D3D11_QUERY_MISC_FLAG" },
{ "D3D11_FEATURE_DATA_FORMAT_SUPPORT::OutFormatSupport", "D3D11_FORMAT_SUPPORT" }, { "D3D11_FEATURE_DATA_FORMAT_SUPPORT::OutFormatSupport", "D3D11_FORMAT_SUPPORT" },
{ "D3D11_FEATURE_DATA_FORMAT_SUPPORT2::OutFormatSupport2", "D3D11_FORMAT_SUPPORT2" }, { "D3D11_FEATURE_DATA_FORMAT_SUPPORT2::OutFormatSupport2", "D3D11_FORMAT_SUPPORT2" },
@@ -894,6 +911,11 @@ public static class Program
// DXGI // DXGI
{ "IDXGIDevice::CreateSurface::Usage", "DXGI_USAGE" }, { "IDXGIDevice::CreateSurface::Usage", "DXGI_USAGE" },
{ "IDXGIOutput::GetDisplayModeList::Flags", "DXGI_ENUM_MODES" }, { "IDXGIOutput::GetDisplayModeList::Flags", "DXGI_ENUM_MODES" },
{ "IDXGISwapChain::Present::Flags", "DXGI_PRESENT" },
{ "IDXGISwapChain1::Present::Flags", "DXGI_PRESENT" },
{ "IDXGISwapChain2::Present::Flags", "DXGI_PRESENT" },
{ "IDXGISwapChain3::Present::Flags", "DXGI_PRESENT" },
{ "IDXGISwapChain4::Present::Flags", "DXGI_PRESENT" },
// D3D11 // D3D11
{ "ID3D11DeviceContext::Map::MapFlags", "D3D11_MAP_FLAG" }, { "ID3D11DeviceContext::Map::MapFlags", "D3D11_MAP_FLAG" },
@@ -2393,6 +2415,10 @@ public static class Program
{ {
sb.Append("Srgb"); sb.Append("Srgb");
} }
else if (part.Equals("BIAS", StringComparison.OrdinalIgnoreCase))
{
sb.Append("Bias");
}
else if (part.Equals("SHAREDEXP", StringComparison.OrdinalIgnoreCase)) else if (part.Equals("SHAREDEXP", StringComparison.OrdinalIgnoreCase))
{ {
sb.Append("SharedExp"); sb.Append("SharedExp");

View File

@@ -3399,19 +3399,19 @@ public enum BufferPrecision : uint
Unknown = 0, Unknown = 0,
/// <include file='../Direct2D.xml' path='doc/member[@name="D2D1_BUFFER_PRECISION::D2D1_BUFFER_PRECISION_8BPC_UNORM"]/*' /> /// <include file='../Direct2D.xml' path='doc/member[@name="D2D1_BUFFER_PRECISION::D2D1_BUFFER_PRECISION_8BPC_UNORM"]/*' />
/// <unmanaged>D2D1_BUFFER_PRECISION_8BPC_UNORM</unmanaged> /// <unmanaged>D2D1_BUFFER_PRECISION_8BPC_UNORM</unmanaged>
_8bpcUnorm = 1, Precision8BitUnorm = 1,
/// <include file='../Direct2D.xml' path='doc/member[@name="D2D1_BUFFER_PRECISION::D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB"]/*' /> /// <include file='../Direct2D.xml' path='doc/member[@name="D2D1_BUFFER_PRECISION::D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB"]/*' />
/// <unmanaged>D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB</unmanaged> /// <unmanaged>D2D1_BUFFER_PRECISION_8BPC_UNORM_SRGB</unmanaged>
_8bpcUnormSrgb = 2, Precision8BitUnormSrgb = 2,
/// <include file='../Direct2D.xml' path='doc/member[@name="D2D1_BUFFER_PRECISION::D2D1_BUFFER_PRECISION_16BPC_UNORM"]/*' /> /// <include file='../Direct2D.xml' path='doc/member[@name="D2D1_BUFFER_PRECISION::D2D1_BUFFER_PRECISION_16BPC_UNORM"]/*' />
/// <unmanaged>D2D1_BUFFER_PRECISION_16BPC_UNORM</unmanaged> /// <unmanaged>D2D1_BUFFER_PRECISION_16BPC_UNORM</unmanaged>
_16bpcUnorm = 3, Precision16BitUnorm = 3,
/// <include file='../Direct2D.xml' path='doc/member[@name="D2D1_BUFFER_PRECISION::D2D1_BUFFER_PRECISION_16BPC_FLOAT"]/*' /> /// <include file='../Direct2D.xml' path='doc/member[@name="D2D1_BUFFER_PRECISION::D2D1_BUFFER_PRECISION_16BPC_FLOAT"]/*' />
/// <unmanaged>D2D1_BUFFER_PRECISION_16BPC_FLOAT</unmanaged> /// <unmanaged>D2D1_BUFFER_PRECISION_16BPC_FLOAT</unmanaged>
_16bpcFloat = 4, Precision16BitFloat = 4,
/// <include file='../Direct2D.xml' path='doc/member[@name="D2D1_BUFFER_PRECISION::D2D1_BUFFER_PRECISION_32BPC_FLOAT"]/*' /> /// <include file='../Direct2D.xml' path='doc/member[@name="D2D1_BUFFER_PRECISION::D2D1_BUFFER_PRECISION_32BPC_FLOAT"]/*' />
/// <unmanaged>D2D1_BUFFER_PRECISION_32BPC_FLOAT</unmanaged> /// <unmanaged>D2D1_BUFFER_PRECISION_32BPC_FLOAT</unmanaged>
_32bpcFloat = 5, Precision32BitFloat = 5,
} }
/// <include file='../Direct2D.xml' path='doc/member[@name="D2D1_MAP_OPTIONS"]/*' /> /// <include file='../Direct2D.xml' path='doc/member[@name="D2D1_MAP_OPTIONS"]/*' />

View File

@@ -2849,7 +2849,7 @@ public enum AsyncGetDataFlags : int
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY"]/*' />
/// <unmanaged>D3D11_QUERY</unmanaged> /// <unmanaged>D3D11_QUERY</unmanaged>
public enum Query : int public enum QueryType : int
{ {
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY::D3D11_QUERY_EVENT"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY::D3D11_QUERY_EVENT"]/*' />
/// <unmanaged>D3D11_QUERY_EVENT</unmanaged> /// <unmanaged>D3D11_QUERY_EVENT</unmanaged>
@@ -10066,10 +10066,10 @@ public partial struct SamplerDescription
public partial struct QueryDescription public partial struct QueryDescription
{ {
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY_DESC::Query"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY_DESC::Query"]/*' />
public Query Query; public QueryType Query;
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY_DESC::MiscFlags"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY_DESC::MiscFlags"]/*' />
public uint MiscFlags; public QueryMiscFlags MiscFlags;
} }
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY_DATA_TIMESTAMP_DISJOINT"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY_DATA_TIMESTAMP_DISJOINT"]/*' />
@@ -11862,13 +11862,13 @@ public partial struct Texture2DDescription1
public Usage Usage; public Usage Usage;
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE2D_DESC1::BindFlags"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE2D_DESC1::BindFlags"]/*' />
public uint BindFlags; public BindFlags BindFlags;
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE2D_DESC1::CPUAccessFlags"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE2D_DESC1::CPUAccessFlags"]/*' />
public uint CPUAccessFlags; public CpuAccessFlags CPUAccessFlags;
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE2D_DESC1::MiscFlags"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE2D_DESC1::MiscFlags"]/*' />
public uint MiscFlags; public ResourceMiscFlags MiscFlags;
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE2D_DESC1::TextureLayout"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE2D_DESC1::TextureLayout"]/*' />
public TextureLayout TextureLayout; public TextureLayout TextureLayout;
@@ -11897,13 +11897,13 @@ public partial struct Texture3DDescription1
public Usage Usage; public Usage Usage;
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE3D_DESC1::BindFlags"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE3D_DESC1::BindFlags"]/*' />
public uint BindFlags; public BindFlags BindFlags;
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE3D_DESC1::CPUAccessFlags"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE3D_DESC1::CPUAccessFlags"]/*' />
public uint CPUAccessFlags; public CpuAccessFlags CPUAccessFlags;
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE3D_DESC1::MiscFlags"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE3D_DESC1::MiscFlags"]/*' />
public uint MiscFlags; public ResourceMiscFlags MiscFlags;
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE3D_DESC1::TextureLayout"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_TEXTURE3D_DESC1::TextureLayout"]/*' />
public TextureLayout TextureLayout; public TextureLayout TextureLayout;
@@ -12552,10 +12552,10 @@ public partial struct UnorderedAccessViewDescription1
public partial struct QueryDescription1 public partial struct QueryDescription1
{ {
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY_DESC1::Query"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY_DESC1::Query"]/*' />
public Query Query; public QueryType Query;
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY_DESC1::MiscFlags"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY_DESC1::MiscFlags"]/*' />
public uint MiscFlags; public QueryMiscFlags MiscFlags;
/// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY_DESC1::ContextType"]/*' /> /// <include file='../Direct3D11.xml' path='doc/member[@name="D3D11_QUERY_DESC1::ContextType"]/*' />
public ContextType ContextType; public ContextType ContextType;

View File

@@ -378,7 +378,7 @@ public enum Format : uint
B8G8R8X8Unorm = 88, B8G8R8X8Unorm = 88,
/// <include file='../Dxgi.xml' path='doc/member[@name="DXGI_FORMAT::DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM"]/*' /> /// <include file='../Dxgi.xml' path='doc/member[@name="DXGI_FORMAT::DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM"]/*' />
/// <unmanaged>DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM</unmanaged> /// <unmanaged>DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM</unmanaged>
R10G10B10XRBIASA2Unorm = 89, R10G10B10XRBiasA2Unorm = 89,
/// <include file='../Dxgi.xml' path='doc/member[@name="DXGI_FORMAT::DXGI_FORMAT_B8G8R8A8_TYPELESS"]/*' /> /// <include file='../Dxgi.xml' path='doc/member[@name="DXGI_FORMAT::DXGI_FORMAT_B8G8R8A8_TYPELESS"]/*' />
/// <unmanaged>DXGI_FORMAT_B8G8R8A8_TYPELESS</unmanaged> /// <unmanaged>DXGI_FORMAT_B8G8R8A8_TYPELESS</unmanaged>
B8G8R8A8Typeless = 90, B8G8R8A8Typeless = 90,

View File

@@ -1698,7 +1698,7 @@ public enum EnumModesFlags : uint
/// <unmanaged>DXGI_PRESENT</unmanaged> /// <unmanaged>DXGI_PRESENT</unmanaged>
[Flags] [Flags]
public enum Present : uint public enum PresentFlags : uint
{ {
None = 0, None = 0,
/// <unmanaged>DXGI_PRESENT_TEST</unmanaged> /// <unmanaged>DXGI_PRESENT_TEST</unmanaged>

View File

@@ -118,9 +118,9 @@ public unsafe partial struct IDXGISwapChain
/// <include file='../../Dxgi.xml' path='doc/member[@name="IDXGISwapChain::Present"]/*' /> /// <include file='../../Dxgi.xml' path='doc/member[@name="IDXGISwapChain::Present"]/*' />
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(8)] [VtblIndex(8)]
public HResult Present(uint SyncInterval, uint Flags) public HResult Present(uint SyncInterval, PresentFlags Flags)
{ {
return ((delegate* unmanaged[Stdcall]<IDXGISwapChain*, uint, uint, int>)(lpVtbl[8]))((IDXGISwapChain*)Unsafe.AsPointer(ref this), SyncInterval, Flags); return ((delegate* unmanaged[Stdcall]<IDXGISwapChain*, uint, PresentFlags, int>)(lpVtbl[8]))((IDXGISwapChain*)Unsafe.AsPointer(ref this), SyncInterval, Flags);
} }
/// <include file='../../Dxgi.xml' path='doc/member[@name="IDXGISwapChain::GetBuffer"]/*' /> /// <include file='../../Dxgi.xml' path='doc/member[@name="IDXGISwapChain::GetBuffer"]/*' />

View File

@@ -118,9 +118,9 @@ public unsafe partial struct IDXGISwapChain1
/// <inheritdoc cref="IDXGISwapChain.Present" /> /// <inheritdoc cref="IDXGISwapChain.Present" />
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(8)] [VtblIndex(8)]
public HResult Present(uint SyncInterval, uint Flags) public HResult Present(uint SyncInterval, PresentFlags Flags)
{ {
return ((delegate* unmanaged[Stdcall]<IDXGISwapChain1*, uint, uint, int>)(lpVtbl[8]))((IDXGISwapChain1*)Unsafe.AsPointer(ref this), SyncInterval, Flags); return ((delegate* unmanaged[Stdcall]<IDXGISwapChain1*, uint, PresentFlags, int>)(lpVtbl[8]))((IDXGISwapChain1*)Unsafe.AsPointer(ref this), SyncInterval, Flags);
} }
/// <inheritdoc cref="IDXGISwapChain.GetBuffer" /> /// <inheritdoc cref="IDXGISwapChain.GetBuffer" />

View File

@@ -118,9 +118,9 @@ public unsafe partial struct IDXGISwapChain2
/// <inheritdoc cref="IDXGISwapChain.Present" /> /// <inheritdoc cref="IDXGISwapChain.Present" />
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(8)] [VtblIndex(8)]
public HResult Present(uint SyncInterval, uint Flags) public HResult Present(uint SyncInterval, PresentFlags Flags)
{ {
return ((delegate* unmanaged[Stdcall]<IDXGISwapChain2*, uint, uint, int>)(lpVtbl[8]))((IDXGISwapChain2*)Unsafe.AsPointer(ref this), SyncInterval, Flags); return ((delegate* unmanaged[Stdcall]<IDXGISwapChain2*, uint, PresentFlags, int>)(lpVtbl[8]))((IDXGISwapChain2*)Unsafe.AsPointer(ref this), SyncInterval, Flags);
} }
/// <inheritdoc cref="IDXGISwapChain.GetBuffer" /> /// <inheritdoc cref="IDXGISwapChain.GetBuffer" />

View File

@@ -118,9 +118,9 @@ public unsafe partial struct IDXGISwapChain3
/// <inheritdoc cref="IDXGISwapChain.Present" /> /// <inheritdoc cref="IDXGISwapChain.Present" />
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(8)] [VtblIndex(8)]
public HResult Present(uint SyncInterval, uint Flags) public HResult Present(uint SyncInterval, PresentFlags Flags)
{ {
return ((delegate* unmanaged[Stdcall]<IDXGISwapChain3*, uint, uint, int>)(lpVtbl[8]))((IDXGISwapChain3*)Unsafe.AsPointer(ref this), SyncInterval, Flags); return ((delegate* unmanaged[Stdcall]<IDXGISwapChain3*, uint, PresentFlags, int>)(lpVtbl[8]))((IDXGISwapChain3*)Unsafe.AsPointer(ref this), SyncInterval, Flags);
} }
/// <inheritdoc cref="IDXGISwapChain.GetBuffer" /> /// <inheritdoc cref="IDXGISwapChain.GetBuffer" />

View File

@@ -118,9 +118,9 @@ public unsafe partial struct IDXGISwapChain4
/// <inheritdoc cref="IDXGISwapChain.Present" /> /// <inheritdoc cref="IDXGISwapChain.Present" />
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
[VtblIndex(8)] [VtblIndex(8)]
public HResult Present(uint SyncInterval, uint Flags) public HResult Present(uint SyncInterval, PresentFlags Flags)
{ {
return ((delegate* unmanaged[Stdcall]<IDXGISwapChain4*, uint, uint, int>)(lpVtbl[8]))((IDXGISwapChain4*)Unsafe.AsPointer(ref this), SyncInterval, Flags); return ((delegate* unmanaged[Stdcall]<IDXGISwapChain4*, uint, PresentFlags, int>)(lpVtbl[8]))((IDXGISwapChain4*)Unsafe.AsPointer(ref this), SyncInterval, Flags);
} }
/// <inheritdoc cref="IDXGISwapChain.GetBuffer" /> /// <inheritdoc cref="IDXGISwapChain.GetBuffer" />

View File

@@ -59,6 +59,27 @@ public partial struct AuthenticatedProtectionFlags
public static unsafe partial class Apis public static unsafe partial class Apis
{ {
public static HResult D3D11CreateDevice(
IDXGIAdapter* adapter,
DriverType driverType,
CreateDeviceFlags flags,
ID3D11Device** ppDevice,
FeatureLevel* pFeatureLevel,
ID3D11DeviceContext** ppImmediateContext)
{
return D3D11CreateDevice(
adapter,
driverType,
IntPtr.Zero,
flags,
null,
0u,
D3D11_SDK_VERSION,
ppDevice,
pFeatureLevel,
ppImmediateContext);
}
public static HResult D3D11CreateDevice( public static HResult D3D11CreateDevice(
IDXGIAdapter* pAdapter, IDXGIAdapter* pAdapter,
DriverType driverType, DriverType driverType,

View File

@@ -0,0 +1,75 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using static Win32.Graphics.Direct3D11.Apis;
namespace Win32.Graphics.Direct3D11;
public unsafe partial struct BlendDescription
{
/// <summary>
/// A built-in description with settings for opaque blend, that is overwriting the source with the destination data.
/// </summary>
public static readonly BlendDescription Opaque = new(Blend.One, Blend.Zero);
/// <summary>
/// A built-in description with settings for alpha blend, that is blending the source and destination data using alpha.
/// </summary>
public static readonly BlendDescription AlphaBlend = new(Blend.One, Blend.InvSrcAlpha);
/// <summary>
/// A built-in description with settings for additive blend, that is adding the destination data to the source data without using alpha.
/// </summary>
public static readonly BlendDescription Additive = new(Blend.SrcAlpha, Blend.One);
/// <summary>
/// A built-in description with settings for blending with non-premultipled alpha, that is blending source and destination data using alpha while assuming the color data contains no alpha information.
/// </summary>
public static readonly BlendDescription NonPremultiplied = new(Blend.SrcAlpha, Blend.InvSrcAlpha);
/// <summary>
/// Initializes a new instance of the <see cref="BlendDescription"/> struct.
/// </summary>
/// <param name="sourceBlend">The source blend.</param>
/// <param name="destinationBlend">The destination blend.</param>
public BlendDescription(Blend sourceBlend, Blend destinationBlend)
: this(sourceBlend, destinationBlend, sourceBlend, destinationBlend)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="BlendDescription"/> struct.
/// </summary>
/// <param name="sourceBlend">The source blend.</param>
/// <param name="destinationBlend">The destination blend.</param>
/// <param name="srcBlendAlpha">The source alpha blend.</param>
/// <param name="destBlendAlpha">The destination alpha blend.</param>
public BlendDescription(Blend sourceBlend, Blend destinationBlend, Blend srcBlendAlpha, Blend destBlendAlpha)
: this()
{
AlphaToCoverageEnable = false;
IndependentBlendEnable = false;
for (int i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
{
RenderTarget[i].SrcBlend = sourceBlend;
RenderTarget[i].DestBlend = destinationBlend;
RenderTarget[i].BlendOp = BlendOp.Add;
RenderTarget[i].SrcBlendAlpha = srcBlendAlpha;
RenderTarget[i].DestBlendAlpha = destBlendAlpha;
RenderTarget[i].BlendOpAlpha = BlendOp.Add;
RenderTarget[i].RenderTargetWriteMask = ColorWriteEnable.All;
RenderTarget[i].BlendEnable = IsBlendEnabled(ref RenderTarget[i]);
}
}
private static bool IsBlendEnabled(ref RenderTargetBlendDescription renderTarget)
{
return renderTarget.BlendOp != BlendOp.Add
|| renderTarget.SrcBlend != Blend.One
|| renderTarget.DestBlendAlpha != Blend.Zero
|| renderTarget.BlendOp != BlendOp.Add
|| renderTarget.SrcBlend != Blend.One
|| renderTarget.DestBlend != Blend.Zero;
}
}

View File

@@ -0,0 +1,76 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using static Win32.Graphics.Direct3D11.Apis;
namespace Win32.Graphics.Direct3D11;
public unsafe partial struct BlendDescription1
{
/// <summary>
/// A built-in description with settings for opaque blend, that is overwriting the source with the destination data.
/// </summary>
public static readonly BlendDescription1 Opaque = new(Blend.One, Blend.Zero);
/// <summary>
/// A built-in description with settings for alpha blend, that is blending the source and destination data using alpha.
/// </summary>
public static readonly BlendDescription1 AlphaBlend = new(Blend.One, Blend.InvSrcAlpha);
/// <summary>
/// A built-in description with settings for additive blend, that is adding the destination data to the source data without using alpha.
/// </summary>
public static readonly BlendDescription1 Additive = new(Blend.SrcAlpha, Blend.One);
/// <summary>
/// A built-in description with settings for blending with non-premultipled alpha, that is blending source and destination data using alpha while assuming the color data contains no alpha information.
/// </summary>
public static readonly BlendDescription NonPremultiplied = new(Blend.SrcAlpha, Blend.InvSrcAlpha);
/// <summary>
/// Initializes a new instance of the <see cref="BlendDescription1"/> struct.
/// </summary>
/// <param name="sourceBlend">The source blend.</param>
/// <param name="destinationBlend">The destination blend.</param>
public BlendDescription1(Blend sourceBlend, Blend destinationBlend)
: this(sourceBlend, destinationBlend, sourceBlend, destinationBlend)
{
}
/// <summary>
/// Initializes a new instance of the <see cref="BlendDescription1"/> struct.
/// </summary>
/// <param name="sourceBlend">The source blend.</param>
/// <param name="destinationBlend">The destination blend.</param>
/// <param name="srcBlendAlpha">The source alpha blend.</param>
/// <param name="destBlendAlpha">The destination alpha blend.</param>
public BlendDescription1(Blend sourceBlend, Blend destinationBlend, Blend srcBlendAlpha, Blend destBlendAlpha)
: this()
{
AlphaToCoverageEnable = false;
IndependentBlendEnable = false;
for (int i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
{
RenderTarget[i].SrcBlend = sourceBlend;
RenderTarget[i].DestBlend = destinationBlend;
RenderTarget[i].BlendOp = BlendOp.Add;
RenderTarget[i].SrcBlendAlpha = srcBlendAlpha;
RenderTarget[i].DestBlendAlpha = destBlendAlpha;
RenderTarget[i].BlendOpAlpha = BlendOp.Add;
RenderTarget[i].LogicOp = LogicOp.Noop;
RenderTarget[i].RenderTargetWriteMask = ColorWriteEnable.All;
RenderTarget[i].BlendEnable = IsBlendEnabled(ref RenderTarget[i]);
}
}
private static bool IsBlendEnabled(ref RenderTargetBlendDescription1 renderTarget)
{
return renderTarget.BlendOp != BlendOp.Add
|| renderTarget.SrcBlend != Blend.One
|| renderTarget.DestBlendAlpha != Blend.Zero
|| renderTarget.BlendOp != BlendOp.Add
|| renderTarget.SrcBlend != Blend.One
|| renderTarget.DestBlend != Blend.Zero;
}
}

View File

@@ -0,0 +1,18 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
namespace Win32.Graphics.Direct3D11;
public unsafe partial struct QueryDescription
{
/// <summary>
/// Initializes a new instance of the <see cref="QueryDescription"/> struct.
/// </summary>
/// <param name="queryType">Type of query (see <see cref="QueryType"/>).</param>
/// <param name="miscFlags">Miscellaneous flags (see <see cref="QueryMiscFlags"/>).</param>
public QueryDescription(QueryType queryType, QueryMiscFlags miscFlags = QueryMiscFlags.None)
{
Query = queryType;
MiscFlags = miscFlags;
}
}

View File

@@ -0,0 +1,23 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
namespace Win32.Graphics.Direct3D11;
public unsafe partial struct QueryDescription1
{
/// <summary>
/// Initializes a new instance of the <see cref="QueryDescription1"/> struct.
/// </summary>
/// <param name="queryType">Type of query (see <see cref="QueryType"/>).</param>
/// <param name="miscFlags">Miscellaneous flags (see <see cref="QueryMiscFlags"/>).</param>
/// <param name="contextType">A <see cref="ContextType"/> value that specifies the context for the query.</param>
public QueryDescription1(
QueryType queryType,
QueryMiscFlags miscFlags = QueryMiscFlags.None,
ContextType contextType = ContextType.All)
{
Query = queryType;
MiscFlags = miscFlags;
ContextType = contextType;
}
}

View File

@@ -0,0 +1,48 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using static Win32.Graphics.Direct3D11.Apis;
namespace Win32.Graphics.Direct3D11;
public unsafe partial struct RasterizerDescription
{
/// <summary>
/// A built-in description with settings with settings for not culling any primitives.
/// </summary>
public static readonly RasterizerDescription CullNone = new(CullMode.None, FillMode.Solid);
/// <summary>
/// A built-in description with settings for culling primitives with clockwise winding order.
/// </summary>
public static readonly RasterizerDescription CullFront = new(CullMode.Front, FillMode.Solid);
/// <summary>
/// A built-in description with settings for culling primitives with counter-clockwise winding order.
/// </summary>
public static readonly RasterizerDescription CullBack = new(CullMode.Back, FillMode.Solid);
/// <summary>
/// A built-in description with settings for not culling any primitives and wireframe fill mode.
/// </summary>
public static readonly RasterizerDescription Wireframe = new(CullMode.None, FillMode.Wireframe);
/// <summary>
/// Initializes a new instance of the <see cref="RasterizerDescription"/> class.
/// </summary>
/// <param name="cullMode">A <see cref="CullMode"/> value that specifies that triangles facing the specified direction are not drawn..</param>
/// <param name="fillMode">A <see cref="FillMode"/> value that specifies the fill mode to use when rendering.</param>
public RasterizerDescription(CullMode cullMode, FillMode fillMode)
{
CullMode = cullMode;
FillMode = fillMode;
FrontCounterClockwise = false;
DepthBias = (int)D3D11_DEFAULT_DEPTH_BIAS;
DepthBiasClamp = D3D11_DEFAULT_DEPTH_BIAS_CLAMP;
SlopeScaledDepthBias = D3D11_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
DepthClipEnable = true;
ScissorEnable = false;
MultisampleEnable = true;
AntialiasedLineEnable = false;
}
}

View File

@@ -0,0 +1,49 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using static Win32.Graphics.Direct3D11.Apis;
namespace Win32.Graphics.Direct3D11;
public unsafe partial struct RasterizerDescription1
{
/// <summary>
/// A built-in description with settings with settings for not culling any primitives.
/// </summary>
public static readonly RasterizerDescription1 CullNone = new(CullMode.None, FillMode.Solid);
/// <summary>
/// A built-in description with settings for culling primitives with clockwise winding order.
/// </summary>
public static readonly RasterizerDescription1 CullFront = new(CullMode.Front, FillMode.Solid);
/// <summary>
/// A built-in description with settings for culling primitives with counter-clockwise winding order.
/// </summary>
public static readonly RasterizerDescription1 CullBack = new(CullMode.Back, FillMode.Solid);
/// <summary>
/// A built-in description with settings for not culling any primitives and wireframe fill mode.
/// </summary>
public static readonly RasterizerDescription1 Wireframe = new(CullMode.None, FillMode.Wireframe);
/// <summary>
/// Initializes a new instance of the <see cref="RasterizerDescription1"/> class.
/// </summary>
/// <param name="cullMode">A <see cref="CullMode"/> value that specifies that triangles facing the specified direction are not drawn..</param>
/// <param name="fillMode">A <see cref="FillMode"/> value that specifies the fill mode to use when rendering.</param>
public RasterizerDescription1(CullMode cullMode, FillMode fillMode)
{
CullMode = cullMode;
FillMode = fillMode;
FrontCounterClockwise = false;
DepthBias = (int)D3D11_DEFAULT_DEPTH_BIAS;
DepthBiasClamp = D3D11_DEFAULT_DEPTH_BIAS_CLAMP;
SlopeScaledDepthBias = D3D11_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
DepthClipEnable = true;
ScissorEnable = false;
MultisampleEnable = true;
AntialiasedLineEnable = false;
ForcedSampleCount = 0;
}
}

View File

@@ -0,0 +1,50 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using static Win32.Graphics.Direct3D11.Apis;
namespace Win32.Graphics.Direct3D11;
public unsafe partial struct RasterizerDescription2
{
/// <summary>
/// A built-in description with settings with settings for not culling any primitives.
/// </summary>
public static readonly RasterizerDescription2 CullNone = new(CullMode.None, FillMode.Solid);
/// <summary>
/// A built-in description with settings for culling primitives with clockwise winding order.
/// </summary>
public static readonly RasterizerDescription2 CullFront = new(CullMode.Front, FillMode.Solid);
/// <summary>
/// A built-in description with settings for culling primitives with counter-clockwise winding order.
/// </summary>
public static readonly RasterizerDescription2 CullBack = new(CullMode.Back, FillMode.Solid);
/// <summary>
/// A built-in description with settings for not culling any primitives and wireframe fill mode.
/// </summary>
public static readonly RasterizerDescription2 Wireframe = new(CullMode.None, FillMode.Wireframe);
/// <summary>
/// Initializes a new instance of the <see cref="RasterizerDescription2"/> class.
/// </summary>
/// <param name="cullMode">A <see cref="CullMode"/> value that specifies that triangles facing the specified direction are not drawn..</param>
/// <param name="fillMode">A <see cref="FillMode"/> value that specifies the fill mode to use when rendering.</param>
public RasterizerDescription2(CullMode cullMode, FillMode fillMode)
{
CullMode = cullMode;
FillMode = fillMode;
FrontCounterClockwise = false;
DepthBias = (int)D3D11_DEFAULT_DEPTH_BIAS;
DepthBiasClamp = D3D11_DEFAULT_DEPTH_BIAS_CLAMP;
SlopeScaledDepthBias = D3D11_DEFAULT_SLOPE_SCALED_DEPTH_BIAS;
DepthClipEnable = true;
ScissorEnable = false;
MultisampleEnable = true;
AntialiasedLineEnable = false;
ForcedSampleCount = 0;
ConservativeRaster = ConservativeRasterizationMode.Off;
}
}

View File

@@ -0,0 +1,130 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using static Win32.Graphics.Direct3D11.Apis;
namespace Win32.Graphics.Direct3D11;
public unsafe partial struct SamplerDescription
{
public static readonly SamplerDescription PointWrap = new(Filter.MinMagMipPoint, TextureAddressMode.Wrap);
public static readonly SamplerDescription PointClamp = new(Filter.MinMagMipPoint, TextureAddressMode.Clamp);
public static readonly SamplerDescription LinearWrap = new(Filter.MinMagMipLinear, TextureAddressMode.Wrap);
public static readonly SamplerDescription LinearClamp = new(Filter.MinMagMipLinear, TextureAddressMode.Clamp);
public static readonly SamplerDescription AnisotropicWrap = new(Filter.Anisotropic, TextureAddressMode.Wrap, 0.0f, D3D11_MAX_MAXANISOTROPY);
public static readonly SamplerDescription AnisotropicClamp = new(Filter.Anisotropic, TextureAddressMode.Clamp, 0.0f, D3D11_MAX_MAXANISOTROPY);
/// <summary>
/// Initializes a new instance of the <see cref="SamplerDescription"/> struct.
/// </summary>
/// <param name="filter">Filtering method to use when sampling a texture.</param>
/// <param name="addressU">Method to use for resolving a u texture coordinate that is outside the 0 to 1 range.</param>
/// <param name="addressV">Method to use for resolving a v texture coordinate that is outside the 0 to 1 range.</param>
/// <param name="addressW">Method to use for resolving a w texture coordinate that is outside the 0 to 1 range.</param>
/// <param name="mipLODBias">Offset from the calculated mipmap level.</param>
/// <param name="maxAnisotropy">Clamping value used if <see cref="Filter.Anisotropic"/> or <see cref="Filter.ComparisonAnisotropic"/> is specified in Filter. Valid values are between 1 and 16.</param>
/// <param name="comparisonFunction">A function that compares sampled data against existing sampled data. </param>
/// <param name="borderColor">Border color to use if <see cref="TextureAddressMode.Border"/> is specified for AddressU, AddressV, or AddressW.</param>
/// <param name="minLOD">Lower end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed.</param>
/// <param name="maxLOD">Upper end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed. This value must be greater than or equal to MinLOD. </param>
public SamplerDescription(
Filter filter,
TextureAddressMode addressU,
TextureAddressMode addressV,
TextureAddressMode addressW,
float mipLODBias,
uint maxAnisotropy,
ComparisonFunc comparisonFunction,
Color4 borderColor,
float minLOD,
float maxLOD)
{
Filter = filter;
AddressU = addressU;
AddressV = addressV;
AddressW = addressW;
MipLODBias = mipLODBias;
MaxAnisotropy = maxAnisotropy;
ComparisonFunc = comparisonFunction;
BorderColor[0] = borderColor.R;
BorderColor[1] = borderColor.G;
BorderColor[2] = borderColor.B;
BorderColor[3] = borderColor.A;
MinLOD = minLOD;
MaxLOD = maxLOD;
}
/// <summary>
/// Initializes a new instance of the <see cref="SamplerDescription"/> struct.
/// </summary>
/// <param name="filter">Filtering method to use when sampling a texture.</param>
/// <param name="addressU">Method to use for resolving a u texture coordinate that is outside the 0 to 1 range.</param>
/// <param name="addressV">Method to use for resolving a v texture coordinate that is outside the 0 to 1 range.</param>
/// <param name="addressW">Method to use for resolving a w texture coordinate that is outside the 0 to 1 range.</param>
/// <param name="mipLODBias">Offset from the calculated mipmap level.</param>
/// <param name="maxAnisotropy">Clamping value used if <see cref="Filter.Anisotropic"/> or <see cref="Filter.ComparisonAnisotropic"/> is specified in Filter. Valid values are between 1 and 16.</param>
/// <param name="comparisonFunction">A function that compares sampled data against existing sampled data. </param>
/// <param name="minLOD">Lower end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed.</param>
/// <param name="maxLOD">Upper end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed. This value must be greater than or equal to MinLOD. </param>
public SamplerDescription(
Filter filter,
TextureAddressMode addressU,
TextureAddressMode addressV,
TextureAddressMode addressW,
float mipLODBias = 0.0f,
uint maxAnisotropy = 1,
ComparisonFunc comparisonFunction = ComparisonFunc.Never,
float minLOD = float.MinValue,
float maxLOD = float.MaxValue)
{
Filter = filter;
AddressU = addressU;
AddressV = addressV;
AddressW = addressW;
MipLODBias = mipLODBias;
MaxAnisotropy = maxAnisotropy;
ComparisonFunc = comparisonFunction;
BorderColor[0] = 1.0f;
BorderColor[1] = 1.0f;
BorderColor[2] = 1.0f;
BorderColor[3] = 1.0f;
MinLOD = minLOD;
MaxLOD = maxLOD;
}
/// <summary>
/// Initializes a new instance of the <see cref="SamplerDescription"/> struct.
/// </summary>
/// <param name="filter">Filtering method to use when sampling a texture.</param>
/// <param name="address">Method to use for resolving a u, v e w texture coordinate that is outside the 0 to 1 range.</param>
/// <param name="mipLODBias">Offset from the calculated mipmap level.</param>
/// <param name="maxAnisotropy">Clamping value used if <see cref="Filter.Anisotropic"/> or <see cref="Filter.ComparisonAnisotropic"/> is specified in Filter. Valid values are between 1 and 16.</param>
/// <param name="comparisonFunction">A function that compares sampled data against existing sampled data. </param>
/// <param name="minLOD">Lower end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed.</param>
/// <param name="maxLOD">Upper end of the mipmap range to clamp access to, where 0 is the largest and most detailed mipmap level and any level higher than that is less detailed. This value must be greater than or equal to MinLOD. </param>
public SamplerDescription(
Filter filter,
TextureAddressMode address,
float mipLODBias = 0.0f,
uint maxAnisotropy = 1,
ComparisonFunc comparisonFunction = ComparisonFunc.Never,
float minLOD = float.MinValue,
float maxLOD = float.MaxValue)
{
Filter = filter;
AddressU = address;
AddressV = address;
AddressW = address;
MipLODBias = mipLODBias;
MaxAnisotropy = maxAnisotropy;
ComparisonFunc = comparisonFunction;
BorderColor[0] = 1.0f;
BorderColor[1] = 1.0f;
BorderColor[2] = 1.0f;
BorderColor[3] = 1.0f;
MinLOD = minLOD;
MaxLOD = maxLOD;
}
}

View File

@@ -0,0 +1,64 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using Win32.Graphics.Dxgi.Common;
using static Win32.Graphics.Direct3D11.Apis;
namespace Win32.Graphics.Direct3D11;
public partial struct Texture2DDescription1
{
/// <summary>
/// Initializes a new instance of the <see cref="Texture2DDescription1"/> struct.
/// </summary>
/// <param name="format">Texture format.</param>
/// <param name="width">Texture width (in texels).</param>
/// <param name="height">Texture height (in texels).</param>
/// <param name="arraySize">Number of textures in the array.</param>
/// <param name="mipLevels">The maximum number of mipmap levels in the texture.</param>
/// <param name="bindFlags">The <see cref="Direct3D11.BindFlags"/> for binding to pipeline stages.</param>
/// <param name="usage">Value that identifies how the texture is to be read from and written to.</param>
/// <param name="cpuAccessFlags">The <see cref="CpuAccessFlags"/> to specify the types of CPU access allowed.</param>
/// <param name="sampleCount">Specifies multisampling parameters for the texture.</param>
/// <param name="sampleQuality">Specifies multisampling parameters for the texture.</param>
/// <param name="miscFlags">The <see cref="ResourceMiscFlags"/> that identify other, less common resource options. </param>
/// <param name="textureLayout">A <see cref="TextureLayout"/> value that identifies the layout of the texture.</param>
public Texture2DDescription1(
Format format,
uint width,
uint height,
uint arraySize = 1,
uint mipLevels = 0,
BindFlags bindFlags = BindFlags.ShaderResource,
Usage usage = Usage.Default,
CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None,
uint sampleCount = 1,
uint sampleQuality = 0,
ResourceMiscFlags miscFlags = ResourceMiscFlags.None,
TextureLayout textureLayout = TextureLayout.Undefined)
{
if (format == Format.Unknown)
throw new ArgumentException($"format need to be valid", nameof(format));
if (width < 1 || width > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)
throw new ArgumentException($"Width need to be in range 1-{D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION}", nameof(width));
if (height < 1 || height > D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION)
throw new ArgumentException($"Height need to be in range 1-{D3D11_REQ_TEXTURE2D_U_OR_V_DIMENSION}", nameof(height));
if (arraySize < 1 || arraySize > D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION)
throw new ArgumentException($"Array size need to be in range 1-{D3D11_REQ_TEXTURE2D_ARRAY_AXIS_DIMENSION}", nameof(arraySize));
Width = width;
Height = height;
MipLevels = mipLevels;
ArraySize = arraySize;
Format = format;
SampleDesc = new(sampleCount, sampleQuality);
Usage = usage;
BindFlags = bindFlags;
CPUAccessFlags = cpuAccessFlags;
MiscFlags = miscFlags;
TextureLayout = textureLayout;
}
}

View File

@@ -0,0 +1,59 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using Win32.Graphics.Dxgi.Common;
using static Win32.Graphics.Direct3D11.Apis;
namespace Win32.Graphics.Direct3D11;
public partial struct Texture3DDescription1
{
/// <summary>
/// Initializes a new instance of the <see cref="Texture3DDescription1"/> struct.
/// </summary>
/// <param name="width">Texture width (in texels).</param>
/// <param name="height">Texture height (in texels).</param>
/// <param name="depth">Texture depth (in texels).</param>
/// <param name="format">Texture format.</param>
/// <param name="mipLevels">The maximum number of mipmap levels in the texture.</param>
/// <param name="bindFlags">The <see cref="Direct3D11.BindFlags"/> for binding to pipeline stages.</param>
/// <param name="usage">Value that identifies how the texture is to be read from and written to.</param>
/// <param name="cpuAccessFlags">The <see cref="CpuAccessFlags"/> to specify the types of CPU access allowed.</param>
/// <param name="miscFlags">The <see cref="ResourceMiscFlags"/> that identify other, less common resource options. </param>
/// <param name="textureLayout">A <see cref="TextureLayout"/> value that identifies the layout of the texture.</param>
public Texture3DDescription1(
Format format,
uint width,
uint height,
uint depth,
uint mipLevels = 0,
BindFlags bindFlags = BindFlags.ShaderResource,
Usage usage = Usage.Default,
CpuAccessFlags cpuAccessFlags = CpuAccessFlags.None,
ResourceMiscFlags miscFlags = ResourceMiscFlags.None,
TextureLayout textureLayout = TextureLayout.Undefined)
{
if (format == Format.Unknown)
throw new ArgumentException($"format need to be valid", nameof(format));
if (width < 1 || width > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION)
throw new ArgumentException($"Width need to be in range 1-{D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION}", nameof(width));
if (height < 1 || height > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION)
throw new ArgumentException($"Height need to be in range 1-{D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION}", nameof(height));
if (depth < 1 || depth > D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION)
throw new ArgumentException($"Depth need to be in range 1-{D3D11_REQ_TEXTURE3D_U_V_OR_W_DIMENSION}", nameof(depth));
Width = width;
Height = height;
Depth = depth;
MipLevels = mipLevels;
Format = format;
Usage = usage;
BindFlags = bindFlags;
CPUAccessFlags = cpuAccessFlags;
MiscFlags = miscFlags;
TextureLayout = textureLayout;
}
}

View File

@@ -0,0 +1,369 @@
// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
// Ported from d3dx12.h in DirectX-Graphics-Samples commit a7a87f1853b5540f10920518021d91ae641033fb
// Original source is Copyright © Microsoft. All rights reserved. Licensed under the MIT License (MIT).
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using Win32.Graphics.Dxgi.Common;
using static Win32.Apis;
namespace Win32.Graphics.Direct3D12;
public static unsafe partial class Apis
{
public static uint D3D12CalcSubresource(uint MipSlice, uint ArraySlice, uint PlaneSlice, uint MipLevels, uint ArraySize)
{
return MipSlice + ArraySlice * MipLevels + PlaneSlice * MipLevels * ArraySize;
}
public static bool D3D12IsLayoutOpaque(TextureLayout Layout)
{
return Layout == TextureLayout.Unknown || Layout == TextureLayout.L64KbUndefinedSwizzle;
}
public static void D3D12DecomposeSubresource(
uint Subresource,
uint MipLevels,
uint ArraySize,
out uint MipSlice,
out uint ArraySlice,
out uint PlaneSlice)
{
MipSlice = Subresource % MipLevels;
ArraySlice = (Subresource / MipLevels) % ArraySize;
PlaneSlice = Subresource / (MipLevels * ArraySize);
}
public static void MemcpySubresource(
MemcpyDest* pDest,
SubresourceData* pSrc,
nuint RowSizeInBytes,
uint NumRows,
uint NumSlices)
{
for (var z = 0u; z < NumSlices; ++z)
{
var pDestSlice = (byte*)pDest->pData + pDest->SlicePitch * z;
var pSrcSlice = (byte*)pSrc->pData + pSrc->SlicePitch * (nint)z;
for (var y = 0u; y < NumRows; ++y)
{
Buffer.MemoryCopy(
pSrcSlice + pSrc->RowPitch * (nint)y,
pDestSlice + pDest->RowPitch * y,
RowSizeInBytes,
RowSizeInBytes
);
}
}
}
public static void MemcpySubresource(
MemcpyDest* pDest,
void* pResourceData,
SubresourceInfo* pSrc,
nuint RowSizeInBytes, uint NumRows, uint NumSlices)
{
for (var z = 0u; z < NumSlices; ++z)
{
var pDestSlice = (byte*)pDest->pData + pDest->SlicePitch * z;
var pSrcSlice = ((byte*)pResourceData + pSrc->Offset) + pSrc->DepthPitch * (nint)z;
for (var y = 0u; y < NumRows; ++y)
{
Buffer.MemoryCopy(
pSrcSlice + pSrc->RowPitch * (nint)y,
pDestSlice + pDest->RowPitch * y,
(ulong)RowSizeInBytes,
(ulong)RowSizeInBytes
);
}
}
}
public static byte D3D12GetFormatPlaneCount(ID3D12Device* device, Format format)
{
FeatureDataFormatInfo formatInfo = new FeatureDataFormatInfo
{
Format = format,
PlaneCount = 0,
};
if (device->CheckFeatureSupport(Feature.FormatInfo, &formatInfo, (uint)(sizeof(FeatureDataFormatInfo))).Failure)
{
return 0;
}
return formatInfo.PlaneCount;
}
public static ulong GetRequiredIntermediateSize(ID3D12Resource* pDestinationResource, uint FirstSubresource, uint NumSubresources)
{
var Desc = pDestinationResource->GetDesc();
ulong RequiredSize = 0;
ID3D12Device* pDevice = null;
_ = pDestinationResource->GetDevice(__uuidof<ID3D12Device>(), (void**)&pDevice);
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, 0, null, null, null, &RequiredSize);
_ = pDevice->Release();
return RequiredSize;
}
public static ulong UpdateSubresources(
ID3D12GraphicsCommandList* pCmdList,
ID3D12Resource* pDestinationResource,
ID3D12Resource* pIntermediate,
uint FirstSubresource,
uint NumSubresources,
ulong RequiredSize,
PlacedSubresourceFootprint* pLayouts,
uint* pNumRows,
ulong* pRowSizesInBytes,
SubresourceData* pSrcData)
{
ResourceDescription IntermediateDesc = pIntermediate->GetDesc();
ResourceDescription DestinationDesc = pDestinationResource->GetDesc();
if (IntermediateDesc.Dimension != ResourceDimension.Buffer ||
IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset ||
RequiredSize > unchecked((ulong)-1) ||
(DestinationDesc.Dimension == ResourceDimension.Buffer && (FirstSubresource != 0 || NumSubresources != 1)))
{
return 0;
}
byte* pData;
HResult hr = pIntermediate->Map(0, null, (void**)(&pData));
if (hr.Failure)
{
return 0;
}
for (uint i = 0; i < NumSubresources; ++i)
{
if (pRowSizesInBytes[i] > unchecked((nuint)(-1)))
{
return 0;
}
MemcpyDest DestData = new MemcpyDest
{
pData = pData + pLayouts[i].Offset,
RowPitch = pLayouts[i].Footprint.RowPitch,
SlicePitch = pLayouts[i].Footprint.RowPitch * pNumRows[i],
};
MemcpySubresource(&DestData, &pSrcData[i], unchecked((nuint)(pRowSizesInBytes[i])), pNumRows[i], pLayouts[i].Footprint.Depth);
}
pIntermediate->Unmap(0, null);
if (DestinationDesc.Dimension == ResourceDimension.Buffer)
{
pCmdList->CopyBufferRegion(pDestinationResource, 0, pIntermediate, pLayouts[0].Offset, pLayouts[0].Footprint.Width);
}
else
{
for (uint i = 0; i < NumSubresources; ++i)
{
TextureCopyLocation Dst = new(pDestinationResource, i + FirstSubresource);
TextureCopyLocation Src = new(pIntermediate, pLayouts[i]);
pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, null);
}
}
return RequiredSize;
}
public static ulong UpdateSubresources(
ID3D12GraphicsCommandList* pCmdList,
ID3D12Resource* pDestinationResource,
ID3D12Resource* pIntermediate,
uint FirstSubresource,
uint NumSubresources,
ulong RequiredSize,
PlacedSubresourceFootprint* pLayouts,
uint* pNumRows,
ulong* pRowSizesInBytes,
void* pResourceData,
SubresourceInfo* pSrcData)
{
var IntermediateDesc = pIntermediate->GetDesc();
var DestinationDesc = pDestinationResource->GetDesc();
if (IntermediateDesc.Dimension != ResourceDimension.Buffer ||
IntermediateDesc.Width < RequiredSize + pLayouts[0].Offset ||
RequiredSize > unchecked((nuint)(-1)) ||
(DestinationDesc.Dimension == ResourceDimension.Buffer && (FirstSubresource != 0 || NumSubresources != 1)))
{
return 0;
}
byte* pData;
HResult hr = pIntermediate->Map(0, null, (void**)&pData);
if (hr.Failure)
{
return 0;
}
for (var i = 0u; i < NumSubresources; ++i)
{
if (pRowSizesInBytes[i] > unchecked((nuint)(-1)))
{
return 0;
}
MemcpyDest DestData = new MemcpyDest
{
pData = pData + pLayouts[i].Offset,
RowPitch = (nuint)pLayouts[i].Footprint.RowPitch,
SlicePitch = (nuint)(pLayouts[i].Footprint.RowPitch * pNumRows[i])
};
MemcpySubresource(&DestData, pResourceData, &pSrcData[i], (nuint)pRowSizesInBytes[i], pNumRows[i], pLayouts[i].Footprint.Depth);
}
pIntermediate->Unmap(0, null);
if (DestinationDesc.Dimension == ResourceDimension.Buffer)
{
pCmdList->CopyBufferRegion(pDestinationResource, 0, pIntermediate, pLayouts[0].Offset, pLayouts[0].Footprint.Width);
}
else
{
for (var i = 0u; i < NumSubresources; ++i)
{
TextureCopyLocation Dst = new(pDestinationResource, i + FirstSubresource);
TextureCopyLocation Src = new(pIntermediate, pLayouts[i]);
pCmdList->CopyTextureRegion(&Dst, 0, 0, 0, &Src, null);
}
}
return RequiredSize;
}
//public static ulong UpdateSubresources(ID3D12GraphicsCommandList* pCmdList, ID3D12Resource* pDestinationResource, ID3D12Resource* pIntermediate, [NativeTypeName("UINT64")] ulong IntermediateOffset, uint FirstSubresource, uint NumSubresources, D3D12_SUBRESOURCE_DATA* pSrcData)
//{
// ulong RequiredSize = 0;
// ulong MemToAlloc = (ulong)(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(uint) + sizeof(ulong)) * NumSubresources;
// if (MemToAlloc > unchecked((nuint)(-1)))
// {
// return 0;
// }
// var pMem = HeapAlloc(GetProcessHeap(), 0, (nuint)MemToAlloc);
// if (pMem == null)
// {
// return 0;
// }
// var pLayouts = (D3D12_PLACED_SUBRESOURCE_FOOTPRINT*)pMem;
// ulong* pRowSizesInBytes = (ulong*)(pLayouts + NumSubresources);
// uint* pNumRows = (uint*)(pRowSizesInBytes + NumSubresources);
// var Desc = pDestinationResource->GetDesc();
// ID3D12Device* pDevice = null;
// _ = pDestinationResource->GetDevice(__uuidof<ID3D12Device>(), (void**)&pDevice);
// pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize);
// _ = pDevice->Release();
// ulong Result = UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, pLayouts, pNumRows, pRowSizesInBytes, pSrcData);
// _ = HeapFree(GetProcessHeap(), 0, pMem);
// return Result;
//}
//public static ulong UpdateSubresources(ID3D12GraphicsCommandList* pCmdList, ID3D12Resource* pDestinationResource, ID3D12Resource* pIntermediate, [NativeTypeName("UINT64")] ulong IntermediateOffset, uint FirstSubresource, uint NumSubresources, [NativeTypeName("const void *")] void* pResourceData, [NativeTypeName("D3D12_SUBRESOURCE_INFO *")] D3D12_SUBRESOURCE_INFO* pSrcData)
//{
// ulong RequiredSize = 0;
// ulong MemToAlloc = (ulong)(sizeof(D3D12_PLACED_SUBRESOURCE_FOOTPRINT) + sizeof(uint) + sizeof(ulong)) * NumSubresources;
// if (MemToAlloc > unchecked((nuint)(-1)))
// {
// return 0;
// }
// var pMem = HeapAlloc(GetProcessHeap(), 0, (nuint)MemToAlloc);
// if (pMem == null)
// {
// return 0;
// }
// var pLayouts = (D3D12_PLACED_SUBRESOURCE_FOOTPRINT*)pMem;
// ulong* pRowSizesInBytes = (ulong*)(pLayouts + NumSubresources);
// uint* pNumRows = (uint*)(pRowSizesInBytes + NumSubresources);
// var Desc = pDestinationResource->GetDesc();
// ID3D12Device* pDevice = null;
// _ = pDestinationResource->GetDevice(__uuidof<ID3D12Device>(), (void**)&pDevice);
// pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, pLayouts, pNumRows, pRowSizesInBytes, &RequiredSize);
// _ = pDevice->Release();
// ulong Result = UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, pLayouts, pNumRows, pRowSizesInBytes, pResourceData, pSrcData);
// _ = HeapFree(GetProcessHeap(), 0, pMem);
// return Result;
//}
public static ulong UpdateSubresources(
uint MaxSubresources,
ID3D12GraphicsCommandList* pCmdList,
ID3D12Resource* pDestinationResource,
ID3D12Resource* pIntermediate,
ulong IntermediateOffset,
uint FirstSubresource,
uint NumSubresources,
SubresourceData* pSrcData)
{
ulong RequiredSize = 0;
PlacedSubresourceFootprint* Layouts = stackalloc PlacedSubresourceFootprint[(int)MaxSubresources];
uint* NumRows = stackalloc uint[(int)MaxSubresources];
ulong* RowSizesInBytes = stackalloc ulong[(int)MaxSubresources];
var Desc = pDestinationResource->GetDesc();
ID3D12Device* pDevice = null;
_ = pDestinationResource->GetDevice(__uuidof<ID3D12Device>(), (void**)&pDevice);
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, Layouts, NumRows, RowSizesInBytes, &RequiredSize);
_ = pDevice->Release();
return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pSrcData);
}
public static ulong UpdateSubresources(
uint MaxSubresources,
ID3D12GraphicsCommandList* pCmdList,
ID3D12Resource* pDestinationResource,
ID3D12Resource* pIntermediate,
ulong IntermediateOffset,
uint FirstSubresource,
uint NumSubresources,
void* pResourceData,
SubresourceInfo* pSrcData)
{
ulong RequiredSize = 0;
PlacedSubresourceFootprint* Layouts = stackalloc PlacedSubresourceFootprint[(int)MaxSubresources];
uint* NumRows = stackalloc uint[(int)MaxSubresources];
ulong* RowSizesInBytes = stackalloc ulong[(int)MaxSubresources];
var Desc = pDestinationResource->GetDesc();
ID3D12Device* pDevice = null;
_ = pDestinationResource->GetDevice(__uuidof<ID3D12Device>(), (void**)&pDevice);
pDevice->GetCopyableFootprints(&Desc, FirstSubresource, NumSubresources, IntermediateOffset, Layouts, NumRows, RowSizesInBytes, &RequiredSize);
_ = pDevice->Release();
return UpdateSubresources(pCmdList, pDestinationResource, pIntermediate, FirstSubresource, NumSubresources, RequiredSize, Layouts, NumRows, RowSizesInBytes, pResourceData, pSrcData);
}
}

View File

@@ -0,0 +1,57 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
namespace Win32.Graphics.Direct3D12;
public unsafe partial struct Box : IEquatable<Box>
{
public Box(int left, int right)
{
this.left = (uint)left;
top = 0;
front = 0;
this.right = (uint)right;
bottom = 1;
back = 1;
}
public Box(int Left, int Top, int Right, int Bottom)
{
left = (uint)Left;
top = (uint)Top;
front = 0;
right = (uint)Right;
bottom = (uint)Bottom;
back = 1;
}
public Box(int Left, int Top, int Front, int Right, int Bottom, int Back)
{
left = (uint)Left;
top = (uint)Top;
front = (uint)Front;
right = (uint)Right;
bottom = (uint)Bottom;
back = (uint)Back;
}
public static bool operator ==(in Box left, in Box right)
=> (left.left == right.left)
&& (left.top == right.top)
&& (left.front == right.front)
&& (left.right == right.right)
&& (left.bottom == right.bottom)
&& (left.back == right.back);
public static bool operator !=(in Box left, in Box right)
=> !(left == right);
public override bool Equals(object? obj) => (obj is Box other) && Equals(other);
public bool Equals(Box other) => this == other;
public override int GetHashCode()
{
return HashCode.Combine(left, top, front, right, bottom, back);
}
}

View File

@@ -0,0 +1,78 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using Win32.Graphics.Dxgi.Common;
namespace Win32.Graphics.Direct3D12;
public unsafe partial struct ClearValue : IEquatable<ClearValue>
{
public ClearValue(Format format, float* color)
{
Unsafe.SkipInit(out this);
Format = format;
Anonymous.Color[0] = color[0];
Anonymous.Color[1] = color[1];
Anonymous.Color[2] = color[2];
Anonymous.Color[3] = color[3];
}
public ClearValue(Format format, float depth, byte stencil)
{
Format = format;
Anonymous.DepthStencil.Depth = depth;
Anonymous.DepthStencil.Stencil = stencil;
}
public static bool operator ==(in ClearValue left, in ClearValue right)
{
if (left.Format != right.Format)
{
return false;
}
if (left.Format == Format.D24UnormS8Uint ||
left.Format == Format.D16Unorm ||
left.Format == Format.D32Float ||
left.Format == Format.D32FloatS8X24Uint)
{
return (left.Anonymous.DepthStencil.Depth == right.Anonymous.DepthStencil.Depth) && (left.Anonymous.DepthStencil.Stencil == right.Anonymous.DepthStencil.Stencil);
}
else
{
return (left.Anonymous.Color[0] == right.Anonymous.Color[0]) && (left.Anonymous.Color[1] == right.Anonymous.Color[1]) && (left.Anonymous.Color[2] == right.Anonymous.Color[2]) && (left.Anonymous.Color[3] == right.Anonymous.Color[3]);
}
}
public static bool operator !=(in ClearValue left, in ClearValue right)
=> !(left == right);
public override bool Equals(object? obj) => (obj is ClearValue other) && Equals(other);
public bool Equals(ClearValue other) => this == other;
public override int GetHashCode()
{
var hashCode = new HashCode();
{
hashCode.Add(Format);
if (Format == Format.D24UnormS8Uint ||
Format == Format.D16Unorm ||
Format == Format.D32Float ||
Format == Format.D32FloatS8X24Uint)
{
hashCode.Add(Anonymous.DepthStencil);
}
else
{
hashCode.Add(Anonymous.Color[0]);
hashCode.Add(Anonymous.Color[1]);
hashCode.Add(Anonymous.Color[2]);
hashCode.Add(Anonymous.Color[3]);
}
}
return hashCode.ToHashCode();
}
}

View File

@@ -0,0 +1,183 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using Win32.Graphics.Dxgi.Common;
using static Win32.Graphics.Direct3D12.Apis;
namespace Win32.Graphics.Direct3D12;
public unsafe partial struct ResourceDescription : IEquatable<ResourceDescription>
{
/// <summary>
/// Initializes a new instance of the <see cref="ResourceDescription"/> struct.
/// </summary>
/// <param name="dimension"></param>
/// <param name="alignment"></param>
/// <param name="width"></param>
/// <param name="height"></param>
/// <param name="depthOrArraySize"></param>
/// <param name="mipLevels"></param>
/// <param name="format"></param>
/// <param name="sampleCount"></param>
/// <param name="sampleQuality"></param>
/// <param name="layout"></param>
/// <param name="flags"></param>
public ResourceDescription(
ResourceDimension dimension,
ulong alignment,
ulong width,
uint height,
ushort depthOrArraySize,
ushort mipLevels,
Format format,
uint sampleCount,
uint sampleQuality,
TextureLayout layout,
ResourceFlags flags)
{
Dimension = dimension;
Alignment = alignment;
Width = width;
Height = height;
DepthOrArraySize = depthOrArraySize;
MipLevels = mipLevels;
Format = format;
SampleDesc = new(sampleCount, sampleQuality);
Layout = layout;
Flags = flags;
}
public static ResourceDescription Buffer(in ResourceAllocationInfo resourceAllocInfo, ResourceFlags flags = ResourceFlags.None)
{
return new ResourceDescription(
ResourceDimension.Buffer,
resourceAllocInfo.Alignment,
resourceAllocInfo.SizeInBytes,
1, 1, 1, Format.Unknown, 1, 0, TextureLayout.RowMajor, flags);
}
public static ResourceDescription Buffer(
ulong sizeInBytes,
ResourceFlags flags = ResourceFlags.None,
ulong alignment = 0)
{
return new ResourceDescription(ResourceDimension.Buffer, alignment, sizeInBytes, 1, 1, 1, Format.Unknown, 1, 0, TextureLayout.RowMajor, flags);
}
public static ResourceDescription Tex1D(Format format,
ulong width,
ushort arraySize = 1,
ushort mipLevels = 0,
ResourceFlags flags = ResourceFlags.None,
TextureLayout layout = TextureLayout.Unknown,
ulong alignment = 0)
{
return new ResourceDescription(ResourceDimension.Texture1D, alignment, width, 1, arraySize, mipLevels, format, 1, 0, layout, flags);
}
public static ResourceDescription Tex2D(Format format,
ulong width,
uint height,
ushort arraySize = 1,
ushort mipLevels = 0,
uint sampleCount = 1,
uint sampleQuality = 0,
ResourceFlags flags = ResourceFlags.None,
TextureLayout layout = TextureLayout.Unknown,
ulong alignment = 0)
{
return new ResourceDescription(ResourceDimension.Texture2D,
alignment,
width,
height,
arraySize,
mipLevels,
format,
sampleCount,
sampleQuality,
layout,
flags);
}
public static ResourceDescription Texture3D(Format format,
ulong width,
uint height,
ushort depth,
ushort mipLevels = 0,
ResourceFlags flags = ResourceFlags.None,
TextureLayout layout = TextureLayout.Unknown,
ulong alignment = 0)
{
return new ResourceDescription(
ResourceDimension.Texture3D,
alignment,
width,
height,
depth,
mipLevels,
format,
1,
0,
layout,
flags);
}
public ushort Depth => ((Dimension == ResourceDimension.Texture3D) ? DepthOrArraySize : (ushort)(1));
public ushort ArraySize => ((Dimension != ResourceDimension.Texture3D) ? DepthOrArraySize : (ushort)(1));
public byte GetPlaneCount(ID3D12Device* pDevice)
{
return D3D12GetFormatPlaneCount(pDevice, Format);
}
public uint GetSubresources(ID3D12Device* pDevice)
{
return MipLevels * (uint)ArraySize * GetPlaneCount(pDevice);
}
public uint CalcSubresource(uint MipSlice, uint ArraySlice, uint PlaneSlice)
{
return D3D12CalcSubresource(MipSlice, ArraySlice, PlaneSlice, MipLevels, ArraySize);
}
public static bool operator ==(in ResourceDescription left, in ResourceDescription right)
{
return (left.Dimension == right.Dimension)
&& (left.Alignment == right.Alignment)
&& (left.Width == right.Width)
&& (left.Height == right.Height)
&& (left.DepthOrArraySize == right.DepthOrArraySize)
&& (left.MipLevels == right.MipLevels)
&& (left.Format == right.Format)
&& (left.SampleDesc.Count == right.SampleDesc.Count)
&& (left.SampleDesc.Quality == right.SampleDesc.Quality)
&& (left.Layout == right.Layout)
&& (left.Flags == right.Flags);
}
public static bool operator !=(in ResourceDescription l, in ResourceDescription r)
=> !(l == r);
public override bool Equals(object? obj) => (obj is ResourceDescription other) && Equals(other);
public bool Equals(ResourceDescription other) => this == other;
public override int GetHashCode()
{
var hashCode = new HashCode();
{
hashCode.Add(Dimension);
hashCode.Add(Alignment);
hashCode.Add(Width);
hashCode.Add(Height);
hashCode.Add(DepthOrArraySize);
hashCode.Add(MipLevels);
hashCode.Add(Format);
hashCode.Add(SampleDesc);
hashCode.Add(Layout);
hashCode.Add(Flags);
}
return hashCode.ToHashCode();
}
}

View File

@@ -0,0 +1,27 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
using Win32.Graphics.Dxgi.Common;
namespace Win32.Graphics.Direct3D12;
public unsafe partial struct SubresourceFootprint
{
public SubresourceFootprint(Format format, uint width, uint height, uint depth, uint rowPitch)
{
Format = format;
Width = width;
Height = height;
Depth = depth;
RowPitch = rowPitch;
}
public SubresourceFootprint(in ResourceDescription resourceDesc, uint rowPitch)
{
Format = resourceDesc.Format;
Width = (uint)resourceDesc.Width;
Height = resourceDesc.Height;
Depth = (resourceDesc.Dimension == ResourceDimension.Texture3D ? resourceDesc.DepthOrArraySize : 1u);
RowPitch = rowPitch;
}
}

View File

@@ -0,0 +1,35 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
namespace Win32.Graphics.Direct3D12;
public unsafe partial struct TextureCopyLocation
{
public TextureCopyLocation(ID3D12Resource* resource)
{
Unsafe.SkipInit(out this);
pResource = resource;
Type = TextureCopyType.SubresourceIndex;
Anonymous.PlacedFootprint = new PlacedSubresourceFootprint();
}
public TextureCopyLocation(ID3D12Resource* resource, in PlacedSubresourceFootprint footprint)
{
Unsafe.SkipInit(out this);
pResource = resource;
Type = TextureCopyType.PlacedFootprint;
Anonymous.PlacedFootprint = footprint;
}
public TextureCopyLocation(ID3D12Resource* resource, uint subresourceIndex)
{
Unsafe.SkipInit(out this);
pResource = resource;
Type = TextureCopyType.SubresourceIndex;
Anonymous.PlacedFootprint = new PlacedSubresourceFootprint();
Anonymous.SubresourceIndex = subresourceIndex;
}
}

View File

@@ -0,0 +1,560 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
namespace Win32.Graphics.Dxgi.Common;
/// <summary>
/// Helper to use with <see cref="Format"/>.
/// </summary>
public static class FormatHelper
{
public const Format Xbox_R10G10B10_7E3_A2_Float = (Format)116;
public const Format Xbox_R10G10B10_6E4_A2_Float = (Format)117;
public const Format Xbox_D16_UNorm_S8_UInt = (Format)118;
public const Format Xbox_R16_UNorm_X8_Typeless = (Format)119;
public const Format Xbox_X16_Typeless_G8_UInt = (Format)120;
public const Format Xbox_R10G10B10_SNorm_A2_UNorm = (Format)189;
public const Format Xbox_R4G4_UNorm = (Format)190;
/// <summary>
/// Return the BPP for a given <see cref="Format"/>.
/// </summary>
/// <param name="format">The DXGI format.</param>
/// <returns>BPP of </returns>
public static int GetBitsPerPixel(this Format format)
{
switch (format)
{
case Format.R32G32B32A32Typeless:
case Format.R32G32B32A32Float:
case Format.R32G32B32A32Uint:
case Format.R32G32B32A32Sint:
return 128;
case Format.R32G32B32Typeless:
case Format.R32G32B32Float:
case Format.R32G32B32Uint:
case Format.R32G32B32Sint:
return 96;
case Format.R16G16B16A16Typeless:
case Format.R16G16B16A16Float:
case Format.R16G16B16A16Unorm:
case Format.R16G16B16A16Uint:
case Format.R16G16B16A16Snorm:
case Format.R16G16B16A16Sint:
case Format.R32G32Typeless:
case Format.R32G32Float:
case Format.R32G32Uint:
case Format.R32G32Sint:
case Format.R32G8X24Typeless:
case Format.D32FloatS8X24Uint:
case Format.R32FloatX8X24Typeless:
case Format.X32TypelessG8X24Uint:
case Format.Y416:
case Format.Y210:
case Format.Y216:
return 64;
case Format.R10G10B10A2Typeless:
case Format.R10G10B10A2Unorm:
case Format.R10G10B10A2Uint:
case Format.R11G11B10Float:
case Format.R8G8B8A8Typeless:
case Format.R8G8B8A8Unorm:
case Format.R8G8B8A8UnormSrgb:
case Format.R8G8B8A8Snorm:
case Format.R8G8B8A8Uint:
case Format.R8G8B8A8Sint:
case Format.R16G16Typeless:
case Format.R16G16Float:
case Format.R16G16Unorm:
case Format.R16G16Snorm:
case Format.R16G16Uint:
case Format.R16G16Sint:
case Format.R32Typeless:
case Format.D32Float:
case Format.R32Float:
case Format.R32Uint:
case Format.R32Sint:
case Format.R24G8Typeless:
case Format.D24UnormS8Uint:
case Format.R24UnormX8Typeless:
case Format.X24TypelessG8Uint:
case Format.R9G9B9E5SharedExp:
case Format.R8G8B8G8Unorm:
case Format.G8R8G8B8Unorm:
case Format.B8G8R8A8Unorm:
case Format.B8G8R8X8Unorm:
case Format.R10G10B10XRBiasA2Unorm:
case Format.B8G8R8A8Typeless:
case Format.B8G8R8A8UnormSrgb:
case Format.B8G8R8X8Typeless:
case Format.B8G8R8X8UnormSrgb:
case Format.AYUV:
case Format.Y410:
case Format.YUY2:
case Xbox_R10G10B10_7E3_A2_Float:
case Xbox_R10G10B10_6E4_A2_Float:
case Xbox_R10G10B10_SNorm_A2_UNorm:
return 32;
case Format.P010:
case Format.P016:
case Xbox_D16_UNorm_S8_UInt:
case Xbox_R16_UNorm_X8_Typeless:
case Xbox_X16_Typeless_G8_UInt:
case Format.V408:
return 24;
case Format.R8G8Typeless:
case Format.R8G8Unorm:
case Format.R8G8Uint:
case Format.R8G8Snorm:
case Format.R8G8Sint:
case Format.R16Typeless:
case Format.R16Float:
case Format.D16Unorm:
case Format.R16Unorm:
case Format.R16Uint:
case Format.R16Snorm:
case Format.R16Sint:
case Format.B5G6R5Unorm:
case Format.B5G5R5A1Unorm:
case Format.A8P8:
case Format.B4G4R4A4Unorm:
case Format.P208:
case Format.V208:
return 16;
case Format.NV12:
case Format.Opaque420:
case Format.NV11:
return 12;
case Format.R8Typeless:
case Format.R8Unorm:
case Format.R8Uint:
case Format.R8Snorm:
case Format.R8Sint:
case Format.A8Unorm:
case Format.BC2Typeless:
case Format.BC2Unorm:
case Format.BC2UnormSrgb:
case Format.BC3Typeless:
case Format.BC3Unorm:
case Format.BC3UnormSrgb:
case Format.BC5Typeless:
case Format.BC5Unorm:
case Format.BC5Snorm:
case Format.BC6HTypeless:
case Format.BC6HUF16:
case Format.BC6HSF16:
case Format.BC7Typeless:
case Format.BC7Unorm:
case Format.BC7UnormSrgb:
case Format.AI44:
case Format.IA44:
case Format.P8:
case Xbox_R4G4_UNorm:
return 8;
case Format.R1Unorm:
return 1;
case Format.BC1Typeless:
case Format.BC1Unorm:
case Format.BC1UnormSrgb:
case Format.BC4Typeless:
case Format.BC4Unorm:
case Format.BC4Snorm:
return 4;
default:
return 0;
}
}
/// <summary>
/// Returns true if the <see cref="Format"/> is valid.
/// </summary>
/// <param name="format">A format to validate</param>
/// <returns>True if the <see cref="Format"/> is valid.</returns>
public static bool IsValid(this Format format)
{
return ((int)(format) >= 1 && (int)(format) <= 115);
}
/// <summary>
/// Returns true if the <see cref="Format"/> is a compressed format.
/// </summary>
/// <param name="format">The format to check for compressed.</param>
/// <returns>True if the <see cref="Format"/> is a compressed format</returns>
public static bool IsCompressed(this Format format)
{
switch (format)
{
case Format.BC1Typeless:
case Format.BC1Unorm:
case Format.BC1UnormSrgb:
case Format.BC2Typeless:
case Format.BC2Unorm:
case Format.BC2UnormSrgb:
case Format.BC3Typeless:
case Format.BC3Unorm:
case Format.BC3UnormSrgb:
case Format.BC4Typeless:
case Format.BC4Unorm:
case Format.BC4Snorm:
case Format.BC5Typeless:
case Format.BC5Unorm:
case Format.BC5Snorm:
case Format.BC6HTypeless:
case Format.BC6HUF16:
case Format.BC6HSF16:
case Format.BC7Typeless:
case Format.BC7Unorm:
case Format.BC7UnormSrgb:
return true;
default:
return false;
}
}
/// <summary>
/// Determines whether the specified <see cref="Format"/> is packed.
/// </summary>
/// <param name="format">The DXGI Format.</param>
/// <returns><c>true</c> if the specified <see cref="Format"/> is packed; otherwise, <c>false</c>.</returns>
public static bool IsPacked(this Format format)
{
switch (format)
{
case Format.R8G8B8G8Unorm:
case Format.G8R8G8B8Unorm:
case Format.YUY2: // 4:2:2 8-bit
case Format.Y210: // 4:2:2 10-bit
case Format.Y216: // 4:2:2 16-bit
return true;
default:
return false;
}
}
/// <summary>
/// Determines whether the specified <see cref="Format"/> is video.
/// </summary>
/// <param name="format">The <see cref="Format"/>.</param>
/// <returns><c>true</c> if the specified <see cref="Format"/> is video; otherwise, <c>false</c>.</returns>
public static bool IsVideo(this Format format)
{
switch (format)
{
case Format.AYUV:
case Format.Y410:
case Format.Y416:
case Format.NV12:
case Format.P010:
case Format.P016:
case Format.YUY2:
case Format.Y210:
case Format.Y216:
case Format.NV11:
// These video formats can be used with the 3D pipeline through special view mappings
case Format.Opaque420:
case Format.AI44:
case Format.IA44:
case Format.P8:
case Format.A8P8:
// These are limited use video formats not usable in any way by the 3D pipeline
case Format.P208:
case Format.V208:
case Format.V408:
// These video formats are for JPEG Hardware decode (DXGI 1.4)
return true;
default:
return false;
}
}
public static bool IsPlanar(this Format format)
{
switch (format)
{
case Format.NV12: // 4:2:0 8-bit
case Format.P010: // 4:2:0 10-bit
case Format.P016: // 4:2:0 16-bit
case Format.Opaque420:// 4:2:0 8-bit
case Format.NV11: // 4:1:1 8-bit
case Format.P208: // 4:2:2 8-bit
case Format.V208: // 4:4:0 8-bit
case Format.V408: // 4:4:4 8-bit
// These are JPEG Hardware decode formats (DXGI 1.4)
case Xbox_D16_UNorm_S8_UInt:
case Xbox_R16_UNorm_X8_Typeless:
case Xbox_X16_Typeless_G8_UInt:
// These are Xbox One platform specific types
return true;
default:
return false;
}
}
public static bool IsPalettized(this Format format)
{
switch (format)
{
case Format.AI44:
case Format.IA44:
case Format.P8:
case Format.A8P8:
return true;
default:
return false;
}
}
public static bool IsDepthStencil(this Format format)
{
switch (format)
{
case Format.R32G8X24Typeless:
case Format.D32FloatS8X24Uint:
case Format.R32FloatX8X24Typeless:
case Format.X32TypelessG8X24Uint:
case Format.D32Float:
case Format.R24G8Typeless:
case Format.D24UnormS8Uint:
case Format.R24UnormX8Typeless:
case Format.X24TypelessG8Uint:
case Format.D16Unorm:
case Xbox_D16_UNorm_S8_UInt:
case Xbox_R16_UNorm_X8_Typeless:
case Xbox_X16_Typeless_G8_UInt:
return true;
default:
return false;
}
}
/// <summary>
/// Determines whether the specified <see cref="Format"/> is a SRGB format.
/// </summary>
/// <param name="format">The <see cref="Format"/>.</param>
/// <returns><c>true</c> if the specified <see cref="Format"/> is a SRGB format; otherwise, <c>false</c>.</returns>
public static bool IsSRGB(this Format format)
{
switch (format)
{
case Format.R8G8B8A8UnormSrgb:
case Format.BC1UnormSrgb:
case Format.BC2UnormSrgb:
case Format.BC3UnormSrgb:
case Format.B8G8R8A8UnormSrgb:
case Format.B8G8R8X8UnormSrgb:
case Format.BC7UnormSrgb:
return true;
default:
return false;
}
}
/// <summary>
/// Determines whether the specified <see cref="Format"/> is typeless.
/// </summary>
/// <param name="format">The <see cref="Format"/>.</param>
/// <param name="partialTypeless"></param>
/// <returns><c>true</c> if the specified <see cref="Format"/> is typeless; otherwise, <c>false</c>.</returns>
public static bool IsTypeless(this Format format, bool partialTypeless = true)
{
switch (format)
{
case Format.R32G32B32A32Typeless:
case Format.R32G32B32Typeless:
case Format.R16G16B16A16Typeless:
case Format.R32G32Typeless:
case Format.R32G8X24Typeless:
case Format.R10G10B10A2Typeless:
case Format.R8G8B8A8Typeless:
case Format.R16G16Typeless:
case Format.R32Typeless:
case Format.R24G8Typeless:
case Format.R8G8Typeless:
case Format.R16Typeless:
case Format.R8Typeless:
case Format.BC1Typeless:
case Format.BC2Typeless:
case Format.BC3Typeless:
case Format.BC4Typeless:
case Format.BC5Typeless:
case Format.B8G8R8A8Typeless:
case Format.B8G8R8X8Typeless:
case Format.BC6HTypeless:
case Format.BC7Typeless:
return true;
case Format.R32FloatX8X24Typeless:
case Format.X32TypelessG8X24Uint:
case Format.R24UnormX8Typeless:
case Format.X24TypelessG8Uint:
case Xbox_R16_UNorm_X8_Typeless:
case Xbox_X16_Typeless_G8_UInt:
return partialTypeless;
default:
return false;
}
}
public static bool IsBGR(this Format format)
{
switch (format)
{
case Format.B5G6R5Unorm:
case Format.B5G5R5A1Unorm:
case Format.B8G8R8A8Unorm:
case Format.B8G8R8X8Unorm:
case Format.B8G8R8A8Typeless:
case Format.B8G8R8A8UnormSrgb:
case Format.B8G8R8X8Typeless:
case Format.B8G8R8X8UnormSrgb:
case Format.B4G4R4A4Unorm:
return true;
default:
return false;
}
}
public static void GetSurfaceInfo(
Format format,
int width,
int height,
out int rowPitch,
out int slicePitch,
out int rowCount)
{
bool bc = false;
bool packed = false;
bool planar = false;
int bpe = 0;
switch (format)
{
case Format.BC1Typeless:
case Format.BC1Unorm:
case Format.BC1UnormSrgb:
case Format.BC4Typeless:
case Format.BC4Unorm:
case Format.BC4Snorm:
bc = true;
bpe = 8;
break;
case Format.BC2Typeless:
case Format.BC2Unorm:
case Format.BC2UnormSrgb:
case Format.BC3Typeless:
case Format.BC3Unorm:
case Format.BC3UnormSrgb:
case Format.BC5Typeless:
case Format.BC5Unorm:
case Format.BC5Snorm:
case Format.BC6HTypeless:
case Format.BC6HUF16:
case Format.BC6HSF16:
case Format.BC7Typeless:
case Format.BC7Unorm:
case Format.BC7UnormSrgb:
bc = true;
bpe = 16;
break;
case Format.R8G8B8G8Unorm:
case Format.G8R8G8B8Unorm:
case Format.YUY2:
packed = true;
bpe = 4;
break;
case Format.Y210:
case Format.Y216:
packed = true;
bpe = 8;
break;
case Format.NV12:
case Format.Opaque420:
case Format.P208:
planar = true;
bpe = 2;
break;
case Format.P010:
case Format.P016:
planar = true;
bpe = 4;
break;
default:
break;
}
if (bc)
{
int numBlocksWide = 0;
if (width > 0)
{
numBlocksWide = Math.Max(1, (width + 3) / 4);
}
int numBlocksHigh = 0;
if (height > 0)
{
numBlocksHigh = Math.Max(1, (height + 3) / 4);
}
rowPitch = numBlocksWide * bpe;
rowCount = numBlocksHigh;
slicePitch = rowPitch * numBlocksHigh;
}
else if (packed)
{
rowPitch = ((width + 1) >> 1) * bpe;
rowCount = height;
slicePitch = rowPitch * height;
}
else if (format == Format.NV11)
{
rowPitch = ((width + 3) >> 2) * 4;
rowCount = height * 2; // Direct3D makes this simplifying assumption, although it is larger than the 4:1:1 data
slicePitch = rowPitch * rowCount;
}
else if (planar)
{
rowPitch = ((width + 1) >> 1) * bpe;
slicePitch = (rowPitch * height) + ((rowPitch * height + 1) >> 1);
rowCount = (int)(height + ((height + 1u) >> 1));
}
else
{
int bpp = GetBitsPerPixel(format);
rowPitch = (width * bpp + 7) / 8; // round up to nearest byte
rowCount = height;
slicePitch = rowPitch * height;
}
}
public static void GetSurfaceInfo(Format format, int width, int height, out int rowPitch, out int slicePitch)
{
GetSurfaceInfo(format, width, height, out rowPitch, out slicePitch, out _);
}
}

View File

@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>netstandard2.0;net6.0;</TargetFrameworks> <TargetFrameworks>netstandard2.0;net6.0;</TargetFrameworks>
<Description>Windows API low level bindings.</Description> <Description>Windows API low level bindings.</Description>
<VersionPrefix>1.5.4</VersionPrefix> <VersionPrefix>1.5.5</VersionPrefix>
<VersionSuffix Condition="'$(VersionSuffix)' == ''"></VersionSuffix> <VersionSuffix Condition="'$(VersionSuffix)' == ''"></VersionSuffix>
<GenerateDocumentationFile>true</GenerateDocumentationFile> <GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup> </PropertyGroup>