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
fix(render): seeding a material's samplers skips the ones a program optimized out, instead of warning of a typo for each
yhhd9d518946747
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex a12551165..307d17c57 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -90,6 +90,7 @@ published separately; it ships inside the editor.- **Lit materials draw on WebGPU again.** A lit material on the engine's own vertex stage, and a 2D lit shader, built a WebGPU program with a preprocessor line left in it, so the material drew nothing (and a desktop build of a 3D scene came up black). `#if` and `#elif` conditions with `defined`, `!`, `&&`, `||` and parentheses now resolve in a WGSL twin as they do in GLSL.- **A scanned preview reaches the game's own server.** The page a phone opens from the preview QR code allowed connections only to itself, so a game that logged in to a server on the LAN worked in Play and in a single-file build but not on the phone. The preview now connects as Play does; a shipping web export still connects only to the servers listed in Project Settings → Allowed server origins.- **The ground has no dark patches on a Mac.** With the depth prepass on (quality high and medium), a material written as a fragment shader alone, the terrain among them, drew its colour from a vertex stage that did not declare its position invariant, while its depth came from one that did. Metal is free to compute the two a bit apart, and wherever they differed the colour failed the equal-depth test: sand, sea floor and grass showed dark triangles. Both stages now declare it, on WebGL2 and WebGPU.+- **No "uniform not found" warnings for a texture a program does not read.** A material sets each of its textures on every program it is drawn with, and the depth program of a terrain or a lit material reads few of them, so opening a scene filled the log with warnings that read like typos. A texture a program does not use is now skipped quietly.- **A subpath of an official package resolves.** Importing `estella-plugin-…/something` from a project script no longer hangs the script build.- **Background shader compilation, the warm-up and on-demand drawing reach a build whose quality level is Off.** A build dropped the whole `quality` block when the level was Off, though these three choices hold whatever the level: a project that switched `asyncShaderCompile`, `prewarmShaders` or `renderOnDemand` on read them in the editor and shipped a game that ignored them. The block now ships when any of them is on.- **A terrain and a streamed world run on the Android and iOS templates.** The terrain's layer textures were refused on a device (it has no wasm heap to copy them through), and a chunked world's maker threw on every tick because QuickJS has no `AbortController`. The layers now go over as bytes, as every other texture does, and the world uses a handle of its own where the host has none.diff --git a/src/esengine/renderer/store/MaterialStore.cpp b/src/esengine/renderer/store/MaterialStore.cppindex 467736358..5db437d8c 100644--- a/src/esengine/renderer/store/MaterialStore.cpp+++ b/src/esengine/renderer/store/MaterialStore.cpp@@ -373,10 +373,13 @@ void MaterialStore::seedSamplers(Shader& shader, const resource::ParsedShader& pseeds.emplace_back(p.name, static_cast<i32>(p.textureUnit));}}- // After the program links, which for one made with deferLink is when something first needs it.+ // After the program links, which for one made with deferLink is when something first needs it. Every variant gets the material's+ // whole list, and one that does not read a texture (a depth program, most of all) has had it optimized out: that is not a typo.shader.whenLinked([seeds = std::move(seeds)](Shader& s) {s.bind();- for (const auto& [name, unit] : seeds) s.setUniform(name, unit);+ for (const auto& [name, unit] : seeds) {+ if (s.hasUniform(name)) s.setUniform(name, unit);+ }s.unbind();});}diff --git a/tests/renderer/MockGfxDevice.hpp b/tests/renderer/MockGfxDevice.hppindex 902e16987..657da6216 100644--- a/tests/renderer/MockGfxDevice.hpp+++ b/tests/renderer/MockGfxDevice.hpp@@ -10,6 +10,7 @@#include <cstring>#include <array>+#include <string>#include <vector>namespace esengine {@@ -51,6 +52,8 @@ struct MockGfxDevice final : GfxDevice {void backendDeleteCompute(u32) override { ++deleteComputeCalls; }bool backendDispatchCompute(u32, const GfxComputeBinding*, u32, u32, u32, u32) override { ++dispatchComputeCalls; return true; }int deleteProgramCalls = 0;+ /** Uniforms a compiler would have optimized out: no location. */+ std::vector<std::string> absentUniforms;int setUniform1iCalls = 0;int setUniform1fCalls = 0;int setUniform4fCalls = 0;@@ -288,7 +291,10 @@ protected:}void backendDeleteProgram(u32) override { ++deleteProgramCalls; }void backendUseProgram(u32 id) override { ++useProgramCalls; lastProgram = ShaderHandle{id}; }- i32 backendUniformLocation(u32, const char*) override { return 0; }+ i32 backendUniformLocation(u32, const char* name) override {+ for (const auto& absent : absentUniforms) if (absent == name) return -1;+ return 0;+ }i32 backendAttribLocation(u32, const char*) override { return 0; }void backendSetUniform(i32 location, const GfxUniformValue& value) override {switch (value.type) {diff --git a/tests/resource/test_material_shader_lifetime.cpp b/tests/resource/test_material_shader_lifetime.cppindex 0de30d450..7bb2bb451 100644--- a/tests/resource/test_material_shader_lifetime.cpp+++ b/tests/resource/test_material_shader_lifetime.cpp@@ -3,6 +3,9 @@#include "../renderer/MockGfxDevice.hpp"#include "esengine/resource/ResourceManager.hpp"#include "esengine/renderer/store/MaterialStore.hpp"+#include "esengine/renderer/rhi/Shader.hpp"+#include "esengine/resource/ShaderParser.hpp"+#include "esengine/core/Log.hpp"#include <cstdio>using namespace esengine;static int failures = 0;@@ -81,6 +84,28 @@ int main() {CHECK(rm.getStats().shaderCount == 0, "retirement after store destruction invokes no dead observer");rm.shutdown();}+ {+ // A variant that does not read one of the material's textures (a depth program) has it optimized out: seeding skips it, and says nothing.+ MockGfxDevice device; resource::ResourceManager rm; rm.init(device);+ device.absentUniforms = {"u_detail"};+ auto handle = rm.createShader("vertex", "fragment", false);+ Shader* shader = rm.getShader(handle);+ const resource::ParsedShader parsed = resource::ShaderParser::parse(+ "#pragma shader \"Seeds\"\n#pragma version 300 es\n#pragma domain Unlit\n"+ "#pragma param u_base texture default(white)\n#pragma param u_detail texture default(white)\n"+ "#pragma fragment\nprecision mediump float;\nout vec4 fragColor;\nvoid main() { fragColor = vec4(1.0); }\n#pragma end\n");+ int notFound = 0;+ const u32 sink = Log::addSink([&](const LogEntry& entry) {+ if (entry.level == LogLevel::Warn && entry.message.find("not found") != std::string::npos) ++notFound;+ });+ const int before = device.setUniform1iCalls;+ CHECK(parsed.valid && shader != nullptr, "a shader with two texture params");+ if (shader) MaterialStore::seedSamplers(*shader, parsed);+ Log::removeSink(sink);+ CHECK(device.setUniform1iCalls == before + 1, "the texture the program reads is seeded");+ CHECK(notFound == 0, "the one it optimized out is skipped without a warning");+ rm.releaseShader(handle); rm.shutdown();+ }std::printf("Material shader lifetime: %d failures\n", failures);return failures ? 1 : 0;}diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 30b366777..e33db2773 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -3428,4 +3428,6 @@ export const NOTED = {{"note":"The loading screens say how far they are."},"fix(render): a fragment-only material's vertex stage declares its position invariant, so its colour lands on its prepass depth on Metal":{"note":"The ground has no dark patches on a Mac."},+ "fix(render): seeding a material's samplers skips the ones a program optimized out, instead of warning of a typo for each":+ {"note":"No \"uniform not found\" warnings for a texture a program does not read."},};