OpenGL/GLSL 运行时错误处理

标签 opengl runtime-error glsl

这是一个一般性问题。我没有在网上找到任何关于此的资源,但我认为值得在某处进行记录。

Shader Runtime(不是编译错误)究竟是如何处理的,比如是否试图访问当前值为 Null 的制服?

线程是否刚刚中止?会产生垃圾值吗?是否依赖于驱动程序/硬件?

最佳答案

对于“普通”统一变量,我看不出它们会导致运行时错误的任何可能性。由于它们都是原始类型,因此不可能有像 NULL 这样的值。所有这些变量都在链接时初始化。规范告诉:

2.15.3.1

All uniform variables are read-only and are initialized externally either at link time or through the API. The link-time initial value is either the value of the variable's initializer, if present, or 0 if no initializer is present.

但这里还有两种其他类型的制服可能值得关注:

采样器制服

采样器也被初始化为零,这意味着它们指向纹理 0。根据 OpenGL 规范:

8.1

The name space for texture objects is the unsigned integers, with zero reserved by the GL to represent the default texture object. The default texture object is bound to each of the TEXTURE_1D, TEXTURE_2D, TEXTURE_3D, TEXTURE_1D_ARRAY, TEXTURE_- 2D_ARRAY, TEXTURE_RECTANGLE, TEXTURE_BUFFER, TEXTURE_CUBE_MAP, TEXTURE_CUBE_MAP_ARRAY, TEXTURE_2D_MULTISAMPLE, and TEXTURE_- 2D_MULTISAMPLE_ARRAY targets during context initialization.

这基本上意味着,这里也不可能生成任何运行时异常。答案here指示从纹理 0 读取时会发生什么。

统一 block

表示由 UBO 或 SSBO 存储支持的制服。这似乎是根据:

If any active uniform block is not backed by a sufficiently large buffer object, the results of shader execution are undefined, and may result in GL interruption or termination.

依赖于实现。

结论

在着色器中获得运行时异常的唯一方法似乎是当一个统一 block 试图访问一个没有缓冲区支持的变量时。据我所知,在着色器内部无法处理这种情况。

GLSL 4.5 Specification

OpenGL 4.5 Specification

关于OpenGL/GLSL 运行时错误处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35322119/

相关文章:

opengl - GLSL 中的圆柱体冒名顶替者

c++ - OpenGL 纹理映射禁用着色

c++ - 使用统一缓冲区对象进行批量渲染

java - Java 中的 MATLAB 函数导致运行时错误 (EXCEPTION_ACCESS_VIOLATION)

scala - SublimeREPL Scala 错误

opengl - 将 ARB 程序集翻译成 GLSL?

opengl - 反投影中的 W 坐标

c - 在openGL程序中实现太阳能系统中的方向键

swift - 当我尝试在 Swift 中访问粒子文件时,我的代码出现 fatal error

c++ - 在 GLSL(330 或其他)中,什么会导致统一结构的行为不同于可变结构?