Show HN: Metashade – a Pythonic GPU shading/compute EDSL
Comments
leguminous
ppenenko
Agreed that the ability to just run on the CPU is valuable. Metashade doesn't support that yet and its codegen syntax doesn't look like regular Python code (everything codegen-related is prefixed with `sh.` etc.) but it's certainly possible to write a generator that would just execute the code "in the immediate mode" or generate C/C++ code for the CPU.
Regarding templating functions with functions - in Metashade you can just specialize the generated code however you see fit, with Python as the meta language. E.g. Python's `if` statements can act like `#ifdef`s or `if constexpr`, and you can certainly pass around callables to parameterize behavior.
raytopia
Super interesting project. Been looking into template generation and uber shaders to make coding shaders easier for the game engine Ursina. I'm going to bring this to their attention.
Would it be easy to add another target like glsl?
ppenenko
Thanks!
Multiple targets is definitely the plan, and GLSL is my next priority. Metashade can currently generate HLSL for the DX12 version of https://github.com/ppenenko/glTFSample/tree/metashade_demo, and there's also a Vulkan version of that demo using GLSL. So implementing GLSL generation for that would be a great proof of concept and a test bed: HLSL and GLSL generated from single source and producing identical rendering results.
The diagram on slide 31 of my presentation shows how implementation is currently inherited between the Metashade packages. The future GLSL generators should inherit common functionality from the "rtsl" package, just like the existing HLSL generators. However, I expect heavy refactoring to be necessary because I was initially targeting just one language and so not all code is implemented at the appropriate level.
BTW, here's a poll where you can vote for a target language you'd like to see prioritized: https://github.com/ppenenko/metashade/discussions/17
kookamamie
Wouldn't jinja templates would have sufficed for this? I'm not sure it's a good idea to create a whole new language just for getting templating capabilities to shaders.
ppenenko
No, I don't believe Jinja would suffice. For starters, how would you abstract out the syntax differences between, say, HLSL and WGSL? Jinja's approach seems to be taking the syntax of the target language and embedding templating into it. But with Metashade, we're replacing the different syntaxes of individual target languages with that of Python. Since this approach is largely agnostic of the target language syntax, new targets can be added in the future without rewriting target-independent, polymorphic code implementing rendering or compute techniques.
pixelpoet
Hi Pavlo, nice to see you here and thanks for the presentation at Maxon :)
ppenenko
Cheers Thomas!
2genders28507
[dead]
SEXMCNIGGA28386
[dead]
SEXMCNIGGA47335
[dead]
SEXMCNIGGA3291
[dead]
SEXMCNIGGA19574
[dead]
SEXMCNIGGA43215
[dead]
SEXMCNIGGA20543
[dead]
SEXMCNIGGA28322
[dead]
SEXMCNIGGA6701
[dead]
SEXMCNIGGA26902
[dead]
SEXMCNIGGA28854
[dead]
2genders14637
[dead]
SEXMCNIGGA14392
[dead]
2genders8765
[dead]
SEXMCNIGGA16009
[dead]
SEXMCNIGGA36472
[dead]
2genders22238
[dead]
2genders777
[dead]
2genders26709
[dead]
2genders5056
[dead]
2genders9531
[flagged]
2genders22942
[flagged]
2genders1206
[flagged]
2genders47148
[flagged]
2genders839
[flagged]
sexmc25878
[flagged]
sexmc22797
[flagged]
sexmc22464
[flagged]
sexmc7261
[flagged]
sexmc44307
[flagged]
sexmc31107
[flagged]
indianmilf23186
[flagged]
indianmilf40012
[flagged]
sexmc12681
[flagged]
sexmc34063
[flagged]
indianmilf7474
[flagged]
sexmc33282
[flagged]
sexmc47940
[flagged]
sexmc34509
[flagged]
SEXMCNIGGA36557
[flagged]
2genders32561
[flagged]
2genders47272
[flagged]
2genders38930
[flagged]
2genders23289
[flagged]
2genders25297
[flagged]
2genders45764
[flagged]
2genders3617
[flagged]
sexmc33999
[flagged]
2genders44794
[flagged]
2genders40320
[flagged]
2genders20975
[flagged]
2genders26728
[flagged]
sexmc17979
[flagged]
sexmc114
[flagged]
sexmc17627
[flagged]
2genders2516
[flagged]
2genders23779
[flagged]
2genders12074
[flagged]
SEXMCNIGGA29133
[flagged]
SEXMCNIGGA32816
[flagged]
2genders37574
[flagged]
2genders3648
[flagged]
2genders30187
[flagged]
2genders13469
[flagged]
2genders49246
[flagged]
2genders44424
[flagged]
SEXMCNIGGA5453
[flagged]
2genders28563
[flagged]
2genders14678
[flagged]
2genders31161
[flagged]
SEXMCNIGGA45535
[flagged]
SEXMCNIGGA7323
[flagged]
2genders34771
[flagged]
2genders9639
[flagged]
I was using Taichi recently to prototype some fragment shaders (I just mocked out texelFetch, texture, etc and wrote a for loop over each pixel). I found it convenient to be able to run on the CPU and also not have to deal with any OpenGL or Vulkan setup.
One thing that was frustrating was that I couldn't template a function with another function (as far as I know). That lead to some copied and pasted code when I had multiple implementations that I wanted to compare. Can Metashade do that?