MayaFlux 1.0.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 1229 of file BackendResoureManager.cpp.

1233{
1234 size_t hash = 0;
1235 auto hash_combine = [](size_t& seed, size_t value) {
1236 seed ^= value + 0x9e3779b9 + (seed << 6) + (seed >> 2);
1237 };
1238
1239 hash_combine(hash, static_cast<size_t>(filter));
1240 hash_combine(hash, static_cast<size_t>(address_mode));
1241 hash_combine(hash, std::hash<float> {}(max_anisotropy));
1242
1243 auto it = m_sampler_cache.find(hash);
1244 if (it != m_sampler_cache.end()) {
1246 "Reusing cached sampler (hash: 0x{:X})", hash);
1247 return it->second;
1248 }
1249
1250 vk::SamplerCreateInfo sampler_info;
1251 sampler_info.magFilter = filter;
1252 sampler_info.minFilter = filter;
1253 sampler_info.mipmapMode = vk::SamplerMipmapMode::eLinear;
1254 sampler_info.addressModeU = address_mode;
1255 sampler_info.addressModeV = address_mode;
1256 sampler_info.addressModeW = address_mode;
1257 sampler_info.mipLodBias = 0.0F;
1258 sampler_info.anisotropyEnable = max_anisotropy > 0.0F;
1259 sampler_info.maxAnisotropy = max_anisotropy;
1260 sampler_info.compareEnable = VK_FALSE;
1261 sampler_info.compareOp = vk::CompareOp::eAlways;
1262 sampler_info.minLod = 0.0F;
1263 sampler_info.maxLod = VK_LOD_CLAMP_NONE;
1264 sampler_info.borderColor = vk::BorderColor::eFloatOpaqueBlack;
1265 sampler_info.unnormalizedCoordinates = VK_FALSE;
1266
1267 vk::Sampler sampler;
1268 try {
1269 sampler = m_context.get_device().createSampler(sampler_info);
1270 } catch (const vk::SystemError& e) {
1272 "Failed to create sampler: {}", e.what());
1273 return nullptr;
1274 }
1275
1276 m_sampler_cache[hash] = sampler;
1277
1279 "Created sampler (filter: {}, address: {}, anisotropy: {}, hash: 0x{:X})",
1280 vk::to_string(filter), vk::to_string(address_mode), max_anisotropy, hash);
1281
1282 return sampler;
1283}
#define MF_INFO(comp, ctx,...)
#define MF_ERROR(comp, ctx,...)
#define MF_DEBUG(comp, ctx,...)
glm::vec3 value
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.
void hash_combine(size_t &seed, size_t value)
Combine a hash into an existing seed, FNV-style.
Definition VisionOp.hpp:594

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

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

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