mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-28 15:02:01 +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,39 +63,44 @@ void VkHardwareTexture::Reset()
|
||||||
|
|
||||||
VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &state)
|
VulkanDescriptorSet *VkHardwareTexture::GetDescriptorSet(const FMaterialState &state)
|
||||||
{
|
{
|
||||||
if (!mDescriptorSet)
|
FMaterial *mat = state.mMaterial;
|
||||||
|
FTexture *tex = state.mMaterial->tex;
|
||||||
|
int clampmode = state.mClampMode;
|
||||||
|
int translation = state.mTranslation;
|
||||||
|
|
||||||
|
//if (tex->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER;
|
||||||
|
//if (tex->isHardwareCanvas()) clampmode = CLAMP_CAMTEX;
|
||||||
|
//else if ((tex->isWarped() || tex->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE;
|
||||||
|
|
||||||
|
// 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;
|
||||||
|
|
||||||
|
DescriptorKey key;
|
||||||
|
key.clampmode = clampmode;
|
||||||
|
key.translation = translation;
|
||||||
|
key.flags = flags;
|
||||||
|
auto &descriptorSet = mDescriptorSets[key];
|
||||||
|
if (!descriptorSet)
|
||||||
{
|
{
|
||||||
auto fb = GetVulkanFrameBuffer();
|
auto fb = GetVulkanFrameBuffer();
|
||||||
|
|
||||||
FMaterial *mat = state.mMaterial;
|
descriptorSet = fb->GetRenderPassManager()->DescriptorPool->allocate(fb->GetRenderPassManager()->TextureSetLayout.get());
|
||||||
FTexture *tex = state.mMaterial->tex;
|
|
||||||
int clampmode = state.mClampMode;
|
|
||||||
int translation = state.mTranslation;
|
|
||||||
|
|
||||||
//if (tex->UseType == ETextureType::SWCanvas) clampmode = CLAMP_NOFILTER;
|
|
||||||
//if (tex->isHardwareCanvas()) clampmode = CLAMP_CAMTEX;
|
|
||||||
//else if ((tex->isWarped() || tex->shaderindex >= FIRST_USER_SHADER) && clampmode <= CLAMP_XY) clampmode = CLAMP_NONE;
|
|
||||||
|
|
||||||
// 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());
|
|
||||||
|
|
||||||
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