xref: /aosp_15_r20/external/deqp/modules/gles3/functional/es3fFboTestUtil.hpp (revision 35238bce31c2a825756842865a792f8cf7f89930)
1 #ifndef _ES3FFBOTESTUTIL_HPP
2 #define _ES3FFBOTESTUTIL_HPP
3 /*-------------------------------------------------------------------------
4  * drawElements Quality Program OpenGL ES 3.0 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 FBO test utilities.
24  *//*--------------------------------------------------------------------*/
25 
26 #include "tcuDefs.hpp"
27 #include "sglrContext.hpp"
28 #include "gluShaderUtil.hpp"
29 #include "tcuTexture.hpp"
30 #include "tcuMatrix.hpp"
31 #include "tcuRenderTarget.hpp"
32 
33 #include <vector>
34 
35 namespace deqp
36 {
37 namespace gles3
38 {
39 namespace Functional
40 {
41 namespace FboTestUtil
42 {
43 
44 // \todo [2012-04-29 pyry] Clean up and name as SglrUtil
45 
46 // Helper class for constructing DataType vectors.
47 struct DataTypes
48 {
49     std::vector<glu::DataType> vec;
operator <<deqp::gles3::Functional::FboTestUtil::DataTypes50     DataTypes &operator<<(glu::DataType type)
51     {
52         vec.push_back(type);
53         return *this;
54     }
55 };
56 
57 // Shaders.
58 
59 class FlatColorShader : public sglr::ShaderProgram
60 {
61 public:
62     FlatColorShader(glu::DataType outputType);
~FlatColorShader(void)63     ~FlatColorShader(void)
64     {
65     }
66 
67     void setColor(sglr::Context &context, uint32_t program, const tcu::Vec4 &color);
68 
69     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const;
70     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
71                         const rr::FragmentShadingContext &context) const;
72 
73 private:
74     const glu::DataType m_outputType;
75 };
76 
77 class GradientShader : public sglr::ShaderProgram
78 {
79 public:
80     GradientShader(glu::DataType outputType);
~GradientShader(void)81     ~GradientShader(void)
82     {
83     }
84 
85     void setGradient(sglr::Context &context, uint32_t program, const tcu::Vec4 &gradientMin,
86                      const tcu::Vec4 &gradientMax);
87 
88     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const;
89     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
90                         const rr::FragmentShadingContext &context) const;
91 
92 private:
93     const glu::DataType m_outputType;
94 };
95 
96 class Texture2DShader : public sglr::ShaderProgram
97 {
98 public:
99     Texture2DShader(const DataTypes &samplerTypes, glu::DataType outputType,
100                     const tcu::Vec4 &outScale = tcu::Vec4(1.0f), const tcu::Vec4 &outBias = tcu::Vec4(0.0f));
~Texture2DShader(void)101     ~Texture2DShader(void)
102     {
103     }
104 
105     void setUnit(int samplerNdx, int unitNdx);
106     void setTexScaleBias(int samplerNdx, const tcu::Vec4 &scale, const tcu::Vec4 &bias);
107     void setOutScaleBias(const tcu::Vec4 &scale, const tcu::Vec4 &bias);
108 
109     void setUniforms(sglr::Context &context, uint32_t program) const;
110 
111     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const;
112     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
113                         const rr::FragmentShadingContext &context) const;
114 
115 private:
116     struct Input
117     {
118         int unitNdx;
119         tcu::Vec4 scale;
120         tcu::Vec4 bias;
121     };
122 
123     std::vector<Input> m_inputs;
124     tcu::Vec4 m_outScale;
125     tcu::Vec4 m_outBias;
126 
127     const glu::DataType m_outputType;
128 };
129 
130 class TextureCubeShader : public sglr::ShaderProgram
131 {
132 public:
133     TextureCubeShader(glu::DataType samplerType, glu::DataType outputType);
~TextureCubeShader(void)134     ~TextureCubeShader(void)
135     {
136     }
137 
138     void setFace(tcu::CubeFace face);
139     void setTexScaleBias(const tcu::Vec4 &scale, const tcu::Vec4 &bias);
140 
141     void setUniforms(sglr::Context &context, uint32_t program) const;
142 
143     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const;
144     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
145                         const rr::FragmentShadingContext &context) const;
146 
147 private:
148     tcu::Mat3 m_coordMat;
149     tcu::Vec4 m_texScale;
150     tcu::Vec4 m_texBias;
151 
152     const glu::DataType m_outputType;
153 };
154 
155 class Texture2DArrayShader : public sglr::ShaderProgram
156 {
157 public:
158     Texture2DArrayShader(glu::DataType samplerType, glu::DataType outputType);
~Texture2DArrayShader(void)159     ~Texture2DArrayShader(void)
160     {
161     }
162 
163     void setLayer(int layer);
164     void setTexScaleBias(const tcu::Vec4 &scale, const tcu::Vec4 &bias);
165 
166     void setUniforms(sglr::Context &context, uint32_t program) const;
167 
168     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const;
169     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
170                         const rr::FragmentShadingContext &context) const;
171 
172 private:
173     tcu::Vec4 m_texScale;
174     tcu::Vec4 m_texBias;
175     int m_layer;
176 
177     const glu::DataType m_outputType;
178 };
179 
180 class Texture3DShader : public sglr::ShaderProgram
181 {
182 public:
183     Texture3DShader(glu::DataType samplerType, glu::DataType outputType);
~Texture3DShader(void)184     ~Texture3DShader(void)
185     {
186     }
187 
188     void setDepth(float r);
189     void setTexScaleBias(const tcu::Vec4 &scale, const tcu::Vec4 &bias);
190 
191     void setUniforms(sglr::Context &context, uint32_t program) const;
192 
193     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const;
194     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
195                         const rr::FragmentShadingContext &context) const;
196 
197 private:
198     tcu::Vec4 m_texScale;
199     tcu::Vec4 m_texBias;
200     float m_depth;
201 
202     const glu::DataType m_outputType;
203 };
204 
205 class DepthGradientShader : public sglr::ShaderProgram
206 {
207 public:
208     DepthGradientShader(glu::DataType outputType);
~DepthGradientShader(void)209     ~DepthGradientShader(void)
210     {
211     }
212 
213     void setUniforms(sglr::Context &context, uint32_t program, const float gradientMin, const float gradientMax,
214                      const tcu::Vec4 &color);
215 
216     void shadeVertices(const rr::VertexAttrib *inputs, rr::VertexPacket *const *packets, const int numPackets) const;
217     void shadeFragments(rr::FragmentPacket *packets, const int numPackets,
218                         const rr::FragmentShadingContext &context) const;
219 
220 private:
221     const glu::DataType m_outputType;
222     const sglr::UniformSlot &u_minGradient;
223     const sglr::UniformSlot &u_maxGradient;
224     const sglr::UniformSlot &u_color;
225 };
226 
227 // Framebuffer incomplete exception.
228 class FboIncompleteException : public tcu::TestError
229 {
230 public:
231     FboIncompleteException(uint32_t reason, const char *file, int line);
~FboIncompleteException(void)232     virtual ~FboIncompleteException(void) throw()
233     {
234     }
235 
getReason(void) const236     uint32_t getReason(void) const
237     {
238         return m_reason;
239     }
240 
241 private:
242     uint32_t m_reason;
243 };
244 
245 // Utility functions.
246 
247 glu::DataType getFragmentOutputType(const tcu::TextureFormat &format);
248 tcu::TextureFormat getFramebufferReadFormat(const tcu::TextureFormat &format);
249 
250 const char *getFormatName(uint32_t format);
251 
252 void clearColorBuffer(sglr::Context &ctx, const tcu::TextureFormat &format, const tcu::Vec4 &value);
253 void readPixels(sglr::Context &ctx, tcu::Surface &dst, int x, int y, int width, int height,
254                 const tcu::TextureFormat &format, const tcu::Vec4 &scale, const tcu::Vec4 &bias);
255 
256 tcu::RGBA getFormatThreshold(const tcu::TextureFormat &format);
257 tcu::RGBA getFormatThreshold(const uint32_t glFormat);
258 
259 tcu::RGBA getToSRGBConversionThreshold(const tcu::TextureFormat &src, const tcu::TextureFormat &dst);
260 
261 } // namespace FboTestUtil
262 } // namespace Functional
263 } // namespace gles3
264 } // namespace deqp
265 
266 #endif // _ES3FFBOTESTUTIL_HPP
267