Skip to content
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

Shader hot compile and reload #421

Merged
merged 9 commits into from
Nov 22, 2023
Merged

Shader hot compile and reload #421

merged 9 commits into from
Nov 22, 2023

Conversation

roeas
Copy link
Contributor

@roeas roeas commented Nov 13, 2023

Finally, we can modify the shader and apply the changes in real time while the editor is launched.

  • The compilation of shader occurs when the editor window regains focus, so make sure that the syntax in shader is correct at this time.
  • The watching directory is CatDogEngine/Engine/BuiltInShaders/shaders.
  • No support for detecting changes in shader header files.

TODO:
We can't handle dependencies between resource files right now.

Engine/Source/Editor/EditorApp.cpp Outdated Show resolved Hide resolved
Engine/Source/Editor/EditorApp.cpp Outdated Show resolved Hide resolved
Engine/Source/Editor/EditorApp.cpp Outdated Show resolved Hide resolved
const std::string& featuresCombine = pMaterialComponent->GetFeaturesCombine();

// New shader feature added, need to compile new variants.
m_pRenderContext->CheckShaderProgram(programName, featuresCombine);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckXXX seems like a const function which just returns bool result if shader program modified. How about UpdateShaderProgram?

Copy link
Contributor Author

@roeas roeas Nov 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will add shader compilt task when we don't have a shader program handle and register the new shader feature to ShaderCollections, which did a little bit more than Update?

Engine/Source/Editor/EditorApp.cpp Outdated Show resolved Hide resolved
Comment on lines +90 to +91
bool m_crtInputFocus = true;
bool m_preInputFocus = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like you want to check if current window is active. This will be improved after my WindowManager refactor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feature is most interested in detecting the moment when the editor window regains focus.

Engine/Source/Editor/Resources/FileWatcher.cpp Outdated Show resolved Hide resolved
Comment on lines 81 to 82
engine::RenderContext* ShaderHotModifyCallbackWrapper::m_pRenderContext = nullptr;
engine::Window* ShaderHotModifyCallbackWrapper::m_pWindow = nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One way to avoid static is to add delegates for EditorApp methods to bind. Here to invoke.
Can be improved after my multiple window PR merged. Or may cause many conflicts.

Engine/Source/Editor/Resources/FileWatcher.cpp Outdated Show resolved Hide resolved
@T-rvw
Copy link
Contributor

T-rvw commented Nov 17, 2023

It is a very useful feature for us to improve experience on developing shaders across platforms.

@roeas roeas requested a review from T-rvw November 21, 2023 09:57
Engine/Source/Runtime/Rendering/RenderContext.cpp Outdated Show resolved Hide resolved
Co-authored-by: Jiajun <75730859+T-rvw@users.noreply.github.com>
@roeas roeas merged commit a7a2baf into main Nov 22, 2023
1 of 3 checks passed
@roeas roeas deleted the hot branch November 22, 2023 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants