Commit 306b6c16 by Jamie Madill Committed by Commit Bot

D3D11: Use angle::Result error pattern. 1/3

This CL improves performance on the draw call microbenchmark by 10% when no-oping driver calls. Bug: angleproject:2738 Change-Id: I4f5c11db90d9056ce4557b2a4432bc55b42b5bba Reviewed-on: https://chromium-review.googlesource.com/1150093 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarYuly Novikov <ynovikov@chromium.org>
parent c0b61500
...@@ -311,4 +311,10 @@ std::ostream &FmtHex(std::ostream &os, T value) ...@@ -311,4 +311,10 @@ std::ostream &FmtHex(std::ostream &os, T value)
ANGLE_EMPTY_STATEMENT ANGLE_EMPTY_STATEMENT
#endif // defined(ANGLE_TRACE_ENABLED) || defined(ANGLE_ENABLE_ASSERTS) #endif // defined(ANGLE_TRACE_ENABLED) || defined(ANGLE_ENABLE_ASSERTS)
#if defined(ANGLE_PLATFORM_WINDOWS)
#define ANGLE_FUNCTION __FUNCTION__
#else
#define ANGLE_FUNCTION __func__
#endif
#endif // COMMON_DEBUG_H_ #endif // COMMON_DEBUG_H_
...@@ -2545,7 +2545,7 @@ void Context::getProgramInterfaceivRobust(GLuint program, ...@@ -2545,7 +2545,7 @@ void Context::getProgramInterfaceivRobust(GLuint program,
UNIMPLEMENTED(); UNIMPLEMENTED();
} }
void Context::handleError(const Error &error) void Context::handleError(const Error &error) const
{ {
mErrors.handleError(error); mErrors.handleError(error);
} }
...@@ -7538,7 +7538,7 @@ ErrorSet::ErrorSet(Context *context) : mContext(context) ...@@ -7538,7 +7538,7 @@ ErrorSet::ErrorSet(Context *context) : mContext(context)
ErrorSet::~ErrorSet() = default; ErrorSet::~ErrorSet() = default;
void ErrorSet::handleError(const Error &error) void ErrorSet::handleError(const Error &error) const
{ {
// This internal enum is used to filter internal errors that are already handled. // This internal enum is used to filter internal errors that are already handled.
// TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491 // TODO(jmadill): Remove this when refactor is done. http://anglebug.com/2491
......
...@@ -69,13 +69,16 @@ class ErrorSet : angle::NonCopyable ...@@ -69,13 +69,16 @@ class ErrorSet : angle::NonCopyable
explicit ErrorSet(Context *context); explicit ErrorSet(Context *context);
~ErrorSet(); ~ErrorSet();
void handleError(const Error &error); // TODO(jmadill): Remove const. http://anglebug.com/2378
void handleError(const Error &error) const;
bool empty() const; bool empty() const;
GLenum popError(); GLenum popError();
private: private:
Context *mContext; Context *mContext;
std::set<GLenum> mErrors;
// TODO(jmadill): Remove mutable. http://anglebug.com/2378
mutable std::set<GLenum> mErrors;
}; };
class Context final : public egl::LabeledObject, angle::NonCopyable class Context final : public egl::LabeledObject, angle::NonCopyable
...@@ -1395,7 +1398,8 @@ class Context final : public egl::LabeledObject, angle::NonCopyable ...@@ -1395,7 +1398,8 @@ class Context final : public egl::LabeledObject, angle::NonCopyable
void framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level); void framebufferTexture(GLenum target, GLenum attachment, GLuint texture, GLint level);
// Consumes the error. // Consumes the error.
void handleError(const Error &error); // TODO(jmadill): Remove const. http://anglebug.com/2378
void handleError(const Error &error) const;
GLenum getError(); GLenum getError();
void markContextLost(); void markContextLost();
......
...@@ -236,6 +236,19 @@ inline Error NoError() ...@@ -236,6 +236,19 @@ inline Error NoError()
#define ANGLE_RETURN(X) return X; #define ANGLE_RETURN(X) return X;
#define ANGLE_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_RETURN); #define ANGLE_TRY(EXPR) ANGLE_TRY_TEMPLATE(EXPR, ANGLE_RETURN);
// TODO(jmadill): Remove this once refactor is complete. http://anglebug.com/2738
#define ANGLE_TRY_HANDLE(CONTEXT, EXPR) \
\
{ \
auto ANGLE_LOCAL_VAR = (EXPR); \
if (ANGLE_LOCAL_VAR.isError()) \
{ \
CONTEXT->handleError(ANGLE_LOCAL_VAR); \
return angle::Result::Stop(); \
} \
\
}
#define ANGLE_TRY_RESULT(EXPR, RESULT) \ #define ANGLE_TRY_RESULT(EXPR, RESULT) \
{ \ { \
auto ANGLE_LOCAL_VAR = EXPR; \ auto ANGLE_LOCAL_VAR = EXPR; \
...@@ -285,6 +298,10 @@ class ANGLE_NO_DISCARD Result ...@@ -285,6 +298,10 @@ class ANGLE_NO_DISCARD Result
return operator gl::Error(); return operator gl::Error();
} }
bool operator==(Result other) const { return mStop == other.mStop; }
bool operator!=(Result other) const { return mStop != other.mStop; }
private: private:
Result(bool stop) : mStop(stop) {} Result(bool stop) : mStop(stop) {}
bool mStop; bool mStop;
......
...@@ -73,6 +73,32 @@ enum RendererClass ...@@ -73,6 +73,32 @@ enum RendererClass
RENDERER_D3D9 RENDERER_D3D9
}; };
// ANGLE_TRY for HRESULT errors.
#define ANGLE_TRY_HR(CONTEXT, EXPR, MESSAGE) \
\
{ \
auto ANGLE_LOCAL_VAR = (EXPR); \
if (ANGLE_UNLIKELY(FAILED(ANGLE_LOCAL_VAR))) \
{ \
CONTEXT->handleError(ANGLE_LOCAL_VAR, MESSAGE, __FILE__, ANGLE_FUNCTION, __LINE__); \
return angle::Result::Stop(); \
} \
\
}
#define ANGLE_CHECK_HR(CONTEXT, EXPR, MESSAGE, ERROR) \
\
{ \
if (ANGLE_UNLIKELY(!(EXPR))) \
{ \
CONTEXT->handleError(ERROR, MESSAGE, __FILE__, ANGLE_FUNCTION, __LINE__); \
return angle::Result::Stop(); \
} \
}
#define ANGLE_CHECK_HR_ALLOC(context, result) \
ANGLE_CHECK_HR(context, result, "Failed to allocate host memory", E_OUTOFMEMORY)
// Check if the device is lost every 10 failures to get the query data // Check if the device is lost every 10 failures to get the query data
constexpr unsigned int kPollingD3DDeviceLostCheckFrequency = 10; constexpr unsigned int kPollingD3DDeviceLostCheckFrequency = 10;
......
...@@ -53,25 +53,27 @@ class Buffer11 : public BufferD3D ...@@ -53,25 +53,27 @@ class Buffer11 : public BufferD3D
Buffer11(const gl::BufferState &state, Renderer11 *renderer); Buffer11(const gl::BufferState &state, Renderer11 *renderer);
~Buffer11() override; ~Buffer11() override;
gl::Error getBuffer(const gl::Context *context, BufferUsage usage, ID3D11Buffer **bufferOut); angle::Result getBuffer(const gl::Context *context,
gl::Error getEmulatedIndexedBuffer(const gl::Context *context, BufferUsage usage,
SourceIndexData *indexInfo, ID3D11Buffer **bufferOut);
const TranslatedAttribute &attribute, angle::Result getEmulatedIndexedBuffer(const gl::Context *context,
GLint startVertex, SourceIndexData *indexInfo,
ID3D11Buffer **bufferOut); const TranslatedAttribute &attribute,
gl::Error getConstantBufferRange(const gl::Context *context, GLint startVertex,
GLintptr offset, ID3D11Buffer **bufferOut);
GLsizeiptr size, angle::Result getConstantBufferRange(const gl::Context *context,
const d3d11::Buffer **bufferOut, GLintptr offset,
UINT *firstConstantOut, GLsizeiptr size,
UINT *numConstantsOut); const d3d11::Buffer **bufferOut,
gl::Error getSRV(const gl::Context *context, UINT *firstConstantOut,
DXGI_FORMAT srvFormat, UINT *numConstantsOut);
const d3d11::ShaderResourceView **srvOut); angle::Result getSRV(const gl::Context *context,
DXGI_FORMAT srvFormat,
const d3d11::ShaderResourceView **srvOut);
bool isMapped() const { return mMappedStorage != nullptr; } bool isMapped() const { return mMappedStorage != nullptr; }
gl::Error packPixels(const gl::Context *context, angle::Result packPixels(const gl::Context *context,
const gl::FramebufferAttachment &readAttachment, const gl::FramebufferAttachment &readAttachment,
const PackPixelsParams &params); const PackPixelsParams &params);
size_t getTotalCPUBufferMemoryBytes() const; size_t getTotalCPUBufferMemoryBytes() const;
// BufferD3D implementation // BufferD3D implementation
...@@ -122,33 +124,34 @@ class Buffer11 : public BufferD3D ...@@ -122,33 +124,34 @@ class Buffer11 : public BufferD3D
}; };
void markBufferUsage(BufferUsage usage); void markBufferUsage(BufferUsage usage);
gl::Error garbageCollection(const gl::Context *context, BufferUsage currentUsage); angle::Result garbageCollection(const gl::Context *context, BufferUsage currentUsage);
gl::Error updateBufferStorage(const gl::Context *context, angle::Result updateBufferStorage(const gl::Context *context,
BufferStorage *storage, BufferStorage *storage,
size_t sourceOffset, size_t sourceOffset,
size_t storageSize); size_t storageSize);
template <typename StorageOutT> template <typename StorageOutT>
gl::Error getBufferStorage(const gl::Context *context, angle::Result getBufferStorage(const gl::Context *context,
BufferUsage usage, BufferUsage usage,
StorageOutT **storageOut); StorageOutT **storageOut);
template <typename StorageOutT> template <typename StorageOutT>
gl::Error getStagingStorage(const gl::Context *context, StorageOutT **storageOut); angle::Result getStagingStorage(const gl::Context *context, StorageOutT **storageOut);
gl::Error getLatestBufferStorage(const gl::Context *context, BufferStorage **storageOut) const; angle::Result getLatestBufferStorage(const gl::Context *context,
BufferStorage **storageOut) const;
gl::Error getConstantBufferRangeStorage(const gl::Context *context, angle::Result getConstantBufferRangeStorage(const gl::Context *context,
GLintptr offset, GLintptr offset,
GLsizeiptr size, GLsizeiptr size,
NativeStorage **storageOut); NativeStorage **storageOut);
BufferStorage *allocateStorage(BufferUsage usage); BufferStorage *allocateStorage(BufferUsage usage);
void updateDeallocThreshold(BufferUsage usage); void updateDeallocThreshold(BufferUsage usage);
// Free the storage if we decide it isn't being used very often. // Free the storage if we decide it isn't being used very often.
gl::Error checkForDeallocation(const gl::Context *context, BufferUsage usage); angle::Result checkForDeallocation(const gl::Context *context, BufferUsage usage);
// For some cases of uniform buffer storage, we can't deallocate system memory storage. // For some cases of uniform buffer storage, we can't deallocate system memory storage.
bool canDeallocateSystemMemory() const; bool canDeallocateSystemMemory() const;
......
...@@ -38,9 +38,9 @@ class Clear11 : angle::NonCopyable ...@@ -38,9 +38,9 @@ class Clear11 : angle::NonCopyable
~Clear11(); ~Clear11();
// Clears the framebuffer with the supplied clear parameters, assumes that the framebuffer is currently applied. // Clears the framebuffer with the supplied clear parameters, assumes that the framebuffer is currently applied.
gl::Error clearFramebuffer(const gl::Context *context, angle::Result clearFramebuffer(const gl::Context *context,
const ClearParameters &clearParams, const ClearParameters &clearParams,
const gl::FramebufferState &fboData); const gl::FramebufferState &fboData);
private: private:
class ShaderManager final : angle::NonCopyable class ShaderManager final : angle::NonCopyable
...@@ -48,14 +48,15 @@ class Clear11 : angle::NonCopyable ...@@ -48,14 +48,15 @@ class Clear11 : angle::NonCopyable
public: public:
ShaderManager(); ShaderManager();
~ShaderManager(); ~ShaderManager();
gl::Error getShadersAndLayout(Renderer11 *renderer, angle::Result getShadersAndLayout(const gl::Context *context,
const INT clearType, Renderer11 *renderer,
const uint32_t numRTs, const INT clearType,
const bool hasLayeredLayout, const uint32_t numRTs,
const d3d11::InputLayout **il, const bool hasLayeredLayout,
const d3d11::VertexShader **vs, const d3d11::InputLayout **il,
const d3d11::GeometryShader **gs, const d3d11::VertexShader **vs,
const d3d11::PixelShader **ps); const d3d11::GeometryShader **gs,
const d3d11::PixelShader **ps);
private: private:
constexpr static size_t kNumShaders = D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT; constexpr static size_t kNumShaders = D3D11_SIMULTANEOUS_RENDER_TARGET_COUNT;
...@@ -73,9 +74,9 @@ class Clear11 : angle::NonCopyable ...@@ -73,9 +74,9 @@ class Clear11 : angle::NonCopyable
}; };
bool useVertexBuffer() const; bool useVertexBuffer() const;
gl::Error ensureConstantBufferCreated(); angle::Result ensureConstantBufferCreated(const gl::Context *context);
gl::Error ensureVertexBufferCreated(); angle::Result ensureVertexBufferCreated(const gl::Context *context);
gl::Error ensureResourcesInitialized(); angle::Result ensureResourcesInitialized(const gl::Context *context);
Renderer11 *mRenderer; Renderer11 *mRenderer;
bool mResourcesInitialized; bool mResourcesInitialized;
......
...@@ -106,6 +106,16 @@ gl::Error ReadbackIndirectBuffer(const gl::Context *context, ...@@ -106,6 +106,16 @@ gl::Error ReadbackIndirectBuffer(const gl::Context *context,
return gl::NoError(); return gl::NoError();
} }
GLenum DefaultGLErrorCode(HRESULT hr)
{
switch (hr)
{
case E_OUTOFMEMORY:
return GL_OUT_OF_MEMORY;
default:
return GL_INVALID_OPERATION;
}
}
} // anonymous namespace } // anonymous namespace
Context11::Context11(const gl::ContextState &state, Renderer11 *renderer) Context11::Context11(const gl::ContextState &state, Renderer11 *renderer)
...@@ -485,8 +495,8 @@ gl::Error Context11::dispatchComputeIndirect(const gl::Context *context, GLintpt ...@@ -485,8 +495,8 @@ gl::Error Context11::dispatchComputeIndirect(const gl::Context *context, GLintpt
return gl::InternalError(); return gl::InternalError();
} }
gl::Error Context11::triggerDrawCallProgramRecompilation(const gl::Context *context, angle::Result Context11::triggerDrawCallProgramRecompilation(const gl::Context *context,
gl::PrimitiveMode drawMode) gl::PrimitiveMode drawMode)
{ {
const auto &glState = context->getGLState(); const auto &glState = context->getGLState();
const auto *va11 = GetImplAs<VertexArray11>(glState.getVertexArray()); const auto *va11 = GetImplAs<VertexArray11>(glState.getVertexArray());
...@@ -503,53 +513,50 @@ gl::Error Context11::triggerDrawCallProgramRecompilation(const gl::Context *cont ...@@ -503,53 +513,50 @@ gl::Error Context11::triggerDrawCallProgramRecompilation(const gl::Context *cont
if (!recompileVS && !recompileGS && !recompilePS) if (!recompileVS && !recompileGS && !recompilePS)
{ {
return gl::NoError(); return angle::Result::Continue();
} }
// Load the compiler if necessary and recompile the programs. // Load the compiler if necessary and recompile the programs.
ANGLE_TRY(mRenderer->ensureHLSLCompilerInitialized(context)); ANGLE_TRY_HANDLE(context, mRenderer->ensureHLSLCompilerInitialized(context));
gl::InfoLog infoLog; gl::InfoLog infoLog;
if (recompileVS) if (recompileVS)
{ {
ShaderExecutableD3D *vertexExe = nullptr; ShaderExecutableD3D *vertexExe = nullptr;
ANGLE_TRY( ANGLE_TRY_HANDLE(context, programD3D->getVertexExecutableForCachedInputLayout(
programD3D->getVertexExecutableForCachedInputLayout(context, &vertexExe, &infoLog)); context, &vertexExe, &infoLog));
if (!programD3D->hasVertexExecutableForCachedInputLayout()) if (!programD3D->hasVertexExecutableForCachedInputLayout())
{ {
ASSERT(infoLog.getLength() > 0); ASSERT(infoLog.getLength() > 0);
ERR() << "Dynamic recompilation error log: " << infoLog.str(); ERR() << "Error compiling dynamic vertex executable: " << infoLog.str();
return gl::InternalError() ANGLE_TRY_HR(this, E_FAIL, "Error compiling dynamic vertex executable");
<< "Error compiling dynamic vertex executable:" << infoLog.str();
} }
} }
if (recompileGS) if (recompileGS)
{ {
ShaderExecutableD3D *geometryExe = nullptr; ShaderExecutableD3D *geometryExe = nullptr;
ANGLE_TRY(programD3D->getGeometryExecutableForPrimitiveType(context, drawMode, &geometryExe, ANGLE_TRY_HANDLE(context, programD3D->getGeometryExecutableForPrimitiveType(
&infoLog)); context, drawMode, &geometryExe, &infoLog));
if (!programD3D->hasGeometryExecutableForPrimitiveType(drawMode)) if (!programD3D->hasGeometryExecutableForPrimitiveType(drawMode))
{ {
ASSERT(infoLog.getLength() > 0); ASSERT(infoLog.getLength() > 0);
ERR() << "Dynamic recompilation error log: " << infoLog.str(); ERR() << "Error compiling dynamic geometry executable: " << infoLog.str();
return gl::InternalError() ANGLE_TRY_HR(this, E_FAIL, "Error compiling dynamic geometry executable");
<< "Error compiling dynamic geometry executable:" << infoLog.str();
} }
} }
if (recompilePS) if (recompilePS)
{ {
ShaderExecutableD3D *pixelExe = nullptr; ShaderExecutableD3D *pixelExe = nullptr;
ANGLE_TRY( ANGLE_TRY_HANDLE(context, programD3D->getPixelExecutableForCachedOutputLayout(
programD3D->getPixelExecutableForCachedOutputLayout(context, &pixelExe, &infoLog)); context, &pixelExe, &infoLog));
if (!programD3D->hasPixelExecutableForCachedOutputLayout()) if (!programD3D->hasPixelExecutableForCachedOutputLayout())
{ {
ASSERT(infoLog.getLength() > 0); ASSERT(infoLog.getLength() > 0);
ERR() << "Dynamic recompilation error log: " << infoLog.str(); ERR() << "Error compiling dynamic pixel executable: " << infoLog.str();
return gl::InternalError() ANGLE_TRY_HR(this, E_FAIL, "Error compiling dynamic pixel executable");
<< "Error compiling dynamic pixel executable:" << infoLog.str();
} }
} }
...@@ -559,14 +566,14 @@ gl::Error Context11::triggerDrawCallProgramRecompilation(const gl::Context *cont ...@@ -559,14 +566,14 @@ gl::Error Context11::triggerDrawCallProgramRecompilation(const gl::Context *cont
mMemoryProgramCache->updateProgram(context, program); mMemoryProgramCache->updateProgram(context, program);
} }
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error Context11::prepareForDrawCall(const gl::Context *context, angle::Result Context11::prepareForDrawCall(const gl::Context *context,
const gl::DrawCallParams &drawCallParams) const gl::DrawCallParams &drawCallParams)
{ {
ANGLE_TRY(mRenderer->getStateManager()->updateState(context, drawCallParams)); ANGLE_TRY(mRenderer->getStateManager()->updateState(context, drawCallParams));
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error Context11::memoryBarrier(const gl::Context *context, GLbitfield barriers) gl::Error Context11::memoryBarrier(const gl::Context *context, GLbitfield barriers)
...@@ -597,4 +604,32 @@ gl::Error Context11::initializeMultisampleTextureToBlack(const gl::Context *cont ...@@ -597,4 +604,32 @@ gl::Error Context11::initializeMultisampleTextureToBlack(const gl::Context *cont
return mRenderer->clearRenderTarget(context, renderTarget, gl::ColorF(0.0f, 0.0f, 0.0f, 1.0f), return mRenderer->clearRenderTarget(context, renderTarget, gl::ColorF(0.0f, 0.0f, 0.0f, 1.0f),
1.0f, 0); 1.0f, 0);
} }
void Context11::handleError(HRESULT hr,
const char *message,
const char *file,
const char *function,
unsigned int line)
{
ASSERT(FAILED(hr));
if (d3d11::isDeviceLostError(hr))
{
mRenderer->notifyDeviceLost();
}
GLenum glErrorCode = DefaultGLErrorCode(hr);
std::stringstream errorStream;
errorStream << "Internal D3D11 error: " << gl::FmtHR(hr) << ", in " << file << ", " << function
<< ":" << line << ". " << message;
mErrors->handleError(gl::Error(glErrorCode, glErrorCode, errorStream.str()));
}
// TODO(jmadill): Remove this once refactor is complete. http://anglebug.com/2738
void Context11::handleError(const gl::Error &error)
{
mErrors->handleError(error);
}
} // namespace rx } // namespace rx
...@@ -147,8 +147,8 @@ class Context11 : public ContextImpl, public MultisampleTextureInitializer ...@@ -147,8 +147,8 @@ class Context11 : public ContextImpl, public MultisampleTextureInitializer
gl::Error memoryBarrier(const gl::Context *context, GLbitfield barriers) override; gl::Error memoryBarrier(const gl::Context *context, GLbitfield barriers) override;
gl::Error memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers) override; gl::Error memoryBarrierByRegion(const gl::Context *context, GLbitfield barriers) override;
gl::Error triggerDrawCallProgramRecompilation(const gl::Context *context, angle::Result triggerDrawCallProgramRecompilation(const gl::Context *context,
gl::PrimitiveMode drawMode); gl::PrimitiveMode drawMode);
gl::Error getIncompleteTexture(const gl::Context *context, gl::Error getIncompleteTexture(const gl::Context *context,
gl::TextureType type, gl::TextureType type,
...@@ -157,9 +157,18 @@ class Context11 : public ContextImpl, public MultisampleTextureInitializer ...@@ -157,9 +157,18 @@ class Context11 : public ContextImpl, public MultisampleTextureInitializer
gl::Error initializeMultisampleTextureToBlack(const gl::Context *context, gl::Error initializeMultisampleTextureToBlack(const gl::Context *context,
gl::Texture *glTexture) override; gl::Texture *glTexture) override;
void handleError(HRESULT hr,
const char *message,
const char *file,
const char *function,
unsigned int line);
// TODO(jmadill): Remove this once refactor is complete. http://anglebug.com/2738
void handleError(const gl::Error &error);
private: private:
gl::Error prepareForDrawCall(const gl::Context *context, angle::Result prepareForDrawCall(const gl::Context *context,
const gl::DrawCallParams &drawCallParams); const gl::DrawCallParams &drawCallParams);
Renderer11 *mRenderer; Renderer11 *mRenderer;
IncompleteTextureSet mIncompleteTextures; IncompleteTextureSet mIncompleteTextures;
......
...@@ -8,9 +8,11 @@ ...@@ -8,9 +8,11 @@
// rx::FenceNVImpl and rx::SyncImpl. // rx::FenceNVImpl and rx::SyncImpl.
#include "libANGLE/renderer/d3d/d3d11/Fence11.h" #include "libANGLE/renderer/d3d/d3d11/Fence11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "common/utilities.h" #include "common/utilities.h"
#include "libANGLE/Context.h"
#include "libANGLE/renderer/d3d/d3d11/Context11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
namespace rx namespace rx
{ {
...@@ -20,7 +22,7 @@ namespace rx ...@@ -20,7 +22,7 @@ namespace rx
// //
template <class FenceClass> template <class FenceClass>
gl::Error FenceSetHelper(FenceClass *fence) angle::Result FenceSetHelper(const gl::Context *context, FenceClass *fence)
{ {
if (!fence->mQuery) if (!fence->mQuery)
{ {
...@@ -28,34 +30,33 @@ gl::Error FenceSetHelper(FenceClass *fence) ...@@ -28,34 +30,33 @@ gl::Error FenceSetHelper(FenceClass *fence)
queryDesc.Query = D3D11_QUERY_EVENT; queryDesc.Query = D3D11_QUERY_EVENT;
queryDesc.MiscFlags = 0; queryDesc.MiscFlags = 0;
Context11 *context11 = GetImplAs<Context11>(context);
HRESULT result = fence->mRenderer->getDevice()->CreateQuery(&queryDesc, &fence->mQuery); HRESULT result = fence->mRenderer->getDevice()->CreateQuery(&queryDesc, &fence->mQuery);
if (FAILED(result)) ANGLE_TRY_HR(context11, result, "Failed to create event query");
{
return gl::OutOfMemory() << "Failed to create event query, " << gl::FmtHR(result);
}
} }
fence->mRenderer->getDeviceContext()->End(fence->mQuery); fence->mRenderer->getDeviceContext()->End(fence->mQuery);
return gl::NoError(); return angle::Result::Continue();
} }
template <class FenceClass> template <class FenceClass>
gl::Error FenceTestHelper(FenceClass *fence, bool flushCommandBuffer, GLboolean *outFinished) angle::Result FenceTestHelper(const gl::Context *context,
FenceClass *fence,
bool flushCommandBuffer,
GLboolean *outFinished)
{ {
ASSERT(fence->mQuery); ASSERT(fence->mQuery);
UINT getDataFlags = (flushCommandBuffer ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH); UINT getDataFlags = (flushCommandBuffer ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH);
Context11 *context11 = GetImplAs<Context11>(context);
HRESULT result = HRESULT result =
fence->mRenderer->getDeviceContext()->GetData(fence->mQuery, nullptr, 0, getDataFlags); fence->mRenderer->getDeviceContext()->GetData(fence->mQuery, nullptr, 0, getDataFlags);
ANGLE_TRY_HR(context11, result, "Failed to get query data");
if (FAILED(result))
{
return gl::OutOfMemory() << "Failed to get query data, " << gl::FmtHR(result);
}
ASSERT(result == S_OK || result == S_FALSE); ASSERT(result == S_OK || result == S_FALSE);
*outFinished = ((result == S_OK) ? GL_TRUE : GL_FALSE); *outFinished = ((result == S_OK) ? GL_TRUE : GL_FALSE);
return gl::NoError(); return angle::Result::Continue();
} }
// //
...@@ -73,12 +74,12 @@ FenceNV11::~FenceNV11() ...@@ -73,12 +74,12 @@ FenceNV11::~FenceNV11()
gl::Error FenceNV11::set(const gl::Context *context, GLenum condition) gl::Error FenceNV11::set(const gl::Context *context, GLenum condition)
{ {
return FenceSetHelper(this); return FenceSetHelper(context, this);
} }
gl::Error FenceNV11::test(const gl::Context *context, GLboolean *outFinished) gl::Error FenceNV11::test(const gl::Context *context, GLboolean *outFinished)
{ {
return FenceTestHelper(this, true, outFinished); return FenceTestHelper(context, this, true, outFinished);
} }
gl::Error FenceNV11::finish(const gl::Context *context) gl::Error FenceNV11::finish(const gl::Context *context)
...@@ -89,7 +90,7 @@ gl::Error FenceNV11::finish(const gl::Context *context) ...@@ -89,7 +90,7 @@ gl::Error FenceNV11::finish(const gl::Context *context)
while (finished != GL_TRUE) while (finished != GL_TRUE)
{ {
loopCount++; loopCount++;
ANGLE_TRY(FenceTestHelper(this, true, &finished)); ANGLE_TRY(FenceTestHelper(context, this, true, &finished));
bool checkDeviceLost = (loopCount % kPollingD3DDeviceLostCheckFrequency) == 0; bool checkDeviceLost = (loopCount % kPollingD3DDeviceLostCheckFrequency) == 0;
if (checkDeviceLost && mRenderer->testDeviceLost()) if (checkDeviceLost && mRenderer->testDeviceLost())
...@@ -135,7 +136,7 @@ Sync11::~Sync11() ...@@ -135,7 +136,7 @@ Sync11::~Sync11()
gl::Error Sync11::set(const gl::Context *context, GLenum condition, GLbitfield flags) gl::Error Sync11::set(const gl::Context *context, GLenum condition, GLbitfield flags)
{ {
ASSERT(condition == GL_SYNC_GPU_COMMANDS_COMPLETE && flags == 0); ASSERT(condition == GL_SYNC_GPU_COMMANDS_COMPLETE && flags == 0);
return FenceSetHelper(this); return FenceSetHelper(context, this);
} }
gl::Error Sync11::clientWait(const gl::Context *context, gl::Error Sync11::clientWait(const gl::Context *context,
...@@ -148,7 +149,7 @@ gl::Error Sync11::clientWait(const gl::Context *context, ...@@ -148,7 +149,7 @@ gl::Error Sync11::clientWait(const gl::Context *context,
bool flushCommandBuffer = ((flags & GL_SYNC_FLUSH_COMMANDS_BIT) != 0); bool flushCommandBuffer = ((flags & GL_SYNC_FLUSH_COMMANDS_BIT) != 0);
GLboolean result = GL_FALSE; GLboolean result = GL_FALSE;
gl::Error error = FenceTestHelper(this, flushCommandBuffer, &result); gl::Error error = FenceTestHelper(context, this, flushCommandBuffer, &result);
if (error.isError()) if (error.isError())
{ {
*outResult = GL_WAIT_FAILED; *outResult = GL_WAIT_FAILED;
...@@ -188,7 +189,7 @@ gl::Error Sync11::clientWait(const gl::Context *context, ...@@ -188,7 +189,7 @@ gl::Error Sync11::clientWait(const gl::Context *context,
success = QueryPerformanceCounter(&currentCounter); success = QueryPerformanceCounter(&currentCounter);
ASSERT(success); ASSERT(success);
error = FenceTestHelper(this, flushCommandBuffer, &result); error = FenceTestHelper(context, this, flushCommandBuffer, &result);
if (error.isError()) if (error.isError())
{ {
*outResult = GL_WAIT_FAILED; *outResult = GL_WAIT_FAILED;
...@@ -226,8 +227,8 @@ gl::Error Sync11::serverWait(const gl::Context *context, GLbitfield flags, GLuin ...@@ -226,8 +227,8 @@ gl::Error Sync11::serverWait(const gl::Context *context, GLbitfield flags, GLuin
gl::Error Sync11::getStatus(const gl::Context *context, GLint *outResult) gl::Error Sync11::getStatus(const gl::Context *context, GLint *outResult)
{ {
GLboolean result = GL_FALSE; GLboolean result = GL_FALSE;
gl::Error error = FenceTestHelper(this, false, &result); angle::Result error = FenceTestHelper(context, this, false, &result);
if (error.isError()) if (error == angle::Result::Stop())
{ {
// The spec does not specify any way to report errors during the status test (e.g. device // The spec does not specify any way to report errors during the status test (e.g. device
// lost) 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.
......
...@@ -28,8 +28,13 @@ class FenceNV11 : public FenceNVImpl ...@@ -28,8 +28,13 @@ class FenceNV11 : public FenceNVImpl
gl::Error finish(const gl::Context *context) override; gl::Error finish(const gl::Context *context) override;
private: private:
template<class T> friend gl::Error FenceSetHelper(T *fence); template <class T>
template<class T> friend gl::Error FenceTestHelper(T *fence, bool flushCommandBuffer, GLboolean *outFinished); friend angle::Result FenceSetHelper(const gl::Context *context, T *fence);
template <class T>
friend angle::Result FenceTestHelper(const gl::Context *context,
T *fence,
bool flushCommandBuffer,
GLboolean *outFinished);
Renderer11 *mRenderer; Renderer11 *mRenderer;
ID3D11Query *mQuery; ID3D11Query *mQuery;
...@@ -50,8 +55,13 @@ class Sync11 : public SyncImpl ...@@ -50,8 +55,13 @@ class Sync11 : public SyncImpl
gl::Error getStatus(const gl::Context *context, GLint *outResult) override; gl::Error getStatus(const gl::Context *context, GLint *outResult) override;
private: private:
template<class T> friend gl::Error FenceSetHelper(T *fence); template <class T>
template<class T> friend gl::Error FenceTestHelper(T *fence, bool flushCommandBuffer, GLboolean *outFinished); friend angle::Result FenceSetHelper(const gl::Context *context, T *fence);
template <class T>
friend angle::Result FenceTestHelper(const gl::Context *context,
T *fence,
bool flushCommandBuffer,
GLboolean *outFinished);
Renderer11 *mRenderer; Renderer11 *mRenderer;
ID3D11Query *mQuery; ID3D11Query *mQuery;
......
...@@ -30,8 +30,8 @@ namespace rx ...@@ -30,8 +30,8 @@ namespace rx
namespace namespace
{ {
gl::Error MarkAttachmentsDirty(const gl::Context *context, angle::Result MarkAttachmentsDirty(const gl::Context *context,
const gl::FramebufferAttachment *attachment) const gl::FramebufferAttachment *attachment)
{ {
if (attachment->type() == GL_TEXTURE) if (attachment->type() == GL_TEXTURE)
{ {
...@@ -40,7 +40,7 @@ gl::Error MarkAttachmentsDirty(const gl::Context *context, ...@@ -40,7 +40,7 @@ gl::Error MarkAttachmentsDirty(const gl::Context *context,
TextureD3D *textureD3D = GetImplAs<TextureD3D>(texture); TextureD3D *textureD3D = GetImplAs<TextureD3D>(texture);
TextureStorage *texStorage = nullptr; TextureStorage *texStorage = nullptr;
ANGLE_TRY(textureD3D->getNativeTexture(context, &texStorage)); ANGLE_TRY_HANDLE(context, textureD3D->getNativeTexture(context, &texStorage));
if (texStorage) if (texStorage)
{ {
...@@ -51,7 +51,7 @@ gl::Error MarkAttachmentsDirty(const gl::Context *context, ...@@ -51,7 +51,7 @@ gl::Error MarkAttachmentsDirty(const gl::Context *context,
} }
} }
return gl::NoError(); return angle::Result::Continue();
} }
} // anonymous namespace } // anonymous namespace
...@@ -65,7 +65,7 @@ Framebuffer11::~Framebuffer11() ...@@ -65,7 +65,7 @@ Framebuffer11::~Framebuffer11()
{ {
} }
gl::Error Framebuffer11::markAttachmentsDirty(const gl::Context *context) const angle::Result Framebuffer11::markAttachmentsDirty(const gl::Context *context) const
{ {
const auto &colorAttachments = mState.getColorAttachments(); const auto &colorAttachments = mState.getColorAttachments();
for (size_t drawBuffer : mState.getEnabledDrawBuffers()) for (size_t drawBuffer : mState.getEnabledDrawBuffers())
...@@ -81,7 +81,7 @@ gl::Error Framebuffer11::markAttachmentsDirty(const gl::Context *context) const ...@@ -81,7 +81,7 @@ gl::Error Framebuffer11::markAttachmentsDirty(const gl::Context *context) const
ANGLE_TRY(MarkAttachmentsDirty(context, dsAttachment)); ANGLE_TRY(MarkAttachmentsDirty(context, dsAttachment));
} }
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error Framebuffer11::clearImpl(const gl::Context *context, const ClearParameters &clearParams) gl::Error Framebuffer11::clearImpl(const gl::Context *context, const ClearParameters &clearParams)
......
...@@ -34,7 +34,7 @@ class Framebuffer11 : public FramebufferD3D ...@@ -34,7 +34,7 @@ class Framebuffer11 : public FramebufferD3D
const gl::Rectangle &area) override; const gl::Rectangle &area) override;
// Invalidate the cached swizzles of all bound texture attachments. // Invalidate the cached swizzles of all bound texture attachments.
gl::Error markAttachmentsDirty(const gl::Context *context) const; angle::Result markAttachmentsDirty(const gl::Context *context) const;
gl::Error syncState(const gl::Context *context, gl::Error syncState(const gl::Context *context,
const gl::Framebuffer::DirtyBits &dirtyBits) override; const gl::Framebuffer::DirtyBits &dirtyBits) override;
......
...@@ -20,6 +20,12 @@ namespace gl ...@@ -20,6 +20,12 @@ namespace gl
class Framebuffer; class Framebuffer;
} }
namespace d3d11
{
template <typename T>
class ScopedUnmapper;
} // namespace d3d11
namespace rx namespace rx
{ {
class Renderer11; class Renderer11;
...@@ -33,19 +39,19 @@ class Image11 : public ImageD3D ...@@ -33,19 +39,19 @@ class Image11 : public ImageD3D
Image11(Renderer11 *renderer); Image11(Renderer11 *renderer);
~Image11() override; ~Image11() override;
static gl::Error GenerateMipmap(const gl::Context *context, static angle::Result GenerateMipmap(const gl::Context *context,
Image11 *dest, Image11 *dest,
Image11 *src, Image11 *src,
const Renderer11DeviceCaps &rendererCaps); const Renderer11DeviceCaps &rendererCaps);
static gl::Error CopyImage(const gl::Context *context, static angle::Result CopyImage(const gl::Context *context,
Image11 *dest, Image11 *dest,
Image11 *source, Image11 *source,
const gl::Rectangle &sourceRect, const gl::Rectangle &sourceRect,
const gl::Offset &destOffset, const gl::Offset &destOffset,
bool unpackFlipY, bool unpackFlipY,
bool unpackPremultiplyAlpha, bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha, bool unpackUnmultiplyAlpha,
const Renderer11DeviceCaps &rendererCaps); const Renderer11DeviceCaps &rendererCaps);
bool isDirty() const override; bool isDirty() const override;
...@@ -79,25 +85,27 @@ class Image11 : public ImageD3D ...@@ -79,25 +85,27 @@ class Image11 : public ImageD3D
const gl::Rectangle &sourceArea, const gl::Rectangle &sourceArea,
const gl::Framebuffer *source) override; const gl::Framebuffer *source) override;
gl::Error recoverFromAssociatedStorage(const gl::Context *context); angle::Result recoverFromAssociatedStorage(const gl::Context *context);
void verifyAssociatedStorageValid(TextureStorage11 *textureStorage) const; void verifyAssociatedStorageValid(TextureStorage11 *textureStorage) const;
void disassociateStorage(); void disassociateStorage();
protected: protected:
gl::Error map(const gl::Context *context, D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map); template <typename T>
friend class d3d11::ScopedUnmapper;
angle::Result map(const gl::Context *context, D3D11_MAP mapType, D3D11_MAPPED_SUBRESOURCE *map);
void unmap(); void unmap();
private: private:
gl::Error copyWithoutConversion(const gl::Context *context, angle::Result copyWithoutConversion(const gl::Context *context,
const gl::Offset &destOffset, const gl::Offset &destOffset,
const gl::Box &sourceArea, const gl::Box &sourceArea,
const TextureHelper11 &textureHelper, const TextureHelper11 &textureHelper,
UINT sourceSubResource); UINT sourceSubResource);
gl::Error getStagingTexture(const gl::Context *context, angle::Result getStagingTexture(const gl::Context *context,
const TextureHelper11 **outStagingTexture, const TextureHelper11 **outStagingTexture,
unsigned int *outSubresourceIndex); unsigned int *outSubresourceIndex);
gl::Error createStagingTexture(const gl::Context *context); angle::Result createStagingTexture(const gl::Context *context);
void releaseStagingTexture(); void releaseStagingTexture();
Renderer11 *mRenderer; Renderer11 *mRenderer;
......
...@@ -113,7 +113,7 @@ void InputLayoutCache::clear() ...@@ -113,7 +113,7 @@ void InputLayoutCache::clear()
mLayoutCache.Clear(); mLayoutCache.Clear();
} }
gl::Error InputLayoutCache::getInputLayout( angle::Result InputLayoutCache::getInputLayout(
const gl::Context *context, const gl::Context *context,
Renderer11 *renderer, Renderer11 *renderer,
const gl::State &state, const gl::State &state,
...@@ -190,10 +190,10 @@ gl::Error InputLayoutCache::getInputLayout( ...@@ -190,10 +190,10 @@ gl::Error InputLayoutCache::getInputLayout(
} }
} }
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error InputLayoutCache::createInputLayout( angle::Result InputLayoutCache::createInputLayout(
const gl::Context *context, const gl::Context *context,
Renderer11 *renderer, Renderer11 *renderer,
const AttribIndexArray &sortedSemanticIndices, const AttribIndexArray &sortedSemanticIndices,
...@@ -293,15 +293,17 @@ gl::Error InputLayoutCache::createInputLayout( ...@@ -293,15 +293,17 @@ gl::Error InputLayoutCache::createInputLayout(
} }
ShaderExecutableD3D *shader = nullptr; ShaderExecutableD3D *shader = nullptr;
ANGLE_TRY(programD3D->getVertexExecutableForCachedInputLayout(context, &shader, nullptr)); ANGLE_TRY_HANDLE(
context, programD3D->getVertexExecutableForCachedInputLayout(context, &shader, nullptr));
ShaderExecutableD3D *shader11 = GetAs<ShaderExecutable11>(shader); ShaderExecutableD3D *shader11 = GetAs<ShaderExecutable11>(shader);
InputElementArray inputElementArray(inputElements.data(), inputElementCount); InputElementArray inputElementArray(inputElements.data(), inputElementCount);
ShaderData vertexShaderData(shader11->getFunction(), shader11->getLength()); ShaderData vertexShaderData(shader11->getFunction(), shader11->getLength());
ANGLE_TRY(renderer->allocateResource(inputElementArray, &vertexShaderData, inputLayoutOut)); ANGLE_TRY_HANDLE(
return gl::NoError(); context, renderer->allocateResource(inputElementArray, &vertexShaderData, inputLayoutOut));
return angle::Result::Continue();
} }
void InputLayoutCache::setCacheSize(size_t newCacheSize) void InputLayoutCache::setCacheSize(size_t newCacheSize)
......
...@@ -88,22 +88,23 @@ class InputLayoutCache : angle::NonCopyable ...@@ -88,22 +88,23 @@ class InputLayoutCache : angle::NonCopyable
// Useful for testing // Useful for testing
void setCacheSize(size_t newCacheSize); void setCacheSize(size_t newCacheSize);
gl::Error getInputLayout(const gl::Context *context, angle::Result getInputLayout(const gl::Context *context,
Renderer11 *renderer, Renderer11 *renderer,
const gl::State &state, const gl::State &state,
const std::vector<const TranslatedAttribute *> &currentAttributes, const std::vector<const TranslatedAttribute *> &currentAttributes,
const AttribIndexArray &sortedSemanticIndices, const AttribIndexArray &sortedSemanticIndices,
const gl::DrawCallParams &drawCallParams, const gl::DrawCallParams &drawCallParams,
const d3d11::InputLayout **inputLayoutOut); const d3d11::InputLayout **inputLayoutOut);
private: private:
gl::Error createInputLayout(const gl::Context *context, angle::Result createInputLayout(
Renderer11 *renderer, const gl::Context *context,
const AttribIndexArray &sortedSemanticIndices, Renderer11 *renderer,
const std::vector<const TranslatedAttribute *> &currentAttributes, const AttribIndexArray &sortedSemanticIndices,
gl::Program *program, const std::vector<const TranslatedAttribute *> &currentAttributes,
const gl::DrawCallParams &drawCallParams, gl::Program *program,
d3d11::InputLayout *inputLayoutOut); const gl::DrawCallParams &drawCallParams,
d3d11::InputLayout *inputLayoutOut);
// Starting cache size. // Starting cache size.
static constexpr size_t kDefaultCacheSize = 1024; static constexpr size_t kDefaultCacheSize = 1024;
......
...@@ -48,11 +48,11 @@ PixelTransfer11::~PixelTransfer11() ...@@ -48,11 +48,11 @@ PixelTransfer11::~PixelTransfer11()
{ {
} }
gl::Error PixelTransfer11::loadResources() angle::Result PixelTransfer11::loadResources(const gl::Context *context)
{ {
if (mResourcesLoaded) if (mResourcesLoaded)
{ {
return gl::NoError(); return angle::Result::Continue();
} }
D3D11_RASTERIZER_DESC rasterDesc; D3D11_RASTERIZER_DESC rasterDesc;
...@@ -67,7 +67,7 @@ gl::Error PixelTransfer11::loadResources() ...@@ -67,7 +67,7 @@ gl::Error PixelTransfer11::loadResources()
rasterDesc.MultisampleEnable = FALSE; rasterDesc.MultisampleEnable = FALSE;
rasterDesc.AntialiasedLineEnable = FALSE; rasterDesc.AntialiasedLineEnable = FALSE;
ANGLE_TRY(mRenderer->allocateResource(rasterDesc, &mCopyRasterizerState)); ANGLE_TRY_HANDLE(context, mRenderer->allocateResource(rasterDesc, &mCopyRasterizerState));
D3D11_DEPTH_STENCIL_DESC depthStencilDesc; D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
depthStencilDesc.DepthEnable = true; depthStencilDesc.DepthEnable = true;
...@@ -85,7 +85,8 @@ gl::Error PixelTransfer11::loadResources() ...@@ -85,7 +85,8 @@ gl::Error PixelTransfer11::loadResources()
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;
ANGLE_TRY(mRenderer->allocateResource(depthStencilDesc, &mCopyDepthStencilState)); ANGLE_TRY_HANDLE(context,
mRenderer->allocateResource(depthStencilDesc, &mCopyDepthStencilState));
D3D11_BUFFER_DESC constantBufferDesc = { 0 }; D3D11_BUFFER_DESC constantBufferDesc = { 0 };
constantBufferDesc.ByteWidth = roundUp<UINT>(sizeof(CopyShaderParams), 32u); constantBufferDesc.ByteWidth = roundUp<UINT>(sizeof(CopyShaderParams), 32u);
...@@ -95,23 +96,26 @@ gl::Error PixelTransfer11::loadResources() ...@@ -95,23 +96,26 @@ gl::Error PixelTransfer11::loadResources()
constantBufferDesc.MiscFlags = 0; constantBufferDesc.MiscFlags = 0;
constantBufferDesc.StructureByteStride = 0; constantBufferDesc.StructureByteStride = 0;
ANGLE_TRY(mRenderer->allocateResource(constantBufferDesc, &mParamsConstantBuffer)); ANGLE_TRY_HANDLE(context,
mRenderer->allocateResource(constantBufferDesc, &mParamsConstantBuffer));
mParamsConstantBuffer.setDebugName("PixelTransfer11 constant buffer"); mParamsConstantBuffer.setDebugName("PixelTransfer11 constant buffer");
// init shaders // init shaders
ANGLE_TRY(mRenderer->allocateResource(ShaderData(g_VS_BufferToTexture), &mBufferToTextureVS)); ANGLE_TRY_HANDLE(context, mRenderer->allocateResource(ShaderData(g_VS_BufferToTexture),
&mBufferToTextureVS));
mBufferToTextureVS.setDebugName("BufferToTexture VS"); mBufferToTextureVS.setDebugName("BufferToTexture VS");
ANGLE_TRY(mRenderer->allocateResource(ShaderData(g_GS_BufferToTexture), &mBufferToTextureGS)); ANGLE_TRY_HANDLE(context, mRenderer->allocateResource(ShaderData(g_GS_BufferToTexture),
&mBufferToTextureGS));
mBufferToTextureGS.setDebugName("BufferToTexture GS"); mBufferToTextureGS.setDebugName("BufferToTexture GS");
ANGLE_TRY(buildShaderMap()); ANGLE_TRY(buildShaderMap(context));
StructZero(&mParamsData); StructZero(&mParamsData);
mResourcesLoaded = true; mResourcesLoaded = true;
return gl::NoError(); return angle::Result::Continue();
} }
void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea, const gl::Extents &destSize, GLenum internalFormat, void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea, const gl::Extents &destSize, GLenum internalFormat,
...@@ -137,15 +141,15 @@ void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea, cons ...@@ -137,15 +141,15 @@ void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea, cons
parametersOut->FirstSlice = destArea.z; parametersOut->FirstSlice = destArea.z;
} }
gl::Error PixelTransfer11::copyBufferToTexture(const gl::Context *context, angle::Result PixelTransfer11::copyBufferToTexture(const gl::Context *context,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
unsigned int offset, unsigned int offset,
RenderTargetD3D *destRenderTarget, RenderTargetD3D *destRenderTarget,
GLenum destinationFormat, GLenum destinationFormat,
GLenum sourcePixelsType, GLenum sourcePixelsType,
const gl::Box &destArea) const gl::Box &destArea)
{ {
ANGLE_TRY(loadResources()); ANGLE_TRY(loadResources(context));
gl::Extents destSize = destRenderTarget->getExtents(); gl::Extents destSize = destRenderTarget->getExtents();
...@@ -216,21 +220,21 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::Context *context, ...@@ -216,21 +220,21 @@ gl::Error PixelTransfer11::copyBufferToTexture(const gl::Context *context,
UINT numPixels = (destArea.width * destArea.height * destArea.depth); UINT numPixels = (destArea.width * destArea.height * destArea.depth);
deviceContext->Draw(numPixels, 0); deviceContext->Draw(numPixels, 0);
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error PixelTransfer11::buildShaderMap() angle::Result PixelTransfer11::buildShaderMap(const gl::Context *context)
{ {
d3d11::PixelShader bufferToTextureFloat; d3d11::PixelShader bufferToTextureFloat;
d3d11::PixelShader bufferToTextureInt; d3d11::PixelShader bufferToTextureInt;
d3d11::PixelShader bufferToTextureUint; d3d11::PixelShader bufferToTextureUint;
ANGLE_TRY( ANGLE_TRY_HANDLE(context, mRenderer->allocateResource(ShaderData(g_PS_BufferToTexture_4F),
mRenderer->allocateResource(ShaderData(g_PS_BufferToTexture_4F), &bufferToTextureFloat)); &bufferToTextureFloat));
ANGLE_TRY( ANGLE_TRY_HANDLE(context, mRenderer->allocateResource(ShaderData(g_PS_BufferToTexture_4I),
mRenderer->allocateResource(ShaderData(g_PS_BufferToTexture_4I), &bufferToTextureInt)); &bufferToTextureInt));
ANGLE_TRY( ANGLE_TRY_HANDLE(context, mRenderer->allocateResource(ShaderData(g_PS_BufferToTexture_4UI),
mRenderer->allocateResource(ShaderData(g_PS_BufferToTexture_4UI), &bufferToTextureUint)); &bufferToTextureUint));
bufferToTextureFloat.setDebugName("BufferToTexture RGBA ps"); bufferToTextureFloat.setDebugName("BufferToTexture RGBA ps");
bufferToTextureInt.setDebugName("BufferToTexture RGBA-I ps"); bufferToTextureInt.setDebugName("BufferToTexture RGBA-I ps");
...@@ -240,7 +244,7 @@ gl::Error PixelTransfer11::buildShaderMap() ...@@ -240,7 +244,7 @@ gl::Error PixelTransfer11::buildShaderMap()
mBufferToTexturePSMap[GL_INT] = std::move(bufferToTextureInt); mBufferToTexturePSMap[GL_INT] = std::move(bufferToTextureInt);
mBufferToTexturePSMap[GL_UNSIGNED_INT] = std::move(bufferToTextureUint); mBufferToTexturePSMap[GL_UNSIGNED_INT] = std::move(bufferToTextureUint);
return gl::NoError(); return angle::Result::Continue();
} }
const d3d11::PixelShader *PixelTransfer11::findBufferToTexturePS(GLenum internalFormat) const const d3d11::PixelShader *PixelTransfer11::findBufferToTexturePS(GLenum internalFormat) const
......
...@@ -45,13 +45,13 @@ class PixelTransfer11 ...@@ -45,13 +45,13 @@ class PixelTransfer11
// destRenderTarget: individual slice/layer of a target texture // destRenderTarget: individual slice/layer of a target texture
// destinationFormat/sourcePixelsType: determines shaders + shader parameters // destinationFormat/sourcePixelsType: determines shaders + shader parameters
// destArea: the sub-section of destRenderTarget to copy to // destArea: the sub-section of destRenderTarget to copy to
gl::Error copyBufferToTexture(const gl::Context *context, angle::Result copyBufferToTexture(const gl::Context *context,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
unsigned int offset, unsigned int offset,
RenderTargetD3D *destRenderTarget, RenderTargetD3D *destRenderTarget,
GLenum destinationFormat, GLenum destinationFormat,
GLenum sourcePixelsType, GLenum sourcePixelsType,
const gl::Box &destArea); const gl::Box &destArea);
private: private:
...@@ -71,8 +71,8 @@ class PixelTransfer11 ...@@ -71,8 +71,8 @@ class PixelTransfer11
static void setBufferToTextureCopyParams(const gl::Box &destArea, const gl::Extents &destSize, GLenum internalFormat, static void setBufferToTextureCopyParams(const gl::Box &destArea, const gl::Extents &destSize, GLenum internalFormat,
const gl::PixelUnpackState &unpack, unsigned int offset, CopyShaderParams *parametersOut); const gl::PixelUnpackState &unpack, unsigned int offset, CopyShaderParams *parametersOut);
gl::Error loadResources(); angle::Result loadResources(const gl::Context *context);
gl::Error buildShaderMap(); angle::Result buildShaderMap(const gl::Context *context);
const d3d11::PixelShader *findBufferToTexturePS(GLenum internalFormat) const; const d3d11::PixelShader *findBufferToTexturePS(GLenum internalFormat) const;
Renderer11 *mRenderer; Renderer11 *mRenderer;
......
...@@ -11,6 +11,8 @@ ...@@ -11,6 +11,8 @@
#include <GLES2/gl2ext.h> #include <GLES2/gl2ext.h>
#include "common/utilities.h" #include "common/utilities.h"
#include "libANGLE/Context.h"
#include "libANGLE/renderer/d3d/d3d11/Context11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" #include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h" #include "libANGLE/renderer/d3d/d3d11/renderer11_utils.h"
...@@ -72,12 +74,12 @@ gl::Error Query11::begin(const gl::Context *context) ...@@ -72,12 +74,12 @@ gl::Error Query11::begin(const gl::Context *context)
{ {
mResultSum = 0; mResultSum = 0;
mRenderer->getStateManager()->onBeginQuery(this); mRenderer->getStateManager()->onBeginQuery(this);
return resume(); return resume(GetImplAs<Context11>(context));
} }
gl::Error Query11::end(const gl::Context *context) gl::Error Query11::end(const gl::Context *context)
{ {
return pause(); return pause(GetImplAs<Context11>(context));
} }
gl::Error Query11::queryCounter(const gl::Context *context) gl::Error Query11::queryCounter(const gl::Context *context)
...@@ -90,45 +92,45 @@ gl::Error Query11::queryCounter(const gl::Context *context) ...@@ -90,45 +92,45 @@ gl::Error Query11::queryCounter(const gl::Context *context)
} }
template <typename T> template <typename T>
gl::Error Query11::getResultBase(T *params) angle::Result Query11::getResultBase(Context11 *context11, T *params)
{ {
ASSERT(!mActiveQuery->query.valid()); ASSERT(!mActiveQuery->query.valid());
ANGLE_TRY(flush(true)); ANGLE_TRY(flush(context11, true));
ASSERT(mPendingQueries.empty()); ASSERT(mPendingQueries.empty());
*params = static_cast<T>(mResultSum); *params = static_cast<T>(mResultSum);
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error Query11::getResult(const gl::Context *context, GLint *params) gl::Error Query11::getResult(const gl::Context *context, GLint *params)
{ {
return getResultBase(params); return getResultBase(GetImplAs<Context11>(context), params);
} }
gl::Error Query11::getResult(const gl::Context *context, GLuint *params) gl::Error Query11::getResult(const gl::Context *context, GLuint *params)
{ {
return getResultBase(params); return getResultBase(GetImplAs<Context11>(context), params);
} }
gl::Error Query11::getResult(const gl::Context *context, GLint64 *params) gl::Error Query11::getResult(const gl::Context *context, GLint64 *params)
{ {
return getResultBase(params); return getResultBase(GetImplAs<Context11>(context), params);
} }
gl::Error Query11::getResult(const gl::Context *context, GLuint64 *params) gl::Error Query11::getResult(const gl::Context *context, GLuint64 *params)
{ {
return getResultBase(params); return getResultBase(GetImplAs<Context11>(context), params);
} }
gl::Error Query11::isResultAvailable(const gl::Context *context, bool *available) gl::Error Query11::isResultAvailable(const gl::Context *context, bool *available)
{ {
ANGLE_TRY(flush(false)); ANGLE_TRY(flush(GetImplAs<Context11>(context), false));
*available = mPendingQueries.empty(); *available = mPendingQueries.empty();
return gl::NoError(); return gl::NoError();
} }
gl::Error Query11::pause() angle::Result Query11::pause(Context11 *context11)
{ {
if (mActiveQuery->query.valid()) if (mActiveQuery->query.valid())
{ {
...@@ -147,14 +149,14 @@ gl::Error Query11::pause() ...@@ -147,14 +149,14 @@ gl::Error Query11::pause()
mActiveQuery = std::unique_ptr<QueryState>(new QueryState()); mActiveQuery = std::unique_ptr<QueryState>(new QueryState());
} }
return flush(false); return flush(context11, false);
} }
gl::Error Query11::resume() angle::Result Query11::resume(Context11 *context11)
{ {
if (!mActiveQuery->query.valid()) if (!mActiveQuery->query.valid())
{ {
ANGLE_TRY(flush(false)); ANGLE_TRY(flush(context11, false));
gl::QueryType type = getType(); gl::QueryType type = getType();
D3D11_QUERY d3dQueryType = gl_d3d11::ConvertQueryType(type); D3D11_QUERY d3dQueryType = gl_d3d11::ConvertQueryType(type);
...@@ -163,7 +165,7 @@ gl::Error Query11::resume() ...@@ -163,7 +165,7 @@ gl::Error Query11::resume()
queryDesc.Query = d3dQueryType; queryDesc.Query = d3dQueryType;
queryDesc.MiscFlags = 0; queryDesc.MiscFlags = 0;
ANGLE_TRY(mRenderer->allocateResource(queryDesc, &mActiveQuery->query)); ANGLE_TRY_HANDLE(context11, mRenderer->allocateResource(queryDesc, &mActiveQuery->query));
// If we are doing time elapsed we also need a query to actually query the timestamp // If we are doing time elapsed we also need a query to actually query the timestamp
if (type == gl::QueryType::TimeElapsed) if (type == gl::QueryType::TimeElapsed)
...@@ -172,8 +174,10 @@ gl::Error Query11::resume() ...@@ -172,8 +174,10 @@ gl::Error Query11::resume()
desc.Query = D3D11_QUERY_TIMESTAMP; desc.Query = D3D11_QUERY_TIMESTAMP;
desc.MiscFlags = 0; desc.MiscFlags = 0;
ANGLE_TRY(mRenderer->allocateResource(desc, &mActiveQuery->beginTimestamp)); ANGLE_TRY_HANDLE(context11,
ANGLE_TRY(mRenderer->allocateResource(desc, &mActiveQuery->endTimestamp)); mRenderer->allocateResource(desc, &mActiveQuery->beginTimestamp));
ANGLE_TRY_HANDLE(context11,
mRenderer->allocateResource(desc, &mActiveQuery->endTimestamp));
} }
ID3D11DeviceContext *context = mRenderer->getDeviceContext(); ID3D11DeviceContext *context = mRenderer->getDeviceContext();
...@@ -190,10 +194,10 @@ gl::Error Query11::resume() ...@@ -190,10 +194,10 @@ gl::Error Query11::resume()
} }
} }
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error Query11::flush(bool force) angle::Result Query11::flush(Context11 *context11, bool force)
{ {
while (!mPendingQueries.empty()) while (!mPendingQueries.empty())
{ {
...@@ -201,10 +205,10 @@ gl::Error Query11::flush(bool force) ...@@ -201,10 +205,10 @@ gl::Error Query11::flush(bool force)
do do
{ {
ANGLE_TRY(testQuery(query)); ANGLE_TRY(testQuery(context11, query));
if (!query->finished && !force) if (!query->finished && !force)
{ {
return gl::NoError(); return angle::Result::Continue();
} }
} while (!query->finished); } while (!query->finished);
...@@ -212,10 +216,10 @@ gl::Error Query11::flush(bool force) ...@@ -212,10 +216,10 @@ gl::Error Query11::flush(bool force)
mPendingQueries.pop_front(); mPendingQueries.pop_front();
} }
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error Query11::testQuery(QueryState *queryState) angle::Result Query11::testQuery(Context11 *context11, QueryState *queryState)
{ {
if (!queryState->finished) if (!queryState->finished)
{ {
...@@ -229,11 +233,7 @@ gl::Error Query11::testQuery(QueryState *queryState) ...@@ -229,11 +233,7 @@ gl::Error Query11::testQuery(QueryState *queryState)
UINT64 numPixels = 0; UINT64 numPixels = 0;
HRESULT result = HRESULT result =
context->GetData(queryState->query.get(), &numPixels, sizeof(numPixels), 0); context->GetData(queryState->query.get(), &numPixels, sizeof(numPixels), 0);
if (FAILED(result)) ANGLE_TRY_HR(context11, result, "Failed to get the data of an internal query");
{
return gl::OutOfMemory()
<< "Failed to get the data of an internal query, " << gl::FmtHR(result);
}
if (result == S_OK) if (result == S_OK)
{ {
...@@ -249,11 +249,7 @@ gl::Error Query11::testQuery(QueryState *queryState) ...@@ -249,11 +249,7 @@ gl::Error Query11::testQuery(QueryState *queryState)
D3D11_QUERY_DATA_SO_STATISTICS soStats = {0}; D3D11_QUERY_DATA_SO_STATISTICS soStats = {0};
HRESULT result = HRESULT result =
context->GetData(queryState->query.get(), &soStats, sizeof(soStats), 0); context->GetData(queryState->query.get(), &soStats, sizeof(soStats), 0);
if (FAILED(result)) ANGLE_TRY_HR(context11, result, "Failed to get the data of an internal query");
{
return gl::OutOfMemory()
<< "Failed to get the data of an internal query, " << gl::FmtHR(result);
}
if (result == S_OK) if (result == S_OK)
{ {
...@@ -271,30 +267,20 @@ gl::Error Query11::testQuery(QueryState *queryState) ...@@ -271,30 +267,20 @@ gl::Error Query11::testQuery(QueryState *queryState)
D3D11_QUERY_DATA_TIMESTAMP_DISJOINT timeStats = {0}; D3D11_QUERY_DATA_TIMESTAMP_DISJOINT timeStats = {0};
HRESULT result = HRESULT result =
context->GetData(queryState->query.get(), &timeStats, sizeof(timeStats), 0); context->GetData(queryState->query.get(), &timeStats, sizeof(timeStats), 0);
if (FAILED(result)) ANGLE_TRY_HR(context11, result, "Failed to get the data of an internal query");
{
return gl::OutOfMemory()
<< "Failed to get the data of an internal query, " << gl::FmtHR(result);
}
if (result == S_OK) if (result == S_OK)
{ {
UINT64 beginTime = 0; UINT64 beginTime = 0;
HRESULT beginRes = context->GetData(queryState->beginTimestamp.get(), HRESULT beginRes = context->GetData(queryState->beginTimestamp.get(),
&beginTime, sizeof(UINT64), 0); &beginTime, sizeof(UINT64), 0);
if (FAILED(beginRes)) ANGLE_TRY_HR(context11, beginRes,
{ "Failed to get the data of an internal query");
return gl::OutOfMemory() << "Failed to get the data of an internal query, "
<< gl::FmtHR(beginRes);
}
UINT64 endTime = 0; UINT64 endTime = 0;
HRESULT endRes = context->GetData(queryState->endTimestamp.get(), &endTime, HRESULT endRes = context->GetData(queryState->endTimestamp.get(), &endTime,
sizeof(UINT64), 0); sizeof(UINT64), 0);
if (FAILED(endRes)) ANGLE_TRY_HR(context11, endRes, "Failed to get the data of an internal query");
{
return gl::OutOfMemory() << "Failed to get the data of an internal query, "
<< gl::FmtHR(endRes);
}
if (beginRes == S_OK && endRes == S_OK) if (beginRes == S_OK && endRes == S_OK)
{ {
...@@ -343,11 +329,7 @@ gl::Error Query11::testQuery(QueryState *queryState) ...@@ -343,11 +329,7 @@ gl::Error Query11::testQuery(QueryState *queryState)
BOOL completed = 0; BOOL completed = 0;
HRESULT result = HRESULT result =
context->GetData(queryState->query.get(), &completed, sizeof(completed), 0); context->GetData(queryState->query.get(), &completed, sizeof(completed), 0);
if (FAILED(result)) ANGLE_TRY_HR(context11, result, "Failed to get the data of an internal query");
{
return gl::OutOfMemory()
<< "Failed to get the data of an internal query, " << gl::FmtHR(result);
}
if (result == S_OK) if (result == S_OK)
{ {
...@@ -369,11 +351,12 @@ gl::Error Query11::testQuery(QueryState *queryState) ...@@ -369,11 +351,12 @@ gl::Error Query11::testQuery(QueryState *queryState)
if (!queryState->finished && checkDeviceLost && mRenderer->testDeviceLost()) if (!queryState->finished && checkDeviceLost && mRenderer->testDeviceLost())
{ {
mRenderer->notifyDeviceLost(); mRenderer->notifyDeviceLost();
return gl::OutOfMemory() << "Failed to test get query result, device is lost."; ANGLE_TRY_HR(context11, E_OUTOFMEMORY,
"Failed to test get query result, device is lost.");
} }
} }
return gl::NoError(); return angle::Result::Continue();
} }
} // namespace rx } // namespace rx
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
namespace rx namespace rx
{ {
class Context11;
class Renderer11; class Renderer11;
class Query11 : public QueryImpl class Query11 : public QueryImpl
...@@ -33,8 +34,8 @@ class Query11 : public QueryImpl ...@@ -33,8 +34,8 @@ class Query11 : public QueryImpl
gl::Error getResult(const gl::Context *context, GLuint64 *params) override; gl::Error getResult(const gl::Context *context, GLuint64 *params) override;
gl::Error isResultAvailable(const gl::Context *context, bool *available) override; gl::Error isResultAvailable(const gl::Context *context, bool *available) override;
gl::Error pause(); angle::Result pause(Context11 *context11);
gl::Error resume(); angle::Result resume(Context11 *context11);
private: private:
struct QueryState final : private angle::NonCopyable struct QueryState final : private angle::NonCopyable
...@@ -50,11 +51,11 @@ class Query11 : public QueryImpl ...@@ -50,11 +51,11 @@ class Query11 : public QueryImpl
bool finished; bool finished;
}; };
gl::Error flush(bool force); angle::Result flush(Context11 *context11, bool force);
gl::Error testQuery(QueryState *queryState); angle::Result testQuery(Context11 *context11, QueryState *queryState);
template <typename T> template <typename T>
gl::Error getResultBase(T *params); angle::Result getResultBase(Context11 *context11, T *params);
GLuint64 mResult; GLuint64 mResult;
GLuint64 mResultSum; GLuint64 mResultSum;
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <float.h> #include <float.h>
#include "common/debug.h" #include "common/debug.h"
#include "libANGLE/Context.h"
#include "libANGLE/Framebuffer.h" #include "libANGLE/Framebuffer.h"
#include "libANGLE/FramebufferAttachment.h" #include "libANGLE/FramebufferAttachment.h"
#include "libANGLE/renderer/d3d/d3d11/Framebuffer11.h" #include "libANGLE/renderer/d3d/d3d11/Framebuffer11.h"
...@@ -70,15 +71,16 @@ d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *conte ...@@ -70,15 +71,16 @@ d3d11::BlendStateKey RenderStateCache::GetBlendStateKey(const gl::Context *conte
return key; return key;
} }
gl::Error RenderStateCache::getBlendState(Renderer11 *renderer, angle::Result RenderStateCache::getBlendState(const gl::Context *context,
const d3d11::BlendStateKey &key, Renderer11 *renderer,
const d3d11::BlendState **outBlendState) const d3d11::BlendStateKey &key,
const d3d11::BlendState **outBlendState)
{ {
auto keyIter = mBlendStateCache.Get(key); auto keyIter = mBlendStateCache.Get(key);
if (keyIter != mBlendStateCache.end()) if (keyIter != mBlendStateCache.end())
{ {
*outBlendState = &keyIter->second; *outBlendState = &keyIter->second;
return gl::NoError(); return angle::Result::Continue();
} }
TrimCache(kMaxStates, kGCLimit, "blend state", &mBlendStateCache); TrimCache(kMaxStates, kGCLimit, "blend state", &mBlendStateCache);
...@@ -113,18 +115,19 @@ gl::Error RenderStateCache::getBlendState(Renderer11 *renderer, ...@@ -113,18 +115,19 @@ gl::Error RenderStateCache::getBlendState(Renderer11 *renderer,
} }
d3d11::BlendState d3dBlendState; d3d11::BlendState d3dBlendState;
ANGLE_TRY(renderer->allocateResource(blendDesc, &d3dBlendState)); ANGLE_TRY_HANDLE(context, renderer->allocateResource(blendDesc, &d3dBlendState));
const auto &iter = mBlendStateCache.Put(key, std::move(d3dBlendState)); const auto &iter = mBlendStateCache.Put(key, std::move(d3dBlendState));
*outBlendState = &iter->second; *outBlendState = &iter->second;
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error RenderStateCache::getRasterizerState(Renderer11 *renderer, angle::Result RenderStateCache::getRasterizerState(const gl::Context *context,
const gl::RasterizerState &rasterState, Renderer11 *renderer,
bool scissorEnabled, const gl::RasterizerState &rasterState,
ID3D11RasterizerState **outRasterizerState) bool scissorEnabled,
ID3D11RasterizerState **outRasterizerState)
{ {
d3d11::RasterizerStateKey key; d3d11::RasterizerStateKey key;
key.rasterizerState = rasterState; key.rasterizerState = rasterState;
...@@ -134,7 +137,7 @@ gl::Error RenderStateCache::getRasterizerState(Renderer11 *renderer, ...@@ -134,7 +137,7 @@ gl::Error RenderStateCache::getRasterizerState(Renderer11 *renderer,
if (keyIter != mRasterizerStateCache.end()) if (keyIter != mRasterizerStateCache.end())
{ {
*outRasterizerState = keyIter->second.get(); *outRasterizerState = keyIter->second.get();
return gl::NoError(); return angle::Result::Continue();
} }
TrimCache(kMaxStates, kGCLimit, "rasterizer state", &mRasterizerStateCache); TrimCache(kMaxStates, kGCLimit, "rasterizer state", &mRasterizerStateCache);
...@@ -171,22 +174,23 @@ gl::Error RenderStateCache::getRasterizerState(Renderer11 *renderer, ...@@ -171,22 +174,23 @@ gl::Error RenderStateCache::getRasterizerState(Renderer11 *renderer,
} }
d3d11::RasterizerState dx11RasterizerState; d3d11::RasterizerState dx11RasterizerState;
ANGLE_TRY(renderer->allocateResource(rasterDesc, &dx11RasterizerState)); ANGLE_TRY_HANDLE(context, renderer->allocateResource(rasterDesc, &dx11RasterizerState));
*outRasterizerState = dx11RasterizerState.get(); *outRasterizerState = dx11RasterizerState.get();
mRasterizerStateCache.Put(key, std::move(dx11RasterizerState)); mRasterizerStateCache.Put(key, std::move(dx11RasterizerState));
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error RenderStateCache::getDepthStencilState(Renderer11 *renderer, angle::Result RenderStateCache::getDepthStencilState(const gl::Context *context,
const gl::DepthStencilState &glState, Renderer11 *renderer,
const d3d11::DepthStencilState **outDSState) const gl::DepthStencilState &glState,
const d3d11::DepthStencilState **outDSState)
{ {
auto keyIter = mDepthStencilStateCache.Get(glState); auto keyIter = mDepthStencilStateCache.Get(glState);
if (keyIter != mDepthStencilStateCache.end()) if (keyIter != mDepthStencilStateCache.end())
{ {
*outDSState = &keyIter->second; *outDSState = &keyIter->second;
return gl::NoError(); return angle::Result::Continue();
} }
TrimCache(kMaxStates, kGCLimit, "depth stencil state", &mDepthStencilStateCache); TrimCache(kMaxStates, kGCLimit, "depth stencil state", &mDepthStencilStateCache);
...@@ -208,23 +212,24 @@ gl::Error RenderStateCache::getDepthStencilState(Renderer11 *renderer, ...@@ -208,23 +212,24 @@ gl::Error RenderStateCache::getDepthStencilState(Renderer11 *renderer,
dsDesc.BackFace.StencilFunc = ConvertComparison(glState.stencilBackFunc); dsDesc.BackFace.StencilFunc = ConvertComparison(glState.stencilBackFunc);
d3d11::DepthStencilState dx11DepthStencilState; d3d11::DepthStencilState dx11DepthStencilState;
ANGLE_TRY(renderer->allocateResource(dsDesc, &dx11DepthStencilState)); ANGLE_TRY_HANDLE(context, renderer->allocateResource(dsDesc, &dx11DepthStencilState));
const auto &iter = mDepthStencilStateCache.Put(glState, std::move(dx11DepthStencilState)); const auto &iter = mDepthStencilStateCache.Put(glState, std::move(dx11DepthStencilState));
*outDSState = &iter->second; *outDSState = &iter->second;
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error RenderStateCache::getSamplerState(Renderer11 *renderer, angle::Result RenderStateCache::getSamplerState(const gl::Context *context,
const gl::SamplerState &samplerState, Renderer11 *renderer,
ID3D11SamplerState **outSamplerState) const gl::SamplerState &samplerState,
ID3D11SamplerState **outSamplerState)
{ {
auto keyIter = mSamplerStateCache.Get(samplerState); auto keyIter = mSamplerStateCache.Get(samplerState);
if (keyIter != mSamplerStateCache.end()) if (keyIter != mSamplerStateCache.end())
{ {
*outSamplerState = keyIter->second.get(); *outSamplerState = keyIter->second.get();
return gl::NoError(); return angle::Result::Continue();
} }
TrimCache(kMaxStates, kGCLimit, "sampler state", &mSamplerStateCache); TrimCache(kMaxStates, kGCLimit, "sampler state", &mSamplerStateCache);
...@@ -262,11 +267,11 @@ gl::Error RenderStateCache::getSamplerState(Renderer11 *renderer, ...@@ -262,11 +267,11 @@ gl::Error RenderStateCache::getSamplerState(Renderer11 *renderer,
} }
d3d11::SamplerState dx11SamplerState; d3d11::SamplerState dx11SamplerState;
ANGLE_TRY(renderer->allocateResource(samplerDesc, &dx11SamplerState)); ANGLE_TRY_HANDLE(context, renderer->allocateResource(samplerDesc, &dx11SamplerState));
*outSamplerState = dx11SamplerState.get(); *outSamplerState = dx11SamplerState.get();
mSamplerStateCache.Put(samplerState, std::move(dx11SamplerState)); mSamplerStateCache.Put(samplerState, std::move(dx11SamplerState));
return gl::NoError(); return angle::Result::Continue();
} }
} // namespace rx } // namespace rx
...@@ -70,19 +70,23 @@ class RenderStateCache : angle::NonCopyable ...@@ -70,19 +70,23 @@ class RenderStateCache : angle::NonCopyable
static d3d11::BlendStateKey GetBlendStateKey(const gl::Context *context, static d3d11::BlendStateKey GetBlendStateKey(const gl::Context *context,
Framebuffer11 *framebuffer11, Framebuffer11 *framebuffer11,
const gl::BlendState &blendState); const gl::BlendState &blendState);
gl::Error getBlendState(Renderer11 *renderer, angle::Result getBlendState(const gl::Context *context,
const d3d11::BlendStateKey &key, Renderer11 *renderer,
const d3d11::BlendState **outBlendState); const d3d11::BlendStateKey &key,
gl::Error getRasterizerState(Renderer11 *renderer, const d3d11::BlendState **outBlendState);
const gl::RasterizerState &rasterState, angle::Result getRasterizerState(const gl::Context *context,
bool scissorEnabled, Renderer11 *renderer,
ID3D11RasterizerState **outRasterizerState); const gl::RasterizerState &rasterState,
gl::Error getDepthStencilState(Renderer11 *renderer, bool scissorEnabled,
const gl::DepthStencilState &dsState, ID3D11RasterizerState **outRasterizerState);
const d3d11::DepthStencilState **outDSState); angle::Result getDepthStencilState(const gl::Context *context,
gl::Error getSamplerState(Renderer11 *renderer, Renderer11 *renderer,
const gl::SamplerState &samplerState, const gl::DepthStencilState &dsState,
ID3D11SamplerState **outSamplerState); const d3d11::DepthStencilState **outDSState);
angle::Result getSamplerState(const gl::Context *context,
Renderer11 *renderer,
const gl::SamplerState &samplerState,
ID3D11SamplerState **outSamplerState);
private: private:
// MSDN's documentation of ID3D11Device::CreateBlendState, ID3D11Device::CreateRasterizerState, // MSDN's documentation of ID3D11Device::CreateBlendState, ID3D11Device::CreateRasterizerState,
......
...@@ -3052,8 +3052,9 @@ gl::Error Renderer11::readFromAttachment(const gl::Context *context, ...@@ -3052,8 +3052,9 @@ gl::Error Renderer11::readFromAttachment(const gl::Context *context,
gl::Extents safeSize(safeArea.width, safeArea.height, 1); gl::Extents safeSize(safeArea.width, safeArea.height, 1);
TextureHelper11 stagingHelper; TextureHelper11 stagingHelper;
ANGLE_TRY(createStagingTexture(textureHelper.getTextureType(), textureHelper.getFormatSet(), ANGLE_TRY(createStagingTexture(context, textureHelper.getTextureType(),
safeSize, StagingAccess::READ, &stagingHelper)); textureHelper.getFormatSet(), safeSize, StagingAccess::READ,
&stagingHelper));
stagingHelper.setDebugName("readFromAttachment::stagingHelper"); stagingHelper.setDebugName("readFromAttachment::stagingHelper");
TextureHelper11 resolvedTextureHelper; TextureHelper11 resolvedTextureHelper;
...@@ -3126,10 +3127,10 @@ gl::Error Renderer11::readFromAttachment(const gl::Context *context, ...@@ -3126,10 +3127,10 @@ gl::Error Renderer11::readFromAttachment(const gl::Context *context,
return packPixels(context, stagingHelper, packParams, pixelsOut); return packPixels(context, stagingHelper, packParams, pixelsOut);
} }
gl::Error Renderer11::packPixels(const gl::Context *context, angle::Result Renderer11::packPixels(const gl::Context *context,
const TextureHelper11 &textureHelper, const TextureHelper11 &textureHelper,
const PackPixelsParams &params, const PackPixelsParams &params,
uint8_t *pixelsOut) uint8_t *pixelsOut)
{ {
ID3D11Resource *readResource = textureHelper.get(); ID3D11Resource *readResource = textureHelper.get();
...@@ -3146,7 +3147,7 @@ gl::Error Renderer11::packPixels(const gl::Context *context, ...@@ -3146,7 +3147,7 @@ gl::Error Renderer11::packPixels(const gl::Context *context,
mDeviceContext->Unmap(readResource, 0); mDeviceContext->Unmap(readResource, 0);
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error Renderer11::blitRenderbufferRect(const gl::Context *context, gl::Error Renderer11::blitRenderbufferRect(const gl::Context *context,
...@@ -3682,11 +3683,12 @@ gl::Error Renderer11::dispatchCompute(const gl::Context *context, ...@@ -3682,11 +3683,12 @@ gl::Error Renderer11::dispatchCompute(const gl::Context *context,
return gl::NoError(); return gl::NoError();
} }
gl::Error Renderer11::createStagingTexture(ResourceType textureType, angle::Result Renderer11::createStagingTexture(const gl::Context *context,
const d3d11::Format &formatSet, ResourceType textureType,
const gl::Extents &size, const d3d11::Format &formatSet,
StagingAccess readAndWriteAccess, const gl::Extents &size,
TextureHelper11 *textureOut) StagingAccess readAndWriteAccess,
TextureHelper11 *textureOut)
{ {
if (textureType == ResourceType::Texture2D) if (textureType == ResourceType::Texture2D)
{ {
...@@ -3708,8 +3710,8 @@ gl::Error Renderer11::createStagingTexture(ResourceType textureType, ...@@ -3708,8 +3710,8 @@ gl::Error Renderer11::createStagingTexture(ResourceType textureType,
stagingDesc.CPUAccessFlags |= D3D11_CPU_ACCESS_WRITE; stagingDesc.CPUAccessFlags |= D3D11_CPU_ACCESS_WRITE;
} }
ANGLE_TRY(allocateTexture(stagingDesc, formatSet, textureOut)); ANGLE_TRY_HANDLE(context, allocateTexture(stagingDesc, formatSet, textureOut));
return gl::NoError(); return angle::Result::Continue();
} }
ASSERT(textureType == ResourceType::Texture3D); ASSERT(textureType == ResourceType::Texture3D);
...@@ -3724,8 +3726,8 @@ gl::Error Renderer11::createStagingTexture(ResourceType textureType, ...@@ -3724,8 +3726,8 @@ gl::Error Renderer11::createStagingTexture(ResourceType textureType,
stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ; stagingDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
stagingDesc.MiscFlags = 0; stagingDesc.MiscFlags = 0;
ANGLE_TRY(allocateTexture(stagingDesc, formatSet, textureOut)); ANGLE_TRY_HANDLE(context, allocateTexture(stagingDesc, formatSet, textureOut));
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error Renderer11::allocateTexture(const D3D11_TEXTURE2D_DESC &desc, gl::Error Renderer11::allocateTexture(const D3D11_TEXTURE2D_DESC &desc,
...@@ -3736,7 +3738,7 @@ gl::Error Renderer11::allocateTexture(const D3D11_TEXTURE2D_DESC &desc, ...@@ -3736,7 +3738,7 @@ gl::Error Renderer11::allocateTexture(const D3D11_TEXTURE2D_DESC &desc,
d3d11::Texture2D texture; d3d11::Texture2D texture;
ANGLE_TRY(mResourceManager11.allocate(this, &desc, initData, &texture)); ANGLE_TRY(mResourceManager11.allocate(this, &desc, initData, &texture));
textureOut->init(std::move(texture), desc, format); textureOut->init(std::move(texture), desc, format);
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error Renderer11::allocateTexture(const D3D11_TEXTURE3D_DESC &desc, gl::Error Renderer11::allocateTexture(const D3D11_TEXTURE3D_DESC &desc,
...@@ -3747,32 +3749,37 @@ gl::Error Renderer11::allocateTexture(const D3D11_TEXTURE3D_DESC &desc, ...@@ -3747,32 +3749,37 @@ gl::Error Renderer11::allocateTexture(const D3D11_TEXTURE3D_DESC &desc,
d3d11::Texture3D texture; d3d11::Texture3D texture;
ANGLE_TRY(mResourceManager11.allocate(this, &desc, initData, &texture)); ANGLE_TRY(mResourceManager11.allocate(this, &desc, initData, &texture));
textureOut->init(std::move(texture), desc, format); textureOut->init(std::move(texture), desc, format);
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error Renderer11::getBlendState(const d3d11::BlendStateKey &key, angle::Result Renderer11::getBlendState(const gl::Context *context,
const d3d11::BlendState **outBlendState) const d3d11::BlendStateKey &key,
const d3d11::BlendState **outBlendState)
{ {
return mStateCache.getBlendState(this, key, outBlendState); return mStateCache.getBlendState(context, this, key, outBlendState);
} }
gl::Error Renderer11::getRasterizerState(const gl::RasterizerState &rasterState, angle::Result Renderer11::getRasterizerState(const gl::Context *context,
bool scissorEnabled, const gl::RasterizerState &rasterState,
ID3D11RasterizerState **outRasterizerState) bool scissorEnabled,
ID3D11RasterizerState **outRasterizerState)
{ {
return mStateCache.getRasterizerState(this, rasterState, scissorEnabled, outRasterizerState); return mStateCache.getRasterizerState(context, this, rasterState, scissorEnabled,
outRasterizerState);
} }
gl::Error Renderer11::getDepthStencilState(const gl::DepthStencilState &dsState, angle::Result Renderer11::getDepthStencilState(const gl::Context *context,
const d3d11::DepthStencilState **outDSState) const gl::DepthStencilState &dsState,
const d3d11::DepthStencilState **outDSState)
{ {
return mStateCache.getDepthStencilState(this, dsState, outDSState); return mStateCache.getDepthStencilState(context, this, dsState, outDSState);
} }
gl::Error Renderer11::getSamplerState(const gl::SamplerState &samplerState, angle::Result Renderer11::getSamplerState(const gl::Context *context,
ID3D11SamplerState **outSamplerState) const gl::SamplerState &samplerState,
ID3D11SamplerState **outSamplerState)
{ {
return mStateCache.getSamplerState(this, samplerState, outSamplerState); return mStateCache.getSamplerState(context, this, samplerState, outSamplerState);
} }
gl::Error Renderer11::clearRenderTarget(const gl::Context *context, gl::Error Renderer11::clearRenderTarget(const gl::Context *context,
...@@ -3823,28 +3830,16 @@ bool Renderer11::canSelectViewInVertexShader() const ...@@ -3823,28 +3830,16 @@ bool Renderer11::canSelectViewInVertexShader() const
getRenderer11DeviceCaps().supportsVpRtIndexWriteFromVertexShader; getRenderer11DeviceCaps().supportsVpRtIndexWriteFromVertexShader;
} }
gl::Error Renderer11::mapResource(const gl::Context *context, angle::Result Renderer11::mapResource(const gl::Context *context,
ID3D11Resource *resource, ID3D11Resource *resource,
UINT subResource, UINT subResource,
D3D11_MAP mapType, D3D11_MAP mapType,
UINT mapFlags, UINT mapFlags,
D3D11_MAPPED_SUBRESOURCE *mappedResource) D3D11_MAPPED_SUBRESOURCE *mappedResource)
{ {
HRESULT hr = mDeviceContext->Map(resource, subResource, mapType, mapFlags, mappedResource); HRESULT hr = mDeviceContext->Map(resource, subResource, mapType, mapFlags, mappedResource);
if (FAILED(hr)) ANGLE_TRY_HR(GetImplAs<Context11>(context), hr, "Failed to map D3D11 resource.");
{ return angle::Result::Continue();
if (d3d11::isDeviceLostError(hr))
{
this->notifyDeviceLost();
}
// Note: gl::OutOfMemory is used instead of gl::InternalError to avoid requiring
// additional context queries. This is needed as gl::InternalError corresponds to
// GL_INVALID_OPERATION, which does not uniquely identify a device reset error.
return gl::OutOfMemory() << "Failed to map D3D11 resource." << gl::FmtHR(hr);
}
return gl::NoError();
} }
gl::Error Renderer11::markTransformFeedbackUsage(const gl::Context *context) gl::Error Renderer11::markTransformFeedbackUsage(const gl::Context *context)
......
...@@ -310,15 +310,19 @@ class Renderer11 : public RendererD3D ...@@ -310,15 +310,19 @@ class Renderer11 : public RendererD3D
ID3D11DeviceContext1 *getDeviceContext1IfSupported() { return mDeviceContext1; }; ID3D11DeviceContext1 *getDeviceContext1IfSupported() { return mDeviceContext1; };
IDXGIFactory *getDxgiFactory() { return mDxgiFactory; }; IDXGIFactory *getDxgiFactory() { return mDxgiFactory; };
gl::Error getBlendState(const d3d11::BlendStateKey &key, angle::Result getBlendState(const gl::Context *context,
const d3d11::BlendState **outBlendState); const d3d11::BlendStateKey &key,
gl::Error getRasterizerState(const gl::RasterizerState &rasterState, const d3d11::BlendState **outBlendState);
bool scissorEnabled, angle::Result getRasterizerState(const gl::Context *context,
ID3D11RasterizerState **outRasterizerState); const gl::RasterizerState &rasterState,
gl::Error getDepthStencilState(const gl::DepthStencilState &dsState, bool scissorEnabled,
const d3d11::DepthStencilState **outDSState); ID3D11RasterizerState **outRasterizerState);
gl::Error getSamplerState(const gl::SamplerState &samplerState, angle::Result getDepthStencilState(const gl::Context *context,
ID3D11SamplerState **outSamplerState); const gl::DepthStencilState &dsState,
const d3d11::DepthStencilState **outDSState);
angle::Result getSamplerState(const gl::Context *context,
const gl::SamplerState &samplerState,
ID3D11SamplerState **outSamplerState);
Blit11 *getBlitter() { return mBlit; } Blit11 *getBlitter() { return mBlit; }
Clear11 *getClearer() { return mClear; } Clear11 *getClearer() { return mClear; }
...@@ -334,10 +338,10 @@ class Renderer11 : public RendererD3D ...@@ -334,10 +338,10 @@ class Renderer11 : public RendererD3D
GLenum sourcePixelsType, GLenum sourcePixelsType,
const gl::Box &destArea) override; const gl::Box &destArea) override;
gl::Error packPixels(const gl::Context *context, angle::Result packPixels(const gl::Context *context,
const TextureHelper11 &textureHelper, const TextureHelper11 &textureHelper,
const PackPixelsParams &params, const PackPixelsParams &params,
uint8_t *pixelsOut); uint8_t *pixelsOut);
bool getLUID(LUID *adapterLuid) const override; bool getLUID(LUID *adapterLuid) const override;
VertexConversionType getVertexConversionType( VertexConversionType getVertexConversionType(
...@@ -403,11 +407,12 @@ class Renderer11 : public RendererD3D ...@@ -403,11 +407,12 @@ class Renderer11 : public RendererD3D
GLuint numGroupsZ); GLuint numGroupsZ);
gl::Error applyComputeShader(const gl::Context *context); gl::Error applyComputeShader(const gl::Context *context);
gl::Error createStagingTexture(ResourceType textureType, angle::Result createStagingTexture(const gl::Context *context,
const d3d11::Format &formatSet, ResourceType textureType,
const gl::Extents &size, const d3d11::Format &formatSet,
StagingAccess readAndWriteAccess, const gl::Extents &size,
TextureHelper11 *textureOut); StagingAccess readAndWriteAccess,
TextureHelper11 *textureOut);
template <typename DescT, typename ResourceT> template <typename DescT, typename ResourceT>
gl::Error allocateResource(const DescT &desc, ResourceT *resourceOut) gl::Error allocateResource(const DescT &desc, ResourceT *resourceOut)
...@@ -455,12 +460,12 @@ class Renderer11 : public RendererD3D ...@@ -455,12 +460,12 @@ class Renderer11 : public RendererD3D
void onDirtyUniformBlockBinding(GLuint uniformBlockIndex) override; void onDirtyUniformBlockBinding(GLuint uniformBlockIndex) override;
gl::Error mapResource(const gl::Context *context, angle::Result mapResource(const gl::Context *context,
ID3D11Resource *resource, ID3D11Resource *resource,
UINT subResource, UINT subResource,
D3D11_MAP mapType, D3D11_MAP mapType,
UINT mapFlags, UINT mapFlags,
D3D11_MAPPED_SUBRESOURCE *mappedResource); D3D11_MAPPED_SUBRESOURCE *mappedResource);
gl::Error getIncompleteTexture(const gl::Context *context, gl::Error getIncompleteTexture(const gl::Context *context,
gl::TextureType type, gl::TextureType type,
......
...@@ -308,7 +308,7 @@ class ResourceManager11 final : angle::NonCopyable ...@@ -308,7 +308,7 @@ class ResourceManager11 final : angle::NonCopyable
Resource11<T> res; Resource11<T> res;
ANGLE_TRY(allocate(renderer, desc, initData, &res)); ANGLE_TRY(allocate(renderer, desc, initData, &res));
*sharedRes = std::move(res); *sharedRes = std::move(res);
return gl::NoError(); return angle::Result::Continue();
} }
template <typename T> template <typename T>
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
// executable implementation details. // executable implementation details.
#include "libANGLE/renderer/d3d/d3d11/ShaderExecutable11.h" #include "libANGLE/renderer/d3d/d3d11/ShaderExecutable11.h"
#include "libANGLE/Context.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" #include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
namespace rx namespace rx
...@@ -100,7 +102,9 @@ UniformStorage11::~UniformStorage11() ...@@ -100,7 +102,9 @@ UniformStorage11::~UniformStorage11()
{ {
} }
gl::Error UniformStorage11::getConstantBuffer(Renderer11 *renderer, const d3d11::Buffer **bufferOut) angle::Result UniformStorage11::getConstantBuffer(const gl::Context *context,
Renderer11 *renderer,
const d3d11::Buffer **bufferOut)
{ {
if (size() > 0 && !mConstantBuffer.valid()) if (size() > 0 && !mConstantBuffer.valid())
{ {
...@@ -109,11 +113,11 @@ gl::Error UniformStorage11::getConstantBuffer(Renderer11 *renderer, const d3d11: ...@@ -109,11 +113,11 @@ gl::Error UniformStorage11::getConstantBuffer(Renderer11 *renderer, const d3d11:
desc.Usage = D3D11_USAGE_DEFAULT; desc.Usage = D3D11_USAGE_DEFAULT;
desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
ANGLE_TRY(renderer->allocateResource(desc, &mConstantBuffer)); ANGLE_TRY_HANDLE(context, renderer->allocateResource(desc, &mConstantBuffer));
} }
*bufferOut = &mConstantBuffer; *bufferOut = &mConstantBuffer;
return gl::NoError(); return angle::Result::Continue();
} }
} // namespace rx } // namespace rx
...@@ -51,7 +51,9 @@ class UniformStorage11 : public UniformStorageD3D ...@@ -51,7 +51,9 @@ class UniformStorage11 : public UniformStorageD3D
UniformStorage11(size_t initialSize); UniformStorage11(size_t initialSize);
~UniformStorage11() override; ~UniformStorage11() override;
gl::Error getConstantBuffer(Renderer11 *renderer, const d3d11::Buffer **bufferOut); angle::Result getConstantBuffer(const gl::Context *context,
Renderer11 *renderer,
const d3d11::Buffer **bufferOut);
private: private:
d3d11::Buffer mConstantBuffer; d3d11::Buffer mConstantBuffer;
......
...@@ -100,8 +100,8 @@ UINT TransformFeedback11::getNumSOBuffers() const ...@@ -100,8 +100,8 @@ UINT TransformFeedback11::getNumSOBuffers() const
return static_cast<UINT>(mBuffers.size()); return static_cast<UINT>(mBuffers.size());
} }
gl::Error TransformFeedback11::getSOBuffers(const gl::Context *context, angle::Result TransformFeedback11::getSOBuffers(const gl::Context *context,
const std::vector<ID3D11Buffer *> **buffersOut) const std::vector<ID3D11Buffer *> **buffersOut)
{ {
for (size_t bindingIdx = 0; bindingIdx < mBuffers.size(); bindingIdx++) for (size_t bindingIdx = 0; bindingIdx < mBuffers.size(); bindingIdx++)
{ {
...@@ -115,7 +115,7 @@ gl::Error TransformFeedback11::getSOBuffers(const gl::Context *context, ...@@ -115,7 +115,7 @@ gl::Error TransformFeedback11::getSOBuffers(const gl::Context *context,
} }
*buffersOut = &mBuffers; *buffersOut = &mBuffers;
return gl::NoError(); return angle::Result::Continue();
} }
const std::vector<UINT> &TransformFeedback11::getSOBufferOffsets() const const std::vector<UINT> &TransformFeedback11::getSOBufferOffsets() const
......
...@@ -41,8 +41,8 @@ class TransformFeedback11 : public TransformFeedbackImpl ...@@ -41,8 +41,8 @@ class TransformFeedback11 : public TransformFeedbackImpl
bool isDirty() const; bool isDirty() const;
UINT getNumSOBuffers() const; UINT getNumSOBuffers() const;
gl::Error getSOBuffers(const gl::Context *context, angle::Result getSOBuffers(const gl::Context *context,
const std::vector<ID3D11Buffer *> **buffersOut); const std::vector<ID3D11Buffer *> **buffersOut);
const std::vector<UINT> &getSOBufferOffsets() const; const std::vector<UINT> &getSOBufferOffsets() const;
Serial getSerial() const; Serial getSerial() const;
......
...@@ -124,8 +124,8 @@ gl::Error VertexArray11::syncState(const gl::Context *context, ...@@ -124,8 +124,8 @@ gl::Error VertexArray11::syncState(const gl::Context *context,
return gl::NoError(); return gl::NoError();
} }
gl::Error VertexArray11::syncStateForDraw(const gl::Context *context, angle::Result VertexArray11::syncStateForDraw(const gl::Context *context,
const gl::DrawCallParams &drawCallParams) const gl::DrawCallParams &drawCallParams)
{ {
Renderer11 *renderer = GetImplAs<Context11>(context)->getRenderer(); Renderer11 *renderer = GetImplAs<Context11>(context)->getRenderer();
StateManager11 *stateManager = renderer->getStateManager(); StateManager11 *stateManager = renderer->getStateManager();
...@@ -182,18 +182,19 @@ gl::Error VertexArray11::syncStateForDraw(const gl::Context *context, ...@@ -182,18 +182,19 @@ gl::Error VertexArray11::syncStateForDraw(const gl::Context *context,
} }
} }
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error VertexArray11::updateElementArrayStorage(const gl::Context *context, angle::Result VertexArray11::updateElementArrayStorage(const gl::Context *context,
const gl::DrawCallParams &drawCallParams, const gl::DrawCallParams &drawCallParams,
bool restartEnabled) bool restartEnabled)
{ {
bool usePrimitiveRestartWorkaround = bool usePrimitiveRestartWorkaround =
UsePrimitiveRestartWorkaround(restartEnabled, drawCallParams.type()); UsePrimitiveRestartWorkaround(restartEnabled, drawCallParams.type());
ANGLE_TRY(GetIndexTranslationDestType(context, drawCallParams, usePrimitiveRestartWorkaround, ANGLE_TRY_HANDLE(
&mCachedDestinationIndexType)); context, GetIndexTranslationDestType(context, drawCallParams, usePrimitiveRestartWorkaround,
&mCachedDestinationIndexType));
unsigned int offset = unsigned int offset =
static_cast<unsigned int>(reinterpret_cast<uintptr_t>(drawCallParams.indices())); static_cast<unsigned int>(reinterpret_cast<uintptr_t>(drawCallParams.indices()));
...@@ -202,7 +203,7 @@ gl::Error VertexArray11::updateElementArrayStorage(const gl::Context *context, ...@@ -202,7 +203,7 @@ gl::Error VertexArray11::updateElementArrayStorage(const gl::Context *context,
ClassifyIndexStorage(context->getGLState(), mState.getElementArrayBuffer().get(), ClassifyIndexStorage(context->getGLState(), mState.getElementArrayBuffer().get(),
drawCallParams.type(), mCachedDestinationIndexType, offset); drawCallParams.type(), mCachedDestinationIndexType, offset);
return gl::NoError(); return angle::Result::Continue();
} }
void VertexArray11::updateVertexAttribStorage(const gl::Context *context, void VertexArray11::updateVertexAttribStorage(const gl::Context *context,
...@@ -237,8 +238,8 @@ bool VertexArray11::hasActiveDynamicAttrib(const gl::Context *context) ...@@ -237,8 +238,8 @@ bool VertexArray11::hasActiveDynamicAttrib(const gl::Context *context)
return activeDynamicAttribs.any(); return activeDynamicAttribs.any();
} }
gl::Error VertexArray11::updateDirtyAttribs(const gl::Context *context, angle::Result VertexArray11::updateDirtyAttribs(const gl::Context *context,
const gl::AttributesMask &activeDirtyAttribs) const gl::AttributesMask &activeDirtyAttribs)
{ {
const auto &glState = context->getGLState(); const auto &glState = context->getGLState();
const auto &attribs = mState.getVertexAttributes(); const auto &attribs = mState.getVertexAttributes();
...@@ -265,7 +266,8 @@ gl::Error VertexArray11::updateDirtyAttribs(const gl::Context *context, ...@@ -265,7 +266,8 @@ gl::Error VertexArray11::updateDirtyAttribs(const gl::Context *context,
break; break;
case VertexStorageType::STATIC: case VertexStorageType::STATIC:
{ {
ANGLE_TRY(VertexDataManager::StoreStaticAttrib(context, translatedAttrib)); ANGLE_TRY_HANDLE(context,
VertexDataManager::StoreStaticAttrib(context, translatedAttrib));
break; break;
} }
case VertexStorageType::CURRENT_VALUE: case VertexStorageType::CURRENT_VALUE:
...@@ -277,19 +279,19 @@ gl::Error VertexArray11::updateDirtyAttribs(const gl::Context *context, ...@@ -277,19 +279,19 @@ gl::Error VertexArray11::updateDirtyAttribs(const gl::Context *context,
} }
} }
return gl::NoError(); return angle::Result::Continue();
} }
gl::Error VertexArray11::updateDynamicAttribs(const gl::Context *context, angle::Result VertexArray11::updateDynamicAttribs(const gl::Context *context,
VertexDataManager *vertexDataManager, VertexDataManager *vertexDataManager,
const gl::DrawCallParams &drawCallParams, const gl::DrawCallParams &drawCallParams,
const gl::AttributesMask &activeDynamicAttribs) const gl::AttributesMask &activeDynamicAttribs)
{ {
const auto &glState = context->getGLState(); const auto &glState = context->getGLState();
const auto &attribs = mState.getVertexAttributes(); const auto &attribs = mState.getVertexAttributes();
const auto &bindings = mState.getVertexBindings(); const auto &bindings = mState.getVertexBindings();
ANGLE_TRY(drawCallParams.ensureIndexRangeResolved(context)); ANGLE_TRY_HANDLE(context, drawCallParams.ensureIndexRangeResolved(context));
for (size_t dynamicAttribIndex : activeDynamicAttribs) for (size_t dynamicAttribIndex : activeDynamicAttribs)
{ {
...@@ -303,14 +305,15 @@ gl::Error VertexArray11::updateDynamicAttribs(const gl::Context *context, ...@@ -303,14 +305,15 @@ gl::Error VertexArray11::updateDynamicAttribs(const gl::Context *context,
dynamicAttrib->divisor = dynamicAttrib->binding->getDivisor() * mAppliedNumViewsToDivisor; dynamicAttrib->divisor = dynamicAttrib->binding->getDivisor() * mAppliedNumViewsToDivisor;
} }
ANGLE_TRY(vertexDataManager->storeDynamicAttribs( ANGLE_TRY_HANDLE(context, vertexDataManager->storeDynamicAttribs(
context, &mTranslatedAttribs, activeDynamicAttribs, drawCallParams.firstVertex(), context, &mTranslatedAttribs, activeDynamicAttribs,
drawCallParams.vertexCount(), drawCallParams.instances())); drawCallParams.firstVertex(), drawCallParams.vertexCount(),
drawCallParams.instances()));
VertexDataManager::PromoteDynamicAttribs(context, mTranslatedAttribs, activeDynamicAttribs, VertexDataManager::PromoteDynamicAttribs(context, mTranslatedAttribs, activeDynamicAttribs,
drawCallParams.vertexCount()); drawCallParams.vertexCount());
return gl::NoError(); return angle::Result::Continue();
} }
const std::vector<TranslatedAttribute> &VertexArray11::getTranslatedAttribs() const const std::vector<TranslatedAttribute> &VertexArray11::getTranslatedAttribs() const
......
...@@ -33,8 +33,8 @@ class VertexArray11 : public VertexArrayImpl ...@@ -33,8 +33,8 @@ class VertexArray11 : public VertexArrayImpl
const gl::VertexArray::DirtyBindingBitsArray &bindingBits) override; const gl::VertexArray::DirtyBindingBitsArray &bindingBits) override;
// Applied buffer pointers are updated here. // Applied buffer pointers are updated here.
gl::Error syncStateForDraw(const gl::Context *context, angle::Result syncStateForDraw(const gl::Context *context,
const gl::DrawCallParams &drawCallParams); const gl::DrawCallParams &drawCallParams);
// This will check the dynamic attribs mask. // This will check the dynamic attribs mask.
bool hasActiveDynamicAttrib(const gl::Context *context); bool hasActiveDynamicAttrib(const gl::Context *context);
...@@ -47,11 +47,6 @@ class VertexArray11 : public VertexArrayImpl ...@@ -47,11 +47,6 @@ class VertexArray11 : public VertexArrayImpl
// is adjusted. // is adjusted.
void markAllAttributeDivisorsForAdjustment(int numViews); void markAllAttributeDivisorsForAdjustment(int numViews);
// Returns true if the element array buffer needs to be translated.
gl::Error updateElementArrayStorage(const gl::Context *context,
const gl::DrawCallParams &drawCallParams,
bool restartEnabled);
const TranslatedIndexData &getCachedIndexInfo() const; const TranslatedIndexData &getCachedIndexInfo() const;
void updateCachedIndexInfo(const TranslatedIndexData &indexInfo); void updateCachedIndexInfo(const TranslatedIndexData &indexInfo);
bool isCachedIndexInfoValid() const; bool isCachedIndexInfoValid() const;
...@@ -62,12 +57,16 @@ class VertexArray11 : public VertexArrayImpl ...@@ -62,12 +57,16 @@ class VertexArray11 : public VertexArrayImpl
void updateVertexAttribStorage(const gl::Context *context, void updateVertexAttribStorage(const gl::Context *context,
StateManager11 *stateManager, StateManager11 *stateManager,
size_t attribIndex); size_t attribIndex);
gl::Error updateDirtyAttribs(const gl::Context *context, angle::Result updateDirtyAttribs(const gl::Context *context,
const gl::AttributesMask &activeDirtyAttribs); const gl::AttributesMask &activeDirtyAttribs);
gl::Error updateDynamicAttribs(const gl::Context *context, angle::Result updateDynamicAttribs(const gl::Context *context,
VertexDataManager *vertexDataManager, VertexDataManager *vertexDataManager,
const gl::DrawCallParams &drawCallParams, const gl::DrawCallParams &drawCallParams,
const gl::AttributesMask &activeDynamicAttribs); const gl::AttributesMask &activeDynamicAttribs);
angle::Result updateElementArrayStorage(const gl::Context *context,
const gl::DrawCallParams &drawCallParams,
bool restartEnabled);
std::vector<VertexStorageType> mAttributeStorageTypes; std::vector<VertexStorageType> mAttributeStorageTypes;
std::vector<TranslatedAttribute> mTranslatedAttribs; std::vector<TranslatedAttribute> mTranslatedAttribs;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include "libANGLE/formatutils.h" #include "libANGLE/formatutils.h"
#include "libANGLE/renderer/d3d/BufferD3D.h" #include "libANGLE/renderer/d3d/BufferD3D.h"
#include "libANGLE/renderer/d3d/FramebufferD3D.h" #include "libANGLE/renderer/d3d/FramebufferD3D.h"
#include "libANGLE/renderer/d3d/d3d11/Context11.h"
#include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h" #include "libANGLE/renderer/d3d/d3d11/RenderTarget11.h"
#include "libANGLE/renderer/d3d/d3d11/Renderer11.h" #include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
#include "libANGLE/renderer/d3d/d3d11/dxgi_support_table.h" #include "libANGLE/renderer/d3d/d3d11/dxgi_support_table.h"
...@@ -2030,14 +2031,15 @@ void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsi ...@@ -2030,14 +2031,15 @@ void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsi
} }
} }
gl::Error GenerateInitialTextureData(const gl::Context *context, angle::Result GenerateInitialTextureData(
GLint internalFormat, const gl::Context *context,
const Renderer11DeviceCaps &renderer11DeviceCaps, GLint internalFormat,
GLuint width, const Renderer11DeviceCaps &renderer11DeviceCaps,
GLuint height, GLuint width,
GLuint depth, GLuint height,
GLuint mipLevels, GLuint depth,
gl::TexLevelArray<D3D11_SUBRESOURCE_DATA> *outSubresourceData) GLuint mipLevels,
gl::TexLevelArray<D3D11_SUBRESOURCE_DATA> *outSubresourceData)
{ {
const d3d11::Format &d3dFormatInfo = d3d11::Format::Get(internalFormat, renderer11DeviceCaps); const d3d11::Format &d3dFormatInfo = d3d11::Format::Get(internalFormat, renderer11DeviceCaps);
ASSERT(d3dFormatInfo.dataInitializerFunction != nullptr); ASSERT(d3dFormatInfo.dataInitializerFunction != nullptr);
...@@ -2050,7 +2052,8 @@ gl::Error GenerateInitialTextureData(const gl::Context *context, ...@@ -2050,7 +2052,8 @@ gl::Error GenerateInitialTextureData(const gl::Context *context,
unsigned int maxImageSize = depthPitch * depth; unsigned int maxImageSize = depthPitch * depth;
angle::MemoryBuffer *scratchBuffer = nullptr; angle::MemoryBuffer *scratchBuffer = nullptr;
ANGLE_TRY_ALLOCATION(context->getScratchBuffer(maxImageSize, &scratchBuffer)); ANGLE_CHECK_HR_ALLOC(GetImplAs<Context11>(context),
context->getScratchBuffer(maxImageSize, &scratchBuffer));
d3dFormatInfo.dataInitializerFunction(width, height, depth, scratchBuffer->data(), rowPitch, d3dFormatInfo.dataInitializerFunction(width, height, depth, scratchBuffer->data(), rowPitch,
depthPitch); depthPitch);
...@@ -2068,7 +2071,7 @@ gl::Error GenerateInitialTextureData(const gl::Context *context, ...@@ -2068,7 +2071,7 @@ gl::Error GenerateInitialTextureData(const gl::Context *context,
outSubresourceData->at(i).SysMemSlicePitch = mipDepthPitch; outSubresourceData->at(i).SysMemSlicePitch = mipDepthPitch;
} }
return gl::NoError(); return angle::Result::Continue();
} }
UINT GetPrimitiveRestartIndex() UINT GetPrimitiveRestartIndex()
...@@ -2177,7 +2180,7 @@ gl::Error LazyResource<ResourceT>::resolveImpl(Renderer11 *renderer, ...@@ -2177,7 +2180,7 @@ gl::Error LazyResource<ResourceT>::resolveImpl(Renderer11 *renderer,
ANGLE_TRY(renderer->allocateResource(desc, initData, &mResource)); ANGLE_TRY(renderer->allocateResource(desc, initData, &mResource));
mResource.setDebugName(name); mResource.setDebugName(name);
} }
return gl::NoError(); return angle::Result::Continue();
} }
template gl::Error LazyResource<ResourceType::BlendState>::resolveImpl(Renderer11 *renderer, template gl::Error LazyResource<ResourceType::BlendState>::resolveImpl(Renderer11 *renderer,
......
...@@ -97,14 +97,15 @@ ANGLED3D11DeviceType GetDeviceType(ID3D11Device *device); ...@@ -97,14 +97,15 @@ ANGLED3D11DeviceType GetDeviceType(ID3D11Device *device);
void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset); void MakeValidSize(bool isImage, DXGI_FORMAT format, GLsizei *requestWidth, GLsizei *requestHeight, int *levelOffset);
gl::Error GenerateInitialTextureData(const gl::Context *context, angle::Result GenerateInitialTextureData(
GLint internalFormat, const gl::Context *context,
const Renderer11DeviceCaps &renderer11DeviceCaps, GLint internalFormat,
GLuint width, const Renderer11DeviceCaps &renderer11DeviceCaps,
GLuint height, GLuint width,
GLuint depth, GLuint height,
GLuint mipLevels, GLuint depth,
gl::TexLevelArray<D3D11_SUBRESOURCE_DATA> *outSubresourceData); GLuint mipLevels,
gl::TexLevelArray<D3D11_SUBRESOURCE_DATA> *outSubresourceData);
UINT GetPrimitiveRestartIndex(); UINT GetPrimitiveRestartIndex();
...@@ -303,6 +304,18 @@ enum ReservedConstantBufferSlot ...@@ -303,6 +304,18 @@ enum ReservedConstantBufferSlot
}; };
void InitConstantBufferDesc(D3D11_BUFFER_DESC *constantBufferDescription, size_t byteWidth); void InitConstantBufferDesc(D3D11_BUFFER_DESC *constantBufferDescription, size_t byteWidth);
// Helper class for RAII patterning.
template <typename T>
class ScopedUnmapper final : angle::NonCopyable
{
public:
ScopedUnmapper(T *object) : mObject(object) {}
~ScopedUnmapper() { mObject->unmap(); }
private:
T *mObject;
};
} // namespace d3d11 } // namespace d3d11
struct GenericData struct GenericData
......
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