53
53
#include " opencv2/cudaarithm.hpp"
54
54
#include " opencv2/cudev.hpp"
55
55
#include " opencv2/core/private.cuda.hpp"
56
+ #include < opencv2/cudev/ptr2d/texture.hpp>
56
57
57
58
using namespace cv ;
58
59
using namespace cv ::cuda;
59
60
using namespace cv ::cudev;
60
61
61
62
namespace cv { namespace cuda {
62
63
63
- texture<uchar, cudaTextureType1D, cudaReadModeElementType> texLutTable;
64
-
65
64
LookUpTableImpl::LookUpTableImpl (InputArray _lut)
66
65
{
67
66
if (_lut.kind () == _InputArray::CUDA_GPU_MAT)
@@ -73,83 +72,28 @@ namespace cv { namespace cuda {
73
72
Mat h_lut = _lut.getMat ();
74
73
d_lut.upload (Mat (1 , 256 , h_lut.type (), h_lut.data ));
75
74
}
76
-
77
75
CV_Assert ( d_lut.depth () == CV_8U );
78
76
CV_Assert ( d_lut.rows == 1 && d_lut.cols == 256 );
79
-
80
- cc30 = deviceSupports (FEATURE_SET_COMPUTE_30);
81
-
82
- if (cc30)
83
- {
84
- // Use the texture object
85
- cudaResourceDesc texRes;
86
- std::memset (&texRes, 0 , sizeof (texRes));
87
- texRes.resType = cudaResourceTypeLinear;
88
- texRes.res .linear .devPtr = d_lut.data ;
89
- texRes.res .linear .desc = cudaCreateChannelDesc<uchar>();
90
- texRes.res .linear .sizeInBytes = 256 * d_lut.channels () * sizeof (uchar);
91
-
92
- cudaTextureDesc texDescr;
93
- std::memset (&texDescr, 0 , sizeof (texDescr));
94
-
95
- CV_CUDEV_SAFE_CALL ( cudaCreateTextureObject (&texLutTableObj, &texRes, &texDescr, 0 ) );
96
- }
97
- else
98
- {
99
- // Use the texture reference
100
- cudaChannelFormatDesc desc = cudaCreateChannelDesc<uchar>();
101
- CV_CUDEV_SAFE_CALL ( cudaBindTexture (0 , &texLutTable, d_lut.data , &desc) );
102
- }
103
- }
104
-
105
- LookUpTableImpl::~LookUpTableImpl ()
106
- {
107
- if (cc30)
108
- {
109
- // Use the texture object
110
- cudaDestroyTextureObject (texLutTableObj);
111
- }
112
- else
113
- {
114
- // Use the texture reference
115
- cudaUnbindTexture (texLutTable);
116
- }
77
+ szInBytes = 256 * d_lut.channels () * sizeof (uchar);
117
78
}
118
79
119
80
struct LutTablePtrC1
120
81
{
121
82
typedef uchar value_type;
122
83
typedef uchar index_type;
123
-
124
- cudaTextureObject_t texLutTableObj;
125
-
126
- __device__ __forceinline__ uchar operator ()(uchar, uchar x) const
127
- {
128
- #if CV_CUDEV_ARCH < 300
129
- // Use the texture reference
130
- return tex1Dfetch (texLutTable, x);
131
- #else
132
- // Use the texture object
133
- return tex1Dfetch <uchar>(texLutTableObj, x);
134
- #endif
84
+ cv::cudev::TexturePtr<uchar> tex;
85
+ __device__ __forceinline__ uchar operator ()(uchar, uchar x) const {
86
+ return tex (x);
135
87
}
136
88
};
89
+
137
90
struct LutTablePtrC3
138
91
{
139
92
typedef uchar3 value_type;
140
93
typedef uchar3 index_type;
141
-
142
- cudaTextureObject_t texLutTableObj;
143
-
144
- __device__ __forceinline__ uchar3 operator ()(const uchar3 &, const uchar3 & x) const
145
- {
146
- #if CV_CUDEV_ARCH < 300
147
- // Use the texture reference
148
- return make_uchar3 (tex1Dfetch (texLutTable, x.x * 3 ), tex1Dfetch (texLutTable, x.y * 3 + 1 ), tex1Dfetch (texLutTable, x.z * 3 + 2 ));
149
- #else
150
- // Use the texture object
151
- return make_uchar3 (tex1Dfetch <uchar>(texLutTableObj, x.x * 3 ), tex1Dfetch <uchar>(texLutTableObj, x.y * 3 + 1 ), tex1Dfetch <uchar>(texLutTableObj, x.z * 3 + 2 ));
152
- #endif
94
+ cv::cudev::TexturePtr<uchar> tex;
95
+ __device__ __forceinline__ uchar3 operator ()(const uchar3 &, const uchar3 & x) const {
96
+ return make_uchar3 (tex (x.x * 3 ), tex (x.y * 3 + 1 ), tex (x.z * 3 + 2 ));
153
97
}
154
98
};
155
99
@@ -169,20 +113,18 @@ namespace cv { namespace cuda {
169
113
{
170
114
GpuMat_<uchar> src1 (src.reshape (1 ));
171
115
GpuMat_<uchar> dst1 (dst.reshape (1 ));
172
-
116
+ cv::cudev::Texture<uchar> tex (szInBytes, reinterpret_cast <uchar*>(d_lut. data ));
173
117
LutTablePtrC1 tbl;
174
- tbl.texLutTableObj = texLutTableObj;
175
-
118
+ tbl.tex = TexturePtr<uchar>(tex);
176
119
dst1.assign (lut_ (src1, tbl), stream);
177
120
}
178
121
else if (lut_cn == 3 )
179
122
{
180
123
GpuMat_<uchar3 >& src3 = (GpuMat_<uchar3 >&) src;
181
124
GpuMat_<uchar3 >& dst3 = (GpuMat_<uchar3 >&) dst;
182
-
125
+ cv::cudev::Texture<uchar> tex (szInBytes, reinterpret_cast <uchar*>(d_lut. data ));
183
126
LutTablePtrC3 tbl;
184
- tbl.texLutTableObj = texLutTableObj;
185
-
127
+ tbl.tex = TexturePtr<uchar>(tex);
186
128
dst3.assign (lut_ (src3, tbl), stream);
187
129
}
188
130
0 commit comments