From cc0629493297d315cdb29a5fab72c9551f44862b Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Sun, 8 Sep 2024 21:18:22 +0200 Subject: [PATCH] Remove linear depth from texture manager again (this wasn't a good idea) Add linear depth texture to the fixed descriptor set --- src/common/rendering/v_video.h | 2 -- .../descriptorsets/vk_descriptorset.cpp | 18 +++++++++--------- .../vulkan/textures/vk_hwtexture.cpp | 11 ----------- .../rendering/vulkan/textures/vk_hwtexture.h | 4 ---- .../rendering/vulkan/vk_renderdevice.cpp | 19 ------------------- src/common/rendering/vulkan/vk_renderdevice.h | 5 ----- src/common/textures/texture.cpp | 10 ---------- src/common/textures/texturemanager.cpp | 5 ----- src/common/textures/textures.h | 15 --------------- .../static/shaders/scene/binding_fixed.glsl | 9 +++++---- wadsrc/static/shaders/scene/frag_main.glsl | 4 ++-- 11 files changed, 16 insertions(+), 86 deletions(-) diff --git a/src/common/rendering/v_video.h b/src/common/rendering/v_video.h index 67fd1effee..9bdb2ab4b9 100644 --- a/src/common/rendering/v_video.h +++ b/src/common/rendering/v_video.h @@ -103,7 +103,6 @@ class DCanvas class IHardwareTexture; class FTexture; -class FSceneTexture; class DFrameBuffer { @@ -179,7 +178,6 @@ class DFrameBuffer // 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() {} diff --git a/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp b/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp index 00343c9d54..387a5a794b 100644 --- a/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp +++ b/src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp @@ -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); diff --git a/src/common/rendering/vulkan/textures/vk_hwtexture.cpp b/src/common/rendering/vulkan/textures/vk_hwtexture.cpp index 016afee1ef..d09fc61857 100644 --- a/src/common/rendering/vulkan/textures/vk_hwtexture.cpp +++ b/src/common/rendering/vulkan/textures/vk_hwtexture.cpp @@ -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); diff --git a/src/common/rendering/vulkan/textures/vk_hwtexture.h b/src/common/rendering/vulkan/textures/vk_hwtexture.h index 1bb1e56916..19dd71dc5f 100644 --- a/src/common/rendering/vulkan/textures/vk_hwtexture.h +++ b/src/common/rendering/vulkan/textures/vk_hwtexture.h @@ -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 @@ class VkHardwareTexture : public IHardwareTexture 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; diff --git a/src/common/rendering/vulkan/vk_renderdevice.cpp b/src/common/rendering/vulkan/vk_renderdevice.cpp index c5c60406bf..873214bb72 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.cpp +++ b/src/common/rendering/vulkan/vk_renderdevice.cpp @@ -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) diff --git a/src/common/rendering/vulkan/vk_renderdevice.h b/src/common/rendering/vulkan/vk_renderdevice.h index 414d516581..a4d9559bba 100644 --- a/src/common/rendering/vulkan/vk_renderdevice.h +++ b/src/common/rendering/vulkan/vk_renderdevice.h @@ -74,7 +74,6 @@ class VulkanRenderDevice : public SystemBaseFrameBuffer 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 @@ class VulkanRenderDevice : public SystemBaseFrameBuffer void PrintStartupLog(); void CopyScreenToBuffer(int w, int h, uint8_t *data) override; - void UpdateSceneTextureSizes(); - std::shared_ptr mDevice; std::unique_ptr mCommands; std::unique_ptr mBufferManager; @@ -121,8 +118,6 @@ class VulkanRenderDevice : public SystemBaseFrameBuffer std::unique_ptr mLightmapper; std::unique_ptr mRenderState; - std::unordered_map mSceneTextureOwners; - VkRenderBuffers *mActiveRenderBuffers = nullptr; bool mVSync = false; diff --git a/src/common/textures/texture.cpp b/src/common/textures/texture.cpp index 40165ca568..38e0a561d1 100644 --- a/src/common/textures/texture.cpp +++ b/src/common/textures/texture.cpp @@ -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); -} diff --git a/src/common/textures/texturemanager.cpp b/src/common/textures/texturemanager.cpp index 2681c85bbc..1173f61be0 100644 --- a/src/common/textures/texturemanager.cpp +++ b/src/common/textures/texturemanager.cpp @@ -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)()) diff --git a/src/common/textures/textures.h b/src/common/textures/textures.h index b692047c53..34dbdd5042 100644 --- a/src/common/textures/textures.h +++ b/src/common/textures/textures.h @@ -358,21 +358,6 @@ class FCanvasTexture : public FTexture } }; -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 { diff --git a/wadsrc/static/shaders/scene/binding_fixed.glsl b/wadsrc/static/shaders/scene/binding_fixed.glsl index 387ed6d161..8bfcae2c48 100644 --- a/wadsrc/static/shaders/scene/binding_fixed.glsl +++ b/wadsrc/static/shaders/scene/binding_fixed.glsl @@ -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 diff --git a/wadsrc/static/shaders/scene/frag_main.glsl b/wadsrc/static/shaders/scene/frag_main.glsl index 189658b368..ddc844f660 100644 --- a/wadsrc/static/shaders/scene/frag_main.glsl +++ b/wadsrc/static/shaders/scene/frag_main.glsl @@ -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);