Commit 4787d70b by Jamie Madill Committed by Commit Bot

Use active textures mask in GL and Vulkan.

This also inlines a few accessors and changes the type of the texture cache. Bug: angleproject:2763 Change-Id: I82f3c508613f6284d835e8cb64808cfe26a56161 Reviewed-on: https://chromium-review.googlesource.com/1166142 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent 7e4eff11
......@@ -106,6 +106,8 @@ State::State(bool debug,
mProgram(nullptr),
mVertexArray(nullptr),
mActiveSampler(0),
mActiveTexturesCache{},
mCachedTexturesInitState(InitState::MayNeedInit),
mPrimitiveRestart(false),
mDebug(debug),
mMultiSampling(false),
......@@ -211,7 +213,6 @@ void State::initialize(const Context *context)
{
mSamplerTextures[TextureType::External].resize(caps.maxCombinedTextureImageUnits);
}
mCompleteTextureCache.resize(caps.maxCombinedTextureImageUnits, nullptr);
mCompleteTextureBindings.reserve(caps.maxCombinedTextureImageUnits);
mCachedTexturesInitState = InitState::MayNeedInit;
for (uint32_t textureIndex = 0; textureIndex < caps.maxCombinedTextureImageUnits;
......@@ -1091,11 +1092,6 @@ GLuint State::getSamplerId(GLuint textureUnit) const
return mSamplers[textureUnit].id();
}
Sampler *State::getSampler(GLuint textureUnit) const
{
return mSamplers[textureUnit].get();
}
void State::detachSampler(const Context *context, GLuint sampler)
{
// [OpenGL ES 3.0.2] section 3.8.2 pages 123-124:
......@@ -2662,7 +2658,7 @@ Error State::syncProgramTextures(const Context *context)
Texture *texture = getSamplerTexture(textureUnitIndex, textureType);
Sampler *sampler = getSampler(textureUnitIndex);
ASSERT(static_cast<size_t>(textureUnitIndex) < mCompleteTextureCache.size());
ASSERT(static_cast<size_t>(textureUnitIndex) < mActiveTexturesCache.size());
ASSERT(static_cast<size_t>(textureUnitIndex) < newActiveTextures.size());
ASSERT(texture);
......@@ -2673,11 +2669,11 @@ Error State::syncProgramTextures(const Context *context)
!mDrawFramebuffer->hasTextureAttachment(texture))
{
ANGLE_TRY(texture->syncState(context));
mCompleteTextureCache[textureUnitIndex] = texture;
mActiveTexturesCache[textureUnitIndex] = texture;
}
else
{
mCompleteTextureCache[textureUnitIndex] = nullptr;
mActiveTexturesCache[textureUnitIndex] = nullptr;
}
// Bind the texture unconditionally, to recieve completeness change notifications.
......@@ -2702,7 +2698,7 @@ Error State::syncProgramTextures(const Context *context)
for (auto textureIndex : negativeMask)
{
mCompleteTextureBindings[textureIndex].reset();
mCompleteTextureCache[textureIndex] = nullptr;
mActiveTexturesCache[textureIndex] = nullptr;
}
}
......@@ -2808,8 +2804,8 @@ void State::onSubjectStateChange(const Context *context,
// TODO(jmadill): More fine-grained update.
mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
if (!mCompleteTextureCache[index] ||
mCompleteTextureCache[index]->initState() == InitState::MayNeedInit)
if (!mActiveTexturesCache[index] ||
mActiveTexturesCache[index]->initState() == InitState::MayNeedInit)
{
mCachedTexturesInitState = InitState::MayNeedInit;
}
......@@ -2831,7 +2827,7 @@ Error State::clearUnclearedActiveTextures(const Context *context)
for (auto textureIndex : mProgram->getActiveSamplersMask())
{
Texture *texture = mCompleteTextureCache[textureIndex];
Texture *texture = mActiveTexturesCache[textureIndex];
if (texture)
{
ANGLE_TRY(texture->ensureInitialized(context));
......
......@@ -184,7 +184,9 @@ class State : public angle::ObserverInterface, angle::NonCopyable
// Sampler object binding manipulation
void setSamplerBinding(const Context *context, GLuint textureUnit, Sampler *sampler);
GLuint getSamplerId(GLuint textureUnit) const;
Sampler *getSampler(GLuint textureUnit) const;
Sampler *getSampler(GLuint textureUnit) const { return mSamplers[textureUnit].get(); }
void detachSampler(const Context *context, GLuint sampler);
// Renderbuffer binding manipulation
......@@ -467,7 +469,7 @@ class State : public angle::ObserverInterface, angle::NonCopyable
GLenum format);
const ImageUnit &getImageUnit(GLuint unit) const;
const std::vector<Texture *> &getCompleteTextureCache() const { return mCompleteTextureCache; }
const ActiveTexturePointerArray &getActiveTexturesCache() const { return mActiveTexturesCache; }
ComponentTypeMask getCurrentValuesTypeMask() const { return mCurrentValuesTypeMask; }
// Observer implementation.
......@@ -555,7 +557,7 @@ class State : public angle::ObserverInterface, angle::NonCopyable
// A cache of complete textures. nullptr indicates unbound or incomplete.
// Don't use BindingPointer because this cache is only valid within a draw call.
// Also stores a notification channel to the texture itself to handle texture change events.
std::vector<Texture *> mCompleteTextureCache;
ActiveTexturePointerArray mActiveTexturesCache;
std::vector<angle::ObserverBinding> mCompleteTextureBindings;
InitState mCachedTexturesInitState;
......
......@@ -333,6 +333,9 @@ using ActiveTextureMask = angle::BitSet<IMPLEMENTATION_MAX_ACTIVE_TEXTURES>;
template <typename T>
using ActiveTextureArray = std::array<T, IMPLEMENTATION_MAX_ACTIVE_TEXTURES>;
using ActiveTexturePointerArray = ActiveTextureArray<Texture *>;
using ActiveTextureTypeArray = ActiveTextureArray<TextureType>;
// OffsetBindingPointer.getSize() returns the size specified by the user, which may be larger than
// the size of the bound buffer. This function reduces the returned size to fit the bound buffer if
// necessary. Returns 0 if no buffer is bound or if integer overflow occurs.
......
......@@ -2375,7 +2375,7 @@ angle::Result StateManager11::applyTextures(const gl::Context *context, gl::Shad
ASSERT(!mProgramD3D->isSamplerMappingDirty());
// TODO(jmadill): Use the Program's sampler bindings.
const auto &completeTextures = glState.getCompleteTextureCache();
const gl::ActiveTexturePointerArray &completeTextures = glState.getActiveTexturesCache();
unsigned int samplerRange = mProgramD3D->getUsedSamplerRange(shaderType);
for (unsigned int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++)
......
......@@ -3147,14 +3147,14 @@ angle::Result Renderer9::applyTextures(const gl::Context *context, gl::ShaderTyp
ASSERT(!programD3D->isSamplerMappingDirty());
// TODO(jmadill): Use the Program's sampler bindings.
const auto &completeTextures = glState.getCompleteTextureCache();
const gl::ActiveTexturePointerArray &activeTextures = glState.getActiveTexturesCache();
unsigned int samplerRange = programD3D->getUsedSamplerRange(shaderType);
for (unsigned int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++)
{
GLint textureUnit = programD3D->getSamplerMapping(shaderType, samplerIndex, caps);
ASSERT(textureUnit != -1);
gl::Texture *texture = completeTextures[textureUnit];
gl::Texture *texture = activeTextures[textureUnit];
// A nullptr texture indicates incomplete.
if (texture)
......
......@@ -952,49 +952,46 @@ void StateManagerGL::updateProgramTextureAndSamplerBindings(const gl::Context *c
const gl::State &glState = context->getGLState();
const gl::Program *program = glState.getProgram();
const auto &completeTextures = glState.getCompleteTextureCache();
for (const gl::SamplerBinding &samplerBinding : program->getSamplerBindings())
const gl::ActiveTexturePointerArray &textures = glState.getActiveTexturesCache();
const gl::ActiveTextureMask &activeTextures = program->getActiveSamplersMask();
const gl::ActiveTextureTypeArray &textureTypes = program->getActiveSamplerTypes();
for (size_t textureUnitIndex : activeTextures)
{
if (samplerBinding.unreferenced)
continue;
gl::TextureType textureType = textureTypes[textureUnitIndex];
gl::Texture *texture = textures[textureUnitIndex];
gl::TextureType textureType = samplerBinding.textureType;
for (GLuint textureUnitIndex : samplerBinding.boundTextureUnits)
// A nullptr texture indicates incomplete.
if (texture != nullptr)
{
gl::Texture *texture = completeTextures[textureUnitIndex];
const TextureGL *textureGL = GetImplAs<TextureGL>(texture);
ASSERT(!texture->hasAnyDirtyBit());
ASSERT(!textureGL->hasAnyDirtyBit());
// A nullptr texture indicates incomplete.
if (texture != nullptr)
if (mTextures[textureType][textureUnitIndex] != textureGL->getTextureID())
{
const TextureGL *textureGL = GetImplAs<TextureGL>(texture);
ASSERT(!texture->hasAnyDirtyBit());
ASSERT(!textureGL->hasAnyDirtyBit());
if (mTextures[textureType][textureUnitIndex] != textureGL->getTextureID())
{
activeTexture(textureUnitIndex);
bindTexture(textureType, textureGL->getTextureID());
}
activeTexture(textureUnitIndex);
bindTexture(textureType, textureGL->getTextureID());
}
else
}
else
{
if (mTextures[textureType][textureUnitIndex] != 0)
{
if (mTextures[textureType][textureUnitIndex] != 0)
{
activeTexture(textureUnitIndex);
bindTexture(textureType, 0);
}
activeTexture(textureUnitIndex);
bindTexture(textureType, 0);
}
}
const gl::Sampler *sampler = glState.getSampler(textureUnitIndex);
if (sampler != nullptr)
{
SamplerGL *samplerGL = GetImplAs<SamplerGL>(sampler);
bindSampler(textureUnitIndex, samplerGL->getSamplerID());
}
else
{
bindSampler(textureUnitIndex, 0);
}
const gl::Sampler *sampler = glState.getSampler(textureUnitIndex);
if (sampler != nullptr)
{
SamplerGL *samplerGL = GetImplAs<SamplerGL>(sampler);
bindSampler(textureUnitIndex, samplerGL->getSamplerID());
}
else
{
bindSampler(textureUnitIndex, 0);
}
}
}
......
......@@ -1497,11 +1497,6 @@ const LevelInfoGL &TextureGL::getBaseLevelInfo() const
return getLevelInfo(target, effectiveBaseLevel);
}
GLuint TextureGL::getTextureID() const
{
return mTextureID;
}
gl::TextureType TextureGL::getType() const
{
return mState.mType;
......
......@@ -160,7 +160,8 @@ class TextureGL : public TextureImpl
gl::TextureType type,
egl::Image *image) override;
GLuint getTextureID() const;
GLuint getTextureID() const { return mTextureID; }
gl::TextureType getType() const;
gl::Error syncState(const gl::Context *context,
......
......@@ -969,27 +969,27 @@ void ContextVk::handleError(VkResult errorCode, const char *file, unsigned int l
gl::Error ContextVk::updateActiveTextures(const gl::Context *context)
{
const auto &completeTextures = mState.getState().getCompleteTextureCache();
const gl::Program *program = mState.getState().getProgram();
const gl::State &glState = mState.getState();
const gl::Program *program = glState.getProgram();
mActiveTextures.fill(nullptr);
for (const gl::SamplerBinding &samplerBinding : program->getSamplerBindings())
const gl::ActiveTexturePointerArray &textures = glState.getActiveTexturesCache();
const gl::ActiveTextureMask &activeTextures = program->getActiveSamplersMask();
const gl::ActiveTextureTypeArray &textureTypes = program->getActiveSamplerTypes();
for (size_t textureUnit : activeTextures)
{
ASSERT(!samplerBinding.unreferenced);
gl::Texture *texture = textures[textureUnit];
gl::TextureType textureType = textureTypes[textureUnit];
for (GLuint textureUnit : samplerBinding.boundTextureUnits)
// Null textures represent incomplete textures.
if (texture == nullptr)
{
gl::Texture *texture = completeTextures[textureUnit];
// Null textures represent incomplete textures.
if (texture == nullptr)
{
ANGLE_TRY(getIncompleteTexture(context, samplerBinding.textureType, &texture));
}
mActiveTextures[textureUnit] = vk::GetImpl(texture);
ANGLE_TRY(getIncompleteTexture(context, textureType, &texture));
}
mActiveTextures[textureUnit] = vk::GetImpl(texture);
}
return gl::NoError();
......
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