- create a descriptor for each texture+sampler configuration in use

This commit is contained in:
Magnus Norddahl 2019-03-04 00:28:37 +01:00
parent eaf367e876
commit ddf21ffd72
2 changed files with 33 additions and 19 deletions

View file

@ -55,7 +55,7 @@ VkHardwareTexture::~VkHardwareTexture()
void VkHardwareTexture::Reset()
{
mDescriptorSet.reset();
mDescriptorSets.clear();
mImage.reset();
mImageView.reset();
mStagingBuffer.reset();
@ -63,10 +63,6 @@ void VkHardwareTexture::Reset()
VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &state)
{
if (!mDescriptorSet)
{
auto fb = GetVulkanFrameBuffer();
FMaterial *mat = state.mMaterial;
FTexture *tex = state.mMaterial->tex;
int clampmode = state.mClampMode;
@ -79,23 +75,32 @@ VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &s
// Textures that are already scaled in the texture lump will not get replaced by hires textures.
int flags = state.mMaterial->isExpanded() ? CTF_Expand : (gl_texture_usehires && !tex->isScaled() && clampmode <= CLAMP_XY) ? CTF_CheckHires : 0;
mDescriptorSet = fb->GetRenderPassManager()->DescriptorPool->allocate(fb->GetRenderPassManager()->TextureSetLayout.get());
DescriptorKey key;
key.clampmode = clampmode;
key.translation = translation;
key.flags = flags;
auto &descriptorSet = mDescriptorSets[key];
if (!descriptorSet)
{
auto fb = GetVulkanFrameBuffer();
descriptorSet = fb->GetRenderPassManager()->DescriptorPool->allocate(fb->GetRenderPassManager()->TextureSetLayout.get());
VulkanSampler *sampler = fb->GetSamplerManager()->Get(clampmode);
int numLayers = mat->GetLayers();
WriteDescriptors update;
update.addCombinedImageSampler(mDescriptorSet.get(), 0, GetImageView(tex, clampmode, translation, flags), sampler, mImageLayout);
update.addCombinedImageSampler(descriptorSet.get(), 0, GetImageView(tex, clampmode, translation, flags), sampler, mImageLayout);
for (int i = 1; i < numLayers; i++)
{
FTexture *layer;
auto systex = static_cast<VkHardwareTexture*>(mat->GetLayer(i, 0, &layer));
update.addCombinedImageSampler(mDescriptorSet.get(), i, systex->GetImageView(layer, clampmode, 0, mat->isExpanded() ? CTF_Expand : 0), sampler, mImageLayout);
update.addCombinedImageSampler(descriptorSet.get(), i, systex->GetImageView(layer, clampmode, 0, mat->isExpanded() ? CTF_Expand : 0), sampler, mImageLayout);
}
update.updateSets(fb->device);
}
return mDescriptorSet.get();
return descriptorSet.get();
}
VulkanImageView *VkHardwareTexture::GetImageView(FTexture *tex, int clampmode, int translation, int flags)

View file

@ -43,7 +43,16 @@ private:
void GenerateMipmaps(VulkanImage *image, VulkanCommandBuffer *cmdbuffer);
static int GetMipLevels(int w, int h);
std::unique_ptr<VulkanDescriptorSet> mDescriptorSet;
struct DescriptorKey
{
int clampmode;
int translation;
int flags;
bool operator<(const DescriptorKey &other) const { return memcmp(this, &other, sizeof(DescriptorKey)) < 0; }
};
std::map<DescriptorKey, std::unique_ptr<VulkanDescriptorSet>> mDescriptorSets;
std::unique_ptr<VulkanImage> mImage;
std::unique_ptr<VulkanImageView> mImageView;
std::unique_ptr<VulkanBuffer> mStagingBuffer;