Go to the documentation of this file.
30 #include <VersionHelpers.h>
40 template <
class BaseInterface,
typename DXGISwapChainType>
50 const NativeWindow& Window) :
52 TBase{pRefCounters, pDevice, pDeviceContext, SCDesc},
62 " is not an allowed pretransform because Direct3D swap chains only support identity transform. "
63 "Use SURFACE_TRANSFORM_OPTIMAL (recommended) or SURFACE_TRANSFORM_IDENTITY.");
75 BOOL IsFullScreen = FALSE;
76 m_pSwapChain->GetFullscreenState(&IsFullScreen,
nullptr);
91 " is not an allowed pretransform because Direct3D swap chains only support identity transform. "
92 "Use SURFACE_TRANSFORM_OPTIMAL (recommended) or SURFACE_TRANSFORM_IDENTITY.");
102 auto hWnd =
reinterpret_cast<HWND
>(
m_Window.hWnd);
108 const HWND hDesktop = GetDesktopWindow();
109 GetWindowRect(hDesktop, &rc);
113 GetClientRect(hWnd, &rc);
121 "Direct3D swap chains only support identity transform.");
127 DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {};
138 switch (DXGIColorBuffFmt)
140 case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:
141 swapChainDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
144 case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
145 swapChainDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
149 swapChainDesc.Format = DXGIColorBuffFmt;
152 swapChainDesc.Stereo = FALSE;
156 swapChainDesc.SampleDesc.Count = 1;
157 swapChainDesc.SampleDesc.Quality = 0;
161 swapChainDesc.BufferUsage = 0;
163 swapChainDesc.BufferUsage |= DXGI_USAGE_RENDER_TARGET_OUTPUT;
165 swapChainDesc.BufferUsage |= DXGI_USAGE_SHADER_INPUT;
170 swapChainDesc.Scaling = DXGI_SCALING_NONE;
172 #if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
174 if (!IsWindows8OrGreater())
175 swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
182 swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
184 swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
189 swapChainDesc.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
192 CComPtr<IDXGIFactory2> pDXGIFactory;
194 HRESULT hr = CreateDXGIFactory1(__uuidof(pDXGIFactory),
reinterpret_cast<void**
>(
static_cast<IDXGIFactory2**
>(&pDXGIFactory)));
208 CComPtr<IDXGIFactory3> pDXGIFactory3;
209 if (SUCCEEDED(pDXGIFactory.QueryInterface(&pDXGIFactory3)))
211 swapChainDesc.Flags |= DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT;
216 CComPtr<IDXGISwapChain1> pSwapChain1;
220 DXGI_SWAP_CHAIN_FULLSCREEN_DESC FullScreenDesc = {};
225 FullScreenDesc.Scaling =
static_cast<DXGI_MODE_SCALING
>(
m_FSDesc.
Scaling);
228 hr = pDXGIFactory->CreateSwapChainForHwnd(pD3D11DeviceOrD3D12CmdQueue, hWnd, &swapChainDesc, &FullScreenDesc,
nullptr, &pSwapChain1);
235 CComPtr<IDXGIFactory1> pFactoryFromSC;
236 if (SUCCEEDED(pSwapChain1->GetParent(__uuidof(pFactoryFromSC), (
void**)&pFactoryFromSC)))
239 pFactoryFromSC->MakeWindowAssociation(hWnd, DXGI_MWA_NO_WINDOW_CHANGES | DXGI_MWA_NO_ALT_ENTER);
243 #elif PLATFORM_UNIVERSAL_WINDOWS
248 hr = pDXGIFactory->CreateSwapChainForCoreWindow(
249 pD3D11DeviceOrD3D12CmdQueue,
250 reinterpret_cast<IUnknown*
>(
m_Window.pCoreWindow),
261 if ((swapChainDesc.Flags & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT) != 0)
263 CComPtr<IDXGISwapChain2> pSwapChain2;
264 if (SUCCEEDED(pSwapChain1.QueryInterface(&pSwapChain2)))
288 if (Res != WAIT_OBJECT_0)
290 const char* ErrorMsg = Res == WAIT_TIMEOUT ?
291 "Timeout elapsed while waiting for the frame waitable object." :
292 "Waiting for the frame waitable object failed.";
293 LOG_ERROR_MESSAGE(ErrorMsg,
" This is a strong indication of a synchronization error.");
@ SWAP_CHAIN_USAGE_RENDER_TARGET
Swap chain can be used as render target ouput.
Definition: GraphicsTypes.h:1301
const char * GetSurfaceTransformString(SURFACE_TRANSFORM SrfTransform)
Definition: GraphicsAccessories.cpp:1119
Base interface for a reference counter object that stores the number of strong and weak references an...
Definition: ReferenceCounters.h:44
#define LOG_ERROR_MESSAGE(...)
Definition: Errors.hpp:122
SURFACE_TRANSFORM m_DesiredPreTransform
Desired surface pre-transformation.
Definition: SwapChainBase.hpp:125
void CreateDXGISwapChain(IUnknown *pD3D11DeviceOrD3D12CmdQueue)
Definition: SwapChainD3DBase.hpp:99
bool Resize(Uint32 NewWidth, Uint32 NewHeight, SURFACE_TRANSFORM NewPreTransform, Int32 Dummy=0)
Definition: SwapChainD3DBase.hpp:85
Uint32 Width
The swap chain width. Default value is 0.
Definition: GraphicsTypes.h:1350
TEXTURE_FORMAT ColorBufferFormat
Back buffer format. Default value is Diligent::TEX_FORMAT_RGBA8_UNORM_SRGB.
Definition: GraphicsTypes.h:1356
Uint32 RefreshRateDenominator
Refresh rate denominator.
Definition: GraphicsTypes.h:1434
CComPtr< DXGISwapChainType > m_pSwapChain
Definition: SwapChainD3DBase.hpp:364
virtual void UpdateSwapChain(bool CreateNew)=0
@ SURFACE_TRANSFORM_IDENTITY
The image content is presented without being transformed.
Definition: GraphicsTypes.h:1321
Uint32 m_MaxFrameLatency
Definition: SwapChainD3DBase.hpp:369
#define DEV_CHECK_ERR(...)
Definition: DebugUtilities.hpp:90
@ TEX_FORMAT_UNKNOWN
Unknown format.
Definition: GraphicsTypes.h:331
enum SCALING_MODE Scaling
The scanline drawing mode.
Definition: GraphicsTypes.h:1437
int32_t Int32
32-bit signed integer
Definition: BasicTypes.h:46
@ SURFACE_TRANSFORM_OPTIMAL
Uset the most optimal surface transform.
Definition: GraphicsTypes.h:1318
Render device interface.
Definition: RenderDevice.h:75
SURFACE_TRANSFORM
The transform applied to the image content prior to presentation.
Definition: GraphicsTypes.h:1315
virtual void SetDXGIDeviceMaximumFrameLatency()
Definition: SwapChainD3DBase.hpp:361
Base implementation of a D3D swap chain.
Definition: SwapChainD3DBase.hpp:41
SWAP_CHAIN_USAGE_FLAGS Usage
Swap chain usage flags. Default value is Diligent::SWAP_CHAIN_USAGE_RENDER_TARGET.
Definition: GraphicsTypes.h:1363
n int Dummy
Definition: GenerateMipsCS_inc.h:25
Display mode attributes.
Definition: GraphicsTypes.h:1269
#define DILIGENT_CALL_TYPE
Definition: CommonDefinitions.h:45
Uint32 BufferCount
The number of buffers in the swap chain.
Definition: GraphicsTypes.h:1379
void WaitForFrame()
Definition: SwapChainD3DBase.hpp:280
NativeWindow m_Window
Definition: SwapChainD3DBase.hpp:365
Base implementation of the swap chain.
Definition: SwapChainBase.hpp:51
@ SWAP_CHAIN_USAGE_COPY_SOURCE
Swap chain images can be used as source of copy operation.
Definition: GraphicsTypes.h:1307
Swap chain description.
Definition: GraphicsTypes.h:1347
uint32_t Uint32
32-bit unsigned integer
Definition: BasicTypes.h:51
bool Resize(Uint32 NewWidth, Uint32 NewHeight, SURFACE_TRANSFORM NewPreTransform, Int32 Dummy=0)
Definition: SwapChainBase.hpp:97
FullScreenModeDesc m_FSDesc
Definition: SwapChainD3DBase.hpp:363
virtual void SetFullscreenMode(const DisplayModeAttribs &DisplayMode) override final
Definition: SwapChainD3DBase.hpp:298
@ SWAP_CHAIN_USAGE_LAST
Definition: GraphicsTypes.h:1309
RefCntAutoPtr< IRenderDevice > m_pRenderDevice
Strong reference to the render device.
Definition: SwapChainBase.hpp:115
@ SWAP_CHAIN_USAGE_SHADER_INPUT
Swap chain images can be used as shader inputs.
Definition: GraphicsTypes.h:1304
Bool Fullscreen
A Boolean value that specifies whether the swap chain is in fullscreen mode.
Definition: GraphicsTypes.h:1428
SwapChainDesc m_SwapChainDesc
Swap chain description.
Definition: SwapChainBase.hpp:122
#define LOG_WARNING_MESSAGE(...)
Definition: Errors.hpp:123
SwapChainD3DBase(IReferenceCounters *pRefCounters, IRenderDevice *pDevice, IDeviceContext *pDeviceContext, const SwapChainDesc &SCDesc, const FullScreenModeDesc &FSDesc, const NativeWindow &Window)
Definition: SwapChainD3DBase.hpp:45
HANDLE m_FrameLatencyWaitableObject
Definition: SwapChainD3DBase.hpp:367
Device context interface.
Definition: DeviceContext.h:1460
@ RENDER_DEVICE_TYPE_D3D11
D3D11 device.
Definition: GraphicsTypes.h:1482
SURFACE_TRANSFORM PreTransform
The transform, relative to the presentation engine's natural orientation, applied to the image conten...
Definition: GraphicsTypes.h:1376
DXGI_FORMAT TexFormatToDXGI_Format(TEXTURE_FORMAT TexFormat, Uint32 BindFlags=0)
Definition: DXGITypeConversions.cpp:276
Uint32 RefreshRateNumerator
Refresh rate numerator.
Definition: GraphicsTypes.h:1431
~SwapChainD3DBase()
Definition: SwapChainD3DBase.hpp:69
#define VERIFY(...)
Definition: DebugUtilities.hpp:76
#define CHECK_D3D_RESULT_THROW(Expr, Message)
Definition: D3DErrors.hpp:82
enum SCANLINE_ORDER ScanlineOrder
The scaling mode.
Definition: GraphicsTypes.h:1440
virtual void SetMaximumFrameLatency(Uint32 MaxLatency) override final
Definition: SwapChainD3DBase.hpp:329
Uint32 Height
The swap chain height. Default value is 0.
Definition: GraphicsTypes.h:1353
virtual void SetWindowedMode() override final
Definition: SwapChainD3DBase.hpp:320
The library uses Direct3D-style math:
Definition: AdvancedMath.hpp:37
Full screen mode description.
Definition: GraphicsTypes.h:1425