Skip to content

Commit

Permalink
Merge pull request #1233 from KhronosGroup/fix-1231
Browse files Browse the repository at this point in the history
GLSL: Fix EmitStreamVertex/Primitive.
  • Loading branch information
HansKristian-Work authored Dec 9, 2019
2 parents 15b860e + d7e612f commit 363035c
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
14 changes: 14 additions & 0 deletions reference/opt/shaders/geom/multi-stream.geom
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#version 450
layout(triangles) in;
layout(max_vertices = 2, points) out;

void main()
{
gl_Position = gl_in[0].gl_Position;
EmitStreamVertex(0);
EndStreamPrimitive(0);
gl_Position = gl_in[0].gl_Position + vec4(2.0);
EmitStreamVertex(1);
EndStreamPrimitive(1);
}

14 changes: 14 additions & 0 deletions reference/shaders/geom/multi-stream.geom
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#version 450
layout(triangles) in;
layout(max_vertices = 2, points) out;

void main()
{
gl_Position = gl_in[0].gl_Position;
EmitStreamVertex(0);
EndStreamPrimitive(0);
gl_Position = gl_in[0].gl_Position + vec4(2.0);
EmitStreamVertex(1);
EndStreamPrimitive(1);
}

15 changes: 15 additions & 0 deletions shaders/geom/multi-stream.geom
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#version 450

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

void main()
{
gl_Position = gl_in[0].gl_Position;
EmitStreamVertex(0);
EndStreamPrimitive(0);
gl_Position = gl_in[0].gl_Position + 2;
EmitStreamVertex(1);
EndStreamPrimitive(1);
}

24 changes: 22 additions & 2 deletions spirv_glsl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9464,12 +9464,32 @@ void CompilerGLSL::emit_instruction(const Instruction &instruction)
break;

case OpEmitStreamVertex:
statement("EmitStreamVertex();");
{
if (options.es)
SPIRV_CROSS_THROW("Multi-stream geometry shaders not supported in ES.");
else if (!options.es && options.version < 400)
SPIRV_CROSS_THROW("Multi-stream geometry shaders only supported in GLSL 400.");

auto stream_expr = to_expression(ops[0]);
if (expression_type(ops[0]).basetype != SPIRType::Int)
stream_expr = join("int(", stream_expr, ")");
statement("EmitStreamVertex(", stream_expr, ");");
break;
}

case OpEndStreamPrimitive:
statement("EndStreamPrimitive();");
{
if (options.es)
SPIRV_CROSS_THROW("Multi-stream geometry shaders not supported in ES.");
else if (!options.es && options.version < 400)
SPIRV_CROSS_THROW("Multi-stream geometry shaders only supported in GLSL 400.");

auto stream_expr = to_expression(ops[0]);
if (expression_type(ops[0]).basetype != SPIRType::Int)
stream_expr = join("int(", stream_expr, ")");
statement("EndStreamPrimitive(", stream_expr, ");");
break;
}

// Textures
case OpImageSampleExplicitLod:
Expand Down

0 comments on commit 363035c

Please sign in to comment.