diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device-private.h b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device-private.h new file mode 100644 index 0000000000..e9e7551506 --- /dev/null +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device-private.h @@ -0,0 +1,55 @@ +/* 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 + +G_BEGIN_DECLS + +GST_D3D11_API +gint64 gst_d3d11_pixel_shader_token_new (void); + +GST_D3D11_API +gint64 gst_d3d11_vertex_shader_token_new (void); + +GST_D3D11_API +HRESULT gst_d3d11_device_get_pixel_shader (GstD3D11Device * device, + gint64 token, + const void * bytecode, + gsize bytecode_size, + const gchar * source, + const gchar * entry_point, + ID3D11PixelShader ** ps); + +GST_D3D11_API +HRESULT gst_d3d11_device_get_vertex_shader (GstD3D11Device * device, + gint64 token, + const void * bytecode, + gsize bytecode_size, + const gchar * source, + const gchar * entry_point, + const D3D11_INPUT_ELEMENT_DESC * input_desc, + guint desc_len, + ID3D11VertexShader ** vs, + ID3D11InputLayout ** layout); + +G_END_DECLS + diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device.cpp b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device.cpp index 93bd366bfc..9c01daa754 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device.cpp +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device.cpp @@ -23,15 +23,22 @@ #endif #include "gstd3d11device.h" +#include "gstd3d11device-private.h" #include "gstd3d11utils.h" #include "gstd3d11format.h" #include "gstd3d11-private.h" #include "gstd3d11memory.h" +#include "gstd3d11compile.h" +#include "gstd3d11shadercache.h" #include #include #include #include +#include +#include +#include +#include /** * SECTION:gstd3d11device @@ -92,42 +99,49 @@ enum #define DEFAULT_ADAPTER 0 #define DEFAULT_CREATE_FLAGS 0 +/* *INDENT-OFF* */ struct _GstD3D11DevicePrivate { - guint adapter; - guint device_id; - guint vendor_id; - gboolean hardware; - gchar *description; - guint create_flags; - gint64 adapter_luid; + guint adapter = 0; + guint device_id = 0; + guint vendor_id = 0; + gboolean hardware = 0; + gchar *description = nullptr; + guint create_flags = 0; + gint64 adapter_luid = 0; - ID3D11Device *device; - ID3D11Device5 *device5; - ID3D11DeviceContext *device_context; - ID3D11DeviceContext4 *device_context4; + ID3D11Device *device = nullptr; + ID3D11Device5 *device5 = nullptr; + ID3D11DeviceContext *device_context = nullptr; + ID3D11DeviceContext4 *device_context4 = nullptr; - ID3D11VideoDevice *video_device; - ID3D11VideoContext *video_context; + ID3D11VideoDevice *video_device = nullptr; + ID3D11VideoContext *video_context = nullptr; - IDXGIFactory1 *factory; - GArray *format_table; + IDXGIFactory1 *factory = nullptr; + GArray *format_table = nullptr; - CRITICAL_SECTION extern_lock; - SRWLOCK resource_lock; + std::recursive_mutex extern_lock; + std::mutex resource_lock; LARGE_INTEGER frequency; + D3D_FEATURE_LEVEL feature_level; + std::map > ps_cache; + std::map , ComPtr>> vs_cache; + #if HAVE_D3D11SDKLAYERS_H - ID3D11Debug *d3d11_debug; - ID3D11InfoQueue *d3d11_info_queue; + ID3D11Debug *d3d11_debug = nullptr; + ID3D11InfoQueue *d3d11_info_queue = nullptr; #endif #if HAVE_DXGIDEBUG_H - IDXGIDebug *dxgi_debug; - IDXGIInfoQueue *dxgi_info_queue; + IDXGIDebug *dxgi_debug = nullptr; + IDXGIInfoQueue *dxgi_info_queue = nullptr; #endif }; +/* *INDENT-ON* */ static void debug_init_once (void) @@ -144,7 +158,7 @@ debug_init_once (void) #define gst_d3d11_device_parent_class parent_class G_DEFINE_TYPE_WITH_CODE (GstD3D11Device, gst_d3d11_device, GST_TYPE_OBJECT, - G_ADD_PRIVATE (GstD3D11Device); debug_init_once ()); + debug_init_once ()); static void gst_d3d11_device_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); @@ -405,14 +419,11 @@ gst_d3d11_device_init (GstD3D11Device * self) { GstD3D11DevicePrivate *priv; - priv = (GstD3D11DevicePrivate *) - gst_d3d11_device_get_instance_private (self); + priv = new GstD3D11DevicePrivate (); priv->adapter = DEFAULT_ADAPTER; priv->format_table = g_array_sized_new (FALSE, FALSE, sizeof (GstD3D11Format), GST_D3D11_N_FORMATS); - InitializeCriticalSection (&priv->extern_lock); - self->priv = priv; } @@ -732,6 +743,9 @@ gst_d3d11_device_dispose (GObject * object) GST_LOG_OBJECT (self, "dispose"); + priv->ps_cache.clear (); + priv->vs_cache.clear (); + GST_D3D11_CLEAR_COM (priv->device5); GST_D3D11_CLEAR_COM (priv->device_context4); GST_D3D11_CLEAR_COM (priv->video_device); @@ -763,9 +777,10 @@ gst_d3d11_device_finalize (GObject * object) GST_LOG_OBJECT (self, "finalize"); g_array_unref (priv->format_table); - DeleteCriticalSection (&priv->extern_lock); g_free (priv->description); + delete priv; + G_OBJECT_CLASS (parent_class)->finalize (object); } @@ -1113,6 +1128,7 @@ gst_d3d11_device_new_internal (const GstD3D11DeviceConstructData * data) priv->description = g_utf16_to_utf8 ((gunichar2 *) adapter_desc.Description, -1, nullptr, nullptr, nullptr); priv->adapter_luid = gst_d3d11_luid_to_int64 (&adapter_desc.AdapterLuid); + priv->feature_level = priv->device->GetFeatureLevel (); DXGI_ADAPTER_DESC1 desc1; hr = adapter->GetDesc1 (&desc1); @@ -1276,7 +1292,7 @@ gst_d3d11_device_get_video_device_handle (GstD3D11Device * device) g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL); priv = device->priv; - GstD3D11SRWLockGuard lk (&priv->resource_lock); + std::lock_guard < std::mutex > lk (priv->resource_lock); if (!priv->video_device) { HRESULT hr; ID3D11VideoDevice *video_device = NULL; @@ -1309,7 +1325,7 @@ gst_d3d11_device_get_video_context_handle (GstD3D11Device * device) g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL); priv = device->priv; - GstD3D11SRWLockGuard lk (&priv->resource_lock); + std::lock_guard < std::mutex > lk (priv->resource_lock); if (!priv->video_context) { HRESULT hr; ID3D11VideoContext *video_context = NULL; @@ -1342,7 +1358,7 @@ gst_d3d11_device_lock (GstD3D11Device * device) priv = device->priv; GST_TRACE_OBJECT (device, "device locking"); - EnterCriticalSection (&priv->extern_lock); + priv->extern_lock.lock (); GST_TRACE_OBJECT (device, "device locked"); } @@ -1364,7 +1380,7 @@ gst_d3d11_device_unlock (GstD3D11Device * device) priv = device->priv; - LeaveCriticalSection (&priv->extern_lock); + priv->extern_lock.unlock (); GST_TRACE_OBJECT (device, "device unlocked"); } @@ -1664,3 +1680,165 @@ gst_d3d11_fence_wait (GstD3D11Fence * fence) return TRUE; } + +gint64 +gst_d3d11_pixel_shader_token_new (void) +{ + /* *INDENT-OFF* */ + static std::atomic < gint64 > token_ { 0 }; + /* *INDENT-ON* */ + + return token_.fetch_add (1); +} + +gint64 +gst_d3d11_vertex_shader_token_new (void) +{ + /* *INDENT-OFF* */ + static std::atomic < gint64 > token_ { 0 }; + /* *INDENT-ON* */ + + return token_.fetch_add (1); +} + +HRESULT +gst_d3d11_device_get_pixel_shader (GstD3D11Device * device, gint64 token, + const void *bytecode, gsize bytecode_len, const gchar * source, + const gchar * entry_point, ID3D11PixelShader ** ps) +{ + GstD3D11DevicePrivate *priv = device->priv; + HRESULT hr; + ComPtr < ID3D11PixelShader > shader; + + GST_DEBUG_OBJECT (device, "Getting pixel shader \"%s\" for token %" + G_GINT64_FORMAT, entry_point, token); + + std::lock_guard < std::mutex > lk (priv->resource_lock); + auto cached = priv->ps_cache.find (token); + if (cached != priv->ps_cache.end ()) { + GST_DEBUG_OBJECT (device, + "Found cached pixel shader \"%s\" for token %" G_GINT64_FORMAT, + entry_point, token); + *ps = cached->second.Get (); + (*ps)->AddRef (); + return S_OK; + } + + GST_LOG_OBJECT (device, + "Creating pixel shader for token %" G_GINT64_FORMAT ", source:\n%s", + token, source); + + if (priv->feature_level >= D3D_FEATURE_LEVEL_11_0) { + ComPtr < ID3DBlob > blob; + const void *data; + gsize size; + + if (bytecode && bytecode_len > 1) { + data = bytecode; + size = bytecode_len; + GST_DEBUG_OBJECT (device, + "Creating shader \"%s\" using precompiled bytecode", entry_point); + } else { + hr = gst_d3d11_shader_cache_get_pixel_shader_blob (token, + source, entry_point, &blob); + if (!gst_d3d11_result (hr, device)) + return hr; + + data = blob->GetBufferPointer (); + size = blob->GetBufferSize (); + } + + hr = priv->device->CreatePixelShader (data, size, nullptr, &shader); + if (!gst_d3d11_result (hr, device)) + return hr; + } else { + hr = gst_d3d11_create_pixel_shader_simple (device, source, entry_point, + &shader); + if (!gst_d3d11_result (hr, device)) + return hr; + } + + GST_DEBUG_OBJECT (device, + "Created pixel shader \"%s\" for token %" G_GINT64_FORMAT, + entry_point, token); + priv->ps_cache[token] = shader; + *ps = shader.Detach (); + + return S_OK; +} + +HRESULT +gst_d3d11_device_get_vertex_shader (GstD3D11Device * device, gint64 token, + const void *bytecode, gsize bytecode_len, const gchar * source, + const gchar * entry_point, const D3D11_INPUT_ELEMENT_DESC * input_desc, + guint desc_len, ID3D11VertexShader ** vs, ID3D11InputLayout ** layout) +{ + GstD3D11DevicePrivate *priv = device->priv; + HRESULT hr; + ComPtr < ID3D11VertexShader > shader; + ComPtr < ID3D11InputLayout > input_layout; + + GST_DEBUG_OBJECT (device, "Getting vertext shader \"%s\" for token %" + G_GINT64_FORMAT, entry_point, token); + + std::lock_guard < std::mutex > lk (priv->resource_lock); + auto cached = priv->vs_cache.find (token); + if (cached != priv->vs_cache.end ()) { + GST_DEBUG_OBJECT (device, + "Found cached vertex shader \"%s\" for token %" G_GINT64_FORMAT, + entry_point, token); + *vs = cached->second.first.Get (); + *layout = cached->second.second.Get (); + (*vs)->AddRef (); + (*layout)->AddRef (); + return S_OK; + } + + GST_LOG_OBJECT (device, + "Creating vertex shader for token %" G_GINT64_FORMAT ", shader: \n%s", + token, source); + + if (priv->feature_level >= D3D_FEATURE_LEVEL_11_0) { + ComPtr < ID3DBlob > blob; + const void *data; + gsize size; + + if (bytecode && bytecode_len > 1) { + data = bytecode; + size = bytecode_len; + GST_DEBUG_OBJECT (device, + "Creating shader \"%s\" using precompiled bytecode", entry_point); + } else { + hr = gst_d3d11_shader_cache_get_vertex_shader_blob (token, + source, entry_point, &blob); + if (!gst_d3d11_result (hr, device)) + return hr; + + data = blob->GetBufferPointer (); + size = blob->GetBufferSize (); + } + + hr = priv->device->CreateVertexShader (data, size, nullptr, &shader); + if (!gst_d3d11_result (hr, device)) + return hr; + + hr = priv->device->CreateInputLayout (input_desc, desc_len, data, + size, &input_layout); + if (!gst_d3d11_result (hr, device)) + return hr; + } else { + hr = gst_d3d11_create_vertex_shader_simple (device, source, entry_point, + input_desc, desc_len, &shader, &input_layout); + if (!gst_d3d11_result (hr, device)) + return hr; + } + + GST_DEBUG_OBJECT (device, "Created vertex shader \"%s\" for token %" + G_GINT64_FORMAT, entry_point, token); + priv->vs_cache[token] = std::make_pair (shader, input_layout); + + *vs = shader.Detach (); + *layout = input_layout.Detach (); + + return S_OK; +} diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.cpp b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.cpp new file mode 100644 index 0000000000..f9f7e8cadf --- /dev/null +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.cpp @@ -0,0 +1,82 @@ +/* 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 "gstd3d11shadercache.h" +#include "gstd3d11compile.h" +#include +#include +#include + +/* *INDENT-OFF* */ +static std::mutex cache_lock_; +static std::map ps_blob_; +static std::map vs_blob_; +/* *INDENT-ON* */ + +HRESULT +gst_d3d11_shader_cache_get_pixel_shader_blob (gint64 token, + const gchar * source, const gchar * entry_point, ID3DBlob ** blob) +{ + std::lock_guard < std::mutex > lk (cache_lock_); + + auto cached = ps_blob_.find (token); + if (cached != ps_blob_.end ()) { + *blob = cached->second; + cached->second->AddRef (); + return S_OK; + } + + HRESULT hr = gst_d3d11_compile (source, strlen (source), nullptr, nullptr, + nullptr, entry_point, "ps_5_0", 0, 0, blob, nullptr); + if (FAILED (hr)) + return hr; + + (*blob)->AddRef (); + ps_blob_[token] = *blob; + + return S_OK; +} + +HRESULT +gst_d3d11_shader_cache_get_vertex_shader_blob (gint64 token, + const gchar * source, const gchar * entry_point, ID3DBlob ** blob) +{ + std::lock_guard < std::mutex > lk (cache_lock_); + + auto cached = vs_blob_.find (token); + if (cached != vs_blob_.end ()) { + *blob = cached->second; + cached->second->AddRef (); + return S_OK; + } + + HRESULT hr = gst_d3d11_compile (source, strlen (source), nullptr, nullptr, + nullptr, entry_point, "vs_5_0", 0, 0, blob, nullptr); + if (FAILED (hr)) + return hr; + + (*blob)->AddRef (); + vs_blob_[token] = *blob; + + return S_OK; +} diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.h b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.h new file mode 100644 index 0000000000..2c50f26112 --- /dev/null +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.h @@ -0,0 +1,38 @@ +/* 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 + +G_BEGIN_DECLS + +HRESULT gst_d3d11_shader_cache_get_pixel_shader_blob (gint64 token, + const gchar * source, + const gchar * entry_point, + ID3DBlob ** blob); + +HRESULT gst_d3d11_shader_cache_get_vertex_shader_blob (gint64 token, + const gchar * source, + const gchar * entry_point, + ID3DBlob ** blob); + +G_END_DECLS + diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/meson.build b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/meson.build index f9f606918d..eaf566a171 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/meson.build +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/meson.build @@ -5,6 +5,7 @@ d3d11_sources = [ 'gstd3d11device.cpp', 'gstd3d11format.cpp', 'gstd3d11memory.cpp', + 'gstd3d11shadercache.cpp', 'gstd3d11utils.cpp', ] diff --git a/subprojects/gst-plugins-bad/meson_options.txt b/subprojects/gst-plugins-bad/meson_options.txt index 402e098277..05f5115bc7 100644 --- a/subprojects/gst-plugins-bad/meson_options.txt +++ b/subprojects/gst-plugins-bad/meson_options.txt @@ -100,6 +100,7 @@ option('curl-ssh2', type : 'feature', value : 'auto', description : 'cURL networ option('d3dvideosink', type : 'feature', value : 'auto', description : 'Direct3D video sink plugin') option('d3d11', type : 'feature', value : 'auto', description : 'Direct3D11 plugin') option('d3d11-wgc', type : 'feature', value : 'auto', description : 'Windows Graphics Capture API support in d3d11 plugin') +option('d3d11-hlsl-precompile', type : 'feature', value : 'auto', description : 'Enable buildtime HLSL compile for d3d11 library/plugin') option('d3d12', type : 'feature', value : 'auto', description : 'Direct3D12 plugin') option('dash', type : 'feature', value : 'auto', description : 'DASH demuxer plugin') option('dc1394', type : 'feature', value : 'auto', description : 'libdc1394 IIDC camera source plugin') diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp index 04c15a0afc..a35412c99f 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11compositor.cpp @@ -150,109 +150,6 @@ gst_d3d11_compositor_sizing_policy_get_type (void) } /* *INDENT-OFF* */ -static const gchar checker_vs_src[] = - "struct VS_INPUT\n" - "{\n" - " float4 Position : POSITION;\n" - "};\n" - "\n" - "struct VS_OUTPUT\n" - "{\n" - " float4 Position: SV_POSITION;\n" - "};\n" - "\n" - "VS_OUTPUT main(VS_INPUT input)\n" - "{\n" - " return input;\n" - "}\n"; - -static const gchar checker_ps_src_rgb[] = - "static const float blocksize = 8.0;\n" - "static const float4 high = float4(0.667, 0.667, 0.667, 1.0);\n" - "static const float4 low = float4(0.333, 0.333, 0.333, 1.0);\n" - "struct PS_INPUT\n" - "{\n" - " float4 Position: SV_POSITION;\n" - "};\n" - "struct PS_OUTPUT\n" - "{\n" - " float4 Plane: SV_TARGET;\n" - "};\n" - "PS_OUTPUT main(PS_INPUT input)\n" - "{\n" - " PS_OUTPUT output;\n" - " if ((input.Position.x % (blocksize * 2.0)) >= blocksize) {\n" - " if ((input.Position.y % (blocksize * 2.0)) >= blocksize)\n" - " output.Plane = low;\n" - " else\n" - " output.Plane = high;\n" - " } else {\n" - " if ((input.Position.y % (blocksize * 2.0)) < blocksize)\n" - " output.Plane = low;\n" - " else\n" - " output.Plane = high;\n" - " }\n" - " return output;\n" - "}\n"; - -static const gchar checker_ps_src_vuya[] = - "static const float blocksize = 8.0;\n" - "static const float4 high = float4(0.5, 0.5, 0.667, 1.0);\n" - "static const float4 low = float4(0.5, 0.5, 0.333, 1.0);\n" - "struct PS_INPUT\n" - "{\n" - " float4 Position: SV_POSITION;\n" - "};\n" - "struct PS_OUTPUT\n" - "{\n" - " float4 Plane: SV_TARGET;\n" - "};\n" - "PS_OUTPUT main(PS_INPUT input)\n" - "{\n" - " PS_OUTPUT output;\n" - " if ((input.Position.x % (blocksize * 2.0)) >= blocksize) {\n" - " if ((input.Position.y % (blocksize * 2.0)) >= blocksize)\n" - " output.Plane = low;\n" - " else\n" - " output.Plane = high;\n" - " } else {\n" - " if ((input.Position.y % (blocksize * 2.0)) < blocksize)\n" - " output.Plane = low;\n" - " else\n" - " output.Plane = high;\n" - " }\n" - " return output;\n" - "}\n"; - -static const gchar checker_ps_src_luma[] = - "static const float blocksize = 8.0;\n" - "static const float4 high = float4(0.667, 0.0, 0.0, 1.0);\n" - "static const float4 low = float4(0.333, 0.0, 0.0, 1.0);\n" - "struct PS_INPUT\n" - "{\n" - " float4 Position: SV_POSITION;\n" - "};\n" - "struct PS_OUTPUT\n" - "{\n" - " float4 Plane: SV_TARGET;\n" - "};\n" - "PS_OUTPUT main(PS_INPUT input)\n" - "{\n" - " PS_OUTPUT output;\n" - " if ((input.Position.x % (blocksize * 2.0)) >= blocksize) {\n" - " if ((input.Position.y % (blocksize * 2.0)) >= blocksize)\n" - " output.Plane = low;\n" - " else\n" - " output.Plane = high;\n" - " } else {\n" - " if ((input.Position.y % (blocksize * 2.0)) < blocksize)\n" - " output.Plane = low;\n" - " else\n" - " output.Plane = high;\n" - " }\n" - " return output;\n" - "}\n"; - static D3D11_RENDER_TARGET_BLEND_DESC blend_templ[] = { /* SOURCE */ { @@ -1934,7 +1831,6 @@ gst_d3d11_compositor_create_checker_quad (GstD3D11Compositor * self, ID3D11Device *device_handle; ID3D11DeviceContext *context_handle; D3D11_MAPPED_SUBRESOURCE map; - D3D11_INPUT_ELEMENT_DESC input_desc; D3D11_BUFFER_DESC buffer_desc; ComPtr < ID3D11Buffer > vertex_buffer; ComPtr < ID3D11Buffer > index_buffer; @@ -1942,36 +1838,24 @@ gst_d3d11_compositor_create_checker_quad (GstD3D11Compositor * self, ComPtr < ID3D11VertexShader > vs; ComPtr < ID3D11InputLayout > layout; HRESULT hr; - const gchar *ps_src; device_handle = gst_d3d11_device_get_device_handle (self->device); context_handle = gst_d3d11_device_get_device_context_handle (self->device); if (GST_VIDEO_INFO_IS_RGB (info)) { - ps_src = checker_ps_src_rgb; + hr = gst_d3d11_get_pixel_shader_checker_rgb (self->device, &ps); } else if (GST_VIDEO_INFO_FORMAT (info) == GST_VIDEO_FORMAT_VUYA) { - ps_src = checker_ps_src_vuya; + hr = gst_d3d11_get_pixel_shader_checker_vuya (self->device, &ps); } else { - ps_src = checker_ps_src_luma; + hr = gst_d3d11_get_pixel_shader_checker_luma (self->device, &ps); } - hr = gst_d3d11_create_pixel_shader_simple (self->device, ps_src, "main", &ps); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Couldn't setup pixel shader"); return nullptr; } - memset (&input_desc, 0, sizeof (D3D11_INPUT_ELEMENT_DESC)); - input_desc.SemanticName = "POSITION"; - input_desc.SemanticIndex = 0; - input_desc.Format = DXGI_FORMAT_R32G32B32_FLOAT; - input_desc.InputSlot = 0; - input_desc.AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; - input_desc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; - input_desc.InstanceDataStepRate = 0; - - hr = gst_d3d11_create_vertex_shader_simple (self->device, checker_vs_src, - "main", &input_desc, 1, &vs, &layout); + hr = gst_d3d11_get_vertex_shader_pos (self->device, &vs, &layout); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Couldn't setup vertex shader"); return nullptr; diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11dxgicapture.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11dxgicapture.cpp index 1622a98d42..939503bac5 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11dxgicapture.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11dxgicapture.cpp @@ -624,62 +624,18 @@ private: bool InitShader (GstD3D11Device * device) { - static const gchar vs_str[] = - "struct VS_INPUT {\n" - " float4 Position: POSITION;\n" - " float2 Texture: TEXCOORD;\n" - "};\n" - "\n" - "struct VS_OUTPUT {\n" - " float4 Position: SV_POSITION;\n" - " float2 Texture: TEXCOORD;\n" - "};\n" - "\n" - "VS_OUTPUT main (VS_INPUT input)\n" - "{\n" - " return input;\n" - "}"; - - static const gchar ps_str[] = - "Texture2D shaderTexture;\n" - "SamplerState samplerState;\n" - "\n" - "struct PS_INPUT {\n" - " float4 Position: SV_POSITION;\n" - " float2 Texture: TEXCOORD;\n" - "};\n" - "\n" - "struct PS_OUTPUT {\n" - " float4 Plane: SV_Target;\n" - "};\n" - "\n" - "PS_OUTPUT main(PS_INPUT input)\n" - "{\n" - " PS_OUTPUT output;\n" - " output.Plane = shaderTexture.Sample(samplerState, input.Texture);\n" - " return output;\n" - "}"; - - D3D11_INPUT_ELEMENT_DESC input_desc[] = { - {"POSITION", - 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, - {"TEXCOORD", - 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0} - }; - ComPtr vs; + ComPtr ps; ComPtr layout; HRESULT hr; - hr = gst_d3d11_create_vertex_shader_simple (device, - vs_str, "main", input_desc, G_N_ELEMENTS (input_desc), &vs, &layout); + hr = gst_d3d11_get_vertex_shader_coord (device, &vs, &layout); if (!gst_d3d11_result (hr, device)) { GST_ERROR ("Failed to create vertex shader"); return false; } - ComPtr ps; - hr = gst_d3d11_create_pixel_shader_simple (device, ps_str, "main", &ps); + hr = gst_d3d11_get_pixel_shader_sample (device, &ps); if (!gst_d3d11_result (hr, device)) { GST_ERROR ("Failed to create pixel shader"); return false; diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11overlaycompositor.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11overlaycompositor.cpp index 466cb04208..fc6eaf4738 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11overlaycompositor.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11overlaycompositor.cpp @@ -47,56 +47,6 @@ typedef struct } texture; } VertexData; -static const gchar templ_pixel_shader[] = - "Texture2D shaderTexture;\n" - "SamplerState samplerState;\n" - "struct PS_INPUT\n" - "{\n" - " float4 Position: SV_POSITION;\n" - " float2 Texture: TEXCOORD;\n" - "};\n" - "float4 main(PS_INPUT input): SV_TARGET\n" - "{\n" - " return shaderTexture.Sample(samplerState, input.Texture);\n" - "}\n"; - -static const gchar templ_premul_pixel_shader[] = - "Texture2D shaderTexture;\n" - "SamplerState samplerState;\n" - "struct PS_INPUT\n" - "{\n" - " float4 Position: SV_POSITION;\n" - " float2 Texture: TEXCOORD;\n" - "};\n" - "float4 main(PS_INPUT input): SV_TARGET\n" - "{\n" - " float4 sample = shaderTexture.Sample(samplerState, input.Texture);\n" - " float4 premul_sample;\n" - " premul_sample.r = saturate (sample.r * sample.a);\n" - " premul_sample.g = saturate (sample.g * sample.a);\n" - " premul_sample.b = saturate (sample.b * sample.a);\n" - " premul_sample.a = sample.a;\n" - " return premul_sample;\n" - "}\n"; - -static const gchar templ_vertex_shader[] = - "struct VS_INPUT\n" - "{\n" - " float4 Position : POSITION;\n" - " float2 Texture : TEXCOORD;\n" - "};\n" - "\n" - "struct VS_OUTPUT\n" - "{\n" - " float4 Position: SV_POSITION;\n" - " float2 Texture: TEXCOORD;\n" - "};\n" - "\n" - "VS_OUTPUT main(VS_INPUT input)\n" - "{\n" - " return input;\n" - "}\n"; - struct GstD3D11CompositionOverlay { ~GstD3D11CompositionOverlay () @@ -378,7 +328,6 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self) GstD3D11Device *device = self->device; HRESULT hr; D3D11_SAMPLER_DESC sampler_desc; - D3D11_INPUT_ELEMENT_DESC input_desc[2]; D3D11_BUFFER_DESC buffer_desc; D3D11_BLEND_DESC blend_desc; D3D11_MAPPED_SUBRESOURCE map; @@ -394,7 +343,6 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self) ComPtr < ID3D11Buffer > index_buffer; memset (&sampler_desc, 0, sizeof (sampler_desc)); - memset (input_desc, 0, sizeof (input_desc)); memset (&buffer_desc, 0, sizeof (buffer_desc)); memset (&blend_desc, 0, sizeof (blend_desc)); @@ -417,40 +365,21 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self) return FALSE; } - hr = gst_d3d11_create_pixel_shader_simple (device, - templ_pixel_shader, "main", &ps); + hr = gst_d3d11_get_pixel_shader_sample (device, &ps); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Couldn't create pixel shader"); return FALSE; } - hr = gst_d3d11_create_pixel_shader_simple (device, - templ_premul_pixel_shader, "main", &premul_ps); + hr = gst_d3d11_get_pixel_shader_sample_premul (device, &premul_ps); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Couldn't create premul pixel shader"); return FALSE; } - input_desc[0].SemanticName = "POSITION"; - input_desc[0].SemanticIndex = 0; - input_desc[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; - input_desc[0].InputSlot = 0; - input_desc[0].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; - input_desc[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; - input_desc[0].InstanceDataStepRate = 0; - - input_desc[1].SemanticName = "TEXCOORD"; - input_desc[1].SemanticIndex = 0; - input_desc[1].Format = DXGI_FORMAT_R32G32_FLOAT; - input_desc[1].InputSlot = 0; - input_desc[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; - input_desc[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; - input_desc[1].InstanceDataStepRate = 0; - - hr = gst_d3d11_create_vertex_shader_simple (device, templ_vertex_shader, - "main", input_desc, G_N_ELEMENTS (input_desc), &vs, &layout); + hr = gst_d3d11_get_vertex_shader_coord (device, &vs, &layout); if (!gst_d3d11_result (hr, device)) { - GST_ERROR_OBJECT (self, "Couldn't vertex pixel shader"); + GST_ERROR_OBJECT (self, "Couldn't create vertex pixel shader"); return FALSE; } diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp index cd57031170..25d0dc8b07 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp @@ -26,10 +26,17 @@ #include #include +#include + +#include "hlsl/gstd3d11-hlsl.h" GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_plugin_utils_debug); #define GST_CAT_DEFAULT gst_d3d11_plugin_utils_debug +/* *INDENT-OFF* */ +using namespace Microsoft::WRL; +/* *INDENT-ON* */ + /** * GstD3D11AlphaMode: * @@ -688,3 +695,216 @@ gst_d3d11_buffer_pool_new_with_options (GstD3D11Device * device, return pool; } + +HRESULT +gst_d3d11_get_pixel_shader_checker_luma (GstD3D11Device * device, + ID3D11PixelShader ** ps) +{ + static gint64 token = 0; + + GST_D3D11_CALL_ONCE_BEGIN { + token = gst_d3d11_pixel_shader_token_new (); + } GST_D3D11_CALL_ONCE_END; + + return gst_d3d11_device_get_pixel_shader (device, token, + g_PSMain_checker_luma, sizeof (g_PSMain_checker_luma), + g_PSMain_checker_luma_str, "PSMain_checker_luma", ps); +} + +HRESULT +gst_d3d11_get_pixel_shader_checker_rgb (GstD3D11Device * device, + ID3D11PixelShader ** ps) +{ + static gint64 token = 0; + + GST_D3D11_CALL_ONCE_BEGIN { + token = gst_d3d11_pixel_shader_token_new (); + } GST_D3D11_CALL_ONCE_END; + + return gst_d3d11_device_get_pixel_shader (device, token, + g_PSMain_checker_rgb, sizeof (g_PSMain_checker_rgb), + g_PSMain_checker_rgb_str, "PSMain_checker_rgb", ps); +} + +HRESULT +gst_d3d11_get_pixel_shader_checker_vuya (GstD3D11Device * device, + ID3D11PixelShader ** ps) +{ + static gint64 token = 0; + + GST_D3D11_CALL_ONCE_BEGIN { + token = gst_d3d11_pixel_shader_token_new (); + } GST_D3D11_CALL_ONCE_END; + + return gst_d3d11_device_get_pixel_shader (device, token, + g_PSMain_checker_vuya, sizeof (g_PSMain_checker_vuya), + g_PSMain_checker_vuya_str, "PSMain_checker_vuya", ps); +} + +HRESULT +gst_d3d11_get_pixel_shader_checker (GstD3D11Device * device, + ID3D11PixelShader ** ps) +{ + static gint64 token = 0; + + GST_D3D11_CALL_ONCE_BEGIN { + token = gst_d3d11_pixel_shader_token_new (); + } GST_D3D11_CALL_ONCE_END; + + return gst_d3d11_device_get_pixel_shader (device, token, + g_PSMain_checker, sizeof (g_PSMain_checker), + g_PSMain_checker_str, "PSMain_checker", ps); +} + +HRESULT +gst_d3d11_get_pixel_shader_color (GstD3D11Device * device, + ID3D11PixelShader ** ps) +{ + static gint64 token = 0; + + GST_D3D11_CALL_ONCE_BEGIN { + token = gst_d3d11_pixel_shader_token_new (); + } GST_D3D11_CALL_ONCE_END; + + return gst_d3d11_device_get_pixel_shader (device, token, + g_PSMain_color, sizeof (g_PSMain_color), + g_PSMain_color_str, "PSMain_color", ps); +} + +HRESULT +gst_d3d11_get_pixel_shader_sample_premul (GstD3D11Device * device, + ID3D11PixelShader ** ps) +{ + static gint64 token = 0; + + GST_D3D11_CALL_ONCE_BEGIN { + token = gst_d3d11_pixel_shader_token_new (); + } GST_D3D11_CALL_ONCE_END; + + return gst_d3d11_device_get_pixel_shader (device, token, + g_PSMain_sample_premul, sizeof (g_PSMain_sample_premul), + g_PSMain_sample_premul_str, "PSMain_sample_premul", ps); +} + +HRESULT +gst_d3d11_get_pixel_shader_sample (GstD3D11Device * device, + ID3D11PixelShader ** ps) +{ + static gint64 token = 0; + + GST_D3D11_CALL_ONCE_BEGIN { + token = gst_d3d11_pixel_shader_token_new (); + } GST_D3D11_CALL_ONCE_END; + + return gst_d3d11_device_get_pixel_shader (device, token, + g_PSMain_sample, sizeof (g_PSMain_sample), + g_PSMain_sample_str, "PSMain_sample", ps); +} + +HRESULT +gst_d3d11_get_pixel_shader_snow (GstD3D11Device * device, + ID3D11PixelShader ** ps) +{ + static gint64 token = 0; + + GST_D3D11_CALL_ONCE_BEGIN { + token = gst_d3d11_pixel_shader_token_new (); + } GST_D3D11_CALL_ONCE_END; + + return gst_d3d11_device_get_pixel_shader (device, token, + g_PSMain_snow, sizeof (g_PSMain_snow), + g_PSMain_snow_str, "PSMain_snow", ps); +} + +HRESULT +gst_d3d11_get_vertex_shader_color (GstD3D11Device * device, + ID3D11VertexShader ** vs, ID3D11InputLayout ** layout) +{ + static gint64 token = 0; + + GST_D3D11_CALL_ONCE_BEGIN { + token = gst_d3d11_vertex_shader_token_new (); + } GST_D3D11_CALL_ONCE_END; + + D3D11_INPUT_ELEMENT_DESC input_desc[2]; + + input_desc[0].SemanticName = "POSITION"; + input_desc[0].SemanticIndex = 0; + input_desc[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; + input_desc[0].InputSlot = 0; + input_desc[0].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; + input_desc[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; + input_desc[0].InstanceDataStepRate = 0; + + input_desc[1].SemanticName = "COLOR"; + input_desc[1].SemanticIndex = 0; + input_desc[1].Format = DXGI_FORMAT_R32G32B32A32_FLOAT; + input_desc[1].InputSlot = 0; + input_desc[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; + input_desc[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; + input_desc[1].InstanceDataStepRate = 0; + + return gst_d3d11_device_get_vertex_shader (device, token, + g_VSMain_color, sizeof (g_VSMain_color), + g_VSMain_color_str, "VSMain_color", input_desc, G_N_ELEMENTS (input_desc), + vs, layout); +} + +HRESULT +gst_d3d11_get_vertex_shader_coord (GstD3D11Device * device, + ID3D11VertexShader ** vs, ID3D11InputLayout ** layout) +{ + static gint64 token = 0; + + GST_D3D11_CALL_ONCE_BEGIN { + token = gst_d3d11_vertex_shader_token_new (); + } GST_D3D11_CALL_ONCE_END; + + D3D11_INPUT_ELEMENT_DESC input_desc[2]; + + input_desc[0].SemanticName = "POSITION"; + input_desc[0].SemanticIndex = 0; + input_desc[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; + input_desc[0].InputSlot = 0; + input_desc[0].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; + input_desc[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; + input_desc[0].InstanceDataStepRate = 0; + + input_desc[1].SemanticName = "TEXCOORD"; + input_desc[1].SemanticIndex = 0; + input_desc[1].Format = DXGI_FORMAT_R32G32_FLOAT; + input_desc[1].InputSlot = 0; + input_desc[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; + input_desc[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; + input_desc[1].InstanceDataStepRate = 0; + + return gst_d3d11_device_get_vertex_shader (device, token, + g_VSMain_coord, sizeof (g_VSMain_coord), + g_VSMain_coord_str, "VSMain_coord", input_desc, G_N_ELEMENTS (input_desc), + vs, layout); +} + +HRESULT +gst_d3d11_get_vertex_shader_pos (GstD3D11Device * device, + ID3D11VertexShader ** vs, ID3D11InputLayout ** layout) +{ + static gint64 token = 0; + + GST_D3D11_CALL_ONCE_BEGIN { + token = gst_d3d11_vertex_shader_token_new (); + } GST_D3D11_CALL_ONCE_END; + + D3D11_INPUT_ELEMENT_DESC input_desc; + + input_desc.SemanticName = "POSITION"; + input_desc.SemanticIndex = 0; + input_desc.Format = DXGI_FORMAT_R32G32B32_FLOAT; + input_desc.InputSlot = 0; + input_desc.AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; + input_desc.InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; + input_desc.InstanceDataStepRate = 0; + + return gst_d3d11_device_get_vertex_shader (device, token, + g_VSMain_pos, sizeof (g_VSMain_pos), + g_VSMain_pos_str, "VSMain_pos", &input_desc, 1, vs, layout); +} diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.h b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.h index 07b99bda92..e7020146c9 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.h +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.h @@ -25,6 +25,7 @@ #include #include #include +#include G_BEGIN_DECLS @@ -100,6 +101,42 @@ GstBufferPool * gst_d3d11_buffer_pool_new_with_options (GstD3D11Device * device guint min_buffers, guint max_buffers); +HRESULT gst_d3d11_get_pixel_shader_checker_luma (GstD3D11Device * device, + ID3D11PixelShader ** ps); + +HRESULT gst_d3d11_get_pixel_shader_checker_rgb (GstD3D11Device * device, + ID3D11PixelShader ** ps); + +HRESULT gst_d3d11_get_pixel_shader_checker_vuya (GstD3D11Device * device, + ID3D11PixelShader ** ps); + +HRESULT gst_d3d11_get_pixel_shader_checker (GstD3D11Device * device, + ID3D11PixelShader ** ps); + +HRESULT gst_d3d11_get_pixel_shader_color (GstD3D11Device * device, + ID3D11PixelShader ** ps); + +HRESULT gst_d3d11_get_pixel_shader_sample_premul (GstD3D11Device * device, + ID3D11PixelShader ** ps); + +HRESULT gst_d3d11_get_pixel_shader_sample (GstD3D11Device * device, + ID3D11PixelShader ** ps); + +HRESULT gst_d3d11_get_pixel_shader_snow (GstD3D11Device * device, + ID3D11PixelShader ** ps); + +HRESULT gst_d3d11_get_vertex_shader_color (GstD3D11Device * device, + ID3D11VertexShader ** vs, + ID3D11InputLayout ** layout); + +HRESULT gst_d3d11_get_vertex_shader_coord (GstD3D11Device * device, + ID3D11VertexShader ** vs, + ID3D11InputLayout ** layout); + +HRESULT gst_d3d11_get_vertex_shader_pos (GstD3D11Device * device, + ID3D11VertexShader ** vs, + ID3D11InputLayout ** layout); + G_END_DECLS #endif /* __GST_D3D11_PLUGIN_UTILS_H__ */ diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp index 077d59b4ea..8c79c0cf62 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp @@ -870,48 +870,6 @@ error: static gboolean gst_d3d11_screen_capture_prepare_shader (GstD3D11ScreenCaptureSrc * self) { - /* *INDENT-OFF* */ - static const gchar vs_str[] = - "struct VS_INPUT {\n" - " float4 Position: POSITION;\n" - " float2 Texture: TEXCOORD;\n" - "};\n" - "\n" - "struct VS_OUTPUT {\n" - " float4 Position: SV_POSITION;\n" - " float2 Texture: TEXCOORD;\n" - "};\n" - "\n" - "VS_OUTPUT main (VS_INPUT input)\n" - "{\n" - " return input;\n" - "}"; - static const gchar ps_str[] = - "Texture2D shaderTexture;\n" - "SamplerState samplerState;\n" - "\n" - "struct PS_INPUT {\n" - " float4 Position: SV_POSITION;\n" - " float2 Texture: TEXCOORD;\n" - "};\n" - "\n" - "struct PS_OUTPUT {\n" - " float4 Plane: SV_Target;\n" - "};\n" - "\n" - "PS_OUTPUT main(PS_INPUT input)\n" - "{\n" - " PS_OUTPUT output;\n" - " output.Plane = shaderTexture.Sample(samplerState, input.Texture);\n" - " return output;\n" - "}"; - /* *INDENT-ON* */ - D3D11_INPUT_ELEMENT_DESC input_desc[] = { - {"POSITION", - 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, - {"TEXCOORD", - 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0} - }; ComPtr < ID3D11VertexShader > vs; ComPtr < ID3D11InputLayout > layout; ComPtr < ID3D11PixelShader > ps; @@ -924,14 +882,13 @@ gst_d3d11_screen_capture_prepare_shader (GstD3D11ScreenCaptureSrc * self) device_handle = gst_d3d11_device_get_device_handle (self->device); - hr = gst_d3d11_create_vertex_shader_simple (self->device, - vs_str, "main", input_desc, G_N_ELEMENTS (input_desc), &vs, &layout); + hr = gst_d3d11_get_vertex_shader_coord (self->device, &vs, &layout); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to create vertex shader"); return FALSE; } - hr = gst_d3d11_create_pixel_shader_simple (self->device, ps_str, "main", &ps); + hr = gst_d3d11_get_pixel_shader_sample (self->device, &ps); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to create pixel shader"); return FALSE; diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11testsrc.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11testsrc.cpp index 82f3e5f3ce..d11763663a 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11testsrc.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11testsrc.cpp @@ -291,100 +291,11 @@ typedef struct } color; } ColorVertexData; -/* *INDENT-OFF* */ -static const gchar templ_vs_coord[] = - "struct VS_INPUT {\n" - " float4 Position: POSITION;\n" - " float2 Texture: TEXCOORD;\n" - "};\n" - "struct VS_OUTPUT {\n" - " float4 Position: SV_POSITION;\n" - " float2 Texture: TEXCOORD;\n" - "};\n" - "VS_OUTPUT VSMain_coord (VS_INPUT input)\n" - "{\n" - " return input;\n" - "}"; - -static const gchar templ_vs_color[] = - "struct VS_INPUT {\n" - " float4 Position: POSITION;\n" - " float4 Color: COLOR;\n" - "};\n" - "struct VS_OUTPUT {\n" - " float4 Position: SV_POSITION;\n" - " float4 Color: COLOR;\n" - "};\n" - "VS_OUTPUT VSMain_color (VS_INPUT input)\n" - "{\n" - " return input;\n" - "}"; - -static const gchar templ_ps_snow[] = - "cbuffer SnowConstBuffer : register(b0)\n" - "{\n" - " float time;\n" - " float alpha;\n" - " float2 padding;\n" - "}\n" - "struct PS_INPUT {\n" - " float4 Position: SV_POSITION;\n" - " float2 Texture: TEXCOORD;\n" - "};\n" - "float get_rand(float2 uv)\n" - "{\n" - " return frac(sin(dot(uv, float2(12.9898,78.233))) * 43758.5453);\n" - "}\n" - "float4 PSMain_snow(PS_INPUT input) : SV_Target\n" - "{\n" - " float4 output;\n" - " float val = get_rand (time * input.Texture);\n" - " output.rgb = float3(val, val, val);\n" - " output.a = alpha;\n" - " return output;\n" - "}"; - -static const gchar templ_ps_smpte[] = - "struct PS_INPUT {\n" - " float4 Position: SV_POSITION;\n" - " float4 Color: COLOR;\n" - "};\n" - "float4 PSMain_smpte (PS_INPUT input) : SV_TARGET\n" - "{\n" - " return input.Color;\n" - "}"; - -static const gchar templ_ps_checker[] = - "cbuffer CheckerConstBuffer : register(b0)\n" - "{\n" - " float width;\n" - " float height;\n" - " float checker_size;\n" - " float alpha;\n" - "};\n" - "struct PS_INPUT {\n" - " float4 Position: SV_POSITION;\n" - " float2 Texture: TEXCOORD;\n" - "};\n" - "float4 PSMain_checker (PS_INPUT input) : SV_Target\n" - "{\n" - " float4 output;\n" - " float2 xy_mod = floor (0.5 * input.Texture * float2 (width, height) / checker_size);\n" - " float result = fmod (xy_mod.x + xy_mod.y, 2.0);\n" - " output.r = step (result, 0.5);\n" - " output.g = 1.0 - output.r;\n" - " output.b = 0;\n" - " output.a = alpha;\n" - " return output;\n" - "}"; -/* *INDENT-ON* */ - static gboolean setup_snow_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render, guint on_smpte) { HRESULT hr; - D3D11_INPUT_ELEMENT_DESC input_desc[2]; D3D11_BUFFER_DESC buffer_desc; D3D11_MAPPED_SUBRESOURCE map; UvVertexData *vertex_data; @@ -401,34 +312,15 @@ setup_snow_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render, ComPtr < ID3D11Buffer > const_buffer; GstD3D11TestSrcQuad *quad; - memset (input_desc, 0, sizeof (input_desc)); memset (&buffer_desc, 0, sizeof (buffer_desc)); - input_desc[0].SemanticName = "POSITION"; - input_desc[0].SemanticIndex = 0; - input_desc[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; - input_desc[0].InputSlot = 0; - input_desc[0].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; - input_desc[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; - input_desc[0].InstanceDataStepRate = 0; - - input_desc[1].SemanticName = "TEXCOORD"; - input_desc[1].SemanticIndex = 0; - input_desc[1].Format = DXGI_FORMAT_R32G32_FLOAT; - input_desc[1].InputSlot = 0; - input_desc[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; - input_desc[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; - input_desc[1].InstanceDataStepRate = 0; - - hr = gst_d3d11_create_vertex_shader_simple (self->device, templ_vs_coord, - "VSMain_coord", input_desc, G_N_ELEMENTS (input_desc), &vs, &layout); + hr = gst_d3d11_get_vertex_shader_coord (self->device, &vs, &layout); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to compile vertext shader"); return FALSE; } - hr = gst_d3d11_create_pixel_shader_simple (self->device, - templ_ps_snow, "PSMain_snow", &ps); + hr = gst_d3d11_get_pixel_shader_snow (self->device, &ps); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to compile pixel shader"); return FALSE; @@ -591,7 +483,6 @@ static gboolean setup_smpte_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render) { HRESULT hr; - D3D11_INPUT_ELEMENT_DESC input_desc[2]; D3D11_BUFFER_DESC buffer_desc; D3D11_MAPPED_SUBRESOURCE map; ColorVertexData *vertex_data; @@ -609,34 +500,15 @@ setup_smpte_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render) guint num_vertex = 0; guint num_index = 0; - memset (input_desc, 0, sizeof (input_desc)); memset (&buffer_desc, 0, sizeof (buffer_desc)); - input_desc[0].SemanticName = "POSITION"; - input_desc[0].SemanticIndex = 0; - input_desc[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; - input_desc[0].InputSlot = 0; - input_desc[0].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; - input_desc[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; - input_desc[0].InstanceDataStepRate = 0; - - input_desc[1].SemanticName = "COLOR"; - input_desc[1].SemanticIndex = 0; - input_desc[1].Format = DXGI_FORMAT_R32G32B32A32_FLOAT; - input_desc[1].InputSlot = 0; - input_desc[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; - input_desc[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; - input_desc[1].InstanceDataStepRate = 0; - - hr = gst_d3d11_create_vertex_shader_simple (self->device, templ_vs_color, - "VSMain_color", input_desc, G_N_ELEMENTS (input_desc), &vs, &layout); + hr = gst_d3d11_get_vertex_shader_color (self->device, &vs, &layout); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to compile vertext shader"); return FALSE; } - hr = gst_d3d11_create_pixel_shader_simple (self->device, - templ_ps_smpte, "PSMain_smpte", &ps); + hr = gst_d3d11_get_pixel_shader_color (self->device, &ps); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to compile pixel shader"); return FALSE; @@ -940,7 +812,6 @@ setup_checker_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render, guint checker_size) { HRESULT hr; - D3D11_INPUT_ELEMENT_DESC input_desc[2]; D3D11_BUFFER_DESC buffer_desc; D3D11_MAPPED_SUBRESOURCE map; UvVertexData *vertex_data; @@ -957,34 +828,15 @@ setup_checker_render (GstD3D11TestSrc * self, GstD3D11TestSrcRender * render, ComPtr < ID3D11Buffer > const_buffer; GstD3D11TestSrcQuad *quad; - memset (input_desc, 0, sizeof (input_desc)); memset (&buffer_desc, 0, sizeof (buffer_desc)); - input_desc[0].SemanticName = "POSITION"; - input_desc[0].SemanticIndex = 0; - input_desc[0].Format = DXGI_FORMAT_R32G32B32_FLOAT; - input_desc[0].InputSlot = 0; - input_desc[0].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; - input_desc[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; - input_desc[0].InstanceDataStepRate = 0; - - input_desc[1].SemanticName = "TEXCOORD"; - input_desc[1].SemanticIndex = 0; - input_desc[1].Format = DXGI_FORMAT_R32G32_FLOAT; - input_desc[1].InputSlot = 0; - input_desc[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT; - input_desc[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA; - input_desc[1].InstanceDataStepRate = 0; - - hr = gst_d3d11_create_vertex_shader_simple (self->device, templ_vs_coord, - "VSMain_coord", input_desc, G_N_ELEMENTS (input_desc), &vs, &layout); + hr = gst_d3d11_get_vertex_shader_coord (self->device, &vs, &layout); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to compile vertext shader"); return FALSE; } - hr = gst_d3d11_create_pixel_shader_simple (self->device, - templ_ps_checker, "PSMain_checker", &ps); + hr = gst_d3d11_get_pixel_shader_checker (self->device, &ps); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to compile pixel shader"); return FALSE; diff --git a/subprojects/gst-plugins-bad/sys/d3d11/hlsl/gstd3d11-hlsl.h b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/gstd3d11-hlsl.h new file mode 100644 index 0000000000..3d356d7050 --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/gstd3d11-hlsl.h @@ -0,0 +1,58 @@ +/* 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 + +#ifdef HLSL_PRECOMPILED +#include "ps-checker-luma.h" +#include "ps-checker-rgb.h" +#include "ps-checker-vuya.h" +#include "ps-checker.h" +#include "ps-color.h" +#include "ps-sample-premul.h" +#include "ps-sample.h" +#include "ps-snow.h" +#include "vs-color.h" +#include "vs-coord.h" +#include "vs-pos.h" +#else +const BYTE g_PSMain_checker_luma[] = { 0 }; +const BYTE g_PSMain_checker_rgb[] = { 0 }; +const BYTE g_PSMain_checker_vuya[] = { 0 }; +const BYTE g_PSMain_checker[] = { 0 }; +const BYTE g_PSMain_color[] = { 0 }; +const BYTE g_PSMain_sample_premul[] = { 0 }; +const BYTE g_PSMain_sample[] = { 0 }; +const BYTE g_PSMain_snow[] = { 0 }; +const BYTE g_VSMain_color[] = { 0 }; +const BYTE g_VSMain_coord[] = { 0 }; +const BYTE g_VSMain_pos[] = { 0 }; +#endif + +#include "ps-checker-luma.hlsl" +#include "ps-checker-rgb.hlsl" +#include "ps-checker-vuya.hlsl" +#include "ps-checker.hlsl" +#include "ps-color.hlsl" +#include "ps-sample-premul.hlsl" +#include "ps-sample.hlsl" +#include "ps-snow.hlsl" +#include "vs-color.hlsl" +#include "vs-coord.hlsl" +#include "vs-pos.hlsl" diff --git a/subprojects/gst-plugins-bad/sys/d3d11/hlsl/meson.build b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/meson.build new file mode 100644 index 0000000000..7f1d3b2117 --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/meson.build @@ -0,0 +1,28 @@ +hlsl_sources = [ + ['ps-checker-luma', 'PSMain_checker_luma', 'ps_5_0'], + ['ps-checker-rgb', 'PSMain_checker_rgb', 'ps_5_0'], + ['ps-checker-vuya', 'PSMain_checker_vuya', 'ps_5_0'], + ['ps-checker', 'PSMain_checker', 'ps_5_0'], + ['ps-color', 'PSMain_color', 'ps_5_0'], + ['ps-sample-premul', 'PSMain_sample_premul', 'ps_5_0'], + ['ps-sample', 'PSMain_sample', 'ps_5_0'], + ['ps-snow', 'PSMain_snow', 'ps_5_0'], + ['vs-color', 'VSMain_color', 'vs_5_0'], + ['vs-coord', 'VSMain_coord', 'vs_5_0'], + ['vs-pos', 'VSMain_pos', 'vs_5_0'], +] + +foreach shader : hlsl_sources + basename = shader.get(0) + source = files('@0@.hlsl'.format(basename)) + header = '@0@.h'.format(basename) + compiled_shader = custom_target(header, + input : source, + output : header, + command : [fxc, '/Fh', '@OUTPUT@', + '/E', shader.get(1), + '/T', shader.get(2), + '/D', 'BUILDING_HLSL=1', + '@INPUT@']) + hlsl_precompiled += [compiled_shader] +endforeach diff --git a/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-checker-luma.hlsl b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-checker-luma.hlsl new file mode 100644 index 0000000000..79a31ffe7b --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-checker-luma.hlsl @@ -0,0 +1,83 @@ +/* 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 BUILDING_HLSL +static const float blocksize = 8.0; +static const float4 high = float4 (0.667, 0.0, 0.0, 1.0); +static const float4 low = float4 (0.333, 0.0, 0.0, 1.0); + +struct PS_INPUT +{ + float4 Position : SV_POSITION; +}; + +struct PS_OUTPUT +{ + float4 Plane : SV_TARGET; +}; + +PS_OUTPUT PSMain_checker_luma (PS_INPUT input) +{ + PS_OUTPUT output; + if ((input.Position.x % (blocksize * 2.0)) >= blocksize) { + if ((input.Position.y % (blocksize * 2.0)) >= blocksize) + output.Plane = low; + else + output.Plane = high; + } else { + if ((input.Position.y % (blocksize * 2.0)) < blocksize) + output.Plane = low; + else + output.Plane = high; + } + return output; +} +#else +static const char g_PSMain_checker_luma_str[] = +"static const float blocksize = 8.0;\n" +"static const float4 high = float4 (0.667, 0.0, 0.0, 1.0);\n" +"static const float4 low = float4 (0.333, 0.0, 0.0, 1.0);\n" +"\n" +"struct PS_INPUT\n" +"{\n" +" float4 Position : SV_POSITION;\n" +"};\n" +"\n" +"struct PS_OUTPUT\n" +"{\n" +" float4 Plane : SV_TARGET;\n" +"};\n" +"\n" +"PS_OUTPUT PSMain_checker_luma (PS_INPUT input)\n" +"{\n" +" PS_OUTPUT output;\n" +" if ((input.Position.x % (blocksize * 2.0)) >= blocksize) {\n" +" if ((input.Position.y % (blocksize * 2.0)) >= blocksize)\n" +" output.Plane = low;\n" +" else\n" +" output.Plane = high;\n" +" } else {\n" +" if ((input.Position.y % (blocksize * 2.0)) < blocksize)\n" +" output.Plane = low;\n" +" else\n" +" output.Plane = high;\n" +" }\n" +" return output;\n" +"}\n"; +#endif diff --git a/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-checker-rgb.hlsl b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-checker-rgb.hlsl new file mode 100644 index 0000000000..a45f01adad --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-checker-rgb.hlsl @@ -0,0 +1,83 @@ +/* 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 BUILDING_HLSL +static const float blocksize = 8.0; +static const float4 high = float4 (0.667, 0.667, 0.667, 1.0); +static const float4 low = float4 (0.333, 0.333, 0.333, 1.0); + +struct PS_INPUT +{ + float4 Position : SV_POSITION; +}; + +struct PS_OUTPUT +{ + float4 Plane : SV_TARGET; +}; + +PS_OUTPUT PSMain_checker_rgb (PS_INPUT input) +{ + PS_OUTPUT output; + if ((input.Position.x % (blocksize * 2.0)) >= blocksize) { + if ((input.Position.y % (blocksize * 2.0)) >= blocksize) + output.Plane = low; + else + output.Plane = high; + } else { + if ((input.Position.y % (blocksize * 2.0)) < blocksize) + output.Plane = low; + else + output.Plane = high; + } + return output; +} +#else +static const char g_PSMain_checker_rgb_str[] = +"static const float blocksize = 8.0;\n" +"static const float4 high = float4 (0.667, 0.667, 0.667, 1.0);\n" +"static const float4 low = float4 (0.333, 0.333, 0.333, 1.0);\n" +"\n" +"struct PS_INPUT\n" +"{\n" +" float4 Position : SV_POSITION;\n" +"};\n" +"\n" +"struct PS_OUTPUT\n" +"{\n" +" float4 Plane : SV_TARGET;\n" +"};\n" +"\n" +"PS_OUTPUT PSMain_checker_rgb (PS_INPUT input)\n" +"{\n" +" PS_OUTPUT output;\n" +" if ((input.Position.x % (blocksize * 2.0)) >= blocksize) {\n" +" if ((input.Position.y % (blocksize * 2.0)) >= blocksize)\n" +" output.Plane = low;\n" +" else\n" +" output.Plane = high;\n" +" } else {\n" +" if ((input.Position.y % (blocksize * 2.0)) < blocksize)\n" +" output.Plane = low;\n" +" else\n" +" output.Plane = high;\n" +" }\n" +" return output;\n" +"}\n"; +#endif diff --git a/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-checker-vuya.hlsl b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-checker-vuya.hlsl new file mode 100644 index 0000000000..40d31d7efb --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-checker-vuya.hlsl @@ -0,0 +1,83 @@ +/* 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 BUILDING_HLSL +static const float blocksize = 8.0; +static const float4 high = float4 (0.5, 0.5, 0.667, 1.0); +static const float4 low = float4 (0.5, 0.5, 0.333, 1.0); + +struct PS_INPUT +{ + float4 Position : SV_POSITION; +}; + +struct PS_OUTPUT +{ + float4 Plane : SV_TARGET; +}; + +PS_OUTPUT PSMain_checker_vuya (PS_INPUT input) +{ + PS_OUTPUT output; + if ((input.Position.x % (blocksize * 2.0)) >= blocksize) { + if ((input.Position.y % (blocksize * 2.0)) >= blocksize) + output.Plane = low; + else + output.Plane = high; + } else { + if ((input.Position.y % (blocksize * 2.0)) < blocksize) + output.Plane = low; + else + output.Plane = high; + } + return output; +} +#else +static const char g_PSMain_checker_vuya_str[] = +"static const float blocksize = 8.0;\n" +"static const float4 high = float4 (0.5, 0.5, 0.667, 1.0);\n" +"static const float4 low = float4 (0.5, 0.5, 0.333, 1.0);\n" +"\n" +"struct PS_INPUT\n" +"{\n" +" float4 Position : SV_POSITION;\n" +"};\n" +"\n" +"struct PS_OUTPUT\n" +"{\n" +" float4 Plane : SV_TARGET;\n" +"};\n" +"\n" +"PS_OUTPUT PSMain_checker_vuya (PS_INPUT input)\n" +"{\n" +" PS_OUTPUT output;\n" +" if ((input.Position.x % (blocksize * 2.0)) >= blocksize) {\n" +" if ((input.Position.y % (blocksize * 2.0)) >= blocksize)\n" +" output.Plane = low;\n" +" else\n" +" output.Plane = high;\n" +" } else {\n" +" if ((input.Position.y % (blocksize * 2.0)) < blocksize)\n" +" output.Plane = low;\n" +" else\n" +" output.Plane = high;\n" +" }\n" +" return output;\n" +"}\n"; +#endif diff --git a/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-checker.hlsl b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-checker.hlsl new file mode 100644 index 0000000000..2ef6cb5454 --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-checker.hlsl @@ -0,0 +1,73 @@ +/* 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 BUILDING_HLSL +cbuffer CheckerConstBuffer : register(b0) +{ + float width; + float height; + float checker_size; + float alpha; +}; + +struct PS_INPUT +{ + float4 Position: SV_POSITION; + float2 Texture: TEXCOORD; +}; + +float4 PSMain_checker (PS_INPUT input) : SV_Target +{ + float4 output; + float2 xy_mod = floor (0.5 * input.Texture * float2 (width, height) / checker_size); + float result = fmod (xy_mod.x + xy_mod.y, 2.0); + output.r = step (result, 0.5); + output.g = 1.0 - output.r; + output.b = 0; + output.a = alpha; + return output; +} +#else +static const char g_PSMain_checker_str[] = +"cbuffer CheckerConstBuffer : register(b0)\n" +"{\n" +" float width;\n" +" float height;\n" +" float checker_size;\n" +" float alpha;\n" +"};\n" +"\n" +"struct PS_INPUT\n" +"{\n" +" float4 Position: SV_POSITION;\n" +" float2 Texture: TEXCOORD;\n" +"};\n" +"\n" +"float4 PSMain_checker (PS_INPUT input) : SV_Target\n" +"{\n" +" float4 output;\n" +" float2 xy_mod = floor (0.5 * input.Texture * float2 (width, height) / checker_size);\n" +" float result = fmod (xy_mod.x + xy_mod.y, 2.0);\n" +" output.r = step (result, 0.5);\n" +" output.g = 1.0 - output.r;\n" +" output.b = 0;\n" +" output.a = alpha;\n" +" return output;\n" +"}\n"; +#endif diff --git a/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-color.hlsl b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-color.hlsl new file mode 100644 index 0000000000..921b83ca25 --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-color.hlsl @@ -0,0 +1,43 @@ +/* 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 BUILDING_HLSL +struct PS_INPUT +{ + float4 Position: SV_POSITION; + float4 Color: COLOR; +}; + +float4 PSMain_color (PS_INPUT input) : SV_TARGET +{ + return input.Color; +} +#else +static const char g_PSMain_color_str[] = +"struct PS_INPUT\n" +"{\n" +" float4 Position: SV_POSITION;\n" +" float4 Color: COLOR;\n" +"};\n" +"\n" +"float4 PSMain_color (PS_INPUT input) : SV_TARGET\n" +"{\n" +" return input.Color;\n" +"}\n"; +#endif diff --git a/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-sample-premul.hlsl b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-sample-premul.hlsl new file mode 100644 index 0000000000..1836650109 --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-sample-premul.hlsl @@ -0,0 +1,61 @@ +/* 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 BUILDING_HLSL +Texture2D shaderTexture; +SamplerState samplerState; + +struct PS_INPUT +{ + float4 Position : SV_POSITION; + float2 Texture : TEXCOORD; +}; + +float4 PSMain_sample_premul (PS_INPUT input): SV_TARGET +{ + float4 sample = shaderTexture.Sample (samplerState, input.Texture); + float4 premul_sample; + premul_sample.r = saturate (sample.r * sample.a); + premul_sample.g = saturate (sample.g * sample.a); + premul_sample.b = saturate (sample.b * sample.a); + premul_sample.a = sample.a; + return premul_sample; +} +#else +static const char g_PSMain_sample_premul_str[] = +"Texture2D shaderTexture;\n" +"SamplerState samplerState;\n" +"\n" +"struct PS_INPUT\n" +"{\n" +" float4 Position : SV_POSITION;\n" +" float2 Texture : TEXCOORD;\n" +"};\n" +"\n" +"float4 PSMain_sample_premul (PS_INPUT input): SV_TARGET\n" +"{\n" +" float4 sample = shaderTexture.Sample (samplerState, input.Texture);\n" +" float4 premul_sample;\n" +" premul_sample.r = saturate (sample.r * sample.a);\n" +" premul_sample.g = saturate (sample.g * sample.a);\n" +" premul_sample.b = saturate (sample.b * sample.a);\n" +" premul_sample.a = sample.a;\n" +" return premul_sample;\n" +"}\n"; +#endif diff --git a/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-sample.hlsl b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-sample.hlsl new file mode 100644 index 0000000000..90f91b46d6 --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-sample.hlsl @@ -0,0 +1,49 @@ +/* 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 BUILDING_HLSL +Texture2D shaderTexture; +SamplerState samplerState; + +struct PS_INPUT +{ + float4 Position : SV_POSITION; + float2 Texture : TEXCOORD; +}; + +float4 PSMain_sample (PS_INPUT input): SV_TARGET +{ + return shaderTexture.Sample (samplerState, input.Texture); +} +#else +static const char g_PSMain_sample_str[] = +"Texture2D shaderTexture;\n" +"SamplerState samplerState;\n" +"\n" +"struct PS_INPUT\n" +"{\n" +" float4 Position: SV_POSITION;\n" +" float2 Texture: TEXCOORD;\n" +"};\n" +"\n" +"float4 PSMain_sample (PS_INPUT input): SV_TARGET\n" +"{\n" +" return shaderTexture.Sample (samplerState, input.Texture);\n" +"}\n"; +#endif diff --git a/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-snow.hlsl b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-snow.hlsl new file mode 100644 index 0000000000..15b71ba109 --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/ps-snow.hlsl @@ -0,0 +1,75 @@ +/* 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 BUILDING_HLSL +cbuffer SnowConstBuffer : register(b0) +{ + float time; + float alpha; + float2 padding; +}; + +struct PS_INPUT +{ + float4 Position : SV_POSITION; + float2 Texture : TEXCOORD; +}; + +float get_rand (float2 uv) +{ + return frac (sin (dot (uv, float2 (12.9898,78.233))) * 43758.5453); +} + +float4 PSMain_snow (PS_INPUT input) : SV_Target +{ + float4 output; + float val = get_rand (time * input.Texture); + output.rgb = float3(val, val, val); + output.a = alpha; + return output; +} +#else +static const char g_PSMain_snow_str[] = +"cbuffer TimeConstBuffer : register(b0)\n" +"{\n" +" float time;\n" +" float alpha;\n" +" float2 padding;\n" +"};\n" +"\n" +"struct PS_INPUT\n" +"{\n" +" float4 Position : SV_POSITION;\n" +" float2 Texture : TEXCOORD;\n" +"};\n" +"\n" +"float get_rand(float2 uv)\n" +"{\n" +" return frac (sin (dot (uv, float2 (12.9898,78.233))) * 43758.5453);\n" +"}\n" +"\n" +"float4 PSMain_snow (PS_INPUT input) : SV_Target\n" +"{\n" +" float4 output;\n" +" float val = get_rand (time * input.Texture);\n" +" output.rgb = float3(val, val, val);\n" +" output.a = alpha;\n" +" return output;\n" +"}\n"; +#endif diff --git a/subprojects/gst-plugins-bad/sys/d3d11/hlsl/vs-color.hlsl b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/vs-color.hlsl new file mode 100644 index 0000000000..4c60a73634 --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/vs-color.hlsl @@ -0,0 +1,55 @@ +/* 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 BUILDING_HLSL +struct VS_INPUT +{ + float4 Position : POSITION; + float4 Color : COLOR; +}; + +struct VS_OUTPUT +{ + float4 Position : SV_POSITION; + float4 Color : COLOR; +}; + +VS_OUTPUT VSMain_color (VS_INPUT input) +{ + return input; +} +#else +static const char g_VSMain_color_str[] = +"struct VS_INPUT\n" +"{\n" +" float4 Position : POSITION;\n" +" float4 Color : COLOR;\n" +"};\n" +"\n" +"struct VS_OUTPUT\n" +"{\n" +" float4 Position : SV_POSITION;\n" +" float4 Color : COLOR;\n" +"};\n" +"\n" +"VS_OUTPUT VSMain_color (VS_INPUT input)\n" +"{\n" +" return input;\n" +"}\n"; +#endif diff --git a/subprojects/gst-plugins-bad/sys/d3d11/hlsl/vs-coord.hlsl b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/vs-coord.hlsl new file mode 100644 index 0000000000..f79bd39627 --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/vs-coord.hlsl @@ -0,0 +1,55 @@ +/* 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 BUILDING_HLSL +struct VS_INPUT +{ + float4 Position : POSITION; + float2 Texture : TEXCOORD; +}; + +struct VS_OUTPUT +{ + float4 Position : SV_POSITION; + float2 Texture : TEXCOORD; +}; + +VS_OUTPUT VSMain_coord (VS_INPUT input) +{ + return input; +} +#else +static const char g_VSMain_coord_str[] = +"struct VS_INPUT\n" +"{\n" +" float4 Position : POSITION;\n" +" float2 Texture : TEXCOORD;\n" +"};\n" +"\n" +"struct VS_OUTPUT\n" +"{\n" +" float4 Position : SV_POSITION;\n" +" float2 Texture : TEXCOORD;\n" +"};\n" +"\n" +"VS_OUTPUT VSMain_coord (VS_INPUT input)\n" +"{\n" +" return input;\n" +"}\n"; +#endif diff --git a/subprojects/gst-plugins-bad/sys/d3d11/hlsl/vs-pos.hlsl b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/vs-pos.hlsl new file mode 100644 index 0000000000..9b786b3826 --- /dev/null +++ b/subprojects/gst-plugins-bad/sys/d3d11/hlsl/vs-pos.hlsl @@ -0,0 +1,51 @@ +/* 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 BUILDING_HLSL +struct VS_INPUT +{ + float4 Position : POSITION; +}; + +struct VS_OUTPUT +{ + float4 Position : SV_POSITION; +}; + +VS_OUTPUT VSMain_pos (VS_INPUT input) +{ + return input; +} +#else +static const char g_VSMain_pos_str[] = +"struct VS_INPUT\n" +"{\n" +" float4 Position : POSITION;\n" +"};\n" +"\n" +"struct VS_OUTPUT\n" +"{\n" +" float4 Position : SV_POSITION;\n" +"};\n" +"\n" +"VS_OUTPUT VSMain_pos (VS_INPUT input)\n" +"{\n" +" return input;\n" +"}\n"; +#endif diff --git a/subprojects/gst-plugins-bad/sys/d3d11/meson.build b/subprojects/gst-plugins-bad/sys/d3d11/meson.build index 2a600c9790..40da8bb773 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/meson.build +++ b/subprojects/gst-plugins-bad/sys/d3d11/meson.build @@ -123,8 +123,15 @@ if cc.get_id() != 'msvc' extra_args += extra_mingw_args endif +hlsl_precompiled = [] +fxc = find_program ('fxc', required : get_option ('d3d11-hlsl-precompile')) +if cc.get_id() == 'msvc' and fxc.found() + subdir('hlsl') + extra_args += ['-DHLSL_PRECOMPILED'] +endif + gstd3d11 = library('gstd3d11', - d3d11_sources, + d3d11_sources + hlsl_precompiled, c_args : gst_plugins_bad_args + extra_c_args + extra_args, cpp_args: gst_plugins_bad_args + extra_args, include_directories : [configinc],