[vlc-commits] direct3d11: use a separate structure for the compiled Vertex shader data
Steve Lhomme
git at videolan.org
Thu Aug 2 13:08:19 CEST 2018
vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Jul 13 13:46:51 2018 +0200| [c09c968dec2357a64ceeec19f4e08abf155a40af] | committer: Steve Lhomme
direct3d11: use a separate structure for the compiled Vertex shader data
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c09c968dec2357a64ceeec19f4e08abf155a40af
---
modules/video_output/win32/d3d11_quad.c | 12 +++++-----
modules/video_output/win32/d3d11_quad.h | 4 ++--
modules/video_output/win32/d3d11_shaders.c | 37 ++++++++++++++++++++++++------
modules/video_output/win32/d3d11_shaders.h | 16 +++++++++----
modules/video_output/win32/direct3d11.c | 30 ++++++++----------------
5 files changed, 59 insertions(+), 40 deletions(-)
diff --git a/modules/video_output/win32/d3d11_quad.c b/modules/video_output/win32/d3d11_quad.c
index b9a07275b8..b896c4d5ca 100644
--- a/modules/video_output/win32/d3d11_quad.c
+++ b/modules/video_output/win32/d3d11_quad.c
@@ -51,13 +51,13 @@ void D3D11_RenderQuad(d3d11_device_t *d3d_dev, d3d_quad_t *quad,
ID3D11DeviceContext_IASetPrimitiveTopology(d3d_dev->d3dcontext, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
/* vertex shader */
- ID3D11DeviceContext_IASetInputLayout(d3d_dev->d3dcontext, quad->pVertexLayout);
+ ID3D11DeviceContext_IASetInputLayout(d3d_dev->d3dcontext, quad->vertexShader.layout);
ID3D11DeviceContext_IASetVertexBuffers(d3d_dev->d3dcontext, 0, 1, &quad->pVertexBuffer, &quad->vertexStride, &offset);
ID3D11DeviceContext_IASetIndexBuffer(d3d_dev->d3dcontext, quad->pIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
if ( quad->pVertexShaderConstants )
ID3D11DeviceContext_VSSetConstantBuffers(d3d_dev->d3dcontext, 0, 1, &quad->pVertexShaderConstants);
- ID3D11DeviceContext_VSSetShader(d3d_dev->d3dcontext, quad->d3dvertexShader, NULL, 0);
+ ID3D11DeviceContext_VSSetShader(d3d_dev->d3dcontext, quad->vertexShader.shader, NULL, 0);
if (quad->d3dsampState[0])
ID3D11DeviceContext_PSSetSamplers(d3d_dev->d3dcontext, 0, 2, quad->d3dsampState);
@@ -156,7 +156,7 @@ void D3D11_ReleaseQuad(d3d_quad_t *quad)
ID3D11Buffer_Release(quad->pVertexBuffer);
quad->pVertexBuffer = NULL;
}
- quad->d3dvertexShader = NULL;
+ D3D11_ReleaseVertexShader(&quad->vertexShader);
if (quad->pIndexBuffer)
{
ID3D11Buffer_Release(quad->pIndexBuffer);
@@ -690,7 +690,7 @@ error:
#undef D3D11_SetupQuad
int D3D11_SetupQuad(vlc_object_t *o, d3d11_device_t *d3d_dev, const video_format_t *fmt, d3d_quad_t *quad,
const display_info_t *displayFormat, const RECT *output,
- ID3D11VertexShader *d3dvertexShader, ID3D11InputLayout *pVertexLayout,
+ d3d_vshader_t *shader,
video_orientation_t orientation)
{
const bool RGB_shader = IsRGBShader(quad->formatInfo);
@@ -841,8 +841,8 @@ int D3D11_SetupQuad(vlc_object_t *o, d3d11_device_t *d3d_dev, const video_format
quad->cropViewport[i].MinDepth = 0.0f;
quad->cropViewport[i].MaxDepth = 1.0f;
}
- quad->d3dvertexShader = d3dvertexShader;
- quad->pVertexLayout = pVertexLayout;
+ D3D11_ReleaseVertexShader(&quad->vertexShader);
+ D3D11_SetVertexShader(&quad->vertexShader, shader);
quad->resourceCount = DxgiResourceCount(quad->formatInfo);
return VLC_SUCCESS;
diff --git a/modules/video_output/win32/d3d11_quad.h b/modules/video_output/win32/d3d11_quad.h
index 0ce1ba3625..0b96433355 100644
--- a/modules/video_output/win32/d3d11_quad.h
+++ b/modules/video_output/win32/d3d11_quad.h
@@ -56,9 +56,9 @@ void D3D11_ReleaseQuad(d3d_quad_t *);
int D3D11_SetupQuad(vlc_object_t *, d3d11_device_t *, const video_format_t *, d3d_quad_t *,
const display_info_t *, const RECT *,
- ID3D11VertexShader *, ID3D11InputLayout *,
+ d3d_vshader_t *,
video_orientation_t);
-#define D3D11_SetupQuad(a,b,c,d,e,f,g,h,i) D3D11_SetupQuad(VLC_OBJECT(a),b,c,d,e,f,g,h,i)
+#define D3D11_SetupQuad(a,b,c,d,e,f,g,h) D3D11_SetupQuad(VLC_OBJECT(a),b,c,d,e,f,g,h)
bool D3D11_UpdateQuadPosition( vlc_object_t *, d3d11_device_t *, d3d_quad_t *,
const RECT *output, video_orientation_t );
diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c
index a16f47f455..010f644da5 100644
--- a/modules/video_output/win32/d3d11_shaders.c
+++ b/modules/video_output/win32/d3d11_shaders.c
@@ -701,7 +701,8 @@ void D3D11_ClearRenderTargets(d3d11_device_t *d3d_dev, const d3d_format_t *cfg,
}
static HRESULT D3D11_CompileVertexShader(vlc_object_t *obj, d3d11_handle_t *hd3d,
- d3d11_device_t *d3d_dev, const char *psz_shader, d3d_quad_t *quad)
+ d3d11_device_t *d3d_dev, const char *psz_shader,
+ d3d_vshader_t *output)
{
HRESULT hr;
ID3DBlob *pVSBlob = D3D11_CompileShader(obj, hd3d, d3d_dev, psz_shader, false);
@@ -709,7 +710,7 @@ static HRESULT D3D11_CompileVertexShader(vlc_object_t *obj, d3d11_handle_t *hd3d
goto error;
hr = ID3D11Device_CreateVertexShader(d3d_dev->d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
- ID3D10Blob_GetBufferSize(pVSBlob), NULL, &quad->d3dvertexShader);
+ ID3D10Blob_GetBufferSize(pVSBlob), NULL, &output->shader);
if(FAILED(hr)) {
msg_Err(obj, "Failed to create the flat vertex shader. (hr=0x%lX)", hr);
@@ -722,7 +723,7 @@ static HRESULT D3D11_CompileVertexShader(vlc_object_t *obj, d3d11_handle_t *hd3d
};
hr = ID3D11Device_CreateInputLayout(d3d_dev->d3ddevice, layout, 2, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
- ID3D10Blob_GetBufferSize(pVSBlob), &quad->pVertexLayout);
+ ID3D10Blob_GetBufferSize(pVSBlob), &output->layout);
ID3D10Blob_Release(pVSBlob);
pVSBlob = NULL;
@@ -736,16 +737,38 @@ error:
return hr;
}
+void D3D11_SetVertexShader(d3d_vshader_t *dst, d3d_vshader_t *src)
+{
+ dst->layout = src->layout;
+ ID3D11InputLayout_AddRef(dst->layout);
+ dst->shader = src->shader;
+ ID3D11VertexShader_AddRef(dst->shader);
+}
+
+void D3D11_ReleaseVertexShader(d3d_vshader_t *shader)
+{
+ if (shader->layout)
+ {
+ ID3D11InputLayout_Release(shader->layout);
+ shader->layout = NULL;
+ }
+ if (shader->shader)
+ {
+ ID3D11VertexShader_Release(shader->shader);
+ shader->shader = NULL;
+ }
+}
+
#undef D3D11_CompileFlatVertexShader
HRESULT D3D11_CompileFlatVertexShader(vlc_object_t *obj, d3d11_handle_t *hd3d,
- d3d11_device_t *d3d_dev, d3d_quad_t *quad)
+ d3d11_device_t *d3d_dev, d3d_vshader_t *output)
{
- return D3D11_CompileVertexShader(obj, hd3d, d3d_dev, globVertexShaderFlat, quad);
+ return D3D11_CompileVertexShader(obj, hd3d, d3d_dev, globVertexShaderFlat, output);
}
#undef D3D11_CompileProjectionVertexShader
HRESULT D3D11_CompileProjectionVertexShader(vlc_object_t *obj, d3d11_handle_t *hd3d,
- d3d11_device_t *d3d_dev, d3d_quad_t *quad)
+ d3d11_device_t *d3d_dev, d3d_vshader_t *output)
{
- return D3D11_CompileVertexShader(obj, hd3d, d3d_dev, globVertexShaderProjection, quad);
+ return D3D11_CompileVertexShader(obj, hd3d, d3d_dev, globVertexShaderProjection, output);
}
diff --git a/modules/video_output/win32/d3d11_shaders.h b/modules/video_output/win32/d3d11_shaders.h
index dc8266c892..13c7d23596 100644
--- a/modules/video_output/win32/d3d11_shaders.h
+++ b/modules/video_output/win32/d3d11_shaders.h
@@ -75,6 +75,12 @@ typedef struct {
const char* globVertexShaderFlat;
const char* globVertexShaderProjection;
+/* Vertex Shader compiled sructures */
+typedef struct {
+ ID3D11VertexShader *shader;
+ ID3D11InputLayout *layout;
+} d3d_vshader_t;
+
/* A Quad is texture that can be displayed in a rectangle */
typedef struct
{
@@ -84,7 +90,6 @@ typedef struct
ID3D11Buffer *pVertexBuffer;
UINT vertexCount;
UINT vertexStride;
- ID3D11VertexShader *d3dvertexShader;
ID3D11Buffer *pIndexBuffer;
UINT indexCount;
ID3D11Buffer *pVertexShaderConstants;
@@ -92,7 +97,7 @@ typedef struct
UINT PSConstantsCount;
ID3D11PixelShader *d3dpixelShader[D3D11_MAX_SHADER_VIEW];
ID3D11SamplerState *d3dsampState[2];
- ID3D11InputLayout *pVertexLayout;
+ d3d_vshader_t vertexShader;
D3D11_VIEWPORT cropViewport[D3D11_MAX_SHADER_VIEW];
unsigned int i_width;
unsigned int i_height;
@@ -114,10 +119,10 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *, d3d11_handle_t *, bool legacy_s
#define D3D11_CompilePixelShader(a,b,c,d,e,f,g,h) \
D3D11_CompilePixelShader(VLC_OBJECT(a),b,c,d,e,f,g,h)
-HRESULT D3D11_CompileFlatVertexShader(vlc_object_t *, d3d11_handle_t *, d3d11_device_t *, d3d_quad_t *);
+HRESULT D3D11_CompileFlatVertexShader(vlc_object_t *, d3d11_handle_t *, d3d11_device_t *, d3d_vshader_t *);
#define D3D11_CompileFlatVertexShader(a,b,c,d) D3D11_CompileFlatVertexShader(VLC_OBJECT(a),b,c,d)
-HRESULT D3D11_CompileProjectionVertexShader(vlc_object_t *, d3d11_handle_t *, d3d11_device_t *, d3d_quad_t *);
+HRESULT D3D11_CompileProjectionVertexShader(vlc_object_t *, d3d11_handle_t *, d3d11_device_t *, d3d_vshader_t *);
#define D3D11_CompileProjectionVertexShader(a,b,c,d) D3D11_CompileProjectionVertexShader(VLC_OBJECT(a),b,c,d)
float GetFormatLuminance(vlc_object_t *, const video_format_t *);
@@ -129,4 +134,7 @@ HRESULT D3D11_CreateRenderTargets(d3d11_device_t *, ID3D11Resource *, const d3d_
void D3D11_ClearRenderTargets(d3d11_device_t *, const d3d_format_t *,
ID3D11RenderTargetView *targets[D3D11_MAX_SHADER_VIEW]);
+void D3D11_SetVertexShader(d3d_vshader_t *dst, d3d_vshader_t *src);
+void D3D11_ReleaseVertexShader(d3d_vshader_t *);
+
#endif /* VLC_D3D11_SHADERS_H */
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index 693503cdf0..6f7250e076 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -104,7 +104,8 @@ struct vout_display_sys_t
ID3D11RenderTargetView *d3drenderTargetView[D3D11_MAX_SHADER_VIEW];
- d3d_quad_t projectionQuad;
+ d3d_vshader_t projectionVShader;
+ d3d_vshader_t flatVShader;
/* copy from the decoder pool into picSquad before display
* Uses a Texture2D with slices rather than a Texture2DArray for the decoder */
@@ -359,8 +360,7 @@ static picture_pool_t *Pool(vout_display_t *vd, unsigned pool_size)
}
if (D3D11_SetupQuad( vd, &sys->d3d_dev, &surface_fmt, &sys->picQuad, &sys->display, &sys->sys.rect_src_clipped,
- vd->fmt.projection_mode == PROJECTION_MODE_RECTANGULAR ? sys->regionQuad.d3dvertexShader : sys->projectionQuad.d3dvertexShader,
- sys->regionQuad.pVertexLayout,
+ vd->fmt.projection_mode == PROJECTION_MODE_RECTANGULAR ? &sys->flatVShader : &sys->projectionVShader,
vd->fmt.orientation ) != VLC_SUCCESS) {
msg_Err(vd, "Could not Create the main quad picture.");
return NULL;
@@ -1523,13 +1523,13 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd)
}
}
- hr = D3D11_CompileFlatVertexShader(vd, &sys->hd3d, &sys->d3d_dev, &sys->regionQuad);
+ hr = D3D11_CompileFlatVertexShader(vd, &sys->hd3d, &sys->d3d_dev, &sys->flatVShader);
if(FAILED(hr)) {
msg_Err(vd, "Failed to create the vertex input layout. (hr=0x%lX)", hr);
return VLC_EGENERIC;
}
- hr = D3D11_CompileProjectionVertexShader(vd, &sys->hd3d, &sys->d3d_dev, &sys->projectionQuad);
+ hr = D3D11_CompileProjectionVertexShader(vd, &sys->hd3d, &sys->d3d_dev, &sys->projectionVShader);
if(FAILED(hr)) {
msg_Err(vd, "Failed to create the projection vertex shader. (hr=0x%lX)", hr);
return VLC_EGENERIC;
@@ -1562,21 +1562,9 @@ static void Direct3D11DestroyResources(vout_display_t *vd)
ReleasePictureSys(&sys->stagingSys);
- if (sys->regionQuad.pVertexLayout)
- {
- ID3D11InputLayout_Release(sys->regionQuad.pVertexLayout);
- sys->regionQuad.pVertexLayout = NULL;
- }
- if (sys->regionQuad.d3dvertexShader)
- {
- ID3D11VertexShader_Release(sys->regionQuad.d3dvertexShader);
- sys->regionQuad.d3dvertexShader = NULL;
- }
- if (sys->projectionQuad.d3dvertexShader)
- {
- ID3D11VertexShader_Release(sys->projectionQuad.d3dvertexShader);
- sys->projectionQuad.d3dvertexShader = NULL;
- }
+ D3D11_ReleaseVertexShader(&sys->flatVShader);
+ D3D11_ReleaseVertexShader(&sys->projectionVShader);
+
for (size_t i=0; i < D3D11_MAX_SHADER_VIEW; i++)
{
if (sys->d3drenderTargetView[i]) {
@@ -1693,7 +1681,7 @@ static int Direct3D11MapSubpicture(vout_display_t *vd, int *subpicture_region_co
}
err = D3D11_SetupQuad( vd, &sys->d3d_dev, &r->fmt, d3dquad, &sys->display, &output,
- sys->regionQuad.d3dvertexShader, sys->regionQuad.pVertexLayout, ORIENT_NORMAL );
+ &sys->flatVShader, ORIENT_NORMAL );
if (err != VLC_SUCCESS) {
msg_Err(vd, "Failed to setup %dx%d quad for OSD",
r->fmt.i_visible_width, r->fmt.i_visible_height);
More information about the vlc-commits
mailing list