Skip to content

Commit 7920752

Browse files
author
runes
committed
added code to bind shadow resources to compute shaders
1 parent eb92e1b commit 7920752

4 files changed

Lines changed: 38 additions & 22 deletions

File tree

Assets/ScriptableRenderPipeline/Core/Shadow/Shadow.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,14 +1389,14 @@ public override void SyncData()
13891389
m_ShadowCtxt.SyncData();
13901390
}
13911391

1392-
public override void BindResources(CommandBuffer cmd)
1392+
public override void BindResources(CommandBuffer cmd, ComputeShader computeShader, int computeKernel)
13931393
{
13941394
foreach (var sm in m_Shadowmaps)
13951395
{
13961396
sm.Fill(m_ShadowCtxt);
13971397
}
13981398
cmd.BeginSample("Bind resources to GPU");
1399-
m_ShadowCtxt.BindResources(cmd);
1399+
m_ShadowCtxt.BindResources(cmd, computeShader, computeKernel);
14001400
cmd.EndSample("Bind resources to GPU");
14011401
}
14021402

Assets/ScriptableRenderPipeline/Core/Shadow/ShadowBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ public uint RequestSamplerSlot( ComparisonSamplerState css )
578578
public class ShadowContext : ShadowContextStorage
579579
{
580580
public delegate void SyncDel( ShadowContext sc );
581-
public delegate void BindDel( ShadowContext sc, CommandBuffer cb );
581+
public delegate void BindDel( ShadowContext sc, CommandBuffer cb, ComputeShader computeShader, int computeKernel);
582582
public struct CtxtInit
583583
{
584584
public Init storage;
@@ -595,7 +595,7 @@ public ShadowContext( ref CtxtInit initializer ) : base( ref initializer.storage
595595
// delegate that takes care of syncing data to the GPU
596596
public void SyncData() { m_DataSyncerDel( this ); }
597597
// delegate that takes care of binding textures, buffers and samplers to shaders just before rendering
598-
public void BindResources( CommandBuffer cb ) { m_ResourceBinderDel( this, cb ); }
598+
public void BindResources( CommandBuffer cb, ComputeShader computeShader, int computeKernel) { m_ResourceBinderDel( this, cb, computeShader, computeKernel); }
599599

600600
// the following functions are to be used by the bind and sync delegates
601601
public void GetShadowDatas( out ShadowData[] shadowDatas, out uint offset, out uint count ) { shadowDatas = m_ShadowDatas.AsArray( out offset, out count ); }
@@ -785,7 +785,7 @@ interface IShadowManager
785785
// Synchronize data with GPU buffers
786786
void SyncData();
787787
// Binds resources to shader stages just before rendering the lighting pass
788-
void BindResources( CommandBuffer cmd );
788+
void BindResources( CommandBuffer cmd, ComputeShader computeShader, int computeKernel);
789789
// Fixes up some parameters within the cullResults
790790
void UpdateCullingParameters( ref ScriptableCullingParameters cullingParams );
791791

@@ -806,7 +806,7 @@ abstract public class ShadowManagerBase : ShadowRegistry, IShadowManager
806806
public abstract void DisplayShadow(CommandBuffer cmd, int shadowIndex, uint faceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
807807
public abstract void DisplayShadowMap(CommandBuffer cmd, uint shadowMapIndex, uint sliceIndex, float screenX, float screenY, float screenSizeX, float screenSizeY, float minValue, float maxValue);
808808
public abstract void SyncData();
809-
public abstract void BindResources( CommandBuffer cmd );
809+
public abstract void BindResources( CommandBuffer cmd, ComputeShader computeShader, int computeKernel);
810810
public abstract void UpdateCullingParameters( ref ScriptableCullingParameters cullingParams );
811811
// sort the shadow requests in descending priority - may only modify shadowRequests
812812
protected abstract void PrioritizeShadowCasters( Camera camera, List<VisibleLight> lights, uint shadowRequestsCount, int[] shadowRequests );

Assets/ScriptableRenderPipeline/Fptl/FptlLighting.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public ShadowSetup(ShadowInitParameters shadowInit, ShadowSettings shadowSetting
4848
};
4949

5050
// binding code. This needs to be in sync with ShadowContext.hlsl
51-
ShadowContext.BindDel binder = (ShadowContext sc, CommandBuffer cb) =>
51+
ShadowContext.BindDel binder = (ShadowContext sc, CommandBuffer cb, ComputeShader computeShader, int computeKernel) =>
5252
{
5353
// bind buffers
5454
cb.SetGlobalBuffer("_ShadowDatasExp", s_ShadowDataBuffer);
@@ -1100,7 +1100,7 @@ void ExecuteRenderLoop(Camera camera, CullResults cullResults, ScriptableRenderC
11001100
CommandBuffer cmdShadow = CommandBufferPool.Get();
11011101
m_ShadowMgr.RenderShadows( m_FrameId, loop, cmdShadow, cullResults, cullResults.visibleLights );
11021102
m_ShadowMgr.SyncData();
1103-
m_ShadowMgr.BindResources( cmdShadow );
1103+
m_ShadowMgr.BindResources( cmdShadow, null, 0 );
11041104
loop.ExecuteCommandBuffer(cmdShadow);
11051105
CommandBufferPool.Release(cmdShadow);
11061106

Assets/ScriptableRenderPipeline/HDRenderPipeline/Lighting/TilePass/TilePass.cs

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -80,19 +80,35 @@ public ShadowSetup(ShadowInitParameters shadowInit, ShadowSettings shadowSetting
8080
};
8181

8282
// binding code. This needs to be in sync with ShadowContext.hlsl
83-
ShadowContext.BindDel binder = (ShadowContext sc, CommandBuffer cb) =>
84-
{
85-
// bind buffers
86-
cb.SetGlobalBuffer("_ShadowDatasExp", s_ShadowDataBuffer);
87-
cb.SetGlobalBuffer("_ShadowPayloads", s_ShadowPayloadBuffer);
88-
// bind textures
83+
ShadowContext.BindDel binder = (ShadowContext sc, CommandBuffer cb, ComputeShader computeShader, int computeKernel) =>
84+
{
8985
uint offset, count;
9086
RenderTargetIdentifier[] tex;
91-
sc.GetTex2DArrays( out tex, out offset, out count );
92-
cb.SetGlobalTexture( "_ShadowmapExp_VSM_0", tex[0] );
93-
cb.SetGlobalTexture( "_ShadowmapExp_VSM_1", tex[1] );
94-
cb.SetGlobalTexture( "_ShadowmapExp_VSM_2", tex[2] );
95-
cb.SetGlobalTexture( "_ShadowmapExp_PCF" , tex[3] );
87+
sc.GetTex2DArrays(out tex, out offset, out count);
88+
89+
if(computeShader)
90+
{
91+
// bind buffers
92+
cb.SetComputeBufferParam(computeShader, computeKernel, "_ShadowDatasExp", s_ShadowDataBuffer);
93+
cb.SetComputeBufferParam(computeShader, computeKernel, "_ShadowPayloads", s_ShadowPayloadBuffer);
94+
// bind textures
95+
cb.SetComputeTextureParam(computeShader, computeKernel, "_ShadowmapExp_VSM_0", tex[0]);
96+
cb.SetComputeTextureParam(computeShader, computeKernel, "_ShadowmapExp_VSM_1", tex[1]);
97+
cb.SetComputeTextureParam(computeShader, computeKernel, "_ShadowmapExp_VSM_2", tex[2]);
98+
cb.SetComputeTextureParam(computeShader, computeKernel, "_ShadowmapExp_PCF", tex[3]);
99+
}
100+
else
101+
{
102+
// bind buffers
103+
cb.SetGlobalBuffer("_ShadowDatasExp", s_ShadowDataBuffer);
104+
cb.SetGlobalBuffer("_ShadowPayloads", s_ShadowPayloadBuffer);
105+
// bind textures
106+
cb.SetGlobalTexture("_ShadowmapExp_VSM_0", tex[0]);
107+
cb.SetGlobalTexture("_ShadowmapExp_VSM_1", tex[1]);
108+
cb.SetGlobalTexture("_ShadowmapExp_VSM_2", tex[2]);
109+
cb.SetGlobalTexture("_ShadowmapExp_PCF", tex[3]);
110+
}
111+
96112
// TODO: Currently samplers are hard coded in ShadowContext.hlsl, so we can't really set them here
97113
};
98114

@@ -1825,9 +1841,9 @@ private void UpdateDataBuffers()
18251841
s_LightVolumeDataBuffer.SetData(m_lightList.lightVolumes);
18261842
}
18271843

1828-
private void BindGlobalParams(CommandBuffer cmd, ComputeShader computeShader, int kernelIndex, Camera camera)
1844+
private void BindGlobalParams(CommandBuffer cmd, Camera camera)
18291845
{
1830-
m_ShadowMgr.BindResources(cmd);
1846+
m_ShadowMgr.BindResources(cmd, activeComputeShader, activeComputeKernel);
18311847

18321848
SetGlobalBuffer("g_vLightListGlobal", !usingFptl ? s_PerVoxelLightLists : s_LightList); // opaques list (unless MSAA possibly)
18331849

@@ -1881,7 +1897,7 @@ private void PushGlobalParams(Camera camera, CommandBuffer cmd, ComputeShader co
18811897
m_ShadowMgr.SyncData();
18821898

18831899
SetGlobalPropertyRedirect(computeShader, kernelIndex, cmd);
1884-
BindGlobalParams(cmd, computeShader, kernelIndex, camera);
1900+
BindGlobalParams(cmd, camera);
18851901
SetGlobalPropertyRedirect(null, 0, null);
18861902
}
18871903
}

0 commit comments

Comments
 (0)