update sampler creation

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

View File

@ -311,13 +311,34 @@ struct DescInfo
};
struct
{
MipmapMode mipmap_mode;
bool enable_anisotropy;
Filter min_filter;
Filter mag_filter;
SamplerAddrMode address_mode_u;
SamplerAddrMode address_mode_v;
SamplerAddrMode address_mode_w;
MipmapMode mipmap_mode;
};
};
}
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
{
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)
{
CreateSampler(desc, info.mipmap_mode);
CreateSampler(desc, &info);
}
else assert(false, "Unknown descriptor type in CreateDescriptor");
}
@ -2374,23 +2395,23 @@ SelectSwapchainFormats()
}
void
CreateSampler(Descriptor* desc, MipmapMode mode)
CreateSampler(Descriptor* desc, DescInfo* info)
{
VkPhysicalDeviceProperties props;
vkGetPhysicalDeviceProperties(g_vk.physical_device, &props);
VkSamplerCreateInfo sampler_info = {
sType: VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO,
magFilter: VK_FILTER_NEAREST,
minFilter: VK_FILTER_NEAREST,
addressModeU: VK_SAMPLER_ADDRESS_MODE_REPEAT,
addressModeV: VK_SAMPLER_ADDRESS_MODE_REPEAT,
addressModeW: VK_SAMPLER_ADDRESS_MODE_REPEAT,
anisotropyEnable: VK_TRUE,
magFilter: info.mag_filter,
minFilter: info.min_filter,
addressModeU: info.address_mode_u,
addressModeV: info.address_mode_v,
addressModeW: info.address_mode_w,
anisotropyEnable: info.enable_anisotropy,
maxAnisotropy: props.limits.maxSamplerAnisotropy,
borderColor: VK_BORDER_COLOR_INT_OPAQUE_BLACK,
compareOp: VK_COMPARE_OP_ALWAYS,
mipmapMode: mode,
mipmapMode: info.mipmap_mode,
};
VkResult result = vkCreateSampler(g_vk.device, &sampler_info, null, &desc.sampler);