Add vulkan sampler cache
This commit is contained in:
31
src/core/renderer_vk/vk_sampler_cache.cpp
Normal file
31
src/core/renderer_vk/vk_sampler_cache.cpp
Normal file
@@ -0,0 +1,31 @@
|
||||
#include "renderer_vk/vk_sampler_cache.hpp"
|
||||
|
||||
#include <vulkan/vulkan_hash.hpp>
|
||||
|
||||
#include "helpers.hpp"
|
||||
|
||||
namespace Vulkan {
|
||||
|
||||
SamplerCache::SamplerCache(vk::Device device) : device(device) {}
|
||||
|
||||
const vk::Sampler& SamplerCache::getSampler(const vk::SamplerCreateInfo& samplerInfo) {
|
||||
const std::size_t samplerHash = std::hash<vk::SamplerCreateInfo>()(samplerInfo);
|
||||
|
||||
// Cache hit
|
||||
if (samplerMap.contains(samplerHash)) {
|
||||
return samplerMap.at(samplerHash).get();
|
||||
}
|
||||
|
||||
if (auto createResult = device.createSamplerUnique(samplerInfo); createResult.result == vk::Result::eSuccess) {
|
||||
return (samplerMap[samplerHash] = std::move(createResult.value)).get();
|
||||
} else {
|
||||
Helpers::panic("Error creating sampler: %s\n", vk::to_string(createResult.result).c_str());
|
||||
}
|
||||
}
|
||||
|
||||
std::optional<SamplerCache> SamplerCache::create(vk::Device device) {
|
||||
SamplerCache newSamplerCache(device);
|
||||
|
||||
return {std::move(newSamplerCache)};
|
||||
}
|
||||
} // namespace Vulkan
|
||||
Reference in New Issue
Block a user