【问题标题】:OpenGL shader fails to compile on deviceOpenGL 着色器无法在设备上编译
【发布时间】:2016-08-17 11:01:24
【问题描述】:

我正在编写一个可以在 PC 和 Android 上运行的计算着色器。它在 PC 上运行良好,但在 Android 上无法编译。

这是着色器:

#version 310 es

uniform vec2 lightPos; // passed from the app

layout (local_size_x = 512, local_size_y = 1) in;
layout (rgba8, binding = 0) uniform image2D img_output;
layout (rgba8, binding = 1) uniform readonly image2D colorTex;
layout (rgba8, binding = 2) uniform readonly image2D transpTex;

void main () {
    imageStore(img_output, ivec2(3, 6), vec4(0.3 ,0.2 ,0.5 ,0.9));
}

错误是:
Shader compile error: ERROR: '' : unsupported format on read/write image

如果我将最后一个参数更改为ivec4uvec4,我会得到:
ERROR: 'imageStore' : no matching overloaded function found

GL.GetString(StringName.Version); 返回 GL version:OpenGL ES 3.1 V@141.0 (GIT@I0bc8e21cf2)

这是在 Sony Xperia Z5 上(Android 模拟器似乎不支持 OpenGL ES 3.1)。

【问题讨论】:

标签: android opengl-es compute-shader


【解决方案1】:

这在GLSL ES 3.10 spec 中指定,在第 72 页的“4.9 内存访问限定符”部分:

除了使用格式限定符 r32f、r32i 和 r32ui 限定的图像变量外,图像变量必须指定内存限定符 readonly 或内存限定符 writeonly。

此限制在 GLSL ES 3.20 中仍然适用。

【讨论】:

    【解决方案2】:

    如果输出图像被声明为只写,则着色器编译:

    layout (rgba8, binding = 0) uniform writeonly image2D img_output;

    不知道为什么需要这样做,有人有讨论此问题的规范的链接吗?

    【讨论】:

      猜你喜欢
      • 2018-05-30
      • 1970-01-01
      • 2015-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多