gpt4 book ai didi

webgl - 保存/加载编译的 webgl 着色器

转载 作者:行者123 更新时间:2023-12-02 12:36:13 24 4
gpt4 key购买 nike

我还没有找到任何明确的答案,所以决定在这里提问。难道真的没有办法保存和加载编译后的 webgl 着色器吗?每次有人加载页面时都编译着色器似乎是一种浪费,因为您所要做的就是编译一次着色器,将其保存到文件中,然后加载编译后的着色器对象,就像 HLSL 一样(我知道这不是GLSL,但我对 OpenGL 还是有点陌生​​)。

那么,如果可能的话,如何在 webgl 中保存和加载已编译的着色器?

最佳答案

确实没有办法,恕我直言,这是一件好事。除了更新驱动程序时,预编译着色器可能会丢失新的优化或只是中断之外,这还会带来安全问题(向 GPU 提供任意字节码)。

when all you would have to do is compile the shaders once, save it to a file, then load the compiled shader object, as you would HLSL

OpenGL(及其衍生产品)不支持像 DirectX 那样加载预编译着色器:

Program binary formats are not intended to be transmitted. It is not reasonable to expect different hardware vendors to accept the same binary formats. It is not reasonable to expect different hardware from the same vendor to accept the same binary formats. https://www.opengl.org/wiki/Shader_Compilation#Binary_limitations

OpenGL 中似乎没有像 SPIR-V 这样的中间格式,因此您需要在目标平台上编译着色器,这会给用户更换显卡/采用混合图形解决方案、存储限制带来很多额外的担忧在客户端上(5 MB,使用 localstorage )以及滥用它来识别硬件的可能性。

关于webgl - 保存/加载编译的 webgl 着色器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36018753/

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