CanvasKit: Switch to WebGL 2.0

CQ_INCLUDE_TRYBOTS=skia.primary:Test-Debian9-EMCC-GCE-GPU-AVX2-wasm-Release-All-CanvasKit,Test-Debian9-EMCC-GCE-CPU-AVX2-wasm-Release-All-CanvasKit

Bug: skia:9052
Change-Id: I444031276aea90d82f289b16ba6cd36de5192abd
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/248927
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
Hal Canary 2019-10-16 10:17:05 -04:00 committed by Skia Commit-Bot
parent 11e6aa823d
commit e054d3cf3d
8 changed files with 36 additions and 10 deletions

View File

@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- and `no_embedded_font` option now allows creating a `SkFontMgr.FromData` instead of
always having an empty one.
- Updated to emscripten 1.38.47
- Switch to WebGL 2.0, but fall back to 1.0 when unavailable - bug.skia.org/9052
### Fixed
- Null terminator bug in draw text - skbug.com/9314

View File

@ -48,12 +48,13 @@ mkdir -p $BUILD_DIR
GN_GPU="skia_enable_gpu=true skia_gl_standard = \"webgl\""
GN_GPU_FLAGS="\"-DSK_DISABLE_LEGACY_SHADERCONTEXT\","
WASM_GPU="-lEGL -lGLESv2 -DSK_SUPPORT_GPU=1 \
-DSK_DISABLE_LEGACY_SHADERCONTEXT --pre-js $BASE_DIR/cpu.js --pre-js $BASE_DIR/gpu.js"
-DSK_DISABLE_LEGACY_SHADERCONTEXT --pre-js $BASE_DIR/cpu.js --pre-js $BASE_DIR/gpu.js\
-s USE_WEBGL2=1"
if [[ $@ == *cpu* ]]; then
echo "Using the CPU backend instead of the GPU backend"
GN_GPU="skia_enable_gpu=false"
GN_GPU_FLAGS=""
WASM_GPU="-DSK_SUPPORT_GPU=0 --pre-js $BASE_DIR/cpu.js"
WASM_GPU="-DSK_SUPPORT_GPU=0 --pre-js $BASE_DIR/cpu.js -s USE_WEBGL2=0"
fi
SKOTTIE_JS="--pre-js $BASE_DIR/skottie.js"
@ -258,6 +259,5 @@ ${EMCXX} \
-s USE_FREETYPE=1 \
-s USE_LIBPNG=1 \
-s WARN_UNALIGNED=1 \
-s USE_WEBGL2=0 \
-s WASM=1 \
-o $BUILD_DIR/canvaskit.js

View File

@ -21,7 +21,7 @@
preserveDrawingBuffer: get(attrs, 'preserveDrawingBuffer', 0),
preferLowPowerToHighPerformance: get(attrs, 'preferLowPowerToHighPerformance', 0),
failIfMajorPerformanceCaveat: get(attrs, 'failIfMajorPerformanceCaveat', 0),
majorVersion: get(attrs, 'majorVersion', 1),
majorVersion: get(attrs, 'majorVersion', 2),
minorVersion: get(attrs, 'minorVersion', 0),
enableExtensionsByDefault: get(attrs, 'enableExtensionsByDefault', 1),
explicitSwapControl: get(attrs, 'explicitSwapControl', 0),
@ -38,7 +38,14 @@
}
// GL is an enscripten provided helper
// See https://github.com/emscripten-core/emscripten/blob/incoming/src/library_webgl.js
return GL.createContext(canvas, contextAttributes);
var ctx = GL.createContext(canvas, contextAttributes);
if (!ctx && contextAttributes.majorVersion > 1) {
contextAttributes.majorVersion = 1; // fall back to WebGL 1.0
contextAttributes.minorVersion = 0;
ctx = GL.createContext(canvas, contextAttributes);
}
return ctx;
}
CanvasKit.GetWebGLContext = function(canvas, attrs) {

View File

@ -180,6 +180,10 @@ sk_sp<const GrGLInterface> GrGLMakeAssembledWebGLInterface(void *ctx, GrGLGetPro
GET_PROC(TexStorage2D);
}
if (glVer >= GR_GL_VER(2,0)) {
GET_PROC(VertexAttribDivisor);
}
if (glVer >= GR_GL_VER(2,0)) {
GET_PROC(VertexAttribIPointer);
}

View File

@ -986,9 +986,13 @@ void GrGLCaps::initFSAASupport(const GrContextOptions& contextOptions, const GrG
fMSFBOType = kES_Apple_MSFBOType;
}
} else if (GR_IS_GR_WEBGL(ctxInfo.standard())) {
// No support in WebGL
// No support in WebGL 1, but there is for 2.0
if (ctxInfo.version() >= GR_GL_VER(2,0)) {
fMSFBOType = kStandard_MSFBOType;
} else {
fMSFBOType = kNone_MSFBOType;
}
}
// We disable MSAA for all Intel GPUs. Before Gen9, performance was very bad. Even with Gen9,
// we've seen driver crashes in the wild. We don't have data on Gen11 yet.

View File

@ -46,7 +46,7 @@ bool GrGLGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation
*generation = k110_GrGLSLGeneration;
}
return true;
} else if (GR_IS_GR_GL_ES(gl->fStandard) || GR_IS_GR_WEBGL(gl->fStandard)) {
} else if (GR_IS_GR_GL_ES(gl->fStandard)) {
SkASSERT(ver >= GR_GL_VER(1,00));
if (ver >= GR_GLSL_VER(3,20)) {
*generation = k320es_GrGLSLGeneration;
@ -58,6 +58,14 @@ bool GrGLGetGLSLGeneration(const GrGLInterface* gl, GrGLSLGeneration* generation
*generation = k110_GrGLSLGeneration;
}
return true;
} else if (GR_IS_GR_WEBGL(gl->fStandard)) {
SkASSERT(ver >= GR_GL_VER(1,0));
if (ver >= GR_GLSL_VER(2,0)) {
*generation = k330_GrGLSLGeneration; // ES 3.0
} else {
*generation = k110_GrGLSLGeneration;
}
return true;
}
SK_ABORT("Unknown GL Standard");
}

View File

@ -346,7 +346,9 @@ bool GrGLInterface::validate() const {
fExtensions.has("GL_ARB_instanced_arrays"))) ||
(GR_IS_GR_GL_ES(fStandard) && (
(glVer >= GR_GL_VER(3,0)) ||
fExtensions.has("GL_EXT_instanced_arrays")))) {
fExtensions.has("GL_EXT_instanced_arrays"))) ||
(GR_IS_GR_WEBGL(fStandard) && (
(glVer >= GR_GL_VER(2,0))))) {
if (!fFunctions.fVertexAttribDivisor) {
RETURN_FALSE_INTERFACE;
}

View File

@ -279,7 +279,7 @@
{/* else if */ "ext": "GL_ARB_instanced_arrays"}],
"GLES": [{"min_version": [3, 0], "ext": "<core>"},
{/* else if */ "ext": "GL_EXT_instanced_arrays"}],
"WebGL": null,
"WebGL": [{"min_version": [2, 0], "ext": "<core>"}],
"functions": [
"VertexAttribDivisor",