Cuda and DirectX11 interoperability problem


I am trying to create water renderer, which uses CUDA to generate water mesh and then render this mesh using DirectX11.

The problem is with mesh generation, which looks like this:

cudaError cuResult = cudaGraphicsMapResources( 1, &cuVertexBuffer );

  cuResult = cudaGraphicsResourceGetMappedPointer( reinterpret_cast< void ** >( &deviceMesh ), &vertexBufferSize, cuVertexBuffer );

  kernel<<< blocksPerGrid, threadsPerBlock >>>( deviceMesh, waves.dev_ptr( ), waves.size( ), gridInfo, time );

  cuResult = cudaGraphicsUnmapResources( 1, &cuVertexBuffer );

Of course, I check all the errors (there is none). After resource is unmapped, vertexBuffer is used in rendering.

The problem is that when I render only water mesh, vertex buffer gets properly updated.

When I add any other meshes, vertex buffer freezes after first update (doesn’t matter if water mesh is rendered first, last or in the middle of other meshes, it always freezes).

Of course application works fine, no CUDA or DirectX errors, only mesh becomes static. Also kernel executes, takes the same amount of time as when no other meshes were rendered.

It is the only place in application where I use CUDA.

Maybe someone had similar problem and resolved it?