diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index c27c8dca9..e0d5c3f9a 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -55,7 +55,7 @@ VkHardwareTexture::~VkHardwareTexture() void VkHardwareTexture::Reset() { - mDescriptorSet.reset(); + mDescriptorSets.clear(); mImage.reset(); mImageView.reset(); mStagingBuffer.reset(); @@ -63,39 +63,44 @@ void VkHardwareTexture::Reset() VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &state) { - if (!mDescriptorSet) + FMaterial *mat = state.mMaterial; + FTexture *tex = state.mMaterial->tex; + int clampmode = state.mClampMode; + int translation = state.mTranslation; + + //if (tex->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; + //if (tex->isHardwareCanvas()) clampmode = CLAMP_CAMTEX; + //else if ((tex->isWarped() || tex->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; + + // Textures that are already scaled in the texture lump will not get replaced by hires textures. + int flags = state.mMaterial->isExpanded() ? CTF_Expand : (gl_texture_usehires && !tex->isScaled() && clampmode <= CLAMP_XY) ? CTF_CheckHires : 0; + + DescriptorKey key; + key.clampmode = clampmode; + key.translation = translation; + key.flags = flags; + auto &descriptorSet = mDescriptorSets[key]; + if (!descriptorSet) { auto fb = GetVulkanFrameBuffer(); - FMaterial *mat = state.mMaterial; - FTexture *tex = state.mMaterial->tex; - int clampmode = state.mClampMode; - int translation = state.mTranslation; - - //if (tex->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER; - //if (tex->isHardwareCanvas()) clampmode = CLAMP_CAMTEX; - //else if ((tex->isWarped() || tex->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE; - - // Textures that are already scaled in the texture lump will not get replaced by hires textures. - int flags = state.mMaterial->isExpanded() ? CTF_Expand : (gl_texture_usehires && !tex->isScaled() && clampmode <= CLAMP_XY) ? CTF_CheckHires : 0; - - mDescriptorSet = fb->GetRenderPassManager()->DescriptorPool->allocate(fb->GetRenderPassManager()->TextureSetLayout.get()); + descriptorSet = fb->GetRenderPassManager()->DescriptorPool->allocate(fb->GetRenderPassManager()->TextureSetLayout.get()); VulkanSampler *sampler = fb->GetSamplerManager()->Get(clampmode); int numLayers = mat->GetLayers(); WriteDescriptors update; - update.addCombinedImageSampler(mDescriptorSet.get(), 0, GetImageView(tex, clampmode, translation, flags), sampler, mImageLayout); + update.addCombinedImageSampler(descriptorSet.get(), 0, GetImageView(tex, clampmode, translation, flags), sampler, mImageLayout); for (int i = 1; i < numLayers; i++) { FTexture *layer; auto systex = static_cast(mat->GetLayer(i, 0, &layer)); - update.addCombinedImageSampler(mDescriptorSet.get(), i, systex->GetImageView(layer, clampmode, 0, mat->isExpanded() ? CTF_Expand : 0), sampler, mImageLayout); + update.addCombinedImageSampler(descriptorSet.get(), i, systex->GetImageView(layer, clampmode, 0, mat->isExpanded() ? CTF_Expand : 0), sampler, mImageLayout); } update.updateSets(fb->device); } - return mDescriptorSet.get(); + return descriptorSet.get(); } VulkanImageView *VkHardwareTexture::GetImageView(FTexture *tex, int clampmode, int translation, int flags) diff --git a/src/rendering/vulkan/textures/vk_hwtexture.h b/src/rendering/vulkan/textures/vk_hwtexture.h index 018dd8647..2be0dc305 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.h +++ b/src/rendering/vulkan/textures/vk_hwtexture.h @@ -43,7 +43,16 @@ private: void GenerateMipmaps(VulkanImage *image, VulkanCommandBuffer *cmdbuffer); static int GetMipLevels(int w, int h); - std::unique_ptr mDescriptorSet; + struct DescriptorKey + { + int clampmode; + int translation; + int flags; + + bool operator<(const DescriptorKey &other) const { return memcmp(this, &other, sizeof(DescriptorKey)) < 0; } + }; + + std::map> mDescriptorSets; std::unique_ptr mImage; std::unique_ptr mImageView; std::unique_ptr mStagingBuffer;