godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.62k stars 21.1k forks source link

Using "Stop Running Project(F8)" button prevents generating vulkan pipeline cache #85639

Open masterthdev opened 11 months ago

masterthdev commented 11 months ago

Godot version

4.2.stable

System information

Godot v4.2.stable - Windows 10.0.22000 - Vulkan (Forward+) - dedicated AMD Radeon RX 5600M (Advanced Micro Devices, Inc.; 31.0.21023.2010) - AMD Ryzen 7 4800H with Radeon Graphics (16 Threads)

Issue description

Edit: Check my latest reply, looks like using "Stop Running Project(F8)" button prevents generating vulkan cache file.

Shader loading is very slow on Forward+ compared to mobile and compatibility renderers, when running a project with F5/F6.

Shader cache and vulkan pipeline cache at %AppData%\Godot\app_userdata\projectname\ directory don't regenerate, but most shaders don't load any faster.

I deleted all caches and used --verbose output to measure shader loading times. Looks like there is no way to output timestamps, I had to screen record console output.

Caches I deleted: %AppData%\Roaming\Godot\ %AppData%\Local\Godot\ .godot /AMD folders from each drive(includes directx caches but deleted anyway) Shader cache from gpu driver

I repeated the test multiple times, timings below were consistent each run. Shader time is time between first and last "Shader 'shadername' (group x) SHA256: XXXX..." line in verbose output.

Project loading time from project manager Without cache With Cache Shaders Without Cache Shaders With Cache
Forward+ 8000ms 6800ms 1600ms 1000ms
Mobile 7000ms 6100ms 733ms 267ms
Compat 6867ms 5900ms 366ms 133ms
Project running time with F6 Without cache With Cache Shaders Without Cache Shaders With Cache
Forward+ 14133ms 13200ms 12633ms 11900ms
Mobile 3100ms 2433ms 1600ms 966ms
Compat 1533ms 1400ms 334ms 100ms
Notable Forward+ shaders Without cache With Cache
ParticlesCopyShaderRD 500ms 500ms
SsilShaderRD 267ms 233ms
SdfgiPreprocessShaderRD 2100ms 2067ms
SdfgiDirectLightShaderRD 300ms 300ms
SdfgiIntegrateShaderRD 433ms 400ms
GiShaderRD 4033ms 4000ms
VolumetricFogProcessShaderRD 200ms 200ms
CubemapFilterShaderRD 1133ms 1100ms

I have this issue in all godot 4 builds I tried. If there is a way to profile shader loading times please let me know. I don't know how accurate verbose output is.

Steps to reproduce

Minimal reproduction project

bench.zip

masterthdev commented 11 months ago

Quick Update

I tried CLI benchmark command twice using this command: godot -d camera_3d.tscn --benchmark

It loaded faster in second run. Here are the results:

First run: BENCHMARK:

Second run: BENCHMARK:

Now running the project from editor loads faster too. AppData\Roaming\Godot\app_userdata\projectname\vulkan folder contains two files in benchmarked projects:

pipelines.amd_radeon_rx_5600m.cache pipelines.amd_radeon_rx_5600m.editor.cache

Looks like pipelines.amd_radeon_rx_5600m.cache isn't generated when running project from editor, which prevents loading caches from shader_cache folder. It generated once yesterday but it was very small(307 kb, others are more than 1 mb)

masterthdev commented 11 months ago

I think I found the issue.

Cache files are created on exit. Editor.cache file is created when switching renderer on editor, using 'Quit To Process' List from process menu or using X button on top right corner of the window.

Running project with --benchmark created non-editor cache correctly because I closed it using X button. When running project from the editor, using X button or using get_tree().quit() generates the non-editor cache file. However, using "Stop Running Project(F8)" button on the editor doesn't generate cache file in any renderers. This prevents generating cache file on borderless windows.

Calinou commented 10 months ago

However, using "Stop Running Project(F8)" button on the editor doesn't generate cache file in any renderers.

F8 kills the project's process, so it has no time to intercept this and call a signal handler that can safely write files on exit. (Godot also currently lacks support for SIGTERM signal handlers either way.)

Looks like pipelines.amd_radeon_rx_5600m.cache isn't generated when running project from editor, which prevents loading caches from shader_cache folder.

They may be generating in a different path: https://github.com/godotengine/godot/pull/82972