diff --git a/subprojects/gst-plugins-bad/sys/d3d12/gstd3d11on12.cpp b/subprojects/gst-plugins-bad/sys/d3d12/gstd3d11on12.cpp deleted file mode 100644 index aa8f1f6638..0000000000 --- a/subprojects/gst-plugins-bad/sys/d3d12/gstd3d11on12.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* GStreamer - * Copyright (C) 2023 Seungha Yang - * - * 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. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include "gstd3d11on12.h" -#include -#include - -/* *INDENT-OFF* */ -using namespace Microsoft::WRL; -/* *INDENT-ON* */ - -HRESULT -GstD3D11On12CreateDevice (IUnknown * device, IUnknown * command_queue, - IUnknown ** d3d11on12) -{ - static const D3D_FEATURE_LEVEL feature_levels[] = { - D3D_FEATURE_LEVEL_12_1, - D3D_FEATURE_LEVEL_12_0, - D3D_FEATURE_LEVEL_11_1, - D3D_FEATURE_LEVEL_11_0, - }; - - g_return_val_if_fail (device, E_INVALIDARG); - g_return_val_if_fail (command_queue, E_INVALIDARG); - g_return_val_if_fail (d3d11on12, E_INVALIDARG); - - IUnknown *cq[] = { command_queue }; - - ComPtr < ID3D11Device > d3d11device; - auto hr = D3D11On12CreateDevice (device, D3D11_CREATE_DEVICE_BGRA_SUPPORT, - feature_levels, G_N_ELEMENTS (feature_levels), cq, 1, 0, &d3d11device, - nullptr, nullptr); - - if (FAILED (hr)) - return hr; - - ComPtr < ID3D11On12Device > d3d11on12device; - hr = d3d11device.As (&d3d11on12device); - if (FAILED (hr)) - return hr; - - *d3d11on12 = d3d11on12device.Detach (); - return S_OK; -} - -HRESULT -GstD3D11On12CreateWrappedResource (IUnknown * d3d11on12, IUnknown * resource12, - UINT bind_flags, UINT misc_flags, UINT cpu_access_flags, - UINT structure_byte_stride, UINT in_state, UINT out_state, - ID3D11Resource ** resource11) -{ - g_return_val_if_fail (d3d11on12, E_INVALIDARG); - g_return_val_if_fail (resource12, E_INVALIDARG); - g_return_val_if_fail (resource11, E_INVALIDARG); - - ComPtr < ID3D11On12Device > device; - auto hr = d3d11on12->QueryInterface (IID_PPV_ARGS (&device)); - if (FAILED (hr)) - return hr; - - D3D11_RESOURCE_FLAGS flags = { }; - flags.BindFlags = bind_flags; - flags.MiscFlags = misc_flags; - flags.CPUAccessFlags = cpu_access_flags; - flags.StructureByteStride = structure_byte_stride; - - ComPtr < ID3D11Resource > resource; - hr = device->CreateWrappedResource (resource12, &flags, - (D3D12_RESOURCE_STATES) in_state, (D3D12_RESOURCE_STATES) out_state, - IID_PPV_ARGS (&resource)); - if (FAILED (hr)) - return hr; - - *resource11 = resource.Detach (); - - return S_OK; -} - -HRESULT -GstD3D11On12ReleaseWrappedResource (IUnknown * d3d11on12, - ID3D11Resource ** resources, guint num_resources) -{ - g_return_val_if_fail (d3d11on12, E_INVALIDARG); - - ComPtr < ID3D11On12Device > device; - auto hr = d3d11on12->QueryInterface (IID_PPV_ARGS (&device)); - if (FAILED (hr)) - return hr; - - device->ReleaseWrappedResources (resources, num_resources); - - return S_OK; -} - -HRESULT -GstD3D11On12AcquireWrappedResource (IUnknown * d3d11on12, - ID3D11Resource ** resources, guint num_resources) -{ - g_return_val_if_fail (d3d11on12, E_INVALIDARG); - - ComPtr < ID3D11On12Device > device; - auto hr = d3d11on12->QueryInterface (IID_PPV_ARGS (&device)); - if (FAILED (hr)) - return hr; - - device->AcquireWrappedResources (resources, num_resources); - - return S_OK; -} diff --git a/subprojects/gst-plugins-bad/sys/d3d12/gstd3d11on12.h b/subprojects/gst-plugins-bad/sys/d3d12/gstd3d11on12.h deleted file mode 100644 index 0ed8bcc44b..0000000000 --- a/subprojects/gst-plugins-bad/sys/d3d12/gstd3d11on12.h +++ /dev/null @@ -1,50 +0,0 @@ -/* GStreamer - * Copyright (C) 2023 Seungha Yang - * - * 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 -#include -#include - -G_BEGIN_DECLS - -HRESULT GstD3D11On12CreateDevice (IUnknown * device, - IUnknown * command_queue, - IUnknown ** d3d11on12); - -HRESULT GstD3D11On12CreateWrappedResource (IUnknown * d3d11on12, - IUnknown * resource12, - UINT bind_flags, - UINT misc_flags, - UINT cpu_access_flags, - UINT structure_byte_stride, - UINT in_state, - UINT out_state, - ID3D11Resource ** resource11); - -HRESULT GstD3D11On12ReleaseWrappedResource (IUnknown * d3d11on12, - ID3D11Resource ** resources, - guint num_resources); - -HRESULT GstD3D11On12AcquireWrappedResource (IUnknown * d3d11on12, - ID3D11Resource ** resources, - guint num_resources); - -G_END_DECLS diff --git a/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12device.cpp b/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12device.cpp index 38e69c72b2..f893ecd2de 100644 --- a/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12device.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12device.cpp @@ -23,7 +23,6 @@ #include "gstd3d12.h" #include "gstd3d12-private.h" -#include "gstd3d11on12.h" #include #include #include @@ -87,7 +86,6 @@ struct DeviceInner factory = nullptr; adapter = nullptr; - d3d11on12 = nullptr; ReportLiveObjects (); } @@ -153,8 +151,6 @@ struct DeviceInner ComPtr info_queue; - ComPtr d3d11on12; - GstD3D12CommandQueue *direct_queue = nullptr; GstD3D12CommandQueue *copy_queue = nullptr; @@ -823,51 +819,6 @@ gst_d3d12_device_get_factory_handle (GstD3D12Device * device) return device->priv->inner->factory.Get (); } -gboolean -gst_d3d12_device_get_d3d11on12_device (GstD3D12Device * device, - IUnknown ** d3d11on12) -{ - g_return_val_if_fail (GST_IS_D3D12_DEVICE (device), FALSE); - g_return_val_if_fail (d3d11on12, FALSE); - - auto priv = device->priv->inner; - - std::lock_guard < std::mutex > lk (priv->lock); - if (!priv->d3d11on12) { - ComPtr < ID3D12CommandQueue > cq; - gst_d3d12_command_queue_get_handle (priv->direct_queue, &cq); - auto hr = GstD3D11On12CreateDevice (priv->device.Get (), cq.Get (), - &priv->d3d11on12); - if (!gst_d3d12_result (hr, device)) { - GST_ERROR_OBJECT (device, "Couldn't create d3d11on12 device"); - return FALSE; - } - } - - *d3d11on12 = priv->d3d11on12.Get (); - (*d3d11on12)->AddRef (); - - return TRUE; -} - -void -gst_d3d12_device_lock (GstD3D12Device * device) -{ - g_return_if_fail (GST_IS_D3D12_DEVICE (device)); - - auto priv = device->priv->inner; - priv->extern_lock.lock (); -} - -void -gst_d3d12_device_unlock (GstD3D12Device * device) -{ - g_return_if_fail (GST_IS_D3D12_DEVICE (device)); - - auto priv = device->priv->inner; - priv->extern_lock.unlock (); -} - gboolean gst_d3d12_device_get_format (GstD3D12Device * device, GstVideoFormat format, GstD3D12Format * device_format) diff --git a/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12device.h b/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12device.h index 32efa82faa..9925fda161 100644 --- a/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12device.h +++ b/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12device.h @@ -75,13 +75,6 @@ IDXGIAdapter1 * gst_d3d12_device_get_adapter_handle (GstD3D12Devic IDXGIFactory2 * gst_d3d12_device_get_factory_handle (GstD3D12Device * device); -gboolean gst_d3d12_device_get_d3d11on12_device (GstD3D12Device * device, - IUnknown ** d3d11on12); - -void gst_d3d12_device_lock (GstD3D12Device * device); - -void gst_d3d12_device_unlock (GstD3D12Device * device); - gboolean gst_d3d12_device_get_format (GstD3D12Device * device, GstVideoFormat format, GstD3D12Format * device_format); diff --git a/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12ipcclient.cpp b/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12ipcclient.cpp index 5af8fd0cfe..e0fc737769 100644 --- a/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12ipcclient.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12ipcclient.cpp @@ -609,15 +609,11 @@ gst_d3d12_ipc_client_wait_msg_finish (GstD3D12IpcClient * client) break; case GstD3D12IpcPktType::HAVE_DATA: GST_LOG_OBJECT (client, "Got HAVE-DATA"); - gst_d3d12_device_lock (priv->device); if (!gst_d3d12_ipc_client_have_data (client)) { - gst_d3d12_device_unlock (priv->device); gst_d3d12_ipc_client_abort (client); return; } - gst_d3d12_device_unlock (priv->device); - GST_LOG_OBJECT (client, "Sending READ-DONE"); gst_d3d12_ipc_pkt_build_read_done (conn->client_msg); conn->type = GstD3D12IpcPktType::READ_DONE; diff --git a/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12testsrc.cpp b/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12testsrc.cpp index 3335411e55..1a64553882 100644 --- a/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12testsrc.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d12/gstd3d12testsrc.cpp @@ -35,11 +35,11 @@ #endif #include "gstd3d12testsrc.h" -#include "gstd3d11on12.h" #include "gstd3d12pluginutils.h" #include #include #include +#include #include #include #include @@ -240,12 +240,12 @@ struct RenderContext CloseHandle (event_handle); - /* releasing d3d12/d3d11/d2d shared resource might not thread safe? */ - gst_d3d12_device_lock (device); brush = nullptr; d2d_target = nullptr; wrapped_texture = nullptr; - gst_d3d12_device_unlock (device); + device11on12 = nullptr; + d3d11_context = nullptr; + device11 = nullptr; gst_clear_buffer (&render_buffer); @@ -264,7 +264,8 @@ struct RenderContext GstBuffer *render_buffer = nullptr; GstBufferPool *convert_pool = nullptr; - ComPtr d3d11on12; + ComPtr device11on12; + ComPtr device11; ComPtr d3d11_context; ComPtr d2d_target; ComPtr brush; @@ -1180,6 +1181,13 @@ setup_d2d_render (GstD3D12TestSrc * self, RenderContext * ctx) auto priv = self->priv; HRESULT hr; + static const D3D_FEATURE_LEVEL feature_levels[] = { + D3D_FEATURE_LEVEL_12_1, + D3D_FEATURE_LEVEL_12_0, + D3D_FEATURE_LEVEL_11_1, + D3D_FEATURE_LEVEL_11_0, + }; + if (!priv->d2d_factory) { ComPtr < ID2D1Factory > d2d_factory; hr = D2D1CreateFactory (D2D1_FACTORY_TYPE_MULTI_THREADED, @@ -1193,27 +1201,35 @@ setup_d2d_render (GstD3D12TestSrc * self, RenderContext * ctx) priv->d2d_factory = d2d_factory; } - hr = gst_d3d12_device_get_d3d11on12_device (self->device, &ctx->d3d11on12); - if (!gst_d3d12_result (hr, self->device)) { - GST_ERROR_OBJECT (self, "Couldn't get d3d11on12 device"); - return FALSE; - } + auto device = gst_d3d12_device_get_device_handle (self->device); + auto cq = gst_d3d12_device_get_command_queue (self->device, + D3D12_COMMAND_LIST_TYPE_DIRECT); + ComPtr < ID3D12CommandQueue > cq_handle; + gst_d3d12_command_queue_get_handle (cq, &cq_handle); + IUnknown *cq_list[] = { cq_handle.Get () }; - ComPtr < ID3D11Device > d3d11dev; - hr = ctx->d3d11on12.As (&d3d11dev); + hr = D3D11On12CreateDevice (device, D3D11_CREATE_DEVICE_BGRA_SUPPORT, + feature_levels, G_N_ELEMENTS (feature_levels), cq_list, 1, 0, + &ctx->device11, &ctx->d3d11_context, nullptr); if (!gst_d3d12_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Couldn't get d3d11 device"); return FALSE; } - d3d11dev->GetImmediateContext (&ctx->d3d11_context); + hr = ctx->device11.As (&ctx->device11on12); + if (!gst_d3d12_result (hr, self->device)) { + GST_ERROR_OBJECT (self, "Couldn't get d3d11on12 device"); + return FALSE; + } - hr = GstD3D11On12CreateWrappedResource (ctx->d3d11on12.Get (), - ctx->texture.Get (), - D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE, - D3D11_RESOURCE_MISC_SHARED, 0, 0, + D3D11_RESOURCE_FLAGS flags11 = { }; + flags11.BindFlags = D3D11_BIND_RENDER_TARGET | D3D11_BIND_SHADER_RESOURCE; + flags11.MiscFlags = D3D11_RESOURCE_MISC_SHARED; + + hr = ctx->device11on12->CreateWrappedResource (ctx->texture.Get (), &flags11, D3D12_RESOURCE_STATE_RENDER_TARGET, - D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, &ctx->wrapped_texture); + D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE, + IID_PPV_ARGS (&ctx->wrapped_texture)); if (!gst_d3d12_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Couldn't create wrapped resource"); return FALSE; @@ -1998,11 +2014,9 @@ gst_d3d12_test_src_draw_ball (GstD3D12TestSrc * self) x = 20 + (0.5 + 0.5 * sin (rad)) * (priv->info.width - 40); y = 20 + (0.5 + 0.5 * sin (rad * sqrt (2))) * (priv->info.height - 40); - gst_d3d12_device_lock (self->device); ID3D11Resource *resources[] = { priv->ctx->wrapped_texture.Get () }; - GstD3D11On12AcquireWrappedResource (priv->ctx->d3d11on12.Get (), resources, - 1); + priv->ctx->device11on12->AcquireWrappedResources (resources, 1); priv->ctx->brush->SetCenter (D2D1::Point2F (x, y)); priv->ctx->d2d_target->BeginDraw (); @@ -2010,12 +2024,9 @@ gst_d3d12_test_src_draw_ball (GstD3D12TestSrc * self) priv->ctx->d2d_target->FillEllipse (D2D1::Ellipse (D2D1::Point2F (x, y), 20, 20), priv->ctx->brush.Get ()); priv->ctx->d2d_target->EndDraw (); - - GstD3D11On12ReleaseWrappedResource (priv->ctx->d3d11on12.Get (), resources, - 1); + priv->ctx->device11on12->ReleaseWrappedResources (resources, 1); priv->ctx->d3d11_context->Flush (); - gst_d3d12_device_unlock (self->device); return TRUE; } @@ -2025,25 +2036,19 @@ gst_d3d12_test_src_draw_circular (GstD3D12TestSrc * self) { auto priv = self->priv; - gst_d3d12_device_lock (self->device); ID3D11Resource *resources[] = { priv->ctx->wrapped_texture.Get () }; - GstD3D11On12AcquireWrappedResource (priv->ctx->d3d11on12.Get (), resources, - 1); + priv->ctx->device11on12->AcquireWrappedResources (resources, 1); priv->ctx->d2d_target->BeginDraw (); priv->ctx->d2d_target->Clear (D2D1::ColorF (D2D1::ColorF::Black)); priv->ctx->d2d_target->FillEllipse (D2D1::Ellipse (D2D1::Point2F (priv-> ctx->x, priv->ctx->y), priv->ctx->rad, priv->ctx->rad), priv->ctx->brush.Get ()); priv->ctx->d2d_target->EndDraw (); - - GstD3D11On12ReleaseWrappedResource (priv->ctx->d3d11on12.Get (), resources, - 1); + priv->ctx->device11on12->ReleaseWrappedResources (resources, 1); priv->ctx->d3d11_context->Flush (); - gst_d3d12_device_unlock (self->device); - return TRUE; } diff --git a/subprojects/gst-plugins-bad/sys/d3d12/meson.build b/subprojects/gst-plugins-bad/sys/d3d12/meson.build index 0f0144c03a..0b9761117c 100644 --- a/subprojects/gst-plugins-bad/sys/d3d12/meson.build +++ b/subprojects/gst-plugins-bad/sys/d3d12/meson.build @@ -1,5 +1,4 @@ d3d12_sources = [ - 'gstd3d11on12.cpp', 'gstd3d12av1dec.cpp', 'gstd3d12basefilter.cpp', 'gstd3d12bufferpool.cpp',