Commit c75907d2 authored by Seungha Yang's avatar Seungha Yang 🐑 Committed by Tim-Philipp Müller
Browse files

nvenc: Fix undefined reference build error on MSVC and CUDA 9.1

parent 3cd1d0c7
......@@ -33,6 +33,7 @@
#include <cuda.h>
#include <cuda_runtime_api.h>
#include <cuda_gl_interop.h>
#include <cudaGL.h>
#include <gst/gl/gl.h>
#endif
......@@ -171,8 +172,8 @@ G_LOCK_DEFINE_STATIC (initialization_lock);
struct gl_input_resource
{
GstGLMemory *gl_mem[GST_VIDEO_MAX_PLANES];
struct cudaGraphicsResource *cuda_texture;
gpointer cuda_plane_pointers[GST_VIDEO_MAX_PLANES];
CUgraphicsResource cuda_texture;
CUdeviceptr cuda_plane_pointers[GST_VIDEO_MAX_PLANES];
gpointer cuda_pointer;
gsize cuda_stride;
gsize cuda_num_bytes;
......@@ -1453,6 +1454,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
cudaError_t cuda_ret;
guint8 *data_pointer;
guint i;
CUDA_MEMCPY2D param;
cuCtxPushCurrent (data->nvenc->cuda_ctx);
data_pointer = data->in_gl_resource->cuda_pointer;
......@@ -1480,7 +1482,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
gl_mem->mem.tex_id);
cuda_ret =
cudaGraphicsGLRegisterBuffer (&data->in_gl_resource->cuda_texture,
cuGraphicsGLRegisterBuffer (&data->in_gl_resource->cuda_texture,
gl_buf_obj->id, cudaGraphicsRegisterFlagsReadOnly);
if (cuda_ret != cudaSuccess) {
GST_ERROR_OBJECT (data->nvenc, "failed to register GL texture %u to cuda "
......@@ -1489,7 +1491,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
}
cuda_ret =
cudaGraphicsMapResources (1, &data->in_gl_resource->cuda_texture, 0);
cuGraphicsMapResources (1, &data->in_gl_resource->cuda_texture, 0);
if (cuda_ret != cudaSuccess) {
GST_ERROR_OBJECT (data->nvenc, "failed to map GL texture %u into cuda "
"ret :%d", gl_mem->mem.tex_id, cuda_ret);
......@@ -1497,7 +1499,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
}
cuda_ret =
cudaGraphicsResourceGetMappedPointer (&data->in_gl_resource->
cuGraphicsResourceGetMappedPointer (&data->in_gl_resource->
cuda_plane_pointers[i], &data->in_gl_resource->cuda_num_bytes,
data->in_gl_resource->cuda_texture);
if (cuda_ret != cudaSuccess) {
......@@ -1510,11 +1512,21 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
dest_stride = data->in_gl_resource->cuda_stride;
/* copy into scratch buffer */
cuda_ret =
cudaMemcpy2D (data_pointer, dest_stride,
data->in_gl_resource->cuda_plane_pointers[i], src_stride,
_get_plane_width (data->info, i) * plane_n_components,
_get_plane_height (data->info, i), cudaMemcpyDeviceToDevice);
param.srcXInBytes = 0;
param.srcY = 0;
param.srcMemoryType = CU_MEMORYTYPE_DEVICE;
param.srcDevice = data->in_gl_resource->cuda_plane_pointers[i];
param.srcPitch = src_stride;
param.dstXInBytes = 0;
param.dstY = 0;
param.dstMemoryType = CU_MEMORYTYPE_DEVICE;
param.dstDevice = (CUdeviceptr) data_pointer;
param.dstPitch = dest_stride;
param.WidthInBytes = _get_plane_width (data->info, i) * plane_n_components;
param.Height = _get_plane_height (data->info, i);
cuda_ret = cuMemcpy2D (&param);
if (cuda_ret != cudaSuccess) {
GST_ERROR_OBJECT (data->nvenc, "failed to copy GL texture %u into cuda "
"ret :%d", gl_mem->mem.tex_id, cuda_ret);
......@@ -1522,7 +1534,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
}
cuda_ret =
cudaGraphicsUnmapResources (1, &data->in_gl_resource->cuda_texture, 0);
cuGraphicsUnmapResources (1, &data->in_gl_resource->cuda_texture, 0);
if (cuda_ret != cudaSuccess) {
GST_ERROR_OBJECT (data->nvenc, "failed to unmap GL texture %u from cuda "
"ret :%d", gl_mem->mem.tex_id, cuda_ret);
......@@ -1530,7 +1542,7 @@ _map_gl_input_buffer (GstGLContext * context, struct map_gl_input *data)
}
cuda_ret =
cudaGraphicsUnregisterResource (data->in_gl_resource->cuda_texture);
cuGraphicsUnregisterResource (data->in_gl_resource->cuda_texture);
if (cuda_ret != cudaSuccess) {
GST_ERROR_OBJECT (data->nvenc, "failed to unregister GL texture %u from "
"cuda ret :%d", gl_mem->mem.tex_id, cuda_ret);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment