-
Notifications
You must be signed in to change notification settings - Fork 0
/
CudaTexture.cuh
54 lines (43 loc) · 1.54 KB
/
CudaTexture.cuh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#pragma once
#include "CudaArray.cuh"
#include "CudaSurface.cuh"
template <class T>
struct CudaTextureAccessor {
cudaTextureObject_t m_cuTex;
__device__ __forceinline__ T sample(float x, float y, float z) const {
return tex3D<T>(m_cuTex, x, y, z);
}
};
template <class T>
struct CudaTexture : CudaSurface<T> {
struct Parameters {
cudaTextureAddressMode addressMode{cudaAddressModeBorder};
cudaTextureFilterMode filterMode{cudaFilterModeLinear};
cudaTextureReadMode readMode{cudaReadModeElementType};
bool normalizedCoords{false};
};
cudaTextureObject_t m_cuTex{};
explicit CudaTexture(uint3 const &_dim, Parameters const &_args = {})
: CudaSurface<T>(_dim) {
cudaResourceDesc resDesc{};
resDesc.resType = cudaResourceTypeArray;
resDesc.res.array.array = CudaSurface<T>::getArray();
cudaTextureDesc texDesc{};
texDesc.addressMode[0] = _args.addressMode;
texDesc.addressMode[1] = _args.addressMode;
texDesc.addressMode[2] = _args.addressMode;
texDesc.filterMode = _args.filterMode;
texDesc.readMode = _args.readMode;
texDesc.normalizedCoords = _args.normalizedCoords;
checkCudaErrors(cudaCreateTextureObject(&m_cuTex, &resDesc, &texDesc, NULL));
}
cudaTextureObject_t getTexture() const {
return m_cuTex;
}
CudaTextureAccessor<T> accessTexture() const {
return {m_cuTex};
}
~CudaTexture() {
checkCudaErrors(cudaDestroyTextureObject(m_cuTex));
}
};