Commit 47c0e048 by Jamie Madill Committed by Commit Bot

Use ComPtr references for D3D objects.

This is an work-in-progress CL to prototype using ComPtr. It also has a new design for internal errors that doesn't use FormatString, preferring a stream-based approach. One thing to be aware of is that the address operator does not behave as expected with ComPtr - we should use ::AddressOf. BUG=angleproject:530 BUG=angleproject:1644 Change-Id: If5643e9e5726fd9aa5cbd422fca12ae169eb5b1f Reviewed-on: https://chromium-review.googlesource.com/415027 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org>
parent 08d4aa93
......@@ -23,6 +23,10 @@
namespace angle
{
#if defined(ANBLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
using Microsoft::WRL::ComPtr;
#endif // defined(ANBLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
class NonCopyable
{
public:
......
......@@ -65,6 +65,10 @@
# include <d3dcompiler.h>
# endif
#if defined(ANBLE_ENABLE_D3D9) || defined(ANGLE_ENABLE_D3D11)
#include <wrl.h>
#endif
# if defined(ANGLE_ENABLE_WINDOWS_STORE)
# include <dxgi1_3.h>
# if defined(_DEBUG)
......
......@@ -16,6 +16,11 @@
namespace gl
{
Error::Error(GLenum errorCode, std::string &&message)
: mCode(errorCode), mID(errorCode), mMessage(new std::string(std::move(message)))
{
}
Error::Error(GLenum errorCode, const char *msg, ...) : mCode(errorCode), mID(errorCode)
{
va_list vararg;
......@@ -64,8 +69,27 @@ bool Error::operator!=(const Error &other) const
{
return !(*this == other);
}
namespace priv
{
template <GLenum EnumT>
ErrorStream<EnumT>::ErrorStream()
{
}
template <GLenum EnumT>
ErrorStream<EnumT>::operator gl::Error()
{
return Error(EnumT, mErrorStream.str().c_str());
}
template class ErrorStream<GL_OUT_OF_MEMORY>;
template class ErrorStream<GL_INVALID_OPERATION>;
} // namespace priv
} // namespace gl
namespace egl
{
......
......@@ -10,6 +10,7 @@
#define LIBANGLE_ERROR_H_
#include "angle_gl.h"
#include "common/angleutils.h"
#include <EGL/egl.h>
#include <string>
......@@ -18,10 +19,14 @@
namespace gl
{
template <typename T>
class ErrorOrResult;
class Error final
{
public:
explicit inline Error(GLenum errorCode);
Error(GLenum errorCode, std::string &&msg);
Error(GLenum errorCode, const char *msg, ...);
Error(GLenum errorCode, GLuint id, const char *msg, ...);
inline Error(const Error &other);
......@@ -48,6 +53,63 @@ class Error final
mutable std::unique_ptr<std::string> mMessage;
};
namespace priv
{
template <GLenum EnumT>
class ErrorStream : angle::NonCopyable
{
public:
ErrorStream();
template <typename T>
ErrorStream &operator<<(T value);
operator Error();
template <typename T>
operator ErrorOrResult<T>()
{
return static_cast<Error>(*this);
}
private:
std::ostringstream mErrorStream;
};
// These convience methods for HRESULTS (really long) are used all over the place in the D3D
// back-ends.
#if defined(ANGLE_PLATFORM_WINDOWS)
template <>
template <>
inline ErrorStream<GL_OUT_OF_MEMORY> &ErrorStream<GL_OUT_OF_MEMORY>::operator<<(HRESULT hresult)
{
mErrorStream << "HRESULT: 0x" << std::ios::hex << hresult;
return *this;
}
template <>
template <>
inline ErrorStream<GL_INVALID_OPERATION> &ErrorStream<GL_INVALID_OPERATION>::operator<<(
HRESULT hresult)
{
mErrorStream << "HRESULT: 0x" << std::ios::hex << hresult;
return *this;
}
#endif // defined(ANGLE_PLATFORM_WINDOWS)
template <GLenum EnumT>
template <typename T>
ErrorStream<EnumT> &ErrorStream<EnumT>::operator<<(T value)
{
mErrorStream << value;
return *this;
}
} // namespace priv
using OutOfMemory = priv::ErrorStream<GL_OUT_OF_MEMORY>;
using InternalError = priv::ErrorStream<GL_INVALID_OPERATION>;
template <typename T>
class ErrorOrResult
{
......
......@@ -589,8 +589,6 @@ Blit11::Blit11(Renderer11 *renderer)
Blit11::~Blit11()
{
freeResources();
mQuad2DIL.release();
mQuad2DVS.release();
mDepthPS.release();
......@@ -607,7 +605,7 @@ gl::Error Blit11::initResources()
{
if (mResourcesInitialized)
{
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
TRACE_EVENT0("gpu.angle", "Blit11::initResources");
......@@ -626,13 +624,11 @@ gl::Error Blit11::initResources()
vbDesc.MiscFlags = 0;
vbDesc.StructureByteStride = 0;
result = device->CreateBuffer(&vbDesc, nullptr, &mVertexBuffer);
result = device->CreateBuffer(&vbDesc, nullptr, mVertexBuffer.GetAddressOf());
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
freeResources();
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create blit vertex buffer, HRESULT: 0x%X",
result);
return gl::OutOfMemory() << "Failed to create blit vertex buffer, " << result;
}
d3d11::SetDebugName(mVertexBuffer, "Blit11 vertex buffer");
......@@ -651,13 +647,11 @@ gl::Error Blit11::initResources()
pointSamplerDesc.MinLOD = 0.0f;
pointSamplerDesc.MaxLOD = FLT_MAX;
result = device->CreateSamplerState(&pointSamplerDesc, &mPointSampler);
result = device->CreateSamplerState(&pointSamplerDesc, mPointSampler.GetAddressOf());
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
freeResources();
return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create blit point sampler state, HRESULT: 0x%X", result);
return gl::OutOfMemory() << "Failed to create blit point sampler state, " << result;
}
d3d11::SetDebugName(mPointSampler, "Blit11 point sampler");
......@@ -676,13 +670,11 @@ gl::Error Blit11::initResources()
linearSamplerDesc.MinLOD = 0.0f;
linearSamplerDesc.MaxLOD = FLT_MAX;
result = device->CreateSamplerState(&linearSamplerDesc, &mLinearSampler);
result = device->CreateSamplerState(&linearSamplerDesc, mLinearSampler.GetAddressOf());
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
freeResources();
return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create blit linear sampler state, HRESULT: 0x%X", result);
return gl::OutOfMemory() << "Failed to create blit linear sampler state, " << result;
}
d3d11::SetDebugName(mLinearSampler, "Blit11 linear sampler");
......@@ -699,26 +691,23 @@ gl::Error Blit11::initResources()
rasterDesc.AntialiasedLineEnable = FALSE;
rasterDesc.ScissorEnable = TRUE;
result = device->CreateRasterizerState(&rasterDesc, &mScissorEnabledRasterizerState);
result =
device->CreateRasterizerState(&rasterDesc, mScissorEnabledRasterizerState.GetAddressOf());
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
freeResources();
return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create blit scissoring rasterizer state, HRESULT: 0x%X",
result);
return gl::OutOfMemory() << "Failed to create blit scissoring rasterizer state, " << result;
}
d3d11::SetDebugName(mScissorEnabledRasterizerState, "Blit11 scissoring rasterizer state");
rasterDesc.ScissorEnable = FALSE;
result = device->CreateRasterizerState(&rasterDesc, &mScissorDisabledRasterizerState);
result =
device->CreateRasterizerState(&rasterDesc, mScissorDisabledRasterizerState.GetAddressOf());
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
freeResources();
return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create blit no scissoring rasterizer state, HRESULT: 0x%X",
result);
return gl::OutOfMemory() << "Failed to create blit no scissoring rasterizer state, "
<< result;
}
d3d11::SetDebugName(mScissorDisabledRasterizerState, "Blit11 no scissoring rasterizer state");
......@@ -738,13 +727,11 @@ gl::Error Blit11::initResources()
depthStencilDesc.BackFace.StencilPassOp = D3D11_STENCIL_OP_KEEP;
depthStencilDesc.BackFace.StencilFunc = D3D11_COMPARISON_ALWAYS;
result = device->CreateDepthStencilState(&depthStencilDesc, &mDepthStencilState);
result = device->CreateDepthStencilState(&depthStencilDesc, mDepthStencilState.GetAddressOf());
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
freeResources();
return gl::Error(GL_OUT_OF_MEMORY,
"Failed to create blit depth stencil state, HRESULT: 0x%X", result);
return gl::OutOfMemory() << "Failed to create blit depth stencil state, " << result;
}
d3d11::SetDebugName(mDepthStencilState, "Blit11 depth stencil state");
......@@ -756,32 +743,17 @@ gl::Error Blit11::initResources()
swizzleBufferDesc.MiscFlags = 0;
swizzleBufferDesc.StructureByteStride = 0;
result = device->CreateBuffer(&swizzleBufferDesc, nullptr, &mSwizzleCB);
result = device->CreateBuffer(&swizzleBufferDesc, nullptr, mSwizzleCB.GetAddressOf());
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
freeResources();
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create blit swizzle buffer, HRESULT: 0x%X",
result);
return gl::OutOfMemory() << "Failed to create blit swizzle buffer, " << result;
}
d3d11::SetDebugName(mSwizzleCB, "Blit11 swizzle constant buffer");
mResourcesInitialized = true;
return gl::Error(GL_NO_ERROR);
}
void Blit11::freeResources()
{
SafeRelease(mVertexBuffer);
SafeRelease(mPointSampler);
SafeRelease(mLinearSampler);
SafeRelease(mScissorEnabledRasterizerState);
SafeRelease(mScissorDisabledRasterizerState);
SafeRelease(mDepthStencilState);
SafeRelease(mSwizzleCB);
mResourcesInitialized = false;
return gl::NoError();
}
// static
......@@ -1064,12 +1036,11 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source,
// Set vertices
D3D11_MAPPED_SUBRESOURCE mappedResource;
result = deviceContext->Map(mVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
result =
deviceContext->Map(mVertexBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY,
"Failed to map internal vertex buffer for swizzle, HRESULT: 0x%X.",
result);
return gl::OutOfMemory() << "Failed to map internal vertex buffer for swizzle, " << result;
}
const ShaderSupport &support = getShaderSupport(*shader);
......@@ -1083,15 +1054,14 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source,
support.vertexWriteFunction(area, size, area, size, mappedResource.pData, &stride, &drawCount,
&topology);
deviceContext->Unmap(mVertexBuffer, 0);
deviceContext->Unmap(mVertexBuffer.Get(), 0);
// Set constant buffer
result = deviceContext->Map(mSwizzleCB, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
result = deviceContext->Map(mSwizzleCB.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY,
"Failed to map internal constant buffer for swizzle, HRESULT: 0x%X.",
result);
return gl::OutOfMemory() << "Failed to map internal constant buffer for swizzle, "
<< result;
}
unsigned int *swizzleIndices = reinterpret_cast<unsigned int *>(mappedResource.pData);
......@@ -1100,18 +1070,18 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source,
swizzleIndices[2] = GetSwizzleIndex(swizzleTarget.swizzleBlue);
swizzleIndices[3] = GetSwizzleIndex(swizzleTarget.swizzleAlpha);
deviceContext->Unmap(mSwizzleCB, 0);
deviceContext->Unmap(mSwizzleCB.Get(), 0);
// Apply vertex buffer
deviceContext->IASetVertexBuffers(0, 1, &mVertexBuffer, &stride, &startIdx);
deviceContext->IASetVertexBuffers(0, 1, mVertexBuffer.GetAddressOf(), &stride, &startIdx);
// Apply constant buffer
deviceContext->PSSetConstantBuffers(0, 1, &mSwizzleCB);
deviceContext->PSSetConstantBuffers(0, 1, mSwizzleCB.GetAddressOf());
// Apply state
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
deviceContext->OMSetDepthStencilState(nullptr, 0xFFFFFFFF);
deviceContext->RSSetState(mScissorDisabledRasterizerState);
deviceContext->RSSetState(mScissorDisabledRasterizerState.Get());
// Apply shaders
deviceContext->IASetInputLayout(support.inputLayout);
......@@ -1142,7 +1112,7 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source,
stateManager->setShaderResource(gl::SAMPLER_PIXEL, 0, source);
// Apply samplers
deviceContext->PSSetSamplers(0, 1, &mPointSampler);
deviceContext->PSSetSamplers(0, 1, mPointSampler.GetAddressOf());
// Draw the quad
deviceContext->Draw(drawCount, 0);
......@@ -1156,7 +1126,7 @@ gl::Error Blit11::swizzleTexture(ID3D11ShaderResourceView *source,
mRenderer->markAllStateDirty();
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source,
......@@ -1199,12 +1169,12 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source,
// Set vertices
D3D11_MAPPED_SUBRESOURCE mappedResource;
result = deviceContext->Map(mVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
result =
deviceContext->Map(mVertexBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY,
"Failed to map internal vertex buffer for texture copy, HRESULT: 0x%X.",
result);
return gl::OutOfMemory() << "Failed to map internal vertex buffer for texture copy, "
<< result;
}
UINT stride = 0;
......@@ -1215,10 +1185,10 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source,
support.vertexWriteFunction(sourceArea, sourceSize, destArea, destSize, mappedResource.pData,
&stride, &drawCount, &topology);
deviceContext->Unmap(mVertexBuffer, 0);
deviceContext->Unmap(mVertexBuffer.Get(), 0);
// Apply vertex buffer
deviceContext->IASetVertexBuffers(0, 1, &mVertexBuffer, &stride, &startIdx);
deviceContext->IASetVertexBuffers(0, 1, mVertexBuffer.GetAddressOf(), &stride, &startIdx);
// Apply state
if (maskOffAlpha)
......@@ -1242,11 +1212,11 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source,
scissorRect.bottom = scissor->y + scissor->height;
deviceContext->RSSetScissorRects(1, &scissorRect);
deviceContext->RSSetState(mScissorEnabledRasterizerState);
deviceContext->RSSetState(mScissorEnabledRasterizerState.Get());
}
else
{
deviceContext->RSSetState(mScissorDisabledRasterizerState);
deviceContext->RSSetState(mScissorDisabledRasterizerState.Get());
}
// Apply shaders
......@@ -1282,15 +1252,15 @@ gl::Error Blit11::copyTexture(ID3D11ShaderResourceView *source,
switch (filter)
{
case GL_NEAREST:
sampler = mPointSampler;
sampler = mPointSampler.Get();
break;
case GL_LINEAR:
sampler = mLinearSampler;
sampler = mLinearSampler.Get();
break;
default:
UNREACHABLE();
return gl::Error(GL_OUT_OF_MEMORY, "Internal error, unknown blit filter mode.");
return gl::InternalError() << "Internal error, unknown blit filter mode.";
}
deviceContext->PSSetSamplers(0, 1, &sampler);
......@@ -1338,12 +1308,12 @@ gl::Error Blit11::copyDepth(ID3D11ShaderResourceView *source,
// Set vertices
D3D11_MAPPED_SUBRESOURCE mappedResource;
result = deviceContext->Map(mVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
result =
deviceContext->Map(mVertexBuffer.Get(), 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY,
"Failed to map internal vertex buffer for texture copy, HRESULT: 0x%X.",
result);
return gl::OutOfMemory() << "Failed to map internal vertex buffer for texture copy, "
<< result;
}
UINT stride = 0;
......@@ -1354,14 +1324,14 @@ gl::Error Blit11::copyDepth(ID3D11ShaderResourceView *source,
Write2DVertices(sourceArea, sourceSize, destArea, destSize, mappedResource.pData, &stride,
&drawCount, &topology);
deviceContext->Unmap(mVertexBuffer, 0);
deviceContext->Unmap(mVertexBuffer.Get(), 0);
// Apply vertex buffer
deviceContext->IASetVertexBuffers(0, 1, &mVertexBuffer, &stride, &startIdx);
deviceContext->IASetVertexBuffers(0, 1, mVertexBuffer.GetAddressOf(), &stride, &startIdx);
// Apply state
deviceContext->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
deviceContext->OMSetDepthStencilState(mDepthStencilState, 0xFFFFFFFF);
deviceContext->OMSetDepthStencilState(mDepthStencilState.Get(), 0xFFFFFFFF);
if (scissor)
{
......@@ -1372,18 +1342,18 @@ gl::Error Blit11::copyDepth(ID3D11ShaderResourceView *source,
scissorRect.bottom = scissor->y + scissor->height;
deviceContext->RSSetScissorRects(1, &scissorRect);
deviceContext->RSSetState(mScissorEnabledRasterizerState);
deviceContext->RSSetState(mScissorEnabledRasterizerState.Get());
}
else
{
deviceContext->RSSetState(mScissorDisabledRasterizerState);
deviceContext->RSSetState(mScissorDisabledRasterizerState.Get());
}
ID3D11Device *device = mRenderer->getDevice();
ID3D11VertexShader *quad2DVS = mQuad2DVS.resolve(device);
if (quad2DVS == nullptr)
{
return gl::Error(GL_INVALID_OPERATION, "Error compiling internal 2D blit vertex shader");
return gl::InternalError() << "Error compiling internal 2D blit vertex shader";
}
// Apply shaders
......@@ -1415,7 +1385,7 @@ gl::Error Blit11::copyDepth(ID3D11ShaderResourceView *source,
stateManager->setShaderResource(gl::SAMPLER_PIXEL, 0, source);
// Apply samplers
deviceContext->PSSetSamplers(0, 1, &mPointSampler);
deviceContext->PSSetSamplers(0, 1, mPointSampler.GetAddressOf());
// Draw the quad
deviceContext->Draw(drawCount, 0);
......@@ -1429,7 +1399,7 @@ gl::Error Blit11::copyDepth(ID3D11ShaderResourceView *source,
mRenderer->markAllStateDirty();
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
gl::Error Blit11::copyDepthStencil(const TextureHelper11 &source,
......@@ -1539,10 +1509,9 @@ gl::Error Blit11::copyAndConvertImpl(const TextureHelper11 &source,
deviceContext->Map(sourceStaging.getResource(), 0, D3D11_MAP_READ, 0, &sourceMapping);
if (FAILED(result))
{
return gl::Error(
GL_OUT_OF_MEMORY,
"Failed to map internal source staging texture for depth stencil blit, HRESULT: 0x%X.",
result);
return gl::OutOfMemory()
<< "Failed to map internal source staging texture for depth stencil blit, "
<< result;
}
D3D11_MAPPED_SUBRESOURCE destMapping;
......@@ -1550,10 +1519,9 @@ gl::Error Blit11::copyAndConvertImpl(const TextureHelper11 &source,
if (FAILED(result))
{
deviceContext->Unmap(sourceStaging.getResource(), 0);
return gl::Error(GL_OUT_OF_MEMORY,
"Failed to map internal destination staging texture for depth stencil "
"blit, HRESULT: 0x%X.",
result);
return gl::OutOfMemory()
<< "Failed to map internal destination staging texture for depth stencil blit, "
<< result;
}
// Clip dest area to the destination size
......@@ -1685,14 +1653,14 @@ gl::Error Blit11::getBlitShader(GLenum destFormat,
if (blitShaderType == BLITSHADER_INVALID)
{
return gl::Error(GL_INVALID_OPERATION, "Internal blit shader type mismatch");
return gl::InternalError() << "Internal blit shader type mismatch";
}
auto blitShaderIt = mBlitShaderMap.find(blitShaderType);
if (blitShaderIt != mBlitShaderMap.end())
{
*shader = &blitShaderIt->second;
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
ASSERT(dimension == SHADER_2D || mRenderer->isES3Capable());
......@@ -1893,13 +1861,13 @@ gl::Error Blit11::getBlitShader(GLenum destFormat,
break;
default:
UNREACHABLE();
return gl::Error(GL_INVALID_OPERATION, "Internal error");
return gl::InternalError() << "Internal error";
}
blitShaderIt = mBlitShaderMap.find(blitShaderType);
ASSERT(blitShaderIt != mBlitShaderMap.end());
*shader = &blitShaderIt->second;
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
gl::Error Blit11::getSwizzleShader(GLenum type,
......@@ -1910,14 +1878,14 @@ gl::Error Blit11::getSwizzleShader(GLenum type,
if (swizzleShaderType == SWIZZLESHADER_INVALID)
{
return gl::Error(GL_INVALID_OPERATION, "Swizzle shader type not found");
return gl::InternalError() << "Swizzle shader type not found";
}
auto swizzleShaderIt = mSwizzleShaderMap.find(swizzleShaderType);
if (swizzleShaderIt != mSwizzleShaderMap.end())
{
*shader = &swizzleShaderIt->second;
return gl::Error(GL_NO_ERROR);
return gl::NoError();
}
// Swizzling shaders (OpenGL ES 3+)
......@@ -1989,7 +1957,7 @@ gl::Error Blit11::getSwizzleShader(GLenum type,
break;
default:
UNREACHABLE();
return gl::Error(GL_INVALID_OPERATION, "Internal error");
return gl::InternalError() << "Internal error";
}
swizzleShaderIt = mSwizzleShaderMap.find(swizzleShaderType);
......@@ -2003,9 +1971,8 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveDepth(RenderTarget11 *depth)
// Multisampled depth stencil SRVs are not available in feature level 10.0
if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_10_0)
{
return gl::Error(GL_INVALID_OPERATION,
"Resolving multisampled depth stencil textures is not supported in "
"feature level 10.0.");
return gl::InternalError() << "Resolving multisampled depth stencil textures is not "
"supported in feature level 10.0.";
}
const auto &extents = depth->getExtents();
......@@ -2024,7 +1991,7 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveDepth(RenderTarget11 *depth)
context->GSSetShader(nullptr, nullptr, 0);
context->RSSetState(nullptr);
context->OMSetDepthStencilState(nullptr, 0xFFFFFFFF);
context->OMSetRenderTargets(1, &mResolvedDepthStencilRTView, nullptr);
context->OMSetRenderTargets(1, mResolvedDepthStencilRTView.GetAddressOf(), nullptr);
context->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
// Set the viewport
......@@ -2070,7 +2037,7 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveDepth(RenderTarget11 *depth)
HRESULT hr = device->CreateTexture2D(&destDesc, nullptr, &destTex);
if (FAILED(hr))
{
return gl::Error(GL_OUT_OF_MEMORY, "Error creating depth resolve dest texture.");
return gl::OutOfMemory() << "Error creating depth resolve dest texture, " << hr;
}
d3d11::SetDebugName(destTex, "resolveDepthDest");
......@@ -2114,17 +2081,17 @@ gl::Error Blit11::initResolveDepthStencil(const gl::Extents &extents)
HRESULT hr = device->CreateTexture2D(&textureDesc, nullptr, &resolvedDepthStencil);
if (FAILED(hr))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to allocate resolved depth stencil texture");
return gl::OutOfMemory() << "Failed to allocate resolved depth stencil texture, " << hr;
}
d3d11::SetDebugName(resolvedDepthStencil, "Blit11::mResolvedDepthStencil");
ASSERT(mResolvedDepthStencilRTView == nullptr);
hr =
device->CreateRenderTargetView(resolvedDepthStencil, nullptr, &mResolvedDepthStencilRTView);
hr = device->CreateRenderTargetView(resolvedDepthStencil, nullptr,
mResolvedDepthStencilRTView.GetAddressOf());
if (FAILED(hr))
{
return gl::Error(GL_OUT_OF_MEMORY,
"Failed to allocate Blit11::mResolvedDepthStencilRTView");
return gl::OutOfMemory() << "Failed to allocate Blit11::mResolvedDepthStencilRTView, "
<< hr;
}
d3d11::SetDebugName(mResolvedDepthStencilRTView, "Blit11::mResolvedDepthStencilRTView");
......@@ -2139,9 +2106,8 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveStencil(RenderTarget11 *depthS
// Multisampled depth stencil SRVs are not available in feature level 10.0
if (mRenderer->getRenderer11DeviceCaps().featureLevel <= D3D_FEATURE_LEVEL_10_0)
{
return gl::Error(GL_INVALID_OPERATION,
"Resolving multisampled depth stencil textures is not supported in "
"feature level 10.0.");
return gl::InternalError() << "Resolving multisampled depth stencil textures is not "
"supported in feature level 10.0.";
}
const auto &extents = depthStencil->getExtents();
......@@ -2161,20 +2127,21 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveStencil(RenderTarget11 *depthS
if (stencilResource != priorResource)
{
SafeRelease(mStencilSRV);
mStencilSRV.Reset();
}
}
if (!mStencilSRV)
if (mStencilSRV == nullptr)
{
D3D11_SHADER_RESOURCE_VIEW_DESC srViewDesc;
srViewDesc.Format = GetStencilSRVFormat(depthStencil->getFormatSet());
srViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
HRESULT hr = device->CreateShaderResourceView(stencilResource, &srViewDesc, &mStencilSRV);
HRESULT hr = device->CreateShaderResourceView(stencilResource, &srViewDesc,
mStencilSRV.GetAddressOf());
if (FAILED(hr))
{
return gl::Error(GL_OUT_OF_MEMORY, "Error creating Blit11 stencil SRV");
return gl::OutOfMemory() << "Error creating Blit11 stencil SRV, " << hr;
}
d3d11::SetDebugName(mStencilSRV, "Blit11::mStencilSRV");
}
......@@ -2189,7 +2156,7 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveStencil(RenderTarget11 *depthS
context->GSSetShader(nullptr, nullptr, 0);
context->RSSetState(nullptr);
context->OMSetDepthStencilState(nullptr, 0xFFFFFFFF);
context->OMSetRenderTargets(1, &mResolvedDepthStencilRTView, nullptr);
context->OMSetRenderTargets(1, mResolvedDepthStencilRTView.GetAddressOf(), nullptr);
context->OMSetBlendState(nullptr, nullptr, 0xFFFFFFF);
// Set the viewport
......@@ -2203,7 +2170,7 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveStencil(RenderTarget11 *depthS
context->RSSetViewports(1, &viewport);
ID3D11ShaderResourceView *pixelViews[] = {
depthStencil->getShaderResourceView(), mStencilSRV,
depthStencil->getShaderResourceView(), mStencilSRV.Get(),
};
context->PSSetShaderResources(0, 2, pixelViews);
......@@ -2243,8 +2210,8 @@ gl::ErrorOrResult<TextureHelper11> Blit11::resolveStencil(RenderTarget11 *depthS
void Blit11::releaseResolveDepthStencilResources()
{
SafeRelease(mStencilSRV);
SafeRelease(mResolvedDepthStencilRTView);
mStencilSRV.Reset();
mResolvedDepthStencilRTView.Reset();
}
} // namespace rx
......@@ -181,7 +181,6 @@ class Blit11 : angle::NonCopyable
};
gl::Error initResources();
void freeResources();
ShaderSupport getShaderSupport(const Shader &shader);
......@@ -262,12 +261,12 @@ class Blit11 : angle::NonCopyable
std::map<SwizzleShaderType, Shader> mSwizzleShaderMap;
bool mResourcesInitialized;
ID3D11Buffer *mVertexBuffer;
ID3D11SamplerState *mPointSampler;
ID3D11SamplerState *mLinearSampler;
ID3D11RasterizerState *mScissorEnabledRasterizerState;
ID3D11RasterizerState *mScissorDisabledRasterizerState;
ID3D11DepthStencilState *mDepthStencilState;
angle::ComPtr<ID3D11Buffer> mVertexBuffer;
angle::ComPtr<ID3D11SamplerState> mPointSampler;
angle::ComPtr<ID3D11SamplerState> mLinearSampler;
angle::ComPtr<ID3D11RasterizerState> mScissorEnabledRasterizerState;
angle::ComPtr<ID3D11RasterizerState> mScissorDisabledRasterizerState;
angle::ComPtr<ID3D11DepthStencilState> mDepthStencilState;
d3d11::LazyInputLayout mQuad2DIL;
d3d11::LazyShader<ID3D11VertexShader> mQuad2DVS;
......@@ -279,15 +278,15 @@ class Blit11 : angle::NonCopyable
d3d11::LazyBlendState mAlphaMaskBlendState;
ID3D11Buffer *mSwizzleCB;
angle::ComPtr<ID3D11Buffer> mSwizzleCB;
d3d11::LazyShader<ID3D11VertexShader> mResolveDepthStencilVS;
d3d11::LazyShader<ID3D11PixelShader> mResolveDepthPS;
d3d11::LazyShader<ID3D11PixelShader> mResolveDepthStencilPS;
d3d11::LazyShader<ID3D11PixelShader> mResolveStencilPS;
ID3D11ShaderResourceView *mStencilSRV;
angle::ComPtr<ID3D11ShaderResourceView> mStencilSRV;
TextureHelper11 mResolvedDepthStencil;
ID3D11RenderTargetView *mResolvedDepthStencilRTView;
angle::ComPtr<ID3D11RenderTargetView> mResolvedDepthStencilRTView;
};
} // namespace rx
......
......@@ -13,9 +13,7 @@
#include "libANGLE/angletypes.h"
#include "libANGLE/Error.h"
#if !defined(ANGLE_ENABLE_WINDOWS_STORE)
typedef void* EventRegistrationToken;
#else
#if defined(ANGLE_ENABLE_WINDOWS_STORE)
#include <EventToken.h>
#endif
......
......@@ -135,6 +135,12 @@ void SetPositionDepthColorVertex(PositionDepthColorVertex<T>* vertex, float x, f
HRESULT SetDebugName(ID3D11DeviceChild *resource, const char *name);
template <typename T>
HRESULT SetDebugName(angle::ComPtr<T> &resource, const char *name)
{
return SetDebugName(resource.Get(), name);
}
template <typename outType>
outType* DynamicCastComObject(IUnknown* object)
{
......
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