Invalid vertex program header

Each of my shaders are passed through a custom compiler, then through LunarGLASS, then finally through glslang, this being the complete output:

#version 450
// LunarGOO output
struct BrushData {
	int member0;
	vec3 member1;
	vec4 member2;
	vec4 member3;
	vec4 member4;
	vec2 member5;
	vec2 member6;
};
struct PacketData {
	mat4 member0;
	BrushData member1;
};
layout(std140, set=0, binding=0) uniform SharedData {
	mat4 member0;
} _uniformSharedData;
layout(std140, set=1, binding=0) uniform PacketBatch {
	PacketData member0[455];
} _uniformPacketBatch;
layout(push_constant) uniform PushConstant {
	int member0;
	int member1;
	int member2;
	int member3;
} _uniformPushConstant;
layout(set=2, binding=0) uniform sampler2D BrushImage[56];
layout(location=0) in vec2 gIn_VSIn_In_Position_0;
layout(location=1) in vec2 gIn_VSIn_In_UV_1;
layout(location=1) out vec2 gOut_VSOut_R_UV_1;
const float C_10000d0 = 10000.0;
const float C_1d0 = 1.0;

void main()
{
	float sitofp = float(_uniformPushConstant.member3);
	float fdivtmp = sitofp / C_10000d0;
	float fsubtmp = C_1d0 - fdivtmp;
	vec4 H_z8w9nb = vec4(gIn_VSIn_In_Position_0.x, gIn_VSIn_In_Position_0.y, fsubtmp, C_1d0);
	highp float dotres = dot(H_z8w9nb, _uniformPacketBatch.member0[_uniformPushConstant.member0].member0[0]);
	highp float dotres1 = dot(H_z8w9nb, _uniformPacketBatch.member0[_uniformPushConstant.member0].member0[1]);
	highp float dotres2 = dot(H_z8w9nb, _uniformPacketBatch.member0[_uniformPushConstant.member0].member0[2]);
	highp float dotres3 = dot(H_z8w9nb, _uniformPacketBatch.member0[_uniformPushConstant.member0].member0[3]);
	vec4 H_siz04c = vec4(dotres, dotres1, dotres2, dotres3);
	highp float dotres4 = dot(H_siz04c, _uniformSharedData.member0[0]);
	highp float dotres5 = dot(H_siz04c, _uniformSharedData.member0[1]);
	highp float dotres6 = dot(H_siz04c, _uniformSharedData.member0[2]);
	highp float dotres7 = dot(H_siz04c, _uniformSharedData.member0[3]);
	vec4 H_gg6lc3 = vec4(dotres4, dotres5, dotres6, dotres7);
	gl_Position = H_gg6lc3;
	gOut_VSOut_R_UV_1 = gIn_VSIn_In_UV_1;
	
}

However (With validation) when attempting to create the pipeline, the following is spit out (A bit of custom logging, but the main message is still there):

ERROR: [Driver] Code 2 : Vertex info
-----------
Internal error: assembly compile error for vertex shader at offset 0:
-- error message --
line 1, column 1:  error: invalid vertex program header
-- internal assembly text --

WARNING: [ParameterValidation] Code 9 : vkCreateGraphicsPipelines: returned VK_ERROR_INVALID_SHADER_NV, indicating that one or more shaders failed to compile or link
[-1000012000, ErrorInvalidShaderNV] - Failed to create graphics pipeline!

So for some reason the program header is invalid, looking at a past post his issue was that he was exceeding the common 64k buffer limit, however I do not find that to be the case here, since: (My array sizes are passed as preprocessors before shader compilation)

sizeof BrushData = 4 + 12 + 16 * 3 + 8 * 2 = 80
sizeof PacketData = 64 + sizeof BrushData = 144
sizeof PacketBatch = sizeof BrushData * 455 = 65520

And assuming the max limit is 65536, this should fit well within the limits, right? Unless the compiler is changing the memory layout I can’t think of what’s wrong…

If it helps, this is the compiled SPIRV:

1:             ExtInstImport  "GLSL.std.450"
                              MemoryModel Logical GLSL450
                              EntryPoint Vertex 4  "main" 31 120 125 126
                              Source GLSL 450
                              Name 4  "main"
                              Name 8  "sitofp"
                              Name 10  "PushConstant"
                              MemberName 10(PushConstant) 0  "member0"
                              MemberName 10(PushConstant) 1  "member1"
                              MemberName 10(PushConstant) 2  "member2"
                              MemberName 10(PushConstant) 3  "member3"
                              Name 12  "_uniformPushConstant"
                              Name 18  "fdivtmp"
                              Name 22  "fsubtmp"
                              Name 28  "H_z8w9nb"
                              Name 31  "gIn_VSIn_In_Position_0"
                              Name 42  "dotres"
                              Name 45  "BrushData"
                              MemberName 45(BrushData) 0  "member0"
                              MemberName 45(BrushData) 1  "member1"
                              MemberName 45(BrushData) 2  "member2"
                              MemberName 45(BrushData) 3  "member3"
                              MemberName 45(BrushData) 4  "member4"
                              MemberName 45(BrushData) 5  "member5"
                              Name 46  "PacketData"
                              MemberName 46(PacketData) 0  "member0"
                              MemberName 46(PacketData) 1  "member1"
                              Name 49  "PacketBatch"
                              MemberName 49(PacketBatch) 0  "member0"
                              Name 51  "_uniformPacketBatch"
                              Name 59  "dotres1"
                              Name 67  "dotres2"
                              Name 75  "dotres3"
                              Name 82  "H_siz04c"
                              Name 88  "dotres4"
                              Name 90  "SharedData"
                              MemberName 90(SharedData) 0  "member0"
                              Name 92  "_uniformSharedData"
                              Name 96  "dotres5"
                              Name 101  "dotres6"
                              Name 106  "dotres7"
                              Name 111  "H_gg6lc3"
                              Name 118  "gl_PerVertex"
                              MemberName 118(gl_PerVertex) 0  "gl_Position"
                              MemberName 118(gl_PerVertex) 1  "gl_PointSize"
                              MemberName 118(gl_PerVertex) 2  "gl_ClipDistance"
                              MemberName 118(gl_PerVertex) 3  "gl_CullDistance"
                              Name 120  ""
                              Name 125  "gOut_VSOut_R_UV_1"
                              Name 126  "gIn_VSIn_In_UV_1"
                              Name 133  "BrushImage"
                              MemberDecorate 10(PushConstant) 0 Offset 0
                              MemberDecorate 10(PushConstant) 1 Offset 4
                              MemberDecorate 10(PushConstant) 2 Offset 8
                              MemberDecorate 10(PushConstant) 3 Offset 12
                              Decorate 10(PushConstant) Block
                              Decorate 31(gIn_VSIn_In_Position_0) Location 0
                              MemberDecorate 45(BrushData) 0 Offset 0
                              MemberDecorate 45(BrushData) 1 Offset 16
                              MemberDecorate 45(BrushData) 2 Offset 32
                              MemberDecorate 45(BrushData) 3 Offset 48
                              MemberDecorate 45(BrushData) 4 Offset 64
                              MemberDecorate 45(BrushData) 5 Offset 72
                              MemberDecorate 46(PacketData) 0 ColMajor
                              MemberDecorate 46(PacketData) 0 Offset 0
                              MemberDecorate 46(PacketData) 0 MatrixStride 16
                              MemberDecorate 46(PacketData) 1 Offset 64
                              Decorate 48 ArrayStride 144
                              MemberDecorate 49(PacketBatch) 0 Offset 0
                              Decorate 49(PacketBatch) Block
                              Decorate 51(_uniformPacketBatch) DescriptorSet 1
                              Decorate 51(_uniformPacketBatch) Binding 0
                              MemberDecorate 90(SharedData) 0 ColMajor
                              MemberDecorate 90(SharedData) 0 Offset 0
                              MemberDecorate 90(SharedData) 0 MatrixStride 16
                              Decorate 90(SharedData) Block
                              Decorate 92(_uniformSharedData) DescriptorSet 0
                              Decorate 92(_uniformSharedData) Binding 0
                              MemberDecorate 118(gl_PerVertex) 0 BuiltIn Position
                              MemberDecorate 118(gl_PerVertex) 1 BuiltIn PointSize
                              MemberDecorate 118(gl_PerVertex) 2 BuiltIn ClipDistance
                              MemberDecorate 118(gl_PerVertex) 3 BuiltIn CullDistance
                              Decorate 118(gl_PerVertex) Block
                              Decorate 125(gOut_VSOut_R_UV_1) Location 1
                              Decorate 126(gIn_VSIn_In_UV_1) Location 1
                              Decorate 133(BrushImage) DescriptorSet 2
                              Decorate 133(BrushImage) Binding 0
               2:             TypeVoid
               3:             TypeFunction 2
               6:             TypeFloat 32
               7:             TypePointer Function 6(float)
               9:             TypeInt 32 1
10(PushConstant):             TypeStruct 9(int) 9(int) 9(int) 9(int)
              11:             TypePointer PushConstant 10(PushConstant)
12(_uniformPushConstant):     11(ptr) Variable PushConstant
              13:      9(int) Constant 3
              14:             TypePointer PushConstant 9(int)
              20:    6(float) Constant 1176256512
              23:    6(float) Constant 1065353216
              26:             TypeVector 6(float) 4
              27:             TypePointer Function 26(fvec4)
              29:             TypeVector 6(float) 2
              30:             TypePointer Input 29(fvec2)
31(gIn_VSIn_In_Position_0):     30(ptr) Variable Input
              32:             TypeInt 32 0
              33:     32(int) Constant 0
              34:             TypePointer Input 6(float)
              37:     32(int) Constant 1
              44:             TypeMatrix 26(fvec4) 4
   45(BrushData):             TypeStruct 9(int) 26(fvec4) 26(fvec4) 26(fvec4) 29(fvec2) 29(fvec2)
  46(PacketData):             TypeStruct 44 45(BrushData)
              47:     32(int) Constant 496
              48:             TypeArray 46(PacketData) 47
 49(PacketBatch):             TypeStruct 48
              50:             TypePointer Uniform 49(PacketBatch)
51(_uniformPacketBatch):     50(ptr) Variable Uniform
              52:      9(int) Constant 0
              55:             TypePointer Uniform 26(fvec4)
              63:      9(int) Constant 1
              71:      9(int) Constant 2
  90(SharedData):             TypeStruct 44
              91:             TypePointer Uniform 90(SharedData)
92(_uniformSharedData):     91(ptr) Variable Uniform
             117:             TypeArray 6(float) 37
118(gl_PerVertex):             TypeStruct 26(fvec4) 6(float) 117 117
             119:             TypePointer Output 118(gl_PerVertex)
             120:    119(ptr) Variable Output
             122:             TypePointer Output 26(fvec4)
             124:             TypePointer Output 29(fvec2)
125(gOut_VSOut_R_UV_1):    124(ptr) Variable Output
126(gIn_VSIn_In_UV_1):     30(ptr) Variable Input
             128:             TypeImage 6(float) 2D sampled format:Unknown
             129:             TypeSampledImage 128
             130:     32(int) Constant 56
             131:             TypeArray 129 130
             132:             TypePointer UniformConstant 131
 133(BrushImage):    132(ptr) Variable UniformConstant
         4(main):           2 Function None 3
               5:             Label
       8(sitofp):      7(ptr) Variable Function
     18(fdivtmp):      7(ptr) Variable Function
     22(fsubtmp):      7(ptr) Variable Function
    28(H_z8w9nb):     27(ptr) Variable Function
      42(dotres):      7(ptr) Variable Function
     59(dotres1):      7(ptr) Variable Function
     67(dotres2):      7(ptr) Variable Function
     75(dotres3):      7(ptr) Variable Function
    82(H_siz04c):     27(ptr) Variable Function
     88(dotres4):      7(ptr) Variable Function
     96(dotres5):      7(ptr) Variable Function
    101(dotres6):      7(ptr) Variable Function
    106(dotres7):      7(ptr) Variable Function
   111(H_gg6lc3):     27(ptr) Variable Function
              15:     14(ptr) AccessChain 12(_uniformPushConstant) 13
              16:      9(int) Load 15
              17:    6(float) ConvertSToF 16
                              Store 8(sitofp) 17
              19:    6(float) Load 8(sitofp)
              21:    6(float) FDiv 19 20
                              Store 18(fdivtmp) 21
              24:    6(float) Load 18(fdivtmp)
              25:    6(float) FSub 23 24
                              Store 22(fsubtmp) 25
              35:     34(ptr) AccessChain 31(gIn_VSIn_In_Position_0) 33
              36:    6(float) Load 35
              38:     34(ptr) AccessChain 31(gIn_VSIn_In_Position_0) 37
              39:    6(float) Load 38
              40:    6(float) Load 22(fsubtmp)
              41:   26(fvec4) CompositeConstruct 36 39 40 23
                              Store 28(H_z8w9nb) 41
              43:   26(fvec4) Load 28(H_z8w9nb)
              53:     14(ptr) AccessChain 12(_uniformPushConstant) 52
              54:      9(int) Load 53
              56:     55(ptr) AccessChain 51(_uniformPacketBatch) 52 54 52 52
              57:   26(fvec4) Load 56
              58:    6(float) Dot 43 57
                              Store 42(dotres) 58
              60:   26(fvec4) Load 28(H_z8w9nb)
              61:     14(ptr) AccessChain 12(_uniformPushConstant) 52
              62:      9(int) Load 61
              64:     55(ptr) AccessChain 51(_uniformPacketBatch) 52 62 52 63
              65:   26(fvec4) Load 64
              66:    6(float) Dot 60 65
                              Store 59(dotres1) 66
              68:   26(fvec4) Load 28(H_z8w9nb)
              69:     14(ptr) AccessChain 12(_uniformPushConstant) 52
              70:      9(int) Load 69
              72:     55(ptr) AccessChain 51(_uniformPacketBatch) 52 70 52 71
              73:   26(fvec4) Load 72
              74:    6(float) Dot 68 73
                              Store 67(dotres2) 74
              76:   26(fvec4) Load 28(H_z8w9nb)
              77:     14(ptr) AccessChain 12(_uniformPushConstant) 52
              78:      9(int) Load 77
              79:     55(ptr) AccessChain 51(_uniformPacketBatch) 52 78 52 13
              80:   26(fvec4) Load 79
              81:    6(float) Dot 76 80
                              Store 75(dotres3) 81
              83:    6(float) Load 42(dotres)
              84:    6(float) Load 59(dotres1)
              85:    6(float) Load 67(dotres2)
              86:    6(float) Load 75(dotres3)
              87:   26(fvec4) CompositeConstruct 83 84 85 86
                              Store 82(H_siz04c) 87
              89:   26(fvec4) Load 82(H_siz04c)
              93:     55(ptr) AccessChain 92(_uniformSharedData) 52 52
              94:   26(fvec4) Load 93
              95:    6(float) Dot 89 94
                              Store 88(dotres4) 95
              97:   26(fvec4) Load 82(H_siz04c)
              98:     55(ptr) AccessChain 92(_uniformSharedData) 52 63
              99:   26(fvec4) Load 98
             100:    6(float) Dot 97 99
                              Store 96(dotres5) 100
             102:   26(fvec4) Load 82(H_siz04c)
             103:     55(ptr) AccessChain 92(_uniformSharedData) 52 71
             104:   26(fvec4) Load 103
             105:    6(float) Dot 102 104
                              Store 101(dotres6) 105
             107:   26(fvec4) Load 82(H_siz04c)
             108:     55(ptr) AccessChain 92(_uniformSharedData) 52 13
             109:   26(fvec4) Load 108
             110:    6(float) Dot 107 109
                              Store 106(dotres7) 110
             112:    6(float) Load 88(dotres4)
             113:    6(float) Load 96(dotres5)
             114:    6(float) Load 101(dotres6)
             115:    6(float) Load 106(dotres7)
             116:   26(fvec4) CompositeConstruct 112 113 114 115
                              Store 111(H_gg6lc3) 116
             121:   26(fvec4) Load 111(H_gg6lc3)
             123:    122(ptr) AccessChain 120 52
                              Store 123 121
             127:   29(fvec2) Load 126(gIn_VSIn_In_UV_1)
                              Store 125(gOut_VSOut_R_UV_1) 127
                              Return
                              FunctionEnd

It seems that the actual error is the internal NVIDIA SPIRV compiler? Is there any way to get the actual error messages instead of – error message – and – internal assembly text --?

Sorry to break this to you, but you exceed the 64k buffer limit.

Your calculation for the size of BrushData is simply adding the sizes of its members, disregarding the std140 layout it is used with. A vec3 has a base alignment of 4N, so 16 byte for 32-bit float. This means that you have 12 byte padding after member0 and 4 byte padding after member1. There is no “oh i can reorder and pack this”, std140 has fixed rules that do not allow any packing or reordering. So BrushData is actually 96 bytes in size, PacketData becomes 160 bytes and PacketBatch becomes 72800 bytes.

To remove the padding, you could replace member0 and member1 with a vec4 member01 and then unpack with

int member0 = floatBitsToInt(member01.x);
vec3 member1 = member01.yzw;

I’m not sure how you generated that SPIR-V code, but it doesn’t fit the GLSL code. In the SPIR-V code BrushData has only 6 members (0-5), while in GLSL it has 7 (0-6). But even so you can see in the offsets that the first int member takes up 16 bytes in the offsets (see lines 58-59). But since it misses the vec3 (see struct in SPIR-V at line 110) something is off.

Regards

Oh, I thought it would pack it, seems that I need to revisit the layout definitions, sorry about that. And I might have selected an old spirv dump instead of a more recent one, sorry again.

EDIT: I come from a DirectX environment, so I’m still adapting to the OGL like environment…

It seems you were right on the money, thank you for your time, I really appreciate it.