MAMEWorld >> EmuChat
View all threads Index   Threaded Mode Threaded  

Pages: 1

BAM
MAME Fan
Reged: 01/05/23
Posts: 5
Send PM


MAME HLSL - Windows vs. Linux
#395488 - 01/05/23 11:53 PM Attachment: sf2ce-radial-convergence-0.1.jpg 859 KB (0 downloads)


Hi all,

I recently moved from Windows to Linux. When trying to apply my MAME HLSL config on the Linux version, I am getting very different results.

Some of the shader parameters "Slider Controls" appear to have different value scales and ranges than in Windows.

For example, any of the "radial_convergence" values have a greatly amplified impact on the video. Modifying even by the smallest 0.1 value increment, which in Windows would be almost visually inperceptable (ie. offset the effect by a single pixel) instead has the following effect in Linux where the impact on the video is massive:

radial_convergence_x incremeneted by + 0.1:




Another video parameter, "Signal Offset" allows setting a negative value in Windows MAME, but on Linux the minimal value is zero and so I cannot apply the required negative value that I use in the config to attain the desired HLSL effect.

I guess there is probably some way to modify the math/values in the shader files or something but I didnt know where to start and wondering if anyone else has experiencing this issue?

I have tweaked my HLSL settings for years and have it perfected to my preferences and really eager to replicate it on Linux so if anyone had any suggestions I would greatly apprecaite it.

Out of interest, my final base (Windows) HLSL parameters are as follows and many thanks must go to the folks over at this mammoth forum post as I used a lot of the tweaks there as my starting point:

https://shmups.system11.org/viewtopic.php?f=6&t=45026&start=150

#
# DIRECT3D POST-PROCESSING OPTIONS
#
hlslpath hlsl
hlsl_enable 1
hlsl_oversampling 0
hlsl_write
hlsl_snap_width 2048
hlsl_snap_height 1536
shadow_mask_tile_mode 0
shadow_mask_alpha 0.30
shadow_mask_texture slot-mask.png
shadow_mask_x_count 16
shadow_mask_y_count 24
shadow_mask_usize 1
shadow_mask_vsize 1
shadow_mask_uoffset 0.0
shadow_mask_voffset 0.0
distortion 0.1
cubic_distortion 0.0
distort_corner 0.0
round_corner 0.05
smooth_border 0.04
reflection 0.2
vignetting 0.1
scanline_alpha 0.5
scanline_size 1.0
scanline_height 1.0
scanline_variation 1.0
scanline_bright_scale 1.0
scanline_bright_offset 1.0
scanline_jitter 0.05
hum_bar_alpha 0.0
defocus 0.0,0.0
converge_x 0.0,0.0,0.0
converge_y 0.0,0.0,0.0
radial_converge_x 2.0,-1.0,0.0
radial_converge_y 2.0,0.0,1.0
red_ratio 1.0,0.0,0.0
grn_ratio 0.0,1.0,0.0
blu_ratio 0.0,0.0,1.0
saturation 1.0
offset -0.34,-0.34,-0.34
scanline_bright_scale 1.34,1.34,1.34
power 0.9,0.8,0.65
floor 0.0,0.0,0.0
phosphor_life 0.0,0.0,0.0
chroma_mode 3
chroma_conversion_gain 0.299,0.587,0.114
chroma_a 0.64,0.33
chroma_b 0.30,0.60
chroma_c 0.15,0.06
chroma_y_gain 0.2126,0.7152,0.0722


Many thanks for reading and thanks in advance.

BAM

[ATTACHED IMAGE - CLICK FOR FULL SIZE]

Attachment

Edited by BAM (01/05/23 11:57 PM)



MooglyGuy
Renegade MAME Dev
Reged: 09/01/05
Posts: 2265
Send PM


Re: MAME HLSL - Windows vs. Linux new [Re: BAM]
#395489 - 01/06/23 08:13 AM


> Hi all,
>
> I recently moved from Windows to Linux. When trying to apply my MAME HLSL config on
> the Linux version, I am getting very different results.
>
> Some of the shader parameters "Slider Controls" appear to have different value scales
> and ranges than in Windows.
>
> For example, any of the "radial_convergence" values have a greatly amplified impact
> on the video. Modifying even by the smallest 0.1 value increment, which in Windows
> would be almost visually inperceptable (ie. offset the effect by a single pixel)
> instead has the following effect in Linux where the impact on the video is massive:
>
> radial_convergence_x incremeneted by + 0.1:
>
>
> Another video parameter, "Signal Offset" allows setting a negative value in Windows
> MAME, but on Linux the minimal value is zero and so I cannot apply the required
> negative value that I use in the config to attain the desired HLSL effect.
>
> I guess there is probably some way to modify the math/values in the shader files or
> something but I didnt know where to start and wondering if anyone else has
> experiencing this issue?
>
> I have tweaked my HLSL settings for years and have it perfected to my preferences and
> really eager to replicate it on Linux so if anyone had any suggestions I would
> greatly apprecaite it.
>
> Out of interest, my final base (Windows) HLSL parameters are as follows and many
> thanks must go to the folks over at this mammoth forum post as I used a lot of the
> tweaks there as my starting point:
>
> https://shmups.system11.org/viewtopic.php?f=6&t=45026&start=150
>
> #
> # DIRECT3D POST-PROCESSING OPTIONS
> #
> hlslpath hlsl
> hlsl_enable 1
> hlsl_oversampling 0
> hlsl_write
> hlsl_snap_width 2048
> hlsl_snap_height 1536
> shadow_mask_tile_mode 0
> shadow_mask_alpha 0.30
> shadow_mask_texture slot-mask.png
> shadow_mask_x_count 16
> shadow_mask_y_count 24
> shadow_mask_usize 1
> shadow_mask_vsize 1
> shadow_mask_uoffset 0.0
> shadow_mask_voffset 0.0
> distortion 0.1
> cubic_distortion 0.0
> distort_corner 0.0
> round_corner 0.05
> smooth_border 0.04
> reflection 0.2
> vignetting 0.1
> scanline_alpha 0.5
> scanline_size 1.0
> scanline_height 1.0
> scanline_variation 1.0
> scanline_bright_scale 1.0
> scanline_bright_offset 1.0
> scanline_jitter 0.05
> hum_bar_alpha 0.0
> defocus 0.0,0.0
> converge_x 0.0,0.0,0.0
> converge_y 0.0,0.0,0.0
> radial_converge_x 2.0,-1.0,0.0
> radial_converge_y 2.0,0.0,1.0
> red_ratio 1.0,0.0,0.0
> grn_ratio 0.0,1.0,0.0
> blu_ratio 0.0,0.0,1.0
> saturation 1.0
> offset -0.34,-0.34,-0.34
> scanline_bright_scale 1.34,1.34,1.34
> power 0.9,0.8,0.65
> floor 0.0,0.0,0.0
> phosphor_life 0.0,0.0,0.0
> chroma_mode 3
> chroma_conversion_gain 0.299,0.587,0.114
> chroma_a 0.64,0.33
> chroma_b 0.30,0.60
> chroma_c 0.15,0.06
> chroma_y_gain 0.2126,0.7152,0.0722
>
>
> Many thanks for reading and thanks in advance.
>
> BAM

Edit the default slider values in hlsl.json directly



BAM
MAME Fan
Reged: 01/05/23
Posts: 5
Send PM


Re: MAME HLSL - Windows vs. Linux new [Re: MooglyGuy]
#395490 - 01/06/23 03:18 PM


Hi,

I found the hlsl.json file in /bgfx/chains, going to have a play now - thanks very much for pointing me in the right direction

BAM



MooglyGuy
Renegade MAME Dev
Reged: 09/01/05
Posts: 2265
Send PM


Re: MAME HLSL - Windows vs. Linux new [Re: BAM]
#395491 - 01/06/23 06:44 PM


> Hi,
>
> I found the hlsl.json file in /bgfx/chains, going to have a play now - thanks very
> much for pointing me in the right direction

No worries! Directly editing the default values should be relatively straightforward, I think hlsl.json was one of the shader chains where I embedded documentation on the overall file format in it.

Eventually it should be easier to adjust than that, but saving slider settings for things provided by the OS layer (like shader-related rendering) is currently a bit difficult. I believe there's an item on someone's backlog to look into making that happen, but I have no idea how long it'll take to get to.



BAM
MAME Fan
Reged: 01/05/23
Posts: 5
Send PM


Re: MAME HLSL - Windows vs. Linux new [Re: MooglyGuy]
#395492 - 01/07/23 02:24 AM Attachment: Linux-HLSL.jpg 1261 KB (0 downloads)


I made some changes to the default hlsl.json values successfully.

I had to modify the radial_converge values from 2 to 4 decimal places to get the equivalent level of granularity as the Windows default scale and was able to get it set up exactly how I remember it on Windows

Thank you so much once again for the guidance!

Adding a before-and-after screenshot and will upload the tweaked hlsl.conf in a bit if anyone else finds it useful.

Many thanks,
BAM

[ATTACHED IMAGE - CLICK FOR FULL SIZE]

Attachment



BAM
MAME Fan
Reged: 01/05/23
Posts: 5
Send PM


Re: MAME HLSL - Windows vs. Linux new [Re: BAM]
#395493 - 01/07/23 02:51 AM Attachment: hlsl.json.ini 35 KB (2 downloads)


Attaching the modified hlsl.json file to this post.

One other question if i may...

I noticed that some of the other .ini files I have for other games, as well as source drivers (ini/source folder) which has some hlsl config parameters in them, do not get applied on my Linux MAME. I know my .ini paths are correct as I placed a general mame config parameter into one of these game .ini files and it applied the change (I tested by setting a custom pause_brightness value).

So, it seems that MAME is reading the .ini, applying the general mame config parameters, but ignoring the HLSL ones. Is there some other config that needs to be changed to get mame to read & apply the hlsl parameters from .ini files so that these take precendece over the defaults in the hlsl.json file?

Please forgive me if I have overlooked anything from the comments in the hlsl.json file. I did find a section relating to "input" that almost seems like what I need to use, but it referred to something explicitly about the artwork folder and reading in an image file:


Quote:


// option (optional): The name of any MAME option, which will have its value fetched and used as the name of a PNG to load from the artwork directory.
// value: Any valid MAME INI option name.




I have some custom hlsl settings for vertical games that I place in the vertical.ini for example and quite a lot of custom tweaks for specific games and drivers so if the json file can be modified in any way to read in the values from .ini files I am more than happy to go the legwork if I can figure out what it is I need to do

Cheers!
BAM



MooglyGuy
Renegade MAME Dev
Reged: 09/01/05
Posts: 2265
Send PM


Re: MAME HLSL - Windows vs. Linux new [Re: BAM]
#395494 - 01/07/23 04:40 AM


> So, it seems that MAME is reading the .ini, applying the general mame config
> parameters, but ignoring the HLSL ones.
>
> Please forgive me if I have overlooked anything from the comments in the hlsl.json
> file.

Not entirely, but there's this comment block in mame.ini, above the HLSL settings:


Code:


#
# DIRECT3D POST-PROCESSING OPTIONS
#



Direct3D isn't an API (Application Programming Interface) that's available on Linux.

What's being missed is the context in which the term "HLSL" is used.

HLSL stands for "High Level Shader Language", and is a method for authoring shaders specifically used by Microsoft's DirectX API. When I initially added shader post-processing to MAME back in 2011, DirectX was the rendering API with which I was the most familiar, so that was what I went with. It was one single chain of effects, with no real ability to swap it out for other post-processing effects that various other emulators use.

About 5-6 years later, I had heard about a cross-platform rendering library called BGFX, which provides a common interface for talking to the wide variety of graphics APIs that exist nowadays: Direct3D 9 through 11 (now 12), OpenGL ES (used on mobile devices like cell phones), GLSL (an OpenGL-specific shader language), Vulkan (a next-generation rendering API developed by the same workgroup that created OpenGL), and Metal (Apple's own rendering API used on macOS and iOS).

So, I went and added a separate renderer module to MAME that talks to BGFX. Moreover, I opted to put the overall setup of the chain of shaders into external data files, so that there would be other options for post-processing as well. For example, you can specify "-bgfx_screen_chains crt-geom-deluxe" for a different CRT-simulation effect. Or you could specify "-bgfx_screen_chains super-eagle" for a particularly bad, but long-lived, smoothing effect.

When I added it, I also ported the same shader code that I used in the initial DirectX/HLSL backend over to BGFX's platform-agnostic shader language (which primarily resembles GLSL). Hence the filename, hlsl.json - it's designed to provide broadly the same visual output as running MAME with "-video d3d -hlsl" on a Windows system.


> I did find a section relating to "input" that almost seems like what I need to
> use, but it referred to something explicitly about the artwork folder and reading in
> an image file:
>
> // option (optional): The name of any MAME option, which will have its value fetched
> and used as the name of a PNG to load from the artwork directory.
> // value: Any valid MAME INI option name.

Yes, it has to do with reading in image files so that various post-processing chains available to BGFX can load externally-supplied images. You can see an example of some of those options in this section of mame.ini:


Code:


#
# BGFX POST-PROCESSING OPTIONS
#
bgfx_path bgfx
bgfx_backend auto
bgfx_debug 0
bgfx_screen_chains default
bgfx_shadow_mask slot-mask.png
bgfx_lut lut-default.png
bgfx_avi_name auto



> I have some custom hlsl settings for vertical games that I place in the vertical.ini
> for example and quite a lot of custom tweaks for specific games and drivers so if the
> json file can be modified in any way to read in the values from .ini files I am more
> than happy to go the legwork if I can figure out what it is I need to do

Since all the JSON files in the bgfx/chains/ directory do is contain the setup for the overall chain, and the unique setup for each effect pass, you can just open it in a text editor then save it as some other name.

The fastest way to do what you want to do, using vertical games as an example:
- Copy (don't rename) hlsl.json into hlsl_vertical.json
- Plug the HLSL settings from your vertical INI file into hlsl_vertical.json, as you did with the settings for horizontal games.
- Take the INI file that you're using for vertical games, and either modify (if it exists) or add (if it doesn't) the following line:

Code:


bgfx_screen_chains hlsl_vertical



The same method should work for any other driver-specific or game-specific INIs you have: dupe the JSON, copy settings in, add or change the line pertaining to "bgfx_screen_chains" in the INI file.

If any of them are multi-screen games, be aware that you can (and should) specify the chain per-screen, delimited by commas. For example, on a game with two monitors, you should specify:

Code:


bgfx_screen_chains hlsl_vertical,hlsl_vertical



This can (and should) be made easier, but the same thing about saving the settings sliders applies here, too: It was easy enough to add settings for HLSL to the INI file, since there was only ever that one effect available on Windows via Direct3D. Each option in the INI file requires several lines of code to be added to MAME itself, but that was simple enough since it was a known, unchanging target. Since you now have free selection of what chain you want to use, per-monitor, via BGFX, it's impossible to hard-code which settings are available in an INI file.

There's also eventually going to be a major re-write of MAME's underlying rendering architecture, since at the moment it's rather bad. So, at the moment I'm in something of a holding pattern when it comes to making any significant changes (beyond bugfixes) to the BGFX-based renderer, as in all likelihood both it and the Direct3D renderer will be going away eventually in favor of something more unified and better.



BAM
MAME Fan
Reged: 01/05/23
Posts: 5
Send PM


Re: MAME HLSL - Windows vs. Linux new [Re: MooglyGuy]
#395496 - 01/07/23 02:56 PM


Hi,

fantastic explanation and thank your for all of your time and effort for providing that!

So the magic is in the bgfx_screen_chains parameter, which will allow me to create my custom hlsl json files for each of my tweaked settings, then I can reference that in each of my custom. inis...

...that is awesome thank you

All the best and Happy New Year

BAM


Pages: 1

MAMEWorld >> EmuChat
View all threads Index   Threaded Mode Threaded  

Extra information Permissions
Moderator:  Robbbert, Tafoid 
0 registered and 199 anonymous users are browsing this forum.
You cannot start new topics
You cannot reply to topics
HTML is enabled
UBBCode is enabled
Thread views: 308