veldrid / veldrid-spirv

SPIR-V shader translation for Veldrid, using SPIRV-Cross
MIT License
49 stars 36 forks source link

How to get reflection info? #11

Open Wolfos opened 4 years ago

Wolfos commented 4 years ago

The API's recommended usage (I.E. through ResourceFactory) doesn't output the compilation results needed to get the reflection info. I looked at the code a bit and this doesn't seem easy to implement. Especially given how differently Vulkan compilation is handled.

AntiBlueQuirk commented 3 years ago

Is it possible to create dummy "Spir-V to Spir-V" compiler in the native library that just passes the shader through unmodified? The code in the Spirv-Cross CLI for handling reflection seems to support this.

Something like this in libveldrid-spirv.cpp?

case SPIRV:
{
    auto ret = new CompilerReflection(spirvBytes); // Special reflection compiler.
    return ret;
}

Then you can probably skip over most of the logic in CompileVertexFragment. At the end, you would just leave the CompilationResult DataBuffers empty, then collect the reflection information as normal. On the C# side, collect the reflection info from the compilation result and return the input shaders unmodified.

This would mean that reflection info would be available no matter the target backend, so it could be added to the public API.

(I don't have a dev environment available for this project, so I can't test this, but it seems like it would work.)