xref: /aosp_15_r20/external/deqp/external/openglcts/modules/common/glcShaderMacroTests.cpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 /*-------------------------------------------------------------------------
2  * OpenGL Conformance Test Suite
3  * -----------------------------
4  *
5  * Copyright (c) 2017 The Khronos Group Inc.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */ /*!
20  * \file
21  * \brief
22  */ /*-------------------------------------------------------------------*/
23 
24 #include "glcShaderMacroTests.hpp"
25 #include "deSharedPtr.hpp"
26 #include "glsShaderExecUtil.hpp"
27 #include "gluContextInfo.hpp"
28 #include "tcuTestLog.hpp"
29 
30 namespace glcts
31 {
32 
33 using tcu::TestLog;
34 using namespace deqp::gls::ShaderExecUtil;
35 
36 class ExecutorTestCase : public deqp::TestCase
37 {
38 public:
39     ExecutorTestCase(deqp::Context &context, const char *name, glu::ShaderType shaderType, const ShaderSpec &shaderSpec,
40                      int expectedOutput);
41     virtual ~ExecutorTestCase(void);
42     virtual tcu::TestNode::IterateResult iterate(void);
43 
44 protected:
45     glu::ShaderType m_shaderType;
46     ShaderSpec m_shaderSpec;
47     int m_expectedOutput;
48 };
49 
ExecutorTestCase(deqp::Context & context,const char * name,glu::ShaderType shaderType,const ShaderSpec & shaderSpec,int expectedOutput)50 ExecutorTestCase::ExecutorTestCase(deqp::Context &context, const char *name, glu::ShaderType shaderType,
51                                    const ShaderSpec &shaderSpec, int expectedOutput)
52     : deqp::TestCase(context, name, "")
53     , m_shaderType(shaderType)
54     , m_shaderSpec(shaderSpec)
55     , m_expectedOutput(expectedOutput)
56 {
57 }
58 
~ExecutorTestCase(void)59 ExecutorTestCase::~ExecutorTestCase(void)
60 {
61 }
62 
iterate(void)63 tcu::TestNode::IterateResult ExecutorTestCase::iterate(void)
64 {
65     de::SharedPtr<ShaderExecutor> executor(createExecutor(m_context.getRenderContext(), m_shaderType, m_shaderSpec));
66 
67     DE_ASSERT(executor.get());
68 
69     executor->log(m_context.getTestContext().getLog());
70 
71     if (!executor->isOk())
72         TCU_FAIL("Compilation failed");
73 
74     executor->useProgram();
75 
76     int result          = 0;
77     void *const outputs = &result;
78     executor->execute(1, DE_NULL, &outputs);
79 
80     if (m_expectedOutput == result)
81     {
82         m_testCtx.setTestResult(QP_TEST_RESULT_PASS, "Pass");
83         return tcu::TestNode::STOP;
84     }
85 
86     m_context.getTestContext().getLog() << tcu::TestLog::Message << "Expected: " << m_expectedOutput
87                                         << " but test returned: " << result << tcu::TestLog::EndMessage;
88     m_testCtx.setTestResult(QP_TEST_RESULT_FAIL, "Fail");
89 
90     return tcu::TestNode::STOP;
91 }
92 
ShaderMacroTests(deqp::Context & context)93 ShaderMacroTests::ShaderMacroTests(deqp::Context &context)
94     : TestCaseGroup(context, "shader_macros", "Shader Macro tests")
95 {
96 }
97 
~ShaderMacroTests()98 ShaderMacroTests::~ShaderMacroTests()
99 {
100 }
101 
init(void)102 void ShaderMacroTests::init(void)
103 {
104     const char *fragmentPrecisionShaderTemplate = "out0 = 0;\n"
105                                                   "#ifdef GL_FRAGMENT_PRECISION_HIGH\n"
106                                                   "out0 = 1;\n"
107                                                   "#endif\n";
108 
109     glu::ContextType contextType = m_context.getRenderContext().getType();
110 
111     ShaderSpec shaderSpec;
112     shaderSpec.version = glu::getContextTypeGLSLVersion(contextType);
113     shaderSpec.source  = fragmentPrecisionShaderTemplate;
114     shaderSpec.outputs.push_back(Symbol("out0", glu::VarType(glu::TYPE_INT, glu::PRECISION_HIGHP)));
115 
116     std::vector<glu::ShaderType> shaderTypes;
117     shaderTypes.push_back(glu::SHADERTYPE_VERTEX);
118     shaderTypes.push_back(glu::SHADERTYPE_FRAGMENT);
119 
120     if (glu::contextSupports(contextType, glu::ApiType::es(3, 2)))
121     {
122         shaderSpec.version = glu::GLSL_VERSION_320_ES;
123         shaderTypes.push_back(glu::SHADERTYPE_GEOMETRY);
124         shaderTypes.push_back(glu::SHADERTYPE_TESSELLATION_CONTROL);
125         shaderTypes.push_back(glu::SHADERTYPE_TESSELLATION_EVALUATION);
126     }
127     else if (glu::contextSupports(contextType, glu::ApiType::es(3, 1)))
128     {
129         shaderSpec.version = glu::GLSL_VERSION_310_ES;
130         shaderTypes.push_back(glu::SHADERTYPE_GEOMETRY);
131         shaderTypes.push_back(glu::SHADERTYPE_TESSELLATION_CONTROL);
132         shaderTypes.push_back(glu::SHADERTYPE_TESSELLATION_EVALUATION);
133     }
134 
135     for (std::size_t typeIndex = 0; typeIndex < shaderTypes.size(); ++typeIndex)
136     {
137         glu::ShaderType shaderType = shaderTypes[typeIndex];
138         std::string caseName("fragment_precision_high_");
139         caseName += getShaderTypeName(shaderType);
140         addChild(new ExecutorTestCase(m_context, caseName.c_str(), shaderType, shaderSpec, 1));
141     }
142 }
143 
144 } // namespace glcts
145