ShockCoding
ShockCoding

Reputation: 256

VK_FILTER_NEAREST not working during sampling

I have a problem with my sampler in Vulkan: it doesn't matter if I create the sampler with VK_FILTER_NEAREST or VK_FILTER_LINEAR for both magnification or minification filter, my texture will be sampled as if I created it with VK_FILTER_LINEAR;

This is the method where I create my sampler:

void                         Gui::Texture_2D::createVkSampler(const VkFilter & _magFilter,
                                                              const VkFilter & _minFilter,
                                                              const VkSamplerMipmapMode & _mipMapFilter,
                                                              const unsigned char & _maxAnisotropy) {
    VkSamplerCreateInfo samplerInfo = {};

    samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
    samplerInfo.magFilter = _magFilter; // VK_FILTER_NEAREST
    samplerInfo.minFilter = _minFilter; // VK_FILTER_NEAREST
    samplerInfo.addressModeU = VK_SAMPLER_ADDRESS_MODE_REPEAT;
    samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
    samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
    samplerInfo.anisotropyEnable = _maxAnisotropy == 0 ? VK_FALSE : VK_TRUE; // 0
    samplerInfo.maxAnisotropy = _maxAnisotropy; // 0
    samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
    samplerInfo.unnormalizedCoordinates = VK_FALSE;
    samplerInfo.compareEnable = VK_FALSE;
    samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS;
    samplerInfo.mipmapMode = _mipMapFilter; // VK_SAMPLER_MIPMAP_MODE_NEAREST
    samplerInfo.mipLodBias = 0.0f;
    samplerInfo.minLod = 0.0f;
    samplerInfo.maxLod = static_cast<float>(image.getMipLevels());

    if (vkCreateSampler(logicalDevice, &samplerInfo, nullptr, &sampler) != VK_SUCCESS)
        throw std::runtime_error("Texture sampler creation failed!");

}

...but the texture is rendered as if I passed VK_FILTER_LINEAR and VK_SAMPLER_MIPMAP_MODE_LINEAR, and I really don't know what's wrong.

Does someone have an idea? Thanks.

More Info:

This is the image texture (a simple 8x8 .png with every 4x4 corner of a different color):

Here

This is the result using VK_FILTER_NEAREST and VK_SAMPLER_MIPMAP_MODE_NEAREST:

Here2

This is the .obj file of the cube, with Normals and Texture Coordinates:

# Blender v2.79 (sub 0) OBJ File: ''
# www.blender.org
mtllib untitled.mtl
o Cube
v 1.000000 -1.000000 -1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 -1.000000 1.000000
v -1.000000 -1.000000 -1.000000
v 1.000000 1.000000 -1.000000
v 1.000000 1.000000 1.000000
v -1.000000 1.000000 1.000000
v -1.000000 1.000000 -1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 0.000000 1.000000
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.000000 1.000000
vn 0.0000 -1.0000 0.0000
vn 0.0000 1.0000 0.0000
vn 1.0000 0.0000 0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn 0.0000 0.0000 -1.0000
usemtl Material
s off
f 1/1/1 2/2/1 3/3/1 4/4/1
f 5/5/2 8/6/2 7/7/2 6/8/2
f 1/1/3 5/9/3 6/10/3 2/11/3
f 2/12/4 6/13/4 7/7/4 3/14/4
f 3/15/5 7/16/5 8/17/5 4/4/5
f 5/5/6 1/18/6 4/19/6 8/20/6

I would expect a Minecraft-like behaviour, but I get this blurry style that I should obtain with VK_FILTER_LINEAR.

Thanks.

Update

I ran the program on another pc and the texture is sampled correctly, I suppose there's a bug/glitch/problem with my GPU, I'll try to update my drivers.

Update 2

I updated my GPU drivers and I'm now using the latest Vulkan SDK version (1.1.101.0), still nothing; RenderDoc analysis of the sampler reports no problem, I'm using the right filter; Removing/Not using mipmaps doesn't help; Not a single Validation layer error.

I'm starting to think my GPU still doesn't support Vulkan very well (Intel HD Graphics 620) so I guess I'll have to accept it and go on, knowing that at least it'll work on other PCs.

Update 3

I updated my GPU drivers and I'm now using the latest Vulkan SDK version (1.1.114.0), still nothing; RenderDoc analysis of the sampler reports no problem, I'm using the right filter; Removing/Not using mipmaps doesn't help; Not a single Validation layer error.

I'm starting to think my GPU still doesn't support Vulkan very well (Intel HD Graphics 620) so I guess I'll have to accept it and go on, knowing that at least it'll work on other PCs.

Upvotes: 2

Views: 776

Answers (1)

Aidan Hammond
Aidan Hammond

Reputation: 61

I had the exact same issue and decided to mess around with VkSamplerCreateInfo and found out that setting anisotropyEnabled to VK_FALSE fixes the problem, but I don't know why.

Upvotes: 4

Related Questions