-
Notifications
You must be signed in to change notification settings - Fork 15
compare metadata for hot reloading #4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,7 +9,7 @@ var compute_shader_file_paths : Array = Array() | |
| var rd : RenderingDevice | ||
|
|
||
| var shader_compilations = {} | ||
| var shader_code_cache = {} | ||
| var shader_compilation_time = {} | ||
|
|
||
| var compute_shader_kernel_compilations = {} | ||
|
|
||
|
|
@@ -45,7 +45,6 @@ func compile_shader(shader_file_path) -> void: | |
| rd.free_rid(shader_compilations[shader_name]) | ||
|
|
||
| var shader_code = FileAccess.open(shader_file_path, FileAccess.READ).get_as_text() | ||
| shader_code_cache[shader_name] = shader_code | ||
|
|
||
| var shader_compilation = RID() | ||
|
|
||
|
|
@@ -66,6 +65,7 @@ func compile_shader(shader_file_path) -> void: | |
| return | ||
|
|
||
| shader_compilations[shader_name] = shader_compilation | ||
| shader_compilation_time[shader_file_path] = FileAccess.get_modified_time(shader_file_path) | ||
|
|
||
|
|
||
| func compile_compute_shader(compute_shader_file_path) -> void: | ||
|
|
@@ -75,7 +75,7 @@ func compile_compute_shader(compute_shader_file_path) -> void: | |
|
|
||
| var file = FileAccess.open(compute_shader_file_path, FileAccess.READ) | ||
| var raw_shader_code_string = file.get_as_text() | ||
| shader_code_cache[compute_shader_file_path] = raw_shader_code_string | ||
| shader_compilation_time[compute_shader_file_path] = FileAccess.get_modified_time(compute_shader_file_path) | ||
|
|
||
| var raw_shader_code = raw_shader_code_string.split("\n") | ||
|
|
||
|
|
@@ -200,7 +200,7 @@ func _init() -> void: | |
| func _process(delta: float) -> void: | ||
| # Compare current shader code with cached shader code and recompile if changed | ||
| for file_path in compute_shader_file_paths: | ||
| if shader_code_cache[file_path] != FileAccess.open(file_path, FileAccess.READ).get_as_text(): | ||
| if shader_compilation_time[file_path] != FileAccess.get_modified_time(file_path): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe keep the file content check after the modification time check? Would still cut down time considerably, but also avoids edge cases—for example, an autosaving editor writing the exact same content to the file. Don't have the stats, but I'm fairly certain compilation is much more expensive in almost all cases than reading the file contents so it's best avoided if possible. Compilations should be infrequent anyway so the negligible increase in cost of also reading the file contents as well should be okay. |
||
| var shader_name = get_shader_name(file_path) | ||
|
|
||
| # Free existing kernels | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this might be better named
shader_modified_timeorraw_shader_modified_time. It's possible the shader may be modified while this is not running, making modification time != compilation time.