diff --git a/src/api/l_graphics.c b/src/api/l_graphics.c index bb8d8d33..e8ba7e8e 100644 --- a/src/api/l_graphics.c +++ b/src/api/l_graphics.c @@ -451,6 +451,14 @@ static int l_lovrGraphicsGetLimits(lua_State* L) { lua_setfield(L, -2, "anisotropy"); lua_pushinteger(L, limits->blockSize); lua_setfield(L, -2, "blocksize"); + lua_createtable(L, 3, 0); + lua_pushinteger(L, limits->compute[0]); + lua_rawseti(L, -2, 1); + lua_pushinteger(L, limits->compute[1]); + lua_rawseti(L, -2, 2); + lua_pushinteger(L, limits->compute[2]); + lua_rawseti(L, -2, 3); + lua_setfield(L, -2, "compute"); return 1; } diff --git a/src/modules/graphics/graphics.h b/src/modules/graphics/graphics.h index 468fad91..ea21f347 100644 --- a/src/modules/graphics/graphics.h +++ b/src/modules/graphics/graphics.h @@ -189,13 +189,13 @@ typedef struct { } GpuFeatures; typedef struct { - bool initialized; float pointSizes[2]; int textureSize; int textureMSAA; float textureAnisotropy; int blockSize; int blockAlign; + int compute[3]; } GpuLimits; typedef struct { diff --git a/src/modules/graphics/opengl.c b/src/modules/graphics/opengl.c index b52f9823..64e49ed5 100644 --- a/src/modules/graphics/opengl.c +++ b/src/modules/graphics/opengl.c @@ -1263,6 +1263,12 @@ void lovrGpuInit(void* (*getProcAddress)(const char*), bool debug) { #endif glGetFloatv(GL_POINT_SIZE_RANGE, state.limits.pointSizes); + if (state.features.compute) { + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 0, &state.limits.compute[0]); + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 1, &state.limits.compute[1]); + glGetIntegeri_v(GL_MAX_COMPUTE_WORK_GROUP_COUNT, 2, &state.limits.compute[2]); + } + if (state.features.multiview) { state.singlepass = MULTIVIEW; } else if (state.features.instancedStereo) { @@ -1395,6 +1401,9 @@ void lovrGpuCompute(Shader* shader, int x, int y, int z) { #else lovrAssert(state.features.compute, "Compute shaders are not supported on this system"); lovrAssert(shader->type == SHADER_COMPUTE, "Attempt to use a non-compute shader for a compute operation"); + lovrAssert(x <= state.limits.compute[0], "Compute x size %d exceeds the maximum of %d", state.limits.compute[0]); + lovrAssert(y <= state.limits.compute[1], "Compute y size %d exceeds the maximum of %d", state.limits.compute[1]); + lovrAssert(z <= state.limits.compute[2], "Compute z size %d exceeds the maximum of %d", state.limits.compute[2]); lovrGraphicsFlush(); lovrGpuBindShader(shader); glDispatchCompute(x, y, z);