Merge "Allow alternative form for refract()." into nyc-dev am: f492a25
[platform/upstream/VK-GL-CTS.git] / modules / glshared / glsShaderExecUtil.hpp
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
53         Symbol (void) {}
54         Symbol (const std::string& name_, const glu::VarType& varType_) : name(name_), varType(varType_) {}
55 };
56
57 //! Complete shader specification.
58 struct ShaderSpec
59 {
60         glu::GLSLVersion                version;                                //!< Shader version.
61         std::vector<Symbol>             inputs;
62         std::vector<Symbol>             outputs;
63         std::string                             globalDeclarations;             //!< These are placed into global scope. Can contain uniform declarations for example.
64         std::string                             source;                                 //!< Source snippet to be executed.
65
66         ShaderSpec (void) : version(glu::GLSL_VERSION_300_ES) {}
67 };
68
69 //! Base class for shader executor.
70 class ShaderExecutor
71 {
72 public:
73         virtual                                         ~ShaderExecutor                 (void);
74
75         //! Check if executor can be used.
76         virtual bool                            isOk                                    (void) const = 0;
77
78         //! Log executor details (program etc.).
79         virtual void                            log                                             (tcu::TestLog& log) const = 0;
80
81         //! Get program.
82         virtual deUint32                        getProgram                              (void) const = 0;
83
84         //! Set this shader program current in context. Must be called before execute().
85         virtual void                            useProgram                              (void);
86
87         //! Execute active program. useProgram() must be called before this.
88         virtual void                            execute                                 (int numValues, const void* const* inputs, void* const* outputs) = 0;
89
90 protected:
91                                                                 ShaderExecutor                  (const glu::RenderContext& renderCtx, const ShaderSpec& shaderSpec);
92
93         const glu::RenderContext&       m_renderCtx;
94
95         std::vector<Symbol>                     m_inputs;
96         std::vector<Symbol>                     m_outputs;
97 };
98
99 inline tcu::TestLog& operator<< (tcu::TestLog& log, const ShaderExecutor* executor) { executor->log(log);       return log; }
100 inline tcu::TestLog& operator<< (tcu::TestLog& log, const ShaderExecutor& executor) { executor.log(log);        return log; }
101
102 ShaderExecutor* createExecutor (const glu::RenderContext& renderCtx, glu::ShaderType shaderType, const ShaderSpec& shaderSpec);
103
104 } // ShaderExecUtil
105 } // gls
106 } // deqp
107
108 #endif // _GLSSHADEREXECUTIL_HPP