Hacker News new | ask | show | jobs
by Const-me 2957 days ago
> You give it regular C# structures and methods, and it automatically converts them to HLSL, GLSL SPIR-V, and Metal shaders.

Code introspection is one of the huge strengths of .NET ecosystem.

You can even do it multiple levels of abstraction: bytecode (using e.g. Mono.Cecil), with built-in reflection API, with built-in expressions API since .NET 3.5, and apparently this project uses even higher-level approach, Roslyn.

I have never transformed C# code into shaders, when I’m working on something similar I usually prefer traditional GPU languages like HLSL or CUDA, because tooling (e.g. visual studio can debug both).

I transformed expressions into NoSQL database queries, worked well. Here’s the main parts: https://github.com/Const-me/EsentSerialize/blob/master/Core/...

2 comments

You can also roll your own expression language using operator overloading and then plug that into the DLR or HSL, or whatever as needed (I did this in https://archive.codeplex.com/?p=bling). It doesn’t allow for statements, however, which introspection gives you.

It is much harder in the new UWP, however, where dynamic features (reflection, introspection, native JIT via the DLR) are no longer guaranteed to be present.

Don't forget that Linq operates over duck-typed extension methods, so you can also define your own wizardry there.
Extension methods are important to doing an EDSL in C#. Link syntax is mostly a dud, however.
Hopefully the weird special-case LINQ syntax will die out soon. The only time I've found it remotely more helpful than method-chaining is when doing some nasty joins that I probably shouldn't have been doing in the first place.
While it is great feature that I enjoy a lot, it isn't the only eco-system with it. :)