Skip to content

Comments

fix: compressed texture unit test#1290

Merged
yiiqii merged 1 commit intofeat/2.8from
fix/texture-unit-test
Nov 27, 2025
Merged

fix: compressed texture unit test#1290
yiiqii merged 1 commit intofeat/2.8from
fix/texture-unit-test

Conversation

@ChengYi996
Copy link
Collaborator

@ChengYi996 ChengYi996 commented Nov 27, 2025

Summary by CodeRabbit

Release Notes

  • New Features

    • KTX2 compressed texture handling improved with explicit linear filtering applied to magnification and minification operations, ensuring enhanced visual quality and consistent rendering.
  • Tests

    • Test suite updated with comprehensive KTX2 loader integration to ensure robust texture handling and compatibility.
  • Chores

    • Build configuration enhanced with WebAssembly support for improved development capabilities.

✏️ Tip: You can customize this high-level summary in your review settings.

@ChengYi996 ChengYi996 requested a review from yiiqii November 27, 2025 04:37
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 27, 2025

Walkthrough

The changes extend KTX2 compressed texture loading by adding explicit linear filtering configuration (minFilter and magFilter set to glContext.LINEAR) to the TextureSourceOptions returned when loading KTX2 textures. Test fixtures are updated to reflect a new ASTC 4x4 compression format with adjusted texture dimensions (2048x2048) and mipmap counts (1 instead of 10). Build configuration adds wasm plugin support to the test environment.

Changes

Cohort / File(s) Summary
KTX2 Texture Configuration
packages/effects-core/src/texture/texture-factory.ts
Added minFilter and magFilter properties to TextureSourceOptions for KTX2 compressed textures, both set to glContext.LINEAR.
Test Updates
web-packages/test/unit/src/effects-webgl/gl-texture.spec.ts
Integrated KTX2 loader registration; updated ASTC compression format from 6x6 (constant 37812) to 4x4 (37808); revised texture metadata expectations from 512x512/10 mipmaps to 2048x2048/1 mipmap; updated related memory calculations and assertions.
Build Configuration
web-packages/test/vite.config.js
Added wasm plugin to Vite configuration with targetEnv set to auto-inline; imported wasm from rollup-config-helper.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Verify all ASTC format constant replacements (37812 → 37808) are consistently applied across all test assertions
  • Cross-check memory calculation logic updates for 4x4 ASTC format consistency with width/height chunk sizes
  • Confirm KTX2 loader registration and unregistration calls are properly paired and scoped within test boundaries
  • Validate that minFilter and magFilter additions to TextureSourceOptions don't introduce breaking changes in downstream consumers

Poem

🐰 Textures now filter oh so fine,
With LINEAR modes in perfect line,
Four by four, a smaller tile,
Tests reorient with stoic style.
Build tools wasm, set to bloom—
Compressed textures claim their room! 🎨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title describes fixing compressed texture unit tests, which aligns with the primary changes involving KTX2 loader integration and ASTC format updates in test files.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/texture-unit-test

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
web-packages/test/unit/src/effects-webgl/gl-texture.spec.ts (1)

1-60: Avoid test-order coupling for KTX2 loader registration

registerKTX2Loader(0) is only called in the "load 2d astc ktx file" test, but "upload 2d astc" also relies on the KTX2 loader being registered. Running the second test in isolation (e.g. with it.only) or reordering tests would break that assumption.

I’d move loader setup/teardown to the suite hooks so all KTX2-related tests are independent:

   before(() => {
     canvas = document.createElement('canvas');
     engine = new GLEngine(canvas, { glType: 'webgl' });
     renderer = engine.renderer as GLRenderer;
     gl = renderer.context.gl as WebGLRenderingContext;
+    registerKTX2Loader(0);
   });

   after(() => {
     // runs once after the last test in this block
     engine.dispose();
@@
-    // @ts-expect-error
-    gl = null;
+    // @ts-expect-error
+    gl = null;
+    // keep texture loader registry clean for other suites
+    unregisterKTX2Loader();
   });
@@
-  it('load 2d astc ktx file', async () => {
-    registerKTX2Loader(0);
+  it('load 2d astc ktx file', async () => {

This keeps tests deterministic and avoids hidden dependencies between them.

Also applies to: 105-136

🧹 Nitpick comments (2)
web-packages/test/vite.config.js (1)

22-24: Configuration looks correct for test environment.

The wasm plugin with targetEnv: 'auto-inline' is appropriate for the test environment, as it embeds the WASM binary directly in the JavaScript bundle, making tests self-contained and portable. This aligns with the PR's goal of adding KTX2 compressed texture support to tests.

The comment on line 23 is redundant since it merely repeats the value. Consider removing it:

     wasm({
-      targetEnv: 'auto-inline', // auto-inline
+      targetEnv: 'auto-inline',
     }),
web-packages/test/unit/src/effects-webgl/gl-texture.spec.ts (1)

105-136: Replace magic number 37808 with the ASTC 4x4 constant / runtime value

In the "upload 2d astc" test you hard‑code 37808 in both the GPU info expectation and the memory calculation:

expect(gpuInfo).to.deep.equals(
-  [37808, 0, gl.TEXTURE_2D, [[2048, 2048]]]
+  [COMPRESSED_RGBA_ASTC_4x4_KHR, 0, gl.TEXTURE_2D, [[2048, 2048]]]
);

- memory += byteLengthForASTC(37808, mipmap[0], mipmap[1]);
+ memory += byteLengthForASTC(COMPRESSED_RGBA_ASTC_4x4_KHR, mipmap[0], mipmap[1]);

or alternatively:

const [internalFormat] = gpuInfo;

memory += byteLengthForASTC(internalFormat as number, mipmap[0], mipmap[1]);

Using the symbolic constant or the actual internalFormat keeps the test aligned if the format enum ever changes.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 330f077 and c08adcb.

📒 Files selected for processing (3)
  • packages/effects-core/src/texture/texture-factory.ts (1 hunks)
  • web-packages/test/unit/src/effects-webgl/gl-texture.spec.ts (5 hunks)
  • web-packages/test/vite.config.js (2 hunks)
🧰 Additional context used
🧠 Learnings (3)
📓 Common learnings
Learnt from: ChengYi996
Repo: galacean/effects-runtime PR: 1263
File: packages/effects-core/src/texture/ktx2/transcoder/binomial-workercode.ts:99-110
Timestamp: 2025-11-10T07:59:18.725Z
Learning: In packages/effects-core/src/texture/ktx2/transcoder/binomial-workercode.ts, the KTX2TargetFormat.ETC case in getTranscodeFormatFromTarget already handles ETC1 through the hasAlpha flag (returns BasisFormat.ETC1 when hasAlpha is false, BasisFormat.ETC2 when true), so a separate ETC1 case is not needed.
Learnt from: ChengYi996
Repo: galacean/effects-runtime PR: 1263
File: plugin-packages/ktx2/src/transcoder/buffer-reader.ts:105-113
Timestamp: 2025-11-25T02:19:43.276Z
Learning: The KTX2 texture format specification mandates little-endian byte order for all data fields, so KTX2 parsers and readers should always use little-endian interpretation.
📚 Learning: 2025-11-10T07:59:18.725Z
Learnt from: ChengYi996
Repo: galacean/effects-runtime PR: 1263
File: packages/effects-core/src/texture/ktx2/transcoder/binomial-workercode.ts:99-110
Timestamp: 2025-11-10T07:59:18.725Z
Learning: In packages/effects-core/src/texture/ktx2/transcoder/binomial-workercode.ts, the KTX2TargetFormat.ETC case in getTranscodeFormatFromTarget already handles ETC1 through the hasAlpha flag (returns BasisFormat.ETC1 when hasAlpha is false, BasisFormat.ETC2 when true), so a separate ETC1 case is not needed.

Applied to files:

  • packages/effects-core/src/texture/texture-factory.ts
  • web-packages/test/unit/src/effects-webgl/gl-texture.spec.ts
📚 Learning: 2025-11-25T02:19:43.276Z
Learnt from: ChengYi996
Repo: galacean/effects-runtime PR: 1263
File: plugin-packages/ktx2/src/transcoder/buffer-reader.ts:105-113
Timestamp: 2025-11-25T02:19:43.276Z
Learning: The KTX2 texture format specification mandates little-endian byte order for all data fields, so KTX2 parsers and readers should always use little-endian interpretation.

Applied to files:

  • web-packages/test/unit/src/effects-webgl/gl-texture.spec.ts
🧬 Code graph analysis (2)
packages/effects-core/src/texture/texture-factory.ts (1)
packages/effects-core/src/gl/index.ts (1)
  • glContext (8-8)
web-packages/test/unit/src/effects-webgl/gl-texture.spec.ts (1)
plugin-packages/ktx2/src/ktx2-loader.ts (1)
  • registerKTX2Loader (190-194)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
web-packages/test/vite.config.js (1)

4-4: LGTM! Wasm import added appropriately.

The addition of the wasm import is correct and necessary for enabling WASM-based KTX2 texture transcoding in the test environment.

packages/effects-core/src/texture/texture-factory.ts (1)

124-125: Based on the information provided in the review comment and the code snippet shown, let me provide the rewritten review comment:

Good defaults for compressed texture filtering; verify test passage.

Adding explicit minFilter: glContext.LINEAR and magFilter: glContext.LINEAR provides sensible defaults for KTX2 compressed textures. The placement before the ...config spread (line 127) correctly allows these defaults to be overridden by caller configuration, which is appropriate design.

Verify this resolves the unit test failures for compressed textures. Consider whether any use cases (pixel art, UI elements) might require NEAREST filtering—though those can override via config if needed.

web-packages/test/unit/src/effects-webgl/gl-texture.spec.ts (1)

622-629: ASTC 4×4 byte-size math looks correct

The updated helper

if (type === COMPRESSED_RGBA_ASTC_4x4_KHR) {
  return Math.floor((width + 3) / 4) * Math.floor((height + 3) / 4) * 16;
}

matches the ASTC 4×4 spec (4×4 blocks, 16 bytes per block) and is consistent with the new 2048×2048, single‑mip expectations. No issues from the test side.

@yiiqii yiiqii merged commit cd79cd2 into feat/2.8 Nov 27, 2025
2 checks passed
@yiiqii yiiqii deleted the fix/texture-unit-test branch November 27, 2025 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants