Commit c174db3a by Jamie Madill Committed by Commit Bot

D3D11: Apply a non-null blendstate in masked depth clear.

In https://chromium-review.googlesource.com/c/453888/, we changed how blendstates were applied in masked clears. This change would apply a null blendstate when all color channels were disabled, but this seems to have an issue on Intel Cherry View drivers. Work around this issue by restoring the prior functionality of making a simple masked blend state. Also clean up some of the code style in the Clear11 class. BUG=chromium:730126 Change-Id: I9a4044201b2f07e9483525513a59e19bb2a8bcd3 Reviewed-on: https://chromium-review.googlesource.com/533684Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent dbcced8e
...@@ -213,9 +213,9 @@ gl::Error Clear11::ensureResourcesInitialized() ...@@ -213,9 +213,9 @@ gl::Error Clear11::ensureResourcesInitialized()
mDepthStencilStateKey.depthFunc = GL_ALWAYS; mDepthStencilStateKey.depthFunc = GL_ALWAYS;
mDepthStencilStateKey.stencilWritemask = static_cast<GLuint>(-1); mDepthStencilStateKey.stencilWritemask = static_cast<GLuint>(-1);
mDepthStencilStateKey.stencilBackWritemask = static_cast<GLuint>(-1); mDepthStencilStateKey.stencilBackWritemask = static_cast<GLuint>(-1);
mDepthStencilStateKey.stencilBackMask = static_cast<GLuint>(-1); mDepthStencilStateKey.stencilBackMask = 0;
mDepthStencilStateKey.stencilTest = false; mDepthStencilStateKey.stencilTest = false;
mDepthStencilStateKey.stencilMask = static_cast<GLuint>(-1); mDepthStencilStateKey.stencilMask = 0;
mDepthStencilStateKey.stencilFail = GL_REPLACE; mDepthStencilStateKey.stencilFail = GL_REPLACE;
mDepthStencilStateKey.stencilPassDepthFail = GL_REPLACE; mDepthStencilStateKey.stencilPassDepthFail = GL_REPLACE;
mDepthStencilStateKey.stencilPassDepthPass = GL_REPLACE; mDepthStencilStateKey.stencilPassDepthPass = GL_REPLACE;
...@@ -316,19 +316,6 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -316,19 +316,6 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
{ {
ANGLE_TRY(ensureResourcesInitialized()); ANGLE_TRY(ensureResourcesInitialized());
const auto &colorAttachments = fboData.getColorAttachments();
const auto &drawBufferStates = fboData.getDrawBufferStates();
const gl::FramebufferAttachment *depthStencilAttachment = fboData.getDepthOrStencilAttachment();
RenderTarget11 *depthStencilRenderTarget = nullptr;
ASSERT(colorAttachments.size() <= drawBufferStates.size());
if (clearParams.clearDepth || clearParams.clearStencil)
{
ASSERT(depthStencilAttachment != nullptr);
ANGLE_TRY(depthStencilAttachment->getRenderTarget(&depthStencilRenderTarget));
}
// Iterate over the color buffers which require clearing and determine if they can be // Iterate over the color buffers which require clearing and determine if they can be
// cleared with ID3D11DeviceContext::ClearRenderTargetView or ID3D11DeviceContext1::ClearView. // cleared with ID3D11DeviceContext::ClearRenderTargetView or ID3D11DeviceContext1::ClearView.
// This requires: // This requires:
...@@ -358,6 +345,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -358,6 +345,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
gl::Extents framebufferSize; gl::Extents framebufferSize;
const auto *depthStencilAttachment = fboData.getDepthOrStencilAttachment();
if (depthStencilAttachment != nullptr) if (depthStencilAttachment != nullptr)
{ {
framebufferSize = depthStencilAttachment->getSize(); framebufferSize = depthStencilAttachment->getSize();
...@@ -399,21 +387,23 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -399,21 +387,23 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
ID3D11DeviceContext1 *deviceContext1 = mRenderer->getDeviceContext1IfSupported(); ID3D11DeviceContext1 *deviceContext1 = mRenderer->getDeviceContext1IfSupported();
std::array<ID3D11RenderTargetView *, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT> rtvs; std::array<ID3D11RenderTargetView *, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT> rtvs;
std::array<uint8_t, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT> rtvMasks; std::array<uint8_t, D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT> rtvMasks = {};
ID3D11DepthStencilView *dsv = nullptr;
uint32_t numRtvs = 0; uint32_t numRtvs = 0;
const uint8_t colorMask = const uint8_t colorMask =
gl_d3d11::ConvertColorMask(clearParams.colorMaskRed, clearParams.colorMaskGreen, gl_d3d11::ConvertColorMask(clearParams.colorMaskRed, clearParams.colorMaskGreen,
clearParams.colorMaskBlue, clearParams.colorMaskAlpha); clearParams.colorMaskBlue, clearParams.colorMaskAlpha);
for (size_t colorAttachmentIndex = 0; colorAttachmentIndex < colorAttachments.size(); const auto &colorAttachments = fboData.getColorAttachments();
colorAttachmentIndex++) for (auto colorAttachmentIndex : fboData.getEnabledDrawBuffers())
{ {
const gl::FramebufferAttachment &attachment = colorAttachments[colorAttachmentIndex]; const gl::FramebufferAttachment &attachment = colorAttachments[colorAttachmentIndex];
if (clearParams.clearColor[colorAttachmentIndex] && attachment.isAttached() && if (!clearParams.clearColor[colorAttachmentIndex])
drawBufferStates[colorAttachmentIndex] != GL_NONE)
{ {
continue;
}
RenderTarget11 *renderTarget = nullptr; RenderTarget11 *renderTarget = nullptr;
ANGLE_TRY(attachment.getRenderTarget(&renderTarget)); ANGLE_TRY(attachment.getRenderTarget(&renderTarget));
...@@ -440,12 +430,8 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -440,12 +430,8 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
continue; continue;
} }
const d3d11::RenderTargetView &framebufferRTV = renderTarget->getRenderTargetView(); const auto &framebufferRTV = renderTarget->getRenderTargetView();
if (!framebufferRTV.valid()) ASSERT(framebufferRTV.valid());
{
return gl::OutOfMemory()
<< "Clear11: Render target view pointer unexpectedly null.";
}
if ((!(mRenderer->getRenderer11DeviceCaps().supportsClearView) && needScissoredClear) || if ((!(mRenderer->getRenderer11DeviceCaps().supportsClearView) && needScissoredClear) ||
clearParams.colorType != GL_FLOAT || clearParams.colorType != GL_FLOAT ||
...@@ -455,7 +441,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -455,7 +441,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
(formatInfo.alphaBits > 0 && !clearParams.colorMaskAlpha)) (formatInfo.alphaBits > 0 && !clearParams.colorMaskAlpha))
{ {
rtvs[numRtvs] = framebufferRTV.get(); rtvs[numRtvs] = framebufferRTV.get();
rtvMasks[numRtvs] = gl_d3d11::GetColorMask(&formatInfo) & colorMask; rtvMasks[numRtvs] = gl_d3d11::GetColorMask(formatInfo) & colorMask;
numRtvs++; numRtvs++;
} }
else else
...@@ -468,14 +454,12 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -468,14 +454,12 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
// Check if the actual format has a channel that the internal format does not and // Check if the actual format has a channel that the internal format does not and
// set them to the default values // set them to the default values
float clearValues[4] = { float clearValues[4] = {
((formatInfo.redBits == 0 && nativeFormat.redBits > 0) ((formatInfo.redBits == 0 && nativeFormat.redBits > 0) ? 0.0f
? 0.0f
: clearParams.colorF.red), : clearParams.colorF.red),
((formatInfo.greenBits == 0 && nativeFormat.greenBits > 0) ((formatInfo.greenBits == 0 && nativeFormat.greenBits > 0)
? 0.0f ? 0.0f
: clearParams.colorF.green), : clearParams.colorF.green),
((formatInfo.blueBits == 0 && nativeFormat.blueBits > 0) ((formatInfo.blueBits == 0 && nativeFormat.blueBits > 0) ? 0.0f
? 0.0f
: clearParams.colorF.blue), : clearParams.colorF.blue),
((formatInfo.alphaBits == 0 && nativeFormat.alphaBits > 0) ((formatInfo.alphaBits == 0 && nativeFormat.alphaBits > 0)
? 1.0f ? 1.0f
...@@ -523,19 +507,21 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -523,19 +507,21 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
} }
} }
} }
}
if (depthStencilRenderTarget) ID3D11DepthStencilView *dsv = nullptr;
{
dsv = depthStencilRenderTarget->getDepthStencilView().get();
if (!dsv) if (clearParams.clearDepth || clearParams.clearStencil)
{ {
return gl::OutOfMemory() << "Clear11: Depth stencil view pointer unexpectedly null."; RenderTarget11 *depthStencilRenderTarget = nullptr;
}
ASSERT(depthStencilAttachment != nullptr);
ANGLE_TRY(depthStencilAttachment->getRenderTarget(&depthStencilRenderTarget));
dsv = depthStencilRenderTarget->getDepthStencilView().get();
ASSERT(dsv != nullptr);
const auto &nativeFormat = depthStencilRenderTarget->getFormatSet().format(); const auto &nativeFormat = depthStencilRenderTarget->getFormatSet().format();
const gl::FramebufferAttachment *stencilAttachment = fboData.getStencilAttachment(); const auto *stencilAttachment = fboData.getStencilAttachment();
uint32_t stencilUnmasked = uint32_t stencilUnmasked =
(stencilAttachment != nullptr) ? (1 << nativeFormat.stencilBits) - 1 : 0; (stencilAttachment != nullptr) ? (1 << nativeFormat.stencilBits) - 1 : 0;
...@@ -594,11 +580,6 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -594,11 +580,6 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
ASSERT(numRtvs <= mRenderer->getNativeCaps().maxDrawBuffers); ASSERT(numRtvs <= mRenderer->getNativeCaps().maxDrawBuffers);
const UINT sampleMask = 0xFFFFFFFF;
ID3D11BlendState *blendState = nullptr;
if (numRtvs > 0)
{
// Setup BlendStateKey parameters // Setup BlendStateKey parameters
mBlendStateKey.blendState.colorMaskRed = clearParams.colorMaskRed; mBlendStateKey.blendState.colorMaskRed = clearParams.colorMaskRed;
mBlendStateKey.blendState.colorMaskGreen = clearParams.colorMaskGreen; mBlendStateKey.blendState.colorMaskGreen = clearParams.colorMaskGreen;
...@@ -608,10 +589,9 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -608,10 +589,9 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
memcpy(mBlendStateKey.rtvMasks, &rtvMasks[0], sizeof(mBlendStateKey.rtvMasks)); memcpy(mBlendStateKey.rtvMasks, &rtvMasks[0], sizeof(mBlendStateKey.rtvMasks));
// Get BlendState // Get BlendState
ID3D11BlendState *blendState = nullptr;
ANGLE_TRY(mRenderer->getBlendState(mBlendStateKey, &blendState)); ANGLE_TRY(mRenderer->getBlendState(mBlendStateKey, &blendState));
}
const UINT stencilValue = clearParams.stencilValue & 0xFF;
ID3D11DepthStencilState *dsState = nullptr; ID3D11DepthStencilState *dsState = nullptr;
const float *zValue = nullptr; const float *zValue = nullptr;
...@@ -679,7 +659,9 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -679,7 +659,9 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
deviceContext->RSSetViewports(1, &viewport); deviceContext->RSSetViewports(1, &viewport);
// Apply state // Apply state
deviceContext->OMSetBlendState(blendState, nullptr, sampleMask); deviceContext->OMSetBlendState(blendState, nullptr, 0xFFFFFFFF);
const UINT stencilValue = clearParams.stencilValue & 0xFF;
deviceContext->OMSetDepthStencilState(dsState, stencilValue); deviceContext->OMSetDepthStencilState(dsState, stencilValue);
if (needScissoredClear) if (needScissoredClear)
......
...@@ -69,7 +69,7 @@ d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Framebuffer *f ...@@ -69,7 +69,7 @@ d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Framebuffer *f
} }
key.rtvMasks[i] = key.rtvMasks[i] =
(gl_d3d11::GetColorMask(attachment->getFormat().info)) & blendStateMask; (gl_d3d11::GetColorMask(*attachment->getFormat().info)) & blendStateMask;
} }
else else
{ {
......
...@@ -1700,26 +1700,10 @@ D3D11_QUERY ConvertQueryType(GLenum queryType) ...@@ -1700,26 +1700,10 @@ D3D11_QUERY ConvertQueryType(GLenum queryType)
} }
// Get the D3D11 write mask covering all color channels of a given format // Get the D3D11 write mask covering all color channels of a given format
UINT8 GetColorMask(const gl::InternalFormat *formatInfo) UINT8 GetColorMask(const gl::InternalFormat &format)
{ {
UINT8 mask = 0; return ConvertColorMask(format.redBits > 0, format.greenBits > 0, format.blueBits > 0,
if (formatInfo->redBits > 0) format.alphaBits > 0);
{
mask |= D3D11_COLOR_WRITE_ENABLE_RED;
}
if (formatInfo->greenBits > 0)
{
mask |= D3D11_COLOR_WRITE_ENABLE_GREEN;
}
if (formatInfo->blueBits > 0)
{
mask |= D3D11_COLOR_WRITE_ENABLE_BLUE;
}
if (formatInfo->alphaBits > 0)
{
mask |= D3D11_COLOR_WRITE_ENABLE_ALPHA;
}
return mask;
} }
} // namespace gl_d3d11 } // namespace gl_d3d11
......
...@@ -56,7 +56,7 @@ UINT ConvertMaxAnisotropy(float maxAnisotropy, D3D_FEATURE_LEVEL featureLevel); ...@@ -56,7 +56,7 @@ UINT ConvertMaxAnisotropy(float maxAnisotropy, D3D_FEATURE_LEVEL featureLevel);
D3D11_QUERY ConvertQueryType(GLenum queryType); D3D11_QUERY ConvertQueryType(GLenum queryType);
UINT8 GetColorMask(const gl::InternalFormat *formatInfo); UINT8 GetColorMask(const gl::InternalFormat &formatInfo);
} // namespace gl_d3d11 } // namespace gl_d3d11
......
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