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
diff --git a/src/compiler/Initialize.cpp b/src/compiler/Initialize.cpp
index 3e5f264..4188316 100644
--- a/src/compiler/Initialize.cpp
+++ b/src/compiler/Initialize.cpp
@@ -519,18 +519,26 @@
// 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 @@
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 @@
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,
diff --git a/src/compiler/ShaderLang.cpp b/src/compiler/ShaderLang.cpp
index a11b663..6aefaaa 100644
--- a/src/compiler/ShaderLang.cpp
+++ b/src/compiler/ShaderLang.cpp
@@ -131,6 +131,12 @@
// 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;
diff --git a/src/libGLESv2/Shader.cpp b/src/libGLESv2/Shader.cpp
index 7ac7772..5451dd3 100644
--- a/src/libGLESv2/Shader.cpp
+++ b/src/libGLESv2/Shader.cpp
@@ -247,6 +247,11 @@
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);
diff --git a/src/libGLESv2/renderer/Renderer11.cpp b/src/libGLESv2/renderer/Renderer11.cpp
index 608a8ff..3420db8 100644
--- a/src/libGLESv2/renderer/Renderer11.cpp
+++ b/src/libGLESv2/renderer/Renderer11.cpp
@@ -2126,6 +2126,8 @@
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: