Commit graph

479 commits

Author SHA1 Message Date
Admin
a495095c9a optimising 2026-03-28 20:03:37 +01:00
Admin
0cc533660e optimising 2026-03-28 19:56:09 +01:00
Admin
cf0b9d0153 working refactor 2026-03-28 18:46:43 +01:00
Admin
282a9a34e2 working refactor 2026-03-28 17:58:49 +01:00
Admin
29ca115f14 actually working alignment 2026-03-28 16:36:27 +01:00
Admin
5112d37ebd cleanup 2026-03-28 13:22:52 +01:00
Admin
0088feb734 contour map 2026-03-28 12:02:56 +01:00
Admin
83fd90015f auto alignment working 2026-03-27 16:31:02 +01:00
Admin
83a9fa2017 xr room mapping 2026-03-27 13:51:54 +01:00
Admin
a517b9cb42 fix xr UIs 2026-03-26 15:25:55 +01:00
Admin
d2853799f9 wrist ui 2026-03-26 15:25:55 +01:00
wyenox
6da8ad2f23
fix openxr compile error on non-vulkan android builds (#989) 2026-03-26 08:25:25 +01:00
Kevin Boos
afbca7d466
Additional opptimizations for windows shader compilation (#988)
* Additional opptimizations for windows shader compilation

`hlsl_compile_shaders` was called unconditionally after every draw event, even on
frames where no new shaders needed compilation. Added an early return:

```rust
if self.draw_shaders.compile_set.is_empty() {
    return;
}
```

The loop previously collected `compile_set` into a temporary `Vec` before
iterating, in order to release the borrow on `compile_set` so the loop body
could mutate other `draw_shaders` fields. This caused a heap allocation and a
full copy of all indices on every compilation batch.

`std::mem::take` atomically replaces `compile_set` with an empty `BTreeSet` and
returns ownership of the original — no intermediate allocation, no copy, and no
separate `.clear()` needed at the end:

```rust
let compile_set = std::mem::take(&mut self.draw_shaders.compile_set);
for draw_shader_id in compile_set { ... }
// no .clear() needed
```

Previously `shader_cache_dir()` was an inner function called inside
`CxOsDrawShader::new`, meaning it ran once **per shader** on every compilation.
Each call performs two syscalls: `env::var("LOCALAPPDATA")` and
`fs::create_dir_all`. With N shaders compiling on first launch, this was 2N
unnecessary syscalls.

`shader_cache_dir()` is now a module-level function called **once** before the
loop in `hlsl_compile_shaders`, and the resulting `Option<&Path>` is passed into
`new` as a parameter.

The HLSL source already lives in `cx_shader.mapping.code`. The previous code
cloned it into an owned `String` before passing it to `new`, even though all
downstream uses (hashing, `D3DCompile`, cache I/O, error printing) only need a
`&str`. Changed the parameter type to `&str` and restructured the loop body into
a block scope so the immutable borrow on `cx_shader` ends before the mutable
reborrow — eliminating the clone entirely.

`CxOsDrawShader::new` already took `&UniformBufferBindings` by reference. The
clone existed only because the immutable borrow on `cx_shader` had to be released
before the mutable reborrow. The same block-scope restructuring from fix #4
resolves this: `&cx_shader.mapping.uniform_buffer_bindings` is now passed
directly.

This field was written once on construction and **never read** — the only reader
was the O(n) deduplication scan removed in the previous round of fixes. It held
a full copy of each shader's HLSL source for the entire lifetime of the
application. At tens of KB per shader and dozens of shaders, this was megabytes
of permanently retained dead storage. The field is gone.

* More shader optimizations on windows

Properly get the Local AppData directory instead of using the
env var %LOCALAPPDATA, which may not always be there.
Now we do it with `SHGetKnownFolderPath(FOLDERID_LocalAppData)`,
which is canonically correct.

We also cache the directory path itself.
2026-03-26 08:25:01 +01:00
Admin
788d7a42c4 xr test 2026-03-26 00:32:24 +01:00
Kevin Boos
0d13952005
Cache shader compilation on windows to avoid long UI hangs (#987)
On Windows, a large app like Robrix freezes for 10–20+ seconds after login while sync begins.
Profiling (`sc.user_aux.etl` from Visual Studio Performance Profiler) showed:

| Module | Exclusive CPU samples | % of total |
|---|---|---|
| `d3dcompiler_47.dll` | 24,239 | **76.76%** |
| `robrix.exe` | 2,715 | 8.60% |

A single thread (TID 20308) consumed **27.9 seconds of CPU** over the 35-second trace.
Every other robrix thread combined used under 2 seconds.

The butterfly call graph confirmed: `robrix.exe → d3dcompiler_47.dll` with 25,337
inclusive hits (80.24%). The UI was blocked the entire time.

In `makepad/platform/src/os/windows/windows.rs`, the main Win32 event loop calls:

```rust
if self.need_redrawing() {
    self.call_draw_event(time_now);
    self.hlsl_compile_shaders(&d3d11_cx);  // blocks here
}
```

`hlsl_compile_shaders` iterates over every shader in `compile_set` and calls
`CxOsDrawShader::new`, which calls `D3DCompile` (from `d3dcompiler_47.dll`)
**synchronously on the UI thread** for each unique shader. After login, many
new UI panels render for the first time, flooding `compile_set`. `D3DCompile`
is a full software HLSL→DXBC compiler with no OS-level cache — it is CPU-bound
and cannot yield.

This affects all makepad apps on Windows, not just Robrix.

**File changed:** `makepad/platform/src/os/windows/d3d11.rs`

Added a disk-based shader bytecode cache so that `D3DCompile` is only called
once per unique shader source, on first launch. Subsequent launches load the
pre-compiled DXBC bytecode directly, skipping `D3DCompile` entirely.

**Specific changes:**

1. `CxOsDrawShader` struct: changed `pixel_shader_blob` and `vertex_shader_blob`
   field types from `ID3DBlob` to `Vec<u8>`. These fields were stored but never
   read after construction, so there is no behavioral difference.

2. `compile_shader` (inner fn): changed return type from `ID3DBlob` to `Vec<u8>`,
   copying the blob bytes out before returning.

3. Three new inner helper functions added to `CxOsDrawShader::new`:
   - `hlsl_cache_key(hlsl: &str) -> u64` — FNV-1a 64-bit hash of the HLSL
     source string, stable across Rust versions, used as the cache key.
   - `shader_cache_dir() -> Option<PathBuf>` — resolves
     `%LOCALAPPDATA%\makepad\d3d11_shader_cache\`, creating it if needed.
     Returns `None` gracefully if `LOCALAPPDATA` is unset or the directory
     cannot be created, in which case compilation proceeds as before.
   - `get_shader_bytes(...)` — checks for a cached `<hash>_vs.dxbc` /
     `<hash>_ps.dxbc` file; on a cache miss, compiles via `D3DCompile` and
     writes the result to disk before returning.

- **First launch:** all shaders compile as before; each VS/PS blob is written to
  `%LOCALAPPDATA%\makepad\d3d11_shader_cache\<hash>_vs.dxbc` and `<hash>_ps.dxbc`.
- **Subsequent launches:** bytecode is read from disk; `CreateVertexShader` /
  `CreatePixelShader` / `CreateInputLayout` are called directly with the cached
  bytes — `D3DCompile` is never invoked.
- **Cache invalidation:** the cache key is the FNV-1a hash of the HLSL source,
  so entries automatically become stale (and are recompiled + re-cached) whenever
  the shader source changes.
- **Failure safety:** file I/O errors are silently ignored — a failed write means
  the cache is just skipped next time, and a failed read falls through to
  recompilation.
2026-03-26 00:03:59 +01:00
Admin
014732ecf7 optimising quest renderpath with physics 2026-03-25 23:29:41 +01:00
Admin
2820fa6bf5 optimising quest renderpath with physics 2026-03-25 22:44:16 +01:00
Admin
5e04f6fb06 optimising quest renderpath with physics 2026-03-25 22:44:16 +01:00
Admin
b6fa66ae41 optimising quest renderpath with physics 2026-03-25 22:44:16 +01:00
Admin
988d28505c foveation 2026-03-25 18:20:38 +01:00
Admin
6431464aa1 better physics 2026-03-25 17:39:00 +01:00
Admin
d997a1b05a multiview 2026-03-25 17:38:59 +01:00
Admin
7a102e5cf4 finally 2026-03-25 17:38:59 +01:00
Admin
0fc2114f61 finally runs 2026-03-25 17:31:52 +01:00
Admin
3f7b0a1bac xr otw 2026-03-25 17:31:52 +01:00
Sabin Regmi
0cff3fd7f6
ft makepad_test (#974)
* ft makepad_test

* Improve run handling, manifest parsing, and stdout newline

Replace dynamic free-port lookup with an ephemeral localhost SocketAddr in test runtime and remove the unused find_free_listen_address helper. Ensure headless stdout messages end with a newline. Simplify send_to_app error handling and add a test that queued bootstrap messages are delivered once an app socket connects. Substantially enhance process_manager: unify cargo flag parsing, parse Cargo.toml to determine package/bin targets, resolve the correct binary name for direct stdio runs, and build the cargo/build+exec script from the resolved args. Add unit tests for manifest parsing and script generation and adjust related call sites.

* test harness

* Preserve test attrs; return Vec for gateway binds

In the test macro (libs/makepad_test/macros/src/lib.rs) preserve wrapper-only attributes (ignore and should_panic) on the generated wrapper test while removing them from the inner function. Added Attribute import, is_wrapper_only_test_attr helper, adjusted attribute filtering and emission, and added unit tests to verify attribute placement and expansion.

In the hub (studio/hub/src/hub.rs) change gateway_bind_candidates to return a Vec<SocketAddr> instead of an iterator and special-case ephemeral port 0 to preserve ephemeral binding; otherwise collect the range of candidate ports into a Vec. Added tests to validate candidate behavior. Also minor formatting/whitespace tweaks and a small IPv6 formatting adjustment.

* Add visible Studio mode and remote client

Enable running UI tests visibly through a running Makepad Studio. Adds a new makepad-network dependency and studio_remote client (libs/makepad_test/src/studio_remote.rs) and integrates it into the runtime via a TestConnection enum. Introduces visible-mode tooling: env vars (MAKEPAD_TEST_VISIBLE, MAKEPAD_TEST_STUDIO, MAKEPAD_TEST_STUDIO_MOUNT, MAKEPAD_TEST_STARTUP_DELAY_MS, MAKEPAD_TEST_ACTION_DELAY_MS, MAKEPAD_TEST_KEEP_OPEN_MS), pacing/delays after actions, and pause-before-shutdown. Splits startup into start_headless_app/start_visible_app, clears existing visible builds before launching, and updates tests, docs (GUIDE.md, README.md), and selector/runtime minor cleanups/formatting.
2026-03-25 16:09:03 +01:00
Kevin Boos
a6ea8a662b
Fix shader compilation bug on linux and window positioning (#979)
TL;DR: the shader compiler needed explicit casts in for loop bounds,
and the window positioning was messed up, causing the app-level title bar
to overlap with the native OS-level title bar (which means you couldn't
see or press the window chrome buttons)

--------

here's an AI-generated summary of the changes, for more details:

On OpenGL ES 3.0 targets (Linux/EGL, Android), shaders containing `for` loops
over `uint` variables failed to compile with a GLSL type-error. The shader
compiler emitted the loop header as:

```glsl
for(uint i = 0; i < 4; i++) { … }
```

The integer literals `0` and `4` are of type `int` in GLSL. GLSL ES 3.0 forbids
implicit casts between `int` and `uint`, so the initialiser and the comparison
both produce a compile error. The other shader backends (Metal/WGSL/Rust) do not
have this restriction, so no corresponding arm existed for GLSL.

**`platform/script/src/shader_control.rs`** — Add a `ShaderBackend::Glsl` arm to
`handle_for_1` that wraps both loop bounds in an explicit constructor call for the
loop variable's type:

```glsl
for(uint i = uint(0); i < uint(4); i++) { … }
```

This satisfies GLSL ES 3.0's strict no-implicit-cast rule and matches the
behavior already implemented for the WGSL backend (which uses typed variable
declarations for the same reason).

**`platform/src/os/linux/opengl.rs`** — Gate the helper functions
`shader_source_hash` and `shader_source_preview` (and their call-sites) behind
`#[cfg(target_os = "android")]`. These functions are only referenced from
Android-specific shader-cache code paths; without the attribute the compiler
emits dead-code warnings on every other Linux/OpenGL build.

- `platform/script/src/shader_control.rs`
- `platform/src/os/linux/opengl.rs`

----------------------------------------------------------------------------

On GNOME (and likely other modern WMs), restoring a saved window position would
consistently produce two visual artifacts:

1. **No WM title bar visible** — the client area was rendered where the title bar
   should appear.
2. **Black bar at the bottom** — the bottom portion of the window surface was not
   covered by rendered content.

The root cause was two related issues in `xlib_window.rs`:

**Issue 1 — `XMoveWindow` called after `XMapWindow` (races with WM reparenting)**

After `XMapWindow`, the window manager asynchronously reparents the client window
into a decoration frame. If `XMoveWindow` is called after reparenting has occurred,
the coordinates are interpreted relative to the WM frame rather than the root
window. For example, calling `XMoveWindow(client, 23, 89)` after GNOME reparents
places the client 89 px from the top of the WM frame. Since the title bar is only
~37 px tall, the client ends up 52 px below the title bar, and its bottom edge
extends 52 px *beyond* the bottom of the WM frame. GNOME responds by resizing or
repositioning the client, producing the rendering artifacts described above.

**Issue 2 — No `USPosition` hint set**

Without the `USPosition` flag in `WM_NORMAL_HINTS`, GNOME ignores the position
provided to `XCreateWindow` and applies its own smart-placement algorithm. This
meant the application relied entirely on the post-map `XMoveWindow` call described
above, which was itself broken.

**`platform/src/os/linux/x11/x11_sys.rs`** — Add the standard `XSizeHints` flag
constants:

- `USPosition` (`1 << 0`) — user-specified x, y
- `USSize` (`1 << 1`) — user-specified width, height
- `PPosition` (`1 << 2`) — program-specified position
- `PSize` (`1 << 3`) — program-specified size

**`platform/src/os/linux/x11/xlib_window.rs`** — Two changes in `XlibWindow::init()`:

1. Before calling `Xutf8SetWMProperties`, populate an `XSizeHints` struct with
   `flags = USPosition | PPosition` (and `x`/`y` set to the requested coordinates)
   when a position was provided. Pass this struct as the `WM_NORMAL_HINTS` argument
   instead of the previous `ptr::null_mut()`. This tells GNOME/Mutter to honor the
   requested position rather than running its own placement heuristic.

2. Move the `XMoveWindow` call to *before* `XMapWindow`. At that point the window is
   still a direct child of the root window, so the coordinates are unambiguously
   root-relative. This eliminates the race with WM reparenting entirely.
2026-03-24 19:52:21 +01:00
Admin
06c3e1c0d1 xr otw 2026-03-23 20:52:29 +01:00
Admin
dea06dd282 cleanup 2026-03-23 10:12:37 +01:00
Admin
e888e946ab android borked 2026-03-22 17:28:18 +01:00
Sabin Regmi
a0351cf90e
Some small web nits from my crazy experiement (#972)
* Schedule loader removal after presented frame

Introduce loader_after_presented_frame_id and add schedule/cancel helpers to remove the canvas loader after a presented animation frame. Cancel any pending requestAnimationFrame when the loader is removed or conditions change, and update update_startup_loader to use the new scheduling logic (remove loader only after seen animation frame and quiet frames threshold). This prevents premature removal and visual glitches while preserving the existing fallback timer.

* small fonts should be used when --profile=small

* dont include large fonts on small profile + fix compress serving

* Refactor window initialization and caption sync

Extract sync_caption_bar_state and sync_caption_title from ensure_initialized and call them before the initialized early-return so caption bar state and title are kept in sync even when the widget is re-applied. ensure_initialized still performs the original one-time setup (pass, depth texture, demo frame), but runtime chrome (VR button and caption visibility/title) is now updated up-front to avoid stale UI state.

* fix --bindgen

* Set imports.env in wasm import patches

Add additional string replacements to ensure imports.env = env is injected into generated JS for different formatting variants of the __wbg_get_imports(...) call. This makes the patch robust to variations like missing const or spacing so the env object is always attached to the wasm imports.

* Revert "Set imports.env in wasm import patches"

This reverts commit 37933234d36b4ee867690cf167474638e81febf7.

* Revert "fix --bindgen"

This reverts commit cb236b202b92a46eda3cb1ee4c678bdf6507081a.

* Reapply "fix --bindgen"

This reverts commit 27df4175bd1889222b928ffb68213aa865d1c839.

* Reapply "Set imports.env in wasm import patches"

This reverts commit 23695b4fa646d8f1b7a31a3fc27eb92f5bce0cf8.

* fix xr compilation error
2026-03-21 11:23:16 +01:00
Kevin Boos
291e9365a2
cargo makepad: fix android SDK installation (unzip step) on linux (#977)
* Fix windows build: add missing constants in vendored windows-rs bindings

* fix more build errors and warnings in windows-rs vendored copy

* Fix SVG parsing and vector drawing

* Fix erroneous unzip glob pattern that doesn't work on normal linux

* try another approach: unzip everything, cp needed dirs
2026-03-21 11:21:52 +01:00
Admin
0aa7118f78 protocol 2026-03-20 10:09:40 +01:00
Admin
d50d15f16b protocol 2026-03-20 09:42:35 +01:00
Admin
2cff94d01b fix android screencap to studio 2026-03-20 09:03:50 +01:00
Admin
785b823751 fix android screencap to studio 2026-03-19 13:59:42 +01:00
Admin
840b8b5cb3 fix android screencap to studio 2026-03-19 13:57:55 +01:00
Admin
2914c74b79 fix studio 2026-03-19 12:42:27 +01:00
Admin
d5e73849a5 fix studio 2026-03-19 11:54:38 +01:00
Admin
23e1973ac9 fix studio 2026-03-19 11:24:51 +01:00
Admin
bb24dbd50a studio ws fix 2026-03-19 10:42:55 +01:00
Admin
5a4bef21d6 cleanup 2026-03-19 10:16:38 +01:00
Admin
6cd202a553 remove dep 2026-03-18 01:02:57 +01:00
Admin
52afaf022b remove dep 2026-03-18 00:06:32 +01:00
Admin
1a0f01ce89 vulkan debugging 2026-03-17 23:59:07 +01:00
Admin
987f21bea4 cef 2026-03-17 19:00:28 +01:00
Admin
3803e091de vulkan video textures 2026-03-17 19:00:28 +01:00
Admin
efb38f2f89 vulkan video textures 2026-03-17 19:00:28 +01:00
Admin
91f0873847 vulkan video textures 2026-03-17 19:00:28 +01:00
Admin
72269c0da2 not bad 2026-03-17 19:00:28 +01:00