Skip to content

Commit 073428d

Browse files
committed
library: miuix-blur: clarify render-effect uniform-caching comments
Creation-time uniform capture makes a built effect safe to reuse; distinct shader keys keep concurrent passes/levels on separate instances. Reword so the two read as complementary, not contradictory. Comment-only, no behavior change.
1 parent d6e7c1c commit 073428d

3 files changed

Lines changed: 10 additions & 8 deletions

File tree

miuix-blur/src/commonMain/kotlin/top/yukonga/miuix/kmp/blur/BackdropEffectScope.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,9 @@ internal abstract class BackdropEffectScopeImpl :
163163
internal var cachedBlurResult: RenderEffect? = null
164164

165165
// blendColors()/colorControls() build RenderEffects that don't depend on the animating radius,
166-
// so cache them: a fixed tint/adjustment rebuilds once, not per frame. Reuse is safe because a
167-
// RenderEffect snapshots its shader's uniforms at creation (see LevelTarget.dsEffects).
166+
// so cache them: a fixed tint/adjustment rebuilds once, not per frame. A RenderEffect captures
167+
// its shader's uniforms when created, so a built effect is unaffected by later re-sets of the
168+
// tree-shared RuntimeShader — reuse across frames and both cross-fade passes is safe.
168169
internal var cachedBlendColors: BlurColors? = null
169170
internal var cachedBlendResult: RenderEffect? = null
170171
internal var cachedColorBrightness: Float = Float.NaN

miuix-blur/src/commonMain/kotlin/top/yukonga/miuix/kmp/blur/DrawBackdropModifier.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ private class DrawBackdropNode(
225225
var cascadeFirstStepScale: Int = 1
226226

227227
// Draw-path RenderEffects cached for reuse while the source size / noise coefficient hold.
228-
// A RenderEffect snapshots its shader's uniforms at creation, so reusing the instance is
229-
// safe and avoids a native allocation per frame. Two slots cover the deepest cascade (sf=16).
228+
// A RenderEffect captures its shader's uniforms when created, so a built instance is
229+
// unaffected by later re-sets of the tree-shared RuntimeShader — reuse is safe and saves a
230+
// native allocation per frame. Two slots cover the deepest cascade (sf=16).
230231
val dsKeys = arrayOf("", "")
231232
val dsW = intArrayOf(-1, -1)
232233
val dsH = intArrayOf(-1, -1)

miuix-blur/src/commonMain/kotlin/top/yukonga/miuix/kmp/blur/internal/BlurEffect.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ private val BLUR_V_KEYS: Array<Array<String>> = Array(MAX_BLUR_TAPS + 1) { n ->
3636
/**
3737
* Builds the separable Blur [RenderEffect] (H then V) for an EXPLICIT [downScale] level using the
3838
* per-axis variances already compensated for that level's box prefilter (see [adjustedVarianceForExp]).
39-
* The shader cache keys carry [downScale] so two adjacent levels rendered in the same frame (the
40-
* cross-fade lo/hi passes) never share a Gaussian shader instance and corrupt each other's kernel.
39+
* The shader cache keys carry [downScale] so the H/V passes and the cross-fade lo/hi levels each
40+
* build from a separate shader instance and never alias each other's uniform arrays.
4141
*/
4242
internal fun createBlurEffect(
4343
radiusX: Float,
@@ -64,8 +64,8 @@ internal fun createBlurEffect(
6464

6565
var effect: RenderEffect? = null
6666

67-
// H / V use distinct cache keys so each pass holds its own uniform state; the _d$downScale
68-
// suffix additionally isolates the cross-fade lo/hi levels from one another.
67+
// H / V use distinct cache keys so each pass builds from its own shader instance; the
68+
// _d$downScale suffix additionally isolates the cross-fade lo/hi levels from one another.
6969
if (radiusX > 0f) {
7070
val n = computeBlurParamsInto(adjustedVarianceX, rawScratch, paramOffsets, paramWeights)
7171
if (n > 0) {

0 commit comments

Comments
 (0)