CudaTexture.h

Go to the documentation of this file.
00001 /******************************************************************************
00002 *       SOFA, Simulation Open-Framework Architecture, version 1.0 beta 3      *
00003 *                (c) 2006-2008 MGH, INRIA, USTL, UJF, CNRS                    *
00004 *                                                                             *
00005 * This library is free software; you can redistribute it and/or modify it     *
00006 * under the terms of the GNU Lesser General Public License as published by    *
00007 * the Free Software Foundation; either version 2.1 of the License, or (at     *
00008 * your option) any later version.                                             *
00009 *                                                                             *
00010 * This library is distributed in the hope that it will be useful, but WITHOUT *
00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       *
00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License *
00013 * for more details.                                                           *
00014 *                                                                             *
00015 * You should have received a copy of the GNU Lesser General Public License    *
00016 * along with this library; if not, write to the Free Software Foundation,     *
00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA.          *
00018 *******************************************************************************
00019 *                               SOFA :: Modules                               *
00020 *                                                                             *
00021 * Authors: The SOFA Team and external contributors (see Authors.txt)          *
00022 *                                                                             *
00023 * Contact information: contact@sofa-framework.org                             *
00024 ******************************************************************************/
00025 #ifndef CUDATEXTURE_H
00026 #define CUDATEXTURE_H
00027 
00028 #include "CudaMath.h"
00029 
00033 template<class TIn, class TOut, bool useTexture>
00034 class InputVector;
00035 
00039 template<class TIn, class TOut>
00040 class InputVectorDirect
00041 {
00042 public:
00043     __host__ void set(const TIn*) {}
00044     __inline__ __device__ TOut get(int i, const TIn* x) { return TOut::make(x[i]); }
00045 };
00046 
00050 template<class TIn, class TOut>
00051 class InputVectorTexture;
00052 
00053 template<class TIn, class TOut>
00054 class InputVector<TIn, TOut, false> : public InputVectorDirect<TIn, TOut>
00055 {
00056 };
00057 
00058 template<class TIn, class TOut>
00059 class InputVector<TIn, TOut, true> : public InputVectorTexture<TIn, TOut>
00060 {
00061 };
00062 
00063 template<class TOut>
00064 class InputVectorTexture<float, TOut>
00065 {
00066 public:
00067     typedef float TIn;
00068     static texture<float,1,cudaReadModeElementType> tex;
00069 
00070     __host__ void set(const TIn* x)
00071     {
00072     static const void* cur = NULL;
00073     if (x != cur)
00074     {
00075         cudaBindTexture((size_t*)NULL, tex, x);
00076         cur = x;
00077     }
00078     }
00079     __inline__ __device__ TOut get(int i, const TIn* x)
00080     {
00081     return tex1Dfetch(tex, i);
00082     }
00083 };
00084 
00085 template<class TOut>
00086 class InputVectorTexture<CudaVec2<float>, TOut>
00087 {
00088 public:
00089     typedef CudaVec2<float> TIn;
00090     static texture<float2,1,cudaReadModeElementType> tex;
00091 
00092     __host__ void set(const TIn* x)
00093     {
00094     static const void* cur = NULL;
00095     if (x != cur)
00096     {
00097         cudaBindTexture((size_t*)NULL, tex, x);
00098         cur = x;
00099     }
00100     }
00101     __inline__ __device__ TOut get(int i, const TIn* x)
00102     {
00103     return TOut::make(tex1Dfetch(tex, i));
00104     }
00105 };
00106 
00107 template<class TOut>
00108 class InputVectorTexture<CudaVec3<float>, TOut>
00109 {
00110 public:
00111     typedef CudaVec3<float> TIn;
00112     static texture<float,1,cudaReadModeElementType> tex;
00113 
00114     __host__ void set(const TIn* x)
00115     {
00116     static const void* cur = NULL;
00117     if (x != cur)
00118     {
00119         cudaBindTexture((size_t*)NULL, tex, x);
00120         cur = x;
00121     }
00122     }
00123     __inline__ __device__ TOut get(int i, const TIn* x)
00124     {
00125     int i3 = umul24(i,3);
00126     float x1 = tex1Dfetch(tex, i3);
00127     float x2 = tex1Dfetch(tex, i3+1);
00128     float x3 = tex1Dfetch(tex, i3+2);
00129     return TOut::make(x1,x2,x3);
00130     }
00131 };
00132 
00133 template<class TOut>
00134 class InputVectorTexture<CudaVec4<float>, TOut>
00135 {
00136 public:
00137     typedef CudaVec4<float> TIn;
00138     static texture<float4,1,cudaReadModeElementType> tex;
00139 
00140     __host__ void set(const TIn* x)
00141     {
00142     static const void* cur = NULL;
00143     if (x != cur)
00144     {
00145         cudaBindTexture((size_t*)NULL, tex, x);
00146         cur = x;
00147     }
00148     }
00149     __inline__ __device__ TOut get(int i, const TIn* x)
00150     {
00151     return TOut::make(tex1Dfetch(tex, i));
00152     }
00153 };
00154 
00155 
00156 
00157 #endif

Generated on Sun Nov 23 04:04:16 2008 for Sofa by  doxygen 1.5.7.1