update sampler creation

This commit is contained in:
Matthew 2026-04-21 04:30:00 +10:00
parent 7bef66157b
commit 245db6ea6f

View File

@ -311,6 +311,12 @@ struct DescInfo
}; };
struct struct
{ {
bool enable_anisotropy;
Filter min_filter;
Filter mag_filter;
SamplerAddrMode address_mode_u;
SamplerAddrMode address_mode_v;
SamplerAddrMode address_mode_w;
MipmapMode mipmap_mode; MipmapMode mipmap_mode;
}; };
}; };
@ -318,6 +324,21 @@ struct DescInfo
alias Desc = Descriptor; alias Desc = Descriptor;
enum Filter : VkFilter
{
Nearest = VK_FILTER_NEAREST,
Linear = VK_FILTER_LINEAR,
}
enum SamplerAddrMode : VkSamplerAddressMode
{
Repeat = VK_SAMPLER_ADDRESS_MODE_REPEAT,
MirroredRepeat = VK_SAMPLER_ADDRESS_MODE_MIRRORED_REPEAT,
ClampToEdge = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
ClampToBorder = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_BORDER,
MirrorClampToEdge = VK_SAMPLER_ADDRESS_MODE_MIRROR_CLAMP_TO_EDGE,
} alias SAM = SamplerAddrMode;
enum MipmapMode : VkSamplerMipmapMode enum MipmapMode : VkSamplerMipmapMode
{ {
Nearest = VK_SAMPLER_MIPMAP_MODE_NEAREST, Nearest = VK_SAMPLER_MIPMAP_MODE_NEAREST,
@ -1174,7 +1195,7 @@ CreateDescriptor(T = u8[])(Descriptor* desc, DescInfo info, T data = null) if(is
} }
else if(info.type == DT.Sampler) else if(info.type == DT.Sampler)
{ {
CreateSampler(desc, info.mipmap_mode); CreateSampler(desc, &info);
} }
else assert(false, "Unknown descriptor type in CreateDescriptor"); else assert(false, "Unknown descriptor type in CreateDescriptor");
} }
@ -2374,23 +2395,23 @@ SelectSwapchainFormats()
} }
void void
CreateSampler(Descriptor* desc, MipmapMode mode) CreateSampler(Descriptor* desc, DescInfo* info)
{ {
VkPhysicalDeviceProperties props; VkPhysicalDeviceProperties props;
vkGetPhysicalDeviceProperties(g_vk.physical_device, &props); vkGetPhysicalDeviceProperties(g_vk.physical_device, &props);
VkSamplerCreateInfo sampler_info = { VkSamplerCreateInfo sampler_info = {
sType: VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO, sType: VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
magFilter: VK_FILTER_NEAREST, magFilter: info.mag_filter,
minFilter: VK_FILTER_NEAREST, minFilter: info.min_filter,
addressModeU: VK_SAMPLER_ADDRESS_MODE_REPEAT, addressModeU: info.address_mode_u,
addressModeV: VK_SAMPLER_ADDRESS_MODE_REPEAT, addressModeV: info.address_mode_v,
addressModeW: VK_SAMPLER_ADDRESS_MODE_REPEAT, addressModeW: info.address_mode_w,
anisotropyEnable: VK_TRUE, anisotropyEnable: info.enable_anisotropy,
maxAnisotropy: props.limits.maxSamplerAnisotropy, maxAnisotropy: props.limits.maxSamplerAnisotropy,
borderColor: VK_BORDER_COLOR_INT_OPAQUE_BLACK, borderColor: VK_BORDER_COLOR_INT_OPAQUE_BLACK,
compareOp: VK_COMPARE_OP_ALWAYS, compareOp: VK_COMPARE_OP_ALWAYS,
mipmapMode: mode, mipmapMode: info.mipmap_mode,
}; };
VkResult result = vkCreateSampler(g_vk.device, &sampler_info, null, &desc.sampler); VkResult result = vkCreateSampler(g_vk.device, &sampler_info, null, &desc.sampler);