glGetUniformLocation 使用了很多 CPU
glGetUniformLocation using a lot of CPU
当我在我的渲染循环中只调用一次 glGetUniformLocation
时,进程的 CPU 使用率上升到 30-40% 这是否正常?我应该只调用一次此方法并将位置存储在内存中吗?
这是我的代码:
GLuint Shader::getUniform(const std::string &name) const
{
return glGetUniformLocation(m_programId, name.c_str());
}
Should I only call this method once and store the location in memory?
是的,这就是普通程序。或者,或者使用 fixed locations.
Is it normal that when I call glGetUniformLocation
in my render loop only once, the CPU usage of the process goes up to 30-40% ?
这样做会浪费 CPU 周期是正常的,但这对您的整体性能的影响将取决于主机 CPU 和场景的复杂性。
如果这么简单的事情会使您的 CPU 负载增加那么多,您似乎就相当依赖 GPU。在某种程度上,这是一件好事,它表明您正在有效地使用 OpenGL API 的 rest。
Should I only call this method once and store the location in memory?
您需要了解,只有当您 link 您的程序时,位置才会改变。即使驱动程序使用像 trie 这样的优化数据结构来加速此搜索,仍然会大量浪费 CPU 周期来重复执行对未更改的内容的搜索。
"Insanity is doing the same thing over and over again and expecting different results." - 阿尔伯特·爱因斯坦
通常,人们会在程序 linked 后枚举活动的统一位置并永久存储它们。在较新版本的 GLSL(4.30 或使用 GL_ARB_explicit_uniform_location
)中,您可以使用 layout (location = N) uniform ...
显式分配制服位置并避免查询任何内容。
当我在我的渲染循环中只调用一次 glGetUniformLocation
时,进程的 CPU 使用率上升到 30-40% 这是否正常?我应该只调用一次此方法并将位置存储在内存中吗?
这是我的代码:
GLuint Shader::getUniform(const std::string &name) const
{
return glGetUniformLocation(m_programId, name.c_str());
}
Should I only call this method once and store the location in memory?
是的,这就是普通程序。或者,或者使用 fixed locations.
Is it normal that when I call
glGetUniformLocation
in my render loop only once, the CPU usage of the process goes up to 30-40% ?
这样做会浪费 CPU 周期是正常的,但这对您的整体性能的影响将取决于主机 CPU 和场景的复杂性。
如果这么简单的事情会使您的 CPU 负载增加那么多,您似乎就相当依赖 GPU。在某种程度上,这是一件好事,它表明您正在有效地使用 OpenGL API 的 rest。
Should I only call this method once and store the location in memory?
您需要了解,只有当您 link 您的程序时,位置才会改变。即使驱动程序使用像 trie 这样的优化数据结构来加速此搜索,仍然会大量浪费 CPU 周期来重复执行对未更改的内容的搜索。
"Insanity is doing the same thing over and over again and expecting different results." - 阿尔伯特·爱因斯坦
通常,人们会在程序 linked 后枚举活动的统一位置并永久存储它们。在较新版本的 GLSL(4.30 或使用 GL_ARB_explicit_uniform_location
)中,您可以使用 layout (location = N) uniform ...
显式分配制服位置并避免查询任何内容。