xref: /aosp_15_r20/external/deqp/modules/glshared/glsShaderExecUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _GLSSHADEREXECUTIL_HPP
2 #define _GLSSHADEREXECUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program OpenGL (ES) Module
5  * -----------------------------------------------
6  *
7  * Copyright 2014 The Android Open Source Project
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  *//*!
22  * \file
23  * \brief Shader execution utilities.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "gluVarType.hpp"
28 #include "gluShaderUtil.hpp"
29 
30 namespace tcu
31 {
32 class TestLog;
33 }
34 
35 namespace glu
36 {
37 class RenderContext;
38 }
39 
40 namespace deqp
41 {
42 namespace gls
43 {
44 namespace ShaderExecUtil
45 {
46 
47 //! Shader input / output variable declaration.
48 struct Symbol
49 {
50     std::string name;     //!< Symbol name.
51     glu::VarType varType; //!< Symbol type.
52 
Symboldeqp::gls::ShaderExecUtil::Symbol53     Symbol(void)
54     {
55     }
Symboldeqp::gls::ShaderExecUtil::Symbol56     Symbol(const std::string &name_, const glu::VarType &varType_) : name(name_), varType(varType_)
57     {
58     }
59 };
60 
61 //! Complete shader specification.
62 struct ShaderSpec
63 {
64     glu::GLSLVersion version; //!< Shader version.
65     std::vector<Symbol> inputs;
66     std::vector<Symbol> outputs;
67     std::string
68         globalDeclarations; //!< These are placed into global scope. Can contain uniform declarations for example.
69     std::string source;     //!< Source snippet to be executed.
70 
ShaderSpecdeqp::gls::ShaderExecUtil::ShaderSpec71     ShaderSpec(void) : version(glu::GLSL_VERSION_300_ES)
72     {
73     }
74 };
75 
76 //! Base class for shader executor.
77 class ShaderExecutor
78 {
79 public:
80     virtual ~ShaderExecutor(void);
81 
82     //! Check if executor can be used.
83     virtual bool isOk(void) const = 0;
84 
85     //! Log executor details (program etc.).
86     virtual void log(tcu::TestLog &log) const = 0;
87 
88     //! Get program.
89     virtual uint32_t getProgram(void) const = 0;
90 
91     //! Set this shader program current in context. Must be called before execute().
92     virtual void useProgram(void);
93 
94     //! Execute active program. useProgram() must be called before this.
95     virtual void execute(int numValues, const void *const *inputs, void *const *outputs) = 0;
96 
97 protected:
98     ShaderExecutor(const glu::RenderContext &renderCtx, const ShaderSpec &shaderSpec);
99 
100     const glu::RenderContext &m_renderCtx;
101 
102     std::vector<Symbol> m_inputs;
103     std::vector<Symbol> m_outputs;
104 };
105 
operator <<(tcu::TestLog & log,const ShaderExecutor * executor)106 inline tcu::TestLog &operator<<(tcu::TestLog &log, const ShaderExecutor *executor)
107 {
108     executor->log(log);
109     return log;
110 }
operator <<(tcu::TestLog & log,const ShaderExecutor & executor)111 inline tcu::TestLog &operator<<(tcu::TestLog &log, const ShaderExecutor &executor)
112 {
113     executor.log(log);
114     return log;
115 }
116 
117 bool executorSupported(glu::ShaderType shaderType);
118 ShaderExecutor *createExecutor(const glu::RenderContext &renderCtx, glu::ShaderType shaderType,
119                                const ShaderSpec &shaderSpec);
120 
121 } // namespace ShaderExecUtil
122 } // namespace gls
123 } // namespace deqp
124 
125 #endif // _GLSSHADEREXECUTIL_HPP
126