@@ -9,7 +9,20 @@ use crate::shared::LightType;
99
1010use super :: POINT_COOKIE_FACE_COUNT ;
1111
12- /// One requested light-cookie source assigned to an atlas layer.
12+ /// Fallback metadata row for white cookie sampling.
13+ pub ( super ) const LIGHT_COOKIE_FALLBACK_RECT_INDEX : u32 = 0 ;
14+ /// Maximum resident 2D cookies.
15+ pub ( super ) const COOKIE_2D_RECT_CAP : u32 = 64 ;
16+ /// Maximum resident point-light cookie cubemaps.
17+ pub ( super ) const POINT_COOKIE_CUBEMAP_CAP : u32 = 16 ;
18+ /// First metadata row reserved for point-light cubemap face cookies.
19+ pub ( super ) const POINT_COOKIE_RECT_BASE : u32 =
20+ LIGHT_COOKIE_FALLBACK_RECT_INDEX + 1 + COOKIE_2D_RECT_CAP ;
21+ /// Total light-cookie metadata rows bound for all atlas kinds.
22+ pub ( super ) const LIGHT_COOKIE_RECT_CAPACITY : usize =
23+ ( POINT_COOKIE_RECT_BASE + POINT_COOKIE_CUBEMAP_CAP * POINT_COOKIE_FACE_COUNT ) as usize ;
24+
25+ /// One requested light-cookie source assigned to atlas metadata rows.
1326#[ derive( Clone , Copy , Debug ) ]
1427pub ( super ) struct LightCookieRequest {
1528 /// Packed host texture handle.
@@ -18,7 +31,7 @@ pub(super) struct LightCookieRequest {
1831 pub ( super ) asset_id : i32 ,
1932 /// Unpacked host texture kind.
2033 pub ( super ) kind : HostTextureAssetKind ,
21- /// 2D atlas layer or first point face layer .
34+ /// 2D atlas rect index or first point face rect index .
2235 pub ( super ) layer : u32 ,
2336}
2437
@@ -37,10 +50,10 @@ pub(super) struct LightCookieAssignment {
3750 pub ( super ) wrap_bits : u32 ,
3851}
3952
40- /// Atlas slot state for a packed host texture handle.
53+ /// Atlas metadata slot state for a packed host texture handle.
4154#[ derive( Clone , Copy , Debug ) ]
4255struct LightCookieSlot {
43- /// Atlas layer assigned to this packed handle.
56+ /// Atlas metadata row assigned to this packed handle.
4457 layer : u32 ,
4558 /// Whether this slot is referenced by the current frame's packed lights.
4659 requested_this_frame : bool ,
@@ -89,12 +102,7 @@ impl LightCookieAtlasState {
89102 }
90103
91104 /// Assigns a cookie atlas binding for one resolved light.
92- pub ( super ) fn assign (
93- & mut self ,
94- assignment : LightCookieAssignment ,
95- two_d_layers : u32 ,
96- point_layers : u32 ,
97- ) -> LightCookieBinding {
105+ pub ( super ) fn assign ( & mut self , assignment : LightCookieAssignment ) -> LightCookieBinding {
98106 match ( assignment. light_type , assignment. kind ) {
99107 (
100108 LightType :: Spot ,
@@ -105,7 +113,6 @@ impl LightCookieAtlasState {
105113 assignment. packed_id ,
106114 assignment. asset_id ,
107115 assignment. kind ,
108- two_d_layers,
109116 LIGHT_COOKIE_KIND_SPOT_2D ,
110117 assignment. wrap_bits ,
111118 ) ,
@@ -118,35 +125,30 @@ impl LightCookieAtlasState {
118125 assignment. packed_id ,
119126 assignment. asset_id ,
120127 assignment. kind ,
121- two_d_layers,
122128 LIGHT_COOKIE_KIND_DIRECTIONAL_2D ,
123129 assignment. wrap_bits ,
124130 ) ,
125- ( LightType :: Point , HostTextureAssetKind :: Cubemap ) => self . assign_point (
126- assignment. packed_id ,
127- assignment. asset_id ,
128- assignment. kind ,
129- point_layers,
130- ) ,
131+ ( LightType :: Point , HostTextureAssetKind :: Cubemap ) => {
132+ self . assign_point ( assignment. packed_id , assignment. asset_id , assignment. kind )
133+ }
131134 _ => LightCookieBinding :: NONE ,
132135 }
133136 }
134137
135- /// Assigns a 2D cookie layer .
138+ /// Assigns a 2D cookie metadata row .
136139 fn assign_2d (
137140 & mut self ,
138141 packed_id : i32 ,
139142 asset_id : i32 ,
140143 kind : HostTextureAssetKind ,
141- layers : u32 ,
142144 cookie_kind : u32 ,
143145 wrap_bits : u32 ,
144146 ) -> LightCookieBinding {
145147 let Some ( layer) = assign_cookie_layer (
146148 & mut self . two_d_slots ,
147149 packed_id,
148- 1 ,
149- layers ,
150+ LIGHT_COOKIE_FALLBACK_RECT_INDEX + 1 ,
151+ POINT_COOKIE_RECT_BASE ,
150152 1 ,
151153 & mut self . two_d_overflow_logged ,
152154 "2D" ,
@@ -171,19 +173,18 @@ impl LightCookieAtlasState {
171173 }
172174 }
173175
174- /// Assigns six 2D-array layers for a point-light cubemap cookie.
176+ /// Assigns six metadata rows for a point-light cubemap cookie.
175177 fn assign_point (
176178 & mut self ,
177179 packed_id : i32 ,
178180 asset_id : i32 ,
179181 kind : HostTextureAssetKind ,
180- layers : u32 ,
181182 ) -> LightCookieBinding {
182183 let Some ( layer) = assign_cookie_layer (
183184 & mut self . point_slots ,
184185 packed_id,
185- 1 ,
186- layers ,
186+ POINT_COOKIE_RECT_BASE ,
187+ LIGHT_COOKIE_RECT_CAPACITY as u32 ,
187188 POINT_COOKIE_FACE_COUNT ,
188189 & mut self . point_overflow_logged ,
189190 "point" ,
@@ -219,7 +220,7 @@ impl LightCookieAtlasState {
219220 }
220221}
221222
222- /// Assigns or reuses one atlas layer block.
223+ /// Assigns or reuses one atlas metadata row block.
223224fn assign_cookie_layer (
224225 slots : & mut HashMap < i32 , LightCookieSlot > ,
225226 packed_id : i32 ,
0 commit comments