00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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