Commit 3cf1f4ea by Al Patrick

add TRACE_EVENT to ANGLE (reland)

Tracing code the same as previous CL: https://codereview.appspot.com/12699047/ Setup code simplified, and follows the GetProcAddress model of other gl functions. R=shannonwoods@google.com
parent d0310437
# This is the official list of people who can contribute # This is the official list of people who can contribute
# (and who have contributed) code to the ANGLE project # (and who have contributed) code to the ANGLE project
# repository. # repository.
# The AUTHORS file lists the copyright holders; this file # The AUTHORS file lists the copyright holders; this file
# lists people. For example, Google employees are listed here # lists people. For example, Google employees are listed here
# but not in AUTHORS, because Google holds the copyright. # but not in AUTHORS, because Google holds the copyright.
# #
TransGaming Inc. TransGaming Inc.
Nicolas Capens Nicolas Capens
Daniel Koch Daniel Koch
Geoff Lang Geoff Lang
Andrew Lewycky Andrew Lewycky
Jamie Madill Jamie Madill
Gavriel State Gavriel State
Shannon Woods Shannon Woods
Google Inc. Google Inc.
Brent Austin Brent Austin
Michael Bai Michael Bai
John Bauman John Bauman
Peter Beverloo Peter Beverloo
Steve Block Steve Block
Rachel Blum Rachel Blum
Eric Boren Eric Boren
Henry Bridge Henry Bridge
Nat Duca Nat Duca
Peter Kasting Peter Kasting
Vangelis Kokkevis Vangelis Kokkevis
Zhenyao Mo Zhenyao Mo
Daniel Nicoara Daniel Nicoara
Alastair Patrick Alastair Patrick
Alok Priyadarshi Alok Priyadarshi
Kenneth Russell Kenneth Russell
Brian Salomon Brian Salomon
Gregg Tavares Gregg Tavares
Jeff Timanus Jeff Timanus
Ben Vanik Ben Vanik
Adrienne Walker Adrienne Walker
thestig@chromium.org thestig@chromium.org
Justin Schuh Justin Schuh
Scott Graham
Adobe Systems Inc.
Alexandru Chiculita Adobe Systems Inc.
Steve Minns Alexandru Chiculita
Max Vujovic Steve Minns
Max Vujovic
Autodesk, Inc.
Ranger Harke Autodesk, Inc.
Ranger Harke
Cloud Party, Inc.
Conor Dickinson Cloud Party, Inc.
Conor Dickinson
Intel Corporation
Jin Yang Intel Corporation
Andy Chen Jin Yang
Josh Triplett Andy Chen
Josh Triplett
Klarälvdalens Datakonsult AB
Milian Wolff Klarälvdalens Datakonsult AB
Milian Wolff
Mozilla Corp.
Ehsan Akhgari Mozilla Corp.
Jeff Gilbert Ehsan Akhgari
Mike Hommey Jeff Gilbert
Benoit Jacob Mike Hommey
Makoto Kato Benoit Jacob
Vladimir Vukicevic Makoto Kato
Vladimir Vukicevic
Turbulenz
Michael Braithwaite Turbulenz
Michael Braithwaite
Ulrik Persson (ddefrostt)
Mark Banner (standard8mbp) Ulrik Persson (ddefrostt)
David Kilzer Mark Banner (standard8mbp)
David Kilzer
...@@ -228,9 +228,12 @@ ...@@ -228,9 +228,12 @@
'sources': [ 'sources': [
'third_party/murmurhash/MurmurHash3.h', 'third_party/murmurhash/MurmurHash3.h',
'third_party/murmurhash/MurmurHash3.cpp', 'third_party/murmurhash/MurmurHash3.cpp',
'third_party/trace_event/trace_event.h',
'common/angleutils.h', 'common/angleutils.h',
'common/debug.cpp', 'common/debug.cpp',
'common/debug.h', 'common/debug.h',
'common/event_tracer.cpp',
'common/event_tracer.h',
'common/RefCountObject.cpp', 'common/RefCountObject.cpp',
'common/RefCountObject.h', 'common/RefCountObject.h',
'common/version.h', 'common/version.h',
......
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "common/event_tracer.h"
namespace gl
{
GetCategoryEnabledFlagFunc g_getCategoryEnabledFlag;
AddTraceEventFunc g_addTraceEvent;
} // namespace gl
extern "C" {
void __stdcall SetTraceFunctionPointers(GetCategoryEnabledFlagFunc getCategoryEnabledFlag,
AddTraceEventFunc addTraceEvent)
{
gl::g_getCategoryEnabledFlag = getCategoryEnabledFlag;
gl::g_addTraceEvent = addTraceEvent;
}
} // extern "C"
namespace gl
{
const unsigned char* TraceGetTraceCategoryEnabledFlag(const char* name)
{
if (g_getCategoryEnabledFlag)
{
return g_getCategoryEnabledFlag(name);
}
static unsigned char disabled = 0;
return &disabled;
}
void TraceAddTraceEvent(char phase, const unsigned char* categoryGroupEnabled, const char* name, unsigned long long id,
int numArgs, const char** argNames, const unsigned char* argTypes,
const unsigned long long* argValues, unsigned char flags)
{
if (g_addTraceEvent)
{
g_addTraceEvent(phase, categoryGroupEnabled, name, id, numArgs, argNames, argTypes, argValues, flags);
}
}
} // namespace gl
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMMON_EVENT_TRACER_H_
#define COMMON_EVENT_TRACER_H_
extern "C" {
typedef const unsigned char* (*GetCategoryEnabledFlagFunc)(const char* name);
typedef void (*AddTraceEventFunc)(char phase, const unsigned char* categoryGroupEnabled, const char* name,
unsigned long long id, int numArgs, const char** argNames,
const unsigned char* argTypes, const unsigned long long* argValues,
unsigned char flags);
// extern "C" so that it has a reasonable name for GetProcAddress.
void __stdcall SetTraceFunctionPointers(GetCategoryEnabledFlagFunc get_category_enabled_flag,
AddTraceEventFunc add_trace_event_func);
}
namespace gl
{
const unsigned char* TraceGetTraceCategoryEnabledFlag(const char* name);
void TraceAddTraceEvent(char phase, const unsigned char* categoryGroupEnabled, const char* name, unsigned long long id,
int numArgs, const char** argNames, const unsigned char* argTypes,
const unsigned long long* argValues, unsigned char flags);
}
#endif // COMMON_EVENT_TRACER_H_
#define MAJOR_VERSION 1 #define MAJOR_VERSION 1
#define MINOR_VERSION 2 #define MINOR_VERSION 2
#define BUILD_VERSION 0 #define BUILD_VERSION 0
#define BUILD_REVISION 2435 #define BUILD_REVISION 2436
#define STRINGIFY(x) #x #define STRINGIFY(x) #x
#define MACRO_STRINGIFY(x) STRINGIFY(x) #define MACRO_STRINGIFY(x) STRINGIFY(x)
......
...@@ -182,4 +182,7 @@ EXPORTS ...@@ -182,4 +182,7 @@ EXPORTS
glGetProcAddress @148 NONAME glGetProcAddress @148 NONAME
glBindTexImage @158 NONAME glBindTexImage @158 NONAME
glCreateRenderer @177 NONAME glCreateRenderer @177 NONAME
glDestroyRenderer @178 NONAME glDestroyRenderer @178 NONAME
\ No newline at end of file
; Setting up TRACE macro callbacks
SetTraceFunctionPointers @180
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "libGLESv2/renderer/Renderer9.h" #include "libGLESv2/renderer/Renderer9.h"
#include "libGLESv2/renderer/Renderer11.h" #include "libGLESv2/renderer/Renderer11.h"
#include "libGLESv2/utilities.h" #include "libGLESv2/utilities.h"
#include "third_party/trace_event/trace_event.h"
#if !defined(ANGLE_ENABLE_D3D11) #if !defined(ANGLE_ENABLE_D3D11)
// Enables use of the Direct3D 11 API for a default display, when available // Enables use of the Direct3D 11 API for a default display, when available
...@@ -40,6 +41,7 @@ Renderer::~Renderer() ...@@ -40,6 +41,7 @@ Renderer::~Renderer()
bool Renderer::initializeCompiler() bool Renderer::initializeCompiler()
{ {
TRACE_EVENT0("gpu", "initializeCompiler");
#if defined(ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES) #if defined(ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES)
// Find a D3DCompiler module that had already been loaded based on a predefined list of versions. // Find a D3DCompiler module that had already been loaded based on a predefined list of versions.
static TCHAR* d3dCompilerNames[] = ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES; static TCHAR* d3dCompilerNames[] = ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES;
......
...@@ -30,6 +30,8 @@ ...@@ -30,6 +30,8 @@
#include "libEGL/Display.h" #include "libEGL/Display.h"
#include "third_party/trace_event/trace_event.h"
// Can also be enabled by defining FORCE_REF_RAST in the project's predefined macros // Can also be enabled by defining FORCE_REF_RAST in the project's predefined macros
#define REF_RAST 0 #define REF_RAST 0
...@@ -184,10 +186,12 @@ EGLint Renderer9::initialize() ...@@ -184,10 +186,12 @@ EGLint Renderer9::initialize()
if (mSoftwareDevice) if (mSoftwareDevice)
{ {
TRACE_EVENT0("gpu", "GetModuleHandle_swiftshader");
mD3d9Module = GetModuleHandle(TEXT("swiftshader_d3d9.dll")); mD3d9Module = GetModuleHandle(TEXT("swiftshader_d3d9.dll"));
} }
else else
{ {
TRACE_EVENT0("gpu", "GetModuleHandle_d3d9");
mD3d9Module = GetModuleHandle(TEXT("d3d9.dll")); mD3d9Module = GetModuleHandle(TEXT("d3d9.dll"));
} }
...@@ -205,12 +209,14 @@ EGLint Renderer9::initialize() ...@@ -205,12 +209,14 @@ EGLint Renderer9::initialize()
// desktop. Direct3D9Ex is available in Windows Vista and later if suitable drivers are available. // desktop. Direct3D9Ex is available in Windows Vista and later if suitable drivers are available.
if (ANGLE_ENABLE_D3D9EX && Direct3DCreate9ExPtr && SUCCEEDED(Direct3DCreate9ExPtr(D3D_SDK_VERSION, &mD3d9Ex))) if (ANGLE_ENABLE_D3D9EX && Direct3DCreate9ExPtr && SUCCEEDED(Direct3DCreate9ExPtr(D3D_SDK_VERSION, &mD3d9Ex)))
{ {
TRACE_EVENT0("gpu", "D3d9Ex_QueryInterface");
ASSERT(mD3d9Ex); ASSERT(mD3d9Ex);
mD3d9Ex->QueryInterface(IID_IDirect3D9, reinterpret_cast<void**>(&mD3d9)); mD3d9Ex->QueryInterface(IID_IDirect3D9, reinterpret_cast<void**>(&mD3d9));
ASSERT(mD3d9); ASSERT(mD3d9);
} }
else else
{ {
TRACE_EVENT0("gpu", "Direct3DCreate9");
mD3d9 = Direct3DCreate9(D3D_SDK_VERSION); mD3d9 = Direct3DCreate9(D3D_SDK_VERSION);
} }
...@@ -228,21 +234,24 @@ EGLint Renderer9::initialize() ...@@ -228,21 +234,24 @@ EGLint Renderer9::initialize()
HRESULT result; HRESULT result;
// Give up on getting device caps after about one second. // Give up on getting device caps after about one second.
for (int i = 0; i < 10; ++i)
{ {
result = mD3d9->GetDeviceCaps(mAdapter, mDeviceType, &mDeviceCaps); TRACE_EVENT0("gpu", "GetDeviceCaps");
if (SUCCEEDED(result)) for (int i = 0; i < 10; ++i)
{
break;
}
else if (result == D3DERR_NOTAVAILABLE)
{
Sleep(100); // Give the driver some time to initialize/recover
}
else if (FAILED(result)) // D3DERR_OUTOFVIDEOMEMORY, E_OUTOFMEMORY, D3DERR_INVALIDDEVICE, or another error we can't recover from
{ {
ERR("failed to get device caps (0x%x)\n", result); result = mD3d9->GetDeviceCaps(mAdapter, mDeviceType, &mDeviceCaps);
return EGL_NOT_INITIALIZED; if (SUCCEEDED(result))
{
break;
}
else if (result == D3DERR_NOTAVAILABLE)
{
Sleep(100); // Give the driver some time to initialize/recover
}
else if (FAILED(result)) // D3DERR_OUTOFVIDEOMEMORY, E_OUTOFMEMORY, D3DERR_INVALIDDEVICE, or another error we can't recover from
{
ERR("failed to get device caps (0x%x)\n", result);
return EGL_NOT_INITIALIZED;
}
} }
} }
...@@ -260,7 +269,10 @@ EGLint Renderer9::initialize() ...@@ -260,7 +269,10 @@ EGLint Renderer9::initialize()
return EGL_NOT_INITIALIZED; return EGL_NOT_INITIALIZED;
} }
mD3d9->GetAdapterIdentifier(mAdapter, 0, &mAdapterIdentifier); {
TRACE_EVENT0("gpu", "GetAdapterIdentifier");
mD3d9->GetAdapterIdentifier(mAdapter, 0, &mAdapterIdentifier);
}
// ATI cards on XP have problems with non-power-of-two textures. // ATI cards on XP have problems with non-power-of-two textures.
mSupportsNonPower2Textures = !(mDeviceCaps.TextureCaps & D3DPTEXTURECAPS_POW2) && mSupportsNonPower2Textures = !(mDeviceCaps.TextureCaps & D3DPTEXTURECAPS_POW2) &&
...@@ -301,35 +313,41 @@ EGLint Renderer9::initialize() ...@@ -301,35 +313,41 @@ EGLint Renderer9::initialize()
} }
int max = 0; int max = 0;
for (unsigned int i = 0; i < ArraySize(RenderTargetFormats); ++i)
{ {
bool *multisampleArray = new bool[D3DMULTISAMPLE_16_SAMPLES + 1]; TRACE_EVENT0("gpu", "getMultiSampleSupport");
getMultiSampleSupport(RenderTargetFormats[i], multisampleArray); for (unsigned int i = 0; i < ArraySize(RenderTargetFormats); ++i)
mMultiSampleSupport[RenderTargetFormats[i]] = multisampleArray;
for (int j = D3DMULTISAMPLE_16_SAMPLES; j >= 0; --j)
{ {
if (multisampleArray[j] && j != D3DMULTISAMPLE_NONMASKABLE && j > max) bool *multisampleArray = new bool[D3DMULTISAMPLE_16_SAMPLES + 1];
getMultiSampleSupport(RenderTargetFormats[i], multisampleArray);
mMultiSampleSupport[RenderTargetFormats[i]] = multisampleArray;
for (int j = D3DMULTISAMPLE_16_SAMPLES; j >= 0; --j)
{ {
max = j; if (multisampleArray[j] && j != D3DMULTISAMPLE_NONMASKABLE && j > max)
{
max = j;
}
} }
} }
} }
for (unsigned int i = 0; i < ArraySize(DepthStencilFormats); ++i)
{ {
if (DepthStencilFormats[i] == D3DFMT_UNKNOWN) TRACE_EVENT0("gpu", "getMultiSampleSupport2");
continue; for (unsigned int i = 0; i < ArraySize(DepthStencilFormats); ++i)
{
if (DepthStencilFormats[i] == D3DFMT_UNKNOWN)
continue;
bool *multisampleArray = new bool[D3DMULTISAMPLE_16_SAMPLES + 1]; bool *multisampleArray = new bool[D3DMULTISAMPLE_16_SAMPLES + 1];
getMultiSampleSupport(DepthStencilFormats[i], multisampleArray); getMultiSampleSupport(DepthStencilFormats[i], multisampleArray);
mMultiSampleSupport[DepthStencilFormats[i]] = multisampleArray; mMultiSampleSupport[DepthStencilFormats[i]] = multisampleArray;
for (int j = D3DMULTISAMPLE_16_SAMPLES; j >= 0; --j) for (int j = D3DMULTISAMPLE_16_SAMPLES; j >= 0; --j)
{
if (multisampleArray[j] && j != D3DMULTISAMPLE_NONMASKABLE && j > max)
{ {
max = j; if (multisampleArray[j] && j != D3DMULTISAMPLE_NONMASKABLE && j > max)
{
max = j;
}
} }
} }
} }
...@@ -339,12 +357,18 @@ EGLint Renderer9::initialize() ...@@ -339,12 +357,18 @@ EGLint Renderer9::initialize()
static const TCHAR windowName[] = TEXT("AngleHiddenWindow"); static const TCHAR windowName[] = TEXT("AngleHiddenWindow");
static const TCHAR className[] = TEXT("STATIC"); static const TCHAR className[] = TEXT("STATIC");
mDeviceWindow = CreateWindowEx(WS_EX_NOACTIVATE, className, windowName, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, HWND_MESSAGE, NULL, GetModuleHandle(NULL), NULL); {
TRACE_EVENT0("gpu", "CreateWindowEx");
mDeviceWindow = CreateWindowEx(WS_EX_NOACTIVATE, className, windowName, WS_DISABLED | WS_POPUP, 0, 0, 1, 1, HWND_MESSAGE, NULL, GetModuleHandle(NULL), NULL);
}
D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters(); D3DPRESENT_PARAMETERS presentParameters = getDefaultPresentParameters();
DWORD behaviorFlags = D3DCREATE_FPU_PRESERVE | D3DCREATE_NOWINDOWCHANGES; DWORD behaviorFlags = D3DCREATE_FPU_PRESERVE | D3DCREATE_NOWINDOWCHANGES;
result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &presentParameters, &mDevice); {
TRACE_EVENT0("gpu", "D3d9_CreateDevice");
result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_PUREDEVICE, &presentParameters, &mDevice);
}
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DEVICELOST) if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DEVICELOST)
{ {
return EGL_BAD_ALLOC; return EGL_BAD_ALLOC;
...@@ -352,6 +376,7 @@ EGLint Renderer9::initialize() ...@@ -352,6 +376,7 @@ EGLint Renderer9::initialize()
if (FAILED(result)) if (FAILED(result))
{ {
TRACE_EVENT0("gpu", "D3d9_CreateDevice2");
result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParameters, &mDevice); result = mD3d9->CreateDevice(mAdapter, mDeviceType, mDeviceWindow, behaviorFlags | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParameters, &mDevice);
if (FAILED(result)) if (FAILED(result))
...@@ -363,35 +388,45 @@ EGLint Renderer9::initialize() ...@@ -363,35 +388,45 @@ EGLint Renderer9::initialize()
if (mD3d9Ex) if (mD3d9Ex)
{ {
TRACE_EVENT0("gpu", "mDevice_QueryInterface");
result = mDevice->QueryInterface(IID_IDirect3DDevice9Ex, (void**) &mDeviceEx); result = mDevice->QueryInterface(IID_IDirect3DDevice9Ex, (void**) &mDeviceEx);
ASSERT(SUCCEEDED(result)); ASSERT(SUCCEEDED(result));
} }
mVertexShaderCache.initialize(mDevice); {
mPixelShaderCache.initialize(mDevice); TRACE_EVENT0("gpu", "ShaderCache initialize");
mVertexShaderCache.initialize(mDevice);
mPixelShaderCache.initialize(mDevice);
}
// Check occlusion query support // Check occlusion query support
IDirect3DQuery9 *occlusionQuery = NULL; IDirect3DQuery9 *occlusionQuery = NULL;
if (SUCCEEDED(mDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &occlusionQuery)) && occlusionQuery)
{
occlusionQuery->Release();
mOcclusionQuerySupport = true;
}
else
{ {
mOcclusionQuerySupport = false; TRACE_EVENT0("gpu", "device_CreateQuery");
if (SUCCEEDED(mDevice->CreateQuery(D3DQUERYTYPE_OCCLUSION, &occlusionQuery)) && occlusionQuery)
{
occlusionQuery->Release();
mOcclusionQuerySupport = true;
}
else
{
mOcclusionQuerySupport = false;
}
} }
// Check event query support // Check event query support
IDirect3DQuery9 *eventQuery = NULL; IDirect3DQuery9 *eventQuery = NULL;
if (SUCCEEDED(mDevice->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery)) && eventQuery)
{
eventQuery->Release();
mEventQuerySupport = true;
}
else
{ {
mEventQuerySupport = false; TRACE_EVENT0("gpu", "device_CreateQuery2");
if (SUCCEEDED(mDevice->CreateQuery(D3DQUERYTYPE_EVENT, &eventQuery)) && eventQuery)
{
eventQuery->Release();
mEventQuerySupport = true;
}
else
{
mEventQuerySupport = false;
}
} }
D3DDISPLAYMODE currentDisplayMode; D3DDISPLAYMODE currentDisplayMode;
......
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