Skip to content

Vulkan Backend image rendering. Image sampler always 'REPEAT' #5502

@rytisss

Description

@rytisss

Version/Branch of Dear ImGui:

Version: 1.88
Branch: docking

Back-end/Renderer/Compiler/OS

Back-ends: imgui_impl_vulkan.cpp
Compiler: Visual Studio C++ 2022
Operating System: Windows 10

I have a problem with texture visualization, I am trying to visualize the texture (picture) and clamp the image to the border. However, as much as I try to change the parameters in the sampler, I still get the repetitive pattern:

image

The code for the sampler:

        VkSamplerCreateInfo samplerInfo{};
	samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
	samplerInfo.magFilter = VK_FILTER_LINEAR;
	samplerInfo.minFilter = VK_FILTER_LINEAR;
	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.anisotropyEnable = VK_FALSE;
	samplerInfo.maxAnisotropy = 1.0f;
	samplerInfo.borderColor = VK_BORDER_COLOR_INT_OPAQUE_BLACK;
	samplerInfo.unnormalizedCoordinates = VK_FALSE;
	samplerInfo.compareEnable = VK_FALSE;
	samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS;
	samplerInfo.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
	samplerInfo.mipLodBias = 0.0f;
	samplerInfo.minLod = 0.0f;
	samplerInfo.maxLod = 0.0f;
	if (vkCreateSampler(m_info.Device, &samplerInfo, nullptr, &m_textureSampler) != VK_SUCCESS)
	{
		throw std::runtime_error("failed to create texture sampler!");
	}

Even when VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER or VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE is set, the results are the same (see image above). It seems that sampling is all the time VK_SAMPLER_ADDRESS_MODE_REPEAT.

To create a descriptor set (VkDescriptorSet), I am using:
m_descriptorSet = ImGui_ImplVulkan_AddTexture(m_textureSampler, m_textureImageView, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);

And to add an image:

ImGui::PushID((void*)(intptr_t)m_descriptorSet);
ImGui::GetWindowDrawList()->AddImageQuad(
					(ImTextureID)(m_descriptorSet),
					m_canvasTopLeft,
					m_canvasTopRight,
					m_canvasBottomRight,
					m_canvasBottomLeft,
					m_uv_0,
					m_uv_1,
					m_uv_2,
					m_uv_3,
					IM_COL32_WHITE);
ImGui::PopID();

It is sampling outside of image regions (outside should be with defined color), however, I get repetitive image patterns all the time (similar to repeat sampling mode).

I am wondering if there are any options set by default in the ImGui Vulkan backend that might interfere with this texture sampling (or override it)? Any help and hints are appreciated!

Might be related to #914

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions