Example #1
0
 /// <summary>
 /// Creates a CUDA mipmapped array from an existing mipmap array handle.
 /// </summary>
 /// <param name="handle">handle to wrap</param>
 /// <param name="format">Array format of the wrapped array. Cannot be gathered through CUDA API.</param>
 /// <param name="numChannels">Number of channels of wrapped array.</param>
 public CudaMipmappedArray(CUmipmappedArray handle, CUArrayFormat format, CudaMipmappedArrayNumChannels numChannels)
 {
     _mipmappedArray              = handle;
     _arrayDescriptor             = new CUDAArray3DDescriptor();
     _arrayDescriptor.Format      = format;
     _arrayDescriptor.NumChannels = (uint)numChannels;
     _isOwner = false;
 }
Example #2
0
        /// <summary>
        /// Creates a CUDA mipmapped array according to <c>descriptor</c>. <para/>
        /// Width, Height, and Depth are the width, height, and depth of the CUDA array (in elements); the following
        /// types of CUDA arrays can be allocated:<para/>
        /// – A 1D mipmapped array is allocated if Height and Depth extents are both zero.<para/>
        /// – A 2D mipmapped array is allocated if only Depth extent is zero.<para/>
        /// – A 3D mipmapped array is allocated if all three extents are non-zero.<para/>
        /// – A 1D layered CUDA mipmapped array is allocated if only Height is zero and the <see cref="CUDAArray3DFlags.Layered"/>
        ///   flag is set. Each layer is a 1D array. The number of layers is determined by the depth extent.<para/>
        /// – A 2D layered CUDA mipmapped array is allocated if all three extents are non-zero and the <see cref="CUDAArray3DFlags.Layered"/>
        ///   flag is set. Each layer is a 2D array. The number of layers is determined by the depth extent.<para/>
        /// – A cubemap CUDA mipmapped array is allocated if all three extents are non-zero and the <see cref="CUDAArray3DFlags.Cubemap"/>
        ///   flag is set. Width must be equal to Height, and Depth must be six. A
        ///   cubemap is a special type of 2D layered CUDA array, where the six layers represent the six faces of a
        ///   cube. The order of the six layers in memory is the same as that listed in CUarray_cubemap_face.<para/>
        /// – A cubemap layered CUDA mipmapped array is allocated if all three extents are non-zero, and both,
        ///   <see cref="CUDAArray3DFlags.Cubemap"/> and <see cref="CUDAArray3DFlags.Layered"/> flags are set. Width must be equal
        ///   to Height, and Depth must be a multiple of six. A cubemap layered CUDA array is a special type of
        ///   2D layered CUDA array that consists of a collection of cubemaps. The first six layers represent the first
        ///   cubemap, the next six layers form the second cubemap, and so on.<para/>
        /// Flags may be set to:<para/>
        /// – <see cref="CUDAArray3DFlags.Layered"/> to enable creation of layered CUDA mipmapped arrays. If this flag is set,
        ///   Depth specifies the number of layers, not the depth of a 3D array.<para/>
        /// – <see cref="CUDAArray3DFlags.Cubemap"/> to enable creation of mipmapped cubemaps. If this flag is set, Width
        ///   must be equal to Height, and Depth must be six. If the CUDA_ARRAY3D_LAYERED flag is also set,
        ///   then Depth must be a multiple of six.<para/>
        /// – <see cref="CUDAArray3DFlags.TextureGather"/> to indicate that the CUDA mipmapped array will be used for
        ///   texture gather. Texture gather can only be performed on 2D CUDA mipmapped arrays.
        /// </summary>
        /// <param name="descriptor">mipmapped array descriptor</param>
        /// <param name="numMipmapLevels">Number of mipmap levels. This value is clamped to the range [1, 1 + floor(log2(max(width, height, depth)))]</param>
        public CudaMipmappedArray(CUDAArray3DDescriptor descriptor, uint numMipmapLevels)
        {
            _mipmappedArray  = new CUmipmappedArray();
            _arrayDescriptor = descriptor;

            res = DriverAPINativeMethods.ArrayManagement.cuMipmappedArrayCreate(ref _mipmappedArray, ref _arrayDescriptor, numMipmapLevels);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMipmappedArrayCreate", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            _isOwner = true;
        }
Example #3
0
        /// <summary>
        /// Creates a new CUDA array from an existing CUarray.
        /// Array properties are obtained by cuArrayGetDescriptor
        /// </summary>
        /// <param name="cuArray"></param>
        /// <param name="isOwner">The cuArray will be destroyed while disposing, if the CudaArray is the owner</param>
        public CudaArray3D(CUarray cuArray, bool isOwner)
        {
            _cuArray           = cuArray;
            _array3DDescriptor = new CUDAArray3DDescriptor();

            res = DriverAPINativeMethods.ArrayManagement.cuArray3DGetDescriptor_v2(ref _array3DDescriptor, _cuArray);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuArray3DGetDescriptor", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            _isOwner = isOwner;
        }
Example #4
0
        /// <summary>
        /// Creates a CUDA mipmapped array according to <c>descriptor</c>. <para/>
        /// Width, Height, and Depth are the width, height, and depth of the CUDA array (in elements); the following
        /// types of CUDA arrays can be allocated:<para/>
        /// – A 1D mipmapped array is allocated if Height and Depth extents are both zero.<para/>
        /// – A 2D mipmapped array is allocated if only Depth extent is zero.<para/>
        /// – A 3D mipmapped array is allocated if all three extents are non-zero.<para/>
        /// – A 1D layered CUDA mipmapped array is allocated if only Height is zero and the <see cref="CUDAArray3DFlags.Layered"/>
        ///   flag is set. Each layer is a 1D array. The number of layers is determined by the depth extent.
        /// – A 2D layered CUDA mipmapped array is allocated if all three extents are non-zero and the <see cref="CUDAArray3DFlags.Layered"/>
        ///   flag is set. Each layer is a 2D array. The number of layers is determined by the depth extent.
        /// – A cubemap CUDA mipmapped array is allocated if all three extents are non-zero and the <see cref="CUDAArray3DFlags.Cubemap"/>
        ///   flag is set. Width must be equal to Height, and Depth must be six. A
        ///   cubemap is a special type of 2D layered CUDA array, where the six layers represent the six faces of a
        ///   cube. The order of the six layers in memory is the same as that listed in CUarray_cubemap_face.
        /// – A cubemap layered CUDA mipmapped array is allocated if all three extents are non-zero, and both,
        ///   <see cref="CUDAArray3DFlags.Cubemap"/> and <see cref="CUDAArray3DFlags.Layered"/> flags are set. Width must be equal
        ///   to Height, and Depth must be a multiple of six. A cubemap layered CUDA array is a special type of
        ///   2D layered CUDA array that consists of a collection of cubemaps. The first six layers represent the first
        ///   cubemap, the next six layers form the second cubemap, and so on.
        /// </summary>
        /// <param name="format">Array format</param>
        /// <param name="width">Array width. See general description.</param>
        /// <param name="height">Array height. See general description.</param>
        /// <param name="depth">Array depth or layer count. See general description.</param>
        /// <param name="numChannels">number of channels</param>
        /// <param name="flags">Flags may be set to:<para/>
        /// – <see cref="CUDAArray3DFlags.Layered"/> to enable creation of layered CUDA mipmapped arrays. If this flag is set,
        ///   Depth specifies the number of layers, not the depth of a 3D array.<para/>
        /// – <see cref="CUDAArray3DFlags.Cubemap"/> to enable creation of mipmapped cubemaps. If this flag is set, Width
        ///   must be equal to Height, and Depth must be six. If the CUDA_ARRAY3D_LAYERED flag is also set,
        ///   then Depth must be a multiple of six.<para/>
        /// – <see cref="CUDAArray3DFlags.TextureGather"/> to indicate that the CUDA mipmapped array will be used for
        ///   texture gather. Texture gather can only be performed on 2D CUDA mipmapped arrays.</param>
        /// <param name="numMipmapLevels">Number of mipmap levels. This value is clamped to the range [1, 1 + floor(log2(max(width, height, depth)))]</param>
        public CudaMipmappedArray(CUArrayFormat format, SizeT width, SizeT height, SizeT depth, CudaMipmappedArrayNumChannels numChannels, CUDAArray3DFlags flags, uint numMipmapLevels)
        {
            _mipmappedArray              = new CUmipmappedArray();
            _arrayDescriptor             = new CUDAArray3DDescriptor();
            _arrayDescriptor.Width       = width;
            _arrayDescriptor.Height      = height;
            _arrayDescriptor.Depth       = depth;
            _arrayDescriptor.NumChannels = (uint)numChannels;
            _arrayDescriptor.Flags       = flags;
            _arrayDescriptor.Format      = format;


            res = DriverAPINativeMethods.ArrayManagement.cuMipmappedArrayCreate(ref _mipmappedArray, ref _arrayDescriptor, numMipmapLevels);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMipmappedArrayCreate", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            _isOwner = true;
        }
Example #5
0
        /// <summary>
        /// Creates a new mipmapped texture from array memory. Allocates a new mipmapped array.
        /// </summary>
        /// <param name="kernel"></param>
        /// <param name="texName"></param>
        /// <param name="addressMode0"></param>
        /// <param name="addressMode1"></param>
        /// <param name="addressMode2"></param>
        /// <param name="filterMode"></param>
        /// <param name="flags"></param>
        /// <param name="descriptor"></param>
        /// <param name="numMipmapLevels"></param>
        /// <param name="maxAniso"></param>
        /// <param name="mipmapFilterMode"></param>
        /// <param name="mipmapLevelBias"></param>
        /// <param name="minMipmapLevelClamp"></param>
        /// <param name="maxMipmapLevelClamp"></param>
        public CudaTextureMipmappedArray(CudaKernel kernel, string texName, CUAddressMode addressMode0, CUAddressMode addressMode1, CUAddressMode addressMode2,
                                         CUFilterMode filterMode, CUTexRefSetFlags flags, CUDAArray3DDescriptor descriptor, uint numMipmapLevels,
                                         uint maxAniso, CUFilterMode mipmapFilterMode, float mipmapLevelBias, float minMipmapLevelClamp, float maxMipmapLevelClamp)
        {
            _maxAniso            = maxAniso;
            _mipmapFilterMode    = mipmapFilterMode;
            _mipmapLevelBias     = mipmapLevelBias;
            _minMipmapLevelClamp = minMipmapLevelClamp;
            _maxMipmapLevelClamp = maxMipmapLevelClamp;

            _texref = new CUtexref();
            res     = DriverAPINativeMethods.ModuleManagement.cuModuleGetTexRef(ref _texref, kernel.CUModule, texName);
            Debug.Write("");//Line(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.Write("");//Line(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.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetAddressMode", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetAddressMode(_texref, 2, addressMode2);
            Debug.Write("");//Line(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.Write("");//Line(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.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFlags", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetFormat(_texref, descriptor.Format, (int)descriptor.NumChannels);
            Debug.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetFormat", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }

            _filtermode      = filterMode;
            _flags           = flags;
            _addressMode0    = addressMode0;
            _addressMode1    = addressMode1;
            _addressMode2    = addressMode2;
            _arrayDescriptor = descriptor;
            _name            = texName;
            _module          = kernel.CUModule;
            _cufunction      = kernel.CUFunction;

            _array = new CudaMipmappedArray(descriptor, numMipmapLevels);

            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetMipmappedArray(_texref, _array.CUMipmappedArray, CUTexRefSetArrayFlags.OverrideFormat);
            Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetMipmappedArray", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetMaxAnisotropy(_texref, maxAniso);
            Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetMaxAnisotropy", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetMipmapFilterMode(_texref, mipmapFilterMode);
            Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetMipmapFilterMode", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetMipmapLevelBias(_texref, mipmapLevelBias);
            Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetMipmapLevelBias", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
            res = DriverAPINativeMethods.TextureReferenceManagement.cuTexRefSetMipmapLevelClamp(_texref, minMipmapLevelClamp, maxMipmapLevelClamp);
            Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuTexRefSetMipmapLevelClamp", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
        }
Example #6
0
 /// <summary>
 /// Creates a new mipmapped texture from array memory. Allocates a new mipmapped array.
 /// </summary>
 /// <param name="kernel"></param>
 /// <param name="texName"></param>
 /// <param name="addressModeForAllDimensions"></param>
 /// <param name="filterMode"></param>
 /// <param name="flags"></param>
 /// <param name="descriptor"></param>
 /// <param name="numMipmapLevels"></param>
 /// <param name="maxAniso"></param>
 /// <param name="mipmapFilterMode"></param>
 /// <param name="mipmapLevelBias"></param>
 /// <param name="minMipmapLevelClamp"></param>
 /// <param name="maxMipmapLevelClamp"></param>
 public CudaTextureMipmappedArray(CudaKernel kernel, string texName, CUAddressMode addressModeForAllDimensions,
                                  CUFilterMode filterMode, CUTexRefSetFlags flags, CUDAArray3DDescriptor descriptor, uint numMipmapLevels,
                                  uint maxAniso, CUFilterMode mipmapFilterMode, float mipmapLevelBias, float minMipmapLevelClamp, float maxMipmapLevelClamp)
     : this(kernel, texName, addressModeForAllDimensions, addressModeForAllDimensions, addressModeForAllDimensions, filterMode, flags, descriptor,
            numMipmapLevels, maxAniso, mipmapFilterMode, mipmapLevelBias, minMipmapLevelClamp, maxMipmapLevelClamp)
 {
 }