From b15a36452d78004c3279159433bc515bf85feb8b Mon Sep 17 00:00:00 2001 From: Moonchild Date: Wed, 25 Oct 2023 07:53:57 +0200 Subject: [WebGL] Add preffed limit to WebGL vertCount Defaults to 30M, working around driver bugs (looking at you, Mesa) --- dom/canvas/WebGLContext.h | 2 ++ dom/canvas/WebGLContextDraw.cpp | 12 ++++++++++++ gfx/thebes/gfxPrefs.h | 3 ++- modules/libpref/init/all.js | 1 + 4 files changed, 17 insertions(+), 1 deletion(-) diff --git a/dom/canvas/WebGLContext.h b/dom/canvas/WebGLContext.h index 0510e6898a..8984b71366 100644 --- a/dom/canvas/WebGLContext.h +++ b/dom/canvas/WebGLContext.h @@ -8,6 +8,7 @@ #include +#include "gfxPrefs.h" #include "GLContextTypes.h" #include "GLDefs.h" #include "mozilla/Attributes.h" @@ -1397,6 +1398,7 @@ protected: CheckedUint32 mGeneration; WebGLContextOptions mOptions; + const uint32_t mMaxVertIdsPerDraw = gfxPrefs::WebglMaxVertIDsPerDraw(); bool mInvalidated; bool mCapturedFrameInvalidated; diff --git a/dom/canvas/WebGLContextDraw.cpp b/dom/canvas/WebGLContextDraw.cpp index 6c684b2ff8..a01e38c5c6 100644 --- a/dom/canvas/WebGLContextDraw.cpp +++ b/dom/canvas/WebGLContextDraw.cpp @@ -607,6 +607,12 @@ WebGLContext::DrawArraysInstanced(GLenum mode, GLint first, GLsizei vertCount, return; MakeContextCurrent(); + + if (vertCount > mMaxVertIdsPerDraw) { + ErrorOutOfMemory( + "Context's max vertCount is %u, but %u requested. [webgl.max-vert-ids-per-draw]", mMaxVertIdsPerDraw, vertCount); + return; + } bool error = false; ScopedResolveTexturesForDraw scopedResolve(this, funcName, &error); @@ -849,6 +855,12 @@ WebGLContext::DrawElementsInstanced(GLenum mode, GLsizei vertCount, GLenum type, return; MakeContextCurrent(); + + if (vertCount > mMaxVertIdsPerDraw) { + ErrorOutOfMemory( + "Context's max vertCount is %u, but %u requested. [webgl.max-vert-ids-per-draw]", mMaxVertIdsPerDraw, vertCount); + return; + } bool error = false; ScopedResolveTexturesForDraw scopedResolve(this, funcName, &error); diff --git a/gfx/thebes/gfxPrefs.h b/gfx/thebes/gfxPrefs.h index 5dfb742077..3c9fef7d16 100644 --- a/gfx/thebes/gfxPrefs.h +++ b/gfx/thebes/gfxPrefs.h @@ -597,7 +597,8 @@ private: DECL_GFX_PREF(Once, "webgl.force-layers-readback", WebGLForceLayersReadback, bool, false); DECL_GFX_PREF(Live, "webgl.lose-context-on-memory-pressure", WebGLLoseContextOnMemoryPressure, bool, false); DECL_GFX_PREF(Live, "webgl.max-warnings-per-context", WebGLMaxWarningsPerContext, uint32_t, 32); - DECL_GFX_PREF(Live, "webgl.max-size-per-texture-mb", WebGLMaxSizePerTextureMB, uint32_t, 1024); + DECL_GFX_PREF(Live, "webgl.max-size-per-texture-mb", WebGLMaxSizePerTextureMB, uint32_t, 1024); + DECL_GFX_PREF(Live, "webgl.max-vert-ids-per-draw", WebglMaxVertIDsPerDraw, uint32_t, 30*1000*1000); DECL_GFX_PREF(Live, "webgl.min_capability_mode", WebGLMinCapabilityMode, bool, false); DECL_GFX_PREF(Live, "webgl.msaa-force", WebGLForceMSAA, bool, false); DECL_GFX_PREF(Live, "webgl.prefer-16bpp", WebGLPrefer16bpp, bool, false); diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index 0f3fa7c85c..f2a53ab720 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -4263,6 +4263,7 @@ pref("webgl.can-lose-context-in-foreground", true); pref("webgl.restore-context-when-visible", true); pref("webgl.max-warnings-per-context", 32); pref("webgl.max-size-per-texture-mb", 1024); +pref("webgl.max-vert-ids-per-draw", 30000000); pref("webgl.enable-draft-extensions", false); pref("webgl.enable-privileged-extensions", false); pref("webgl.bypass-shader-validation", false); -- cgit v1.2.3