KhronosGroup / SPIRV-Tools

Apache License 2.0
1.02k stars 539 forks source link

Request: allow SpirvToolsEliminateDeadInputComponents() to strip non-trailing members from blocks #5631

Open mbechard opened 3 months ago

mbechard commented 3 months ago

Sending the the following fragment shader through SpirvToolsEliminateDeadInputComponents() and SpirvToolsAnalyzeDeadOutputStores() results in t getting eliminated, but not pos. Can't pos also be eliminated? The analyze pass is correctly detecting that only c is being used, and only returning it as part of the livelocs. And then similarly, SpirvToolsEliminateDeadOutputStores() would need to also to remove pos.

Vertex

out Vertex
{
    vec3 pos;
    vec4 c;
    vec2 t;
} oVert;
void main() 
{
    oVert.pos = vec3(0.5);
    oVert.c = vec4(1.0);
    oVert.t = vec2(0.4);
    gl_Position = vec4(0.0);
}

Fragment

in Vertex
{
    vec3 pos;
    vec4 c;
    vec2 t;
} iVert;

out vec4 fragColor;
void main()
{
    vec4 color = vec4(iVert.c);
    fragColor = color;
}

Compiled using 'auto map locations'.

Thanks

greg-lunarg commented 2 months ago

As you are likely aware, moving non-trailing members of input blocks in vertex shaders is impossible and would cause incompatibility at the vertex input interface. Likewise for output blocks in frag shaders and the frag output interface.

Technically we could remove non-trailing members from other shader interfaces but we would have to add logic to remap any OpAccessChain instructions that index into the block because the positions of the remaining members would change. This is very do-able. It would not cause any changes to the larger workflow. It would just be some coding effort.

mbechard commented 2 months ago

Yep, this is what I would expect. I'm only looking for this optimization in shader->shader interfaces, since those resources are quite limited.