Commit eaa759c4 by Geoff Lang

Remove Texture serials and Texture::INCOMPLETE_TEXTURE_ID.

Texture serials were not used in any place that pointers could not be used and Texture::INCOMPLETE_TEXTURE_ID was only referenced by RendererD3D. This was the last place that serials are used in the gl layer. BUG=angleproject:681 Change-Id: Iad24321fba57db8ade3c9eb8f04cc20e98ded1b0 Reviewed-on: https://chromium-review.googlesource.com/263659Reviewed-by: 's avatarBrandon Jones <bajones@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org> Tested-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent c2520564
...@@ -45,12 +45,9 @@ static size_t GetImageDescIndex(GLenum target, size_t level) ...@@ -45,12 +45,9 @@ static size_t GetImageDescIndex(GLenum target, size_t level)
return IsCubeMapTextureTarget(target) ? ((level * 6) + CubeMapTextureTargetToLayerIndex(target)) : level; return IsCubeMapTextureTarget(target) ? ((level * 6) + CubeMapTextureTargetToLayerIndex(target)) : level;
} }
unsigned int Texture::mCurrentTextureSerial = 1;
Texture::Texture(rx::TextureImpl *impl, GLuint id, GLenum target) Texture::Texture(rx::TextureImpl *impl, GLuint id, GLenum target)
: FramebufferAttachmentObject(id), : FramebufferAttachmentObject(id),
mTexture(impl), mTexture(impl),
mTextureSerial(issueTextureSerial()),
mUsage(GL_NONE), mUsage(GL_NONE),
mImmutableLevelCount(0), mImmutableLevelCount(0),
mTarget(target), mTarget(target),
...@@ -155,16 +152,6 @@ bool Texture::isCubeComplete() const ...@@ -155,16 +152,6 @@ bool Texture::isCubeComplete() const
return true; return true;
} }
unsigned int Texture::getTextureSerial() const
{
return mTextureSerial;
}
unsigned int Texture::issueTextureSerial()
{
return mCurrentTextureSerial++;
}
bool Texture::isImmutable() const bool Texture::isImmutable() const
{ {
return (mImmutableLevelCount > 0); return (mImmutableLevelCount > 0);
......
...@@ -75,10 +75,6 @@ class Texture final : public FramebufferAttachmentObject ...@@ -75,10 +75,6 @@ class Texture final : public FramebufferAttachmentObject
virtual Error generateMipmaps(); virtual Error generateMipmaps();
// Texture serials provide a unique way of identifying a Texture that isn't a raw pointer.
// "id" is not good enough, as Textures can be deleted, then re-allocated with the same id.
unsigned int getTextureSerial() const;
bool isImmutable() const; bool isImmutable() const;
GLsizei immutableLevelCount(); GLsizei immutableLevelCount();
...@@ -88,8 +84,6 @@ class Texture final : public FramebufferAttachmentObject ...@@ -88,8 +84,6 @@ class Texture final : public FramebufferAttachmentObject
rx::TextureImpl *getImplementation() { return mTexture; } rx::TextureImpl *getImplementation() { return mTexture; }
const rx::TextureImpl *getImplementation() const { return mTexture; } const rx::TextureImpl *getImplementation() const { return mTexture; }
static const GLuint INCOMPLETE_TEXTURE_ID = static_cast<GLuint>(-1); // Every texture takes an id at creation time. The value is arbitrary because it is never registered with the resource manager.
// FramebufferAttachmentObject implementation // FramebufferAttachmentObject implementation
GLsizei getAttachmentWidth(const FramebufferAttachment::Target &target) const override; GLsizei getAttachmentWidth(const FramebufferAttachment::Target &target) const override;
GLsizei getAttachmentHeight(const FramebufferAttachment::Target &target) const override; GLsizei getAttachmentHeight(const FramebufferAttachment::Target &target) const override;
...@@ -98,7 +92,6 @@ class Texture final : public FramebufferAttachmentObject ...@@ -98,7 +92,6 @@ class Texture final : public FramebufferAttachmentObject
private: private:
rx::FramebufferAttachmentObjectImpl *getAttachmentImpl() const override { return mTexture; } rx::FramebufferAttachmentObjectImpl *getAttachmentImpl() const override { return mTexture; }
static unsigned int issueTextureSerial();
rx::TextureImpl *mTexture; rx::TextureImpl *mTexture;
...@@ -109,7 +102,6 @@ class Texture final : public FramebufferAttachmentObject ...@@ -109,7 +102,6 @@ class Texture final : public FramebufferAttachmentObject
GLenum mTarget; GLenum mTarget;
struct ImageDesc struct ImageDesc
{ {
Extents size; Extents size;
...@@ -119,9 +111,6 @@ class Texture final : public FramebufferAttachmentObject ...@@ -119,9 +111,6 @@ class Texture final : public FramebufferAttachmentObject
ImageDesc(const Extents &size, GLenum internalFormat); ImageDesc(const Extents &size, GLenum internalFormat);
}; };
const unsigned int mTextureSerial;
static unsigned int mCurrentTextureSerial;
GLenum getBaseImageTarget() const; GLenum getBaseImageTarget() const;
size_t getExpectedMipLevels() const; size_t getExpectedMipLevels() const;
......
...@@ -32,6 +32,8 @@ namespace ...@@ -32,6 +32,8 @@ namespace
const int ScratchMemoryBufferLifetime = 1000; const int ScratchMemoryBufferLifetime = 1000;
} }
const uintptr_t RendererD3D::DirtyPointer = std::numeric_limits<uintptr_t>::max();
RendererD3D::RendererD3D(egl::Display *display) RendererD3D::RendererD3D(egl::Display *display)
: mDisplay(display), : mDisplay(display),
mDeviceLost(false), mDeviceLost(false),
...@@ -372,7 +374,7 @@ gl::Error RendererD3D::applyShaders(const gl::Data &data) ...@@ -372,7 +374,7 @@ gl::Error RendererD3D::applyShaders(const gl::Data &data)
// looks up the corresponding OpenGL texture image unit and texture type, // looks up the corresponding OpenGL texture image unit and texture type,
// and sets the texture and its addressing/filtering state (or NULL when inactive). // and sets the texture and its addressing/filtering state (or NULL when inactive).
gl::Error RendererD3D::applyTextures(const gl::Data &data, gl::SamplerType shaderType, gl::Error RendererD3D::applyTextures(const gl::Data &data, gl::SamplerType shaderType,
const FramebufferTextureSerialArray &framebufferSerials, size_t framebufferSerialCount) const FramebufferTextureArray &framebufferTextures, size_t framebufferTextureCount)
{ {
gl::Program *program = data.state->getProgram(); gl::Program *program = data.state->getProgram();
...@@ -395,7 +397,7 @@ gl::Error RendererD3D::applyTextures(const gl::Data &data, gl::SamplerType shade ...@@ -395,7 +397,7 @@ gl::Error RendererD3D::applyTextures(const gl::Data &data, gl::SamplerType shade
// TODO: std::binary_search may become unavailable using older versions of GCC // TODO: std::binary_search may become unavailable using older versions of GCC
if (texture->isSamplerComplete(sampler, data) && if (texture->isSamplerComplete(sampler, data) &&
!std::binary_search(framebufferSerials.begin(), framebufferSerials.begin() + framebufferSerialCount, texture->getTextureSerial())) !std::binary_search(framebufferTextures.begin(), framebufferTextures.begin() + framebufferTextureCount, texture))
{ {
gl::Error error = setSamplerState(shaderType, samplerIndex, texture, sampler); gl::Error error = setSamplerState(shaderType, samplerIndex, texture, sampler);
if (error.isError()) if (error.isError())
...@@ -448,16 +450,16 @@ gl::Error RendererD3D::applyTextures(const gl::Data &data, gl::SamplerType shade ...@@ -448,16 +450,16 @@ gl::Error RendererD3D::applyTextures(const gl::Data &data, gl::SamplerType shade
gl::Error RendererD3D::applyTextures(const gl::Data &data) gl::Error RendererD3D::applyTextures(const gl::Data &data)
{ {
FramebufferTextureSerialArray framebufferSerials; FramebufferTextureArray framebufferTextures;
size_t framebufferSerialCount = getBoundFramebufferTextureSerials(data, &framebufferSerials); size_t framebufferSerialCount = getBoundFramebufferTextures(data, &framebufferTextures);
gl::Error error = applyTextures(data, gl::SAMPLER_VERTEX, framebufferSerials, framebufferSerialCount); gl::Error error = applyTextures(data, gl::SAMPLER_VERTEX, framebufferTextures, framebufferSerialCount);
if (error.isError()) if (error.isError())
{ {
return error; return error;
} }
error = applyTextures(data, gl::SAMPLER_PIXEL, framebufferSerials, framebufferSerialCount); error = applyTextures(data, gl::SAMPLER_PIXEL, framebufferTextures, framebufferSerialCount);
if (error.isError()) if (error.isError())
{ {
return error; return error;
...@@ -507,10 +509,9 @@ void RendererD3D::markTransformFeedbackUsage(const gl::Data &data) ...@@ -507,10 +509,9 @@ void RendererD3D::markTransformFeedbackUsage(const gl::Data &data)
} }
} }
size_t RendererD3D::getBoundFramebufferTextureSerials(const gl::Data &data, size_t RendererD3D::getBoundFramebufferTextures(const gl::Data &data, FramebufferTextureArray *outTextureArray)
FramebufferTextureSerialArray *outSerialArray)
{ {
size_t serialCount = 0; size_t textureCount = 0;
const gl::Framebuffer *drawFramebuffer = data.state->getDrawFramebuffer(); const gl::Framebuffer *drawFramebuffer = data.state->getDrawFramebuffer();
for (unsigned int i = 0; i < data.caps->maxColorAttachments; i++) for (unsigned int i = 0; i < data.caps->maxColorAttachments; i++)
...@@ -518,21 +519,19 @@ size_t RendererD3D::getBoundFramebufferTextureSerials(const gl::Data &data, ...@@ -518,21 +519,19 @@ size_t RendererD3D::getBoundFramebufferTextureSerials(const gl::Data &data,
const gl::FramebufferAttachment *attachment = drawFramebuffer->getColorbuffer(i); const gl::FramebufferAttachment *attachment = drawFramebuffer->getColorbuffer(i);
if (attachment && attachment->type() == GL_TEXTURE) if (attachment && attachment->type() == GL_TEXTURE)
{ {
gl::Texture *texture = attachment->getTexture(); (*outTextureArray)[textureCount++] = attachment->getTexture();
(*outSerialArray)[serialCount++] = texture->getTextureSerial();
} }
} }
const gl::FramebufferAttachment *depthStencilAttachment = drawFramebuffer->getDepthOrStencilbuffer(); const gl::FramebufferAttachment *depthStencilAttachment = drawFramebuffer->getDepthOrStencilbuffer();
if (depthStencilAttachment && depthStencilAttachment->type() == GL_TEXTURE) if (depthStencilAttachment && depthStencilAttachment->type() == GL_TEXTURE)
{ {
gl::Texture *depthStencilTexture = depthStencilAttachment->getTexture(); (*outTextureArray)[textureCount++] = depthStencilAttachment->getTexture();
(*outSerialArray)[serialCount++] = depthStencilTexture->getTextureSerial();
} }
std::sort(outSerialArray->begin(), outSerialArray->begin() + serialCount); std::sort(outTextureArray->begin(), outTextureArray->begin() + textureCount);
return serialCount; return textureCount;
} }
gl::Texture *RendererD3D::getIncompleteTexture(GLenum type) gl::Texture *RendererD3D::getIncompleteTexture(GLenum type)
...@@ -543,7 +542,7 @@ gl::Texture *RendererD3D::getIncompleteTexture(GLenum type) ...@@ -543,7 +542,7 @@ gl::Texture *RendererD3D::getIncompleteTexture(GLenum type)
const gl::Extents colorSize(1, 1, 1); const gl::Extents colorSize(1, 1, 1);
const gl::PixelUnpackState incompleteUnpackState(1, 0); const gl::PixelUnpackState incompleteUnpackState(1, 0);
gl::Texture* t = new gl::Texture(createTexture(type), gl::Texture::INCOMPLETE_TEXTURE_ID, type); gl::Texture* t = new gl::Texture(createTexture(type), std::numeric_limits<GLuint>::max(), type);
if (type == GL_TEXTURE_CUBE_MAP) if (type == GL_TEXTURE_CUBE_MAP)
{ {
......
...@@ -193,12 +193,15 @@ class RendererD3D : public Renderer, public BufferFactoryD3D ...@@ -193,12 +193,15 @@ class RendererD3D : public Renderer, public BufferFactoryD3D
void cleanup(); void cleanup();
// dirtyPointer is a special value that will make the comparison with any valid pointer fail and force the renderer to re-apply the state.
static const uintptr_t DirtyPointer;
egl::Display *mDisplay; egl::Display *mDisplay;
bool mDeviceLost; bool mDeviceLost;
private: private:
//FIXME(jmadill): std::array is currently prohibited by Chromium style guide //FIXME(jmadill): std::array is currently prohibited by Chromium style guide
typedef std::array<unsigned int, gl::IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS> FramebufferTextureSerialArray; typedef std::array<gl::Texture*, gl::IMPLEMENTATION_MAX_FRAMEBUFFER_ATTACHMENTS> FramebufferTextureArray;
gl::Error generateSwizzles(const gl::Data &data, gl::SamplerType type); gl::Error generateSwizzles(const gl::Data &data, gl::SamplerType type);
gl::Error generateSwizzles(const gl::Data &data); gl::Error generateSwizzles(const gl::Data &data);
...@@ -207,14 +210,13 @@ class RendererD3D : public Renderer, public BufferFactoryD3D ...@@ -207,14 +210,13 @@ class RendererD3D : public Renderer, public BufferFactoryD3D
gl::Error applyState(const gl::Data &data, GLenum drawMode); gl::Error applyState(const gl::Data &data, GLenum drawMode);
gl::Error applyShaders(const gl::Data &data); gl::Error applyShaders(const gl::Data &data);
gl::Error applyTextures(const gl::Data &data, gl::SamplerType shaderType, gl::Error applyTextures(const gl::Data &data, gl::SamplerType shaderType,
const FramebufferTextureSerialArray &framebufferSerials, size_t framebufferSerialCount); const FramebufferTextureArray &framebufferTextures, size_t framebufferTextureCount);
gl::Error applyTextures(const gl::Data &data); gl::Error applyTextures(const gl::Data &data);
bool skipDraw(const gl::Data &data, GLenum drawMode); bool skipDraw(const gl::Data &data, GLenum drawMode);
void markTransformFeedbackUsage(const gl::Data &data); void markTransformFeedbackUsage(const gl::Data &data);
size_t getBoundFramebufferTextureSerials(const gl::Data &data, size_t getBoundFramebufferTextures(const gl::Data &data, FramebufferTextureArray *outTextureArray);
FramebufferTextureSerialArray *outSerialArray);
gl::Texture *getIncompleteTexture(GLenum type); gl::Texture *getIncompleteTexture(GLenum type);
gl::TextureMap mIncompleteTextures; gl::TextureMap mIncompleteTextures;
......
...@@ -75,9 +75,6 @@ enum ...@@ -75,9 +75,6 @@ enum
MAX_TEXTURE_IMAGE_UNITS_VTF_SM4 = 16 MAX_TEXTURE_IMAGE_UNITS_VTF_SM4 = 16
}; };
// dirtyPointer is a special value that will make the comparison with any valid pointer fail and force the renderer to re-apply the state.
static const uintptr_t DirtyPointer = static_cast<uintptr_t>(-1);
static bool ImageIndexConflictsWithSRV(const gl::ImageIndex &index, D3D11_SHADER_RESOURCE_VIEW_DESC desc) static bool ImageIndexConflictsWithSRV(const gl::ImageIndex &index, D3D11_SHADER_RESOURCE_VIEW_DESC desc)
{ {
unsigned mipLevel = index.mipIndex; unsigned mipLevel = index.mipIndex;
......
...@@ -360,8 +360,8 @@ void Renderer9::initializeDevice() ...@@ -360,8 +360,8 @@ void Renderer9::initializeDevice()
mForceSetPixelSamplerStates.resize(rendererCaps.maxTextureImageUnits); mForceSetPixelSamplerStates.resize(rendererCaps.maxTextureImageUnits);
mCurPixelSamplerStates.resize(rendererCaps.maxTextureImageUnits); mCurPixelSamplerStates.resize(rendererCaps.maxTextureImageUnits);
mCurVertexTextureSerials.resize(rendererCaps.maxVertexTextureImageUnits); mCurVertexTextures.resize(rendererCaps.maxVertexTextureImageUnits);
mCurPixelTextureSerials.resize(rendererCaps.maxTextureImageUnits); mCurPixelTextures.resize(rendererCaps.maxTextureImageUnits);
markAllStateDirty(); markAllStateDirty();
...@@ -821,10 +821,9 @@ gl::Error Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *te ...@@ -821,10 +821,9 @@ gl::Error Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *te
int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0; int d3dSamplerOffset = (type == gl::SAMPLER_PIXEL) ? 0 : D3DVERTEXTEXTURESAMPLER0;
int d3dSampler = index + d3dSamplerOffset; int d3dSampler = index + d3dSamplerOffset;
IDirect3DBaseTexture9 *d3dTexture = NULL; IDirect3DBaseTexture9 *d3dTexture = NULL;
unsigned int serial = 0;
bool forceSetTexture = false; bool forceSetTexture = false;
std::vector<unsigned int> &appliedSerials = (type == gl::SAMPLER_PIXEL) ? mCurPixelTextureSerials : mCurVertexTextureSerials; std::vector<uintptr_t> &appliedTextures = (type == gl::SAMPLER_PIXEL) ? mCurPixelTextures : mCurVertexTextures;
if (texture) if (texture)
{ {
...@@ -851,17 +850,16 @@ gl::Error Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *te ...@@ -851,17 +850,16 @@ gl::Error Renderer9::setTexture(gl::SamplerType type, int index, gl::Texture *te
// in the texture class and we're unexpectedly missing the d3d texture // in the texture class and we're unexpectedly missing the d3d texture
ASSERT(d3dTexture != NULL); ASSERT(d3dTexture != NULL);
serial = texture->getTextureSerial();
forceSetTexture = textureImpl->hasDirtyImages(); forceSetTexture = textureImpl->hasDirtyImages();
textureImpl->resetDirty(); textureImpl->resetDirty();
} }
if (forceSetTexture || appliedSerials[index] != serial) if (forceSetTexture || appliedTextures[index] != reinterpret_cast<uintptr_t>(d3dTexture))
{ {
mDevice->SetTexture(d3dSampler, d3dTexture); mDevice->SetTexture(d3dSampler, d3dTexture);
} }
appliedSerials[index] = serial; appliedTextures[index] = reinterpret_cast<uintptr_t>(d3dTexture);
return gl::Error(GL_NO_ERROR); return gl::Error(GL_NO_ERROR);
} }
...@@ -2241,18 +2239,18 @@ void Renderer9::markAllStateDirty() ...@@ -2241,18 +2239,18 @@ void Renderer9::markAllStateDirty()
mForceSetViewport = true; mForceSetViewport = true;
mForceSetBlendState = true; mForceSetBlendState = true;
ASSERT(mForceSetVertexSamplerStates.size() == mCurVertexTextureSerials.size()); ASSERT(mForceSetVertexSamplerStates.size() == mCurVertexTextures.size());
for (unsigned int i = 0; i < mForceSetVertexSamplerStates.size(); i++) for (unsigned int i = 0; i < mForceSetVertexSamplerStates.size(); i++)
{ {
mForceSetVertexSamplerStates[i] = true; mForceSetVertexSamplerStates[i] = true;
mCurVertexTextureSerials[i] = 0; mCurVertexTextures[i] = DirtyPointer;
} }
ASSERT(mForceSetPixelSamplerStates.size() == mCurPixelTextureSerials.size()); ASSERT(mForceSetPixelSamplerStates.size() == mCurPixelTextures.size());
for (unsigned int i = 0; i < mForceSetPixelSamplerStates.size(); i++) for (unsigned int i = 0; i < mForceSetPixelSamplerStates.size(); i++)
{ {
mForceSetPixelSamplerStates[i] = true; mForceSetPixelSamplerStates[i] = true;
mCurPixelTextureSerials[i] = 0; mCurPixelTextures[i] = DirtyPointer;
} }
mAppliedIBSerial = 0; mAppliedIBSerial = 0;
......
...@@ -338,8 +338,8 @@ class Renderer9 : public RendererD3D ...@@ -338,8 +338,8 @@ class Renderer9 : public RendererD3D
std::vector<gl::SamplerState> mCurPixelSamplerStates; std::vector<gl::SamplerState> mCurPixelSamplerStates;
// Currently applied textures // Currently applied textures
std::vector<unsigned int> mCurVertexTextureSerials; std::vector<uintptr_t> mCurVertexTextures;
std::vector<unsigned int> mCurPixelTextureSerials; std::vector<uintptr_t> mCurPixelTextures;
unsigned int mAppliedIBSerial; unsigned int mAppliedIBSerial;
IDirect3DVertexShader9 *mAppliedVertexShader; IDirect3DVertexShader9 *mAppliedVertexShader;
......
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