Skip to content

Commit

Permalink
refactor: remove DeferredShared (doodlum#673)
Browse files Browse the repository at this point in the history
* refactor: force include path to Shaders folder

no relative include is allowed any more

* fix: prevent delete nullptr

* fix: add missing sss include

* refactor: remove DeferredShared

replaced with SharedData
  • Loading branch information
Pentalimbed authored Oct 19, 2024
1 parent 28329f4 commit ba2fcb6
Show file tree
Hide file tree
Showing 21 changed files with 65 additions and 197 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "Common/Color.hlsli"
#include "Common/Constants.hlsli"
#include "Common/DeferredShared.hlsli"
#include "Common/FrameBuffer.hlsli"
#include "Common/SharedData.hlsli"
#include "Common/VR.hlsli"

RWTexture2DArray<float4> DynamicCubemap : register(u0);
Expand Down Expand Up @@ -97,7 +97,7 @@ float smoothbumpstep(float edge0, float edge1, float x)
uv = Stereo::ConvertToStereoUV(uv, 0);

float depth = DepthTexture.SampleLevel(LinearSampler, uv, 0);
float linearDepth = DeferredShared::GetScreenDepth(depth);
float linearDepth = SharedData::GetScreenDepth(depth);

if (linearDepth > 16.5) { // Ignore objects which are too close
half4 positionCS = half4(2 * half2(uv.x, -uv.y + 1) - 1, depth, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

///////////////////////////////////////////////////////////////////////////////

#include "Common/DeferredShared.hlsli"
#include "Common/SharedData.hlsli"

cbuffer SSGICB : register(b1)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

#include "Common/DeferredShared.hlsli"
#include "Common/SharedData.hlsli"

#include "ScreenSpaceShadows/bend_sss_gpu.hlsli"

Expand Down
35 changes: 6 additions & 29 deletions features/Skylighting/Shaders/Skylighting/Skylighting.hlsli
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
// Define SL_INCL_STRUCT and SL_INCL_METHODS to include different parts
// Because this file is included by both forward and deferred shaders
#include "Common/Random.hlsli"
#include "Common/SharedData.hlsli"
#include "Common/Spherical Harmonics/SphericalHarmonics.hlsli"

#ifdef SL_INCL_STRUCT
struct SkylightingSettings
{
row_major float4x4 OcclusionViewProj;
float4 OcclusionDir;

float4 PosOffset; // xyz: cell origin in camera model space
uint4 ArrayOrigin; // xyz: array origin
int4 ValidMargin;

float MinDiffuseVisibility;
float MinSpecularVisibility;
uint pad[2];
};

#endif

#ifdef SL_INCL_METHODS

# include "Common/Random.hlsli"
# include "Common/Spherical Harmonics/SphericalHarmonics.hlsli"

# ifdef PSHADER
#ifdef PSHADER
Texture3D<sh2> SkylightingProbeArray : register(t29);
# endif
#endif

namespace Skylighting
{
Expand Down Expand Up @@ -149,6 +128,4 @@ namespace Skylighting

return result;
}
}

#endif
}
11 changes: 1 addition & 10 deletions features/Skylighting/Shaders/Skylighting/UpdateProbesCS.hlsl
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
#define SL_INCL_STRUCT
#include "Skylighting/Skylighting.hlsli"

#include "Common/DeferredShared.hlsli"
#include "Common/FrameBuffer.hlsli"
#include "Common/Spherical Harmonics/SphericalHarmonics.hlsli"

cbuffer SkylightingCB : register(b1)
{
SkylightingSettings settings;
};

Texture2D<unorm float> srcOcclusionDepth : register(t0);

RWTexture3D<sh2> outProbeArray : register(u0);
Expand All @@ -24,6 +14,7 @@ SamplerState samplerPointClamp : register(s0);
: SV_DispatchThreadID) {
const float fadeInThreshold = 255;
const static sh2 unitSH = float4(sqrt(4.0 * shPI), 0, 0, 0);
const SkylightingSettings settings = skylightingSettings;

uint3 cellID = (int3(dtid) - settings.ArrayOrigin.xyz) % ARRAY_DIM;
bool isValid = all(cellID >= max(0, settings.ValidMargin.xyz)) && all(cellID <= ARRAY_DIM - 1 + min(0, settings.ValidMargin.xyz)); // check if the cell is newly added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ float4 SSSSBlurCS(

// Fetch linear depth of current pixel:
float depthM = DepthTexture[DTid.xy].r;
depthM = DeferredShared::GetScreenDepth(depthM);
depthM = SharedData::GetScreenDepth(depthM);

float2 profile = humanProfile ? HumanProfile.xy : BaseProfile.xy;
uint kernelOffset = humanProfile ? SSSS_N_SAMPLES : 0;
Expand Down Expand Up @@ -161,7 +161,7 @@ float4 SSSSBlurCS(
#endif

float depth = DepthTexture[coords].r;
depth = DeferredShared::GetScreenDepth(depth);
depth = SharedData::GetScreenDepth(depth);

// If the difference in depth is huge, we lerp color back to "colorM":
float s = saturate(profile.y * distanceToProjectionWindow * abs(depthM - depth));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ cbuffer PerFrameSSS : register(b1)

#include "Common/Color.hlsli"
#include "Common/Constants.hlsli"
#include "Common/DeferredShared.hlsli"
#include "Common/Random.hlsli"
#include "Common/SharedData.hlsli"

#include "SubsurfaceScattering/SeparableSSS.hlsli"

Expand Down
11 changes: 2 additions & 9 deletions package/Shaders/AmbientCompositeCS.hlsl
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
#include "Common/Color.hlsli"
#include "Common/DeferredShared.hlsli"
#include "Common/FrameBuffer.hlsli"
#include "Common/GBuffer.hlsli"
#include "Common/SharedData.hlsli"
#include "Common/VR.hlsli"

Texture2D<unorm half3> AlbedoTexture : register(t0);
Texture2D<unorm half3> NormalRoughnessTexture : register(t1);

#if defined(SKYLIGHTING)
# define SL_INCL_STRUCT
# define SL_INCL_METHODS
# include "Skylighting/Skylighting.hlsli"

cbuffer SkylightingCB : register(b1)
{
SkylightingSettings skylightingSettings;
};

Texture2D<unorm float> DepthTexture : register(t2);
Texture3D<sh2> SkylightingProbeArray : register(t3);
#endif
Expand Down Expand Up @@ -49,7 +42,7 @@ RWTexture2D<half3> DiffuseAmbientRW : register(u1);

half3 normalWS = normalize(mul(CameraViewInverse[eyeIndex], half4(normalVS, 0)).xyz);

half3 directionalAmbientColor = mul(DirectionalAmbient, half4(normalWS, 1.0));
half3 directionalAmbientColor = mul(DirectionalAmbientShared, half4(normalWS, 1.0));

half3 linAlbedo = Color::GammaToLinear(albedo) / Color::AlbedoPreMult;
half3 linDirectionalAmbientColor = Color::GammaToLinear(directionalAmbientColor) / Color::LightPreMult;
Expand Down
21 changes: 0 additions & 21 deletions package/Shaders/Common/DeferredShared.hlsli

This file was deleted.

6 changes: 4 additions & 2 deletions package/Shaders/Common/SharedData.hlsli
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
#define SHARED_DATA

#include "Common/Constants.hlsli"
#include "Common/FrameBuffer.hlsli"
#include "Common/VR.hlsli"

#if defined(PSHADER)

#if defined(PSHADER) || defined(COMPUTESHADER)
cbuffer SharedData : register(b5)
{
float4 WaterData[25];
Expand All @@ -16,8 +16,10 @@ cbuffer SharedData : register(b5)
float4 BufferDim;
float Timer;
uint FrameCount;
uint FrameCountAlwaysActive;
bool InInterior; // If the area lacks a directional shadow light e.g. the sun or moon
bool InMapMenu; // If the world/local map is open (note that the renderer is still deferred here)
float3 pad0;
};

struct GrassLightingSettings
Expand Down
10 changes: 1 addition & 9 deletions package/Shaders/DeferredCompositeCS.hlsl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

#include "Common/Color.hlsli"
#include "Common/DeferredShared.hlsli"
#include "Common/FrameBuffer.hlsli"
#include "Common/GBuffer.hlsli"
#include "Common/SharedData.hlsli"
#include "Common/VR.hlsli"

Texture2D<half3> SpecularTexture : register(t0);
Expand All @@ -25,15 +25,8 @@ SamplerState LinearSampler : register(s0);
#endif

#if defined(SKYLIGHTING)
# define SL_INCL_STRUCT
# define SL_INCL_METHODS
# include "Skylighting/Skylighting.hlsli"

cbuffer SkylightingCB : register(b1)
{
SkylightingSettings skylightingSettings;
};

Texture3D<sh2> SkylightingProbeArray : register(t9);
#endif

Expand Down Expand Up @@ -89,7 +82,6 @@ Texture2D<half4> SpecularSSGITexture : register(t10);
half roughness = 1.0 - glossiness;
half level = roughness * 7.0;

half3 directionalAmbientColor = Color::GammaToLinear(mul(DirectionalAmbient, half4(R, 1.0))) / Color::LightPreMult;
half3 finalIrradiance = 0;

# if defined(INTERIOR)
Expand Down
1 change: 0 additions & 1 deletion package/Shaders/Lighting.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,6 @@ float GetSnowParameterY(float texProjTmp, float alpha)
# endif

# if defined(SKYLIGHTING)
# define SL_INCL_METHODS
# include "Skylighting/Skylighting.hlsli"
# endif

Expand Down
1 change: 0 additions & 1 deletion package/Shaders/RunGrass.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ cbuffer PerMaterial : register(b1)
# endif

# if defined(SKYLIGHTING)
# define SL_INCL_METHODS
# include "Skylighting/Skylighting.hlsli"
# endif

Expand Down
1 change: 0 additions & 1 deletion package/Shaders/Water.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,6 @@ float calculateDepthMultfromUV(float2 a_uv, float a_depth, uint a_eyeIndex = 0)
# endif

# if defined(SKYLIGHTING)
# define SL_INCL_METHODS
# include "Skylighting/Skylighting.hlsli"
# endif

Expand Down
53 changes: 4 additions & 49 deletions src/Deferred.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ void Deferred::SetupResources()
SetupRenderTarget(MASKS2, texDesc, srvDesc, rtvDesc, uavDesc, DXGI_FORMAT_R8G8B8A8_UNORM);
}

{
deferredCB = new ConstantBuffer(ConstantBufferDesc<DeferredCB>());
}

{
auto& device = State::GetSingleton()->device;

Expand Down Expand Up @@ -228,32 +224,6 @@ void Deferred::CopyShadowData()
}
}

void Deferred::UpdateConstantBuffer()
{
DeferredCB data{};

auto state = State::GetSingleton();

data.BufferDim.x = state->screenSize.x;
data.BufferDim.y = state->screenSize.y;
data.BufferDim.z = 1.0f / data.BufferDim.x;
data.BufferDim.w = 1.0f / data.BufferDim.y;

data.CameraData = Util::GetCameraData();

const auto& shaderManager = RE::BSShaderManager::State::GetSingleton();
const RE::NiTransform& dalcTransform = shaderManager.directionalAmbientTransform;
Util::StoreTransform3x4NoScale(data.DirectionalAmbient, dalcTransform);

auto imageSpaceManager = RE::ImageSpaceManager::GetSingleton();

auto useTAA = !REL::Module::IsVR() ? imageSpaceManager->GetRuntimeData().BSImagespaceShaderISTemporalAA->taaEnabled : imageSpaceManager->GetVRRuntimeData().BSImagespaceShaderISTemporalAA->taaEnabled;
data.FrameCount = useTAA ? RE::BSGraphics::State::GetSingleton()->frameCount : 0;
data.FrameCountAlwaysActive = RE::BSGraphics::State::GetSingleton()->frameCount;

deferredCB->Update(data);
}

void Deferred::PrepassPasses()
{
ZoneScoped;
Expand Down Expand Up @@ -360,13 +330,10 @@ void Deferred::DeferredPasses()
auto renderer = RE::BSGraphics::Renderer::GetSingleton();
auto& context = State::GetSingleton()->context;

UpdateConstantBuffer();

{
static REL::Relocation<ID3D11Buffer**> perFrame{ REL::RelocationID(524768, 411384) };
ID3D11Buffer* buffers[2] = { deferredCB->CB(), *perFrame.get() };

context->CSSetConstantBuffers(11, 2, buffers);
ID3D11Buffer* buffers[1] = { *perFrame.get() };
context->CSSetConstantBuffers(12, 1, buffers);
}

auto specular = renderer->GetRuntimeData().renderTargets[SPECULAR];
Expand Down Expand Up @@ -399,9 +366,6 @@ void Deferred::DeferredPasses()
{
TracyD3D11Zone(State::GetSingleton()->tracyCtx, "Ambient Composite");

ID3D11Buffer* buffer = skylighting->loaded ? skylighting->skylightingCB->CB() : nullptr;
context->CSSetConstantBuffers(1, 1, &buffer);

ID3D11ShaderResourceView* srvs[6]{
albedo.SRV,
normalRoughness.SRV,
Expand Down Expand Up @@ -430,9 +394,6 @@ void Deferred::DeferredPasses()
ID3D11UnorderedAccessView* uavs[2]{ nullptr, nullptr };
context->CSSetUnorderedAccessViews(0, ARRAYSIZE(uavs), uavs, nullptr);

ID3D11Buffer* buffer = nullptr;
context->CSSetConstantBuffers(0, 1, &buffer);

context->CSSetShader(nullptr, nullptr, 0);
}
}
Expand All @@ -451,9 +412,6 @@ void Deferred::DeferredPasses()
{
TracyD3D11Zone(State::GetSingleton()->tracyCtx, "Deferred Composite");

ID3D11Buffer* buffer = skylighting->loaded ? skylighting->skylightingCB->CB() : nullptr;
context->CSSetConstantBuffers(1, 1, &buffer);

bool doSSGISpecular = ssgi->loaded && ssgi->settings.Enabled && ssgi->settings.EnableGI && ssgi->settings.EnableSpecularGI;

ID3D11ShaderResourceView* srvs[11]{
Expand Down Expand Up @@ -482,9 +440,6 @@ void Deferred::DeferredPasses()
context->CSSetShader(shader, nullptr, 0);

context->Dispatch(dispatchCount.x, dispatchCount.y, 1);

buffer = nullptr;
context->CSSetConstantBuffers(0, 1, &buffer);
}

// Clear
Expand All @@ -495,8 +450,8 @@ void Deferred::DeferredPasses()
ID3D11UnorderedAccessView* uavs[3]{ nullptr, nullptr, nullptr };
context->CSSetUnorderedAccessViews(0, ARRAYSIZE(uavs), uavs, nullptr);

ID3D11Buffer* buffer = nullptr;
context->CSSetConstantBuffers(0, 1, &buffer);
ID3D11Buffer* buffers[1] = { nullptr };
context->CSSetConstantBuffers(12, 1, buffers);

context->CSSetShader(nullptr, nullptr, 0);
}
Expand Down
Loading

0 comments on commit ba2fcb6

Please sign in to comment.