Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShKernelLib.cpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory
00004 // Project administrator: Michael D. McCool
00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa,
00006 //          Bryan Chan, Michael D. McCool
00007 // 
00008 // This software is provided 'as-is', without any express or implied
00009 // warranty. In no event will the authors be held liable for any damages
00010 // arising from the use of this software.
00011 // 
00012 // Permission is granted to anyone to use this software for any purpose,
00013 // including commercial applications, and to alter it and redistribute it
00014 // freely, subject to the following restrictions:
00015 // 
00016 // 1. The origin of this software must not be misrepresented; you must
00017 // not claim that you wrote the original software. If you use this
00018 // software in a product, an acknowledgment in the product documentation
00019 // would be appreciated but is not required.
00020 // 
00021 // 2. Altered source versions must be plainly marked as such, and must
00022 // not be misrepresented as being the original software.
00023 // 
00024 // 3. This notice may not be removed or altered from any source
00025 // distribution.
00027 #include <sstream>
00028 #include "ShKernelLib.hpp"
00029 #include "ShFunc.hpp"
00030 
00031 namespace ShUtil {
00032 
00033 std::string ShKernelLib::makeName(std::string prefix, int index) {
00034   std::ostringstream name;
00035   if( index == 0 ) return prefix;
00036   name << prefix << index;
00037   return name.str();
00038 }
00039 
00040 ShProgram ShKernelLib::outputPass( const ShProgram &p ) {
00041   ShProgram passer = SH_BEGIN_PROGRAM() {
00042     for( ShProgramNode::VarList::const_iterator it = p.node()->outputs.begin();
00043         it != p.node()->outputs.end(); ++it ) {
00044       ShVariableNodePtr var = *it;
00045       ShVariable inout(new ShVariableNode(SH_INOUT, var->size(), var->valueType(), var->specialType()));
00046       inout.name( var->name() ); 
00047     }
00048   } SH_END;
00049   return passer;
00050 }
00051 
00052 ShProgram ShKernelLib::inputPass( const ShProgram &p ) {
00053   ShProgram passer = SH_BEGIN_PROGRAM() {
00054     for( ShProgramNode::VarList::const_iterator it = p.node()->inputs.begin();
00055         it != p.node()->inputs.end(); ++it ) {
00056       ShVariableNodePtr var = *it;
00057       ShVariable inout(new ShVariableNode(SH_INOUT, var->size(), var->valueType(), var->specialType()));
00058       inout.name( var->name() ); 
00059     }
00060   } SH_END;
00061   return passer;
00062 }
00063 
00064 ShProgram ShKernelLib::shChangeBasis(std::string name, 
00065     std::string b0Name, std::string b1Name, std::string b2Name) {
00066   ShProgram kernel = SH_BEGIN_PROGRAM() {
00067     ShInputVector3f SH_NAMEDECL( b0, b0Name );
00068     ShInputVector3f SH_NAMEDECL( b1, b1Name );
00069     ShInputVector3f SH_NAMEDECL( b2, b2Name );
00070     ShInOutVector3f SH_NAMEDECL( vec, name ) = changeBasis(b0, b1, b2, vec);
00071   } SH_END;
00072   return kernel;
00073 }
00074 
00075 };

Generated on Mon Jan 24 18:36:32 2005 for Sh by  doxygen 1.4.1