MayaFlux 0.3.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ create_sampler()

vk::Sampler MayaFlux::Core::BackendResourceManager::create_sampler ( vk::Filter  filter = vk::Filter::eLinear,
vk::SamplerAddressMode  address_mode = vk::SamplerAddressMode::eRepeat,
float  max_anisotropy = 0.0F 
)

Create sampler.

Parameters
filterMag/min filter
address_modeTexture address mode (wrap, clamp, etc.)
anisotropyMax anisotropy (0 = disabled)
Returns
Sampler handle

Definition at line 786 of file BackendResoureManager.cpp.

790{
791 size_t hash = 0;
792 auto hash_combine = [](size_t& seed, size_t value) {
793 seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2);
794 };
795
796 hash_combine(hash, static_cast<size_t>(filter));
797 hash_combine(hash, static_cast<size_t>(address_mode));
798 hash_combine(hash, std::hash<float> {}(max_anisotropy));
799
800 auto it = m_sampler_cache.find(hash);
801 if (it != m_sampler_cache.end()) {
803 "Reusing cached sampler (hash: 0x{:X})", hash);
804 return it->second;
805 }
806
807 vk::SamplerCreateInfo sampler_info;
808 sampler_info.magFilter = filter;
809 sampler_info.minFilter = filter;
810 sampler_info.mipmapMode = vk::SamplerMipmapMode::eLinear;
811 sampler_info.addressModeU = address_mode;
812 sampler_info.addressModeV = address_mode;
813 sampler_info.addressModeW = address_mode;
814 sampler_info.mipLodBias = 0.0F;
815 sampler_info.anisotropyEnable = max_anisotropy > 0.0F;
816 sampler_info.maxAnisotropy = max_anisotropy;
817 sampler_info.compareEnable = VK_FALSE;
818 sampler_info.compareOp = vk::CompareOp::eAlways;
819 sampler_info.minLod = 0.0F;
820 sampler_info.maxLod = VK_LOD_CLAMP_NONE;
821 sampler_info.borderColor = vk::BorderColor::eFloatOpaqueBlack;
822 sampler_info.unnormalizedCoordinates = VK_FALSE;
823
824 vk::Sampler sampler;
825 try {
826 sampler = m_context.get_device().createSampler(sampler_info);
827 } catch (const vk::SystemError& e) {
829 "Failed to create sampler: {}", e.what());
830 return nullptr;
831 }
832
833 m_sampler_cache[hash] = sampler;
834
836 "Created sampler (filter: {}, address: {}, anisotropy: {}, hash: 0x{:X})",
837 vk::to_string(filter), vk::to_string(address_mode), max_anisotropy, hash);
838
839 return sampler;
840}
#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.
Definition VKContext.hpp:49
@ GraphicsBackend
Graphics/visual rendering backend (Vulkan, OpenGL)
@ Core
Core engine, backend, subsystems.

References MayaFlux::Journal::Core, MayaFlux::Core::VKContext::get_device(), MayaFlux::Journal::GraphicsBackend, m_context, m_sampler_cache, MF_DEBUG, MF_ERROR, and MF_INFO.

Referenced by MayaFlux::Portal::Graphics::TextureLoom::create_sampler().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: