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.

feat(native): the Windows desktop host renders — verified on a real GPU

esengine58ae0468fe6c
diff --git a/build-tools/utils/nativeTemplate.js b/build-tools/utils/nativeTemplate.js
index af80409dc..40db80775 100644
--- a/build-tools/utils/nativeTemplate.js
+++ b/build-tools/utils/nativeTemplate.js
@@ -38,6 +38,21 @@ export const BYTECODE_FILE = 'esengine.native.qjsbc';
*/
export const DEFAULT_ICON = 'icon.png';
+/**
+ * The HLSL compiler Dawn's D3D backend loads before it can create a device.
+ *
+ * It ships WITH the game rather than being taken from System32: Dawn's own note
+ * says the OS copy has functionality and heap-corruption bugs on older Windows,
+ * so a game carries the SDK's. Dawn looks beside the executable first.
+ */
+export const D3D_COMPILER = 'd3dcompiler_47.dll';
+
+/** Where the Windows SDK keeps the redistributable D3D compiler, newest first. */
+function windowsSdkD3DRedist() {
+ const root = 'C:/Program Files (x86)/Windows Kits/10/Redist/D3D/x64';
+ return existsSync(path.join(root, D3D_COMPILER)) ? path.join(root, D3D_COMPILER) : null;
+}
+
/**
* A template's id: ONE per platform.
*
@@ -122,6 +137,12 @@ export function templateLayout(platform, options = {}) {
rel: 'Info.plist.in',
from: (ctx) => path.join(ctx.root, 'native', 'desktop', 'Info.plist.in'),
}] : []),
+ // Required to create a device at all, so a template without it produces
+ // an app that opens and immediately reports a lost device.
+ ...(platform === 'windows' ? [{
+ rel: D3D_COMPILER, releaseRequired: true, optional: true,
+ from: () => windowsSdkD3DRedist(),
+ }] : []),
{ rel: DEFAULT_ICON, from: (ctx) => path.join(ctx.root, 'native', 'icon.png') },
];
}
@@ -435,5 +456,7 @@ export function desktopTemplateSources(dir, platform = 'macos') {
infoPlistIn: path.join(dir, 'Info.plist.in'),
icon: path.join(dir, DEFAULT_ICON),
bytecode: path.join(dir, BYTECODE_FILE),
+ /** Windows only; absent elsewhere. */
+ d3dCompiler: path.join(dir, D3D_COMPILER),
};
}
diff --git a/desktop/tests/desktop-app.test.ts b/desktop/tests/desktop-app.test.ts
index 8a0932b13..d0bc212a8 100644
--- a/desktop/tests/desktop-app.test.ts
+++ b/desktop/tests/desktop-app.test.ts
@@ -154,8 +154,20 @@ describe('the layout table is the only thing that names files', () => {
it('describes the macOS template the assembler reads', () => {
const rels = templateLayout('macos').map((e: { rel: string }) => e.rel);
const sources = desktopTemplateSources('T');
- for (const file of Object.values(sources)) {
+ for (const [key, file] of Object.entries(sources)) {
+ // The D3D compiler is Windows-only; macOS has no counterpart.
+ if (key === 'd3dCompiler') continue;
expect(rels).toContain(path.relative('T', file as string));
}
});
+
+ it('carries the HLSL compiler on Windows, without which no device is created', () => {
+ const rels = templateLayout('windows').map((e: { rel: string }) => e.rel);
+ expect(rels).toContain('d3dcompiler_47.dll');
+ expect(rels).toContain('estella_desktop.exe');
+ // No Info.plist: a bundle description is macOS's, and an entry every
+ // consumer has to check for is worse than a layout that differs where the
+ // platforms do.
+ expect(rels).not.toContain('Info.plist.in');
+ });
});