mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-20 04:29:13 +12:00
Add vulkan sampler cache
This commit is contained in:
parent
14b1d7d8a8
commit
7a86595a1b
3 changed files with 61 additions and 0 deletions
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
|
Loading…
Add table
Add a link
Reference in a new issue