Aleksoid1978 / VideoRenderer

Внешний видео-рендерер
GNU General Public License v3.0
1.03k stars 115 forks source link

D3d11 subpic #53

Closed tiben20 closed 2 years ago

tiben20 commented 2 years ago

This patch make possible rendering subtitle to d3d11 texture with mpcbe and mpc video renderer. Just have problems with subtitle position when its not a 1 to 1 ratio and a warning from d3d11 about rendertarget. I didn't do much d3d11 rendering i just developped this because i was going to do it with the d3d12 renderer im developing and wanted to see if it was easily doable with d3d11. Can you review it just to see if it was what you were planning to do eventually with d3d11. subtitle d3d11 It works as follow On mpc-be side -added dx11 subpic translating most call from dx9 to dx11 only the dirty rect was not converted i dont know the equivalence -added in the mpcvideorenderer class the create for the dx11 callback -added render11 function which is pretty much the same as the render4, we could probably use RenderEx3 but the add setdevice in ISubRender11Callback as to stay there -The dx11 subpic allocate surface like dx9 -in dx11 Sampler state ,blend state and pixel shader are not set on mpc-be side i didn't want to recreate those on mpc-be side. It only create a vertexbuffer, set the input texture as shaderesource and call draw.

on the videorenderer side -in the NonDelegatingQueryInterface function i added the settings for the subtitles which block the interface query pretty much like d3dfullscreen -During the initswapchain the settings block the creation of the d3d9 device and use the same Shader Resource and d3d11 texture to draw onto. If you switch the config during the playback the configure will call the device to be recreated

The only thing that need to be checked is the blendstate. I dont know why but sometimes the last color float pixel is set to 1 and sometimes not. This result in a black image. This should be easy to fix. The harder thing is to set the correct target on the surface. In d3d9 we create a backbuffer the size of the screen. Which render the position correctly before passing the surface to the renderer. Right now the surface that we render on is the maximum size of what the allocatorpresenter will be set at. So i was thinking about 2 solution, 1 we create the texture with the size d3d9 does way bigger than we need the second would be to create it smaller and we position it during rendering. The second solution is more complex to do since we need to give back to the renderer the position we need the offset to be.

v0lt commented 2 years ago

It is interesting. But for some reason it doesn't work for me.

tiben20 commented 2 years ago

It is interesting. But for some reason it doesn't work for me. Ill post the fix tonight commented a line in the render fonction by accident

tiben20 commented 2 years ago

You can test again. Of course the fact that mpcbe is on svn and the renderer on github make that kind of patch weird to make.

Aleksoid1978 commented 2 years ago

Of course the fact that mpcbe is on svn and the renderer on github make that kind of patch weird to make. https://github.com/Aleksoid1978/MPC-BE

tiben20 commented 2 years ago

Cool anyway its the only patch on the videorenderer that require modification in mpcbe. Ill keep submitting patches. I already have a working d3d12 renderer with hw and sw rendering. Im also working on a threaded rendering system. I love directshow and d3d.

v0lt commented 2 years ago

Can you make simple patch files? It is inconvenient for me to work with commits from another repository.

tiben20 commented 2 years ago

Will do

v0lt commented 2 years ago

I made changes in MPC-BE 1.6.2.7034.

tiben20 commented 2 years ago

Not sure how you want me to post simple patch files but here a patch of the commit you did on mpc-be https://pastebin.com/raw/6ZP1RwEu -cleanup of useless comments i did while testing -use d3d11device instead of d3d11device1 -Fixed the scaling and the position of where the subtitle are rendered

the things left are this message i get when not rendering the render graph or the alpha bitmap D3D11 WARNING: ID3D11DeviceContext::OMSetRenderTargets: Resource being set to OM RenderTarget slot 0 is still bound on input! [ STATE_SETTING WARNING #9: DEVICE_OMSETRENDERTARGETS_HAZARD] D3D11 WARNING: ID3D11DeviceContext::OMSetRenderTargets[AndUnorderedAccessViews]: Forcing PS shader resource slot 0 to NULL. [ STATE_SETTING WARNING #7: DEVICE_PSSETSHADERRESOURCES_HAZARD] and sometimes the pixels are not set correctly for the clear which results in a blacked out image on some frame

Aleksoid1978 commented 2 years ago

About mpc-be: CDX11SubPic::AlphaBlt() is incorrect, totally ignore input pSrc/pDst parameters.

v0lt commented 2 years ago

Feature added. Use the following components: MPC-BE 1.6.2.7047 alpha (git 2022.04.30 - 525a9d432) MPC Video Renderer 0.5.7.1871 (git-2022.04.30-1fb404e) compiled with USE_DX11_SUBPIC set to 1.

tiben20 commented 2 years ago

Thanks for the help to make it work.