00001 // Sh: A GPU metaprogramming language. 00002 // 00003 // Copyright 2003-2005 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 void operator()(const SH::ShCtrlGraphNode* node); 00043 00044 ChannelMap& channel_map; 00045 SH::ShTextureDims dims; 00046 }; 00047 00048 00049 // Replace FETCH and LOOKUP operations with texture fetches 00050 // Run this after a pass with channelgatherer. 00051 class TexFetcher { 00052 public: 00053 TexFetcher(ChannelMap& channel_map, 00054 const SH::ShVariableNodePtr& tc_node, 00055 bool indexed, 00056 const SH::ShProgramNodePtr& program); 00057 00058 void operator()(SH::ShCtrlGraphNode* node); 00059 00060 private: 00061 ChannelMap& channel_map; 00062 SH::ShVariableNodePtr tc_node; 00063 bool indexed; 00064 SH::ShProgramNodePtr program; 00065 }; 00066 00067 void split_program(SH::ShProgramNode* program, 00068 std::list<SH::ShProgramNodePtr>& programs, 00069 const std::string& target); 00070 00071 } 00072 00073 #endif
1.4.5