Blender V4.3
vk_sampler.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "vk_sampler.hh"
10#include "vk_backend.hh"
11#include "vk_context.hh"
12#include "vk_memory.hh"
13
14#include "DNA_userdef_types.h"
15
16namespace blender::gpu {
21
22void VKSampler::create(const GPUSamplerState &sampler_state)
23{
25 BLI_assert(vk_sampler_ == VK_NULL_HANDLE);
26
27 const VKDevice &device = VKBackend::get().device;
28
29 VkSamplerCreateInfo sampler_info = {};
30 sampler_info.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
31 /* Extend */
32 sampler_info.addressModeU = to_vk_sampler_address_mode(sampler_state.extend_x);
33 sampler_info.addressModeV = sampler_info.addressModeW = to_vk_sampler_address_mode(
34 sampler_state.extend_yz);
35 sampler_info.minLod = 0;
36 sampler_info.maxLod = 1000;
37
38 if (sampler_state.type == GPU_SAMPLER_STATE_TYPE_PARAMETERS) {
39 /* Apply filtering. */
40 if (sampler_state.filtering & GPU_SAMPLER_FILTERING_LINEAR) {
41 sampler_info.magFilter = VK_FILTER_LINEAR;
42 sampler_info.minFilter = VK_FILTER_LINEAR;
43 }
44 if (sampler_state.filtering & GPU_SAMPLER_FILTERING_MIPMAP) {
45 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_LINEAR;
46 }
47 if ((sampler_state.filtering & GPU_SAMPLER_FILTERING_ANISOTROPIC) &&
48 (U.anisotropic_filter > 1) &&
49 (device.physical_device_features_get().samplerAnisotropy == VK_TRUE))
50 {
51 sampler_info.anisotropyEnable = VK_TRUE;
52 sampler_info.maxAnisotropy = U.anisotropic_filter;
53 }
54 }
55 else if (sampler_state.type == GPU_SAMPLER_STATE_TYPE_CUSTOM) {
56 if (sampler_state.custom_type == GPU_SAMPLER_CUSTOM_ICON) {
57 sampler_info.magFilter = VK_FILTER_LINEAR;
58 sampler_info.minFilter = VK_FILTER_LINEAR;
59 sampler_info.mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST;
60 sampler_info.minLod = 0;
61 sampler_info.maxLod = 1;
62 }
63 else if (sampler_state.custom_type == GPU_SAMPLER_CUSTOM_COMPARE) {
64 sampler_info.magFilter = VK_FILTER_LINEAR;
65 sampler_info.minFilter = VK_FILTER_LINEAR;
66 sampler_info.compareEnable = VK_TRUE;
67 sampler_info.compareOp = VK_COMPARE_OP_LESS_OR_EQUAL;
68 }
69 }
70
72 vkCreateSampler(device.vk_handle(), &sampler_info, vk_allocation_callbacks, &vk_sampler_);
73 debug::object_label(vk_sampler_, sampler_state.to_string().c_str());
74}
75
77{
78
79 if (vk_sampler_ != VK_NULL_HANDLE) {
81
82 const VKDevice &device = VKBackend::get().device;
83 if (device.vk_handle() != VK_NULL_HANDLE) {
84 vkDestroySampler(device.vk_handle(), vk_sampler_, vk_allocation_callbacks);
85 }
86 vk_sampler_ = VK_NULL_HANDLE;
87 }
88}
89
90} // namespace blender::gpu
#define BLI_assert(a)
Definition BLI_assert.h:50
@ GPU_SAMPLER_CUSTOM_ICON
@ GPU_SAMPLER_CUSTOM_COMPARE
@ GPU_SAMPLER_STATE_TYPE_CUSTOM
@ GPU_SAMPLER_STATE_TYPE_PARAMETERS
@ GPU_SAMPLER_STATE_TYPE_INTERNAL
@ GPU_SAMPLER_FILTERING_MIPMAP
@ GPU_SAMPLER_FILTERING_ANISOTROPIC
@ GPU_SAMPLER_FILTERING_LINEAR
unsigned int U
Definition btGjkEpa3.h:78
static VKBackend & get()
Definition vk_backend.hh:92
const VkPhysicalDeviceFeatures & physical_device_features_get() const
Definition vk_device.hh:204
VkDevice vk_handle() const
Definition vk_device.hh:224
void create(const GPUSamplerState &sampler_state)
Definition vk_sampler.cc:22
void object_label(GLenum type, GLuint object, const char *name)
Definition gl_debug.cc:344
VkSamplerAddressMode to_vk_sampler_address_mode(const GPUSamplerExtendMode extend_mode)
Definition vk_common.cc:899
GPUSamplerCustomType custom_type
GPUSamplerExtendMode extend_yz
GPUSamplerFiltering filtering
std::string to_string() const
GPUSamplerExtendMode extend_x
GPUSamplerStateType type
#define VK_ALLOCATION_CALLBACKS
Definition vk_memory.hh:58