/* * Copyright 2021 Google LLC * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #ifndef skgpu_ProgramCache_DEFINED #define skgpu_ProgramCache_DEFINED #include #include #include #include "experimental/graphite/src/ContextUtils.h" #include "include/core/SkRefCnt.h" namespace skgpu { class ProgramCache { public: ProgramCache(); static constexpr uint32_t kInvalidProgramID = 0; // TODO: this is a bit underspecified. It still needs the rendering technique info. // Additionally, it still needs an entry point to generate the text of the program. class ProgramInfo : public SkRefCnt { public: ProgramInfo(uint32_t uniqueID, Combination c); ~ProgramInfo() override; uint32_t id() const { return fID; } Combination combo() const { return fCombination; } std::string getMSL() const; private: const uint32_t fID; const Combination fCombination; // TODO: store the rendering technique info from Chris here }; // TODO: we need the rendering technique info from Chris for this look up sk_sp findOrCreateProgram(Combination); sk_sp lookup(uint32_t uniqueID); // The number of unique programs in the cache size_t count() const { SkASSERT(fProgramHash.size()+1 == fProgramVector.size()); return fProgramHash.size(); } private: struct Hash { size_t operator()(Combination) const; }; std::unordered_map, Hash> fProgramHash; std::vector> fProgramVector; // The ProgramInfo's unique ID is only unique w/in a Recorder _not_ globally uint32_t fNextUniqueID = 1; }; } // namespace skgpu #endif // skgpu_ProgramCache_DEFINED