Commit 43a53e24 by Brandon Jones

Converted ProgramBinary to use Context caps instead of Renderer

BUG=angle:731 Change-Id: I9bbce69cabf767fb5fb2c94f437a9950bc79d1aa Reviewed-on: https://chromium-review.googlesource.com/215370Tested-by: 's avatarBrandon Jones <bajones@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Reviewed-by: 's avatarGeoff Lang <geofflang@chromium.org>
parent a502c749
......@@ -652,7 +652,7 @@ void Context::linkProgram(GLuint program)
{
Program *programObject = mResourceManager->getProgram(program);
bool linked = programObject->link();
bool linked = programObject->link(getCaps());
// if the current program was relinked successfully we
// need to install the new executables
......@@ -1409,7 +1409,7 @@ size_t Context::getCurrentTexturesAndSamplerStates(ProgramBinary *programBinary,
for (size_t i = 0; i < samplerRange; i++)
{
outTextureTypes[i] = programBinary->getSamplerTextureType(type, i);
GLint textureUnit = programBinary->getSamplerMapping(type, i); // OpenGL texture image unit index
GLint textureUnit = programBinary->getSamplerMapping(type, i, getCaps()); // OpenGL texture image unit index
if (textureUnit != -1)
{
outTextures[i] = getSamplerTexture(textureUnit, outTextureTypes[i]);
......@@ -1508,7 +1508,7 @@ bool Context::applyUniformBuffers()
}
}
return programBinary->applyUniformBuffers(boundBuffers);
return programBinary->applyUniformBuffers(boundBuffers, getCaps());
}
bool Context::applyTransformFeedbackBuffers()
......
......@@ -243,7 +243,7 @@ void Program::bindAttributeLocation(GLuint index, const char *name)
// Links the HLSL code of the vertex and pixel shader by matching up their varyings,
// compiling them into binaries, determining the attribute mappings, and collecting
// a list of uniforms
bool Program::link()
bool Program::link(const Caps &caps)
{
unlink(false);
......@@ -252,7 +252,7 @@ bool Program::link()
mProgramBinary.set(new ProgramBinary(mRenderer));
mLinked = mProgramBinary->link(mInfoLog, mAttributeBindings, mFragmentShader, mVertexShader,
mTransformFeedbackVaryings, mTransformFeedbackBufferMode);
mTransformFeedbackVaryings, mTransformFeedbackBufferMode, caps);
return mLinked;
}
......@@ -501,14 +501,14 @@ bool Program::isFlaggedForDeletion() const
return mDeleteStatus;
}
void Program::validate()
void Program::validate(const Caps &caps)
{
mInfoLog.reset();
ProgramBinary *programBinary = getProgramBinary();
if (isLinked() && programBinary)
{
programBinary->validate(mInfoLog);
programBinary->validate(mInfoLog, caps);
}
else
{
......
......@@ -28,6 +28,7 @@ class Renderer;
namespace gl
{
struct Caps;
class ResourceManager;
class Shader;
......@@ -76,7 +77,7 @@ class Program
void bindAttributeLocation(GLuint index, const char *name);
bool link();
bool link(const Caps &caps);
bool isLinked();
bool setProgramBinary(GLenum binaryFormat, const void *binary, GLsizei length);
ProgramBinary *getProgramBinary() const;
......@@ -111,7 +112,7 @@ class Program
void flagForDeletion();
bool isFlaggedForDeletion() const;
void validate();
void validate(const Caps &caps);
bool isValidated() const;
GLint getProgramBinaryLength() const;
......
......@@ -384,7 +384,7 @@ bool ProgramBinary::usesGeometryShader() const
// Returns the index of the texture image unit (0-19) corresponding to a Direct3D 9 sampler
// index (0-15 for the pixel shader and 0-3 for the vertex shader).
GLint ProgramBinary::getSamplerMapping(SamplerType type, unsigned int samplerIndex)
GLint ProgramBinary::getSamplerMapping(SamplerType type, unsigned int samplerIndex, const Caps &caps)
{
GLint logicalTextureUnit = -1;
......@@ -409,8 +409,7 @@ GLint ProgramBinary::getSamplerMapping(SamplerType type, unsigned int samplerInd
default: UNREACHABLE();
}
// TODO (geofflang): Use context's caps
if (logicalTextureUnit >= 0 && logicalTextureUnit < (GLint)mRenderer->getRendererCaps().maxCombinedTextureImageUnits)
if (logicalTextureUnit >= 0 && logicalTextureUnit < static_cast<GLint>(caps.maxCombinedTextureImageUnits))
{
return logicalTextureUnit;
}
......@@ -1014,7 +1013,7 @@ void ProgramBinary::applyUniforms()
}
}
bool ProgramBinary::applyUniformBuffers(const std::vector<gl::Buffer*> boundBuffers)
bool ProgramBinary::applyUniformBuffers(const std::vector<gl::Buffer*> boundBuffers, const Caps &caps)
{
const gl::Buffer *vertexUniformBuffers[gl::IMPLEMENTATION_MAX_VERTEX_SHADER_UNIFORM_BUFFERS] = {NULL};
const gl::Buffer *fragmentUniformBuffers[gl::IMPLEMENTATION_MAX_FRAGMENT_SHADER_UNIFORM_BUFFERS] = {NULL};
......@@ -1043,7 +1042,7 @@ bool ProgramBinary::applyUniformBuffers(const std::vector<gl::Buffer*> boundBuff
{
unsigned int registerIndex = uniformBlock->vsRegisterIndex - reservedBuffersInVS;
ASSERT(vertexUniformBuffers[registerIndex] == NULL);
ASSERT(registerIndex < mRenderer->getRendererCaps().maxVertexUniformBlocks);
ASSERT(registerIndex < caps.maxVertexUniformBlocks);
vertexUniformBuffers[registerIndex] = uniformBuffer;
}
......@@ -1051,7 +1050,7 @@ bool ProgramBinary::applyUniformBuffers(const std::vector<gl::Buffer*> boundBuff
{
unsigned int registerIndex = uniformBlock->psRegisterIndex - reservedBuffersInFS;
ASSERT(fragmentUniformBuffers[registerIndex] == NULL);
ASSERT(registerIndex < mRenderer->getRendererCaps().maxFragmentUniformBlocks);
ASSERT(registerIndex < caps.maxFragmentUniformBlocks);
fragmentUniformBuffers[registerIndex] = uniformBuffer;
}
}
......@@ -1601,7 +1600,7 @@ GLint ProgramBinary::getLength()
}
bool ProgramBinary::link(InfoLog &infoLog, const AttributeBindings &attributeBindings, Shader *fragmentShader, Shader *vertexShader,
const std::vector<std::string>& transformFeedbackVaryings, GLenum transformFeedbackBufferMode)
const std::vector<std::string>& transformFeedbackVaryings, GLenum transformFeedbackBufferMode, const Caps &caps)
{
if (!fragmentShader || !fragmentShader->isCompiled())
{
......@@ -1660,7 +1659,7 @@ bool ProgramBinary::link(InfoLog &infoLog, const AttributeBindings &attributeBin
success = false;
}
if (!linkUniforms(infoLog, *vertexShader, *fragmentShader))
if (!linkUniforms(infoLog, *vertexShader, *fragmentShader, caps))
{
success = false;
}
......@@ -1675,13 +1674,13 @@ bool ProgramBinary::link(InfoLog &infoLog, const AttributeBindings &attributeBin
mUniforms.push_back(new LinkedUniform(GL_FLOAT, GL_HIGH_FLOAT, "gl_DepthRange.diff", 0, -1, defaultInfo));
}
if (!linkUniformBlocks(infoLog, *vertexShader, *fragmentShader))
if (!linkUniformBlocks(infoLog, *vertexShader, *fragmentShader, caps))
{
success = false;
}
if (!gatherTransformFeedbackLinkedVaryings(infoLog, linkedVaryings, transformFeedbackVaryings,
transformFeedbackBufferMode, &mTransformFeedbackLinkedVaryings))
transformFeedbackBufferMode, &mTransformFeedbackLinkedVaryings, caps))
{
success = false;
}
......@@ -1898,7 +1897,7 @@ bool ProgramBinary::linkValidateInterfaceBlockFields(InfoLog &infoLog, const std
return true;
}
bool ProgramBinary::linkUniforms(InfoLog &infoLog, const Shader &vertexShader, const Shader &fragmentShader)
bool ProgramBinary::linkUniforms(InfoLog &infoLog, const Shader &vertexShader, const Shader &fragmentShader, const Caps &caps)
{
const rx::VertexShaderD3D *vertexShaderD3D = rx::VertexShaderD3D::makeVertexShaderD3D(vertexShader.getImplementation());
const rx::FragmentShaderD3D *fragmentShaderD3D = rx::FragmentShaderD3D::makeFragmentShaderD3D(fragmentShader.getImplementation());
......@@ -1943,7 +1942,7 @@ bool ProgramBinary::linkUniforms(InfoLog &infoLog, const Shader &vertexShader, c
defineUniformBase(GL_FRAGMENT_SHADER, uniform, fragmentShaderD3D->getUniformRegister(uniform.name));
}
if (!indexUniforms(infoLog))
if (!indexUniforms(infoLog, caps))
{
return false;
}
......@@ -2026,12 +2025,11 @@ void ProgramBinary::defineUniform(GLenum shader, const sh::ShaderVariable &unifo
}
}
bool ProgramBinary::indexSamplerUniform(const LinkedUniform &uniform, InfoLog &infoLog)
bool ProgramBinary::indexSamplerUniform(const LinkedUniform &uniform, InfoLog &infoLog, const Caps &caps)
{
ASSERT(IsSampler(uniform.type));
ASSERT(uniform.vsRegisterIndex != GL_INVALID_INDEX || uniform.psRegisterIndex != GL_INVALID_INDEX);
const gl::Caps &caps = mRenderer->getRendererCaps();
if (uniform.vsRegisterIndex != GL_INVALID_INDEX)
{
if (!assignSamplers(uniform.vsRegisterIndex, uniform.type, uniform.arraySize, mSamplersVS,
......@@ -2073,7 +2071,7 @@ bool ProgramBinary::indexSamplerUniform(const LinkedUniform &uniform, InfoLog &i
return true;
}
bool ProgramBinary::indexUniforms(InfoLog &infoLog)
bool ProgramBinary::indexUniforms(InfoLog &infoLog, const Caps &caps)
{
for (size_t uniformIndex = 0; uniformIndex < mUniforms.size(); uniformIndex++)
{
......@@ -2081,7 +2079,7 @@ bool ProgramBinary::indexUniforms(InfoLog &infoLog)
if (IsSampler(uniform.type))
{
if (!indexSamplerUniform(uniform, infoLog))
if (!indexSamplerUniform(uniform, infoLog, caps))
{
return false;
}
......@@ -2171,7 +2169,7 @@ bool ProgramBinary::areMatchingInterfaceBlocks(InfoLog &infoLog, const sh::Inter
return true;
}
bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const Shader &vertexShader, const Shader &fragmentShader)
bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const Shader &vertexShader, const Shader &fragmentShader, const Caps &caps)
{
const rx::VertexShaderD3D *vertexShaderD3D = rx::VertexShaderD3D::makeVertexShaderD3D(vertexShader.getImplementation());
const rx::FragmentShaderD3D *fragmentShaderD3D = rx::FragmentShaderD3D::makeFragmentShaderD3D(fragmentShader.getImplementation());
......@@ -2205,7 +2203,7 @@ bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const Shader &vertexShad
for (unsigned int blockIndex = 0; blockIndex < vertexInterfaceBlocks.size(); blockIndex++)
{
if (!defineUniformBlock(infoLog, vertexShader, vertexInterfaceBlocks[blockIndex]))
if (!defineUniformBlock(infoLog, vertexShader, vertexInterfaceBlocks[blockIndex], caps))
{
return false;
}
......@@ -2213,7 +2211,7 @@ bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const Shader &vertexShad
for (unsigned int blockIndex = 0; blockIndex < fragmentInterfaceBlocks.size(); blockIndex++)
{
if (!defineUniformBlock(infoLog, fragmentShader, fragmentInterfaceBlocks[blockIndex]))
if (!defineUniformBlock(infoLog, fragmentShader, fragmentInterfaceBlocks[blockIndex], caps))
{
return false;
}
......@@ -2225,13 +2223,11 @@ bool ProgramBinary::linkUniformBlocks(InfoLog &infoLog, const Shader &vertexShad
bool ProgramBinary::gatherTransformFeedbackLinkedVaryings(InfoLog &infoLog, const std::vector<LinkedVarying> &linkedVaryings,
const std::vector<std::string> &transformFeedbackVaryingNames,
GLenum transformFeedbackBufferMode,
std::vector<LinkedVarying> *outTransformFeedbackLinkedVaryings) const
std::vector<LinkedVarying> *outTransformFeedbackLinkedVaryings,
const Caps &caps) const
{
size_t totalComponents = 0;
// TODO (geofflang): Use context's caps.
const gl::Caps &caps = mRenderer->getRendererCaps();
// Gather the linked varyings that are used for transform feedback, they should all exist.
outTransformFeedbackLinkedVaryings->clear();
for (size_t i = 0; i < transformFeedbackVaryingNames.size(); i++)
......@@ -2321,7 +2317,7 @@ void ProgramBinary::defineUniformBlockMembers(const std::vector<VarT> &fields, c
}
}
bool ProgramBinary::defineUniformBlock(InfoLog &infoLog, const Shader &shader, const sh::InterfaceBlock &interfaceBlock)
bool ProgramBinary::defineUniformBlock(InfoLog &infoLog, const Shader &shader, const sh::InterfaceBlock &interfaceBlock, const Caps &caps)
{
const rx::ShaderD3D* shaderD3D = rx::ShaderD3D::makeShaderD3D(shader.getImplementation());
......@@ -2380,7 +2376,7 @@ bool ProgramBinary::defineUniformBlock(InfoLog &infoLog, const Shader &shader, c
ASSERT(uniformBlock->name == interfaceBlock.name);
if (!assignUniformBlockRegister(infoLog, uniformBlock, shader.getType(),
interfaceBlockRegister + uniformBlockElement))
interfaceBlockRegister + uniformBlockElement, caps))
{
return false;
}
......@@ -2389,9 +2385,8 @@ bool ProgramBinary::defineUniformBlock(InfoLog &infoLog, const Shader &shader, c
return true;
}
bool ProgramBinary::assignUniformBlockRegister(InfoLog &infoLog, UniformBlock *uniformBlock, GLenum shader, unsigned int registerIndex)
bool ProgramBinary::assignUniformBlockRegister(InfoLog &infoLog, UniformBlock *uniformBlock, GLenum shader, unsigned int registerIndex, const Caps &caps)
{
const gl::Caps &caps = mRenderer->getRendererCaps();
if (shader == GL_VERTEX_SHADER)
{
uniformBlock->vsRegisterIndex = registerIndex;
......@@ -2676,10 +2671,10 @@ GLuint ProgramBinary::getActiveUniformBlockMaxLength() const
return maxLength;
}
void ProgramBinary::validate(InfoLog &infoLog)
void ProgramBinary::validate(InfoLog &infoLog, const Caps &caps)
{
applyUniforms();
if (!validateSamplers(&infoLog))
if (!validateSamplers(&infoLog, caps))
{
mValidated = false;
}
......@@ -2689,15 +2684,14 @@ void ProgramBinary::validate(InfoLog &infoLog)
}
}
bool ProgramBinary::validateSamplers(InfoLog *infoLog)
bool ProgramBinary::validateSamplers(InfoLog *infoLog, const Caps &caps)
{
// if any two active samplers in a program are of different types, but refer to the same
// texture image unit, and this is the current program, then ValidateProgram will fail, and
// DrawArrays and DrawElements will issue the INVALID_OPERATION error.
updateSamplerMapping();
// TODO (geofflang): Use context's caps
const unsigned int maxCombinedTextureImageUnits = mRenderer->getRendererCaps().maxCombinedTextureImageUnits;
const unsigned int maxCombinedTextureImageUnits = caps.maxCombinedTextureImageUnits;
TextureType textureUnitType[IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS];
for (unsigned int i = 0; i < IMPLEMENTATION_MAX_COMBINED_TEXTURE_IMAGE_UNITS; ++i)
......
......@@ -46,6 +46,7 @@ class UniformStorage;
namespace gl
{
struct Caps;
class Shader;
class InfoLog;
class AttributeBindings;
......@@ -99,7 +100,7 @@ class ProgramBinary : public RefCountObject
GLuint getAttributeLocation(const char *name);
int getSemanticIndex(int attributeIndex);
GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex);
GLint getSamplerMapping(SamplerType type, unsigned int samplerIndex, const Caps &caps);
TextureType getSamplerTextureType(SamplerType type, unsigned int samplerIndex);
GLint getUsedSamplerRange(SamplerType type);
bool usesPointSize() const;
......@@ -137,14 +138,14 @@ class ProgramBinary : public RefCountObject
void dirtyAllUniforms();
void applyUniforms();
bool applyUniformBuffers(const std::vector<Buffer*> boundBuffers);
bool applyUniformBuffers(const std::vector<Buffer*> boundBuffers, const Caps &caps);
bool load(InfoLog &infoLog, GLenum binaryFormat, const void *binary, GLsizei length);
bool save(GLenum *binaryFormat, void *binary, GLsizei bufSize, GLsizei *length);
GLint getLength();
bool link(InfoLog &infoLog, const AttributeBindings &attributeBindings, Shader *fragmentShader, Shader *vertexShader,
const std::vector<std::string>& transformFeedbackVaryings, GLenum transformFeedbackBufferMode);
const std::vector<std::string>& transformFeedbackVaryings, GLenum transformFeedbackBufferMode, const Caps &caps);
void getAttachedShaders(GLsizei maxCount, GLsizei *count, GLuint *shaders);
void getActiveAttribute(GLuint index, GLsizei bufsize, GLsizei *length, GLint *size, GLenum *type, GLchar *name) const;
......@@ -171,8 +172,8 @@ class ProgramBinary : public RefCountObject
const LinkedVarying &getTransformFeedbackVarying(size_t idx) const;
GLenum getTransformFeedbackBufferMode() const;
void validate(InfoLog &infoLog);
bool validateSamplers(InfoLog *infoLog);
void validate(InfoLog &infoLog, const Caps &caps);
bool validateSamplers(InfoLog *infoLog, const Caps &caps);
bool isValidated() const;
void updateSamplerMapping();
......@@ -212,25 +213,26 @@ class ProgramBinary : public RefCountObject
bool linkValidateUniforms(InfoLog &infoLog, const std::string &uniformName, const sh::Uniform &vertexUniform, const sh::Uniform &fragmentUniform);
bool linkValidateVaryings(InfoLog &infoLog, const std::string &varyingName, const sh::Varying &vertexVarying, const sh::Varying &fragmentVarying);
bool linkValidateInterfaceBlockFields(InfoLog &infoLog, const std::string &uniformName, const sh::InterfaceBlockField &vertexUniform, const sh::InterfaceBlockField &fragmentUniform);
bool linkUniforms(InfoLog &infoLog, const Shader &vertexShader, const Shader &fragmentShader);
bool linkUniforms(InfoLog &infoLog, const Shader &vertexShader, const Shader &fragmentShader, const Caps &caps);
void defineUniformBase(GLenum shader, const sh::Uniform &uniform, unsigned int uniformRegister);
void defineUniform(GLenum shader, const sh::ShaderVariable &uniform, const std::string &fullName, sh::HLSLBlockEncoder *encoder);
bool indexSamplerUniform(const LinkedUniform &uniform, InfoLog &infoLog);
bool indexUniforms(InfoLog &infoLog);
bool indexSamplerUniform(const LinkedUniform &uniform, InfoLog &infoLog, const Caps &caps);
bool indexUniforms(InfoLog &infoLog, const Caps &caps);
static bool assignSamplers(unsigned int startSamplerIndex, GLenum samplerType, unsigned int samplerCount,
Sampler *outArray, GLuint *usedRange, unsigned int limit);
bool areMatchingInterfaceBlocks(InfoLog &infoLog, const sh::InterfaceBlock &vertexInterfaceBlock, const sh::InterfaceBlock &fragmentInterfaceBlock);
bool linkUniformBlocks(InfoLog &infoLog, const Shader &vertexShader, const Shader &fragmentShader);
bool linkUniformBlocks(InfoLog &infoLog, const Shader &vertexShader, const Shader &fragmentShader, const Caps &caps);
bool gatherTransformFeedbackLinkedVaryings(InfoLog &infoLog, const std::vector<LinkedVarying> &linkedVaryings,
const std::vector<std::string> &transformFeedbackVaryingNames,
GLenum transformFeedbackBufferMode,
std::vector<LinkedVarying> *outTransformFeedbackLinkedVaryings) const;
std::vector<LinkedVarying> *outTransformFeedbackLinkedVaryings,
const Caps &caps) const;
template <typename VarT>
void defineUniformBlockMembers(const std::vector<VarT> &fields, const std::string &prefix, int blockIndex,
sh::BlockLayoutEncoder *encoder, std::vector<unsigned int> *blockUniformIndexes,
bool inRowMajorLayout);
bool defineUniformBlock(InfoLog &infoLog, const Shader &shader, const sh::InterfaceBlock &interfaceBlock);
bool assignUniformBlockRegister(InfoLog &infoLog, UniformBlock *uniformBlock, GLenum shader, unsigned int registerIndex);
bool defineUniformBlock(InfoLog &infoLog, const Shader &shader, const sh::InterfaceBlock &interfaceBlock, const Caps &caps);
bool assignUniformBlockRegister(InfoLog &infoLog, UniformBlock *uniformBlock, GLenum shader, unsigned int registerIndex, const Caps &caps);
void defineOutputVariables(Shader *fragmentShader);
void initializeUniformStorage();
......
......@@ -4632,7 +4632,7 @@ void __stdcall glValidateProgram(GLuint program)
}
}
programObject->validate();
programObject->validate(context->getCaps());
}
}
......
......@@ -1466,7 +1466,7 @@ static bool ValidateDrawBase(Context *context, GLenum mode, GLsizei count, GLsiz
}
gl::ProgramBinary *programBinary = state.getCurrentProgramBinary();
if (!programBinary->validateSamplers(NULL))
if (!programBinary->validateSamplers(NULL, context->getCaps()))
{
context->recordError(Error(GL_INVALID_OPERATION));
return false;
......
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