Commit 7685a79e by Etienne Bergeron Committed by Commit Bot

Add trace event to angle Program compilation API

Bug: chromium:1064662 Change-Id: I2ee48718ff3946ab9307ba27177a02858bf436b0 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2230789 Commit-Queue: Etienne Bergeron <etienneb@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 462e40f2
......@@ -10,6 +10,8 @@
#include "libANGLE/WorkerThread.h"
#include "libANGLE/trace.h"
#if (ANGLE_STD_ASYNC_WORKERS == ANGLE_ENABLED)
# include <condition_variable>
# include <future>
......@@ -88,7 +90,7 @@ class AsyncWaitableEvent final : public WaitableEvent
friend class AsyncWorkerPool;
void setFuture(std::future<void> &&future);
// To block wait() when the task is stil in queue to be run.
// To block wait() when the task is still in queue to be run.
// Also to protect the concurrent accesses from both main thread and
// background threads to the member fields.
std::mutex mMutex;
......@@ -105,6 +107,7 @@ void AsyncWaitableEvent::setFuture(std::future<void> &&future)
void AsyncWaitableEvent::wait()
{
ANGLE_TRACE_EVENT0("gpu.angle", "AsyncWaitableEvent::wait");
{
std::unique_lock<std::mutex> lock(mMutex);
mCondition.wait(lock, [this] { return !mIsPending; });
......@@ -186,7 +189,10 @@ void AsyncWorkerPool::checkToRunPendingTasks()
auto closure = task.second;
auto future = std::async(std::launch::async, [closure, this] {
(*closure)();
{
ANGLE_TRACE_EVENT0("gpu.angle", "AsyncWorkerPool::RunTask");
(*closure)();
}
{
std::lock_guard<std::mutex> lock(mMutex);
ASSERT(mRunningThreads != 0);
......
......@@ -9,6 +9,7 @@
#include "libANGLE/renderer/ShaderImpl.h"
#include "libANGLE/Context.h"
#include "libANGLE/trace.h"
namespace rx
{
......@@ -46,6 +47,7 @@ class TranslateTask : public angle::Closure
void operator()() override
{
ANGLE_TRACE_EVENT1("gpu.angle", "TranslateTask::run", "source", mSource);
const char *source = mSource.c_str();
mResult = sh::Compile(mHandle, &source, 1, mOptions);
}
......
......@@ -236,7 +236,7 @@ angle::Result HLSLCompiler::compileToBinary(d3d::Context *context,
HRESULT result = S_OK;
{
ANGLE_TRACE_EVENT0("gpu.angle", "D3DCompile");
ANGLE_TRACE_EVENT1("gpu.angle", "D3DCompile", "source", hlsl);
SCOPED_ANGLE_HISTOGRAM_TIMER("GPU.ANGLE.D3DCompileMS");
result = mD3DCompileFunc(hlsl.c_str(), hlsl.length(), gl::g_fakepath, macros, nullptr,
"main", profile.c_str(), configs[i].flags, 0, &binary,
......@@ -247,6 +247,7 @@ angle::Result HLSLCompiler::compileToBinary(d3d::Context *context,
{
std::string message = static_cast<const char *>(errorMessage->GetBufferPointer());
SafeRelease(errorMessage);
ANGLE_TRACE_EVENT1("gpu.angle", "D3DCompile::Error", "error", errorMessage);
infoLog.appendSanitized(message.c_str());
......
......@@ -29,6 +29,7 @@
#include "libANGLE/renderer/d3d/ShaderExecutableD3D.h"
#include "libANGLE/renderer/d3d/VertexDataManager.h"
#include "libANGLE/renderer/renderer_utils.h"
#include "libANGLE/trace.h"
using namespace angle;
......@@ -898,6 +899,7 @@ class ProgramD3D::LoadBinaryTask : public ProgramD3D::GetExecutableTask
angle::Result run() override
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramD3D::LoadBinaryTask::run");
if (!mDataCopySucceeded)
{
mInfoLog << "Failed to copy program binary data to local buffer.";
......@@ -1685,6 +1687,7 @@ class ProgramD3D::GetVertexExecutableTask : public ProgramD3D::GetExecutableTask
GetVertexExecutableTask(ProgramD3D *program) : GetExecutableTask(program) {}
angle::Result run() override
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramD3D::GetVertexExecutableTask::run");
if (!mProgram->mState.getAttachedShader(gl::ShaderType::Vertex))
{
return angle::Result::Continue;
......@@ -1712,6 +1715,7 @@ class ProgramD3D::GetPixelExecutableTask : public ProgramD3D::GetExecutableTask
GetPixelExecutableTask(ProgramD3D *program) : GetExecutableTask(program) {}
angle::Result run() override
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramD3D::GetPixelExecutableTask::run");
if (!mProgram->mState.getAttachedShader(gl::ShaderType::Fragment))
{
return angle::Result::Continue;
......@@ -1747,6 +1751,7 @@ class ProgramD3D::GetGeometryExecutableTask : public ProgramD3D::GetExecutableTa
angle::Result run() override
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramD3D::GetGeometryExecutableTask::run");
// Auto-generate the geometry shader here, if we expect to be using point rendering in
// D3D11.
if (mProgram->usesGeometryShader(mState, gl::PrimitiveMode::Points))
......@@ -1768,6 +1773,7 @@ class ProgramD3D::GetComputeExecutableTask : public ProgramD3D::GetExecutableTas
GetComputeExecutableTask(ProgramD3D *program) : GetExecutableTask(program) {}
angle::Result run() override
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramD3D::GetComputeExecutableTask::run");
mProgram->updateCachedImage2DBindLayoutFromComputeShader();
ShaderExecutableD3D *computeExecutable = nullptr;
ANGLE_TRY(mProgram->getComputeExecutableForImage2DBindLayout(this, &computeExecutable,
......@@ -1806,6 +1812,7 @@ class ProgramD3D::GraphicsProgramLinkEvent final : public LinkEvent
angle::Result wait(const gl::Context *context) override
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramD3D::GraphicsProgramLinkEvent::wait");
WaitableEvent::WaitMany(&mWaitEvents);
ANGLE_TRY(checkTask(context, mVertexTask.get()));
......@@ -1906,6 +1913,7 @@ class ProgramD3D::ComputeProgramLinkEvent final : public LinkEvent
angle::Result wait(const gl::Context *context) override
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramD3D::ComputeProgramLinkEvent::wait");
mWaitEvent->wait();
angle::Result result = mComputeTask->getResult();
......@@ -1925,6 +1933,7 @@ class ProgramD3D::ComputeProgramLinkEvent final : public LinkEvent
std::unique_ptr<LinkEvent> ProgramD3D::compileProgramExecutables(const gl::Context *context,
gl::InfoLog &infoLog)
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramD3D::compileProgramExecutables");
// Ensure the compiler is initialized to avoid race conditions.
angle::Result result = mRenderer->ensureHLSLCompilerInitialized(GetImplAs<ContextD3D>(context));
if (result != angle::Result::Continue)
......@@ -1950,6 +1959,7 @@ std::unique_ptr<LinkEvent> ProgramD3D::compileProgramExecutables(const gl::Conte
std::unique_ptr<LinkEvent> ProgramD3D::compileComputeExecutable(const gl::Context *context,
gl::InfoLog &infoLog)
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramD3D::compileComputeExecutable");
// Ensure the compiler is initialized to avoid race conditions.
angle::Result result = mRenderer->ensureHLSLCompilerInitialized(GetImplAs<ContextD3D>(context));
if (result != angle::Result::Continue)
......@@ -1982,6 +1992,7 @@ angle::Result ProgramD3D::getComputeExecutableForImage2DBindLayout(
ShaderExecutableD3D **outExecutable,
gl::InfoLog *infoLog)
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramD3D::getComputeExecutableForImage2DBindLayout");
if (mCachedComputeExecutableIndex.valid())
{
*outExecutable =
......@@ -2023,6 +2034,7 @@ std::unique_ptr<LinkEvent> ProgramD3D::link(const gl::Context *context,
const gl::ProgramLinkedResources &resources,
gl::InfoLog &infoLog)
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramD3D::link");
const auto &data = context->getState();
reset();
......
......@@ -16,6 +16,7 @@
#include "libANGLE/features.h"
#include "libANGLE/renderer/d3d/ProgramD3D.h"
#include "libANGLE/renderer/d3d/RendererD3D.h"
#include "libANGLE/trace.h"
namespace rx
{
......@@ -36,6 +37,7 @@ class TranslateTaskD3D : public angle::Closure
void operator()() override
{
ANGLE_TRACE_EVENT1("gpu.angle", "TranslateTask::run", "source", mSource);
std::vector<const char *> srcStrings;
if (!mSourcePath.empty())
{
......
......@@ -23,6 +23,7 @@
#include "libANGLE/renderer/gl/RendererGL.h"
#include "libANGLE/renderer/gl/ShaderGL.h"
#include "libANGLE/renderer/gl/StateManagerGL.h"
#include "libANGLE/trace.h"
#include "platform/FeaturesGL.h"
#include "platform/PlatformMethods.h"
......@@ -59,6 +60,7 @@ std::unique_ptr<LinkEvent> ProgramGL::load(const gl::Context *context,
gl::BinaryInputStream *stream,
gl::InfoLog &infoLog)
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramGL::load");
preLink();
// Read the binary format, size and blob
......@@ -135,7 +137,12 @@ class ProgramGL::LinkTask final : public angle::Closure
LinkTask(LinkImplFunctor &&functor) : mLinkImplFunctor(functor), mFallbackToMainContext(false)
{}
void operator()() override { mFallbackToMainContext = mLinkImplFunctor(mInfoLog); }
void operator()() override
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramGL::LinkTask::run");
mFallbackToMainContext = mLinkImplFunctor(mInfoLog);
}
bool fallbackToMainContext() { return mFallbackToMainContext; }
const std::string &getInfoLog() { return mInfoLog; }
......@@ -159,6 +166,8 @@ class ProgramGL::LinkEventNativeParallel final : public LinkEvent
angle::Result wait(const gl::Context *context) override
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramGL::LinkEventNativeParallel::wait");
GLint linkStatus = GL_FALSE;
mFunctions->getProgramiv(mProgramID, GL_LINK_STATUS, &linkStatus);
if (linkStatus == GL_TRUE)
......@@ -196,6 +205,8 @@ class ProgramGL::LinkEventGL final : public LinkEvent
angle::Result wait(const gl::Context *context) override
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramGL::LinkEventGL::wait");
mWaitableEvent->wait();
return mPostLinkImplFunctor(mLinkTask->fallbackToMainContext(), mLinkTask->getInfoLog());
}
......@@ -212,6 +223,8 @@ std::unique_ptr<LinkEvent> ProgramGL::link(const gl::Context *context,
const gl::ProgramLinkedResources &resources,
gl::InfoLog &infoLog)
{
ANGLE_TRACE_EVENT0("gpu.angle", "ProgramGL::link");
preLink();
if (mState.getAttachedShader(gl::ShaderType::Compute))
......
......@@ -13,6 +13,7 @@
#include "libANGLE/Context.h"
#include "libANGLE/renderer/gl/FunctionsGL.h"
#include "libANGLE/renderer/gl/RendererGL.h"
#include "libANGLE/trace.h"
#include "platform/FeaturesGL.h"
#include <iostream>
......@@ -38,6 +39,7 @@ class TranslateTaskGL : public angle::Closure
void operator()() override
{
ANGLE_TRACE_EVENT1("gpu.angle", "TranslateTaskGL::run", "source", mSource);
const char *source = mSource.c_str();
mResult = sh::Compile(mHandle, &source, 1, mOptions);
if (mResult)
......
......@@ -20,5 +20,7 @@
#define ANGLE_TRACE_EVENT_INSTANT0(CATEGORY, EVENT) \
TRACE_EVENT_INSTANT0(ANGLEPlatformCurrent(), CATEGORY, EVENT)
#define ANGLE_TRACE_EVENT0(CATEGORY, EVENT) TRACE_EVENT0(ANGLEPlatformCurrent(), CATEGORY, EVENT)
#define ANGLE_TRACE_EVENT1(CATEGORY, EVENT, NAME, PARAM) \
TRACE_EVENT1(ANGLEPlatformCurrent(), CATEGORY, EVENT, NAME, PARAM)
#endif // LIBANGLE_TRACE_H_
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