diff --git a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11converter.cpp b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11converter.cpp index 87e6188202..30b838ed5e 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11converter.cpp +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11converter.cpp @@ -774,7 +774,6 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Converter * self, GstD3D11ConverterPrivate *priv = self->priv; GstD3D11Device *device = self->device; HRESULT hr; - D3D11_RASTERIZER_DESC rasterizer_desc; D3D11_BUFFER_DESC buffer_desc; VertexData vertex_data[4]; WORD indices[6]; @@ -791,7 +790,6 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Converter * self, ComPtr < ID3D11RasterizerState > msaa_rasterizer; D3D11_SUBRESOURCE_DATA subresource; - memset (&rasterizer_desc, 0, sizeof (rasterizer_desc)); memset (&subresource, 0, sizeof (subresource)); memset (&buffer_desc, 0, sizeof (buffer_desc)); @@ -827,22 +825,18 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Converter * self, return FALSE; } - /* Everything is the same as default but use D3D11_CULL_NONE to render - * back-facing objects too */ - rasterizer_desc.FillMode = D3D11_FILL_SOLID; - rasterizer_desc.CullMode = D3D11_CULL_NONE; - rasterizer_desc.DepthClipEnable = TRUE; - - hr = device_handle->CreateRasterizerState (&rasterizer_desc, &rasterizer); + hr = gst_d3d11_device_get_rasterizer (device, &rasterizer); + if (!gst_d3d11_result (hr, device)) { + GST_ERROR_OBJECT (self, "Couldn't create rasterizer state"); + return FALSE; + } + + hr = gst_d3d11_device_get_rasterizer_msaa (device, &msaa_rasterizer); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Couldn't create rasterizer state"); return FALSE; } - rasterizer_desc.MultisampleEnable = TRUE; - rasterizer_desc.AntialiasedLineEnable = TRUE; - hr = device_handle->CreateRasterizerState (&rasterizer_desc, - &msaa_rasterizer); if (!gst_d3d11_result (hr, device)) { GST_ERROR_OBJECT (self, "Couldn't create MSAA rasterizer state"); return FALSE; 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 1c923ed5b4..17323f6609 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 @@ -70,5 +70,13 @@ HRESULT gst_d3d11_device_get_sampler (GstD3D11Device * device, D3D11_FILTER filter, ID3D11SamplerState ** sampler); +GST_D3D11_API +HRESULT gst_d3d11_device_get_rasterizer (GstD3D11Device * device, + ID3D11RasterizerState ** rasterizer); + +GST_D3D11_API +HRESULT gst_d3d11_device_get_rasterizer_msaa (GstD3D11Device * device, + ID3D11RasterizerState ** rasterizer); + 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 3da32f7a70..89a2b7549b 100644 --- a/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device.cpp +++ b/subprojects/gst-plugins-bad/gst-libs/gst/d3d11/gstd3d11device.cpp @@ -133,6 +133,9 @@ struct _GstD3D11DevicePrivate std::pair, ComPtr>> vs_cache; std::map > sampler_cache; + ID3D11RasterizerState *rs = nullptr; + ID3D11RasterizerState *rs_msaa = nullptr; + #if HAVE_D3D11SDKLAYERS_H ID3D11Debug *d3d11_debug = nullptr; ID3D11InfoQueue *d3d11_info_queue = nullptr; @@ -749,6 +752,8 @@ gst_d3d11_device_dispose (GObject * object) priv->vs_cache.clear (); priv->sampler_cache.clear (); + GST_D3D11_CLEAR_COM (priv->rs); + GST_D3D11_CLEAR_COM (priv->rs_msaa); GST_D3D11_CLEAR_COM (priv->device5); GST_D3D11_CLEAR_COM (priv->device_context4); GST_D3D11_CLEAR_COM (priv->video_device); @@ -1913,3 +1918,65 @@ gst_d3d11_device_get_sampler (GstD3D11Device * device, D3D11_FILTER filter, return S_OK; } + +HRESULT +gst_d3d11_device_get_rasterizer (GstD3D11Device * device, + ID3D11RasterizerState ** rasterizer) +{ + GstD3D11DevicePrivate *priv = device->priv; + D3D11_RASTERIZER_DESC desc; + HRESULT hr; + + std::lock_guard < std::mutex > lk (priv->resource_lock); + if (priv->rs) { + *rasterizer = priv->rs; + priv->rs->AddRef (); + return S_OK; + } + + memset (&desc, 0, sizeof (D3D11_RASTERIZER_DESC)); + desc.FillMode = D3D11_FILL_SOLID; + desc.CullMode = D3D11_CULL_NONE; + desc.DepthClipEnable = TRUE; + + hr = priv->device->CreateRasterizerState (&desc, rasterizer); + if (!gst_d3d11_result (hr, device)) + return hr; + + priv->rs = *rasterizer; + priv->rs->AddRef (); + + return S_OK; +} + +HRESULT +gst_d3d11_device_get_rasterizer_msaa (GstD3D11Device * device, + ID3D11RasterizerState ** rasterizer) +{ + GstD3D11DevicePrivate *priv = device->priv; + D3D11_RASTERIZER_DESC desc; + HRESULT hr; + + std::lock_guard < std::mutex > lk (priv->resource_lock); + if (priv->rs_msaa) { + *rasterizer = priv->rs_msaa; + priv->rs_msaa->AddRef (); + return S_OK; + } + + memset (&desc, 0, sizeof (D3D11_RASTERIZER_DESC)); + desc.FillMode = D3D11_FILL_SOLID; + desc.CullMode = D3D11_CULL_NONE; + desc.DepthClipEnable = TRUE; + desc.MultisampleEnable = TRUE; + desc.AntialiasedLineEnable = TRUE; + + hr = priv->device->CreateRasterizerState (&desc, rasterizer); + if (!gst_d3d11_result (hr, device)) + return hr; + + priv->rs_msaa = *rasterizer; + priv->rs_msaa->AddRef (); + + return S_OK; +}