Create sampler.
888{
889 size_t hash = 0;
890 auto hash_combine = [](size_t& seed, size_t value) {
891 seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2);
892 };
893
894 hash_combine(hash, static_cast<size_t>(filter));
895 hash_combine(hash, static_cast<size_t>(address_mode));
896 hash_combine(hash, std::hash<float> {}(max_anisotropy));
897
901 "Reusing cached sampler (hash: 0x{:X})", hash);
902 return it->second;
903 }
904
905 vk::SamplerCreateInfo sampler_info;
906 sampler_info.magFilter = filter;
907 sampler_info.minFilter = filter;
908 sampler_info.mipmapMode = vk::SamplerMipmapMode::eLinear;
909 sampler_info.addressModeU = address_mode;
910 sampler_info.addressModeV = address_mode;
911 sampler_info.addressModeW = address_mode;
912 sampler_info.mipLodBias = 0.0F;
913 sampler_info.anisotropyEnable = max_anisotropy > 0.0F;
914 sampler_info.maxAnisotropy = max_anisotropy;
915 sampler_info.compareEnable = VK_FALSE;
916 sampler_info.compareOp = vk::CompareOp::eAlways;
917 sampler_info.minLod = 0.0F;
918 sampler_info.maxLod = VK_LOD_CLAMP_NONE;
919 sampler_info.borderColor = vk::BorderColor::eFloatOpaqueBlack;
920 sampler_info.unnormalizedCoordinates = VK_FALSE;
921
922 vk::Sampler sampler;
923 try {
925 } catch (const vk::SystemError& e) {
927 "Failed to create sampler: {}", e.what());
928 return nullptr;
929 }
930
932
934 "Created sampler (filter: {}, address: {}, anisotropy: {}, hash: 0x{:X})",
935 vk::to_string(filter), vk::to_string(address_mode), max_anisotropy, hash);
936
937 return sampler;
938}
#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.