vulkan: properly implement samplers

This commit is contained in:
niki
2022-08-01 18:51:09 +02:00
parent 7bbc2888e2
commit dcea056fcb
8 changed files with 142 additions and 38 deletions
+6 -31
View File
@@ -83,7 +83,7 @@ bool Texture::loadVolatile() {
}
}
createTextureImageView();
createTextureSampler();
textureSampler = vgfx->getCachedSampler(samplerState);
return true;
}
@@ -94,12 +94,10 @@ void Texture::unloadVolatile() {
vgfx->queueCleanUp([
device = device,
textureSampler = textureSampler,
textureImageView = textureImageView,
allocator = allocator,
textureImage = textureImage,
textureImageAllocation = textureImageAllocation] () {
vkDestroySampler(device, textureSampler, nullptr);
vkDestroyImageView(device, textureImageView, nullptr);
vmaDestroyImage(allocator, textureImage, textureImageAllocation);
});
@@ -111,6 +109,11 @@ Texture::~Texture() {
unloadVolatile();
}
void Texture::setSamplerState(const SamplerState &s) {
love::graphics::Texture::setSamplerState(s);
textureSampler = vgfx->getCachedSampler(s);
}
void Texture::createTextureImageView() {
auto vulkanFormat = Vulkan::getTextureFormat(format);
@@ -134,34 +137,6 @@ void Texture::createTextureImageView() {
}
}
void Texture::createTextureSampler() {
auto physicalDevice = vgfx->getPhysicalDevice();
VkPhysicalDeviceProperties properties{};
vkGetPhysicalDeviceProperties(physicalDevice, &properties);
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_REPEAT;
samplerInfo.addressModeV = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerInfo.addressModeW = VK_SAMPLER_ADDRESS_MODE_REPEAT;
samplerInfo.anisotropyEnable = VK_TRUE;
samplerInfo.maxAnisotropy = properties.limits.maxSamplerAnisotropy;
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_LINEAR;
samplerInfo.mipLodBias = 0.0f;
samplerInfo.minLod = 0.0f;
samplerInfo.maxLod = 0.0f;
if (vkCreateSampler(device, &samplerInfo, nullptr, &textureSampler) != VK_SUCCESS) {
throw love::Exception("failed to create texture sampler");
}
}
void Texture::clear(bool white) {
auto commandBuffer = vgfx->beginSingleTimeCommands();