1 /*------------------------------------------------------------------------
2 * Copyright (c) 2015 The Khronos Group Inc.
3 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and/or associated documentation files (the
7 * "Materials"), to deal in the Materials without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Materials, and to
10 * permit persons to whom the Materials are furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice(s) and this permission notice shall be included
14 * in all copies or substantial portions of the Materials.
16 * The Materials are Confidential Information as defined by the
17 * Khronos Membership Agreement until designated non-confidential by Khronos,
18 * at which point this condition clause shall be removed.
20 * THE MATERIALS ARE PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 * MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.
30 * \brief Vulkan ShaderRenderCase
31 *//*--------------------------------------------------------------------*/
33 #ifndef _VKTSHADERRENDERCASE_HPP
35 #include "tcuTexture.hpp"
37 #include "vktTestCase.hpp"
38 #include "vkPrograms.hpp"
42 namespace shaderrendercase
53 class ShaderEvalContext
66 const tcu::Texture2D* tex2D;
67 const tcu::TextureCube* texCube;
68 const tcu::Texture2DArray* tex2DArray;
69 const tcu::Texture3D* tex3D;
71 inline ShaderSampler (void)
80 ShaderEvalContext (const QuadGrid& quadGrid);
81 ~ShaderEvalContext (void);
83 void reset (float sx, float sy);
88 tcu::Vec4 constCoords;
90 tcu::Vec4 in[MAX_USER_ATTRIBS];
91 ShaderSampler textures[MAX_TEXTURES];
98 inline void discard (void) { isDiscarded = true; }
99 tcu::Vec4 texture2D (int unitNdx, const tcu::Vec2& coords);
102 const QuadGrid& quadGrid;
106 typedef void (*ShaderEvalFunc) (ShaderEvalContext& c);
108 inline void evalCoordsPassthroughX (ShaderEvalContext& c) { c.color.x() = c.coords.x(); }
109 inline void evalCoordsPassthroughXY (ShaderEvalContext& c) { c.color.xy() = c.coords.swizzle(0,1); }
110 inline void evalCoordsPassthroughXYZ (ShaderEvalContext& c) { c.color.xyz() = c.coords.swizzle(0,1,2); }
111 inline void evalCoordsPassthrough (ShaderEvalContext& c) { c.color = c.coords; }
112 inline void evalCoordsSwizzleWZYX (ShaderEvalContext& c) { c.color = c.coords.swizzle(3,2,1,0); }
115 // Either inherit a class with overridden evaluate() or just pass in an evalFunc.
117 class ShaderEvaluator
120 ShaderEvaluator (void);
121 ShaderEvaluator (ShaderEvalFunc evalFunc);
122 virtual ~ShaderEvaluator (void);
124 virtual void evaluate (ShaderEvalContext& ctx);
127 ShaderEvaluator (const ShaderEvaluator&); // not allowed!
128 ShaderEvaluator& operator= (const ShaderEvaluator&); // not allowed!
130 ShaderEvalFunc m_evalFunc;
134 class ShaderRenderCase : public vkt::TestCase
137 ShaderRenderCase (tcu::TestContext& testCtx,
138 const std::string& name,
139 const std::string& description,
141 ShaderEvalFunc evalFunc);
142 ShaderRenderCase (tcu::TestContext& testCtx,
143 const std::string& name,
144 const std::string& description,
146 ShaderEvaluator* evaulator);
148 virtual ~ShaderRenderCase (void);
149 virtual void initPrograms (vk::ProgramCollection<glu::ProgramSources>& programCollection) const;
150 virtual TestInstance* createInstance (Context& context) const;
154 ShaderEvaluator* m_evaluator;
157 // ShaderRenderCaseInstance.
159 class ShaderRenderCaseInstance : public vkt::TestInstance
162 ShaderRenderCaseInstance (Context& context, bool isVertexCase, ShaderEvaluator& evaluator);
163 virtual ~ShaderRenderCaseInstance (void);
164 virtual tcu::TestStatus iterate (void);
168 ShaderEvaluator& m_evaluator;
172 } // shaderrendercase
175 #endif // _VKTSHADERRENDERCASE_HPP