1
#version 400

#extension GL_ARB_separate_shader_objects : enable
#extension GL_ARB_shading_language_420pack : enable

layout(location = 0) out vec4 fs_color;

struct Test
{
    float value;
};

layout(std140,set = 0,binding = 0) uniform UTest
{
    Test t;
} u_test;

float get_value(Test t) {return t.value;}

void main()
{
    fs_color = vec4(get_value(u_test.t),0.0,0.0,1.0);
}

The GLSL code above causes the following SPIR-V compiler error:

Object: 0x0 | SPIR-V module not valid: OpFunctionCall Argument <id> '29's type does not match Function <id> '8's parameter type.

The error comes from the get_value function call in main. The error happens whenever I try to pass a struct instance as a function argument, if that instance is part of a uniform (In this case u_test). If the struct is not part of a uniform, it compiles fine.

Why is this a problem and what can I do to get around it?

Silverlan
  • 2,783
  • 3
  • 31
  • 66
  • 1
    I've had trouble with this sort of thing in the past. Honestly I can't remember how I fixed it, but I would start by making your call stack shallower: `Test t = u_test.t;` `float val = get_value(t);` `fs_color = vec4(val,0.0,0.0,1.0);` It'll make debugging far simpler. You can optimise later. – Ian Young Apr 02 '18 at 10:51
  • Thanks for the tip, that got rid of the error! Still don't quite understand why it happens in the first place though. – Silverlan Apr 02 '18 at 10:56
  • It's something to do with nested functions I think. Try running the original version through glslvalidator.exe and see what it tells you. – Ian Young Apr 02 '18 at 11:00

0 Answers0