KhronosGroup / SPIRV-Cross

SPIRV-Cross is a practical tool and library for performing reflection on SPIR-V and disassembling SPIR-V back to high level languages.
Apache License 2.0
2.07k stars 566 forks source link

[GLSL] `--flatten-ubo` with preserving names #2020

Open vladislavbelov opened 2 years ago

vladislavbelov commented 2 years ago

Hi! Is it possible to flatten UBO with preserving member names? Or it's too complicated to support?

GLSL (source) > SPIRV:

#version 450

layout (location = 0) uniform Constants
{
    vec4 color;
    // ...
};

layout (location = 0) out vec4 outColor;

void main()
{
    outColor = color;
}

SPIRV > GLSL (result):

#version 110

// Instead of uniform vec4 Constants[...];
uniform vec4 color;
// uniform ...

void main()
{
    gl_FragColor = color; // instead of Constants[0];
}
HansKristian-Work commented 2 years ago

In GLSL, the block name is the name you use to link against the outside world, not the member name. You can always use the reflection API to rename things as desired before cross-compiling.

vladislavbelov commented 2 years ago

In GLSL, the block name is the name you use to link against the outside world, not the member name.

It's true only for GL3+. Currently I support ARB (Cg) and GLSL (110) shaders, so my abstract GAPI works with uniform variables not uniform structs/buffers.

You can always use the reflection API to rename things as desired before cross-compiling.

I think it works only for the block name in that case, no?