Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vf_d3d11vpp: add support for scaling #14698

Merged
merged 2 commits into from
Aug 20, 2024

Conversation

kasper93
Copy link
Contributor

No description provided.

@kasper93
Copy link
Contributor Author

I've refactored options a bit to avoid hardcoded scaling size. @billxc: please take a look if that works for you.

Copy link

github-actions bot commented Aug 19, 2024

Download the artifacts for this pull request:

Windows
macOS

@kasper93 kasper93 force-pushed the vf_d3d11vpp_vsr branch 3 times, most recently from 1f1f4ce to ec73f8e Compare August 19, 2024 16:25
@billxc
Copy link
Contributor

billxc commented Aug 20, 2024

looks good for me, thanks for the work!@kasper93

kasper93 and others added 2 commits August 20, 2024 03:10
Adds `--vf=d3d11vpp=scale` to scale video using d3d11 video processor.

Co-authored-by: xc <[email protected]>
Adds `--vf=d3d11vpp=scaling-mode` to control which extensions should be
enabled.

Fixes: mpv-player#11390
Co-authored-by: xc <[email protected]>
@kasper93 kasper93 merged commit 2848af5 into mpv-player:master Aug 20, 2024
24 checks passed
@kasper93 kasper93 deleted the vf_d3d11vpp_vsr branch August 20, 2024 01:34
@IC0hO
Copy link
Contributor

IC0hO commented Aug 20, 2024

For my 4K screen, when using the super resolution feature, to achieve an output resolution of 4K, the scale value should ideally be set to 2.0 for a 1080p video and 3.0 for a 720p video. Could you add a feature to automatically set the scale values?

@Andarwinux
Copy link
Contributor

Andarwinux commented Aug 20, 2024

For my 4K screen, when using the super resolution feature, to achieve an output resolution of 4K, the scale value should ideally be set to 2.0 for a 1080p video and 3.0 for a 720p video. Could you add a feature to automatically set the scale values?

This can be done with lua script, although it would be nice to have native support.

function autovsr()
    display_width = mp.get_property_native("display-width")
    video_width = mp.get_property_native("width")
    display_height = mp.get_property_native("display-height")
    video_height = mp.get_property_native("height")
    mp.set_property_native("vf","")
    pixfmt = mp.get_property_native("video-params/hw-pixelformat") or mp.get_property_native("video-params/pixelformat")
    if video_width ~= nil and display_width ~= nil then 
        scale = math.max(display_width,display_height) / math.max(video_width,video_height)
        scale = scale - scale % 0.1
        if scale > 1 then
            if pixfmt == "nv12" then
                mp.set_property_native("vf","d3d11vpp:scaling-mode=nvidia:scale="..scale)
            elseif pixfmt == "yuv420p" then
                mp.set_property_native("vf","format=nv12,format=d3d11,d3d11vpp:scaling-mode=nvidia:scale="..scale)
            end
        end
    end
end
mp.observe_property("video-params/pixelformat", "native", autovsr)

Update: Improved the script, now automatically adapts to different hwdec or swdec.

@wadixx
Copy link

wadixx commented Aug 20, 2024

I couldn't make it work. Isn't below commands in mpv.config enough?

vf-add=d3d11vpp
vf=d3d11vpp=scale=1.0
vf=d3d11vpp=scaling-mode=nvidia

@kasper93
Copy link
Contributor Author

I couldn't make it work. Isn't below commands in mpv.config enough?

vf-add=d3d11vpp vf=d3d11vpp=scale=1.0 vf=d3d11vpp=scaling-mode=nvidia

vf=d3d11vpp=scale=2:scaling-mode=nvidia it has to be one filter.

@kasper93
Copy link
Contributor Author

This can be done with lua script, although it would be nice to have native support.

Same as --vf=scale don't use window dimensions. vf is before output, we don't even have window yet. And it it correct way to feedback the required size after the window is created in lua script. Otherwise patches welcome, but I will not hack this around in mpv code.

@hooke007
Copy link
Contributor

I meet with an issue with d3d11vpp filter.
If a cpu filter appended. How should I correctly make it work.

vf-append = d3d11vpp=scale=2.0
vf-append = vflip # How to make it work?

@wadixx
Copy link

wadixx commented Aug 20, 2024

I couldn't make it work. Isn't below commands in mpv.config enough?
vf-add=d3d11vpp vf=d3d11vpp=scale=1.0 vf=d3d11vpp=scaling-mode=nvidia

vf=d3d11vpp=scale=2:scaling-mode=nvidia it has to be one filter.

I added lines below still no luck. Already tried with different resolutions. Mpv registers d3d11vpp as filter but it doesn't trigger super resolution status in Nvidia Control panel. In case of conflict i tried it with fresh install with no other configuration other than below.

vf-add=d3d11vpp
vf=d3d11vpp=scale=2:scaling-mode=nvidia

@kasper93
Copy link
Contributor Author

I meet with an issue with d3d11vpp filter.
If a cpu filter appended. How should I correctly make it work.

vf-append = d3d11vpp=scale=2.0
vf-append = vflip # How to make it work?

Frame download doesn't work currently, because they are not allocated by ffmpeg and we don't have proper context to use for that. Will see what can be done about it.

@CrendKing
Copy link
Contributor

CrendKing commented Aug 21, 2024

When using this, I always get two warning messages

[w][d3d11vpp] No fitting video processor found, picking #0.
[w][autoconvert] Unexpected AVFrame/imgfmt hardware context mismatch.

I could eliminate the first warning by specifying the mode like mode=blend (only mocomp does not work). I guess it doesn't matter as long as I only have one video card?

The second warning seems to come from

mp_warn(log, "Unexpected AVFrame/imgfmt hardware context mismatch.\n");
. Does that mean the frame image becomes software after the filter?

@Johnnycyan
Copy link

I can't for the life of me get this to actually work. I have this in my mpv.conf:

vf-add=d3d11vpp
vf=d3d11vpp=scale=2:scaling-mode=nvidia

Also tried without the first line. I don't get any logging even saying it's trying to enable it. Though it shows that it's set in the info section, it doesn't actually do anything and Nvidia reports it is inactive.

@Andarwinux
Copy link
Contributor

RTX Video Super Resolution will not be active when a game is using NVIDIA Image Scaling (NIS), Dynamic Super Resolution (DSR) or Deep Learning Dynamic Super Resolution (DLDSR)

@Johnnycyan
Copy link

Well none of those are the case for me, and other applications have no issues enabling it

@kasper93
Copy link
Contributor Author

kasper93 commented Aug 24, 2024

vf-add=d3d11vpp

Why?

@Johnnycyan
Copy link

vf-add=d3d11vpp

Why?

Because I saw that elsewhere. But as I said I tried without that line and it still did nothing

@kasper93
Copy link
Contributor Author

Have you read documentation? Do you have hardware decoding enabled?

gpu-api=d3d11
hwdec=d3d11va

@Johnnycyan
Copy link

Have you read documentation? Do you have hardware decoding enabled?

gpu-api=d3d11
hwdec=d3d11va

Ah I was missing hwdec=d3d11va thank you. Another question, does this not support RTX VSR HDR? Or is there something else I'm missing for that? Cause it just does the scaling right now.

@kasper93
Copy link
Contributor Author

does this not support RTX VSR HDR?

No. I don't have hardware to test this, so you have to wait for someone else to implement or at least poc how to configure this.

@Johnnycyan
Copy link

Okay thank you!

@hooke007
Copy link
Contributor

Do you have hardware decoding enabled

Well, I found actually it could work with swdec if the source is yuv420p10.

@Andarwinux
Copy link
Contributor

Just add format=nv12, any pixfmt will work with d3d11vpp

@hooke007
Copy link
Contributor

Just add format=nv12, any pixfmt will work with d3d11vpp

That's not the issue here. I think autoconvert is broken in some place. yuv420p8 should also work without users manual setting.

@kasper93
Copy link
Contributor Author

Frame download doesn't work currently, because they are not allocated by ffmpeg and we don't have proper context to use for that. Will see what can be done about it.

Fixed by #14746

Just add format=nv12, any pixfmt will work with d3d11vpp

That's not the issue here. I think autoconvert is broken in some place. yuv420p8 should also work without users manual setting.

Not really broken, autoconvert will not inject software on cpu format conversion before hwupload. So it currently fails with

hwupload: Unable to find a compatible upload format for yuv420p

and while it could automatically do the conversion, I think it is better to let users explicitly state it, to avoid possibly slow on CPU conversion.

Currently if you want to have this filter work with software input/output you can do

vf-append=format=nv12
vf-append=d3d11vpp=scale=2
vf-append=format=nv12
vf-append=vflip

Well, I found actually it could work with swdec if the source is yuv420p10.

Yes, because there is direct upload format compatibility in this case. Also I need to update this filter to output also rgb10a2 when needed.

@kasper93
Copy link
Contributor Author

That's not the issue here. I think autoconvert is broken in some place. yuv420p8 should also work without users manual setting.

autoconvert is also now fixed in #14746

@Damole-wer
Copy link

Damole-wer commented Oct 12, 2024

Is there a way to disable upscaling part for Nvidia VSR? I'm only interested in artifact reduction, since upscaling is only slightly better than lanczos.
It seems to support this (at least at 1080p), according to this blog post. Works in chrome. I've tried --vf=d3d11vpp:scale=1:scaling-mode=nvidia, but the feature doesn't get enabled and shows "Status: Inactive" in NVCP, checked at 480p, 720p and 1080p.
It works with a scale=1.002, but distorts the image quite a bit and obviously not an ideal way.
Thank you in advance!

kasper93 added a commit to kasper93/mpv that referenced this pull request Oct 12, 2024
Apparently, some processing is still desired by users even at a 1.0
scaling factor.

Fixes: mpv-player#14698 (comment)
@kasper93
Copy link
Contributor Author

@Damole-wer: Try #15071, should help in this case.

kasper93 added a commit to kasper93/mpv that referenced this pull request Feb 9, 2025
Apparently, some processing is still desired by users even at a 1.0
scaling factor.

Fixes: mpv-player#14698 (comment)
kasper93 added a commit to kasper93/mpv that referenced this pull request Feb 20, 2025
Apparently, some processing is still desired by users even at a 1.0
scaling factor.

Fixes: mpv-player#14698 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants