godot
godot copied to clipboard
TextureEditors: Compile shader/material only once
Compile shaders only once for TexturePreview, TextureLayeredEditor and Texture3DEditor. For TexturePreview entire material is compiled (instance uniform used).
This was suggested in https://github.com/godotengine/godot/pull/100157#discussion_r1912274195
Some benchmarks results:
PC spec
CPU: AMD Ryzen 5 5600X (underclocked 75% to reduce coolers noise and CPU temperature) GPU: NVIDIA GeForce RTX 3070 RAM: 32 GB (2×16 GB DDR4-2666) SSD: ADATA SX8200 Pro OS: Windows 10 (build 19045)Startup benchmarks results
hyperfine -m25 -iw1 "godot.windows.editor.x86_64.2303ce8.exe -e --path G:\media\projects\godot\ClickMaskMinimal --quit" "godot.windows.editor.x86_64.pr.exe -e --path G:\media\projects\godot\ClickMaskMinimal --quit"
Benchmark 1: godot.windows.editor.x86_64.2303ce8.exe -e --path G:\media\projects\godot\ClickMaskMinimal --quit
Time (mean ± σ): 14.316 s ± 0.131 s [User: 11.495 s, System: 1.052 s]
Range (min … max): 14.229 s … 14.713 s 25 runs
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
Benchmark 2: godot.windows.editor.x86_64.pr.exe -e --path G:\media\projects\godot\ClickMaskMinimal --quit
Time (mean ± σ): 14.365 s ± 0.124 s [User: 11.550 s, System: 1.019 s]
Range (min … max): 14.219 s … 14.697 s 25 runs
Summary
godot.windows.editor.x86_64.2303ce8.exe -e --path G:\media\projects\godot\ClickMaskMinimal --quit ran
1.00 ± 0.01 times faster than
Shaders init/deinit on editor startup/quit:
register_editor_types - init_shaders, dev, avg for 5 runs: 7445 us
register_editor_types - init_shaders, production, avg for 5 runs: 3158 us
unregister_editor_types - finish_shaders, dev, avg for 5 runs: 121 us
unregister_editor_types - finish_shaders, production, avg for 5 runs: 64 us
I.e. +7ms on dev build and +3ms on production build for editor startup.
Selecting textures (show in Inspector dock) before:
TexturePreview::TexturePreview, production, avg for 10 samples: ~2930 us
Texture3DEditor::edit, production, avg for 10 samples: ~7521 us
TextureLayeredEditor::edit, production, avg for 10 samples: ~2616 us
Selecting textures (show in Inspector dock) after:
TexturePreview::TexturePreview, production, avg for 10 samples: ~472 us
Texture3DEditor::edit, production, avg for 10 samples: ~51 us
TextureLayeredEditor::edit, production, avg for 10 samples: ~68 us
I suppose for TexturePreview it is almost the same as in 4.3 (there was no shader in 4.3).
The code needs some tweaks, but the idea makes sense. I wonder if all shaders could use instance uniforms?
I wonder if all shaders could use instance uniforms?
According to docs, per-instance uniforms do not support textures, so I suppose all shaders could not use it.
Rebased because GitHub was showing conflicts.
Thanks!