[vlc-devel] [PATCH 1/5] direct3d11: use a different vertex shader per quad
Stève Lhomme
robux4 at videolabs.io
Mon Nov 21 17:56:49 CET 2016
Merged
On Mon, Nov 21, 2016 at 5:55 PM, Steve Lhomme <robux4 at videolabs.io> wrote:
> The SPU need the flat vertex shader but others may need different shaders.
> ---
> modules/video_output/win32/common.h | 2 +
> modules/video_output/win32/direct3d11.c | 102 +++++++++++++++++---------------
> 2 files changed, 57 insertions(+), 47 deletions(-)
>
> diff --git a/modules/video_output/win32/common.h b/modules/video_output/win32/common.h
> index 5190fab..c9eceaf 100644
> --- a/modules/video_output/win32/common.h
> +++ b/modules/video_output/win32/common.h
> @@ -62,6 +62,8 @@ typedef struct
> {
> ID3D11Buffer *pVertexBuffer;
> UINT vertexCount;
> + ID3D11VertexShader *d3dvertexShader;
> + ID3D11InputLayout *pVertexLayout;
> ID3D11Buffer *pIndexBuffer;
> UINT indexCount;
> ID3D11Texture2D *pTexture;
> diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
> index 23703b9..17499fc 100644
> --- a/modules/video_output/win32/direct3d11.c
> +++ b/modules/video_output/win32/direct3d11.c
> @@ -909,15 +909,21 @@ static void DisplayD3DPicture(vout_display_sys_t *sys, d3d_quad_t *quad)
> UINT offset = 0;
>
> /* Render the quad */
> - ID3D11DeviceContext_RSSetViewports(sys->d3dcontext, 1, &quad->cropViewport);
> + /* vertex shader */
> + ID3D11DeviceContext_IASetVertexBuffers(sys->d3dcontext, 0, 1, &quad->pVertexBuffer, &stride, &offset);
> + ID3D11DeviceContext_IASetIndexBuffer(sys->d3dcontext, quad->pIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
> +
> + ID3D11DeviceContext_VSSetShader(sys->d3dcontext, quad->d3dvertexShader, NULL, 0);
> + ID3D11DeviceContext_IASetInputLayout(sys->d3dcontext, quad->pVertexLayout);
> +
> + /* pixel shader */
> ID3D11DeviceContext_PSSetShader(sys->d3dcontext, quad->d3dpixelShader, NULL, 0);
> ID3D11DeviceContext_PSSetShaderResources(sys->d3dcontext, 0, 1, &quad->d3dresViewY);
> -
> if( quad->d3dresViewUV )
> ID3D11DeviceContext_PSSetShaderResources(sys->d3dcontext, 1, 1, &quad->d3dresViewUV);
>
> - ID3D11DeviceContext_IASetVertexBuffers(sys->d3dcontext, 0, 1, &quad->pVertexBuffer, &stride, &offset);
> - ID3D11DeviceContext_IASetIndexBuffer(sys->d3dcontext, quad->pIndexBuffer, DXGI_FORMAT_R16_UINT, 0);
> + ID3D11DeviceContext_RSSetViewports(sys->d3dcontext, 1, &quad->cropViewport);
> +
> ID3D11DeviceContext_DrawIndexed(sys->d3dcontext, quad->indexCount, 0, 0);
> }
>
> @@ -1474,49 +1480,6 @@ static int Direct3D11CreateResources(vout_display_t *vd, video_format_t *fmt)
> ID3D11DepthStencilState_Release(pDepthStencilState);
> }
>
> - ID3DBlob* pVSBlob = NULL;
> -
> - /* TODO : Match the version to the D3D_FEATURE_LEVEL */
> - hr = D3DCompile(globVertexShaderDefault, strlen(globVertexShaderDefault),
> - NULL, NULL, NULL, "VS", "vs_4_0_level_9_1", 0, 0, &pVSBlob, NULL);
> -
> - if( FAILED(hr)) {
> - msg_Err(vd, "The Vertex Shader is invalid. (hr=0x%lX)", hr);
> - return VLC_EGENERIC;
> - }
> -
> - ID3D11VertexShader *d3dvertexShader;
> - hr = ID3D11Device_CreateVertexShader(sys->d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
> - ID3D10Blob_GetBufferSize(pVSBlob), NULL, &d3dvertexShader);
> -
> - if(FAILED(hr)) {
> - ID3D11Device_Release(pVSBlob);
> - msg_Err(vd, "Failed to create the vertex shader. (hr=0x%lX)", hr);
> - return VLC_EGENERIC;
> - }
> - ID3D11DeviceContext_VSSetShader(sys->d3dcontext, d3dvertexShader, NULL, 0);
> - ID3D11VertexShader_Release(d3dvertexShader);
> -
> - D3D11_INPUT_ELEMENT_DESC layout[] = {
> - { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
> - { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
> - { "OPACITY", 0, DXGI_FORMAT_R32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
> - };
> -
> - ID3D11InputLayout* pVertexLayout = NULL;
> - hr = ID3D11Device_CreateInputLayout(sys->d3ddevice, layout, 3, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
> - ID3D10Blob_GetBufferSize(pVSBlob), &pVertexLayout);
> -
> - ID3D10Blob_Release(pVSBlob);
> -
> - if(FAILED(hr)) {
> - msg_Err(vd, "Failed to create the vertex input layout. (hr=0x%lX)", hr);
> - return VLC_EGENERIC;
> - }
> -
> - ID3D11DeviceContext_IASetInputLayout(sys->d3dcontext, pVertexLayout);
> - ID3D11SamplerState_Release(pVertexLayout);
> -
> ID3D11DeviceContext_IASetPrimitiveTopology(sys->d3dcontext, D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
>
> ID3DBlob* pPSBlob = NULL;
> @@ -1698,6 +1661,41 @@ static int AllocQuad(vout_display_t *vd, const video_format_t *fmt, d3d_quad_t *
> goto error;
> }
>
> + ID3DBlob* pVSBlob = NULL;
> + /* TODO : Match the version to the D3D_FEATURE_LEVEL */
> + hr = D3DCompile(globVertexShaderDefault, strlen(globVertexShaderDefault),
> + NULL, NULL, NULL, "VS", "vs_4_0_level_9_1", 0, 0, &pVSBlob, NULL);
> +
> + if( FAILED(hr)) {
> + msg_Err(vd, "The Vertex Shader is invalid. (hr=0x%lX)", hr);
> + goto error;
> + }
> +
> + D3D11_INPUT_ELEMENT_DESC layout[] = {
> + { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
> + { "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0},
> + { "OPACITY", 0, DXGI_FORMAT_R32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0},
> + };
> +
> + hr = ID3D11Device_CreateInputLayout(sys->d3ddevice, layout, 3, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
> + ID3D10Blob_GetBufferSize(pVSBlob), &quad->pVertexLayout);
> +
> + ID3D10Blob_Release(pVSBlob);
> +
> + if(FAILED(hr)) {
> + msg_Err(vd, "Failed to create the vertex input layout. (hr=0x%lX)", hr);
> + goto error;
> + }
> +
> + hr = ID3D11Device_CreateVertexShader(sys->d3ddevice, (void *)ID3D10Blob_GetBufferPointer(pVSBlob),
> + ID3D10Blob_GetBufferSize(pVSBlob), NULL, &quad->d3dvertexShader);
> +
> + if(FAILED(hr)) {
> + ID3D11Device_Release(pVSBlob);
> + msg_Err(vd, "Failed to create the vertex shader. (hr=0x%lX)", hr);
> + goto error;
> + }
> +
> D3D11_TEXTURE2D_DESC texDesc;
> memset(&texDesc, 0, sizeof(texDesc));
> texDesc.Width = b_visible ? fmt->i_visible_width : fmt->i_width;
> @@ -1854,6 +1852,16 @@ static void ReleaseQuad(d3d_quad_t *quad)
> ID3D11Buffer_Release(quad->pVertexBuffer);
> quad->pVertexBuffer = NULL;
> }
> + if (quad->d3dvertexShader)
> + {
> + ID3D11VertexShader_Release(quad->d3dvertexShader);
> + quad->d3dvertexShader = NULL;
> + }
> + if (quad->pVertexLayout)
> + {
> + ID3D11SamplerState_Release(quad->pVertexLayout);
> + quad->pVertexLayout = NULL;
> + }
> if (quad->pIndexBuffer)
> {
> ID3D11Buffer_Release(quad->pIndexBuffer);
> --
> 2.10.1
>
More information about the vlc-devel
mailing list