| 1 |
/* |
| 2 |
* Copyright 2025 Google LLC |
| 3 |
* |
| 4 |
* Use of this source code is governed by a BSD-style license that can be |
| 5 |
* found in the LICENSE file. |
| 6 |
*/ |
| 7 |
|
| 8 |
#ifndef skgpu_graphite_PipelineManager_DEFINED |
| 9 |
#define skgpu_graphite_PipelineManager_DEFINED |
| 10 |
|
| 11 |
#include "include/core/SkRefCnt.h" |
| 12 |
#include "src/base/SkEnumBitMask.h" |
| 13 |
#include "src/base/SkSpinlock.h" |
| 14 |
#include "src/core/SkTHash.h" |
| 15 |
|
| 16 |
namespace skgpu { |
| 17 |
class UniqueKey; |
| 18 |
} |
| 19 |
|
| 20 |
namespace skgpu::graphite { |
| 21 |
|
| 22 |
class GraphicsPipeline; |
| 23 |
class GraphicsPipelineDesc; |
| 24 |
class GraphicsPipelineHandle; |
| 25 |
enum class PipelineCreationFlags : uint8_t; |
| 26 |
class PipelineCreationTask; |
| 27 |
struct RenderPassDesc; |
| 28 |
class RuntimeEffectDictionary; |
| 29 |
class SharedContext; |
| 30 |
|
| 31 |
class PipelineManager { |
| 32 |
public: |
| 33 |
PipelineManager(); |
| 34 |
~PipelineManager(); |
| 35 |
|
| 36 |
GraphicsPipelineHandle createHandle( |
| 37 |
SharedContext*, |
| 38 |
const GraphicsPipelineDesc&, |
| 39 |
const RenderPassDesc&, |
| 40 |
SkEnumBitMask<PipelineCreationFlags>); |
| 41 |
|
| 42 |
void startPipelineCreationTask(SharedContext*, |
| 43 |
sk_sp<const RuntimeEffectDictionary>, |
| 44 |
const GraphicsPipelineHandle&); |
| 45 |
|
| 46 |
sk_sp<GraphicsPipeline> resolveHandle(const GraphicsPipelineHandle&); |
| 47 |
|
| 48 |
#if defined(GPU_TEST_UTILS) |
| 49 |
struct Stats { |
| 50 |
// The number of times we find a pre-existing task for a Pipeline |
| 51 |
int fNumPreemptivelyFoundTasks = 0; |
| 52 |
int fNumTasksCreated = 0; |
| 53 |
int fNumTaskCreationRaces = 0; |
| 54 |
}; |
| 55 |
|
| 56 |
Stats getStats() const SK_EXCLUDES(fSpinLock); |
| 57 |
#endif |
| 58 |
|
| 59 |
private: |
| 60 |
mutable SkSpinlock fSpinLock; |
| 61 |
|
| 62 |
sk_sp<PipelineCreationTask> findTask(const UniqueKey& pipelineKey) SK_EXCLUDES(fSpinLock); |
| 63 |
|
| 64 |
sk_sp<PipelineCreationTask> findOrCreateTask( |
| 65 |
const UniqueKey& pipelineKey, |
| 66 |
const GraphicsPipelineDesc&, |
| 67 |
const RenderPassDesc&, |
| 68 |
SkEnumBitMask<PipelineCreationFlags>) SK_EXCLUDES(fSpinLock); |
| 69 |
|
| 70 |
void removeTask(PipelineCreationTask*) SK_EXCLUDES(fSpinLock); |
| 71 |
|
| 72 |
struct Traits { |
| 73 |
static const UniqueKey& GetKey(const sk_sp<PipelineCreationTask>&); |
| 74 |
static uint32_t Hash(const UniqueKey& pipelineKey); |
| 75 |
}; |
| 76 |
using TaskMap = skia_private::THashTable<sk_sp<PipelineCreationTask>, UniqueKey, Traits>; |
| 77 |
|
| 78 |
TaskMap fActiveTasks SK_GUARDED_BY(fSpinLock); |
| 79 |
|
| 80 |
#if defined(GPU_TEST_UTILS) |
| 81 |
Stats fStats SK_GUARDED_BY(fSpinLock); |
| 82 |
#endif |
| 83 |
}; |
| 84 |
|
| 85 |
} // namespace skgpu::graphite |
| 86 |
|
| 87 |
#endif // skgpu_graphite_PipelineManager_DEFINED |