From ec7a874a61f796f54828c366bd3ff9f09e124f9e Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 17 Mar 2019 22:41:02 +0100 Subject: [PATCH] - implement PrecacheMaterial --- src/rendering/vulkan/system/vk_framebuffer.cpp | 12 ++++++++++++ src/rendering/vulkan/system/vk_framebuffer.h | 1 + src/rendering/vulkan/textures/vk_hwtexture.cpp | 12 ++++++++++++ src/rendering/vulkan/textures/vk_hwtexture.h | 2 ++ 4 files changed, 27 insertions(+) diff --git a/src/rendering/vulkan/system/vk_framebuffer.cpp b/src/rendering/vulkan/system/vk_framebuffer.cpp index 401365c9c7..3c72bbc0a5 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.cpp +++ b/src/rendering/vulkan/system/vk_framebuffer.cpp @@ -604,6 +604,18 @@ void VulkanFrameBuffer::CleanForRestart() swdrawer.reset(); } +void VulkanFrameBuffer::PrecacheMaterial(FMaterial *mat, int translation) +{ + auto tex = mat->tex; + if (tex->isSWCanvas()) return; + + // Textures that are already scaled in the texture lump will not get replaced by hires textures. + int flags = mat->isExpanded() ? CTF_Expand : (gl_texture_usehires && !tex->isScaled()) ? CTF_CheckHires : 0; + auto base = static_cast(mat->GetLayer(0, translation)); + + base->Precache(mat, translation, flags); +} + IHardwareTexture *VulkanFrameBuffer::CreateHardwareTexture() { return new VkHardwareTexture(); diff --git a/src/rendering/vulkan/system/vk_framebuffer.h b/src/rendering/vulkan/system/vk_framebuffer.h index 58e682fe56..e26483ff90 100644 --- a/src/rendering/vulkan/system/vk_framebuffer.h +++ b/src/rendering/vulkan/system/vk_framebuffer.h @@ -69,6 +69,7 @@ public: void InitializeState() override; void CleanForRestart() override; + void PrecacheMaterial(FMaterial *mat, int translation) override; void UpdatePalette() override; uint32_t GetCaps() override; void WriteSavePic(player_t *player, FileWriter *file, int width, int height) override; diff --git a/src/rendering/vulkan/textures/vk_hwtexture.cpp b/src/rendering/vulkan/textures/vk_hwtexture.cpp index 48c9c1baab..0e6d58b318 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/rendering/vulkan/textures/vk_hwtexture.cpp @@ -79,6 +79,18 @@ void VkHardwareTexture::ResetDescriptors() mDescriptorSets.clear(); } +void VkHardwareTexture::Precache(FMaterial *mat, int translation, int flags) +{ + int numLayers = mat->GetLayers(); + GetImageView(mat->tex, translation, flags); + for (int i = 1; i < numLayers; i++) + { + FTexture *layer; + auto systex = static_cast(mat->GetLayer(i, 0, &layer)); + systex->GetImageView(layer, 0, mat->isExpanded() ? CTF_Expand : 0); + } +} + VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &state) { FMaterial *mat = state.mMaterial; diff --git a/src/rendering/vulkan/textures/vk_hwtexture.h b/src/rendering/vulkan/textures/vk_hwtexture.h index d8f4ba6b20..5066bf62e1 100644 --- a/src/rendering/vulkan/textures/vk_hwtexture.h +++ b/src/rendering/vulkan/textures/vk_hwtexture.h @@ -26,6 +26,8 @@ public: void Reset(); void ResetDescriptors(); + void Precache(FMaterial *mat, int translation, int flags); + VulkanDescriptorSet *GetDescriptorSet(const FMaterialState &state); // Software renderer stuff