mirror of
https://github.com/KytyPS5/KytyPS5.git
synced 2026-08-03 11:23:49 +00:00
52 lines
1.4 KiB
C++
52 lines
1.4 KiB
C++
#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 <array>
|
|
#include <cstddef>
|
|
#include <unordered_map>
|
|
|
|
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);
|
|
|
|
private:
|
|
using SamplerKey = std::array<uint32_t, 4>;
|
|
|
|
struct SamplerKeyHash {
|
|
std::size_t operator()(const SamplerKey& key) const {
|
|
std::size_t hash = 0;
|
|
for (auto value: key) {
|
|
hash ^= static_cast<std::size_t>(value) +
|
|
static_cast<std::size_t>(0x9e3779b97f4a7c15ull) + (hash << 6u) +
|
|
(hash >> 2u);
|
|
}
|
|
return hash;
|
|
}
|
|
};
|
|
|
|
GraphicContext& m_graphics;
|
|
Common::Mutex m_mutex;
|
|
std::unordered_map<SamplerKey, vk::Sampler, SamplerKeyHash> m_samplers;
|
|
};
|
|
|
|
} // namespace Libs::Graphics
|
|
|
|
#endif // EMULATOR_SRC_GRAPHICS_HOST_GPU_RENDERER_SAMPLERCACHE_H_
|