@@ -17,57 +17,62 @@ string GetKeyword()
1717 return "LIGHTLOOP_SINGLE_PASS" ;
1818 }
1919
20- ComputeBuffer m_punctualLightList ;
21- ComputeBuffer m_envLightList ;
22- ComputeBuffer m_areaLightList ;
23- ComputeBuffer m_punctualShadowList ;
20+ // Static keyword is required here else we get a "DestroyBuffer can only be call in main thread"
21+ static ComputeBuffer s_PunctualLightList ;
22+ static ComputeBuffer s_EnvLightList ;
23+ static ComputeBuffer s_AreaLightList ;
24+ static ComputeBuffer s_PunctualShadowList ;
2425
2526 void ClearComputeBuffers ( )
2627 {
27- if ( m_punctualLightList != null )
28- m_punctualLightList . Release ( ) ;
28+ if ( s_PunctualLightList != null )
29+ s_PunctualLightList . Release ( ) ;
2930
30- if ( m_areaLightList != null )
31- m_areaLightList . Release ( ) ;
31+ if ( s_AreaLightList != null )
32+ s_AreaLightList . Release ( ) ;
3233
33- if ( m_punctualShadowList != null )
34- m_punctualShadowList . Release ( ) ;
34+ if ( s_PunctualShadowList != null )
35+ s_PunctualShadowList . Release ( ) ;
3536
36- if ( m_envLightList != null )
37- m_envLightList . Release ( ) ;
37+ if ( s_EnvLightList != null )
38+ s_EnvLightList . Release ( ) ;
3839 }
3940
4041 public void Rebuild ( )
4142 {
4243 ClearComputeBuffers ( ) ;
4344
44- m_punctualLightList = new ComputeBuffer ( HDRenderLoop . k_MaxPunctualLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( PunctualLightData ) ) ) ;
45- m_areaLightList = new ComputeBuffer ( HDRenderLoop . k_MaxAreaLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( AreaLightData ) ) ) ;
46- m_envLightList = new ComputeBuffer ( HDRenderLoop . k_MaxEnvLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( EnvLightData ) ) ) ;
47- m_punctualShadowList = new ComputeBuffer ( HDRenderLoop . k_MaxShadowOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( PunctualShadowData ) ) ) ;
45+ s_PunctualLightList = new ComputeBuffer ( HDRenderLoop . k_MaxPunctualLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( PunctualLightData ) ) ) ;
46+ s_AreaLightList = new ComputeBuffer ( HDRenderLoop . k_MaxAreaLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( AreaLightData ) ) ) ;
47+ s_EnvLightList = new ComputeBuffer ( HDRenderLoop . k_MaxEnvLightsOnSCreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( EnvLightData ) ) ) ;
48+ s_PunctualShadowList = new ComputeBuffer ( HDRenderLoop . k_MaxShadowOnScreen , System . Runtime . InteropServices . Marshal . SizeOf ( typeof ( PunctualShadowData ) ) ) ;
4849 }
4950
5051 public void OnDisable ( )
5152 {
52- m_punctualLightList . Release ( ) ;
53- m_areaLightList . Release ( ) ;
54- m_envLightList . Release ( ) ;
55- m_punctualShadowList . Release ( ) ;
53+ s_PunctualLightList . Release ( ) ;
54+ s_PunctualLightList = null ;
55+ s_AreaLightList . Release ( ) ;
56+ s_AreaLightList = null ;
57+ s_EnvLightList . Release ( ) ;
58+ s_EnvLightList = null ;
59+ s_PunctualShadowList . Release ( ) ;
60+ s_PunctualShadowList = null ;
5661 }
5762
5863 public void PushGlobalParams ( Camera camera , RenderLoop loop , HDRenderLoop . LightList lightList )
5964 {
60- m_punctualLightList . SetData ( lightList . punctualLights . ToArray ( ) ) ;
61- m_areaLightList . SetData ( lightList . areaLights . ToArray ( ) ) ;
62- m_envLightList . SetData ( lightList . envLights . ToArray ( ) ) ;
63- m_punctualShadowList . SetData ( lightList . punctualShadows . ToArray ( ) ) ;
65+ s_PunctualLightList . SetData ( lightList . punctualLights . ToArray ( ) ) ;
66+ s_AreaLightList . SetData ( lightList . areaLights . ToArray ( ) ) ;
67+ s_EnvLightList . SetData ( lightList . envLights . ToArray ( ) ) ;
68+ s_PunctualShadowList . SetData ( lightList . punctualShadows . ToArray ( ) ) ;
6469
65- Shader . SetGlobalBuffer ( "_PunctualLightList" , m_punctualLightList ) ;
70+ Shader . SetGlobalBuffer ( "_PunctualLightList" , s_PunctualLightList ) ;
6671 Shader . SetGlobalInt ( "_PunctualLightCount" , lightList . punctualLights . Count ) ;
67- Shader . SetGlobalBuffer ( "_AreaLightList" , m_areaLightList ) ;
72+ Shader . SetGlobalBuffer ( "_AreaLightList" , s_AreaLightList ) ;
6873 Shader . SetGlobalInt ( "_AreaLightCount" , lightList . areaLights . Count ) ;
69- Shader . SetGlobalBuffer ( "_PunctualShadowList" , m_punctualShadowList ) ;
70- Shader . SetGlobalBuffer ( "_EnvLightList" , m_envLightList ) ;
74+ Shader . SetGlobalBuffer ( "_PunctualShadowList" , s_PunctualShadowList ) ;
75+ Shader . SetGlobalBuffer ( "_EnvLightList" , s_EnvLightList ) ;
7176 Shader . SetGlobalInt ( "_EnvLightCount" , lightList . envLights . Count ) ;
7277 }
7378 }
0 commit comments