Commit e6382c3b by Jamie Madill

Fix zero texture application.

Patch https://chromium-review.googlesource.com/#/c/227711/ would allow NULL Textures sometimes from State::getSamplerTexture. Fix this by always setting the zero "Default" textures instead of NULL in the State. This was breaking the ES2-CTS test 'framebuffer_objects' on Windows. BUG=angle:826 Change-Id: Ie08a89cff0555f21c769759e0c0ed73456a2f91c Reviewed-on: https://chromium-review.googlesource.com/228275Tested-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Reviewed-by: 's avatarShannon Woods <shannonwoods@chromium.org>
parent b28126ef
...@@ -66,28 +66,24 @@ Context::Context(int clientVersion, const gl::Context *shareContext, rx::Rendere ...@@ -66,28 +66,24 @@ Context::Context(int clientVersion, const gl::Context *shareContext, rx::Rendere
// In order that access to these initial textures not be lost, they are treated as texture // In order that access to these initial textures not be lost, they are treated as texture
// objects all of whose names are 0. // objects all of whose names are 0.
ASSERT(mState.getActiveSampler() == 0);
Texture2D *zeroTexture2D = new Texture2D(mRenderer->createTexture(GL_TEXTURE_2D), 0); Texture2D *zeroTexture2D = new Texture2D(mRenderer->createTexture(GL_TEXTURE_2D), 0);
mZeroTextures[GL_TEXTURE_2D].set(zeroTexture2D); mZeroTextures[GL_TEXTURE_2D].set(zeroTexture2D);
mState.setSamplerTexture(GL_TEXTURE_2D, zeroTexture2D);
TextureCubeMap *zeroTextureCube = new TextureCubeMap(mRenderer->createTexture(GL_TEXTURE_CUBE_MAP), 0); TextureCubeMap *zeroTextureCube = new TextureCubeMap(mRenderer->createTexture(GL_TEXTURE_CUBE_MAP), 0);
mZeroTextures[GL_TEXTURE_CUBE_MAP].set(zeroTextureCube); mZeroTextures[GL_TEXTURE_CUBE_MAP].set(zeroTextureCube);
mState.setSamplerTexture(GL_TEXTURE_CUBE_MAP, zeroTextureCube);
if (mClientVersion >= 3) if (mClientVersion >= 3)
{ {
// TODO: These could also be enabled via extension // TODO: These could also be enabled via extension
Texture3D *zeroTexture3D = new Texture3D(mRenderer->createTexture(GL_TEXTURE_3D), 0); Texture3D *zeroTexture3D = new Texture3D(mRenderer->createTexture(GL_TEXTURE_3D), 0);
mZeroTextures[GL_TEXTURE_3D].set(zeroTexture3D); mZeroTextures[GL_TEXTURE_3D].set(zeroTexture3D);
mState.setSamplerTexture(GL_TEXTURE_3D, zeroTexture3D);
Texture2DArray *zeroTexture2DArray = new Texture2DArray(mRenderer->createTexture(GL_TEXTURE_2D_ARRAY), 0); Texture2DArray *zeroTexture2DArray = new Texture2DArray(mRenderer->createTexture(GL_TEXTURE_2D_ARRAY), 0);
mZeroTextures[GL_TEXTURE_2D_ARRAY].set(zeroTexture2DArray); mZeroTextures[GL_TEXTURE_2D_ARRAY].set(zeroTexture2DArray);
mState.setSamplerTexture(GL_TEXTURE_2D_ARRAY, zeroTexture2DArray);
} }
mState.initializeZeroTextures(mZeroTextures);
bindVertexArray(0); bindVertexArray(0);
bindArrayBuffer(0); bindArrayBuffer(0);
bindElementArrayBuffer(0); bindElementArrayBuffer(0);
...@@ -1413,7 +1409,8 @@ Error Context::generateSwizzles(ProgramBinary *programBinary, SamplerType type) ...@@ -1413,7 +1409,8 @@ Error Context::generateSwizzles(ProgramBinary *programBinary, SamplerType type)
GLint textureUnit = programBinary->getSamplerMapping(type, i, getCaps()); GLint textureUnit = programBinary->getSamplerMapping(type, i, getCaps());
if (textureUnit != -1) if (textureUnit != -1)
{ {
Texture* texture = getSamplerTexture(textureUnit, textureType); Texture *texture = getSamplerTexture(textureUnit, textureType);
ASSERT(texture);
if (texture->getSamplerState().swizzleRequired()) if (texture->getSamplerState().swizzleRequired())
{ {
Error error = mRenderer->generateSwizzle(texture); Error error = mRenderer->generateSwizzle(texture);
...@@ -1459,6 +1456,7 @@ Error Context::applyTextures(ProgramBinary *programBinary, SamplerType shaderTyp ...@@ -1459,6 +1456,7 @@ Error Context::applyTextures(ProgramBinary *programBinary, SamplerType shaderTyp
if (textureUnit != -1) if (textureUnit != -1)
{ {
Texture *texture = getSamplerTexture(textureUnit, textureType); Texture *texture = getSamplerTexture(textureUnit, textureType);
ASSERT(texture);
SamplerState sampler = texture->getSamplerState(); SamplerState sampler = texture->getSamplerState();
Sampler *samplerObject = mState.getSampler(textureUnit); Sampler *samplerObject = mState.getSampler(textureUnit);
...@@ -1999,7 +1997,7 @@ void Context::detachTexture(GLuint texture) ...@@ -1999,7 +1997,7 @@ void Context::detachTexture(GLuint texture)
// allocation map management either here or in the resource manager at detach time. // allocation map management either here or in the resource manager at detach time.
// Zero textures are held by the Context, and we don't attempt to request them from // Zero textures are held by the Context, and we don't attempt to request them from
// the State. // the State.
mState.detachTexture(texture); mState.detachTexture(mZeroTextures, texture);
} }
void Context::detachBuffer(GLuint buffer) void Context::detachBuffer(GLuint buffer)
......
...@@ -268,7 +268,6 @@ class Context ...@@ -268,7 +268,6 @@ class Context
int mClientVersion; int mClientVersion;
typedef std::map< GLenum, BindingPointer<Texture> > TextureMap;
TextureMap mZeroTextures; TextureMap mZeroTextures;
TextureMap mIncompleteTextures; TextureMap mIncompleteTextures;
......
...@@ -621,7 +621,7 @@ GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const ...@@ -621,7 +621,7 @@ GLuint State::getSamplerTextureId(unsigned int sampler, GLenum type) const
return mSamplerTextures.at(type)[sampler].id(); return mSamplerTextures.at(type)[sampler].id();
} }
void State::detachTexture(GLuint texture) void State::detachTexture(const TextureMap &zeroTextures, GLuint texture)
{ {
// Textures have a detach method on State rather than a simple // Textures have a detach method on State rather than a simple
// removeBinding, because the zero/null texture objects are managed // removeBinding, because the zero/null texture objects are managed
...@@ -634,13 +634,15 @@ void State::detachTexture(GLuint texture) ...@@ -634,13 +634,15 @@ void State::detachTexture(GLuint texture)
for (TextureBindingMap::iterator bindingVec = mSamplerTextures.begin(); bindingVec != mSamplerTextures.end(); bindingVec++) for (TextureBindingMap::iterator bindingVec = mSamplerTextures.begin(); bindingVec != mSamplerTextures.end(); bindingVec++)
{ {
GLenum textureType = bindingVec->first;
TextureBindingVector &textureVector = bindingVec->second; TextureBindingVector &textureVector = bindingVec->second;
for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++) for (size_t textureIdx = 0; textureIdx < textureVector.size(); textureIdx++)
{ {
BindingPointer<Texture> &binding = textureVector[textureIdx]; BindingPointer<Texture> &binding = textureVector[textureIdx];
if (binding.id() == texture) if (binding.id() == texture)
{ {
binding.set(NULL); // Zero textures are the "default" textures instead of NULL
binding.set(zeroTextures.at(textureType).get());
} }
} }
} }
...@@ -661,6 +663,19 @@ void State::detachTexture(GLuint texture) ...@@ -661,6 +663,19 @@ void State::detachTexture(GLuint texture)
} }
} }
void State::initializeZeroTextures(const TextureMap &zeroTextures)
{
for (const auto &zeroTexture : zeroTextures)
{
auto &samplerTextureArray = mSamplerTextures[zeroTexture.first];
for (size_t textureUnit = 0; textureUnit < samplerTextureArray.size(); ++textureUnit)
{
samplerTextureArray[textureUnit].set(zeroTexture.second.get());
}
}
}
void State::setSamplerBinding(GLuint textureUnit, Sampler *sampler) void State::setSamplerBinding(GLuint textureUnit, Sampler *sampler)
{ {
mSamplers[textureUnit].set(sampler); mSamplers[textureUnit].set(sampler);
......
...@@ -27,6 +27,8 @@ class Context; ...@@ -27,6 +27,8 @@ class Context;
struct Caps; struct Caps;
struct Data; struct Data;
typedef std::map< GLenum, BindingPointer<Texture> > TextureMap;
class State class State
{ {
public: public:
...@@ -132,7 +134,8 @@ class State ...@@ -132,7 +134,8 @@ class State
void setSamplerTexture(GLenum type, Texture *texture); void setSamplerTexture(GLenum type, Texture *texture);
Texture *getSamplerTexture(unsigned int sampler, GLenum type) const; Texture *getSamplerTexture(unsigned int sampler, GLenum type) const;
GLuint getSamplerTextureId(unsigned int sampler, GLenum type) const; GLuint getSamplerTextureId(unsigned int sampler, GLenum type) const;
void detachTexture(GLuint texture); void detachTexture(const TextureMap &zeroTextures, GLuint texture);
void initializeZeroTextures(const TextureMap &zeroTextures);
// Sampler object binding manipulation // Sampler object binding manipulation
void setSamplerBinding(GLuint textureUnit, Sampler *sampler); void setSamplerBinding(GLuint textureUnit, Sampler *sampler);
......
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