获取计算着色器的最大工作组大小?

时间:2016-08-17 19:35:17

标签: android opengl-es compute-shader

我正在编写一个OpenGL ES 3.1程序,想知道我正在运行的设备的最大工作组大小(它在Android 6上运行)。

对于PC查询GL_MAX_COMPUTE_WORK_GROUP_COUNTGL_MAX_COMPUTE_WORK_GROUP_SIZE工作正常,但我似乎无法在Android上执行等效操作,当我尝试类似

时,我得到OpenGL error: InvalidEnum

OpenTK代码:

int[] work_grp_cnt = new int[3];
GL.GetInteger(All.MaxComputeWorkGroupCount, work_grp_cnt);

与原生Android API相同:

int[] work_grp_cnt = new int[3];
IntBuffer maxCount = IntBuffer.Allocate(3);
GLES20.GlGetIntegerv(GLES31.GlMaxComputeWorkGroupCount, maxCount);
maxCount.Get(work_grp_cnt);

(在两种情况下,GLGetInteger都会引发相同的InvalidEnum错误) 这可能与OpenGL ES 3.1有关吗? 我正在使用索尼Xperia Z5

2 个答案:

答案 0 :(得分:2)

正如@NicolBoas指出我调用了错误的函数。下面是工作代码:

OpenTK:

        GL.GetInteger(All.MaxComputeWorkGroupCount, 0, out work_grp_cnt[0]);
        GL.GetInteger(All.MaxComputeWorkGroupCount, 1, out work_grp_cnt[1]);
        GL.GetInteger(All.MaxComputeWorkGroupCount, 2, out work_grp_cnt[2]);

        GL.GetInteger(All.MaxComputeWorkGroupSize, 0, out work_grp_size[0]);
        GL.GetInteger(All.MaxComputeWorkGroupSize, 1, out work_grp_size[1]);
        GL.GetInteger(All.MaxComputeWorkGroupSize, 2, out work_grp_size[2]);

原生Android:

        GLES31.GlGetIntegeri_v(GLES31.GlMaxComputeWorkGroupCount, 0, work_grp_cnt, 0);
        GLES31.GlGetIntegeri_v(GLES31.GlMaxComputeWorkGroupCount, 1, work_grp_cnt, 1);
        GLES31.GlGetIntegeri_v(GLES31.GlMaxComputeWorkGroupCount, 2, work_grp_cnt, 2);

        GLES31.GlGetIntegeri_v(GLES31.GlMaxComputeWorkGroupSize, 0, work_grp_size, 0);
        GLES31.GlGetIntegeri_v(GLES31.GlMaxComputeWorkGroupSize, 1, work_grp_size, 1);
        GLES31.GlGetIntegeri_v(GLES31.GlMaxComputeWorkGroupSize, 2, work_grp_size, 2);

答案 1 :(得分:1)

在C中,您必须调用带有索引的glGetIntegeri_v。对于GL_MAX_COMPUTE_WORK_GROUP_COUNT,索引是您要查询的维度。它一次只返回一个值。

您需要找到并使用此函数的Java等效项。

相关问题