Commit Graph

2352 Commits

Author SHA1 Message Date
Haroon Qureshi ecb15a8d9e Cache the render targets.
PiperOrigin-RevId: 929230223
Change-Id: I06571687ba0153c6ee8631685d1d37052419d2ac
2026-06-09 09:11:19 -07:00
Haroon Qureshi b083ae487e Introduce outline render passes and shader.
Use the jump flood algorithm to render an outline around selected
objects. This requires using custom post-processing shaders and
render passes which is managed by a new "Outliner" class.

PiperOrigin-RevId: 929212147
Change-Id: Ie6f475c7c677df7b0d4fc030a8e9520ff9dd03af
2026-06-09 08:31:49 -07:00
Haroon Qureshi e6e5229126 Format header to conform to style guide.
Also moves some types to the mjrender.h header.

PiperOrigin-RevId: 929189125
Change-Id: I19e5598210898c0defb663c60d7ecfb9a19bcd38
2026-06-09 07:43:16 -07:00
Yuval Tassa e349ea5834 Remove MJAPI from templated function declaration.
PiperOrigin-RevId: 928849785
Change-Id: I35ba63f599ba12a5d2bdb0d694240e39ca7d4174
2026-06-08 17:08:17 -07:00
Yuval Tassa 986d73c062 Fix non-unit normals in mesh convex hull compiler.
PiperOrigin-RevId: 928777934
Change-Id: I43d7adcf4c5781b57f0af9805a8ce01ebc2e3872
2026-06-08 14:40:11 -07:00
Haroon Qureshi ae2e8aa940 Rename mjrRenderTargetConfig to mjrfRenderTargetConfig.
This rename was overlooked in the previous commit which updated
the prefixes for all filament-specific render objects.

PiperOrigin-RevId: 928710590
Change-Id: I0ff09cb077f7d5643371d43a43fc992352e6d85d
2026-06-08 12:33:27 -07:00
Haroon Qureshi 2fcd135179 Remove layer mask from public API.
Instead, use materials to determine the layer mask of an object.

This hides the details/complexities of how layers are used
to render different passes from the user and will allow the
renderer to do more advanced rendering passes.

PiperOrigin-RevId: 928682525
Change-Id: I1f53dc8d12d2e574de6528977f55e79f896c6e42
2026-06-08 11:37:47 -07:00
Haroon Qureshi 982e3be9ef Add mjrfCallback type.
PiperOrigin-RevId: 928640487
Change-Id: Iebf470caafe924a976e4a1b39b0c47727e22195b
2026-06-08 10:26:40 -07:00
Adrian Collister 74d1459a4a Enable contact sensors to work with Flex.
The sensor engine now correctly retrieves body IDs for contacts involving Flex elements by using mj_flexBody when a geom ID is -1. This allows contact sensors to detect and report forces/torques on bodies involved in Flex contacts.

PiperOrigin-RevId: 928607416
Change-Id: Ia815e1b3345bcfb393c9c4a829dc98959f2da50c
2026-06-08 09:31:42 -07:00
Yuval Tassa 828052e6f4 CG solver: Replace PRP+ with Hager-Zhang update
Replace the Polak-Ribière-Plus (PRP+) conjugate direction update with the Hager-Zhang  formula in `mj_solPrimal`.

While this change has negligible effect under float64, it leads to a significant 17.5% throughput speedup over PRP+ under float32 (measured via `engine_cg_convergence_test`). This performance gain is driven by:
* A 9.4% reduction in CG iterations per step.
* A 12.1% reduction in line search evaluations per step.

The full output of the comparison is

```
================================================================
1/4: HZ + float64
================================================================

CG Convergence: 2humanoid100.xml
  1000 Newton steps, 100 evaluation points
  nv = 654, nq = 756
  metric: ||qacc_cg - qacc_newton|| / ||qacc_newton||

  Warmstart (tolerance = 0):
   Iters |    Mean Err |     Max Err | Mean Iters | LS evals
  -------+-------------+-------------+------------+---------
       5 |  3.8532e-01 |  1.4285e+00 |       5.00 |    22368
      10 |  2.0809e-01 |  9.9315e-01 |      10.00 |    44591
      20 |  6.4977e-02 |  2.3410e-01 |      20.00 |    89417
      40 |  5.2839e-03 |  2.1916e-02 |      40.00 |   180984
      80 |  3.9709e-05 |  3.0010e-04 |      80.00 |   364241
     160 |  3.2498e-09 |  3.5480e-08 |     160.00 |   730131
  -------+-------------+-------------+------------+---------

  No warmstart (tolerance = 0):
   Iters |    Mean Err |     Max Err | Mean Iters | LS evals
  -------+-------------+-------------+------------+---------
       5 |  9.0740e-01 |  5.0045e+00 |       5.00 |    22123
      10 |  3.9506e-01 |  2.1927e+00 |      10.00 |    44879
      20 |  1.2496e-01 |  6.8911e-01 |      20.00 |    90341
      40 |  1.2846e-02 |  6.9533e-02 |      40.00 |   182869
      80 |  1.0288e-04 |  8.6457e-04 |      80.00 |   368312
     160 |  5.9820e-09 |  5.0903e-08 |     160.00 |   738479
  -------+-------------+-------------+------------+---------

  Tolerance sweep (iterations = 100, warmstart):
         Tol |    Mean Err |     Max Err | Mean Iters |  Max Iters |   Solver us | LS evals
  -----------+-------------+-------------+------------+------------+-------------+---------
       1e-04 |  1.1297e-02 |  8.9331e-02 |      34.88 |         51 |   131002.94 |    12052
       1e-06 |  1.0907e-03 |  7.7468e-03 |      50.87 |         72 |   184172.44 |    16700
       1e-08 |  1.1485e-04 |  1.0085e-03 |      66.82 |         91 |   232189.34 |    20194
       1e-10 |  1.1357e-05 |  8.1547e-05 |      81.97 |        100 |   276114.42 |    23264
       1e-12 |  3.7695e-06 |  2.8592e-05 |      90.47 |        100 |   299526.58 |    24964
           0 |  3.5019e-06 |  2.8592e-05 |     100.00 |        100 |  2062208.36 |   456276
  -----------+-------------+-------------+------------+------------+-------------+---------
  Total solver time: 3185214.08 us, avg time per iter: 74.9445 us

  Pipeline mode (consecutive mj_step, tolerance = 1e-8):
  1000 steps, nv = 654
  Steps/s          : 380
  us/step (total)  : 2630.0
  us/step (constr) : 2103.7  (80.0%)
  CG iters/step    : 63.28
  LS evals/step    : 190.75
  us/iter          : 33.24

================================================================
2/4: PRP+ + float64
================================================================

CG Convergence: 2humanoid100.xml
  1000 Newton steps, 100 evaluation points
  nv = 654, nq = 756
  metric: ||qacc_cg - qacc_newton|| / ||qacc_newton||

  Warmstart (tolerance = 0):
   Iters |    Mean Err |     Max Err | Mean Iters | LS evals
  -------+-------------+-------------+------------+---------
       5 |  3.8533e-01 |  1.4285e+00 |       5.00 |    22228
      10 |  2.0808e-01 |  9.9315e-01 |      10.00 |    44873
      20 |  6.4978e-02 |  2.3410e-01 |      20.00 |    89349
      40 |  5.2895e-03 |  2.1916e-02 |      40.00 |   179827
      80 |  4.0188e-05 |  3.0010e-04 |      80.00 |   363740
     160 |  3.2891e-09 |  3.5480e-08 |     160.00 |   733905
  -------+-------------+-------------+------------+---------

  No warmstart (tolerance = 0):
   Iters |    Mean Err |     Max Err | Mean Iters | LS evals
  -------+-------------+-------------+------------+---------
       5 |  9.0740e-01 |  5.0045e+00 |       5.00 |    22590
      10 |  3.9506e-01 |  2.1927e+00 |      10.00 |    45093
      20 |  1.2496e-01 |  6.8911e-01 |      20.00 |    90393
      40 |  1.2846e-02 |  6.9533e-02 |      40.00 |   182422
      80 |  1.0288e-04 |  8.6457e-04 |      80.00 |   367264
     160 |  5.9811e-09 |  5.0903e-08 |     160.00 |   739556
  -------+-------------+-------------+------------+---------

  Tolerance sweep (iterations = 100, warmstart):
         Tol |    Mean Err |     Max Err | Mean Iters |  Max Iters |   Solver us | LS evals
  -----------+-------------+-------------+------------+------------+-------------+---------
       1e-04 |  1.1325e-02 |  8.9941e-02 |      34.95 |         52 |   129456.81 |    12060
       1e-06 |  1.0910e-03 |  7.7469e-03 |      50.85 |         72 |   181004.51 |    16687
       1e-08 |  1.1488e-04 |  1.0085e-03 |      66.83 |         91 |   228183.13 |    20189
       1e-10 |  1.1401e-05 |  8.1547e-05 |      81.98 |        100 |   269635.40 |    23259
       1e-12 |  3.8040e-06 |  2.8592e-05 |      90.52 |        100 |   293811.25 |    24967
           0 |  3.5543e-06 |  2.8592e-05 |     100.00 |        100 |  2051927.47 |   456000
  -----------+-------------+-------------+------------+------------+-------------+---------
  Total solver time: 3154018.57 us, avg time per iter: 74.1895 us

  Pipeline mode (consecutive mj_step, tolerance = 1e-8):
  1000 steps, nv = 654
  Steps/s          : 382
  us/step (total)  : 2616.6
  us/step (constr) : 2091.8  (79.9%)
  CG iters/step    : 63.57
  LS evals/step    : 193.35
  us/iter          : 32.91

================================================================
3/4: HZ + float32
================================================================

CG Convergence: 2humanoid100.xml
  1000 Newton steps, 100 evaluation points
  nv = 654, nq = 756
  metric: ||qacc_cg - qacc_newton|| / ||qacc_newton||

  Warmstart (tolerance = 0):
   Iters |    Mean Err |     Max Err | Mean Iters | LS evals
  -------+-------------+-------------+------------+---------
       5 |  3.6748e-01 |  1.2281e+00 |       5.00 |    19239
      10 |  2.0034e-01 |  6.8689e-01 |      10.00 |    39001
      20 |  6.1972e-02 |  1.9859e-01 |      20.00 |    80112
      40 |  4.0704e-03 |  1.5797e-02 |      40.00 |   168211
      80 |  2.4380e-05 |  1.5803e-04 |      79.45 |   347735
     160 |  7.7413e-07 |  4.4732e-06 |     157.27 |   704210
  -------+-------------+-------------+------------+---------

  No warmstart (tolerance = 0):
   Iters |    Mean Err |     Max Err | Mean Iters | LS evals
  -------+-------------+-------------+------------+---------
       5 |  9.3385e-01 |  4.9648e+00 |       5.00 |    19272
      10 |  3.6117e-01 |  1.9618e+00 |      10.00 |    37982
      20 |  9.7490e-02 |  5.1451e-01 |      20.00 |    76502
      40 |  9.5924e-03 |  5.5088e-02 |      40.00 |   162782
      80 |  6.7689e-05 |  5.1113e-04 |      79.91 |   344281
     160 |  1.5541e-06 |  7.6955e-06 |     157.30 |   697076
  -------+-------------+-------------+------------+---------

  Tolerance sweep (iterations = 100, warmstart):
         Tol |    Mean Err |     Max Err | Mean Iters |  Max Iters |   Solver us | LS evals
  -----------+-------------+-------------+------------+------------+-------------+---------
       1e-04 |  1.5891e-02 |  1.2929e-01 |      32.56 |         50 |   136254.00 |    10980
       1e-06 |  1.5719e-03 |  1.0990e-02 |      47.42 |         68 |   193566.00 |    15418
       1e-08 |  1.6260e-04 |  1.0680e-03 |      62.70 |         86 |   252661.00 |    20162
       1e-10 |  1.5664e-05 |  1.0999e-04 |      78.10 |        100 |   311535.00 |    24509
       1e-12 |  2.8152e-06 |  1.5236e-05 |      90.39 |        100 |   356814.00 |    27902
           0 |  2.4989e-06 |  1.5025e-05 |      99.05 |        100 |  1980580.00 |   436825
  -----------+-------------+-------------+------------+------------+-------------+---------
  Total solver time: 3231410.00 us, avg time per iter: 78.7726 us

  Pipeline mode (consecutive mj_step, tolerance = 1e-8):
  1000 steps, nv = 654
  Steps/s          : 349
  us/step (total)  : 2862.7
  us/step (constr) : 2379.3  (83.1%)
  CG iters/step    : 61.97
  LS evals/step    : 199.01
  us/iter          : 38.39

================================================================
4/4: PRP+ + float32
================================================================

CG Convergence: 2humanoid100.xml
  1000 Newton steps, 100 evaluation points
  nv = 654, nq = 756
  metric: ||qacc_cg - qacc_newton|| / ||qacc_newton||

  Warmstart (tolerance = 0):
   Iters |    Mean Err |     Max Err | Mean Iters | LS evals
  -------+-------------+-------------+------------+---------
       5 |  3.6753e-01 |  1.2281e+00 |       5.00 |    19052
      10 |  2.0028e-01 |  6.8689e-01 |      10.00 |    38761
      20 |  6.1737e-02 |  1.9863e-01 |      20.00 |    79937
      40 |  4.0915e-03 |  1.5821e-02 |      39.99 |   168159
      80 |  2.4360e-05 |  1.5808e-04 |      79.59 |   348385
     160 |  7.8367e-07 |  4.1549e-06 |     157.04 |   700760
  -------+-------------+-------------+------------+---------

  No warmstart (tolerance = 0):
   Iters |    Mean Err |     Max Err | Mean Iters | LS evals
  -------+-------------+-------------+------------+---------
       5 |  9.3385e-01 |  4.9648e+00 |       5.00 |    19494
      10 |  3.6117e-01 |  1.9618e+00 |      10.00 |    38480
      20 |  9.7485e-02 |  5.1451e-01 |      20.00 |    77213
      40 |  9.5904e-03 |  5.5078e-02 |      40.00 |   162472
      80 |  6.7647e-05 |  5.1087e-04 |      79.87 |   342990
     160 |  1.4979e-06 |  7.2291e-06 |     157.92 |   699052
  -------+-------------+-------------+------------+---------

  Tolerance sweep (iterations = 100, warmstart):
         Tol |    Mean Err |     Max Err | Mean Iters |  Max Iters |   Solver us | LS evals
  -----------+-------------+-------------+------------+------------+-------------+---------
       1e-04 |  1.5998e-02 |  1.3172e-01 |      32.49 |         50 |   135111.00 |    10953
       1e-06 |  1.5878e-03 |  1.1052e-02 |      47.33 |         67 |   190914.00 |    15418
       1e-08 |  1.5901e-04 |  1.0680e-03 |      62.65 |         84 |   250609.00 |    20215
       1e-10 |  1.5953e-05 |  1.1116e-04 |      78.01 |        100 |   307067.00 |    24562
       1e-12 |  2.8520e-06 |  1.5174e-05 |      90.27 |        100 |   353010.00 |    27931
           0 |  2.5161e-06 |  1.5129e-05 |      99.39 |        100 |  1999478.00 |   438790
  -----------+-------------+-------------+------------+------------+-------------+---------
  Total solver time: 3236189.00 us, avg time per iter: 78.9045 us

  Pipeline mode (consecutive mj_step, tolerance = 1e-8):
  1000 steps, nv = 654
  Steps/s          : 298
  us/step (total)  : 3352.8
  us/step (constr) : 2832.0  (84.5%)
  CG iters/step    : 68.43
  LS evals/step    : 226.33
  us/iter          : 41.39
```

PiperOrigin-RevId: 928590104
Change-Id: I1a96730f50f444d6141d8978feb3519009daf320
2026-06-08 08:54:07 -07:00
Haroon Qureshi 7e790879ef Fix namespace for filament-specific "mjrf" API.
PiperOrigin-RevId: 928582582
Change-Id: Idc312607b2f063d8ace8d5cc79bfbc8ac588d13f
2026-06-08 08:37:52 -07:00
Alessio Quaglino 7a7dc7ccad Add support for loading 1D flex components from OBJ line segments.
The obj_decoder plugin is updated to parse line segments ('l') from OBJ files and represent them as degenerate triangles. The user_flexcomp compiler now supports flex dimensions of 1, using these parsed line segments to define the 1D flex elements. The compile sample's error reporting is also improved.

PiperOrigin-RevId: 928566870
Change-Id: I6920729d1b1d5aeb391401c3245ebb1d4784c190
2026-06-08 08:03:30 -07:00
Kyle Bayes ac7f198536 Tune constants for nativeccd to perform better with single precision.
PiperOrigin-RevId: 928549147
Change-Id: Ic28c60f73e92bb1b9578c56f790b6cda94875907
2026-06-08 07:21:17 -07:00
Haroon Qureshi 116cfe9c70 Remove initial width/height arguments.
The ValidateSwapChains function will correctly set up swap chains
before any render calls, negating the need to have something done
in the constructor.

PiperOrigin-RevId: 928529339
Change-Id: Ie584d57f649730adc092f8683f18697892a5a14f
2026-06-08 06:34:40 -07:00
Kyle Bayes 318880126f Provide better dedupe logic in multiccd in edge collision case.
PiperOrigin-RevId: 928519426
Change-Id: I67531d1c346b1b38c098eaf32c3b13fa7d0c8eaf
2026-06-08 06:07:31 -07:00
Yuval Tassa 6c33e16bf1 Canonicalize mjVisual macros to include type and dimension.
PiperOrigin-RevId: 928506110
Change-Id: If5d031f9d87892f13486ae9ccde23c16131212de
2026-06-08 05:30:57 -07:00
Haroon Qureshi da5500c202 Implement additional draw modes:
- Default rendering but without textures.
- Island coloring based on sleep state.
- Selected object highlighting.

PiperOrigin-RevId: 928482603
Change-Id: I5eda1307bc6e71a4b0b2933b5b941e945cb9de75
2026-06-08 04:29:27 -07:00
Haroon Qureshi 543165a6cc Expose hsv2rgb as internally public function.
PiperOrigin-RevId: 928464175
Change-Id: I57ef75f28663b0da89b9af7bf730d82b965093bf
2026-06-08 03:44:50 -07:00
Haroon Qureshi b17b5f7918 Expose mjv_flexBodyIdAndPoint as a helper function.
Use the above in studio rather than a custom implementation.

PiperOrigin-RevId: 928432476
Change-Id: I99d772c4baf7260abbf9ac8f6d8032704f1ba769
2026-06-08 02:28:39 -07:00
Yuval Tassa ea2d785e0a Improve quality of maxhullvert coarse convex hulls using Qhull's Q9 option.
PiperOrigin-RevId: 928417339
Change-Id: I59ecd454f063f2e32e1c3ce08eb4a18506ddf8c8
2026-06-08 01:56:24 -07:00
Haroon Qureshi 0093210173 Remove hard-coded render target formats.
The formats are defined in the config.

PiperOrigin-RevId: 928412818
Change-Id: I20ea72214d8e1484723793d8a3f89cdcb4b617b1
2026-06-08 01:45:24 -07:00
Kevin Zakka 5fe916045c Replace strncpy with memcpy for gridlayout initialization.
memcpy is more appropriate here as the source and destination buffers have the same size, ensuring the entire buffer is copied.

PiperOrigin-RevId: 927395770
Change-Id: Idbe9dade3160f593060fae5783743b28c0452695
2026-06-05 11:25:49 -07:00
Haroon Qureshi 511cf27ff8 Move segmentation coloring logic into renderer.
PiperOrigin-RevId: 927300828
Change-Id: I994c5742ec30993d2245df167042e72820f91ac7
2026-06-05 07:57:59 -07:00
Haroon Qureshi 8fbacf2883 Introduce MaterialManager to allow sharing of material instances.
PiperOrigin-RevId: 927139826
Change-Id: I923a24f28ab7af3a8c854286f064e851b9fd494e
2026-06-05 01:17:37 -07:00
Haroon Qureshi 53ac994759 Add missing files.
PiperOrigin-RevId: 926123240
Change-Id: I59b9baaa106ef12a9bf3c7a6399558753c2c5415
2026-06-03 10:27:41 -07:00
Google DeepMind 36f5c4899c Remove the usage of Texture::setImage that uses FaceOffsets
PiperOrigin-RevId: 926092842
Change-Id: I8010804c6dda89d41ebaf650af776505e5c5ed34
2026-06-03 09:47:37 -07:00
Haroon Qureshi 4d70b18048 Manage reflections at the scene level.
Renderables may be created/destroyed frequently causing issues with
the underlying RenderTargets used for reflections. Instead, use a
ReflectionManager (associated with a Scene) to manage the RenderTargets.

PiperOrigin-RevId: 926072766
Change-Id: I56c70000183417a92ab9297bc6fec5779f484cbd
2026-06-03 09:18:32 -07:00
Kevin Zakka 25afa6b732 Fix wasm OOM on large models: 32mb stack, raise MAXIMUM_MEMORY to 4gb.
PiperOrigin-RevId: 926060014
Change-Id: I8c4e152321737b1f4cc963f3c6c424af2fe951b4
2026-06-03 08:59:05 -07:00
Kevin Zakka 0897e3aec1 Skip the prefetcher when the URL scheme isn't fetchable.
Drag-and-drop uploads go through Module.loadFile and never reached the prefetcher. This is a guard for future provider schemes (e.g., vfs) that shouldn't be passed to fetch().

PiperOrigin-RevId: 926042158
Change-Id: I119d5b1a7512f8e84bb4c752414797593a1e98cd
2026-06-03 08:23:19 -07:00
Kyle Bayes 558366f364 Always normalize in planeNormal to reduce rounding errors in single precision.
PiperOrigin-RevId: 926002329
Change-Id: I682f3b90249e60838c2432231b3181e57c565c28
2026-06-03 07:04:12 -07:00
Haroon Qureshi 4cfdf5f34b Bind materials before rendering reflection passes.
PiperOrigin-RevId: 925911124
Change-Id: I134d29424233ccbf57f56e7379e8830662a57836
2026-06-03 03:31:03 -07:00
Haroon Qureshi 0fe2064847 Cleanup Renderable API.
Add function for getting the material. Remove unused/unneeded functions.

PiperOrigin-RevId: 925847769
Change-Id: Iefaf9112b7419830eb2dc4d1323e9c27725c4b16
2026-06-03 01:06:21 -07:00
Yuval Tassa 7b9b88060e Refactor mj_fullM. This change is part of the deprecation of mjData.qM.
PiperOrigin-RevId: 925669464
Change-Id: I4889c66591bc1df4c31135a13776052aad491f7a
2026-06-02 17:22:55 -07:00
Matija Kecman 0e4749501c Allow custom step function in StepControl::Advance.
The StepControl::Advance method now accepts an optional std::function to be used instead of mj_step. This allows for custom simulation logic to be executed within the stepping loop. The Python bindings for StepControl::advance have been updated to support passing a Python callable as the custom step function.

PiperOrigin-RevId: 925393132
Change-Id: Id2820c4b55cbdfee6b01adc2395e99a990d4e7a3
2026-06-02 09:20:06 -07:00
Kyle Bayes 3a5626bc27 Align GJK internal memory to avoid misalignment segfaults when compiled as single precision. This is effectively a no-op under double precision.
PiperOrigin-RevId: 925389982
Change-Id: I7117779669965ebf72cb77ccbece419acf9b1b96
2026-06-02 09:15:26 -07:00
Copybara-Service 15cbc8fb55 Merge pull request #3156 from andrewkaufman:newton-schemas
PiperOrigin-RevId: 925328794
Change-Id: If45b8659ea9b88785660331bca5ee837ac172f67
2026-06-02 07:06:59 -07:00
Yuval Tassa 062b0f1ea6 Remove deprecated mju_{error,warning}_{i,s} functions.
PiperOrigin-RevId: 925204136
Change-Id: Ia877d08a135092db8037d04e6a237e81325a1d7c
2026-06-02 01:59:05 -07:00
Alessio Quaglino 91c92279d2 Enable interior nodes for interpolated flex shell mode.
Previously shell mode required cellcount=1 along at least one axis. This CL
adds support for cellcount > 1 in all three axes by pinning interior grid nodes
to the parent body and reconstructing their positions from boundary nodes via
Transfinite Interpolation (TFI).

PiperOrigin-RevId: 924314800
Change-Id: I8c2438f4866dd4133feed65f535a1ab69f0c9188
2026-05-31 10:36:01 -07:00
Yuval Tassa 4548e81e4d Rename efc_diagApprox -> efc_diagA.
The field now stores either an approximate or exact diagonal of the constraint matrix A, so the name is made more general.

PiperOrigin-RevId: 924244954
Change-Id: I62b2f76531fb88b7b3bf96e6769940197596702b
2026-05-31 04:54:11 -07:00
Yuval Tassa cd6db9ebe2 Improve CG solver precision and stability under float32 via line search refactor
Fixes #2313

This CL combines two complementary improvements to the Conjugate Gradient (CG) solver, significantly improving numerical precision, stability, and efficiency, particularly in single precision (float32).

1. Line Search Cost Evaluation Refactor: Previously, solver improvement was calculated by subtracting absolute costs: cost(alpha) - cost(0). In highly converged states or single precision, this is susceptible to catastrophic cancellation. We refactor PrimalSearch to compute the cost delta directly, dramatically improving precision.

2. Improved Solver Termination Condition: Near the float32 precision limit, line search deltas can occasionally be slightly negative due to numerical noise. Previously, any value below m->opt.tolerance (including negative values) triggered termination, halting the solver and locking in destabilizing steps. We update the termination condition to require positive improvement (0 < improvement < m->opt.tolerance), allowing the solver to continue iterating and recover stability.

Together, these changes yield substantial improvements, see reduced tolerances herein.

PiperOrigin-RevId: 924229669
Change-Id: Ic0bbefaed090f3a8b1e79ab8d45422c3e86fb56c
2026-05-31 04:00:09 -07:00
Yuval Tassa 3a6e0ee9b3 Reduce effect of infinite planes on center and extent statistics
PiperOrigin-RevId: 923868757
Change-Id: I3630d29f05a19e0767549284abbe8a8d9386894b
2026-05-30 04:12:07 -07:00
Yuval Tassa d7e872b6f9 Add UI control for MuJoCo threadpool size.
PiperOrigin-RevId: 923860258
Change-Id: I11dc5d7904f1c3657d7e1dd2b0e3c7864c0c7ead
2026-05-30 03:41:38 -07:00
Yuval Tassa 96bf8aea81 Move island-specific sparse matrices from arena to stack.
PiperOrigin-RevId: 923850345
Change-Id: I9683d7554b15b7cd8c45a8dce7814640aa266452
2026-05-30 03:09:46 -07:00
Yuval Tassa 5d782a2bb8 Fix memory overallocation in sparse primal solvers.
PiperOrigin-RevId: 923586079
Change-Id: I8d484b840063c0a7a8a79c5bdc9074a57d2ee55f
2026-05-29 13:51:47 -07:00
Haroon Qureshi f63b92da5e Clear draw queue instead of failing if rendering skipped.
PiperOrigin-RevId: 923420183
Change-Id: I34aac76810a7bf0e4a0394ebe27b45a8fc32f110
2026-05-29 08:09:15 -07:00
Kyle Bayes c7d340be4f Cap box<->box collisions.
PiperOrigin-RevId: 923312868
Change-Id: I801d76cf1d1d7b9ed1535d3e3c723a5e8af4162a
2026-05-29 03:52:57 -07:00
Copybara-Service 46d2405b42 Merge pull request #3288 from davidhozic:fix/strchr-const-char
PiperOrigin-RevId: 923297843
Change-Id: I13b07c6cf0f611a8b3ee797dac94b35ce8d9deb4
2026-05-29 03:16:33 -07:00
Copybara-Service 9af965f241 Merge pull request #3120 from Ashutosh0x:fix/safe-overflow-msvc
PiperOrigin-RevId: 923296001
Change-Id: I037dcc55c91d6eb68b3e63b34a0e059c796b5116
2026-05-29 03:12:40 -07:00
Kyle Bayes b612d352d4 Fix GitHub Actions for threading.
PiperOrigin-RevId: 922926969
Change-Id: I968e6b130b6125dbc0ec65ba913d04292270b563
2026-05-28 12:57:16 -07:00
Kyle Bayes b935d4153c Add new mju_threadpool API function, and delete old threading API.
PiperOrigin-RevId: 922838541
Change-Id: Id9f7e0fb298ffde61fcc49a802dc78971858ce51
2026-05-28 10:11:44 -07:00