Commit 419bfc91 by Corentin Wallez Committed by Commit Bot

On Desktop GL, require index-constant sampler array indexing

BUG=598924 Change-Id: If97dbaa782595997b815c70d14f079e0f0c3d82a Reviewed-on: https://chromium-review.googlesource.com/356710Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Corentin Wallez <cwallez@chromium.org>
parent 0b2cc797
...@@ -192,6 +192,23 @@ void TranslatorGLSL::writeExtensionBehavior(TIntermNode *root) ...@@ -192,6 +192,23 @@ void TranslatorGLSL::writeExtensionBehavior(TIntermNode *root)
sink << "#extension GL_ARB_explicit_attrib_location : require\n"; sink << "#extension GL_ARB_explicit_attrib_location : require\n";
} }
// Need to enable gpu_shader5 to have index constant sampler array indexing
if (getOutputType() != SH_ESSL_OUTPUT && getOutputType() < SH_GLSL_400_CORE_OUTPUT)
{
sink << "#extension GL_ARB_gpu_shader5 : ";
// Don't use "require" on WebGL 1 to avoid breaking WebGL on drivers that silently
// support index constant sampler array indexing, but don't have the extension.
if (getShaderVersion() >= 300)
{
sink << "require\n";
}
else
{
sink << "enable\n";
}
}
TExtensionGLSL extensionGLSL(getOutputType()); TExtensionGLSL extensionGLSL(getOutputType());
root->traverse(&extensionGLSL); root->traverse(&extensionGLSL);
......
...@@ -536,6 +536,17 @@ void GenerateCaps(const FunctionsGL *functions, gl::Caps *caps, gl::TextureCapsM ...@@ -536,6 +536,17 @@ void GenerateCaps(const FunctionsGL *functions, gl::Caps *caps, gl::TextureCapsM
LimitVersion(maxSupportedESVersion, gl::Version(2, 0)); LimitVersion(maxSupportedESVersion, gl::Version(2, 0));
} }
// Check if index constant sampler array indexing is supported
if (!functions->isAtLeastGL(gl::Version(4, 0)) &&
!functions->isAtLeastGLES(gl::Version(2, 0)) &&
!functions->hasExtension("GL_ARB_gpu_shader5"))
{
// This should also be required for ES2 but there are some driver support index constant
// sampler array indexing without meeting the requirements above. Don't limit their ES
// version as it would break WebGL for some users.
LimitVersion(maxSupportedESVersion, gl::Version(2, 0));
}
// Check if sampler objects are supported // Check if sampler objects are supported
if (!functions->isAtLeastGL(gl::Version(3, 3)) && if (!functions->isAtLeastGL(gl::Version(3, 3)) &&
!functions->hasGLExtension("GL_ARB_sampler_objects") && !functions->hasGLExtension("GL_ARB_sampler_objects") &&
......
...@@ -1821,6 +1821,50 @@ TEST_P(GLSLTest_ES3, InitGlobalArrayWithArrayIndexing) ...@@ -1821,6 +1821,50 @@ TEST_P(GLSLTest_ES3, InitGlobalArrayWithArrayIndexing)
EXPECT_NE(0u, program); EXPECT_NE(0u, program);
} }
// Test that index-constant sampler array indexing is supported.
TEST_P(GLSLTest, IndexConstantSamplerArrayIndexing)
{
if (IsD3D11_FL93()) {
std::cout << "Test skipped on D3D11 FL 9.3." << std::endl;
return;
}
const std::string vertexShaderSource =
"attribute vec4 vPosition;\n"
"void main()\n"
"{\n"
" gl_Position = vPosition;\n"
"}";
const std::string fragmentShaderSource =
"precision mediump float;\n"
"uniform sampler2D uni[2];\n"
"\n"
"float zero(int x)\n"
"{\n"
" return float(x) - float(x);\n"
"}\n"
"\n"
"void main()\n"
"{\n"
" vec4 c = vec4(0,0,0,0);\n"
" for (int ii = 1; ii < 3; ++ii) {\n"
" if (c.x > 255.0) {\n"
" c.x = 255.0 + zero(ii);\n"
" break;\n"
" }\n"
// Index the sampler array with a predictable loop index (index-constant) as opposed to
// a true constant. This is valid in OpenGL ES but isn't in many Desktop OpenGL versions,
// without an extension.
" c += texture2D(uni[ii - 1], vec2(0.5, 0.5));\n"
" }\n"
" gl_FragColor = c;\n"
"}";
GLuint program = CompileProgram(vertexShaderSource, fragmentShaderSource);
EXPECT_NE(0u, program);
}
// Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against. // Use this to select which configurations (e.g. which renderer, which GLES major version) these tests should be run against.
ANGLE_INSTANTIATE_TEST(GLSLTest, ANGLE_INSTANTIATE_TEST(GLSLTest,
ES2_D3D9(), ES2_D3D9(),
......
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