Skip to content

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.

fix(render): a compressed texture reaches the WebGPU backend

esengine24f9b94c0024
diff --git a/desktop/src/engine/EngineHost.ts b/desktop/src/engine/EngineHost.ts
index c42d2d2d0..591b845f6 100644
--- a/desktop/src/engine/EngineHost.ts
+++ b/desktop/src/engine/EngineHost.ts
@@ -14,6 +14,7 @@ import {
installEditorGrid,
setEditorMode,
setPlayMode,
+ engineWebGPUFeatures,
} from 'esengine';
import type { App, ResourceDef, SubsystemStatus, SceneData, RenderSurfaceSource, FrameCosts } from 'esengine';
import type { ESEngineModule } from 'esengine/wasm';
@@ -602,12 +603,10 @@ class EngineHostImpl {
if (!gpu) throw new Error('WebGPU is not available in this renderer.');
const adapter = await gpu.requestAdapter();
if (!adapter) throw new Error('No WebGPU adapter available.');
- // Opt into timestamp-query when the adapter supports it, so the engine's GPU
- // timer can populate gpuMs/gpuScopes (matches the GL timer-query path). Absent
- // it, the WebGPU backend reports no GPU timing — same as before.
- const hasTimestamp = adapter.features?.has('timestamp-query') ?? false;
- const requiredFeatures = hasTimestamp ? ['timestamp-query'] : [];
- console.info(`[engine] webgpu timestamp-query: ${hasTimestamp ? 'enabled (GPU timing on)' : 'unavailable (no GPU timing)'}`);
+ // The engine says which optional features it uses; a device created without
+ // them refuses the work later, as a texture that never loaded.
+ const requiredFeatures = engineWebGPUFeatures(adapter);
+ console.info(`[engine] webgpu features: ${requiredFeatures.join(', ') || '(none available)'}`);
moduleArg.preinitializedWebGPUDevice = await adapter.requestDevice(
requiredFeatures.length ? { requiredFeatures } : undefined);
// Surface Dawn validation failures: without a listener an invalid draw is
diff --git a/docs/astro/src/data/apiStability.generated.json b/docs/astro/src/data/apiStability.generated.json
index 3c7d39d20..b28f30e4d 100644
--- a/docs/astro/src/data/apiStability.generated.json
+++ b/docs/astro/src/data/apiStability.generated.json
@@ -3,10 +3,10 @@
"counts": {
"public": 113,
"beta": 61,
- "experimental": 1510,
+ "experimental": 1513,
"deprecated": 3
},
- "total": 1684,
+ "total": 1687,
"subsystems": [
{
"id": "ecs",
diff --git a/sdk/etc/index.api.md b/sdk/etc/index.api.md
index f2ec97404..2f94a4110 100644
--- a/sdk/etc/index.api.md
+++ b/sdk/etc/index.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 113 public · 54 beta · 1395 experimental · 3 deprecated
+Symbols: 113 public · 54 beta · 1398 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -2604,6 +2604,11 @@ world: World
-1
```
+## ENGINE_WEBGPU_FEATURES — const @experimental
+```
+readonly ["texture-compression-astc", "texture-compression-bc", "texture-compression-etc2", "timestamp-query"]
+```
+
## EasingType — type @experimental
```
(typeof EasingType)[keyof typeof EasingType]
@@ -8590,6 +8595,11 @@ sideModules: SideModuleHost | undefined
ySortLayers: number | undefined
```
+## WebGPUAdapterLike — interface @experimental
+```
+features: { has(name: string): boolean; } | undefined
+```
+
## WeldJoint — const @experimental
```
ComponentDef<WeldJointData>
@@ -9488,6 +9498,11 @@ DragPlugin
(id: number, flags?: TileFlags): number
```
+## engineWebGPUFeatures — function @experimental
+```
+(adapter: WebGPUAdapterLike): string[]
+```
+
## ensureBtIds — function @experimental
```
(def: BtDefinition): BtDefinition
diff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.md
index 9c876cada..5e3908eb9 100644
--- a/sdk/etc/index.native.api.md
+++ b/sdk/etc/index.native.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.native
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 113 public · 59 beta · 1414 experimental · 3 deprecated
+Symbols: 113 public · 59 beta · 1417 experimental · 3 deprecated
## ABI_LAYOUT_HASH — const @experimental
```
@@ -2612,6 +2612,11 @@ world: World
-1
```
+## ENGINE_WEBGPU_FEATURES — const @experimental
+```
+readonly ["texture-compression-astc", "texture-compression-bc", "texture-compression-etc2", "timestamp-query"]
+```
+
## EasingType — type @experimental
```
(typeof EasingType)[keyof typeof EasingType]
@@ -8783,6 +8788,11 @@ sideModules: SideModuleHost | undefined
ySortLayers: number | undefined
```
+## WebGPUAdapterLike — interface @experimental
+```
+features: { has(name: string): boolean; } | undefined
+```
+
## WeldJoint — const @experimental
```
ComponentDef<WeldJointData>
@@ -9721,6 +9731,11 @@ DragPlugin
(id: number, flags?: TileFlags): number
```
+## engineWebGPUFeatures — function @experimental
+```
+(adapter: WebGPUAdapterLike): string[]
+```
+
## ensureBtIds — function @experimental
```
(def: BtDefinition): BtDefinition
diff --git a/sdk/etc/index.node.api.md b/sdk/etc/index.node.api.md
index 568b738ca..94e573a9e 100644
--- a/sdk/etc/index.node.api.md
+++ b/sdk/etc/index.node.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/index.node
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 113 public · 56 beta · 1394 experimental · 3 deprecated
+Symbols: 113 public · 56 beta · 1397 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -2599,6 +2599,11 @@ world: World
-1
```
+## ENGINE_WEBGPU_FEATURES — const @experimental
+```
+readonly ["texture-compression-astc", "texture-compression-bc", "texture-compression-etc2", "timestamp-query"]
+```
+
## EasingType — type @experimental
```
(typeof EasingType)[keyof typeof EasingType]
@@ -8585,6 +8590,11 @@ sideModules: SideModuleHost | undefined
ySortLayers: number | undefined
```
+## WebGPUAdapterLike — interface @experimental
+```
+features: { has(name: string): boolean; } | undefined
+```
+
## WeldJoint — const @experimental
```
ComponentDef<WeldJointData>
@@ -9483,6 +9493,11 @@ DragPlugin
(id: number, flags?: TileFlags): number
```
+## engineWebGPUFeatures — function @experimental
+```
+(adapter: WebGPUAdapterLike): string[]
+```
+
## ensureBtIds — function @experimental
```
(def: BtDefinition): BtDefinition
diff --git a/sdk/etc/minigame.api.md b/sdk/etc/minigame.api.md
index 15faebd51..76349d8b3 100644
--- a/sdk/etc/minigame.api.md
+++ b/sdk/etc/minigame.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/minigame
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 113 public · 54 beta · 1415 experimental · 3 deprecated
+Symbols: 113 public · 54 beta · 1418 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -2599,6 +2599,11 @@ world: World
-1
```
+## ENGINE_WEBGPU_FEATURES — const @experimental
+```
+readonly ["texture-compression-astc", "texture-compression-bc", "texture-compression-etc2", "timestamp-query"]
+```
+
## EasingType — type @experimental
```
(typeof EasingType)[keyof typeof EasingType]
@@ -8830,6 +8835,11 @@ sideModules: SideModuleHost | undefined
ySortLayers: number | undefined
```
+## WebGPUAdapterLike — interface @experimental
+```
+features: { has(name: string): boolean; } | undefined
+```
+
## WeldJoint — const @experimental
```
ComponentDef<WeldJointData>
@@ -9733,6 +9743,11 @@ DragPlugin
(id: number, flags?: TileFlags): number
```
+## engineWebGPUFeatures — function @experimental
+```
+(adapter: WebGPUAdapterLike): string[]
+```
+
## ensureBtIds — function @experimental
```
(def: BtDefinition): BtDefinition
diff --git a/sdk/etc/wasm.api.md b/sdk/etc/wasm.api.md
index 05db2206b..cdac0ff9b 100644
--- a/sdk/etc/wasm.api.md
+++ b/sdk/etc/wasm.api.md
@@ -144,6 +144,7 @@ valid: (entity: Entity) => boolean
## CppResourceManager — interface @experimental
```
acquireTextureByPath: (path: string) => number
+createCompressedTexture: ((width: number, height: number, format: number, dataPtr: number, dataLen: number, mipLevels: number) => number) | undefined
createLabelAtlasFont: (textureHandle: number, texWidth: number, texHeight: number, chars: string, charWidth: number, charHeight: number) => number
createShader: (vertSrc: string, fragSrc: string) => number
createTexture: (width: number, height: number, pixels: number, pixelsLen: number, format: number, flipY: boolean) => number
@@ -168,6 +169,7 @@ releaseTexture: (handle: number) => void
retargetExternalTexture: ((handle: number, glTextureId: number, width: number, height: number) => boolean) | undefined
setTextureBudget: (bytes: number) => void
setTextureMetadata: (handle: number, left: number, right: number, top: number, bottom: number) => void
+supportsCompressedFormat: ((format: number) => boolean) | undefined
trimTextureCache: () => number
updateTextureSubregion: (handle: number, x: number, y: number, width: number, height: number, pixels: number, pixelsLen: number) => void
updateTextureSubregionFromBytes: ((handle: number, x: number, y: number, width: number, height: number, pixels: Uint8Array) => void) | undefined
diff --git a/sdk/etc/wechat.api.md b/sdk/etc/wechat.api.md
index c3fce8c18..776592fe4 100644
--- a/sdk/etc/wechat.api.md
+++ b/sdk/etc/wechat.api.md
@@ -1,7 +1,7 @@
# API surface — esengine/wechat
<!-- Generated by tools/api-surface.mjs — do not edit. Run --update to accept changes. -->
-Symbols: 113 public · 54 beta · 1405 experimental · 3 deprecated
+Symbols: 113 public · 54 beta · 1408 experimental · 3 deprecated
## ANCHOR_AXES — const @experimental
```
@@ -2599,6 +2599,11 @@ world: World
-1
```
+## ENGINE_WEBGPU_FEATURES — const @experimental
+```
+readonly ["texture-compression-astc", "texture-compression-bc", "texture-compression-etc2", "timestamp-query"]
+```
+
## EasingType — type @experimental
```
(typeof EasingType)[keyof typeof EasingType]
@@ -8612,6 +8617,11 @@ sideModules: SideModuleHost | undefined
ySortLayers: number | undefined
```
+## WebGPUAdapterLike — interface @experimental
+```
+features: { has(name: string): boolean; } | undefined
+```
+
## WeldJoint — const @experimental
```
ComponentDef<WeldJointData>
@@ -9510,6 +9520,11 @@ DragPlugin
(id: number, flags?: TileFlags): number
```
+## engineWebGPUFeatures — function @experimental
+```
+(adapter: WebGPUAdapterLike): string[]
+```
+
## ensureBtIds — function @experimental
```
(def: BtDefinition): BtDefinition
diff --git a/sdk/src/asset/compressed.ts b/sdk/src/asset/compressed.ts
index d500f4b81..2992fbfd4 100644
--- a/sdk/src/asset/compressed.ts
+++ b/sdk/src/asset/compressed.ts
@@ -123,6 +123,37 @@ export function detectCompressedTextureSupport(gl: WebGL2RenderingContext): Comp
};
}
+/**
+ * The C++ `GfxCompressedFormat` ordinal for each target, as [unorm, sRGB].
+ *
+ * Asking the ENGINE which formats it samples is the only question both backends
+ * answer; WebGL extensions are one backend's answer, and on the other one that
+ * answer is "none", which is how a compressed texture became a white placeholder.
+ */
+const ENGINE_FORMAT_CODE: Record<CompressedTextureFormat, readonly [number, number]> = {
+ [CompressedTextureFormat.ETC2_RGBA8]: [1, 6],
+ [CompressedTextureFormat.ASTC_4x4]: [2, 7],
+ [CompressedTextureFormat.S3TC_DXT5]: [5, 8],
+};
+
+/** The engine's ordinal for `format` under the running colour pipeline. */
+export function engineFormatCode(format: CompressedTextureFormat, srgb: boolean): number {
+ return ENGINE_FORMAT_CODE[format][srgb ? 1 : 0];
+}
+
+/** Best target the ENGINE says it can sample, in quality/size order. */
+export function chooseEngineTargetFormat(
+ supports: (code: number) => boolean, srgb = false,
+): CompressedTextureFormat | null {
+ const order = [
+ CompressedTextureFormat.ASTC_4x4,
+ CompressedTextureFormat.ETC2_RGBA8,
+ CompressedTextureFormat.S3TC_DXT5,
+ ];
+ for (const f of order) if (supports(engineFormatCode(f, srgb))) return f;
+ return null;
+}
+
/**
* Best available target in quality/size order: ASTC > ETC2 > S3TC. null = none.
* With `srgb` (linear pipeline) a format only qualifies when its sRGB variant is
diff --git a/sdk/src/asset/loaders/TextureLoader.ts b/sdk/src/asset/loaders/TextureLoader.ts
index c12920be9..aaabaa9c8 100644
--- a/sdk/src/asset/loaders/TextureLoader.ts
+++ b/sdk/src/asset/loaders/TextureLoader.ts
@@ -8,7 +8,10 @@ import { decodeImageBitmap } from '../imageDecode';
import { requireResourceManager } from '../../wasm/resourceManager';
import type { ESEngineModule } from '../../wasm';
import { withMalloc } from '../../wasm/wasmScratch';
-import { isKtx2, isKtx2Path, loadCompressedTexture, type BasisTranscoder } from '../compressed';
+import {
+ isKtx2, isKtx2Path, loadCompressedTexture, chooseEngineTargetFormat, engineFormatCode,
+ type BasisTranscoder,
+} from '../compressed';
import { uploadBoundTextureImage, applyBoundTextureSampling } from '../glTextureUpload';
import { createTextureFromPixels, type TextureParams } from '../../runtime/runtimeAssets';
@@ -219,12 +222,17 @@ export class TextureLoader implements AssetLoader<TextureResult> {
if (!r) throw new Error(`TextureLoader: KTX2 transcode failed for ${path}`);
return { handle: r.handle, width: r.width, height: r.height };
}
- const gl = this.getWebGL2Context();
- if (!gl) throw new Error('TextureLoader: KTX2 textures require a WebGL2 context');
const transcoder = await this.ensureTranscoder_();
if (!transcoder) {
throw new Error('TextureLoader: no Basis transcoder available (basis side module missing — KTX2 assets need it)');
}
+ const gl = this.getWebGL2Context();
+ if (!gl) {
+ // No GL context (the WebGPU backend): ask the ENGINE which format it
+ // samples and upload through it. Sampler state is what the GL path
+ // below still has and this one does not — here it takes the defaults.
+ return this.loadCompressedViaEngine(path, transcoder, bytes);
+ }
// KTX2 payloads are color, like the PNG path: linear mode wants the
// sRGB variant of whatever compressed format the device supports.
// A WebGL2 context implies a wasm module (native has neither, and threw
@@ -234,6 +242,37 @@ export class TextureLoader implements AssetLoader<TextureResult> {
return { handle: r.handle, width: r.width, height: r.height };
}
+ /**
+ * KTX2 through the engine's own upload, for a backend with no GL context.
+ * Falls back to an RGBA decode when no compressed format is available or the
+ * transcode to it fails — the same bargain the GL path makes.
+ */
+ private async loadCompressedViaEngine(
+ path: string, transcoder: BasisTranscoder, bytes: Uint8Array,
+ ): Promise<TextureResult> {
+ const rm = requireResourceManager();
+ const module = this.module_;
+ const srgb = linearColorSpace();
+ if (module && rm.supportsCompressedFormat && rm.createCompressedTexture) {
+ const supports = rm.supportsCompressedFormat.bind(rm);
+ const target = chooseEngineTargetFormat((code) => supports(code), srgb);
+ if (target) {
+ const t = transcoder.transcode(bytes, target);
+ if (t) {
+ const code = engineFormatCode(target, srgb);
+ const handle = withMalloc(module, t.data.length, (ptr) => {
+ module.HEAPU8.set(t.data, ptr);
+ return rm.createCompressedTexture!(t.width, t.height, code, ptr, t.data.length, 1);
+ });
+ if (handle) return { handle, width: t.width, height: t.height };
+ }
+ }
+ }
+ const rgba = transcoder.transcodeToRgba(bytes);
+ if (!rgba) throw new Error(`TextureLoader: KTX2 decode failed for ${path}`);
+ return this.loadFromPixels(rgba.width, rgba.height, rgba.data, false);
+ }
+
/**
* Decode `src` into a GPU-uploadable source. When `createImageBitmap` is
* available we bake the vertical orientation into the bitmap here via
diff --git a/sdk/src/core-render.ts b/sdk/src/core-render.ts
index 68e7ab9b5..140a9e78b 100644
--- a/sdk/src/core-render.ts
+++ b/sdk/src/core-render.ts
@@ -186,6 +186,18 @@ export {
*
* @beta Pre-1.0: the frame-advance callback may become a schedule hook.
*/
+/**
+ * What a WebGPU device has to be created with for the engine to use everything
+ * it ships — compressed textures above all.
+ *
+ * @beta
+ */
+export {
+ ENGINE_WEBGPU_FEATURES,
+ engineWebGPUFeatures,
+ type WebGPUAdapterLike,
+} from './render/webgpuFeatures';
+
export {
captureFramePixels,
canCaptureFramePixels,
diff --git a/sdk/src/render/webgpuFeatures.ts b/sdk/src/render/webgpuFeatures.ts
new file mode 100644
index 000000000..81c0d8749
--- /dev/null
+++ b/sdk/src/render/webgpuFeatures.ts
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
+/**
+ * @file What the engine needs a WebGPU device to be created with.
+ *
+ * A feature the adapter offers is unusable until the device asked for it,
+ * and the refusal arrives late and quietly: `createTexture` throws, the
+ * asset loader logs a warning, and the frame draws the white placeholder.
+ * So every host that acquires a device asks the same question here rather
+ * than each remembering its own list.
+ */
+
+/** Optional device features the engine uses when the adapter has them. */
+export const ENGINE_WEBGPU_FEATURES = [
+ // Compressed textures: the cook ships KTX2, and which family a device can
+ // sample decides what the transcoder targets.
+ 'texture-compression-astc',
+ 'texture-compression-bc',
+ 'texture-compression-etc2',
+ // GPU timing for the profiler; absent, the backend reports no GPU time.
+ 'timestamp-query',
+] as const;
+
+/** An adapter, as far as this needs to know it. */
+export interface WebGPUAdapterLike {
+ readonly features?: { has(name: string): boolean };
+}
+
+/** The subset of {@link ENGINE_WEBGPU_FEATURES} this adapter actually offers. */
+export function engineWebGPUFeatures(adapter: WebGPUAdapterLike): string[] {
+ return ENGINE_WEBGPU_FEATURES.filter((f) => adapter.features?.has(f) ?? false);
+}
diff --git a/sdk/src/wasm.ts b/sdk/src/wasm.ts
index 932ea1b45..a0527bc02 100644
--- a/sdk/src/wasm.ts
+++ b/sdk/src/wasm.ts
@@ -53,6 +53,13 @@ export interface CppResourceManager {
* format (or RGBA32). Native only (the basis transcoder lives in the host);
* the web KTX2 path is WebGL2 + the wasm transcoder instead. */
createTextureFromKTX2?(bytes: Uint8Array, srgb: boolean): { handle: number; width: number; height: number } | null;
+ /** Whether the ACTIVE backend samples this compressed format (the C++
+ * `GfxCompressedFormat` ordinal). Absent on an older wasm build. */
+ supportsCompressedFormat?(format: number): boolean;
+ /** Uploads pre-transcoded blocks (level 0 first) as one compressed texture,
+ * whichever backend is running. Absent on an older wasm build. */
+ createCompressedTexture?(width: number, height: number, format: number,
+ dataPtr: number, dataLen: number, mipLevels: number): number;
/** Module-free {@link updateTextureSubregion} — native byte upload for the
* glyph atlas, symmetric with {@link createTextureFromBytes}. */
updateTextureSubregionFromBytes?(handle: number, x: number, y: number, width: number, height: number, pixels: Uint8Array): void;
diff --git a/src/esengine/bindings/ResourceManagerBindings.cpp b/src/esengine/bindings/ResourceManagerBindings.cpp
index 671ec1a71..013db9637 100644
--- a/src/esengine/bindings/ResourceManagerBindings.cpp
+++ b/src/esengine/bindings/ResourceManagerBindings.cpp
@@ -11,6 +11,7 @@
#ifdef __EMSCRIPTEN__
#include <emscripten/val.h>
+#include "../renderer/rhi/GfxDevice.hpp"
#endif
namespace esengine {
@@ -84,6 +85,31 @@ u32 rm_createTextureEx(resource::ResourceManager& rm, u32 width, u32 height,
return handle.id();
}
+/**
+ * Whether the ACTIVE backend can sample this compressed format — the question
+ * WebGL extensions answer for one backend only, and answer with "none" for the
+ * other, which arrives as a texture that never loaded.
+ */
+bool rm_supportsCompressedFormat(resource::ResourceManager& rm, i32 format) {
+ auto* device = rm.device();
+ if (!device) return false;
+ if (format < 0 || format > static_cast<i32>(GfxCompressedFormat::S3TC_DXT5_SRGB)) return false;
+ return device->supportsCompressedFormat(static_cast<GfxCompressedFormat>(format));
+}
+
+/** Uploads pre-transcoded blocks (level 0 first) as one compressed texture. */
+u32 rm_createCompressedTexture(resource::ResourceManager& rm, u32 width, u32 height,
+ i32 format, uintptr_t dataPtr, u32 dataLen, u32 mipLevels) {
+ if (format < 0 || format > static_cast<i32>(GfxCompressedFormat::S3TC_DXT5_SRGB)) return 0;
+ const u8* data = boundarySpan<u8>(dataPtr, dataLen, "rm_createCompressedTexture");
+ if (!data) return 0;
+ auto handle = rm.createCompressedTexture(width, height,
+ static_cast<GfxCompressedFormat>(format),
+ ConstSpan<u8>(data, dataLen),
+ mipLevels ? mipLevels : 1);
+ return handle.id();
+}
+
u32 rm_createShader(resource::ResourceManager& rm,
const std::string& vertSrc, const std::string& fragSrc) {
auto handle = rm.createShader(vertSrc, fragSrc);
diff --git a/src/esengine/bindings/ResourceManagerBindings.hpp b/src/esengine/bindings/ResourceManagerBindings.hpp
index 1c35c7a5d..299521be5 100644
--- a/src/esengine/bindings/ResourceManagerBindings.hpp
+++ b/src/esengine/bindings/ResourceManagerBindings.hpp
@@ -25,6 +25,13 @@ u32 rm_createTextureEx(resource::ResourceManager& rm, u32 width, u32 height,
i32 filterMode, i32 wrapMode);
u32 rm_createShader(resource::ResourceManager& rm,
const std::string& vertSrc, const std::string& fragSrc);
+/** Whether the active backend samples this compressed format. */
+bool rm_supportsCompressedFormat(resource::ResourceManager& rm, i32 format);
+
+/** Uploads pre-transcoded blocks as one compressed texture. */
+u32 rm_createCompressedTexture(resource::ResourceManager& rm, u32 width, u32 height,
+ i32 format, uintptr_t dataPtr, u32 dataLen, u32 mipLevels);
+
u32 rm_registerExternalTexture(resource::ResourceManager& rm, u32 glTextureId,
u32 width, u32 height);
/** @brief Points an EXISTING texture handle at a freshly uploaded GPU object. */
diff --git a/src/esengine/bindings/WebSDKEntry.cpp b/src/esengine/bindings/WebSDKEntry.cpp
index 99b62fb7c..8f0202798 100644
--- a/src/esengine/bindings/WebSDKEntry.cpp
+++ b/src/esengine/bindings/WebSDKEntry.cpp
@@ -430,6 +430,8 @@ EMSCRIPTEN_BINDINGS(esengine_renderer) {
.function("createTexture", &esengine::rm_createTexture)
.function("createTextureEx", &esengine::rm_createTextureEx)
.function("createShader", &esengine::rm_createShader)
+ .function("supportsCompressedFormat", &esengine::rm_supportsCompressedFormat)
+ .function("createCompressedTexture", &esengine::rm_createCompressedTexture)
.function("registerExternalTexture", &esengine::rm_registerExternalTexture)
.function("registerExternalTextureSized", &esengine::rm_registerExternalTextureSized)
.function("retargetExternalTexture", &esengine::rm_retargetExternalTexture)
diff --git a/src/esengine/renderer/webgpu/WebGPUDevice.cpp b/src/esengine/renderer/webgpu/WebGPUDevice.cpp
index 0842c31c4..2240e6596 100644
--- a/src/esengine/renderer/webgpu/WebGPUDevice.cpp
+++ b/src/esengine/renderer/webgpu/WebGPUDevice.cpp
@@ -868,12 +868,11 @@ void WebGPUDevice::bindTexture(u32 slot, TextureHandle texture) {
bool WebGPUDevice::supportsCompressedFormat(GfxCompressedFormat format) {
if (toWGPUCompressedFormat(format) == WGPUTextureFormat_Undefined) return false;
- // Native: the host passes the adapter, so query it for real — and it requests
- // exactly the supported compression families at device creation, so "adapter
- // has" == "device can create". Without an adapter handle (the web WebGPU
- // build) assume the ETC2 core baseline.
- if (!adapter_) return toWGPUCompressedFormat(format) != WGPUTextureFormat_Undefined;
- return wgpuAdapterHasFeature(adapter_, compressionFeatureFor(format)) != 0;
+ if (!device_) return false;
+ // The DEVICE, not the adapter: a format the adapter offers is unusable until
+ // the device was created asking for its feature, and createTexture rejects it
+ // — which arrives as a texture that never loaded rather than as this answer.
+ return wgpuDeviceHasFeature(device_, compressionFeatureFor(format)) != 0;
}
// =============================================================================
diff --git a/src/esengine/resource/ResourceManager.hpp b/src/esengine/resource/ResourceManager.hpp
index cc18a15c0..22cee301f 100644
--- a/src/esengine/resource/ResourceManager.hpp
+++ b/src/esengine/resource/ResourceManager.hpp
@@ -109,6 +109,10 @@ public:
*/
void init(GfxDevice& device);
+ /** The device resources are created on, or null before {@link init}.
+ * Read by callers that must ASK the backend what it supports. */
+ GfxDevice* device() const { return device_; }
+
/**
* @brief Shuts down and releases all resources
*/
diff --git a/tools/renderScenes.mjs b/tools/renderScenes.mjs
index 209a11784..bb0c2b726 100644
--- a/tools/renderScenes.mjs
+++ b/tools/renderScenes.mjs
@@ -24,12 +24,12 @@ export const TIERS = ['pr', 'nightly'];
/**
* What still separates the second backend from the first. Measured where an
- * adapter exists, 50 of the 52 agree with their GL frames; the two that do not
- * come back as the white placeholder — a texture that never arrived rather than
- * a frame drawn wrong.
+ * adapter exists, 51 of the 52 agree with their GL frames. The one that does not
+ * uses a `#pragma switch` shader, and twin generation skips those: a permutation
+ * has no WGSL to run, so the material never compiles on this backend.
*/
-export const WEBGPU_GAP = 'no adapter on a CI runner; with one, 50/52 pass — ktx2 and '
- + 'material-switch land the white placeholder, so a compressed texture does not reach this backend';
+export const WEBGPU_GAP = 'no adapter on a CI runner; with one, 51/52 pass — material-switch '
+ + 'needs WGSL twins for shader permutations, which gen-shader-twins does not emit';
/**
* Every pixel gate. `env` is handed to desktop/scripts/headless-verify.mjs
@@ -98,7 +98,7 @@ export const SCENES = [
// positioned Sprite (bottom-left anchor, tileset UV).
{ id: "tilemap-gidobj", tier: "pr", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/tilemap-gidobj.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/tilemap-gidobj.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "10", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":40},{\"x\":0.5,\"y\":0.12,\"rgb\":[0,0,0],\"tol\":30},{\"x\":0.8125,\"y\":0.375,\"rgb\":[0,0,255],\"tol\":40},{\"x\":0.9375,\"y\":0.375,\"rgb\":[255,255,0],\"tol\":40},{\"x\":0.875,\"y\":0.8125,\"rgb\":[0,0,255],\"tol\":40},{\"x\":0.875,\"y\":0.9375,\"rgb\":[255,255,0],\"tol\":40}]" } },
{ id: "material", tier: "nightly", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mat-tint.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mat-tint.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[255,0,0],\"tol\":40}]" } },
- { id: "ktx2", tier: "nightly", env: { ESTELLA_VERIFY_SCENE: "/scenes/ktx2-sprite.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/ktx2-sprite.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,180,0],\"tol\":50}]" } },
+ { id: "ktx2", tier: "nightly", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/ktx2-sprite.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/ktx2-sprite.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,180,0],\"tol\":50}]" } },
{ id: "material-instance", tier: "nightly", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mat-instance.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mat-instance.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":40}]" } },
{ id: "material-texture", tier: "nightly", webgpu: true, env: { ESTELLA_VERIFY_SCENE: "/scenes/mat-tex.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mat-tex.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.5,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":50}]" } },
{ id: "material-switch", tier: "nightly", env: { ESTELLA_VERIFY_SCENE: "/scenes/mat-sw.esscene", ESTELLA_VERIFY_MANIFEST: "/scenes/mat-sw.textures.json", ESTELLA_VERIFY_W: "256", ESTELLA_VERIFY_H: "256", ESTELLA_VERIFY_STEPS: "2", ESTELLA_VERIFY_EXPECT: "[{\"x\":0.25,\"y\":0.5,\"rgb\":[255,0,0],\"tol\":50},{\"x\":0.75,\"y\":0.5,\"rgb\":[0,255,0],\"tol\":50}]" } },