From 92cc5722c8c7401f7dd67caaec655c01b9477d6d Mon Sep 17 00:00:00 2001 From: Seungha Yang Date: Tue, 10 Oct 2023 19:35:36 +0900 Subject: [PATCH] d3d11: Pass HLSL source size to compile function The string size is known at build time Part-of: --- .../gst/d3d11/gstd3d11device-private.h | 2 ++ .../gst-libs/gst/d3d11/gstd3d11device.cpp | 11 ++++--- .../gst/d3d11/gstd3d11shadercache.cpp | 10 +++--- .../gst-libs/gst/d3d11/gstd3d11shadercache.h | 2 ++ .../sys/d3d11/gstd3d11pluginutils.cpp | 32 +++++++++++-------- 5 files changed, 35 insertions(+), 22 deletions(-) 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 index e9e7551506..ffc8860512 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device-private.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device-private.h @@ -36,6 +36,7 @@ HRESULT gst_d3d11_device_get_pixel_shader (GstD3D11Device * device, const void * bytecode, gsize bytecode_size, const gchar * source, + gsize source_size, const gchar * entry_point, ID3D11PixelShader ** ps); @@ -45,6 +46,7 @@ HRESULT gst_d3d11_device_get_vertex_shader (GstD3D11Device * device, const void * bytecode, gsize bytecode_size, const gchar * source, + gsize source_size, const gchar * entry_point, const D3D11_INPUT_ELEMENT_DESC * input_desc, guint desc_len, 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 9c01daa754..80c478a569 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device.cpp +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device.cpp @@ -1704,7 +1704,7 @@ gst_d3d11_vertex_shader_token_new (void) 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) + gsize source_size, const gchar * entry_point, ID3D11PixelShader ** ps) { GstD3D11DevicePrivate *priv = device->priv; HRESULT hr; @@ -1740,7 +1740,7 @@ gst_d3d11_device_get_pixel_shader (GstD3D11Device * device, gint64 token, "Creating shader \"%s\" using precompiled bytecode", entry_point); } else { hr = gst_d3d11_shader_cache_get_pixel_shader_blob (token, - source, entry_point, &blob); + source, source_size, entry_point, &blob); if (!gst_d3d11_result (hr, device)) return hr; @@ -1770,8 +1770,9 @@ gst_d3d11_device_get_pixel_shader (GstD3D11Device * device, gint64 token, 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) + gsize source_size, const gchar * entry_point, + const D3D11_INPUT_ELEMENT_DESC * input_desc, guint desc_len, + ID3D11VertexShader ** vs, ID3D11InputLayout ** layout) { GstD3D11DevicePrivate *priv = device->priv; HRESULT hr; @@ -1810,7 +1811,7 @@ gst_d3d11_device_get_vertex_shader (GstD3D11Device * device, gint64 token, "Creating shader \"%s\" using precompiled bytecode", entry_point); } else { hr = gst_d3d11_shader_cache_get_vertex_shader_blob (token, - source, entry_point, &blob); + source, source_size, entry_point, &blob); if (!gst_d3d11_result (hr, device)) return hr; diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.cpp b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.cpp index f9f7e8cadf..36fe3f3b50 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.cpp +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.cpp @@ -35,7 +35,8 @@ static std::map vs_blob_; HRESULT gst_d3d11_shader_cache_get_pixel_shader_blob (gint64 token, - const gchar * source, const gchar * entry_point, ID3DBlob ** blob) + const gchar * source, gsize source_size, const gchar * entry_point, + ID3DBlob ** blob) { std::lock_guard < std::mutex > lk (cache_lock_); @@ -46,7 +47,7 @@ gst_d3d11_shader_cache_get_pixel_shader_blob (gint64 token, return S_OK; } - HRESULT hr = gst_d3d11_compile (source, strlen (source), nullptr, nullptr, + HRESULT hr = gst_d3d11_compile (source, source_size, nullptr, nullptr, nullptr, entry_point, "ps_5_0", 0, 0, blob, nullptr); if (FAILED (hr)) return hr; @@ -59,7 +60,8 @@ gst_d3d11_shader_cache_get_pixel_shader_blob (gint64 token, HRESULT gst_d3d11_shader_cache_get_vertex_shader_blob (gint64 token, - const gchar * source, const gchar * entry_point, ID3DBlob ** blob) + const gchar * source, gsize source_size, const gchar * entry_point, + ID3DBlob ** blob) { std::lock_guard < std::mutex > lk (cache_lock_); @@ -70,7 +72,7 @@ gst_d3d11_shader_cache_get_vertex_shader_blob (gint64 token, return S_OK; } - HRESULT hr = gst_d3d11_compile (source, strlen (source), nullptr, nullptr, + HRESULT hr = gst_d3d11_compile (source, source_size, nullptr, nullptr, nullptr, entry_point, "vs_5_0", 0, 0, blob, nullptr); if (FAILED (hr)) return hr; diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.h b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.h index 2c50f26112..bc4e0ee641 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.h +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11shadercache.h @@ -26,11 +26,13 @@ G_BEGIN_DECLS HRESULT gst_d3d11_shader_cache_get_pixel_shader_blob (gint64 token, const gchar * source, + gsize source_size, const gchar * entry_point, ID3DBlob ** blob); HRESULT gst_d3d11_shader_cache_get_vertex_shader_blob (gint64 token, const gchar * source, + gsize source_size, const gchar * entry_point, ID3DBlob ** blob); diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp index 29a001db50..9c1b43e724 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11pluginutils.cpp @@ -708,7 +708,8 @@ gst_d3d11_get_pixel_shader_checker_luma (GstD3D11Device * device, 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); + g_PSMain_checker_luma_str, sizeof (g_PSMain_checker_luma_str), + "PSMain_checker_luma", ps); } HRESULT @@ -723,7 +724,8 @@ gst_d3d11_get_pixel_shader_checker_rgb (GstD3D11Device * device, 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); + g_PSMain_checker_rgb_str, sizeof (g_PSMain_checker_rgb_str), + "PSMain_checker_rgb", ps); } HRESULT @@ -738,7 +740,8 @@ gst_d3d11_get_pixel_shader_checker_vuya (GstD3D11Device * device, 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); + g_PSMain_checker_vuya_str, sizeof (g_PSMain_checker_vuya_str), + "PSMain_checker_vuya", ps); } HRESULT @@ -753,7 +756,8 @@ gst_d3d11_get_pixel_shader_checker (GstD3D11Device * device, return gst_d3d11_device_get_pixel_shader (device, token, g_PSMain_checker, sizeof (g_PSMain_checker), - g_PSMain_checker_str, "PSMain_checker", ps); + g_PSMain_checker_str, sizeof (g_PSMain_checker_str), + "PSMain_checker", ps); } HRESULT @@ -768,7 +772,7 @@ gst_d3d11_get_pixel_shader_color (GstD3D11Device * device, return gst_d3d11_device_get_pixel_shader (device, token, g_PSMain_color, sizeof (g_PSMain_color), - g_PSMain_color_str, "PSMain_color", ps); + g_PSMain_color_str, sizeof (g_PSMain_color_str), "PSMain_color", ps); } HRESULT @@ -783,7 +787,8 @@ gst_d3d11_get_pixel_shader_sample_premul (GstD3D11Device * device, 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); + g_PSMain_sample_premul_str, sizeof (g_PSMain_sample_premul_str), + "PSMain_sample_premul", ps); } HRESULT @@ -798,7 +803,7 @@ gst_d3d11_get_pixel_shader_sample (GstD3D11Device * device, return gst_d3d11_device_get_pixel_shader (device, token, g_PSMain_sample, sizeof (g_PSMain_sample), - g_PSMain_sample_str, "PSMain_sample", ps); + g_PSMain_sample_str, sizeof (g_PSMain_sample_str), "PSMain_sample", ps); } HRESULT @@ -813,7 +818,7 @@ gst_d3d11_get_pixel_shader_snow (GstD3D11Device * device, return gst_d3d11_device_get_pixel_shader (device, token, g_PSMain_snow, sizeof (g_PSMain_snow), - g_PSMain_snow_str, "PSMain_snow", ps); + g_PSMain_snow_str, sizeof (g_PSMain_snow_str), "PSMain_snow", ps); } HRESULT @@ -846,8 +851,8 @@ gst_d3d11_get_vertex_shader_color (GstD3D11Device * device, 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); + g_VSMain_color_str, sizeof (g_VSMain_color_str), "VSMain_color", + input_desc, G_N_ELEMENTS (input_desc), vs, layout); } HRESULT @@ -880,8 +885,8 @@ gst_d3d11_get_vertex_shader_coord (GstD3D11Device * device, 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); + g_VSMain_coord_str, sizeof (g_VSMain_coord_str), "VSMain_coord", + input_desc, G_N_ELEMENTS (input_desc), vs, layout); } HRESULT @@ -906,5 +911,6 @@ gst_d3d11_get_vertex_shader_pos (GstD3D11Device * device, 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); + g_VSMain_pos_str, sizeof (g_VSMain_pos_str), "VSMain_pos", &input_desc, 1, + vs, layout); }