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
perf(render): sprite and particle shaders compile in the background too - the batch shader's variants and the particle shader were linked in place whatever asyncShaderCompile said, a third to half a second of one frame when a lit sprite or the first particle appeared; they are deferred as mesh shaders are, their samplers seeded when the link lands
yhh1b57801226ae
diff --git a/src/esengine/renderer/frame/RenderFrame.cpp b/src/esengine/renderer/frame/RenderFrame.cppindex d65a36afe..ca639f12e 100644--- a/src/esengine/renderer/frame/RenderFrame.cpp+++ b/src/esengine/renderer/frame/RenderFrame.cpp@@ -3031,18 +3031,21 @@ resource::ShaderHandle RenderFrame::compileBatchVariant(const std::vector<std::sresource::ShaderParser::assembleStage(parsed, resource::ShaderStage::Vertex, "", features, target),resource::ShaderParser::assembleStage(parsed, resource::ShaderStage::Fragment, "", features, target),{{0, "a_position"}, {1, "a_color"}, {2, "a_texCoord"}},- resource_manager_.preferredShaderLanguage());+ resource_manager_.preferredShaderLanguage(), resource_manager_.deferLinks());Shader* shader = resource_manager_.getShader(handle);if (shader && shader->isValid()) {- shader->bind();- // Bind the 8 multi-texture samplers to units 0..7 (per-program, set once).- for (i32 i = 0; i < 8; ++i) {- i32 loc = device_.getUniformLocation(shader->handle(),- ("u_textures[" + std::to_string(i) + "]").c_str());- if (loc >= 0) device_.setUniform1i(loc, i);- }- shader->unbind();+ // After it links: at once, or (where shaders are not waited for) when a draw first needs it.+ // Sampler seeding is a GLSL concept; on WGSL the textures ride the bind group.+ if (shader->language() == GfxShaderLanguage::GLSL_ES300) shader->whenLinked([](Shader& s) {+ s.bind();+ // Bind the 8 multi-texture samplers to units 0..7 (per-program, set once).+ for (i32 i = 0; i < 8; ++i) {+ const std::string name = "u_textures[" + std::to_string(i) + "]";+ s.setUniform(name, i);+ }+ s.unbind();+ });return handle;}diff --git a/src/esengine/renderer/plugins/ParticlePlugin.cpp b/src/esengine/renderer/plugins/ParticlePlugin.cppindex b1ca82bc3..cdadbae13 100644--- a/src/esengine/renderer/plugins/ParticlePlugin.cpp+++ b/src/esengine/renderer/plugins/ParticlePlugin.cpp@@ -59,18 +59,20 @@ void ParticlePlugin::init(RenderFrameContext& ctx) {handle = ctx.resources.createShaderWithBindings(resource::ShaderParser::assembleStage(parsed, resource::ShaderStage::Vertex, "", features, target),resource::ShaderParser::assembleStage(parsed, resource::ShaderStage::Fragment, "", features, target),- {}, ctx.resources.preferredShaderLanguage());+ {}, ctx.resources.preferredShaderLanguage(), ctx.resources.deferLinks());Shader* shader = ctx.resources.getShader(handle);if (shader && shader->isValid()) {particle_shader_id_ = shader->getProgramId();if (shader->language() == GfxShaderLanguage::GLSL_ES300) {// Sampler seeding is a GLSL concept; on WGSL the texture rides the- // bind group.- shader->bind();- for (i32 unit = 0; unit < 8; ++unit) {- shader->setUniform("u_textures[" + std::to_string(unit) + "]", unit);- }- shader->unbind();+ // bind group. After it links: at once, or when a draw first needs it.+ shader->whenLinked([](Shader& s) {+ s.bind();+ for (i32 unit = 0; unit < 8; ++unit) {+ s.setUniform("u_textures[" + std::to_string(unit) + "]", unit);+ }+ s.unbind();+ });}}}