KhronosGroup / KhronosGroup/glslang

glslangValidator compiles glsl in to spirv ok but spirv-val throws errors

Open
#4,144 1 comment 0 reactions 1 assignee Claimed by @arcady-lunarg View on GitHub
bug sev:miscompile SPIR-V
Dominant language
C++
Stars
3.6k
Forks
989
Avg merge
1d 2h
Merged PRs (30d)
31

Description

```
#version 460

layout (points) in;
layout (line_strip, max_vertices = 2) out;

void main()
{
int stream = 0;
gl_Position = gl_in[0].gl_Position + vec4(-0.1, 0.0, 0.0, 0.0);
EmitStreamVertex(stream);

gl_Position = gl_in[0].gl_Position + vec4( 0.1, 0.0, 0.0, 0.0);
EmitStreamVertex(stream);

EndPrimitive();

}
```

If I compile this code in to glsl using sdk 1.4.335.0 (happens on earlier versions too)

`glslangValidator.exe --target-env spirv1.6 -V c:\testGeom.geom -o test.geom.spv`

The output is just

`c:\testGeom.geom`

which means it is sucessful. But if I validate this I get an error

```
spirv-val test.geom.spv
error: line 17: Opcode EmitStreamVertex requires one of these capabilities: GeometryStreams
OpEmitStreamVertex %int_0
```

If I fix this and comment out the gl_Position lines

```
#version 460

layout (points) in;
layout (line_strip, max_vertices = 2) out;

void main()
{
const int stream = 0;
//gl_Position = gl_in[0].gl_Position + vec4(-0.1, 0.0, 0.0, 0.0);
EmitStreamVertex(stream);

//gl_Position = gl_in[0].gl_Position + vec4( 0.1, 0.0, 0.0, 0.0);
EmitStreamVertex(stream);

EndPrimitive();

}
```

it compiles fine again

```
glslangValidator.exe --target-env spirv1.6 -V c:\testGeom.geom -o test.geom.spv
c:\testGeom.geom
```

and now spirv throws the following error

```
spirv-val test.geom.spv
error: line 17: Opcode EmitStreamVertex requires one of these capabilities: GeometryStreams
OpEmitStreamVertex %int_0
```

The spirv-dis of this for reference

```
spirv-dis test.geom.spv
; SPIR-V
; Version: 1.6
; Generator: Khronos Glslang Reference Front End; 11
; Bound: 8
; Schema: 0
OpCapability Geometry
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Geometry %main "main"
OpExecutionMode %main InputPoints
OpExecutionMode %main Invocations 1
OpExecutionMode %main OutputLineStrip
OpExecutionMode %main OutputVertices 2
OpSource GLSL 460
OpName %main "main"
%void = OpTypeVoid
%3 = OpTypeFunction %void
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%main = OpFunction %void None %3
%5 = OpLabel
OpEmitStreamVertex %int_0
OpEmitStreamVertex %int_0
OpEndPrimitive
OpReturn
OpFunctionEnd
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.