1 //
2 // Copyright 2018 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // OES_standard_derivatives_test.cpp:
7 // Test for OES_standard_derivatives
8 //
9
10 #include "tests/test_utils/ShaderExtensionTest.h"
11
12 using OESStandardDerivativesTest = sh::ShaderExtensionTest;
13
14 namespace
15 {
16 const char OESPragma[] = "#extension GL_OES_standard_derivatives : require\n";
17
18 // Shader calling dFdx()
19 const char ESSL100_DfdxShader[] =
20 R"(
21 precision mediump float;
22 varying float x;
23
24 void main()
25 {
26 gl_FragColor = vec4(dFdx(x));
27 })";
28
29 // Shader calling dFdy()
30 const char ESSL100_DfdyShader[] =
31 R"(
32 precision mediump float;
33 varying float x;
34
35 void main()
36 {
37 gl_FragColor = vec4(dFdy(x));
38 })";
39
40 // Shader calling fwidth()
41 const char ESSL100_FwidthShader[] =
42 R"(
43 precision mediump float;
44 varying float x;
45
46 void main()
47 {
48 gl_FragColor = vec4(fwidth(x));
49 })";
50
51 // Extension flag is required to compile properly. Expect failure when it is
52 // not present.
TEST_P(OESStandardDerivativesTest,CompileFailsWithoutExtension)53 TEST_P(OESStandardDerivativesTest, CompileFailsWithoutExtension)
54 {
55 mResources.OES_standard_derivatives = 0;
56 InitializeCompiler();
57 EXPECT_FALSE(TestShaderCompile(OESPragma));
58 }
59
60 // Extension directive is required to compile properly. Expect failure when
61 // it is not present.
TEST_P(OESStandardDerivativesTest,CompileFailsWithExtensionWithoutPragma)62 TEST_P(OESStandardDerivativesTest, CompileFailsWithExtensionWithoutPragma)
63 {
64 mResources.OES_standard_derivatives = 1;
65 InitializeCompiler();
66 EXPECT_FALSE(TestShaderCompile(""));
67 }
68
69 // With extension flag and extension directive, compiling succeeds.
70 // Also test that the extension directive state is reset correctly.
TEST_P(OESStandardDerivativesTest,CompileSucceedsWithExtensionAndPragma)71 TEST_P(OESStandardDerivativesTest, CompileSucceedsWithExtensionAndPragma)
72 {
73 mResources.OES_standard_derivatives = 1;
74 InitializeCompiler();
75 EXPECT_TRUE(TestShaderCompile(OESPragma));
76 // Test reset functionality.
77 EXPECT_FALSE(TestShaderCompile(""));
78 EXPECT_TRUE(TestShaderCompile(OESPragma));
79 }
80
81 // The SL #version 100 shaders that are correct work similarly
82 // in both GL2 and GL3, with and without the version string.
83 INSTANTIATE_TEST_SUITE_P(
84 CorrectESSL100Shaders,
85 OESStandardDerivativesTest,
86 Combine(Values(SH_GLES2_SPEC),
87 Values(sh::ESSLVersion100),
88 Values(ESSL100_DfdxShader, ESSL100_DfdyShader, ESSL100_FwidthShader)));
89
90 } // anonymous namespace
91