Create sampler.
700{
701 size_t hash = 0;
702 auto hash_combine = [](size_t& seed, size_t value) {
703 seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2);
704 };
705
706 hash_combine(hash, static_cast<size_t>(filter));
707 hash_combine(hash, static_cast<size_t>(address_mode));
708 hash_combine(hash, std::hash<float> {}(max_anisotropy));
709
713 "Reusing cached sampler (hash: 0x{:X})", hash);
714 return it->second;
715 }
716
717 vk::SamplerCreateInfo sampler_info;
718 sampler_info.magFilter = filter;
719 sampler_info.minFilter = filter;
720 sampler_info.mipmapMode = vk::SamplerMipmapMode::eLinear;
721 sampler_info.addressModeU = address_mode;
722 sampler_info.addressModeV = address_mode;
723 sampler_info.addressModeW = address_mode;
724 sampler_info.mipLodBias = 0.0F;
725 sampler_info.anisotropyEnable = max_anisotropy > 0.0F;
726 sampler_info.maxAnisotropy = max_anisotropy;
727 sampler_info.compareEnable = VK_FALSE;
728 sampler_info.compareOp = vk::CompareOp::eAlways;
729 sampler_info.minLod = 0.0F;
730 sampler_info.maxLod = VK_LOD_CLAMP_NONE;
731 sampler_info.borderColor = vk::BorderColor::eFloatOpaqueBlack;
732 sampler_info.unnormalizedCoordinates = VK_FALSE;
733
734 vk::Sampler sampler;
735 try {
737 } catch (const vk::SystemError& e) {
739 "Failed to create sampler: {}", e.what());
740 return nullptr;
741 }
742
744
746 "Created sampler (filter: {}, address: {}, anisotropy: {}, hash: 0x{:X})",
747 vk::to_string(filter), vk::to_string(address_mode), max_anisotropy, hash);
748
749 return sampler;
750}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
std::unordered_map< size_t, vk::Sampler > m_sampler_cache
vk::Device get_device() const
Get logical device.
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.