Skip to content
This repository was archived by the owner on Mar 30, 2019. It is now read-only.

Commit 556aee5

Browse files
committed
Added initial support for the DXGI debug layer, might need to revise InfoQueue
1 parent 94f2883 commit 556aee5

8 files changed

Lines changed: 233 additions & 1 deletion

File tree

Source/SharpDX.DXGI/Debug.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2010-2018 SharpDX - Alexandre Mutel
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
using System;
21+
22+
namespace SharpDX.DXGI
23+
{
24+
public partial class Debug
25+
{
26+
/// <summary>
27+
/// If the DXGI debug layer is installed (e.g. on developer machines), creates the DXGI Debug object.
28+
/// Otherwise, returns null.
29+
/// </summary>
30+
/// <remarks>
31+
/// Currently doesn't work for Windows Store (aka UWP) apps
32+
/// </remarks>
33+
public static Debug TryCreate()
34+
{
35+
return DebugInterface.TryCreateComPtr<Debug>(out IntPtr comPtr) ? new Debug(comPtr) : null;
36+
}
37+
}
38+
}

Source/SharpDX.DXGI/Debug1.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2010-2018 SharpDX - Alexandre Mutel
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
using System;
21+
22+
namespace SharpDX.DXGI
23+
{
24+
public partial class Debug1
25+
{
26+
/// <summary>
27+
/// If the DXGI debug layer is installed (e.g. on developer machines), creates the DXGI Debug1 object.
28+
/// Otherwise, returns null.
29+
/// </summary>
30+
/// <remarks>
31+
/// Currently doesn't work for Windows Store (aka UWP) apps
32+
/// </remarks>
33+
public new static Debug1 TryCreate()
34+
{
35+
return DebugInterface.TryCreateComPtr<Debug1>(out IntPtr comPtr) ? new Debug1(comPtr) : null;
36+
}
37+
}
38+
}

Source/SharpDX.DXGI/DebugId.cs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2010-2018 SharpDX - Alexandre Mutel
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
using System;
21+
22+
namespace SharpDX.DXGI
23+
{
24+
public static class DebugId
25+
{
26+
public static readonly Guid All = new Guid("e48ae283-da80-490b-87e6-43e9a9cfda08");
27+
public static readonly Guid App = new Guid("06cd6e01-4219-4ebd-8709-27ed23360c62");
28+
public static readonly Guid Dx = new Guid("35cdd7fc-13b2-421d-a5d7-7e4451287d64");
29+
public static readonly Guid Dxgi = new Guid("25cddaa4-b1c6-47e1-ac3e-98875b5a2e2a");
30+
}
31+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Reflection;
3+
using System.Runtime.InteropServices;
4+
5+
namespace SharpDX.DXGI
6+
{
7+
internal static class DebugInterface
8+
{
9+
[UnmanagedFunctionPointer(CallingConvention.Winapi)]
10+
private delegate Result GetDebugInterface(ref Guid guid, out IntPtr result);
11+
12+
private static readonly GetDebugInterface getDebugInterface;
13+
14+
static DebugInterface()
15+
{
16+
// https://blogs.msdn.microsoft.com/chuckw/2015/07/27/dxgi-debug-device/
17+
#if DESKTOP_APP
18+
IntPtr moduleHandle = Kernel32.LoadLibraryEx("dxgidebug.dll", IntPtr.Zero, Kernel32.LoadLibraryFlags.LoadLibrarySearchSystem32);
19+
if (moduleHandle != IntPtr.Zero)
20+
{
21+
IntPtr procedureHandle = Kernel32.GetProcAddress(moduleHandle, "DXGIGetDebugInterface");
22+
if (procedureHandle != IntPtr.Zero)
23+
{
24+
getDebugInterface = (GetDebugInterface)Marshal.GetDelegateForFunctionPointer(procedureHandle, typeof(GetDebugInterface));
25+
}
26+
}
27+
#else
28+
getDebugInterface = null;
29+
#endif
30+
}
31+
32+
public static bool TryCreateComPtr<T>(out IntPtr comPtr) where T : class
33+
{
34+
comPtr = IntPtr.Zero;
35+
if (getDebugInterface == null)
36+
return false;
37+
38+
var guid = typeof(T).GetTypeInfo().GUID;
39+
var result = getDebugInterface(ref guid, out comPtr);
40+
if (result.Failure)
41+
return false;
42+
43+
return comPtr != IntPtr.Zero;
44+
}
45+
46+
}
47+
}

Source/SharpDX.DXGI/InfoQueue.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2010-2018 SharpDX - Alexandre Mutel
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy
4+
// of this software and associated documentation files (the "Software"), to deal
5+
// in the Software without restriction, including without limitation the rights
6+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
// copies of the Software, and to permit persons to whom the Software is
8+
// furnished to do so, subject to the following conditions:
9+
//
10+
// The above copyright notice and this permission notice shall be included in
11+
// all copies or substantial portions of the Software.
12+
//
13+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
// THE SOFTWARE.
20+
using System;
21+
22+
namespace SharpDX.DXGI
23+
{
24+
public partial class InfoQueue
25+
{
26+
/// <summary>
27+
/// If the DXGI debug layer is installed (e.g. on developer machines), creates the DXGI InfoQueue object.
28+
/// Otherwise, returns null.
29+
/// </summary>
30+
/// <remarks>
31+
/// Currently doesn't work for Windows Store (aka UWP) apps
32+
/// </remarks>
33+
public static InfoQueue TryCreate()
34+
{
35+
return DebugInterface.TryCreateComPtr<InfoQueue>(out IntPtr comPtr) ? new InfoQueue(comPtr) : null;
36+
}
37+
}
38+
}

Source/SharpDX.DXGI/Kernel32.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
using System;
2+
using System.Runtime.InteropServices;
3+
4+
namespace SharpDX.DXGI {
5+
internal static class Kernel32
6+
{
7+
[Flags]
8+
public enum LoadLibraryFlags : uint
9+
{
10+
DontResolveDllReferences = 0x00000001,
11+
LoadIgnoreCodeAuthzLevel = 0x00000010,
12+
LoadLibraryAsDatafile = 0x00000002,
13+
LoadLibraryAsDatafileExclusive = 0x00000040,
14+
LoadLibraryAsImageResource = 0x00000020,
15+
LoadLibrarySearchApplicationDir = 0x00000200,
16+
LoadLibrarySearchDefaultDirs = 0x00001000,
17+
LoadLibrarySearchDllLoadDir = 0x00000100,
18+
LoadLibrarySearchSystem32 = 0x00000800,
19+
LoadLibrarySearchUserDirs = 0x00000400,
20+
LoadWithAlteredSearchPath = 0x00000008
21+
}
22+
23+
[DllImport("kernel32.dll", SetLastError = true)]
24+
public static extern IntPtr LoadLibraryEx(string lpFileName, IntPtr hReservedNull, LoadLibraryFlags dwFlags);
25+
26+
[DllImport("kernel32.dll")]
27+
public static extern IntPtr GetModuleHandle(string lpModuleName);
28+
29+
[DllImport("kernel32.dll")]
30+
public static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
31+
}
32+
}

Source/SharpDX.DXGI/Mapping.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<!-- DXGI includes -->
3030
<include id="dxgi" file="dxgi.h" attach="true" />
3131
<include id="dxgiformat" file="dxgiformat.h" attach="true" />
32+
<include id="dxgidebug" file="dxgidebug.h" attach="true" />
3233
<include id="winerror" file="winerror.h"/>
3334
<include id="dxgitype" file="dxgitype.h" attach="true"/>
3435
<include id="dxgicommon" file="dxgicommon.h" attach="true"/>
@@ -44,6 +45,7 @@
4445
<context>sharpdx-dxgi-ext</context>
4546
<context>dxgi</context>
4647
<context>dxgiformat</context>
48+
<context>dxgidebug</context>
4749
<context>dxgitype</context>
4850
<context>dxgicommon</context>
4951
<context>dxgi1_2</context>
@@ -159,6 +161,11 @@
159161
<map struct="DXGI_ADAPTER_DESC" pack="4"/>
160162
<map struct="DXGI_ADAPTER_DESC1" pack="4"/>
161163

164+
<map struct="DXGI_INFO_QUEUE_FILTER" name="InfoQueueFilter" />
165+
<map struct="DXGI_INFO_QUEUE_FILTER_DESC" name="InfoQueueFilterDescription" />
166+
167+
<map struct="DXGI_DEBUG_ID" name="DebugId" />
168+
162169
<!--
163170
// *****************************************************************
164171
// DXGI Interfaces
@@ -283,7 +290,8 @@
283290

284291
<!-- TODO: No documentation - don't know how to map it. -->
285292
<remove function="DXGIGetDebugInterface1" />
286-
293+
<remove function="DXGIGetDebugInterface" />
294+
287295
<context-clear/>
288296
</mapping>
289297
</config>

Source/Tools/SharpGen/MSDNDoc.zip

54.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)