Skip to content

Commit

Permalink
Move null texture to the texture manager
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas authored and coelckers committed Jun 22, 2022
1 parent 63d40ff commit 3d43819
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
23 changes: 1 addition & 22 deletions src/common/rendering/vulkan/renderer/vk_descriptorset.cpp
Expand Up @@ -51,7 +51,6 @@ void VkDescriptorSetManager::Init()
{
CreateFixedSet();
CreateDynamicSet();
CreateNullTexture();
}

void VkDescriptorSetManager::CreateDynamicSet()
Expand Down Expand Up @@ -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)
Expand All @@ -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);
}
Expand Down
6 changes: 0 additions & 6 deletions src/common/rendering/vulkan/renderer/vk_descriptorset.h
Expand Up @@ -32,15 +32,12 @@ class VkDescriptorSetManager

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);

Expand All @@ -63,8 +60,5 @@ class VkDescriptorSetManager
std::unique_ptr<VulkanDescriptorSet> FixedSet;
std::unique_ptr<VulkanDescriptorSet> NullTextureDescriptorSet;

std::unique_ptr<VulkanImage> NullTexture;
std::unique_ptr<VulkanImageView> NullTextureView;

std::list<VkMaterial*> Materials;
};
2 changes: 1 addition & 1 deletion src/common/rendering/vulkan/textures/vk_hwtexture.cpp
Expand Up @@ -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);
Expand Down
20 changes: 20 additions & 0 deletions src/common/rendering/vulkan/textures/vk_texture.cpp
Expand Up @@ -28,6 +28,7 @@

VkTextureManager::VkTextureManager(VulkanFrameBuffer* fb) : fb(fb)
{
CreateNullTexture();
}

VkTextureManager::~VkTextureManager()
Expand Down Expand Up @@ -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);
}
7 changes: 7 additions & 0 deletions src/common/rendering/vulkan/textures/vk_texture.h
Expand Up @@ -27,11 +27,18 @@ class VkTextureManager
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;
};

0 comments on commit 3d43819

Please sign in to comment.