1 module aurora.directx.dxgi.dxgi;
2 
3 version(Windows):
4 
5 import aurora.directx.com;
6 public import aurora.directx.dxgi.dxgitype;
7 public import aurora.directx.dxgi.dxgicommon;
8 public import aurora.directx.dxgi.dxgiformat;
9 
10 public:
11 
12 //
13 //	Constants
14 //
15 
16 //DXGI_ERROR
17 enum DXGI_ERROR_DEVICE_HUNG = 0x887A0006;
18 enum DXGI_ERROR_DEVICE_REMOVED = 0x887A0005;
19 enum DXGI_ERROR_DEVICE_RESET = 0x887A0007;
20 enum DXGI_ERROR_DRIVER_INTERNAL_ERROR = 0x887A0020;
21 enum DXGI_ERROR_FRAME_STATISTICS_DISJOINT = 0x887A000B;
22 enum DXGI_ERROR_GRAPHICS_VIDPN_SOURCE_IN_USE = 0x887A000C;
23 enum DXGI_ERROR_INVALID_CALL = 0x887A0001;
24 enum DXGI_ERROR_NONEXCLUSIVE = 0x887A0021;
25 enum DXGI_ERROR_NOT_CURRENTLY_AVAILABLE = 0x887A0022;
26 enum DXGI_ERROR_NOT_FOUND = 0x887A0002;
27 enum DXGI_ERROR_REMOTE_CLIENT_DISCONNECTED = 0x887A0023;
28 enum DXGI_ERROR_REMOTE_OUTOFMEMORY = 0x887A0024;
29 enum DXGI_ERROR_WAS_STILL_DRAWING = 0x887A000A;
30 enum DXGI_ERROR_UNSUPPORTED = 0x887A0004;
31 enum DXGI_ERROR_ACCESS_LOST = 0x887A0026;
32 enum DXGI_ERROR_WAIT_TIMEOUT = 0x887A0027;
33 enum DXGI_ERROR_SESSION_DISCONNECTED = 0x887A0028;
34 enum DXGI_ERROR_RESTRICT_TO_OUTPUT_STALE = 0x887A0029;
35 enum DXGI_ERROR_CANNOT_PROTECT_CONTENT = 0x887A002A;
36 enum DXGI_ERROR_ACCESS_DENIED = 0x887A002B;
37 enum DXGI_ERROR_NAME_ALREADY_EXISTS = 0x887A002C;
38 
39 //DXGI_ENUM_MODES
40 enum DXGI_ENUM_MODES_INTERLACED = (1U);
41 enum DXGI_ENUM_MODES_SCALING    = (2U);
42 
43 //DXGI_PRESENT
44 enum DXGI_PRESENT_FRAME           = (0x00000000U);
45 enum DXGI_PRESENT_TEST            = (0x00000001U);
46 enum DXGI_PRESENT_DO_NOT_SEQUENCE = (0x00000002U);
47 enum DXGI_PRESENT_RESTART         = (0x00000004U);
48 
49 //DXGI_STATUS
50 enum DXGI_STATUS_OCCLUDED = 0x087A0001;
51 enum DXGI_STATUS_MODE_CHANGED = 0x087A0007;
52 enum DXGI_STATUS_MODE_CHANGE_IN_PROGRESS = 0x087A0008;
53 
54 //DXGI_USAGE
55 enum DXGI_USAGE_SHADER_INPUT         = (1L << (0 + 4));
56 enum DXGI_USAGE_RENDER_TARGET_OUTPUT = (1L << (1 + 4));
57 enum DXGI_USAGE_BACK_BUFFER          = (1L << (2 + 4));
58 enum DXGI_USAGE_SHARED               = (1L << (3 + 4));
59 enum DXGI_USAGE_READ_ONLY            = (1L << (4 + 4));
60 enum DXGI_USAGE_DISCARD_ON_PRESENT   = (1L << (5 + 4));
61 enum DXGI_USAGE_UNORDERED_ACCESS     = (1L << (6 + 4));
62 alias uint DXGI_USAGE;
63 
64 //DXGI_MAP
65 enum DXGI_MAP_READ    = (1U);
66 enum DXGI_MAP_WRITE   = (2U);
67 enum DXGI_MAP_DISCARD = (4U);
68 
69 //DXGI_RESOURCE_PRIORITY
70 enum DXGI_RESOURCE_PRIORITY_MINIMUM = (0x2800_0000U);
71 enum DXGI_RESOURCE_PRIORITY_LOW	    = (0x5000_0000U);
72 enum DXGI_RESOURCE_PRIORITY_NORMAL  = (0x7800_0000U);
73 enum DXGI_RESOURCE_PRIORITY_HIGH    = (0xa000_0000U);
74 enum DXGI_RESOURCE_PRIORITY_MAXIMUM = (0xc800_0000U);
75 
76 //DXGI_CPU_ACCESS
77 enum DXGI_CPU_ACCESS_NONE       = ( 0U);
78 enum DXGI_CPU_ACCESS_DYNAMIC    = ( 1U);
79 enum DXGI_CPU_ACCESS_READ_WRITE = ( 2U);
80 enum DXGI_CPU_ACCESS_SCRATCH    = ( 3U);
81 enum DXGI_CPU_ACCESS_FIELD      = (15U);
82 
83 //DXGI_SWAP_CHAIN_FLAG
84 enum DXGI_SWAP_CHAIN_FLAG_NONPREROTATED                    = (1U);
85 enum DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH                = (2U);
86 enum DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE                   = (4U);
87 enum DXGI_SWAP_CHAIN_FLAG_RESTRICTED_CONTENT               = (8U);
88 enum DXGI_SWAP_CHAIN_FLAG_RESTRICT_SHARED_RESOURCE_DRIVER  = (16U);
89 enum DXGI_SWAP_CHAIN_FLAG_DISPLAY_ONLY                     = (32U);
90 enum DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT    = (64U);
91 enum DXGI_SWAP_CHAIN_FLAG_FOREGROUND_LAYER                 = (128U);
92 
93 //DXGI_MWA
94 enum DXGI_MWA_NO_WINDOW_CHANGES = (1 << 0);
95 enum DXGI_MWA_NO_ALT_ENTER      = (1 << 1);
96 enum DXGI_MWA_NO_PRINT_SCREEN   = (1 << 2);
97 enum DXGI_MWA_VALID             = (0x7);
98 
99 //DXGI_DEBUG
100 //const IID DXGI_DEBUG_ALL = { 0xe48ae283, 0xda80, 0x490b, 0x87, 0xe6, 0x43, 0xe9, 0xa9, 0xcf, 0xda, 0x8 };
101 //const IID DXGI_DEBUG_DX = { 0x35cdd7fc, 0x13b2, 0x421d, 0xa5, 0xd7, 0x7e, 0x44, 0x51, 0x28, 0x7d, 0x64 };
102 //const IID DXGI_DEBUG_DXGI = { 0x25cddaa4, 0xb1c6, 0x47e1, 0xac, 0x3e, 0x98, 0x87, 0x5b, 0x5a, 0x2e, 0x2a };
103 //const IID DXGI_DEBUG_APP = { 0x6cd6e01, 0x4219, 0x4ebd, 0x87, 0x9, 0x27, 0xed, 0x23, 0x36, 0xc, 0x62 };
104 //const IID DXGI_DEBUG_D3D11 = { 0x4b99317b, 0xac39, 0x4aa6, 0xbb, 0xb, 0xba, 0xa0, 0x47, 0x84, 0x79, 0x8f };
105 
106 //
107 //	Enumerations
108 //
109 
110 public enum DXGI_ADAPTER_FLAG : int { 
111 	NONE         = 0,
112 	REMOTE       = 1,
113 	SOFTWARE     = 2,
114 	FORCE_DWORD  = 0xffffffff
115 }
116 
117 public enum DXGI_FRAME_PRESENTATION_MODE : int { 
118 	COMPOSED  = 0,
119 	OVERLAY   = 1,
120 	NONE      = 2
121 }
122 
123 public enum DXGI_MULTIPLANE_OVERLAY_YCbCr_FLAGS : int { 
124 	NOMINAL_RANGE  = 0x1,
125 	BT709          = 0x2,
126 	xvYCC          = 0x4
127 }
128 
129 public enum DXGI_RESIDENCY : int { 
130 	FULLY_RESIDENT             = 1,
131 	RESIDENT_IN_SHARED_MEMORY  = 2,
132 	EVICTED_TO_DISK            = 3
133 }
134 
135 public enum DXGI_SWAP_CHAIN_FLAG : int { 
136 	NONPREROTATED                    = 1,
137 	ALLOW_MODE_SWITCH                = 2,
138 	GDI_COMPATIBLE                   = 4,
139 	RESTRICTED_CONTENT               = 8,
140 	RESTRICT_SHARED_RESOURCE_DRIVER  = 16,
141 	DISPLAY_ONLY                     = 32,
142 	FRAME_LATENCY_WAITABLE_OBJECT    = 64,
143 	FOREGROUND_LAYER                 = 128
144 }
145 
146 enum DXGI_SWAP_EFFECT : int { 
147 	DISCARD          = 0,
148 	SEQUENTIAL       = 1,
149 	FLIP_SEQUENTIAL  = 3
150 }
151 
152 //
153 //	Structures
154 //
155 
156 public struct DXGI_ADAPTER_DESC {
157 	wchar[128] Description;
158 	uint VendorId;
159 	uint DeviceId;
160 	uint SubSysId;
161 	uint Revision;
162 	size_t DedicatedVideoMemory;
163 	size_t DedicatedSystemMemory;
164 	size_t SharedSystemMemory;
165 	LUID AdapterLuid;
166 }
167 
168 public struct DXGI_ADAPTER_DESC1 {
169 	wchar[128] Description;
170 	uint VendorId;
171 	uint DeviceId;
172 	uint SubSysId;
173 	uint Revision;
174 	size_t DedicatedVideoMemory;
175 	size_t DedicatedSystemMemory;
176 	size_t SharedSystemMemory;
177 	LUID AdapterLuid;
178 	uint Flags;
179 }
180 
181 public struct DXGI_FRAME_STATISTICS {
182 	uint PresentCount;
183 	uint PresentRefreshCount;
184 	uint SyncRefreshCount;
185 	LARGE_INTEGER SyncQPCTime;
186 	LARGE_INTEGER SyncGPUTime;
187 }
188 
189 public struct DXGI_GAMMA_CONTROL {
190 	DXGI_RGB               Scale;
191 	DXGI_RGB               Offset;
192 	DXGI_RGB[1025]         GammaCurve;
193 }
194 
195 public struct DXGI_GAMMA_CONTROL_CAPABILITIES {
196 	BOOL                   ScaleAndOffsetSupported;
197 	float                  MaxConvertedValue;
198 	float                  MinConvertedValue;
199 	uint                   NumGammaControlPoints;
200 	float[1025]           ControlPointPosition;
201 }
202 
203 public struct DXGI_MAPPED_RECT {
204 	int Pitch;
205 	ubyte *pBits;
206 }
207 
208 public struct DXGI_MODE_DESC {
209 	uint                     Width;
210 	uint                     Height;
211 	DXGI_RATIONAL            RefreshRate;
212 	DXGI_FORMAT              Format;
213 	DXGI_MODE_SCANLINE_ORDER ScanlineOrdering;
214 	DXGI_MODE_SCALING        Scaling;
215 }
216 
217 public struct DXGI_OUTPUT_DESC {
218 	wchar[32]          DeviceName;
219 	RECT               DesktopCoordinates;
220 	BOOL               AttachedToDesktop;
221 	DXGI_MODE_ROTATION Rotation;
222 	long               Monitor;
223 }
224 
225 public struct DXGI_OUTDUPL_DESC {
226 	DXGI_MODE_DESC     ModeDesc;
227 	DXGI_MODE_ROTATION Rotation;
228 	BOOL               DesktopImageInSystemMemory;
229 }
230 
231 public struct DXGI_SHARED_RESOURCE {
232 	HANDLE Handle;
233 }
234 
235 public struct DXGI_SURFACE_DESC {
236 	uint             Width;
237 	uint             Height;
238 	DXGI_FORMAT      Format;
239 	DXGI_SAMPLE_DESC SampleDesc;
240 }
241 
242 public struct DXGI_SWAP_CHAIN_DESC {
243 	DXGI_MODE_DESC   BufferDesc;
244 	DXGI_SAMPLE_DESC SampleDesc;
245 	uint             BufferUsage;
246 	uint             BufferCount;
247 	HWND             OutputWindow;
248 	BOOL             Windowed;
249 	DXGI_SWAP_EFFECT SwapEffect;
250 	uint             Flags;
251 }
252 
253 //
254 //	Interfaces
255 //
256 
257 mixin(uuid!(IDXGIObject, "aec22fb8-76f3-4639-9be0-28eb43a67a2e"));
258 interface IDXGIObject : IUnknown
259 {
260 extern(Windows):
261 	HRESULT GetParent(GUID* IID, void** Parent);
262 	HRESULT GetPrivateData(GUID* IID, uint* DataSize, void* Data);
263 	HRESULT SetPrivateData(GUID* IID, uint DataSize, const void* Data);
264 	HRESULT SetPrivateDataInterface(GUID* IID, const(IUnknown) Unknown);
265 }
266 
267 mixin(uuid!(IDXGIAdapter, "2411e7e1-12ac-4ccf-bd14-9798e8534dc0"));
268 interface IDXGIAdapter : IDXGIObject
269 {
270 extern(Windows):
271 	HRESULT CheckInterfaceSupport(GUID* InterfaceName, LARGE_INTEGER *UMDVersion);
272 	HRESULT EnumOutputs(uint Output, IDXGIOutput *Output);
273 	HRESULT GetDesc(DXGI_ADAPTER_DESC *Desc);
274 }
275 
276 mixin(uuid!(IDXGIAdapter1, "29038f61-3839-4626-91fd-086879011a05"));
277 interface IDXGIAdapter1 : IDXGIAdapter
278 {
279 extern(Windows):
280 	HRESULT GetDesc1(DXGI_ADAPTER_DESC1 *Desc);
281 }
282 
283 mixin(uuid!(IDXGIDevice, "54ec77fa-1377-44e6-8c32-88fd5f44c84c"));
284 interface IDXGIDevice : IDXGIObject
285 {
286 extern(Windows):
287 	HRESULT CreateSurface(const DXGI_SURFACE_DESC *Desc, uint NumSurfaces, DXGI_USAGE Usage, const DXGI_SHARED_RESOURCE *SharedResource, IDXGISurface *Surface);
288 	HRESULT GetAdapter(IDXGIAdapter *Adapter);
289 	HRESULT GetGPUThreadPriority(int *Priority);
290 	HRESULT QueryResourceResidency(const(IUnknown) *Resources, DXGI_RESIDENCY *ResidencyStatus, uint NumResources);
291 	HRESULT SetGPUThreadPriority(int Priority);
292 }
293 
294 mixin(uuid!(IDXGIDevice1, "77db970f-6276-48ba-ba28-070143b4392c"));
295 interface IDXGIDevice1 : IDXGIDevice
296 {
297 extern(Windows):
298 	HRESULT GetMaximumFrameLatency(uint *MaxLatency);
299 	HRESULT SetMaximumFrameLatency(uint MaxLatency);
300 }
301 
302 mixin(uuid!(IDXGIDeviceSubObject, "3d3e0379-f9de-4d58-bb6c-18d62992f1a6"));
303 interface IDXGIDeviceSubObject : IDXGIObject
304 {
305 extern(Windows):
306 	HRESULT GetDevice(GUID RIID, void **Device);
307 }
308 
309 mixin(uuid!(IDXGIFactory, "7b7166ec-21c7-44ae-b21a-c9ae321ae369"));
310 interface IDXGIFactory : IDXGIObject
311 {
312 extern(Windows):
313 	HRESULT CreateSoftwareAdapter(HMODULE Module, IDXGIAdapter *Adapter);
314 	HRESULT CreateSwapChain(IUnknown Device, DXGI_SWAP_CHAIN_DESC *Desc, IDXGISwapChain *SwapChain);
315 	HRESULT EnumAdapters(uint Adapter,IDXGIAdapter *Adapter);
316 	HRESULT GetWindowAssociation(HWND *WindowHandle);
317 	HRESULT MakeWindowAssociation(HWND WindowHandle, uint Flags);
318 }
319 
320 mixin(uuid!(IDXGIFactory1, "770aae78-f26f-4dba-a829-253c83d1b387"));
321 interface IDXGIFactory1 : IDXGIFactory
322 {
323 extern(Windows):
324 	HRESULT EnumAdapters1(uint Adapter, IDXGIAdapter1 *Adapter);
325 	BOOL IsCurrent();
326 }
327 
328 mixin(uuid!(IDXGIKeyedMutex, "9d8e1289-d7b3-465f-8126-250e349af85d"));
329 interface IDXGIKeyedMutex : IDXGIDeviceSubObject
330 {
331 extern(Windows):
332 	HRESULT AcquireSync(ulong Key, DWORD Milliseconds);
333 	HRESULT ReleaseSync(ulong Key);
334 }
335 
336 mixin(uuid!(IDXGIOutput, "ae02eedb-c735-4690-8d52-5a8dc20213aa"));
337 interface IDXGIOutput : IDXGIObject
338 {
339 extern(Windows):
340 	HRESULT FindClosestMatchingMode(const DXGI_MODE_DESC *ModeToMatch, DXGI_MODE_DESC *ClosestMatch, IUnknown ConcernedDevice);
341 	HRESULT GetDesc(DXGI_OUTPUT_DESC *Desc);
342 	HRESULT GetDisplayModeList(DXGI_FORMAT EnumFormat, uint Flags, uint *NumModes, DXGI_MODE_DESC *Desc);
343 	HRESULT GetDisplaySurfaceData(IDXGISurface Destination);
344 	HRESULT GetFrameStatistics(DXGI_FRAME_STATISTICS *Stats);
345 	HRESULT GetGammaControl(DXGI_GAMMA_CONTROL *Array);
346 	HRESULT GetGammaControlCapabilities(DXGI_GAMMA_CONTROL_CAPABILITIES *GammaCaps);
347 	void ReleaseOwnership();
348 	HRESULT SetDisplaySurface(IDXGISurface ScanoutSurface);
349 	HRESULT SetGammaControl(const DXGI_GAMMA_CONTROL *Array);
350 	HRESULT TakeOwnership(IUnknown Device, BOOL Exclusive);
351 	HRESULT WaitForVBlank();
352 }
353 
354 mixin(uuid!(IDXGIResource, "035f3ab4-482e-4e50-b41f-8a7f8bd8960b"));
355 interface IDXGIResource : IDXGIDeviceSubObject
356 {
357 extern(Windows):
358 	HRESULT GetEvictionPriority(uint *EvictionPriority);
359 	HRESULT GetSharedHandle(HANDLE *SharedHandle);
360 	HRESULT GetUsage(DXGI_USAGE *Usage);
361 	HRESULT SetEvictionPriority(uint EvictionPriority);
362 }
363 
364 mixin(uuid!(IDXGISurface, "cafcb56c-6ac3-4889-bf47-9e23bbd260ec"));
365 interface IDXGISurface : IDXGIDeviceSubObject
366 {
367 extern(Windows):
368 	HRESULT GetDesc(DXGI_SURFACE_DESC *Desc);
369 	HRESULT Map(DXGI_MAPPED_RECT *LockedRect, uint MapFlags);
370 	HRESULT Unmap();
371 }
372 
373 mixin(uuid!(IDXGISurface1, "4AE63092-6327-4c1b-80AE-BFE12EA32B86"));
374 interface IDXGISurface1 : IDXGISurface
375 {
376 extern(Windows):
377 	HRESULT GetDC(BOOL Discard, HDC *hdc);
378 	HRESULT ReleaseDC(RECT *DirtyRect);
379 }
380 
381 mixin(uuid!(IDXGISwapChain, "310d36a0-d2e7-4c0a-aa04-6a9d23b8886a"));
382 interface IDXGISwapChain : IDXGIDeviceSubObject
383 {
384 extern(Windows):
385 	HRESULT GetBuffer(uint Buffer, GUID *RIID, void **Surface);
386 	HRESULT GetContainingOutput(IDXGIOutput *Output);
387 	HRESULT GetDesc(DXGI_SWAP_CHAIN_DESC *Desc);
388 	HRESULT GetFrameStatistics(DXGI_FRAME_STATISTICS *Stats);
389 	HRESULT GetFullscreenState(BOOL *Fullscreen, IDXGIOutput *Target);
390 	HRESULT GetLastPresentCount(uint *LastPresentCount);
391 	HRESULT Present(uint SyncInterval, uint Flags);
392 	HRESULT ResizeBuffers(uint BufferCount, uint Width, uint Height, DXGI_FORMAT NewFormat, uint SwapChainFlags);
393 	HRESULT ResizeTarget(const DXGI_MODE_DESC *NewTargetParameters);
394 	HRESULT SetFullscreenState(BOOL Fullscreen, IDXGIOutput Target);
395 }
396 
397 //
398 //	Functions
399 //
400 extern(Windows) public HRESULT CreateDXGIFactory(const(GUID)* RIID, void **Factory);
401 extern(Windows) public HRESULT CreateDXGIFactory1(const(GUID)* RIID, void **Factory);
402 extern(Windows) public HRESULT DXGIGetDebugInterface(const(GUID)* RIID, void **Debug);