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, ...@@ -106,6 +106,8 @@ State::State(bool debug,
mProgram(nullptr), mProgram(nullptr),
mVertexArray(nullptr), mVertexArray(nullptr),
mActiveSampler(0), mActiveSampler(0),
mActiveTexturesCache{},
mCachedTexturesInitState(InitState::MayNeedInit),
mPrimitiveRestart(false), mPrimitiveRestart(false),
mDebug(debug), mDebug(debug),
mMultiSampling(false), mMultiSampling(false),
...@@ -211,7 +213,6 @@ void State::initialize(const Context *context) ...@@ -211,7 +213,6 @@ void State::initialize(const Context *context)
{ {
mSamplerTextures[TextureType::External].resize(caps.maxCombinedTextureImageUnits); mSamplerTextures[TextureType::External].resize(caps.maxCombinedTextureImageUnits);
} }
mCompleteTextureCache.resize(caps.maxCombinedTextureImageUnits, nullptr);
mCompleteTextureBindings.reserve(caps.maxCombinedTextureImageUnits); mCompleteTextureBindings.reserve(caps.maxCombinedTextureImageUnits);
mCachedTexturesInitState = InitState::MayNeedInit; mCachedTexturesInitState = InitState::MayNeedInit;
for (uint32_t textureIndex = 0; textureIndex < caps.maxCombinedTextureImageUnits; for (uint32_t textureIndex = 0; textureIndex < caps.maxCombinedTextureImageUnits;
...@@ -1091,11 +1092,6 @@ GLuint State::getSamplerId(GLuint textureUnit) const ...@@ -1091,11 +1092,6 @@ GLuint State::getSamplerId(GLuint textureUnit) const
return mSamplers[textureUnit].id(); return mSamplers[textureUnit].id();
} }
Sampler *State::getSampler(GLuint textureUnit) const
{
return mSamplers[textureUnit].get();
}
void State::detachSampler(const Context *context, GLuint sampler) void State::detachSampler(const Context *context, GLuint sampler)
{ {
// [OpenGL ES 3.0.2] section 3.8.2 pages 123-124: // [OpenGL ES 3.0.2] section 3.8.2 pages 123-124:
...@@ -2662,7 +2658,7 @@ Error State::syncProgramTextures(const Context *context) ...@@ -2662,7 +2658,7 @@ Error State::syncProgramTextures(const Context *context)
Texture *texture = getSamplerTexture(textureUnitIndex, textureType); Texture *texture = getSamplerTexture(textureUnitIndex, textureType);
Sampler *sampler = getSampler(textureUnitIndex); 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(static_cast<size_t>(textureUnitIndex) < newActiveTextures.size());
ASSERT(texture); ASSERT(texture);
...@@ -2673,11 +2669,11 @@ Error State::syncProgramTextures(const Context *context) ...@@ -2673,11 +2669,11 @@ Error State::syncProgramTextures(const Context *context)
!mDrawFramebuffer->hasTextureAttachment(texture)) !mDrawFramebuffer->hasTextureAttachment(texture))
{ {
ANGLE_TRY(texture->syncState(context)); ANGLE_TRY(texture->syncState(context));
mCompleteTextureCache[textureUnitIndex] = texture; mActiveTexturesCache[textureUnitIndex] = texture;
} }
else else
{ {
mCompleteTextureCache[textureUnitIndex] = nullptr; mActiveTexturesCache[textureUnitIndex] = nullptr;
} }
// Bind the texture unconditionally, to recieve completeness change notifications. // Bind the texture unconditionally, to recieve completeness change notifications.
...@@ -2702,7 +2698,7 @@ Error State::syncProgramTextures(const Context *context) ...@@ -2702,7 +2698,7 @@ Error State::syncProgramTextures(const Context *context)
for (auto textureIndex : negativeMask) for (auto textureIndex : negativeMask)
{ {
mCompleteTextureBindings[textureIndex].reset(); mCompleteTextureBindings[textureIndex].reset();
mCompleteTextureCache[textureIndex] = nullptr; mActiveTexturesCache[textureIndex] = nullptr;
} }
} }
...@@ -2808,8 +2804,8 @@ void State::onSubjectStateChange(const Context *context, ...@@ -2808,8 +2804,8 @@ void State::onSubjectStateChange(const Context *context,
// TODO(jmadill): More fine-grained update. // TODO(jmadill): More fine-grained update.
mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES); mDirtyObjects.set(DIRTY_OBJECT_PROGRAM_TEXTURES);
if (!mCompleteTextureCache[index] || if (!mActiveTexturesCache[index] ||
mCompleteTextureCache[index]->initState() == InitState::MayNeedInit) mActiveTexturesCache[index]->initState() == InitState::MayNeedInit)
{ {
mCachedTexturesInitState = InitState::MayNeedInit; mCachedTexturesInitState = InitState::MayNeedInit;
} }
...@@ -2831,7 +2827,7 @@ Error State::clearUnclearedActiveTextures(const Context *context) ...@@ -2831,7 +2827,7 @@ Error State::clearUnclearedActiveTextures(const Context *context)
for (auto textureIndex : mProgram->getActiveSamplersMask()) for (auto textureIndex : mProgram->getActiveSamplersMask())
{ {
Texture *texture = mCompleteTextureCache[textureIndex]; Texture *texture = mActiveTexturesCache[textureIndex];
if (texture) if (texture)
{ {
ANGLE_TRY(texture->ensureInitialized(context)); ANGLE_TRY(texture->ensureInitialized(context));
......
...@@ -184,7 +184,9 @@ class State : public angle::ObserverInterface, angle::NonCopyable ...@@ -184,7 +184,9 @@ class State : public angle::ObserverInterface, angle::NonCopyable
// Sampler object binding manipulation // Sampler object binding manipulation
void setSamplerBinding(const Context *context, GLuint textureUnit, Sampler *sampler); void setSamplerBinding(const Context *context, GLuint textureUnit, Sampler *sampler);
GLuint getSamplerId(GLuint textureUnit) const; 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); void detachSampler(const Context *context, GLuint sampler);
// Renderbuffer binding manipulation // Renderbuffer binding manipulation
...@@ -467,7 +469,7 @@ class State : public angle::ObserverInterface, angle::NonCopyable ...@@ -467,7 +469,7 @@ class State : public angle::ObserverInterface, angle::NonCopyable
GLenum format); GLenum format);
const ImageUnit &getImageUnit(GLuint unit) const; 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; } ComponentTypeMask getCurrentValuesTypeMask() const { return mCurrentValuesTypeMask; }
// Observer implementation. // Observer implementation.
...@@ -555,7 +557,7 @@ class State : public angle::ObserverInterface, angle::NonCopyable ...@@ -555,7 +557,7 @@ class State : public angle::ObserverInterface, angle::NonCopyable
// A cache of complete textures. nullptr indicates unbound or incomplete. // A cache of complete textures. nullptr indicates unbound or incomplete.
// Don't use BindingPointer because this cache is only valid within a draw call. // 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. // 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; std::vector<angle::ObserverBinding> mCompleteTextureBindings;
InitState mCachedTexturesInitState; InitState mCachedTexturesInitState;
......
...@@ -333,6 +333,9 @@ using ActiveTextureMask = angle::BitSet<IMPLEMENTATION_MAX_ACTIVE_TEXTURES>; ...@@ -333,6 +333,9 @@ using ActiveTextureMask = angle::BitSet<IMPLEMENTATION_MAX_ACTIVE_TEXTURES>;
template <typename T> template <typename T>
using ActiveTextureArray = std::array<T, IMPLEMENTATION_MAX_ACTIVE_TEXTURES>; 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 // 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 // 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. // 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 ...@@ -2375,7 +2375,7 @@ angle::Result StateManager11::applyTextures(const gl::Context *context, gl::Shad
ASSERT(!mProgramD3D->isSamplerMappingDirty()); ASSERT(!mProgramD3D->isSamplerMappingDirty());
// TODO(jmadill): Use the Program's sampler bindings. // 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); unsigned int samplerRange = mProgramD3D->getUsedSamplerRange(shaderType);
for (unsigned int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++) for (unsigned int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++)
......
...@@ -3147,14 +3147,14 @@ angle::Result Renderer9::applyTextures(const gl::Context *context, gl::ShaderTyp ...@@ -3147,14 +3147,14 @@ angle::Result Renderer9::applyTextures(const gl::Context *context, gl::ShaderTyp
ASSERT(!programD3D->isSamplerMappingDirty()); ASSERT(!programD3D->isSamplerMappingDirty());
// TODO(jmadill): Use the Program's sampler bindings. // 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); unsigned int samplerRange = programD3D->getUsedSamplerRange(shaderType);
for (unsigned int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++) for (unsigned int samplerIndex = 0; samplerIndex < samplerRange; samplerIndex++)
{ {
GLint textureUnit = programD3D->getSamplerMapping(shaderType, samplerIndex, caps); GLint textureUnit = programD3D->getSamplerMapping(shaderType, samplerIndex, caps);
ASSERT(textureUnit != -1); ASSERT(textureUnit != -1);
gl::Texture *texture = completeTextures[textureUnit]; gl::Texture *texture = activeTextures[textureUnit];
// A nullptr texture indicates incomplete. // A nullptr texture indicates incomplete.
if (texture) if (texture)
......
...@@ -952,16 +952,14 @@ void StateManagerGL::updateProgramTextureAndSamplerBindings(const gl::Context *c ...@@ -952,16 +952,14 @@ void StateManagerGL::updateProgramTextureAndSamplerBindings(const gl::Context *c
const gl::State &glState = context->getGLState(); const gl::State &glState = context->getGLState();
const gl::Program *program = glState.getProgram(); const gl::Program *program = glState.getProgram();
const auto &completeTextures = glState.getCompleteTextureCache(); const gl::ActiveTexturePointerArray &textures = glState.getActiveTexturesCache();
for (const gl::SamplerBinding &samplerBinding : program->getSamplerBindings()) const gl::ActiveTextureMask &activeTextures = program->getActiveSamplersMask();
{ const gl::ActiveTextureTypeArray &textureTypes = program->getActiveSamplerTypes();
if (samplerBinding.unreferenced)
continue;
gl::TextureType textureType = samplerBinding.textureType; for (size_t textureUnitIndex : activeTextures)
for (GLuint textureUnitIndex : samplerBinding.boundTextureUnits)
{ {
gl::Texture *texture = completeTextures[textureUnitIndex]; gl::TextureType textureType = textureTypes[textureUnitIndex];
gl::Texture *texture = textures[textureUnitIndex];
// A nullptr texture indicates incomplete. // A nullptr texture indicates incomplete.
if (texture != nullptr) if (texture != nullptr)
...@@ -996,7 +994,6 @@ void StateManagerGL::updateProgramTextureAndSamplerBindings(const gl::Context *c ...@@ -996,7 +994,6 @@ void StateManagerGL::updateProgramTextureAndSamplerBindings(const gl::Context *c
bindSampler(textureUnitIndex, 0); bindSampler(textureUnitIndex, 0);
} }
} }
}
} }
void StateManagerGL::updateProgramStorageBufferBindings(const gl::Context *context) void StateManagerGL::updateProgramStorageBufferBindings(const gl::Context *context)
......
...@@ -1497,11 +1497,6 @@ const LevelInfoGL &TextureGL::getBaseLevelInfo() const ...@@ -1497,11 +1497,6 @@ const LevelInfoGL &TextureGL::getBaseLevelInfo() const
return getLevelInfo(target, effectiveBaseLevel); return getLevelInfo(target, effectiveBaseLevel);
} }
GLuint TextureGL::getTextureID() const
{
return mTextureID;
}
gl::TextureType TextureGL::getType() const gl::TextureType TextureGL::getType() const
{ {
return mState.mType; return mState.mType;
......
...@@ -160,7 +160,8 @@ class TextureGL : public TextureImpl ...@@ -160,7 +160,8 @@ class TextureGL : public TextureImpl
gl::TextureType type, gl::TextureType type,
egl::Image *image) override; egl::Image *image) override;
GLuint getTextureID() const; GLuint getTextureID() const { return mTextureID; }
gl::TextureType getType() const; gl::TextureType getType() const;
gl::Error syncState(const gl::Context *context, gl::Error syncState(const gl::Context *context,
......
...@@ -969,28 +969,28 @@ void ContextVk::handleError(VkResult errorCode, const char *file, unsigned int l ...@@ -969,28 +969,28 @@ void ContextVk::handleError(VkResult errorCode, const char *file, unsigned int l
gl::Error ContextVk::updateActiveTextures(const gl::Context *context) gl::Error ContextVk::updateActiveTextures(const gl::Context *context)
{ {
const auto &completeTextures = mState.getState().getCompleteTextureCache(); const gl::State &glState = mState.getState();
const gl::Program *program = mState.getState().getProgram(); const gl::Program *program = glState.getProgram();
mActiveTextures.fill(nullptr); mActiveTextures.fill(nullptr);
for (const gl::SamplerBinding &samplerBinding : program->getSamplerBindings()) const gl::ActiveTexturePointerArray &textures = glState.getActiveTexturesCache();
{ const gl::ActiveTextureMask &activeTextures = program->getActiveSamplersMask();
ASSERT(!samplerBinding.unreferenced); const gl::ActiveTextureTypeArray &textureTypes = program->getActiveSamplerTypes();
for (GLuint textureUnit : samplerBinding.boundTextureUnits) for (size_t textureUnit : activeTextures)
{ {
gl::Texture *texture = completeTextures[textureUnit]; gl::Texture *texture = textures[textureUnit];
gl::TextureType textureType = textureTypes[textureUnit];
// Null textures represent incomplete textures. // Null textures represent incomplete textures.
if (texture == nullptr) if (texture == nullptr)
{ {
ANGLE_TRY(getIncompleteTexture(context, samplerBinding.textureType, &texture)); ANGLE_TRY(getIncompleteTexture(context, textureType, &texture));
} }
mActiveTextures[textureUnit] = vk::GetImpl(texture); mActiveTextures[textureUnit] = vk::GetImpl(texture);
} }
}
return gl::NoError(); 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