Library/ManagedCuda/CudaTexture.cs
/// <summary>
/// Create a new CudaDeviceVariable and bind it to a texture reference.
/// </summary>
/// <param name="kernel"></param>
/// <param name="texName"></param>
/// <param name="addressMode0"></param>
/// <param name="flags"></param>
/// <param name="format"></param>
/// <param name="size">In elements</param>
Create a new CudaDeviceVariable and bind it to a texture reference.
Create a new CudaDeviceVariable and bind it to a texture reference .
public static CudaDeviceVariable<T> BindTexture<T>(CudaKernel kernel, string texName, CUTexRefSetFlags flags, CUAddressMode addressMode0, CUArrayFormat format, SizeT size) where T : struct
		{
			CUtexref texref = new CUtexref();
			CUResult res = DriverAPINativeMethods.ModuleManagement.cuModuleGetTexRef(ref texref, kernel.CUModule, texName);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}, Texture name: {3}", DateTime.Now, "cuModuleGetTexRef", res, texName));
			if (res != CUResult.Success) throw new CudaException(res);
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetAddressMode(texref, 0, addressMode0);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetAddressMode", res));
			if (res != CUResult.Success) throw new CudaException(res);
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFilterMode(texref, CUFilterMode.Point); 
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFilterMode", res));
			if (res != CUResult.Success) throw new CudaException(res);
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFlags(texref, flags);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFlags", res));
			if (res != CUResult.Success) throw new CudaException(res);
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFormat(texref, format, CudaHelperMethods.GetNumChannels(typeof(T)));
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFormat", res));
			if (res != CUResult.Success) throw new CudaException(res);
			CudaDeviceVariable<T> devVar = new CudaDeviceVariable<T>(size);
			SizeT NULL = 0;
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetAddress_v2(ref NULL, texref, devVar.DevicePointer, devVar.SizeInBytes);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetAddress", res));
			if (res != CUResult.Success) throw new CudaException(res);
			return devVar;
		}
public static CudaDeviceVariable < T > BindTexture < T > ( CudaKernel kernel , string texName , CUTexRefSetFlags flags , CUAddressMode addressMode0 , CUArrayFormat format , SizeT size ) where T : struct { CUtexref texref = new CUtexref ( ) ; CUResult res = DriverAPINativeMethods . ModuleManagement . cuModuleGetTexRef ( ref texref , kernel . CUModule , texName ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res , texName ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; res = DriverAPINativeMethods . TextureReferenceManagement . cuTexRefSetAddressMode ( texref , 0 , addressMode0 ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; res = DriverAPINativeMethods . TextureReferenceManagement . cuTexRefSetFilterMode ( texref , CUFilterMode . Point ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; res = DriverAPINativeMethods . TextureReferenceManagement . cuTexRefSetFlags ( texref , flags ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; res = DriverAPINativeMethods . TextureReferenceManagement . cuTexRefSetFormat ( texref , format , CudaHelperMethods . GetNumChannels ( typeof ( T ) ) ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; CudaDeviceVariable < T > devVar = new CudaDeviceVariable < T > ( size ) ; SizeT NULL = 0 ; res = DriverAPINativeMethods . TextureReferenceManagement . cuTexRefSetAddress_v2 ( ref NULL , texref , devVar . DevicePointer , devVar . SizeInBytes ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; return devVar ; }
Create a new CudaDeviceVariable and bind it to a texture reference.
Create a new CudaDeviceVariable and bind it to a texture reference .
//Textures from linear memory can only by point filtered
kernel
CudaKernel
None
texName
string
None
flags
CUTexRefSetFlags
None
addressMode0
CUAddressMode
None
format
CUArrayFormat
None
size
SizeT
None