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 ffc8860512..4d84104798 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 @@ -53,5 +53,10 @@ HRESULT gst_d3d11_device_get_vertex_shader (GstD3D11Device * device, ID3D11VertexShader ** vs, ID3D11InputLayout ** layout); +GST_D3D11_API +HRESULT gst_d3d11_device_get_sampler (GstD3D11Device * device, + D3D11_FILTER filter, + ID3D11SamplerState ** sampler); + 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 80c478a569..fe891c5d45 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device.cpp +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device.cpp @@ -39,6 +39,7 @@ #include #include #include +#include /** * SECTION:gstd3d11device @@ -130,6 +131,7 @@ struct _GstD3D11DevicePrivate std::map > ps_cache; std::map , ComPtr>> vs_cache; + std::map > sampler_cache; #if HAVE_D3D11SDKLAYERS_H ID3D11Debug *d3d11_debug = nullptr; @@ -745,6 +747,7 @@ gst_d3d11_device_dispose (GObject * object) priv->ps_cache.clear (); priv->vs_cache.clear (); + priv->sampler_cache.clear (); GST_D3D11_CLEAR_COM (priv->device5); GST_D3D11_CLEAR_COM (priv->device_context4); @@ -1843,3 +1846,39 @@ gst_d3d11_device_get_vertex_shader (GstD3D11Device * device, gint64 token, return S_OK; } + +HRESULT +gst_d3d11_device_get_sampler (GstD3D11Device * device, D3D11_FILTER filter, + ID3D11SamplerState ** sampler) +{ + GstD3D11DevicePrivate *priv = device->priv; + ComPtr < ID3D11SamplerState > state; + D3D11_SAMPLER_DESC desc; + HRESULT hr; + + std::lock_guard < std::mutex > lk (priv->resource_lock); + auto cached = priv->sampler_cache.find (filter); + if (cached != priv->sampler_cache.end ()) { + *sampler = cached->second.Get (); + (*sampler)->AddRef (); + return S_OK; + } + + memset (&desc, 0, sizeof (D3D11_SAMPLER_DESC)); + + desc.Filter = filter; + desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; + desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; + desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; + desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; + desc.MaxLOD = D3D11_FLOAT32_MAX; + + hr = priv->device->CreateSamplerState (&desc, &state); + if (!gst_d3d11_result (hr, device)) + return hr; + + priv->sampler_cache[filter] = state; + *sampler = state.Detach (); + + return S_OK; +} diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11dxgicapture.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11dxgicapture.cpp index 939503bac5..d97ee0e807 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11dxgicapture.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11dxgicapture.cpp @@ -641,19 +641,9 @@ private: return false; } - D3D11_SAMPLER_DESC sampler_desc; - memset (&sampler_desc, 0, sizeof (D3D11_SAMPLER_DESC)); - sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; - sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER; - sampler_desc.MinLOD = 0; - sampler_desc.MaxLOD = D3D11_FLOAT32_MAX; - - ID3D11Device *device_handle = gst_d3d11_device_get_device_handle (device); ComPtr sampler; - hr = device_handle->CreateSamplerState (&sampler_desc, &sampler); + hr = gst_d3d11_device_get_sampler (device, D3D11_FILTER_MIN_MAG_MIP_LINEAR, + &sampler); if (!gst_d3d11_result (hr, device)) { GST_ERROR ("Failed to create sampler state, hr 0x%x", (guint) hr); return false; diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11overlaycompositor.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11overlaycompositor.cpp index fc6eaf4738..55dee86306 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11overlaycompositor.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11overlaycompositor.cpp @@ -327,7 +327,6 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self) GstVideoInfo *info = &priv->info; GstD3D11Device *device = self->device; HRESULT hr; - D3D11_SAMPLER_DESC sampler_desc; D3D11_BUFFER_DESC buffer_desc; D3D11_BLEND_DESC blend_desc; D3D11_MAPPED_SUBRESOURCE map; @@ -342,23 +341,14 @@ gst_d3d11_overlay_compositor_setup_shader (GstD3D11OverlayCompositor * self) ComPtr < ID3D11BlendState > blend; ComPtr < ID3D11Buffer > index_buffer; - memset (&sampler_desc, 0, sizeof (sampler_desc)); memset (&buffer_desc, 0, sizeof (buffer_desc)); memset (&blend_desc, 0, sizeof (blend_desc)); device_handle = gst_d3d11_device_get_device_handle (device); context_handle = gst_d3d11_device_get_device_context_handle (device); - /* bilinear filtering */ - sampler_desc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; - sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - sampler_desc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; - sampler_desc.MinLOD = 0; - sampler_desc.MaxLOD = D3D11_FLOAT32_MAX; - - hr = device_handle->CreateSamplerState (&sampler_desc, &sampler); + hr = gst_d3d11_device_get_sampler (device, + D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT, &sampler); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Couldn't create sampler state, hr: 0x%x", (guint) hr); diff --git a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp index 8c79c0cf62..efc77fb84e 100644 --- a/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp +++ b/subprojects/gst-plugins-bad/sys/d3d11/gstd3d11screencapturesrc.cpp @@ -875,7 +875,6 @@ gst_d3d11_screen_capture_prepare_shader (GstD3D11ScreenCaptureSrc * self) ComPtr < ID3D11PixelShader > ps; ComPtr < ID3D11SamplerState > sampler; ComPtr < ID3D11BlendState > blend; - D3D11_SAMPLER_DESC sampler_desc; D3D11_BLEND_DESC blend_desc; ID3D11Device *device_handle; HRESULT hr; @@ -894,16 +893,8 @@ gst_d3d11_screen_capture_prepare_shader (GstD3D11ScreenCaptureSrc * self) return FALSE; } - memset (&sampler_desc, 0, sizeof (D3D11_SAMPLER_DESC)); - sampler_desc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; - sampler_desc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - sampler_desc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - sampler_desc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - sampler_desc.ComparisonFunc = D3D11_COMPARISON_NEVER; - sampler_desc.MinLOD = 0; - sampler_desc.MaxLOD = D3D11_FLOAT32_MAX; - - hr = device_handle->CreateSamplerState (&sampler_desc, &sampler); + hr = gst_d3d11_device_get_sampler (self->device, + D3D11_FILTER_MIN_MAG_MIP_LINEAR, &sampler); if (!gst_d3d11_result (hr, self->device)) { GST_ERROR_OBJECT (self, "Failed to create sampler state, hr 0x%x", (guint) hr);