floooh / sokol-tools

Command line tools for use with sokol headers
MIT License
219 stars 54 forks source link

fixed YamlGenerator's flattened uniform block reflection #143

Closed allcreater closed 4 weeks ago

allcreater commented 4 weeks ago

Hi!

I finally got around to updating sokol, everything is great (and a huge thank you and the community for these amazing improvements!!), but unfortunately I found a small problem with sokol-shdc, or more precisely with YamlGenerator.

The thing is that it generates incorrect reflection for the flattened uniform blocks.

For example, consider the original structure:

layout (std140, binding = 3) uniform NodeParamsTransmittance {
    vec4 color;
    vec4 metalness_roughness_normalscale_aostrength;
    vec4 alphacutoff_enableblending_padding2;
    vec4 specularcolor_specularintensity;
    vec4 emissive_ior;
    vec4 attenuationfactor_padding1;
    vec4 thickness_transmission_numbounce_padding1;
    vec4 dispersion_ssr;
} u_node_params;

In GLSL 410 it is transformed into the following form:

uniform vec4 NodeParamsTransmittance[8];

The generator works like this:

              slot: 3
              size: 128
              struct_name: NodeParamsTransmittance
              inst_name: u_node_params
              uniforms:
                -
                  name: color
                  type: vec4
                  array_count: 1
                  offset: 0

Previously it worked like this, and it seems that this behavior (which began to change in fd9a675db) was IMHO more correct:

             slot: 3
              size: 128
              struct_name: NodeParamsTransmittance
              inst_name: u_node_params
              uniforms:
                -
                  name: NodeParamsTransmittance
                  type: FLOAT4
                  array_count: 8
                  offset: 0

I would like to propose to return the original behavior, that is, reflect uniform block as if it consists of a single array field, having the name of the block itself.

If such changes were made intentionally, I suggest expanding the output, leaving all members of the block, and adding a flag that the block is flattened, or something like that :)

floooh commented 4 weeks ago

Yeah pretty sure that's a bug. Let me try to find out why that happened...

floooh commented 4 weeks ago

Yeah it's clearly a bug, sorry about that. For instance in the C generator it looks correct (same as your fix):

https://github.com/floooh/sokol-tools/blob/24089e3ae023f69e52efb167c463573e2b17b2e1/src/shdc/generators/sokolc.cc#L302-L307

floooh commented 4 weeks ago

Merged. Thanks for the fix! I'll add a quick blurb to the changelog and then start a CI pipeline to update the binaries.

floooh commented 4 weeks ago

Ok, binaries will be uptodate when this CI pipeline goes green: https://github.com/floooh/sokol-tools/actions/runs/10374632850