mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-23 02:01:12 +00:00
d3d11converter: Reuse rasterizer state object
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5572>
This commit is contained in:
parent
e13612162b
commit
5f44390b3e
3 changed files with 82 additions and 13 deletions
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -133,6 +133,9 @@ struct _GstD3D11DevicePrivate
|
|||
std::pair<ComPtr<ID3D11VertexShader>, ComPtr<ID3D11InputLayout>>> vs_cache;
|
||||
std::map <D3D11_FILTER, ComPtr<ID3D11SamplerState>> 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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue