diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..4a07af4
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "src/Generator/win32json"]
+ path = src/Generator/win32json
+ url = https://github.com/marlersoft/win32json.git
diff --git a/src/Generator/ApiData.cs b/src/Generator/ApiData.cs
new file mode 100644
index 0000000..d8d2700
--- /dev/null
+++ b/src/Generator/ApiData.cs
@@ -0,0 +1,64 @@
+// Copyright © Amer Koleci and Contributors.
+// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
+
+#nullable disable
+
+namespace Generator;
+
+public class ApiDataArrayShape
+{
+ public int Size { get; set; }
+}
+
+public class ApiDataType
+{
+ public string Kind { get; set; }
+ public string Name { get; set; }
+
+ // Kind == Array
+ public ApiDataArrayShape Shape { get; set; }
+ public ApiDataType Child { get; set; }
+}
+
+public class ApiDataConstant
+{
+ public string Name { get; set; }
+ public ApiDataType Type { get; set; }
+ public string ValueType { get; set; }
+ public object Value { get; set; }
+}
+
+public class ApiEnumValue
+{
+ public string Name { get; set; }
+ public object Value { get; set; }
+}
+
+public class ApiStructField
+{
+ public string Name { get; set; }
+ public ApiDataType Type { get; set; }
+}
+
+public class ApiType
+{
+ public string Name { get; set; }
+ public string Kind { get; set; }
+
+ // Enum
+ public bool Flags { get; set; }
+ public bool Scoped { get; set; }
+ public string IntegerBase { get; set; }
+ public ApiEnumValue[] Values { get; set; }
+
+ // Struct
+ public int Size { get; set; }
+ public int PackingSize { get; set; }
+ public ApiStructField[] Fields { get; set; }
+}
+
+public sealed class ApiData
+{
+ public ApiDataConstant[] Constants { get; set; }
+ public ApiType[] Types { get; set; }
+}
diff --git a/src/Generator/CodeWriter.cs b/src/Generator/CodeWriter.cs
index 7ec0e05..34e0087 100644
--- a/src/Generator/CodeWriter.cs
+++ b/src/Generator/CodeWriter.cs
@@ -12,7 +12,7 @@ public sealed class CodeWriter : IDisposable
public int IndentLevel { get; private set; }
- public CodeWriter(string fileName, bool enableNullable, params string[] namespaces)
+ public CodeWriter(string fileName, string ns, params string[] usingNamespaces)
{
_indentStrings = new string[10];
for (int i = 0; i < _indentStrings.Length; i++)
@@ -31,23 +31,18 @@ public sealed class CodeWriter : IDisposable
_writer.WriteLine("// ------------------------------------------------------------------------------");
_writer.WriteLine();
- if (enableNullable)
+ _writer.WriteLine($"using System;");
+ _writer.WriteLine($"using System.Runtime.CompilerServices;");
+ _writer.WriteLine($"using System.Diagnostics.CodeAnalysis;");
+
+ foreach (string usingNamespace in usingNamespaces)
{
- _writer.WriteLine($"#nullable enable");
- _writer.WriteLine();
+ _writer.WriteLine($"using {usingNamespace};");
}
- foreach (string ns in namespaces)
- {
- _writer.WriteLine($"using {ns};");
- }
+ _writer.WriteLine();
- if (namespaces.Length > 0)
- {
- _writer.WriteLine();
- }
-
- _writer.WriteLine("namespace Vortice.Vulkan;");
+ _writer.WriteLine($"namespace {ns};");
_writer.WriteLine();
}
@@ -79,6 +74,12 @@ public sealed class CodeWriter : IDisposable
_shouldIndent = true;
}
+ public void WriteUndindented(string @string)
+ {
+ _writer.WriteLine(@string);
+ _shouldIndent = true;
+ }
+
public void BeginBlock(string content)
{
WriteLine(content);
diff --git a/src/Generator/Generator.csproj b/src/Generator/Generator.csproj
index 1d5d07e..597c081 100644
--- a/src/Generator/Generator.csproj
+++ b/src/Generator/Generator.csproj
@@ -8,10 +8,11 @@
-
- PreserveNewest
-
-
+
+
+
+
+
PreserveNewest
diff --git a/src/Generator/Program.cs b/src/Generator/Program.cs
index d58bdef..61f7846 100644
--- a/src/Generator/Program.cs
+++ b/src/Generator/Program.cs
@@ -1,10 +1,59 @@
// Copyright © Amer Koleci and Contributors.
// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
+using System.ComponentModel.DataAnnotations;
+using System.Text;
+using System.Xml.Linq;
+using Microsoft.VisualBasic.FileIO;
+using Newtonsoft.Json;
+
namespace Generator;
public static class Program
{
+ private static readonly string[] jsons = new[]
+ {
+ "Graphics.Dxgi.Common.json"
+ };
+
+ private static readonly Dictionary s_csNameMappings = new()
+ {
+ {"Void", "void" },
+ {"Byte", "byte" },
+ {"SByte", "sbyte" },
+ {"Int8", "sbyte" },
+ {"Int16", "short" },
+ {"Int32", "int" },
+ {"Int64", "long" },
+ {"UInt8", "byte" },
+ {"UInt16", "ushort" },
+ {"UInt32", "uint" },
+ {"UInt64", "ulong" },
+ {"Single", "float" },
+ {"Double", "double" },
+
+ { "BOOL", "Bool32" },
+ };
+
+ private static readonly Dictionary s_knownTypesPrefixes = new()
+ {
+ { "DXGI_COLOR_SPACE_TYPE", "DXGI_COLOR_SPACE" },
+ };
+
+ private static readonly Dictionary s_knownEnumValueNames = new()
+ {
+ { "DXGI_FORMAT_420_OPAQUE", "Opaque420" }
+ };
+
+ private static readonly HashSet s_ignoredParts = new(StringComparer.OrdinalIgnoreCase)
+ {
+ "DXGI"
+ };
+
+ private static readonly HashSet s_preserveCaps = new(StringComparer.OrdinalIgnoreCase)
+ {
+ };
+
public static int Main(string[] args)
{
string outputPath = AppContext.BaseDirectory;
@@ -23,6 +72,374 @@ public static class Program
Directory.CreateDirectory(outputPath);
}
+ foreach (string jsonFile in jsons)
+ {
+ string outputFolder = Path.Combine(outputPath, "Graphics");
+ if (!Directory.Exists(outputFolder))
+ {
+ Directory.CreateDirectory(outputFolder);
+ }
+
+ string finalPath = Path.Combine(AppContext.BaseDirectory, "win32json", "api", jsonFile);
+ string jsonData = File.ReadAllText(finalPath);
+ ApiData? api = JsonConvert.DeserializeObject(jsonData);
+ Generate(api!, outputFolder);
+ }
+
return 0;
}
+
+ private static void Generate(ApiData api, string outputPath)
+ {
+ using var writer = new CodeWriter(
+ Path.Combine(outputPath, "Dxgi.Common.cs"),
+ "Win32.Graphics.Dxgi");
+
+ GenerateConstants(writer, api);
+ GenerateTypes(writer, api);
+ }
+
+ private static void GenerateConstants(CodeWriter writer, ApiData api)
+ {
+ using (writer.PushBlock($"public static partial class Apis"))
+ {
+ foreach (var constant in api.Constants)
+ {
+ if (ShouldSkipConstant(constant))
+ continue;
+
+ string typeName = GetTypeName(constant.ValueType);
+ writer.WriteLine($"public const {typeName} {constant.Name} = {constant.Value};");
+ }
+ }
+ writer.WriteLine();
+ }
+
+ private static void GenerateTypes(CodeWriter writer, ApiData api)
+ {
+ writer.WriteLine($"#region Enums");
+ foreach (ApiType enumType in api.Types.Where(item => item.Kind.ToLowerInvariant() == "enum"))
+ {
+ GenerateEnum(writer, enumType);
+ }
+ writer.WriteLine($"#endregion Enums");
+ writer.WriteLine();
+
+ writer.WriteLine($"#region Structs");
+ foreach (ApiType structType in api.Types.Where(item => item.Kind.ToLowerInvariant() == "struct"))
+ {
+ GenerateStruct(writer, structType);
+ }
+ writer.WriteLine($"#endregion Structs");
+ writer.WriteLine();
+ }
+
+ private static void GenerateEnum(CodeWriter writer, ApiType enumType)
+ {
+ if (enumType.Flags)
+ {
+ writer.WriteLine("[Flags]");
+ }
+
+ string csTypeName = GetDataTypeName(enumType.Name, out string enumPrefix);
+ string baseTypeName = GetTypeName(enumType.IntegerBase);
+ AddCsMapping(enumType.Name, csTypeName);
+
+ writer.WriteLine($"/// {enumType.Name}");
+ using (writer.PushBlock($"public enum {csTypeName} : {baseTypeName}"))
+ {
+ foreach (ApiEnumValue value in enumType.Values)
+ {
+ if (value.Name.EndsWith("_FORCE_DWORD") ||
+ value.Name.EndsWith("_FORCE_UINT"))
+ continue;
+
+ string enumValueName = GetPrettyFieldName(value.Name, enumPrefix);
+ writer.WriteLine($"/// {value.Name}");
+ writer.WriteLine($"{enumValueName} = {value.Value},");
+ }
+ }
+
+ writer.WriteLine();
+ }
+
+ private static void GenerateStruct(CodeWriter writer, ApiType structType)
+ {
+ string csTypeName = GetDataTypeName(structType.Name, out string structPrefix);
+ AddCsMapping(structType.Name, csTypeName);
+
+ writer.WriteLine($"/// {structType.Name}");
+ using (writer.PushBlock($"public partial struct {csTypeName}"))
+ {
+ foreach (ApiStructField field in structType.Fields)
+ {
+ if (field.Name.EndsWith("_FORCE_DWORD"))
+ continue;
+
+ string fieldValueName = GetPrettyFieldName(field.Name, structPrefix);
+ string fieldTypeName = GetTypeName(field.Type);
+ //writer.WriteLine($"/// {field.Name}");
+
+ if (fieldTypeName == "Array")
+ {
+ bool canUseFixed = false;
+ if (field.Type.Child.Kind == "Native")
+ {
+ canUseFixed = true;
+ }
+
+ fieldTypeName = GetTypeName(field.Type.Child);
+
+ if (canUseFixed)
+ {
+ writer.WriteLine($"public unsafe fixed {fieldTypeName} {fieldValueName}[{field.Type.Shape.Size}];");
+ }
+ else
+ {
+ writer.WriteLine($"public {fieldValueName}__FixedBuffer {fieldValueName};");
+ writer.WriteLine();
+
+ using (writer.PushBlock($"public unsafe struct {fieldValueName}__FixedBuffer"))
+ {
+ for (int i = 0; i < field.Type.Shape.Size; i++)
+ {
+ writer.WriteLine($"public {fieldTypeName} e{i};");
+ }
+ writer.WriteLine();
+
+ writer.WriteLine("[UnscopedRef]");
+ using (writer.PushBlock($"public ref {fieldTypeName} this[int index]"))
+ {
+ writer.WriteLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]");
+ using (writer.PushBlock("get"))
+ {
+ writer.WriteLine($"return ref AsSpan()[index];");
+ }
+ }
+ writer.WriteLine();
+
+ writer.WriteLine("[UnscopedRef]");
+ writer.WriteLine("[MethodImpl(MethodImplOptions.AggressiveInlining)]");
+ using (writer.PushBlock($"public Span<{fieldTypeName}> AsSpan()"))
+ {
+ writer.WriteUndindented("#if NET6_0_OR_GREATER");
+ writer.WriteLine($"return MemoryMarshal.CreateSpan(ref e0, {field.Type.Shape.Size});");
+ writer.WriteUndindented("#else");
+ writer.WriteLine($"return new(Unsafe.AsPointer(ref e0), {field.Type.Shape.Size});");
+ writer.WriteUndindented("#endif");
+ }
+ }
+ }
+ }
+ else
+ {
+ writer.WriteLine($"public {fieldTypeName} {fieldValueName};");
+ }
+ }
+ }
+
+ writer.WriteLine();
+ }
+
+ private static bool ShouldSkipConstant(ApiDataConstant constant)
+ {
+ if (constant.Name == "_FACDXGI")
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ private static string GetDataTypeName(string typeName, out string prefix)
+ {
+ prefix = typeName;
+ if (s_knownTypesPrefixes.TryGetValue(typeName, out string? knowPrefix))
+ {
+ prefix = knowPrefix!;
+ }
+
+ string[] parts = typeName.Split(new[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
+
+ var sb = new StringBuilder();
+ foreach (string part in parts)
+ {
+ if (s_ignoredParts.Contains(part))
+ {
+ continue;
+ }
+
+ if (s_preserveCaps.Contains(part))
+ {
+ sb.Append(part);
+ }
+ else
+ {
+ if (part.Equals("DESC", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Description");
+ }
+ else
+ {
+ sb.Append(char.ToUpper(part[0]));
+ for (int i = 1; i < part.Length; i++)
+ {
+ sb.Append(char.ToLower(part[i]));
+ }
+ }
+ }
+ }
+
+ string prettyName = sb.ToString();
+ return (char.IsNumber(prettyName[0])) ? "_" + prettyName : prettyName;
+ }
+
+ private static string GetPrettyFieldName(string value, string enumPrefix)
+ {
+ if (s_knownEnumValueNames.TryGetValue(value, out string? knownName))
+ {
+ return knownName;
+ }
+
+ if (value.IndexOf(enumPrefix) != 0)
+ {
+ return value;
+ }
+
+ bool isDXGIFormat = enumPrefix == "DXGI_FORMAT";
+
+ string[] parts = value[enumPrefix.Length..].Split(new[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
+
+ var sb = new StringBuilder();
+ foreach (string part in parts)
+ {
+ if (s_ignoredParts.Contains(part))
+ {
+ continue;
+ }
+
+ if (s_preserveCaps.Contains(part))
+ {
+ sb.Append(part);
+ }
+ else
+ {
+ if (isDXGIFormat)
+ {
+ if (part.Equals("UNKNOWN", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Unknown");
+ }
+ else if (part.Equals("TYPELESS", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Typeless");
+ }
+ else if (part.Equals("UNORM", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Unorm");
+ }
+ else if (part.Equals("SNORM", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Snorm");
+ }
+ else if (part.Equals("UINT", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Uint");
+ }
+ else if (part.Equals("SINT", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Sint");
+ }
+ else if (part.Equals("FLOAT", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Float");
+ }
+ else if (part.Equals("SRGB", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Srgb");
+ }
+ else if (part.Equals("SHAREDEXP", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("SharedExp");
+ }
+ else if (part.Equals("SAMPLER", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Sampler");
+ }
+ else if (part.Equals("FEEDBACK", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Feedback");
+ }
+ else if (part.Equals("MIN", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Min");
+ }
+ else if (part.Equals("MIP", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Mip");
+ }
+ else if (part.Equals("OPAQUE", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Opaque");
+ }
+ else if (part.Equals("REGION", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Region");
+ }
+ else if (part.Equals("USED", StringComparison.OrdinalIgnoreCase))
+ {
+ sb.Append("Used");
+ }
+ else
+ {
+ sb.Append(part);
+ }
+ }
+ else
+ {
+ sb.Append(char.ToUpper(part[0]));
+ for (int i = 1; i < part.Length; i++)
+ {
+ sb.Append(char.ToLower(part[i]));
+ }
+ }
+ }
+ }
+
+ string prettyName = sb.ToString();
+ return (char.IsNumber(prettyName[0])) ? "_" + prettyName : prettyName;
+ }
+
+ private static string GetTypeName(ApiDataType dataType)
+ {
+ if (dataType.Kind == "ApiRef")
+ {
+ return GetTypeName(dataType.Name);
+ }
+ else if (dataType.Kind == "Array")
+ {
+ return "Array";
+ }
+ else if (dataType.Kind == "PointerTo")
+ {
+ throw new NotImplementedException();
+ }
+
+ return GetTypeName(dataType.Name);
+ }
+
+ private static void AddCsMapping(string typeName, string csTypeName)
+ {
+ s_csNameMappings[typeName] = csTypeName;
+ }
+
+ private static string GetTypeName(string name)
+ {
+ if (s_csNameMappings.TryGetValue(name, out string? mappedName))
+ {
+ return mappedName;
+ }
+
+ return name;
+ }
}
diff --git a/src/Generator/win32json b/src/Generator/win32json
new file mode 160000
index 0000000..d7c046e
--- /dev/null
+++ b/src/Generator/win32json
@@ -0,0 +1 @@
+Subproject commit d7c046e6989ffecb61f666ed62cb19226d131f28
diff --git a/src/Vortice.Win32/Attributes.cs b/src/Vortice.Win32/Attributes.cs
new file mode 100644
index 0000000..40e0b8c
--- /dev/null
+++ b/src/Vortice.Win32/Attributes.cs
@@ -0,0 +1,39 @@
+// Copyright © Amer Koleci and Contributors.
+// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
+// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
+
+using System.Diagnostics;
+
+namespace Win32;
+
+/// Defines the type of a member as it was used in the native signature.
+[AttributeUsage(AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter | AttributeTargets.ReturnValue, AllowMultiple = false, Inherited = true)]
+[Conditional("DEBUG")]
+internal sealed partial class NativeTypeNameAttribute : Attribute
+{
+ /// Initializes a new instance of the class.
+ /// The name of the type that was used in the native signature.
+ public NativeTypeNameAttribute(string name)
+ {
+ Name = name;
+ }
+
+ /// Gets the name of the type that was used in the native signature.
+ public string Name { get; }
+}
+
+/// Defines the vtbl index of a method as it was in the native signature.
+[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
+[Conditional("DEBUG")]
+internal sealed partial class VtblIndexAttribute : Attribute
+{
+ /// Initializes a new instance of the class.
+ /// The vtbl index of a method as it was in the native signature.
+ public VtblIndexAttribute(uint index)
+ {
+ Index = index;
+ }
+
+ /// Gets the vtbl index of a method as it was in the native signature.
+ public uint Index { get; }
+}
diff --git a/src/Vortice.Win32/Bool32.cs b/src/Vortice.Win32/Bool32.cs
new file mode 100644
index 0000000..bd11ff2
--- /dev/null
+++ b/src/Vortice.Win32/Bool32.cs
@@ -0,0 +1,99 @@
+// Copyright © Amer Koleci and Contributors.
+// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
+
+namespace Win32;
+
+public readonly partial struct Bool32 : IComparable, IComparable, IEquatable, IFormattable
+{
+ public readonly int Value;
+
+ public Bool32(int value)
+ {
+ Value = value;
+ }
+
+ public static Bool32 True => new Bool32(1);
+ public static Bool32 False => new Bool32(0);
+
+ public static bool operator ==(Bool32 left, Bool32 right) => left.Value == right.Value;
+
+ public static bool operator !=(Bool32 left, Bool32 right) => left.Value != right.Value;
+
+ public static bool operator <(Bool32 left, Bool32 right) => left.Value < right.Value;
+
+ public static bool operator <=(Bool32 left, Bool32 right) => left.Value <= right.Value;
+
+ public static bool operator >(Bool32 left, Bool32 right) => left.Value > right.Value;
+
+ public static bool operator >=(Bool32 left, Bool32 right) => left.Value >= right.Value;
+
+ public static implicit operator bool(Bool32 value) => value.Value != 0;
+
+ public static implicit operator Bool32(bool value) => new Bool32(value ? 1 : 0);
+
+ public static bool operator false(Bool32 value) => value.Value == 0;
+
+ public static bool operator true(Bool32 value) => value.Value != 0;
+
+ public static implicit operator Bool32(byte value) => new Bool32(value);
+
+ public static explicit operator byte(Bool32 value) => (byte)(value.Value);
+
+ public static implicit operator Bool32(short value) => new Bool32(value);
+
+ public static explicit operator short(Bool32 value) => (short)(value.Value);
+
+ public static implicit operator Bool32(int value) => new Bool32(value);
+
+ public static implicit operator int(Bool32 value) => value.Value;
+
+ public static explicit operator Bool32(long value) => new Bool32(unchecked((int)(value)));
+
+ public static implicit operator long(Bool32 value) => value.Value;
+
+ public static explicit operator Bool32(nint value) => new Bool32(unchecked((int)(value)));
+
+ public static implicit operator nint(Bool32 value) => value.Value;
+
+ public static implicit operator Bool32(sbyte value) => new Bool32(value);
+
+ public static explicit operator sbyte(Bool32 value) => (sbyte)(value.Value);
+
+ public static implicit operator Bool32(ushort value) => new Bool32(value);
+
+ public static explicit operator ushort(Bool32 value) => (ushort)(value.Value);
+
+ public static explicit operator Bool32(uint value) => new Bool32(unchecked((int)(value)));
+
+ public static explicit operator uint(Bool32 value) => (uint)(value.Value);
+
+ public static explicit operator Bool32(ulong value) => new Bool32(unchecked((int)(value)));
+
+ public static explicit operator ulong(Bool32 value) => (ulong)(value.Value);
+
+ public static explicit operator Bool32(nuint value) => new Bool32(unchecked((int)(value)));
+
+ public static explicit operator nuint(Bool32 value) => (nuint)(value.Value);
+
+ public int CompareTo(object? obj)
+ {
+ if (obj is Bool32 other)
+ {
+ return CompareTo(other);
+ }
+
+ return (obj is null) ? 1 : throw new ArgumentException("obj is not an instance of Bool32.");
+ }
+
+ public int CompareTo(Bool32 other) => Value.CompareTo(other.Value);
+
+ public override bool Equals(object? obj) => (obj is Bool32 other) && Equals(other);
+
+ public bool Equals(Bool32 other) => Value.Equals(other.Value);
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString();
+
+ public string ToString(string? format, IFormatProvider? formatProvider) => Value.ToString(format, formatProvider);
+}
diff --git a/src/Vortice.Win32/ComPtr.cs b/src/Vortice.Win32/ComPtr.cs
new file mode 100644
index 0000000..71c7a94
--- /dev/null
+++ b/src/Vortice.Win32/ComPtr.cs
@@ -0,0 +1,318 @@
+// Copyright © Tanner Gooding and Contributors. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
+// Ported from winrt/wrl/client.h in the Windows SDK for Windows 10.0.22621.0
+// Original source is Copyright © Microsoft. All rights reserved.
+
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+using static Win32.Apis;
+
+namespace Win32;
+
+/// A type that allows working with pointers to COM objects more securely.
+/// The type to wrap in the current instance.
+/// While this type is not marked as so that it can also be used in fields, make sure to keep the reference counts properly tracked if you do store instances on the heap.
+public unsafe struct ComPtr : IDisposable
+ where T : unmanaged, IUnknown.Interface
+{
+ /// The raw pointer to a COM object, if existing.
+ private T* ptr_;
+
+ /// Creates a new instance from a raw pointer and increments the ref count.
+ /// The raw pointer to wrap.
+ public ComPtr(T* other)
+ {
+ ptr_ = other;
+ InternalAddRef();
+ }
+
+ /// Creates a new instance from a second one and increments the ref count.
+ /// The other instance to copy.
+ public ComPtr(ComPtr other)
+ {
+ ptr_ = other.ptr_;
+ InternalAddRef();
+ }
+
+ /// Converts a raw pointer to a new instance and increments the ref count.
+ /// The raw pointer to wrap.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static implicit operator ComPtr(T* other)
+ => new ComPtr(other);
+
+ /// Unwraps a instance and returns the internal raw pointer.
+ /// The instance to unwrap.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static implicit operator T*(ComPtr other)
+ => other.Get();
+
+ /// Converts the current object reference to type and assigns that to a target value.
+ /// The interface type to use to try casting the current COM object.
+ /// A raw pointer to the target value to write to.
+ /// The result of for the target type .
+ /// This method will automatically release the target COM object pointed to by , if any.
+ public readonly HResult As(ComPtr* p)
+ where U : unmanaged, IUnknown.Interface
+ {
+ return ptr_->QueryInterface(__uuidof(), (void**)p->ReleaseAndGetAddressOf());
+ }
+
+ /// Converts the current object reference to type and assigns that to a target value.
+ /// The interface type to use to try casting the current COM object.
+ /// A reference to the target value to write to.
+ /// The result of for the target type .
+ /// This method will automatically release the target COM object pointed to by , if any.
+ public readonly HResult As(ref ComPtr other)
+ where U : unmanaged, IUnknown.Interface
+ {
+ U* ptr;
+ HResult result = ptr_->QueryInterface(__uuidof(), (void**)&ptr);
+
+ other.Attach(ptr);
+ return result;
+ }
+
+ /// Converts the current object reference to a type indicated by the given IID and assigns that to a target value.
+ /// The IID indicating the interface type to convert the COM object reference to.
+ /// A raw pointer to the target value to write to.
+ /// The result of for the target IID.
+ /// This method will automatically release the target COM object pointed to by , if any.
+ public readonly HResult AsIID(Guid* riid, ComPtr* other)
+ {
+ return ptr_->QueryInterface(riid, (void**)other->ReleaseAndGetAddressOf());
+ }
+
+ /// Converts the current object reference to a type indicated by the given IID and assigns that to a target value.
+ /// The IID indicating the interface type to convert the COM object reference to.
+ /// A reference to the target value to write to.
+ /// The result of for the target IID.
+ /// This method will automatically release the target COM object pointed to by , if any.
+ public readonly HResult AsIID(Guid* riid, ref ComPtr other)
+ {
+ IUnknown* ptr;
+ HResult result = ptr_->QueryInterface(riid, (void**)&ptr);
+
+ other.Attach(ptr);
+ return result;
+ }
+
+ /// Releases the current COM object, if any, and replaces the internal pointer with an input raw pointer.
+ /// The input raw pointer to wrap.
+ /// This method will release the current raw pointer, if any, but it will not increment the references for .
+ public void Attach(T* other)
+ {
+ if (ptr_ != null)
+ {
+ var @ref = ptr_->Release();
+ Debug.Assert((@ref != 0) || (ptr_ != other));
+ }
+ ptr_ = other;
+ }
+
+ /// Returns the raw pointer wrapped by the current instance, and resets the current value.
+ /// The raw pointer wrapped by the current value.
+ /// This method will not change the reference count for the COM object in use.
+ public T* Detach()
+ {
+ T* ptr = ptr_;
+ ptr_ = null;
+ return ptr;
+ }
+
+ /// Increments the reference count for the current COM object, if any, and copies its address to a target raw pointer.
+ /// The target raw pointer to copy the address of the current COM object to.
+ /// This method always returns .
+ public readonly HResult CopyTo(T** ptr)
+ {
+ InternalAddRef();
+ *ptr = ptr_;
+ return HResult.Ok;
+ }
+
+ /// Increments the reference count for the current COM object, if any, and copies its address to a target .
+ /// The target raw pointer to copy the address of the current COM object to.
+ /// This method always returns .
+ public readonly HResult CopyTo(ComPtr* p)
+ {
+ InternalAddRef();
+ *p->ReleaseAndGetAddressOf() = ptr_;
+ return HResult.Ok;
+ }
+
+ /// Increments the reference count for the current COM object, if any, and copies its address to a target .
+ /// The target reference to copy the address of the current COM object to.
+ /// This method always returns .
+ public readonly HResult CopyTo(ref ComPtr other)
+ {
+ InternalAddRef();
+ other.Attach(ptr_);
+ return HResult.Ok;
+ }
+
+ /// Converts the current COM object reference to a given interface type and assigns that to a target raw pointer.
+ /// The target raw pointer to copy the address of the current COM object to.
+ /// The result of for the target type .
+ public readonly HResult CopyTo(U** ptr)
+ where U : unmanaged, IUnknown.Interface
+ {
+ return ptr_->QueryInterface(__uuidof(), (void**)ptr);
+ }
+
+ /// Converts the current COM object reference to a given interface type and assigns that to a target .
+ /// The target raw pointer to copy the address of the current COM object to.
+ /// The result of for the target type .
+ public readonly HResult CopyTo(ComPtr* p)
+ where U : unmanaged, IUnknown.Interface
+ {
+ return ptr_->QueryInterface(__uuidof(), (void**)p->ReleaseAndGetAddressOf());
+ }
+
+ /// Converts the current COM object reference to a given interface type and assigns that to a target .
+ /// The target reference to copy the address of the current COM object to.
+ /// The result of for the target type .
+ public readonly HResult CopyTo(ref ComPtr other)
+ where U : unmanaged, IUnknown.Interface
+ {
+ U* ptr;
+ HResult result = ptr_->QueryInterface(__uuidof(), (void**)&ptr);
+
+ other.Attach(ptr);
+ return result;
+ }
+
+ /// Converts the current object reference to a type indicated by the given IID and assigns that to a target address.
+ /// The IID indicating the interface type to convert the COM object reference to.
+ /// The target raw pointer to copy the address of the current COM object to.
+ /// The result of for the target IID.
+ public readonly HResult CopyTo(Guid* riid, void** ptr)
+ {
+ return ptr_->QueryInterface(riid, ptr);
+ }
+
+ /// Converts the current object reference to a type indicated by the given IID and assigns that to a target value.
+ /// The IID indicating the interface type to convert the COM object reference to.
+ /// The target raw pointer to copy the address of the current COM object to.
+ /// The result of for the target IID.
+ public readonly HResult CopyTo(Guid* riid, ComPtr* p)
+ {
+ return ptr_->QueryInterface(riid, (void**)p->ReleaseAndGetAddressOf());
+ }
+
+ /// Converts the current object reference to a type indicated by the given IID and assigns that to a target value.
+ /// The IID indicating the interface type to convert the COM object reference to.
+ /// The target reference to copy the address of the current COM object to.
+ /// The result of for the target IID.
+ public readonly HResult CopyTo(Guid* riid, ref ComPtr other)
+ {
+ IUnknown* ptr;
+ HResult result = ptr_->QueryInterface(riid, (void**)&ptr);
+
+ other.Attach(ptr);
+ return result;
+ }
+
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public void Dispose()
+ {
+ T* pointer = ptr_;
+
+ if (pointer != null)
+ {
+ ptr_ = null;
+ _ = pointer->Release();
+ }
+ }
+
+ /// Gets the currently wrapped raw pointer to a COM object.
+ /// The raw pointer wrapped by the current instance.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly T* Get()
+ {
+ return ptr_;
+ }
+
+ /// Gets the address of the current instance as a raw double pointer. This method is only valid when the current instance is on the stack or pinned.
+ ///
+ /// The raw pointer to the current instance.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public readonly T** GetAddressOf()
+ {
+ return (T**)Unsafe.AsPointer(ref Unsafe.AsRef(in this));
+ }
+
+ /// Gets the address of the current instance as a raw double pointer.
+ /// The raw pointer to the current instance.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public readonly ref T* GetPinnableReference()
+ {
+ fixed (T** ptr = &ptr_)
+ {
+ return ref *ptr;
+ }
+ }
+
+ /// Releases the current COM object in use and gets the address of the instance as a raw double pointer. This method is only valid when the current instance is on the stack or pinned.
+ /// The raw pointer to the current instance.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public T** ReleaseAndGetAddressOf()
+ {
+ _ = InternalRelease();
+ return GetAddressOf();
+ }
+
+ /// Resets the current instance by decrementing the reference count for the target COM object and setting the internal raw pointer to .
+ /// The updated reference count for the COM object that was in use, if any.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public uint Reset()
+ {
+ return InternalRelease();
+ }
+
+ /// Swaps the current COM object reference with that of a given instance.
+ /// The target instance to swap with the current one.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public void Swap(ComPtr* r)
+ {
+ T* tmp = ptr_;
+ ptr_ = r->ptr_;
+ r->ptr_ = tmp;
+ }
+
+ /// Swaps the current COM object reference with that of a given instance.
+ /// The target instance to swap with the current one.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public void Swap(ref ComPtr other)
+ {
+ T* tmp = ptr_;
+ ptr_ = other.ptr_;
+ other.ptr_ = tmp;
+ }
+
+ // Increments the reference count for the current COM object, if any
+ private readonly void InternalAddRef()
+ {
+ T* temp = ptr_;
+
+ if (temp != null)
+ {
+ _ = temp->AddRef();
+ }
+ }
+
+ // Decrements the reference count for the current COM object, if any
+ private uint InternalRelease()
+ {
+ uint @ref = 0;
+ T* temp = ptr_;
+
+ if (temp != null)
+ {
+ ptr_ = null;
+ @ref = temp->Release();
+ }
+
+ return @ref;
+ }
+}
diff --git a/src/Vortice.Win32/Generated/Graphics/Dxgi.Common.cs b/src/Vortice.Win32/Generated/Graphics/Dxgi.Common.cs
new file mode 100644
index 0000000..e62ae26
--- /dev/null
+++ b/src/Vortice.Win32/Generated/Graphics/Dxgi.Common.cs
@@ -0,0 +1,1510 @@
+// ------------------------------------------------------------------------------
+//
+// This code was generated by a tool.
+//
+// Changes to this file may cause incorrect behavior and will be lost if
+// the code is regenerated.
+//
+// ------------------------------------------------------------------------------
+
+using System;
+using System.Runtime.CompilerServices;
+using System.Diagnostics.CodeAnalysis;
+
+namespace Win32.Graphics.Dxgi;
+
+public static partial class Apis
+{
+ public const uint DXGI_CPU_ACCESS_NONE = 0;
+ public const uint DXGI_CPU_ACCESS_DYNAMIC = 1;
+ public const uint DXGI_CPU_ACCESS_READ_WRITE = 2;
+ public const uint DXGI_CPU_ACCESS_SCRATCH = 3;
+ public const uint DXGI_CPU_ACCESS_FIELD = 15;
+ public const uint DXGI_FORMAT_DEFINED = 1;
+ public const uint DXGI_STANDARD_MULTISAMPLE_QUALITY_PATTERN = 4294967295;
+ public const uint DXGI_CENTER_MULTISAMPLE_QUALITY_PATTERN = 4294967294;
+}
+
+#region Enums
+/// DXGI_COLOR_SPACE_TYPE
+public enum ColorSpaceType : int
+{
+ /// DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P709
+ RgbFullG22NoneP709 = 0,
+ /// DXGI_COLOR_SPACE_RGB_FULL_G10_NONE_P709
+ RgbFullG10NoneP709 = 1,
+ /// DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P709
+ RgbStudioG22NoneP709 = 2,
+ /// DXGI_COLOR_SPACE_RGB_STUDIO_G22_NONE_P2020
+ RgbStudioG22NoneP2020 = 3,
+ /// DXGI_COLOR_SPACE_RESERVED
+ Reserved = 4,
+ /// DXGI_COLOR_SPACE_YCBCR_FULL_G22_NONE_P709_X601
+ YcbcrFullG22NoneP709X601 = 5,
+ /// DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P601
+ YcbcrStudioG22LeftP601 = 6,
+ /// DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P601
+ YcbcrFullG22LeftP601 = 7,
+ /// DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P709
+ YcbcrStudioG22LeftP709 = 8,
+ /// DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P709
+ YcbcrFullG22LeftP709 = 9,
+ /// DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_LEFT_P2020
+ YcbcrStudioG22LeftP2020 = 10,
+ /// DXGI_COLOR_SPACE_YCBCR_FULL_G22_LEFT_P2020
+ YcbcrFullG22LeftP2020 = 11,
+ /// DXGI_COLOR_SPACE_RGB_FULL_G2084_NONE_P2020
+ RgbFullG2084NoneP2020 = 12,
+ /// DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_LEFT_P2020
+ YcbcrStudioG2084LeftP2020 = 13,
+ /// DXGI_COLOR_SPACE_RGB_STUDIO_G2084_NONE_P2020
+ RgbStudioG2084NoneP2020 = 14,
+ /// DXGI_COLOR_SPACE_YCBCR_STUDIO_G22_TOPLEFT_P2020
+ YcbcrStudioG22TopleftP2020 = 15,
+ /// DXGI_COLOR_SPACE_YCBCR_STUDIO_G2084_TOPLEFT_P2020
+ YcbcrStudioG2084TopleftP2020 = 16,
+ /// DXGI_COLOR_SPACE_RGB_FULL_G22_NONE_P2020
+ RgbFullG22NoneP2020 = 17,
+ /// DXGI_COLOR_SPACE_YCBCR_STUDIO_GHLG_TOPLEFT_P2020
+ YcbcrStudioGhlgTopleftP2020 = 18,
+ /// DXGI_COLOR_SPACE_YCBCR_FULL_GHLG_TOPLEFT_P2020
+ YcbcrFullGhlgTopleftP2020 = 19,
+ /// DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P709
+ RgbStudioG24NoneP709 = 20,
+ /// DXGI_COLOR_SPACE_RGB_STUDIO_G24_NONE_P2020
+ RgbStudioG24NoneP2020 = 21,
+ /// DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P709
+ YcbcrStudioG24LeftP709 = 22,
+ /// DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_LEFT_P2020
+ YcbcrStudioG24LeftP2020 = 23,
+ /// DXGI_COLOR_SPACE_YCBCR_STUDIO_G24_TOPLEFT_P2020
+ YcbcrStudioG24TopleftP2020 = 24,
+ /// DXGI_COLOR_SPACE_CUSTOM
+ Custom = -1,
+}
+
+/// DXGI_FORMAT
+public enum Format : uint
+{
+ /// DXGI_FORMAT_UNKNOWN
+ Unknown = 0,
+ /// DXGI_FORMAT_R32G32B32A32_TYPELESS
+ R32G32B32A32Typeless = 1,
+ /// DXGI_FORMAT_R32G32B32A32_FLOAT
+ R32G32B32A32Float = 2,
+ /// DXGI_FORMAT_R32G32B32A32_UINT
+ R32G32B32A32Uint = 3,
+ /// DXGI_FORMAT_R32G32B32A32_SINT
+ R32G32B32A32Sint = 4,
+ /// DXGI_FORMAT_R32G32B32_TYPELESS
+ R32G32B32Typeless = 5,
+ /// DXGI_FORMAT_R32G32B32_FLOAT
+ R32G32B32Float = 6,
+ /// DXGI_FORMAT_R32G32B32_UINT
+ R32G32B32Uint = 7,
+ /// DXGI_FORMAT_R32G32B32_SINT
+ R32G32B32Sint = 8,
+ /// DXGI_FORMAT_R16G16B16A16_TYPELESS
+ R16G16B16A16Typeless = 9,
+ /// DXGI_FORMAT_R16G16B16A16_FLOAT
+ R16G16B16A16Float = 10,
+ /// DXGI_FORMAT_R16G16B16A16_UNORM
+ R16G16B16A16Unorm = 11,
+ /// DXGI_FORMAT_R16G16B16A16_UINT
+ R16G16B16A16Uint = 12,
+ /// DXGI_FORMAT_R16G16B16A16_SNORM
+ R16G16B16A16Snorm = 13,
+ /// DXGI_FORMAT_R16G16B16A16_SINT
+ R16G16B16A16Sint = 14,
+ /// DXGI_FORMAT_R32G32_TYPELESS
+ R32G32Typeless = 15,
+ /// DXGI_FORMAT_R32G32_FLOAT
+ R32G32Float = 16,
+ /// DXGI_FORMAT_R32G32_UINT
+ R32G32Uint = 17,
+ /// DXGI_FORMAT_R32G32_SINT
+ R32G32Sint = 18,
+ /// DXGI_FORMAT_R32G8X24_TYPELESS
+ R32G8X24Typeless = 19,
+ /// DXGI_FORMAT_D32_FLOAT_S8X24_UINT
+ D32FloatS8X24Uint = 20,
+ /// DXGI_FORMAT_R32_FLOAT_X8X24_TYPELESS
+ R32FloatX8X24Typeless = 21,
+ /// DXGI_FORMAT_X32_TYPELESS_G8X24_UINT
+ X32TypelessG8X24Uint = 22,
+ /// DXGI_FORMAT_R10G10B10A2_TYPELESS
+ R10G10B10A2Typeless = 23,
+ /// DXGI_FORMAT_R10G10B10A2_UNORM
+ R10G10B10A2Unorm = 24,
+ /// DXGI_FORMAT_R10G10B10A2_UINT
+ R10G10B10A2Uint = 25,
+ /// DXGI_FORMAT_R11G11B10_FLOAT
+ R11G11B10Float = 26,
+ /// DXGI_FORMAT_R8G8B8A8_TYPELESS
+ R8G8B8A8Typeless = 27,
+ /// DXGI_FORMAT_R8G8B8A8_UNORM
+ R8G8B8A8Unorm = 28,
+ /// DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
+ R8G8B8A8UnormSrgb = 29,
+ /// DXGI_FORMAT_R8G8B8A8_UINT
+ R8G8B8A8Uint = 30,
+ /// DXGI_FORMAT_R8G8B8A8_SNORM
+ R8G8B8A8Snorm = 31,
+ /// DXGI_FORMAT_R8G8B8A8_SINT
+ R8G8B8A8Sint = 32,
+ /// DXGI_FORMAT_R16G16_TYPELESS
+ R16G16Typeless = 33,
+ /// DXGI_FORMAT_R16G16_FLOAT
+ R16G16Float = 34,
+ /// DXGI_FORMAT_R16G16_UNORM
+ R16G16Unorm = 35,
+ /// DXGI_FORMAT_R16G16_UINT
+ R16G16Uint = 36,
+ /// DXGI_FORMAT_R16G16_SNORM
+ R16G16Snorm = 37,
+ /// DXGI_FORMAT_R16G16_SINT
+ R16G16Sint = 38,
+ /// DXGI_FORMAT_R32_TYPELESS
+ R32Typeless = 39,
+ /// DXGI_FORMAT_D32_FLOAT
+ D32Float = 40,
+ /// DXGI_FORMAT_R32_FLOAT
+ R32Float = 41,
+ /// DXGI_FORMAT_R32_UINT
+ R32Uint = 42,
+ /// DXGI_FORMAT_R32_SINT
+ R32Sint = 43,
+ /// DXGI_FORMAT_R24G8_TYPELESS
+ R24G8Typeless = 44,
+ /// DXGI_FORMAT_D24_UNORM_S8_UINT
+ D24UnormS8Uint = 45,
+ /// DXGI_FORMAT_R24_UNORM_X8_TYPELESS
+ R24UnormX8Typeless = 46,
+ /// DXGI_FORMAT_X24_TYPELESS_G8_UINT
+ X24TypelessG8Uint = 47,
+ /// DXGI_FORMAT_R8G8_TYPELESS
+ R8G8Typeless = 48,
+ /// DXGI_FORMAT_R8G8_UNORM
+ R8G8Unorm = 49,
+ /// DXGI_FORMAT_R8G8_UINT
+ R8G8Uint = 50,
+ /// DXGI_FORMAT_R8G8_SNORM
+ R8G8Snorm = 51,
+ /// DXGI_FORMAT_R8G8_SINT
+ R8G8Sint = 52,
+ /// DXGI_FORMAT_R16_TYPELESS
+ R16Typeless = 53,
+ /// DXGI_FORMAT_R16_FLOAT
+ R16Float = 54,
+ /// DXGI_FORMAT_D16_UNORM
+ D16Unorm = 55,
+ /// DXGI_FORMAT_R16_UNORM
+ R16Unorm = 56,
+ /// DXGI_FORMAT_R16_UINT
+ R16Uint = 57,
+ /// DXGI_FORMAT_R16_SNORM
+ R16Snorm = 58,
+ /// DXGI_FORMAT_R16_SINT
+ R16Sint = 59,
+ /// DXGI_FORMAT_R8_TYPELESS
+ R8Typeless = 60,
+ /// DXGI_FORMAT_R8_UNORM
+ R8Unorm = 61,
+ /// DXGI_FORMAT_R8_UINT
+ R8Uint = 62,
+ /// DXGI_FORMAT_R8_SNORM
+ R8Snorm = 63,
+ /// DXGI_FORMAT_R8_SINT
+ R8Sint = 64,
+ /// DXGI_FORMAT_A8_UNORM
+ A8Unorm = 65,
+ /// DXGI_FORMAT_R1_UNORM
+ R1Unorm = 66,
+ /// DXGI_FORMAT_R9G9B9E5_SHAREDEXP
+ R9G9B9E5SharedExp = 67,
+ /// DXGI_FORMAT_R8G8_B8G8_UNORM
+ R8G8B8G8Unorm = 68,
+ /// DXGI_FORMAT_G8R8_G8B8_UNORM
+ G8R8G8B8Unorm = 69,
+ /// DXGI_FORMAT_BC1_TYPELESS
+ BC1Typeless = 70,
+ /// DXGI_FORMAT_BC1_UNORM
+ BC1Unorm = 71,
+ /// DXGI_FORMAT_BC1_UNORM_SRGB
+ BC1UnormSrgb = 72,
+ /// DXGI_FORMAT_BC2_TYPELESS
+ BC2Typeless = 73,
+ /// DXGI_FORMAT_BC2_UNORM
+ BC2Unorm = 74,
+ /// DXGI_FORMAT_BC2_UNORM_SRGB
+ BC2UnormSrgb = 75,
+ /// DXGI_FORMAT_BC3_TYPELESS
+ BC3Typeless = 76,
+ /// DXGI_FORMAT_BC3_UNORM
+ BC3Unorm = 77,
+ /// DXGI_FORMAT_BC3_UNORM_SRGB
+ BC3UnormSrgb = 78,
+ /// DXGI_FORMAT_BC4_TYPELESS
+ BC4Typeless = 79,
+ /// DXGI_FORMAT_BC4_UNORM
+ BC4Unorm = 80,
+ /// DXGI_FORMAT_BC4_SNORM
+ BC4Snorm = 81,
+ /// DXGI_FORMAT_BC5_TYPELESS
+ BC5Typeless = 82,
+ /// DXGI_FORMAT_BC5_UNORM
+ BC5Unorm = 83,
+ /// DXGI_FORMAT_BC5_SNORM
+ BC5Snorm = 84,
+ /// DXGI_FORMAT_B5G6R5_UNORM
+ B5G6R5Unorm = 85,
+ /// DXGI_FORMAT_B5G5R5A1_UNORM
+ B5G5R5A1Unorm = 86,
+ /// DXGI_FORMAT_B8G8R8A8_UNORM
+ B8G8R8A8Unorm = 87,
+ /// DXGI_FORMAT_B8G8R8X8_UNORM
+ B8G8R8X8Unorm = 88,
+ /// DXGI_FORMAT_R10G10B10_XR_BIAS_A2_UNORM
+ R10G10B10XRBIASA2Unorm = 89,
+ /// DXGI_FORMAT_B8G8R8A8_TYPELESS
+ B8G8R8A8Typeless = 90,
+ /// DXGI_FORMAT_B8G8R8A8_UNORM_SRGB
+ B8G8R8A8UnormSrgb = 91,
+ /// DXGI_FORMAT_B8G8R8X8_TYPELESS
+ B8G8R8X8Typeless = 92,
+ /// DXGI_FORMAT_B8G8R8X8_UNORM_SRGB
+ B8G8R8X8UnormSrgb = 93,
+ /// DXGI_FORMAT_BC6H_TYPELESS
+ BC6HTypeless = 94,
+ /// DXGI_FORMAT_BC6H_UF16
+ BC6HUF16 = 95,
+ /// DXGI_FORMAT_BC6H_SF16
+ BC6HSF16 = 96,
+ /// DXGI_FORMAT_BC7_TYPELESS
+ BC7Typeless = 97,
+ /// DXGI_FORMAT_BC7_UNORM
+ BC7Unorm = 98,
+ /// DXGI_FORMAT_BC7_UNORM_SRGB
+ BC7UnormSrgb = 99,
+ /// DXGI_FORMAT_AYUV
+ AYUV = 100,
+ /// DXGI_FORMAT_Y410
+ Y410 = 101,
+ /// DXGI_FORMAT_Y416
+ Y416 = 102,
+ /// DXGI_FORMAT_NV12
+ NV12 = 103,
+ /// DXGI_FORMAT_P010
+ P010 = 104,
+ /// DXGI_FORMAT_P016
+ P016 = 105,
+ /// DXGI_FORMAT_420_OPAQUE
+ Opaque420 = 106,
+ /// DXGI_FORMAT_YUY2
+ YUY2 = 107,
+ /// DXGI_FORMAT_Y210
+ Y210 = 108,
+ /// DXGI_FORMAT_Y216
+ Y216 = 109,
+ /// DXGI_FORMAT_NV11
+ NV11 = 110,
+ /// DXGI_FORMAT_AI44
+ AI44 = 111,
+ /// DXGI_FORMAT_IA44
+ IA44 = 112,
+ /// DXGI_FORMAT_P8
+ P8 = 113,
+ /// DXGI_FORMAT_A8P8
+ A8P8 = 114,
+ /// DXGI_FORMAT_B4G4R4A4_UNORM
+ B4G4R4A4Unorm = 115,
+ /// DXGI_FORMAT_P208
+ P208 = 130,
+ /// DXGI_FORMAT_V208
+ V208 = 131,
+ /// DXGI_FORMAT_V408
+ V408 = 132,
+ /// DXGI_FORMAT_SAMPLER_FEEDBACK_MIN_MIP_OPAQUE
+ SamplerFeedbackMinMipOpaque = 189,
+ /// DXGI_FORMAT_SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE
+ SamplerFeedbackMipRegionUsedOpaque = 190,
+}
+
+/// DXGI_MODE_SCANLINE_ORDER
+public enum ModeScanlineOrder : int
+{
+ /// DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED
+ Unspecified = 0,
+ /// DXGI_MODE_SCANLINE_ORDER_PROGRESSIVE
+ Progressive = 1,
+ /// DXGI_MODE_SCANLINE_ORDER_UPPER_FIELD_FIRST
+ UpperFieldFirst = 2,
+ /// DXGI_MODE_SCANLINE_ORDER_LOWER_FIELD_FIRST
+ LowerFieldFirst = 3,
+}
+
+/// DXGI_MODE_SCALING
+public enum ModeScaling : int
+{
+ /// DXGI_MODE_SCALING_UNSPECIFIED
+ Unspecified = 0,
+ /// DXGI_MODE_SCALING_CENTERED
+ Centered = 1,
+ /// DXGI_MODE_SCALING_STRETCHED
+ Stretched = 2,
+}
+
+/// DXGI_MODE_ROTATION
+public enum ModeRotation : int
+{
+ /// DXGI_MODE_ROTATION_UNSPECIFIED
+ Unspecified = 0,
+ /// DXGI_MODE_ROTATION_IDENTITY
+ Identity = 1,
+ /// DXGI_MODE_ROTATION_ROTATE90
+ Rotate90 = 2,
+ /// DXGI_MODE_ROTATION_ROTATE180
+ Rotate180 = 3,
+ /// DXGI_MODE_ROTATION_ROTATE270
+ Rotate270 = 4,
+}
+
+/// DXGI_ALPHA_MODE
+public enum AlphaMode : uint
+{
+ /// DXGI_ALPHA_MODE_UNSPECIFIED
+ Unspecified = 0,
+ /// DXGI_ALPHA_MODE_PREMULTIPLIED
+ Premultiplied = 1,
+ /// DXGI_ALPHA_MODE_STRAIGHT
+ Straight = 2,
+ /// DXGI_ALPHA_MODE_IGNORE
+ Ignore = 3,
+}
+
+#endregion Enums
+
+#region Structs
+/// DXGI_RATIONAL
+public partial struct Rational
+{
+ public uint Numerator;
+ public uint Denominator;
+}
+
+/// DXGI_SAMPLE_DESC
+public partial struct SampleDescription
+{
+ public uint Count;
+ public uint Quality;
+}
+
+/// DXGI_RGB
+public partial struct Rgb
+{
+ public float Red;
+ public float Green;
+ public float Blue;
+}
+
+/// DXGI_GAMMA_CONTROL
+public partial struct GammaControl
+{
+ public Rgb Scale;
+ public Rgb Offset;
+ public GammaCurve__FixedBuffer GammaCurve;
+
+ public unsafe struct GammaCurve__FixedBuffer
+ {
+ public Rgb e0;
+ public Rgb e1;
+ public Rgb e2;
+ public Rgb e3;
+ public Rgb e4;
+ public Rgb e5;
+ public Rgb e6;
+ public Rgb e7;
+ public Rgb e8;
+ public Rgb e9;
+ public Rgb e10;
+ public Rgb e11;
+ public Rgb e12;
+ public Rgb e13;
+ public Rgb e14;
+ public Rgb e15;
+ public Rgb e16;
+ public Rgb e17;
+ public Rgb e18;
+ public Rgb e19;
+ public Rgb e20;
+ public Rgb e21;
+ public Rgb e22;
+ public Rgb e23;
+ public Rgb e24;
+ public Rgb e25;
+ public Rgb e26;
+ public Rgb e27;
+ public Rgb e28;
+ public Rgb e29;
+ public Rgb e30;
+ public Rgb e31;
+ public Rgb e32;
+ public Rgb e33;
+ public Rgb e34;
+ public Rgb e35;
+ public Rgb e36;
+ public Rgb e37;
+ public Rgb e38;
+ public Rgb e39;
+ public Rgb e40;
+ public Rgb e41;
+ public Rgb e42;
+ public Rgb e43;
+ public Rgb e44;
+ public Rgb e45;
+ public Rgb e46;
+ public Rgb e47;
+ public Rgb e48;
+ public Rgb e49;
+ public Rgb e50;
+ public Rgb e51;
+ public Rgb e52;
+ public Rgb e53;
+ public Rgb e54;
+ public Rgb e55;
+ public Rgb e56;
+ public Rgb e57;
+ public Rgb e58;
+ public Rgb e59;
+ public Rgb e60;
+ public Rgb e61;
+ public Rgb e62;
+ public Rgb e63;
+ public Rgb e64;
+ public Rgb e65;
+ public Rgb e66;
+ public Rgb e67;
+ public Rgb e68;
+ public Rgb e69;
+ public Rgb e70;
+ public Rgb e71;
+ public Rgb e72;
+ public Rgb e73;
+ public Rgb e74;
+ public Rgb e75;
+ public Rgb e76;
+ public Rgb e77;
+ public Rgb e78;
+ public Rgb e79;
+ public Rgb e80;
+ public Rgb e81;
+ public Rgb e82;
+ public Rgb e83;
+ public Rgb e84;
+ public Rgb e85;
+ public Rgb e86;
+ public Rgb e87;
+ public Rgb e88;
+ public Rgb e89;
+ public Rgb e90;
+ public Rgb e91;
+ public Rgb e92;
+ public Rgb e93;
+ public Rgb e94;
+ public Rgb e95;
+ public Rgb e96;
+ public Rgb e97;
+ public Rgb e98;
+ public Rgb e99;
+ public Rgb e100;
+ public Rgb e101;
+ public Rgb e102;
+ public Rgb e103;
+ public Rgb e104;
+ public Rgb e105;
+ public Rgb e106;
+ public Rgb e107;
+ public Rgb e108;
+ public Rgb e109;
+ public Rgb e110;
+ public Rgb e111;
+ public Rgb e112;
+ public Rgb e113;
+ public Rgb e114;
+ public Rgb e115;
+ public Rgb e116;
+ public Rgb e117;
+ public Rgb e118;
+ public Rgb e119;
+ public Rgb e120;
+ public Rgb e121;
+ public Rgb e122;
+ public Rgb e123;
+ public Rgb e124;
+ public Rgb e125;
+ public Rgb e126;
+ public Rgb e127;
+ public Rgb e128;
+ public Rgb e129;
+ public Rgb e130;
+ public Rgb e131;
+ public Rgb e132;
+ public Rgb e133;
+ public Rgb e134;
+ public Rgb e135;
+ public Rgb e136;
+ public Rgb e137;
+ public Rgb e138;
+ public Rgb e139;
+ public Rgb e140;
+ public Rgb e141;
+ public Rgb e142;
+ public Rgb e143;
+ public Rgb e144;
+ public Rgb e145;
+ public Rgb e146;
+ public Rgb e147;
+ public Rgb e148;
+ public Rgb e149;
+ public Rgb e150;
+ public Rgb e151;
+ public Rgb e152;
+ public Rgb e153;
+ public Rgb e154;
+ public Rgb e155;
+ public Rgb e156;
+ public Rgb e157;
+ public Rgb e158;
+ public Rgb e159;
+ public Rgb e160;
+ public Rgb e161;
+ public Rgb e162;
+ public Rgb e163;
+ public Rgb e164;
+ public Rgb e165;
+ public Rgb e166;
+ public Rgb e167;
+ public Rgb e168;
+ public Rgb e169;
+ public Rgb e170;
+ public Rgb e171;
+ public Rgb e172;
+ public Rgb e173;
+ public Rgb e174;
+ public Rgb e175;
+ public Rgb e176;
+ public Rgb e177;
+ public Rgb e178;
+ public Rgb e179;
+ public Rgb e180;
+ public Rgb e181;
+ public Rgb e182;
+ public Rgb e183;
+ public Rgb e184;
+ public Rgb e185;
+ public Rgb e186;
+ public Rgb e187;
+ public Rgb e188;
+ public Rgb e189;
+ public Rgb e190;
+ public Rgb e191;
+ public Rgb e192;
+ public Rgb e193;
+ public Rgb e194;
+ public Rgb e195;
+ public Rgb e196;
+ public Rgb e197;
+ public Rgb e198;
+ public Rgb e199;
+ public Rgb e200;
+ public Rgb e201;
+ public Rgb e202;
+ public Rgb e203;
+ public Rgb e204;
+ public Rgb e205;
+ public Rgb e206;
+ public Rgb e207;
+ public Rgb e208;
+ public Rgb e209;
+ public Rgb e210;
+ public Rgb e211;
+ public Rgb e212;
+ public Rgb e213;
+ public Rgb e214;
+ public Rgb e215;
+ public Rgb e216;
+ public Rgb e217;
+ public Rgb e218;
+ public Rgb e219;
+ public Rgb e220;
+ public Rgb e221;
+ public Rgb e222;
+ public Rgb e223;
+ public Rgb e224;
+ public Rgb e225;
+ public Rgb e226;
+ public Rgb e227;
+ public Rgb e228;
+ public Rgb e229;
+ public Rgb e230;
+ public Rgb e231;
+ public Rgb e232;
+ public Rgb e233;
+ public Rgb e234;
+ public Rgb e235;
+ public Rgb e236;
+ public Rgb e237;
+ public Rgb e238;
+ public Rgb e239;
+ public Rgb e240;
+ public Rgb e241;
+ public Rgb e242;
+ public Rgb e243;
+ public Rgb e244;
+ public Rgb e245;
+ public Rgb e246;
+ public Rgb e247;
+ public Rgb e248;
+ public Rgb e249;
+ public Rgb e250;
+ public Rgb e251;
+ public Rgb e252;
+ public Rgb e253;
+ public Rgb e254;
+ public Rgb e255;
+ public Rgb e256;
+ public Rgb e257;
+ public Rgb e258;
+ public Rgb e259;
+ public Rgb e260;
+ public Rgb e261;
+ public Rgb e262;
+ public Rgb e263;
+ public Rgb e264;
+ public Rgb e265;
+ public Rgb e266;
+ public Rgb e267;
+ public Rgb e268;
+ public Rgb e269;
+ public Rgb e270;
+ public Rgb e271;
+ public Rgb e272;
+ public Rgb e273;
+ public Rgb e274;
+ public Rgb e275;
+ public Rgb e276;
+ public Rgb e277;
+ public Rgb e278;
+ public Rgb e279;
+ public Rgb e280;
+ public Rgb e281;
+ public Rgb e282;
+ public Rgb e283;
+ public Rgb e284;
+ public Rgb e285;
+ public Rgb e286;
+ public Rgb e287;
+ public Rgb e288;
+ public Rgb e289;
+ public Rgb e290;
+ public Rgb e291;
+ public Rgb e292;
+ public Rgb e293;
+ public Rgb e294;
+ public Rgb e295;
+ public Rgb e296;
+ public Rgb e297;
+ public Rgb e298;
+ public Rgb e299;
+ public Rgb e300;
+ public Rgb e301;
+ public Rgb e302;
+ public Rgb e303;
+ public Rgb e304;
+ public Rgb e305;
+ public Rgb e306;
+ public Rgb e307;
+ public Rgb e308;
+ public Rgb e309;
+ public Rgb e310;
+ public Rgb e311;
+ public Rgb e312;
+ public Rgb e313;
+ public Rgb e314;
+ public Rgb e315;
+ public Rgb e316;
+ public Rgb e317;
+ public Rgb e318;
+ public Rgb e319;
+ public Rgb e320;
+ public Rgb e321;
+ public Rgb e322;
+ public Rgb e323;
+ public Rgb e324;
+ public Rgb e325;
+ public Rgb e326;
+ public Rgb e327;
+ public Rgb e328;
+ public Rgb e329;
+ public Rgb e330;
+ public Rgb e331;
+ public Rgb e332;
+ public Rgb e333;
+ public Rgb e334;
+ public Rgb e335;
+ public Rgb e336;
+ public Rgb e337;
+ public Rgb e338;
+ public Rgb e339;
+ public Rgb e340;
+ public Rgb e341;
+ public Rgb e342;
+ public Rgb e343;
+ public Rgb e344;
+ public Rgb e345;
+ public Rgb e346;
+ public Rgb e347;
+ public Rgb e348;
+ public Rgb e349;
+ public Rgb e350;
+ public Rgb e351;
+ public Rgb e352;
+ public Rgb e353;
+ public Rgb e354;
+ public Rgb e355;
+ public Rgb e356;
+ public Rgb e357;
+ public Rgb e358;
+ public Rgb e359;
+ public Rgb e360;
+ public Rgb e361;
+ public Rgb e362;
+ public Rgb e363;
+ public Rgb e364;
+ public Rgb e365;
+ public Rgb e366;
+ public Rgb e367;
+ public Rgb e368;
+ public Rgb e369;
+ public Rgb e370;
+ public Rgb e371;
+ public Rgb e372;
+ public Rgb e373;
+ public Rgb e374;
+ public Rgb e375;
+ public Rgb e376;
+ public Rgb e377;
+ public Rgb e378;
+ public Rgb e379;
+ public Rgb e380;
+ public Rgb e381;
+ public Rgb e382;
+ public Rgb e383;
+ public Rgb e384;
+ public Rgb e385;
+ public Rgb e386;
+ public Rgb e387;
+ public Rgb e388;
+ public Rgb e389;
+ public Rgb e390;
+ public Rgb e391;
+ public Rgb e392;
+ public Rgb e393;
+ public Rgb e394;
+ public Rgb e395;
+ public Rgb e396;
+ public Rgb e397;
+ public Rgb e398;
+ public Rgb e399;
+ public Rgb e400;
+ public Rgb e401;
+ public Rgb e402;
+ public Rgb e403;
+ public Rgb e404;
+ public Rgb e405;
+ public Rgb e406;
+ public Rgb e407;
+ public Rgb e408;
+ public Rgb e409;
+ public Rgb e410;
+ public Rgb e411;
+ public Rgb e412;
+ public Rgb e413;
+ public Rgb e414;
+ public Rgb e415;
+ public Rgb e416;
+ public Rgb e417;
+ public Rgb e418;
+ public Rgb e419;
+ public Rgb e420;
+ public Rgb e421;
+ public Rgb e422;
+ public Rgb e423;
+ public Rgb e424;
+ public Rgb e425;
+ public Rgb e426;
+ public Rgb e427;
+ public Rgb e428;
+ public Rgb e429;
+ public Rgb e430;
+ public Rgb e431;
+ public Rgb e432;
+ public Rgb e433;
+ public Rgb e434;
+ public Rgb e435;
+ public Rgb e436;
+ public Rgb e437;
+ public Rgb e438;
+ public Rgb e439;
+ public Rgb e440;
+ public Rgb e441;
+ public Rgb e442;
+ public Rgb e443;
+ public Rgb e444;
+ public Rgb e445;
+ public Rgb e446;
+ public Rgb e447;
+ public Rgb e448;
+ public Rgb e449;
+ public Rgb e450;
+ public Rgb e451;
+ public Rgb e452;
+ public Rgb e453;
+ public Rgb e454;
+ public Rgb e455;
+ public Rgb e456;
+ public Rgb e457;
+ public Rgb e458;
+ public Rgb e459;
+ public Rgb e460;
+ public Rgb e461;
+ public Rgb e462;
+ public Rgb e463;
+ public Rgb e464;
+ public Rgb e465;
+ public Rgb e466;
+ public Rgb e467;
+ public Rgb e468;
+ public Rgb e469;
+ public Rgb e470;
+ public Rgb e471;
+ public Rgb e472;
+ public Rgb e473;
+ public Rgb e474;
+ public Rgb e475;
+ public Rgb e476;
+ public Rgb e477;
+ public Rgb e478;
+ public Rgb e479;
+ public Rgb e480;
+ public Rgb e481;
+ public Rgb e482;
+ public Rgb e483;
+ public Rgb e484;
+ public Rgb e485;
+ public Rgb e486;
+ public Rgb e487;
+ public Rgb e488;
+ public Rgb e489;
+ public Rgb e490;
+ public Rgb e491;
+ public Rgb e492;
+ public Rgb e493;
+ public Rgb e494;
+ public Rgb e495;
+ public Rgb e496;
+ public Rgb e497;
+ public Rgb e498;
+ public Rgb e499;
+ public Rgb e500;
+ public Rgb e501;
+ public Rgb e502;
+ public Rgb e503;
+ public Rgb e504;
+ public Rgb e505;
+ public Rgb e506;
+ public Rgb e507;
+ public Rgb e508;
+ public Rgb e509;
+ public Rgb e510;
+ public Rgb e511;
+ public Rgb e512;
+ public Rgb e513;
+ public Rgb e514;
+ public Rgb e515;
+ public Rgb e516;
+ public Rgb e517;
+ public Rgb e518;
+ public Rgb e519;
+ public Rgb e520;
+ public Rgb e521;
+ public Rgb e522;
+ public Rgb e523;
+ public Rgb e524;
+ public Rgb e525;
+ public Rgb e526;
+ public Rgb e527;
+ public Rgb e528;
+ public Rgb e529;
+ public Rgb e530;
+ public Rgb e531;
+ public Rgb e532;
+ public Rgb e533;
+ public Rgb e534;
+ public Rgb e535;
+ public Rgb e536;
+ public Rgb e537;
+ public Rgb e538;
+ public Rgb e539;
+ public Rgb e540;
+ public Rgb e541;
+ public Rgb e542;
+ public Rgb e543;
+ public Rgb e544;
+ public Rgb e545;
+ public Rgb e546;
+ public Rgb e547;
+ public Rgb e548;
+ public Rgb e549;
+ public Rgb e550;
+ public Rgb e551;
+ public Rgb e552;
+ public Rgb e553;
+ public Rgb e554;
+ public Rgb e555;
+ public Rgb e556;
+ public Rgb e557;
+ public Rgb e558;
+ public Rgb e559;
+ public Rgb e560;
+ public Rgb e561;
+ public Rgb e562;
+ public Rgb e563;
+ public Rgb e564;
+ public Rgb e565;
+ public Rgb e566;
+ public Rgb e567;
+ public Rgb e568;
+ public Rgb e569;
+ public Rgb e570;
+ public Rgb e571;
+ public Rgb e572;
+ public Rgb e573;
+ public Rgb e574;
+ public Rgb e575;
+ public Rgb e576;
+ public Rgb e577;
+ public Rgb e578;
+ public Rgb e579;
+ public Rgb e580;
+ public Rgb e581;
+ public Rgb e582;
+ public Rgb e583;
+ public Rgb e584;
+ public Rgb e585;
+ public Rgb e586;
+ public Rgb e587;
+ public Rgb e588;
+ public Rgb e589;
+ public Rgb e590;
+ public Rgb e591;
+ public Rgb e592;
+ public Rgb e593;
+ public Rgb e594;
+ public Rgb e595;
+ public Rgb e596;
+ public Rgb e597;
+ public Rgb e598;
+ public Rgb e599;
+ public Rgb e600;
+ public Rgb e601;
+ public Rgb e602;
+ public Rgb e603;
+ public Rgb e604;
+ public Rgb e605;
+ public Rgb e606;
+ public Rgb e607;
+ public Rgb e608;
+ public Rgb e609;
+ public Rgb e610;
+ public Rgb e611;
+ public Rgb e612;
+ public Rgb e613;
+ public Rgb e614;
+ public Rgb e615;
+ public Rgb e616;
+ public Rgb e617;
+ public Rgb e618;
+ public Rgb e619;
+ public Rgb e620;
+ public Rgb e621;
+ public Rgb e622;
+ public Rgb e623;
+ public Rgb e624;
+ public Rgb e625;
+ public Rgb e626;
+ public Rgb e627;
+ public Rgb e628;
+ public Rgb e629;
+ public Rgb e630;
+ public Rgb e631;
+ public Rgb e632;
+ public Rgb e633;
+ public Rgb e634;
+ public Rgb e635;
+ public Rgb e636;
+ public Rgb e637;
+ public Rgb e638;
+ public Rgb e639;
+ public Rgb e640;
+ public Rgb e641;
+ public Rgb e642;
+ public Rgb e643;
+ public Rgb e644;
+ public Rgb e645;
+ public Rgb e646;
+ public Rgb e647;
+ public Rgb e648;
+ public Rgb e649;
+ public Rgb e650;
+ public Rgb e651;
+ public Rgb e652;
+ public Rgb e653;
+ public Rgb e654;
+ public Rgb e655;
+ public Rgb e656;
+ public Rgb e657;
+ public Rgb e658;
+ public Rgb e659;
+ public Rgb e660;
+ public Rgb e661;
+ public Rgb e662;
+ public Rgb e663;
+ public Rgb e664;
+ public Rgb e665;
+ public Rgb e666;
+ public Rgb e667;
+ public Rgb e668;
+ public Rgb e669;
+ public Rgb e670;
+ public Rgb e671;
+ public Rgb e672;
+ public Rgb e673;
+ public Rgb e674;
+ public Rgb e675;
+ public Rgb e676;
+ public Rgb e677;
+ public Rgb e678;
+ public Rgb e679;
+ public Rgb e680;
+ public Rgb e681;
+ public Rgb e682;
+ public Rgb e683;
+ public Rgb e684;
+ public Rgb e685;
+ public Rgb e686;
+ public Rgb e687;
+ public Rgb e688;
+ public Rgb e689;
+ public Rgb e690;
+ public Rgb e691;
+ public Rgb e692;
+ public Rgb e693;
+ public Rgb e694;
+ public Rgb e695;
+ public Rgb e696;
+ public Rgb e697;
+ public Rgb e698;
+ public Rgb e699;
+ public Rgb e700;
+ public Rgb e701;
+ public Rgb e702;
+ public Rgb e703;
+ public Rgb e704;
+ public Rgb e705;
+ public Rgb e706;
+ public Rgb e707;
+ public Rgb e708;
+ public Rgb e709;
+ public Rgb e710;
+ public Rgb e711;
+ public Rgb e712;
+ public Rgb e713;
+ public Rgb e714;
+ public Rgb e715;
+ public Rgb e716;
+ public Rgb e717;
+ public Rgb e718;
+ public Rgb e719;
+ public Rgb e720;
+ public Rgb e721;
+ public Rgb e722;
+ public Rgb e723;
+ public Rgb e724;
+ public Rgb e725;
+ public Rgb e726;
+ public Rgb e727;
+ public Rgb e728;
+ public Rgb e729;
+ public Rgb e730;
+ public Rgb e731;
+ public Rgb e732;
+ public Rgb e733;
+ public Rgb e734;
+ public Rgb e735;
+ public Rgb e736;
+ public Rgb e737;
+ public Rgb e738;
+ public Rgb e739;
+ public Rgb e740;
+ public Rgb e741;
+ public Rgb e742;
+ public Rgb e743;
+ public Rgb e744;
+ public Rgb e745;
+ public Rgb e746;
+ public Rgb e747;
+ public Rgb e748;
+ public Rgb e749;
+ public Rgb e750;
+ public Rgb e751;
+ public Rgb e752;
+ public Rgb e753;
+ public Rgb e754;
+ public Rgb e755;
+ public Rgb e756;
+ public Rgb e757;
+ public Rgb e758;
+ public Rgb e759;
+ public Rgb e760;
+ public Rgb e761;
+ public Rgb e762;
+ public Rgb e763;
+ public Rgb e764;
+ public Rgb e765;
+ public Rgb e766;
+ public Rgb e767;
+ public Rgb e768;
+ public Rgb e769;
+ public Rgb e770;
+ public Rgb e771;
+ public Rgb e772;
+ public Rgb e773;
+ public Rgb e774;
+ public Rgb e775;
+ public Rgb e776;
+ public Rgb e777;
+ public Rgb e778;
+ public Rgb e779;
+ public Rgb e780;
+ public Rgb e781;
+ public Rgb e782;
+ public Rgb e783;
+ public Rgb e784;
+ public Rgb e785;
+ public Rgb e786;
+ public Rgb e787;
+ public Rgb e788;
+ public Rgb e789;
+ public Rgb e790;
+ public Rgb e791;
+ public Rgb e792;
+ public Rgb e793;
+ public Rgb e794;
+ public Rgb e795;
+ public Rgb e796;
+ public Rgb e797;
+ public Rgb e798;
+ public Rgb e799;
+ public Rgb e800;
+ public Rgb e801;
+ public Rgb e802;
+ public Rgb e803;
+ public Rgb e804;
+ public Rgb e805;
+ public Rgb e806;
+ public Rgb e807;
+ public Rgb e808;
+ public Rgb e809;
+ public Rgb e810;
+ public Rgb e811;
+ public Rgb e812;
+ public Rgb e813;
+ public Rgb e814;
+ public Rgb e815;
+ public Rgb e816;
+ public Rgb e817;
+ public Rgb e818;
+ public Rgb e819;
+ public Rgb e820;
+ public Rgb e821;
+ public Rgb e822;
+ public Rgb e823;
+ public Rgb e824;
+ public Rgb e825;
+ public Rgb e826;
+ public Rgb e827;
+ public Rgb e828;
+ public Rgb e829;
+ public Rgb e830;
+ public Rgb e831;
+ public Rgb e832;
+ public Rgb e833;
+ public Rgb e834;
+ public Rgb e835;
+ public Rgb e836;
+ public Rgb e837;
+ public Rgb e838;
+ public Rgb e839;
+ public Rgb e840;
+ public Rgb e841;
+ public Rgb e842;
+ public Rgb e843;
+ public Rgb e844;
+ public Rgb e845;
+ public Rgb e846;
+ public Rgb e847;
+ public Rgb e848;
+ public Rgb e849;
+ public Rgb e850;
+ public Rgb e851;
+ public Rgb e852;
+ public Rgb e853;
+ public Rgb e854;
+ public Rgb e855;
+ public Rgb e856;
+ public Rgb e857;
+ public Rgb e858;
+ public Rgb e859;
+ public Rgb e860;
+ public Rgb e861;
+ public Rgb e862;
+ public Rgb e863;
+ public Rgb e864;
+ public Rgb e865;
+ public Rgb e866;
+ public Rgb e867;
+ public Rgb e868;
+ public Rgb e869;
+ public Rgb e870;
+ public Rgb e871;
+ public Rgb e872;
+ public Rgb e873;
+ public Rgb e874;
+ public Rgb e875;
+ public Rgb e876;
+ public Rgb e877;
+ public Rgb e878;
+ public Rgb e879;
+ public Rgb e880;
+ public Rgb e881;
+ public Rgb e882;
+ public Rgb e883;
+ public Rgb e884;
+ public Rgb e885;
+ public Rgb e886;
+ public Rgb e887;
+ public Rgb e888;
+ public Rgb e889;
+ public Rgb e890;
+ public Rgb e891;
+ public Rgb e892;
+ public Rgb e893;
+ public Rgb e894;
+ public Rgb e895;
+ public Rgb e896;
+ public Rgb e897;
+ public Rgb e898;
+ public Rgb e899;
+ public Rgb e900;
+ public Rgb e901;
+ public Rgb e902;
+ public Rgb e903;
+ public Rgb e904;
+ public Rgb e905;
+ public Rgb e906;
+ public Rgb e907;
+ public Rgb e908;
+ public Rgb e909;
+ public Rgb e910;
+ public Rgb e911;
+ public Rgb e912;
+ public Rgb e913;
+ public Rgb e914;
+ public Rgb e915;
+ public Rgb e916;
+ public Rgb e917;
+ public Rgb e918;
+ public Rgb e919;
+ public Rgb e920;
+ public Rgb e921;
+ public Rgb e922;
+ public Rgb e923;
+ public Rgb e924;
+ public Rgb e925;
+ public Rgb e926;
+ public Rgb e927;
+ public Rgb e928;
+ public Rgb e929;
+ public Rgb e930;
+ public Rgb e931;
+ public Rgb e932;
+ public Rgb e933;
+ public Rgb e934;
+ public Rgb e935;
+ public Rgb e936;
+ public Rgb e937;
+ public Rgb e938;
+ public Rgb e939;
+ public Rgb e940;
+ public Rgb e941;
+ public Rgb e942;
+ public Rgb e943;
+ public Rgb e944;
+ public Rgb e945;
+ public Rgb e946;
+ public Rgb e947;
+ public Rgb e948;
+ public Rgb e949;
+ public Rgb e950;
+ public Rgb e951;
+ public Rgb e952;
+ public Rgb e953;
+ public Rgb e954;
+ public Rgb e955;
+ public Rgb e956;
+ public Rgb e957;
+ public Rgb e958;
+ public Rgb e959;
+ public Rgb e960;
+ public Rgb e961;
+ public Rgb e962;
+ public Rgb e963;
+ public Rgb e964;
+ public Rgb e965;
+ public Rgb e966;
+ public Rgb e967;
+ public Rgb e968;
+ public Rgb e969;
+ public Rgb e970;
+ public Rgb e971;
+ public Rgb e972;
+ public Rgb e973;
+ public Rgb e974;
+ public Rgb e975;
+ public Rgb e976;
+ public Rgb e977;
+ public Rgb e978;
+ public Rgb e979;
+ public Rgb e980;
+ public Rgb e981;
+ public Rgb e982;
+ public Rgb e983;
+ public Rgb e984;
+ public Rgb e985;
+ public Rgb e986;
+ public Rgb e987;
+ public Rgb e988;
+ public Rgb e989;
+ public Rgb e990;
+ public Rgb e991;
+ public Rgb e992;
+ public Rgb e993;
+ public Rgb e994;
+ public Rgb e995;
+ public Rgb e996;
+ public Rgb e997;
+ public Rgb e998;
+ public Rgb e999;
+ public Rgb e1000;
+ public Rgb e1001;
+ public Rgb e1002;
+ public Rgb e1003;
+ public Rgb e1004;
+ public Rgb e1005;
+ public Rgb e1006;
+ public Rgb e1007;
+ public Rgb e1008;
+ public Rgb e1009;
+ public Rgb e1010;
+ public Rgb e1011;
+ public Rgb e1012;
+ public Rgb e1013;
+ public Rgb e1014;
+ public Rgb e1015;
+ public Rgb e1016;
+ public Rgb e1017;
+ public Rgb e1018;
+ public Rgb e1019;
+ public Rgb e1020;
+ public Rgb e1021;
+ public Rgb e1022;
+ public Rgb e1023;
+ public Rgb e1024;
+
+ [UnscopedRef]
+ public ref Rgb this[int index]
+ {
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ get
+ {
+ return ref AsSpan()[index];
+ }
+ }
+
+ [UnscopedRef]
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public Span AsSpan()
+ {
+#if NET6_0_OR_GREATER
+ return MemoryMarshal.CreateSpan(ref e0, 1025);
+#else
+ return new(Unsafe.AsPointer(ref e0), 1025);
+#endif
+ }
+ }
+}
+
+/// DXGI_GAMMA_CONTROL_CAPABILITIES
+public partial struct GammaControlCapabilities
+{
+ public Bool32 ScaleAndOffsetSupported;
+ public float MaxConvertedValue;
+ public float MinConvertedValue;
+ public uint NumGammaControlPoints;
+ public unsafe fixed float ControlPointPositions[1025];
+}
+
+/// DXGI_MODE_DESC
+public partial struct ModeDescription
+{
+ public uint Width;
+ public uint Height;
+ public Rational RefreshRate;
+ public Format Format;
+ public ModeScanlineOrder ScanlineOrdering;
+ public ModeScaling Scaling;
+}
+
+/// DXGI_JPEG_DC_HUFFMAN_TABLE
+public partial struct JpegDcHuffmanTable
+{
+ public unsafe fixed byte CodeCounts[12];
+ public unsafe fixed byte CodeValues[12];
+}
+
+/// DXGI_JPEG_AC_HUFFMAN_TABLE
+public partial struct JpegAcHuffmanTable
+{
+ public unsafe fixed byte CodeCounts[16];
+ public unsafe fixed byte CodeValues[162];
+}
+
+/// DXGI_JPEG_QUANTIZATION_TABLE
+public partial struct JpegQuantizationTable
+{
+ public unsafe fixed byte Elements[64];
+}
+
+#endregion Structs
+
diff --git a/src/Vortice.Win32/Graphics/Dxgi.Common.Manual.cs b/src/Vortice.Win32/Graphics/Dxgi.Common.Manual.cs
new file mode 100644
index 0000000..11ca908
--- /dev/null
+++ b/src/Vortice.Win32/Graphics/Dxgi.Common.Manual.cs
@@ -0,0 +1,66 @@
+// Copyright © Amer Koleci and Contributors.
+// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
+
+namespace Win32.Graphics.Dxgi;
+
+public partial struct Rgb
+{
+ ///
+ /// Initialize instance of struct.
+ ///
+ ///
+ ///
+ ///
+ public Rgb(float red, float green, float blue)
+ {
+ Red = red;
+ Green = green;
+ Blue = blue;
+ }
+
+ public override string ToString()
+ {
+ return $"{nameof(Rgb)}(Red: {Red}, Green: {Green}, Blue: {Blue})";
+ }
+}
+
+public partial struct Rational
+{
+ ///
+ /// Initialize instance of struct.
+ ///
+ ///
+ ///
+ public Rational(uint numerator, uint denominator)
+ {
+ Numerator = numerator;
+ Denominator = denominator;
+ }
+
+ public override string ToString()
+ {
+ return $"{nameof(Rational)}(Numerator: {Numerator}, Denominator: {Denominator})";
+ }
+}
+
+public partial struct SampleDescription
+{
+ ///
+ /// A with Count=1 and Quality=0.
+ ///
+ public static readonly SampleDescription Default = new(1, 0);
+
+ ///
+ /// Create new instance of struct.
+ ///
+ ///
+ ///
+ public SampleDescription(uint count, uint quality)
+ {
+ Count = count;
+ Quality = quality;
+ }
+
+ public override string ToString() => $"Count: {Count}, Quality: {Quality}";
+}
+
diff --git a/src/Vortice.Win32/HResult.Constants.cs b/src/Vortice.Win32/HResult.Constants.cs
new file mode 100644
index 0000000..50caa27
--- /dev/null
+++ b/src/Vortice.Win32/HResult.Constants.cs
@@ -0,0 +1,61 @@
+// Copyright © Amer Koleci and Contributors.
+// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
+
+namespace Win32;
+
+public readonly partial struct HResult
+{
+ /// S_OK
+ public static readonly HResult Ok = 0;
+
+ /// S_FALSE
+ public static readonly HResult False = 1;
+
+ /// E_ABORT
+ public static readonly HResult Abort = unchecked((int)0x80004004);
+
+ /// E_ACCESSDENIED
+ public static readonly HResult AccessDenied = unchecked((int)0x80070005);
+
+ /// E_FAIL
+ public static readonly HResult Fail = unchecked((int)0x80004005);
+
+ /// E_HANDLE
+ public static readonly HResult Handle = unchecked((int)0x80070006);
+
+ /// E_INVALIDARG
+ public static readonly HResult InvalidArg = unchecked((int)0x80070057);
+
+ /// E_NOINTERFACE
+ public static readonly HResult NoInterface = unchecked((int)0x80004002);
+
+ /// E_NOTIMPL
+ public static readonly HResult NotImplemented = unchecked((int)0x80004001);
+
+ /// E_OUTOFMEMORY
+ public static readonly HResult OutOfMemory = unchecked((int)0x8007000E);
+
+ /// E_POINTER
+ public static readonly HResult InvalidPointer = unchecked((int)0x80004003);
+
+ /// E_UNEXPECTED
+ public static readonly HResult UnexpectedFailure = unchecked((int)0x8000FFFF);
+
+ /// WAIT_ABANDONED
+ public static readonly HResult WaitAbandoned = unchecked((int)0x00000080);
+
+ /// WAIT_TIMEOUT
+ public static readonly HResult WaitTimeout = unchecked((int)0x00000102);
+
+ ///
+ /// The data necessary to complete this operation is not yet available.
+ ///
+ /// E_PENDING
+ public static readonly HResult Pending = unchecked((int)0x8000000A);
+
+ ///
+ /// The data area passed to a system call is too small.
+ ///
+ /// E_NOT_SUFFICIENT_BUFFER
+ public static readonly HResult InsufficientBuffer = unchecked((int)0x8007007A);
+}
diff --git a/src/Vortice.Win32/HResult.cs b/src/Vortice.Win32/HResult.cs
new file mode 100644
index 0000000..c72e828
--- /dev/null
+++ b/src/Vortice.Win32/HResult.cs
@@ -0,0 +1,92 @@
+// Copyright © Amer Koleci and Contributors.
+// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
+
+namespace Win32;
+
+public readonly partial struct HResult : IComparable, IComparable, IEquatable, IFormattable
+{
+ public readonly int Value;
+
+ public HResult(int value)
+ {
+ Value = value;
+ }
+
+ public static bool operator ==(HResult left, HResult right) => left.Value == right.Value;
+
+ public static bool operator !=(HResult left, HResult right) => left.Value != right.Value;
+
+ public static bool operator <(HResult left, HResult right) => left.Value < right.Value;
+
+ public static bool operator <=(HResult left, HResult right) => left.Value <= right.Value;
+
+ public static bool operator >(HResult left, HResult right) => left.Value > right.Value;
+
+ public static bool operator >=(HResult left, HResult right) => left.Value >= right.Value;
+
+ public static implicit operator HResult(byte value) => new HResult(value);
+
+ public static explicit operator byte(HResult value) => (byte)(value.Value);
+
+ public static implicit operator HResult(short value) => new HResult(value);
+
+ public static explicit operator short(HResult value) => (short)(value.Value);
+
+ public static implicit operator HResult(int value) => new HResult(value);
+
+ public static implicit operator int(HResult value) => value.Value;
+
+ public static explicit operator HResult(long value) => new HResult(unchecked((int)(value)));
+
+ public static implicit operator long(HResult value) => value.Value;
+
+ public static explicit operator HResult(nint value) => new HResult(unchecked((int)(value)));
+
+ public static implicit operator nint(HResult value) => value.Value;
+
+ public static implicit operator HResult(sbyte value) => new HResult(value);
+
+ public static explicit operator sbyte(HResult value) => (sbyte)(value.Value);
+
+ public static implicit operator HResult(ushort value) => new HResult(value);
+
+ public static explicit operator ushort(HResult value) => (ushort)(value.Value);
+
+ public static explicit operator HResult(uint value) => new HResult(unchecked((int)(value)));
+
+ public static explicit operator uint(HResult value) => (uint)(value.Value);
+
+ public static explicit operator HResult(ulong value) => new HResult(unchecked((int)(value)));
+
+ public static explicit operator ulong(HResult value) => (ulong)(value.Value);
+
+ public static explicit operator HResult(nuint value) => new HResult(unchecked((int)(value)));
+
+ public static explicit operator nuint(HResult value) => (nuint)(value.Value);
+
+ public int CompareTo(object? obj)
+ {
+ if (obj is HResult other)
+ {
+ return CompareTo(other);
+ }
+
+ return (obj is null) ? 1 : throw new ArgumentException("obj is not an instance of HResult.");
+ }
+
+ public int CompareTo(HResult other) => Value.CompareTo(other.Value);
+
+ public override bool Equals(object? obj) => (obj is HResult other) && Equals(other);
+
+ public bool Equals(HResult other) => Value.Equals(other.Value);
+
+ public override int GetHashCode() => Value.GetHashCode();
+
+ public override string ToString() => Value.ToString("X8");
+
+ public string ToString(string? format, IFormatProvider? formatProvider) => Value.ToString(format, formatProvider);
+
+ public bool Failure => Value < 0;
+
+ public bool Success => Value >= 0;
+}
diff --git a/src/Vortice.Win32/IUnknown.cs b/src/Vortice.Win32/IUnknown.cs
new file mode 100644
index 0000000..46b1bd8
--- /dev/null
+++ b/src/Vortice.Win32/IUnknown.cs
@@ -0,0 +1,65 @@
+// Copyright © Amer Koleci and Contributors.
+// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
+
+using System.Runtime.CompilerServices;
+using static Win32.Apis;
+
+namespace Win32;
+
+[Guid("00000000-0000-0000-C000-000000000046")]
+public unsafe partial struct IUnknown : IUnknown.Interface
+{
+ public static Guid* NativeGuid => (Guid*)Unsafe.AsPointer(ref Unsafe.AsRef(in IID_IUnknown));
+
+ public void** lpVtbl;
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [VtblIndex(0)]
+ public HResult QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject)
+ {
+ return ((delegate* unmanaged[Stdcall])(lpVtbl[0]))((IUnknown*)Unsafe.AsPointer(ref this), riid, ppvObject);
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [VtblIndex(1)]
+ [return: NativeTypeName("ULONG")]
+ public uint AddRef()
+ {
+ return ((delegate* unmanaged[Stdcall])(lpVtbl[1]))((IUnknown*)Unsafe.AsPointer(ref this));
+ }
+
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ [VtblIndex(2)]
+ [return: NativeTypeName("ULONG")]
+ public uint Release()
+ {
+ return ((delegate* unmanaged[Stdcall])(lpVtbl[2]))((IUnknown*)Unsafe.AsPointer(ref this));
+ }
+
+ public interface Interface
+ {
+ [VtblIndex(0)]
+ HResult QueryInterface([NativeTypeName("const IID &")] Guid* riid, void** ppvObject);
+
+ [VtblIndex(1)]
+ [return: NativeTypeName("ULONG")]
+ uint AddRef();
+
+ [VtblIndex(2)]
+ [return: NativeTypeName("ULONG")]
+ uint Release();
+ }
+
+ public partial struct Vtbl
+ where TSelf : unmanaged, Interface
+ {
+ [NativeTypeName("HRESULT (const IID &, void **) __attribute__((stdcall))")]
+ public delegate* unmanaged[Stdcall] QueryInterface;
+
+ [NativeTypeName("ULONG () __attribute__((stdcall))")]
+ public delegate* unmanaged[Stdcall] AddRef;
+
+ [NativeTypeName("ULONG () __attribute__((stdcall))")]
+ public delegate* unmanaged[Stdcall] Release;
+ }
+}
diff --git a/src/Vortice.Win32/UnscopedRefAttribute.cs b/src/Vortice.Win32/UnscopedRefAttribute.cs
new file mode 100644
index 0000000..08abfa8
--- /dev/null
+++ b/src/Vortice.Win32/UnscopedRefAttribute.cs
@@ -0,0 +1,36 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+namespace System.Diagnostics.CodeAnalysis;
+
+///
+/// Used to indicate a byref escapes and is not scoped.
+///
+///
+///
+/// There are several cases where the C# compiler treats a as implicitly
+/// - where the compiler does not allow the to escape the method.
+///
+///
+/// For example:
+///
+/// - for instance methods.
+/// - parameters that refer to types.
+/// - parameters.
+///
+///
+///
+/// This attribute is used in those instances where the should be allowed to escape.
+///
+///
+/// Applying this attribute, in any form, has impact on consumers of the applicable API. It is necessary for
+/// API authors to understand the lifetime implications of applying this attribute and how it may impact their users.
+///
+///
+[AttributeUsage(
+ AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter,
+ AllowMultiple = false,
+ Inherited = false)]
+internal sealed class UnscopedRefAttribute : Attribute
+{
+}
diff --git a/src/Vortice.Win32/Win32.cs b/src/Vortice.Win32/Win32.cs
new file mode 100644
index 0000000..f219d2f
--- /dev/null
+++ b/src/Vortice.Win32/Win32.cs
@@ -0,0 +1,110 @@
+// Copyright © Amer Koleci and Contributors.
+// Licensed under the MIT License (MIT). See LICENSE in the repository root for more information.
+
+
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Runtime.CompilerServices;
+
+namespace Win32;
+
+public static partial class Apis
+{
+ public static ref readonly Guid IID_IUnknown
+ {
+ get
+ {
+ ReadOnlySpan data = new byte[] {
+ 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00,
+ 0x00, 0x00,
+ 0xC0,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x00,
+ 0x46
+ };
+
+ Debug.Assert(data.Length == Unsafe.SizeOf());
+ return ref Unsafe.As(ref MemoryMarshal.GetReference(data));
+ }
+ }
+
+ /// Retrieves the GUID of of a specified type.
+ /// A value of type .
+ /// The type to retrieve the GUID for.
+ /// A value wrapping a pointer to the GUID data for the input type. This value can be either converted to a pointer, or implicitly assigned to a value.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static unsafe UuidOfType __uuidof(T value) // for type inference similar to C++'s __uuidof
+ where T : unmanaged
+ {
+ return new UuidOfType(UUID.RIID);
+ }
+
+ /// Retrieves the GUID of of a specified type.
+ /// A pointer to a value of type .
+ /// The type to retrieve the GUID for.
+ /// A value wrapping a pointer to the GUID data for the input type. This value can be either converted to a pointer, or implicitly assigned to a value.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static unsafe UuidOfType __uuidof(T* value) // for type inference similar to C++'s __uuidof
+ where T : unmanaged
+ {
+ return new UuidOfType(UUID.RIID);
+ }
+
+ /// Retrieves the GUID of of a specified type.
+ /// The type to retrieve the GUID for.
+ /// A value wrapping a pointer to the GUID data for the input type. This value can be either converted to a pointer, or implicitly assigned to a value.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ public static unsafe UuidOfType __uuidof()
+ where T : unmanaged
+ {
+ return new UuidOfType(UUID.RIID);
+ }
+
+ /// A proxy type that wraps a pointer to GUID data. Values of this type can be implicitly converted to and assigned to * or parameters.
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ public readonly unsafe ref struct UuidOfType
+ {
+ private readonly Guid* riid;
+
+ internal UuidOfType(Guid* riid)
+ {
+ this.riid = riid;
+ }
+
+ /// Reads a value from the GUID buffer for a given instance.
+ /// The input instance to read data for.
+ public static implicit operator Guid(UuidOfType guid) => *guid.riid;
+
+ /// Returns the * pointer to the GUID buffer for a given instance.
+ /// The input instance to read data for.
+ public static implicit operator Guid*(UuidOfType guid) => guid.riid;
+ }
+
+ /// A helper type to provide static GUID buffers for specific types.
+ /// The type to allocate a GUID buffer for.
+ private static unsafe class UUID
+ where T : unmanaged
+ {
+ /// The pointer to the value for the current type.
+ /// The target memory area should never be written to.
+ public static readonly Guid* RIID = CreateRIID();
+
+ /// Allocates memory for a value and initializes it.
+ /// A pointer to memory holding the value for the current type.
+ private static Guid* CreateRIID()
+ {
+#if NET6_0_OR_GREATER
+ var p = (Guid*)RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(T), sizeof(Guid));
+#else
+ var p = (Guid*)Marshal.AllocHGlobal(sizeof(Guid));
+#endif
+ *p = typeof(T).GUID;
+ return p;
+ }
+ }
+}