Commit 53c1a456 by Austin Kinross Committed by Jamie Madill

In Clear11, use ID3D11DeviceContext1::ClearView when appropriate

Change-Id: I8d9054b5582cfe78beaff07146adc73b4716eaf9 Reviewed-on: https://chromium-review.googlesource.com/233680Tested-by: 's avatarAustin Kinross <aukinros@microsoft.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent eb32a2e9
......@@ -81,7 +81,7 @@ Clear11::ClearShader Clear11::CreateClearShader(ID3D11Device *device, DXGI_FORMA
Clear11::Clear11(Renderer11 *renderer)
: mRenderer(renderer), mClearBlendStates(StructLessThan<ClearBlendInfo>), mClearDepthStencilStates(StructLessThan<ClearDepthStencilInfo>),
mVertexBuffer(NULL), mRasterizerState(NULL)
mVertexBuffer(NULL), mRasterizerState(NULL), mSupportsClearView(false)
{
HRESULT result;
ID3D11Device *device = renderer->getDevice();
......@@ -128,6 +128,13 @@ Clear11::Clear11(Renderer11 *renderer)
mUintClearShader = CreateClearShader(device, DXGI_FORMAT_R32G32B32A32_UINT, g_VS_ClearUint, g_PS_ClearUint );
mIntClearShader = CreateClearShader(device, DXGI_FORMAT_R32G32B32A32_SINT, g_VS_ClearSint, g_PS_ClearSint );
}
if (renderer->getDeviceContext1IfSupported())
{
D3D11_FEATURE_DATA_D3D11_OPTIONS d3d11Options;
device->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS, &d3d11Options, sizeof(D3D11_FEATURE_DATA_D3D11_OPTIONS));
mSupportsClearView = (d3d11Options.ClearView != FALSE);
}
}
Clear11::~Clear11()
......@@ -165,15 +172,19 @@ Clear11::~Clear11()
gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, const gl::Framebuffer *frameBuffer)
{
// First determine if a scissored clear is needed, this will always require drawing a quad.
//
// Otherwise, iterate over the color buffers which require clearing and determine if they can be
// cleared with ID3D11DeviceContext::ClearRenderTargetView... This requires:
// Iterate over the color buffers which require clearing and determine if they can be
// cleared with ID3D11DeviceContext::ClearRenderTargetView or ID3D11DeviceContext1::ClearView.
// This requires:
// 1) The render target is being cleared to a float value (will be cast to integer when clearing integer
// render targets as expected but does not work the other way around)
// 2) The format of the render target has no color channels that are currently masked out.
// Clear the easy-to-clear buffers on the spot and accumulate the ones that require special work.
//
// If these conditions are met, and:
// - No scissored clear is needed, then clear using ID3D11DeviceContext::ClearRenderTargetView.
// - A scissored clear is needed then clear using ID3D11DeviceContext1::ClearView if available.
// Otherwise draw a quad.
//
// Also determine if the depth stencil can be cleared with ID3D11DeviceContext::ClearDepthStencilView
// by checking if the stencil write mask covers the entire stencil.
//
......@@ -218,6 +229,7 @@ gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, cons
RenderTarget11* maskedClearDepthStencil = NULL;
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
ID3D11DeviceContext1 *deviceContext1 = mRenderer->getDeviceContext1IfSupported();
for (unsigned int colorAttachment = 0; colorAttachment < gl::IMPLEMENTATION_MAX_DRAW_BUFFERS; colorAttachment++)
{
......@@ -251,13 +263,13 @@ gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, cons
// Every channel either does not exist in the render target or is masked out
continue;
}
else if (needScissoredClear || clearParams.colorClearType != GL_FLOAT ||
else if ((!mSupportsClearView && needScissoredClear) || clearParams.colorClearType != GL_FLOAT ||
(formatInfo.redBits > 0 && !clearParams.colorMaskRed) ||
(formatInfo.greenBits > 0 && !clearParams.colorMaskGreen) ||
(formatInfo.blueBits > 0 && !clearParams.colorMaskBlue) ||
(formatInfo.alphaBits > 0 && !clearParams.colorMaskAlpha))
{
// A scissored or masked clear is required
// A masked clear is required, or a scissored clear is required and ID3D11DeviceContext1::ClearView is unavailable
MaskedRenderTarget maskAndRt;
bool clearColor = clearParams.clearColor[colorAttachment];
maskAndRt.colorMask[0] = (clearColor && clearParams.colorMaskRed);
......@@ -269,7 +281,7 @@ gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, cons
}
else
{
// ID3D11DeviceContext::ClearRenderTargetView is possible
// ID3D11DeviceContext::ClearRenderTargetView or ID3D11DeviceContext1::ClearView is possible
ID3D11RenderTargetView *framebufferRTV = renderTarget->getRenderTargetView();
if (!framebufferRTV)
......@@ -289,7 +301,23 @@ gl::Error Clear11::clearFramebuffer(const gl::ClearParameters &clearParams, cons
((formatInfo.alphaBits == 0 && actualFormatInfo.alphaBits > 0) ? 1.0f : clearParams.colorFClearValue.alpha),
};
deviceContext->ClearRenderTargetView(framebufferRTV, clearValues);
if (needScissoredClear)
{
// We shouldn't reach here if deviceContext1 is unavailable.
ASSERT(deviceContext1);
D3D11_RECT rect;
rect.left = clearParams.scissor.x;
rect.right = clearParams.scissor.x + clearParams.scissor.width;
rect.top = clearParams.scissor.y;
rect.bottom = clearParams.scissor.y + clearParams.scissor.height;
deviceContext1->ClearView(framebufferRTV, clearValues, &rect, 1);
}
else
{
deviceContext->ClearRenderTargetView(framebufferRTV, clearValues);
}
}
}
}
......
......@@ -80,6 +80,8 @@ class Clear11
ID3D11Buffer *mVertexBuffer;
ID3D11RasterizerState *mRasterizerState;
bool mSupportsClearView;
};
}
......
......@@ -177,6 +177,7 @@ Renderer11::Renderer11(egl::Display *display, EGLNativeDisplayType hDc, const eg
mDevice = NULL;
mDeviceContext = NULL;
mDeviceContext1 = NULL;
mDxgiAdapter = NULL;
mDxgiFactory = NULL;
......@@ -334,6 +335,11 @@ EGLint Renderer11::initialize()
#endif
#endif
// Cast the DeviceContext to a DeviceContext1.
// This could fail on Windows 7 without the Platform Update.
// Don't error in this case- just don't use mDeviceContext1.
mDeviceContext1 = d3d11::DynamicCastComObject<ID3D11DeviceContext1>(mDeviceContext);
IDXGIDevice *dxgiDevice = NULL;
result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice);
......@@ -1924,6 +1930,8 @@ void Renderer11::release()
SafeRelease(mDxgiFactory);
SafeRelease(mDxgiAdapter);
SafeRelease(mDeviceContext1);
if (mDeviceContext)
{
mDeviceContext->ClearState();
......
......@@ -189,6 +189,7 @@ class Renderer11 : public RendererD3D
// D3D11-renderer specific methods
ID3D11Device *getDevice() { return mDevice; }
ID3D11DeviceContext *getDeviceContext() { return mDeviceContext; };
ID3D11DeviceContext1 *getDeviceContext1IfSupported() { return mDeviceContext1; };
DXGIFactory *getDxgiFactory() { return mDxgiFactory; };
Blit11 *getBlitter() { return mBlit; }
......@@ -366,6 +367,7 @@ class Renderer11 : public RendererD3D
ID3D11Device *mDevice;
D3D_FEATURE_LEVEL mFeatureLevel;
ID3D11DeviceContext *mDeviceContext;
ID3D11DeviceContext1 *mDeviceContext1;
IDXGIAdapter *mDxgiAdapter;
DXGI_ADAPTER_DESC mAdapterDescription;
char mDescription[128];
......
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