Fix rendering bugs when using ubershaders

This commit is contained in:
RaveYard 2025-04-04 00:40:50 +02:00 committed by Magnus Norddahl
commit b82ba53b6b
2 changed files with 10 additions and 2 deletions

View file

@ -93,7 +93,7 @@ void VkShaderManager::Deinit()
VkShaderProgram* VkShaderManager::Get(const VkShaderKey& key, bool isUberShader)
{
VkShaderProgram& program = isUberShader ? generic[key.Layout.AsDWORD] : specialized[key];
VkShaderProgram& program = isUberShader ? generic[key.GeneralizedShaderKey()] : specialized[key];
if (program.frag)
return &program;

View file

@ -136,6 +136,14 @@ public:
uint32_t AsDWORD = 0;
} Layout;
inline uint64_t GeneralizedShaderKey() const
{
return uint64_t(Layout.AsDWORD) |
(uint64_t(EffectState) << 32) |
((uint64_t(SpecialEffect) & 0xFF) << (32 + 16)) |
((uint64_t(VertexFormat) & 0xFF) << (32 + 16 + 8));
}
bool operator<(const VkShaderKey& other) const { return memcmp(this, &other, sizeof(VkShaderKey)) < 0; }
bool operator==(const VkShaderKey& other) const { return memcmp(this, &other, sizeof(VkShaderKey)) == 0; }
bool operator!=(const VkShaderKey& other) const { return memcmp(this, &other, sizeof(VkShaderKey)) != 0; }
@ -186,7 +194,7 @@ private:
VulkanRenderDevice* fb = nullptr;
std::map<uint32_t, VkShaderProgram> generic;
std::map<uint64_t, VkShaderProgram> generic;
std::map<VkShaderKey, VkShaderProgram> specialized;
std::list<VkPPShader*> PPShaders;