mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-19 16:21:17 +00:00
d3d11shader: Don't hold state object in GstD3D11Quad
We might want to update state object Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2276>
This commit is contained in:
parent
49992be643
commit
f3331652f2
5 changed files with 32 additions and 48 deletions
|
@ -2049,7 +2049,7 @@ gst_d3d11_compositor_create_checker_quad (GstD3D11Compositor * self)
|
|||
context_handle->Unmap (index_buffer.Get (), 0);
|
||||
|
||||
quad = gst_d3d11_quad_new (self->device,
|
||||
ps.Get (), vs.Get (), layout.Get (), NULL, NULL, NULL, NULL,
|
||||
ps.Get (), vs.Get (), layout.Get (), NULL,
|
||||
vertex_buffer.Get (), sizeof (VertexData), index_buffer.Get (),
|
||||
DXGI_FORMAT_R16_UINT, 6);
|
||||
if (!quad) {
|
||||
|
@ -2081,7 +2081,7 @@ gst_d3d11_compositor_draw_background_checker (GstD3D11Compositor * self,
|
|||
}
|
||||
|
||||
return gst_d3d11_draw_quad_unlocked (self->checker_background,
|
||||
&self->viewport, 1, NULL, 0, &rtv, 1, NULL, NULL, NULL);
|
||||
&self->viewport, 1, NULL, 0, &rtv, 1, NULL, NULL, NULL, 0);
|
||||
}
|
||||
|
||||
/* Must be called with d3d11 device lock */
|
||||
|
|
|
@ -350,6 +350,8 @@ struct _GstD3D11Converter
|
|||
ID3D11Buffer *vertex_buffer;
|
||||
gboolean update_vertex;
|
||||
|
||||
ID3D11SamplerState *linear_sampler;
|
||||
|
||||
ConvertInfo convert_info;
|
||||
};
|
||||
|
||||
|
@ -1068,7 +1070,7 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Converter * self,
|
|||
ComPtr<ID3D11PixelShader> ps[CONVERTER_MAX_QUADS];
|
||||
ComPtr<ID3D11VertexShader> vs;
|
||||
ComPtr<ID3D11InputLayout> layout;
|
||||
ComPtr<ID3D11SamplerState> sampler;
|
||||
ComPtr<ID3D11SamplerState> linear_sampler;
|
||||
ComPtr<ID3D11Buffer> const_buffer;
|
||||
ComPtr<ID3D11Buffer> vertex_buffer;
|
||||
ComPtr<ID3D11Buffer> index_buffer;
|
||||
|
@ -1093,7 +1095,7 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Converter * self,
|
|||
sampler_desc.MinLOD = 0;
|
||||
sampler_desc.MaxLOD = D3D11_FLOAT32_MAX;
|
||||
|
||||
hr = device_handle->CreateSamplerState (&sampler_desc, &sampler);
|
||||
hr = device_handle->CreateSamplerState (&sampler_desc, &linear_sampler);
|
||||
if (!gst_d3d11_result (hr, device)) {
|
||||
GST_ERROR ("Couldn't create sampler state, hr: 0x%x", (guint) hr);
|
||||
return FALSE;
|
||||
|
@ -1262,13 +1264,13 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Converter * self,
|
|||
gst_d3d11_device_unlock (device);
|
||||
|
||||
self->quad[0] = gst_d3d11_quad_new (device,
|
||||
ps[0].Get (), vs.Get (), layout.Get (), sampler.Get (), NULL, NULL,
|
||||
ps[0].Get (), vs.Get (), layout.Get (),
|
||||
const_buffer.Get (), vertex_buffer.Get (), sizeof (VertexData),
|
||||
index_buffer.Get (), DXGI_FORMAT_R16_UINT, index_count);
|
||||
|
||||
if (ps[1]) {
|
||||
self->quad[1] = gst_d3d11_quad_new (device,
|
||||
ps[1].Get (), vs.Get (), layout.Get (), sampler.Get (), NULL, NULL,
|
||||
ps[1].Get (), vs.Get (), layout.Get (),
|
||||
const_buffer.Get (), vertex_buffer.Get (), sizeof (VertexData),
|
||||
index_buffer.Get (), DXGI_FORMAT_R16_UINT, index_count);
|
||||
}
|
||||
|
@ -1292,6 +1294,8 @@ gst_d3d11_color_convert_setup_shader (GstD3D11Converter * self,
|
|||
self->input_texture_width = GST_VIDEO_INFO_WIDTH (in_info);
|
||||
self->input_texture_height = GST_VIDEO_INFO_HEIGHT (in_info);
|
||||
|
||||
self->linear_sampler = linear_sampler.Detach ();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -1448,6 +1452,7 @@ gst_d3d11_converter_free (GstD3D11Converter * converter)
|
|||
}
|
||||
|
||||
GST_D3D11_CLEAR_COM (converter->vertex_buffer);
|
||||
GST_D3D11_CLEAR_COM (converter->linear_sampler);
|
||||
|
||||
gst_clear_object (&converter->device);
|
||||
g_free (converter);
|
||||
|
@ -1604,7 +1609,8 @@ gst_d3d11_converter_convert_unlocked (GstD3D11Converter * converter,
|
|||
}
|
||||
|
||||
ret = gst_d3d11_draw_quad_unlocked (converter->quad[0], converter->viewport,
|
||||
1, srv, converter->num_input_view, rtv, 1, NULL, blend, blend_factor);
|
||||
1, srv, converter->num_input_view, rtv, 1, blend, blend_factor,
|
||||
&converter->linear_sampler, 1);
|
||||
|
||||
if (!ret)
|
||||
return FALSE;
|
||||
|
@ -1613,7 +1619,7 @@ gst_d3d11_converter_convert_unlocked (GstD3D11Converter * converter,
|
|||
ret = gst_d3d11_draw_quad_unlocked (converter->quad[1],
|
||||
&converter->viewport[1], converter->num_output_view - 1,
|
||||
srv, converter->num_input_view, &rtv[1], converter->num_output_view - 1,
|
||||
NULL, blend, blend_factor);
|
||||
blend, blend_factor, &converter->linear_sampler, 1);
|
||||
|
||||
if (!ret)
|
||||
return FALSE;
|
||||
|
|
|
@ -285,7 +285,7 @@ gst_d3d11_composition_overlay_new (GstD3D11OverlayCompositor * self,
|
|||
overlay->texture = texture.Detach ();
|
||||
overlay->srv = srv.Detach ();
|
||||
overlay->quad = gst_d3d11_quad_new (device,
|
||||
self->ps, self->vs, self->layout, self->sampler, self->blend, NULL, NULL,
|
||||
self->ps, self->vs, self->layout, NULL,
|
||||
vertex_buffer.Get (), sizeof (VertexData),
|
||||
self->index_buffer, DXGI_FORMAT_R16_UINT, index_count);
|
||||
|
||||
|
@ -637,7 +637,8 @@ gst_d3d11_overlay_compositor_draw_unlocked (GstD3D11OverlayCompositor *
|
|||
(GstD3D11CompositionOverlay *) iter->data;
|
||||
|
||||
ret = gst_d3d11_draw_quad_unlocked (overlay->quad,
|
||||
&compositor->viewport, 1, &overlay->srv, 1, rtv, 1, NULL, NULL, NULL);
|
||||
&compositor->viewport, 1, &overlay->srv, 1, rtv, 1,
|
||||
compositor->blend, NULL, &compositor->sampler, 1);
|
||||
|
||||
if (!ret)
|
||||
break;
|
||||
|
|
|
@ -237,9 +237,6 @@ struct _GstD3D11Quad
|
|||
ID3D11PixelShader *ps;
|
||||
ID3D11VertexShader *vs;
|
||||
ID3D11InputLayout *layout;
|
||||
ID3D11SamplerState *sampler;
|
||||
ID3D11BlendState *blend;
|
||||
ID3D11DepthStencilState *depth_stencil;
|
||||
ID3D11Buffer *const_buffer;
|
||||
ID3D11Buffer *vertex_buffer;
|
||||
guint vertex_stride;
|
||||
|
@ -256,8 +253,6 @@ struct _GstD3D11Quad
|
|||
GstD3D11Quad *
|
||||
gst_d3d11_quad_new (GstD3D11Device * device, ID3D11PixelShader * pixel_shader,
|
||||
ID3D11VertexShader * vertex_shader, ID3D11InputLayout * layout,
|
||||
ID3D11SamplerState * sampler, ID3D11BlendState * blend,
|
||||
ID3D11DepthStencilState * depth_stencil,
|
||||
ID3D11Buffer * const_buffer,
|
||||
ID3D11Buffer * vertex_buffer, guint vertex_stride,
|
||||
ID3D11Buffer * index_buffer, DXGI_FORMAT index_format, guint index_count)
|
||||
|
@ -279,9 +274,6 @@ gst_d3d11_quad_new (GstD3D11Device * device, ID3D11PixelShader * pixel_shader,
|
|||
quad->ps = pixel_shader;
|
||||
quad->vs = vertex_shader;
|
||||
quad->layout = layout;
|
||||
quad->sampler = sampler;
|
||||
quad->blend = blend;
|
||||
quad->depth_stencil = depth_stencil;
|
||||
quad->vertex_buffer = vertex_buffer;
|
||||
quad->vertex_stride = vertex_stride;
|
||||
quad->index_buffer = index_buffer;
|
||||
|
@ -294,15 +286,6 @@ gst_d3d11_quad_new (GstD3D11Device * device, ID3D11PixelShader * pixel_shader,
|
|||
vertex_buffer->AddRef ();
|
||||
index_buffer->AddRef ();
|
||||
|
||||
if (sampler)
|
||||
sampler->AddRef ();
|
||||
|
||||
if (blend)
|
||||
blend->AddRef ();
|
||||
|
||||
if (depth_stencil)
|
||||
depth_stencil->AddRef ();
|
||||
|
||||
if (const_buffer) {
|
||||
quad->const_buffer = const_buffer;
|
||||
const_buffer->AddRef ();
|
||||
|
@ -319,9 +302,6 @@ gst_d3d11_quad_free (GstD3D11Quad * quad)
|
|||
GST_D3D11_CLEAR_COM (quad->ps);
|
||||
GST_D3D11_CLEAR_COM (quad->vs);
|
||||
GST_D3D11_CLEAR_COM (quad->layout);
|
||||
GST_D3D11_CLEAR_COM (quad->sampler);
|
||||
GST_D3D11_CLEAR_COM (quad->blend);
|
||||
GST_D3D11_CLEAR_COM (quad->depth_stencil);
|
||||
GST_D3D11_CLEAR_COM (quad->const_buffer);
|
||||
GST_D3D11_CLEAR_COM (quad->vertex_buffer);
|
||||
GST_D3D11_CLEAR_COM (quad->index_buffer);
|
||||
|
@ -335,8 +315,8 @@ gst_d3d11_draw_quad (GstD3D11Quad * quad,
|
|||
D3D11_VIEWPORT viewport[GST_VIDEO_MAX_PLANES], guint num_viewport,
|
||||
ID3D11ShaderResourceView * srv[GST_VIDEO_MAX_PLANES], guint num_srv,
|
||||
ID3D11RenderTargetView * rtv[GST_VIDEO_MAX_PLANES], guint num_rtv,
|
||||
ID3D11DepthStencilView * dsv, ID3D11BlendState * blend,
|
||||
gfloat blend_factor[4])
|
||||
ID3D11BlendState * blend, gfloat blend_factor[4],
|
||||
ID3D11SamplerState ** sampler, guint num_sampler)
|
||||
{
|
||||
gboolean ret;
|
||||
|
||||
|
@ -344,7 +324,8 @@ gst_d3d11_draw_quad (GstD3D11Quad * quad,
|
|||
|
||||
gst_d3d11_device_lock (quad->device);
|
||||
ret = gst_d3d11_draw_quad_unlocked (quad, viewport, num_viewport,
|
||||
srv, num_srv, rtv, num_viewport, dsv, blend, blend_factor);
|
||||
srv, num_srv, rtv, num_viewport, blend, blend_factor, sampler,
|
||||
num_sampler);
|
||||
gst_d3d11_device_unlock (quad->device);
|
||||
|
||||
return ret;
|
||||
|
@ -355,8 +336,8 @@ gst_d3d11_draw_quad_unlocked (GstD3D11Quad * quad,
|
|||
D3D11_VIEWPORT viewport[GST_VIDEO_MAX_PLANES], guint num_viewport,
|
||||
ID3D11ShaderResourceView * srv[GST_VIDEO_MAX_PLANES], guint num_srv,
|
||||
ID3D11RenderTargetView * rtv[GST_VIDEO_MAX_PLANES], guint num_rtv,
|
||||
ID3D11DepthStencilView * dsv, ID3D11BlendState * blend,
|
||||
gfloat blend_factor[4])
|
||||
ID3D11BlendState * blend, gfloat blend_factor[4],
|
||||
ID3D11SamplerState ** sampler, guint num_sampler)
|
||||
{
|
||||
ID3D11DeviceContext *context;
|
||||
UINT offsets = 0;
|
||||
|
@ -377,8 +358,8 @@ gst_d3d11_draw_quad_unlocked (GstD3D11Quad * quad,
|
|||
&offsets);
|
||||
context->IASetIndexBuffer (quad->index_buffer, quad->index_format, 0);
|
||||
|
||||
if (quad->sampler)
|
||||
context->PSSetSamplers (0, 1, &quad->sampler);
|
||||
if (sampler)
|
||||
context->PSSetSamplers (0, num_sampler, sampler);
|
||||
context->VSSetShader (quad->vs, NULL, 0);
|
||||
context->PSSetShader (quad->ps, NULL, 0);
|
||||
context->RSSetViewports (num_viewport, viewport);
|
||||
|
@ -388,11 +369,8 @@ gst_d3d11_draw_quad_unlocked (GstD3D11Quad * quad,
|
|||
|
||||
if (srv)
|
||||
context->PSSetShaderResources (0, num_srv, srv);
|
||||
context->OMSetRenderTargets (num_rtv, rtv, dsv);
|
||||
if (!blend_state)
|
||||
blend_state = quad->blend;
|
||||
context->OMSetRenderTargets (num_rtv, rtv, NULL);
|
||||
context->OMSetBlendState (blend_state, blend_factor, 0xffffffff);
|
||||
context->OMSetDepthStencilState (quad->depth_stencil, 1);
|
||||
|
||||
context->DrawIndexed (quad->index_count, 0, 0);
|
||||
|
||||
|
|
|
@ -47,9 +47,6 @@ GstD3D11Quad * gst_d3d11_quad_new (GstD3D11Device * device,
|
|||
ID3D11PixelShader * pixel_shader,
|
||||
ID3D11VertexShader * vertex_shader,
|
||||
ID3D11InputLayout * layout,
|
||||
ID3D11SamplerState * sampler,
|
||||
ID3D11BlendState * blend,
|
||||
ID3D11DepthStencilState *depth_stencil,
|
||||
ID3D11Buffer * const_buffer,
|
||||
ID3D11Buffer * vertex_buffer,
|
||||
guint vertex_stride,
|
||||
|
@ -66,9 +63,10 @@ gboolean gst_d3d11_draw_quad (GstD3D11Quad * quad,
|
|||
guint num_srv,
|
||||
ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES],
|
||||
guint num_rtv,
|
||||
ID3D11DepthStencilView *dsv,
|
||||
ID3D11BlendState *blend,
|
||||
gfloat blend_factor[4]);
|
||||
gfloat blend_factor[4],
|
||||
ID3D11SamplerState ** sampler,
|
||||
guint num_sampler);
|
||||
|
||||
gboolean gst_d3d11_draw_quad_unlocked (GstD3D11Quad * quad,
|
||||
D3D11_VIEWPORT viewport[GST_VIDEO_MAX_PLANES],
|
||||
|
@ -77,9 +75,10 @@ gboolean gst_d3d11_draw_quad_unlocked (GstD3D11Quad * quad,
|
|||
guint num_srv,
|
||||
ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES],
|
||||
guint num_rtv,
|
||||
ID3D11DepthStencilView *dsv,
|
||||
ID3D11BlendState *blend,
|
||||
gfloat blend_factor[4]);
|
||||
gfloat blend_factor[4],
|
||||
ID3D11SamplerState ** sampler,
|
||||
guint num_sampler);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
Loading…
Reference in a new issue