与 glUniform* 的隐式同步 [英] Implicit synchronization with glUniform*

查看:70
本文介绍了与 glUniform* 的隐式同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下 GL 代码中是否存在隐式同步?

Is there an implicit synchronization in the following GL code?

glClear(GL_COLOR_BUFFER_BIT);
glUseProgram(prg);

glUniform1f(loc, a);
glDrawArrays(GL_TRIANGLES, 0, N);

glUniform1f(loc, b);                     // <-- Implicit synchronization??
glDrawArrays(GL_TRIANGLES, 0, N);

swapBuffers();

推荐答案

一如既往,OpenGL 实现可以按照他们喜欢的方式处理事情,只要它导致正确的行为.所以真的没有办法说它必须如何工作.

As always, OpenGL implementations can handle things the way they like, as long as it results in the correct behavior. So there's really no way to say how it has to work.

话虽如此,更新uniforms 是一种常见的操作,强制GPU 和CPU 之间同步更新uniform 对性能来说会很糟糕.

That being said, updating uniforms is a common operation, and forcing a synchronization between GPU and CPU for uniform updates would be horrible for performance.

想象这在现实中最有可能如何工作的最简单方法是,您发出的 OpenGL 调用被编码在一个命令流中,然后由 GPU 执行.当您进行 glUniform() 调用时,这将生成一个命令来更新统一值,并将该命令附加到命令流中.它稍后将由 GPU 执行,同时绘制调用也是同一命令流的一部分.

The easiest way to picture how this most likely works in reality is that the OpenGL calls you make are encoded in a command stream that is later executed by the GPU. When you make a glUniform() call, this will generate a command to update the uniform value, and append that command to the command stream. It will be executed by the GPU later, along with the draw calls that are also part of the same command stream.

只有当 GPU 执行命令时(通常发生在 glUniform() 调用返回后很久),GPU 使用的实际值才会更新.

Only when the GPU executes the command, which will mostly happen long after the glUniform() call returns, will the actual value used by the GPU be updated.

这篇关于与 glUniform* 的隐式同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆