sydd
sydd

Reputation: 1946

Get maximum workgroup size for compute shaders?

I am writing an OpenGL ES 3.1 program and want to know the maximum workgroup size for the device I'm running on (its running on Android 6).

For PC querying GL_MAX_COMPUTE_WORK_GROUP_COUNT and GL_MAX_COMPUTE_WORK_GROUP_SIZE works fine, but I cant seem to do the equivalent for on Android, I get OpenGL error: InvalidEnum when I try something like

OpenTK code:

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

Same with native Android APIs:

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

(in both cases the GLGetInteger raises the same InvalidEnum error) Is this possible with OpenGL ES 3.1?
I am using a Sony Xperia Z5

Upvotes: 1

Views: 2263

Answers (2)

sydd
sydd

Reputation: 1946

As @NicolBoas pointed out I called the wrong function. Heres the working code:

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]);

Native 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);

Upvotes: 3

Nicol Bolas
Nicol Bolas

Reputation: 473966

In C, you must call glGetIntegeri_v, which takes an index. For GL_MAX_COMPUTE_WORK_GROUP_COUNT, the index is the dimension you want to query. It only returns one value at a time.

You will need to find and use the Java-equivalent of this function.

Upvotes: 2

Related Questions