Browse Source

fix: broken shader cache due to compilation error (#40473)

* fix: broken shader cache due to compilation error

Backports:
- https://chromium-review.googlesource.com/c/chromium/src/+/4988290
- https://chromium-review.googlesource.com/c/chromium/src/+/4766018

Co-authored-by: deepak1556 <[email protected]>

* chore: update patches

---------

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: deepak1556 <[email protected]>
trop[bot] 1 year ago
parent
commit
bb6a7d443b

+ 2 - 0
patches/chromium/.patches

@@ -147,3 +147,5 @@ cherry-pick-d756d71a652c.patch
 parameterize_axtreeserializer_by_vector_type.patch
 avoid_allocating_recordid_objects_in_elementtiming_and_lcp.patch
 cherry-pick-80106e31c7ea.patch
+gpu_use_load_program_shader_shm_count_on_drdc_thread.patch
+crash_gpu_process_and_clear_shader_cache_when_skia_reports.patch

+ 54 - 0
patches/chromium/crash_gpu_process_and_clear_shader_cache_when_skia_reports.patch

@@ -0,0 +1,54 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: deepak1556 <[email protected]>
+Date: Sun, 5 Nov 2023 21:05:04 +0900
+Subject: Crash GPU process and clear shader cache when skia reports
+ compileError.
+
+Refs https://chromium-review.googlesource.com/c/chromium/src/+/4988290
+
+diff --git a/gpu/command_buffer/service/shared_context_state.cc b/gpu/command_buffer/service/shared_context_state.cc
+index 9960748b644a4f89919c6c19889d8cb3d875d3b8..71f9495306ad817a0d530f701d6ff35fc9966960 100644
+--- a/gpu/command_buffer/service/shared_context_state.cc
++++ b/gpu/command_buffer/service/shared_context_state.cc
+@@ -4,6 +4,7 @@
+ 
+ #include "gpu/command_buffer/service/shared_context_state.h"
+ 
++#include "base/immediate_crash.h"
+ #include "base/observer_list.h"
+ #include "base/strings/stringprintf.h"
+ #include "base/system/sys_info.h"
+@@ -82,6 +83,12 @@ void SharedContextState::compileError(const char* shader, const char* errors) {
+                << "------------------------\n"
+                << shader << "\nErrors:\n"
+                << errors;
++    // Increase shader cache shm count and crash the GPU process so that the
++    // browser process would clear the cache.
++    GpuProcessActivityFlags::ScopedSetFlag set_flag(
++        activity_flags_.get(), ActivityFlagsBase::FLAG_LOADING_PROGRAM_BINARY);
++
++    base::ImmediateCrash();
+   }
+ }
+ 
+@@ -271,6 +278,7 @@ bool SharedContextState::InitializeGanesh(
+     gl::ProgressReporter* progress_reporter) {
+   progress_reporter_ = progress_reporter;
+   gr_shader_cache_ = cache;
++  activity_flags_ = activity_flags;
+ 
+   size_t max_resource_cache_bytes;
+   size_t glyph_cache_max_texture_bytes;
+diff --git a/gpu/command_buffer/service/shared_context_state.h b/gpu/command_buffer/service/shared_context_state.h
+index c07796e90453c8ecbcfc4a8b3946deb1c46a3300..b795d0cf8e16218c01acdbe921bad067e0b63677 100644
+--- a/gpu/command_buffer/service/shared_context_state.h
++++ b/gpu/command_buffer/service/shared_context_state.h
+@@ -379,6 +379,8 @@ class GPU_GLES2_EXPORT SharedContextState
+   uint64_t skia_gr_cache_size_ = 0;
+   std::vector<uint8_t> scratch_deserialization_buffer_;
+   raw_ptr<gpu::raster::GrShaderCache> gr_shader_cache_ = nullptr;
++  raw_ptr<GpuProcessActivityFlags, DanglingUntriaged> activity_flags_ =
++      nullptr;
+ 
+   // |need_context_state_reset| is set whenever Skia may have altered the
+   // driver's GL state.

+ 21 - 0
patches/chromium/gpu_use_load_program_shader_shm_count_on_drdc_thread.patch

@@ -0,0 +1,21 @@
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
+From: deepak1556 <[email protected]>
+Date: Sun, 5 Nov 2023 18:22:15 +0900
+Subject: gpu: Use load_program_shader_shm_count on DrDC thread
+
+Refs https://chromium-review.googlesource.com/c/chromium/src/+/4766018
+
+diff --git a/components/viz/service/display_embedder/compositor_gpu_thread.cc b/components/viz/service/display_embedder/compositor_gpu_thread.cc
+index a9ca58db18823c09457eb89eb9776ce51ec668b2..d8384bddd7ebd45c5fa87ddb7af10c967db9ac25 100644
+--- a/components/viz/service/display_embedder/compositor_gpu_thread.cc
++++ b/components/viz/service/display_embedder/compositor_gpu_thread.cc
+@@ -207,7 +207,8 @@ CompositorGpuThread::GetSharedContextState() {
+   // Initialize Skia.
+   if (!shared_context_state->InitializeSkia(
+           gpu_preferences, workarounds, gpu_channel_manager_->gr_shader_cache(),
+-          /*activity_flags=*/nullptr, /*progress_reporter=*/nullptr)) {
++          gpu_channel_manager_->activity_flags(),
++          /*progress_reporter=*/nullptr)) {
+     LOG(ERROR) << "Failed to Initialize Skia for DrDC SharedContextState";
+   }
+   shared_context_state_ = std::move(shared_context_state);