librashader icon indicating copy to clipboard operation
librashader copied to clipboard

Metal Shader Compatibility Report (via ares emulator)

Open jcm93 opened this issue 11 months ago • 13 comments

Native Metal support was recently added to ares to complement its librashader support. I've started to do some testing with a bunch of shaders and wanted to start reporting preliminary findings from the .slangp shader library it bundles.

Overall impressions are great. Most things seem to be working correctly and performing well.

I don't have a reference for how these shaders behave on other platforms, so I can mostly only point out things that seem 'obviously broken,' or else obvious things like compiler failures.

With that said, here's a preliminary list so far. I expect to eventually test everything, this is just from my first round of tests, to start getting stuff out there.

Loads fine, blank output

crt/crt-geom-deluxe.slangp crt/crt-slangtest-cubic.slangp crt/crt-slangtest-lanczos.slangp

Filter chain creation failure

crt/crt-guest-advanced-ntsc.slangp ~~vhs/mudlord-pal-vhs.slangp~~ known broken shader test/feedback-noncausal.slangp ~~sharpen/Anime4k.slangp~~ known broken shader vhs/VHSPro.slangp

Other

vhs/vhs_and_crt_godot.slangp - Loads, renders, but pegs GPU to 100% even at low resolutions. Could just be a shader issue. presets/crt-royale-smooth.slangp - blurring issue, see downthread bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp - same blurring issue

~~reshade/gba.slangp - Fails to create preset~~ shader issue ~~reshade/nds.slangp - Fails to create preset~~ shader issue

Other notes so far are that "megabezel" shader performance across the board is somewhat poor at ~4K resolutions when its reflections are enabled. This may simply be a shader issue but I figured worth including.

For testing, the ares' recent CI builds all include the Metal backend. I can provide more information or Metal GPU captures as well if needed for anything, if that is helpful.

jcm93 avatar Apr 03 '24 06:04 jcm93

Filter chain failure is odd, I wonder if it might be something in SPIRV-Cross.. Will take a look this or next week.

chyyran avatar Apr 06 '24 14:04 chyyran

Metal GPU captures would be massively helpful here, as well as LLVM logs from the compiler if you’re able to get them.

chyyran avatar Apr 06 '24 14:04 chyyran

Metal GPU captures would be massively helpful here, as well as LLVM logs from the compiler if you’re able to get them.

Sure, I'll get captures from the ones that appear to be rendering nothing; can you provide any guidance on the latter point? Is there a way to get the compiler output to appear in stdout for example? Would compiling librashader in debug mode do the job? I notice that I already get compilation warnings from the shaders by default.

jcm93 avatar Apr 06 '24 19:04 jcm93

It should show up in debug logs in Xcode when first loading the shader. It’s not a librashader thing but a Metal -> MetalIR thing

chyyran avatar Apr 06 '24 19:04 chyyran

Hmm, I don't get any output I can see from filter chain creation, even with Xcode Metal API and Shader validation enabled. I tried in the objctest code as well; selecting crt-guest-advanced-ntsc just ends up with a nil _filterChain. I see a couple compilation warnings, but compilation succeeds.

jcm93 avatar Apr 06 '24 20:04 jcm93

Thats fine, I’ll investigate crt-guest-advanced-ntsc on my end.

chyyran avatar Apr 06 '24 21:04 chyyran

Here are the GPU captures. They should be labeled appropriately. Let me know if you have any issues opening or getting relevant data from them!

https://drive.google.com/file/d/11bNWB78_drEg1IW3t4ZcViupYgg8qQkd/view?usp=sharing

For the vhs shader capture, it seemed to peg my GPU above a certain resolution, so I notched it just above that and took a capture. Again, that one could just be a shader issue, but I figured it was worth including. I also included a megabezel capture; it seems to be doing some very weird stuff indeed (~~frame times there were exceedingly high every few frames, though not every frame, so~~ looking at this more closely, I think it's just dropping frames; regardless, I included three frames in that capture); I couldn't exactly tell what was going on.

jcm93 avatar Apr 06 '24 22:04 jcm93

mudlord-pal is a known broken shader: https://github.com/SnowflakePowered/librashader/actions/runs/8577373017/job/23509866495#step:4:376

seems like crt-guest-advanced has been failing, will need to double check but it smells like a shader issue.

chyyran avatar Apr 10 '24 02:04 chyyran

Anime4k is also a known broken shader

chyyran avatar Apr 10 '24 02:04 chyyran

scratch that, seems to be the result of a driver issue

jcm93 avatar Apr 12 '24 04:04 jcm93

Testing some things in ares and noticed another librashader issue with certain 'smoothing' shaders such as presets/crt-royale-smooth.slangp or bezel/Mega_Bezel/Presets/MBZ__0__SMOOTH-ADV.slangp.

Left librashader, right RetroArch: Screenshot 2024-05-31 at 3 52 58 PMScreenshot 2024-05-31 at 3 53 37 PM

Screenshots are of the megabezel shader; here is a gputrace from the crt-royale-smooth shader which exhibits similar behavior.

https://drive.google.com/file/d/1NBePGt62XmFZ_mthqlR8YTj8EC7EFVdG/view?usp=share_link

jcm93 avatar May 31 '24 21:05 jcm93

I think the smoothing behaviour probably has to do with how mipmaps are handled. I won't have a shot at debugging this until a few weeks from now, sorry for the extended wait.

chyyran avatar Aug 02 '24 03:08 chyyran

No worries! Nothing critical. I haven't finished testing either and it's possible there are upstream updates to some of the ones in this thread, I'll just keep adding reports and keeping the OP updated when time allows for me as well.

jcm93 avatar Aug 02 '24 04:08 jcm93

1957f576ca0d7087131da274ebde26aca37fea40 could possibly fix crt-geom-deluxe in librashader 0.3.3.

chyyran avatar Aug 24 '24 20:08 chyyran

Seems like test/history.slangp is horribly broken for some reason.

chyyran avatar Sep 08 '24 01:09 chyyran

22b2118e97e1bfccb072072b5e5faebc9179de90 + e24beede0b7de69f0315f5da873f72d3355f80eb definitively fix crt-geom-deluxe

cebc7a939ad11dc31f45b8d4cf086501573949ef fixes history

chyyran avatar Sep 13 '24 05:09 chyyran

  • crt-guest-advanced-ntsc seems like a broken shader preset:
ShaderReflectError(FragmentSemanticError(UnknownSemantics("PrePass0")))
  • feedback-noncausal is a test shader that is intended to be broken.

  • VHSPro is interesting..

    called `Result::unwrap()` on an `Err` value: MetalError(NSError { domain: "MTLLibraryErrorDomain", code: 3, user_info: {"NSLocalizedDescription": <__NSCFString: 0x1510fe800>} })
    

chyyran avatar Sep 13 '24 05:09 chyyran

VHSPro compiler error

program_source:171:22: error: call to 'fmod' is ambiguous
    return fract(sin(fmod(param, param_1)) * 43758.546875);
                     ^~~~
/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.196/include/metal/metal_math:4661:18: note: candidate function
METAL_FUNC float fmod(float x, float y)
                 ^
program_source:153:7: note: candidate function
float fmod(thread const float& a, thread const float& b)
      ^
program_source:192:30: error: call to 'fmod' is ambiguous
    float c = n * smoothstep(fmod(param_2, param_3), 0.0, 0.949999988079071044921875);
                             ^~~~
/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.196/include/metal/metal_math:4661:18: note: candidate function
METAL_FUNC float fmod(float x, float y)
                 ^
program_source:153:7: note: candidate function
float fmod(thread const float& a, thread const float& b)
      ^
program_source:206:10: warning: unused variable 'VHS_Bleed' [-Wunused-variable]
    bool VHS_Bleed = global.VHS_Bleed_toggle != 0.0;
         ^
program_source:207:9: warning: unused variable 'VHS_BleedMode' [-Wunused-variable]
    int VHS_BleedMode = int(global.VHS_BleedMode_select);
        ^
program_source:208:10: warning: unused variable 'VHS_FishEye' [-Wunused-variable]
    bool VHS_FishEye = global.VHS_FishEye_toggle != 0.0;
         ^
program_source:209:10: warning: unused variable 'VHS_FishEye_Hyperspace' [-Wunused-variable]
    bool VHS_FishEye_Hyperspace = global.VHS_FishEye_Hyperspace_toggle != 0.0;
         ^
program_source:210:10: warning: unused variable 'VHS_Vignette' [-Wunused-variable]
    bool VHS_Vignette = global.VHS_Vignette_toggle != 0.0;
         ^
program_source:213:10: warning: unused variable 'VHS_YIQNoise' [-Wunused-variable]
    bool VHS_YIQNoise = global.VHS_YIQNoise_toggle != 0.0;
         ^
program_source:214:9: warning: unused variable 'signalNoiseType' [-Wunused-variable]
    int signalNoiseType = int(global.signalNoiseType_select);
        ^
program_source:217:10: warning: unused variable 'VHS_ScanLines' [-Wunused-variable]
    bool VHS_ScanLines = global.VHS_ScanLines_toggle != 0.0;
         ^
program_source:218:10: warning: unused variable 'VHS_LinesFloat' [-Wunused-variable]
    bool VHS_LinesFloat = global.VHS_LinesFloat_toggle != 0.0;
         ^
program_source:219:10: warning: unused variable 'VHS_Stretch' [-Wunused-variable]
    bool VHS_Stretch = global.VHS_Stretch_toggle != 0.0;
         ^
program_source:220:10: warning: unused variable 'VHS_Jitter_H' [-Wunused-variable]
    bool VHS_Jitter_H = global.VHS_Jitter_H_toggle != 0.0;
         ^
program_source:221:10: warning: unused variable 'VHS_Jitter_V' [-Wunused-variable]
    bool VHS_Jitter_V = global.VHSJitter_V_toggle != 0.0;
         ^
program_source:222:10: warning: unused variable 'VHS_Twitch_H' [-Wunused-variable]
    bool VHS_Twitch_H = global.VHS_Twitch_H_toggle != 0.0;
         ^
program_source:223:10: warning: unused variable 'VHS_Twitch_V' [-Wunused-variable]
    bool VHS_Twitch_V = global.VHS_Twitch_V_toggle != 0.0;
         ^
program_source:224:10: warning: unused variable 'VHS_SignalTweak' [-Wunused-variable]
    bool VHS_SignalTweak = global.VHS_SignalTweak_toggle != 0.0;
         ^
program_source:225:10: warning: unused variable 'VHS_Feedback' [-Wunused-variable]
    bool VHS_Feedback = global.VHS_Feedback_toggle != 0.0;
         ^
program_source:226:12: warning: unused variable 'feedbackColor' [-Wunused-variable]
    float3 feedbackColor = float3(global.feedbackColor_R, global.feedbackColor_G, global.feedbackColor_B);
           ^
program_source:227:10: warning: unused variable 'feedbackDebug' [-Wunused-variable]
    bool feedbackDebug = global.feedbackDebug_toggle != 0.0;
         ^

program_source:123:12: error: call to 'fmod' is ambiguous
    uv.y = fmod(param_4, param_5);
           ^~~~
/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.196/include/metal/metal_math:4661:18: note: candidate function
METAL_FUNC float fmod(float x, float y)
                 ^
program_source:99:7: note: candidate function
float fmod(thread const float& a, thread const float& b)
      ^
program_source:138:150: error: call to 'fmod' is ambiguous
    uv.x += ((((sin((uv.y * 10.0) + t) / 250.0) * onOff(param, param_1, param_2, param_3)) * (1.0 + cos(t * 80.0))) * (1.0 / (1.0 + ((20.0 * (uv.y - fmod(param_4, param_5))) * (uv.y - fmod(param_6, param_7))))));
                                                                                                                                                     ^~~~
/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.196/include/metal/metal_math:4661:18: note: candidate function
METAL_FUNC float fmod(float x, float y)
                 ^
program_source:99:7: note: candidate function
float fmod(thread const float& a, thread const float& b)
      ^
program_source:138:185: error: call to 'fmod' is ambiguous
    uv.x += ((((sin((uv.y * 10.0) + t) / 250.0) * onOff(param, param_1, param_2, param_3)) * (1.0 + cos(t * 80.0))) * (1.0 / (1.0 + ((20.0 * (uv.y - fmod(param_4, param_5))) * (uv.y - fmod(param_6, param_7))))));
                                                                                                                                                                                        ^~~~
/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.196/include/metal/metal_math:4661:18: note: candidate function
METAL_FUNC float fmod(float x, float y)
                 ^
program_source:99:7: note: candidate function
float fmod(thread const float& a, thread const float& b)
      ^
program_source:155:21: error: call to 'fmod' is ambiguous
    float t2 = tt - fmod(param, param_1);
                    ^~~~
/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.196/include/metal/metal_math:4661:18: note: candidate function
METAL_FUNC float fmod(float x, float y)
                 ^
program_source:99:7: note: candidate function
float fmod(thread const float& a, thread const float& b)
      ^
program_source:170:24: error: call to 'fmod' is ambiguous
    float sh2 = 1.0 - (fmod(param_8, param_9) / w);
                       ^~~~
/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.196/include/metal/metal_math:4661:18: note: candidate function
METAL_FUNC float fmod(float x, float y)
                 ^
program_source:99:7: note: candidate function
float fmod(thread const float& a, thread const float& b)
      ^
program_source:194:22: error: call to 'fmod' is ambiguous
    return fract(sin(fmod(param, param_1)) * 43758.546875);
                     ^~~~
/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.196/include/metal/metal_math:4661:18: note: candidate function
METAL_FUNC float fmod(float x, float y)
                 ^
program_source:99:7: note: candidate function
float fmod(thread const float& a, thread const float& b)
      ^
program_source:365:13: error: call to 'fmod' is ambiguous
        if (fmod(param_24, param_25) < 1.0)
            ^~~~
/System/Library/PrivateFrameworks/GPUCompiler.framework/Versions/32023/Libraries/lib/clang/32023.196/include/metal/metal_math:4661:18: note: candidate function
METAL_FUNC float fmod(float x, float y)
                 ^
program_source:99:7: note: candidate function
float fmod(thread const float& a, thread const float& b)
      ^
program_source:489:19: warning: unused variable 'tnl_1' [-Wunused-variable]
            float tnl_1 = tape.sample(tapeSmplr, pn).y;
                  ^

chyyran avatar Sep 13 '24 05:09 chyyran

#125 should fix crt-guest-advanced-ntsc and crt-slangtest-*

chyyran avatar Sep 16 '24 23:09 chyyran

https://github.com/SnowflakePowered/librashader/pull/127 fixes

  • misc/print-resolution.slangp
  • bfi/120hz-smart-BFI.slangp
  • test/pragma-name.slangp

VHSPro seems to be an issue with the SPIRV-Cross output. I will file a ticket upstream to see if we can get it fixed.

patchy-color is a shader problem upstream, this is the output from D3D11 but I assume there are similar issues with Metal

Shader@0x0000013690D34FD0(211,18-30): error X3507: 'testPattern': Not all control paths return a value

chyyran avatar Sep 17 '24 22:09 chyyran

patchy-color was fixed upstream

chyyran avatar Sep 18 '24 04:09 chyyran

Updated OP; could not find any further filter chain creation failures or obviously incorrect outputs. Testing not totally exhaustive yet but fairly broad. Thanks for all the fixes!

jcm93 avatar Sep 18 '24 18:09 jcm93

https://github.com/KhronosGroup/SPIRV-Cross/pull/2382 this should hopefully fix VHSPro (after bumping spirv-cross-sys)

chyyran avatar Sep 25 '24 06:09 chyyran

spirv-cross-sys was updated and should fix VHSPro. This won't automatically backport to 0.4.x but if librashader-capi is rebuilt it'll pull in the new version of the sys crate.

chyyran avatar Sep 25 '24 23:09 chyyran

Converting this issue to a discussion until there are more concrete examples of shader failures on Metal.

chyyran avatar Oct 06 '24 17:10 chyyran