From cf5596adbad3aeea77ac10b9641b238113de99bf Mon Sep 17 00:00:00 2001 From: Christoph Haag Date: Thu, 20 Aug 2020 02:20:49 +0200 Subject: [PATCH] comp: Use CLAMP_TO_EDGE for swapchains Avoids sampling black at the edges of layers. --- src/xrt/auxiliary/vk/vk_helpers.c | 10 ++++++---- src/xrt/auxiliary/vk/vk_helpers.h | 4 +++- src/xrt/compositor/main/comp_layer_renderer.c | 3 ++- src/xrt/compositor/main/comp_swapchain.c | 3 ++- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/xrt/auxiliary/vk/vk_helpers.c b/src/xrt/auxiliary/vk/vk_helpers.c index 5d4249294..e2b40d6f3 100644 --- a/src/xrt/auxiliary/vk/vk_helpers.c +++ b/src/xrt/auxiliary/vk/vk_helpers.c @@ -382,7 +382,9 @@ vk_create_semaphore_from_native(struct vk_bundle *vk, } VkResult -vk_create_sampler(struct vk_bundle *vk, VkSampler *out_sampler) +vk_create_sampler(struct vk_bundle *vk, + VkSamplerAddressMode clamp_mode, + VkSampler *out_sampler) { VkSampler sampler; VkResult ret; @@ -392,9 +394,9 @@ vk_create_sampler(struct vk_bundle *vk, VkSampler *out_sampler) .magFilter = VK_FILTER_LINEAR, .minFilter = VK_FILTER_LINEAR, .mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR, - .addressModeU = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, - .addressModeV = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, - .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, + .addressModeU = clamp_mode, + .addressModeV = clamp_mode, + .addressModeW = clamp_mode, .borderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK, .unnormalizedCoordinates = VK_FALSE, }; diff --git a/src/xrt/auxiliary/vk/vk_helpers.h b/src/xrt/auxiliary/vk/vk_helpers.h index 65f90cefe..b843134c8 100644 --- a/src/xrt/auxiliary/vk/vk_helpers.h +++ b/src/xrt/auxiliary/vk/vk_helpers.h @@ -372,7 +372,9 @@ vk_create_image_simple(struct vk_bundle *vk, * @ingroup aux_vk */ VkResult -vk_create_sampler(struct vk_bundle *vk, VkSampler *out_sampler); +vk_create_sampler(struct vk_bundle *vk, + VkSamplerAddressMode clamp_mode, + VkSampler *out_sampler); /*! * @ingroup aux_vk diff --git a/src/xrt/compositor/main/comp_layer_renderer.c b/src/xrt/compositor/main/comp_layer_renderer.c index c85df4c45..0930c5429 100644 --- a/src/xrt/compositor/main/comp_layer_renderer.c +++ b/src/xrt/compositor/main/comp_layer_renderer.c @@ -425,7 +425,8 @@ _init_frame_buffer(struct comp_layer_renderer *self, &self->framebuffers[eye].image); vk_check_error("vk_create_image_simple", res, false); - vk_create_sampler(vk, &self->framebuffers[eye].sampler); + vk_create_sampler(vk, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER, + &self->framebuffers[eye].sampler); VkImageSubresourceRange subresource_range = { .aspectMask = VK_IMAGE_ASPECT_COLOR_BIT, diff --git a/src/xrt/compositor/main/comp_swapchain.c b/src/xrt/compositor/main/comp_swapchain.c index 7bee6bfa2..863e64f3a 100644 --- a/src/xrt/compositor/main/comp_swapchain.c +++ b/src/xrt/compositor/main/comp_swapchain.c @@ -125,7 +125,8 @@ do_post_create_vulkan_setup(struct comp_compositor *c, U_TYPED_ARRAY_CALLOC(VkImageView, info->array_size); sc->images[i].array_size = info->array_size; - vk_create_sampler(&c->vk, &sc->images[i].sampler); + vk_create_sampler(&c->vk, VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, + &sc->images[i].sampler); for (uint32_t layer = 0; layer < info->array_size; ++layer) { VkImageSubresourceRange subresource_range = {