Commit 34ca4f5b by Jamie Madill Committed by Commit Bot

Remove Shader::getSemanticIndex.

This method doesn't really belong to GL, and was only used by the D3D back-end to compute some attribute indexes. Simplify the code by moving it into ProgramD3D. Also add the ability for the ShaderImpl to assert that any pending compiles have resolved. BUG=angleproject:1156 Change-Id: I0af3d3082ff8c908e6a87b9734989efbefd28808 Reviewed-on: https://chromium-review.googlesource.com/526336 Commit-Queue: Jamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent cabdd1a0
...@@ -382,6 +382,19 @@ GLuint ProgramState::getSamplerIndexFromUniformIndex(GLuint uniformIndex) const ...@@ -382,6 +382,19 @@ GLuint ProgramState::getSamplerIndexFromUniformIndex(GLuint uniformIndex) const
return uniformIndex - mSamplerUniformRange.low(); return uniformIndex - mSamplerUniformRange.low();
} }
GLuint ProgramState::getAttributeLocation(const std::string &name) const
{
for (const sh::Attribute &attribute : mAttributes)
{
if (attribute.name == name)
{
return attribute.location;
}
}
return static_cast<GLuint>(-1);
}
Program::Program(rx::GLImplFactory *factory, ShaderProgramManager *manager, GLuint handle) Program::Program(rx::GLImplFactory *factory, ShaderProgramManager *manager, GLuint handle)
: mProgram(factory->createProgram(mState)), : mProgram(factory->createProgram(mState)),
mValidated(false), mValidated(false),
...@@ -941,15 +954,7 @@ void Program::getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shade ...@@ -941,15 +954,7 @@ void Program::getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shade
GLuint Program::getAttributeLocation(const std::string &name) const GLuint Program::getAttributeLocation(const std::string &name) const
{ {
for (const sh::Attribute &attribute : mState.mAttributes) return mState.getAttributeLocation(name);
{
if (attribute.name == name)
{
return attribute.location;
}
}
return static_cast<GLuint>(-1);
} }
bool Program::isAttribLocationActive(size_t attribLocation) const bool Program::isAttribLocationActive(size_t attribLocation) const
......
...@@ -255,6 +255,7 @@ class ProgramState final : angle::NonCopyable ...@@ -255,6 +255,7 @@ class ProgramState final : angle::NonCopyable
Optional<GLuint> getSamplerIndex(GLint location) const; Optional<GLuint> getSamplerIndex(GLint location) const;
bool isSamplerUniformIndex(GLuint index) const; bool isSamplerUniformIndex(GLuint index) const;
GLuint getSamplerIndexFromUniformIndex(GLuint uniformIndex) const; GLuint getSamplerIndexFromUniformIndex(GLuint uniformIndex) const;
GLuint getAttributeLocation(const std::string &name) const;
private: private:
friend class MemoryProgramCache; friend class MemoryProgramCache;
......
...@@ -74,7 +74,11 @@ bool CompareShaderVar(const sh::ShaderVariable &x, const sh::ShaderVariable &y) ...@@ -74,7 +74,11 @@ bool CompareShaderVar(const sh::ShaderVariable &x, const sh::ShaderVariable &y)
return gl::VariableSortOrder(x.type) < gl::VariableSortOrder(y.type); return gl::VariableSortOrder(x.type) < gl::VariableSortOrder(y.type);
} }
ShaderState::ShaderState(GLenum shaderType) : mLabel(), mShaderType(shaderType), mShaderVersion(100) ShaderState::ShaderState(GLenum shaderType)
: mLabel(),
mShaderType(shaderType),
mShaderVersion(100),
mCompileStatus(CompileStatus::NOT_COMPILED)
{ {
mLocalSize.fill(-1); mLocalSize.fill(-1);
} }
...@@ -95,7 +99,6 @@ Shader::Shader(ShaderProgramManager *manager, ...@@ -95,7 +99,6 @@ Shader::Shader(ShaderProgramManager *manager,
mType(type), mType(type),
mRefCount(0), mRefCount(0),
mDeleteStatus(false), mDeleteStatus(false),
mStatus(CompileStatus::NOT_COMPILED),
mResourceManager(manager) mResourceManager(manager)
{ {
ASSERT(mImplementation); ASSERT(mImplementation);
...@@ -263,7 +266,7 @@ void Shader::compile(const Context *context) ...@@ -263,7 +266,7 @@ void Shader::compile(const Context *context)
mState.mActiveAttributes.clear(); mState.mActiveAttributes.clear();
mState.mActiveOutputVariables.clear(); mState.mActiveOutputVariables.clear();
mStatus = CompileStatus::COMPILE_REQUESTED; mState.mCompileStatus = CompileStatus::COMPILE_REQUESTED;
mBoundCompiler.set(context->getCompiler()); mBoundCompiler.set(context->getCompiler());
// Cache the compile source and options for compilation. Must be done now, since the source // Cache the compile source and options for compilation. Must be done now, since the source
...@@ -296,7 +299,7 @@ void Shader::compile(const Context *context) ...@@ -296,7 +299,7 @@ void Shader::compile(const Context *context)
void Shader::resolveCompile(const Context *context) void Shader::resolveCompile(const Context *context)
{ {
if (mStatus != CompileStatus::COMPILE_REQUESTED) if (!mState.compilePending())
{ {
return; return;
} }
...@@ -317,7 +320,7 @@ void Shader::resolveCompile(const Context *context) ...@@ -317,7 +320,7 @@ void Shader::resolveCompile(const Context *context)
{ {
mInfoLog = sh::GetInfoLog(compilerHandle); mInfoLog = sh::GetInfoLog(compilerHandle);
WARN() << std::endl << mInfoLog; WARN() << std::endl << mInfoLog;
mStatus = CompileStatus::NOT_COMPILED; mState.mCompileStatus = CompileStatus::NOT_COMPILED;
return; return;
} }
...@@ -378,7 +381,7 @@ void Shader::resolveCompile(const Context *context) ...@@ -378,7 +381,7 @@ void Shader::resolveCompile(const Context *context)
ASSERT(!mState.mTranslatedSource.empty()); ASSERT(!mState.mTranslatedSource.empty());
bool success = mImplementation->postTranslateCompile(mBoundCompiler.get(), &mInfoLog); bool success = mImplementation->postTranslateCompile(mBoundCompiler.get(), &mInfoLog);
mStatus = success ? CompileStatus::COMPILED : CompileStatus::NOT_COMPILED; mState.mCompileStatus = success ? CompileStatus::COMPILED : CompileStatus::NOT_COMPILED;
} }
void Shader::addRef() void Shader::addRef()
...@@ -414,7 +417,7 @@ void Shader::flagForDeletion() ...@@ -414,7 +417,7 @@ void Shader::flagForDeletion()
bool Shader::isCompiled(const Context *context) bool Shader::isCompiled(const Context *context)
{ {
resolveCompile(context); resolveCompile(context);
return mStatus == CompileStatus::COMPILED; return mState.mCompileStatus == CompileStatus::COMPILED;
} }
int Shader::getShaderVersion(const Context *context) int Shader::getShaderVersion(const Context *context)
...@@ -453,30 +456,6 @@ const std::vector<sh::OutputVariable> &Shader::getActiveOutputVariables(const Co ...@@ -453,30 +456,6 @@ const std::vector<sh::OutputVariable> &Shader::getActiveOutputVariables(const Co
return mState.getActiveOutputVariables(); return mState.getActiveOutputVariables();
} }
int Shader::getSemanticIndex(const Context *context, const std::string &attributeName)
{
resolveCompile(context);
if (!attributeName.empty())
{
const auto &activeAttributes = mState.getActiveAttributes();
int semanticIndex = 0;
for (size_t attributeIndex = 0; attributeIndex < activeAttributes.size(); attributeIndex++)
{
const sh::ShaderVariable &attribute = activeAttributes[attributeIndex];
if (attribute.name == attributeName)
{
return semanticIndex;
}
semanticIndex += gl::VariableRegisterCount(attribute.type);
}
}
return -1;
}
const sh::WorkGroupSize &Shader::getWorkGroupSize(const Context *context) const sh::WorkGroupSize &Shader::getWorkGroupSize(const Context *context)
{ {
resolveCompile(context); resolveCompile(context);
......
...@@ -40,6 +40,14 @@ struct Limitations; ...@@ -40,6 +40,14 @@ struct Limitations;
class ShaderProgramManager; class ShaderProgramManager;
class Context; class Context;
// We defer the compile until link time, or until properties are queried.
enum class CompileStatus
{
NOT_COMPILED,
COMPILE_REQUESTED,
COMPILED,
};
class ShaderState final : angle::NonCopyable class ShaderState final : angle::NonCopyable
{ {
public: public:
...@@ -63,6 +71,8 @@ class ShaderState final : angle::NonCopyable ...@@ -63,6 +71,8 @@ class ShaderState final : angle::NonCopyable
return mActiveOutputVariables; return mActiveOutputVariables;
} }
bool compilePending() const { return mCompileStatus == CompileStatus::COMPILE_REQUESTED; }
private: private:
friend class Shader; friend class Shader;
...@@ -80,6 +90,9 @@ class ShaderState final : angle::NonCopyable ...@@ -80,6 +90,9 @@ class ShaderState final : angle::NonCopyable
std::vector<sh::InterfaceBlock> mInterfaceBlocks; std::vector<sh::InterfaceBlock> mInterfaceBlocks;
std::vector<sh::Attribute> mActiveAttributes; std::vector<sh::Attribute> mActiveAttributes;
std::vector<sh::OutputVariable> mActiveOutputVariables; std::vector<sh::OutputVariable> mActiveOutputVariables;
// Indicates if this shader has been successfully compiled
CompileStatus mCompileStatus;
}; };
class Shader final : angle::NonCopyable, public LabeledObject class Shader final : angle::NonCopyable, public LabeledObject
...@@ -136,8 +149,6 @@ class Shader final : angle::NonCopyable, public LabeledObject ...@@ -136,8 +149,6 @@ class Shader final : angle::NonCopyable, public LabeledObject
const std::vector<sh::Attribute> &getActiveAttributes(const Context *context); const std::vector<sh::Attribute> &getActiveAttributes(const Context *context);
const std::vector<sh::OutputVariable> &getActiveOutputVariables(const Context *context); const std::vector<sh::OutputVariable> &getActiveOutputVariables(const Context *context);
int getSemanticIndex(const Context *context, const std::string &attributeName);
const sh::WorkGroupSize &getWorkGroupSize(const Context *context); const sh::WorkGroupSize &getWorkGroupSize(const Context *context);
private: private:
...@@ -148,14 +159,6 @@ class Shader final : angle::NonCopyable, public LabeledObject ...@@ -148,14 +159,6 @@ class Shader final : angle::NonCopyable, public LabeledObject
void resolveCompile(const Context *context); void resolveCompile(const Context *context);
// We defer the compile until link time, or until properties are queried.
enum class CompileStatus
{
NOT_COMPILED,
COMPILE_REQUESTED,
COMPILED,
};
ShaderState mState; ShaderState mState;
std::string mLastCompiledSource; std::string mLastCompiledSource;
std::string mLastCompiledSourcePath; std::string mLastCompiledSourcePath;
...@@ -166,7 +169,6 @@ class Shader final : angle::NonCopyable, public LabeledObject ...@@ -166,7 +169,6 @@ class Shader final : angle::NonCopyable, public LabeledObject
const GLenum mType; const GLenum mType;
unsigned int mRefCount; // Number of program objects this shader is attached to unsigned int mRefCount; // Number of program objects this shader is attached to
bool mDeleteStatus; // Flag to indicate that the shader can be deleted when no longer in use bool mDeleteStatus; // Flag to indicate that the shader can be deleted when no longer in use
CompileStatus mStatus; // Indicates if this shader has been successfully compiled
std::string mInfoLog; std::string mInfoLog;
// We keep a reference to the translator in order to defer compiles while preserving settings. // We keep a reference to the translator in order to defer compiles while preserving settings.
......
...@@ -2374,14 +2374,16 @@ void ProgramD3D::initAttribLocationsToD3DSemantic(const gl::Context *context) ...@@ -2374,14 +2374,16 @@ void ProgramD3D::initAttribLocationsToD3DSemantic(const gl::Context *context)
ASSERT(vertexShader != nullptr); ASSERT(vertexShader != nullptr);
// Init semantic index // Init semantic index
for (const sh::Attribute &attribute : mState.getAttributes()) int semanticIndex = 0;
for (const sh::Attribute &attribute : vertexShader->getActiveAttributes(context))
{ {
int d3dSemantic = vertexShader->getSemanticIndex(context, attribute.name);
int regCount = gl::VariableRegisterCount(attribute.type); int regCount = gl::VariableRegisterCount(attribute.type);
GLuint location = mState.getAttributeLocation(attribute.name);
ASSERT(location != std::numeric_limits<GLuint>::max());
for (int reg = 0; reg < regCount; ++reg) for (int reg = 0; reg < regCount; ++reg)
{ {
mAttribLocationToD3DSemantic[attribute.location + reg] = d3dSemantic + reg; mAttribLocationToD3DSemantic[location + reg] = semanticIndex++;
} }
} }
} }
......
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