KhronosGroup / KhronosGroup/glslang

Problems with Hull Shader and Patch Constant Function in 1.2.141.2

Open
#2,269 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
3.6k
Forks
989
Avg merge
1d 2h
Merged PRs (30d)
31

Description

I’ve moved to Vulkan SDK 1.2.141.2 to try out fixes in tessellation shaders (array flattening or something like that). My tessellation shaders are working fine in my D3D12 renderer, but there are problems running them in Vulkan (nothing is drawn). I’m using PN Triangles Tessellation method similar to this one: http://ogldev.atspace.co.uk/www/tutorial31/tutorial31.html

1) If I set disableOptimizer to true in glslang::SpvOptions, then vkCreateGraphicsPipelines with tessellation will crash in nvoglv64.dll, showing Access violation writing location 0x00007FF8E0321DC9.

2) There is a problem with patch constant function, implemented as a barrier + if(gl_InvocationID == 0) in Vulkan. I have this line of pseudocode in Hull Shader:
`oppositeEdgeTessFactor = (normal.z < -0.75) ? 0.0 : max(1.0, oppositeEdgeTessFactor * (1.0 - abs(normal.z * 0.75))).`
And nothing similar in patch constant function.
When I decompile this shader in RenderDoc to GLSL I can see this:
`float _someNumber = (_1239.z < (-0.75)) ? … * (1.0 - abs(_someNumber.z * 0.75)));`
copied 1 time before barrier() and 3 times inside if(gl_InvocationID == 0) block (for every vertex, I assume). Why is it doing this? This is already calculated in Hull shader’s part, this should not be calculated again inside patch constant function’s if block, it’s just wasting GPU cycles.
I can see some result drawn by changing patch constant function, so that it just sets some tessFactors and doesn’t send any output to domain shader (previously it was computing b111 center bezier control point).
I think there is a problem with synchronization. I see that the code gets copied and shuffled from one side of barrier() to the other. Hull Shader and patch constant function should be treated as 2 different shaders without optimizations across barrier() call.

Contributor guide

Open the contributing guide

Research direction

No source files or tests are named. Start by reproducing the PN Triangles tessellation case from the issue with Vulkan SDK 1.2.141.2, comparing behavior with disableOptimizer enabled and inspecting the generated shader around the barrier and gl_InvocationID branch. Done means the crash and incorrect patch-constant behavior are explained and corrected with evidence.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, computer-graphics
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.