#SPIRV-Cross reflection failing on some inputs

18 messages · Page 1 of 1 (latest)

bright shadow
#

When running the SPIRV-Cross command line tool on various input it works most of the time but occasionally it throws

SPIRV-Cross threw an exception: Buffer block cannot be expressed as any of std430, std140, scalar, even with enhanced layouts. You can try flattening this block to support a more flexible layout.

Here is a working and a failing example
Working sample https://vcs.codecreation.dev/spirv-samples/sample1.html
Problematic sample https://vcs.codecreation.dev/spirv-samples/sample2.html

I'm running these as spirv-cross.exe sample1.spv (works - outputs a decompilation) and spirv-cross.exe sample2.spv (fails)

ocean flame
#

Sounds like you've written something unrepresentable in GLSL?

#

Was the original source that generated the spir-v bytecode glsl?

bright shadow
#

Hi there! Actually I found something that seems to work, perhaps it is what the exception is requesting

#

I tried settings different options and it turned out there were several that work against the second sample

#

the ones that seemed the most reasonable are

spirv-cross.exe --flatten-ubo sample2.spv
spirv-cross.exe --glsl-emit-ubo-as-plain-uniforms sample2.spv
#

I don't really know what they do or what the differences are, I've updated the sample2.html page with the different results

bright shadow
#

I guess 47 4C 53 4C 2E 73 74 64 2E 34 35 30 near the top reads GLSL std 450 it must be what was used

ocean flame
#

Not necessarily. That's a library import most likely

#

A lot of functions (e.g. trig stuff ) aren't part of spirv

bright shadow
#

ok, interesting .. I'll probably need to study the basics to understand what it means ..

#

I did find, I was able to extract OpenGL files from an earlier version of the same game (this is Dota2 and I'm using a tool called 'ValveResourceFormat'), and I can make a side-by-side comparison of the same shaders, one version in OpenGL (with the source given uncompiled by the game) and the other in Vulkan using Spirv reflection

#

I think it's safe to say, at least, the shader stack being analysed is far too complicated to make any practical use out of ..

#

but taking an interest anyway .. it appears in the Vulkan file

layout(location = 0) in vec3 _5275;
layout(location = 1) in vec4 _3208;
layout(location = 2) in vec2 _5800;
...

has a direct correspondence in the OpenGL source

layout(location=0) in vec3 VS_INPUT_gl_vPositionOs;
layout(location=1) in vec4 VS_INPUT_gl_vNormalOs;
layout(location=2) in vec2 VS_INPUT_gl_vTexCoord;
...

and probably means the same thing

#

following on from that, for example, searching for the pair (_5800, VS_INPUT_gl_vTexCoord) in their respective files shows

  float _8864 = _4930._m3 * 0.01745329238474369049072265625;
  vec2 _16310 = _5800 - vec2(0.5);
  float _21977 = cos(_8864);
  float _21439 = sin(_8864);  

must is the same as

float param1 = g_flTexCoordRotate0 * C_0d0174533;
vec2 vAdjust = VS_INPUT_gl_vTexCoord + C_vec2pa0d5p;
float H_vyry841 = cos(param1);
float H_u7xj891 = sin(param1);

and C_vec2pa0d5p is indeed defined as const vec2 C_vec2pa0d5p = vec2(-0.5); in the OpenGL file