#ifndef EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_SAMPLERCACHE_H_ #define EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_SAMPLERCACHE_H_ #include "common/abi.h" #include "common/assert.h" #include "common/common.h" #include "common/threads.h" #include "graphics/host_gpu/vulkanCommon.h" #include "graphics/shader/shaderBindings.h" #include #include #include namespace Libs::Graphics { struct GraphicContext; class SamplerCache { public: explicit SamplerCache(GraphicContext& graphics): m_graphics(graphics) { EXIT_NOT_IMPLEMENTED(!Common::Thread::IsMainThread()); } ~SamplerCache(); KYTY_CLASS_NO_COPY(SamplerCache); vk::Sampler GetSampler(const ShaderSamplerResource& r, bool integer_border); private: using SamplerKey = std::array; struct SamplerKeyHash { std::size_t operator()(const SamplerKey& key) const { std::size_t hash = 0; for (auto value: key) { hash ^= static_cast(value) + static_cast(0x9e3779b97f4a7c15ull) + (hash << 6u) + (hash >> 2u); } return hash; } }; GraphicContext& m_graphics; Common::Mutex m_mutex; std::unordered_map m_samplers; }; } // namespace Libs::Graphics #endif // EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_SAMPLERCACHE_H_