mirror of
https://github.com/doitsujin/dxvk.git
synced 2025-03-13 19:29:14 +01:00
[dxvk] Move sampler border color handling to the backend
This commit is contained in:
parent
e15e693dc4
commit
36ccd46ae7
@ -33,19 +33,15 @@ namespace dxvk {
|
||||
info.compareToDepth = (filterBits & 0x80) ? VK_TRUE : VK_FALSE;
|
||||
info.compareOp = DecodeCompareOp(desc.ComparisonFunc);
|
||||
|
||||
info.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
|
||||
for (uint32_t i = 0; i < 4; i++)
|
||||
info.borderColor.float32[i] = desc.BorderColor[i];
|
||||
|
||||
info.usePixelCoord = VK_FALSE; // Not supported in D3D11
|
||||
|
||||
// Make sure to use a valid anisotropy value
|
||||
if (desc.MaxAnisotropy < 1) info.maxAnisotropy = 1.0f;
|
||||
if (desc.MaxAnisotropy > 16) info.maxAnisotropy = 16.0f;
|
||||
|
||||
// Try to find a matching border color if clamp to border is enabled
|
||||
if (info.addressModeU == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
|
||||
|| info.addressModeV == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER
|
||||
|| info.addressModeW == VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER)
|
||||
info.borderColor = DecodeBorderColor(desc.BorderColor);
|
||||
|
||||
// Enforce anisotropy specified in the device options
|
||||
int32_t samplerAnisotropyOption = device->GetOptions()->samplerAnisotropy;
|
||||
|
||||
|
@ -552,7 +552,7 @@ namespace dxvk {
|
||||
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER;
|
||||
samplerInfo.compareToDepth = VK_FALSE;
|
||||
samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS;
|
||||
samplerInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
|
||||
samplerInfo.borderColor = VkClearColorValue();
|
||||
samplerInfo.usePixelCoord = VK_FALSE;
|
||||
m_samplerFitting = m_device->createSampler(samplerInfo);
|
||||
|
||||
|
@ -46,34 +46,6 @@ namespace dxvk {
|
||||
}
|
||||
|
||||
|
||||
VkBorderColor DecodeBorderColor(const FLOAT BorderColor[4]) {
|
||||
struct BorderColorEntry {
|
||||
float r, g, b, a;
|
||||
VkBorderColor bc;
|
||||
};
|
||||
|
||||
// Vulkan only supports a very limited set of border colors
|
||||
const std::array<BorderColorEntry, 3> borderColorMap = {{
|
||||
{ 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 },
|
||||
}};
|
||||
|
||||
for (const auto& e : borderColorMap) {
|
||||
if (e.r == BorderColor[0] && e.g == BorderColor[1]
|
||||
&& e.b == BorderColor[2] && e.a == BorderColor[3])
|
||||
return e.bc;
|
||||
}
|
||||
|
||||
Logger::warn(str::format(
|
||||
"D3D11Device: No matching border color found for (",
|
||||
BorderColor[0], ",", BorderColor[1], ",",
|
||||
BorderColor[2], ",", BorderColor[3], ")"));
|
||||
|
||||
return VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
|
||||
}
|
||||
|
||||
|
||||
VkCompareOp DecodeCompareOp(D3D11_COMPARISON_FUNC Mode) {
|
||||
switch (Mode) {
|
||||
case D3D11_COMPARISON_NEVER: return VK_COMPARE_OP_NEVER;
|
||||
|
@ -28,9 +28,6 @@ namespace dxvk {
|
||||
VkSamplerAddressMode DecodeAddressMode(
|
||||
D3D11_TEXTURE_ADDRESS_MODE mode);
|
||||
|
||||
VkBorderColor DecodeBorderColor(
|
||||
const FLOAT BorderColor[4]);
|
||||
|
||||
VkCompareOp DecodeCompareOp(
|
||||
D3D11_COMPARISON_FUNC Mode);
|
||||
|
||||
|
@ -23,8 +23,13 @@ namespace dxvk {
|
||||
samplerInfo.compareOp = info.compareOp;
|
||||
samplerInfo.minLod = info.mipmapLodMin;
|
||||
samplerInfo.maxLod = info.mipmapLodMax;
|
||||
samplerInfo.borderColor = info.borderColor;
|
||||
samplerInfo.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
|
||||
samplerInfo.unnormalizedCoordinates = info.usePixelCoord;
|
||||
|
||||
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.borderColor);
|
||||
|
||||
if (m_vkd->vkCreateSampler(m_vkd->device(),
|
||||
&samplerInfo, nullptr, &m_sampler) != VK_SUCCESS)
|
||||
@ -36,5 +41,25 @@ namespace dxvk {
|
||||
m_vkd->vkDestroySampler(
|
||||
m_vkd->device(), m_sampler, nullptr);
|
||||
}
|
||||
|
||||
|
||||
VkBorderColor DxvkSampler::getBorderColor(VkClearColorValue borderColor) const {
|
||||
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 },
|
||||
}};
|
||||
|
||||
for (const auto& e : s_borderColors) {
|
||||
if (!std::memcmp(&e.first, &borderColor, sizeof(VkClearColorValue)))
|
||||
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], ")"));
|
||||
return VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ namespace dxvk {
|
||||
VkCompareOp compareOp;
|
||||
|
||||
/// Texture border color
|
||||
VkBorderColor borderColor;
|
||||
VkClearColorValue borderColor;
|
||||
|
||||
/// Enables unnormalized coordinates
|
||||
VkBool32 usePixelCoord;
|
||||
@ -76,6 +76,8 @@ namespace dxvk {
|
||||
Rc<vk::DeviceFn> m_vkd;
|
||||
DxvkSamplerCreateInfo m_info;
|
||||
VkSampler m_sampler = VK_NULL_HANDLE;
|
||||
|
||||
VkBorderColor getBorderColor(VkClearColorValue borderColor) const;
|
||||
|
||||
};
|
||||
|
||||
|
@ -55,7 +55,7 @@ namespace dxvk {
|
||||
info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
info.compareToDepth = VK_FALSE;
|
||||
info.compareOp = VK_COMPARE_OP_NEVER;
|
||||
info.borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_WHITE;
|
||||
info.borderColor = VkClearColorValue();
|
||||
info.usePixelCoord = VK_FALSE;
|
||||
|
||||
return dev->createSampler(info);
|
||||
|
@ -279,7 +279,7 @@ namespace dxvk::hud {
|
||||
info.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
|
||||
info.compareToDepth = VK_FALSE;
|
||||
info.compareOp = VK_COMPARE_OP_NEVER;
|
||||
info.borderColor = VK_BORDER_COLOR_FLOAT_TRANSPARENT_BLACK;
|
||||
info.borderColor = VkClearColorValue();
|
||||
info.usePixelCoord = VK_TRUE;
|
||||
|
||||
return device->createSampler(info);
|
||||
|
Loading…
x
Reference in New Issue
Block a user