vulkan: use SamplerState::toKey for caching

This commit is contained in:
niki
2022-09-19 14:23:46 +02:00
parent 4b13e5b99d
commit ba759f5bc0
4 changed files with 12 additions and 24 deletions
-4
View File
@@ -139,10 +139,6 @@ struct SamplerState
static bool getConstant(const char *in, WrapMode &out);
static bool getConstant(WrapMode in, const char *&out);
static std::vector<std::string> getConstants(WrapMode);
bool operator==(const SamplerState& other) const {
return memcmp(this, &other, sizeof(SamplerState)) == 0;
}
};
/**
+6 -7
View File
@@ -2495,10 +2495,9 @@ 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(const SamplerState &samplerState)
VkSampler Graphics::createSampler(uint64 samplerKey)
{
VkPhysicalDeviceProperties properties{};
vkGetPhysicalDeviceProperties(physicalDevice, &properties);
auto samplerState = SamplerState::fromKey(samplerKey);
VkSamplerCreateInfo samplerInfo{};
samplerInfo.sType = VK_STRUCTURE_TYPE_SAMPLER_CREATE_INFO;
@@ -2575,15 +2574,15 @@ std::set<Shader*> &Graphics::getUsedShadersInFrame()
return usedShadersInFrame;
}
VkSampler Graphics::getCachedSampler(const SamplerState &samplerState)
VkSampler Graphics::getCachedSampler(uint64 samplerkey)
{
auto it = samplers.find(samplerState);
auto it = samplers.find(samplerkey);
if (it != samplers.end())
return it->second;
else
{
VkSampler sampler = createSampler(samplerState);
samplers.insert({samplerState, sampler});
VkSampler sampler = createSampler(samplerkey);
samplers.insert({ samplerkey, sampler });
return sampler;
}
}
+3 -11
View File
@@ -193,14 +193,6 @@ struct GraphicsPipelineConfigurationHasher
}
};
struct SamplerStateHasher
{
size_t operator()(const SamplerState &samplerState) const
{
return XXH32(&samplerState, sizeof(SamplerState), 0);
}
};
struct BatchedDrawBuffers
{
StreamBuffer *vertexBuffer1;
@@ -316,7 +308,7 @@ public:
uint32_t getFrameIndex() const;
const VkDeviceSize getMinUniformBufferOffsetAlignment() const;
graphics::Texture *getDefaultTexture() const;
VkSampler getCachedSampler(const SamplerState &samplerState);
VkSampler getCachedSampler(uint64);
void setComputeShader(Shader *computeShader);
std::set<Shader*> &getUsedShadersInFrame();
graphics::Shader::BuiltinUniformData getCurrentBuiltinUniformData();
@@ -387,7 +379,7 @@ private:
void setDefaultRenderPass();
void startRenderPass();
void endRenderPass();
VkSampler createSampler(const SamplerState &samplerState);
VkSampler createSampler(uint64 samplerKey);
void cleanupUnusedObjects();
uint32_t vulkanApiVersion = VK_VERSION_1_0;
@@ -423,7 +415,7 @@ private:
std::unordered_map<VkRenderPass, bool> renderPassUsages;
std::unordered_map<VkFramebuffer, bool> framebufferUsages;
std::unordered_map<VkPipeline, bool> pipelineUsages;
std::unordered_map<SamplerState, VkSampler, SamplerStateHasher> samplers;
std::unordered_map<uint64, VkSampler> samplers;
VkCommandPool commandPool = VK_NULL_HANDLE;
std::vector<VkCommandBuffer> commandBuffers;
Shader* computeShader = nullptr;
+3 -2
View File
@@ -152,7 +152,7 @@ bool Texture::loadVolatile()
clear();
createTextureImageView();
textureSampler = vgfx->getCachedSampler(samplerState);
textureSampler = vgfx->getCachedSampler(samplerState.toKey());
if (!isPixelFormatDepthStencil(format) && mipmapCount > 1 && getMipmapsMode() != MIPMAPS_NONE)
generateMipmaps();
@@ -250,7 +250,8 @@ ptrdiff_t Texture::getHandle() const
void Texture::setSamplerState(const SamplerState &s)
{
love::graphics::Texture::setSamplerState(s);
textureSampler = vgfx->getCachedSampler(s);
textureSampler = vgfx->getCachedSampler(s.toKey());
}
VkImageLayout Texture::getImageLayout() const