diff options
author | dyen <dyen@chromium.org> | 2015-02-12 14:27:43 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-12 22:28:49 +0000 |
commit | 0ff9e4405e9b91c0a2ca4a18a382ba6dd0d6f934 (patch) | |
tree | 1be7f8df87f1cd3de89bdaa27e2405858c77c3c6 /gpu/command_buffer/tests | |
parent | 5d118a6b1d6a6b5c7325a16c2f9ac6187cd5918d (diff) | |
download | chromium_src-0ff9e4405e9b91c0a2ca4a18a382ba6dd0d6f934.zip chromium_src-0ff9e4405e9b91c0a2ca4a18a382ba6dd0d6f934.tar.gz chromium_src-0ff9e4405e9b91c0a2ca4a18a382ba6dd0d6f934.tar.bz2 |
Shader compiles deferred until program link time after a cache miss.
Shader compiles are now deferred until glLinkProgram() or until an
status is queried from glGetShaderiv() which requires compilation
information.
Additionally, the shader cache is now checked first before the shader
gets compiled. That way, if the shader is in the cache it will skip
the compilation step altogether.
BUG=450690
TEST=trybots
Review URL: https://codereview.chromium.org/894973004
Cr-Commit-Position: refs/heads/master@{#316064}
Diffstat (limited to 'gpu/command_buffer/tests')
-rw-r--r-- | gpu/command_buffer/tests/gl_program_unittest.cc | 64 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_test_utils.cc | 18 | ||||
-rw-r--r-- | gpu/command_buffer/tests/gl_test_utils.h | 12 |
3 files changed, 90 insertions, 4 deletions
diff --git a/gpu/command_buffer/tests/gl_program_unittest.cc b/gpu/command_buffer/tests/gl_program_unittest.cc index 186b28b..d243994 100644 --- a/gpu/command_buffer/tests/gl_program_unittest.cc +++ b/gpu/command_buffer/tests/gl_program_unittest.cc @@ -4,7 +4,9 @@ #include <GLES2/gl2.h> #include <GLES2/gl2ext.h> +#include <GLES2/gl2extchromium.h> +#include "gpu/command_buffer/service/context_group.h" #include "gpu/command_buffer/tests/gl_manager.h" #include "gpu/command_buffer/tests/gl_test_utils.h" #include "testing/gmock/include/gmock/gmock.h" @@ -187,5 +189,67 @@ TEST_F(GLProgramTest, UniformsInCurrentProgram) { GLTestHelper::CheckGLError("no errors", __LINE__); } +TEST_F(GLProgramTest, DeferCompileWithExt) { + // This test must have extensions enabled. + gles2::ContextGroup* context_group = gl_.decoder()->GetContextGroup(); + gles2::FeatureInfo* feature_info = context_group->feature_info(); + const gles2::FeatureInfo::FeatureFlags& flags = feature_info->feature_flags(); + if (!flags.ext_frag_depth) + return; + + static const char* v_shdr_str = R"( + attribute vec4 vPosition; + void main() + { + gl_Position = vPosition; + } + )"; + static const char* f_shdr_str = R"( + #extension GL_EXT_frag_depth : enable + void main() + { + gl_FragDepthEXT = 1.0; + } + )"; + + // First compile and link to be shader compiles. + GLuint vs_good = GLTestHelper::CompileShader(GL_VERTEX_SHADER, v_shdr_str); + GLuint fs_good = GLTestHelper::CompileShader(GL_FRAGMENT_SHADER, f_shdr_str); + GLuint program_good = GLTestHelper::LinkProgram(vs_good, fs_good); + GLint linked_good = 0; + glGetProgramiv(program_good, GL_LINK_STATUS, &linked_good); + EXPECT_NE(0, linked_good); + + // Disable extension and be sure shader no longer compiles. + ASSERT_TRUE(glEnableFeatureCHROMIUM("webgl_enable_glsl_webgl_validation")); + GLuint vs_bad = GLTestHelper::CompileShader(GL_VERTEX_SHADER, v_shdr_str); + GLuint fs_bad = GLTestHelper::CompileShader(GL_FRAGMENT_SHADER, f_shdr_str); + GLuint program_bad = GLTestHelper::LinkProgram(vs_bad, fs_bad); + GLint linked_bad = 0; + glGetProgramiv(program_bad, GL_LINK_STATUS, &linked_bad); + EXPECT_EQ(0, linked_bad); + + // Relinking good compilations without extension disabled should still link. + GLuint program_defer_good = GLTestHelper::LinkProgram(vs_good, fs_good); + GLint linked_defer_good = 0; + glGetProgramiv(program_defer_good, GL_LINK_STATUS, &linked_defer_good); + EXPECT_NE(0, linked_defer_good); + + // linking bad compilations with extension enabled should still not link. + GLuint vs_bad2 = GLTestHelper::CompileShader(GL_VERTEX_SHADER, v_shdr_str); + GLuint fs_bad2 = GLTestHelper::CompileShader(GL_FRAGMENT_SHADER, f_shdr_str); + glRequestExtensionCHROMIUM("GL_EXT_frag_depth"); + GLuint program_bad2 = GLTestHelper::LinkProgram(vs_bad2, fs_bad2); + GLint linked_bad2 = 0; + glGetProgramiv(program_bad2, GL_LINK_STATUS, &linked_bad2); + EXPECT_EQ(0, linked_bad2); + + // Be sure extension was actually turned on by recompiling. + GLuint vs_good2 = GLTestHelper::LoadShader(GL_VERTEX_SHADER, v_shdr_str); + GLuint fs_good2 = GLTestHelper::LoadShader(GL_FRAGMENT_SHADER, f_shdr_str); + GLuint program_good2 = GLTestHelper::SetupProgram(vs_good2, fs_good2); + EXPECT_NE(0u, program_good2); +} + } // namespace gpu diff --git a/gpu/command_buffer/tests/gl_test_utils.cc b/gpu/command_buffer/tests/gl_test_utils.cc index d3272ca..7582a5d 100644 --- a/gpu/command_buffer/tests/gl_test_utils.cc +++ b/gpu/command_buffer/tests/gl_test_utils.cc @@ -31,12 +31,19 @@ bool GLTestHelper::CheckGLError(const char* msg, int line) { return success; } -GLuint GLTestHelper::LoadShader(GLenum type, const char* shaderSrc) { +GLuint GLTestHelper::CompileShader(GLenum type, const char* shaderSrc) { GLuint shader = glCreateShader(type); // Load the shader source glShaderSource(shader, 1, &shaderSrc, NULL); // Compile the shader glCompileShader(shader); + + return shader; +} + +GLuint GLTestHelper::LoadShader(GLenum type, const char* shaderSrc) { + GLuint shader = CompileShader(type, shaderSrc); + // Check the compile status GLint value = 0; glGetShaderiv(shader, GL_COMPILE_STATUS, &value); @@ -52,7 +59,7 @@ GLuint GLTestHelper::LoadShader(GLenum type, const char* shaderSrc) { return shader; } -GLuint GLTestHelper::SetupProgram( +GLuint GLTestHelper::LinkProgram( GLuint vertex_shader, GLuint fragment_shader) { // Create the program object GLuint program = glCreateProgram(); @@ -60,6 +67,13 @@ GLuint GLTestHelper::SetupProgram( glAttachShader(program, fragment_shader); // Link the program glLinkProgram(program); + + return program; +} + +GLuint GLTestHelper::SetupProgram( + GLuint vertex_shader, GLuint fragment_shader) { + GLuint program = LinkProgram(vertex_shader, fragment_shader); // Check the link status GLint linked = 0; glGetProgramiv(program, GL_LINK_STATUS, &linked); diff --git a/gpu/command_buffer/tests/gl_test_utils.h b/gpu/command_buffer/tests/gl_test_utils.h index 15a726e..802d54d 100644 --- a/gpu/command_buffer/tests/gl_test_utils.h +++ b/gpu/command_buffer/tests/gl_test_utils.h @@ -18,11 +18,19 @@ class GLTestHelper { static bool CheckGLError(const char* msg, int line); // Compiles a shader. - // Returns shader, 0 on failure.. + // Does not check for errors, always returns shader. + static GLuint CompileShader(GLenum type, const char* shaderSrc); + + // Compiles a shader and checks for compilation errors. + // Returns shader, 0 on failure. static GLuint LoadShader(GLenum type, const char* shaderSrc); // Attaches 2 shaders and links them to a program. - // Returns program, 0 on failure.. + // Does not check for errors, always returns program. + static GLuint LinkProgram(GLuint vertex_shader, GLuint fragment_shader); + + // Attaches 2 shaders, links them to a program, and checks for errors. + // Returns program, 0 on failure. static GLuint SetupProgram(GLuint vertex_shader, GLuint fragment_shader); // Compiles 2 shaders, attaches and links them to a program |