Library/ManagedCuda/CudaTexture.cs
/// <summary>
/// Create a new CudaPitchedDeviceVariable and bind it to a texture reference.
/// Sets the border color for the texture reference<para/>
/// Specifies the value of the RGBA color via the \p pBorderColor to the texture reference
/// \p hTexRef. The color value supports only float type and holds color components in
/// the following sequence:<para/>
/// pBorderColor[0] holds 'R' component<para/>
/// pBorderColor[1] holds 'G' component<para/>
/// pBorderColor[2] holds 'B' component<para/>
/// pBorderColor[3] holds 'A' component<para/>
/// addressMode is set to CU_TR_ADDRESS_MODE_BORDER
/// </summary>
/// <param name="kernel"></param>
/// <param name="texName"></param>
/// <param name="filterMode"></param>
/// <param name="flags"></param>
/// <param name="format"></param>
/// <param name="width">In elements</param>
/// <param name="height">In elements</param>
/// <param name="borderColor">RGBA color</param>
Create a new CudaPitchedDeviceVariable and bind it to a texture reference.
Sets the border color for the texture reference
Specifies the value of the RGBA color via the \p pBorderColor to the texture reference
\p hTexRef.
Create a new CudaPitchedDeviceVariable and bind it to a texture reference . Sets the border color for the texture reference Specifies the value of the RGBA color via the \ p pBorderColor to the texture reference \ p hTexRef .
public static CudaPitchedDeviceVariable<T> BindTexture<T>(CudaKernel kernel, string texName, CUFilterMode filterMode, CUTexRefSetFlags flags, CUArrayFormat format, SizeT width, SizeT height, float[] borderColor) 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, CUAddressMode.Border);
			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, CUAddressMode.Border);
			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);
			int numChannels = CudaHelperMethods.GetNumChannels(typeof(T));
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFormat(texref, format, numChannels);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFormat", res));
			if (res != CUResult.Success) throw new CudaException(res);
			CudaPitchedDeviceVariable<T> devVar = new CudaPitchedDeviceVariable<T>(width, height);
			CUDAArrayDescriptor arrayDescr = new CUDAArrayDescriptor();
			arrayDescr.Format = format;
			arrayDescr.Height = height;
			arrayDescr.NumChannels = (uint)numChannels;
			arrayDescr.Width = width;
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetAddress2D_v2(texref, ref arrayDescr, devVar.DevicePointer, devVar.Pitch);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetAddress2D", res));
			if (res != CUResult.Success) throw new CudaException(res);
			res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetBorderColor(texref, borderColor);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetBorderColor", res));
			if (res != CUResult.Success) throw new CudaException(res);
			return devVar;
		}
public static CudaPitchedDeviceVariable < T > BindTexture < T > ( CudaKernel kernel , string texName , CUFilterMode filterMode , CUTexRefSetFlags flags , CUArrayFormat format , SizeT width , SizeT height , float [ ] borderColor ) 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 , CUAddressMode . Border ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; res = DriverAPINativeMethods . TextureReferenceManagement . cuTexRefSetAddressMode ( texref , 1 , CUAddressMode . Border ) ; 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 ) ; int numChannels = CudaHelperMethods . GetNumChannels ( typeof ( T ) ) ; res = DriverAPINativeMethods . TextureReferenceManagement . cuTexRefSetFormat ( texref , format , numChannels ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; CudaPitchedDeviceVariable < T > devVar = new CudaPitchedDeviceVariable < T > ( width , height ) ; CUDAArrayDescriptor arrayDescr = new CUDAArrayDescriptor ( ) ; arrayDescr . Format = format ; arrayDescr . Height = height ; arrayDescr . NumChannels = ( uint ) numChannels ; arrayDescr . Width = width ; res = DriverAPINativeMethods . TextureReferenceManagement . cuTexRefSetAddress2D_v2 ( texref , ref arrayDescr , devVar . DevicePointer , devVar . Pitch ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; res = DriverAPINativeMethods . TextureReferenceManagement . cuTexRefSetBorderColor ( texref , borderColor ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; return devVar ; }
Create a new CudaPitchedDeviceVariable and bind it to a texture reference.
Create a new CudaPitchedDeviceVariable and bind it to a texture reference .
kernel
CudaKernel
None
texName
string
None
filterMode
CUFilterMode
None
flags
CUTexRefSetFlags
None
format
CUArrayFormat
None
width
SizeT
None
height
SizeT
None
borderColor
float[]
None