-
Hi, I’m trying (perhaps foolishly) to write slang shaders for my C# game running OpenGL. I’m a bit out of my depth here, but scrambling to get up to speed on things. I’m looking for advice on how to set this up with as little pain as possible. I’ve used slangc to generate my glsl files so far, but from what I can see in the docs it’s not recommended because you can’t get reflection info. I don’t really mind specifying registers manually and this worked well for specifying cbuffers and such, but I hit a snag when it came to textures and samplers. Using a Texture2D and SamplerState doesn’t seem to work, it generates invalid glsl code. I’m not sure if this is a bug or if it’s just not supported. The only way I’ve managed to get things to work is via Sampler2D objects, but they do not seem to support specifying registers. I guess I could just create samplers and such and have my code assume they’re listed in a linear order, but I don’t really know how slang assigns the binding indices so it seems safer to get them via reflection. The next problem is I can’t find any readily available C# bindings, so I tried to set up some interop with slang.dll, but I can’t for the life of me figure out how to get the COM interop to work. I’m still working on it, having some marginal success by skipping all of the built-in C# interop features and just working with manual pointers, but it seems like a less than ideal way of doing it. It’s trivial to use the C bindings, but from what I’ve understood they are being deprecated, but there’s talk about generating the C bindings later, so maybe not after all? So in summary my questions are:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 6 replies
-
@Ollhax Thank you for giving slang a try for your use case. Unfortunately, Slang's GLSL backend isn't intended to generate glsl code for OpenGL, instead it emits Vulkan-flavored GLSL which does allow separated texture-samplers. It seems that we will need to get explicit binding to work on Sampler2D objects to get you unblocked, which we should be able to do. There should be existing ways to export COM interfaces to .Net as C# interfaces. I haven't digged into it, but https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms404285(v=vs.100) seems relevant. |
Beta Was this translation helpful? Give feedback.
-
For explicit binding, I quickly gave it a try, and it seems that the following syntax should work for you:
Alternatively, the following syntax also works:
|
Beta Was this translation helpful? Give feedback.
-
I don't think I'll continue working on the C# bindings since I can avoid using reflection, but in case anyone is interested I'll just post my experiment here. I think it'd be better to get normal COM interop to work if someone manages it, but perhaps this route could work out well enough using some code generation.
|
Beta Was this translation helpful? Give feedback.
-
As an update, we now provide a simpler reflection interface via the |
Beta Was this translation helpful? Give feedback.
@Ollhax Thank you for giving slang a try for your use case. Unfortunately, Slang's GLSL backend isn't intended to generate glsl code for OpenGL, instead it emits Vulkan-flavored GLSL which does allow separated texture-samplers.
It seems that we will need to get explicit binding to work on Sampler2D objects to get you unblocked, which we should be able to do.
There should be existing ways to export COM interfaces to .Net as C# interfaces. I haven't digged into it, but https://learn.microsoft.com/en-us/previous-versions/dotnet/netframework-4.0/ms404285(v=vs.100) seems relevant.