xBR algorithm tutorial

BTW, I forgot to mention in this thread: the first comercial game using xBR filters was released a couple of months ago and already has passed 5,000 downloads.

Simon The Sorcerer

Credits

It’s a relaunch (20th anniversary edition) made by MojoTouch for Android devices.

Link: https://play.google.com/store/apps/details?id=com.mojotouch.simon

One of the things I’m working is on the algorithm’s corner detection for small details. The problem is more complex than it seems. Not only it must be good for stills as it must keep HUDs and Fonts stable enough in movement to minimize artifacts where they blend with backgrounds. Another challenge is to prevent important pixels (for example, those that represent character eyes) from blending with neighbor pixels.

Here are some screens from the algorithm corner detection as it is now (In these examples I’m using just LV2). Now you can see the number “1” correctly and not smeared.

Original: … xBR 4x (next corner detection):

Got news!

Repo updated with xBR Multilevel4 multipass shader. This shader is LV1 to 4, because it chooses the level that best fit the pattern according to some new rules.

A major bug was found by another user (aliaspider) which was causing some glitches in nvidia cards with multipass shaders. So I just updated some multipass shaders: mdapt-4p, xbr-lv2-multipass and xbr-lv3-multipass.

your multilvl4 shader doesn’t work for me here. tried it with d3d9:

RetroArch: Environ GET_OVERSCAN: 0
RetroArch: Environ SET_PIXEL_FORMAT: XRGB8888.
RetroArch: Set audio input rate to: 31923.97 Hz.
RetroArch: Adjusting aspect ratio to 1.33
RetroArch: Video @ fullscreen
RetroArch: Setting multimedia scheduling for DWM.
RetroArch: [D3D9]: Monitor size: 1680x1050.
RetroArch: [D3D9 Meta-Cg] Found 4 shaders.
RetroArch: [D3D9 Cg]: Created context.
RetroArch: [D3D9 Cg]: Vertex profile: vs_3_0
RetroArch: [D3D9 Cg]: Fragment profile: ps_3_0
RetroArch: [D3D9 Cg]: Compiling shader: E:/shaders/xbr-mlv4-multipass/xbr-mlv4-pass1.cg.
RetroArch [ERROR] :: [D3D9 Cg]: Vertex error:
E:/shaders/xbr-mlv4-multipass/xbr-mlv4-pass1.cg(110) : error C7004: Too many output registers used. When no output has the PSIZE semantic, only 11 output registers are available.

RetroArch [ERROR] :: [D3D9]: Render chain error: (Failed to compile shaders!).
RetroArch [ERROR] :: [D3D9]: Failed to init D3D9 (Failed to init render chain, code: 0x0).
RetroArch [ERROR] :: Cannot open video driver ... Exiting ...
RetroArch [ERROR] :: Fatal error received in: "init_video_input()"

and with ogl:

RetroArch: Environ GET_OVERSCAN: 0
RetroArch: Environ SET_PIXEL_FORMAT: XRGB8888.
RetroArch: Set audio input rate to: 31923.97 Hz.
RetroArch: Adjusting aspect ratio to 1.33
RetroArch: Video @ fullscreen
RetroArch: Setting multimedia scheduling for DWM.
RetroArch: Found GL context: wgl
RetroArch: Detecting screen resolution 1680x1050.
RetroArch: [WGL]: Setting fullscreen to 1680x1050 on device \\.\DISPLAY1.
RetroArch: [WGL]: wglSwapInterval(1)
RetroArch: [GL]: Vendor: ATI Technologies Inc., Renderer: ATI Radeon HD 4800 Series.
RetroArch: [GL]: Version: 3.3.11672 Compatibility Profile Context.
RetroArch: Querying GL extension: ARB_sync => exists
RetroArch: GL: Using resolution 1680x1050
RetroArch: [GL]: Using Cg shader backend.
RetroArch: [Cg]: Vertex profile: arbvp1
RetroArch: [Cg]: Fragment profile: arbfp1
RetroArch: Loading Cg meta-shader: E:/shaders/xbr-mlv4-multipass/xbr-mlv4.cgp
RetroArch: Loading Cg shader: "E:/shaders/xbr-mlv4-multipass/xbr-mlv4-pass1.cg".
RetroArch [ERROR] :: CG error: The compile returned an error.
RetroArch [ERROR] :: Fragment:
E:/shaders/xbr-mlv4-multipass/xbr-mlv4-pass1.cg(153) : error C5041: cannot locate suitable resource to bind parameter "t8"
E:/shaders/xbr-mlv4-multipass/xbr-mlv4-pass1.cg(153) : error C5041: cannot locate suitable resource to bind parameter "t9"

RetroArch [ERROR] :: Failed to load shaders ...
RetroArch: CG: Destroying programs.
RetroArch: CG: Destroying context.
RetroArch [ERROR] :: [GL]: Failed to init shader, falling back to stock.

used the latest 64bit retroarch version on win8. hmm maybe my gpu is just too old. I guess you tested it on your ps3?

your guess was right, the reason why you can’t run the shader is that it requires a more recent GPU, due to the high register requirement of the shader in its current version, as you can see it in the error message. specifically, there are not enough registers available to store t8 and t9 in the vertex shader so that the fragment shader can use them. you only have 11 registers available per shader but xbr wants to use at least two more.

you could however move all the pre-calculations ( t0 to t9 at least ) from the vertex to the fragment shader, that way the compiler will hopefully be able to optimize register usage and run on your GPU.

EDIT : this is a modified version that should work for you: link

thx a lot aliaspider. yeah it’s working now. what’s funny though that with d3d9 I got an distorded picture but it’s fine with ogl. with the xbr-lvl3-multipass shader it’s the other way around. don’t know what’s the reason for that, the log shows nothing wrong.

All fixed on repo. Tks, aliaspider!

It’s not working on my HTPC at all. It’s an AMD A-10 5700 with a Radeon HD7660D with latest 13.9 WHQL driver on Windows 8.1 pro 64bit (and latest RetroArch 64bit Version 20131013. OpenGL looks like Nearest, without filters. Sometimes vertikal lines, which are wrong. D3D9 have a shifted square in the down-left corner.

On my PC with GTX480 it looks fine with OpenGL (after the fix from aliaspider). Same problem with D3D9 like above. btw. lv3 and lv2 also not working on my AMD.

Does it worked before the last two fixes?

Where did you get them? Directly from the repository or along Retroarch installation?

If you’ve got with Retroarch, then you’re using the old versions without the last fixes.

I don’t have the old version anymore and can’t test (because you replaced with the fix). I took it from here: https://github.com/libretro/common-shad … -multipass The lv4 isn’t yet in the RetroArch package. lv3 and lv2 I tested from the RetroArch package (so I guess the old version). So it seems the old and the new versions don’t work with my AMD configuration.

No idea what could be wrong. Are you loading the shaders through the cgc preset?

Try the cg2glsl.py script.

I am loading xbr-mlv4.cgp All I can do is show you some screenshots: http://i.imagebanana.com/img/eovoripu/1.png Should be loaded correctly.

Thats the result in OpenGL: http://i.imagebanana.com/img/ijn6urap/2.png notice the tiny lines and dots in the logo

and DirectX: http://i.imagebanana.com/img/e2tqewyh/3.png

I don’t know what I have to do with cg2glsl.py.

Change that default filter to nearest:

defaul filter --> nearest

And then click “Apply Shader Changes”.

Don’t work. Same result like on the screenshots.

Your only option is to use cg2glsl.py script to convert the shader.

Ask hunterk how to do this.

cg2glsl.py can be annoying to setup in windows if you have never used a python shell before so you can have my already converted shaders to test

https://anonfiles.com/file/adb86144c5954ecb73000ab9f52ac24f

obviously glsl is only compatible with opengl so don’t even try directx. Works fine on linux with open source r600 driver so if they don’t work on windows it could be a driver compiler error. In any case give these a shot and report back. Also try using integer scale as this can sometimes solve annoying lines in opengl.

Thank you for helping me! This looks much better: http://i.imagebanana.com/img/9jsx5ano/4.png

but there are still little lines, also with enabled integer scale (c at Micro or b at Turbo). Without Integer Scale much worse.

In my normal PC I don’t have these lines (with and without integer scale).

need some help. I wanted to combine the xbr multipass shader (mlv4) with my newest mdapt version. it’s again a similar problem we already discussed here, but I don’t know how to solve it. the issue is, that besides the first passes are correctly configured for mdapt, the following xbr passes just ignores them and uses the original raw picture instead, so mdapt has no effect on the final result. it’s just weird, here is the cgp I used:

shaders = 8

shader0 = mdapt-pass1.cg
filter_linear0 = false
scale_type0 = source
scale0 = 1.0

shader1 = mdapt-pass2.cg
filter_linear1 = false
scale_type1 = source
scale1 = 1.0

shader2 = mdapt-pass3.cg
filter_linear2 = false
scale_type2 = source
scale2 = 1.0

shader3 = mdapt-pass4.cg
filter_linear3 = false
scale_type3 = source
scale3 = 1.0

shader4 = xbr-mlv4-pass1.cg
filter_linear4 = false
scale_type4 = source
scale4 = 1.0

shader5 = xbr-mlv4-pass2.cg
filter_linear5 = false
scale_type5 = source
scale5 = 1.0

shader6 = xbr-mlv4-pass3.cg
filter_linear6 = false
scale_type6 = source
scale6 = 2.0

shader7 = xbr-mlv4-pass4.cg
filter_linear7 = false
scale_type7 = source
scale7 = 2.0

Sp00kyFox,

xBR passes 2, 3 and 4 need to access the original texture. As you're passing mdapt before it, the "new" original texture for these xbr passes is now the result of mdapt pass4, which is PASS4 according to the cg shader specs from maister.

So, you have to open xbr passes 2, 3 and 4 and replace all ORIG terms by PASS4 for it to run correctly.

BTW, this won’t be necessary when next RA releases, because maister has implemented the feature of accessing the previous pass output.

that was an easy fix, thx!