Removes unnecessary GPU uploads. There are upload 7 calls (2 
`SetVertexShaderConstantF` and 5 `SetPixelShaderConstantF`) that are called per 
mesh per frame even when the lights affecting these nodes are unchanged.

**History**
There were 3 uploads per mesh per frame: position, color, and ambient color. 
After the addition of attenuation and light types, 4 additional uploads per 
mesh per frame were added: attenuation, range, spotlight factors, and 
direction. This resulted in an FPS hit. All 7 calls are now called only per 
frame, so some of the FPS loss from the additional 4 uploads is recuperated, 
plus a "retroactive" FPS recuperation from the initial 3 uploads.

**Mechanism**
The constant registers retain their values throughout the context's lifetime*, 
so by caching the lights in the context, the per mesh calls are eliminated, 
leaving only the per frame calls. Cache invalidation happens on changes in the 
device, and cache misses happen when a node is affected by different lights. 
The scene will always override the registers, so 1 call per frame is needed to 
upload them for the 3D rendering. More nodes affected by different lights will 
causes more cache misses (uploads), and it depends on the submission order of 
the nodes to the renderer.

**Results**
Using the 3DLighting application, I measured a ~20% increase in FPS in 5k 
`MeshView` tests, both in the single animation and the many animation modes. 
Some tests with low N showed even a 30% or 40% increases, but are not as 
trustworthy. These are the result of a flat per-mesh cost drop (~0.1 
microseconds per mesh on my setup).
The number of lights in the scene is irrelevant since 3 lights are sent to the 
context in any case. This was confirmed in measurements.

Removal of the unneeded (per frame) render calls already on the Java side via 
the dirty bits mechanism could be a future enhancement that affects all the 
pipelines.

* <sub>A "discovery" I made only recently.</sub>

---------
- [x] I confirm that I make this contribution in accordance with the [OpenJDK 
Interim AI Policy](https://openjdk.org/legal/ai).

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

Commit messages:
 - Merge remote-tracking branch 'origin/master' into
 - Whitespaces
 - EOF newline
 - Remove commented out old code
 - Merge remote-tracking branch 'origin/master' into 
8392736_Cache_lights_instead_of_reuploading_to_the_GPU_on_every_call
 - Initial test
 - Merge branch '8327179_Update_the_3D_lighting_application' into 
8392736_Cache_lights_instead_of_reuploading_to_the_GPU_on_every_call
 - Relative path warning
 - Docs clarifications
 - EOF line
 - ... and 33 more: https://git.openjdk.org/jfx/compare/eab83a4b...c38b7ae2

Changes: https://git.openjdk.org/jfx/pull/2319/files
  Webrev: https://webrevs.openjdk.org/?repo=jfx&pr=2319&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8392736
  Stats: 201 lines in 5 files changed: 106 ins; 91 del; 4 mod
  Patch: https://git.openjdk.org/jfx/pull/2319.diff
  Fetch: git fetch https://git.openjdk.org/jfx.git pull/2319/head:pull/2319

PR: https://git.openjdk.org/jfx/pull/2319

Reply via email to