Shaders for Vulkan (new .slang shaders)

Since Vulkan is now enabled in Windows nightly builds and therefore is accessible to a wider audience, I figured I should share this information Twinaphex told me in IRC on the forums.

Shaders written for RetroArch’s non-Vulkan rendering drivers, such as Cg and GLSL shaders, do not work with RetroArch’s Vulkan driver. There is a draft of RetroArch’s new shader specification written up by Themaister (original SSNES/RetroArch dev, and also the main RetroArch Vulkan driver dev) here:

There is a number of example shaders written by Themaister already in the same repository, here:

Just like “.cg”/".glsl" and “.cgp”/".glslp", “.slang” files are individual shader passes and “.slangp” files are shader presets which can be loaded to add and configure any number of passes. These files are currently usable in RetroArch with Vulkan.

I hope this helps people who want to play with Vulkan! :slight_smile:

1 Like

I’m hoping most of the cg shaders from common-shaders can be converted to slang, since I’d like to switch to Vulkan eventually.

It shouldn’t be too bad for most things. I’m waiting to get started on it until I actually have a GPU/driver that supports it, though.

Thankfully, I see that it supports #include, which standard GLSL doesn’t. This makes it actually realistic to port crt-royale, which would have been basically impossible otherwise.

Does anyone know the status of mesa’s ivy bridge vulkan support?

Me too. I’ve already asked Themaister if he could port his crtglow_gauss_ntsc_3phase.cgp shader preset to slang and he said “should be doable”. He also mentioned that it “should be faster in vulkan, no need to have RGBA32F, can use R16F, 1/8 the bandwidth hit”. Very cool!

Does this article help? https://www.phoronix.com/scan.php?page=news_item&px=Intel-Mesa-Vulkan-Published

First off, I wanted to thank the good developers of Libretro for their tireless work in improving the emulator, even with a deficit of developers! It’s revolutionized my retro gaming setup, including streaming, and is an experience I would have killed for about ten years earlier. Just figured I should express that!

I also wanted to give a positive report on Vulkan for once - RetroArch’s Vulkan driver seems to be working for me on Windows 10, using an R9 285 and the video driver version 16.7.2. I’m not entirely sure how it’s working now when it wasn’t before, but maybe there was a fix I missed in git or AMD fixed things on their end.

The only real issue for me now is shaders. The sample shaders in Git are adequate, but not amazing. There’s still so much shader development going on in Cg that it’s kind of a big barrier to entry for Vulkan, in terms of unofficial shaders in the forums. Will there be any attempt to adapt the Cg shaders to the Vulkan driver’s shader format? Or GLSL - I’m not a programmer, but I looked at the spec and it seems GLSL of some variety is still the language being used, and even if the autoconverted GLSL shaders are a mess, at least some of them do work in my experience.

(It’d also be great if work on Vulkan shaders could feed back into GLSL - poor GLSL shaders are a major issue on my Android devices.)

Obviously, this will take some time, and I’m willing to be patient with the new features. I just want to know what the devs might be doing currently to address the implementation gap.

Yep, r5 and I are working on converting them, but it’s slow-going because the spec isn’t complete yet (LUTs, access to arbitrary previous passes and parameters aren’t supported yet, and I think the frame counter is bugged). You can keep up with our progress and try them out at:

They are indeed basically GLSL, and will be auto-convertible to lower GLSL specs for use on mobile (that’s not implemented yet but it’s planned).

We’ll eventually move that repo over to the libretro organization and I assume they’ll be included in the online updater, but we wanted to get more converted before doing so.

Working crt-geom for vulkan, nice! :slight_smile:

[QUOTE=hunterk;40699] Does anyone know the status of mesa’s ivy bridge vulkan support?[/QUOTE]

On Ivy Bridge I don’t know, but on both Sandy Bridge and Skylake Retroarch on Vulkan works OK. I haven’t bothered to get the new N64 stuff working yet and I’ll probably wait until the mesa changes are in mainline.

:open_mouth: are you sure? Sandy Bridge as in HD3000?

My bad. I mean Haswell. Intel Core i7-4500U with HD4400 graphics. http://www.notebookcheck.net/Intel-Core-i7-4500U-Notebook-Processor.93562.0.html

P

crt-geom has the infamous black dot in the middle of the screen back!

(old cg issue here, but that’s not the same)

Alright, try it now. I just applied the FIX around that line.

Thanks that fixed it! :slight_smile:

Btw the curvature toggle with 1.0 doesn’t work as there is

#ifdef CURVATURE

instead of

if (CURVATURE > 0.5)

in the cg code.

Yeah, that’s just vestigial at the moment, waiting for parameters to come back. Good catch, though, and keep your eyes peeled for anything like that you come across.

Waiting on the 5xBR HLSL shader to hopefully get ported to slang for Vulkan (please),specifically on Shield TV,as xbr is the biggest one for HD smoothness and sharpness,though I wish 6xBR would get created like GLideN64 has with 6xBRz as it exactly hits just above 1080P resolution for that perfect quality,also,RA would require 6x scale to be added for the full effect.

Thankfully, the Vulkan API and the slang shaders work fine for me on my Radeon R9 290, which is GCN 1.1. crt-cubic seems to look nice when trying out some SNES games on the bsnes core. I just hope that most of the common CG and GLSL shaders will work in Vulkan once they eventually get ported over. But for now I’m still going to use OpenGL and CG shaders, simply because they still work fine for me.

Hello. This is an excelent work about Vulkan support.

By the way, I have this shader named “bsnes-gamma-ramp.cg” created by Themaister:

/* Author: Themaister License: Public domain */

// Shader that replicates gamma-ramp of bSNES/Higan.

void main_vertex ( float4 position : POSITION, out float4 oPosition : POSITION, uniform float4x4 modelViewProj,

float2 tex : TEXCOORD, out float2 oTex : TEXCOORD ) { oPosition = mul(modelViewProj, position); oTex = tex; }

// Tweakables. const float saturation = 1.0; const float gamma = 1.5; const float luminance = 1.0;

float3 grayscale(float3 col) { // Non-conventional way to do grayscale, // but bSNES uses this as grayscale value. return float3(dot(col, float3(0.3333))); }

float4 main_fragment(float2 tex : TEXCOORD, uniform sampler2D s0 : TEXUNIT0) : COLOR { float3 res = tex2D(s0, tex).xyz; res = lerp(grayscale(res), res, saturation); // Apply saturation res = pow(res, float3(gamma)); // Apply gamma return float4(saturate(res * luminance), 1.0); }

Someone know how convert this into .slang shader?

Thank you!!!

That shader is the basis of the image-adjustment shader, which is already in vulkan/slang format.

Dear hunter,

is there any chance to see mudlord’s shaders being converted to slang?

Sure. Which did you have in mind?