Commit 7efe747c by Jamie Madill Committed by Commit Bot

D3D11: Fix style in the entire back-end.

BUG=None Change-Id: I32cbcd4daa1f386654ea5e8f0a25d8635b5df731 Reviewed-on: https://chromium-review.googlesource.com/402016Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Commit-Queue: Jamie Madill <jmadill@chromium.org>
parent a284f2ff
...@@ -34,9 +34,14 @@ namespace rx ...@@ -34,9 +34,14 @@ namespace rx
{ {
template <typename T> template <typename T>
static void ApplyVertices(const gl::Extents &framebufferSize, const gl::Rectangle *scissor, const gl::Color<T> &color, float depth, void *buffer) static void ApplyVertices(const gl::Extents &framebufferSize,
const gl::Rectangle *scissor,
const gl::Color<T> &color,
float depth,
void *buffer)
{ {
d3d11::PositionDepthColorVertex<T> *vertices = reinterpret_cast<d3d11::PositionDepthColorVertex<T>*>(buffer); d3d11::PositionDepthColorVertex<T> *vertices =
reinterpret_cast<d3d11::PositionDepthColorVertex<T> *>(buffer);
float depthClear = gl::clamp01(depth); float depthClear = gl::clamp01(depth);
float left = -1.0f; float left = -1.0f;
...@@ -48,9 +53,15 @@ static void ApplyVertices(const gl::Extents &framebufferSize, const gl::Rectangl ...@@ -48,9 +53,15 @@ static void ApplyVertices(const gl::Extents &framebufferSize, const gl::Rectangl
if (scissor != nullptr) if (scissor != nullptr)
{ {
left = std::max(left, (scissor->x / float(framebufferSize.width)) * 2.0f - 1.0f); left = std::max(left, (scissor->x / float(framebufferSize.width)) * 2.0f - 1.0f);
right = std::min(right, ((scissor->x + scissor->width) / float(framebufferSize.width)) * 2.0f - 1.0f); right = std::min(
top = std::max(top, ((framebufferSize.height - scissor->y - scissor->height) / float(framebufferSize.height)) * 2.0f - 1.0f); right, ((scissor->x + scissor->width) / float(framebufferSize.width)) * 2.0f - 1.0f);
bottom = std::min(bottom, ((framebufferSize.height - scissor->y) / float(framebufferSize.height)) * 2.0f - 1.0f); top = std::max(top, ((framebufferSize.height - scissor->y - scissor->height) /
float(framebufferSize.height)) *
2.0f -
1.0f);
bottom = std::min(
bottom,
((framebufferSize.height - scissor->y) / float(framebufferSize.height)) * 2.0f - 1.0f);
} }
d3d11::SetPositionDepthColorVertex<T>(vertices + 0, left, bottom, depthClear, color); d3d11::SetPositionDepthColorVertex<T>(vertices + 0, left, bottom, depthClear, color);
...@@ -71,10 +82,9 @@ Clear11::ClearShader::ClearShader(DXGI_FORMAT colorType, ...@@ -71,10 +82,9 @@ Clear11::ClearShader::ClearShader(DXGI_FORMAT colorType,
vertexShader(vsByteCode, vsSize, vsDebugName), vertexShader(vsByteCode, vsSize, vsDebugName),
pixelShader(psByteCode, psSize, psDebugName) pixelShader(psByteCode, psSize, psDebugName)
{ {
D3D11_INPUT_ELEMENT_DESC quadLayout[] = D3D11_INPUT_ELEMENT_DESC quadLayout[] = {
{ {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }, {"COLOR", 0, colorType, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
{ "COLOR", 0, colorType, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 },
}; };
inputLayout = new d3d11::LazyInputLayout(quadLayout, 2, vsByteCode, vsSize, inputLayoutName); inputLayout = new d3d11::LazyInputLayout(quadLayout, 2, vsByteCode, vsSize, inputLayoutName);
...@@ -132,51 +142,36 @@ Clear11::Clear11(Renderer11 *renderer) ...@@ -132,51 +142,36 @@ Clear11::Clear11(Renderer11 *renderer)
if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3) if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_9_3)
{ {
mFloatClearShader = new ClearShader(DXGI_FORMAT_R32G32B32A32_FLOAT, mFloatClearShader =
"Clear11 Float IL", new ClearShader(DXGI_FORMAT_R32G32B32A32_FLOAT, "Clear11 Float IL", g_VS_ClearFloat,
g_VS_ClearFloat, ArraySize(g_VS_ClearFloat), "Clear11 Float VS", g_PS_ClearFloat_FL9,
ArraySize(g_VS_ClearFloat), ArraySize(g_PS_ClearFloat_FL9), "Clear11 Float PS");
"Clear11 Float VS",
g_PS_ClearFloat_FL9,
ArraySize(g_PS_ClearFloat_FL9),
"Clear11 Float PS");
} }
else else
{ {
mFloatClearShader = new ClearShader(DXGI_FORMAT_R32G32B32A32_FLOAT, mFloatClearShader =
"Clear11 Float IL", new ClearShader(DXGI_FORMAT_R32G32B32A32_FLOAT, "Clear11 Float IL", g_VS_ClearFloat,
g_VS_ClearFloat, ArraySize(g_VS_ClearFloat), "Clear11 Float VS", g_PS_ClearFloat,
ArraySize(g_VS_ClearFloat), ArraySize(g_PS_ClearFloat), "Clear11 Float PS");
"Clear11 Float VS",
g_PS_ClearFloat,
ArraySize(g_PS_ClearFloat),
"Clear11 Float PS");
} }
if (renderer->isES3Capable()) if (renderer->isES3Capable())
{ {
mUintClearShader = new ClearShader(DXGI_FORMAT_R32G32B32A32_UINT, mUintClearShader =
"Clear11 UINT IL", new ClearShader(DXGI_FORMAT_R32G32B32A32_UINT, "Clear11 UINT IL", g_VS_ClearUint,
g_VS_ClearUint, ArraySize(g_VS_ClearUint), "Clear11 UINT VS", g_PS_ClearUint,
ArraySize(g_VS_ClearUint), ArraySize(g_PS_ClearUint), "Clear11 UINT PS");
"Clear11 UINT VS", mIntClearShader =
g_PS_ClearUint, new ClearShader(DXGI_FORMAT_R32G32B32A32_UINT, "Clear11 SINT IL", g_VS_ClearSint,
ArraySize(g_PS_ClearUint), ArraySize(g_VS_ClearSint), "Clear11 SINT VS", g_PS_ClearSint,
"Clear11 UINT PS"); ArraySize(g_PS_ClearSint), "Clear11 SINT PS");
mIntClearShader = new ClearShader(DXGI_FORMAT_R32G32B32A32_UINT,
"Clear11 SINT IL",
g_VS_ClearSint,
ArraySize(g_VS_ClearSint),
"Clear11 SINT VS",
g_PS_ClearSint,
ArraySize(g_PS_ClearSint),
"Clear11 SINT PS");
} }
} }
Clear11::~Clear11() Clear11::~Clear11()
{ {
for (ClearBlendStateMap::iterator i = mClearBlendStates.begin(); i != mClearBlendStates.end(); i++) for (ClearBlendStateMap::iterator i = mClearBlendStates.begin(); i != mClearBlendStates.end();
i++)
{ {
SafeRelease(i->second); SafeRelease(i->second);
} }
...@@ -186,7 +181,8 @@ Clear11::~Clear11() ...@@ -186,7 +181,8 @@ Clear11::~Clear11()
SafeDelete(mUintClearShader); SafeDelete(mUintClearShader);
SafeDelete(mIntClearShader); SafeDelete(mIntClearShader);
for (ClearDepthStencilStateMap::iterator i = mClearDepthStencilStates.begin(); i != mClearDepthStencilStates.end(); i++) for (ClearDepthStencilStateMap::iterator i = mClearDepthStencilStates.begin();
i != mClearDepthStencilStates.end(); i++)
{ {
SafeRelease(i->second); SafeRelease(i->second);
} }
...@@ -209,20 +205,24 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -209,20 +205,24 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
// 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:
// 1) The render target is being cleared to a float value (will be cast to integer when clearing integer // 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) // 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. // 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. // Clear the easy-to-clear buffers on the spot and accumulate the ones that require special
// work.
// //
// If these conditions are met, and: // If these conditions are met, and:
// - No scissored clear is needed, then clear using ID3D11DeviceContext::ClearRenderTargetView. // - No scissored clear is needed, then clear using ID3D11DeviceContext::ClearRenderTargetView.
// - A scissored clear is needed then clear using ID3D11DeviceContext1::ClearView if available. // - A scissored clear is needed then clear using ID3D11DeviceContext1::ClearView if available.
// Otherwise draw a quad. // Otherwise draw a quad.
// //
// Also determine if the depth stencil can be cleared with ID3D11DeviceContext::ClearDepthStencilView // Also determine if the depth stencil can be cleared with
// ID3D11DeviceContext::ClearDepthStencilView
// by checking if the stencil write mask covers the entire stencil. // by checking if the stencil write mask covers the entire stencil.
// //
// To clear the remaining buffers, quads must be drawn containing an int, uint or float vertex color // To clear the remaining buffers, quads must be drawn containing an int, uint or float vertex
// color
// attribute. // attribute.
gl::Extents framebufferSize; gl::Extents framebufferSize;
...@@ -255,12 +255,14 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -255,12 +255,14 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
bool needScissoredClear = clearParams.scissorEnabled && (clearParams.scissor.x > 0 || clearParams.scissor.y > 0 || bool needScissoredClear =
clearParams.scissorEnabled &&
(clearParams.scissor.x > 0 || clearParams.scissor.y > 0 ||
clearParams.scissor.x + clearParams.scissor.width < framebufferSize.width || clearParams.scissor.x + clearParams.scissor.width < framebufferSize.width ||
clearParams.scissor.y + clearParams.scissor.height < framebufferSize.height); clearParams.scissor.y + clearParams.scissor.height < framebufferSize.height);
std::vector<MaskedRenderTarget> maskedClearRenderTargets; std::vector<MaskedRenderTarget> maskedClearRenderTargets;
RenderTarget11* maskedClearDepthStencil = nullptr; RenderTarget11 *maskedClearDepthStencil = nullptr;
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
ID3D11DeviceContext1 *deviceContext1 = mRenderer->getDeviceContext1IfSupported(); ID3D11DeviceContext1 *deviceContext1 = mRenderer->getDeviceContext1IfSupported();
...@@ -307,7 +309,8 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -307,7 +309,8 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
(formatInfo.blueBits > 0 && !clearParams.colorMaskBlue) || (formatInfo.blueBits > 0 && !clearParams.colorMaskBlue) ||
(formatInfo.alphaBits > 0 && !clearParams.colorMaskAlpha)) (formatInfo.alphaBits > 0 && !clearParams.colorMaskAlpha))
{ {
// A masked clear is required, or a scissored clear is required and ID3D11DeviceContext1::ClearView is unavailable // A masked clear is required, or a scissored clear is required and
// ID3D11DeviceContext1::ClearView is unavailable
MaskedRenderTarget maskAndRt; MaskedRenderTarget maskAndRt;
bool clearColor = clearParams.clearColor[colorAttachmentIndex]; bool clearColor = clearParams.clearColor[colorAttachmentIndex];
maskAndRt.colorMask[0] = (clearColor && clearParams.colorMaskRed); maskAndRt.colorMask[0] = (clearColor && clearParams.colorMaskRed);
...@@ -319,18 +322,20 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -319,18 +322,20 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
} }
else else
{ {
// ID3D11DeviceContext::ClearRenderTargetView or ID3D11DeviceContext1::ClearView is possible // ID3D11DeviceContext::ClearRenderTargetView or ID3D11DeviceContext1::ClearView is
// possible
ID3D11RenderTargetView *framebufferRTV = renderTarget->getRenderTargetView(); ID3D11RenderTargetView *framebufferRTV = renderTarget->getRenderTargetView();
if (!framebufferRTV) if (!framebufferRTV)
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Internal render target view pointer unexpectedly null."); return gl::Error(GL_OUT_OF_MEMORY,
"Internal render target view pointer unexpectedly null.");
} }
const auto &nativeFormat = renderTarget->getFormatSet().format; const auto &nativeFormat = renderTarget->getFormatSet().format;
// Check if the actual format has a channel that the internal format does not and set them to the // Check if the actual format has a channel that the internal format does not and
// 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
...@@ -348,9 +353,9 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -348,9 +353,9 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
if (formatInfo.alphaBits == 1) if (formatInfo.alphaBits == 1)
{ {
// Some drivers do not correctly handle calling Clear() on a format with 1-bit alpha. // Some drivers do not correctly handle calling Clear() on a format with 1-bit
// They can incorrectly round all non-zero values up to 1.0f. Note that WARP does not do this. // alpha. They can incorrectly round all non-zero values up to 1.0f. Note that
// We should handle the rounding for them instead. // WARP does not do this. We should handle the rounding for them instead.
clearValues[3] = (clearParams.colorFClearValue.alpha >= 0.5f) ? 1.0f : 0.0f; clearValues[3] = (clearParams.colorFClearValue.alpha >= 0.5f) ? 1.0f : 0.0f;
} }
...@@ -377,7 +382,8 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -377,7 +382,8 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
if (clearParams.clearDepth || clearParams.clearStencil) if (clearParams.clearDepth || clearParams.clearStencil)
{ {
const gl::FramebufferAttachment *attachment = (depthAttachment != nullptr) ? depthAttachment : stencilAttachment; const gl::FramebufferAttachment *attachment =
(depthAttachment != nullptr) ? depthAttachment : stencilAttachment;
ASSERT(attachment != nullptr); ASSERT(attachment != nullptr);
RenderTarget11 *renderTarget = nullptr; RenderTarget11 *renderTarget = nullptr;
...@@ -387,7 +393,9 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -387,7 +393,9 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
unsigned int stencilUnmasked = unsigned int stencilUnmasked =
(stencilAttachment != nullptr) ? (1 << nativeFormat.stencilBits) - 1 : 0; (stencilAttachment != nullptr) ? (1 << nativeFormat.stencilBits) - 1 : 0;
bool needMaskedStencilClear = clearParams.clearStencil && (clearParams.stencilWriteMask & stencilUnmasked) != stencilUnmasked; bool needMaskedStencilClear =
clearParams.clearStencil &&
(clearParams.stencilWriteMask & stencilUnmasked) != stencilUnmasked;
if (needScissoredClear || needMaskedStencilClear) if (needScissoredClear || needMaskedStencilClear)
{ {
...@@ -398,7 +406,8 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -398,7 +406,8 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
ID3D11DepthStencilView *framebufferDSV = renderTarget->getDepthStencilView(); ID3D11DepthStencilView *framebufferDSV = renderTarget->getDepthStencilView();
if (!framebufferDSV) if (!framebufferDSV)
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Internal depth stencil view pointer unexpectedly null."); return gl::Error(GL_OUT_OF_MEMORY,
"Internal depth stencil view pointer unexpectedly null.");
} }
UINT clearFlags = (clearParams.clearDepth ? D3D11_CLEAR_DEPTH : 0) | UINT clearFlags = (clearParams.clearDepth ? D3D11_CLEAR_DEPTH : 0) |
...@@ -406,7 +415,8 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -406,7 +415,8 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
FLOAT depthClear = gl::clamp01(clearParams.depthClearValue); FLOAT depthClear = gl::clamp01(clearParams.depthClearValue);
UINT8 stencilClear = clearParams.stencilClearValue & 0xFF; UINT8 stencilClear = clearParams.stencilClearValue & 0xFF;
deviceContext->ClearDepthStencilView(framebufferDSV, clearFlags, depthClear, stencilClear); deviceContext->ClearDepthStencilView(framebufferDSV, clearFlags, depthClear,
stencilClear);
} }
} }
...@@ -545,7 +555,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams, ...@@ -545,7 +555,7 @@ gl::Error Clear11::clearFramebuffer(const ClearParameters &clearParams,
return gl::NoError(); return gl::NoError();
} }
ID3D11BlendState *Clear11::getBlendState(const std::vector<MaskedRenderTarget>& rts) ID3D11BlendState *Clear11::getBlendState(const std::vector<MaskedRenderTarget> &rts)
{ {
ClearBlendInfo blendKey = {}; ClearBlendInfo blendKey = {};
for (unsigned int i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++) for (unsigned int i = 0; i < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; i++)
...@@ -553,7 +563,8 @@ ID3D11BlendState *Clear11::getBlendState(const std::vector<MaskedRenderTarget>& ...@@ -553,7 +563,8 @@ ID3D11BlendState *Clear11::getBlendState(const std::vector<MaskedRenderTarget>&
if (i < rts.size()) if (i < rts.size())
{ {
RenderTarget11 *rt = rts[i].renderTarget; RenderTarget11 *rt = rts[i].renderTarget;
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(rt->getInternalFormat()); const gl::InternalFormat &formatInfo =
gl::GetInternalFormatInfo(rt->getInternalFormat());
blendKey.maskChannels[i][0] = (rts[i].colorMask[0] && formatInfo.redBits > 0); blendKey.maskChannels[i][0] = (rts[i].colorMask[0] && formatInfo.redBits > 0);
blendKey.maskChannels[i][1] = (rts[i].colorMask[1] && formatInfo.greenBits > 0); blendKey.maskChannels[i][1] = (rts[i].colorMask[1] && formatInfo.greenBits > 0);
...@@ -576,21 +587,20 @@ ID3D11BlendState *Clear11::getBlendState(const std::vector<MaskedRenderTarget>& ...@@ -576,21 +587,20 @@ ID3D11BlendState *Clear11::getBlendState(const std::vector<MaskedRenderTarget>&
} }
else else
{ {
D3D11_BLEND_DESC blendDesc = { 0 }; D3D11_BLEND_DESC blendDesc = {0};
blendDesc.AlphaToCoverageEnable = FALSE; blendDesc.AlphaToCoverageEnable = FALSE;
blendDesc.IndependentBlendEnable = (rts.size() > 1) ? TRUE : FALSE; blendDesc.IndependentBlendEnable = (rts.size() > 1) ? TRUE : FALSE;
for (unsigned int j = 0; j < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; j++) for (unsigned int j = 0; j < D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; j++)
{ {
blendDesc.RenderTarget[j].BlendEnable = FALSE; blendDesc.RenderTarget[j].BlendEnable = FALSE;
blendDesc.RenderTarget[j].RenderTargetWriteMask = gl_d3d11::ConvertColorMask(blendKey.maskChannels[j][0], blendDesc.RenderTarget[j].RenderTargetWriteMask = gl_d3d11::ConvertColorMask(
blendKey.maskChannels[j][1], blendKey.maskChannels[j][0], blendKey.maskChannels[j][1],
blendKey.maskChannels[j][2], blendKey.maskChannels[j][2], blendKey.maskChannels[j][3]);
blendKey.maskChannels[j][3]);
} }
ID3D11Device *device = mRenderer->getDevice(); ID3D11Device *device = mRenderer->getDevice();
ID3D11BlendState* blendState = nullptr; ID3D11BlendState *blendState = nullptr;
HRESULT result = device->CreateBlendState(&blendDesc, &blendState); HRESULT result = device->CreateBlendState(&blendDesc, &blendState);
if (FAILED(result) || !blendState) if (FAILED(result) || !blendState)
{ {
...@@ -606,7 +616,7 @@ ID3D11BlendState *Clear11::getBlendState(const std::vector<MaskedRenderTarget>& ...@@ -606,7 +616,7 @@ ID3D11BlendState *Clear11::getBlendState(const std::vector<MaskedRenderTarget>&
ID3D11DepthStencilState *Clear11::getDepthStencilState(const ClearParameters &clearParams) ID3D11DepthStencilState *Clear11::getDepthStencilState(const ClearParameters &clearParams)
{ {
ClearDepthStencilInfo dsKey = { 0 }; ClearDepthStencilInfo dsKey = {0};
dsKey.clearDepth = clearParams.clearDepth; dsKey.clearDepth = clearParams.clearDepth;
dsKey.clearStencil = clearParams.clearStencil; dsKey.clearStencil = clearParams.clearStencil;
dsKey.stencilWriteMask = clearParams.stencilWriteMask & 0xFF; dsKey.stencilWriteMask = clearParams.stencilWriteMask & 0xFF;
...@@ -618,9 +628,10 @@ ID3D11DepthStencilState *Clear11::getDepthStencilState(const ClearParameters &cl ...@@ -618,9 +628,10 @@ ID3D11DepthStencilState *Clear11::getDepthStencilState(const ClearParameters &cl
} }
else else
{ {
D3D11_DEPTH_STENCIL_DESC dsDesc = { 0 }; D3D11_DEPTH_STENCIL_DESC dsDesc = {0};
dsDesc.DepthEnable = dsKey.clearDepth ? TRUE : FALSE; dsDesc.DepthEnable = dsKey.clearDepth ? TRUE : FALSE;
dsDesc.DepthWriteMask = dsKey.clearDepth ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO; dsDesc.DepthWriteMask =
dsKey.clearDepth ? D3D11_DEPTH_WRITE_MASK_ALL : D3D11_DEPTH_WRITE_MASK_ZERO;
dsDesc.DepthFunc = D3D11_COMPARISON_ALWAYS; dsDesc.DepthFunc = D3D11_COMPARISON_ALWAYS;
dsDesc.StencilEnable = dsKey.clearStencil ? TRUE : FALSE; dsDesc.StencilEnable = dsKey.clearStencil ? TRUE : FALSE;
dsDesc.StencilReadMask = 0; dsDesc.StencilReadMask = 0;
...@@ -635,7 +646,7 @@ ID3D11DepthStencilState *Clear11::getDepthStencilState(const ClearParameters &cl ...@@ -635,7 +646,7 @@ ID3D11DepthStencilState *Clear11::getDepthStencilState(const ClearParameters &cl
dsDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS; dsDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
ID3D11Device *device = mRenderer->getDevice(); ID3D11Device *device = mRenderer->getDevice();
ID3D11DepthStencilState* dsState = nullptr; ID3D11DepthStencilState *dsState = nullptr;
HRESULT result = device->CreateDepthStencilState(&dsDesc, &dsState); HRESULT result = device->CreateDepthStencilState(&dsDesc, &dsState);
if (FAILED(result) || !dsState) if (FAILED(result) || !dsState)
{ {
...@@ -648,5 +659,4 @@ ID3D11DepthStencilState *Clear11::getDepthStencilState(const ClearParameters &cl ...@@ -648,5 +659,4 @@ ID3D11DepthStencilState *Clear11::getDepthStencilState(const ClearParameters &cl
return dsState; return dsState;
} }
} }
} }
...@@ -4,7 +4,8 @@ ...@@ -4,7 +4,8 @@
// found in the LICENSE file. // found in the LICENSE file.
// //
// Fence11.cpp: Defines the rx::FenceNV11 and rx::FenceSync11 classes which implement rx::FenceNVImpl and rx::FenceSyncImpl. // Fence11.cpp: Defines the rx::FenceNV11 and rx::FenceSync11 classes which implement
// rx::FenceNVImpl and rx::FenceSyncImpl.
#include "libANGLE/renderer/d3d/d3d11/Fence11.h" #include "libANGLE/renderer/d3d/d3d11/Fence11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" #include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
...@@ -20,7 +21,7 @@ static const int kDeviceLostCheckPeriod = 64; ...@@ -20,7 +21,7 @@ static const int kDeviceLostCheckPeriod = 64;
// Template helpers for set and test operations. // Template helpers for set and test operations.
// //
template<class FenceClass> template <class FenceClass>
gl::Error FenceSetHelper(FenceClass *fence) gl::Error FenceSetHelper(FenceClass *fence)
{ {
if (!fence->mQuery) if (!fence->mQuery)
...@@ -32,7 +33,8 @@ gl::Error FenceSetHelper(FenceClass *fence) ...@@ -32,7 +33,8 @@ gl::Error FenceSetHelper(FenceClass *fence)
HRESULT result = fence->mRenderer->getDevice()->CreateQuery(&queryDesc, &fence->mQuery); HRESULT result = fence->mRenderer->getDevice()->CreateQuery(&queryDesc, &fence->mQuery);
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create event query, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create event query, result: 0x%X.",
result);
} }
} }
...@@ -46,7 +48,8 @@ gl::Error FenceTestHelper(FenceClass *fence, bool flushCommandBuffer, GLboolean ...@@ -46,7 +48,8 @@ gl::Error FenceTestHelper(FenceClass *fence, bool flushCommandBuffer, GLboolean
ASSERT(fence->mQuery); ASSERT(fence->mQuery);
UINT getDataFlags = (flushCommandBuffer ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH); UINT getDataFlags = (flushCommandBuffer ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH);
HRESULT result = fence->mRenderer->getDeviceContext()->GetData(fence->mQuery, NULL, 0, getDataFlags); HRESULT result =
fence->mRenderer->getDeviceContext()->GetData(fence->mQuery, NULL, 0, getDataFlags);
if (FAILED(result)) if (FAILED(result))
{ {
...@@ -62,10 +65,7 @@ gl::Error FenceTestHelper(FenceClass *fence, bool flushCommandBuffer, GLboolean ...@@ -62,10 +65,7 @@ gl::Error FenceTestHelper(FenceClass *fence, bool flushCommandBuffer, GLboolean
// FenceNV11 // FenceNV11
// //
FenceNV11::FenceNV11(Renderer11 *renderer) FenceNV11::FenceNV11(Renderer11 *renderer) : FenceNVImpl(), mRenderer(renderer), mQuery(NULL)
: FenceNVImpl(),
mRenderer(renderer),
mQuery(NULL)
{ {
} }
...@@ -121,10 +121,7 @@ gl::Error FenceNV11::finish() ...@@ -121,10 +121,7 @@ gl::Error FenceNV11::finish()
// We still opt to use QPC. In the present and moving forward, most newer systems will not suffer // We still opt to use QPC. In the present and moving forward, most newer systems will not suffer
// from buggy implementations. // from buggy implementations.
FenceSync11::FenceSync11(Renderer11 *renderer) FenceSync11::FenceSync11(Renderer11 *renderer) : FenceSyncImpl(), mRenderer(renderer), mQuery(NULL)
: FenceSyncImpl(),
mRenderer(renderer),
mQuery(NULL)
{ {
LARGE_INTEGER counterFreqency = {}; LARGE_INTEGER counterFreqency = {};
BOOL success = QueryPerformanceFrequency(&counterFreqency); BOOL success = QueryPerformanceFrequency(&counterFreqency);
...@@ -218,8 +215,8 @@ gl::Error FenceSync11::clientWait(GLbitfield flags, GLuint64 timeout, GLenum *ou ...@@ -218,8 +215,8 @@ gl::Error FenceSync11::clientWait(GLbitfield flags, GLuint64 timeout, GLenum *ou
gl::Error FenceSync11::serverWait(GLbitfield flags, GLuint64 timeout) gl::Error FenceSync11::serverWait(GLbitfield flags, GLuint64 timeout)
{ {
// Because our API is currently designed to be called from a single thread, we don't need to do // Because our API is currently designed to be called from a single thread, we don't need to do
// extra work for a server-side fence. GPU commands issued after the fence is created will always // extra work for a server-side fence. GPU commands issued after the fence is created will
// be processed after the fence is signaled. // always be processed after the fence is signaled.
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
...@@ -229,8 +226,8 @@ gl::Error FenceSync11::getStatus(GLint *outResult) ...@@ -229,8 +226,8 @@ gl::Error FenceSync11::getStatus(GLint *outResult)
gl::Error error = FenceTestHelper(this, false, &result); gl::Error error = FenceTestHelper(this, false, &result);
if (error.isError()) if (error.isError())
{ {
// The spec does not specify any way to report errors during the status test (e.g. device lost) // The spec does not specify any way to report errors during the status test (e.g. device
// so we report the fence is unblocked in case of error or signaled. // lost) so we report the fence is unblocked in case of error or signaled.
*outResult = GL_SIGNALED; *outResult = GL_SIGNALED;
return error; return error;
......
...@@ -60,8 +60,8 @@ gl::Error Image11::generateMipmap(Image11 *dest, ...@@ -60,8 +60,8 @@ gl::Error Image11::generateMipmap(Image11 *dest,
return error; return error;
} }
const uint8_t *sourceData = reinterpret_cast<const uint8_t*>(srcMapped.pData); const uint8_t *sourceData = reinterpret_cast<const uint8_t *>(srcMapped.pData);
uint8_t *destData = reinterpret_cast<uint8_t*>(destMapped.pData); uint8_t *destData = reinterpret_cast<uint8_t *>(destMapped.pData);
auto mipGenerationFunction = auto mipGenerationFunction =
d3d11::Format::Get(src->getInternalFormat(), rendererCaps).format.mipGenerationFunction; d3d11::Format::Get(src->getInternalFormat(), rendererCaps).format.mipGenerationFunction;
...@@ -79,10 +79,9 @@ gl::Error Image11::generateMipmap(Image11 *dest, ...@@ -79,10 +79,9 @@ gl::Error Image11::generateMipmap(Image11 *dest,
bool Image11::isDirty() const bool Image11::isDirty() const
{ {
// If mDirty is true // If mDirty is true AND mStagingTexture doesn't exist AND mStagingTexture doesn't need to be
// AND mStagingTexture doesn't exist AND mStagingTexture doesn't need to be recovered from TextureStorage // recovered from TextureStorage AND the texture doesn't require init data (i.e. a blank new
// AND the texture doesn't require init data (i.e. a blank new texture will suffice) // texture will suffice) then isDirty should still return false.
// then isDirty should still return false.
if (mDirty && !mStagingTexture && !mRecoverFromStorage) if (mDirty && !mStagingTexture && !mRecoverFromStorage)
{ {
const Renderer11DeviceCaps &deviceCaps = mRenderer->getRenderer11DeviceCaps(); const Renderer11DeviceCaps &deviceCaps = mRenderer->getRenderer11DeviceCaps();
...@@ -96,19 +95,22 @@ bool Image11::isDirty() const ...@@ -96,19 +95,22 @@ bool Image11::isDirty() const
return mDirty; return mDirty;
} }
gl::Error Image11::copyToStorage(TextureStorage *storage, const gl::ImageIndex &index, const gl::Box &region) gl::Error Image11::copyToStorage(TextureStorage *storage,
const gl::ImageIndex &index,
const gl::Box &region)
{ {
TextureStorage11 *storage11 = GetAs<TextureStorage11>(storage); TextureStorage11 *storage11 = GetAs<TextureStorage11>(storage);
// If an app's behavior results in an Image11 copying its data to/from to a TextureStorage multiple times, // If an app's behavior results in an Image11 copying its data to/from to a TextureStorage
// then we should just keep the staging texture around to prevent the copying from impacting perf. // multiple times, then we should just keep the staging texture around to prevent the copying
// We allow the Image11 to copy its data to/from TextureStorage once. // from impacting perf. We allow the Image11 to copy its data to/from TextureStorage once. This
// This accounts for an app making a late call to glGenerateMipmap. // accounts for an app making a late call to glGenerateMipmap.
bool attemptToReleaseStagingTexture = (mRecoveredFromStorageCount < 2); bool attemptToReleaseStagingTexture = (mRecoveredFromStorageCount < 2);
if (attemptToReleaseStagingTexture) if (attemptToReleaseStagingTexture)
{ {
// If another image is relying on this Storage for its data, then we must let it recover its data before we overwrite it. // If another image is relying on this Storage for its data, then we must let it recover its
// data before we overwrite it.
ANGLE_TRY(storage11->releaseAssociatedImage(index, this)); ANGLE_TRY(storage11->releaseAssociatedImage(index, this));
} }
...@@ -131,7 +133,7 @@ gl::Error Image11::copyToStorage(TextureStorage *storage, const gl::ImageIndex & ...@@ -131,7 +133,7 @@ gl::Error Image11::copyToStorage(TextureStorage *storage, const gl::ImageIndex &
return gl::NoError(); return gl::NoError();
} }
bool Image11::isAssociatedStorageValid(TextureStorage11* textureStorage) const bool Image11::isAssociatedStorageValid(TextureStorage11 *textureStorage) const
{ {
return (mAssociatedStorage == textureStorage); return (mAssociatedStorage == textureStorage);
} }
...@@ -142,10 +144,12 @@ gl::Error Image11::recoverFromAssociatedStorage() ...@@ -142,10 +144,12 @@ gl::Error Image11::recoverFromAssociatedStorage()
{ {
ANGLE_TRY(createStagingTexture()); ANGLE_TRY(createStagingTexture());
bool textureStorageCorrect = mAssociatedStorage->isAssociatedImageValid(mAssociatedImageIndex, this); bool textureStorageCorrect =
mAssociatedStorage->isAssociatedImageValid(mAssociatedImageIndex, this);
// This means that the cached TextureStorage has been modified after this Image11 released its copy of its data. // This means that the cached TextureStorage has been modified after this Image11 released
// This should not have happened. The TextureStorage should have told this Image11 to recover its data before it was overwritten. // its copy of its data. This should not have happened. The TextureStorage should have told
// this Image11 to recover its data before it was overwritten.
ASSERT(textureStorageCorrect); ASSERT(textureStorageCorrect);
if (textureStorageCorrect) if (textureStorageCorrect)
...@@ -177,11 +181,12 @@ void Image11::disassociateStorage() ...@@ -177,11 +181,12 @@ void Image11::disassociateStorage()
} }
} }
bool Image11::redefine(GLenum target, GLenum internalformat, const gl::Extents &size, bool forceRelease) bool Image11::redefine(GLenum target,
GLenum internalformat,
const gl::Extents &size,
bool forceRelease)
{ {
if (mWidth != size.width || if (mWidth != size.width || mHeight != size.height || mInternalFormat != internalformat ||
mHeight != size.height ||
mInternalFormat != internalformat ||
forceRelease) forceRelease)
{ {
// End the association with the TextureStorage, since that data will be out of date. // End the association with the TextureStorage, since that data will be out of date.
...@@ -219,7 +224,8 @@ DXGI_FORMAT Image11::getDXGIFormat() const ...@@ -219,7 +224,8 @@ DXGI_FORMAT Image11::getDXGIFormat() const
return mDXGIFormat; return mDXGIFormat;
} }
// Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as format/type at input // Store the pixel rectangle designated by xoffset,yoffset,width,height with pixels stored as
// format/type at input
// into the target pixel rectangle. // into the target pixel rectangle.
gl::Error Image11::loadData(const gl::Box &area, gl::Error Image11::loadData(const gl::Box &area,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
...@@ -250,7 +256,9 @@ gl::Error Image11::loadData(const gl::Box &area, ...@@ -250,7 +256,9 @@ gl::Error Image11::loadData(const gl::Box &area,
D3D11_MAPPED_SUBRESOURCE mappedImage; D3D11_MAPPED_SUBRESOURCE mappedImage;
ANGLE_TRY(map(D3D11_MAP_WRITE, &mappedImage)); ANGLE_TRY(map(D3D11_MAP_WRITE, &mappedImage));
uint8_t *offsetMappedData = (reinterpret_cast<uint8_t*>(mappedImage.pData) + (area.y * mappedImage.RowPitch + area.x * outputPixelSize + area.z * mappedImage.DepthPitch)); uint8_t *offsetMappedData = (reinterpret_cast<uint8_t *>(mappedImage.pData) +
(area.y * mappedImage.RowPitch + area.x * outputPixelSize +
area.z * mappedImage.DepthPitch));
loadFunction(area.width, area.height, area.depth, loadFunction(area.width, area.height, area.depth,
reinterpret_cast<const uint8_t *>(input) + inputSkipBytes, inputRowPitch, reinterpret_cast<const uint8_t *>(input) + inputSkipBytes, inputRowPitch,
inputDepthPitch, offsetMappedData, mappedImage.RowPitch, mappedImage.DepthPitch); inputDepthPitch, offsetMappedData, mappedImage.RowPitch, mappedImage.DepthPitch);
...@@ -283,13 +291,14 @@ gl::Error Image11::loadCompressedData(const gl::Box &area, const void *input) ...@@ -283,13 +291,14 @@ gl::Error Image11::loadCompressedData(const gl::Box &area, const void *input)
D3D11_MAPPED_SUBRESOURCE mappedImage; D3D11_MAPPED_SUBRESOURCE mappedImage;
ANGLE_TRY(map(D3D11_MAP_WRITE, &mappedImage)); ANGLE_TRY(map(D3D11_MAP_WRITE, &mappedImage));
uint8_t* offsetMappedData = reinterpret_cast<uint8_t*>(mappedImage.pData) + ((area.y / outputBlockHeight) * mappedImage.RowPitch + uint8_t *offsetMappedData =
(area.x / outputBlockWidth) * outputPixelSize + reinterpret_cast<uint8_t *>(mappedImage.pData) +
area.z * mappedImage.DepthPitch); ((area.y / outputBlockHeight) * mappedImage.RowPitch +
(area.x / outputBlockWidth) * outputPixelSize + area.z * mappedImage.DepthPitch);
loadFunction(area.width, area.height, area.depth, loadFunction(area.width, area.height, area.depth, reinterpret_cast<const uint8_t *>(input),
reinterpret_cast<const uint8_t*>(input), inputRowPitch, inputDepthPitch, inputRowPitch, inputDepthPitch, offsetMappedData, mappedImage.RowPitch,
offsetMappedData, mappedImage.RowPitch, mappedImage.DepthPitch); mappedImage.DepthPitch);
unmap(); unmap();
...@@ -461,7 +470,8 @@ gl::Error Image11::copyWithoutConversion(const gl::Offset &destOffset, ...@@ -461,7 +470,8 @@ gl::Error Image11::copyWithoutConversion(const gl::Offset &destOffset,
return gl::NoError(); return gl::NoError();
} }
gl::Error Image11::getStagingTexture(ID3D11Resource **outStagingTexture, unsigned int *outSubresourceIndex) gl::Error Image11::getStagingTexture(ID3D11Resource **outStagingTexture,
unsigned int *outSubresourceIndex)
{ {
ANGLE_TRY(createStagingTexture()); ANGLE_TRY(createStagingTexture());
...@@ -516,8 +526,9 @@ gl::Error Image11::createStagingTexture() ...@@ -516,8 +526,9 @@ gl::Error Image11::createStagingTexture()
{ {
std::vector<D3D11_SUBRESOURCE_DATA> initialData; std::vector<D3D11_SUBRESOURCE_DATA> initialData;
std::vector<std::vector<BYTE>> textureData; std::vector<std::vector<BYTE>> textureData;
d3d11::GenerateInitialTextureData(mInternalFormat, mRenderer->getRenderer11DeviceCaps(), width, height, mDepth, d3d11::GenerateInitialTextureData(mInternalFormat, mRenderer->getRenderer11DeviceCaps(),
lodOffset + 1, &initialData, &textureData); width, height, mDepth, lodOffset + 1, &initialData,
&textureData);
result = device->CreateTexture3D(&desc, initialData.data(), &newTexture); result = device->CreateTexture3D(&desc, initialData.data(), &newTexture);
} }
...@@ -529,13 +540,15 @@ gl::Error Image11::createStagingTexture() ...@@ -529,13 +540,15 @@ gl::Error Image11::createStagingTexture()
if (FAILED(result)) if (FAILED(result))
{ {
ASSERT(result == E_OUTOFMEMORY); ASSERT(result == E_OUTOFMEMORY);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create staging texture, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create staging texture, result: 0x%X.",
result);
} }
mStagingTexture = newTexture; mStagingTexture = newTexture;
mStagingSubresource = D3D11CalcSubresource(lodOffset, 0, lodOffset + 1); mStagingSubresource = D3D11CalcSubresource(lodOffset, 0, lodOffset + 1);
} }
else if (mTarget == GL_TEXTURE_2D || mTarget == GL_TEXTURE_2D_ARRAY || mTarget == GL_TEXTURE_CUBE_MAP) else if (mTarget == GL_TEXTURE_2D || mTarget == GL_TEXTURE_2D_ARRAY ||
mTarget == GL_TEXTURE_CUBE_MAP)
{ {
ID3D11Texture2D *newTexture = NULL; ID3D11Texture2D *newTexture = NULL;
...@@ -557,8 +570,9 @@ gl::Error Image11::createStagingTexture() ...@@ -557,8 +570,9 @@ gl::Error Image11::createStagingTexture()
{ {
std::vector<D3D11_SUBRESOURCE_DATA> initialData; std::vector<D3D11_SUBRESOURCE_DATA> initialData;
std::vector<std::vector<BYTE>> textureData; std::vector<std::vector<BYTE>> textureData;
d3d11::GenerateInitialTextureData(mInternalFormat, mRenderer->getRenderer11DeviceCaps(), width, height, 1, d3d11::GenerateInitialTextureData(mInternalFormat, mRenderer->getRenderer11DeviceCaps(),
lodOffset + 1, &initialData, &textureData); width, height, 1, lodOffset + 1, &initialData,
&textureData);
result = device->CreateTexture2D(&desc, initialData.data(), &newTexture); result = device->CreateTexture2D(&desc, initialData.data(), &newTexture);
} }
...@@ -570,7 +584,8 @@ gl::Error Image11::createStagingTexture() ...@@ -570,7 +584,8 @@ gl::Error Image11::createStagingTexture()
if (FAILED(result)) if (FAILED(result))
{ {
ASSERT(result == E_OUTOFMEMORY); ASSERT(result == E_OUTOFMEMORY);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create staging texture, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create staging texture, result: 0x%X.",
result);
} }
mStagingTexture = newTexture; mStagingTexture = newTexture;
......
...@@ -250,7 +250,9 @@ gl::Error Query11::testQuery(QueryState *queryState) ...@@ -250,7 +250,9 @@ gl::Error Query11::testQuery(QueryState *queryState)
context->GetData(queryState->query, &numPixels, sizeof(numPixels), 0); context->GetData(queryState->query, &numPixels, sizeof(numPixels), 0);
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to get the data of an internal query, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to get the data of an internal query, result: 0x%X.",
result);
} }
if (result == S_OK) if (result == S_OK)
...@@ -264,11 +266,13 @@ gl::Error Query11::testQuery(QueryState *queryState) ...@@ -264,11 +266,13 @@ gl::Error Query11::testQuery(QueryState *queryState)
case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN: case GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN:
{ {
ASSERT(queryState->query); ASSERT(queryState->query);
D3D11_QUERY_DATA_SO_STATISTICS soStats = { 0 }; D3D11_QUERY_DATA_SO_STATISTICS soStats = {0};
HRESULT result = context->GetData(queryState->query, &soStats, sizeof(soStats), 0); HRESULT result = context->GetData(queryState->query, &soStats, sizeof(soStats), 0);
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to get the data of an internal query, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to get the data of an internal query, result: 0x%X.",
result);
} }
if (result == S_OK) if (result == S_OK)
......
...@@ -98,20 +98,25 @@ enum ...@@ -98,20 +98,25 @@ enum
MAX_TEXTURE_IMAGE_UNITS_VTF_SM4 = 16 MAX_TEXTURE_IMAGE_UNITS_VTF_SM4 = 16
}; };
void CalculateConstantBufferParams(GLintptr offset, GLsizeiptr size, UINT *outFirstConstant, UINT *outNumConstants) void CalculateConstantBufferParams(GLintptr offset,
GLsizeiptr size,
UINT *outFirstConstant,
UINT *outNumConstants)
{ {
// The offset must be aligned to 256 bytes (should have been enforced by glBindBufferRange). // The offset must be aligned to 256 bytes (should have been enforced by glBindBufferRange).
ASSERT(offset % 256 == 0); ASSERT(offset % 256 == 0);
// firstConstant and numConstants are expressed in constants of 16-bytes. Furthermore they must be a multiple of 16 constants. // firstConstant and numConstants are expressed in constants of 16-bytes. Furthermore they must
// be a multiple of 16 constants.
*outFirstConstant = static_cast<UINT>(offset / 16); *outFirstConstant = static_cast<UINT>(offset / 16);
// The GL size is not required to be aligned to a 256 bytes boundary. // The GL size is not required to be aligned to a 256 bytes boundary.
// Round the size up to a 256 bytes boundary then express the results in constants of 16-bytes. // Round the size up to a 256 bytes boundary then express the results in constants of 16-bytes.
*outNumConstants = static_cast<UINT>(rx::roundUp(size, static_cast<GLsizeiptr>(256)) / 16); *outNumConstants = static_cast<UINT>(rx::roundUp(size, static_cast<GLsizeiptr>(256)) / 16);
// Since the size is rounded up, firstConstant + numConstants may be bigger than the actual size of the buffer. // Since the size is rounded up, firstConstant + numConstants may be bigger than the actual size
// This behaviour is explictly allowed according to the documentation on ID3D11DeviceContext1::PSSetConstantBuffers1 // of the buffer. This behaviour is explictly allowed according to the documentation on
// ID3D11DeviceContext1::PSSetConstantBuffers1
// https://msdn.microsoft.com/en-us/library/windows/desktop/hh404649%28v=vs.85%29.aspx // https://msdn.microsoft.com/en-us/library/windows/desktop/hh404649%28v=vs.85%29.aspx
} }
...@@ -130,14 +135,20 @@ ANGLEFeatureLevel GetANGLEFeatureLevel(D3D_FEATURE_LEVEL d3dFeatureLevel) ...@@ -130,14 +135,20 @@ ANGLEFeatureLevel GetANGLEFeatureLevel(D3D_FEATURE_LEVEL d3dFeatureLevel)
{ {
switch (d3dFeatureLevel) switch (d3dFeatureLevel)
{ {
case D3D_FEATURE_LEVEL_9_3: return ANGLE_FEATURE_LEVEL_9_3; case D3D_FEATURE_LEVEL_9_3:
case D3D_FEATURE_LEVEL_10_0: return ANGLE_FEATURE_LEVEL_10_0; return ANGLE_FEATURE_LEVEL_9_3;
case D3D_FEATURE_LEVEL_10_1: return ANGLE_FEATURE_LEVEL_10_1; case D3D_FEATURE_LEVEL_10_0:
case D3D_FEATURE_LEVEL_11_0: return ANGLE_FEATURE_LEVEL_11_0; return ANGLE_FEATURE_LEVEL_10_0;
case D3D_FEATURE_LEVEL_10_1:
return ANGLE_FEATURE_LEVEL_10_1;
case D3D_FEATURE_LEVEL_11_0:
return ANGLE_FEATURE_LEVEL_11_0;
// Note: we don't ever request a 11_1 device, because this gives // Note: we don't ever request a 11_1 device, because this gives
// an E_INVALIDARG error on systems that don't have the platform update. // an E_INVALIDARG error on systems that don't have the platform update.
case D3D_FEATURE_LEVEL_11_1: return ANGLE_FEATURE_LEVEL_11_1; case D3D_FEATURE_LEVEL_11_1:
default: return ANGLE_FEATURE_LEVEL_INVALID; return ANGLE_FEATURE_LEVEL_11_1;
default:
return ANGLE_FEATURE_LEVEL_INVALID;
} }
} }
...@@ -557,7 +568,8 @@ egl::Error Renderer11::initialize() ...@@ -557,7 +568,8 @@ egl::Error Renderer11::initialize()
#if !ANGLE_SKIP_DXGI_1_2_CHECK #if !ANGLE_SKIP_DXGI_1_2_CHECK
{ {
TRACE_EVENT0("gpu.angle", "Renderer11::initialize (DXGICheck)"); TRACE_EVENT0("gpu.angle", "Renderer11::initialize (DXGICheck)");
// In order to create a swap chain for an HWND owned by another process, DXGI 1.2 is required. // In order to create a swap chain for an HWND owned by another process, DXGI 1.2 is
// required.
// The easiest way to check is to query for a IDXGIDevice2. // The easiest way to check is to query for a IDXGIDevice2.
bool requireDXGI1_2 = false; bool requireDXGI1_2 = false;
HWND hwnd = WindowFromDC(mDisplay->getNativeDisplayId()); HWND hwnd = WindowFromDC(mDisplay->getNativeDisplayId());
...@@ -576,11 +588,11 @@ egl::Error Renderer11::initialize() ...@@ -576,11 +588,11 @@ egl::Error Renderer11::initialize()
if (requireDXGI1_2) if (requireDXGI1_2)
{ {
IDXGIDevice2 *dxgiDevice2 = NULL; IDXGIDevice2 *dxgiDevice2 = NULL;
result = mDevice->QueryInterface(__uuidof(IDXGIDevice2), (void**)&dxgiDevice2); result = mDevice->QueryInterface(__uuidof(IDXGIDevice2), (void **)&dxgiDevice2);
if (FAILED(result)) if (FAILED(result))
{ {
return egl::Error(EGL_NOT_INITIALIZED, return egl::Error(
D3D11_INIT_INCOMPATIBLE_DXGI, EGL_NOT_INITIALIZED, D3D11_INIT_INCOMPATIBLE_DXGI,
"DXGI 1.2 required to present to HWNDs owned by another process."); "DXGI 1.2 required to present to HWNDs owned by another process.");
} }
SafeRelease(dxgiDevice2); SafeRelease(dxgiDevice2);
...@@ -597,21 +609,19 @@ egl::Error Renderer11::initialize() ...@@ -597,21 +609,19 @@ egl::Error Renderer11::initialize()
mDeviceContext1 = d3d11::DynamicCastComObject<ID3D11DeviceContext1>(mDeviceContext); mDeviceContext1 = d3d11::DynamicCastComObject<ID3D11DeviceContext1>(mDeviceContext);
IDXGIDevice *dxgiDevice = NULL; IDXGIDevice *dxgiDevice = NULL;
result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void**)&dxgiDevice); result = mDevice->QueryInterface(__uuidof(IDXGIDevice), (void **)&dxgiDevice);
if (FAILED(result)) if (FAILED(result))
{ {
return egl::Error(EGL_NOT_INITIALIZED, return egl::Error(EGL_NOT_INITIALIZED, D3D11_INIT_OTHER_ERROR,
D3D11_INIT_OTHER_ERROR,
"Could not query DXGI device."); "Could not query DXGI device.");
} }
result = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void**)&mDxgiAdapter); result = dxgiDevice->GetParent(__uuidof(IDXGIAdapter), (void **)&mDxgiAdapter);
if (FAILED(result)) if (FAILED(result))
{ {
return egl::Error(EGL_NOT_INITIALIZED, return egl::Error(EGL_NOT_INITIALIZED, D3D11_INIT_OTHER_ERROR,
D3D11_INIT_OTHER_ERROR,
"Could not retrieve DXGI adapter"); "Could not retrieve DXGI adapter");
} }
...@@ -619,16 +629,20 @@ egl::Error Renderer11::initialize() ...@@ -619,16 +629,20 @@ egl::Error Renderer11::initialize()
IDXGIAdapter2 *dxgiAdapter2 = d3d11::DynamicCastComObject<IDXGIAdapter2>(mDxgiAdapter); IDXGIAdapter2 *dxgiAdapter2 = d3d11::DynamicCastComObject<IDXGIAdapter2>(mDxgiAdapter);
// On D3D_FEATURE_LEVEL_9_*, IDXGIAdapter::GetDesc returns "Software Adapter" for the description string. // On D3D_FEATURE_LEVEL_9_*, IDXGIAdapter::GetDesc returns "Software Adapter" for the
// If DXGI1.2 is available then IDXGIAdapter2::GetDesc2 can be used to get the actual hardware values. // description string.
// If DXGI1.2 is available then IDXGIAdapter2::GetDesc2 can be used to get the actual
// hardware values.
if (mRenderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3 && dxgiAdapter2 != NULL) if (mRenderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3 && dxgiAdapter2 != NULL)
{ {
DXGI_ADAPTER_DESC2 adapterDesc2 = {}; DXGI_ADAPTER_DESC2 adapterDesc2 = {};
result = dxgiAdapter2->GetDesc2(&adapterDesc2); result = dxgiAdapter2->GetDesc2(&adapterDesc2);
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
// Copy the contents of the DXGI_ADAPTER_DESC2 into mAdapterDescription (a DXGI_ADAPTER_DESC). // Copy the contents of the DXGI_ADAPTER_DESC2 into mAdapterDescription (a
memcpy(mAdapterDescription.Description, adapterDesc2.Description, sizeof(mAdapterDescription.Description)); // DXGI_ADAPTER_DESC).
memcpy(mAdapterDescription.Description, adapterDesc2.Description,
sizeof(mAdapterDescription.Description));
mAdapterDescription.VendorId = adapterDesc2.VendorId; mAdapterDescription.VendorId = adapterDesc2.VendorId;
mAdapterDescription.DeviceId = adapterDesc2.DeviceId; mAdapterDescription.DeviceId = adapterDesc2.DeviceId;
mAdapterDescription.SubSysId = adapterDesc2.SubSysId; mAdapterDescription.SubSysId = adapterDesc2.SubSysId;
...@@ -648,25 +662,23 @@ egl::Error Renderer11::initialize() ...@@ -648,25 +662,23 @@ egl::Error Renderer11::initialize()
if (FAILED(result)) if (FAILED(result))
{ {
return egl::Error(EGL_NOT_INITIALIZED, return egl::Error(EGL_NOT_INITIALIZED, D3D11_INIT_OTHER_ERROR,
D3D11_INIT_OTHER_ERROR,
"Could not read DXGI adaptor description."); "Could not read DXGI adaptor description.");
} }
memset(mDescription, 0, sizeof(mDescription)); memset(mDescription, 0, sizeof(mDescription));
wcstombs(mDescription, mAdapterDescription.Description, sizeof(mDescription) - 1); wcstombs(mDescription, mAdapterDescription.Description, sizeof(mDescription) - 1);
result = mDxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void**)&mDxgiFactory); result = mDxgiAdapter->GetParent(__uuidof(IDXGIFactory), (void **)&mDxgiFactory);
if (!mDxgiFactory || FAILED(result)) if (!mDxgiFactory || FAILED(result))
{ {
return egl::Error(EGL_NOT_INITIALIZED, return egl::Error(EGL_NOT_INITIALIZED, D3D11_INIT_OTHER_ERROR,
D3D11_INIT_OTHER_ERROR,
"Could not create DXGI factory."); "Could not create DXGI factory.");
} }
} }
// Disable some spurious D3D11 debug warnings to prevent them from flooding the output log // Disable some spurious D3D11 debug warnings to prevent them from flooding the output log
#if defined(ANGLE_SUPPRESS_D3D11_HAZARD_WARNINGS) && defined(_DEBUG) #if defined(ANGLE_SUPPRESS_D3D11_HAZARD_WARNINGS) && defined(_DEBUG)
{ {
TRACE_EVENT0("gpu.angle", "Renderer11::initialize (HideWarnings)"); TRACE_EVENT0("gpu.angle", "Renderer11::initialize (HideWarnings)");
...@@ -675,10 +687,8 @@ egl::Error Renderer11::initialize() ...@@ -675,10 +687,8 @@ egl::Error Renderer11::initialize()
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
D3D11_MESSAGE_ID hideMessages[] = D3D11_MESSAGE_ID hideMessages[] = {
{ D3D11_MESSAGE_ID_DEVICE_DRAW_RENDERTARGETVIEW_NOT_SET};
D3D11_MESSAGE_ID_DEVICE_DRAW_RENDERTARGETVIEW_NOT_SET
};
D3D11_INFO_QUEUE_FILTER filter = {}; D3D11_INFO_QUEUE_FILTER filter = {};
filter.DenyList.NumIDs = static_cast<unsigned int>(ArraySize(hideMessages)); filter.DenyList.NumIDs = static_cast<unsigned int>(ArraySize(hideMessages));
...@@ -868,8 +878,7 @@ void Renderer11::initializeDevice() ...@@ -868,8 +878,7 @@ void Renderer11::initializeDevice()
angleFeatureLevel = ANGLE_FEATURE_LEVEL_11_1; angleFeatureLevel = ANGLE_FEATURE_LEVEL_11_1;
} }
ANGLE_HISTOGRAM_ENUMERATION("GPU.ANGLE.D3D11FeatureLevel", ANGLE_HISTOGRAM_ENUMERATION("GPU.ANGLE.D3D11FeatureLevel", angleFeatureLevel,
angleFeatureLevel,
NUM_ANGLE_FEATURE_LEVELS); NUM_ANGLE_FEATURE_LEVELS);
} }
...@@ -892,11 +901,13 @@ void Renderer11::populateRenderer11DeviceCaps() ...@@ -892,11 +901,13 @@ void Renderer11::populateRenderer11DeviceCaps()
if (mDeviceContext1) if (mDeviceContext1)
{ {
D3D11_FEATURE_DATA_D3D11_OPTIONS d3d11Options; D3D11_FEATURE_DATA_D3D11_OPTIONS d3d11Options;
HRESULT result = mDevice->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS, &d3d11Options, sizeof(D3D11_FEATURE_DATA_D3D11_OPTIONS)); HRESULT result = mDevice->CheckFeatureSupport(D3D11_FEATURE_D3D11_OPTIONS, &d3d11Options,
sizeof(D3D11_FEATURE_DATA_D3D11_OPTIONS));
if (SUCCEEDED(result)) if (SUCCEEDED(result))
{ {
mRenderer11DeviceCaps.supportsClearView = (d3d11Options.ClearView != FALSE); mRenderer11DeviceCaps.supportsClearView = (d3d11Options.ClearView != FALSE);
mRenderer11DeviceCaps.supportsConstantBufferOffsets = (d3d11Options.ConstantBufferOffsetting != FALSE); mRenderer11DeviceCaps.supportsConstantBufferOffsets =
(d3d11Options.ConstantBufferOffsetting != FALSE);
} }
} }
...@@ -914,13 +925,15 @@ void Renderer11::populateRenderer11DeviceCaps() ...@@ -914,13 +925,15 @@ void Renderer11::populateRenderer11DeviceCaps()
} }
} }
hr = mDevice->CheckFormatSupport(DXGI_FORMAT_B4G4R4A4_UNORM, &(mRenderer11DeviceCaps.B4G4R4A4support)); hr = mDevice->CheckFormatSupport(DXGI_FORMAT_B4G4R4A4_UNORM,
&(mRenderer11DeviceCaps.B4G4R4A4support));
if (FAILED(hr)) if (FAILED(hr))
{ {
mRenderer11DeviceCaps.B4G4R4A4support = 0; mRenderer11DeviceCaps.B4G4R4A4support = 0;
} }
hr = mDevice->CheckFormatSupport(DXGI_FORMAT_B5G5R5A1_UNORM, &(mRenderer11DeviceCaps.B5G5R5A1support)); hr = mDevice->CheckFormatSupport(DXGI_FORMAT_B5G5R5A1_UNORM,
&(mRenderer11DeviceCaps.B5G5R5A1support));
if (FAILED(hr)) if (FAILED(hr))
{ {
mRenderer11DeviceCaps.B5G5R5A1support = 0; mRenderer11DeviceCaps.B5G5R5A1support = 0;
...@@ -952,11 +965,8 @@ egl::ConfigSet Renderer11::generateConfigs() ...@@ -952,11 +965,8 @@ egl::ConfigSet Renderer11::generateConfigs()
colorBufferFormats.push_back(GL_RGB565); colorBufferFormats.push_back(GL_RGB565);
} }
static const GLenum depthStencilBufferFormats[] = static const GLenum depthStencilBufferFormats[] = {
{ GL_NONE, GL_DEPTH24_STENCIL8_OES, GL_DEPTH_COMPONENT16,
GL_NONE,
GL_DEPTH24_STENCIL8_OES,
GL_DEPTH_COMPONENT16,
}; };
const gl::Caps &rendererCaps = getNativeCaps(); const gl::Caps &rendererCaps = getNativeCaps();
...@@ -968,7 +978,8 @@ egl::ConfigSet Renderer11::generateConfigs() ...@@ -968,7 +978,8 @@ egl::ConfigSet Renderer11::generateConfigs()
egl::ConfigSet configs; egl::ConfigSet configs;
for (GLenum colorBufferInternalFormat : colorBufferFormats) for (GLenum colorBufferInternalFormat : colorBufferFormats)
{ {
const gl::TextureCaps &colorBufferFormatCaps = rendererTextureCaps.get(colorBufferInternalFormat); const gl::TextureCaps &colorBufferFormatCaps =
rendererTextureCaps.get(colorBufferInternalFormat);
if (!colorBufferFormatCaps.renderable) if (!colorBufferFormatCaps.renderable)
{ {
continue; continue;
...@@ -1125,7 +1136,8 @@ gl::Error Renderer11::finish() ...@@ -1125,7 +1136,8 @@ gl::Error Renderer11::finish()
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create event query, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create event query, result: 0x%X.",
result);
} }
} }
...@@ -1141,7 +1153,8 @@ gl::Error Renderer11::finish() ...@@ -1141,7 +1153,8 @@ gl::Error Renderer11::finish()
result = mDeviceContext->GetData(mSyncQuery, NULL, 0, flags); result = mDeviceContext->GetData(mSyncQuery, NULL, 0, flags);
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to get event query data, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "Failed to get event query data, result: 0x%X.",
result);
} }
// Keep polling, but allow other threads to do something useful first // Keep polling, but allow other threads to do something useful first
...@@ -1152,8 +1165,7 @@ gl::Error Renderer11::finish() ...@@ -1152,8 +1165,7 @@ gl::Error Renderer11::finish()
mDisplay->notifyDeviceLost(); mDisplay->notifyDeviceLost();
return gl::Error(GL_OUT_OF_MEMORY, "Device was lost while waiting for sync."); return gl::Error(GL_OUT_OF_MEMORY, "Device was lost while waiting for sync.");
} }
} } while (result == S_FALSE);
while (result == S_FALSE);
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
...@@ -1193,7 +1205,7 @@ SwapChainD3D *Renderer11::createSwapChain(NativeWindowD3D *nativeWindow, ...@@ -1193,7 +1205,7 @@ SwapChainD3D *Renderer11::createSwapChain(NativeWindowD3D *nativeWindow,
void *Renderer11::getD3DDevice() void *Renderer11::getD3DDevice()
{ {
return reinterpret_cast<void*>(mDevice); return reinterpret_cast<void *>(mDevice);
} }
gl::Error Renderer11::generateSwizzle(gl::Texture *texture) gl::Error Renderer11::generateSwizzle(gl::Texture *texture)
...@@ -1306,7 +1318,8 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type, ...@@ -1306,7 +1318,8 @@ gl::Error Renderer11::setSamplerState(gl::SamplerType type,
metadata = &mSamplerMetadataVS; metadata = &mSamplerMetadataVS;
} }
else UNREACHABLE(); else
UNREACHABLE();
ASSERT(metadata != nullptr); ASSERT(metadata != nullptr);
metadata->update(index, *texture); metadata->update(index, *texture);
...@@ -1332,8 +1345,8 @@ gl::Error Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *t ...@@ -1332,8 +1345,8 @@ gl::Error Renderer11::setTexture(gl::SamplerType type, int index, gl::Texture *t
ANGLE_TRY(storage11->getSRV(texture->getTextureState(), &textureSRV)); ANGLE_TRY(storage11->getSRV(texture->getTextureState(), &textureSRV));
// If we get NULL back from getSRV here, something went wrong in the texture class and we're unexpectedly // If we get NULL back from getSRV here, something went wrong in the texture class and we're
// missing the shader resource view // unexpectedly missing the shader resource view
ASSERT(textureSRV != NULL); ASSERT(textureSRV != NULL);
textureImpl->resetDirty(); textureImpl->resetDirty();
...@@ -1353,7 +1366,8 @@ gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data, ...@@ -1353,7 +1366,8 @@ gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data,
const std::vector<GLint> &vertexUniformBuffers, const std::vector<GLint> &vertexUniformBuffers,
const std::vector<GLint> &fragmentUniformBuffers) const std::vector<GLint> &fragmentUniformBuffers)
{ {
for (size_t uniformBufferIndex = 0; uniformBufferIndex < vertexUniformBuffers.size(); uniformBufferIndex++) for (size_t uniformBufferIndex = 0; uniformBufferIndex < vertexUniformBuffers.size();
uniformBufferIndex++)
{ {
GLint binding = vertexUniformBuffers[uniformBufferIndex]; GLint binding = vertexUniformBuffers[uniformBufferIndex];
...@@ -1412,7 +1426,8 @@ gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data, ...@@ -1412,7 +1426,8 @@ gl::Error Renderer11::setUniformBuffers(const gl::ContextState &data,
} }
} }
for (size_t uniformBufferIndex = 0; uniformBufferIndex < fragmentUniformBuffers.size(); uniformBufferIndex++) for (size_t uniformBufferIndex = 0; uniformBufferIndex < fragmentUniformBuffers.size();
uniformBufferIndex++)
{ {
GLint binding = fragmentUniformBuffers[uniformBufferIndex]; GLint binding = fragmentUniformBuffers[uniformBufferIndex];
...@@ -1523,14 +1538,35 @@ bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count, bool usesPointSi ...@@ -1523,14 +1538,35 @@ bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count, bool usesPointSi
switch (mode) switch (mode)
{ {
case GL_POINTS: primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_POINTLIST; minCount = 1; break; case GL_POINTS:
case GL_LINES: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINELIST; minCount = 2; break; primitiveTopology = D3D11_PRIMITIVE_TOPOLOGY_POINTLIST;
case GL_LINE_LOOP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP; minCount = 2; break; minCount = 1;
case GL_LINE_STRIP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP; minCount = 2; break; break;
case GL_TRIANGLES: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; minCount = 3; break; case GL_LINES:
case GL_TRIANGLE_STRIP: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP; minCount = 3; break; primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINELIST;
minCount = 2;
break;
case GL_LINE_LOOP:
primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP;
minCount = 2;
break;
case GL_LINE_STRIP:
primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_LINESTRIP;
minCount = 2;
break;
case GL_TRIANGLES:
primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
minCount = 3;
break;
case GL_TRIANGLE_STRIP:
primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
minCount = 3;
break;
// emulate fans via rewriting index buffer // emulate fans via rewriting index buffer
case GL_TRIANGLE_FAN: primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; minCount = 3; break; case GL_TRIANGLE_FAN:
primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
minCount = 3;
break;
default: default:
UNREACHABLE(); UNREACHABLE();
return false; return false;
...@@ -1538,7 +1574,8 @@ bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count, bool usesPointSi ...@@ -1538,7 +1574,8 @@ bool Renderer11::applyPrimitiveType(GLenum mode, GLsizei count, bool usesPointSi
// If instanced pointsprite emulation is being used and If gl_PointSize is used in the shader, // If instanced pointsprite emulation is being used and If gl_PointSize is used in the shader,
// GL_POINTS mode is expected to render pointsprites. // GL_POINTS mode is expected to render pointsprites.
// Instanced PointSprite emulation requires that the topology to be D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST. // Instanced PointSprite emulation requires that the topology to be
// D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST.
if (mode == GL_POINTS && usesPointSize && getWorkarounds().useInstancedPointSpriteEmulation) if (mode == GL_POINTS && usesPointSize && getWorkarounds().useInstancedPointSpriteEmulation)
{ {
primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST; primitiveTopology = D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
...@@ -1615,7 +1652,8 @@ gl::Error Renderer11::applyIndexBuffer(const gl::ContextState &data, ...@@ -1615,7 +1652,8 @@ gl::Error Renderer11::applyIndexBuffer(const gl::ContextState &data,
indexInfo, glState.isPrimitiveRestartEnabled())); indexInfo, glState.isPrimitiveRestartEnabled()));
ID3D11Buffer *buffer = nullptr; ID3D11Buffer *buffer = nullptr;
DXGI_FORMAT bufferFormat = (indexInfo->indexType == GL_UNSIGNED_INT) ? DXGI_FORMAT_R32_UINT : DXGI_FORMAT_R16_UINT; DXGI_FORMAT bufferFormat =
(indexInfo->indexType == GL_UNSIGNED_INT) ? DXGI_FORMAT_R32_UINT : DXGI_FORMAT_R16_UINT;
if (indexInfo->storage) if (indexInfo->storage)
{ {
...@@ -1624,12 +1662,13 @@ gl::Error Renderer11::applyIndexBuffer(const gl::ContextState &data, ...@@ -1624,12 +1662,13 @@ gl::Error Renderer11::applyIndexBuffer(const gl::ContextState &data,
} }
else else
{ {
IndexBuffer11* indexBuffer = GetAs<IndexBuffer11>(indexInfo->indexBuffer); IndexBuffer11 *indexBuffer = GetAs<IndexBuffer11>(indexInfo->indexBuffer);
buffer = indexBuffer->getBuffer(); buffer = indexBuffer->getBuffer();
} }
mAppliedIBChanged = false; mAppliedIBChanged = false;
if (buffer != mAppliedIB || bufferFormat != mAppliedIBFormat || indexInfo->startOffset != mAppliedIBOffset) if (buffer != mAppliedIB || bufferFormat != mAppliedIBFormat ||
indexInfo->startOffset != mAppliedIBOffset)
{ {
mDeviceContext->IASetIndexBuffer(buffer, bufferFormat, indexInfo->startOffset); mDeviceContext->IASetIndexBuffer(buffer, bufferFormat, indexInfo->startOffset);
...@@ -1891,7 +1930,8 @@ gl::Error Renderer11::drawLineLoop(const gl::ContextState &data, ...@@ -1891,7 +1930,8 @@ gl::Error Renderer11::drawLineLoop(const gl::ContextState &data,
if (!mLineLoopIB) if (!mLineLoopIB)
{ {
mLineLoopIB = new StreamingIndexBufferInterface(this); mLineLoopIB = new StreamingIndexBufferInterface(this);
gl::Error error = mLineLoopIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT); gl::Error error =
mLineLoopIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT);
if (error.isError()) if (error.isError())
{ {
SafeDelete(mLineLoopIB); SafeDelete(mLineLoopIB);
...@@ -1902,9 +1942,12 @@ gl::Error Renderer11::drawLineLoop(const gl::ContextState &data, ...@@ -1902,9 +1942,12 @@ gl::Error Renderer11::drawLineLoop(const gl::ContextState &data,
// Checked by Renderer11::applyPrimitiveType // Checked by Renderer11::applyPrimitiveType
ASSERT(count >= 0); ASSERT(count >= 0);
if (static_cast<unsigned int>(count) + 1 > (std::numeric_limits<unsigned int>::max() / sizeof(unsigned int))) if (static_cast<unsigned int>(count) + 1 >
(std::numeric_limits<unsigned int>::max() / sizeof(unsigned int)))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create a 32-bit looping index buffer for GL_LINE_LOOP, too many indices required."); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create a 32-bit looping index buffer for GL_LINE_LOOP, too "
"many indices required.");
} }
GetLineLoopIndices(indices, type, static_cast<GLuint>(count), GetLineLoopIndices(indices, type, static_cast<GLuint>(count),
...@@ -1914,7 +1957,7 @@ gl::Error Renderer11::drawLineLoop(const gl::ContextState &data, ...@@ -1914,7 +1957,7 @@ gl::Error Renderer11::drawLineLoop(const gl::ContextState &data,
static_cast<unsigned int>(sizeof(GLuint) * mScratchIndexDataBuffer.size()); static_cast<unsigned int>(sizeof(GLuint) * mScratchIndexDataBuffer.size());
ANGLE_TRY(mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT)); ANGLE_TRY(mLineLoopIB->reserveBufferSpace(spaceNeeded, GL_UNSIGNED_INT));
void* mappedMemory = NULL; void *mappedMemory = NULL;
unsigned int offset; unsigned int offset;
ANGLE_TRY(mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory, &offset)); ANGLE_TRY(mLineLoopIB->mapBuffer(spaceNeeded, &mappedMemory, &offset));
...@@ -1979,7 +2022,8 @@ gl::Error Renderer11::drawTriangleFan(const gl::ContextState &data, ...@@ -1979,7 +2022,8 @@ gl::Error Renderer11::drawTriangleFan(const gl::ContextState &data,
if (!mTriangleFanIB) if (!mTriangleFanIB)
{ {
mTriangleFanIB = new StreamingIndexBufferInterface(this); mTriangleFanIB = new StreamingIndexBufferInterface(this);
gl::Error error = mTriangleFanIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT); gl::Error error =
mTriangleFanIB->reserveBufferSpace(INITIAL_INDEX_BUFFER_SIZE, GL_UNSIGNED_INT);
if (error.isError()) if (error.isError())
{ {
SafeDelete(mTriangleFanIB); SafeDelete(mTriangleFanIB);
...@@ -1994,7 +2038,9 @@ gl::Error Renderer11::drawTriangleFan(const gl::ContextState &data, ...@@ -1994,7 +2038,9 @@ gl::Error Renderer11::drawTriangleFan(const gl::ContextState &data,
if (numTris > (std::numeric_limits<unsigned int>::max() / (sizeof(unsigned int) * 3))) if (numTris > (std::numeric_limits<unsigned int>::max() / (sizeof(unsigned int) * 3)))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create a scratch index buffer for GL_TRIANGLE_FAN, too many indices required."); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create a scratch index buffer for GL_TRIANGLE_FAN, too many "
"indices required.");
} }
GetTriFanIndices(indexPointer, type, count, data.getState().isPrimitiveRestartEnabled(), GetTriFanIndices(indexPointer, type, count, data.getState().isPrimitiveRestartEnabled(),
...@@ -2148,13 +2194,14 @@ gl::Error Renderer11::applyUniforms(const ProgramD3D &programD3D, ...@@ -2148,13 +2194,14 @@ gl::Error Renderer11::applyUniforms(const ProgramD3D &programD3D,
ID3D11Buffer *vertexConstantBuffer = vertexUniformStorage->getConstantBuffer(); ID3D11Buffer *vertexConstantBuffer = vertexUniformStorage->getConstantBuffer();
ID3D11Buffer *pixelConstantBuffer = fragmentUniformStorage->getConstantBuffer(); ID3D11Buffer *pixelConstantBuffer = fragmentUniformStorage->getConstantBuffer();
float (*mapVS)[4] = NULL; float(*mapVS)[4] = NULL;
float (*mapPS)[4] = NULL; float(*mapPS)[4] = NULL;
if (totalRegisterCountVS > 0 && vertexUniformsDirty) if (totalRegisterCountVS > 0 && vertexUniformsDirty)
{ {
D3D11_MAPPED_SUBRESOURCE map = {0}; D3D11_MAPPED_SUBRESOURCE map = {0};
HRESULT result = mDeviceContext->Map(vertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); HRESULT result =
mDeviceContext->Map(vertexConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
UNUSED_ASSERTION_VARIABLE(result); UNUSED_ASSERTION_VARIABLE(result);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
mapVS = (float(*)[4])map.pData; mapVS = (float(*)[4])map.pData;
...@@ -2163,7 +2210,8 @@ gl::Error Renderer11::applyUniforms(const ProgramD3D &programD3D, ...@@ -2163,7 +2210,8 @@ gl::Error Renderer11::applyUniforms(const ProgramD3D &programD3D,
if (totalRegisterCountPS > 0 && pixelUniformsDirty) if (totalRegisterCountPS > 0 && pixelUniformsDirty)
{ {
D3D11_MAPPED_SUBRESOURCE map = {0}; D3D11_MAPPED_SUBRESOURCE map = {0};
HRESULT result = mDeviceContext->Map(pixelConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map); HRESULT result =
mDeviceContext->Map(pixelConstantBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &map);
UNUSED_ASSERTION_VARIABLE(result); UNUSED_ASSERTION_VARIABLE(result);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
mapPS = (float(*)[4])map.pData; mapPS = (float(*)[4])map.pData;
...@@ -2227,7 +2275,9 @@ gl::Error Renderer11::applyUniforms(const ProgramD3D &programD3D, ...@@ -2227,7 +2275,9 @@ gl::Error Renderer11::applyUniforms(const ProgramD3D &programD3D,
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create vertex shader constant buffer, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create vertex shader constant buffer, result: 0x%X.",
result);
} }
mDeviceContext->VSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1, mDeviceContext->VSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1,
&mDriverConstantBufferVS); &mDriverConstantBufferVS);
...@@ -2242,7 +2292,9 @@ gl::Error Renderer11::applyUniforms(const ProgramD3D &programD3D, ...@@ -2242,7 +2292,9 @@ gl::Error Renderer11::applyUniforms(const ProgramD3D &programD3D,
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create pixel shader constant buffer, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create pixel shader constant buffer, result: 0x%X.",
result);
} }
mDeviceContext->PSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1, mDeviceContext->PSSetConstantBuffers(d3d11::RESERVED_CONSTANT_BUFFER_SLOT_DRIVER, 1,
&mDriverConstantBufferPS); &mDriverConstantBufferPS);
...@@ -2516,25 +2568,26 @@ bool Renderer11::testDeviceLost() ...@@ -2516,25 +2568,26 @@ bool Renderer11::testDeviceLost()
bool Renderer11::testDeviceResettable() bool Renderer11::testDeviceResettable()
{ {
// determine if the device is resettable by creating a dummy device // determine if the device is resettable by creating a dummy device
PFN_D3D11_CREATE_DEVICE D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)GetProcAddress(mD3d11Module, "D3D11CreateDevice"); PFN_D3D11_CREATE_DEVICE D3D11CreateDevice =
(PFN_D3D11_CREATE_DEVICE)GetProcAddress(mD3d11Module, "D3D11CreateDevice");
if (D3D11CreateDevice == NULL) if (D3D11CreateDevice == NULL)
{ {
return false; return false;
} }
ID3D11Device* dummyDevice; ID3D11Device *dummyDevice;
D3D_FEATURE_LEVEL dummyFeatureLevel; D3D_FEATURE_LEVEL dummyFeatureLevel;
ID3D11DeviceContext* dummyContext; ID3D11DeviceContext *dummyContext;
ASSERT(mRequestedDriverType != D3D_DRIVER_TYPE_UNKNOWN); ASSERT(mRequestedDriverType != D3D_DRIVER_TYPE_UNKNOWN);
HRESULT result = D3D11CreateDevice( HRESULT result = D3D11CreateDevice(
NULL, mRequestedDriverType, NULL, NULL, mRequestedDriverType, NULL,
#if defined(_DEBUG) #if defined(_DEBUG)
D3D11_CREATE_DEVICE_DEBUG, D3D11_CREATE_DEVICE_DEBUG,
#else #else
0, 0,
#endif #endif
mAvailableFeatureLevels.data(), static_cast<unsigned int>(mAvailableFeatureLevels.size()), mAvailableFeatureLevels.data(), static_cast<unsigned int>(mAvailableFeatureLevels.size()),
D3D11_SDK_VERSION, &dummyDevice, &dummyFeatureLevel, &dummyContext); D3D11_SDK_VERSION, &dummyDevice, &dummyFeatureLevel, &dummyContext);
...@@ -2630,8 +2683,10 @@ std::string Renderer11::getRendererDescription() const ...@@ -2630,8 +2683,10 @@ std::string Renderer11::getRendererDescription() const
rendererString << mDescription; rendererString << mDescription;
rendererString << " Direct3D11"; rendererString << " Direct3D11";
rendererString << " vs_" << getMajorShaderModel() << "_" << getMinorShaderModel() << getShaderModelSuffix(); rendererString << " vs_" << getMajorShaderModel() << "_" << getMinorShaderModel()
rendererString << " ps_" << getMajorShaderModel() << "_" << getMinorShaderModel() << getShaderModelSuffix(); << getShaderModelSuffix();
rendererString << " ps_" << getMajorShaderModel() << "_" << getMinorShaderModel()
<< getShaderModelSuffix();
return rendererString.str(); return rendererString.str();
} }
...@@ -2639,7 +2694,7 @@ std::string Renderer11::getRendererDescription() const ...@@ -2639,7 +2694,7 @@ std::string Renderer11::getRendererDescription() const
DeviceIdentifier Renderer11::getAdapterIdentifier() const DeviceIdentifier Renderer11::getAdapterIdentifier() const
{ {
// Don't use the AdapterLuid here, since that doesn't persist across reboot. // Don't use the AdapterLuid here, since that doesn't persist across reboot.
DeviceIdentifier deviceIdentifier = { 0 }; DeviceIdentifier deviceIdentifier = {0};
deviceIdentifier.VendorId = mAdapterDescription.VendorId; deviceIdentifier.VendorId = mAdapterDescription.VendorId;
deviceIdentifier.DeviceId = mAdapterDescription.DeviceId; deviceIdentifier.DeviceId = mAdapterDescription.DeviceId;
deviceIdentifier.SubSysId = mAdapterDescription.SubSysId; deviceIdentifier.SubSysId = mAdapterDescription.SubSysId;
...@@ -2717,7 +2772,8 @@ bool Renderer11::getShareHandleSupport() const ...@@ -2717,7 +2772,8 @@ bool Renderer11::getShareHandleSupport() const
return false; return false;
} }
// Also disable share handles on Feature Level 9_3, since it doesn't support share handles on RGBA8 textures/swapchains. // Also disable share handles on Feature Level 9_3, since it doesn't support share handles on
// RGBA8 textures/swapchains.
if (mRenderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3) if (mRenderer11DeviceCaps.featureLevel <= D3D_FEATURE_LEVEL_9_3)
{ {
mSupportsShareHandles = false; mSupportsShareHandles = false;
...@@ -2780,11 +2836,17 @@ int Renderer11::getMajorShaderModel() const ...@@ -2780,11 +2836,17 @@ int Renderer11::getMajorShaderModel() const
{ {
switch (mRenderer11DeviceCaps.featureLevel) switch (mRenderer11DeviceCaps.featureLevel)
{ {
case D3D_FEATURE_LEVEL_11_0: return D3D11_SHADER_MAJOR_VERSION; // 5 case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1: return D3D10_1_SHADER_MAJOR_VERSION; // 4 return D3D11_SHADER_MAJOR_VERSION; // 5
case D3D_FEATURE_LEVEL_10_0: return D3D10_SHADER_MAJOR_VERSION; // 4 case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_9_3: return D3D10_SHADER_MAJOR_VERSION; // 4 return D3D10_1_SHADER_MAJOR_VERSION; // 4
default: UNREACHABLE(); return 0; case D3D_FEATURE_LEVEL_10_0:
return D3D10_SHADER_MAJOR_VERSION; // 4
case D3D_FEATURE_LEVEL_9_3:
return D3D10_SHADER_MAJOR_VERSION; // 4
default:
UNREACHABLE();
return 0;
} }
} }
...@@ -2792,11 +2854,17 @@ int Renderer11::getMinorShaderModel() const ...@@ -2792,11 +2854,17 @@ int Renderer11::getMinorShaderModel() const
{ {
switch (mRenderer11DeviceCaps.featureLevel) switch (mRenderer11DeviceCaps.featureLevel)
{ {
case D3D_FEATURE_LEVEL_11_0: return D3D11_SHADER_MINOR_VERSION; // 0 case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1: return D3D10_1_SHADER_MINOR_VERSION; // 1 return D3D11_SHADER_MINOR_VERSION; // 0
case D3D_FEATURE_LEVEL_10_0: return D3D10_SHADER_MINOR_VERSION; // 0 case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_9_3: return D3D10_SHADER_MINOR_VERSION; // 0 return D3D10_1_SHADER_MINOR_VERSION; // 1
default: UNREACHABLE(); return 0; case D3D_FEATURE_LEVEL_10_0:
return D3D10_SHADER_MINOR_VERSION; // 0
case D3D_FEATURE_LEVEL_9_3:
return D3D10_SHADER_MINOR_VERSION; // 0
default:
UNREACHABLE();
return 0;
} }
} }
...@@ -2804,11 +2872,17 @@ std::string Renderer11::getShaderModelSuffix() const ...@@ -2804,11 +2872,17 @@ std::string Renderer11::getShaderModelSuffix() const
{ {
switch (mRenderer11DeviceCaps.featureLevel) switch (mRenderer11DeviceCaps.featureLevel)
{ {
case D3D_FEATURE_LEVEL_11_0: return ""; case D3D_FEATURE_LEVEL_11_0:
case D3D_FEATURE_LEVEL_10_1: return ""; return "";
case D3D_FEATURE_LEVEL_10_0: return ""; case D3D_FEATURE_LEVEL_10_1:
case D3D_FEATURE_LEVEL_9_3: return "_level_9_3"; return "";
default: UNREACHABLE(); return ""; case D3D_FEATURE_LEVEL_10_0:
return "";
case D3D_FEATURE_LEVEL_9_3:
return "_level_9_3";
default:
UNREACHABLE();
return "";
} }
} }
...@@ -2886,8 +2960,13 @@ gl::Error Renderer11::copyImage2D(const gl::Framebuffer *framebuffer, ...@@ -2886,8 +2960,13 @@ gl::Error Renderer11::copyImage2D(const gl::Framebuffer *framebuffer,
return gl::NoError(); return gl::NoError();
} }
gl::Error Renderer11::copyImageCube(const gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, gl::Error Renderer11::copyImageCube(const gl::Framebuffer *framebuffer,
const gl::Offset &destOffset, TextureStorage *storage, GLenum target, GLint level) const gl::Rectangle &sourceRect,
GLenum destFormat,
const gl::Offset &destOffset,
TextureStorage *storage,
GLenum target,
GLint level)
{ {
TextureStorage11_Cube *storage11 = GetAs<TextureStorage11_Cube>(storage); TextureStorage11_Cube *storage11 = GetAs<TextureStorage11_Cube>(storage);
ASSERT(storage11); ASSERT(storage11);
...@@ -2904,8 +2983,12 @@ gl::Error Renderer11::copyImageCube(const gl::Framebuffer *framebuffer, const gl ...@@ -2904,8 +2983,12 @@ gl::Error Renderer11::copyImageCube(const gl::Framebuffer *framebuffer, const gl
return gl::NoError(); return gl::NoError();
} }
gl::Error Renderer11::copyImage3D(const gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, gl::Error Renderer11::copyImage3D(const gl::Framebuffer *framebuffer,
const gl::Offset &destOffset, TextureStorage *storage, GLint level) const gl::Rectangle &sourceRect,
GLenum destFormat,
const gl::Offset &destOffset,
TextureStorage *storage,
GLint level)
{ {
TextureStorage11_3D *storage11 = GetAs<TextureStorage11_3D>(storage); TextureStorage11_3D *storage11 = GetAs<TextureStorage11_3D>(storage);
ASSERT(storage11); ASSERT(storage11);
...@@ -2922,8 +3005,12 @@ gl::Error Renderer11::copyImage3D(const gl::Framebuffer *framebuffer, const gl:: ...@@ -2922,8 +3005,12 @@ gl::Error Renderer11::copyImage3D(const gl::Framebuffer *framebuffer, const gl::
return gl::NoError(); return gl::NoError();
} }
gl::Error Renderer11::copyImage2DArray(const gl::Framebuffer *framebuffer, const gl::Rectangle &sourceRect, GLenum destFormat, gl::Error Renderer11::copyImage2DArray(const gl::Framebuffer *framebuffer,
const gl::Offset &destOffset, TextureStorage *storage, GLint level) const gl::Rectangle &sourceRect,
GLenum destFormat,
const gl::Offset &destOffset,
TextureStorage *storage,
GLint level)
{ {
TextureStorage11_2DArray *storage11 = GetAs<TextureStorage11_2DArray>(storage); TextureStorage11_2DArray *storage11 = GetAs<TextureStorage11_2DArray>(storage);
ASSERT(storage11); ASSERT(storage11);
...@@ -3064,7 +3151,11 @@ gl::Error Renderer11::copyCompressedTexture(const gl::Texture *source, ...@@ -3064,7 +3151,11 @@ gl::Error Renderer11::copyCompressedTexture(const gl::Texture *source,
return gl::NoError(); return gl::NoError();
} }
gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, GLsizei samples, RenderTargetD3D **outRT) gl::Error Renderer11::createRenderTarget(int width,
int height,
GLenum format,
GLsizei samples,
RenderTargetD3D **outRT)
{ {
const d3d11::Format &formatInfo = d3d11::Format::Get(format, mRenderer11DeviceCaps); const d3d11::Format &formatInfo = d3d11::Format::Get(format, mRenderer11DeviceCaps);
...@@ -3106,7 +3197,8 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G ...@@ -3106,7 +3197,8 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
if (FAILED(result)) if (FAILED(result))
{ {
ASSERT(result == E_OUTOFMEMORY); ASSERT(result == E_OUTOFMEMORY);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create render target texture, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create render target texture, result: 0x%X.", result);
} }
ID3D11ShaderResourceView *srv = nullptr; ID3D11ShaderResourceView *srv = nullptr;
...@@ -3115,7 +3207,8 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G ...@@ -3115,7 +3207,8 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
{ {
D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc; D3D11_SHADER_RESOURCE_VIEW_DESC srvDesc;
srvDesc.Format = formatInfo.srvFormat; srvDesc.Format = formatInfo.srvFormat;
srvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_SRV_DIMENSION_TEXTURE2D : D3D11_SRV_DIMENSION_TEXTURE2DMS; srvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_SRV_DIMENSION_TEXTURE2D
: D3D11_SRV_DIMENSION_TEXTURE2DMS;
srvDesc.Texture2D.MostDetailedMip = 0; srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = 1; srvDesc.Texture2D.MipLevels = 1;
...@@ -3124,7 +3217,9 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G ...@@ -3124,7 +3217,9 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
{ {
ASSERT(result == E_OUTOFMEMORY); ASSERT(result == E_OUTOFMEMORY);
SafeRelease(texture); SafeRelease(texture);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create render target shader resource view, result: 0x%X.", result); return gl::Error(
GL_OUT_OF_MEMORY,
"Failed to create render target shader resource view, result: 0x%X.", result);
} }
if (formatInfo.blitSRVFormat != formatInfo.srvFormat) if (formatInfo.blitSRVFormat != formatInfo.srvFormat)
...@@ -3160,7 +3255,8 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G ...@@ -3160,7 +3255,8 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
{ {
D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc; D3D11_DEPTH_STENCIL_VIEW_DESC dsvDesc;
dsvDesc.Format = formatInfo.dsvFormat; dsvDesc.Format = formatInfo.dsvFormat;
dsvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_DSV_DIMENSION_TEXTURE2D : D3D11_DSV_DIMENSION_TEXTURE2DMS; dsvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_DSV_DIMENSION_TEXTURE2D
: D3D11_DSV_DIMENSION_TEXTURE2DMS;
dsvDesc.Texture2D.MipSlice = 0; dsvDesc.Texture2D.MipSlice = 0;
dsvDesc.Flags = 0; dsvDesc.Flags = 0;
...@@ -3172,7 +3268,9 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G ...@@ -3172,7 +3268,9 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
SafeRelease(texture); SafeRelease(texture);
SafeRelease(srv); SafeRelease(srv);
SafeRelease(blitSRV); SafeRelease(blitSRV);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create render target depth stencil view, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create render target depth stencil view, result: 0x%X.",
result);
} }
*outRT = new TextureRenderTarget11(dsv, texture, srv, format, formatInfo, width, height, *outRT = new TextureRenderTarget11(dsv, texture, srv, format, formatInfo, width, height,
...@@ -3184,7 +3282,8 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G ...@@ -3184,7 +3282,8 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
{ {
D3D11_RENDER_TARGET_VIEW_DESC rtvDesc; D3D11_RENDER_TARGET_VIEW_DESC rtvDesc;
rtvDesc.Format = formatInfo.rtvFormat; rtvDesc.Format = formatInfo.rtvFormat;
rtvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_RTV_DIMENSION_TEXTURE2D : D3D11_RTV_DIMENSION_TEXTURE2DMS; rtvDesc.ViewDimension = (supportedSamples == 0) ? D3D11_RTV_DIMENSION_TEXTURE2D
: D3D11_RTV_DIMENSION_TEXTURE2DMS;
rtvDesc.Texture2D.MipSlice = 0; rtvDesc.Texture2D.MipSlice = 0;
ID3D11RenderTargetView *rtv = NULL; ID3D11RenderTargetView *rtv = NULL;
...@@ -3195,12 +3294,14 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G ...@@ -3195,12 +3294,14 @@ gl::Error Renderer11::createRenderTarget(int width, int height, GLenum format, G
SafeRelease(texture); SafeRelease(texture);
SafeRelease(srv); SafeRelease(srv);
SafeRelease(blitSRV); SafeRelease(blitSRV);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create render target render target view, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create render target render target view, result: 0x%X.",
result);
} }
if (formatInfo.dataInitializerFunction != NULL) if (formatInfo.dataInitializerFunction != NULL)
{ {
const float clearValues[4] = { 0.0f, 0.0f, 0.0f, 1.0f }; const float clearValues[4] = {0.0f, 0.0f, 0.0f, 1.0f};
mDeviceContext->ClearRenderTargetView(rtv, clearValues); mDeviceContext->ClearRenderTargetView(rtv, clearValues);
} }
...@@ -3264,7 +3365,8 @@ gl::Error Renderer11::loadExecutable(const void *function, ...@@ -3264,7 +3365,8 @@ gl::Error Renderer11::loadExecutable(const void *function,
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create vertex shader, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create vertex shader, result: 0x%X.",
result);
} }
if (!streamOutVaryings.empty()) if (!streamOutVaryings.empty())
...@@ -3292,11 +3394,13 @@ gl::Error Renderer11::loadExecutable(const void *function, ...@@ -3292,11 +3394,13 @@ gl::Error Renderer11::loadExecutable(const void *function,
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create steam output shader, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create steam output shader, result: 0x%X.", result);
} }
} }
*outExecutable = new ShaderExecutable11(function, length, vertexShader, streamOutShader); *outExecutable =
new ShaderExecutable11(function, length, vertexShader, streamOutShader);
} }
break; break;
case SHADER_PIXEL: case SHADER_PIXEL:
...@@ -3307,7 +3411,8 @@ gl::Error Renderer11::loadExecutable(const void *function, ...@@ -3307,7 +3411,8 @@ gl::Error Renderer11::loadExecutable(const void *function,
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create pixel shader, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY, "Failed to create pixel shader, result: 0x%X.",
result);
} }
*outExecutable = new ShaderExecutable11(function, length, pixelShader); *outExecutable = new ShaderExecutable11(function, length, pixelShader);
...@@ -3321,7 +3426,8 @@ gl::Error Renderer11::loadExecutable(const void *function, ...@@ -3321,7 +3426,8 @@ gl::Error Renderer11::loadExecutable(const void *function,
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create geometry shader, result: 0x%X.", result); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create geometry shader, result: 0x%X.", result);
} }
*outExecutable = new ShaderExecutable11(function, length, geometryShader); *outExecutable = new ShaderExecutable11(function, length, geometryShader);
...@@ -3360,7 +3466,8 @@ gl::Error Renderer11::compileToExecutable(gl::InfoLog &infoLog, ...@@ -3360,7 +3466,8 @@ gl::Error Renderer11::compileToExecutable(gl::InfoLog &infoLog,
return gl::Error(GL_INVALID_OPERATION); return gl::Error(GL_INVALID_OPERATION);
} }
std::string profile = FormatString("%s_%d_%d%s", profileType, getMajorShaderModel(), getMinorShaderModel(), getShaderModelSuffix().c_str()); std::string profile = FormatString("%s_%d_%d%s", profileType, getMajorShaderModel(),
getMinorShaderModel(), getShaderModelSuffix().c_str());
UINT flags = D3DCOMPILE_OPTIMIZATION_LEVEL2; UINT flags = D3DCOMPILE_OPTIMIZATION_LEVEL2;
...@@ -3376,11 +3483,12 @@ gl::Error Renderer11::compileToExecutable(gl::InfoLog &infoLog, ...@@ -3376,11 +3483,12 @@ gl::Error Renderer11::compileToExecutable(gl::InfoLog &infoLog,
if (workarounds.enableIEEEStrictness) if (workarounds.enableIEEEStrictness)
flags |= D3DCOMPILE_IEEE_STRICTNESS; flags |= D3DCOMPILE_IEEE_STRICTNESS;
// Sometimes D3DCompile will fail with the default compilation flags for complicated shaders when it would otherwise pass with alternative options. // Sometimes D3DCompile will fail with the default compilation flags for complicated shaders
// when it would otherwise pass with alternative options.
// Try the default flags first and if compilation fails, try some alternatives. // Try the default flags first and if compilation fails, try some alternatives.
std::vector<CompileConfig> configs; std::vector<CompileConfig> configs;
configs.push_back(CompileConfig(flags, "default" )); configs.push_back(CompileConfig(flags, "default"));
configs.push_back(CompileConfig(flags | D3DCOMPILE_SKIP_VALIDATION, "skip validation" )); configs.push_back(CompileConfig(flags | D3DCOMPILE_SKIP_VALIDATION, "skip validation"));
configs.push_back(CompileConfig(flags | D3DCOMPILE_SKIP_OPTIMIZATION, "skip optimization")); configs.push_back(CompileConfig(flags | D3DCOMPILE_SKIP_OPTIMIZATION, "skip optimization"));
if (getMajorShaderModel() == 4 && getShaderModelSuffix() != "") if (getMajorShaderModel() == 4 && getShaderModelSuffix() != "")
...@@ -3392,15 +3500,16 @@ gl::Error Renderer11::compileToExecutable(gl::InfoLog &infoLog, ...@@ -3392,15 +3500,16 @@ gl::Error Renderer11::compileToExecutable(gl::InfoLog &infoLog,
CompileConfig(flags | D3DCOMPILE_AVOID_FLOW_CONTROL, "avoid flow control")); CompileConfig(flags | D3DCOMPILE_AVOID_FLOW_CONTROL, "avoid flow control"));
} }
D3D_SHADER_MACRO loopMacros[] = { {"ANGLE_ENABLE_LOOP_FLATTEN", "1"}, {0, 0} }; D3D_SHADER_MACRO loopMacros[] = {{"ANGLE_ENABLE_LOOP_FLATTEN", "1"}, {0, 0}};
ID3DBlob *binary = NULL; ID3DBlob *binary = NULL;
std::string debugInfo; std::string debugInfo;
ANGLE_TRY(mCompiler.compileToBinary(infoLog, shaderHLSL, profile, configs, loopMacros, &binary, ANGLE_TRY(mCompiler.compileToBinary(infoLog, shaderHLSL, profile, configs, loopMacros, &binary,
&debugInfo)); &debugInfo));
// It's possible that binary is NULL if the compiler failed in all configurations. Set the executable to NULL // It's possible that binary is NULL if the compiler failed in all configurations. Set the
// and return GL_NO_ERROR to signify that there was a link error but the internal state is still OK. // executable to NULL and return GL_NO_ERROR to signify that there was a link error but the
// internal state is still OK.
if (!binary) if (!binary)
{ {
*outExectuable = NULL; *outExectuable = NULL;
...@@ -3493,11 +3602,16 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const ...@@ -3493,11 +3602,16 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const
return true; return true;
} }
gl::Error Renderer11::fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTargetD3D *destRenderTarget, gl::Error Renderer11::fastCopyBufferToTexture(const gl::PixelUnpackState &unpack,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea) unsigned int offset,
RenderTargetD3D *destRenderTarget,
GLenum destinationFormat,
GLenum sourcePixelsType,
const gl::Box &destArea)
{ {
ASSERT(supportsFastCopyBufferToTexture(destinationFormat)); ASSERT(supportsFastCopyBufferToTexture(destinationFormat));
return mPixelTransfer->copyBufferToTexture(unpack, offset, destRenderTarget, destinationFormat, sourcePixelsType, destArea); return mPixelTransfer->copyBufferToTexture(unpack, offset, destRenderTarget, destinationFormat,
sourcePixelsType, destArea);
} }
ImageD3D *Renderer11::createImage() ImageD3D *Renderer11::createImage()
...@@ -3548,24 +3662,47 @@ TextureStorage *Renderer11::createTextureStorageExternal( ...@@ -3548,24 +3662,47 @@ TextureStorage *Renderer11::createTextureStorageExternal(
return new TextureStorage11_External(this, stream, desc); return new TextureStorage11_External(this, stream, desc);
} }
TextureStorage *Renderer11::createTextureStorage2D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels, bool hintLevelZeroOnly) TextureStorage *Renderer11::createTextureStorage2D(GLenum internalformat,
bool renderTarget,
GLsizei width,
GLsizei height,
int levels,
bool hintLevelZeroOnly)
{ {
return new TextureStorage11_2D(this, internalformat, renderTarget, width, height, levels, hintLevelZeroOnly); return new TextureStorage11_2D(this, internalformat, renderTarget, width, height, levels,
hintLevelZeroOnly);
} }
TextureStorage *Renderer11::createTextureStorageCube(GLenum internalformat, bool renderTarget, int size, int levels, bool hintLevelZeroOnly) TextureStorage *Renderer11::createTextureStorageCube(GLenum internalformat,
bool renderTarget,
int size,
int levels,
bool hintLevelZeroOnly)
{ {
return new TextureStorage11_Cube(this, internalformat, renderTarget, size, levels, hintLevelZeroOnly); return new TextureStorage11_Cube(this, internalformat, renderTarget, size, levels,
hintLevelZeroOnly);
} }
TextureStorage *Renderer11::createTextureStorage3D(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, GLsizei depth, int levels) TextureStorage *Renderer11::createTextureStorage3D(GLenum internalformat,
bool renderTarget,
GLsizei width,
GLsizei height,
GLsizei depth,
int levels)
{ {
return new TextureStorage11_3D(this, internalformat, renderTarget, width, height, depth, levels); return new TextureStorage11_3D(this, internalformat, renderTarget, width, height, depth,
levels);
} }
TextureStorage *Renderer11::createTextureStorage2DArray(GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, GLsizei depth, int levels) TextureStorage *Renderer11::createTextureStorage2DArray(GLenum internalformat,
bool renderTarget,
GLsizei width,
GLsizei height,
GLsizei depth,
int levels)
{ {
return new TextureStorage11_2DArray(this, internalformat, renderTarget, width, height, depth, levels); return new TextureStorage11_2DArray(this, internalformat, renderTarget, width, height, depth,
levels);
} }
gl::Error Renderer11::readFromAttachment(const gl::FramebufferAttachment &srcAttachment, gl::Error Renderer11::readFromAttachment(const gl::FramebufferAttachment &srcAttachment,
...@@ -3717,7 +3854,8 @@ gl::Error Renderer11::packPixels(const TextureHelper11 &textureHelper, ...@@ -3717,7 +3854,8 @@ gl::Error Renderer11::packPixels(const TextureHelper11 &textureHelper,
if (FAILED(hr)) if (FAILED(hr))
{ {
ASSERT(hr == E_OUTOFMEMORY); ASSERT(hr == E_OUTOFMEMORY);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal texture for reading, result: 0x%X.", hr); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to map internal texture for reading, result: 0x%X.", hr);
} }
uint8_t *source = static_cast<uint8_t *>(mapping.pData); uint8_t *source = static_cast<uint8_t *>(mapping.pData);
...@@ -3751,7 +3889,9 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn, ...@@ -3751,7 +3889,9 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn,
RenderTarget11 *drawRenderTarget11 = GetAs<RenderTarget11>(drawRenderTarget); RenderTarget11 *drawRenderTarget11 = GetAs<RenderTarget11>(drawRenderTarget);
if (!drawRenderTarget11) if (!drawRenderTarget11)
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the internal draw render target from the draw framebuffer."); return gl::Error(
GL_OUT_OF_MEMORY,
"Failed to retrieve the internal draw render target from the draw framebuffer.");
} }
TextureHelper11 drawTexture = TextureHelper11::MakeAndReference( TextureHelper11 drawTexture = TextureHelper11::MakeAndReference(
...@@ -3763,7 +3903,9 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn, ...@@ -3763,7 +3903,9 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn,
RenderTarget11 *readRenderTarget11 = GetAs<RenderTarget11>(readRenderTarget); RenderTarget11 *readRenderTarget11 = GetAs<RenderTarget11>(readRenderTarget);
if (!readRenderTarget11) if (!readRenderTarget11)
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to retrieve the internal read render target from the read framebuffer."); return gl::Error(
GL_OUT_OF_MEMORY,
"Failed to retrieve the internal read render target from the read framebuffer.");
} }
TextureHelper11 readTexture; TextureHelper11 readTexture;
...@@ -3825,8 +3967,7 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn, ...@@ -3825,8 +3967,7 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn,
// by internally scaling the read and draw rectangles. // by internally scaling the read and draw rectangles.
gl::Rectangle readRect = readRectIn; gl::Rectangle readRect = readRectIn;
gl::Rectangle drawRect = drawRectIn; gl::Rectangle drawRect = drawRectIn;
auto readToDrawX = [&drawRectIn, &readRectIn](int readOffset) auto readToDrawX = [&drawRectIn, &readRectIn](int readOffset) {
{
double readToDrawScale = double readToDrawScale =
static_cast<double>(drawRectIn.width) / static_cast<double>(readRectIn.width); static_cast<double>(drawRectIn.width) / static_cast<double>(readRectIn.width);
return static_cast<int>(round(static_cast<double>(readOffset) * readToDrawScale)); return static_cast<int>(round(static_cast<double>(readOffset) * readToDrawScale));
...@@ -3842,8 +3983,7 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn, ...@@ -3842,8 +3983,7 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn,
drawRect.width -= drawOffset; drawRect.width -= drawOffset;
} }
auto readToDrawY = [&drawRectIn, &readRectIn](int readOffset) auto readToDrawY = [&drawRectIn, &readRectIn](int readOffset) {
{
double readToDrawScale = double readToDrawScale =
static_cast<double>(drawRectIn.height) / static_cast<double>(readRectIn.height); static_cast<double>(drawRectIn.height) / static_cast<double>(readRectIn.height);
return static_cast<int>(round(static_cast<double>(readOffset) * readToDrawScale)); return static_cast<int>(round(static_cast<double>(readOffset) * readToDrawScale));
...@@ -3909,7 +4049,8 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn, ...@@ -3909,7 +4049,8 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn,
bool stretchRequired = readRect.width != drawRect.width || readRect.height != drawRect.height; bool stretchRequired = readRect.width != drawRect.width || readRect.height != drawRect.height;
bool flipRequired = readRect.width < 0 || readRect.height < 0 || drawRect.width < 0 || drawRect.height < 0; bool flipRequired =
readRect.width < 0 || readRect.height < 0 || drawRect.width < 0 || drawRect.height < 0;
bool outOfBounds = readRect.x < 0 || readRect.x + readRect.width > readSize.width || bool outOfBounds = readRect.x < 0 || readRect.x + readRect.width > readSize.width ||
readRect.y < 0 || readRect.y + readRect.height > readSize.height || readRect.y < 0 || readRect.y + readRect.height > readSize.height ||
...@@ -3937,7 +4078,8 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn, ...@@ -3937,7 +4078,8 @@ gl::Error Renderer11::blitRenderbufferRect(const gl::Rectangle &readRectIn,
if (scissorNeeded) if (scissorNeeded)
{ {
// drawRect is guaranteed to have positive width and height because stretchRequired is false. // drawRect is guaranteed to have positive width and height because stretchRequired is
// false.
ASSERT(drawRect.width >= 0 || drawRect.height >= 0); ASSERT(drawRect.width >= 0 || drawRect.height >= 0);
if (drawRect.x < scissor->x) if (drawRect.x < scissor->x)
...@@ -4115,9 +4257,11 @@ bool Renderer11::getLUID(LUID *adapterLuid) const ...@@ -4115,9 +4257,11 @@ bool Renderer11::getLUID(LUID *adapterLuid) const
return true; return true;
} }
VertexConversionType Renderer11::getVertexConversionType(gl::VertexFormatType vertexFormatType) const VertexConversionType Renderer11::getVertexConversionType(
gl::VertexFormatType vertexFormatType) const
{ {
return d3d11::GetVertexFormatInfo(vertexFormatType, mRenderer11DeviceCaps.featureLevel).conversionType; return d3d11::GetVertexFormatInfo(vertexFormatType, mRenderer11DeviceCaps.featureLevel)
.conversionType;
} }
GLenum Renderer11::getVertexComponentType(gl::VertexFormatType vertexFormatType) const GLenum Renderer11::getVertexComponentType(gl::VertexFormatType vertexFormatType) const
...@@ -4163,8 +4307,10 @@ gl::ErrorOrResult<unsigned int> Renderer11::getVertexSpaceRequired( ...@@ -4163,8 +4307,10 @@ gl::ErrorOrResult<unsigned int> Renderer11::getVertexSpaceRequired(
return elementSize * elementCount; return elementSize * elementCount;
} }
void Renderer11::generateCaps(gl::Caps *outCaps, gl::TextureCapsMap *outTextureCaps, void Renderer11::generateCaps(gl::Caps *outCaps,
gl::Extensions *outExtensions, gl::Limitations *outLimitations) const gl::TextureCapsMap *outTextureCaps,
gl::Extensions *outExtensions,
gl::Limitations *outLimitations) const
{ {
d3d11_gl::GenerateCaps(mDevice, mDeviceContext, mRenderer11DeviceCaps, outCaps, outTextureCaps, d3d11_gl::GenerateCaps(mDevice, mDeviceContext, mRenderer11DeviceCaps, outCaps, outTextureCaps,
outExtensions, outLimitations); outExtensions, outLimitations);
......
...@@ -41,7 +41,7 @@ gl::Error VertexBuffer11::initialize(unsigned int size, bool dynamicUsage) ...@@ -41,7 +41,7 @@ gl::Error VertexBuffer11::initialize(unsigned int size, bool dynamicUsage)
if (size > 0) if (size > 0)
{ {
ID3D11Device* dxDevice = mRenderer->getDevice(); ID3D11Device *dxDevice = mRenderer->getDevice();
D3D11_BUFFER_DESC bufferDesc; D3D11_BUFFER_DESC bufferDesc;
bufferDesc.ByteWidth = size; bufferDesc.ByteWidth = size;
...@@ -54,7 +54,8 @@ gl::Error VertexBuffer11::initialize(unsigned int size, bool dynamicUsage) ...@@ -54,7 +54,8 @@ gl::Error VertexBuffer11::initialize(unsigned int size, bool dynamicUsage)
HRESULT result = dxDevice->CreateBuffer(&bufferDesc, NULL, &mBuffer); HRESULT result = dxDevice->CreateBuffer(&bufferDesc, NULL, &mBuffer);
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to allocate internal vertex buffer of size, %lu.", size); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to allocate internal vertex buffer of size, %lu.", size);
} }
if (dynamicUsage) if (dynamicUsage)
...@@ -81,13 +82,15 @@ gl::Error VertexBuffer11::mapResource() ...@@ -81,13 +82,15 @@ gl::Error VertexBuffer11::mapResource()
D3D11_MAPPED_SUBRESOURCE mappedResource; D3D11_MAPPED_SUBRESOURCE mappedResource;
HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource); HRESULT result =
dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_NO_OVERWRITE, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal vertex buffer, HRESULT: 0x%08x.", result); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to map internal vertex buffer, HRESULT: 0x%08x.", result);
} }
mMappedResourceData = reinterpret_cast<uint8_t*>(mappedResource.pData); mMappedResourceData = reinterpret_cast<uint8_t *>(mappedResource.pData);
} }
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
...@@ -133,7 +136,8 @@ gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attri ...@@ -133,7 +136,8 @@ gl::Error VertexBuffer11::storeVertexAttributes(const gl::VertexAttribute &attri
gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib, currentValueType); gl::VertexFormatType vertexFormatType = gl::GetVertexFormatType(attrib, currentValueType);
const D3D_FEATURE_LEVEL featureLevel = mRenderer->getRenderer11DeviceCaps().featureLevel; const D3D_FEATURE_LEVEL featureLevel = mRenderer->getRenderer11DeviceCaps().featureLevel;
const d3d11::VertexFormat &vertexFormatInfo = d3d11::GetVertexFormatInfo(vertexFormatType, featureLevel); const d3d11::VertexFormat &vertexFormatInfo =
d3d11::GetVertexFormatInfo(vertexFormatType, featureLevel);
ASSERT(vertexFormatInfo.copyFunction != NULL); ASSERT(vertexFormatInfo.copyFunction != NULL);
vertexFormatInfo.copyFunction(input, inputStride, count, output); vertexFormatInfo.copyFunction(input, inputStride, count, output);
...@@ -170,7 +174,8 @@ gl::Error VertexBuffer11::discard() ...@@ -170,7 +174,8 @@ gl::Error VertexBuffer11::discard()
HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource); HRESULT result = dxContext->Map(mBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result)) if (FAILED(result))
{ {
return gl::Error(GL_OUT_OF_MEMORY, "Failed to map internal buffer for discarding, HRESULT: 0x%08x", result); return gl::Error(GL_OUT_OF_MEMORY,
"Failed to map internal buffer for discarding, HRESULT: 0x%08x", result);
} }
dxContext->Unmap(mBuffer, 0); dxContext->Unmap(mBuffer, 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