Use toggle to turn off vsync on D3D12

Parameter syncInterval of function Preset specifies how to synchronize
presentation of a frame. To turn off vsync in D3D12 backend,
set syncInterval to 0 which represents the presentation occurs
immediately.

BUG=dawn:237

Change-Id: Ic17f00bae5af9fd6bca4130d6e2282f3c34de4e6
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/12303
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Yizhou Jiang <yizhou.jiang@intel.com>
This commit is contained in:
Yizhou Jiang 2019-10-18 01:45:28 +00:00 committed by Commit Bot service account
parent b2b2ef57a5
commit 4794168ef8
2 changed files with 5 additions and 2 deletions

View File

@ -39,7 +39,7 @@ namespace dawn_native { namespace d3d12 {
} // anonymous namespace
NativeSwapChainImpl::NativeSwapChainImpl(Device* device, HWND window)
: mWindow(window), mDevice(device) {
: mWindow(window), mDevice(device), mInterval(1) {
}
NativeSwapChainImpl::~NativeSwapChainImpl() {
@ -59,6 +59,8 @@ namespace dawn_native { namespace d3d12 {
ComPtr<IDXGIFactory4> factory = mDevice->GetFactory();
ComPtr<ID3D12CommandQueue> queue = mDevice->GetCommandQueue();
mInterval = mDevice->IsToggleEnabled(Toggle::TurnOffVsync) == true ? 0 : 1;
// Create the D3D12 swapchain, assuming only two buffers for now
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {};
swapChainDesc.Width = width;
@ -103,7 +105,7 @@ namespace dawn_native { namespace d3d12 {
DawnSwapChainError NativeSwapChainImpl::Present() {
// This assumes the texture has already been transition to the PRESENT state.
ASSERT_SUCCESS(mSwapChain->Present(1, 0));
ASSERT_SUCCESS(mSwapChain->Present(mInterval, 0));
// TODO(cwallez@chromium.org): Make the serial ticking implicit.
ASSERT(mDevice->NextSerial().IsSuccess());

View File

@ -46,6 +46,7 @@ namespace dawn_native { namespace d3d12 {
private:
HWND mWindow = nullptr;
Device* mDevice = nullptr;
UINT mInterval;
ComPtr<IDXGISwapChain3> mSwapChain = nullptr;
std::vector<ComPtr<ID3D12Resource>> mBuffers;