chromium/gpu/command_buffer/service/dawn_caching_interface.h

// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef GPU_COMMAND_BUFFER_SERVICE_DAWN_CACHING_INTERFACE_H_
#define GPU_COMMAND_BUFFER_SERVICE_DAWN_CACHING_INTERFACE_H_

#include <dawn/platform/DawnPlatform.h>

#include <memory>
#include <string>

#include "base/containers/flat_map.h"
#include "base/containers/flat_set.h"
#include "base/containers/linked_list.h"
#include "base/functional/callback.h"
#include "base/memory/ref_counted.h"
#include "base/synchronization/lock.h"
#include "base/thread_annotations.h"
#include "gpu/gpu_gles2_export.h"
#include "gpu/ipc/common/gpu_disk_cache_type.h"

namespace gpu {
namespace webgpu {

class DawnCachingInterfaceFactory;

namespace detail {

// In memory caching backend that is just a thread-safe wrapper around a map
// with a simple LRU eviction algorithm implemented on top. This is the actual
// backing cache for instances of DawnCachingInterface. The eviction queue is
// set up so that the entries in the front are the first entries to be deleted.
class GPU_GLES2_EXPORT DawnCachingBackend
    : public base::RefCounted<DawnCachingBackend> {};

}  // namespace detail

// Provides a wrapper class around an in-memory DawnCachingBackend. This class
// was originally designed to handle both disk and in-memory cache backends, but
// because it lives on the GPU process and does not have permissions (due to
// sandbox restrictions) to disk, the disk functionality was removed. Should it
// become necessary to provide interfaces over a disk level disk_cache::Backend,
// please refer to the file history for reference. Note that the big difference
// between in-memory and disk backends are the sync vs async nature of the two
// respectively. Because we are only handling in-memory backends now, the logic
// can be simplified to handle everything synchronously.
class GPU_GLES2_EXPORT DawnCachingInterface
    : public dawn::platform::CachingInterface {};

// Factory class for producing and managing DawnCachingInterfaces.
// Creating/using caching interfaces through the factory guarantees that we will
// not run into issues where backends are being initialized with the same
// parameters leading to blockage.
class GPU_GLES2_EXPORT DawnCachingInterfaceFactory {};

}  // namespace webgpu
}  // namespace gpu

#endif  // GPU_COMMAND_BUFFER_SERVICE_DAWN_CACHING_INTERFACE_H_