KhronosGroup / KhronosGroup/SPIRV-Cross
`flip_vert_y` for geometry shaders does not produce expected results
- Dominant language
- GLSL
- Stars
- 2.5k
- Forks
- 713
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 16
Description
The current `vertex.flip_vert_y` implementation adds `gl_Position.y` flipping at `SPIRBlock::Return`. https://github.com/KhronosGroup/SPIRV-Cross/blob/72b5b7c1a604592d98e7d4b0883231274122fd29/spirv_glsl.cpp#L17911-L17917
However, this does not affect the `EmitVertex` calls, so the vertices emitted in geometry shaders remain unflipped, which appears to be unintended.
Relevant issue: https://github.com/KhronosGroup/SPIRV-Cross/issues/1469
Small thoughts:
- Basically we could flip Y just before every `EmitVertex` call to resolve this issue. However, the code may use `gl_Position` after the `EmitVertex` call (I won't write such a code though), so the modification should be rolled back immediately to maintain the original behavior.
- For VS-GS or VS-TCS-TES (or similar) pipelines, we can refer to the `gl_Position` output from the previous stage. So it might be necessary to flip the input initially. However, if the geometry shader is used in isolation, flipping the input is not necessary...
- It might be useful to add an option to specify how the input should be handled...
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in spirv_glsl.cpp at the linked SPIRBlock::Return code and trace how EmitVertex calls are generated. Determine how geometry-shader vertex emission interacts with the existing gl_Position flip, including later uses of gl_Position and the input-stage cases described in the issue; done means the expected Y orientation is preserved without changing other observed behavior.
Written by the indexing model from the issue text.
Assessment
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100