hip: Load GL interop related symbols
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8923>
This commit is contained in:
parent
ecaab82f11
commit
04fb36b2f9
42
subprojects/gst-plugins-bad/sys/hip/gsthiploader-gl.h
Normal file
42
subprojects/gst-plugins-bad/sys/hip/gsthiploader-gl.h
Normal file
@ -0,0 +1,42 @@
|
||||
/* GStreamer
|
||||
* Copyright (C) 2025 Seungha Yang <seungha@centricular.com>
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <gst/gst.h>
|
||||
#include <hip/hip_runtime.h>
|
||||
#include <hip/hip_gl_interop.h>
|
||||
#include "gsthip-enums.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
hipError_t HipGLGetDevices (GstHipVendor vendor,
|
||||
unsigned int* pHipDeviceCount,
|
||||
int* pHipDevices,
|
||||
unsigned int hipDeviceCount,
|
||||
hipGLDeviceList deviceList);
|
||||
|
||||
hipError_t HipGraphicsGLRegisterBuffer (GstHipVendor vendor,
|
||||
hipGraphicsResource** resource,
|
||||
unsigned int buffer,
|
||||
unsigned int flags);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -21,6 +21,8 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "gsthip-config.h"
|
||||
|
||||
#include "gsthip.h"
|
||||
#include "gsthiploader.h"
|
||||
#include <gmodule.h>
|
||||
@ -28,6 +30,11 @@
|
||||
#include <hip/nvidia_hip_runtime_api.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_GST_GL
|
||||
#include "gsthiploader-gl.h"
|
||||
#include <cudaGL.h>
|
||||
#endif
|
||||
|
||||
#ifndef GST_DISABLE_GST_DEBUG
|
||||
#define GST_CAT_DEFAULT ensure_debug_category()
|
||||
static GstDebugCategory *
|
||||
@ -80,6 +87,20 @@ struct GstHipFuncTableAmd
|
||||
const HIP_RESOURCE_DESC * pResDesc, const HIP_TEXTURE_DESC * pTexDesc,
|
||||
const HIP_RESOURCE_VIEW_DESC * pResViewDesc);
|
||||
hipError_t (*hipTexObjectDestroy) (hipTextureObject_t texObject);
|
||||
hipError_t (*hipGraphicsMapResources) (int count,
|
||||
hipGraphicsResource_t* resources, hipStream_t stream);
|
||||
hipError_t (*hipGraphicsResourceGetMappedPointer) (void** devPtr,
|
||||
size_t* size, hipGraphicsResource_t resource);
|
||||
hipError_t (*hipGraphicsUnmapResources) (int count,
|
||||
hipGraphicsResource_t* resources, hipStream_t stream);
|
||||
hipError_t (*hipGraphicsUnregisterResource) (hipGraphicsResource_t resource);
|
||||
#ifdef HAVE_GST_GL
|
||||
hipError_t (*hipGLGetDevices) (unsigned int* pHipDeviceCount,
|
||||
int* pHipDevices, unsigned int hipDeviceCount,
|
||||
hipGLDeviceList deviceList);
|
||||
hipError_t (*hipGraphicsGLRegisterBuffer) (hipGraphicsResource** resource,
|
||||
unsigned int buffer, unsigned int flags);
|
||||
#endif
|
||||
};
|
||||
|
||||
struct GstHipFuncTableCuda
|
||||
@ -126,6 +147,20 @@ struct GstHipFuncTableCudaRt
|
||||
cudaError_t (CUDAAPI *cudaMallocHost) (void **ptr, size_t size, unsigned int flags);
|
||||
cudaError_t (CUDAAPI *cudaFreeHost) (void *ptr);
|
||||
cudaError_t (CUDAAPI *cudaStreamSynchronize) (cudaStream_t stream);
|
||||
cudaError_t (CUDAAPI *cudaGraphicsMapResources) (int count,
|
||||
cudaGraphicsResource_t *resources, cudaStream_t stream);
|
||||
cudaError_t (CUDAAPI *cudaGraphicsResourceGetMappedPointer) (void **devPtr,
|
||||
size_t *size, cudaGraphicsResource_t resource);
|
||||
cudaError_t (CUDAAPI *cudaGraphicsUnmapResources) (int count,
|
||||
cudaGraphicsResource_t *resources, cudaStream_t stream);
|
||||
cudaError_t (CUDAAPI *cudaGraphicsUnregisterResource) (cudaGraphicsResource_t resource);
|
||||
#ifdef HAVE_GST_GL
|
||||
cudaError_t (CUDAAPI *cudaGLGetDevices) (unsigned int *pCudaDeviceCount,
|
||||
int *pCudaDevices, unsigned int cudaDeviceCount,
|
||||
enum cudaGLDeviceList deviceList);
|
||||
cudaError_t (CUDAAPI *cudaGraphicsGLRegisterBuffer) (struct cudaGraphicsResource **resource,
|
||||
unsigned int buffer, unsigned int flags);
|
||||
#endif
|
||||
};
|
||||
/* *INDENT-ON* */
|
||||
|
||||
@ -203,6 +238,14 @@ load_amd_func_table (void)
|
||||
LOAD_SYMBOL (hipMemcpyParam2DAsync);
|
||||
LOAD_SYMBOL (hipTexObjectCreate);
|
||||
LOAD_SYMBOL (hipTexObjectDestroy);
|
||||
LOAD_SYMBOL (hipGraphicsMapResources);
|
||||
LOAD_SYMBOL (hipGraphicsResourceGetMappedPointer);
|
||||
LOAD_SYMBOL (hipGraphicsUnmapResources);
|
||||
LOAD_SYMBOL (hipGraphicsUnregisterResource);
|
||||
#ifdef HAVE_GST_GL
|
||||
LOAD_SYMBOL (hipGLGetDevices);
|
||||
LOAD_SYMBOL (hipGraphicsGLRegisterBuffer);
|
||||
#endif
|
||||
|
||||
table->loaded = TRUE;
|
||||
}
|
||||
@ -301,6 +344,14 @@ load_cudart_func_table (guint major_ver, guint minor_ver)
|
||||
LOAD_SYMBOL (cudaMallocHost);
|
||||
LOAD_SYMBOL (cudaFreeHost);
|
||||
LOAD_SYMBOL (cudaStreamSynchronize);
|
||||
LOAD_SYMBOL (cudaGraphicsMapResources);
|
||||
LOAD_SYMBOL (cudaGraphicsResourceGetMappedPointer);
|
||||
LOAD_SYMBOL (cudaGraphicsUnmapResources);
|
||||
LOAD_SYMBOL (cudaGraphicsUnregisterResource);
|
||||
#ifdef HAVE_GST_GL
|
||||
LOAD_SYMBOL (cudaGLGetDevices);
|
||||
LOAD_SYMBOL (cudaGraphicsGLRegisterBuffer);
|
||||
#endif
|
||||
|
||||
table->loaded = TRUE;
|
||||
}
|
||||
@ -987,3 +1038,96 @@ HipTexObjectDestroy (GstHipVendor vendor, hipTextureObject_t texObject)
|
||||
auto cuda_ret = cuda_ftable.cuTexObjectDestroy ((CUtexObject) texObject);
|
||||
return hipCUResultTohipError (cuda_ret);
|
||||
}
|
||||
|
||||
hipError_t
|
||||
HipGraphicsMapResources (GstHipVendor vendor, int count,
|
||||
hipGraphicsResource_t * resources, hipStream_t stream)
|
||||
{
|
||||
CHECK_VENDOR (vendor);
|
||||
|
||||
if (vendor == GST_HIP_VENDOR_AMD)
|
||||
return amd_ftable.hipGraphicsMapResources (count, resources, stream);
|
||||
|
||||
auto cuda_ret = cudart_ftable.cudaGraphicsMapResources (count,
|
||||
(cudaGraphicsResource_t *) resources, stream);
|
||||
return hipCUDAErrorTohipError (cuda_ret);
|
||||
}
|
||||
|
||||
hipError_t
|
||||
HipGraphicsResourceGetMappedPointer (GstHipVendor vendor, void **devPtr,
|
||||
size_t *size, hipGraphicsResource_t resource)
|
||||
{
|
||||
CHECK_VENDOR (vendor);
|
||||
|
||||
if (vendor == GST_HIP_VENDOR_AMD) {
|
||||
return amd_ftable.hipGraphicsResourceGetMappedPointer (devPtr,
|
||||
size, resource);
|
||||
}
|
||||
|
||||
auto cuda_ret = cudart_ftable.cudaGraphicsResourceGetMappedPointer (devPtr,
|
||||
size, (cudaGraphicsResource_t) resource);
|
||||
return hipCUDAErrorTohipError (cuda_ret);
|
||||
}
|
||||
|
||||
hipError_t
|
||||
HipGraphicsUnmapResources (GstHipVendor vendor, int count,
|
||||
hipGraphicsResource_t * resources, hipStream_t stream)
|
||||
{
|
||||
CHECK_VENDOR (vendor);
|
||||
|
||||
if (vendor == GST_HIP_VENDOR_AMD)
|
||||
return amd_ftable.hipGraphicsUnmapResources (count, resources, stream);
|
||||
|
||||
auto cuda_ret = cudart_ftable.cudaGraphicsUnmapResources (count,
|
||||
(cudaGraphicsResource_t *) resources, stream);
|
||||
return hipCUDAErrorTohipError (cuda_ret);
|
||||
}
|
||||
|
||||
hipError_t
|
||||
HipGraphicsUnregisterResource (GstHipVendor vendor,
|
||||
hipGraphicsResource_t resource)
|
||||
{
|
||||
CHECK_VENDOR (vendor);
|
||||
|
||||
if (vendor == GST_HIP_VENDOR_AMD)
|
||||
return amd_ftable.hipGraphicsUnregisterResource (resource);
|
||||
|
||||
auto cuda_ret =
|
||||
cudart_ftable.cudaGraphicsUnregisterResource ((cudaGraphicsResource_t)
|
||||
resource);
|
||||
return hipCUDAErrorTohipError (cuda_ret);
|
||||
}
|
||||
|
||||
#ifdef HAVE_GST_GL
|
||||
hipError_t
|
||||
HipGLGetDevices (GstHipVendor vendor, unsigned int *pHipDeviceCount,
|
||||
int *pHipDevices, unsigned int hipDeviceCount, hipGLDeviceList deviceList)
|
||||
{
|
||||
CHECK_VENDOR (vendor);
|
||||
|
||||
if (vendor == GST_HIP_VENDOR_AMD) {
|
||||
return amd_ftable.hipGLGetDevices (pHipDeviceCount, pHipDevices,
|
||||
hipDeviceCount, deviceList);
|
||||
}
|
||||
|
||||
auto cuda_ret = cudart_ftable.cudaGLGetDevices (pHipDeviceCount, pHipDevices,
|
||||
hipDeviceCount, (enum cudaGLDeviceList) deviceList);
|
||||
return hipCUDAErrorTohipError (cuda_ret);
|
||||
}
|
||||
|
||||
hipError_t
|
||||
HipGraphicsGLRegisterBuffer (GstHipVendor vendor,
|
||||
hipGraphicsResource ** resource, unsigned int buffer, unsigned int flags)
|
||||
{
|
||||
CHECK_VENDOR (vendor);
|
||||
|
||||
if (vendor == GST_HIP_VENDOR_AMD)
|
||||
return amd_ftable.hipGraphicsGLRegisterBuffer (resource, buffer, flags);
|
||||
|
||||
auto cuda_ret =
|
||||
cudart_ftable.cudaGraphicsGLRegisterBuffer ((struct cudaGraphicsResource
|
||||
**) resource,
|
||||
buffer, flags);
|
||||
return hipCUDAErrorTohipError (cuda_ret);
|
||||
}
|
||||
#endif
|
||||
|
@ -113,6 +113,24 @@ hipError_t HipTexObjectCreate (GstHipVendor vendor,
|
||||
hipError_t HipTexObjectDestroy (GstHipVendor vendor,
|
||||
hipTextureObject_t texObject);
|
||||
|
||||
hipError_t HipGraphicsMapResources (GstHipVendor vendor,
|
||||
int count,
|
||||
hipGraphicsResource_t* resources,
|
||||
hipStream_t stream);
|
||||
|
||||
hipError_t HipGraphicsResourceGetMappedPointer (GstHipVendor vendor,
|
||||
void** devPtr,
|
||||
size_t* size,
|
||||
hipGraphicsResource_t resource);
|
||||
|
||||
hipError_t HipGraphicsUnmapResources (GstHipVendor vendor,
|
||||
int count,
|
||||
hipGraphicsResource_t* resources,
|
||||
hipStream_t stream);
|
||||
|
||||
hipError_t HipGraphicsUnregisterResource (GstHipVendor vendor,
|
||||
hipGraphicsResource_t resource);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
||||
|
@ -78,6 +78,11 @@ if gstcuda_dep.found()
|
||||
extra_deps += [gstcuda_dep]
|
||||
endif
|
||||
|
||||
if gstgl_dep.found()
|
||||
hip_cdata.set('HAVE_GST_GL', true)
|
||||
extra_deps += [gstgl_dep]
|
||||
endif
|
||||
|
||||
configure_file(
|
||||
output: 'gsthip-config.h',
|
||||
configuration: hip_cdata,
|
||||
|
@ -26,6 +26,13 @@ typedef enum
|
||||
CU_GL_DEVICE_LIST_ALL = 0x01,
|
||||
} CUGLDeviceList;
|
||||
|
||||
enum cudaGLDeviceList
|
||||
{
|
||||
cudaGLDeviceListAll = 1,
|
||||
cudaGLDeviceListCurrentFrame = 2,
|
||||
cudaGLDeviceListNextFrame = 3
|
||||
};
|
||||
|
||||
#define cuGLGetDevices cuGLGetDevices_v2
|
||||
|
||||
G_END_DECLS
|
||||
|
@ -396,5 +396,9 @@ enum cudaDeviceAttr
|
||||
|
||||
typedef gpointer cudaStream_t;
|
||||
|
||||
struct cudaGraphicsResource;
|
||||
|
||||
typedef struct cudaGraphicsResource *cudaGraphicsResource_t;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
@ -0,0 +1,31 @@
|
||||
/*
|
||||
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
typedef enum hipGLDeviceList {
|
||||
hipGLDeviceListAll = 1, ///< All hip devices used by current OpenGL context.
|
||||
hipGLDeviceListCurrentFrame = 2, ///< Hip devices used by current OpenGL context in current
|
||||
///< frame
|
||||
hipGLDeviceListNextFrame = 3 ///< Hip devices used by current OpenGL context in next
|
||||
///< frame.
|
||||
} hipGLDeviceList;
|
@ -466,6 +466,20 @@ typedef enum hipError_t {
|
||||
hipErrorTbd ///< Marker that more error codes are needed.
|
||||
} hipError_t;
|
||||
|
||||
typedef enum hipGraphicsRegisterFlags {
|
||||
hipGraphicsRegisterFlagsNone = 0,
|
||||
hipGraphicsRegisterFlagsReadOnly = 1, ///< HIP will not write to this registered resource
|
||||
hipGraphicsRegisterFlagsWriteDiscard =
|
||||
2, ///< HIP will only write and will not read from this registered resource
|
||||
hipGraphicsRegisterFlagsSurfaceLoadStore = 4, ///< HIP will bind this resource to a surface
|
||||
hipGraphicsRegisterFlagsTextureGather =
|
||||
8 ///< HIP will perform texture gather operations on this registered resource
|
||||
} hipGraphicsRegisterFlags;
|
||||
|
||||
typedef struct _hipGraphicsResource hipGraphicsResource;
|
||||
|
||||
typedef hipGraphicsResource* hipGraphicsResource_t;
|
||||
|
||||
typedef struct ihipStream_t* hipStream_t;
|
||||
typedef struct ihipModule_t* hipModule_t;
|
||||
typedef struct ihipModuleSymbol_t* hipFunction_t;
|
||||
|
Loading…
x
Reference in New Issue
Block a user