Commit 5a0c45e1 by Jamie Madill

Accept RenderTargets as parameters to Image::copy.

This gives us the flexibility to use copy internally for Textures as well as FBO attachments. This will be useful for the TexSubImage performance workaround. BUG=angle:729 Change-Id: I4df8ef3a5a928d44ef84100cd96a5d35f12b47fa Reviewed-on: https://chromium-review.googlesource.com/219863Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 9a2e6ac9
......@@ -9,6 +9,8 @@
// surfaces or resources.
#include "libGLESv2/renderer/Image.h"
#include "libGLESv2/Framebuffer.h"
#include "libGLESv2/main.h"
namespace rx
{
......@@ -25,4 +27,18 @@ Image::Image()
mDirty = false;
}
void Image::copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
{
gl::FramebufferAttachment *colorbuffer = source->getReadColorbuffer();
if (!colorbuffer)
{
return gl::error(GL_OUT_OF_MEMORY);
}
RenderTarget *renderTarget = GetAttachmentRenderTarget(colorbuffer);
ASSERT(renderTarget);
copy(xoffset, yoffset, zoffset, x, y, width, height, renderTarget);
}
}
......@@ -23,8 +23,8 @@ class Framebuffer;
namespace rx
{
class Renderer;
class RenderTarget;
class Image
{
......@@ -51,7 +51,8 @@ class Image
virtual gl::Error loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
const void *input) = 0;
virtual void copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source) = 0;
void copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
virtual void copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, RenderTarget *renderTarget) = 0;
protected:
GLsizei mWidth;
......
......@@ -9,6 +9,7 @@
#include "libGLESv2/renderer/d3d/d3d11/Renderer11.h"
#include "libGLESv2/renderer/d3d/d3d11/Image11.h"
#include "libGLESv2/renderer/d3d/d3d11/RenderTarget11.h"
#include "libGLESv2/renderer/d3d/d3d11/TextureStorage11.h"
#include "libGLESv2/renderer/d3d/d3d11/formatutils11.h"
#include "libGLESv2/renderer/d3d/d3d11/renderer11_utils.h"
......@@ -320,69 +321,72 @@ gl::Error Image11::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffse
return gl::Error(GL_NO_ERROR);
}
void Image11::copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
void Image11::copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, RenderTarget *source)
{
gl::FramebufferAttachment *colorbuffer = source->getReadColorbuffer();
RenderTarget11 *renderTarget = RenderTarget11::makeRenderTarget11(source);
if (colorbuffer && colorbuffer->getActualFormat() == mActualFormat)
ID3D11Texture2D *colorBufferTexture = mRenderer->getRenderTargetResource(renderTarget);
unsigned int subresourceIndex = renderTarget->getSubresourceIndex();
if (!colorBufferTexture)
{
// No conversion needed-- use copyback fastpath
ID3D11Texture2D *colorBufferTexture = NULL;
unsigned int subresourceIndex = 0;
// Error already generated
return;
}
if (mRenderer->getRenderTargetResource(colorbuffer, &subresourceIndex, &colorBufferTexture))
{
D3D11_TEXTURE2D_DESC textureDesc;
colorBufferTexture->GetDesc(&textureDesc);
if (source->getActualFormat() == mActualFormat)
{
// No conversion needed-- use copyback fastpath
D3D11_TEXTURE2D_DESC textureDesc;
colorBufferTexture->GetDesc(&textureDesc);
ID3D11Device *device = mRenderer->getDevice();
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
ID3D11Device *device = mRenderer->getDevice();
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
ID3D11Texture2D* srcTex = NULL;
if (textureDesc.SampleDesc.Count > 1)
{
D3D11_TEXTURE2D_DESC resolveDesc;
resolveDesc.Width = textureDesc.Width;
resolveDesc.Height = textureDesc.Height;
resolveDesc.MipLevels = 1;
resolveDesc.ArraySize = 1;
resolveDesc.Format = textureDesc.Format;
resolveDesc.SampleDesc.Count = 1;
resolveDesc.SampleDesc.Quality = 0;
resolveDesc.Usage = D3D11_USAGE_DEFAULT;
resolveDesc.BindFlags = 0;
resolveDesc.CPUAccessFlags = 0;
resolveDesc.MiscFlags = 0;
HRESULT result = device->CreateTexture2D(&resolveDesc, NULL, &srcTex);
if (FAILED(result))
{
ERR("Failed to create resolve texture for Image11::copy, HRESULT: 0x%X.", result);
return;
}
deviceContext->ResolveSubresource(srcTex, 0, colorBufferTexture, subresourceIndex, textureDesc.Format);
subresourceIndex = 0;
}
else
ID3D11Texture2D* srcTex = NULL;
if (textureDesc.SampleDesc.Count > 1)
{
D3D11_TEXTURE2D_DESC resolveDesc;
resolveDesc.Width = textureDesc.Width;
resolveDesc.Height = textureDesc.Height;
resolveDesc.MipLevels = 1;
resolveDesc.ArraySize = 1;
resolveDesc.Format = textureDesc.Format;
resolveDesc.SampleDesc.Count = 1;
resolveDesc.SampleDesc.Quality = 0;
resolveDesc.Usage = D3D11_USAGE_DEFAULT;
resolveDesc.BindFlags = 0;
resolveDesc.CPUAccessFlags = 0;
resolveDesc.MiscFlags = 0;
HRESULT result = device->CreateTexture2D(&resolveDesc, NULL, &srcTex);
if (FAILED(result))
{
srcTex = colorBufferTexture;
srcTex->AddRef();
ERR("Failed to create resolve texture for Image11::copy, HRESULT: 0x%X.", result);
return;
}
D3D11_BOX srcBox;
srcBox.left = x;
srcBox.right = x + width;
srcBox.top = y;
srcBox.bottom = y + height;
srcBox.front = 0;
srcBox.back = 1;
deviceContext->ResolveSubresource(srcTex, 0, colorBufferTexture, subresourceIndex, textureDesc.Format);
subresourceIndex = 0;
}
else
{
srcTex = colorBufferTexture;
srcTex->AddRef();
}
D3D11_BOX srcBox;
srcBox.left = x;
srcBox.right = x + width;
srcBox.top = y;
srcBox.bottom = y + height;
srcBox.front = 0;
srcBox.back = 1;
deviceContext->CopySubresourceRegion(mStagingTexture, 0, xoffset, yoffset, zoffset, srcTex, subresourceIndex, &srcBox);
deviceContext->CopySubresourceRegion(mStagingTexture, 0, xoffset, yoffset, zoffset, srcTex, subresourceIndex, &srcBox);
SafeRelease(srcTex);
SafeRelease(colorBufferTexture);
}
SafeRelease(srcTex);
SafeRelease(colorBufferTexture);
}
else
{
......@@ -401,7 +405,8 @@ void Image11::copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y
const gl::InternalFormat &formatInfo = gl::GetInternalFormatInfo(mInternalFormat);
mRenderer->readPixels(source, x, y, width, height, formatInfo.format, formatInfo.type, mappedImage.RowPitch, gl::PixelPackState(), dataOffset);
gl::Rectangle area(x, y, width, height);
mRenderer->readTextureData(colorBufferTexture, subresourceIndex, area, formatInfo.format, formatInfo.type, mappedImage.RowPitch, gl::PixelPackState(), dataOffset);
unmap();
}
......
......@@ -51,7 +51,7 @@ class Image11 : public ImageD3D
virtual gl::Error loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
const void *input);
virtual void copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
virtual void copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, RenderTarget *source);
bool recoverFromAssociatedStorage();
bool isAssociatedStorageValid(TextureStorage11* textureStorage) const;
......
......@@ -2432,35 +2432,44 @@ bool Renderer11::getRenderTargetResource(gl::FramebufferAttachment *colorbuffer,
ASSERT(colorbuffer != NULL);
RenderTarget11 *renderTarget = d3d11::GetAttachmentRenderTarget(colorbuffer);
if (renderTarget)
if (!renderTarget)
{
*subresourceIndex = renderTarget->getSubresourceIndex();
return false;
}
*subresourceIndex = renderTarget->getSubresourceIndex();
*resource = getRenderTargetResource(renderTarget);
return (*resource != NULL);
}
ID3D11Texture2D *Renderer11::getRenderTargetResource(RenderTarget11 *renderTarget)
{
ASSERT(renderTarget);
ID3D11RenderTargetView *colorBufferRTV = renderTarget->getRenderTargetView();
ID3D11Texture2D *texture2D = NULL;
ID3D11RenderTargetView *colorBufferRTV = renderTarget->getRenderTargetView();
if (colorBufferRTV)
if (colorBufferRTV)
{
ID3D11Resource *textureResource = NULL;
colorBufferRTV->GetResource(&textureResource);
if (textureResource)
{
ID3D11Resource *textureResource = NULL;
colorBufferRTV->GetResource(&textureResource);
HRESULT result = textureResource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void**>(&texture2D));
SafeRelease(textureResource);
if (textureResource)
if (FAILED(result))
{
HRESULT result = textureResource->QueryInterface(__uuidof(ID3D11Texture2D), (void**)resource);
SafeRelease(textureResource);
if (SUCCEEDED(result))
{
return true;
}
else
{
ERR("Failed to extract the ID3D11Texture2D from the render target resource, "
"HRESULT: 0x%X.", result);
}
ERR("Failed to extract the ID3D11Texture2D from the render target resource, "
"HRESULT: 0x%X.", result);
return gl::error(GL_OUT_OF_MEMORY, static_cast <ID3D11Texture2D*>(NULL));
}
}
}
return false;
return texture2D;
}
gl::Error Renderer11::blitRect(gl::Framebuffer *readTarget, const gl::Rectangle &readRect, gl::Framebuffer *drawTarget, const gl::Rectangle &drawRect,
......
......@@ -33,6 +33,7 @@ class StreamingIndexBufferInterface;
class Blit11;
class Clear11;
class PixelTransfer11;
class RenderTarget11;
struct PackPixelsParams;
enum
......@@ -188,6 +189,7 @@ class Renderer11 : public Renderer
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea);
bool getRenderTargetResource(gl::FramebufferAttachment *colorbuffer, unsigned int *subresourceIndex, ID3D11Texture2D **resource);
ID3D11Texture2D *getRenderTargetResource(RenderTarget11 *renderTarget);
void unapplyRenderTargets();
void setOneTimeRenderTarget(ID3D11RenderTargetView *renderTargetView);
void packPixels(ID3D11Texture2D *readTexture, const PackPixelsParams &params, uint8_t *pixelsOut);
......@@ -196,6 +198,9 @@ class Renderer11 : public Renderer
virtual rx::VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const;
virtual GLenum getVertexComponentType(const gl::VertexFormat &vertexFormat) const;
gl::Error readTextureData(ID3D11Texture2D *texture, unsigned int subResource, const gl::Rectangle &area, GLenum format,
GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels);
private:
DISALLOW_COPY_AND_ASSIGN(Renderer11);
......@@ -205,9 +210,6 @@ class Renderer11 : public Renderer
gl::Error drawLineLoop(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer);
gl::Error drawTriangleFan(GLsizei count, GLenum type, const GLvoid *indices, int minIndex, gl::Buffer *elementArrayBuffer, int instances);
gl::Error readTextureData(ID3D11Texture2D *texture, unsigned int subResource, const gl::Rectangle &area, GLenum format,
GLenum type, GLuint outputPitch, const gl::PixelPackState &pack, uint8_t *pixels);
gl::Error blitRenderbufferRect(const gl::Rectangle &readRect, const gl::Rectangle &drawRect, RenderTarget *readRenderTarget,
RenderTarget *drawRenderTarget, GLenum filter, const gl::Rectangle *scissor,
bool colorBlit, bool depthBlit, bool stencilBlit);
......
......@@ -466,19 +466,15 @@ gl::Error Image9::loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset
}
// This implements glCopyTex[Sub]Image2D for non-renderable internal texture formats and incomplete textures
void Image9::copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source)
void Image9::copy(GLint xoffset, GLint yoffset, GLint zoffset, GLint x, GLint y, GLsizei width, GLsizei height, RenderTarget *source)
{
ASSERT(source);
// ES3.0 only behaviour to copy into a 3d texture
ASSERT(zoffset == 0);
RenderTarget9 *renderTarget = NULL;
RenderTarget9 *renderTarget = RenderTarget9::makeRenderTarget9(source);
IDirect3DSurface9 *surface = NULL;
gl::FramebufferAttachment *colorbuffer = source->getColorbuffer(0);
if (colorbuffer)
{
renderTarget = d3d9::GetAttachmentRenderTarget(colorbuffer);
}
if (renderTarget)
{
......
......@@ -54,7 +54,7 @@ class Image9 : public ImageD3D
virtual gl::Error loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth,
const void *input);
virtual void copy(GLint xoffset, GLint yoffset, GLint zoffset,GLint x, GLint y, GLsizei width, GLsizei height, gl::Framebuffer *source);
virtual void copy(GLint xoffset, GLint yoffset, GLint zoffset,GLint x, GLint y, GLsizei width, GLsizei height, RenderTarget *source);
private:
DISALLOW_COPY_AND_ASSIGN(Image9);
......
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