Skip to content

Commit

Permalink
Add a launch option to compile all uber shader variant.
Browse files Browse the repository at this point in the history
  • Loading branch information
roeas committed Oct 23, 2023
1 parent 3fcf2af commit 029ae5b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
20 changes: 16 additions & 4 deletions Engine/Source/Editor/EditorApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void EditorApp::Init(engine::EngineInitArgs initArgs)
InitEngineRenderers();

// Add shader build tasks and create a thread to update tasks.
InitShaderPrograms();
InitShaderPrograms(initArgs.compileAllShaders);
m_pEditorImGuiContext->AddStaticLayer(std::make_unique<Splash>("Splash"));

std::thread resourceThread([]()
Expand Down Expand Up @@ -518,14 +518,26 @@ bool EditorApp::IsAtmosphericScatteringEnable() const
&& engine::GraphicsBackend::OpenGLES != backend;
}

void EditorApp::InitShaderPrograms() const
void EditorApp::InitShaderPrograms(bool compileAllShaders) const
{
ShaderBuilder::CompileRegisteredNonUberShader(m_pRenderContext.get());
ShaderBuilder::CompileRegisteredUberShader(m_pRenderContext.get(), m_pSceneWorld->GetPBRMaterialType());

if (compileAllShaders)
{
ShaderBuilder::CompileUberShaderAllVariants(m_pRenderContext.get(), m_pSceneWorld->GetPBRMaterialType());

#ifdef ENABLE_DDGI
ShaderBuilder::CompileUberShaderAllVariants(m_pRenderContext.get(), m_pSceneWorld->GetDDGIMaterialType());
#endif
}
else
{
ShaderBuilder::CompileRegisteredUberShader(m_pRenderContext.get(), m_pSceneWorld->GetPBRMaterialType());

#ifdef ENABLE_DDGI
ShaderBuilder::CompileRegisteredUberShader(m_pSceneWorld->GetDDGIMaterialType());
ShaderBuilder::CompileRegisteredUberShader(m_pRenderContext.get(), m_pSceneWorld->GetDDGIMaterialType());
#endif
}
}

void EditorApp::InitEditorController()
Expand Down
2 changes: 1 addition & 1 deletion Engine/Source/Editor/EditorApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class EditorApp final : public engine::IApplication
void EditorRenderersWarmup();
void EngineRenderersWarmup();

void InitShaderPrograms() const;
void InitShaderPrograms(bool compileAllShaders = false) const;
void AddEditorRenderer(std::unique_ptr<engine::Renderer> pRenderer);
void AddEngineRenderer(std::unique_ptr<engine::Renderer> pRenderer);

Expand Down
3 changes: 2 additions & 1 deletion Engine/Source/Editor/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ int main()

pEngine->Init({ .pTitle = "CatDogEditor", .pIconFilePath = "editor_icon.png",
.width = 1280, .height = 720, .useFullScreen = false,
.language = Language::ChineseSimplied, .backend = GraphicsBackend::Direct3D11 });
.language = Language::ChineseSimplied,
.backend = GraphicsBackend::Direct3D11, .compileAllShaders = true });

pEngine->Run();

Expand Down
1 change: 0 additions & 1 deletion Engine/Source/Editor/Resources/ShaderBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class ShaderBuilder
public:
static void CompileRegisteredNonUberShader(engine::RenderContext* pRenderContext);
static void CompileRegisteredUberShader(engine::RenderContext* pRenderContext, engine::MaterialType* pMaterialType);

static void CompileUberShaderAllVariants(engine::RenderContext* pRenderContext, engine::MaterialType* pMaterialType);

// Compile specified shader program/program variant.
Expand Down
1 change: 1 addition & 0 deletions Engine/Source/Runtime/Application/IApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ struct EngineInitArgs
bool useFullScreen = false;
Language language = Language::English;
GraphicsBackend backend = GraphicsBackend::Direct3D11;
bool compileAllShaders = false;
};

class IApplication
Expand Down

0 comments on commit 029ae5b

Please sign in to comment.