Exemple #1
0
//-----------------------------------------------------------------------------
// Name: RunCUDA()
// Desc: Launches the CUDA kernels to fill in the texture data
//-----------------------------------------------------------------------------
void RunCUDA()
{
    //
    // map the resources we've registered so we can access them in Cuda
    // - it is most efficient to map and unmap all resources in a single call,
    //   and to have the map/unmap calls be the boundary between using the GPU
    //   for Direct3D and Cuda
    //

    if (!g_bDeviceLost)
    {
        cudaStream_t    stream = 0;
        const int nbResources = 3;
        cudaGraphicsResource *ppResources[nbResources] =
        {
            g_texture_2d.cudaResource,
            g_texture_vol.cudaResource,
            g_texture_cube.cudaResource,
        };
        cudaGraphicsMapResources(nbResources, ppResources, stream);
        getLastCudaError("cudaGraphicsMapResources(3) failed");

        //
        // run kernels which will populate the contents of those textures
        //
        RunKernels();

        //
        // unmap the resources
        //
        cudaGraphicsUnmapResources(nbResources, ppResources, stream);
        getLastCudaError("cudaGraphicsUnmapResources(3) failed");
    }
}
//-----------------------------------------------------------------------------
// Name: RunCL()
// Desc: Launches the CL kernels to fill in the texture data
//-----------------------------------------------------------------------------
void RunCL()
{
	//
	// map the resources we've registered so we can access them in cl
	// - it is most efficient to map and unmap all resources in a single call,
	//   and to have the map/unmap calls be the boundary between using the GPU
	//   for Direct3D and cl
	//

    if (!g_bDeviceLost) {
		//
		// Transfer ownership from D3D to OpenCL
		//
		AcquireTexturesForOpenCL();
	    //
	    // run kernels which will populate the contents of those textures
	    //
	    RunKernels();
	    //
	    // give back the ownership to D3D
	    //
		ReleaseTexturesFromOpenCL();
    }
}