Skip to content

Commit

Permalink
MythNVDECInterop: Fix direct rendering CUDA->OpenGL synchronisation
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-kendall committed Nov 7, 2019
1 parent 0822d3c commit 9eba7cc
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions mythtv/libs/libmythtv/opengl/mythnvdecinterop.cpp
Expand Up @@ -233,8 +233,9 @@ vector<MythVideoTexture*> MythNVDECInterop::Acquire(MythRenderOpenGL *Context,
}

// Copy device data to array data (i.e. texture) - surely this can be avoided?
// N.B. we don't use cuMemcpy2DAsync as it gives occasional 'green screen' flashes,
// even with subsequent synchronisation
// In theory, asynchronous copies should not be required but we use async
// followed by stream synchronisation to ensure CUDA and OpenGL are in sync
// which avoids presenting old/stale frames when the GPU is under load.
result = m_openglTextures[cudabuffer];
for (uint i = 0; i < result.size(); ++i)
{
Expand All @@ -248,9 +249,10 @@ vector<MythVideoTexture*> MythNVDECInterop::Acquire(MythRenderOpenGL *Context,
cpy.dstArray = data->first;
cpy.WidthInBytes = static_cast<size_t>(result[i]->m_size.width()) * (hdr ? 2 : 1);
cpy.Height = static_cast<size_t>(result[i]->m_size.height());
CUDA_CHECK(m_cudaFuncs, cuMemcpy2D(&cpy));
CUDA_CHECK(m_cudaFuncs, cuMemcpy2DAsync(&cpy, nullptr));
}

CUDA_CHECK(m_cudaFuncs, cuStreamSynchronize(nullptr));
CUDA_CHECK(m_cudaFuncs, cuCtxPopCurrent(&dummy));

// GLSL deinterlacing. The decoder will pick up any CPU or driver preference
Expand Down

0 comments on commit 9eba7cc

Please sign in to comment.