Use the real anisotropic filtering value in Vulkan

When creating the Vulkan texture samplers, make them have the real
anisotropic filtering value selected by the user. This has two side
effects:

* We no longer need two sets of texture samplers in Vulkan (one with and
  another one without anisotropic filtering).

* The anisotropic filter value in Vulkan is no longer an on/off switch
  and we use the value as chosen by the user.
This commit is contained in:
Ricardo Garcia 2021-03-21 00:15:12 +01:00
parent 6f8949fd95
commit f601ffddfc
6 changed files with 19 additions and 47 deletions

View File

@ -245,8 +245,6 @@ it's `+set busywait 0` (setting the `busywait` cvar) and `-portable`
dependent on the GPU driver, most of them support `1`, `2`, `4`, `8`
and `16`. Anisotropic filtering gives a huge improvement to texture
quality by a negligible performance impact.
If vulkan render have used, flag is only toggle anisotropic filtering
without use specific level.
* **r_msaa_samples**: Full scene anti aliasing samples. The number of
samples depends on the GPU driver, most drivers support at least `2`,

View File

@ -50,13 +50,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
// fall over
#define ROLL 2
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#endif
extern viddef_t vid;
typedef struct image_s

View File

@ -68,12 +68,8 @@ typedef enum
S_LINEAR = 1,
S_MIPMAP_NEAREST = 2,
S_MIPMAP_LINEAR = 3,
S_ANISO_NEAREST = 4,
S_ANISO_LINEAR = 5,
S_ANISO_MIPMAP_NEAREST = 6,
S_ANISO_MIPMAP_LINEAR = 7,
S_NEAREST_UNNORMALIZED = 8,
S_SAMPLER_CNT = 9
S_NEAREST_UNNORMALIZED = 4,
S_SAMPLER_CNT = 5
} qvksampler_t;
#define NUM_SAMPLERS (S_SAMPLER_CNT * 2)

View File

@ -861,6 +861,14 @@ static void CreateSamplersHelper(VkSampler *samplers, VkSamplerAddressMode addre
.unnormalizedCoordinates = VK_FALSE
};
assert((vk_device.properties.limits.maxSamplerAnisotropy > 1.f) && "maxSamplerAnisotropy is 1");
if (vk_device.features.samplerAnisotropy && vk_aniso->value > 0.f)
{
const float maxAniso = min(max(vk_aniso->value, 1.f), vk_device.properties.limits.maxSamplerAnisotropy);
samplerInfo.anisotropyEnable = VK_TRUE;
samplerInfo.maxAnisotropy = maxAniso;
}
VK_VERIFY(vkCreateSampler(vk_device.logical, &samplerInfo, NULL, &samplers[S_NEAREST]));
QVk_DebugSetObjectName((uint64_t)samplers[S_NEAREST], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_NEAREST");
@ -874,6 +882,8 @@ static void CreateSamplersHelper(VkSampler *samplers, VkSamplerAddressMode addre
nuSamplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
nuSamplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE;
nuSamplerInfo.unnormalizedCoordinates = VK_TRUE;
nuSamplerInfo.anisotropyEnable = VK_FALSE;
nuSamplerInfo.maxAnisotropy = 1.f;
VK_VERIFY(vkCreateSampler(vk_device.logical, &nuSamplerInfo, NULL, &samplers[S_NEAREST_UNNORMALIZED]));
QVk_DebugSetObjectName((uint64_t)samplers[S_NEAREST_UNNORMALIZED], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_NEAREST_UNNORMALIZED");
@ -892,36 +902,6 @@ static void CreateSamplersHelper(VkSampler *samplers, VkSamplerAddressMode addre
samplerInfo.maxLod = 1.f;
VK_VERIFY(vkCreateSampler(vk_device.logical, &samplerInfo, NULL, &samplers[S_LINEAR]));
QVk_DebugSetObjectName((uint64_t)samplers[S_LINEAR], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_LINEAR");
// aniso samplers
assert((vk_device.properties.limits.maxSamplerAnisotropy > 1.f) && "maxSamplerAnisotropy is 1");
samplerInfo.magFilter = VK_FILTER_NEAREST;
samplerInfo.minFilter = VK_FILTER_NEAREST;
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
if (vk_device.features.samplerAnisotropy)
{
samplerInfo.anisotropyEnable = VK_TRUE;
samplerInfo.maxAnisotropy = vk_device.properties.limits.maxSamplerAnisotropy;
}
samplerInfo.maxLod = 1.f;
VK_VERIFY(vkCreateSampler(vk_device.logical, &samplerInfo, NULL, &samplers[S_ANISO_NEAREST]));
QVk_DebugSetObjectName((uint64_t)samplers[S_ANISO_NEAREST], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_ANISO_NEAREST");
samplerInfo.maxLod = FLT_MAX;
VK_VERIFY(vkCreateSampler(vk_device.logical, &samplerInfo, NULL, &samplers[S_ANISO_MIPMAP_NEAREST]));
QVk_DebugSetObjectName((uint64_t)samplers[S_ANISO_MIPMAP_NEAREST], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_ANISO_MIPMAP_NEAREST");
samplerInfo.magFilter = VK_FILTER_LINEAR;
samplerInfo.minFilter = VK_FILTER_LINEAR;
samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
VK_VERIFY(vkCreateSampler(vk_device.logical, &samplerInfo, NULL, &samplers[S_ANISO_MIPMAP_LINEAR]));
QVk_DebugSetObjectName((uint64_t)samplers[S_ANISO_MIPMAP_LINEAR], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_ANISO_MIPMAP_LINEAR");
samplerInfo.maxLod = 1.f;
VK_VERIFY(vkCreateSampler(vk_device.logical, &samplerInfo, NULL, &samplers[S_ANISO_LINEAR]));
QVk_DebugSetObjectName((uint64_t)samplers[S_ANISO_LINEAR], VK_OBJECT_TYPE_SAMPLER, "Sampler: S_ANISO_LINEAR");
}
// internal helper

View File

@ -666,7 +666,6 @@ void Vk_TextureMode( char *string )
memcpy(prev_mode, string, strlen(string));
prev_mode[strlen(string)] = '\0';
i += vk_aniso->value > 0 ? NUM_VK_MODES : 0;
vk_current_sampler = i;
vkDeviceWaitIdle(vk_device.logical);
@ -707,7 +706,6 @@ void Vk_LmapTextureMode( char *string )
memcpy(prev_mode, string, strlen(string));
prev_mode[strlen(string)] = '\0';
i += vk_aniso->value > 0 ? NUM_VK_MODES : 0;
vk_current_lmap_sampler = i;
vkDeviceWaitIdle(vk_device.logical);

View File

@ -90,6 +90,13 @@ typedef unsigned char byte;
#define YAW 1 /* left / right */
#define ROLL 2 /* fall over */
#ifndef min
#define min(a, b) (((a) < (b)) ? (a) : (b))
#endif
#ifndef max
#define max(a, b) (((a) > (b)) ? (a) : (b))
#endif
#define MAX_STRING_CHARS 2048 /* max length of a string passed to Cmd_TokenizeString */
#define MAX_STRING_TOKENS 80 /* max tokens resulting from Cmd_TokenizeString */
#define MAX_TOKEN_CHARS 1024 /* max length of an individual token */