Add GrCap for initializing textures

Change-Id: Ifdf50c6686a3369a00cc15fa868a4807f0898fd6
Bug: skia:8378
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/204266
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
This commit is contained in:
Kevin Lubick 2019-03-28 09:47:15 -04:00 committed by Skia Commit-Bot
parent f1633afac3
commit 61a5f0aef8
3 changed files with 20 additions and 0 deletions

View File

@ -33,6 +33,7 @@ GrCaps::GrCaps(const GrContextOptions& options) {
fPreferClientSideDynamicBuffers = false;
fPreferFullscreenClears = false;
fMustClearUploadedBufferData = false;
fShouldInitializeTextures = false;
fSupportsAHardwareBufferImages = false;
fFenceSyncSupport = false;
fCrossContextTextureSupport = false;
@ -198,6 +199,7 @@ void GrCaps::dumpJSON(SkJSONWriter* writer) const {
writer->appendBool("Prefer client-side dynamic buffers", fPreferClientSideDynamicBuffers);
writer->appendBool("Prefer fullscreen clears", fPreferFullscreenClears);
writer->appendBool("Must clear buffer memory", fMustClearUploadedBufferData);
writer->appendBool("Should initialize textures", fShouldInitializeTextures);
writer->appendBool("Supports importing AHardwareBuffers", fSupportsAHardwareBufferImages);
writer->appendBool("Fence sync support", fFenceSyncSupport);
writer->appendBool("Cross context texture support", fCrossContextTextureSupport);

View File

@ -233,6 +233,13 @@ public:
is not initialized (even if not read by draw calls). */
bool mustClearUploadedBufferData() const { return fMustClearUploadedBufferData; }
/** For some environments, there is a performance or safety concern to not
initializing textures. For example, with WebGL and Firefox, there is a large
performance hit to not doing it.
*/
bool shouldInitializeTextures() const { return fShouldInitializeTextures; }
/** Returns true if the given backend supports importing AHardwareBuffers via the
* GrAHardwarebufferImageGenerator. This will only ever be supported on Android devices with API
* level >= 26.
@ -345,6 +352,7 @@ protected:
bool fPreferClientSideDynamicBuffers : 1;
bool fPreferFullscreenClears : 1;
bool fMustClearUploadedBufferData : 1;
bool fShouldInitializeTextures : 1;
bool fSupportsAHardwareBufferImages : 1;
bool fHalfFloatVertexAttributeSupport : 1;
bool fClampToBorderSupport : 1;

View File

@ -536,6 +536,16 @@ void GrGLCaps::init(const GrContextOptions& contextOptions,
fMustClearUploadedBufferData = true;
}
// In a WASM build on Firefox, we see warnings like
// WebGL warning: texSubImage2D: This operation requires zeroing texture data. This is slow.
// WebGL warning: texSubImage2D: Texture has not been initialized prior to a partial upload,
// forcing the browser to clear it. This may be slow.
// Setting the initial clear seems to make those warnings go away and offers a substantial
// boost in performance in Firefox. Chrome sees a more modest increase.
if (kIsWebGL) {
fShouldInitializeTextures = true;
}
if (GR_IS_GR_GL(standard)) {
// ARB allows mixed size FBO attachments, EXT does not.
if (version >= GR_GL_VER(3, 0) ||