Skip to content

Commit 0faa894

Browse files
committed
rsx/vk: Fix bug with custom border color sampler storage
- If an app used multiple border colors, only the first one was being applied.
1 parent b30a44c commit 0faa894

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

rpcs3/Emu/RSX/VK/VKDraw.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ void VKGSRender::load_texture_env()
275275

276276
auto get_border_color = [&](const rsx::Texture auto& tex)
277277
{
278-
return m_device->get_custom_border_color_support().require_border_color_remap
278+
return m_device->get_custom_border_color_support().require_border_color_remap
279279
? tex.remapped_border_color()
280280
: rsx::decode_border_color(tex.border_color());
281281
};

rpcs3/Emu/RSX/VK/vkutils/sampler.cpp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,8 @@ namespace vk
182182
return found == m_generic_sampler_pool.end() ? nullptr : found->second.get();
183183
}
184184

185-
const auto block = m_custom_color_sampler_pool.equal_range(key.base_key);
186-
for (auto it = block.first; it != block.second; ++it)
187-
{
188-
if (it->second->key.border_color_key == key.border_color_key)
189-
{
190-
return it->second.get();
191-
}
192-
}
193-
194-
return nullptr;
185+
const auto found = m_custom_color_sampler_pool.find(key);
186+
return found == m_custom_color_sampler_pool.end() ? nullptr : found->second.get();
195187
}
196188

197189
cached_sampler_object_t* sampler_pool_t::emplace(const sampler_pool_key_t& key, std::unique_ptr<cached_sampler_object_t>& object)
@@ -204,7 +196,7 @@ namespace vk
204196
return iterator->second.get();
205197
}
206198

207-
const auto [iterator, _unused] = m_custom_color_sampler_pool.emplace(key.base_key, std::move(object));
199+
const auto [iterator, _unused] = m_custom_color_sampler_pool.emplace(key, std::move(object));
208200
return iterator->second.get();
209201
}
210202

rpcs3/Emu/RSX/VK/vkutils/sampler.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ namespace vk
6464
{
6565
u64 base_key;
6666
u64 border_color_key;
67+
68+
bool operator == (const sampler_pool_key_t& that) const
69+
{
70+
return this->base_key == that.base_key &&
71+
this->border_color_key == that.border_color_key;
72+
}
73+
};
74+
75+
struct sampler_pool_key_hash
76+
{
77+
size_t operator()(const vk::sampler_pool_key_t& k) const noexcept
78+
{
79+
usz result = k.base_key;
80+
result ^= k.border_color_key + 0x9e3779b97f4a7c15ULL + (result << 6) + (result >> 2);
81+
return result;
82+
}
6783
};
6884

6985
struct cached_sampler_object_t : public vk::sampler, public rsx::ref_counted
@@ -75,7 +91,7 @@ namespace vk
7591
class sampler_pool_t
7692
{
7793
std::unordered_map<u64, std::unique_ptr<cached_sampler_object_t>> m_generic_sampler_pool;
78-
std::unordered_map<u64, std::unique_ptr<cached_sampler_object_t>> m_custom_color_sampler_pool;
94+
std::unordered_map<sampler_pool_key_t, std::unique_ptr<cached_sampler_object_t>, sampler_pool_key_hash> m_custom_color_sampler_pool;
7995

8096
public:
8197

0 commit comments

Comments
 (0)