On Tue, 6 Oct 2026 07:25:10 GMT, Nir Lisker <[email protected]> wrote:
>> 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). > > Good to see it will help other pipelines as well. I would expect the upload > calls to be cheaper in D3D12, so the performance gain will probably be lower. > Same with Metal if it's affected. I forgot one more thing @nlisker - could you adjust the JBS title and PR title to mention it only affects D3D9? Just adding a D3D9 prefix would be enough, so "8392736: D3D9: Cache lights..." ------------- PR Comment: https://git.openjdk.org/jfx/pull/2319#issuecomment-6146384583
