Library/ManagedCuda/CudaTexture.cs
/// <summary>
/// Create a new CudaArray2D and bind it to a texture reference.
/// </summary>
/// <param name="kernel"></param>
/// <param name="texName"></param>
/// <param name="addressMode0"></param>
/// <param name="addressMode1"></param>
/// <param name="filterMode"></param>
/// <param name="flags"></param>
/// <param name="format"></param>
/// <param name="height">In elements</param>
/// <param name="width">In elements</param>
/// <param name="numChannels">1,2 or 4</param>
Create a new CudaArray2D and bind it to a texture reference.
Create a new CudaArray2D and bind it to a texture reference .
public static CudaArray2D BindTexture(CudaKernel kernel, string texName, CUAddressMode addressMode0, CUAddressMode addressMode1, CUFilterMode filterMode, CUTexRefSetFlags flags, CUArrayFormat format, SizeT width, SizeT height, CudaArray2DNumChannels numChannels)
		{
			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.cuTexRefSetAddressMode(texref, 1, addressMode1);
			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, filterMode);
			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, (int)numChannels);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFormat", res));
			if (res != CUResult.Success) throw new CudaException(res);
			CudaArray2D array = new CudaArray2D(format, width, height, numChannels);
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetArray(texref, array.CUArray, CUTexRefSetArrayFlags.OverrideFormat);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetArray", res));
			if (res != CUResult.Success) throw new CudaException(res);
			return array;
		}
public static CudaArray2D BindTexture ( CudaKernel kernel , string texName , CUAddressMode addressMode0 , CUAddressMode addressMode1 , CUFilterMode filterMode , CUTexRefSetFlags flags , CUArrayFormat format , SizeT width , SizeT height , CudaArray2DNumChannels numChannels ) { 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 . cuTexRefSetAddressMode ( texref , 1 , addressMode1 ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; res = DriverAPINativeMethods . TextureReferenceManagement . cuTexRefSetFilterMode ( texref , filterMode ) ; 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 , ( int ) numChannels ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; CudaArray2D array = new CudaArray2D ( format , width , height , numChannels ) ; res = DriverAPINativeMethods . TextureReferenceManagement . cuTexRefSetArray ( texref , array . CUArray , CUTexRefSetArrayFlags . OverrideFormat ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; return array ; }
Create a new CudaArray2D and bind it to a texture reference.
Create a new CudaArray2D and bind it to a texture reference .
kernel
CudaKernel
None
texName
string
None
addressMode0
CUAddressMode
None
addressMode1
CUAddressMode
None
filterMode
CUFilterMode
None
flags
CUTexRefSetFlags
None
format
CUArrayFormat
None
width
SizeT
None
height
SizeT
None
numChannels
CudaArray2DNumChannels
None