Add new GLSL ES 3.0 built-in constants and split off 1.0 ones.

TRAC #22863 Signed-off-by: Jamie Madill Signed-off-by: Shannon Woods Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2274 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent c6ac65f6
......@@ -218,6 +218,12 @@ typedef struct
// Default is 0.
int FragmentPrecisionHigh;
// GLSL ES 3.0 constants.
int MaxVertexOutputVectors;
int MaxFragmentInputVectors;
int MinProgramTexelOffset;
int MaxProgramTexelOffset;
// Name Hashing.
// Set a 64 bit hash function to enable user-defined name hashing.
// Default is NULL.
......
......@@ -519,18 +519,26 @@ static TString DefaultPrecisionFragment()
// Implementation dependent built-in constants.
//
//============================================================================
static TString BuiltInConstants(ShShaderSpec spec, const ShBuiltInResources &resources, const TExtensionBehavior& extensionBehavior)
static TString BuiltInConstants(const ShBuiltInResources &resources)
{
TStringStream s;
s << "const int gl_MaxVertexAttribs = " << resources.MaxVertexAttribs << ";";
s << "const int gl_MaxVertexUniformVectors = " << resources.MaxVertexUniformVectors << ";";
s << "const mediump int gl_MaxVertexAttribs = " << resources.MaxVertexAttribs << ";";
s << "const mediump int gl_MaxVertexUniformVectors = " << resources.MaxVertexUniformVectors << ";";
s << "const int gl_MaxVaryingVectors = " << resources.MaxVaryingVectors << ";";
s << "const int gl_MaxVertexTextureImageUnits = " << resources.MaxVertexTextureImageUnits << ";";
s << "const int gl_MaxCombinedTextureImageUnits = " << resources.MaxCombinedTextureImageUnits << ";";
s << "const int gl_MaxTextureImageUnits = " << resources.MaxTextureImageUnits << ";";
s << "const int gl_MaxFragmentUniformVectors = " << resources.MaxFragmentUniformVectors << ";";
s << "const mediump int gl_MaxVertexTextureImageUnits = " << resources.MaxVertexTextureImageUnits << ";";
s << "const mediump int gl_MaxCombinedTextureImageUnits = " << resources.MaxCombinedTextureImageUnits << ";";
s << "const mediump int gl_MaxTextureImageUnits = " << resources.MaxTextureImageUnits << ";";
s << "const mediump int gl_MaxFragmentUniformVectors = " << resources.MaxFragmentUniformVectors << ";";
return s.str();
}
static TString BuiltInConstants1_0(ShShaderSpec spec, const ShBuiltInResources &resources, const TExtensionBehavior& extensionBehavior)
{
TStringStream s;
s << "const mediump int gl_MaxVaryingVectors = " << resources.MaxVaryingVectors << ";";
if (spec != SH_CSS_SHADERS_SPEC)
{
......@@ -538,12 +546,24 @@ static TString BuiltInConstants(ShShaderSpec spec, const ShBuiltInResources &res
const bool usingMRTExtension = (iter != extensionBehavior.end() && (iter->second == EBhEnable || iter->second == EBhRequire));
const int maxDrawBuffers = (usingMRTExtension ? resources.MaxDrawBuffers : 1);
s << "const int gl_MaxDrawBuffers = " << maxDrawBuffers << ";";
s << "const mediump int gl_MaxDrawBuffers = " << maxDrawBuffers << ";";
}
return s.str();
}
static TString BuiltInConstants3_0(const ShBuiltInResources &resources)
{
TStringStream s;
s << "const mediump int gl_MaxVertexOutputVectors = " << resources.MaxVertexOutputVectors << ";";
s << "const mediump int gl_MaxFragmentInputVectors = " << resources.MaxFragmentInputVectors << ";";
s << "const mediump int gl_MinProgramTexelOffset = " << resources.MinProgramTexelOffset << ";";
s << "const mediump int gl_MaxProgramTexelOffset = " << resources.MaxProgramTexelOffset << ";";
return s.str();
}
void TBuiltIns::initialize(ShShaderType type, ShShaderSpec spec,
const ShBuiltInResources& resources,
const TExtensionBehavior& extensionBehavior)
......@@ -571,7 +591,9 @@ void TBuiltIns::initialize(ShShaderType type, ShShaderSpec spec,
default: assert(false && "Language not supported");
}
commonBuiltIns.push_back(BuiltInConstants(spec, resources, extensionBehavior));
commonBuiltIns.push_back(BuiltInConstants(resources));
essl1BuiltIns.push_back(BuiltInConstants1_0(spec, resources, extensionBehavior));
essl3BuiltIns.push_back(BuiltInConstants3_0(resources));
}
void IdentifyBuiltIns(ShShaderType type, ShShaderSpec spec,
......
......@@ -131,6 +131,12 @@ void ShInitBuiltInResources(ShBuiltInResources* resources)
// Disable highp precision in fragment shader by default.
resources->FragmentPrecisionHigh = 0;
// GLSL ES 3.0 constants.
resources->MaxVertexOutputVectors = 16;
resources->MaxFragmentInputVectors = 15;
resources->MinProgramTexelOffset = -8;
resources->MaxProgramTexelOffset = 7;
// Disable name hashing by default.
resources->HashFunction = NULL;
......
......@@ -247,6 +247,11 @@ void Shader::initializeCompiler()
resources.EXT_draw_buffers = mRenderer->getMaxRenderTargets() > 1;
// resources.OES_EGL_image_external = mRenderer->getShareHandleSupport() ? 1 : 0; // TODO: commented out until the extension is actually supported.
resources.FragmentPrecisionHigh = 1; // Shader Model 2+ always supports FP24 (s16e7) which corresponds to highp
// GLSL ES 3.0 constants
resources.MaxVertexOutputVectors = mRenderer->getMaxVaryingVectors();
resources.MaxFragmentInputVectors = mRenderer->getMaxVaryingVectors();
resources.MinProgramTexelOffset = -8; // D3D10_COMMONSHADER_TEXEL_OFFSET_MAX_NEGATIVE
resources.MaxProgramTexelOffset = 7; // D3D10_COMMONSHADER_TEXEL_OFFSET_MAX_POSITIVE
mFragmentCompiler = ShConstructCompiler(SH_FRAGMENT_SHADER, SH_GLES2_SPEC, hlslVersion, &resources);
mVertexCompiler = ShConstructCompiler(SH_VERTEX_SHADER, SH_GLES2_SPEC, hlslVersion, &resources);
......
......@@ -2126,6 +2126,8 @@ unsigned int Renderer11::getMaxFragmentUniformVectors() const
unsigned int Renderer11::getMaxVaryingVectors() const
{
META_ASSERT(gl::IMPLEMENTATION_MAX_VARYING_VECTORS == D3D11_VS_OUTPUT_REGISTER_COUNT);
META_ASSERT(D3D11_VS_OUTPUT_REGISTER_COUNT <= D3D11_PS_INPUT_REGISTER_COUNT);
META_ASSERT(D3D10_VS_OUTPUT_REGISTER_COUNT <= D3D10_PS_INPUT_REGISTER_COUNT);
switch (mFeatureLevel)
{
case D3D_FEATURE_LEVEL_11_0:
......
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