WinRT: Call IDXGIDevice3::Trim before app-suspend, as required on Windows 8.1
authorDavid Ludwig <dludwig@pobox.com>
Mon, 24 Mar 2014 22:51:03 -0400
changeset 8679dd52820b7f5c
parent 8678 7149b02f106b
child 8680 eb1281b43b5d
WinRT: Call IDXGIDevice3::Trim before app-suspend, as required on Windows 8.1

Thanks to Sylvain Becker for pointing this out!
src/core/winrt/SDL_winrtapp_direct3d.cpp
src/render/direct3d11/SDL_render_d3d11.c
     1.1 --- a/src/core/winrt/SDL_winrtapp_direct3d.cpp	Mon Mar 24 22:12:38 2014 -0400
     1.2 +++ b/src/core/winrt/SDL_winrtapp_direct3d.cpp	Mon Mar 24 22:51:03 2014 -0400
     1.3 @@ -70,6 +70,13 @@
     1.4  #include "SDL_winrtapp_common.h"
     1.5  #include "SDL_winrtapp_direct3d.h"
     1.6  
     1.7 +#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
     1.8 +/* Calling IDXGIDevice3::Trim on the active Direct3D 11.x device is necessary
     1.9 + * when Windows 8.1 apps are about to get suspended.
    1.10 + */
    1.11 +extern "C" void D3D11_Trim(SDL_Renderer *);
    1.12 +#endif
    1.13 +
    1.14  
    1.15  // Compile-time debugging options:
    1.16  // To enable, uncomment; to disable, comment them out.
    1.17 @@ -616,6 +623,18 @@
    1.18          // WinRT.
    1.19          SDL_SendAppEvent(SDL_APP_DIDENTERBACKGROUND);
    1.20  
    1.21 +        // Let the Direct3D 11 renderer prepare for the app to be backgrounded.
    1.22 +        // This is necessary for Windows 8.1, possibly elsewhere in the future.
    1.23 +        // More details at: http://msdn.microsoft.com/en-us/library/windows/apps/Hh994929.aspx
    1.24 +#if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED
    1.25 +        if (WINRT_GlobalSDLWindow) {
    1.26 +            SDL_Renderer * renderer = SDL_GetRenderer(WINRT_GlobalSDLWindow);
    1.27 +            if (renderer && (SDL_strcmp(renderer->info.name, "direct3d11") == 0)) {
    1.28 +                D3D11_Trim(renderer);
    1.29 +            }
    1.30 +        }
    1.31 +#endif
    1.32 +
    1.33          deferral->Complete();
    1.34      });
    1.35  }
     2.1 --- a/src/render/direct3d11/SDL_render_d3d11.c	Mon Mar 24 22:12:38 2014 -0400
     2.2 +++ b/src/render/direct3d11/SDL_render_d3d11.c	Mon Mar 24 22:51:03 2014 -0400
     2.3 @@ -35,6 +35,10 @@
     2.4  
     2.5  #ifdef __WINRT__
     2.6  
     2.7 +#if NTDDI_VERSION > NTDDI_WIN8
     2.8 +#include <DXGI1_3.h>
     2.9 +#endif
    2.10 +
    2.11  #include "SDL_render_winrt.h"
    2.12  
    2.13  #if WINAPI_FAMILY == WINAPI_FAMILY_APP
    2.14 @@ -134,6 +138,7 @@
    2.15  /* Defined here so we don't have to include uuid.lib */
    2.16  static const GUID IID_IDXGIFactory2 = { 0x50c83a1c, 0xe072, 0x4c48, { 0x87, 0xb0, 0x36, 0x30, 0xfa, 0x36, 0xa6, 0xd0 } };
    2.17  static const GUID IID_IDXGIDevice1 = { 0x77db970f, 0x6276, 0x48ba, { 0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c } };
    2.18 +static const GUID IID_IDXGIDevice3 = { 0x6007896c, 0x3244, 0x4afd, { 0xbf, 0x18, 0xa6, 0xd3, 0xbe, 0xda, 0x50, 0x23 } };
    2.19  static const GUID IID_ID3D11Texture2D = { 0x6f15aaf2, 0xd208, 0x4e89, { 0x9a, 0xb4, 0x48, 0x95, 0x35, 0xd3, 0x4f, 0x9c } };
    2.20  static const GUID IID_ID3D11Device1 = { 0xa04bfb29, 0x08ef, 0x43d6, { 0xa4, 0x9c, 0xa9, 0xbd, 0xbd, 0xcb, 0xe6, 0x86 } };
    2.21  static const GUID IID_ID3D11DeviceContext1 = { 0xbb2c6faa, 0xb5fb, 0x4082, { 0x8e, 0x6b, 0x38, 0x8b, 0x8c, 0xfa, 0x90, 0xe1 } };
    2.22 @@ -1601,6 +1606,27 @@
    2.23      return S_OK;
    2.24  }
    2.25  
    2.26 +void
    2.27 +D3D11_Trim(SDL_Renderer * renderer)
    2.28 +{
    2.29 +#ifdef __WINRT__
    2.30 +#if NTDDI_VERSION > NTDDI_WIN8
    2.31 +    D3D11_RenderData *data = (D3D11_RenderData *)renderer->driverdata;
    2.32 +    HRESULT result = S_OK;
    2.33 +    IDXGIDevice3 *dxgiDevice = NULL;
    2.34 +
    2.35 +    result = ID3D11Device_QueryInterface(data->d3dDevice, &IID_IDXGIDevice3, &dxgiDevice);
    2.36 +    if (FAILED(result)) {
    2.37 +        //WIN_SetErrorFromHRESULT(__FUNCTION__ ", ID3D11Device to IDXGIDevice3", result);
    2.38 +        return;
    2.39 +    }
    2.40 +
    2.41 +    IDXGIDevice3_Trim(dxgiDevice);
    2.42 +    SAFE_RELEASE(dxgiDevice);
    2.43 +#endif
    2.44 +#endif
    2.45 +}
    2.46 +
    2.47  static void
    2.48  D3D11_WindowEvent(SDL_Renderer * renderer, const SDL_WindowEvent *event)
    2.49  {