• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*-------------------------------------------------------------------------
2  * drawElements Quality Program Random Shader Generator
3  * ----------------------------------------------------
4  *
5  * Copyright 2014 The Android Open Source Project
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  *//*!
20  * \file
21  * \brief Random Shader Generator Tester.
22  *//*--------------------------------------------------------------------*/
23 
24 #include "rsgProgramGenerator.hpp"
25 #include "rsgProgramExecutor.hpp"
26 #include "tcuSurface.hpp"
27 #include "tcuImageIO.hpp"
28 #include "rsgUtils.hpp"
29 #include "deStringUtil.hpp"
30 
31 #include <iostream>
32 #include <string>
33 #include <cstdio>
34 
35 using std::string;
36 
runTest(deUint32 seed)37 void runTest (deUint32 seed)
38 {
39 	printf("Seed: %d\n", seed);
40 
41 	// Generate test program
42 	try
43 	{
44 		rsg::ProgramParameters programParams;
45 
46 		programParams.seed = seed;
47 		programParams.fragmentParameters.randomize			= true;
48 		programParams.fragmentParameters.maxStatementDepth	= 3;
49 
50 		rsg::Shader				vertexShader(rsg::Shader::TYPE_VERTEX);
51 		rsg::Shader				fragmentShader(rsg::Shader::TYPE_FRAGMENT);
52 
53 		rsg::ProgramGenerator generator;
54 		generator.generate(programParams, vertexShader, fragmentShader);
55 
56 		std::cout << "Vertex shader:\n--\n"		<< vertexShader.getSource()		<< "--\n";
57 		std::cout << "Fragment shader:\n--\n"	<< fragmentShader.getSource()	<< "--\n";
58 
59 		// Uniforms
60 		std::vector<const rsg::ShaderInput*>	uniforms;
61 		std::vector<rsg::VariableValue>			uniformValues;
62 		de::Random								rnd(seed);
63 		rsg::computeUnifiedUniforms(vertexShader, fragmentShader, uniforms);
64 		rsg::computeUniformValues(rnd, uniformValues, uniforms);
65 
66 		// Render image
67 		tcu::Surface			surface(64, 64);
68 		rsg::ProgramExecutor	executor(surface.getAccess(), 3, 5);
69 
70 		executor.execute(vertexShader, fragmentShader, uniformValues);
71 
72 		string fileName = string("test-") + de::toString(seed) + ".png";
73 		tcu::ImageIO::savePNG(surface.getAccess(), fileName.c_str());
74 		std::cout << fileName << " written\n";
75 	}
76 	catch (const std::exception& e)
77 	{
78 		printf("Failed: %s\n", e.what());
79 	}
80 }
81 
main(int argc,const char * const * argv)82 int main (int argc, const char* const* argv)
83 {
84 	DE_UNREF(argc && argv);
85 
86 	for (int seed = 0; seed < 10; seed++)
87 		runTest(seed);
88 
89 	return 0;
90 }
91