Commit b549be96 by Shahbaz Youssefi Committed by Commit Bot

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/+/2280401Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Shahbaz Youssefi <syoussefi@chromium.org>
parent fac68170
......@@ -36,6 +36,7 @@ ANGLE_REENABLE_EXTRA_SEMI_WARNING
#include "common/utilities.h"
#include "libANGLE/Caps.h"
#include "libANGLE/ProgramLinkedResources.h"
#include "libANGLE/trace.h"
#define ANGLE_GLSLANG_CHECK(CALLBACK, TEST, ERR) \
do \
......@@ -99,6 +100,29 @@ void GetBuiltInResourcesFromCaps(const gl::Caps &caps, TBuiltInResource *outBuil
outBuiltInResources->maxClipDistances = caps.maxClipDistances;
}
// Run at startup to warm up glslang's internals to avoid hitches on first shader compile.
void GlslangWarmup()
{
ANGLE_TRACE_EVENT0("gpu.angle,startup", "GlslangWarmup");
EShMessages messages = static_cast<EShMessages>(EShMsgSpvRules | EShMsgVulkanRules);
// EShMessages messages = EShMsgDefault;
TBuiltInResource builtInResources(glslang::DefaultTBuiltInResource);
glslang::TShader dummyShader(EShLangVertex);
const char *kShaderString = R"(#version 450 core
void main(){}
)";
const int kShaderLength = static_cast<int>(strlen(kShaderString));
dummyShader.setStringsWithLengths(&kShaderString, &kShaderLength, 1);
dummyShader.setEntryPoint("main");
bool result = dummyShader.parse(&builtInResources, 450, ECoreProfile, false, false, messages);
ASSERT(result);
}
// Test if there are non-zero indices in the uniform name, returning false in that case. This
// happens for multi-dimensional arrays, where a uniform is created for every possible index of the
// array (except for the innermost dimension). When assigning decorations (set/binding/etc), only
......@@ -1704,6 +1728,7 @@ void GlslangInitialize()
{
int result = ShInitialize();
ASSERT(result != 0);
GlslangWarmup();
}
void GlslangRelease()
......@@ -1937,6 +1962,8 @@ angle::Result GlslangGetShaderSpirvCode(const GlslangErrorCallback &callback,
continue;
}
ANGLE_TRACE_EVENT0("gpu.angle", "GlslangGetShaderSpirvCode TShader::parse");
const char *shaderString = shaderSources[shaderType].c_str();
int shaderLength = static_cast<int>(shaderSources[shaderType].size());
......@@ -1976,4 +2003,5 @@ angle::Result GlslangGetShaderSpirvCode(const GlslangErrorCallback &callback,
return angle::Result::Continue;
}
} // namespace rx
......@@ -286,6 +286,8 @@ std::unique_ptr<LinkEvent> ProgramVk::link(const gl::Context *context,
const gl::ProgramLinkedResources &resources,
gl::InfoLog &infoLog)
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramVk::link");
ContextVk *contextVk = vk::GetImpl(context);
// Link resources before calling GetShaderSource to make sure they are ready for the set/binding
// assignment done in that function.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment