Commit 3dd8d291 by Jiawei Shao Committed by Commit Bot

Use ShaderBitSet for active use bits on uniforms

BUG=angleproject:2169 Change-Id: I192c2e3c453540c8a6d7b0d066218ea3c9fbaab2 Reviewed-on: https://chromium-review.googlesource.com/989411 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent fe4bbe6c
...@@ -40,10 +40,10 @@ class BitSetT final ...@@ -40,10 +40,10 @@ class BitSetT final
private: private:
friend class BitSetT; friend class BitSetT;
Reference(BitSetT *parent, std::size_t bit) : mParent(parent), mBit(bit) {} Reference(BitSetT *parent, ParamT bit) : mParent(parent), mBit(bit) {}
BitSetT *mParent; BitSetT *mParent;
std::size_t mBit; ParamT mBit;
}; };
class Iterator final class Iterator final
......
...@@ -66,10 +66,10 @@ void WriteShaderVariableBuffer(BinaryOutputStream *stream, const ShaderVariableB ...@@ -66,10 +66,10 @@ void WriteShaderVariableBuffer(BinaryOutputStream *stream, const ShaderVariableB
stream->writeInt(var.binding); stream->writeInt(var.binding);
stream->writeInt(var.dataSize); stream->writeInt(var.dataSize);
stream->writeInt(var.vertexActive); for (ShaderType shaderType : AllShaderTypes())
stream->writeInt(var.fragmentActive); {
stream->writeInt(var.computeActive); stream->writeInt(var.isActive(shaderType));
stream->writeInt(var.geometryActive); }
stream->writeInt(var.memberIndexes.size()); stream->writeInt(var.memberIndexes.size());
for (unsigned int memberCounterIndex : var.memberIndexes) for (unsigned int memberCounterIndex : var.memberIndexes)
...@@ -82,10 +82,11 @@ void LoadShaderVariableBuffer(BinaryInputStream *stream, ShaderVariableBuffer *v ...@@ -82,10 +82,11 @@ void LoadShaderVariableBuffer(BinaryInputStream *stream, ShaderVariableBuffer *v
{ {
var->binding = stream->readInt<int>(); var->binding = stream->readInt<int>();
var->dataSize = stream->readInt<unsigned int>(); var->dataSize = stream->readInt<unsigned int>();
var->vertexActive = stream->readBool();
var->fragmentActive = stream->readBool(); for (ShaderType shaderType : AllShaderTypes())
var->computeActive = stream->readBool(); {
var->geometryActive = stream->readBool(); var->setActive(shaderType, stream->readBool());
}
unsigned int numMembers = stream->readInt<unsigned int>(); unsigned int numMembers = stream->readInt<unsigned int>();
for (unsigned int blockMemberIndex = 0; blockMemberIndex < numMembers; blockMemberIndex++) for (unsigned int blockMemberIndex = 0; blockMemberIndex < numMembers; blockMemberIndex++)
...@@ -105,9 +106,11 @@ void WriteBufferVariable(BinaryOutputStream *stream, const BufferVariable &var) ...@@ -105,9 +106,11 @@ void WriteBufferVariable(BinaryOutputStream *stream, const BufferVariable &var)
stream->writeInt(var.blockInfo.isRowMajorMatrix); stream->writeInt(var.blockInfo.isRowMajorMatrix);
stream->writeInt(var.blockInfo.topLevelArrayStride); stream->writeInt(var.blockInfo.topLevelArrayStride);
stream->writeInt(var.topLevelArraySize); stream->writeInt(var.topLevelArraySize);
stream->writeInt(var.vertexActive);
stream->writeInt(var.fragmentActive); for (ShaderType shaderType : AllShaderTypes())
stream->writeInt(var.computeActive); {
stream->writeInt(var.isActive(shaderType));
}
} }
void LoadBufferVariable(BinaryInputStream *stream, BufferVariable *var) void LoadBufferVariable(BinaryInputStream *stream, BufferVariable *var)
...@@ -121,9 +124,11 @@ void LoadBufferVariable(BinaryInputStream *stream, BufferVariable *var) ...@@ -121,9 +124,11 @@ void LoadBufferVariable(BinaryInputStream *stream, BufferVariable *var)
var->blockInfo.isRowMajorMatrix = stream->readBool(); var->blockInfo.isRowMajorMatrix = stream->readBool();
var->blockInfo.topLevelArrayStride = stream->readInt<int>(); var->blockInfo.topLevelArrayStride = stream->readInt<int>();
var->topLevelArraySize = stream->readInt<int>(); var->topLevelArraySize = stream->readInt<int>();
var->vertexActive = stream->readBool();
var->fragmentActive = stream->readBool(); for (ShaderType shaderType : AllShaderTypes())
var->computeActive = stream->readBool(); {
var->setActive(shaderType, stream->readBool());
}
} }
void WriteInterfaceBlock(BinaryOutputStream *stream, const InterfaceBlock &block) void WriteInterfaceBlock(BinaryOutputStream *stream, const InterfaceBlock &block)
...@@ -426,7 +431,7 @@ LinkResult MemoryProgramCache::Deserialize(const Context *context, ...@@ -426,7 +431,7 @@ LinkResult MemoryProgramCache::Deserialize(const Context *context,
static_assert(static_cast<unsigned long>(ShaderType::EnumCount) <= sizeof(unsigned long) * 8, static_assert(static_cast<unsigned long>(ShaderType::EnumCount) <= sizeof(unsigned long) * 8,
"Too many shader types"); "Too many shader types");
state->mLinkedShaderStages = stream.readInt<gl::ShaderStagesMask>(); state->mLinkedShaderStages = stream.readInt<gl::ShaderBitSet>();
state->updateTransformFeedbackStrides(); state->updateTransformFeedbackStrides();
......
...@@ -172,6 +172,8 @@ struct AllShaderTypes ...@@ -172,6 +172,8 @@ struct AllShaderTypes
angle::EnumIterator<ShaderType> end() const { return kAfterShaderTypeMax; } angle::EnumIterator<ShaderType> end() const { return kAfterShaderTypeMax; }
}; };
using ShaderBitSet = angle::PackedEnumBitSet<ShaderType>;
TextureType SamplerTypeToTextureType(GLenum samplerType); TextureType SamplerTypeToTextureType(GLenum samplerType);
} // namespace gl } // namespace gl
......
...@@ -277,8 +277,6 @@ struct ImageBinding ...@@ -277,8 +277,6 @@ struct ImageBinding
std::vector<GLuint> boundImageUnits; std::vector<GLuint> boundImageUnits;
}; };
using ShaderStagesMask = angle::PackedEnumBitSet<ShaderType>;
class ProgramState final : angle::NonCopyable class ProgramState final : angle::NonCopyable
{ {
public: public:
...@@ -352,7 +350,7 @@ class ProgramState final : angle::NonCopyable ...@@ -352,7 +350,7 @@ class ProgramState final : angle::NonCopyable
int getNumViews() const { return mNumViews; } int getNumViews() const { return mNumViews; }
bool usesMultiview() const { return mNumViews != -1; } bool usesMultiview() const { return mNumViews != -1; }
const ShaderStagesMask &getLinkedShaderStages() const { return mLinkedShaderStages; } const ShaderBitSet &getLinkedShaderStages() const { return mLinkedShaderStages; }
private: private:
friend class MemoryProgramCache; friend class MemoryProgramCache;
...@@ -423,7 +421,7 @@ class ProgramState final : angle::NonCopyable ...@@ -423,7 +421,7 @@ class ProgramState final : angle::NonCopyable
bool mBinaryRetrieveableHint; bool mBinaryRetrieveableHint;
bool mSeparable; bool mSeparable;
ShaderStagesMask mLinkedShaderStages; ShaderBitSet mLinkedShaderStages;
// ANGLE_multiview. // ANGLE_multiview.
int mNumViews; int mNumViews;
......
...@@ -14,7 +14,6 @@ namespace gl ...@@ -14,7 +14,6 @@ namespace gl
{ {
ActiveVariable::ActiveVariable() ActiveVariable::ActiveVariable()
: vertexActive(false), fragmentActive(false), computeActive(false), geometryActive(false)
{ {
} }
...@@ -27,50 +26,24 @@ ActiveVariable &ActiveVariable::operator=(const ActiveVariable &rhs) = default; ...@@ -27,50 +26,24 @@ ActiveVariable &ActiveVariable::operator=(const ActiveVariable &rhs) = default;
void ActiveVariable::setActive(ShaderType shaderType, bool used) void ActiveVariable::setActive(ShaderType shaderType, bool used)
{ {
switch (shaderType) ASSERT(shaderType != ShaderType::InvalidEnum);
{ mActiveUseBits.set(shaderType, used);
case ShaderType::Vertex: }
vertexActive = used;
break;
case ShaderType::Fragment:
fragmentActive = used;
break;
case ShaderType::Compute:
computeActive = used;
break;
case ShaderType::Geometry:
geometryActive = used;
break;
default: bool ActiveVariable::isActive(ShaderType shaderType) const
UNREACHABLE(); {
} ASSERT(shaderType != ShaderType::InvalidEnum);
return mActiveUseBits[shaderType];
} }
void ActiveVariable::unionReferencesWith(const ActiveVariable &other) void ActiveVariable::unionReferencesWith(const ActiveVariable &other)
{ {
vertexActive |= other.vertexActive; mActiveUseBits |= other.mActiveUseBits;
fragmentActive |= other.fragmentActive;
computeActive |= other.computeActive;
geometryActive |= other.geometryActive;
} }
ShaderType ActiveVariable::getFirstShaderTypeWhereActive() const ShaderType ActiveVariable::getFirstShaderTypeWhereActive() const
{ {
if (vertexActive) return static_cast<ShaderType>(gl::ScanForward(mActiveUseBits.bits()));
return ShaderType::Vertex;
if (fragmentActive)
return ShaderType::Fragment;
if (computeActive)
return ShaderType::Compute;
if (geometryActive)
return ShaderType::Geometry;
UNREACHABLE();
return ShaderType::InvalidEnum;
} }
LinkedUniform::LinkedUniform() LinkedUniform::LinkedUniform()
......
...@@ -31,11 +31,10 @@ struct ActiveVariable ...@@ -31,11 +31,10 @@ struct ActiveVariable
ShaderType getFirstShaderTypeWhereActive() const; ShaderType getFirstShaderTypeWhereActive() const;
void setActive(ShaderType shaderType, bool used); void setActive(ShaderType shaderType, bool used);
void unionReferencesWith(const ActiveVariable &other); void unionReferencesWith(const ActiveVariable &other);
bool isActive(ShaderType shaderType) const;
bool vertexActive; private:
bool fragmentActive; ShaderBitSet mActiveUseBits;
bool computeActive;
bool geometryActive;
}; };
// Helper struct representing a single shader uniform // Helper struct representing a single shader uniform
......
...@@ -727,13 +727,13 @@ void GetShaderVariableBufferResourceProperty(const ShaderVariableBuffer &buffer, ...@@ -727,13 +727,13 @@ void GetShaderVariableBufferResourceProperty(const ShaderVariableBuffer &buffer,
} }
break; break;
case GL_REFERENCED_BY_VERTEX_SHADER: case GL_REFERENCED_BY_VERTEX_SHADER:
params[(*outputPosition)++] = static_cast<GLint>(buffer.vertexActive); params[(*outputPosition)++] = static_cast<GLint>(buffer.isActive(ShaderType::Vertex));
break; break;
case GL_REFERENCED_BY_FRAGMENT_SHADER: case GL_REFERENCED_BY_FRAGMENT_SHADER:
params[(*outputPosition)++] = static_cast<GLint>(buffer.fragmentActive); params[(*outputPosition)++] = static_cast<GLint>(buffer.isActive(ShaderType::Fragment));
break; break;
case GL_REFERENCED_BY_COMPUTE_SHADER: case GL_REFERENCED_BY_COMPUTE_SHADER:
params[(*outputPosition)++] = static_cast<GLint>(buffer.computeActive); params[(*outputPosition)++] = static_cast<GLint>(buffer.isActive(ShaderType::Compute));
break; break;
default: default:
UNREACHABLE(); UNREACHABLE();
...@@ -1425,13 +1425,13 @@ GLint GetUniformResourceProperty(const Program *program, GLuint index, const GLe ...@@ -1425,13 +1425,13 @@ GLint GetUniformResourceProperty(const Program *program, GLuint index, const GLe
return static_cast<GLint>(uniform.blockInfo.isRowMajorMatrix); return static_cast<GLint>(uniform.blockInfo.isRowMajorMatrix);
case GL_REFERENCED_BY_VERTEX_SHADER: case GL_REFERENCED_BY_VERTEX_SHADER:
return uniform.vertexActive; return uniform.isActive(ShaderType::Vertex);
case GL_REFERENCED_BY_FRAGMENT_SHADER: case GL_REFERENCED_BY_FRAGMENT_SHADER:
return uniform.fragmentActive; return uniform.isActive(ShaderType::Fragment);
case GL_REFERENCED_BY_COMPUTE_SHADER: case GL_REFERENCED_BY_COMPUTE_SHADER:
return uniform.computeActive; return uniform.isActive(ShaderType::Compute);
case GL_ATOMIC_COUNTER_BUFFER_INDEX: case GL_ATOMIC_COUNTER_BUFFER_INDEX:
return (uniform.isAtomicCounter() ? uniform.bufferIndex : -1); return (uniform.isAtomicCounter() ? uniform.bufferIndex : -1);
...@@ -1468,13 +1468,13 @@ GLint GetBufferVariableResourceProperty(const Program *program, GLuint index, co ...@@ -1468,13 +1468,13 @@ GLint GetBufferVariableResourceProperty(const Program *program, GLuint index, co
return static_cast<GLint>(bufferVariable.blockInfo.isRowMajorMatrix); return static_cast<GLint>(bufferVariable.blockInfo.isRowMajorMatrix);
case GL_REFERENCED_BY_VERTEX_SHADER: case GL_REFERENCED_BY_VERTEX_SHADER:
return bufferVariable.vertexActive; return bufferVariable.isActive(ShaderType::Vertex);
case GL_REFERENCED_BY_FRAGMENT_SHADER: case GL_REFERENCED_BY_FRAGMENT_SHADER:
return bufferVariable.fragmentActive; return bufferVariable.isActive(ShaderType::Fragment);
case GL_REFERENCED_BY_COMPUTE_SHADER: case GL_REFERENCED_BY_COMPUTE_SHADER:
return bufferVariable.computeActive; return bufferVariable.isActive(ShaderType::Compute);
case GL_TOP_LEVEL_ARRAY_SIZE: case GL_TOP_LEVEL_ARRAY_SIZE:
return bufferVariable.topLevelArraySize; return bufferVariable.topLevelArraySize;
......
...@@ -622,10 +622,7 @@ ProgramD3D::ProgramD3D(const gl::ProgramState &state, RendererD3D *renderer) ...@@ -622,10 +622,7 @@ ProgramD3D::ProgramD3D(const gl::ProgramState &state, RendererD3D *renderer)
mDirtySamplerMapping(true), mDirtySamplerMapping(true),
mUsedComputeImageRange(0), mUsedComputeImageRange(0),
mUsedComputeReadonlyImageRange(0), mUsedComputeReadonlyImageRange(0),
mSerial(issueSerial()), mSerial(issueSerial())
mVertexUniformsDirty(true),
mFragmentUniformsDirty(true),
mComputeUniformsDirty(true)
{ {
mDynamicHLSL = new DynamicHLSL(renderer); mDynamicHLSL = new DynamicHLSL(renderer);
} }
...@@ -1148,6 +1145,8 @@ gl::LinkResult ProgramD3D::load(const gl::Context *context, ...@@ -1148,6 +1145,8 @@ gl::LinkResult ProgramD3D::load(const gl::Context *context,
initializeUniformStorage(); initializeUniformStorage();
dirtyAllUniforms();
return true; return true;
} }
...@@ -1697,6 +1696,7 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context, ...@@ -1697,6 +1696,7 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context,
mImagesCS.resize(data.getCaps().maxImageUnits); mImagesCS.resize(data.getCaps().maxImageUnits);
mReadonlyImagesCS.resize(data.getCaps().maxImageUnits); mReadonlyImagesCS.resize(data.getCaps().maxImageUnits);
mShaderUniformsDirty.set(gl::ShaderType::Compute);
defineUniformsAndAssignRegisters(context); defineUniformsAndAssignRegisters(context);
gl::LinkResult result = compileComputeExecutable(context, infoLog); gl::LinkResult result = compileComputeExecutable(context, infoLog);
...@@ -1760,6 +1760,10 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context, ...@@ -1760,6 +1760,10 @@ gl::LinkResult ProgramD3D::link(const gl::Context *context,
initAttribLocationsToD3DSemantic(context); initAttribLocationsToD3DSemantic(context);
// TODO(jiawei.shao@intel.com): set geometry uniforms dirty if user-defined geometry shader
// exists. Tracking bug: http://anglebug.com/1941
mShaderUniformsDirty.set(gl::ShaderType::Vertex);
mShaderUniformsDirty.set(gl::ShaderType::Fragment);
defineUniformsAndAssignRegisters(context); defineUniformsAndAssignRegisters(context);
gatherTransformFeedbackVaryings(resources.varyingPacking, builtins[gl::ShaderType::Vertex]); gatherTransformFeedbackVaryings(resources.varyingPacking, builtins[gl::ShaderType::Vertex]);
...@@ -1811,14 +1815,14 @@ void ProgramD3D::initializeUniformBlocks() ...@@ -1811,14 +1815,14 @@ void ProgramD3D::initializeUniformBlocks()
D3DUniformBlock d3dUniformBlock; D3DUniformBlock d3dUniformBlock;
if (uniformBlock.vertexActive) if (uniformBlock.isActive(gl::ShaderType::Vertex))
{ {
ASSERT(vertexShaderD3D != nullptr); ASSERT(vertexShaderD3D != nullptr);
unsigned int baseRegister = vertexShaderD3D->getUniformBlockRegister(uniformBlock.name); unsigned int baseRegister = vertexShaderD3D->getUniformBlockRegister(uniformBlock.name);
d3dUniformBlock.vsRegisterIndex = baseRegister + uniformBlockElement; d3dUniformBlock.vsRegisterIndex = baseRegister + uniformBlockElement;
} }
if (uniformBlock.fragmentActive) if (uniformBlock.isActive(gl::ShaderType::Fragment))
{ {
ASSERT(fragmentShaderD3D != nullptr); ASSERT(fragmentShaderD3D != nullptr);
unsigned int baseRegister = unsigned int baseRegister =
...@@ -1826,7 +1830,7 @@ void ProgramD3D::initializeUniformBlocks() ...@@ -1826,7 +1830,7 @@ void ProgramD3D::initializeUniformBlocks()
d3dUniformBlock.psRegisterIndex = baseRegister + uniformBlockElement; d3dUniformBlock.psRegisterIndex = baseRegister + uniformBlockElement;
} }
if (uniformBlock.computeActive) if (uniformBlock.isActive(gl::ShaderType::Compute))
{ {
ASSERT(computeShaderD3D != nullptr); ASSERT(computeShaderD3D != nullptr);
unsigned int baseRegister = unsigned int baseRegister =
...@@ -1968,16 +1972,12 @@ const std::vector<GLint> &ProgramD3D::getFragmentUniformBufferCache() const ...@@ -1968,16 +1972,12 @@ const std::vector<GLint> &ProgramD3D::getFragmentUniformBufferCache() const
void ProgramD3D::dirtyAllUniforms() void ProgramD3D::dirtyAllUniforms()
{ {
mVertexUniformsDirty = true; mShaderUniformsDirty = mState.getLinkedShaderStages();
mFragmentUniformsDirty = true;
mComputeUniformsDirty = true;
} }
void ProgramD3D::markUniformsClean() void ProgramD3D::markUniformsClean()
{ {
mVertexUniformsDirty = false; mShaderUniformsDirty.reset();
mFragmentUniformsDirty = false;
mComputeUniformsDirty = false;
} }
void ProgramD3D::setUniform1fv(GLint location, GLsizei count, const GLfloat *v) void ProgramD3D::setUniform1fv(GLint location, GLsizei count, const GLfloat *v)
...@@ -2442,19 +2442,19 @@ void ProgramD3D::setUniformInternal(GLint location, GLsizei count, const T *v, G ...@@ -2442,19 +2442,19 @@ void ProgramD3D::setUniformInternal(GLint location, GLsizei count, const T *v, G
if (targetUniform->vsData) if (targetUniform->vsData)
{ {
setUniformImpl(locationInfo, count, v, targetUniform->vsData, uniformType); setUniformImpl(locationInfo, count, v, targetUniform->vsData, uniformType);
mVertexUniformsDirty = true; mShaderUniformsDirty.set(gl::ShaderType::Vertex);
} }
if (targetUniform->psData) if (targetUniform->psData)
{ {
setUniformImpl(locationInfo, count, v, targetUniform->psData, uniformType); setUniformImpl(locationInfo, count, v, targetUniform->psData, uniformType);
mFragmentUniformsDirty = true; mShaderUniformsDirty.set(gl::ShaderType::Fragment);
} }
if (targetUniform->csData) if (targetUniform->csData)
{ {
setUniformImpl(locationInfo, count, v, targetUniform->csData, uniformType); setUniformImpl(locationInfo, count, v, targetUniform->csData, uniformType);
mComputeUniformsDirty = true; mShaderUniformsDirty.set(gl::ShaderType::Compute);
} }
} }
...@@ -2511,7 +2511,7 @@ void ProgramD3D::setUniformMatrixfvInternal(GLint location, ...@@ -2511,7 +2511,7 @@ void ProgramD3D::setUniformMatrixfvInternal(GLint location,
if (setUniformMatrixfvImpl<cols, rows>(location, countIn, transpose, value, if (setUniformMatrixfvImpl<cols, rows>(location, countIn, transpose, value,
targetUniform->vsData, targetUniformType)) targetUniform->vsData, targetUniformType))
{ {
mVertexUniformsDirty = true; mShaderUniformsDirty.set(gl::ShaderType::Vertex);
} }
} }
...@@ -2520,7 +2520,7 @@ void ProgramD3D::setUniformMatrixfvInternal(GLint location, ...@@ -2520,7 +2520,7 @@ void ProgramD3D::setUniformMatrixfvInternal(GLint location,
if (setUniformMatrixfvImpl<cols, rows>(location, countIn, transpose, value, if (setUniformMatrixfvImpl<cols, rows>(location, countIn, transpose, value,
targetUniform->psData, targetUniformType)) targetUniform->psData, targetUniformType))
{ {
mFragmentUniformsDirty = true; mShaderUniformsDirty.set(gl::ShaderType::Fragment);
} }
} }
...@@ -2529,7 +2529,7 @@ void ProgramD3D::setUniformMatrixfvInternal(GLint location, ...@@ -2529,7 +2529,7 @@ void ProgramD3D::setUniformMatrixfvInternal(GLint location,
if (setUniformMatrixfvImpl<cols, rows>(location, countIn, transpose, value, if (setUniformMatrixfvImpl<cols, rows>(location, countIn, transpose, value,
targetUniform->csData, targetUniformType)) targetUniform->csData, targetUniformType))
{ {
mComputeUniformsDirty = true; mShaderUniformsDirty.set(gl::ShaderType::Compute);
} }
} }
} }
...@@ -2757,7 +2757,7 @@ void ProgramD3D::reset() ...@@ -2757,7 +2757,7 @@ void ProgramD3D::reset()
mGeometryShaderPreamble.clear(); mGeometryShaderPreamble.clear();
dirtyAllUniforms(); markUniformsClean();
mCachedPixelExecutableIndex.reset(); mCachedPixelExecutableIndex.reset();
mCachedVertexExecutableIndex.reset(); mCachedVertexExecutableIndex.reset();
...@@ -2951,6 +2951,11 @@ bool ProgramD3D::hasPixelExecutableForCachedOutputLayout() ...@@ -2951,6 +2951,11 @@ bool ProgramD3D::hasPixelExecutableForCachedOutputLayout()
return mCachedPixelExecutableIndex.valid(); return mCachedPixelExecutableIndex.valid();
} }
bool ProgramD3D::anyShaderUniformsDirty() const
{
return mShaderUniformsDirty.any();
}
template <typename DestT> template <typename DestT>
void ProgramD3D::getUniformInternal(GLint location, DestT *dataOut) const void ProgramD3D::getUniformInternal(GLint location, DestT *dataOut) const
{ {
......
...@@ -308,9 +308,11 @@ class ProgramD3D : public ProgramImpl ...@@ -308,9 +308,11 @@ class ProgramD3D : public ProgramImpl
bool hasGeometryExecutableForPrimitiveType(GLenum drawMode); bool hasGeometryExecutableForPrimitiveType(GLenum drawMode);
bool hasPixelExecutableForCachedOutputLayout(); bool hasPixelExecutableForCachedOutputLayout();
bool areVertexUniformsDirty() const { return mVertexUniformsDirty; } bool anyShaderUniformsDirty() const;
bool areFragmentUniformsDirty() const { return mFragmentUniformsDirty; } bool areShaderUniformsDirty(gl::ShaderType shaderType) const
bool areComputeUniformsDirty() const { return mComputeUniformsDirty; } {
return mShaderUniformsDirty[shaderType];
}
const std::vector<D3DUniform *> &getD3DUniforms() const { return mD3DUniforms; } const std::vector<D3DUniform *> &getD3DUniforms() const { return mD3DUniforms; }
void markUniformsClean(); void markUniformsClean();
...@@ -550,9 +552,7 @@ class ProgramD3D : public ProgramImpl ...@@ -550,9 +552,7 @@ class ProgramD3D : public ProgramImpl
std::map<std::string, int> mImageBindingMap; std::map<std::string, int> mImageBindingMap;
std::vector<D3DUniformBlock> mD3DUniformBlocks; std::vector<D3DUniformBlock> mD3DUniformBlocks;
bool mVertexUniformsDirty; gl::ShaderBitSet mShaderUniformsDirty;
bool mFragmentUniformsDirty;
bool mComputeUniformsDirty;
static unsigned int issueSerial(); static unsigned int issueSerial();
static unsigned int mCurrentSerial; static unsigned int mCurrentSerial;
......
...@@ -261,13 +261,9 @@ StateManager11::SRVCache *StateManager11::getSRVCache(gl::ShaderType shaderType) ...@@ -261,13 +261,9 @@ StateManager11::SRVCache *StateManager11::getSRVCache(gl::ShaderType shaderType)
// ShaderConstants11 implementation // ShaderConstants11 implementation
ShaderConstants11::ShaderConstants11() ShaderConstants11::ShaderConstants11()
: mVertexDirty(true), : mNumActiveVSSamplers(0), mNumActivePSSamplers(0), mNumActiveCSSamplers(0)
mPixelDirty(true),
mComputeDirty(true),
mNumActiveVSSamplers(0),
mNumActivePSSamplers(0),
mNumActiveCSSamplers(0)
{ {
mShaderConstantsDirty.set();
} }
ShaderConstants11::~ShaderConstants11() ShaderConstants11::~ShaderConstants11()
...@@ -299,9 +295,7 @@ size_t ShaderConstants11::getRequiredBufferSize(gl::ShaderType shaderType) const ...@@ -299,9 +295,7 @@ size_t ShaderConstants11::getRequiredBufferSize(gl::ShaderType shaderType) const
void ShaderConstants11::markDirty() void ShaderConstants11::markDirty()
{ {
mVertexDirty = true; mShaderConstantsDirty.set();
mPixelDirty = true;
mComputeDirty = true;
mNumActiveVSSamplers = 0; mNumActiveVSSamplers = 0;
mNumActivePSSamplers = 0; mNumActivePSSamplers = 0;
mNumActiveCSSamplers = 0; mNumActiveCSSamplers = 0;
...@@ -398,15 +392,15 @@ void ShaderConstants11::setComputeWorkGroups(GLuint numGroupsX, ...@@ -398,15 +392,15 @@ void ShaderConstants11::setComputeWorkGroups(GLuint numGroupsX,
mCompute.numWorkGroups[0] = numGroupsX; mCompute.numWorkGroups[0] = numGroupsX;
mCompute.numWorkGroups[1] = numGroupsY; mCompute.numWorkGroups[1] = numGroupsY;
mCompute.numWorkGroups[2] = numGroupsZ; mCompute.numWorkGroups[2] = numGroupsZ;
mComputeDirty = true; mShaderConstantsDirty.set(gl::ShaderType::Compute);
} }
void ShaderConstants11::setMultiviewWriteToViewportIndex(GLfloat index) void ShaderConstants11::setMultiviewWriteToViewportIndex(GLfloat index)
{ {
mVertex.multiviewWriteToViewportIndex = index; mVertex.multiviewWriteToViewportIndex = index;
mVertexDirty = true;
mPixel.multiviewWriteToViewportIndex = index; mPixel.multiviewWriteToViewportIndex = index;
mPixelDirty = true; mShaderConstantsDirty.set(gl::ShaderType::Vertex);
mShaderConstantsDirty.set(gl::ShaderType::Fragment);
} }
void ShaderConstants11::onViewportChange(const gl::Rectangle &glViewport, void ShaderConstants11::onViewportChange(const gl::Rectangle &glViewport,
...@@ -414,8 +408,8 @@ void ShaderConstants11::onViewportChange(const gl::Rectangle &glViewport, ...@@ -414,8 +408,8 @@ void ShaderConstants11::onViewportChange(const gl::Rectangle &glViewport,
bool is9_3, bool is9_3,
bool presentPathFast) bool presentPathFast)
{ {
mVertexDirty = true; mShaderConstantsDirty.set(gl::ShaderType::Vertex);
mPixelDirty = true; mShaderConstantsDirty.set(gl::ShaderType::Fragment);
// On Feature Level 9_*, we must emulate large and/or negative viewports in the shaders // On Feature Level 9_*, we must emulate large and/or negative viewports in the shaders
// using viewAdjust (like the D3D9 renderer). // using viewAdjust (like the D3D9 renderer).
...@@ -513,27 +507,30 @@ gl::Error ShaderConstants11::updateBuffer(Renderer11 *renderer, ...@@ -513,27 +507,30 @@ gl::Error ShaderConstants11::updateBuffer(Renderer11 *renderer,
switch (shaderType) switch (shaderType)
{ {
case gl::ShaderType::Vertex: case gl::ShaderType::Vertex:
dirty = mVertexDirty || (mNumActiveVSSamplers < numSamplers); dirty = mShaderConstantsDirty[gl::ShaderType::Vertex] ||
(mNumActiveVSSamplers < numSamplers);
dataSize = sizeof(Vertex); dataSize = sizeof(Vertex);
data = reinterpret_cast<const uint8_t *>(&mVertex); data = reinterpret_cast<const uint8_t *>(&mVertex);
samplerData = reinterpret_cast<const uint8_t *>(mSamplerMetadataVS.data()); samplerData = reinterpret_cast<const uint8_t *>(mSamplerMetadataVS.data());
mVertexDirty = false; mShaderConstantsDirty.set(gl::ShaderType::Vertex, false);
mNumActiveVSSamplers = numSamplers; mNumActiveVSSamplers = numSamplers;
break; break;
case gl::ShaderType::Fragment: case gl::ShaderType::Fragment:
dirty = mPixelDirty || (mNumActivePSSamplers < numSamplers); dirty = mShaderConstantsDirty[gl::ShaderType::Fragment] ||
(mNumActivePSSamplers < numSamplers);
dataSize = sizeof(Pixel); dataSize = sizeof(Pixel);
data = reinterpret_cast<const uint8_t *>(&mPixel); data = reinterpret_cast<const uint8_t *>(&mPixel);
samplerData = reinterpret_cast<const uint8_t *>(mSamplerMetadataPS.data()); samplerData = reinterpret_cast<const uint8_t *>(mSamplerMetadataPS.data());
mPixelDirty = false; mShaderConstantsDirty.set(gl::ShaderType::Fragment, false);
mNumActivePSSamplers = numSamplers; mNumActivePSSamplers = numSamplers;
break; break;
case gl::ShaderType::Compute: case gl::ShaderType::Compute:
dirty = mComputeDirty || (mNumActiveCSSamplers < numSamplers); dirty = mShaderConstantsDirty[gl::ShaderType::Compute] ||
(mNumActiveCSSamplers < numSamplers);
dataSize = sizeof(Compute); dataSize = sizeof(Compute);
data = reinterpret_cast<const uint8_t *>(&mCompute); data = reinterpret_cast<const uint8_t *>(&mCompute);
samplerData = reinterpret_cast<const uint8_t *>(mSamplerMetadataCS.data()); samplerData = reinterpret_cast<const uint8_t *>(mSamplerMetadataCS.data());
mComputeDirty = false; mShaderConstantsDirty.set(gl::ShaderType::Compute, false);
mNumActiveCSSamplers = numSamplers; mNumActiveCSSamplers = numSamplers;
break; break;
default: default:
...@@ -2008,7 +2005,7 @@ gl::Error StateManager11::updateState(const gl::Context *context, ...@@ -2008,7 +2005,7 @@ gl::Error StateManager11::updateState(const gl::Context *context,
} }
// TODO(jmadill): Use dirty bits. // TODO(jmadill): Use dirty bits.
if (programD3D->areVertexUniformsDirty() || programD3D->areFragmentUniformsDirty()) if (programD3D->anyShaderUniformsDirty())
{ {
mInternalDirtyBits.set(DIRTY_BIT_PROGRAM_UNIFORMS); mInternalDirtyBits.set(DIRTY_BIT_PROGRAM_UNIFORMS);
} }
...@@ -3091,12 +3088,14 @@ gl::Error StateManager11::applyUniforms(ProgramD3D *programD3D) ...@@ -3091,12 +3088,14 @@ gl::Error StateManager11::applyUniforms(ProgramD3D *programD3D)
const d3d11::Buffer *pixelConstantBuffer = nullptr; const d3d11::Buffer *pixelConstantBuffer = nullptr;
ANGLE_TRY(fragmentUniformStorage->getConstantBuffer(mRenderer, &pixelConstantBuffer)); ANGLE_TRY(fragmentUniformStorage->getConstantBuffer(mRenderer, &pixelConstantBuffer));
if (vertexUniformStorage->size() > 0 && programD3D->areVertexUniformsDirty()) if (vertexUniformStorage->size() > 0 &&
programD3D->areShaderUniformsDirty(gl::ShaderType::Vertex))
{ {
UpdateUniformBuffer(deviceContext, vertexUniformStorage, vertexConstantBuffer); UpdateUniformBuffer(deviceContext, vertexUniformStorage, vertexConstantBuffer);
} }
if (fragmentUniformStorage->size() > 0 && programD3D->areFragmentUniformsDirty()) if (fragmentUniformStorage->size() > 0 &&
programD3D->areShaderUniformsDirty(gl::ShaderType::Fragment))
{ {
UpdateUniformBuffer(deviceContext, fragmentUniformStorage, pixelConstantBuffer); UpdateUniformBuffer(deviceContext, fragmentUniformStorage, pixelConstantBuffer);
} }
...@@ -3187,7 +3186,8 @@ gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D) ...@@ -3187,7 +3186,8 @@ gl::Error StateManager11::applyComputeUniforms(ProgramD3D *programD3D)
ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext(); ID3D11DeviceContext *deviceContext = mRenderer->getDeviceContext();
if (computeUniformStorage->size() > 0 && programD3D->areComputeUniformsDirty()) if (computeUniformStorage->size() > 0 &&
programD3D->areShaderUniformsDirty(gl::ShaderType::Compute))
{ {
UpdateUniformBuffer(deviceContext, computeUniformStorage, constantBuffer); UpdateUniformBuffer(deviceContext, computeUniformStorage, constantBuffer);
programD3D->markUniformsClean(); programD3D->markUniformsClean();
......
...@@ -127,11 +127,9 @@ class ShaderConstants11 : angle::NonCopyable ...@@ -127,11 +127,9 @@ class ShaderConstants11 : angle::NonCopyable
bool updateSamplerMetadata(SamplerMetadata *data, const gl::Texture &texture); bool updateSamplerMetadata(SamplerMetadata *data, const gl::Texture &texture);
Vertex mVertex; Vertex mVertex;
bool mVertexDirty;
Pixel mPixel; Pixel mPixel;
bool mPixelDirty;
Compute mCompute; Compute mCompute;
bool mComputeDirty; gl::ShaderBitSet mShaderConstantsDirty;
std::vector<SamplerMetadata> mSamplerMetadataVS; std::vector<SamplerMetadata> mSamplerMetadataVS;
int mNumActiveVSSamplers; int mNumActiveVSSamplers;
......
...@@ -1806,8 +1806,8 @@ gl::Error Renderer9::applyShaders(const gl::Context *context, GLenum drawMode) ...@@ -1806,8 +1806,8 @@ gl::Error Renderer9::applyShaders(const gl::Context *context, GLenum drawMode)
gl::Error Renderer9::applyUniforms(ProgramD3D *programD3D) gl::Error Renderer9::applyUniforms(ProgramD3D *programD3D)
{ {
// Skip updates if we're not dirty. Note that D3D9 cannot have compute. // Skip updates if we're not dirty. Note that D3D9 cannot have compute or geometry.
if (!programD3D->areVertexUniformsDirty() && !programD3D->areFragmentUniformsDirty()) if (!programD3D->anyShaderUniformsDirty())
{ {
return gl::NoError(); return gl::NoError();
} }
......
...@@ -138,13 +138,14 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext, ...@@ -138,13 +138,14 @@ gl::LinkResult GlslangWrapper::linkProgram(const gl::Context *glContext,
std::string setBindingString = "set = 1, binding = " + Str(textureCount); std::string setBindingString = "set = 1, binding = " + Str(textureCount);
ASSERT(samplerUniform.vertexActive || samplerUniform.fragmentActive); ASSERT(samplerUniform.isActive(gl::ShaderType::Vertex) ||
if (samplerUniform.vertexActive) samplerUniform.isActive(gl::ShaderType::Fragment));
if (samplerUniform.isActive(gl::ShaderType::Vertex))
{ {
InsertLayoutSpecifierString(&vertexSource, samplerUniform.name, setBindingString); InsertLayoutSpecifierString(&vertexSource, samplerUniform.name, setBindingString);
} }
if (samplerUniform.fragmentActive) if (samplerUniform.isActive(gl::ShaderType::Fragment))
{ {
InsertLayoutSpecifierString(&fragmentSource, samplerUniform.name, setBindingString); InsertLayoutSpecifierString(&fragmentSource, samplerUniform.name, setBindingString);
} }
......
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