예제 #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;
 }
예제 #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;
        }
        /// <summary>
        /// Returns a CUmipmappedArray handle through which the subresource of the mapped graphics resource resource which
        /// corresponds to array index <c>arrayIndex</c> and mipmap level <c>mipLevel</c> may be accessed. The pointer value in <c>CUmipmappedArray</c>
        /// may change every time that <c>resource</c> is mapped.<para/>
        /// If the resource is not a texture then it cannot be accessed via an array and <see cref="CUResult.ErrorNotMappedAsArray"/>
        /// exception is thrwon. If <c>arrayIndex</c> is not a valid array index for the resource then <see cref="CUResult.ErrorInvalidValue"/>
        /// exception is thrwon. If <c>mipLevel</c> is not a valid mipmap level for the resource then <see cref="CUResult.ErrorInvalidValue"/>
        /// exception is thrwon. If the resource is not mapped then <see cref="CUResult.ErrorNotMapped"/> exception is thrwon.
        /// </summary>
        /// <returns></returns>
        public CUmipmappedArray GetMappedCUMipmappedArray()
        {
            if (disposed)
            {
                throw new ObjectDisposedException(this.ToString());
            }

            CUmipmappedArray array = new CUmipmappedArray();

            res = DriverAPINativeMethods.GraphicsInterop.cuGraphicsResourceGetMappedMipmappedArray(ref array, _cudaResource);
            Debug.Write("");            //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphicsResourceGetMappedMipmappedArray", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }

            return(array);
        }
예제 #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;
        }
예제 #5
0
        /// <summary>
        /// Returns a CudaMipmappedArray through which the subresource of the mapped graphics resource resource which
        /// corresponds to array index <c>arrayIndex</c> and mipmap level <c>mipLevel</c> may be accessed. The pointer value in <c>CudaMipmappedArray</c>
        /// may change every time that <c>resource</c> is mapped.<para/>
        /// If the resource is not a texture then it cannot be accessed via an array and <see cref="CUResult.ErrorNotMappedAsArray"/>
        /// exception is thrwon. If <c>arrayIndex</c> is not a valid array index for the resource then <see cref="CUResult.ErrorInvalidValue"/>
        /// exception is thrwon. If <c>mipLevel</c> is not a valid mipmap level for the resource then <see cref="CUResult.ErrorInvalidValue"/>
        /// exception is thrwon. If the resource is not mapped then <see cref="CUResult.ErrorNotMapped"/> exception is thrwon.
        /// </summary>
        /// <returns></returns>
        public CudaMipmappedArray GetMappedMipmappedArray(CUArrayFormat format, CudaMipmappedArrayNumChannels numChannels)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(this.ToString());
            }

            CUmipmappedArray array = new CUmipmappedArray();

            res = DriverAPINativeMethods.GraphicsInterop.cuGraphicsResourceGetMappedMipmappedArray(ref array, _cudaResource);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphicsResourceGetMappedMipmappedArray", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }

            CudaMipmappedArray retVar = new CudaMipmappedArray(array, format, numChannels);

            return(retVar);
        }