Browse Source

vulkan: fix incorrect samplers

niki 2 years ago
parent
commit
58c801be58

+ 5 - 5
src/modules/graphics/vulkan/Graphics.cpp

@@ -2495,10 +2495,8 @@ void Graphics::endRenderPass()
 		Vulkan::cmdTransitionImageLayout(commandBuffers.at(currentFrame), image, VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
 }
 
-VkSampler Graphics::createSampler(uint64 samplerKey)
+VkSampler Graphics::createSampler(const SamplerState &samplerState)
 {
-	auto samplerState = SamplerState::fromKey(samplerKey);
-
 	VkSamplerCreateInfo samplerInfo{};
 	samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
 	samplerInfo.magFilter = Vulkan::getFilter(samplerState.magFilter);
@@ -2520,6 +2518,7 @@ VkSampler Graphics::createSampler(uint64 samplerKey)
 		samplerInfo.compareEnable = VK_FALSE;
 		samplerInfo.compareOp = VK_COMPARE_OP_ALWAYS;
 	}
+	samplerInfo.compareEnable = VK_FALSE;
 	samplerInfo.mipmapMode = Vulkan::getMipMapMode(samplerState.mipmapFilter);
 	samplerInfo.mipLodBias = samplerState.lodBias;
 	samplerInfo.minLod = static_cast<float>(samplerState.minLod);
@@ -2574,14 +2573,15 @@ std::set<Shader*> &Graphics::getUsedShadersInFrame()
 	return usedShadersInFrame;
 }
 
-VkSampler Graphics::getCachedSampler(uint64 samplerkey)
+VkSampler Graphics::getCachedSampler(const SamplerState &samplerState)
 {
+	auto samplerkey = samplerState.toKey();
 	auto it = samplers.find(samplerkey);
 	if (it != samplers.end())
 		return it->second;
 	else
 	{
-		VkSampler sampler = createSampler(samplerkey);
+		VkSampler sampler = createSampler(samplerState);
 		samplers.insert({ samplerkey, sampler });
 		return sampler;
 	}

+ 2 - 2
src/modules/graphics/vulkan/Graphics.h

@@ -308,7 +308,7 @@ public:
 	uint32_t getFrameIndex() const;
 	const VkDeviceSize getMinUniformBufferOffsetAlignment() const;
 	graphics::Texture *getDefaultTexture() const;
-	VkSampler getCachedSampler(uint64);
+	VkSampler getCachedSampler(const SamplerState &sampler);
 	void setComputeShader(Shader *computeShader);
 	std::set<Shader*> &getUsedShadersInFrame();
 	graphics::Shader::BuiltinUniformData getCurrentBuiltinUniformData();
@@ -379,7 +379,7 @@ private:
 	void setDefaultRenderPass();
 	void startRenderPass();
 	void endRenderPass();
-	VkSampler createSampler(uint64 samplerKey);
+	VkSampler createSampler(const SamplerState &sampler);
 	void cleanupUnusedObjects();
 
 	uint32_t vulkanApiVersion = VK_VERSION_1_0;

+ 2 - 2
src/modules/graphics/vulkan/Texture.cpp

@@ -152,7 +152,7 @@ bool Texture::loadVolatile()
 		clear();
 
 	createTextureImageView();
-	textureSampler = vgfx->getCachedSampler(samplerState.toKey());
+	textureSampler = vgfx->getCachedSampler(samplerState);
 
 	if (!isPixelFormatDepthStencil(format) && mipmapCount > 1 && getMipmapsMode() != MIPMAPS_NONE)
 		generateMipmaps();
@@ -251,7 +251,7 @@ void Texture::setSamplerState(const SamplerState &s)
 {
 	love::graphics::Texture::setSamplerState(s);
 
-	textureSampler = vgfx->getCachedSampler(s.toKey());
+	textureSampler = vgfx->getCachedSampler(s);
 }
 
 VkImageLayout Texture::getImageLayout() const