Commit c483326b by Jamie Madill

Use ImageIndex in getRenderTargetSerial.

Also move getRenderTargetSerial to the TextureStorageInterface base class, since it shares a common interface. BUG=angle:741 Change-Id: I1bc1cfac6426e241ac91d373884a7dd8a1c5b188 Reviewed-on: https://chromium-review.googlesource.com/218313Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent f7100b98
......@@ -155,7 +155,7 @@ unsigned int RenderbufferStorage::getSerial() const
return mSerial;
}
unsigned int RenderbufferStorage::issueSerials(GLuint count)
unsigned int RenderbufferStorage::issueSerials(unsigned int count)
{
unsigned int firstSerial = mCurrentSerial;
mCurrentSerial += count;
......
......@@ -83,7 +83,7 @@ class RenderbufferStorage
virtual bool isTexture() const;
virtual unsigned int getTextureSerial() const;
static unsigned int issueSerials(GLuint count);
static unsigned int issueSerials(unsigned int count);
protected:
GLsizei mWidth;
......
......@@ -455,7 +455,9 @@ void TextureD3D_2D::storage(GLenum target, GLsizei levels, GLenum internalformat
mImmutable = true;
setCompleteTexStorage(new TextureStorageInterface2D(mRenderer, internalformat, IsRenderTargetUsage(mUsage), width, height, levels));
bool renderTarget = IsRenderTargetUsage(mUsage);
TextureStorage *storage = mRenderer->createTextureStorage2D(internalformat, renderTarget, width, height, levels);
setCompleteTexStorage(new TextureStorageInterface2D(storage));
}
void TextureD3D_2D::bindTexImage(egl::Surface *surface)
......@@ -518,7 +520,7 @@ void TextureD3D_2D::generateMipmaps()
unsigned int TextureD3D_2D::getRenderTargetSerial(const gl::ImageIndex &index)
{
ASSERT(!index.hasLayer());
return (ensureRenderTarget() ? mTexStorage->getRenderTargetSerial(index.mipIndex) : 0);
return (ensureRenderTarget() ? mTexStorage->getRenderTargetSerial(index) : 0);
}
RenderTarget *TextureD3D_2D::getRenderTarget(const gl::ImageIndex &index)
......@@ -612,13 +614,15 @@ TextureStorageInterface2D *TextureD3D_2D::createCompleteStorage(bool renderTarge
{
GLsizei width = getBaseLevelWidth();
GLsizei height = getBaseLevelHeight();
GLenum internalFormat = getBaseLevelInternalFormat();
ASSERT(width > 0 && height > 0);
// use existing storage level count, when previously specified by TexStorage*D
GLint levels = (mTexStorage ? mTexStorage->getLevelCount() : creationLevels(width, height, 1));
return new TextureStorageInterface2D(mRenderer, getBaseLevelInternalFormat(), renderTarget, width, height, levels);
TextureStorage *storageInstance = mRenderer->createTextureStorage2D(internalFormat, renderTarget, width, height, levels);
return new TextureStorageInterface2D(storageInstance);
}
void TextureD3D_2D::setCompleteTexStorage(TextureStorageInterface2D *newCompleteTexStorage)
......@@ -938,7 +942,9 @@ void TextureD3D_Cube::storage(GLenum target, GLsizei levels, GLenum internalform
mImmutable = true;
setCompleteTexStorage(new TextureStorageInterfaceCube(mRenderer, internalformat, IsRenderTargetUsage(mUsage), width, levels));
bool renderTarget = IsRenderTargetUsage(mUsage);
TextureStorage *storageInstance = mRenderer->createTextureStorageCube(internalformat, renderTarget, width, levels);
setCompleteTexStorage(new TextureStorageInterfaceCube(storageInstance));
}
// Tests for cube texture completeness. [OpenGL ES 2.0.24] section 3.7.10 page 81.
......@@ -1018,7 +1024,7 @@ void TextureD3D_Cube::generateMipmaps()
unsigned int TextureD3D_Cube::getRenderTargetSerial(const gl::ImageIndex &index)
{
return (ensureRenderTarget() ? mTexStorage->getRenderTargetSerial(index.type, index.mipIndex) : 0);
return (ensureRenderTarget() ? mTexStorage->getRenderTargetSerial(index) : 0);
}
RenderTarget *TextureD3D_Cube::getRenderTarget(const gl::ImageIndex &index)
......@@ -1067,7 +1073,8 @@ TextureStorageInterfaceCube *TextureD3D_Cube::createCompleteStorage(bool renderT
// use existing storage level count, when previously specified by TexStorage*D
GLint levels = (mTexStorage ? mTexStorage->getLevelCount() : creationLevels(size, size, 1));
return new TextureStorageInterfaceCube(mRenderer, getBaseLevelInternalFormat(), renderTarget, size, levels);
TextureStorage *storage = mRenderer->createTextureStorageCube(getBaseLevelInternalFormat(), renderTarget, size, levels);
return new TextureStorageInterfaceCube(storage);
}
void TextureD3D_Cube::setCompleteTexStorage(TextureStorageInterfaceCube *newCompleteTexStorage)
......@@ -1461,7 +1468,9 @@ void TextureD3D_3D::storage(GLenum target, GLsizei levels, GLenum internalformat
mImmutable = true;
setCompleteTexStorage(new TextureStorageInterface3D(mRenderer, internalformat, IsRenderTargetUsage(mUsage), width, height, depth, levels));
bool renderTarget = IsRenderTargetUsage(mUsage);
TextureStorage *storage = mRenderer->createTextureStorage3D(internalformat, renderTarget, width, height, depth, levels);
setCompleteTexStorage(new TextureStorageInterface3D(storage, depth));
}
void TextureD3D_3D::bindTexImage(egl::Surface *surface)
......@@ -1507,7 +1516,7 @@ void TextureD3D_3D::generateMipmaps()
unsigned int TextureD3D_3D::getRenderTargetSerial(const gl::ImageIndex &index)
{
return (ensureRenderTarget() ? mTexStorage->getRenderTargetSerial(index.mipIndex, index.layerIndex) : 0);
return (ensureRenderTarget() ? mTexStorage->getRenderTargetSerial(index) : 0);
}
RenderTarget *TextureD3D_3D::getRenderTarget(const gl::ImageIndex &index)
......@@ -1558,13 +1567,15 @@ TextureStorageInterface3D *TextureD3D_3D::createCompleteStorage(bool renderTarge
GLsizei width = getBaseLevelWidth();
GLsizei height = getBaseLevelHeight();
GLsizei depth = getBaseLevelDepth();
GLenum internalFormat = getBaseLevelInternalFormat();
ASSERT(width > 0 && height > 0 && depth > 0);
// use existing storage level count, when previously specified by TexStorage*D
GLint levels = (mTexStorage ? mTexStorage->getLevelCount() : creationLevels(width, height, depth));
return new TextureStorageInterface3D(mRenderer, getBaseLevelInternalFormat(), renderTarget, width, height, depth, levels);
TextureStorage *storage = mRenderer->createTextureStorage3D(internalFormat, renderTarget, width, height, depth, levels);
return new TextureStorageInterface3D(storage, depth);
}
void TextureD3D_3D::setCompleteTexStorage(TextureStorageInterface3D *newCompleteTexStorage)
......@@ -1938,7 +1949,10 @@ void TextureD3D_2DArray::storage(GLenum target, GLsizei levels, GLenum internalf
}
mImmutable = true;
setCompleteTexStorage(new TextureStorageInterface2DArray(mRenderer, internalformat, IsRenderTargetUsage(mUsage), width, height, depth, levels));
bool renderTarget = IsRenderTargetUsage(mUsage);
TextureStorage *storage = mRenderer->createTextureStorage2DArray(internalformat, renderTarget, width, height, depth, levels);
setCompleteTexStorage(new TextureStorageInterface2DArray(storage, depth));
}
void TextureD3D_2DArray::bindTexImage(egl::Surface *surface)
......@@ -1992,7 +2006,7 @@ void TextureD3D_2DArray::generateMipmaps()
unsigned int TextureD3D_2DArray::getRenderTargetSerial(const gl::ImageIndex &index)
{
return (ensureRenderTarget() ? mTexStorage->getRenderTargetSerial(index.mipIndex, index.layerIndex) : 0);
return (ensureRenderTarget() ? mTexStorage->getRenderTargetSerial(index) : 0);
}
RenderTarget *TextureD3D_2DArray::getRenderTarget(const gl::ImageIndex &index)
......@@ -2035,13 +2049,15 @@ TextureStorageInterface2DArray *TextureD3D_2DArray::createCompleteStorage(bool r
GLsizei width = getBaseLevelWidth();
GLsizei height = getBaseLevelHeight();
GLsizei depth = getLayers(0);
GLenum internalFormat = getBaseLevelInternalFormat();
ASSERT(width > 0 && height > 0 && depth > 0);
// use existing storage level count, when previously specified by TexStorage*D
GLint levels = (mTexStorage ? mTexStorage->getLevelCount() : creationLevels(width, height, 1));
return new TextureStorageInterface2DArray(mRenderer, getBaseLevelInternalFormat(), renderTarget, width, height, depth, levels);
TextureStorage *storage = mRenderer->createTextureStorage2DArray(internalFormat, renderTarget, width, height, depth, levels);
return new TextureStorageInterface2DArray(storage, depth);
}
void TextureD3D_2DArray::setCompleteTexStorage(TextureStorageInterface2DArray *newCompleteTexStorage)
......
......@@ -21,11 +21,12 @@ namespace rx
{
unsigned int TextureStorageInterface::mCurrentTextureSerial = 1;
TextureStorageInterface::TextureStorageInterface()
TextureStorageInterface::TextureStorageInterface(TextureStorage *textureStorage, unsigned int rtSerialLayerStride)
: mTextureSerial(issueTextureSerial()),
mInstance(NULL)
{
}
mInstance(textureStorage),
mFirstRenderTargetSerial(gl::RenderbufferStorage::issueSerials(static_cast<unsigned int>(textureStorage->getLevelCount()) * rtSerialLayerStride)),
mRenderTargetSerialsLayerStride(rtSerialLayerStride)
{}
TextureStorageInterface::~TextureStorageInterface()
{
......@@ -62,94 +63,62 @@ int TextureStorageInterface::getLevelCount() const
return mInstance->getLevelCount();
}
TextureStorageInterface2D::TextureStorageInterface2D(Renderer *renderer, SwapChain *swapchain)
unsigned int TextureStorageInterface::getRenderTargetSerial(const gl::ImageIndex &index) const
{
mFirstRenderTargetSerial = gl::RenderbufferStorage::issueSerials(1);
mInstance = renderer->createTextureStorage2D(swapchain);
unsigned int layerOffset = (index.hasLayer() ? (static_cast<unsigned int>(index.layerIndex) * mRenderTargetSerialsLayerStride) : 0);
return mFirstRenderTargetSerial + static_cast<unsigned int>(index.mipIndex) + layerOffset;
}
TextureStorageInterface2D::TextureStorageInterface2D(Renderer *renderer, GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels)
{
mInstance = renderer->createTextureStorage2D(internalformat, renderTarget, width, height, levels);
mFirstRenderTargetSerial = gl::RenderbufferStorage::issueSerials(static_cast<GLuint>(mInstance->getLevelCount()));
}
TextureStorageInterface2D::TextureStorageInterface2D(Renderer *renderer, SwapChain *swapchain)
: TextureStorageInterface(renderer->createTextureStorage2D(swapchain), 1)
{}
TextureStorageInterface2D::TextureStorageInterface2D(TextureStorage *storageInstance)
: TextureStorageInterface(storageInstance, 1)
{}
TextureStorageInterface2D::~TextureStorageInterface2D()
{
}
{}
void TextureStorageInterface2D::generateMipmap(int level)
{
mInstance->generateMipmap(level);
}
unsigned int TextureStorageInterface2D::getRenderTargetSerial(GLint level) const
{
return mFirstRenderTargetSerial + level;
}
TextureStorageInterfaceCube::TextureStorageInterfaceCube(Renderer *renderer, GLenum internalformat, bool renderTarget, int size, int levels)
{
mInstance = renderer->createTextureStorageCube(internalformat, renderTarget, size, levels);
mFirstRenderTargetSerial = gl::RenderbufferStorage::issueSerials(static_cast<GLuint>(mInstance->getLevelCount() * 6));
}
TextureStorageInterfaceCube::TextureStorageInterfaceCube(TextureStorage *storageInstance)
: TextureStorageInterface(storageInstance, 6)
{}
TextureStorageInterfaceCube::~TextureStorageInterfaceCube()
{
}
{}
void TextureStorageInterfaceCube::generateMipmap(int faceIndex, int level)
{
mInstance->generateMipmap(faceIndex, level);
}
unsigned int TextureStorageInterfaceCube::getRenderTargetSerial(GLenum target, GLint level) const
{
return mFirstRenderTargetSerial + (level * 6) + gl::TextureCubeMap::targetToLayerIndex(target);
}
TextureStorageInterface3D::TextureStorageInterface3D(Renderer *renderer, GLenum internalformat, bool renderTarget,
GLsizei width, GLsizei height, GLsizei depth, int levels)
{
mInstance = renderer->createTextureStorage3D(internalformat, renderTarget, width, height, depth, levels);
mFirstRenderTargetSerial = gl::RenderbufferStorage::issueSerials(static_cast<GLuint>(mInstance->getLevelCount() * depth));
}
TextureStorageInterface3D::TextureStorageInterface3D(TextureStorage *storageInstance, unsigned int depth)
: TextureStorageInterface(storageInstance, depth)
{}
TextureStorageInterface3D::~TextureStorageInterface3D()
{
}
{}
void TextureStorageInterface3D::generateMipmap(int level)
{
mInstance->generateMipmap(level);
}
unsigned int TextureStorageInterface3D::getRenderTargetSerial(GLint level, GLint layer) const
{
return mFirstRenderTargetSerial + static_cast<unsigned int>((layer * mInstance->getLevelCount()) + level);
}
TextureStorageInterface2DArray::TextureStorageInterface2DArray(Renderer *renderer, GLenum internalformat, bool renderTarget,
GLsizei width, GLsizei height, GLsizei depth, int levels)
{
mInstance = renderer->createTextureStorage2DArray(internalformat, renderTarget, width, height, depth, levels);
mFirstRenderTargetSerial = gl::RenderbufferStorage::issueSerials(static_cast<GLuint>(mInstance->getLevelCount() * depth));
}
TextureStorageInterface2DArray::TextureStorageInterface2DArray(TextureStorage *storageInstance, unsigned int depth)
: TextureStorageInterface(storageInstance, depth)
{}
TextureStorageInterface2DArray::~TextureStorageInterface2DArray()
{
}
{}
void TextureStorageInterface2DArray::generateMipmap(int level)
{
mInstance->generateMipmap(level);
}
unsigned int TextureStorageInterface2DArray::getRenderTargetSerial(GLint level, GLint layer) const
{
return mFirstRenderTargetSerial + static_cast<unsigned int>((layer * mInstance->getLevelCount()) + level);
}
}
......@@ -49,7 +49,7 @@ class TextureStorage
class TextureStorageInterface
{
public:
TextureStorageInterface();
TextureStorageInterface(TextureStorage *storageInstance, unsigned int rtSerialLayerStride);
virtual ~TextureStorageInterface();
TextureStorage *getStorageInstance() { return mInstance; }
......@@ -61,6 +61,8 @@ class TextureStorageInterface
virtual bool isManaged() const;
virtual int getLevelCount() const;
unsigned int getRenderTargetSerial(const gl::ImageIndex &index) const;
protected:
TextureStorage *mInstance;
......@@ -71,73 +73,58 @@ class TextureStorageInterface
static unsigned int issueTextureSerial();
static unsigned int mCurrentTextureSerial;
unsigned int mFirstRenderTargetSerial;
unsigned int mRenderTargetSerialsLayerStride;
};
class TextureStorageInterface2D : public TextureStorageInterface
{
public:
TextureStorageInterface2D(Renderer *renderer, SwapChain *swapchain);
TextureStorageInterface2D(Renderer *renderer, GLenum internalformat, bool renderTarget, GLsizei width, GLsizei height, int levels);
TextureStorageInterface2D(TextureStorage *storageInstance);
virtual ~TextureStorageInterface2D();
void generateMipmap(int level);
unsigned int getRenderTargetSerial(GLint level) const;
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorageInterface2D);
unsigned int mFirstRenderTargetSerial;
};
class TextureStorageInterfaceCube : public TextureStorageInterface
{
public:
TextureStorageInterfaceCube(Renderer *renderer, GLenum internalformat, bool renderTarget, int size, int levels);
TextureStorageInterfaceCube(TextureStorage *storageInstance);
virtual ~TextureStorageInterfaceCube();
void generateMipmap(int faceIndex, int level);
virtual unsigned int getRenderTargetSerial(GLenum target, GLint level) const;
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorageInterfaceCube);
unsigned int mFirstRenderTargetSerial;
};
class TextureStorageInterface3D : public TextureStorageInterface
{
public:
TextureStorageInterface3D(Renderer *renderer, GLenum internalformat, bool renderTarget,
GLsizei width, GLsizei height, GLsizei depth, int levels);
TextureStorageInterface3D(TextureStorage *storageInstance, unsigned int depth);
virtual ~TextureStorageInterface3D();
void generateMipmap(int level);
virtual unsigned int getRenderTargetSerial(GLint level, GLint layer) const;
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorageInterface3D);
unsigned int mFirstRenderTargetSerial;
};
class TextureStorageInterface2DArray : public TextureStorageInterface
{
public:
TextureStorageInterface2DArray(Renderer *renderer, GLenum internalformat, bool renderTarget,
GLsizei width, GLsizei height, GLsizei depth, int levels);
TextureStorageInterface2DArray(TextureStorage *storageInstance, unsigned int depth);
virtual ~TextureStorageInterface2DArray();
void generateMipmap(int level);
virtual unsigned int getRenderTargetSerial(GLint level, GLint layer) const;
private:
DISALLOW_COPY_AND_ASSIGN(TextureStorageInterface2DArray);
unsigned int mFirstRenderTargetSerial;
};
}
......
......@@ -137,4 +137,54 @@ TEST_F(ClearTest, MaskedClearBufferBug)
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, 0, 0);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
EXPECT_PIXEL_EQ(0, 0, 0, 127, 255, 255);
glDeleteTextures(2, textures);
}
TEST_F(ClearTest, BadFBOSerialBug)
{
// First make a simple framebuffer, and clear it to green
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
GLuint textures[2];
glGenTextures(2, &textures[0]);
glBindTexture(GL_TEXTURE_2D, textures[0]);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[0], 0);
GLenum drawBuffers[] = { GL_COLOR_ATTACHMENT0 };
glDrawBuffers(1, drawBuffers);
float clearValues1[] = { 0.0f, 1.0f, 0.0f, 1.0f };
glClearBufferfv(GL_COLOR, 0, clearValues1);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
// Next make a second framebuffer, and draw it to red
// (Triggers bad applied render target serial)
GLuint fbo2;
glGenFramebuffers(1, &fbo2);
ASSERT_GL_NO_ERROR();
glBindFramebuffer(GL_FRAMEBUFFER, fbo2);
glBindTexture(GL_TEXTURE_2D, textures[1]);
glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, getWindowWidth(), getWindowHeight());
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textures[1], 0);
glDrawBuffers(1, drawBuffers);
drawQuad(mProgram, "position", 0.5f);
ASSERT_GL_NO_ERROR();
EXPECT_PIXEL_EQ(0, 0, 255, 0, 0, 255);
// Check that the first framebuffer is still green.
glBindFramebuffer(GL_FRAMEBUFFER, mFBO);
EXPECT_PIXEL_EQ(0, 0, 0, 255, 0, 255);
glDeleteTextures(2, textures);
glDeleteFramebuffers(1, &fbo2);
}
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