@@ -133,6 +133,15 @@ private enum SMAAStage
133133
134134 HDRenderPipeline m_HDInstance ;
135135
136+ void FillEmptyExposureTexture ( )
137+ {
138+ var tex = new Texture2D ( 1 , 1 , TextureFormat . RGHalf , false , true ) ;
139+ tex . SetPixel ( 0 , 0 , new Color ( 1f , ColorUtils . ConvertExposureToEV100 ( 1f ) , 0f , 0f ) ) ;
140+ tex . Apply ( ) ;
141+ Graphics . Blit ( tex , m_EmptyExposureTexture ) ;
142+ CoreUtils . Destroy ( tex ) ;
143+ }
144+
136145 public PostProcessSystem ( HDRenderPipelineAsset hdAsset , RenderPipelineResources defaultResources )
137146 {
138147 m_Resources = defaultResources ;
@@ -206,11 +215,7 @@ public PostProcessSystem(HDRenderPipelineAsset hdAsset, RenderPipelineResources
206215 // TODO: Write a version that uses structured buffer instead of texture to do atomic as Metal doesn't support atomics on textures.
207216 m_MotionBlurSupportsScattering = m_MotionBlurSupportsScattering && ( SystemInfo . graphicsDeviceType != GraphicsDeviceType . Metal ) ;
208217
209- var tex = new Texture2D ( 1 , 1 , TextureFormat . RGHalf , false , true ) ;
210- tex . SetPixel ( 0 , 0 , new Color ( 1f , ColorUtils . ConvertExposureToEV100 ( 1f ) , 0f , 0f ) ) ;
211- tex . Apply ( ) ;
212- Graphics . Blit ( tex , m_EmptyExposureTexture ) ;
213- CoreUtils . Destroy ( tex ) ;
218+ FillEmptyExposureTexture ( ) ;
214219
215220 // Initialize our target pool to ease RT management
216221 m_Pool = new TargetPool ( ) ;
@@ -287,6 +292,23 @@ public void Cleanup()
287292 m_FarBokehTileList = null ;
288293 }
289294
295+ // In some cases, the internal buffer of render textures might be invalid.
296+ // Usually when using these textures with API such as SetRenderTarget, they are recreated internally.
297+ // This is not the case when these textures are used exclusively with Compute Shaders. So to make sure they work in this case, we recreate them here.
298+ void CheckRenderTexturesValidity ( )
299+ {
300+ if ( ! m_EmptyExposureTexture . rt . IsCreated ( ) )
301+ FillEmptyExposureTexture ( ) ;
302+
303+ HDUtils . CheckRTCreated ( m_InternalLogLut . rt ) ;
304+ HDUtils . CheckRTCreated ( m_TempTexture1024 . rt ) ;
305+ HDUtils . CheckRTCreated ( m_TempTexture32 . rt ) ;
306+ if ( m_KeepAlpha )
307+ {
308+ HDUtils . CheckRTCreated ( m_AlphaTexture . rt ) ;
309+ }
310+ }
311+
290312 public void BeginFrame ( CommandBuffer cmd , HDCamera camera , HDRenderPipeline hdInstance )
291313 {
292314 m_HDInstance = hdInstance ;
@@ -336,6 +358,8 @@ public void BeginFrame(CommandBuffer cmd, HDCamera camera, HDRenderPipeline hdIn
336358 m_DitheringFS = frameSettings . IsEnabled ( FrameSettingsField . Dithering ) ;
337359 m_AntialiasingFS = frameSettings . IsEnabled ( FrameSettingsField . Antialiasing ) ;
338360
361+ CheckRenderTexturesValidity ( ) ;
362+
339363 // Handle fixed exposure & disabled pre-exposure by forcing an exposure multiplier of 1
340364 if ( ! m_ExposureControlFS )
341365 {
@@ -2644,7 +2668,11 @@ public RTHandle Get(in Vector2 scaleFactor, GraphicsFormat format, bool mipmap =
26442668 var hashCode = ComputeHashCode ( scaleFactor . x , scaleFactor . y , ( int ) format , mipmap ) ;
26452669
26462670 if ( m_Targets . TryGetValue ( hashCode , out var stack ) && stack . Count > 0 )
2647- return stack . Pop ( ) ;
2671+ {
2672+ var tex = stack . Pop ( ) ;
2673+ HDUtils . CheckRTCreated ( tex . rt ) ;
2674+ return tex ;
2675+ }
26482676
26492677 var rt = RTHandles . Alloc (
26502678 scaleFactor , TextureXR . slices , DepthBits . None , colorFormat : format , dimension : TextureXR . dimension ,
0 commit comments