2

My windows 8 app is failing the Certification test:

The app should call the Trim API on its IDXGIDevice3 interface anytime it is about to be suspended.

The link takes me to a C++ page, but I'm using SharpDX. I can only find one example of this mentioned on a post in a book here https://www.packtpub.com/article/integrating-direct3d-xaml-windows81#more

Unfortunately it mentioned a DeviceManager class (from the book I think?) and my SharpDX.DXGI.Device3 is missing. There is a Device1 and Device2 but no 3. Perhaps different version of the library or I'm missing a reference to something else?

So I'm looking for an example of how to call Trim so that the Certification app is happy and it cleans up any graphics objects etc on suspending the app.

void App::OnSuspending(
_In_ Platform::Object^ sender,
_In_ Windows::ApplicationModel::SuspendingEventArgs^ args
)
  {
      Windows::ApplicationModel::SuspendingDeferral^ deferral = args->SuspendingOperation->GetDeferral();

      // Save application data

      m_exampleDxgiAdapter->Trim();
      deferral->Complete();
  }
Stephen Price
  • 1,629
  • 1
  • 24
  • 42

2 Answers2

2

SharpDX.DXGI.Device3 is available from latest SharpDX dev package (2.5.1) from the DirectX11_2-winrt assemblies.

This DeviceManager is not part of DirectX API but looks like it is part of the sample from the book. You need to retrieve the Device3 device by "COM-querying" the interface on the original DXGI device (something like deviceManager.Device1.QueryInterface<Device3>();)

xoofx
  • 3,682
  • 1
  • 17
  • 32
  • Awesome, checking it out now. Side note, there probably should be a link for that dev package on the downloads page. I've been trying to work it out with the one that's on that page (2.5.0). I found it on the About page after searching for 2.5.1 – Stephen Price Feb 11 '14 at 07:48
  • So that that hasn't helped. The Microsoft tool is telling me that I need to call Trim, and as far as I can tell I'm not even using DirectX3D (I'm using SharpDX to modify some bitmaps Direct2D1 - ie draw text onto them) so I feel like I have to add this code to call Trim on something I'm not even using. So i'm wondering how to get the device from that currently. – Stephen Price Feb 11 '14 at 08:55
  • You should post the whole initialization of the Direct2D device here, as it is really unclear in your description what are you using/doing (This DeviceManager, do you have the source code? Is it the same than in the SharpDX samples - which is bad and should not be used for production code). Usually a Direct2D device is initialized from a Direct3D device. – xoofx Feb 11 '14 at 12:28
2

The following example shows how to call Trim() in order to pass the Certification process:

async void OnSuspending(object sender, Windows.ApplicationModel.SuspendingEventArgs e)
{
    var Deferral = e.SuspendingOperation.GetDeferral();

    using (var Device = new SharpDX.Direct3D11.Device(SharpDX.Direct3D.DriverType.Hardware, SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport, new[] { SharpDX.Direct3D.FeatureLevel.Level_11_1, SharpDX.Direct3D.FeatureLevel.Level_11_0 }))
    using (var Direct3DDevice = Device.QueryInterface<SharpDX.Direct3D11.Device1>())
    using (var DxgiDevice3 = Direct3DDevice.QueryInterface<SharpDX.DXGI.Device3>())
        DxgiDevice3.Trim();

    Deferral.Complete();
}

You must download and use SharpDX Latest Dev Package (which is currently 2.5.1) for SharpDX.DXGI.Device3

M. Jahedbozorgan
  • 6,914
  • 2
  • 46
  • 51