GST_DEBUG_CATEGORY_EXTERN (gst_d3d11_shader_debug);
#define GST_CAT_DEFAULT gst_d3d11_shader_debug
-/* too many const buffers doesn't make sense */
-#define MAX_CONST_BUFFERS 16
-
static GModule *d3d_compiler_module = NULL;
static pD3DCompile GstD3DCompileFunc = NULL;
return TRUE;
}
-
-struct _GstD3D11Quad
-{
- GstD3D11Device *device;
- ID3D11PixelShader *ps;
- ID3D11VertexShader *vs;
- ID3D11InputLayout *layout;
- ID3D11Buffer *const_buffer[MAX_CONST_BUFFERS];
- guint num_const_buffers;
- ID3D11Buffer *vertex_buffer;
- guint vertex_stride;
- ID3D11Buffer *index_buffer;
- DXGI_FORMAT index_format;
- guint index_count;
- D3D11_VIEWPORT viewport[GST_VIDEO_MAX_PLANES];
- ID3D11ShaderResourceView *srv[GST_VIDEO_MAX_PLANES];
- guint num_srv;
- ID3D11RenderTargetView *rtv[GST_VIDEO_MAX_PLANES];
- guint num_rtv;
-};
-
-GstD3D11Quad *
-gst_d3d11_quad_new (GstD3D11Device * device, ID3D11PixelShader * pixel_shader,
- ID3D11VertexShader * vertex_shader, ID3D11InputLayout * layout,
- ID3D11Buffer ** const_buffers, guint num_const_buffers,
- ID3D11Buffer * vertex_buffer, guint vertex_stride,
- ID3D11Buffer * index_buffer, DXGI_FORMAT index_format, guint index_count)
-{
- GstD3D11Quad *quad;
-
- g_return_val_if_fail (GST_IS_D3D11_DEVICE (device), NULL);
- g_return_val_if_fail (pixel_shader != NULL, NULL);
- g_return_val_if_fail (vertex_shader != NULL, NULL);
- g_return_val_if_fail (layout != NULL, NULL);
- g_return_val_if_fail (num_const_buffers <= MAX_CONST_BUFFERS, NULL);
- g_return_val_if_fail (vertex_buffer != NULL, NULL);
- g_return_val_if_fail (vertex_stride > 0, NULL);
- g_return_val_if_fail (index_buffer != NULL, NULL);
- g_return_val_if_fail (index_format != DXGI_FORMAT_UNKNOWN, NULL);
-
- quad = g_new0 (GstD3D11Quad, 1);
-
- quad->device = (GstD3D11Device *) gst_object_ref (device);
- quad->ps = pixel_shader;
- quad->vs = vertex_shader;
- quad->layout = layout;
- quad->vertex_buffer = vertex_buffer;
- quad->vertex_stride = vertex_stride;
- quad->index_buffer = index_buffer;
- quad->index_format = index_format;
- quad->index_count = index_count;
-
- pixel_shader->AddRef ();
- vertex_shader->AddRef ();
- layout->AddRef ();
- vertex_buffer->AddRef ();
- index_buffer->AddRef ();
-
- if (num_const_buffers > 0) {
- guint i;
-
- g_assert (const_buffers);
-
- for (i = 0; i < num_const_buffers; i++) {
- quad->const_buffer[i] = const_buffers[i];
- quad->const_buffer[i]->AddRef ();
- }
-
- quad->num_const_buffers = num_const_buffers;
- }
-
- return quad;
-}
-
-void
-gst_d3d11_quad_free (GstD3D11Quad * quad)
-{
- guint i;
-
- g_return_if_fail (quad != NULL);
-
- GST_D3D11_CLEAR_COM (quad->ps);
- GST_D3D11_CLEAR_COM (quad->vs);
- GST_D3D11_CLEAR_COM (quad->layout);
- for (i = 0; i < quad->num_const_buffers; i++)
- quad->const_buffer[i]->Release ();
- GST_D3D11_CLEAR_COM (quad->vertex_buffer);
- GST_D3D11_CLEAR_COM (quad->index_buffer);
-
- gst_clear_object (&quad->device);
- g_free (quad);
-}
-
-gboolean
-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,
- ID3D11BlendState * blend, gfloat blend_factor[4],
- ID3D11SamplerState ** sampler, guint num_sampler)
-{
- gboolean ret;
-
- g_return_val_if_fail (quad != NULL, FALSE);
-
- gst_d3d11_device_lock (quad->device);
- ret = gst_d3d11_draw_quad_unlocked (quad, viewport, num_viewport,
- srv, num_srv, rtv, num_viewport, blend, blend_factor, sampler,
- num_sampler);
- gst_d3d11_device_unlock (quad->device);
-
- return ret;
-}
-
-gboolean
-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,
- ID3D11BlendState * blend, gfloat blend_factor[4],
- ID3D11SamplerState ** sampler, guint num_sampler)
-{
- ID3D11DeviceContext *context;
- UINT offsets = 0;
- ID3D11ShaderResourceView *clear_view[GST_VIDEO_MAX_PLANES] = { NULL, };
- ID3D11BlendState *blend_state = blend;
-
- g_return_val_if_fail (quad != NULL, FALSE);
- g_return_val_if_fail (viewport != NULL, FALSE);
- g_return_val_if_fail (num_viewport <= GST_VIDEO_MAX_PLANES, FALSE);
- g_return_val_if_fail (rtv != NULL, FALSE);
- g_return_val_if_fail (num_rtv <= GST_VIDEO_MAX_PLANES, FALSE);
-
- context = gst_d3d11_device_get_device_context_handle (quad->device);
-
- context->IASetPrimitiveTopology (D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
- context->IASetInputLayout (quad->layout);
- context->IASetVertexBuffers (0, 1, &quad->vertex_buffer, &quad->vertex_stride,
- &offsets);
- context->IASetIndexBuffer (quad->index_buffer, quad->index_format, 0);
-
- 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);
-
- if (quad->num_const_buffers) {
- context->PSSetConstantBuffers (0, quad->num_const_buffers,
- quad->const_buffer);
- }
-
- if (srv)
- context->PSSetShaderResources (0, num_srv, srv);
- context->OMSetRenderTargets (num_rtv, rtv, NULL);
- context->OMSetBlendState (blend_state, blend_factor, 0xffffffff);
-
- context->DrawIndexed (quad->index_count, 0, 0);
-
- if (srv)
- context->PSSetShaderResources (0, num_srv, clear_view);
- context->OMSetRenderTargets (0, NULL, NULL);
-
- return TRUE;
-}
G_BEGIN_DECLS
-typedef struct _GstD3D11Quad GstD3D11Quad;
-
gboolean gst_d3d11_shader_init (void);
gboolean gst_d3d11_create_pixel_shader (GstD3D11Device * device,
ID3D11VertexShader ** shader,
ID3D11InputLayout ** layout);
-GstD3D11Quad * gst_d3d11_quad_new (GstD3D11Device * device,
- ID3D11PixelShader * pixel_shader,
- ID3D11VertexShader * vertex_shader,
- ID3D11InputLayout * layout,
- ID3D11Buffer ** const_buffers,
- guint num_const_buffers,
- ID3D11Buffer * vertex_buffer,
- guint vertex_stride,
- ID3D11Buffer * index_buffer,
- DXGI_FORMAT index_format,
- guint index_count);
-
-void gst_d3d11_quad_free (GstD3D11Quad * quad);
-
-gboolean 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,
- ID3D11BlendState *blend,
- gfloat blend_factor[4],
- ID3D11SamplerState ** sampler,
- guint num_sampler);
-
-gboolean 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,
- ID3D11BlendState *blend,
- gfloat blend_factor[4],
- ID3D11SamplerState ** sampler,
- guint num_sampler);
-
G_END_DECLS
#endif /* __GST_D3D11_SHADER_H__ */