mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-01-19 05:52:11 +01:00
[dxvk] Refactor DxvkSampler::getBorderColor
This commit is contained in:
parent
7b81db2c75
commit
0648314451
@ -30,7 +30,7 @@ namespace dxvk {
|
||||
if (samplerInfo.addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
|
||||
|| samplerInfo.addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
|
||||
|| samplerInfo.addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)
|
||||
samplerInfo.borderColor = getBorderColor(info.compareToDepth, info.borderColor);
|
||||
samplerInfo.borderColor = getBorderColor(device, info);
|
||||
|
||||
if (m_vkd->vkCreateSampler(m_vkd->device(),
|
||||
&samplerInfo, nullptr, &m_sampler) != VK_SUCCESS)
|
||||
@ -44,29 +44,27 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
VkBorderColor DxvkSampler::getBorderColor(bool depthCompare, VkClearColorValue borderColor) const {
|
||||
VkBorderColor DxvkSampler::getBorderColor(const Rc<DxvkDevice>& device, const DxvkSamplerCreateInfo& info) {
|
||||
static const std::array<std::pair<VkClearColorValue, VkBorderColor>, 3> s_borderColors = {{
|
||||
{ { { 0.0f, 0.0f, 0.0f, 0.0f } }, VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK },
|
||||
{ { { 0.0f, 0.0f, 0.0f, 1.0f } }, VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK },
|
||||
{ { { 1.0f, 1.0f, 1.0f, 1.0f } }, VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE },
|
||||
}};
|
||||
|
||||
if (depthCompare) {
|
||||
// If we are a depth compare sampler:
|
||||
// Replicate the first index, only R matters.
|
||||
for (uint32_t i = 1; i < 4; i++)
|
||||
borderColor.float32[i] = borderColor.float32[0];
|
||||
}
|
||||
// Ignore G/B/A components for shadow samplers
|
||||
size_t size = !info.compareToDepth
|
||||
? sizeof(VkClearColorValue)
|
||||
: sizeof(float);
|
||||
|
||||
for (const auto& e : s_borderColors) {
|
||||
if (!std::memcmp(&e.first, &borderColor, sizeof(VkClearColorValue)))
|
||||
if (!std::memcmp(&e.first, &info.borderColor, size))
|
||||
return e.second;
|
||||
}
|
||||
|
||||
Logger::warn(str::format(
|
||||
"DXVK: No matching border color found for (",
|
||||
borderColor.float32[0], ",", borderColor.float32[1], ",",
|
||||
borderColor.float32[2], ",", borderColor.float32[3], ")"));
|
||||
info.borderColor.float32[0], ",", info.borderColor.float32[1], ",",
|
||||
info.borderColor.float32[2], ",", info.borderColor.float32[3], ")"));
|
||||
return VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
|
||||
}
|
||||
|
||||
|
@ -70,7 +70,9 @@ namespace dxvk {
|
||||
Rc<vk::DeviceFn> m_vkd;
|
||||
VkSampler m_sampler = VK_NULL_HANDLE;
|
||||
|
||||
VkBorderColor getBorderColor(bool depthCompare, VkClearColorValue borderColor) const;
|
||||
static VkBorderColor getBorderColor(
|
||||
const Rc<DxvkDevice>& device,
|
||||
const DxvkSamplerCreateInfo& info);
|
||||
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user