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