Remove linear depth from texture manager again (this wasn't a good idea)

Add linear depth texture to the fixed descriptor set
This commit is contained in:
Magnus Norddahl 2024-09-08 21:18:22 +02:00
commit cc06294932
11 changed files with 16 additions and 86 deletions

View file

@ -103,7 +103,6 @@ protected:
class IHardwareTexture;
class FTexture;
class FSceneTexture;
class DFrameBuffer
{
@ -179,7 +178,6 @@ public:
// Delete any resources that need to be deleted after restarting with a different IWAD
virtual void SetTextureFilterMode() {}
virtual IHardwareTexture *CreateHardwareTexture(int numchannels) { return nullptr; }
virtual IHardwareTexture* CreateSceneTexture(FSceneTexture* owner) { return nullptr; }
virtual void PrecacheMaterial(FMaterial *mat, int translation) {}
virtual FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags);
virtual void BeginFrame() {}

View file

@ -57,8 +57,6 @@ VkDescriptorSetManager::~VkDescriptorSetManager()
void VkDescriptorSetManager::Init()
{
UpdateFixedSet();
RSBuffer.Set = RSBuffer.Pool->allocate(RSBuffer.Layout.get());
LevelMesh.Set = LevelMesh.Pool->allocate(LevelMesh.Layout.get());
@ -112,15 +110,16 @@ void VkDescriptorSetManager::UpdateFixedSet()
WriteDescriptors update;
update.AddCombinedImageSampler(Fixed.Set.get(), 0, fb->GetTextureManager()->Shadowmap.View.get(), fb->GetSamplerManager()->ShadowmapSampler.get(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
update.AddCombinedImageSampler(Fixed.Set.get(), 1, fb->GetTextureManager()->Lightmap.View.get(), fb->GetSamplerManager()->LightmapSampler.get(), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
update.AddCombinedImageSampler(Fixed.Set.get(), 2, fb->GetBuffers()->SceneLinearDepth.View.get(), fb->GetSamplerManager()->Get(PPFilterMode::Nearest, PPWrapMode::Clamp), VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
if (fb->IsRayQueryEnabled())
{
update.AddAccelerationStructure(Fixed.Set.get(), 2, fb->GetLevelMesh()->GetAccelStruct());
update.AddAccelerationStructure(Fixed.Set.get(), 3, fb->GetLevelMesh()->GetAccelStruct());
}
else
{
update.AddBuffer(Fixed.Set.get(), 2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, fb->GetLevelMesh()->GetNodeBuffer());
update.AddBuffer(Fixed.Set.get(), 3, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, fb->GetLevelMesh()->GetVertexBuffer());
update.AddBuffer(Fixed.Set.get(), 4, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, fb->GetLevelMesh()->GetIndexBuffer());
update.AddBuffer(Fixed.Set.get(), 3, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, fb->GetLevelMesh()->GetNodeBuffer());
update.AddBuffer(Fixed.Set.get(), 4, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, fb->GetLevelMesh()->GetVertexBuffer());
update.AddBuffer(Fixed.Set.get(), 5, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, fb->GetLevelMesh()->GetIndexBuffer());
}
update.Execute(fb->GetDevice());
}
@ -234,15 +233,16 @@ void VkDescriptorSetManager::CreateFixedLayout()
DescriptorSetLayoutBuilder builder;
builder.AddBinding(0, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
builder.AddBinding(1, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
builder.AddBinding(2, VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
if (fb->IsRayQueryEnabled())
{
builder.AddBinding(2, VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
builder.AddBinding(3, VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
}
else
{
builder.AddBinding(2, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
builder.AddBinding(3, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
builder.AddBinding(4, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
builder.AddBinding(5, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_FRAGMENT_BIT);
}
builder.DebugName("VkDescriptorSetManager.Fixed.SetLayout");
Fixed.Layout = builder.Create(fb->GetDevice());
@ -271,7 +271,7 @@ void VkDescriptorSetManager::CreateRSBufferPool()
void VkDescriptorSetManager::CreateFixedPool()
{
DescriptorPoolBuilder poolbuilder;
poolbuilder.AddPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 2 * MaxFixedSets);
poolbuilder.AddPoolSize(VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, 3 * MaxFixedSets);
if (fb->IsRayQueryEnabled())
{
poolbuilder.AddPoolSize(VK_DESCRIPTOR_TYPE_ACCELERATION_STRUCTURE_KHR, 1 * MaxFixedSets);

View file

@ -43,12 +43,6 @@ VkHardwareTexture::VkHardwareTexture(VulkanRenderDevice* fb, int numchannels) :
fb->GetTextureManager()->AddTexture(this);
}
VkHardwareTexture::VkHardwareTexture(VulkanRenderDevice* fb, FSceneTextureType sceneTextureType) : fb(fb), mSceneTextureType(sceneTextureType)
{
mTexelsize = 4;
fb->GetTextureManager()->AddTexture(this);
}
VkHardwareTexture::~VkHardwareTexture()
{
if (fb)
@ -72,11 +66,6 @@ void VkHardwareTexture::Reset()
VkTextureImage *VkHardwareTexture::GetImage(FTexture *tex, int translation, int flags)
{
if (mSceneTextureType == FSceneTextureType::LinearDepth)
{
return &fb->GetBuffers()->SceneLinearDepth;
}
if (!mImage.Image)
{
CreateImage(tex, translation, flags);

View file

@ -21,14 +21,12 @@ class VulkanImageView;
class VulkanBuffer;
class VulkanRenderDevice;
class FGameTexture;
enum class FSceneTextureType;
class VkHardwareTexture : public IHardwareTexture
{
friend class VkMaterial;
public:
VkHardwareTexture(VulkanRenderDevice* fb, int numchannels);
VkHardwareTexture(VulkanRenderDevice* fb, FSceneTextureType sceneTextureType);
~VkHardwareTexture();
void Reset();
@ -53,8 +51,6 @@ private:
void CreateTexture(int w, int h, int pixelsize, VkFormat format, const void *pixels, bool mipmap);
static int GetMipLevels(int w, int h);
FSceneTextureType mSceneTextureType = FSceneTextureType::None;
VkTextureImage mImage;
int mTexelsize = 4;

View file

@ -355,12 +355,6 @@ IHardwareTexture *VulkanRenderDevice::CreateHardwareTexture(int numchannels)
return new VkHardwareTexture(this, numchannels);
}
IHardwareTexture* VulkanRenderDevice::CreateSceneTexture(FSceneTexture* owner)
{
mSceneTextureOwners[owner->Type] = owner;
return new VkHardwareTexture(this, owner->Type);
}
FMaterial* VulkanRenderDevice::CreateMaterial(FGameTexture* tex, int scaleflags)
{
return new VkMaterial(this, tex, scaleflags);
@ -541,7 +535,6 @@ void VulkanRenderDevice::BeginFrame()
mTextureManager->BeginFrame();
mScreenBuffers->BeginFrame(screen->mScreenViewport.width, screen->mScreenViewport.height, screen->mSceneViewport.width, screen->mSceneViewport.height);
mSaveBuffers->BeginFrame(SAVEPICWIDTH, SAVEPICHEIGHT, SAVEPICWIDTH, SAVEPICHEIGHT);
UpdateSceneTextureSizes();
mRenderState->BeginFrame();
mDescriptorSetManager->BeginFrame();
mLightmapper->BeginFrame();
@ -629,18 +622,6 @@ void VulkanRenderDevice::SetSaveBuffers(bool yes)
{
if (yes) mActiveRenderBuffers = mSaveBuffers.get();
else mActiveRenderBuffers = mScreenBuffers.get();
UpdateSceneTextureSizes();
}
void VulkanRenderDevice::UpdateSceneTextureSizes()
{
for (auto& it : mSceneTextureOwners)
{
if (it.second)
{
it.second->SetSize(mActiveRenderBuffers->GetSceneWidth(), mActiveRenderBuffers->GetSceneHeight());
}
}
}
void VulkanRenderDevice::ImageTransitionScene(bool unknown)

View file

@ -74,7 +74,6 @@ public:
void SetActiveRenderTarget() override;
IHardwareTexture *CreateHardwareTexture(int numchannels) override;
IHardwareTexture* CreateSceneTexture(FSceneTexture* owner) override;
FMaterial* CreateMaterial(FGameTexture* tex, int scaleflags) override;
IBuffer* CreateVertexBuffer(int numBindingPoints, int numAttributes, size_t stride, const FVertexBufferAttribute* attrs) override;
@ -103,8 +102,6 @@ private:
void PrintStartupLog();
void CopyScreenToBuffer(int w, int h, uint8_t *data) override;
void UpdateSceneTextureSizes();
std::shared_ptr<VulkanDevice> mDevice;
std::unique_ptr<VkCommandBufferManager> mCommands;
std::unique_ptr<VkBufferManager> mBufferManager;
@ -121,8 +118,6 @@ private:
std::unique_ptr<VkLightmapper> mLightmapper;
std::unique_ptr<VkRenderState> mRenderState;
std::unordered_map<FSceneTextureType, FSceneTexture*> mSceneTextureOwners;
VkRenderBuffers *mActiveRenderBuffers = nullptr;
bool mVSync = false;

View file

@ -573,13 +573,3 @@ FWrapperTexture::FWrapperTexture(int w, int h, int bits)
// todo: Initialize here.
SystemTextures.AddHardwareTexture(0, false, hwtex);
}
//==========================================================================
FSceneTexture::FSceneTexture(FSceneTextureType type) : Type(type)
{
Width = 1;
Height = 1;
auto hwtex = screen->CreateSceneTexture(this);
SystemTextures.AddHardwareTexture(0, false, hwtex);
}

View file

@ -1211,11 +1211,6 @@ void FTextureManager::Init()
mt = MakeGameTexture(new AnimTexture(), "AnimTextureFrame2", ETextureType::Override);
mt->SetUpscaleFlag(false, true);
AddGameTexture(mt);
// Linear scene depth texture for translucent shaders
auto scenedepth = MakeGameTexture(new FSceneTexture(FSceneTextureType::LinearDepth), "SceneLinearDepth", ETextureType::Override);
scenedepth->SetUpscaleFlag(false, true);
AddGameTexture(scenedepth);
}
void FTextureManager::AddTextures(void (*progressFunc_)(), void (*checkForHacks)(BuildInfo&), void (*customtexturehandler)())

View file

@ -358,21 +358,6 @@ private:
}
};
enum class FSceneTextureType
{
None,
LinearDepth
};
// Hardware textures with data from the frame buffer
class FSceneTexture : public FTexture
{
public:
FSceneTexture(FSceneTextureType type);
FSceneTextureType Type = {};
};
// A wrapper around a hardware texture, to allow using it in the 2D drawing interface.
class FWrapperTexture : public FTexture
{

View file

@ -1,10 +1,11 @@
layout(set = 0, binding = 0) uniform sampler2D ShadowMap;
layout(set = 0, binding = 1) uniform sampler2DArray LightMap;
layout(set = 0, binding = 2) uniform sampler2D LinearDepth;
#if defined(USE_RAYTRACE)
#if defined(SUPPORTS_RAYQUERY)
layout(set = 0, binding = 2) uniform accelerationStructureEXT TopLevelAS;
layout(set = 0, binding = 3) uniform accelerationStructureEXT TopLevelAS;
#else
struct CollisionNode
{
@ -17,7 +18,7 @@ struct CollisionNode
int element_index;
int padding3;
};
layout(std430, set = 0, binding = 2) buffer NodeBuffer
layout(std430, set = 0, binding = 3) buffer NodeBuffer
{
int nodesRoot;
int nodebufferPadding1;
@ -32,7 +33,7 @@ struct SurfaceVertex // Note: this must always match the FFlatVertex struct
vec2 uv;
vec2 luv;
};
layout(std430, set = 0, binding = 3) buffer VertexBuffer { SurfaceVertex vertices[]; };
layout(std430, set = 0, binding = 4) buffer ElementBuffer { int elements[]; };
layout(std430, set = 0, binding = 4) buffer VertexBuffer { SurfaceVertex vertices[]; };
layout(std430, set = 0, binding = 5) buffer ElementBuffer { int elements[]; };
#endif
#endif

View file

@ -28,8 +28,8 @@ void main()
#endif
#ifdef USE_DEPTHFADEFALLOFF
// To do: add linear depth sampling here
// material.Base.a *= clamp((depth.r - pixelpos.w) / uDepthFadeFalloff, 0.0, 1.0);
float behindFragmentDepth = texelFetch(LinearDepth, ivec2(gl_FragCoord.xy));
material.Base.a *= clamp((behindFragmentDepth - pixelpos.w) / uDepthFadeFalloff, 0.0, 1.0);
#endif
FragColor = ProcessLightMode(material);