Hash :
e294bb87
Author :
Date :
2014-07-17T14:16:26
Add new shader inspection APIs. Each new entry point corresponds to one of the variable types: varyings, attributes, uniforms, output variables, and interface blocks. They return a pointer to the vector with all of the parsed variables, which then the app can copy to its own memory. Currently we do not support the staticUse field in the HLSL translator. BUG=angle:466 Change-Id: I7dc09e761ab070feef5360ad27740110c44853b3 Reviewed-on: https://chromium-review.googlesource.com/208750 Tested-by: Jamie Madill <jmadill@chromium.org> Reviewed-by: Zhenyao Mo <zmo@chromium.org> Reviewed-by: Nicolas Capens <capn@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 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
//
// Copyright (c) 2002-2013 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.
//
// Shader.h: Defines the abstract gl::Shader class and its concrete derived
// classes VertexShader and FragmentShader. Implements GL shader objects and
// related functionality. [OpenGL ES 2.0.24] section 2.10 page 24 and section
// 3.8 page 84.
#ifndef LIBGLESV2_SHADER_H_
#define LIBGLESV2_SHADER_H_
#include <string>
#include <list>
#include <vector>
#include "angle_gl.h"
#include <GLSLANG/ShaderLang.h>
#include "common/angleutils.h"
#include "libGLESv2/angletypes.h"
namespace rx
{
class Renderer;
}
namespace gl
{
class ResourceManager;
struct PackedVarying : public sh::Varying
{
unsigned int registerIndex; // Assigned during link
PackedVarying(const sh::Varying &varying)
: sh::Varying(varying),
registerIndex(GL_INVALID_INDEX)
{}
bool registerAssigned() const { return registerIndex != GL_INVALID_INDEX; }
void resetRegisterAssignment()
{
registerIndex = GL_INVALID_INDEX;
}
};
class Shader
{
friend class DynamicHLSL;
public:
Shader(ResourceManager *manager, const rx::Renderer *renderer, GLuint handle);
virtual ~Shader();
virtual GLenum getType() const = 0;
GLuint getHandle() const;
void deleteSource();
void setSource(GLsizei count, const char *const *string, const GLint *length);
int getInfoLogLength() const;
void getInfoLog(GLsizei bufSize, GLsizei *length, char *infoLog) const;
int getSourceLength() const;
void getSource(GLsizei bufSize, GLsizei *length, char *buffer) const;
int getTranslatedSourceLength() const;
void getTranslatedSource(GLsizei bufSize, GLsizei *length, char *buffer) const;
const std::vector<sh::Uniform> &getUniforms() const;
const std::vector<sh::InterfaceBlock> &getInterfaceBlocks() const;
std::vector<PackedVarying> &getVaryings();
virtual void compile() = 0;
virtual void uncompile();
bool isCompiled() const;
const std::string &getHLSL() const;
void addRef();
void release();
unsigned int getRefCount() const;
bool isFlaggedForDeletion() const;
void flagForDeletion();
int getShaderVersion() const;
void resetVaryingsRegisterAssignment();
static void releaseCompiler();
static ShShaderOutput getCompilerOutputType(GLenum shader);
unsigned int getUniformRegister(const std::string &uniformName) const;
unsigned int getInterfaceBlockRegister(const std::string &blockName) const;
bool usesDepthRange() const { return mUsesDepthRange; }
bool usesPointSize() const { return mUsesPointSize; }
rx::D3DWorkaroundType getD3DWorkarounds() const;
protected:
void parseVaryings(void *compiler);
void compileToHLSL(void *compiler);
void getSourceImpl(const std::string &source, GLsizei bufSize, GLsizei *length, char *buffer) const;
static bool compareVarying(const PackedVarying &x, const PackedVarying &y);
const rx::Renderer *const mRenderer;
std::vector<PackedVarying> mVaryings;
bool mUsesMultipleRenderTargets;
bool mUsesFragColor;
bool mUsesFragData;
bool mUsesFragCoord;
bool mUsesFrontFacing;
bool mUsesPointSize;
bool mUsesPointCoord;
bool mUsesDepthRange;
bool mUsesFragDepth;
int mShaderVersion;
bool mUsesDiscardRewriting;
bool mUsesNestedBreak;
static void *mFragmentCompiler;
static void *mVertexCompiler;
private:
DISALLOW_COPY_AND_ASSIGN(Shader);
void initializeCompiler();
const GLuint mHandle;
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
std::string mSource;
std::string mHlsl;
std::string mInfoLog;
std::vector<sh::Uniform> mActiveUniforms;
std::vector<sh::InterfaceBlock> mActiveInterfaceBlocks;
std::map<std::string, unsigned int> mUniformRegisterMap;
std::map<std::string, unsigned int> mInterfaceBlockRegisterMap;
ResourceManager *mResourceManager;
};
class VertexShader : public Shader
{
friend class DynamicHLSL;
public:
VertexShader(ResourceManager *manager, const rx::Renderer *renderer, GLuint handle);
~VertexShader();
virtual GLenum getType() const;
virtual void compile();
virtual void uncompile();
int getSemanticIndex(const std::string &attributeName);
const std::vector<sh::Attribute> &activeAttributes() const { return mActiveAttributes; }
private:
DISALLOW_COPY_AND_ASSIGN(VertexShader);
void parseAttributes();
std::vector<sh::Attribute> mActiveAttributes;
};
class FragmentShader : public Shader
{
public:
FragmentShader(ResourceManager *manager,const rx::Renderer *renderer, GLuint handle);
~FragmentShader();
virtual GLenum getType() const;
virtual void compile();
virtual void uncompile();
const std::vector<sh::Attribute> &getOutputVariables() const;
private:
DISALLOW_COPY_AND_ASSIGN(FragmentShader);
std::vector<sh::Attribute> mActiveOutputVariables;
};
}
#endif // LIBGLESV2_SHADER_H_