简体   繁体   中英

Control decorations when compiling GLSL to SPIR-V with glslang

The SPIR-V specification allows a module to request that a branch will be flattened or a loop unrolled using control decorations for the appropriate instructions. This has a significant impact on the final performance profile of the shader. However, standard GLSL, unlike HLSL, doesn't have a way to express this. The intent is that the driver can make those decisions for you, though arguably only the developer can have enough information to do so.

Is there a way to specify how a control operation should be compiled from GLSL when using glslang, or is this left up to the driver to make these decisions? Do we still have to manually unroll loops to be sure they won't branch?

Is there a way to specify how a control operation should be compiled from GLSL when using glslang

There is no explicit means in GLSL to request such things. There may be glslangValidator switches that can control it, but even then, that would be a global setting, not a per-loop setting.

Do we still have to manually unroll loops to be sure they won't branch?

That's the only way to "be sure they won't branch". Even with SPIR-V's unroll decoration, that is a request , not a guarantee. If the internal SPIR-V compiler doesn't want to unroll that loop, then it won't, regardless of what you tell it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM