Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b549be9

Browse files
ShabbyXCommit Bot
authored and
Commit Bot
committed
Vulkan: Warm up glslang on startup
As soon as glslang is initialized (which is done when EGL is initialized), try to compile a simple shader. This will warm up glslang's internals to avoid hitches on first shader compilation when a WebGL application starts. Potential future optimization is to use a worker thread to do this. Bug: chromium:1091440 Change-Id: I6ac22e982d748af52a6e8b61239889425edc2edb Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2280401 Reviewed-by: Jamie Madill <[email protected]> Commit-Queue: Shahbaz Youssefi <[email protected]>
1 parent fac6817 commit b549be9

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/libANGLE/renderer/glslang_wrapper_utils.cpp

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ ANGLE_REENABLE_EXTRA_SEMI_WARNING
3636
#include "common/utilities.h"
3737
#include "libANGLE/Caps.h"
3838
#include "libANGLE/ProgramLinkedResources.h"
39+
#include "libANGLE/trace.h"
3940

4041
#define ANGLE_GLSLANG_CHECK(CALLBACK, TEST, ERR) \
4142
do \
@@ -99,6 +100,29 @@ void GetBuiltInResourcesFromCaps(const gl::Caps &caps, TBuiltInResource *outBuil
99100
outBuiltInResources->maxClipDistances = caps.maxClipDistances;
100101
}
101102

103+
// Run at startup to warm up glslang's internals to avoid hitches on first shader compile.
104+
void GlslangWarmup()
105+
{
106+
ANGLE_TRACE_EVENT0("gpu.angle,startup", "GlslangWarmup");
107+
108+
EShMessages messages = static_cast<EShMessages>(EShMsgSpvRules | EShMsgVulkanRules);
109+
// EShMessages messages = EShMsgDefault;
110+
111+
TBuiltInResource builtInResources(glslang::DefaultTBuiltInResource);
112+
glslang::TShader dummyShader(EShLangVertex);
113+
114+
const char *kShaderString = R"(#version 450 core
115+
void main(){}
116+
)";
117+
const int kShaderLength = static_cast<int>(strlen(kShaderString));
118+
119+
dummyShader.setStringsWithLengths(&kShaderString, &kShaderLength, 1);
120+
dummyShader.setEntryPoint("main");
121+
122+
bool result = dummyShader.parse(&builtInResources, 450, ECoreProfile, false, false, messages);
123+
ASSERT(result);
124+
}
125+
102126
// Test if there are non-zero indices in the uniform name, returning false in that case. This
103127
// happens for multi-dimensional arrays, where a uniform is created for every possible index of the
104128
// array (except for the innermost dimension). When assigning decorations (set/binding/etc), only
@@ -1704,6 +1728,7 @@ void GlslangInitialize()
17041728
{
17051729
int result = ShInitialize();
17061730
ASSERT(result != 0);
1731+
GlslangWarmup();
17071732
}
17081733

17091734
void GlslangRelease()
@@ -1937,6 +1962,8 @@ angle::Result GlslangGetShaderSpirvCode(const GlslangErrorCallback &callback,
19371962
continue;
19381963
}
19391964

1965+
ANGLE_TRACE_EVENT0("gpu.angle", "GlslangGetShaderSpirvCode TShader::parse");
1966+
19401967
const char *shaderString = shaderSources[shaderType].c_str();
19411968
int shaderLength = static_cast<int>(shaderSources[shaderType].size());
19421969

@@ -1976,4 +2003,5 @@ angle::Result GlslangGetShaderSpirvCode(const GlslangErrorCallback &callback,
19762003

19772004
return angle::Result::Continue;
19782005
}
2006+
19792007
} // namespace rx

src/libANGLE/renderer/vulkan/ProgramVk.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ std::unique_ptr<LinkEvent> ProgramVk::link(const gl::Context *context,
286286
const gl::ProgramLinkedResources &resources,
287287
gl::InfoLog &infoLog)
288288
{
289+
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramVk::link");
290+
289291
ContextVk *contextVk = vk::GetImpl(context);
290292
// Link resources before calling GetShaderSource to make sure they are ready for the set/binding
291293
// assignment done in that function.

0 commit comments

Comments
 (0)