Commit 2c4edc2f by Nicolas Capens

Make back buffers non-lockable.

Bug 21716622 Change-Id: I041fd37d461114a52a3b3dfa57e4aee6c01e5ee5 Reviewed-on: https://swiftshader-review.googlesource.com/3445Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 477314b8
...@@ -356,6 +356,98 @@ namespace ...@@ -356,6 +356,98 @@ namespace
namespace egl namespace egl
{ {
sw::Format SelectInternalFormat(GLenum format, GLenum type)
{
if(format == GL_ETC1_RGB8_OES)
{
return sw::FORMAT_ETC1;
}
else
#if S3TC_SUPPORT
if(format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
{
return sw::FORMAT_DXT1;
}
else if(format == GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE)
{
return sw::FORMAT_DXT3;
}
else if(format == GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE)
{
return sw::FORMAT_DXT5;
}
else
#endif
if(type == GL_FLOAT)
{
return sw::FORMAT_A32B32G32R32F;
}
else if(type == GL_HALF_FLOAT || type == GL_HALF_FLOAT_OES)
{
return sw::FORMAT_A16B16G16R16F;
}
else if(type == GL_UNSIGNED_BYTE)
{
if(format == GL_LUMINANCE)
{
return sw::FORMAT_L8;
}
else if(format == GL_LUMINANCE_ALPHA)
{
return sw::FORMAT_A8L8;
}
else if(format == GL_RGBA)
{
return sw::FORMAT_A8B8G8R8;
}
else if(format == GL_BGRA_EXT)
{
return sw::FORMAT_A8R8G8B8;
}
else if(format == GL_RGB)
{
return sw::FORMAT_X8B8G8R8;
}
else if(format == GL_ALPHA)
{
return sw::FORMAT_A8;
}
else UNREACHABLE();
}
else if(type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT)
{
if(format == GL_DEPTH_COMPONENT)
{
return sw::FORMAT_D32FS8_TEXTURE;
}
else UNREACHABLE();
}
else if(type == GL_UNSIGNED_INT_24_8_OES)
{
if(format == GL_DEPTH_STENCIL_OES)
{
return sw::FORMAT_D32FS8_TEXTURE;
}
else UNREACHABLE();
}
else if(type == GL_UNSIGNED_SHORT_4_4_4_4)
{
return sw::FORMAT_A8R8G8B8;
}
else if(type == GL_UNSIGNED_SHORT_5_5_5_1)
{
return sw::FORMAT_A8R8G8B8;
}
else if(type == GL_UNSIGNED_SHORT_5_6_5)
{
return sw::FORMAT_X8R8G8B8;
}
else UNREACHABLE();
return sw::FORMAT_A8B8G8R8;
}
// Returns the size, in bytes, of a single texel in an Image // Returns the size, in bytes, of a single texel in an Image
int ComputePixelSize(GLenum format, GLenum type) int ComputePixelSize(GLenum format, GLenum type)
{ {
...@@ -491,98 +583,6 @@ namespace egl ...@@ -491,98 +583,6 @@ namespace egl
release(); release();
} }
sw::Format Image::selectInternalFormat(GLenum format, GLenum type)
{
if(format == GL_ETC1_RGB8_OES)
{
return sw::FORMAT_ETC1;
}
else
#if S3TC_SUPPORT
if(format == GL_COMPRESSED_RGB_S3TC_DXT1_EXT ||
format == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT)
{
return sw::FORMAT_DXT1;
}
else if(format == GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE)
{
return sw::FORMAT_DXT3;
}
else if(format == GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE)
{
return sw::FORMAT_DXT5;
}
else
#endif
if(type == GL_FLOAT)
{
return sw::FORMAT_A32B32G32R32F;
}
else if(type == GL_HALF_FLOAT || type == GL_HALF_FLOAT_OES)
{
return sw::FORMAT_A16B16G16R16F;
}
else if(type == GL_UNSIGNED_BYTE)
{
if(format == GL_LUMINANCE)
{
return sw::FORMAT_L8;
}
else if(format == GL_LUMINANCE_ALPHA)
{
return sw::FORMAT_A8L8;
}
else if(format == GL_RGBA)
{
return sw::FORMAT_A8B8G8R8;
}
else if(format == GL_BGRA_EXT)
{
return sw::FORMAT_A8R8G8B8;
}
else if(format == GL_RGB)
{
return sw::FORMAT_X8B8G8R8;
}
else if(format == GL_ALPHA)
{
return sw::FORMAT_A8;
}
else UNREACHABLE();
}
else if(type == GL_UNSIGNED_SHORT || type == GL_UNSIGNED_INT)
{
if(format == GL_DEPTH_COMPONENT)
{
return sw::FORMAT_D32FS8_TEXTURE;
}
else UNREACHABLE();
}
else if(type == GL_UNSIGNED_INT_24_8_OES)
{
if(format == GL_DEPTH_STENCIL_OES)
{
return sw::FORMAT_D32FS8_TEXTURE;
}
else UNREACHABLE();
}
else if(type == GL_UNSIGNED_SHORT_4_4_4_4)
{
return sw::FORMAT_A8R8G8B8;
}
else if(type == GL_UNSIGNED_SHORT_5_5_5_1)
{
return sw::FORMAT_A8R8G8B8;
}
else if(type == GL_UNSIGNED_SHORT_5_6_5)
{
return sw::FORMAT_X8R8G8B8;
}
else UNREACHABLE();
return sw::FORMAT_A8B8G8R8;
}
void Image::loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const UnpackInfo& unpackInfo, const void *input) void Image::loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const UnpackInfo& unpackInfo, const void *input)
{ {
GLsizei inputPitch = (unpackInfo.rowLength == 0) ? ComputePitch(width, format, type, unpackInfo.alignment) : unpackInfo.rowLength; GLsizei inputPitch = (unpackInfo.rowLength == 0) ? ComputePitch(width, format, type, unpackInfo.alignment) : unpackInfo.rowLength;
......
...@@ -30,6 +30,7 @@ typedef unsigned int GLenum; ...@@ -30,6 +30,7 @@ typedef unsigned int GLenum;
typedef int GLint; typedef int GLint;
typedef int GLsizei; typedef int GLsizei;
sw::Format SelectInternalFormat(GLenum format, GLenum type);
int ComputePixelSize(GLenum format, GLenum type); int ComputePixelSize(GLenum format, GLenum type);
GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment); GLsizei ComputePitch(GLsizei width, GLenum format, GLenum type, GLint alignment);
GLsizei ComputeCompressedPitch(GLsizei width, GLenum format); GLsizei ComputeCompressedPitch(GLsizei width, GLenum format);
...@@ -37,37 +38,33 @@ GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format); ...@@ -37,37 +38,33 @@ GLsizei ComputeCompressedSize(GLsizei width, GLsizei height, GLenum format);
static inline sw::Resource *getParentResource(egl::Texture *texture) static inline sw::Resource *getParentResource(egl::Texture *texture)
{ {
if (texture) return texture ? texture->getResource() : nullptr;
{
return texture->getResource();
}
return 0;
} }
class Image : public sw::Surface class Image : public sw::Surface
{ {
public: public:
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type) Image(Texture *parentTexture, GLsizei width, GLsizei height, GLenum format, GLenum type)
: sw::Surface(getParentResource(parentTexture), width, height, 1, selectInternalFormat(format, type), true, true), : sw::Surface(getParentResource(parentTexture), width, height, 1, SelectInternalFormat(format, type), true, true),
width(width), height(height), format(format), type(type), internalFormat(selectInternalFormat(format, type)), depth(1), width(width), height(height), format(format), type(type), internalFormat(SelectInternalFormat(format, type)), depth(1),
parentTexture(parentTexture) parentTexture(parentTexture)
{ {
shared = false; shared = false;
referenceCount = 1; referenceCount = 1;
} }
Image(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type) Image(Texture *parentTexture, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type)
: sw::Surface(getParentResource(parentTexture), width, height, depth, selectInternalFormat(format, type), true, true), : sw::Surface(getParentResource(parentTexture), width, height, depth, SelectInternalFormat(format, type), true, true),
width(width), height(height), format(format), type(type), internalFormat(selectInternalFormat(format, type)), depth(depth), width(width), height(height), format(format), type(type), internalFormat(SelectInternalFormat(format, type)), depth(depth),
parentTexture(parentTexture) parentTexture(parentTexture)
{ {
shared = false; shared = false;
referenceCount = 1; referenceCount = 1;
} }
Image(Texture *parentTexture, GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget) Image(GLsizei width, GLsizei height, sw::Format internalFormat, int multiSampleDepth, bool lockable, bool renderTarget)
: sw::Surface(getParentResource(parentTexture), width, height, multiSampleDepth, internalFormat, lockable, renderTarget), : sw::Surface(nullptr, width, height, multiSampleDepth, internalFormat, lockable, renderTarget),
width(width), height(height), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), internalFormat(internalFormat), depth(multiSampleDepth), parentTexture(parentTexture) width(width), height(height), format(0 /*GL_NONE*/), type(0 /*GL_NONE*/), internalFormat(internalFormat), depth(multiSampleDepth), parentTexture(nullptr)
{ {
shared = false; shared = false;
referenceCount = 1; referenceCount = 1;
...@@ -145,8 +142,6 @@ public: ...@@ -145,8 +142,6 @@ public:
void loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const UnpackInfo& unpackInfo, const void *input); void loadImageData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type, const UnpackInfo& unpackInfo, const void *input);
void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels); void loadCompressedData(GLint xoffset, GLint yoffset, GLint zoffset, GLsizei width, GLsizei height, GLsizei depth, GLsizei imageSize, const void *pixels);
static sw::Format selectInternalFormat(GLenum format, GLenum type);
virtual void addRef(); virtual void addRef();
virtual void release(); virtual void release();
virtual void unbind(const Texture *parent); // Break parent ownership and release virtual void unbind(const Texture *parent); // Break parent ownership and release
......
...@@ -173,7 +173,6 @@ bool Surface::reset(int backBufferWidth, int backBufferHeight) ...@@ -173,7 +173,6 @@ bool Surface::reset(int backBufferWidth, int backBufferHeight)
if(mConfig->mDepthStencilFormat != sw::FORMAT_NULL) if(mConfig->mDepthStencilFormat != sw::FORMAT_NULL)
{ {
if(libGLES_CM) if(libGLES_CM)
{ {
mDepthStencil = libGLES_CM->createDepthStencil(backBufferWidth, backBufferHeight, mConfig->mDepthStencilFormat, 1, false); mDepthStencil = libGLES_CM->createDepthStencil(backBufferWidth, backBufferHeight, mConfig->mDepthStencilFormat, 1, false);
......
...@@ -240,7 +240,7 @@ namespace es1 ...@@ -240,7 +240,7 @@ namespace es1
UNREACHABLE(); UNREACHABLE();
} }
egl::Image *surface = new egl::Image(0, width, height, format, multiSampleDepth, lockable, true); egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable, true);
if(!surface) if(!surface)
{ {
...@@ -259,7 +259,7 @@ namespace es1 ...@@ -259,7 +259,7 @@ namespace es1
return 0; return 0;
} }
egl::Image *surface = new egl::Image(0, width, height, format, multiSampleDepth, lockable, true); egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable, true);
if(!surface) if(!surface)
{ {
...@@ -406,7 +406,7 @@ namespace es1 ...@@ -406,7 +406,7 @@ namespace es1
this->viewport = viewport; this->viewport = viewport;
} }
bool Device::stretchRect(egl::Image *source, const sw::SliceRect *sourceRect, egl::Image *dest, const sw::SliceRect *destRect, bool filter) bool Device::stretchRect(sw::Surface *source, const sw::SliceRect *sourceRect, sw::Surface *dest, const sw::SliceRect *destRect, bool filter)
{ {
if(!source || !dest || !validRectangle(sourceRect, source) || !validRectangle(destRect, dest)) if(!source || !dest || !validRectangle(sourceRect, source) || !validRectangle(destRect, dest))
{ {
...@@ -612,7 +612,7 @@ namespace es1 ...@@ -612,7 +612,7 @@ namespace es1
return true; return true;
} }
bool Device::validRectangle(const sw::Rect *rect, egl::Image *surface) bool Device::validRectangle(const sw::Rect *rect, sw::Surface *surface)
{ {
if(!rect) if(!rect)
{ {
......
...@@ -64,7 +64,7 @@ namespace es1 ...@@ -64,7 +64,7 @@ namespace es1
virtual void setScissorRect(const sw::Rect &rect); virtual void setScissorRect(const sw::Rect &rect);
virtual void setViewport(const Viewport &viewport); virtual void setViewport(const Viewport &viewport);
virtual bool stretchRect(egl::Image *sourceSurface, const sw::SliceRect *sourceRect, egl::Image *destSurface, const sw::SliceRect *destRect, bool filter); virtual bool stretchRect(sw::Surface *sourceSurface, const sw::SliceRect *sourceRect, sw::Surface *destSurface, const sw::SliceRect *destRect, bool filter);
virtual void finish(); virtual void finish();
private: private:
...@@ -73,7 +73,7 @@ namespace es1 ...@@ -73,7 +73,7 @@ namespace es1
bool bindResources(); bool bindResources();
bool bindViewport(); // Also adjusts for scissoring bool bindViewport(); // Also adjusts for scissoring
bool validRectangle(const sw::Rect *rect, egl::Image *surface); bool validRectangle(const sw::Rect *rect, sw::Surface *surface);
Viewport viewport; Viewport viewport;
sw::Rect scissorRect; sw::Rect scissorRect;
......
...@@ -786,7 +786,7 @@ egl::Image *createBackBuffer(int width, int height, const egl::Config *config) ...@@ -786,7 +786,7 @@ egl::Image *createBackBuffer(int width, int height, const egl::Config *config)
{ {
if(config) if(config)
{ {
return new egl::Image(0, width, height, config->mAlphaSize ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE); return new egl::Image(width, height, config->mRenderTargetFormat, 1, false, true);
} }
return 0; return 0;
...@@ -825,7 +825,7 @@ egl::Image *createDepthStencil(unsigned int width, unsigned int height, sw::Form ...@@ -825,7 +825,7 @@ egl::Image *createDepthStencil(unsigned int width, unsigned int height, sw::Form
UNREACHABLE(); UNREACHABLE();
} }
egl::Image *surface = new egl::Image(0, width, height, format, multiSampleDepth, lockable, true); egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable, true);
if(!surface) if(!surface)
{ {
......
...@@ -248,7 +248,7 @@ namespace es2 ...@@ -248,7 +248,7 @@ namespace es2
UNREACHABLE(); UNREACHABLE();
} }
egl::Image *surface = new egl::Image(0, width, height, format, multiSampleDepth, lockable, true); egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable, true);
if(!surface) if(!surface)
{ {
...@@ -267,7 +267,7 @@ namespace es2 ...@@ -267,7 +267,7 @@ namespace es2
return 0; return 0;
} }
egl::Image *surface = new egl::Image(0, width, height, format, multiSampleDepth, lockable, true); egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable, true);
if(!surface) if(!surface)
{ {
...@@ -503,7 +503,7 @@ namespace es2 ...@@ -503,7 +503,7 @@ namespace es2
} }
} }
bool Device::stretchRect(egl::Image *source, const sw::SliceRect *sourceRect, egl::Image *dest, const sw::SliceRect *destRect, bool filter) bool Device::stretchRect(sw::Surface *source, const sw::SliceRect *sourceRect, sw::Surface *dest, const sw::SliceRect *destRect, bool filter)
{ {
if(!source || !dest) if(!source || !dest)
{ {
...@@ -665,7 +665,7 @@ namespace es2 ...@@ -665,7 +665,7 @@ namespace es2
return true; return true;
} }
bool Device::stretchCube(egl::Image *source, egl::Image *dest) bool Device::stretchCube(sw::Surface *source, sw::Surface *dest)
{ {
if(!source || !dest || egl::Image::isDepth(source->getInternalFormat()) || egl::Image::isStencil(source->getInternalFormat())) if(!source || !dest || egl::Image::isDepth(source->getInternalFormat()) || egl::Image::isStencil(source->getInternalFormat()))
{ {
...@@ -846,7 +846,7 @@ namespace es2 ...@@ -846,7 +846,7 @@ namespace es2
return true; return true;
} }
bool Device::validRectangle(const sw::Rect *rect, egl::Image *surface) bool Device::validRectangle(const sw::Rect *rect, sw::Surface *surface)
{ {
if(!rect) if(!rect)
{ {
......
...@@ -68,8 +68,8 @@ namespace es2 ...@@ -68,8 +68,8 @@ namespace es2
virtual void setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count); virtual void setVertexShaderConstantF(unsigned int startRegister, const float *constantData, unsigned int count);
virtual void setViewport(const Viewport &viewport); virtual void setViewport(const Viewport &viewport);
virtual bool stretchRect(egl::Image *sourceSurface, const sw::SliceRect *sourceRect, egl::Image *destSurface, const sw::SliceRect *destRect, bool filter); virtual bool stretchRect(sw::Surface *sourceSurface, const sw::SliceRect *sourceRect, sw::Surface *destSurface, const sw::SliceRect *destRect, bool filter);
virtual bool stretchCube(egl::Image *sourceSurface, egl::Image *destSurface); virtual bool stretchCube(sw::Surface *sourceSurface, sw::Surface *destSurface);
virtual void finish(); virtual void finish();
void getScissoredRegion(egl::Image *sourceSurface, int &x0, int &y0, int& width, int& height) const; void getScissoredRegion(egl::Image *sourceSurface, int &x0, int &y0, int& width, int& height) const;
...@@ -81,7 +81,7 @@ namespace es2 ...@@ -81,7 +81,7 @@ namespace es2
void bindShaderConstants(); void bindShaderConstants();
bool bindViewport(); // Also adjusts for scissoring bool bindViewport(); // Also adjusts for scissoring
bool validRectangle(const sw::Rect *rect, egl::Image *surface); bool validRectangle(const sw::Rect *rect, sw::Surface *surface);
void copyBuffer(sw::byte *sourceBuffer, sw::byte *destBuffer, unsigned int width, unsigned int height, unsigned int sourcePitch, unsigned int destPitch, unsigned int bytes, bool flipX, bool flipY); void copyBuffer(sw::byte *sourceBuffer, sw::byte *destBuffer, unsigned int width, unsigned int height, unsigned int sourcePitch, unsigned int destPitch, unsigned int bytes, bool flipX, bool flipY);
......
...@@ -1889,7 +1889,7 @@ egl::Image *createBackBuffer(int width, int height, const egl::Config *config) ...@@ -1889,7 +1889,7 @@ egl::Image *createBackBuffer(int width, int height, const egl::Config *config)
{ {
if(config) if(config)
{ {
return new egl::Image(0, width, height, config->mAlphaSize ? GL_RGBA : GL_RGB, GL_UNSIGNED_BYTE); return new egl::Image(width, height, config->mRenderTargetFormat, 1, false, true);
} }
return 0; return 0;
...@@ -1928,7 +1928,7 @@ egl::Image *createDepthStencil(unsigned int width, unsigned int height, sw::Form ...@@ -1928,7 +1928,7 @@ egl::Image *createDepthStencil(unsigned int width, unsigned int height, sw::Form
UNREACHABLE(); UNREACHABLE();
} }
egl::Image *surface = new egl::Image(0, width, height, format, multiSampleDepth, lockable, true); egl::Image *surface = new egl::Image(width, height, format, multiSampleDepth, lockable, true);
if(!surface) if(!surface)
{ {
......
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