Commit ae5122c4 by Geoff Lang

Updated the PixelTransfer class to use Error objects.

BUG=angle:520 Change-Id: I7e21acbfd5726607ea62c8fcf64d76bbf5877860 Reviewed-on: https://chromium-review.googlesource.com/216643Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 7acae0a1
......@@ -243,8 +243,8 @@ class Renderer
// Buffer-to-texture and Texture-to-buffer copies
virtual bool supportsFastCopyBufferToTexture(GLenum internalFormat) const = 0;
virtual bool fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea) = 0;
virtual gl::Error fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea) = 0;
virtual bool getLUID(LUID *adapterLuid) const = 0;
virtual rx::VertexConversionType getVertexConversionType(const gl::VertexFormat &vertexFormat) const = 0;
......
......@@ -188,7 +188,13 @@ bool TextureD3D::fastUnpackPixels(const gl::PixelUnpackState &unpack, const void
unsigned int offset = reinterpret_cast<unsigned int>(pixels);
return mRenderer->fastCopyBufferToTexture(unpack, offset, destRenderTarget, sizedInternalFormat, type, destArea);
gl::Error error = mRenderer->fastCopyBufferToTexture(unpack, offset, destRenderTarget, sizedInternalFormat, type, destArea);
if (error.isError())
{
return false;
}
return true;
}
GLint TextureD3D::creationLevels(GLsizei width, GLsizei height, GLsizei depth) const
......
......@@ -33,12 +33,38 @@ namespace rx
PixelTransfer11::PixelTransfer11(Renderer11 *renderer)
: mRenderer(renderer),
mResourcesLoaded(false),
mBufferToTextureVS(NULL),
mBufferToTextureGS(NULL),
mParamsConstantBuffer(NULL),
mCopyRasterizerState(NULL),
mCopyDepthStencilState(NULL)
{
}
PixelTransfer11::~PixelTransfer11()
{
for (auto shaderMapIt = mBufferToTexturePSMap.begin(); shaderMapIt != mBufferToTexturePSMap.end(); shaderMapIt++)
{
SafeRelease(shaderMapIt->second);
}
mBufferToTexturePSMap.clear();
SafeRelease(mBufferToTextureVS);
SafeRelease(mBufferToTextureGS);
SafeRelease(mParamsConstantBuffer);
SafeRelease(mCopyRasterizerState);
SafeRelease(mCopyDepthStencilState);
}
gl::Error PixelTransfer11::loadResources()
{
if (mResourcesLoaded)
{
return gl::Error(GL_NO_ERROR);
}
HRESULT result = S_OK;
ID3D11Device *device = mRenderer->getDevice();
......@@ -56,6 +82,10 @@ PixelTransfer11::PixelTransfer11(Renderer11 *renderer)
result = device->CreateRasterizerState(&rasterDesc, &mCopyRasterizerState);
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal pixel transfer rasterizer state, result: 0x%X.", result);
}
D3D11_DEPTH_STENCIL_DESC depthStencilDesc;
depthStencilDesc.DepthEnable = true;
......@@ -75,6 +105,10 @@ PixelTransfer11::PixelTransfer11(Renderer11 *renderer)
result = device->CreateDepthStencilState(&depthStencilDesc, &mCopyDepthStencilState);
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal pixel transfer depth stencil state, result: 0x%X.", result);
}
D3D11_BUFFER_DESC constantBufferDesc = { 0 };
constantBufferDesc.ByteWidth = rx::roundUp<UINT>(sizeof(CopyShaderParams), 32u);
......@@ -86,31 +120,36 @@ PixelTransfer11::PixelTransfer11(Renderer11 *renderer)
result = device->CreateBuffer(&constantBufferDesc, NULL, &mParamsConstantBuffer);
ASSERT(SUCCEEDED(result));
if (FAILED(result))
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal pixel transfer constant buffer, result: 0x%X.", result);
}
d3d11::SetDebugName(mParamsConstantBuffer, "PixelTransfer11 constant buffer");
// init shaders
mBufferToTextureVS = d3d11::CompileVS(device, g_VS_BufferToTexture, "BufferToTexture VS");
mBufferToTextureGS = d3d11::CompileGS(device, g_GS_BufferToTexture, "BufferToTexture GS");
buildShaderMap();
if (!mBufferToTextureVS)
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal buffer to texture vertex shader.");
}
StructZero(&mParamsData);
}
mBufferToTextureGS = d3d11::CompileGS(device, g_GS_BufferToTexture, "BufferToTexture GS");
if (!mBufferToTextureGS)
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal buffer to texture geometry shader.");
}
PixelTransfer11::~PixelTransfer11()
{
for (auto shaderMapIt = mBufferToTexturePSMap.begin(); shaderMapIt != mBufferToTexturePSMap.end(); shaderMapIt++)
gl::Error error = buildShaderMap();
if (error.isError())
{
SafeRelease(shaderMapIt->second);
return error;
}
mBufferToTexturePSMap.clear();
StructZero(&mParamsData);
SafeRelease(mBufferToTextureVS);
SafeRelease(mBufferToTextureGS);
SafeRelease(mParamsConstantBuffer);
SafeRelease(mCopyRasterizerState);
SafeRelease(mCopyDepthStencilState);
mResourcesLoaded = true;
return gl::Error(GL_NO_ERROR);
}
void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea, const gl::Extents &destSize, GLenum internalFormat,
......@@ -135,18 +174,21 @@ void PixelTransfer11::setBufferToTextureCopyParams(const gl::Box &destArea, cons
parametersOut->PositionScale[1] = -2.0f / static_cast<float>(destSize.height);
}
bool PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea)
gl::Error PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea)
{
gl::Extents destSize = destRenderTarget->getExtents();
if (destArea.x < 0 || destArea.x + destArea.width > destSize.width ||
destArea.y < 0 || destArea.y + destArea.height > destSize.height ||
destArea.z < 0 || destArea.z + destArea.depth > destSize.depth )
gl::Error error = loadResources();
if (error.isError())
{
return false;
return error;
}
gl::Extents destSize = destRenderTarget->getExtents();
ASSERT(destArea.x >= 0 && destArea.x + destArea.width <= destSize.width &&
destArea.y >= 0 && destArea.y + destArea.height <= destSize.height &&
destArea.z >= 0 && destArea.z + destArea.depth <= destSize.depth );
const gl::Buffer &sourceBuffer = *unpack.pixelBuffer.get();
ASSERT(mRenderer->supportsFastCopyBufferToTexture(destinationFormat));
......@@ -222,16 +264,27 @@ bool PixelTransfer11::copyBufferToTexture(const gl::PixelUnpackState &unpack, un
mRenderer->markAllStateDirty();
return true;
return gl::Error(GL_NO_ERROR);
}
void PixelTransfer11::buildShaderMap()
gl::Error PixelTransfer11::buildShaderMap()
{
ID3D11Device *device = mRenderer->getDevice();
mBufferToTexturePSMap[GL_FLOAT] = d3d11::CompilePS(device, g_PS_BufferToTexture_4F, "BufferToTexture RGBA ps");
mBufferToTexturePSMap[GL_INT] = d3d11::CompilePS(device, g_PS_BufferToTexture_4I, "BufferToTexture RGBA-I ps");
mBufferToTexturePSMap[GL_UNSIGNED_INT] = d3d11::CompilePS(device, g_PS_BufferToTexture_4UI, "BufferToTexture RGBA-UI ps");
// Check that all the shaders were created successfully
for (auto shaderMapIt = mBufferToTexturePSMap.begin(); shaderMapIt != mBufferToTexturePSMap.end(); shaderMapIt++)
{
if (shaderMapIt->second == NULL)
{
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal buffer to texture pixel shader.");
}
}
return gl::Error(GL_NO_ERROR);
}
ID3D11PixelShader *PixelTransfer11::findBufferToTexturePS(GLenum internalFormat) const
......
......@@ -11,6 +11,8 @@
#ifndef LIBGLESV2_PIXELTRANSFER11_H_
#define LIBGLESV2_PIXELTRANSFER11_H_
#include "libGLESv2/Error.h"
#include "common/platform.h"
#include <GLES2/gl2.h>
......@@ -38,15 +40,13 @@ class PixelTransfer11
explicit PixelTransfer11(Renderer11 *renderer);
~PixelTransfer11();
static bool supportsBufferToTextureCopy(GLenum internalFormat);
// unpack: the source buffer is stored in the unpack state, and buffer strides
// offset: the start of the data within the unpack buffer
// destRenderTarget: individual slice/layer of a target texture
// destinationFormat/sourcePixelsType: determines shaders + shader parameters
// destArea: the sub-section of destRenderTarget to copy to
bool copyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea);
gl::Error copyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea);
private:
......@@ -65,11 +65,13 @@ class PixelTransfer11
static void setBufferToTextureCopyParams(const gl::Box &destArea, const gl::Extents &destSize, GLenum internalFormat,
const gl::PixelUnpackState &unpack, unsigned int offset, CopyShaderParams *parametersOut);
void buildShaderMap();
gl::Error loadResources();
gl::Error buildShaderMap();
ID3D11PixelShader *findBufferToTexturePS(GLenum internalFormat) const;
Renderer11 *mRenderer;
bool mResourcesLoaded;
std::map<GLenum, ID3D11PixelShader *> mBufferToTexturePSMap;
ID3D11VertexShader *mBufferToTextureVS;
ID3D11GeometryShader *mBufferToTextureGS;
......
......@@ -2476,8 +2476,8 @@ bool Renderer11::supportsFastCopyBufferToTexture(GLenum internalFormat) const
return true;
}
bool Renderer11::fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea)
gl::Error Renderer11::fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea)
{
ASSERT(supportsFastCopyBufferToTexture(destinationFormat));
return mPixelTransfer->copyBufferToTexture(unpack, offset, destRenderTarget, destinationFormat, sourcePixelsType, destArea);
......
......@@ -189,8 +189,8 @@ class Renderer11 : public Renderer
// Buffer-to-texture and Texture-to-buffer copies
virtual bool supportsFastCopyBufferToTexture(GLenum internalFormat) const;
virtual bool fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea);
virtual gl::Error fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea);
bool getRenderTargetResource(gl::FramebufferAttachment *colorbuffer, unsigned int *subresourceIndex, ID3D11Texture2D **resource);
void unapplyRenderTargets();
......
......@@ -628,12 +628,12 @@ bool Renderer9::supportsFastCopyBufferToTexture(GLenum internalFormat) const
return false;
}
bool Renderer9::fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea)
gl::Error Renderer9::fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea)
{
// Pixel buffer objects are not supported in D3D9, since D3D9 is ES2-only and PBOs are ES3.
UNREACHABLE();
return false;
return gl::Error(GL_INVALID_OPERATION);
}
gl::Error Renderer9::generateSwizzle(gl::Texture *texture)
......
......@@ -186,8 +186,8 @@ class Renderer9 : public Renderer
// Buffer-to-texture and Texture-to-buffer copies
virtual bool supportsFastCopyBufferToTexture(GLenum internalFormat) const;
virtual bool fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea);
virtual gl::Error fastCopyBufferToTexture(const gl::PixelUnpackState &unpack, unsigned int offset, RenderTarget *destRenderTarget,
GLenum destinationFormat, GLenum sourcePixelsType, const gl::Box &destArea);
// D3D9-renderer specific methods
gl::Error boxFilter(IDirect3DSurface9 *source, IDirect3DSurface9 *dest);
......
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