mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-12 06:08:30 +09:00
[Fix] (MG_Backend/DirectVulkan): properly compute hash for samplers
This commit is contained in:
@@ -11,12 +11,6 @@
|
|||||||
#include "MG_State/GLState/Core.h"
|
#include "MG_State/GLState/Core.h"
|
||||||
|
|
||||||
namespace MobileGL::MG_Backend::DirectVulkan {
|
namespace MobileGL::MG_Backend::DirectVulkan {
|
||||||
namespace {
|
|
||||||
constexpr Uint64 BuildSamplerKey(Uint externalIndex, Uint16 version) {
|
|
||||||
return (static_cast<Uint64>(externalIndex) << 16) | static_cast<Uint64>(version);
|
|
||||||
}
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
Bool VkTextureSamplerManager::Initialize(const InitInfo& initInfo) {
|
Bool VkTextureSamplerManager::Initialize(const InitInfo& initInfo) {
|
||||||
Shutdown();
|
Shutdown();
|
||||||
|
|
||||||
@@ -24,9 +18,11 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
m_physicalDevice = initInfo.physicalDevice;
|
m_physicalDevice = initInfo.physicalDevice;
|
||||||
m_commandPool = initInfo.commandPool;
|
m_commandPool = initInfo.commandPool;
|
||||||
m_graphicsQueue = initInfo.graphicsQueue;
|
m_graphicsQueue = initInfo.graphicsQueue;
|
||||||
|
m_config = initInfo.config;
|
||||||
|
|
||||||
MOBILEGL_ASSERT(m_device != VK_NULL_HANDLE && m_physicalDevice != VK_NULL_HANDLE && m_commandPool != VK_NULL_HANDLE &&
|
MOBILEGL_ASSERT(m_device != VK_NULL_HANDLE && m_physicalDevice != VK_NULL_HANDLE && m_commandPool != VK_NULL_HANDLE &&
|
||||||
m_graphicsQueue != VK_NULL_HANDLE, "VkTextureSamplerManager::Initialize failed: invalid Vulkan handles");
|
m_graphicsQueue != VK_NULL_HANDLE && m_config != nullptr,
|
||||||
|
"VkTextureSamplerManager::Initialize failed: invalid initialization info");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -49,6 +45,7 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
m_physicalDevice = VK_NULL_HANDLE;
|
m_physicalDevice = VK_NULL_HANDLE;
|
||||||
m_commandPool = VK_NULL_HANDLE;
|
m_commandPool = VK_NULL_HANDLE;
|
||||||
m_graphicsQueue = VK_NULL_HANDLE;
|
m_graphicsQueue = VK_NULL_HANDLE;
|
||||||
|
m_config = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
Bool VkTextureSamplerManager::SyncTextureAndGetDescriptor(const MG_State::GLState::ITextureObject& texture,
|
Bool VkTextureSamplerManager::SyncTextureAndGetDescriptor(const MG_State::GLState::ITextureObject& texture,
|
||||||
@@ -375,8 +372,37 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Uint64 VkTextureSamplerManager::BuildSamplerKey(const MG_State::GLState::SamplerObject& sampler) const {
|
||||||
|
MOBILEGL_ASSERT(m_config != nullptr, "VkTextureSamplerManager::BuildSamplerKey: m_config is null");
|
||||||
|
XXHASH_VERIFY(XXH64_reset(m_hashState, m_config->CacheVersion));
|
||||||
|
|
||||||
|
const auto minFilter = sampler.GetMinFilter();
|
||||||
|
XXHASH_VERIFY(XXH64_update(m_hashState, &minFilter, sizeof(minFilter)));
|
||||||
|
const auto magFilter = sampler.GetMagFilter();
|
||||||
|
XXHASH_VERIFY(XXH64_update(m_hashState, &magFilter, sizeof(magFilter)));
|
||||||
|
const auto mipmapMode = sampler.GetMipmapMode();
|
||||||
|
XXHASH_VERIFY(XXH64_update(m_hashState, &mipmapMode, sizeof(mipmapMode)));
|
||||||
|
const auto wrapS = sampler.GetWrapS();
|
||||||
|
XXHASH_VERIFY(XXH64_update(m_hashState, &wrapS, sizeof(wrapS)));
|
||||||
|
const auto wrapT = sampler.GetWrapT();
|
||||||
|
XXHASH_VERIFY(XXH64_update(m_hashState, &wrapT, sizeof(wrapT)));
|
||||||
|
const auto wrapR = sampler.GetWrapR();
|
||||||
|
XXHASH_VERIFY(XXH64_update(m_hashState, &wrapR, sizeof(wrapR)));
|
||||||
|
const auto minLod = sampler.GetMinLod();
|
||||||
|
XXHASH_VERIFY(XXH64_update(m_hashState, &minLod, sizeof(minLod)));
|
||||||
|
const auto maxLod = sampler.GetMaxLod();
|
||||||
|
XXHASH_VERIFY(XXH64_update(m_hashState, &maxLod, sizeof(maxLod)));
|
||||||
|
const auto lodBias = sampler.GetLodBias();
|
||||||
|
XXHASH_VERIFY(XXH64_update(m_hashState, &lodBias, sizeof(lodBias)));
|
||||||
|
const auto compareMode = sampler.GetCompareMode();
|
||||||
|
XXHASH_VERIFY(XXH64_update(m_hashState, &compareMode, sizeof(compareMode)));
|
||||||
|
const auto compareFunc = sampler.GetSamplerCompareFunc();
|
||||||
|
XXHASH_VERIFY(XXH64_update(m_hashState, &compareFunc, sizeof(compareFunc)));
|
||||||
|
return XXH64_digest(m_hashState);
|
||||||
|
}
|
||||||
|
|
||||||
VkSampler VkTextureSamplerManager::GetOrCreateSampler(const MG_State::GLState::SamplerObject& sampler) {
|
VkSampler VkTextureSamplerManager::GetOrCreateSampler(const MG_State::GLState::SamplerObject& sampler) {
|
||||||
const Uint64 key = BuildSamplerKey(sampler.GetExternalIndex(), sampler.GetVersion());
|
const Uint64 key = BuildSamplerKey(sampler);
|
||||||
auto it = m_samplers.find(key);
|
auto it = m_samplers.find(key);
|
||||||
if (it != m_samplers.end()) {
|
if (it != m_samplers.end()) {
|
||||||
return it->second.handle;
|
return it->second.handle;
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../VkIncludes.h"
|
#include "../VkIncludes.h"
|
||||||
|
#include "../VulkanRendererConfig.h"
|
||||||
#include <Includes.h>
|
#include <Includes.h>
|
||||||
#include <MG_State/GLState/SamplerState/SamplerObject.h>
|
#include <MG_State/GLState/SamplerState/SamplerObject.h>
|
||||||
#include <MG_State/GLState/TextureState/TextureObject.h>
|
#include <MG_State/GLState/TextureState/TextureObject.h>
|
||||||
@@ -26,6 +27,7 @@ public:
|
|||||||
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
||||||
VkCommandPool commandPool = VK_NULL_HANDLE;
|
VkCommandPool commandPool = VK_NULL_HANDLE;
|
||||||
VkQueue graphicsQueue = VK_NULL_HANDLE;
|
VkQueue graphicsQueue = VK_NULL_HANDLE;
|
||||||
|
const VulkanRendererConfig* config = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
Bool Initialize(const InitInfo& initInfo);
|
Bool Initialize(const InitInfo& initInfo);
|
||||||
@@ -63,6 +65,7 @@ private:
|
|||||||
IntVec3& outTexelSize, SizeT& outByteSize);
|
IntVec3& outTexelSize, SizeT& outByteSize);
|
||||||
static VkFormat ResolveTextureFormat(TextureInternalFormat format);
|
static VkFormat ResolveTextureFormat(TextureInternalFormat format);
|
||||||
Uint32 FindMemoryType(Uint32 typeFilter, VkMemoryPropertyFlags properties) const;
|
Uint32 FindMemoryType(Uint32 typeFilter, VkMemoryPropertyFlags properties) const;
|
||||||
|
Uint64 BuildSamplerKey(const MG_State::GLState::SamplerObject& sampler) const;
|
||||||
|
|
||||||
VkSampler GetOrCreateSampler(const MG_State::GLState::SamplerObject& sampler);
|
VkSampler GetOrCreateSampler(const MG_State::GLState::SamplerObject& sampler);
|
||||||
static VkFilter ToVkFilter(SamplerFilterMode mode);
|
static VkFilter ToVkFilter(SamplerFilterMode mode);
|
||||||
@@ -74,8 +77,10 @@ private:
|
|||||||
VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE;
|
VkPhysicalDevice m_physicalDevice = VK_NULL_HANDLE;
|
||||||
VkCommandPool m_commandPool = VK_NULL_HANDLE;
|
VkCommandPool m_commandPool = VK_NULL_HANDLE;
|
||||||
VkQueue m_graphicsQueue = VK_NULL_HANDLE;
|
VkQueue m_graphicsQueue = VK_NULL_HANDLE;
|
||||||
|
const VulkanRendererConfig* m_config = nullptr;
|
||||||
|
|
||||||
UnorderedMap<Uint, TextureResource> m_textureResources;
|
UnorderedMap<Uint, TextureResource> m_textureResources;
|
||||||
UnorderedMap<Uint64, SamplerCacheEntry> m_samplers;
|
UnorderedMap<Uint64, SamplerCacheEntry> m_samplers;
|
||||||
|
static inline XXH64_state_t* m_hashState = XXH64_createState();
|
||||||
};
|
};
|
||||||
} // namespace MobileGL::MG_Backend::DirectVulkan
|
} // namespace MobileGL::MG_Backend::DirectVulkan
|
||||||
|
|||||||
@@ -226,7 +226,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
|
|||||||
m_textureSamplerManager = MakeUnique<VkTextureSamplerManager>();
|
m_textureSamplerManager = MakeUnique<VkTextureSamplerManager>();
|
||||||
MOBILEGL_ASSERT(m_textureSamplerManager != nullptr, "VkTextureSamplerManager creation failed.");
|
MOBILEGL_ASSERT(m_textureSamplerManager != nullptr, "VkTextureSamplerManager creation failed.");
|
||||||
auto succeeded = false;
|
auto succeeded = false;
|
||||||
succeeded = m_textureSamplerManager->Initialize({m_device, m_physicalDevice.handle, m_commandPool, m_graphicsQueue});
|
succeeded =
|
||||||
|
m_textureSamplerManager->Initialize({m_device, m_physicalDevice.handle, m_commandPool, m_graphicsQueue,
|
||||||
|
&m_config});
|
||||||
MOBILEGL_ASSERT(succeeded, "VkTextureSamplerManager initialization failed.");
|
MOBILEGL_ASSERT(succeeded, "VkTextureSamplerManager initialization failed.");
|
||||||
|
|
||||||
m_framebufferManager = MakeUnique<VkFramebufferManager>();
|
m_framebufferManager = MakeUnique<VkFramebufferManager>();
|
||||||
|
|||||||
Reference in New Issue
Block a user