A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
test(assets): hold the bytes Bistro-grade textures cost to move
yhhb38d9fde2f2a
diff --git a/pipeline/tests/fixtures/bistro-crops/Antenna_Metal_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/Antenna_Metal_BaseColor.pngnew file mode 100644index 000000000..b7729137aBinary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Antenna_Metal_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/Balcony_Green_Wood_Normal.png b/pipeline/tests/fixtures/bistro-crops/Balcony_Green_Wood_Normal.pngnew file mode 100644index 000000000..67a107cabBinary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Balcony_Green_Wood_Normal.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/Concrete2_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/Concrete2_BaseColor.pngnew file mode 100644index 000000000..624608005Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Concrete2_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/Foliage_Bux_Hedges46_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/Foliage_Bux_Hedges46_BaseColor.pngnew file mode 100644index 000000000..afa865bb2Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Foliage_Bux_Hedges46_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/Foliage_Paris_Flowers_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/Foliage_Paris_Flowers_BaseColor.pngnew file mode 100644index 000000000..6b93bab8fBinary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Foliage_Paris_Flowers_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/MASTER_Bistro_Main_Door_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/MASTER_Bistro_Main_Door_BaseColor.pngnew file mode 100644index 000000000..e8e4cdf55Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/MASTER_Bistro_Main_Door_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/MASTER_Bronze_BLENDSHADER_Normal.png b/pipeline/tests/fixtures/bistro-crops/MASTER_Bronze_BLENDSHADER_Normal.pngnew file mode 100644index 000000000..25f252ba5Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/MASTER_Bronze_BLENDSHADER_Normal.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/MASTER_Concrete_Smooth_BLENDSHADER_Normal.png b/pipeline/tests/fixtures/bistro-crops/MASTER_Concrete_Smooth_BLENDSHADER_Normal.pngnew file mode 100644index 000000000..bdafd845fBinary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/MASTER_Concrete_Smooth_BLENDSHADER_Normal.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/MASTER_Focus_Glass_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/MASTER_Focus_Glass_BaseColor.pngnew file mode 100644index 000000000..adecbebdfBinary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/MASTER_Focus_Glass_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/MASTER_Grain_Metal_Normal.png b/pipeline/tests/fixtures/bistro-crops/MASTER_Grain_Metal_Normal.pngnew file mode 100644index 000000000..8b087ba3bBinary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/MASTER_Grain_Metal_Normal.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/MASTER_Interior_01_Paris_Lantern_Normal.png b/pipeline/tests/fixtures/bistro-crops/MASTER_Interior_01_Paris_Lantern_Normal.pngnew file mode 100644index 000000000..f8dc7df8aBinary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/MASTER_Interior_01_Paris_Lantern_Normal.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/MASTER_Plastic_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/MASTER_Plastic_BaseColor.pngnew file mode 100644index 000000000..28c683512Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/MASTER_Plastic_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/MASTER_Wood_Brown_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/MASTER_Wood_Brown_BaseColor.pngnew file mode 100644index 000000000..749c94ab2Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/MASTER_Wood_Brown_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/MenuSign_02_Glass_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/MenuSign_02_Glass_BaseColor.pngnew file mode 100644index 000000000..15c9692a7Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/MenuSign_02_Glass_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/NOTICE.md b/pipeline/tests/fixtures/bistro-crops/NOTICE.mdnew file mode 100644index 000000000..4ec175d40--- /dev/null+++ b/pipeline/tests/fixtures/bistro-crops/NOTICE.md@@ -0,0 +1,9 @@+# Bistro texture crops++256x256 crops (offset 896,896) of 24 of the 2048px textures in Amazon Lumberyard+Bistro v5.2 from NVIDIA ORCA, https://developer.nvidia.com/orca/amazon-lumberyard-bistro.+Licensed CC-BY 4.0; (c) Amazon Lumberyard, distributed by NVIDIA. The crops were decoded from+the original DDS and re-encoded as PNG; no other change.++They are what `texture-supercompression.test.ts` cooks, to hold the bytes a large+project's textures cost to move.diff --git a/pipeline/tests/fixtures/bistro-crops/Paris_Cashregister_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/Paris_Cashregister_BaseColor.pngnew file mode 100644index 000000000..82a8ec538Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Paris_Cashregister_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/Paris_Coasters_01_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/Paris_Coasters_01_BaseColor.pngnew file mode 100644index 000000000..d1543f281Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Paris_Coasters_01_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/Paris_Radiator_Normal.png b/pipeline/tests/fixtures/bistro-crops/Paris_Radiator_Normal.pngnew file mode 100644index 000000000..861eda89eBinary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Paris_Radiator_Normal.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/Paris_Wall_Light_Interior_Emissive.png b/pipeline/tests/fixtures/bistro-crops/Paris_Wall_Light_Interior_Emissive.pngnew file mode 100644index 000000000..372bed382Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Paris_Wall_Light_Interior_Emissive.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/Pavement_Cobblestone_Wet_BLENDSHADER_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/Pavement_Cobblestone_Wet_BLENDSHADER_BaseColor.pngnew file mode 100644index 000000000..d2df18b28Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Pavement_Cobblestone_Wet_BLENDSHADER_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/Plants_plants_Normal.png b/pipeline/tests/fixtures/bistro-crops/Plants_plants_Normal.pngnew file mode 100644index 000000000..fc0a05b38Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Plants_plants_Normal.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/Shopsign_Book_Store_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/Shopsign_Book_Store_BaseColor.pngnew file mode 100644index 000000000..ec63fe313Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Shopsign_Book_Store_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/Spotlight_Emissive_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/Spotlight_Emissive_BaseColor.pngnew file mode 100644index 000000000..4b70aae6aBinary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Spotlight_Emissive_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/ToffeeJar_Label_BaseColor.png b/pipeline/tests/fixtures/bistro-crops/ToffeeJar_Label_BaseColor.pngnew file mode 100644index 000000000..00bab8ccbBinary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/ToffeeJar_Label_BaseColor.png differdiff --git a/pipeline/tests/fixtures/bistro-crops/Vespa_Headlight_Normal.png b/pipeline/tests/fixtures/bistro-crops/Vespa_Headlight_Normal.pngnew file mode 100644index 000000000..532620712Binary files /dev/null and b/pipeline/tests/fixtures/bistro-crops/Vespa_Headlight_Normal.png differdiff --git a/pipeline/tests/texture-supercompression.test.ts b/pipeline/tests/texture-supercompression.test.tsnew file mode 100644index 000000000..88687f417--- /dev/null+++ b/pipeline/tests/texture-supercompression.test.ts@@ -0,0 +1,57 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * What a large project's textures cost to move: the bytes the cook ships for real+ * photographic art, not for flat fills a compressor flatters.+ *+ * The fixtures are 256px crops of 24 of Amazon Lumberyard Bistro's 2048px textures+ * (ORCA, CC-BY 4.0 — see the NOTICE beside them), BaseColor and Normal alike. The whole+ * scene's textures are ~1.3GB through the editor protocol, so the bytes each one costs+ * is what opening it waits on.+ */+import { describe, it, expect } from 'vitest';+import { mkdtempSync, readFileSync, readdirSync, rmSync } from 'node:fs';+import { tmpdir } from 'node:os';+import path from 'node:path';+import { fileURLToPath } from 'node:url';+import { cookTexture, loadTextureEncoder } from '../src/assets/textureCook';+import { readKtx2Layout } from '../src/assets/ktx2Mips';++const DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), 'fixtures/bistro-crops');+const SCHEME_ZSTD = 2;++/** What the 24 crops cost under zstd, measured; the budget is this plus headroom for an encoder update. */+const MEASURED_ZSTD_BYTES = 1111520;+const HEADROOM = 1.03;++describe('Bistro texture crops, cooked as a build ships them', () => {+ it('ship under zstd, within the byte budget, and decode to the pixels plain UASTC gives', async () => {+ const files = readdirSync(DIR).filter((f) => f.endsWith('.png')).sort();+ expect(files).toHaveLength(24);+ const encoder = await loadTextureEncoder();+ const root = mkdtempSync(path.join(tmpdir(), 'estella-supercompress-'));+ let shipped = 0, plainBytes = 0;+ try {+ for (const f of files) {+ const png = new Uint8Array(readFileSync(path.join(DIR, f)));+ const cooked = await cookTexture({+ root, path: `t/${f}`, data: png, ext: '.png', importer: { compress: 'on' },+ encoder, compressTextures: true, atlasTextures: false, drawnIn3D: false,+ });+ expect(cooked.ext, f).toBe('.ktx2');+ const layout = readKtx2Layout(cooked.data)!;+ expect(layout.scheme, `${f} ships without zstd`).toBe(SCHEME_ZSTD);+ const plain = await encoder.module.encodeToKtx2({ type: encoder.module.ImageType.PNG, data: png },+ { mode: 'uastc', srgb: layout.srgb });+ const [a, b] = await Promise.all([encoder.module.transcodeKtx2ToRgba(cooked.data), encoder.module.transcodeKtx2ToRgba(plain)]);+ expect(Buffer.from(a.pixels).equals(Buffer.from(b.pixels)), `${f} decodes differently under zstd`).toBe(true);+ shipped += cooked.data.length;+ plainBytes += plain.length;+ }+ } finally {+ rmSync(root, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });+ }+ console.log(`bistro crops: ${shipped} bytes under zstd, ${plainBytes} plain (${((1 - shipped / plainBytes) * 100).toFixed(1)}% saved)`);+ expect(shipped).toBeLessThanOrEqual(MEASURED_ZSTD_BYTES * HEADROOM);+ }, 120000);+});