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