gpt4 book ai didi

opengl - GLSL 4.x 子例程变量会导致任何性能开销吗?

转载 作者:行者123 更新时间:2023-12-04 02:51:05 26 4
gpt4 key购买 nike

网络上没有太多关于它们的深入信息。

它们是如何实现的以及它们在幕后如何工作?我想知道它们是否会导致任何性能开销,特别是在多个子例程的情况下,以决定创建不同版本的着色器的最佳做法是什么:子例程或单独的着色器。

任何信息或建议?

最佳答案

从 OpenGL 论坛引用的一个很好的详细答案 here .

Subroutine variables are pretty much like function pointers in C, or if we have to, we can call them "virtual functions" (as D3D refers to them).

They are probably implemented on all hardware as actual function pointers, i.e. calling a subroutine will translate to an indirect CALL instruction that takes the called address from a register/memory location. Thus you can expect them to likely be more efficient than switch case statements in shaders or switching between multiple shaders.

However, this is all just how it should work, as there could be inefficiencies in some hardware or driver that make them slower than they could be, but that's another story. Also, unfortunately, subroutines have an inherent inefficiency due to the API itself, namely that you have to re-specify the association between subroutine variables and subroutines (using glUniformSubroutinesuiv) every single time you bind a program that has subroutine variables. This is an unfortunate inheritance from D3D, as GL copied this weird behavior from there.

关于opengl - GLSL 4.x 子例程变量会导致任何性能开销吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17706153/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com