@@ -18,25 +18,59 @@ static class RegisterSTP
1818
1919 [ RuntimeInitializeOnLoadMethod ( RuntimeInitializeLoadType . BeforeSceneLoad ) ]
2020 static void InitRuntime ( ) => UpscalerRegistry . Register < STPIUpscaler , STPOptions > ( STPIUpscaler . upscalerName ) ;
21- }
21+ }
22+
23+ /// <summary>
24+ /// Per-camera context for STP upscaling. Wraps the STP.HistoryContext
25+ /// and tracks the display resolution it was created for.
26+ /// </summary>
27+ public class STPUpscalerContext : IUpscalerContext
28+ {
29+ private STP . HistoryContext m_HistoryContext ;
30+
31+ /// <inheritdoc/>
32+ public Vector2Int createdForDisplayResolution { get ; private set ; }
33+
34+ /// <inheritdoc/>
35+ public int lastUsedFrame { get ; set ; }
36+
37+ public STP . HistoryContext historyContext => m_HistoryContext ;
38+
39+ public STPUpscalerContext ( Vector2Int displayResolution )
40+ {
41+ m_HistoryContext = new STP . HistoryContext ( ) ;
42+ createdForDisplayResolution = displayResolution ;
43+ }
44+
45+ /// <inheritdoc/>
46+ public bool IsValidForOptions ( UpscalerOptions options )
47+ {
48+ // STP options only contain injection point which doesn't affect context validity.
49+ // Resolution validation is handled by the framework via createdForDisplayResolution.
50+ return true ;
51+ }
52+
53+ /// <inheritdoc/>
54+ public void Cleanup ( CommandBuffer cmd )
55+ {
56+ if ( m_HistoryContext != null )
57+ {
58+ m_HistoryContext . Dispose ( ) ;
59+ m_HistoryContext = null ;
60+ }
61+ }
62+ }
2263
2364public class STPIUpscaler : AbstractUpscaler
2465{
2566 public static readonly string upscalerName = "Spatial-Temporal Post-Processing" ;
2667
2768 STPOptions m_Options ; // contains injection point (for HDRP at this time)
2869 private const string k_UpscaledColorTargetName = "_UpscaledCameraColor" ;
29- private STP . HistoryContext [ ] m_Histories ; // One history per eye
3070
3171 public STPIUpscaler ( STPOptions optionsIn )
3272 {
3373 m_Options = optionsIn ;
34-
35- m_Histories = new STP . HistoryContext [ 2 ] ;
36- for ( int i = 0 ; i < m_Histories . Length ; i ++ )
37- {
38- m_Histories [ i ] = new STP . HistoryContext ( ) ;
39- }
4074 }
4175
4276 public override UpscalerOptions options => m_Options ;
@@ -46,10 +80,23 @@ public STPIUpscaler(STPOptions optionsIn)
4680 public override bool isTemporal => true ;
4781 public override bool supportsSharpening => true ;
4882
83+ public override IUpscalerContext CreateContext ( UpscalerOptions options , Vector2Int displayResolution )
84+ {
85+ return new STPUpscalerContext ( displayResolution ) ;
86+ }
87+
4988 public override void RecordRenderGraph ( RenderGraph renderGraph , ContextContainer frameData )
5089 {
5190 UpscalingIO io = frameData . Get < UpscalingIO > ( ) ;
5291
92+ // Get the per-camera context from UpscalingIO (set by the pipeline)
93+ var upscalerContext = io . context as STPUpscalerContext ;
94+ if ( upscalerContext == null )
95+ {
96+ Debug . LogWarning ( "STPIUpscaler: No valid context provided via io.context. Skipping upscaling." ) ;
97+ return ;
98+ }
99+
53100 // Create an output texture
54101 TextureHandle outputColor ;
55102 {
@@ -104,17 +151,17 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
104151
105152 config . destination = outputColor ;
106153
107- Debug . Assert ( io . eyeIndex < m_Histories . Length ) ;
154+ // Use the per-camera history context
108155 bool hasValidHistory ;
109156 {
110157 STP . HistoryUpdateInfo info ;
111158 info . preUpscaleSize = io . preUpscaleResolution ;
112159 info . postUpscaleSize = io . postUpscaleResolution ;
113160 info . useHwDrs = io . enableHwDrs ;
114161 info . useTexArray = io . enableTexArray ;
115- hasValidHistory = m_Histories [ io . eyeIndex ] . Update ( ref info ) ;
162+ hasValidHistory = upscalerContext . historyContext . Update ( ref info ) ;
116163 }
117- config . historyContext = m_Histories [ io . eyeIndex ] ;
164+ config . historyContext = upscalerContext . historyContext ;
118165 config . enableHwDrs = io . enableHwDrs ;
119166 config . hasValidHistory = ! io . resetHistory && hasValidHistory ;
120167
@@ -124,7 +171,7 @@ public override void RecordRenderGraph(RenderGraph renderGraph, ContextContainer
124171 Debug . Assert ( io . numActiveViews <= STP . perViewConfigs . Length ) ;
125172 for ( int viewIndex = 0 ; viewIndex < io . numActiveViews ; ++ viewIndex )
126173 {
127- int targetIndex = viewIndex + io . eyeIndex ;
174+ int targetIndex = viewIndex ;
128175
129176 STP . PerViewConfig perViewConfig ;
130177
0 commit comments