保存/加载已编译的 webgl 着色器 [英] Saving/Loading compiled webgl shaders

查看:34
本文介绍了保存/加载已编译的 webgl 着色器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have not found any definitive answers to this, so decided to ask here. Is there really no way to save and load compiled webgl shaders? It seems a waste to compile the shaders every time someone loads the page, 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 (I know it's not GLSL, but i'm still a little new to OpenGL).

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

So, if possible, how can i save and load a compiled shader in webgl?

推荐答案

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

There really is no way, and imho thats a good thing. It would pose a security issue(feeding arbitrary bytecode to the GPU) in addition to that when drivers are updated the precompiled shaders are potentially missing new optimizations or just break.

当您只需要编译一次着色器时,将其保存到一个文件中,然后像 HLSL 一样加载已编译的着色器对象

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 那样加载预编译着色器:

OpenGL(and its derivatives) does not support loading pre-compiled shaders the same way DirectX does:

程序二进制格式用于传输.期望不同的硬件供应商接受相同的二进制格式是合理的.期望来自同一供应商的不同硬件接受相同的二进制格式是合理的.https://www.opengl.org/wiki/Shader_Compilation#Binary_limitations

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)和可能会滥用它来对硬件进行指纹识别.

There seems to be no intermediate format like SPIR-V in OpenGL so you would need to compile the shaders on the target platform introducing a whole lot of additional concerns with users changing their graphics cards / employing a hybrid graphics solution, storage limitations on the client(5 MB using localstorage) and the possibility of abusing it to fingerprint the hardware.

这篇关于保存/加载已编译的 webgl 着色器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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