shader-slang / slang

Making it easier to work with shaders
MIT License
1.78k stars 159 forks source link

Host code gets not properly excluded when building gpu target #4273

Open fknfilewalker opened 3 weeks ago

fknfilewalker commented 3 weeks ago

I would like to have code for cpu and gpu in one file, but when I use the slang file to generate GPU code slang crashes with an internal error 99999. This is mainly caused by export vars/functions like the following below.

E.g., I use a COM Interface in my code

export __global __extern_cpp IProperties __properties;

Compiling to cpp is fine but when I use the same slang file for glsl even though it is not used by the GPU code slang crashes.

I already tried [require(cpp)] but it seems to have no effect. Is there another way to exclude code for certain targets? There is a way inside a function but what about global vars?

It would be awesome if one could annotate something like the example above with [require(cpp)] and then it would just be ignored if the target is not cpp

Edit: Of course I can resort to defines, but would be nice to have a better solution

swoods-nv commented 2 weeks ago

Moving out to Q3 to keep remaining focus this quarter on bugs vs. enhancements.