Home | History | Annotate | Download | only in glshared
      1 #ifndef _GLSDRAWTEST_HPP
      2 #define _GLSDRAWTEST_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 Draw tests
     24  *//*--------------------------------------------------------------------*/
     25 
     26 #include "tcuTestCase.hpp"
     27 #include "gluRenderContext.hpp"
     28 
     29 namespace sglr
     30 {
     31 
     32 class ReferenceContextBuffers;
     33 class ReferenceContext;
     34 class Context;
     35 
     36 } // sglr
     37 
     38 namespace deqp
     39 {
     40 namespace gls
     41 {
     42 
     43 class AttributePack;
     44 
     45 struct DrawTestSpec
     46 {
     47 	enum Target
     48 	{
     49 		TARGET_ELEMENT_ARRAY = 0,
     50 		TARGET_ARRAY,
     51 
     52 		TARGET_LAST
     53 	};
     54 
     55 	enum InputType
     56 	{
     57 		INPUTTYPE_FLOAT = 0,
     58 		INPUTTYPE_FIXED,
     59 		INPUTTYPE_DOUBLE,
     60 
     61 		INPUTTYPE_BYTE,
     62 		INPUTTYPE_SHORT,
     63 
     64 		INPUTTYPE_UNSIGNED_BYTE,
     65 		INPUTTYPE_UNSIGNED_SHORT,
     66 
     67 		INPUTTYPE_INT,
     68 		INPUTTYPE_UNSIGNED_INT,
     69 		INPUTTYPE_HALF,
     70 		INPUTTYPE_UNSIGNED_INT_2_10_10_10,
     71 		INPUTTYPE_INT_2_10_10_10,
     72 
     73 		INPUTTYPE_LAST
     74 	};
     75 
     76 	enum OutputType
     77 	{
     78 		OUTPUTTYPE_FLOAT = 0,
     79 		OUTPUTTYPE_VEC2,
     80 		OUTPUTTYPE_VEC3,
     81 		OUTPUTTYPE_VEC4,
     82 
     83 		OUTPUTTYPE_INT,
     84 		OUTPUTTYPE_UINT,
     85 
     86 		OUTPUTTYPE_IVEC2,
     87 		OUTPUTTYPE_IVEC3,
     88 		OUTPUTTYPE_IVEC4,
     89 
     90 		OUTPUTTYPE_UVEC2,
     91 		OUTPUTTYPE_UVEC3,
     92 		OUTPUTTYPE_UVEC4,
     93 
     94 		OUTPUTTYPE_LAST
     95 	};
     96 
     97 	enum Usage
     98 	{
     99 		USAGE_DYNAMIC_DRAW = 0,
    100 		USAGE_STATIC_DRAW,
    101 		USAGE_STREAM_DRAW,
    102 
    103 		USAGE_STREAM_READ,
    104 		USAGE_STREAM_COPY,
    105 
    106 		USAGE_STATIC_READ,
    107 		USAGE_STATIC_COPY,
    108 
    109 		USAGE_DYNAMIC_READ,
    110 		USAGE_DYNAMIC_COPY,
    111 
    112 		USAGE_LAST
    113 	};
    114 
    115 	enum Storage
    116 	{
    117 		STORAGE_USER = 0,
    118 		STORAGE_BUFFER,
    119 
    120 		STORAGE_LAST
    121 	};
    122 
    123 	enum Primitive
    124 	{
    125 		PRIMITIVE_POINTS = 0,
    126 		PRIMITIVE_TRIANGLES,
    127 		PRIMITIVE_TRIANGLE_FAN,
    128 		PRIMITIVE_TRIANGLE_STRIP,
    129 		PRIMITIVE_LINES,
    130 		PRIMITIVE_LINE_STRIP,
    131 		PRIMITIVE_LINE_LOOP,
    132 
    133 		PRIMITIVE_LINES_ADJACENCY,
    134 		PRIMITIVE_LINE_STRIP_ADJACENCY,
    135 		PRIMITIVE_TRIANGLES_ADJACENCY,
    136 		PRIMITIVE_TRIANGLE_STRIP_ADJACENCY,
    137 
    138 		PRIMITIVE_LAST
    139 	};
    140 
    141 	enum IndexType
    142 	{
    143 		INDEXTYPE_BYTE = 0,
    144 		INDEXTYPE_SHORT,
    145 		INDEXTYPE_INT,
    146 
    147 		INDEXTYPE_LAST
    148 	};
    149 
    150 	enum DrawMethod
    151 	{
    152 		DRAWMETHOD_DRAWARRAYS = 0,
    153 		DRAWMETHOD_DRAWARRAYS_INSTANCED,
    154 		DRAWMETHOD_DRAWARRAYS_INDIRECT,
    155 		DRAWMETHOD_DRAWELEMENTS,
    156 		DRAWMETHOD_DRAWELEMENTS_RANGED,
    157 		DRAWMETHOD_DRAWELEMENTS_INSTANCED,
    158 		DRAWMETHOD_DRAWELEMENTS_INDIRECT,
    159 		DRAWMETHOD_DRAWELEMENTS_BASEVERTEX,
    160 		DRAWMETHOD_DRAWELEMENTS_INSTANCED_BASEVERTEX,
    161 		DRAWMETHOD_DRAWELEMENTS_RANGED_BASEVERTEX,
    162 
    163 		DRAWMETHOD_LAST
    164 	};
    165 
    166 	enum CompatibilityTestType
    167 	{
    168 		COMPATIBILITY_NONE = 0,
    169 		COMPATIBILITY_UNALIGNED_OFFSET,
    170 		COMPATIBILITY_UNALIGNED_STRIDE,
    171 
    172 		COMPATIBILITY_LAST
    173 	};
    174 
    175 	static std::string			targetToString		(Target target);
    176 	static std::string			inputTypeToString	(InputType type);
    177 	static std::string			outputTypeToString	(OutputType type);
    178 	static std::string			usageTypeToString	(Usage usage);
    179 	static std::string			storageToString		(Storage storage);
    180 	static std::string			primitiveToString	(Primitive primitive);
    181 	static std::string			indexTypeToString	(IndexType type);
    182 	static std::string			drawMethodToString	(DrawMethod method);
    183 	static int					inputTypeSize		(InputType type);
    184 	static int					indexTypeSize		(IndexType type);
    185 
    186 	struct AttributeSpec
    187 	{
    188 		static AttributeSpec	createAttributeArray	(InputType inputType, OutputType outputType, Storage storage, Usage usage, int componentCount, int offset, int stride, bool normalize, int instanceDivisor);
    189 		static AttributeSpec	createDefaultAttribute	(InputType inputType, OutputType outputType, int componentCount);	//!< allowed inputType values: INPUTTYPE_INT, INPUTTYPE_UNSIGNED_INT, INPUTTYPE_FLOAT
    190 
    191 		InputType				inputType;
    192 		OutputType				outputType;
    193 		Storage					storage;
    194 		Usage					usage;
    195 		int 					componentCount;
    196 		int						offset;
    197 		int						stride;
    198 		bool					normalize;
    199 		int						instanceDivisor;				//!< used only if drawMethod = Draw*Instanced
    200 		bool					useDefaultAttribute;
    201 
    202 		bool					additionalPositionAttribute;	//!< treat this attribute as position attribute. Attribute at index 0 is alway treated as such. False by default
    203 		bool					bgraComponentOrder;				//!< component order of this attribute is bgra, valid only for 4-component targets. False by default.
    204 
    205 								AttributeSpec			(void);
    206 
    207 		int						hash					(void) const;
    208 		bool					valid					(glu::ApiType apiType) const;
    209 		bool					isBufferAligned			(void) const;
    210 		bool					isBufferStrideAligned	(void) const;
    211 	};
    212 
    213 	std::string 				getName				(void) const;
    214 	std::string					getDesc				(void) const;
    215 	std::string					getMultilineDesc	(void) const;
    216 
    217 	glu::ApiType				apiType;			//!< needed in spec validation
    218 	Primitive					primitive;
    219 	int							primitiveCount;		//!< number of primitives to draw (per instance)
    220 
    221 	DrawMethod					drawMethod;
    222 	IndexType					indexType;			//!< used only if drawMethod = DrawElements*
    223 	int							indexPointerOffset;	//!< used only if drawMethod = DrawElements*
    224 	Storage						indexStorage;		//!< used only if drawMethod = DrawElements*
    225 	int							first;				//!< used only if drawMethod = DrawArrays*
    226 	int							indexMin;			//!< used only if drawMethod = Draw*Ranged
    227 	int							indexMax;			//!< used only if drawMethod = Draw*Ranged
    228 	int							instanceCount;		//!< used only if drawMethod = Draw*Instanced or Draw*Indirect
    229 	int							indirectOffset;		//!< used only if drawMethod = Draw*Indirect
    230 	int							baseVertex;			//!< used only if drawMethod = DrawElementsIndirect or *BaseVertex
    231 
    232 	std::vector<AttributeSpec>	attribs;
    233 
    234 								DrawTestSpec		(void);
    235 
    236 	int							hash				(void) const;
    237 	bool						valid				(void) const;
    238 	CompatibilityTestType		isCompatibilityTest	(void) const;
    239 };
    240 
    241 class DrawTest : public tcu::TestCase
    242 {
    243 public:
    244 									DrawTest				(tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const DrawTestSpec& spec, const char* name, const char* desc);
    245 									DrawTest				(tcu::TestContext& testCtx, glu::RenderContext& renderCtx, const char* name, const char* desc);
    246 	virtual							~DrawTest				(void);
    247 
    248 	void							addIteration			(const DrawTestSpec& spec, const char* description = DE_NULL);
    249 
    250 private:
    251 	void							init					(void);
    252 	void							deinit					(void);
    253 	IterateResult					iterate					(void);
    254 
    255 	bool							compare					(gls::DrawTestSpec::Primitive primitiveType);
    256 	float							getCoordScale			(const DrawTestSpec& spec) const;
    257 	float							getColorScale			(const DrawTestSpec& spec) const;
    258 
    259 	glu::RenderContext&				m_renderCtx;
    260 
    261 	sglr::ReferenceContextBuffers*	m_refBuffers;
    262 	sglr::ReferenceContext*			m_refContext;
    263 	sglr::Context*					m_glesContext;
    264 
    265 	AttributePack*					m_glArrayPack;
    266 	AttributePack*					m_rrArrayPack;
    267 
    268 	int								m_maxDiffRed;
    269 	int								m_maxDiffGreen;
    270 	int								m_maxDiffBlue;
    271 
    272 	std::vector<DrawTestSpec>		m_specs;
    273 	std::vector<std::string>		m_iteration_descriptions;
    274 	int								m_iteration;
    275 	tcu::ResultCollector			m_result;
    276 };
    277 
    278 } // gls
    279 } // deqp
    280 
    281 #endif // _GLSDRAWTEST_HPP
    282