I am engaged on a Unity native plugin that runs a gstreamer pipeline within the background, decodes it utilizing {hardware} decoding, then copies the feel over to a render texture to be displayed in Unity.
I’ve my GStreamer already working, I can run it from Unity and it creates a window with the digital camera output, all decoded on the GPU. From what I can see, GStreamer has a parameter within the d3d11videosink to “draw-on-shared-texture” of format DXGI_FORMAT_R8G8B8A8_UNORM.
It additionally has an sign that will get referred to as when gstreamer is about to attract, and a draw command to attract on a “shared deal with”.
I’ve solely seen code on the market to repeat a decoded texture on the CPU and copying it again on the GPU, however by no means GPU => GPU copies. How do I am going about it?
Additionally, I do know that unity recommends doing all graphic operations within the reader thread utilizing GL.IssuePluginEvent, however how am I supposed to do this when GStreamer would not let me entry the feel once I need, solely in the course of the begin_draw callback.
I do not know a lot about DX11 or native unity plugin usually, and I’m very misplaced. Any assist could be appreciated.
This is some code for my failed try at making an attempt to get GStreamer to attract onto my ID3D11Resource pointer given by unity utilizing RenderTexture.GetNativePtr():
static GstFlowReturn begin_draw_callback(GstElement* videosink, gpointer knowledge)
{
GstApp* app = (GstApp*)knowledge;
ID3D11Resource* resPtr = app->GetResourcePtr();
if (resPtr == nullptr) {
return GST_FLOW_OK;
}
// Your customized code right here
Debug::Log("BEGIN DRAW");
HANDLE deal with;
IDXGIResource1* pResource;
HRESULT res1 = resPtr->QueryInterface(__uuidof(IDXGIResource1), (void**)&pResource);
HRESULT res2 = pResource->CreateSharedHandle(
nullptr, DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, nullptr, &deal with);
std::string res1Str = HRESULTToString(res1);
std::string res2Str = HRESULTToString(res2);
Debug::Log(res1Str);
Debug::Log(res2Str);
gpointer shard_handle = (gpointer)pResource;
guint texture_misc_flags = D3D11_RESOURCE_MISC_FLAG::D3D11_RESOURCE_MISC_SHARED;
guint64 acquire_key = NULL;
guint64 release_key = NULL;
g_signal_emit_by_name(videosink, "draw", shard_handle, texture_misc_flags, acquire_key, release_key, nullptr);
return GST_FLOW_OK;
}