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