vlc | branch: master | Steve Lhomme <[email protected]> | Tue Jan 30 15:41:22 2018 +0100| [70f4ab30c3fa0fa9b6cc0f5032db6f0ee89db5c9] | committer: Steve Lhomme
d3d11_shaders: compile a sampler state per shader > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=70f4ab30c3fa0fa9b6cc0f5032db6f0ee89db5c9 --- modules/video_output/win32/d3d11_quad.c | 11 ++++++++++ modules/video_output/win32/d3d11_quad.h | 1 + modules/video_output/win32/d3d11_shaders.c | 31 +++++++++++++++++++++++++++- modules/video_output/win32/d3d11_shaders.h | 7 ++++--- modules/video_output/win32/direct3d11.c | 33 ++---------------------------- 5 files changed, 48 insertions(+), 35 deletions(-) diff --git a/modules/video_output/win32/d3d11_quad.c b/modules/video_output/win32/d3d11_quad.c index fc88d54979..69b29f891d 100644 --- a/modules/video_output/win32/d3d11_quad.c +++ b/modules/video_output/win32/d3d11_quad.c @@ -59,6 +59,9 @@ void D3D11_RenderQuad(d3d11_device_t *d3d_dev, d3d_quad_t *quad, ID3D11DeviceContext_VSSetShader(d3d_dev->d3dcontext, quad->d3dvertexShader, NULL, 0); + if (quad->d3dsampState[0]) + ID3D11DeviceContext_PSSetSamplers(d3d_dev->d3dcontext, 0, 2, quad->d3dsampState); + /* pixel shader */ ID3D11DeviceContext_PSSetConstantBuffers(d3d_dev->d3dcontext, 0, quad->PSConstantsCount, quad->pPixelShaderConstants); assert(quad->resourceCount <= D3D11_MAX_SHADER_VIEW); @@ -172,6 +175,14 @@ void D3D11_ReleaseQuad(d3d_quad_t *quad) quad->d3dpixelShader[i] = NULL; } } + for (size_t i=0; i<2; i++) + { + if (quad->d3dsampState[i]) + { + ID3D11SamplerState_Release(quad->d3dsampState[i]); + quad->d3dsampState[i] = NULL; + } + } ReleasePictureSys(&quad->picSys); } diff --git a/modules/video_output/win32/d3d11_quad.h b/modules/video_output/win32/d3d11_quad.h index b8d541cf92..0204b44c20 100644 --- a/modules/video_output/win32/d3d11_quad.h +++ b/modules/video_output/win32/d3d11_quad.h @@ -44,6 +44,7 @@ typedef struct ID3D11Buffer *pPixelShaderConstants[2]; UINT PSConstantsCount; ID3D11PixelShader *d3dpixelShader[D3D11_MAX_SHADER_VIEW]; + ID3D11SamplerState *d3dsampState[2]; ID3D11InputLayout *pVertexLayout; D3D11_VIEWPORT cropViewport[D3D11_MAX_SHADER_VIEW]; unsigned int i_width; diff --git a/modules/video_output/win32/d3d11_shaders.c b/modules/video_output/win32/d3d11_shaders.c index 8299d0bc43..e3bbb0d232 100644 --- a/modules/video_output/win32/d3d11_shaders.c +++ b/modules/video_output/win32/d3d11_shaders.c @@ -245,7 +245,8 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg d3d11_device_t *d3d_dev, const d3d_format_t *format, const display_info_t *display, video_transfer_func_t transfer, bool src_full_range, - ID3D11PixelShader *output[D3D11_MAX_SHADER_VIEW]) + ID3D11PixelShader *output[D3D11_MAX_SHADER_VIEW], + ID3D11SamplerState *d3dsampState[2]) { static const char *DEFAULT_NOOP = "return rgb"; const char *psz_sampler[2] = {NULL, NULL}; @@ -256,6 +257,34 @@ HRESULT D3D11_CompilePixelShader(vlc_object_t *o, d3d11_handle_t *hd3d, bool leg const char *psz_move_planes[2] = {DEFAULT_NOOP, DEFAULT_NOOP}; char *psz_range = NULL; + if (d3dsampState) + { + D3D11_SAMPLER_DESC sampDesc; + memset(&sampDesc, 0, sizeof(sampDesc)); + sampDesc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; + sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; + sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; + sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; + sampDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; + sampDesc.MinLOD = 0; + sampDesc.MaxLOD = D3D11_FLOAT32_MAX; + + HRESULT hr; + hr = ID3D11Device_CreateSamplerState(d3d_dev->d3ddevice, &sampDesc, &d3dsampState[0]); + if (FAILED(hr)) { + msg_Err(o, "Could not Create the D3d11 Sampler State. (hr=0x%lX)", hr); + return hr; + } + + sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; + hr = ID3D11Device_CreateSamplerState(d3d_dev->d3ddevice, &sampDesc, &d3dsampState[1]); + if (FAILED(hr)) { + msg_Err(o, "Could not Create the D3d11 Sampler State. (hr=0x%lX)", hr); + ID3D11SamplerState_Release(d3dsampState[0]); + return hr; + } + } + if ( display->pixelFormat->formatTexture == DXGI_FORMAT_NV12 || display->pixelFormat->formatTexture == DXGI_FORMAT_P010 ) { diff --git a/modules/video_output/win32/d3d11_shaders.h b/modules/video_output/win32/d3d11_shaders.h index 3c0b2ba1f0..1a857dd48d 100644 --- a/modules/video_output/win32/d3d11_shaders.h +++ b/modules/video_output/win32/d3d11_shaders.h @@ -84,9 +84,10 @@ bool IsRGBShader(const d3d_format_t *); HRESULT D3D11_CompilePixelShader(vlc_object_t *, d3d11_handle_t *, bool legacy_shader, d3d11_device_t *, const d3d_format_t *, const display_info_t *, video_transfer_func_t, bool src_full_range, - ID3D11PixelShader *output[D3D11_MAX_SHADER_VIEW]); -#define D3D11_CompilePixelShader(a,b,c,d,e,f,g,h,i) \ - D3D11_CompilePixelShader(VLC_OBJECT(a),b,c,d,e,f,g,h,i) + ID3D11PixelShader *output[D3D11_MAX_SHADER_VIEW], + ID3D11SamplerState *d3dsampState[2]); +#define D3D11_CompilePixelShader(a,b,c,d,e,f,g,h,i,j) \ + D3D11_CompilePixelShader(VLC_OBJECT(a),b,c,d,e,f,g,h,i,j) float GetFormatLuminance(vlc_object_t *, const video_format_t *); #define GetFormatLuminance(a,b) GetFormatLuminance(VLC_OBJECT(a),b) diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c index 20e23d0553..077c62d61a 100644 --- a/modules/video_output/win32/direct3d11.c +++ b/modules/video_output/win32/direct3d11.c @@ -1388,7 +1388,7 @@ static int Direct3D11CreateFormatResources(vout_display_t *vd, const video_forma hr = D3D11_CompilePixelShader(vd, &sys->hd3d, sys->legacy_shader, &sys->d3d_dev, sys->picQuad.formatInfo, &sys->display, fmt->transfer, fmt->b_color_range_full, - sys->picQuad.d3dpixelShader); + sys->picQuad.d3dpixelShader, sys->picQuad.d3dsampState); if (FAILED(hr)) { msg_Err(vd, "Failed to create the pixel shader. (hr=0x%lX)", hr); @@ -1501,7 +1501,7 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd) { hr = D3D11_CompilePixelShader(vd, &sys->hd3d, sys->legacy_shader, &sys->d3d_dev, sys->d3dregion_format, &sys->display, TRANSFER_FUNC_SRGB, true, - sys->pSPUPixelShader); + sys->pSPUPixelShader, NULL); if (FAILED(hr)) { for (size_t i=0; i<D3D11_MAX_SHADER_VIEW; i++) @@ -1561,35 +1561,6 @@ static int Direct3D11CreateGenericResources(vout_display_t *vd) UpdatePicQuadPosition(vd); - D3D11_SAMPLER_DESC sampDesc; - memset(&sampDesc, 0, sizeof(sampDesc)); - sampDesc.Filter = D3D11_FILTER_MIN_MAG_LINEAR_MIP_POINT; - sampDesc.AddressU = D3D11_TEXTURE_ADDRESS_CLAMP; - sampDesc.AddressV = D3D11_TEXTURE_ADDRESS_CLAMP; - sampDesc.AddressW = D3D11_TEXTURE_ADDRESS_CLAMP; - sampDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS; - sampDesc.MinLOD = 0; - sampDesc.MaxLOD = D3D11_FLOAT32_MAX; - - ID3D11SamplerState *d3dsampState[2]; - hr = ID3D11Device_CreateSamplerState(sys->d3d_dev.d3ddevice, &sampDesc, &d3dsampState[0]); - if (FAILED(hr)) { - msg_Err(vd, "Could not Create the D3d11 Sampler State. (hr=0x%lX)", hr); - return VLC_EGENERIC; - } - - sampDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_POINT; - hr = ID3D11Device_CreateSamplerState(sys->d3d_dev.d3ddevice, &sampDesc, &d3dsampState[1]); - if (FAILED(hr)) { - msg_Err(vd, "Could not Create the D3d11 Sampler State. (hr=0x%lX)", hr); - ID3D11SamplerState_Release(d3dsampState[0]); - return VLC_EGENERIC; - } - - ID3D11DeviceContext_PSSetSamplers(sys->d3d_dev.d3dcontext, 0, 2, d3dsampState); - ID3D11SamplerState_Release(d3dsampState[0]); - ID3D11SamplerState_Release(d3dsampState[1]); - msg_Dbg(vd, "Direct3D11 resources created"); return VLC_SUCCESS; } _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
