Commit e4aa679c by Jamie Madill Committed by Commit Bot

Texture: Pass explicit unpack buffer to setImage.

This will allow us to call setImage internally even if there's an unpack buffer bound. Useful when implementing robust resource init with copyTexImage in some edge cases. Bug: angleproject:4517 Change-Id: I7e8e9536ab9222c620e572f7b6c20b08fa29d646 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2133088 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarCourtney Goeltzenleuchter <courtneygo@google.com> Reviewed-by: 's avatarCody Northrop <cnorthrop@google.com>
parent dd00f16b
...@@ -4012,9 +4012,11 @@ void Context::texImage2D(TextureTarget target, ...@@ -4012,9 +4012,11 @@ void Context::texImage2D(TextureTarget target,
{ {
ANGLE_CONTEXT_TRY(syncStateForTexImage()); ANGLE_CONTEXT_TRY(syncStateForTexImage());
gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Extents size(width, height, 1); Extents size(width, height, 1);
Texture *texture = getTextureByTarget(target); Texture *texture = getTextureByTarget(target);
ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(), target, level, ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(), unpackBuffer, target, level,
internalformat, size, format, type, internalformat, size, format, type,
static_cast<const uint8_t *>(pixels))); static_cast<const uint8_t *>(pixels)));
} }
...@@ -4046,9 +4048,11 @@ void Context::texImage3D(TextureTarget target, ...@@ -4046,9 +4048,11 @@ void Context::texImage3D(TextureTarget target,
{ {
ANGLE_CONTEXT_TRY(syncStateForTexImage()); ANGLE_CONTEXT_TRY(syncStateForTexImage());
gl::Buffer *unpackBuffer = mState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
Extents size(width, height, depth); Extents size(width, height, depth);
Texture *texture = getTextureByTarget(target); Texture *texture = getTextureByTarget(target);
ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(), target, level, ANGLE_CONTEXT_TRY(texture->setImage(this, mState.getUnpackState(), unpackBuffer, target, level,
internalformat, size, format, type, internalformat, size, format, type,
static_cast<const uint8_t *>(pixels))); static_cast<const uint8_t *>(pixels)));
} }
......
...@@ -111,12 +111,13 @@ TEST(ImageTest, RespecificationReleasesReferences) ...@@ -111,12 +111,13 @@ TEST(ImageTest, RespecificationReleasesReferences)
gl::PixelUnpackState defaultUnpackState; gl::PixelUnpackState defaultUnpackState;
EXPECT_CALL(*textureImpl, setImage(_, _, _, _, _, _, _, _)) EXPECT_CALL(*textureImpl, setImage(_, _, _, _, _, _, _, _, _))
.WillOnce(Return(angle::Result::Continue)) .WillOnce(Return(angle::Result::Continue))
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_EQ(angle::Result::Continue, EXPECT_EQ(
texture->setImage(nullptr, defaultUnpackState, gl::TextureTarget::_2D, 0, GL_RGBA8, angle::Result::Continue,
gl::Extents(1, 1, 1), GL_RGBA, GL_UNSIGNED_BYTE, nullptr)); texture->setImage(nullptr, defaultUnpackState, nullptr, gl::TextureTarget::_2D, 0, GL_RGBA8,
gl::Extents(1, 1, 1), GL_RGBA, GL_UNSIGNED_BYTE, nullptr));
EXPECT_CALL(mockEGLFactory, createImage(_, _, _, _)) EXPECT_CALL(mockEGLFactory, createImage(_, _, _, _))
.WillOnce(CreateMockImageImpl()) .WillOnce(CreateMockImageImpl())
...@@ -135,13 +136,14 @@ TEST(ImageTest, RespecificationReleasesReferences) ...@@ -135,13 +136,14 @@ TEST(ImageTest, RespecificationReleasesReferences)
EXPECT_CALL(*imageImpl, orphan(_, _)) EXPECT_CALL(*imageImpl, orphan(_, _))
.WillOnce(Return(angle::Result::Continue)) .WillOnce(Return(angle::Result::Continue))
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_CALL(*textureImpl, setImage(_, _, _, _, _, _, _, _)) EXPECT_CALL(*textureImpl, setImage(_, _, _, _, _, _, _, _, _))
.WillOnce(Return(angle::Result::Continue)) .WillOnce(Return(angle::Result::Continue))
.RetiresOnSaturation(); .RetiresOnSaturation();
EXPECT_EQ(angle::Result::Continue, EXPECT_EQ(
texture->setImage(nullptr, defaultUnpackState, gl::TextureTarget::_2D, 0, GL_RGBA8, angle::Result::Continue,
gl::Extents(1, 1, 1), GL_RGBA, GL_UNSIGNED_BYTE, nullptr)); texture->setImage(nullptr, defaultUnpackState, nullptr, gl::TextureTarget::_2D, 0, GL_RGBA8,
gl::Extents(1, 1, 1), GL_RGBA, GL_UNSIGNED_BYTE, nullptr));
EXPECT_EQ(1u, texture->getRefCount()); EXPECT_EQ(1u, texture->getRefCount());
EXPECT_EQ(1u, image->getRefCount()); EXPECT_EQ(1u, image->getRefCount());
......
...@@ -37,16 +37,17 @@ size_t GetImageDescIndex(TextureTarget target, size_t level) ...@@ -37,16 +37,17 @@ size_t GetImageDescIndex(TextureTarget target, size_t level)
: level; : level;
} }
InitState DetermineInitState(const Context *context, const uint8_t *pixels) InitState DetermineInitState(const Context *context,
gl::Buffer *unpackBuffer,
const uint8_t *pixels)
{ {
// Can happen in tests. // Can happen in tests.
if (!context || !context->isRobustResourceInitEnabled()) if (!context || !context->isRobustResourceInitEnabled())
{
return InitState::Initialized; return InitState::Initialized;
}
const auto &glState = context->getState(); return (!pixels && !unpackBuffer) ? InitState::MayNeedInit : InitState::Initialized;
return (pixels == nullptr && glState.getTargetBuffer(gl::BufferBinding::PixelUnpack) == nullptr)
? InitState::MayNeedInit
: InitState::Initialized;
} }
} // namespace } // namespace
...@@ -1043,6 +1044,7 @@ void Texture::signalDirtyState(size_t dirtyBit) ...@@ -1043,6 +1044,7 @@ void Texture::signalDirtyState(size_t dirtyBit)
angle::Result Texture::setImage(Context *context, angle::Result Texture::setImage(Context *context,
const PixelUnpackState &unpackState, const PixelUnpackState &unpackState,
Buffer *unpackBuffer,
TextureTarget target, TextureTarget target,
GLint level, GLint level,
GLenum internalFormat, GLenum internalFormat,
...@@ -1060,9 +1062,9 @@ angle::Result Texture::setImage(Context *context, ...@@ -1060,9 +1062,9 @@ angle::Result Texture::setImage(Context *context,
ImageIndex index = ImageIndex::MakeFromTarget(target, level, size.depth); ImageIndex index = ImageIndex::MakeFromTarget(target, level, size.depth);
ANGLE_TRY(mTexture->setImage(context, index, internalFormat, size, format, type, unpackState, ANGLE_TRY(mTexture->setImage(context, index, internalFormat, size, format, type, unpackState,
pixels)); unpackBuffer, pixels));
InitState initState = DetermineInitState(context, pixels); InitState initState = DetermineInitState(context, unpackBuffer, pixels);
mState.setImageDesc(target, level, ImageDesc(size, Format(internalFormat, type), initState)); mState.setImageDesc(target, level, ImageDesc(size, Format(internalFormat, type), initState));
ANGLE_TRY(handleMipmapGenerationHint(context, level)); ANGLE_TRY(handleMipmapGenerationHint(context, level));
...@@ -1118,7 +1120,9 @@ angle::Result Texture::setCompressedImage(Context *context, ...@@ -1118,7 +1120,9 @@ angle::Result Texture::setCompressedImage(Context *context,
ANGLE_TRY(mTexture->setCompressedImage(context, index, internalFormat, size, unpackState, ANGLE_TRY(mTexture->setCompressedImage(context, index, internalFormat, size, unpackState,
imageSize, pixels)); imageSize, pixels));
InitState initState = DetermineInitState(context, pixels); gl::Buffer *unpackBuffer = context->getState().getTargetBuffer(gl::BufferBinding::PixelUnpack);
InitState initState = DetermineInitState(context, unpackBuffer, pixels);
mState.setImageDesc(target, level, ImageDesc(size, Format(internalFormat), initState)); mState.setImageDesc(target, level, ImageDesc(size, Format(internalFormat), initState));
signalDirtyStorage(initState); signalDirtyStorage(initState);
......
...@@ -317,6 +317,7 @@ class Texture final : public RefCountObject<TextureID>, ...@@ -317,6 +317,7 @@ class Texture final : public RefCountObject<TextureID>,
angle::Result setImage(Context *context, angle::Result setImage(Context *context,
const PixelUnpackState &unpackState, const PixelUnpackState &unpackState,
Buffer *unpackBuffer,
TextureTarget target, TextureTarget target,
GLint level, GLint level,
GLenum internalFormat, GLenum internalFormat,
......
...@@ -56,6 +56,7 @@ class TextureImpl : public FramebufferAttachmentObjectImpl, public angle::Subjec ...@@ -56,6 +56,7 @@ class TextureImpl : public FramebufferAttachmentObjectImpl, public angle::Subjec
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) = 0; const uint8_t *pixels) = 0;
virtual angle::Result setSubImage(const gl::Context *context, virtual angle::Result setSubImage(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
......
...@@ -21,7 +21,7 @@ class MockTextureImpl : public TextureImpl ...@@ -21,7 +21,7 @@ class MockTextureImpl : public TextureImpl
public: public:
MockTextureImpl() : TextureImpl(mMockState), mMockState(gl::TextureType::_2D) {} MockTextureImpl() : TextureImpl(mMockState), mMockState(gl::TextureType::_2D) {}
virtual ~MockTextureImpl() { destructor(); } virtual ~MockTextureImpl() { destructor(); }
MOCK_METHOD8(setImage, MOCK_METHOD9(setImage,
angle::Result(const gl::Context *, angle::Result(const gl::Context *,
const gl::ImageIndex &, const gl::ImageIndex &,
GLenum, GLenum,
...@@ -29,6 +29,7 @@ class MockTextureImpl : public TextureImpl ...@@ -29,6 +29,7 @@ class MockTextureImpl : public TextureImpl
GLenum, GLenum,
GLenum, GLenum,
const gl::PixelUnpackState &, const gl::PixelUnpackState &,
gl::Buffer *,
const uint8_t *)); const uint8_t *));
MOCK_METHOD8(setSubImage, MOCK_METHOD8(setSubImage,
angle::Result(const gl::Context *, angle::Result(const gl::Context *,
......
...@@ -345,6 +345,7 @@ class RendererD3D : public BufferFactoryD3D ...@@ -345,6 +345,7 @@ class RendererD3D : public BufferFactoryD3D
virtual bool supportsFastCopyBufferToTexture(GLenum internalFormat) const = 0; virtual bool supportsFastCopyBufferToTexture(GLenum internalFormat) const = 0;
virtual angle::Result fastCopyBufferToTexture(const gl::Context *context, virtual angle::Result fastCopyBufferToTexture(const gl::Context *context,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
unsigned int offset, unsigned int offset,
RenderTargetD3D *destRenderTarget, RenderTargetD3D *destRenderTarget,
GLenum destinationFormat, GLenum destinationFormat,
......
...@@ -226,11 +226,11 @@ angle::Result TextureD3D::setImageImpl(const gl::Context *context, ...@@ -226,11 +226,11 @@ angle::Result TextureD3D::setImageImpl(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels, const uint8_t *pixels,
ptrdiff_t layerOffset) ptrdiff_t layerOffset)
{ {
ImageD3D *image = getImage(index); ImageD3D *image = getImage(index);
gl::Buffer *unpackBuffer = context->getState().getTargetBuffer(gl::BufferBinding::PixelUnpack);
ASSERT(image); ASSERT(image);
// No-op // No-op
...@@ -363,6 +363,7 @@ bool TextureD3D::isFastUnpackable(const gl::Buffer *unpackBuffer, GLenum sizedIn ...@@ -363,6 +363,7 @@ bool TextureD3D::isFastUnpackable(const gl::Buffer *unpackBuffer, GLenum sizedIn
angle::Result TextureD3D::fastUnpackPixels(const gl::Context *context, angle::Result TextureD3D::fastUnpackPixels(const gl::Context *context,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels, const uint8_t *pixels,
const gl::Box &destArea, const gl::Box &destArea,
GLenum sizedInternalFormat, GLenum sizedInternalFormat,
...@@ -386,9 +387,9 @@ angle::Result TextureD3D::fastUnpackPixels(const gl::Context *context, ...@@ -386,9 +387,9 @@ angle::Result TextureD3D::fastUnpackPixels(const gl::Context *context,
uintptr_t offset = reinterpret_cast<uintptr_t>(pixels); uintptr_t offset = reinterpret_cast<uintptr_t>(pixels);
ANGLE_TRY(mRenderer->fastCopyBufferToTexture(context, unpack, static_cast<unsigned int>(offset), ANGLE_TRY(mRenderer->fastCopyBufferToTexture(
destRenderTarget, sizedInternalFormat, type, context, unpack, unpackBuffer, static_cast<unsigned int>(offset), destRenderTarget,
destArea)); sizedInternalFormat, type, destArea));
return angle::Result::Continue; return angle::Result::Continue;
} }
...@@ -889,6 +890,7 @@ angle::Result TextureD3D_2D::setImage(const gl::Context *context, ...@@ -889,6 +890,7 @@ angle::Result TextureD3D_2D::setImage(const gl::Context *context,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) const uint8_t *pixels)
{ {
ASSERT((index.getTarget() == gl::TextureTarget::_2D || ASSERT((index.getTarget() == gl::TextureTarget::_2D ||
...@@ -903,7 +905,6 @@ angle::Result TextureD3D_2D::setImage(const gl::Context *context, ...@@ -903,7 +905,6 @@ angle::Result TextureD3D_2D::setImage(const gl::Context *context,
size, false)); size, false));
// Attempt a fast gpu copy of the pixel data to the surface // Attempt a fast gpu copy of the pixel data to the surface
gl::Buffer *unpackBuffer = context->getState().getTargetBuffer(gl::BufferBinding::PixelUnpack);
if (mTexStorage) if (mTexStorage)
{ {
ANGLE_TRY(mTexStorage->releaseMultisampledTexStorageForLevel(index.getLevelIndex())); ANGLE_TRY(mTexStorage->releaseMultisampledTexStorageForLevel(index.getLevelIndex()));
...@@ -918,7 +919,7 @@ angle::Result TextureD3D_2D::setImage(const gl::Context *context, ...@@ -918,7 +919,7 @@ angle::Result TextureD3D_2D::setImage(const gl::Context *context,
gl::Box destArea(0, 0, 0, getWidth(index.getLevelIndex()), getHeight(index.getLevelIndex()), gl::Box destArea(0, 0, 0, getWidth(index.getLevelIndex()), getHeight(index.getLevelIndex()),
1); 1);
ANGLE_TRY(fastUnpackPixels(context, unpack, pixels, destArea, ANGLE_TRY(fastUnpackPixels(context, unpack, unpackBuffer, pixels, destArea,
internalFormatInfo.sizedInternalFormat, type, destRenderTarget)); internalFormatInfo.sizedInternalFormat, type, destRenderTarget));
// Ensure we don't overwrite our newly initialized data // Ensure we don't overwrite our newly initialized data
...@@ -929,7 +930,7 @@ angle::Result TextureD3D_2D::setImage(const gl::Context *context, ...@@ -929,7 +930,7 @@ angle::Result TextureD3D_2D::setImage(const gl::Context *context,
if (!fastUnpacked) if (!fastUnpacked)
{ {
ANGLE_TRY(setImageImpl(context, index, type, unpack, pixels, 0)); ANGLE_TRY(setImageImpl(context, index, type, unpack, unpackBuffer, pixels, 0));
} }
return angle::Result::Continue; return angle::Result::Continue;
...@@ -957,7 +958,8 @@ angle::Result TextureD3D_2D::setSubImage(const gl::Context *context, ...@@ -957,7 +958,8 @@ angle::Result TextureD3D_2D::setSubImage(const gl::Context *context,
ANGLE_TRY(getRenderTarget(context, index, getRenderToTextureSamples(), &renderTarget)); ANGLE_TRY(getRenderTarget(context, index, getRenderToTextureSamples(), &renderTarget));
ASSERT(!mImageArray[index.getLevelIndex()]->isDirty()); ASSERT(!mImageArray[index.getLevelIndex()]->isDirty());
return fastUnpackPixels(context, unpack, pixels, area, mipFormat, type, renderTarget); return fastUnpackPixels(context, unpack, unpackBuffer, pixels, area, mipFormat, type,
renderTarget);
} }
else else
{ {
...@@ -1692,6 +1694,7 @@ angle::Result TextureD3D_Cube::setImage(const gl::Context *context, ...@@ -1692,6 +1694,7 @@ angle::Result TextureD3D_Cube::setImage(const gl::Context *context,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) const uint8_t *pixels)
{ {
ASSERT(size.depth == 1); ASSERT(size.depth == 1);
...@@ -1700,7 +1703,7 @@ angle::Result TextureD3D_Cube::setImage(const gl::Context *context, ...@@ -1700,7 +1703,7 @@ angle::Result TextureD3D_Cube::setImage(const gl::Context *context,
ANGLE_TRY(redefineImage(context, index.cubeMapFaceIndex(), index.getLevelIndex(), ANGLE_TRY(redefineImage(context, index.cubeMapFaceIndex(), index.getLevelIndex(),
internalFormatInfo.sizedInternalFormat, size, false)); internalFormatInfo.sizedInternalFormat, size, false));
return setImageImpl(context, index, type, unpack, pixels, 0); return setImageImpl(context, index, type, unpack, unpackBuffer, pixels, 0);
} }
angle::Result TextureD3D_Cube::setSubImage(const gl::Context *context, angle::Result TextureD3D_Cube::setSubImage(const gl::Context *context,
...@@ -2425,6 +2428,7 @@ angle::Result TextureD3D_3D::setImage(const gl::Context *context, ...@@ -2425,6 +2428,7 @@ angle::Result TextureD3D_3D::setImage(const gl::Context *context,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) const uint8_t *pixels)
{ {
ASSERT(index.getTarget() == gl::TextureTarget::_3D); ASSERT(index.getTarget() == gl::TextureTarget::_3D);
...@@ -2436,7 +2440,6 @@ angle::Result TextureD3D_3D::setImage(const gl::Context *context, ...@@ -2436,7 +2440,6 @@ angle::Result TextureD3D_3D::setImage(const gl::Context *context,
bool fastUnpacked = false; bool fastUnpacked = false;
// Attempt a fast gpu copy of the pixel data to the surface if the app bound an unpack buffer // Attempt a fast gpu copy of the pixel data to the surface if the app bound an unpack buffer
gl::Buffer *unpackBuffer = context->getState().getTargetBuffer(gl::BufferBinding::PixelUnpack);
if (isFastUnpackable(unpackBuffer, internalFormatInfo.sizedInternalFormat) && !size.empty() && if (isFastUnpackable(unpackBuffer, internalFormatInfo.sizedInternalFormat) && !size.empty() &&
isLevelComplete(index.getLevelIndex())) isLevelComplete(index.getLevelIndex()))
{ {
...@@ -2447,7 +2450,7 @@ angle::Result TextureD3D_3D::setImage(const gl::Context *context, ...@@ -2447,7 +2450,7 @@ angle::Result TextureD3D_3D::setImage(const gl::Context *context,
gl::Box destArea(0, 0, 0, getWidth(index.getLevelIndex()), getHeight(index.getLevelIndex()), gl::Box destArea(0, 0, 0, getWidth(index.getLevelIndex()), getHeight(index.getLevelIndex()),
getDepth(index.getLevelIndex())); getDepth(index.getLevelIndex()));
ANGLE_TRY(fastUnpackPixels(context, unpack, pixels, destArea, ANGLE_TRY(fastUnpackPixels(context, unpack, unpackBuffer, pixels, destArea,
internalFormatInfo.sizedInternalFormat, type, destRenderTarget)); internalFormatInfo.sizedInternalFormat, type, destRenderTarget));
// Ensure we don't overwrite our newly initialized data // Ensure we don't overwrite our newly initialized data
...@@ -2458,7 +2461,7 @@ angle::Result TextureD3D_3D::setImage(const gl::Context *context, ...@@ -2458,7 +2461,7 @@ angle::Result TextureD3D_3D::setImage(const gl::Context *context,
if (!fastUnpacked) if (!fastUnpacked)
{ {
ANGLE_TRY(setImageImpl(context, index, type, unpack, pixels, 0)); ANGLE_TRY(setImageImpl(context, index, type, unpack, unpackBuffer, pixels, 0));
} }
return angle::Result::Continue; return angle::Result::Continue;
...@@ -2483,7 +2486,8 @@ angle::Result TextureD3D_3D::setSubImage(const gl::Context *context, ...@@ -2483,7 +2486,8 @@ angle::Result TextureD3D_3D::setSubImage(const gl::Context *context,
ANGLE_TRY(getRenderTarget(context, index, getRenderToTextureSamples(), &destRenderTarget)); ANGLE_TRY(getRenderTarget(context, index, getRenderToTextureSamples(), &destRenderTarget));
ASSERT(!mImageArray[index.getLevelIndex()]->isDirty()); ASSERT(!mImageArray[index.getLevelIndex()]->isDirty());
return fastUnpackPixels(context, unpack, pixels, area, mipFormat, type, destRenderTarget); return fastUnpackPixels(context, unpack, unpackBuffer, pixels, area, mipFormat, type,
destRenderTarget);
} }
else else
{ {
...@@ -3090,6 +3094,7 @@ angle::Result TextureD3D_2DArray::setImage(const gl::Context *context, ...@@ -3090,6 +3094,7 @@ angle::Result TextureD3D_2DArray::setImage(const gl::Context *context,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) const uint8_t *pixels)
{ {
ASSERT(index.getTarget() == gl::TextureTarget::_2DArray); ASSERT(index.getTarget() == gl::TextureTarget::_2DArray);
...@@ -3110,7 +3115,8 @@ angle::Result TextureD3D_2DArray::setImage(const gl::Context *context, ...@@ -3110,7 +3115,8 @@ angle::Result TextureD3D_2DArray::setImage(const gl::Context *context,
{ {
const ptrdiff_t layerOffset = (inputDepthPitch * i); const ptrdiff_t layerOffset = (inputDepthPitch * i);
gl::ImageIndex layerIndex = gl::ImageIndex::Make2DArray(index.getLevelIndex(), i); gl::ImageIndex layerIndex = gl::ImageIndex::Make2DArray(index.getLevelIndex(), i);
ANGLE_TRY(setImageImpl(context, layerIndex, type, unpack, pixels, layerOffset)); ANGLE_TRY(
setImageImpl(context, layerIndex, type, unpack, unpackBuffer, pixels, layerOffset));
} }
return angle::Result::Continue; return angle::Result::Continue;
...@@ -3806,6 +3812,7 @@ angle::Result TextureD3DImmutableBase::setImage(const gl::Context *context, ...@@ -3806,6 +3812,7 @@ angle::Result TextureD3DImmutableBase::setImage(const gl::Context *context,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) const uint8_t *pixels)
{ {
ANGLE_HR_UNREACHABLE(GetImplAs<ContextD3D>(context)); ANGLE_HR_UNREACHABLE(GetImplAs<ContextD3D>(context));
......
...@@ -122,6 +122,7 @@ class TextureD3D : public TextureImpl, public angle::ObserverInterface ...@@ -122,6 +122,7 @@ class TextureD3D : public TextureImpl, public angle::ObserverInterface
const gl::ImageIndex &index, const gl::ImageIndex &index,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels, const uint8_t *pixels,
ptrdiff_t layerOffset); ptrdiff_t layerOffset);
angle::Result subImage(const gl::Context *context, angle::Result subImage(const gl::Context *context,
...@@ -148,6 +149,7 @@ class TextureD3D : public TextureImpl, public angle::ObserverInterface ...@@ -148,6 +149,7 @@ class TextureD3D : public TextureImpl, public angle::ObserverInterface
bool isFastUnpackable(const gl::Buffer *unpackBuffer, GLenum sizedInternalFormat); bool isFastUnpackable(const gl::Buffer *unpackBuffer, GLenum sizedInternalFormat);
angle::Result fastUnpackPixels(const gl::Context *context, angle::Result fastUnpackPixels(const gl::Context *context,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels, const uint8_t *pixels,
const gl::Box &destArea, const gl::Box &destArea,
GLenum sizedInternalFormat, GLenum sizedInternalFormat,
...@@ -227,6 +229,7 @@ class TextureD3D_2D : public TextureD3D ...@@ -227,6 +229,7 @@ class TextureD3D_2D : public TextureD3D
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) override; const uint8_t *pixels) override;
angle::Result setSubImage(const gl::Context *context, angle::Result setSubImage(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
...@@ -358,6 +361,7 @@ class TextureD3D_Cube : public TextureD3D ...@@ -358,6 +361,7 @@ class TextureD3D_Cube : public TextureD3D
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) override; const uint8_t *pixels) override;
angle::Result setSubImage(const gl::Context *context, angle::Result setSubImage(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
...@@ -490,6 +494,7 @@ class TextureD3D_3D : public TextureD3D ...@@ -490,6 +494,7 @@ class TextureD3D_3D : public TextureD3D
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) override; const uint8_t *pixels) override;
angle::Result setSubImage(const gl::Context *context, angle::Result setSubImage(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
...@@ -619,6 +624,7 @@ class TextureD3D_2DArray : public TextureD3D ...@@ -619,6 +624,7 @@ class TextureD3D_2DArray : public TextureD3D
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) override; const uint8_t *pixels) override;
angle::Result setSubImage(const gl::Context *context, angle::Result setSubImage(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
...@@ -746,6 +752,7 @@ class TextureD3DImmutableBase : public TextureD3D ...@@ -746,6 +752,7 @@ class TextureD3DImmutableBase : public TextureD3D
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) override; const uint8_t *pixels) override;
angle::Result setSubImage(const gl::Context *context, angle::Result setSubImage(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
......
...@@ -150,12 +150,15 @@ void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea, ...@@ -150,12 +150,15 @@ void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea,
angle::Result PixelTransfer11::copyBufferToTexture(const gl::Context *context, angle::Result PixelTransfer11::copyBufferToTexture(const gl::Context *context,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
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)
{ {
ASSERT(unpackBuffer);
ANGLE_TRY(loadResources(context)); ANGLE_TRY(loadResources(context));
gl::Extents destSize = destRenderTarget->getExtents(); gl::Extents destSize = destRenderTarget->getExtents();
...@@ -164,9 +167,6 @@ angle::Result PixelTransfer11::copyBufferToTexture(const gl::Context *context, ...@@ -164,9 +167,6 @@ angle::Result PixelTransfer11::copyBufferToTexture(const gl::Context *context,
destArea.y + destArea.height <= destSize.height && destArea.z >= 0 && destArea.y + destArea.height <= destSize.height && destArea.z >= 0 &&
destArea.z + destArea.depth <= destSize.depth); destArea.z + destArea.depth <= destSize.depth);
const gl::Buffer &sourceBuffer =
*context->getState().getTargetBuffer(gl::BufferBinding::PixelUnpack);
ASSERT(mRenderer->supportsFastCopyBufferToTexture(destinationFormat)); ASSERT(mRenderer->supportsFastCopyBufferToTexture(destinationFormat));
const d3d11::PixelShader *pixelShader = findBufferToTexturePS(destinationFormat); const d3d11::PixelShader *pixelShader = findBufferToTexturePS(destinationFormat);
...@@ -182,7 +182,7 @@ angle::Result PixelTransfer11::copyBufferToTexture(const gl::Context *context, ...@@ -182,7 +182,7 @@ angle::Result PixelTransfer11::copyBufferToTexture(const gl::Context *context,
sourceglFormatInfo.sizedInternalFormat, mRenderer->getRenderer11DeviceCaps()); sourceglFormatInfo.sizedInternalFormat, mRenderer->getRenderer11DeviceCaps());
DXGI_FORMAT srvFormat = sourceFormatInfo.srvFormat; DXGI_FORMAT srvFormat = sourceFormatInfo.srvFormat;
ASSERT(srvFormat != DXGI_FORMAT_UNKNOWN); ASSERT(srvFormat != DXGI_FORMAT_UNKNOWN);
Buffer11 *bufferStorage11 = GetAs<Buffer11>(sourceBuffer.getImplementation()); Buffer11 *bufferStorage11 = GetAs<Buffer11>(unpackBuffer->getImplementation());
const d3d11::ShaderResourceView *bufferSRV = nullptr; const d3d11::ShaderResourceView *bufferSRV = nullptr;
ANGLE_TRY(bufferStorage11->getSRV(context, srvFormat, &bufferSRV)); ANGLE_TRY(bufferStorage11->getSRV(context, srvFormat, &bufferSRV));
ASSERT(bufferSRV != nullptr); ASSERT(bufferSRV != nullptr);
......
...@@ -46,6 +46,7 @@ class PixelTransfer11 ...@@ -46,6 +46,7 @@ class PixelTransfer11
// destArea: the sub-section of destRenderTarget to copy to // destArea: the sub-section of destRenderTarget to copy to
angle::Result copyBufferToTexture(const gl::Context *context, angle::Result copyBufferToTexture(const gl::Context *context,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
unsigned int offset, unsigned int offset,
RenderTargetD3D *destRenderTarget, RenderTargetD3D *destRenderTarget,
GLenum destinationFormat, GLenum destinationFormat,
......
...@@ -3104,6 +3104,7 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const ...@@ -3104,6 +3104,7 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const
angle::Result Renderer11::fastCopyBufferToTexture(const gl::Context *context, angle::Result Renderer11::fastCopyBufferToTexture(const gl::Context *context,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
unsigned int offset, unsigned int offset,
RenderTargetD3D *destRenderTarget, RenderTargetD3D *destRenderTarget,
GLenum destinationFormat, GLenum destinationFormat,
...@@ -3111,8 +3112,9 @@ angle::Result Renderer11::fastCopyBufferToTexture(const gl::Context *context, ...@@ -3111,8 +3112,9 @@ angle::Result Renderer11::fastCopyBufferToTexture(const gl::Context *context,
const gl::Box &destArea) const gl::Box &destArea)
{ {
ASSERT(supportsFastCopyBufferToTexture(destinationFormat)); ASSERT(supportsFastCopyBufferToTexture(destinationFormat));
return mPixelTransfer->copyBufferToTexture(context, unpack, offset, destRenderTarget, return mPixelTransfer->copyBufferToTexture(context, unpack, unpackBuffer, offset,
destinationFormat, sourcePixelsType, destArea); destRenderTarget, destinationFormat,
sourcePixelsType, destArea);
} }
ImageD3D *Renderer11::createImage() ImageD3D *Renderer11::createImage()
......
...@@ -351,6 +351,7 @@ class Renderer11 : public RendererD3D ...@@ -351,6 +351,7 @@ class Renderer11 : public RendererD3D
bool supportsFastCopyBufferToTexture(GLenum internalFormat) const override; bool supportsFastCopyBufferToTexture(GLenum internalFormat) const override;
angle::Result fastCopyBufferToTexture(const gl::Context *context, angle::Result fastCopyBufferToTexture(const gl::Context *context,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
unsigned int offset, unsigned int offset,
RenderTargetD3D *destRenderTarget, RenderTargetD3D *destRenderTarget,
GLenum destinationFormat, GLenum destinationFormat,
......
...@@ -949,6 +949,7 @@ bool Renderer9::supportsFastCopyBufferToTexture(GLenum internalFormat) const ...@@ -949,6 +949,7 @@ bool Renderer9::supportsFastCopyBufferToTexture(GLenum internalFormat) const
angle::Result Renderer9::fastCopyBufferToTexture(const gl::Context *context, angle::Result Renderer9::fastCopyBufferToTexture(const gl::Context *context,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
unsigned int offset, unsigned int offset,
RenderTargetD3D *destRenderTarget, RenderTargetD3D *destRenderTarget,
GLenum destinationFormat, GLenum destinationFormat,
......
...@@ -351,6 +351,7 @@ class Renderer9 : public RendererD3D ...@@ -351,6 +351,7 @@ class Renderer9 : public RendererD3D
bool supportsFastCopyBufferToTexture(GLenum internalFormat) const override; bool supportsFastCopyBufferToTexture(GLenum internalFormat) const override;
angle::Result fastCopyBufferToTexture(const gl::Context *context, angle::Result fastCopyBufferToTexture(const gl::Context *context,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
unsigned int offset, unsigned int offset,
RenderTargetD3D *destRenderTarget, RenderTargetD3D *destRenderTarget,
GLenum destinationFormat, GLenum destinationFormat,
......
...@@ -164,13 +164,11 @@ angle::Result TextureGL::setImage(const gl::Context *context, ...@@ -164,13 +164,11 @@ angle::Result TextureGL::setImage(const gl::Context *context,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) const uint8_t *pixels)
{ {
const angle::FeaturesGL &features = GetFeaturesGL(context); const angle::FeaturesGL &features = GetFeaturesGL(context);
const gl::Buffer *unpackBuffer =
context->getState().getTargetBuffer(gl::BufferBinding::PixelUnpack);
gl::TextureTarget target = index.getTarget(); gl::TextureTarget target = index.getTarget();
size_t level = static_cast<size_t>(index.getLevelIndex()); size_t level = static_cast<size_t>(index.getLevelIndex());
......
...@@ -74,6 +74,7 @@ class TextureGL : public TextureImpl ...@@ -74,6 +74,7 @@ class TextureGL : public TextureImpl
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) override; const uint8_t *pixels) override;
angle::Result setSubImage(const gl::Context *context, angle::Result setSubImage(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
......
...@@ -35,6 +35,7 @@ class TextureMtl : public TextureImpl ...@@ -35,6 +35,7 @@ class TextureMtl : public TextureImpl
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) override; const uint8_t *pixels) override;
angle::Result setSubImage(const gl::Context *context, angle::Result setSubImage(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
......
...@@ -397,7 +397,7 @@ angle::Result TextureMtl::ensureTextureCreated(const gl::Context *context) ...@@ -397,7 +397,7 @@ angle::Result TextureMtl::ensureTextureCreated(const gl::Context *context)
ANGLE_TRY(checkForEmulatedChannels(context, mFormat, mNativeTexture)); ANGLE_TRY(checkForEmulatedChannels(context, mFormat, mNativeTexture));
// Transfer data from images to actual texture object // Transfer data from images to actual texture object
mtl::BlitCommandEncoder *encoder = nullptr; mtl::BlitCommandEncoder *encoder = nullptr;
for (int layer = 0; layer < layers; ++layer) for (int layer = 0; layer < layers; ++layer)
{ {
for (GLuint mip = 0; mip < mips; ++mip) for (GLuint mip = 0; mip < mips; ++mip)
...@@ -489,6 +489,7 @@ angle::Result TextureMtl::setImage(const gl::Context *context, ...@@ -489,6 +489,7 @@ angle::Result TextureMtl::setImage(const gl::Context *context,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) const uint8_t *pixels)
{ {
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat, type); const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat, type);
......
...@@ -25,6 +25,7 @@ angle::Result TextureNULL::setImage(const gl::Context *context, ...@@ -25,6 +25,7 @@ angle::Result TextureNULL::setImage(const gl::Context *context,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) const uint8_t *pixels)
{ {
// TODO(geofflang): Read all incoming pixel data (maybe hash it?) to make sure we don't read out // TODO(geofflang): Read all incoming pixel data (maybe hash it?) to make sure we don't read out
......
...@@ -28,6 +28,7 @@ class TextureNULL : public TextureImpl ...@@ -28,6 +28,7 @@ class TextureNULL : public TextureImpl
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) override; const uint8_t *pixels) override;
angle::Result setSubImage(const gl::Context *context, angle::Result setSubImage(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
......
...@@ -135,11 +135,12 @@ angle::Result TextureVk::setImage(const gl::Context *context, ...@@ -135,11 +135,12 @@ angle::Result TextureVk::setImage(const gl::Context *context,
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) const uint8_t *pixels)
{ {
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat, type); const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(internalFormat, type);
return setImageImpl(context, index, formatInfo, size, type, unpack, pixels); return setImageImpl(context, index, formatInfo, size, type, unpack, unpackBuffer, pixels);
} }
angle::Result TextureVk::setSubImage(const gl::Context *context, angle::Result TextureVk::setSubImage(const gl::Context *context,
...@@ -171,7 +172,11 @@ angle::Result TextureVk::setCompressedImage(const gl::Context *context, ...@@ -171,7 +172,11 @@ angle::Result TextureVk::setCompressedImage(const gl::Context *context,
{ {
const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalFormat); const gl::InternalFormat &formatInfo = gl::GetSizedInternalFormatInfo(internalFormat);
return setImageImpl(context, index, formatInfo, size, GL_UNSIGNED_BYTE, unpack, pixels); const gl::State &glState = context->getState();
gl::Buffer *unpackBuffer = glState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
return setImageImpl(context, index, formatInfo, size, GL_UNSIGNED_BYTE, unpack, unpackBuffer,
pixels);
} }
angle::Result TextureVk::setCompressedSubImage(const gl::Context *context, angle::Result TextureVk::setCompressedSubImage(const gl::Context *context,
...@@ -201,6 +206,7 @@ angle::Result TextureVk::setImageImpl(const gl::Context *context, ...@@ -201,6 +206,7 @@ angle::Result TextureVk::setImageImpl(const gl::Context *context,
const gl::Extents &size, const gl::Extents &size,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) const uint8_t *pixels)
{ {
ContextVk *contextVk = vk::GetImpl(context); ContextVk *contextVk = vk::GetImpl(context);
...@@ -215,8 +221,6 @@ angle::Result TextureVk::setImageImpl(const gl::Context *context, ...@@ -215,8 +221,6 @@ angle::Result TextureVk::setImageImpl(const gl::Context *context,
{ {
return angle::Result::Continue; return angle::Result::Continue;
} }
const gl::State &glState = contextVk->getState();
gl::Buffer *unpackBuffer = glState.getTargetBuffer(gl::BufferBinding::PixelUnpack);
return setSubImageImpl(context, index, gl::Box(0, 0, 0, size.width, size.height, size.depth), return setSubImageImpl(context, index, gl::Box(0, 0, 0, size.width, size.height, size.depth),
formatInfo, type, unpack, unpackBuffer, pixels, vkFormat); formatInfo, type, unpack, unpackBuffer, pixels, vkFormat);
......
...@@ -44,6 +44,7 @@ class TextureVk : public TextureImpl, public angle::ObserverInterface ...@@ -44,6 +44,7 @@ class TextureVk : public TextureImpl, public angle::ObserverInterface
GLenum format, GLenum format,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels) override; const uint8_t *pixels) override;
angle::Result setSubImage(const gl::Context *context, angle::Result setSubImage(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
...@@ -258,6 +259,7 @@ class TextureVk : public TextureImpl, public angle::ObserverInterface ...@@ -258,6 +259,7 @@ class TextureVk : public TextureImpl, public angle::ObserverInterface
const gl::Extents &size, const gl::Extents &size,
GLenum type, GLenum type,
const gl::PixelUnpackState &unpack, const gl::PixelUnpackState &unpack,
gl::Buffer *unpackBuffer,
const uint8_t *pixels); const uint8_t *pixels);
angle::Result setSubImageImpl(const gl::Context *context, angle::Result setSubImageImpl(const gl::Context *context,
const gl::ImageIndex &index, const gl::ImageIndex &index,
......
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