I’ve just released a small one C++ file tool called spirv-stats. It will take one or more SPIR-V input files, and calculate the composition of the SPIR-V shader modules like so:

It firstly outputs the total number of hits in the SPIR-V shader module(s) - this is the total number of opcodes found within the module(s). Then it outputs the total byte size of the module(s), followed by a sorted breakdown of the module(s), with the most hit opcodes coming first.

I decided to run this across the various folders of SPIR-V that @aras_p is using in his smol-v tool, with the following results.

dota2

OpMemberDecorate dominates the dota2 shaders - nearly 20% of the module is decorating members of structs! Next we have OpLoad at 16% of the hits, but with 13% of the size of the files, followed by OpAccessChain at 10% of the hits and 12% of the size. Most of the shader module(s) are taken up with decorating struct members, and then loading and storing to various variables.

shadertoy

The shadertoy folder is dominated by loads and stores. Then curiously OpLabel - this indicates that there is a heavy amount of branching/looping occurring in the source shaders, as an OpLabel signifies a new basic block has been declared. OpBranch is the sixth most used opcode, which also backs up the view that these shaders make heavy use of branching/looping.

talos

The talos folder is dominated once again by loads and stores. Next is OpCompositeExtract - which is extracting an element from a composite (aggregate, matrix or vector). I’d take a guess that there is a lot of vector math going on in these shaders, as the sixth most used opcode is OpVectorShuffle.

unity

And lastly the unity folder. These shader modules are dominated by OpDecorate. The next three most used opcodes are OpLoad, OpStore and OpAccessChain - so loading and storing to variables is taking up a sizeable amount of the shader modules.

All Together

If we look at all the folders above as one output from  spirv-stats instead:

We can see that loading and storing dominates our shader modules at 28% of the opcodes and 25% of the binary size.

Summary

The tool showed us some interesting divergent trends across each of the providers of the SPIR-V shader modules. Thanks to Valve, Shadertoy, Croteam and Unity for allowing @aras_p to use their SPIR-V shaders when he wrote his smol-v tool. I wouldn’t have had such interesting source material otherwise to run my tool against!

The  spirv-stats tool can be got via its GitHub repository - hope it is useful to someone!