如何使用SharpDX调用Trim?

时间:2014-02-11 01:37:16

标签: c# windows-8.1 sharpdx

我的Windows 8应用程序未通过认证测试:

应用程序应在其IDXGIDevice3界面上随时调用Trim API。

该链接将我带到C ++页面,但我正在使用SharpDX。我只能在这里的一篇文章https://www.packtpub.com/article/integrating-direct3d-xaml-windows81#more

中找到一个这样的例子

不幸的是它提到了一个DeviceManager类(我认为这本书?)而我的SharpDX.DXGI.Device3缺失了。有一个Device1和Device2,但没有3.也许不同版本的库或我错过了对其他东西的引用?

所以我正在寻找一个如何调用Trim的示例,以便认证应用程序很高兴并且在挂起应用程序时清理任何图形对象等。

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();
  }

2 个答案:

答案 0 :(得分:2)

SharpDX.DXGI.Device3可从DirectX11_2-winrt组件的最新SharpDX开发包(2.5.1)获得。

此DeviceManager不是DirectX API的一部分,但看起来它是本书示例的一部分。您需要通过“COM查询”原始DXGI设备上的接口来检索Device3设备(类似deviceManager.Device1.QueryInterface<Device3>();

答案 1 :(得分:2)

以下示例显示了如何调用Trim()以通过认证流程:

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();
}

您必须为SharpDX.DXGI.Device3下载并使用SharpDX Latest Dev Package(目前为2.5.1)