Skip to content

Commit

Permalink
Remove linear depth from texture manager again (this wasn't a good idea)
Browse files Browse the repository at this point in the history
Add linear depth texture to the fixed descriptor set
  • Loading branch information
dpjudas committed Sep 8, 2024
1 parent b8248a7 commit cc06294
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 86 deletions.
2 changes: 0 additions & 2 deletions src/common/rendering/v_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class DCanvas

class IHardwareTexture;
class FTexture;
class FSceneTexture;

class DFrameBuffer
{
Expand Down Expand Up @@ -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() {}
Expand Down
18 changes: 9 additions & 9 deletions src/common/rendering/vulkan/descriptorsets/vk_descriptorset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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());
}
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 0 additions & 11 deletions src/common/rendering/vulkan/textures/vk_hwtexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions src/common/rendering/vulkan/textures/vk_hwtexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;

Expand Down
19 changes: 0 additions & 19 deletions src/common/rendering/vulkan/vk_renderdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 0 additions & 5 deletions src/common/rendering/vulkan/vk_renderdevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<VulkanDevice> mDevice;
std::unique_ptr<VkCommandBufferManager> mCommands;
std::unique_ptr<VkBufferManager> mBufferManager;
Expand All @@ -121,8 +118,6 @@ class VulkanRenderDevice : public SystemBaseFrameBuffer
std::unique_ptr<VkLightmapper> mLightmapper;
std::unique_ptr<VkRenderState> mRenderState;

std::unordered_map<FSceneTextureType, FSceneTexture*> mSceneTextureOwners;

VkRenderBuffers *mActiveRenderBuffers = nullptr;

bool mVSync = false;
Expand Down
10 changes: 0 additions & 10 deletions src/common/textures/texture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
5 changes: 0 additions & 5 deletions src/common/textures/texturemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)())
Expand Down
15 changes: 0 additions & 15 deletions src/common/textures/textures.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
9 changes: 5 additions & 4 deletions wadsrc/static/shaders/scene/binding_fixed.glsl
Original file line number Diff line number Diff line change
@@ -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
{
Expand All @@ -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;
Expand All @@ -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
4 changes: 2 additions & 2 deletions wadsrc/static/shaders/scene/frag_main.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit cc06294

Please sign in to comment.