mirror of
https://github.com/ZDoom/gzdoom.git
synced 2024-11-25 21:41:03 +00:00
- create a descriptor for each texture+sampler configuration in use
This commit is contained in:
parent
eaf367e876
commit
ddf21ffd72
2 changed files with 33 additions and 19 deletions
|
@ -55,7 +55,7 @@ VkHardwareTexture::~VkHardwareTexture()
|
||||||
|
|
||||||
void VkHardwareTexture::Reset()
|
void VkHardwareTexture::Reset()
|
||||||
{
|
{
|
||||||
mDescriptorSet.reset();
|
mDescriptorSets.clear();
|
||||||
mImage.reset();
|
mImage.reset();
|
||||||
mImageView.reset();
|
mImageView.reset();
|
||||||
mStagingBuffer.reset();
|
mStagingBuffer.reset();
|
||||||
|
@ -63,10 +63,6 @@ void VkHardwareTexture::Reset()
|
||||||
|
|
||||||
VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &state)
|
VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &state)
|
||||||
{
|
{
|
||||||
if (!mDescriptorSet)
|
|
||||||
{
|
|
||||||
auto fb = GetVulkanFrameBuffer();
|
|
||||||
|
|
||||||
FMaterial *mat = state.mMaterial;
|
FMaterial *mat = state.mMaterial;
|
||||||
FTexture *tex = state.mMaterial->tex;
|
FTexture *tex = state.mMaterial->tex;
|
||||||
int clampmode = state.mClampMode;
|
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.
|
// 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;
|
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);
|
VulkanSampler *sampler = fb->GetSamplerManager()->Get(clampmode);
|
||||||
int numLayers = mat->GetLayers();
|
int numLayers = mat->GetLayers();
|
||||||
|
|
||||||
WriteDescriptors update;
|
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++)
|
for (int i = 1; i < numLayers; i++)
|
||||||
{
|
{
|
||||||
FTexture *layer;
|
FTexture *layer;
|
||||||
auto systex = static_cast<VkHardwareTexture*>(mat->GetLayer(i, 0, &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);
|
update.updateSets(fb->device);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mDescriptorSet.get();
|
return descriptorSet.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
VulkanImageView *VkHardwareTexture::GetImageView(FTexture *tex, int clampmode, int translation, int flags)
|
VulkanImageView *VkHardwareTexture::GetImageView(FTexture *tex, int clampmode, int translation, int flags)
|
||||||
|
|
|
@ -43,7 +43,16 @@ private:
|
||||||
void GenerateMipmaps(VulkanImage *image, VulkanCommandBuffer *cmdbuffer);
|
void GenerateMipmaps(VulkanImage *image, VulkanCommandBuffer *cmdbuffer);
|
||||||
static int GetMipLevels(int w, int h);
|
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<VulkanImage> mImage;
|
||||||
std::unique_ptr<VulkanImageView> mImageView;
|
std::unique_ptr<VulkanImageView> mImageView;
|
||||||
std::unique_ptr<VulkanBuffer> mStagingBuffer;
|
std::unique_ptr<VulkanBuffer> mStagingBuffer;
|
||||||
|
|
Loading…
Reference in a new issue