Commit 56ff3ce2 by Geoff Lang Committed by Commit Bot

D3D9: Implement the CPU-copy path for CopyTextureCHROMIUM.

This path is hit for LUMA formats. Only copy from storage to image when the storage is renderable, otherwise it already has up-to-date data. D3D9 cannot sync storage to image without it being renderable. Commit the region after CPU copies to make sure everything is synchronized afterwards. TEST=conformance/textures/canvas/tex-2d-luminance_alpha-luminance_alpha-unsigned_byte.html BUG=angleproject:2192 Change-Id: I74ff748bd051a52cf472ca7ff77f54dfb5ba65b9 Reviewed-on: https://chromium-review.googlesource.com/730493 Commit-Queue: Geoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent b1fa7d74
...@@ -110,7 +110,7 @@ gl::Error TextureD3D::getImageAndSyncFromStorage(const gl::Context *context, ...@@ -110,7 +110,7 @@ gl::Error TextureD3D::getImageAndSyncFromStorage(const gl::Context *context,
ImageD3D **outImage) const ImageD3D **outImage) const
{ {
ImageD3D *image = getImage(index); ImageD3D *image = getImage(index);
if (mTexStorage) if (mTexStorage && mTexStorage->isRenderTarget())
{ {
ANGLE_TRY(image->copyFromTexStorage(context, index, mTexStorage)); ANGLE_TRY(image->copyFromTexStorage(context, index, mTexStorage));
} }
...@@ -1090,6 +1090,9 @@ gl::Error TextureD3D_2D::copyTexture(const gl::Context *context, ...@@ -1090,6 +1090,9 @@ gl::Error TextureD3D_2D::copyTexture(const gl::Context *context,
ANGLE_TRY(mRenderer->copyImage(context, destImage, sourceImage, sourceRect, destOffset, ANGLE_TRY(mRenderer->copyImage(context, destImage, sourceImage, sourceRect, destOffset,
unpackFlipY, unpackPremultiplyAlpha, unpackUnmultiplyAlpha)); unpackFlipY, unpackPremultiplyAlpha, unpackUnmultiplyAlpha));
gl::Box destRegion(destOffset, size);
ANGLE_TRY(commitRegion(context, destImageIndex, destRegion));
} }
return gl::NoError(); return gl::NoError();
...@@ -1134,6 +1137,9 @@ gl::Error TextureD3D_2D::copySubTexture(const gl::Context *context, ...@@ -1134,6 +1137,9 @@ gl::Error TextureD3D_2D::copySubTexture(const gl::Context *context,
ANGLE_TRY(mRenderer->copyImage(context, destImage, sourceImage, sourceArea, destOffset, ANGLE_TRY(mRenderer->copyImage(context, destImage, sourceImage, sourceArea, destOffset,
unpackFlipY, unpackPremultiplyAlpha, unpackUnmultiplyAlpha)); unpackFlipY, unpackPremultiplyAlpha, unpackUnmultiplyAlpha));
gl::Box destRegion(destOffset.x, destOffset.y, 0, sourceArea.width, sourceArea.height, 1);
ANGLE_TRY(commitRegion(context, destImageIndex, destRegion));
} }
return gl::NoError(); return gl::NoError();
...@@ -1853,6 +1859,9 @@ gl::Error TextureD3D_Cube::copyTexture(const gl::Context *context, ...@@ -1853,6 +1859,9 @@ gl::Error TextureD3D_Cube::copyTexture(const gl::Context *context,
ANGLE_TRY(mRenderer->copyImage(context, destImage, sourceImage, sourceRect, destOffset, ANGLE_TRY(mRenderer->copyImage(context, destImage, sourceImage, sourceRect, destOffset,
unpackFlipY, unpackPremultiplyAlpha, unpackUnmultiplyAlpha)); unpackFlipY, unpackPremultiplyAlpha, unpackUnmultiplyAlpha));
gl::Box destRegion(destOffset, size);
ANGLE_TRY(commitRegion(context, destImageIndex, destRegion));
} }
return gl::NoError(); return gl::NoError();
...@@ -1900,6 +1909,9 @@ gl::Error TextureD3D_Cube::copySubTexture(const gl::Context *context, ...@@ -1900,6 +1909,9 @@ gl::Error TextureD3D_Cube::copySubTexture(const gl::Context *context,
ANGLE_TRY(mRenderer->copyImage(context, destImage, sourceImage, sourceArea, destOffset, ANGLE_TRY(mRenderer->copyImage(context, destImage, sourceImage, sourceArea, destOffset,
unpackFlipY, unpackPremultiplyAlpha, unpackUnmultiplyAlpha)); unpackFlipY, unpackPremultiplyAlpha, unpackUnmultiplyAlpha));
gl::Box destRegion(destOffset.x, destOffset.y, 0, sourceArea.width, sourceArea.height, 1);
ANGLE_TRY(commitRegion(context, destImageIndex, destRegion));
} }
return gl::NoError(); return gl::NoError();
......
...@@ -104,24 +104,12 @@ gl::Error Image9::generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 ...@@ -104,24 +104,12 @@ gl::Error Image9::generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9
gl::Error Image9::generateMipmap(Image9 *dest, Image9 *source) gl::Error Image9::generateMipmap(Image9 *dest, Image9 *source)
{ {
IDirect3DSurface9 *sourceSurface = nullptr; IDirect3DSurface9 *sourceSurface = nullptr;
gl::Error error = source->getSurface(&sourceSurface); ANGLE_TRY(source->getSurface(&sourceSurface));
if (error.isError())
{
return error;
}
IDirect3DSurface9 *destSurface = nullptr; IDirect3DSurface9 *destSurface = nullptr;
error = dest->getSurface(&destSurface); ANGLE_TRY(dest->getSurface(&destSurface));
if (error.isError())
{
return error;
}
error = generateMip(destSurface, sourceSurface); ANGLE_TRY(generateMip(destSurface, sourceSurface));
if (error.isError())
{
return error;
}
dest->markDirty(); dest->markDirty();
...@@ -171,6 +159,84 @@ gl::Error Image9::copyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface ...@@ -171,6 +159,84 @@ gl::Error Image9::copyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface
return gl::NoError(); return gl::NoError();
} }
// static
gl::Error Image9::CopyImage(const gl::Context *context,
Image9 *dest,
Image9 *source,
const gl::Rectangle &sourceRect,
const gl::Offset &destOffset,
bool unpackFlipY,
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha)
{
IDirect3DSurface9 *sourceSurface = nullptr;
ANGLE_TRY(source->getSurface(&sourceSurface));
IDirect3DSurface9 *destSurface = nullptr;
ANGLE_TRY(dest->getSurface(&destSurface));
D3DSURFACE_DESC destDesc;
HRESULT result = destSurface->GetDesc(&destDesc);
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
return gl::OutOfMemory()
<< "Failed to query the source surface description for mipmap generation, "
<< gl::FmtHR(result);
}
const d3d9::D3DFormat &destD3DFormatInfo = d3d9::GetD3DFormatInfo(destDesc.Format);
D3DSURFACE_DESC sourceDesc;
result = sourceSurface->GetDesc(&sourceDesc);
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
return gl::OutOfMemory()
<< "Failed to query the destination surface description for mipmap generation, "
<< gl::FmtHR(result);
}
const d3d9::D3DFormat &sourceD3DFormatInfo = d3d9::GetD3DFormatInfo(sourceDesc.Format);
D3DLOCKED_RECT sourceLocked = {0};
result = sourceSurface->LockRect(&sourceLocked, nullptr, D3DLOCK_READONLY);
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
return gl::OutOfMemory() << "Failed to lock the source surface for CopyImage, "
<< gl::FmtHR(result);
}
D3DLOCKED_RECT destLocked = {0};
result = destSurface->LockRect(&destLocked, nullptr, 0);
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
sourceSurface->UnlockRect();
return gl::OutOfMemory() << "Failed to lock the destination surface for CopyImage, "
<< gl::FmtHR(result);
}
const uint8_t *sourceData = reinterpret_cast<const uint8_t *>(sourceLocked.pBits) +
sourceRect.x * sourceD3DFormatInfo.pixelBytes +
sourceRect.y * sourceLocked.Pitch;
uint8_t *destData = reinterpret_cast<uint8_t *>(destLocked.pBits) +
destOffset.x * destD3DFormatInfo.pixelBytes +
destOffset.y * destLocked.Pitch;
ASSERT(sourceData && destData);
CopyImageCHROMIUM(sourceData, sourceLocked.Pitch, sourceD3DFormatInfo.pixelBytes,
sourceD3DFormatInfo.info().colorReadFunction, destData, destLocked.Pitch,
destD3DFormatInfo.pixelBytes, destD3DFormatInfo.info().colorWriteFunction,
gl::GetUnsizedFormat(dest->getInternalFormat()),
destD3DFormatInfo.info().componentType, sourceRect.width, sourceRect.height,
unpackFlipY, unpackPremultiplyAlpha, unpackUnmultiplyAlpha);
destSurface->UnlockRect();
sourceSurface->UnlockRect();
return gl::NoError();
}
bool Image9::redefine(GLenum target, GLenum internalformat, const gl::Extents &size, bool forceRelease) bool Image9::redefine(GLenum target, GLenum internalformat, const gl::Extents &size, bool forceRelease)
{ {
// 3D textures are not supported by the D3D9 backend. // 3D textures are not supported by the D3D9 backend.
......
...@@ -31,6 +31,14 @@ class Image9 : public ImageD3D ...@@ -31,6 +31,14 @@ class Image9 : public ImageD3D
static gl::Error generateMipmap(Image9 *dest, Image9 *source); static gl::Error generateMipmap(Image9 *dest, Image9 *source);
static gl::Error generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 *sourceSurface); static gl::Error generateMip(IDirect3DSurface9 *destSurface, IDirect3DSurface9 *sourceSurface);
static gl::Error copyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface9 *source); static gl::Error copyLockableSurfaces(IDirect3DSurface9 *dest, IDirect3DSurface9 *source);
static gl::Error CopyImage(const gl::Context *context,
Image9 *dest,
Image9 *source,
const gl::Rectangle &sourceRect,
const gl::Offset &destOffset,
bool unpackFlipY,
bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha);
bool redefine(GLenum target, GLenum internalformat, const gl::Extents &size, bool forceRelease) override; bool redefine(GLenum target, GLenum internalformat, const gl::Extents &size, bool forceRelease) override;
......
...@@ -2920,8 +2920,10 @@ gl::Error Renderer9::copyImage(const gl::Context *context, ...@@ -2920,8 +2920,10 @@ gl::Error Renderer9::copyImage(const gl::Context *context,
bool unpackPremultiplyAlpha, bool unpackPremultiplyAlpha,
bool unpackUnmultiplyAlpha) bool unpackUnmultiplyAlpha)
{ {
UNREACHABLE(); Image9 *dest9 = GetAs<Image9>(dest);
return gl::NoError(); Image9 *src9 = GetAs<Image9>(source);
return Image9::CopyImage(context, dest9, src9, sourceRect, destOffset, unpackFlipY,
unpackPremultiplyAlpha, unpackUnmultiplyAlpha);
} }
TextureStorage *Renderer9::createTextureStorage2D(SwapChainD3D *swapChain) TextureStorage *Renderer9::createTextureStorage2D(SwapChainD3D *swapChain)
......
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