KhronosGroup / SPIRV-Visualizer

Client side only Javascript to visualize a SPIR-V Module binary
https://www.khronos.org/spir/visualizer/
Apache License 2.0
31 stars 5 forks source link

visualizer breaks #24

Closed didito closed 8 months ago

didito commented 8 months ago

Hi,

Unfortunately, the Visualizer silently breaks on some of my SPVs.

main.js:410 Uncaught TypeError: Cannot read properties of undefined (reading 'opname')
    at parseBinaryStream (main.js:410:114)
    at fileSelected (input.js:40:5)
    at reader.onload (input.js:49:9)
parseBinaryStream @ main.js:410
fileSelected @ input.js:40
reader.onload @ input.js:49
load (async)
fileSelect @ input.js:47

I have only tried Chrome ("120.0.6099.130 (Official Build) (64-bit)") but looking at the debugger I don't think it is Browser related. operand simply has the value of 35 but extInstructionSet contains only 34 entries and attempting to get opname results in an error/exception.

 parseBinaryStream (main.js):
 ...
           } else if (kind == 'LiteralExtInstInteger') {
                    assert(
                        opcode == spirv.Enums.Op.OpExtInst, 'Makes assumption OpExtInst is only opcode with LiteralExtInstInteger');
                    // single word literal but from extended instruction set
                    const setId = module[i + 3];

                    // This will have the while loop use the extended grammar
                    const extInstructionSet = spirv.getExtInstructions(setId);
                    // There can be custom extended instructions starting with SPIR-V 1.6
                    const extOpname = (extInstructionSet == undefined) ? operand : extInstructionSet.get(operand).opname;   <=== ERROR
                    instructionString += ' ' + createLiteralHtmlString(extOpname);
                    operandNameList.push(operandName);
                    operandWordIndexList.push(operandOffset);
                    operandOffset++;
...

This SPV in question is a vertex shader of a draw in a Z-prepass of current trunk version of Godot - some variant of https://github.com/godotengine/godot/blob/master/servers/rendering/renderer_rd/shaders/forward_clustered/scene_forward_clustered.glsl

Validation (spirv-val --target-env vulkan1.3) does not report any errors for me on VulkanSDK 1.3.250.0 but I have to admit I captured the SPIR-V disasm from RenderDoc and assembled it again. So not sure how original it still is.

didito commented 8 months ago

There is also room for improvement in UI notification, e.g. tell the user there was an error. Currently the top right corner reports Loaded: my_filename.spvand the left canvas just shows how far it was able to parse ...

spencer-lunarg commented 8 months ago

thanks for the report! I will take a look into this, I agree the error reporting is in need of fixing... can try and improve that as well while on this

spencer-lunarg commented 8 months ago

wow, so there is a extinst.debuginfo.grammar.json and extinst.nonsemantic.shader.debuginfo.100.grammar.json and the DebugInfo was being used by both

was a simple fix, should be working now (making new issue for the lack of good reporting)

didito commented 8 months ago

I can confirm it's working now. Thanks for the quick turn-around! 🙏