13c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#ifndef _RSGSHADER_HPP 23c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#define _RSGSHADER_HPP 33c827367444ee418f129b2c238299f49d3264554Jarkko Poyry/*------------------------------------------------------------------------- 43c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * drawElements Quality Program Random Shader Generator 53c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * ---------------------------------------------------- 63c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 73c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Copyright 2014 The Android Open Source Project 83c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 93c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Licensed under the Apache License, Version 2.0 (the "License"); 103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * you may not use this file except in compliance with the License. 113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * You may obtain a copy of the License at 123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * http://www.apache.org/licenses/LICENSE-2.0 143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * Unless required by applicable law or agreed to in writing, software 163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * distributed under the License is distributed on an "AS IS" BASIS, 173c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * See the License for the specific language governing permissions and 193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * limitations under the License. 203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * 213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*! 223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \file 233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry * \brief Shader Class. 243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry *//*--------------------------------------------------------------------*/ 253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgDefs.hpp" 273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgVariable.hpp" 283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgStatement.hpp" 293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgVariableManager.hpp" 303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgToken.hpp" 313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include "rsgExecutionContext.hpp" 323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <vector> 343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#include <string> 353c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 363c827367444ee418f129b2c238299f49d3264554Jarkko Poyrynamespace rsg 373c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 383c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 393c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Function 403c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 413c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 423c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Function (void); 433c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Function (const char* name); 443c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~Function (void); 453c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 463c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const VariableType& getReturnType (void) const { return m_returnType; } 473c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void setReturnType (const VariableType& type) { m_returnType = type; } 483c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 493c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void addParameter (Variable* variable); 503c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 513c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BlockStatement& getBody (void) { return m_functionBlock; } 523c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const BlockStatement& getBody (void) const { return m_functionBlock; } 533c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 543c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void tokenize (GeneratorState& state, TokenStream& stream) const; 553c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 563c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 573c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string m_name; 583c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Variable*> m_parameters; 593c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableType m_returnType; 603c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 613c827367444ee418f129b2c238299f49d3264554Jarkko Poyry BlockStatement m_functionBlock; 623c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 633c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 643c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass ShaderInput 653c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 663c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 673c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ShaderInput (const Variable* variable, ConstValueRangeAccess valueRange); 683c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~ShaderInput (void) {} 693c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 703c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Variable* getVariable (void) const { return m_variable; } 713c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ConstValueRangeAccess getValueRange (void) const { return ConstValueRangeAccess(m_variable->getType(), &m_min[0], &m_max[0]); } 723c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ValueRangeAccess getValueRange (void) { return ValueRangeAccess(m_variable->getType(), &m_min[0], &m_max[0]); } 733c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 743c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 753c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const Variable* m_variable; 763c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Scalar> m_min; 773c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Scalar> m_max; 783c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 793c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 803c827367444ee418f129b2c238299f49d3264554Jarkko Poyryclass Shader 813c827367444ee418f129b2c238299f49d3264554Jarkko Poyry{ 823c827367444ee418f129b2c238299f49d3264554Jarkko Poyrypublic: 833c827367444ee418f129b2c238299f49d3264554Jarkko Poyry enum Type 843c827367444ee418f129b2c238299f49d3264554Jarkko Poyry { 853c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_VERTEX = 0, 863c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_FRAGMENT, 873c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 883c827367444ee418f129b2c238299f49d3264554Jarkko Poyry TYPE_LAST 893c827367444ee418f129b2c238299f49d3264554Jarkko Poyry }; 903c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 913c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Shader (Type type); 923c827367444ee418f129b2c238299f49d3264554Jarkko Poyry ~Shader (void); 933c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 943c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Type getType (void) const { return m_type; } 953c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const char* getSource (void) const { return m_source.c_str(); } 963c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 973c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void execute (ExecutionContext& execCtx) const; 983c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 993c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // For generator implementation only 1003c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Function& getMain (void) { return m_mainFunction; } 1013c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Function& allocateFunction (void); 1023c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1033c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableScope& getGlobalScope (void) { return m_globalScope; } 1043c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Statement*>& getGlobalStatements (void) { return m_globalStatements; } 1053c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1063c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void tokenize (GeneratorState& state, TokenStream& str) const; 1073c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void setSource (const char* source) { m_source = source; } 1083c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1093c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<ShaderInput*>& getInputs (void) { return m_inputs; } 1103c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<ShaderInput*>& getUniforms (void) { return m_uniforms; } 1113c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1123c827367444ee418f129b2c238299f49d3264554Jarkko Poyry // For executor 1133c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::vector<ShaderInput*>& getInputs (void) const { return m_inputs; } 1143c827367444ee418f129b2c238299f49d3264554Jarkko Poyry const std::vector<ShaderInput*>& getUniforms (void) const { return m_uniforms; } 1153c827367444ee418f129b2c238299f49d3264554Jarkko Poyry void getOutputs (std::vector<const Variable*>& outputs) const; 1163c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1173c827367444ee418f129b2c238299f49d3264554Jarkko Poyryprivate: 1183c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Type m_type; 1193c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1203c827367444ee418f129b2c238299f49d3264554Jarkko Poyry VariableScope m_globalScope; 1213c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Statement*> m_globalStatements; 1223c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1233c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<ShaderInput*> m_inputs; 1243c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<ShaderInput*> m_uniforms; 1253c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1263c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::vector<Function*> m_functions; 1273c827367444ee418f129b2c238299f49d3264554Jarkko Poyry Function m_mainFunction; 1283c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1293c827367444ee418f129b2c238299f49d3264554Jarkko Poyry std::string m_source; 1303c827367444ee418f129b2c238299f49d3264554Jarkko Poyry}; 1313c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1323c827367444ee418f129b2c238299f49d3264554Jarkko Poyry} // rsg 1333c827367444ee418f129b2c238299f49d3264554Jarkko Poyry 1343c827367444ee418f129b2c238299f49d3264554Jarkko Poyry#endif // _RSGSHADER_HPP 135