shader-slang / slang

Making it easier to work with shaders
http://shader-slang.com
MIT License
2.16k stars 186 forks source link

Option to generate binding and layout information for slangc #5492

Open tareksander opened 1 day ago

tareksander commented 1 day ago

As far as I understand the documentation, layout and binding information (unless manually specified) is chosen by the language, and the only way know what was chosen is to use the reflection API. With something like a separate json output file that includes the descriptor set and binding for globals and the type layout, slangc could be used standalone for compilation.

csyonghe commented 1 day ago

This is a good suggestion and is what we've been considering to add. Currently there is already the slang-reflection-test code (that is compiled as a library) that does exactly this, and you can change the code slightly to compile that dll as an exe instead. But it would be useful to package them up directly in slangc.

tareksander commented 1 day ago

If no one is working on it I can try implementing it. Shouldn't be that hard with the reflection API already in place.

csyonghe commented 1 day ago

That will be fantastic. We appreciate your contribution! You can get started by taking a look at \tools\slang-reflection-test\slang-reflection-test-main.cpp, which should already have all the logic we want: reads the refection data, and print them out as json string.

tareksander commented 1 day ago

So basically:

Right?

csyonghe commented 1 day ago

Yes, that should be it.

tareksander commented 1 day ago

How can I run the tests to ensure I don't break anything?

csyonghe commented 18 hours ago

You can run slang-test from repository root directory without any parameters:

slang-test

To speed things up you can run tests in parallel with:

slang-test -use-test-server -server-count 12

To run tests with specific name:

slang-test tests/compute/simple.slang

To run test using a specific API:

slang-test -api d3d12
slang-test -api all-wgpu # run tests using all apis but wgpu.
jkwak-work commented 18 hours ago

I like to recommend checking out our contribution guide. https://github.com/shader-slang/slang/blob/master/CONTRIBUTION.md