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