00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright 2003-2006 Serious Hack Inc. 00004 // 00005 // This library is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU Lesser General Public 00007 // License as published by the Free Software Foundation; either 00008 // version 2.1 of the License, or (at your option) any later version. 00009 // 00010 // This library is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public 00016 // License along with this library; if not, write to the Free Software 00017 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00018 // MA 02110-1301, USA 00020 #ifndef UTILS_HPP 00021 #define UTILS_HPP 00022 00023 #include <map> 00024 #include <list> 00025 #include "ShChannelNode.hpp" 00026 #include "ShTextureNode.hpp" 00027 #include "ShCtrlGraph.hpp" 00028 #include "ShProgramNode.hpp" 00029 00030 namespace shgl { 00031 00032 typedef std::map<SH::ShChannelNodePtr, SH::ShTextureNodePtr> ChannelMap; 00033 00034 // Find all the channels read by a given program. Make textures for them. 00035 struct ChannelGatherer { 00036 ChannelGatherer(ChannelMap& channel_map, SH::ShTextureDims dims) 00037 : channel_map(channel_map), 00038 dims(dims) 00039 { 00040 } 00041 00042 // assignment operator could not be generated 00043 ChannelGatherer& operator=(ChannelGatherer const&); 00044 00045 void operator()(const SH::ShCtrlGraphNode* node); 00046 00047 ChannelMap& channel_map; 00048 SH::ShTextureDims dims; 00049 }; 00050 00051 00052 // Replace FETCH and LOOKUP operations with texture fetches 00053 // Run this after a pass with channelgatherer. 00054 class TexFetcher { 00055 public: 00056 TexFetcher(ChannelMap& channel_map, 00057 const SH::ShVariableNodePtr& tc_node, 00058 bool indexed, 00059 const SH::ShProgramNodePtr& program); 00060 00061 void operator()(SH::ShCtrlGraphNode* node); 00062 00063 private: 00064 // assignment operator could not be generated 00065 TexFetcher& operator=(TexFetcher const&); 00066 00067 ChannelMap& channel_map; 00068 SH::ShVariableNodePtr tc_node; 00069 bool indexed; 00070 SH::ShProgramNodePtr program; 00071 }; 00072 00073 void split_program(SH::ShProgramNode* program, 00074 std::list<SH::ShProgramNodePtr>& programs, 00075 const std::string& target); 00076 00077 } 00078 00079 #endif
1.4.6