diff options
author | Philip Langdale <philipl@overt.org> | 2016-09-09 20:07:43 -0700 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2016-09-10 13:15:27 +0200 |
commit | 76818e3dc7ed8d79a031028fe5bf8d3a9b63cdca (patch) | |
tree | 0c75025b22c6d2a48192621a198c33086ca447f4 /video/out/opengl/hwdec_cuda.c | |
parent | d054a7181fb92bdd2703d0301800fd52daf3cf86 (diff) | |
download | mpv-76818e3dc7ed8d79a031028fe5bf8d3a9b63cdca.tar.bz2 mpv-76818e3dc7ed8d79a031028fe5bf8d3a9b63cdca.tar.xz |
hwdec_cuda: Use the non-deprecated CUDA-GL interop API
The nvidia examples use the old (as in CUDA 3.x) interop API which
is deprecated, and I think not even functional on recent versions
of CUDA for windows. As I was following the examples, I used this
old API.
So, let's update to the new API, and hopefully, it'll start working
on windows too.
Diffstat (limited to 'video/out/opengl/hwdec_cuda.c')
-rw-r--r-- | video/out/opengl/hwdec_cuda.c | 38 |
1 files changed, 26 insertions, 12 deletions
diff --git a/video/out/opengl/hwdec_cuda.c b/video/out/opengl/hwdec_cuda.c index 8b8b099103..9d964792f9 100644 --- a/video/out/opengl/hwdec_cuda.c +++ b/video/out/opengl/hwdec_cuda.c @@ -40,6 +40,7 @@ struct priv { struct mp_image layout; GLuint gl_textures[2]; GLuint gl_pbos[2]; + CUgraphicsResource cu_res[2]; bool mapped; CUcontext cuda_ctx; @@ -155,9 +156,12 @@ static int reinit(struct gl_hwdec *hw, struct mp_image_params *params) mp_image_plane_h(&p->layout, n) * (n + 1), NULL, GL_STREAM_DRAW); gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); - ret = CHECK_CU(cuGLRegisterBufferObject(p->gl_pbos[n])); + ret = CHECK_CU(cuGraphicsGLRegisterBuffer(&p->cu_res[n], + p->gl_pbos[n], + CU_GRAPHICS_MAP_RESOURCE_FLAGS_WRITE_DISCARD)); if (ret < 0) goto error; + } error: @@ -177,8 +181,8 @@ static void destroy(struct gl_hwdec *hw) // Don't bail if any CUDA calls fail. This is all best effort. CHECK_CU(cuCtxPushCurrent(p->cuda_ctx)); for (int n = 0; n < 2; n++) { - if (p->gl_pbos[n] > 0) - CHECK_CU(cuGLUnregisterBufferObject(p->gl_pbos[n])); + if (p->cu_res[n] > 0) + CHECK_CU(cuGraphicsUnregisterResource(p->cu_res[n])); } CHECK_CU(cuCtxPopCurrent(&dummy)); @@ -205,8 +209,6 @@ static int map_frame(struct gl_hwdec *hw, struct mp_image *hw_image, struct priv *p = hw->priv; GL *gl = hw->gl; CUcontext dummy; - CUdeviceptr cuda_data; - size_t cuda_size; int ret = 0, eret = 0; ret = CHECK_CU(cuCtxPushCurrent(p->cuda_ctx)); @@ -215,9 +217,16 @@ static int map_frame(struct gl_hwdec *hw, struct mp_image *hw_image, *out_frame = (struct gl_hwdec_frame) { 0, }; + ret = CHECK_CU(cuGraphicsMapResources(2, p->cu_res, NULL)); + if (ret < 0) + goto error; for (int n = 0; n < 2; n++) { - gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, p->gl_pbos[n]); - ret = CHECK_CU(cuGLMapBufferObject(&cuda_data, &cuda_size, p->gl_pbos[n])); + CUdeviceptr cuda_data; + size_t cuda_size; + + ret = CHECK_CU(cuGraphicsResourceGetMappedPointer(&cuda_data, + &cuda_size, + p->cu_res[n])); if (ret < 0) goto error; @@ -238,20 +247,24 @@ static int map_frame(struct gl_hwdec *hw, struct mp_image *hw_image, if (ret < 0) goto error; + } + ret = CHECK_CU(cuGraphicsUnmapResources(2, p->cu_res, NULL)); + if (ret < 0) + goto error; + + for (int n = 0; n < 2; n++) { + gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, p->gl_pbos[n]); gl->BindTexture(GL_TEXTURE_2D, p->gl_textures[n]); gl->PixelStorei(GL_UNPACK_ALIGNMENT, get_alignment(mp_image_plane_w(&p->layout, n))); + gl->TexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mp_image_plane_w(&p->layout, n), mp_image_plane_h(&p->layout, n), n == 0 ? GL_RED : GL_RG, GL_UNSIGNED_BYTE, NULL); - gl->PixelStorei(GL_UNPACK_ALIGNMENT, 4); - - ret = CHECK_CU(cuGLUnmapBufferObject(p->gl_pbos[n])); - if (ret < 0) - goto error; + gl->PixelStorei(GL_UNPACK_ALIGNMENT, 4); gl->BindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); gl->BindTexture(GL_TEXTURE_2D, 0); @@ -263,6 +276,7 @@ static int map_frame(struct gl_hwdec *hw, struct mp_image *hw_image, }; } + error: eret = CHECK_CU(cuCtxPopCurrent(&dummy)); if (eret < 0) |