Add metrics for shader compilation time and shader blob size

Log the time it takes for the system compiler to compile Metal and D3D
shaders.

Log the D3D shader blob size to get a sense of storage size needed.

Bug: chromium:1481238
Change-Id: I300102dcb035f42e91d7819cd9465ff18436abf3
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4851196
Reviewed-by: Peng Huang <penghuang@chromium.org>
Commit-Queue: Geoff Lang <geofflang@chromium.org>
This commit is contained in:
Geoff Lang
2023-09-11 16:11:33 -04:00
committed by Angle LUCI CQ
parent 8a7ad933a2
commit d3d81498ed
2 changed files with 28 additions and 0 deletions

View File

@@ -215,6 +215,8 @@ angle::Result HLSLCompiler::compileToBinary(d3d::Context *context,
writeFile(sourcePath.c_str(), sourceText.c_str(), sourceText.size());
#endif
auto *platform = ANGLEPlatformCurrent();
const D3D_SHADER_MACRO *macros = overrideMacros ? overrideMacros : nullptr;
for (size_t i = 0; i < configs.size(); ++i)
@@ -223,6 +225,8 @@ angle::Result HLSLCompiler::compileToBinary(d3d::Context *context,
ID3DBlob *binary = nullptr;
HRESULT result = S_OK;
double startTime = platform->currentTime(platform);
{
ANGLE_TRACE_EVENT1("gpu.angle", "D3DCompile", "source", hlsl);
result = mD3DCompileFunc(hlsl.c_str(), hlsl.length(), gl::g_fakepath, macros, nullptr,
@@ -230,6 +234,8 @@ angle::Result HLSLCompiler::compileToBinary(d3d::Context *context,
&errorMessage);
}
double compileTime = platform->currentTime(platform) - startTime;
if (errorMessage)
{
std::string message = static_cast<const char *>(errorMessage->GetBufferPointer());
@@ -285,6 +291,12 @@ angle::Result HLSLCompiler::compileToBinary(d3d::Context *context,
if (SUCCEEDED(result))
{
int compileUs = static_cast<int>(compileTime * 1000'000.0);
ANGLE_HISTOGRAM_COUNTS("GPU.ANGLE.D3DShaderCompilationTimeUs", compileUs);
ANGLE_HISTOGRAM_MEMORY_KB("GPU.ANGLE.D3DShaderBlobSizeKB",
static_cast<int>(binary->GetBufferSize() / 1024));
*outCompiledBlob = binary;
(*outDebugInfo) +=

View File

@@ -17,11 +17,13 @@
#include "common/string_utils.h"
#include "common/system_utils.h"
#include "gpu_info_util/SystemInfo_internal.h"
#include "libANGLE/histogram_macros.h"
#include "libANGLE/renderer/metal/ContextMtl.h"
#include "libANGLE/renderer/metal/DisplayMtl.h"
#include "libANGLE/renderer/metal/RenderTargetMtl.h"
#include "libANGLE/renderer/metal/mtl_render_utils.h"
#include "libANGLE/renderer/metal/process.h"
#include "platform/PlatformMethods.h"
// Compiler can turn on programmatical frame capture in release build by defining
// ANGLE_METAL_FRAME_CAPTURE flag.
@@ -917,6 +919,9 @@ AutoObjCPtr<id<MTLLibrary>> CreateShaderLibrary(
options.preprocessorMacros = macroDict;
}
auto *platform = ANGLEPlatformCurrent();
double startTime = platform->currentTime(platform);
auto library = metalDevice.newLibraryWithSource(nsSource, options, &nsError);
if (angle::GetEnvironmentVar(kANGLEPrintMSLEnv)[0] == '1')
{
@@ -925,6 +930,10 @@ AutoObjCPtr<id<MTLLibrary>> CreateShaderLibrary(
[nsSource ANGLE_MTL_AUTORELEASE];
*errorOut = std::move(nsError);
double endTime = platform->currentTime(platform);
int us = static_cast<int>((endTime - startTime) * 1000'000.0);
ANGLE_HISTOGRAM_COUNTS("GPU.ANGLE.MetalShaderCompilationTimeUs", us);
return library;
}
}
@@ -1018,9 +1027,16 @@ AutoObjCPtr<id<MTLLibrary>> CreateShaderLibrary(id<MTLDevice> metalDevice,
freeWhenDone:NO];
auto options = [[[MTLCompileOptions alloc] init] ANGLE_MTL_AUTORELEASE];
auto *platform = ANGLEPlatformCurrent();
double startTime = platform->currentTime(platform);
NSError *nsError = nil;
auto library = [metalDevice newLibraryWithSource:nsSource options:options error:&nsError];
double endTime = platform->currentTime(platform);
ERR() << "CreateShaderLibrary newLibraryWithSource duration: "
<< (endTime - startTime) * 1000.0 << "ms";
[nsSource ANGLE_MTL_AUTORELEASE];
*errorOut = std::move(nsError);