5353#include " opencv2/cudaarithm.hpp"
5454#include " opencv2/cudev.hpp"
5555#include " opencv2/core/private.cuda.hpp"
56+ #include < opencv2/cudev/ptr2d/texture.hpp>
5657
5758using namespace cv ;
5859using namespace cv ::cuda;
5960using namespace cv ::cudev;
6061
6162namespace cv { namespace cuda {
6263
63- texture<uchar, cudaTextureType1D, cudaReadModeElementType> texLutTable;
64-
6564 LookUpTableImpl::LookUpTableImpl (InputArray _lut)
6665 {
6766 if (_lut.kind () == _InputArray::CUDA_GPU_MAT)
@@ -73,83 +72,28 @@ namespace cv { namespace cuda {
7372 Mat h_lut = _lut.getMat ();
7473 d_lut.upload (Mat (1 , 256 , h_lut.type (), h_lut.data ));
7574 }
76-
7775 CV_Assert ( d_lut.depth () == CV_8U );
7876 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);
11778 }
11879
11980 struct LutTablePtrC1
12081 {
12182 typedef uchar value_type;
12283 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);
13587 }
13688 };
89+
13790 struct LutTablePtrC3
13891 {
13992 typedef uchar3 value_type;
14093 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 ));
15397 }
15498 };
15599
@@ -169,20 +113,18 @@ namespace cv { namespace cuda {
169113 {
170114 GpuMat_<uchar> src1 (src.reshape (1 ));
171115 GpuMat_<uchar> dst1 (dst.reshape (1 ));
172-
116+ cv::cudev::Texture<uchar> tex (szInBytes, reinterpret_cast <uchar*>(d_lut. data ));
173117 LutTablePtrC1 tbl;
174- tbl.texLutTableObj = texLutTableObj;
175-
118+ tbl.tex = TexturePtr<uchar>(tex);
176119 dst1.assign (lut_ (src1, tbl), stream);
177120 }
178121 else if (lut_cn == 3 )
179122 {
180123 GpuMat_<uchar3 >& src3 = (GpuMat_<uchar3 >&) src;
181124 GpuMat_<uchar3 >& dst3 = (GpuMat_<uchar3 >&) dst;
182-
125+ cv::cudev::Texture<uchar> tex (szInBytes, reinterpret_cast <uchar*>(d_lut. data ));
183126 LutTablePtrC3 tbl;
184- tbl.texLutTableObj = texLutTableObj;
185-
127+ tbl.tex = TexturePtr<uchar>(tex);
186128 dst3.assign (lut_ (src3, tbl), stream);
187129 }
188130
0 commit comments