Commit d176dbd7 by Sunny Sachanandani Committed by Jamie Madill

Enable postSubBuffer on D3D11 with DXGI 1.2.

BUG=147291 Change-Id: Iafddb83b4949168f1c59272a99ae0244d86ce3f9 Reviewed-on: https://chromium-review.googlesource.com/270572Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarSunny Sachanandani <sunnyps@chromium.org>
parent 9c0a4218
......@@ -1540,7 +1540,7 @@ gl::Error Renderer11::drawArrays(const gl::Data &data, GLenum mode, GLsizei coun
{
// Since point sprites are generated with a geometry shader, too many vertices will
// be written if transform feedback is active. To work around this, draw only the points
// with the stream out shader and no pixel shader to feed the stream out buffers and then
// with the stream out shader and no pixel shader to feed the stream out buffers and then
// draw again with the point sprite geometry shader to rasterize the point sprites.
mDeviceContext->PSSetShader(NULL, NULL, 0);
......@@ -1605,7 +1605,7 @@ gl::Error Renderer11::drawArrays(const gl::Data &data, GLenum mode, GLsizei coun
else
{
// If gl_PointSize is used and GL_POINTS is specified, then it is expected to render pointsprites.
// If instanced pointsprite emulation is being used the topology is expexted to be
// If instanced pointsprite emulation is being used the topology is expexted to be
// D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST and DrawIndexedInstanced must be used.
if (mode == GL_POINTS && useInstancedPointSpriteEmulation)
{
......@@ -2407,8 +2407,8 @@ bool Renderer11::getShareHandleSupport() const
bool Renderer11::getPostSubBufferSupport() const
{
// D3D11 does not support present with dirty rectangles until D3D11.1 and DXGI 1.2.
return false;
// D3D11 does not support present with dirty rectangles until DXGI 1.2.
return mRenderer11DeviceCaps.supportsDXGI1_2;
}
int Renderer11::getMajorShaderModel() const
......
......@@ -30,6 +30,7 @@ SwapChain11::SwapChain11(Renderer11 *renderer, NativeWindow nativeWindow, HANDLE
mDepthStencilRenderTarget(this, renderer, true)
{
mSwapChain = NULL;
mSwapChain1 = nullptr;
mBackBufferTexture = NULL;
mBackBufferRTView = NULL;
mOffscreenTexture = NULL;
......@@ -57,6 +58,7 @@ SwapChain11::~SwapChain11()
void SwapChain11::release()
{
SafeRelease(mSwapChain1);
SafeRelease(mSwapChain);
SafeRelease(mBackBufferTexture);
SafeRelease(mBackBufferRTView);
......@@ -396,6 +398,7 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap
// Release specific resources to free up memory for the new render target, while the
// old render target still exists for the purpose of preserving its contents.
SafeRelease(mSwapChain1);
SafeRelease(mSwapChain);
SafeRelease(mBackBufferTexture);
SafeRelease(mBackBufferRTView);
......@@ -437,6 +440,11 @@ EGLint SwapChain11::reset(int backbufferWidth, int backbufferHeight, EGLint swap
}
}
if (mRenderer->getRenderer11DeviceCaps().supportsDXGI1_2)
{
mSwapChain1 = d3d11::DynamicCastComObject<IDXGISwapChain1>(mSwapChain);
}
result = mSwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), (LPVOID*)&mBackBufferTexture);
ASSERT(SUCCEEDED(result));
d3d11::SetDebugName(mBackBufferTexture, "Back buffer texture");
......@@ -598,7 +606,21 @@ EGLint SwapChain11::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
#if ANGLE_VSYNC == ANGLE_DISABLED
result = mSwapChain->Present(0, 0);
#else
result = mSwapChain->Present(mSwapInterval, 0);
// Use IDXGISwapChain1::Present1 with a dirty rect if DXGI 1.2 is available.
if (mSwapChain1 != nullptr)
{
RECT rect =
{
static_cast<LONG>(x), static_cast<LONG>(mHeight - y - height),
static_cast<LONG>(x + width), static_cast<LONG>(mHeight - y)
};
DXGI_PRESENT_PARAMETERS params = { 1, &rect, nullptr, nullptr };
result = mSwapChain1->Present1(mSwapInterval, 0, &params);
}
else
{
result = mSwapChain->Present(mSwapInterval, 0);
}
#endif
if (result == DXGI_ERROR_DEVICE_REMOVED)
......
......@@ -57,6 +57,7 @@ class SwapChain11 : public SwapChainD3D
bool mPassThroughResourcesInit;
DXGISwapChain *mSwapChain;
IDXGISwapChain1 *mSwapChain1;
ID3D11Texture2D *mBackBufferTexture;
ID3D11RenderTargetView *mBackBufferRTView;
......
......@@ -7,6 +7,7 @@
// NativeWindow.cpp: Handler for managing HWND native window types.
#include "libANGLE/renderer/d3d/d3d11/NativeWindow.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
#include "common/debug.h"
......@@ -18,8 +19,8 @@ NativeWindow::NativeWindow(EGLNativeWindowType window) : mWindow(window)
}
bool NativeWindow::initialize()
{
return true;
{
return true;
}
bool NativeWindow::getClientRect(LPRECT rect)
......@@ -46,6 +47,30 @@ HRESULT NativeWindow::createSwapChain(ID3D11Device* device, DXGIFactory* factory
return E_INVALIDARG;
}
// Use IDXGIFactory2::CreateSwapChainForHwnd if DXGI 1.2 is available to create a DXGI_SWAP_EFFECT_SEQUENTIAL swap chain.
IDXGIFactory2 *factory2 = d3d11::DynamicCastComObject<IDXGIFactory2>(factory);
if (factory2 != nullptr)
{
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = { 0 };
swapChainDesc.Width = width;
swapChainDesc.Height = height;
swapChainDesc.Format = format;
swapChainDesc.Stereo = FALSE;
swapChainDesc.SampleDesc.Count = 1;
swapChainDesc.SampleDesc.Quality = 0;
swapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_BACK_BUFFER;
swapChainDesc.BufferCount = 1;
swapChainDesc.Scaling = DXGI_SCALING_STRETCH;
swapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_SEQUENTIAL;
swapChainDesc.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
swapChainDesc.Flags = 0;
IDXGISwapChain1 *swapChain1 = nullptr;
HRESULT result = factory2->CreateSwapChainForHwnd(device, mWindow, &swapChainDesc, nullptr, nullptr, &swapChain1);
*swapChain = static_cast<DXGISwapChain*>(swapChain1);
SafeRelease(factory2);
return result;
}
DXGI_SWAP_CHAIN_DESC swapChainDesc = { 0 };
swapChainDesc.BufferCount = 1;
swapChainDesc.BufferDesc.Format = format;
......
......@@ -312,8 +312,8 @@ EGLint SwapChain9::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
RECT rect =
{
x, mHeight - y - height,
x + width, mHeight - y
static_cast<LONG>(x), static_cast<LONG>(mHeight - y - height),
static_cast<LONG>(x + width), static_cast<LONG>(mHeight - y)
};
HRESULT result = mSwapChain->Present(&rect, &rect, NULL, NULL, 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment