Skip to content

Commit

Permalink
graphite: Add kGraphiteDawnGpuDiskCacheHandle for store shader cache
Browse files Browse the repository at this point in the history
This new kGraphiteDawnGpuDiskCacheHandle is added for storing
compiled shaders from dawn used by grapghite for SkiaRenderer and
RasterDecoder. This CL only adds the cache handle and setup the
storage path, but it doesn't hook up to the graphite dawn instance
right now. It will be done in follow-up CLs.

Bug: 1454867
Change-Id: I626af5745078de8c22d216930e60d62ffd592320
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4618907
Commit-Queue: Peng Huang <penghuang@chromium.org>
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: Nasko Oskov <nasko@chromium.org>
Reviewed-by: Vasiliy Telezhnikov <vasilyt@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1159297}
  • Loading branch information
phuang authored and Chromium LUCI CQ committed Jun 17, 2023
1 parent e66a851 commit 8860508
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 2 deletions.
6 changes: 6 additions & 0 deletions chrome/browser/chrome_content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4343,6 +4343,12 @@ base::FilePath ChromeContentBrowserClient::GetGrShaderDiskCacheDirectory() {
return user_data_dir.Append(FILE_PATH_LITERAL("GrShaderCache"));
}

base::FilePath ChromeContentBrowserClient::GetGraphiteDawnDiskCacheDirectory() {
base::FilePath user_data_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
return user_data_dir.Append(FILE_PATH_LITERAL("GraphiteDawnCache"));
}

base::FilePath ChromeContentBrowserClient::GetNetLogDefaultDirectory() {
base::FilePath user_data_dir;
base::PathService::Get(chrome::DIR_USER_DATA, &user_data_dir);
Expand Down
1 change: 1 addition & 0 deletions chrome/browser/chrome_content_browser_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ class ChromeContentBrowserClient : public content::ContentBrowserClient {
std::string GetDefaultDownloadName() override;
base::FilePath GetShaderDiskCacheDirectory() override;
base::FilePath GetGrShaderDiskCacheDirectory() override;
base::FilePath GetGraphiteDawnDiskCacheDirectory() override;
base::FilePath GetNetLogDefaultDirectory() override;
base::FilePath GetFirstPartySetsDirectory() override;
void DidCreatePpapiPlugin(content::BrowserPpapiHost* browser_host) override;
Expand Down
2 changes: 2 additions & 0 deletions components/viz/host/gpu_host_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,8 @@ void GpuHostImpl::DidInitialize(
gpu::kDisplayCompositorGpuDiskCacheHandle);
SetChannelDiskCacheHandle(gpu::kGrShaderCacheClientId,
gpu::kGrShaderGpuDiskCacheHandle);
SetChannelDiskCacheHandle(gpu::kGraphiteDawnClientId,
gpu::kGraphiteDawnGpuDiskCacheHandle);
}
}

Expand Down
6 changes: 6 additions & 0 deletions content/browser/gpu/gpu_disk_cache_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ void CreateFactoryInstance() {
handle_to_path_map.emplace(gpu::kGrShaderGpuDiskCacheHandle,
gr_cache_dir);
}
base::FilePath graphite_dawn_dir =
GetContentClient()->browser()->GetGraphiteDawnDiskCacheDirectory();
if (!graphite_dawn_dir.empty()) {
handle_to_path_map.emplace(gpu::kGraphiteDawnGpuDiskCacheHandle,
graphite_dawn_dir);
}
}

factory_instance = new gpu::GpuDiskCacheFactory(handle_to_path_map);
Expand Down
4 changes: 4 additions & 0 deletions content/public/browser/content_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,10 @@ base::FilePath ContentBrowserClient::GetGrShaderDiskCacheDirectory() {
return base::FilePath();
}

base::FilePath ContentBrowserClient::GetGraphiteDawnDiskCacheDirectory() {
return base::FilePath();
}

base::FilePath ContentBrowserClient::GetNetLogDefaultDirectory() {
return base::FilePath();
}
Expand Down
4 changes: 4 additions & 0 deletions content/public/browser/content_browser_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -1129,6 +1129,10 @@ class CONTENT_EXPORT ContentBrowserClient {
// skia.
virtual base::FilePath GetGrShaderDiskCacheDirectory();

// Returns the path to the shader disk cache root for shaders generated by
// graphite dawn.
virtual base::FilePath GetGraphiteDawnDiskCacheDirectory();

// Returns the path to the net log default directory.
virtual base::FilePath GetNetLogDefaultDirectory();

Expand Down
6 changes: 6 additions & 0 deletions gpu/ipc/common/gpu_client_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ constexpr int32_t kDisplayCompositorClientId = -1;
// namespace for these shaders.
constexpr int32_t kGrShaderCacheClientId = -2;

// The ID used for storing dawn shaders created by graphite dawn in the GPU
// process. Note that this ID doesn't correspond to a real Gpu client/channel,
// but is required so we can use the same disk caching system for shaders and
// use a unique namespace for these shaders.
constexpr int32_t kGraphiteDawnClientId = -3;

inline bool IsReservedClientId(int32_t client_id) {
return client_id < 0;
}
Expand Down
4 changes: 3 additions & 1 deletion gpu/ipc/common/gpu_disk_cache_type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ bool IsReservedGpuDiskCacheHandle(const GpuDiskCacheHandle& handle) {
return gl_shader_handle == kDisplayCompositorGpuDiskCacheHandle ||
gl_shader_handle == kGrShaderGpuDiskCacheHandle;
}
return false;
const auto& dawn_webgpu_handle =
absl::get<gpu::GpuDiskCacheDawnWebGPUHandle>(handle);
return dawn_webgpu_handle == kGraphiteDawnGpuDiskCacheHandle;
}

} // namespace gpu
9 changes: 8 additions & 1 deletion gpu/ipc/common/gpu_disk_cache_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ using GpuDiskCacheGlShaderHandle =

// Dawn cache handles (for the most part, these should be 1:1 per profile).
using GpuDiskCacheDawnWebGPUHandle =
base::IdType32<class GpuDiskCacheDawnWebGPU>;
base::IdType<class GpuDiskCacheDawnWebGPU,
int32_t,
std::numeric_limits<int32_t>::min(),
1>;

//
// Variant handle that encompasses all possible handles, and utilities.
Expand All @@ -81,6 +84,10 @@ constexpr GpuDiskCacheGlShaderHandle kDisplayCompositorGpuDiskCacheHandle(-1);
// The handle used for storing shaders created by skia in the GPU process.
constexpr GpuDiskCacheGlShaderHandle kGrShaderGpuDiskCacheHandle(-2);

// The handle used by GraphiteDawn running in the GPU process. It is used by
// RasterDecoder and SkiaRenderer.
constexpr GpuDiskCacheDawnWebGPUHandle kGraphiteDawnGpuDiskCacheHandle(-3);

GPU_EXPORT bool IsReservedGpuDiskCacheHandle(const GpuDiskCacheHandle& handle);

} // namespace gpu
Expand Down

0 comments on commit 8860508

Please sign in to comment.