diff --git a/src/common/rendering/vulkan/renderer/vk_descriptorset.cpp b/src/common/rendering/vulkan/renderer/vk_descriptorset.cpp index 1e9f610202..78e50f9e89 100644 --- a/src/common/rendering/vulkan/renderer/vk_descriptorset.cpp +++ b/src/common/rendering/vulkan/renderer/vk_descriptorset.cpp @@ -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); } diff --git a/src/common/rendering/vulkan/renderer/vk_descriptorset.h b/src/common/rendering/vulkan/renderer/vk_descriptorset.h index 3e4c63faeb..c80e1a4c99 100644 --- a/src/common/rendering/vulkan/renderer/vk_descriptorset.h +++ b/src/common/rendering/vulkan/renderer/vk_descriptorset.h @@ -32,15 +32,12 @@ public: VulkanDescriptorSet* GetInput(VkPPRenderPassSetup* passSetup, const TArray& 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 AllocatePPDescriptorSet(VulkanDescriptorSetLayout* layout); @@ -63,8 +60,5 @@ private: std::unique_ptr FixedSet; std::unique_ptr NullTextureDescriptorSet; - std::unique_ptr NullTexture; - std::unique_ptr NullTextureView; - std::list Materials; }; diff --git a/src/common/rendering/vulkan/textures/vk_hwtexture.cpp b/src/common/rendering/vulkan/textures/vk_hwtexture.cpp index ab79e25034..b613ad67ca 100644 --- a/src/common/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/common/rendering/vulkan/textures/vk_hwtexture.cpp @@ -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); diff --git a/src/common/rendering/vulkan/textures/vk_texture.cpp b/src/common/rendering/vulkan/textures/vk_texture.cpp index b1ddc8659e..69858dab27 100644 --- a/src/common/rendering/vulkan/textures/vk_texture.cpp +++ b/src/common/rendering/vulkan/textures/vk_texture.cpp @@ -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(fb, texture); return static_cast(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); +} diff --git a/src/common/rendering/vulkan/textures/vk_texture.h b/src/common/rendering/vulkan/textures/vk_texture.h index c31c631fbe..badf1a8dc7 100644 --- a/src/common/rendering/vulkan/textures/vk_texture.h +++ b/src/common/rendering/vulkan/textures/vk_texture.h @@ -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 Textures; std::list PPTextures; + + std::unique_ptr NullTexture; + std::unique_ptr NullTextureView; };