- fixed the hardware rendering precacher not to evict secondary layers of multi-layer textures.

It will now check all layers of a material.
Additionally it will also delete all descriptor sets of Vulkan hardware textures before precaching to make sure that nothing here can accidentally still reference a deleted texture.
This commit is contained in:
Christoph Oelckers 2019-03-21 21:57:39 +01:00
parent 4aef99632d
commit 3ad9783d8f
10 changed files with 66 additions and 7 deletions

View file

@ -119,6 +119,8 @@ public:
void SetKerning(int c) { GlobalKerning = c; } void SetKerning(int c) { GlobalKerning = c; }
bool NoTranslate() const { return noTranslate; } bool NoTranslate() const { return noTranslate; }
protected: protected:
FFont (int lump); FFont (int lump);

View file

@ -351,6 +351,7 @@ public:
void CreateDefaultBrightmap(); void CreateDefaultBrightmap();
bool FindHoles(const unsigned char * buffer, int w, int h); bool FindHoles(const unsigned char * buffer, int w, int h);
void SetUseType(ETextureType type) { UseType = type; } void SetUseType(ETextureType type) { UseType = type; }
ETextureType GetUseType() const { return UseType; }
// Returns the whole texture, stored in column-major order // Returns the whole texture, stored in column-major order
virtual TArray<uint8_t> Get8BitPixels(bool alphatex); virtual TArray<uint8_t> Get8BitPixels(bool alphatex);

View file

@ -136,6 +136,10 @@ public:
static FMaterial *ValidateTexture(FTexture * tex, bool expand, bool create = true); static FMaterial *ValidateTexture(FTexture * tex, bool expand, bool create = true);
static FMaterial *ValidateTexture(FTextureID no, bool expand, bool trans, bool create = true); static FMaterial *ValidateTexture(FTextureID no, bool expand, bool trans, bool create = true);
const TArray<FTexture*> &GetLayerArray() const
{
return mTextureLayers;
}
}; };
#endif #endif

View file

@ -35,6 +35,7 @@
#include "hwrenderer/textures/hw_material.h" #include "hwrenderer/textures/hw_material.h"
#include "image.h" #include "image.h"
#include "v_video.h" #include "v_video.h"
#include "v_font.h"
//========================================================================== //==========================================================================
@ -169,18 +170,50 @@ void hw_PrecacheTexture(uint8_t *texhitlist, TMap<PClassActor*, bool> &actorhitl
if (!modellist[i]) Models[i]->DestroyVertexBuffer(); if (!modellist[i]) Models[i]->DestroyVertexBuffer();
} }
// delete unused textures TMap<FTexture *, bool> usedTextures, usedSprites;
screen->StartPrecaching();
int cnt = TexMan.NumTextures(); int cnt = TexMan.NumTextures();
// prepare the textures for precaching. First collect all used layer textures so that we know which ones should not be deleted.
for (int i = cnt - 1; i >= 0; i--) for (int i = cnt - 1; i >= 0; i--)
{ {
FTexture *tex = TexMan.ByIndex(i); FTexture *tex = TexMan.ByIndex(i);
if (tex != nullptr) if (tex != nullptr)
{ {
if (!texhitlist[i]) FMaterial *mat = FMaterial::ValidateTexture(tex, false, false);
if (mat != nullptr)
{
for (auto ftex : mat->GetLayerArray())
{
usedTextures.Insert(ftex, true);
}
}
if (spritehitlist[i] != nullptr && (*spritehitlist[i]).CountUsed() > 0)
{
FMaterial *mat = FMaterial::ValidateTexture(tex, true, false);
if (mat != nullptr)
{
for (auto ftex : mat->GetLayerArray())
{
usedSprites.Insert(ftex, true);
}
}
}
}
}
// delete unused textures (i.e. those which didn't get referenced by any material in the cache list.
for (int i = cnt - 1; i >= 0; i--)
{
FTexture *tex = TexMan.ByIndex(i);
if (tex != nullptr && tex->GetUseType() != ETextureType::FontChar)
{
if (usedTextures.CheckKey(tex) == nullptr)
{ {
tex->SystemTextures.Clean(true, false); tex->SystemTextures.Clean(true, false);
} }
if (spritehitlist[i] == nullptr || (*spritehitlist[i]).CountUsed() == 0) if (usedSprites.CheckKey(tex) == nullptr)
{ {
tex->SystemTextures.Clean(false, true); tex->SystemTextures.Clean(false, true);
} }

View file

@ -88,7 +88,7 @@ public:
tt->Delete(); tt->Delete();
tt->hwTexture =tex; tt->hwTexture =tex;
} }
//=========================================================================== //===========================================================================
// //
// Deletes all allocated resources and considers translations // Deletes all allocated resources and considers translations
@ -125,6 +125,13 @@ public:
} }
} }
template<class T>
void Iterate(T callback)
{
for (auto & t : hwDefTex) if (t.hwTexture) callback(t.hwTexture);
for (auto & t : hwTex_Translated) if (t.hwTexture) callback(t.hwTexture);
}
}; };

View file

@ -672,6 +672,13 @@ void VulkanFrameBuffer::TextureFilterChanged()
} }
} }
void VulkanFrameBuffer::StartPrecaching()
{
// Destroy the texture descriptors to avoid problems with potentially stale textures.
for (VkHardwareTexture *cur = VkHardwareTexture::First; cur; cur = cur->Next)
cur->ResetDescriptors();
}
void VulkanFrameBuffer::BlurScene(float amount) void VulkanFrameBuffer::BlurScene(float amount)
{ {
if (mPostprocess) if (mPostprocess)

View file

@ -76,6 +76,7 @@ public:
sector_t *RenderView(player_t *player) override; sector_t *RenderView(player_t *player) override;
void SetTextureFilterMode() override; void SetTextureFilterMode() override;
void TextureFilterChanged() override; void TextureFilterChanged() override;
void StartPrecaching() override;
void BeginFrame() override; void BeginFrame() override;
void BlurScene(float amount) override; void BlurScene(float amount) override;
void PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D) override; void PostProcessScene(int fixedcm, const std::function<void()> &afterBloomDrawEndScene2D) override;

View file

@ -57,9 +57,6 @@ VkHardwareTexture::~VkHardwareTexture()
if (fb) if (fb)
{ {
auto &deleteList = fb->FrameDeleteList; auto &deleteList = fb->FrameDeleteList;
for (auto &it : mDescriptorSets)
deleteList.Descriptors.push_back(std::move(it.second));
mDescriptorSets.clear();
if (mImage) deleteList.Images.push_back(std::move(mImage)); if (mImage) deleteList.Images.push_back(std::move(mImage));
if (mImageView) deleteList.ImageViews.push_back(std::move(mImageView)); if (mImageView) deleteList.ImageViews.push_back(std::move(mImageView));
if (mStagingBuffer) deleteList.Buffers.push_back(std::move(mStagingBuffer)); if (mStagingBuffer) deleteList.Buffers.push_back(std::move(mStagingBuffer));

View file

@ -45,6 +45,12 @@ public:
VulkanImage *GetImage(FTexture *tex, int translation, int flags); VulkanImage *GetImage(FTexture *tex, int translation, int flags);
VulkanImageView *GetImageView(FTexture *tex, int translation, int flags); VulkanImageView *GetImageView(FTexture *tex, int translation, int flags);
static void ResetAllDescriptors()
{
for (VkHardwareTexture *cur = First; cur; cur = cur->Next)
cur->ResetDescriptors();
}
private: private:
void CreateImage(FTexture *tex, int translation, int flags); void CreateImage(FTexture *tex, int translation, int flags);

View file

@ -423,6 +423,7 @@ public:
virtual void TextureFilterChanged() {} virtual void TextureFilterChanged() {}
virtual void BeginFrame() {} virtual void BeginFrame() {}
virtual void SetWindowSize(int w, int h) {} virtual void SetWindowSize(int w, int h) {}
virtual void StartPrecaching() {}
virtual int GetClientWidth() = 0; virtual int GetClientWidth() = 0;
virtual int GetClientHeight() = 0; virtual int GetClientHeight() = 0;