Move null texture to the texture manager

This commit is contained in:
Magnus Norddahl 2022-06-11 04:45:54 +02:00 committed by Christoph Oelckers
parent 63d40ffbf9
commit 3d43819a3f
5 changed files with 29 additions and 29 deletions

View file

@ -51,7 +51,6 @@ void VkDescriptorSetManager::Init()
{
CreateFixedSet();
CreateDynamicSet();
CreateNullTexture();
}
void VkDescriptorSetManager::CreateDynamicSet()
@ -131,31 +130,11 @@ void VkDescriptorSetManager::ResetHWTextureSets()
}
deleteList->Add(std::move(NullTextureDescriptorSet));
NullTextureDescriptorSet.reset();
TextureDescriptorPools.clear();
TextureDescriptorSetsLeft = 0;
TextureDescriptorsLeft = 0;
}
void VkDescriptorSetManager::CreateNullTexture()
{
ImageBuilder imgbuilder;
imgbuilder.setFormat(VK_FORMAT_R8G8B8A8_UNORM);
imgbuilder.setSize(1, 1);
imgbuilder.setUsage(VK_IMAGE_USAGE_SAMPLED_BIT);
NullTexture = imgbuilder.create(fb->device);
NullTexture->SetDebugName("VkDescriptorSetManager.NullTexture");
ImageViewBuilder viewbuilder;
viewbuilder.setImage(NullTexture.get(), VK_FORMAT_R8G8B8A8_UNORM);
NullTextureView = viewbuilder.create(fb->device);
NullTextureView->SetDebugName("VkDescriptorSetManager.NullTextureView");
PipelineBarrier barrier;
barrier.addImage(NullTexture.get(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_ASPECT_COLOR_BIT);
barrier.execute(fb->GetCommands()->GetTransferCommands(), VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
}
VulkanDescriptorSet* VkDescriptorSetManager::GetNullTextureDescriptorSet()
{
if (!NullTextureDescriptorSet)
@ -165,7 +144,7 @@ VulkanDescriptorSet* VkDescriptorSetManager::GetNullTextureDescriptorSet()
WriteDescriptors update;
for (int i = 0; i < SHADER_MIN_REQUIRED_TEXTURE_LAYERS; i++)
{
update.addCombinedImageSampler(NullTextureDescriptorSet.get(), i, NullTextureView.get(), fb->GetSamplerManager()->Get(CLAMP_XY_NOMIP), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
update.addCombinedImageSampler(NullTextureDescriptorSet.get(), i, fb->GetTextureManager()->GetNullTextureView(), fb->GetSamplerManager()->Get(CLAMP_XY_NOMIP), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
}
update.updateSets(fb->device);
}

View file

@ -32,15 +32,12 @@ public:
VulkanDescriptorSet* GetInput(VkPPRenderPassSetup* passSetup, const TArray<PPTextureInput>& textures, bool bindShadowMapBuffers);
VulkanImageView* GetNullTextureView() { return NullTextureView.get(); }
void AddMaterial(VkMaterial* texture);
void RemoveMaterial(VkMaterial* texture);
private:
void CreateDynamicSet();
void CreateFixedSet();
void CreateNullTexture();
std::unique_ptr<VulkanDescriptorSet> AllocatePPDescriptorSet(VulkanDescriptorSetLayout* layout);
@ -63,8 +60,5 @@ private:
std::unique_ptr<VulkanDescriptorSet> FixedSet;
std::unique_ptr<VulkanDescriptorSet> NullTextureDescriptorSet;
std::unique_ptr<VulkanImage> NullTexture;
std::unique_ptr<VulkanImageView> NullTextureView;
std::list<VkMaterial*> Materials;
};

View file

@ -375,7 +375,7 @@ VulkanDescriptorSet* VkMaterial::GetDescriptorSet(const FMaterialState& state)
numLayers = 3;
}
auto dummyImage = fb->GetDescriptorSetManager()->GetNullTextureView();
auto dummyImage = fb->GetTextureManager()->GetNullTextureView();
for (int i = numLayers; i < SHADER_MIN_REQUIRED_TEXTURE_LAYERS; i++)
{
update.addCombinedImageSampler(descriptor.get(), i, dummyImage, sampler, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);

View file

@ -28,6 +28,7 @@
VkTextureManager::VkTextureManager(VulkanFrameBuffer* fb) : fb(fb)
{
CreateNullTexture();
}
VkTextureManager::~VkTextureManager()
@ -119,3 +120,22 @@ VkPPTexture* VkTextureManager::GetVkTexture(PPTexture* texture)
texture->Backend = std::make_unique<VkPPTexture>(fb, texture);
return static_cast<VkPPTexture*>(texture->Backend.get());
}
void VkTextureManager::CreateNullTexture()
{
ImageBuilder imgbuilder;
imgbuilder.setFormat(VK_FORMAT_R8G8B8A8_UNORM);
imgbuilder.setSize(1, 1);
imgbuilder.setUsage(VK_IMAGE_USAGE_SAMPLED_BIT);
NullTexture = imgbuilder.create(fb->device);
NullTexture->SetDebugName("VkDescriptorSetManager.NullTexture");
ImageViewBuilder viewbuilder;
viewbuilder.setImage(NullTexture.get(), VK_FORMAT_R8G8B8A8_UNORM);
NullTextureView = viewbuilder.create(fb->device);
NullTextureView->SetDebugName("VkDescriptorSetManager.NullTextureView");
PipelineBarrier barrier;
barrier.addImage(NullTexture.get(), VK_IMAGE_LAYOUT_UNDEFINED, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL, 0, VK_ACCESS_SHADER_READ_BIT, VK_IMAGE_ASPECT_COLOR_BIT);
barrier.execute(fb->GetCommands()->GetTransferCommands(), VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT, VK_PIPELINE_STAGE_FRAGMENT_SHADER_BIT);
}

View file

@ -27,11 +27,18 @@ public:
void AddPPTexture(VkPPTexture* texture);
void RemovePPTexture(VkPPTexture* texture);
VulkanImage* GetNullTexture() { return NullTexture.get(); }
VulkanImageView* GetNullTextureView() { return NullTextureView.get(); }
private:
void CreateNullTexture();
VkPPTexture* GetVkTexture(PPTexture* texture);
VulkanFrameBuffer* fb = nullptr;
std::list<VkHardwareTexture*> Textures;
std::list<VkPPTexture*> PPTextures;
std::unique_ptr<VulkanImage> NullTexture;
std::unique_ptr<VulkanImageView> NullTextureView;
};