Hash :
4cff2477
Author :
Date :
2015-08-21T16:53:18
Make PackedVarying a D3D-only type. The register assignment stuff only applies to the D3D back-end. Cleans up the GL back-ends use of PackedVarying, and will lead to future cleanups relating to packing varyings. BUG=angleproject:1123 Change-Id: Iaaa5fc03577e5b61ea6ae76ee1e15ad608037f34 Reviewed-on: https://chromium-review.googlesource.com/295190 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Geoff Lang <geofflang@chromium.org> Tested-by: Jamie Madill <jmadill@chromium.org>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148
//
// Copyright 2015 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// ShaderGL.cpp: Implements the class methods for ShaderGL.
#include "libANGLE/renderer/gl/ShaderGL.h"
#include "common/debug.h"
#include "libANGLE/Compiler.h"
#include "libANGLE/renderer/gl/CompilerGL.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
template <typename VarT>
static std::vector<VarT> GetFilteredShaderVariables(const std::vector<VarT> *variableList)
{
ASSERT(variableList);
std::vector<VarT> result;
for (size_t varIndex = 0; varIndex < variableList->size(); varIndex++)
{
const VarT &var = variableList->at(varIndex);
if (var.staticUse)
{
result.push_back(var);
}
}
return result;
}
template <typename VarT>
static const std::vector<VarT> &GetShaderVariables(const std::vector<VarT> *variableList)
{
ASSERT(variableList);
return *variableList;
}
namespace rx
{
ShaderGL::ShaderGL(GLenum type, const FunctionsGL *functions)
: ShaderImpl(),
mFunctions(functions),
mType(type),
mShaderID(0)
{
ASSERT(mFunctions);
}
ShaderGL::~ShaderGL()
{
if (mShaderID != 0)
{
mFunctions->deleteShader(mShaderID);
mShaderID = 0;
}
}
bool ShaderGL::compile(gl::Compiler *compiler, const std::string &source)
{
// Reset the previous state
mActiveAttributes.clear();
mVaryings.clear();
mUniforms.clear();
mInterfaceBlocks.clear();
mActiveOutputVariables.clear();
if (mShaderID != 0)
{
mFunctions->deleteShader(mShaderID);
mShaderID = 0;
}
// Translate the ESSL into GLSL
CompilerGL *compilerGL = GetImplAs<CompilerGL>(compiler);
ShHandle compilerHandle = compilerGL->getCompilerHandle(mType);
int compileOptions = (SH_OBJECT_CODE | SH_VARIABLES | SH_INIT_GL_POSITION);
const char* sourceCString = source.c_str();
if (!ShCompile(compilerHandle, &sourceCString, 1, compileOptions))
{
mInfoLog = ShGetInfoLog(compilerHandle);
TRACE("\n%s", mInfoLog.c_str());
return false;
}
mTranslatedSource = ShGetObjectCode(compilerHandle);
const char* translatedSourceCString = mTranslatedSource.c_str();
// Generate a shader object and set the source
mShaderID = mFunctions->createShader(mType);
mFunctions->shaderSource(mShaderID, 1, &translatedSourceCString, nullptr);
mFunctions->compileShader(mShaderID);
// Check for compile errors from the native driver
GLint compileStatus = GL_FALSE;
mFunctions->getShaderiv(mShaderID, GL_COMPILE_STATUS, &compileStatus);
ASSERT(compileStatus == GL_TRUE);
if (compileStatus == GL_FALSE)
{
// Compilation failed, put the error into the info log
GLint infoLogLength = 0;
mFunctions->getShaderiv(mShaderID, GL_INFO_LOG_LENGTH, &infoLogLength);
std::vector<char> buf(infoLogLength);
mFunctions->getShaderInfoLog(mShaderID, infoLogLength, nullptr, &buf[0]);
mFunctions->deleteShader(mShaderID);
mShaderID = 0;
mInfoLog = &buf[0];
TRACE("\n%s", mInfoLog.c_str());
return false;
}
// Gather the shader information
mShaderVersion = ShGetShaderVersion(compilerHandle);
// TODO: refactor this out, gathering of the attributes, varyings and outputs should be done
// at the gl::Shader level
if (mType == GL_VERTEX_SHADER)
{
mActiveAttributes = GetFilteredShaderVariables(ShGetAttributes(compilerHandle));
}
mVaryings = GetShaderVariables(ShGetVaryings(compilerHandle));
mUniforms = GetShaderVariables(ShGetUniforms(compilerHandle));
mInterfaceBlocks = GetShaderVariables(ShGetInterfaceBlocks(compilerHandle));
if (mType == GL_FRAGMENT_SHADER)
{
mActiveOutputVariables = GetFilteredShaderVariables(ShGetOutputVariables(compilerHandle));
}
return true;
}
std::string ShaderGL::getDebugInfo() const
{
return std::string();
}
GLuint ShaderGL::getShaderID() const
{
return mShaderID;
}
}