1 /***********************************************************************\
2 *                                 dxgi.d                                *
3 *                                                                       *
4 *                       Windows API header module                       *
5 *                                                                       *
6 *                       Placed into public domain                       *
7 \***********************************************************************/
8 module win32.directx.dxgi;
9 version(Windows):
10 
11 private import win32.windows;
12 
13 private import win32.directx.dxgitype;
14 
15 enum {
16 	DXGI_CPU_ACCESS_NONE		=  0,
17 	DXGI_CPU_ACCESS_DYNAMIC		=  1,
18 	DXGI_CPU_ACCESS_READ_WRITE	=  2,
19 	DXGI_CPU_ACCESS_SCRATCH		=  3,
20 	DXGI_CPU_ACCESS_FIELD		= 15
21 }
22 
23 enum {
24 	DXGI_USAGE_SHADER_INPUT			= 0b00_00010000,
25 	DXGI_USAGE_RENDER_TARGET_OUTPUT	= 0b00_00100000,
26 	DXGI_USAGE_BACK_BUFFER			= 0b00_01000000,
27 	DXGI_USAGE_SHARED				= 0b00_10000000,
28 	DXGI_USAGE_READ_ONLY			= 0b01_00000000,
29 	DXGI_USAGE_DISCARD_ON_PRESENT	= 0b10_00000000,
30 }
31 alias UINT DXGI_USAGE;
32 
33 struct DXGI_FRAME_STATISTICS {
34 	UINT PresentCount;
35 	UINT PresentRefreshCount;
36 	UINT SyncRefreshCount;
37 	LARGE_INTEGER SyncQPCTime;
38 	LARGE_INTEGER SyncGPUTime;
39 }
40 
41 struct DXGI_MAPPED_RECT {
42 	INT Pitch;
43 	BYTE* pBits;
44 }
45 
46 struct DXGI_ADAPTER_DESC {
47 	WCHAR[128] Description;
48 	UINT VendorId;
49 	UINT DeviceId;
50 	UINT SubSysId;
51 	UINT Revision;
52 	SIZE_T DedicatedVideoMemory;
53 	SIZE_T DedicatedSystemMemory;
54 	SIZE_T SharedSystemMemory;
55 	LUID AdapterLuid;
56 }
57 
58 struct DXGI_OUTPUT_DESC {
59 	WCHAR[32] DeviceName;
60 	RECT DesktopCoordinates;
61 	BOOL AttachedToDesktop;
62 	DXGI_MODE_ROTATION Rotation;
63 	HMONITOR Monitor;
64 }
65 
66 struct DXGI_SHARED_RESOURCE {
67 	HANDLE Handle;
68 }
69 
70 enum {
71 	DXGI_RESOURCE_PRIORITY_MINIMUM	= 0x28000000,
72 	DXGI_RESOURCE_PRIORITY_LOW		= 0x50000000,
73 	DXGI_RESOURCE_PRIORITY_NORMAL	= 0x78000000,
74 	DXGI_RESOURCE_PRIORITY_HIGH		= 0xa0000000,
75 	DXGI_RESOURCE_PRIORITY_MAXIMUM	= 0xc8000000
76 }
77 
78 enum DXGI_RESIDENCY {
79 	DXGI_RESIDENCY_FULLY_RESIDENT				= 1,
80 	DXGI_RESIDENCY_RESIDENT_IN_SHARED_MEMORY	= 2,
81 	DXGI_RESIDENCY_EVICTED_TO_DISK				= 3
82 }
83 
84 struct DXGI_SURFACE_DESC {
85 	UINT Width;
86 	UINT Height;
87 	DXGI_FORMAT Format;
88 	DXGI_SAMPLE_DESC SampleDesc;
89 }
90 
91 enum DXGI_SWAP_EFFECT {
92 	DXGI_SWAP_EFFECT_DISCARD	= 0,
93 	DXGI_SWAP_EFFECT_SEQUENTIAL	= 1
94 }
95 
96 enum DXGI_SWAP_CHAIN_FLAG {
97 	DXGI_SWAP_CHAIN_FLAG_NONPREROTATED		= 1,
98 	DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH	= 2
99 }
100 
101 struct DXGI_SWAP_CHAIN_DESC {
102 	DXGI_MODE_DESC BufferDesc;
103 	DXGI_SAMPLE_DESC SampleDesc;
104 	DXGI_USAGE BufferUsage;
105 	UINT BufferCount;
106 	HWND OutputWindow;
107 	BOOL Windowed;
108 	DXGI_SWAP_EFFECT SwapEffect;
109 	UINT Flags;
110 }
111 
112 interface IDXGIObject : IUnknown {
113 	extern(Windows) :
114 	HRESULT SetPrivateData(REFGUID Name, UINT DataSize, void* pData);
115 	HRESULT SetPrivateDataInterface(REFGUID Name, IUnknown pUnknown);
116 	HRESULT GetPrivateData(REFGUID Name, UINT* pDataSize, void* pData);
117 	HRESULT GetParent(REFIID riid, void** ppParent);
118 }
119 
120 interface IDXGIDeviceSubObject : IDXGIObject {
121 	extern(Windows) :
122 	HRESULT GetDevice(REFIID riid, void** ppDevice);
123 }
124 
125 interface IDXGIResource : IDXGIDeviceSubObject {
126 	extern(Windows) :
127 	HRESULT GetSharedHandle(HANDLE* pSharedHandle);
128 	HRESULT GetUsage(DXGI_USAGE* pUsage);
129 	HRESULT SetEvictionPriority(UINT EvictionPriority);
130 	HRESULT GetEvictionPriority(UINT* pEvictionPriority);
131 }
132 
133 interface IDXGISurface : IDXGIDeviceSubObject {
134 	extern(Windows) :
135 	HRESULT GetDesc(DXGI_SURFACE_DESC* pDesc);
136 	HRESULT Map(DXGI_MAPPED_RECT* pLockedRect, UINT MapFlags);
137 	HRESULT Unmap();
138 }
139 
140 interface IDXGIAdapter : IDXGIObject {
141 	extern(Windows) :
142 	HRESULT EnumOutputs(UINT Output, IDXGIOutput* ppOutput);
143 	HRESULT GetDesc(DXGI_ADAPTER_DESC* pDesc);
144 	HRESULT CheckInterfaceSupport(REFGUID InterfaceName, LARGE_INTEGER* pUMDVersion);
145 }
146 
147 interface IDXGIOutput : IDXGIObject {
148 	extern(Windows) :
149 	HRESULT GetDesc(DXGI_OUTPUT_DESC* pDesc);
150 	HRESULT GetDisplayModeList(DXGI_FORMAT EnumFormat, UINT Flags, UINT* pNumModes, DXGI_MODE_DESC* pDesc);
151 	HRESULT FindClosestMatchingMode(DXGI_MODE_DESC* pModeToMatch, DXGI_MODE_DESC* pClosestMatch, IUnknown pConcernedDevice);
152 	HRESULT WaitForVBlank();
153 	HRESULT TakeOwnership(IUnknown pDevice, BOOL Exclusive);
154 	void ReleaseOwnership();
155 	HRESULT GetGammaControlCapabilities(DXGI_GAMMA_CONTROL_CAPABILITIES* pGammaCaps);
156 	HRESULT SetGammaControl(DXGI_GAMMA_CONTROL* pArray);
157 	HRESULT GetGammaControl(DXGI_GAMMA_CONTROL* pArray);
158 	HRESULT SetDisplaySurface(IDXGISurface pScanoutSurface);
159 	HRESULT GetDisplaySurfaceData(IDXGISurface pDestination);
160 	HRESULT GetFrameStatistics(DXGI_FRAME_STATISTICS* pStats);
161 }
162 
163 const DXGI_MAX_SWAP_CHAIN_BUFFERS = 16;
164 
165 enum {
166 	DXGI_PRESENT_TEST				= 0x00000001,
167 	DXGI_PRESENT_DO_NOT_SEQUENCE	= 0x00000002,
168 	DXGI_PRESENT_RESTART			= 0x00000004
169 }
170 
171 interface IDXGISwapChain : IDXGIDeviceSubObject {
172 	extern(Windows) :
173 	HRESULT Present(UINT SyncInterval, UINT Flags);
174 	HRESULT GetBuffer(UINT Buffer, REFIID riid, void** ppSurface);
175 	HRESULT SetFullscreenState(BOOL Fullscreen, IDXGIOutput pTarget);
176 	HRESULT GetFullscreenState(BOOL* pFullscreen, IDXGIOutput* ppTarget);
177 	HRESULT GetDesc(DXGI_SWAP_CHAIN_DESC* pDesc);
178 	HRESULT ResizeBuffers(UINT BufferCount, UINT Width, UINT Height, DXGI_FORMAT NewFormat, UINT SwapChainFlags);
179 	HRESULT ResizeTarget(DXGI_MODE_DESC* pNewTargetParameters);
180 	HRESULT GetContainingOutput(IDXGIOutput* ppOutput);
181 	HRESULT GetFrameStatistics(DXGI_FRAME_STATISTICS* pStats);
182 	HRESULT GetLastPresentCount(UINT* pLastPresentCount);
183 }
184 
185 interface IDXGIFactory : IDXGIObject {
186 	extern(Windows) :
187 	HRESULT EnumAdapters(UINT Adapter, IDXGIAdapter* ppAdapter);
188 	HRESULT MakeWindowAssociation(HWND WindowHandle, UINT Flags);
189 	HRESULT GetWindowAssociation(HWND* pWindowHandle);
190 	HRESULT CreateSwapChain(IUnknown pDevice, DXGI_SWAP_CHAIN_DESC* pDesc, IDXGISwapChain* ppSwapChain);
191 	HRESULT CreateSoftwareAdapter(HMODULE Module, IDXGIAdapter* ppAdapter);
192 }
193 
194 interface IDXGIDevice : IDXGIObject {
195 	extern(Windows) :
196 	HRESULT GetAdapter(IDXGIAdapter* pAdapter);
197 	HRESULT CreateSurface(DXGI_SURFACE_DESC* pDesc, UINT NumSurfaces, DXGI_USAGE Usage, DXGI_SHARED_RESOURCE* pSharedResource, IDXGISurface* ppSurface);
198 	HRESULT QueryResourceResidency(IUnknown* ppResources, DXGI_RESIDENCY* pResidencyStatus, UINT NumResources);
199 	HRESULT SetGPUThreadPriority(INT Priority);
200 	HRESULT GetGPUThreadPriority(INT* pPriority);
201 }
202 
203 extern(C) const GUID IID_IDXGIObject			= {0xaec22fb8, 0x76f3, 0x4639, [0x9b, 0xe0, 0x28, 0xeb, 0x43, 0xa6, 0x7a, 0x2e]};
204 extern(C) const GUID IID_IDXGIDeviceSubObject	= {0x3d3e0379, 0xf9de, 0x4d58, [0xbb, 0x6c, 0x18, 0xd6, 0x29, 0x92, 0xf1, 0xa6]};
205 extern(C) const GUID IID_IDXGIResource			= {0x035f3ab4, 0x482e, 0x4e50, [0xb4, 0x1f, 0x8a, 0x7f, 0x8b, 0xd8, 0x96, 0x0b]};
206 extern(C) const GUID IID_IDXGISurface			= {0xcafcb56c, 0x6ac3, 0x4889, [0xbf, 0x47, 0x9e, 0x23, 0xbb, 0xd2, 0x60, 0xec]};
207 extern(C) const GUID IID_IDXGIAdapter			= {0x2411e7e1, 0x12ac, 0x4ccf, [0xbd, 0x14, 0x97, 0x98, 0xe8, 0x53, 0x4d, 0xc0]};
208 extern(C) const GUID IID_IDXGIOutput			= {0xae02eedb, 0xc735, 0x4690, [0x8d, 0x52, 0x5a, 0x8d, 0xc2, 0x02, 0x13, 0xaa]};
209 extern(C) const GUID IID_IDXGISwapChain			= {0x310d36a0, 0xd2e7, 0x4c0a, [0xaa, 0x04, 0x6a, 0x9d, 0x23, 0xb8, 0x88, 0x6a]};
210 extern(C) const GUID IID_IDXGIFactory			= {0x7b7166ec, 0x21c7, 0x44ae, [0xb2, 0x1a, 0xc9, 0xae, 0x32, 0x1a, 0xe3, 0x69]};
211 extern(C) const GUID IID_IDXGIDevice			= {0x54ec77fa, 0x1377, 0x44e6, [0x8c, 0x32, 0x88, 0xfd, 0x5f, 0x44, 0xc8, 0x4c]};
212