This review focuses on Makepad internals under makepad/ and only touches HAVI where needed to frame integration.
Goal: determine whether Makepad can support a HAVI-side compositor path that preserves browser-style CSS 3D semantics when needed:
- full hierarchical 4x4 transforms
- perspective and perspective divide
preserve-3dparticipation across a subtree- offscreen surfaces / render-to-texture flattening boundaries
- projected clipping
- depth ordering / z handling
- hit-testing implications only where they affect API design
The question is not whether Makepad can become a browser engine. The question is whether Makepad can expose enough low-level compositor primitives for HAVI to submit surfaces/quads/layers with 4x4 transforms while leaving the normal 2D path intact.
Files:
libs/math/src/math_f32.rsdraw/src/draw_list_2d.rsplatform/src/draw_pass.rs
Makepad already has the needed math primitives:
Mat4f::perspectiveMat4f::orthoMat4f::look_atMat4f::mulMat4f::transform_vec4Mat4f::invert
This is enough for a compositor that keeps transforms as 4x4 matrices until final GPU submission.
Important detail: draw/src/draw_list_2d.rs already treats DrawListUniforms.view_transform as a full Mat4f and its helper methods do a perspective divide when mapping points:
map_point_to_localmap_point_from_local
That means the core math model is not limited to affine 2D even though most widgets use it that way.
Files:
platform/src/draw_list.rsdraw/src/draw_list_2d.rsdraw/src/shader/draw_quad.rs
DrawListUniforms contains:
view_transform: Mat4fview_clip: Vec4fview_shift: Vec2f
DrawList2d exposes:
set_view_transformset_view_transform_self_onlyget_view_transform
DrawQuad shaders multiply by draw_list.view_transform before pass projection.
This is a real compositor-relevant primitive: a subtree draw list can already be transformed by a 4x4 matrix.
Limit: the standard 2D shaders clip to axis-aligned rectangles in local/pass space before transform. That is acceptable for ordinary 2D widgets, but it is not enough for true CSS 3D projected clipping.
Files:
draw/src/cx_draw.rsplatform/src/draw_pass.rswidgets/src/view.rswidgets/src/window.rsplatform/src/texture.rs
Existing pass primitives:
CxDraw::make_child_passCxDraw::begin_passCxDraw::end_passDrawPass::set_color_textureDrawPass::add_color_textureDrawPass::set_depth_texture
Existing render-target textures:
TextureFormat::RenderBGRAu8TextureFormat::RenderRGBAf16TextureFormat::RenderRGBAf32TextureFormat::DepthD32
Existing use:
widgets/src/view.rstexture-caches a subtree by rendering it into a child pass and then drawing the resulting texture.widgets/src/window.rscreates a pass-attached depth texture for the main window pass.
This is the exact base needed for CSS flattening boundaries:
- preserve-3d subtree rendered live in one pass
- flattening boundary rendered into offscreen texture
- parent compositor then reuses that texture as a transformed surface
Files:
platform/src/geometry.rsdraw/src/geometry/geometry_gen.rsdraw/src/shader/draw_pbr.rs
Makepad is not restricted to rect-only rendering internally.
It already has:
GeometryGeometry::update- arbitrary index and vertex buffers
- custom draw shaders via
DrawVars - custom instance attributes and uniforms
This matters because a CSS compositor does not need full triangle meshes, but it does need more than rect_pos + rect_size. It needs at minimum:
- projected quads
- optional subdivided quads later
- custom per-instance data such as 4x4 transform, UV rect, opacity, backface flag, clip planes
A companion compositor crate can build this on top of existing Geometry + DrawVars + custom shader without replacing Makepad’s renderer.
Files:
draw/src/shader/draw_pbr.rsdraw/src/shader/draw_text_3d.rswidgets/src/3d/scene_3d.rswidgets/src/3d/gltf_bridge.rs
What exists:
DrawPbruses model/view/projection 4x4 matricesDrawText3dprojects world positions to screenScene3Dbuilds a 3D camera and submits 3D content- GLTF bridge traverses hierarchical transforms and multiplies world matrices
This proves that Makepad’s GPU/shader/backend stack can already carry 4x4 transforms and depth-tested 3D content.
It does not by itself solve CSS 3D compositing, because CSS needs textured surfaces and browser flattening rules rather than PBR meshes. But it shows the lower levels are capable.
Files:
widgets/src/window.rsplatform/src/draw_pass.rsplatform/src/os/apple/metal.rsplatform/src/os/linux/opengl.rsplatform/src/os/windows/d3d11.rsplatform/src/os/linux/vulkan.rsplatform/src/os/web/web_gl.rs
Backends generally enable depth testing and use LESS_OR_EQUAL style depth behavior.
This is enough for a preserve-3d compositor path as long as the submitted quads are actual 3D geometry and not just painter-sorted 2D rects.
File:
platform/src/draw_matrix.rs
There is a DrawMatrix / CxDrawMatrixPool type that appears intended for hierarchical transform nodes.
Current state:
- partially implemented
- parent propagation unfinished
- not used by the active draw system
This is evidence that hierarchical transform storage was considered, but it is not a usable foundation today.
Evidence:
Mat4fis a script pod type- shaders use
uniform(mat4x4f(...)) - backends chunk attributes into 4-float pieces where needed
This means a compositor shader can carry 4x4 transforms today. No large shader-language rewrite is required for the base design.
Files:
draw/src/draw_list_2d.rsplatform/src/area.rsplatform/src/event/finger.rs
Useful part:
DrawList2d::map_point_to_localandmap_point_from_localcan invert a 4x4 transform with perspective divide.
Blocking part:
Area::clipped_rectis axis-aligned rect logicEvent::hits*tests againstRect/ inset-expanded rects- widget hit-testing is not polygon/projected-surface aware
For HAVI this is acceptable if HAVI owns hit-testing for compositor surfaces. It is not acceptable if the goal is generic Makepad widget-level projected hit-testing.
Files:
draw/src/shader/draw_quad.rsdraw/src/shader/draw_vector.rsplatform/src/area.rsplatform/src/event/finger.rs- backend scissor state in
platform/src/os/*
Current clipping model:
draw_clipandview_clipare axis-aligned rectangles- clipping happens before or in shader relative to axis-aligned local/pass rectangles
- hit-testing uses axis-aligned clipped rects
- backend scissor support is effectively not part of the public drawing model
Backend reality:
- Vulkan sets a full-pass scissor only
- D3D11 rasterizer has
ScissorEnable: FALSE - OpenGL exposes
glScissorbut the draw path does not use it per draw - WebGL path similarly does not expose projected clipping
For CSS 3D, projected ancestor clips need either:
- per-fragment clip planes / projected polygon tests in shader, or
- real scissor/stencil/polygon clipping machinery
Makepad does not currently provide this.
There is no compositor scene graph concept for:
- flattening boundaries n- preserve-3d groups
- backface visibility rules on textured surfaces
- parent perspective that propagates into descendants and then stops at flattening boundaries
This is not a backend problem. It is an API/model-layer gap.
DrawPbr is about meshes and material state.
A CSS compositor needs:
- textured quads or small polygon batches
- offscreen surface allocation
- hierarchical surface/node submission
- opacity/filter/mask hooks later
That API does not exist today.
Files:
platform/src/draw_shader.rsplatform/src/draw_vars.rsdraw/src/shader/draw_pbr.rs- backend files under
platform/src/os/*
The option exists in the draw system:
CxDrawShaderOptions.depth_write- parsed from shader object in
DrawVars DrawPbr::set_depth_write
Backend status:
- Metal honors it by switching depth states
- Vulkan hardcodes
.depth_write_enable(true)in pipeline creation - D3D11 builds one depth stencil state with
DepthWriteMask = ALL - OpenGL/WebGL paths do not wire per-draw
glDepthMask
So the API exists, but it is not consistently implemented.
This matters for a compositor because:
- opaque surfaces should usually write depth
- blended surfaces often need depth test without depth write
- backface or overlay passes may need explicit control
File:
draw/src/shader/draw_pbr.rs
DrawPbr exposes:
clip_ndcdepth_rangedepth_forward_bias
Scene3D computes and supplies these values.
But in the shader code they are uploaded and never actually used in the vertex or fragment path.
So current Makepad 3D does not already provide projected clip rectangles or depth remapping through this API, despite the surface appearance.
Current pieces are low-level and scattered:
DrawPassTextureGeometry- custom draw shaders
There is no focused API for:
- create offscreen surface
- render closure into surface
- submit surface as 3D-transformed quad
- group surfaces into preserve-3d or flattening contexts
If HAVI uses a companion compositor path, HAVI should own hit-testing for those surfaces.
Trying to extend existing widget Event::hits() semantics to projected polygons would be invasive and unnecessary for the immediate HAVI need.
There is no machinery for:
- quad/plane intersection splitting
- BSP-style ordering
- polygon clipping of intersecting transformed layers
This is the right omission for now.
For a browser-style layer compositor, projected quads plus offscreen surfaces are enough for the overwhelming majority of CSS 3D usage. Full plane splitting is only required for exact handling of pathological cases where independently transformed layers geometrically intersect in 3D in ways that cannot be represented by simple per-surface depth ordering.
For HAVI’s target, plane splitting is not a first implementation requirement.
Yes for the practical target.
They are enough to implement:
- full 4x4 transform propagation
- perspective from ancestor contexts
preserve-3dparticipation inside a compositor group- flattening boundaries via render-to-texture
- correct GPU depth testing among participating surfaces
- backface visibility
- ordinary browser content staying on the existing 2D path
They are not enough for exact general handling of all intersecting 3D surfaces if you want mathematically exact order for arbitrary penetrating quads. That requires polygon splitting or a more complex surface decomposition pass.
Recommendation: do not make plane splitting part of the initial Makepad/HAVI CSS 3D compositor plan.
What is required in the first version beyond projected quads and offscreen surfaces is projected clipping. That can be done in shader space with clip planes or projected polygon tests rather than full backend stencil infrastructure.
Technically viable.
This would add a first-class compositor surface/quad API inside existing Makepad crates, likely in makepad-draw plus small makepad-platform backend changes.
This is viable because the critical low-level pieces already exist:
- 4x4 matrices
- custom geometry
- render-to-texture passes
- depth buffers
- shader-driven drawing
At minimum:
pub struct CompositorSurface {
pub color: Texture,
pub depth: Option<Texture>,
pub size: Vec2d,
}
pub struct CompositorNode {
pub texture: Texture,
pub local_rect: Rect,
pub uv_rect: Rect,
pub transform: Mat4f,
pub opacity: f32,
pub premultiplied: bool,
pub backface_visible: bool,
pub depth_test: bool,
pub depth_write: bool,
pub clip_mode: CompositorClipMode,
pub clip_planes: SmallVec<[Vec4f; 8]>,
}
pub enum CompositorClipMode {
None,
ScreenPlanes,
}
pub struct CompositorPass {
pub pass: DrawPass,
}
impl CompositorPass {
pub fn begin_surface(...)
pub fn end_surface(...)
pub fn draw_node(...)
pub fn draw_nodes(...)
}Optional higher-level grouping API if you want Makepad itself to understand flattening/preserve-3d boundaries:
pub enum CompositorGroupMode {
Flat,
Preserve3d,
}I would not put browser semantics such as CSS transform-style enums or DOM concepts into Makepad. Only generic compositor concepts.
The narrowest useful addition is not a full scene graph. It is:
- a new textured projected-quad draw shader and wrapper
- small helpers for offscreen surface allocation via child passes
- backend fixes for per-draw depth-write
- optional projected clip-plane uniform path
That is enough for HAVI to own the actual compositor tree logic.
Likely:
draw/src/lib.rs- new
draw/src/shader/draw_compositor_quad.rs - optionally new
draw/src/compositor.rs platform/src/draw_shader.rsif adding new draw optionsplatform/src/draw_vars.rsif adding option plumbing or helper settersplatform/src/os/apple/metal.rsplatform/src/os/windows/d3d11.rsplatform/src/os/linux/opengl.rsplatform/src/os/linux/vulkan.rsplatform/src/os/web/web_gl.rs
Possible shader-language touch points only if desired:
- fixed-size uniform arrays or nicer uniform-buffer ergonomics for clip planes
Minimal useful version:
- new compositor quad draw wrapper + shader:
350-600 - small compositor surface helper layer:
200-400 - depth-write fixes across backends:
250-500 - projected clip-plane support in shader/API:
150-350 - tests/examples/docs:
200-350
Total: 1,150-2,200 LOC
If you try to make Makepad itself own compositor groups and flattening logic, increase that to roughly:
2,000-3,500 LOC
-
API scope creep
- easy to accidentally build browser-specific semantics into Makepad
- wrong abstraction boundary
-
Backend consistency work
- per-draw depth-write is not consistently wired today
- Vulkan/D3D11/OpenGL/Web need cleanup
-
Projected clipping design
- if you insist on backend stencil/scissor correctness, scope grows quickly
- shader-space clip planes are the right first step
-
This duplicates logic HAVI already owns
- HAVI already knows about paint order, flattening, and 2D layout
- moving too much of that into Makepad is unnecessary
Viable, but only if kept very narrow.
The right Strategy A is not “put CSS 3D in Makepad.” It is “add a generic projected-surface compositor primitive to Makepad.”
This is the best fit and is technically viable.
A companion crate can sit on top of existing Makepad low-level APIs:
DrawPassTextureGeometryDrawVars- custom shaders
- child-pass render-to-texture
It can own the compositor model needed by HAVI without polluting core widget/render abstractions.
HAVI already does:
- layout
- paint ordering
- browser-side flattening decisions
- DOM/CSS semantics
What it needs from Makepad is a rendering/compositor backend, not a second browser engine.
A companion crate can model exactly the missing layer:
- surfaces
- nodes
- preserve-3d groups
- flattening to texture
- projected textured quads
- GPU depth handling
- projected clip planes
I would build the companion crate around three concepts.
pub struct MpSurface {
pub color: Texture,
pub depth: Option<Texture>,
pub pass: DrawPass,
pub size: Vec2d,
}
impl MpSurface {
pub fn begin(cx: &mut Cx2d, parent: Option<&DrawPass>, size: Vec2d, with_depth: bool) -> Self;
pub fn end(&mut self, cx: &mut Cx2d);
}pub struct MpCompositedQuad {
pub texture: Texture,
pub uv_rect: Rect,
pub local_rect: Rect,
pub transform: Mat4f,
pub opacity: f32,
pub premultiplied: bool,
pub backface_visible: bool,
pub depth_test: bool,
pub depth_write: bool,
pub clip_planes: SmallVec<[Vec4f; 8]>,
}pub struct MpCompositor {
// internal quad geometry, shader state, temp buffers
}
impl MpCompositor {
pub fn begin_frame(&mut self, cx: &mut Cx2d, target_pass: &DrawPass, viewport: Rect);
pub fn draw_quad(&mut self, cx: &mut Cx2d, quad: &MpCompositedQuad);
pub fn draw_batch(&mut self, cx: &mut Cx2d, quads: &[MpCompositedQuad]);
pub fn end_frame(&mut self, cx: &mut Cx2d);
}This is enough for HAVI to decide:
- when to flatten into a surface
- when descendants stay in a shared preserve-3d context
- what projected clip planes apply
- what order to submit non-depth-writing translucent quads in
- 4x4 matrix math
- custom geometry and draw shader pipeline
- render-to-texture passes
- texture sampling in shader
- depth buffers on passes
I would still upstream a few narrow changes to Makepad itself.
-
Per-draw depth-write support on all backends
- Metal already has it
- add equivalent handling for Vulkan, D3D11, OpenGL, WebGL
-
A dedicated projected-quad shader wrapper or enough low-level access to build one cleanly
- this can live in the companion crate if preferred
-
Small shader-language convenience for clip planes
- not required if encoded as fixed uniforms or uniform buffer fields
- useful if you want cleaner array-style clip plane submission
-
Optional scissor API
- not needed for first compositor version
- shader-space projected clipping is enough
New companion crate, likely under Makepad workspace:
makepad-compositor/src/lib.rsmakepad-compositor/src/surface.rsmakepad-compositor/src/quad.rsmakepad-compositor/src/shader.rsmakepad-compositor/src/batch.rsmakepad-compositor/examples/...or test harness
Small upstream Makepad touches:
draw/src/lib.rsonly if re-export desired- maybe no changes in
draw/if crate directly usesmakepad_drawandmakepad_platform platform/src/os/apple/metal.rsplatform/src/os/windows/d3d11.rsplatform/src/os/linux/opengl.rsplatform/src/os/linux/vulkan.rsplatform/src/os/web/web_gl.rs
Companion crate itself:
- surface management:
150-300 - projected quad geometry/shader:
300-550 - compositor batching/encoder:
250-500 - projected clip planes / backface / opacity handling:
150-300 - tests/examples/docs:
200-400
Subtotal: 1,050-2,050 LOC
Small upstream Makepad fixes:
- per-draw depth-write across backends:
250-500 - optional helper cleanup / exports:
50-150
Grand total: 1,350-2,700 LOC
This is similar raw size to Strategy A, but it keeps ownership in the right place.
-
Backend depth-write inconsistency
- real blocker for robust compositor blending behavior
- fixable, medium-sized
-
Projected clipping policy
- need to decide clip-plane representation up front
- fixable in shader without backend stencil work
-
Surface lifetime / pooling
- not hard, but needed for performance
- should live in the companion crate, not core Makepad
-
Hit-testing boundary
- must be explicitly left to HAVI
- do not attempt widget-level projected hit test in v1
Viable and clean.
This gives HAVI exactly the layer it needs while minimizing Makepad core changes.
This is the better architecture.
-
The missing piece is compositor policy, not low-level GPU capability
- Makepad already has enough GPU primitives
- what is missing is a focused surface/quad compositor abstraction
-
HAVI already owns browser semantics
- flattening rules
- preserve-3d participation
- paint order decisions
- clip propagation rules
-
Core Makepad should stay general-purpose
- projected textured quads are generic
- CSS-specific tree semantics are not
-
The required core fixes are narrow
- per-draw depth-write on non-Metal backends
- maybe tiny shader convenience for clip planes
-
Fix per-draw
depth_writeon:platform/src/os/linux/vulkan.rsplatform/src/os/windows/d3d11.rsplatform/src/os/linux/opengl.rsplatform/src/os/web/web_gl.rs
-
Do not extend widget hit-testing.
-
Do not add plane splitting.
Implement:
- offscreen surface helper using
DrawPass + Texture - projected textured quad shader using existing matrix support
- backface visibility
- premultiplied alpha blending expectations
- optional clip-plane uniform path
- batch submission API for HAVI
HAVI uses the companion crate to:
- allocate flattening surfaces where CSS requires flattening
- submit preserve-3d descendants directly into a shared 3D compositor context
- submit flattened descendants as textures
- use GPU depth where surfaces remain in the same preserve-3d group
- keep ordinary 2D content on existing fast paths
- generic Makepad widget-level projected hit testing
- plane splitting / BSP
- full stencil/projected polygon clip backend infrastructure
- CSS-specific scene graph inside Makepad core
| Work item | Files | LOC estimate |
|---|---|---|
| Backend per-draw depth-write fixes | platform/src/os/* |
250-500 |
| Projected textured quad shader/wrapper | new draw or companion files | 300-600 |
| Offscreen surface helper | companion crate or draw helper | 150-300 |
| Batch encoder / node submission | companion crate | 250-500 |
| Clip-plane support | companion shader/API | 150-300 |
| Tests/examples/docs | companion + examples | 200-400 |
| Strategy A total, narrow in-Makepad API | mixed | 1,150-2,200 |
| Strategy B total, companion crate + small Makepad fixes | mixed | 1,350-2,700 |
| Strategy A if Makepad owns compositor groups too | mixed | 2,000-3,500 |
draw/src/shader/draw_quad.rsclips local rects withdraw_clipandview_clipbefore final projection.platform/src/area.rsreconstructs clipped rects as axis-aligned rectangles.platform/src/event/finger.rshit-tests those rectangles.
That is correct for existing UI and wrong for browser CSS 3D semantics.
DrawListUniforms.view_transformis a fullMat4fDrawList2d::map_point_to_localalready does inverse + perspective divide
This is enough for a compositor layer, not for widget hit-testing.
widgets/src/view.rsproves Makepad can render subtrees into textures and composite them later.
This is the core flattening primitive required by CSS 3D.
DrawPbris useful as proof of backend capability.- It is not the right abstraction for browser surface composition.
clip_ndc,depth_range,depth_forward_biasare present in Rust state and uploaded as uniforms.- They are not consumed by the shader.
So current Scene3D is not already a reusable CSS compositor substrate.
platform/src/draw_matrix.rsshould not be the basis of the design.
Makepad already has enough low-level rendering machinery for a proper HAVI CSS 3D compositor path:
- full 4x4 math
- GPU geometry submission
- render-to-texture passes
- texture sampling
- depth buffers
What it does not already have is the right compositor-facing API.
The missing work is medium-sized, not large.
The right design is:
- keep Makepad core changes small and generic
- add per-backend depth-write correctness
- build a companion
makepad-compositorcrate around projected textured quads and offscreen surfaces - let HAVI continue to own browser flattening and preserve-3d semantics
Projected quads + offscreen surfaces are enough for the first real implementation. Projected clipping is required. Plane splitting is not a first-version requirement.
Makepad is not a browser compositor today, but it is close enough at the GPU primitive level that HAVI does not need a renderer rewrite.
What Makepad already has:
- 4x4 transform math everywhere it matters
- draw lists carrying
Mat4f - child passes and render-to-texture
- depth textures and 3D rendering
- arbitrary geometry + custom shaders
What is missing:
- a focused projected-surface compositor API
- projected clipping
- consistent per-draw depth-write across all backends
- any notion of preserve-3d / flattening groups at the API layer
- projected hit-testing in widgets, which should be left out of scope
Decision:
- Strategy A: direct in-Makepad API is viable only if kept narrow.
- Strategy B: companion
makepad-compositorcrate is the better choice.
Recommended path:
- fix per-draw depth-write in Makepad backends
- create
makepad-compositor - implement offscreen surfaces + projected textured quads + clip planes
- keep CSS semantics in HAVI
- do not build plane splitting first
Best estimate:
- companion crate plus small Makepad fixes: ~1.35k-2.7k LOC
- enough for a real CSS 3D compositor path for HAVI while preserving the current fast 2D path for ordinary content