Commit dec86230 by Jamie Madill Committed by Commit Bot

Generalize Context scratch buffer errors.

This refactor will allow us to generate different error types in different backends. This makes Vulkan happy because it won't have to generate gl::Errors and can stay with vk::Error. Bug: angleproject:2713 Change-Id: I981402450f3b519d4f79851982547695d583355a Reviewed-on: https://chromium-review.googlesource.com/1128921 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarFrank Henigman <fjhenigman@chromium.org>
parent ca2ff38b
...@@ -259,6 +259,12 @@ std::string ToString(const T &value) ...@@ -259,6 +259,12 @@ std::string ToString(const T &value)
return gl::InternalError() << "Integer overflow."; \ return gl::InternalError() << "Integer overflow."; \
} }
#define ANGLE_TRY_ALLOCATION(result) \
if (!result) \
{ \
return gl::OutOfMemory() << "Failed to allocate internal buffer."; \
}
// The below inlining code lifted from V8. // The below inlining code lifted from V8.
#if defined(__clang__) || (defined(__GNUC__) && defined(__has_attribute)) #if defined(__clang__) || (defined(__GNUC__) && defined(__has_attribute))
#define ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline)) #define ANGLE_HAS_ATTRIBUTE_ALWAYS_INLINE (__has_attribute(always_inline))
......
...@@ -79,7 +79,8 @@ Error Buffer::bufferData(const Context *context, ...@@ -79,7 +79,8 @@ Error Buffer::bufferData(const Context *context,
if (context && context->getGLState().isRobustResourceInitEnabled() && !data && size > 0) if (context && context->getGLState().isRobustResourceInitEnabled() && !data && size > 0)
{ {
angle::MemoryBuffer *scratchBuffer = nullptr; angle::MemoryBuffer *scratchBuffer = nullptr;
ANGLE_TRY(context->getZeroFilledBuffer(static_cast<size_t>(size), &scratchBuffer)); ANGLE_TRY_ALLOCATION(
context->getZeroFilledBuffer(static_cast<size_t>(size), &scratchBuffer));
dataForImpl = scratchBuffer->data(); dataForImpl = scratchBuffer->data();
} }
......
...@@ -5021,24 +5021,16 @@ void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param) ...@@ -5021,24 +5021,16 @@ void Context::framebufferParameteri(GLenum target, GLenum pname, GLint param)
SetFramebufferParameteri(framebuffer, pname, param); SetFramebufferParameteri(framebuffer, pname, param);
} }
Error Context::getScratchBuffer(size_t requstedSizeBytes, bool Context::getScratchBuffer(size_t requstedSizeBytes,
angle::MemoryBuffer **scratchBufferOut) const angle::MemoryBuffer **scratchBufferOut) const
{ {
if (!mScratchBuffer.get(requstedSizeBytes, scratchBufferOut)) return mScratchBuffer.get(requstedSizeBytes, scratchBufferOut);
{
return OutOfMemory() << "Failed to allocate internal buffer.";
}
return NoError();
} }
Error Context::getZeroFilledBuffer(size_t requstedSizeBytes, bool Context::getZeroFilledBuffer(size_t requstedSizeBytes,
angle::MemoryBuffer **zeroBufferOut) const angle::MemoryBuffer **zeroBufferOut) const
{ {
if (!mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0)) return mZeroFilledBuffer.getInitialized(requstedSizeBytes, zeroBufferOut, 0);
{
return OutOfMemory() << "Failed to allocate internal buffer.";
}
return NoError();
} }
Error Context::prepareForDispatch() Error Context::prepareForDispatch()
......
...@@ -1404,8 +1404,8 @@ class Context final : public egl::LabeledObject, angle::NonCopyable ...@@ -1404,8 +1404,8 @@ class Context final : public egl::LabeledObject, angle::NonCopyable
rx::ContextImpl *getImplementation() const { return mImplementation.get(); } rx::ContextImpl *getImplementation() const { return mImplementation.get(); }
const Workarounds &getWorkarounds() const; const Workarounds &getWorkarounds() const;
Error getScratchBuffer(size_t requestedSizeBytes, angle::MemoryBuffer **scratchBufferOut) const; bool getScratchBuffer(size_t requestedSizeBytes, angle::MemoryBuffer **scratchBufferOut) const;
Error getZeroFilledBuffer(size_t requstedSizeBytes, angle::MemoryBuffer **zeroBufferOut) const; bool getZeroFilledBuffer(size_t requstedSizeBytes, angle::MemoryBuffer **zeroBufferOut) const;
Error prepareForDispatch(); Error prepareForDispatch();
......
...@@ -723,7 +723,8 @@ gl::Error TextureD3D::initializeContents(const gl::Context *context, ...@@ -723,7 +723,8 @@ gl::Error TextureD3D::initializeContents(const gl::Context *context,
zeroDataUnpackState.alignment = 1; zeroDataUnpackState.alignment = 1;
angle::MemoryBuffer *zeroBuffer = nullptr; angle::MemoryBuffer *zeroBuffer = nullptr;
ANGLE_TRY(context->getZeroFilledBuffer(imageBytes, &zeroBuffer)); ANGLE_TRY_ALLOCATION(context->getZeroFilledBuffer(imageBytes, &zeroBuffer));
if (shouldUseSetData(image)) if (shouldUseSetData(image))
{ {
ANGLE_TRY(mTexStorage->setData(context, imageIndex, image, nullptr, formatInfo.type, ANGLE_TRY(mTexStorage->setData(context, imageIndex, image, nullptr, formatInfo.type,
......
...@@ -206,11 +206,7 @@ gl::Error VertexDataManager::initialize() ...@@ -206,11 +206,7 @@ gl::Error VertexDataManager::initialize()
{ {
mStreamingBuffer.reset( mStreamingBuffer.reset(
new StreamingVertexBufferInterface(mFactory, INITIAL_STREAM_BUFFER_SIZE)); new StreamingVertexBufferInterface(mFactory, INITIAL_STREAM_BUFFER_SIZE));
if (!mStreamingBuffer) ANGLE_TRY_ALLOCATION(mStreamingBuffer);
{
return gl::OutOfMemory() << "Failed to allocate the streaming vertex buffer.";
}
return gl::NoError(); return gl::NoError();
} }
......
...@@ -502,10 +502,7 @@ gl::Error Buffer11::mapRange(const gl::Context *context, ...@@ -502,10 +502,7 @@ gl::Error Buffer11::mapRange(const gl::Context *context,
ANGLE_TRY_RESULT(getStagingStorage(context), mMappedStorage); ANGLE_TRY_RESULT(getStagingStorage(context), mMappedStorage);
} }
if (!mMappedStorage) ANGLE_TRY_ALLOCATION(mMappedStorage);
{
return gl::OutOfMemory() << "Failed to allocate mappable internal buffer.";
}
if ((access & GL_MAP_WRITE_BIT) > 0) if ((access & GL_MAP_WRITE_BIT) > 0)
{ {
......
...@@ -3649,10 +3649,7 @@ FramebufferImpl *Renderer11::createDefaultFramebuffer(const gl::FramebufferState ...@@ -3649,10 +3649,7 @@ FramebufferImpl *Renderer11::createDefaultFramebuffer(const gl::FramebufferState
gl::Error Renderer11::getScratchMemoryBuffer(size_t requestedSize, angle::MemoryBuffer **bufferOut) gl::Error Renderer11::getScratchMemoryBuffer(size_t requestedSize, angle::MemoryBuffer **bufferOut)
{ {
if (!mScratchMemoryBuffer.get(requestedSize, bufferOut)) ANGLE_TRY_ALLOCATION(mScratchMemoryBuffer.get(requestedSize, bufferOut));
{
return gl::OutOfMemory() << "Failed to allocate internal buffer.";
}
return gl::NoError(); return gl::NoError();
} }
......
...@@ -601,7 +601,8 @@ gl::Error BlitGL::copySubTextureCPUReadback(const gl::Context *context, ...@@ -601,7 +601,8 @@ gl::Error BlitGL::copySubTextureCPUReadback(const gl::Context *context,
size_t destBufferSize = size_t destBufferSize =
sourceArea.width * sourceArea.height * destInternalFormatInfo.pixelBytes; sourceArea.width * sourceArea.height * destInternalFormatInfo.pixelBytes;
angle::MemoryBuffer *buffer = nullptr; angle::MemoryBuffer *buffer = nullptr;
ANGLE_TRY(context->getScratchBuffer(sourceBufferSize + destBufferSize, &buffer)); ANGLE_TRY_ALLOCATION(context->getScratchBuffer(sourceBufferSize + destBufferSize, &buffer));
uint8_t *sourceMemory = buffer->data(); uint8_t *sourceMemory = buffer->data();
uint8_t *destMemory = buffer->data() + sourceBufferSize; uint8_t *destMemory = buffer->data() + sourceBufferSize;
......
...@@ -600,7 +600,7 @@ gl::Error TextureGL::copyImage(const gl::Context *context, ...@@ -600,7 +600,7 @@ gl::Error TextureGL::copyImage(const gl::Context *context,
GLuint pixelBytes = GLuint pixelBytes =
gl::GetInternalFormatInfo(copyTexImageFormat.internalFormat, type).pixelBytes; gl::GetInternalFormatInfo(copyTexImageFormat.internalFormat, type).pixelBytes;
angle::MemoryBuffer *zero; angle::MemoryBuffer *zero;
ANGLE_TRY(context->getZeroFilledBuffer( ANGLE_TRY_ALLOCATION(context->getZeroFilledBuffer(
origSourceArea.width * origSourceArea.height * pixelBytes, &zero)); origSourceArea.width * origSourceArea.height * pixelBytes, &zero));
gl::PixelUnpackState unpack; gl::PixelUnpackState unpack;
...@@ -1539,7 +1539,7 @@ gl::Error TextureGL::initializeContents(const gl::Context *context, ...@@ -1539,7 +1539,7 @@ gl::Error TextureGL::initializeContents(const gl::Context *context,
internalFormatInfo.computeCompressedImageSize(desc.size, &imageSize)); internalFormatInfo.computeCompressedImageSize(desc.size, &imageSize));
angle::MemoryBuffer *zero; angle::MemoryBuffer *zero;
ANGLE_TRY(context->getZeroFilledBuffer(imageSize, &zero)); ANGLE_TRY_ALLOCATION(context->getZeroFilledBuffer(imageSize, &zero));
// WebGL spec requires that zero data is uploaded to compressed textures even if it might // WebGL spec requires that zero data is uploaded to compressed textures even if it might
// not result in zero color data. // not result in zero color data.
...@@ -1569,7 +1569,7 @@ gl::Error TextureGL::initializeContents(const gl::Context *context, ...@@ -1569,7 +1569,7 @@ gl::Error TextureGL::initializeContents(const gl::Context *context,
&imageSize)); &imageSize));
angle::MemoryBuffer *zero; angle::MemoryBuffer *zero;
ANGLE_TRY(context->getZeroFilledBuffer(imageSize, &zero)); ANGLE_TRY_ALLOCATION(context->getZeroFilledBuffer(imageSize, &zero));
if (nativegl::UseTexImage2D(getType())) if (nativegl::UseTexImage2D(getType()))
{ {
......
...@@ -229,7 +229,7 @@ gl::Error PixelBuffer::stageSubresourceUpdateFromFramebuffer(const gl::Context * ...@@ -229,7 +229,7 @@ gl::Error PixelBuffer::stageSubresourceUpdateFromFramebuffer(const gl::Context *
size_t bufferSize = size_t bufferSize =
storageFormat.pixelBytes * clippedRectangle.width * clippedRectangle.height; storageFormat.pixelBytes * clippedRectangle.width * clippedRectangle.height;
angle::MemoryBuffer *memoryBuffer = nullptr; angle::MemoryBuffer *memoryBuffer = nullptr;
ANGLE_TRY(context->getScratchBuffer(bufferSize, &memoryBuffer)); ANGLE_TRY_ALLOCATION(context->getScratchBuffer(bufferSize, &memoryBuffer));
// Read into the scratch buffer // Read into the scratch buffer
ANGLE_TRY( ANGLE_TRY(
......
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