Hash :
73bec982
Author :
Date :
2011-05-12T18:15:03
Cache result of D3DPERF_GetStatus. I profiled the WebGL acquarium with AMD CodeAnalyst and it turns out this function got a lot of hits. Top 10 before change: CS:EIP Symbol + Offset 64-bit Timer samples 0x62a87260 CBatchFilterI::ProcessBatch 13.41 0x62a171f1 D3DPERF_GetStatus 6.04 0x629ce831 CD3DBase::SetVertexShaderConstantF_FP 5.12 0x62a88bea CBatchFilterI::GetBatchBufferPointer<_LH_SETPIXELSHADERCONSTIMM_TOKEN_SMALL> 4.61 0x6298060b UpdateViewportCache 4.2 0x6298da3a CD3DBase::UpdateTextures 3.58 0x6298db6b CD3DDDIDX10::SetTexture 2.76 0x6298df1d CD3DDDIDX10::InsertStreamSource 2.46 0x629d1c1a CD3DBase::SetPixelShaderConstantF_FP 2.25 0x6297efc4 CD3DHal::SetSamplerState_FP 2.05 10 functions, 186 instructions, Total: 454 samples, 46.47% of shown samples, 2.51% of total session samples And after: CS:EIP Symbol + Offset 64-bit Timer samples 0x69317260 CBatchFilterI::ProcessBatch 13.87 0x69318bea CBatchFilterI::GetBatchBufferPointer<_LH_SETPIXELSHADERCONSTIMM_TOKEN_SMALL> 5.84 0x6921060b UpdateViewportCache 5.29 0x6925e831 CD3DBase::SetVertexShaderConstantF_FP 4.93 0x6921da3a CD3DBase::UpdateTextures 4.38 0x6921e034 CD3DBase::SetStreamSource_FP 3.65 0x69261c1a CD3DBase::SetPixelShaderConstantF_FP 3.65 0x69227651 CD3DBase::DrawIndexedPrimitive 2.74 0x6920efc4 CD3DHal::SetSamplerState_FP 2.37 0x6925e9f7 CD3DBase::SetVertexShaderConstantIntF 2.37 10 functions, 152 instructions, Total: 269 samples, 49.09% of shown samples, 0.80% of total session samples UpdateViewportCache looks like it might be low hanging fruit as well. Review URL: http://codereview.appspot.com/4535049 git-svn-id: https://angleproject.googlecode.com/svn/trunk@648 736b8ea6-26fd-11df-bfd4-992fa37f6226
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
//
// Copyright (c) 2002-2010 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.
//
// debug.cpp: Debugging utilities.
#include "common/debug.h"
#include <stdio.h>
#include <stdarg.h>
#include <d3d9.h>
#include <windows.h>
namespace gl
{
typedef void (WINAPI *PerfOutputFunction)(D3DCOLOR, LPCWSTR);
static void output(bool traceFileDebugOnly, PerfOutputFunction perfFunc, const char *format, va_list vararg)
{
#if !defined(ANGLE_DISABLE_PERF)
if (perfActive())
{
char message[4096];
int len = vsprintf_s(message, format, vararg);
if (len < 0)
{
return;
}
// There are no ASCII variants of these D3DPERF functions.
wchar_t wideMessage[4096];
for (int i = 0; i < len; ++i)
{
wideMessage[i] = message[i];
}
wideMessage[len] = 0;
perfFunc(0, wideMessage);
}
#endif
#if !defined(ANGLE_DISABLE_TRACE)
#if defined(NDEBUG)
if (traceFileDebugOnly)
{
return;
}
#endif
FILE* file = fopen(TRACE_OUTPUT_FILE, "a");
if (file)
{
vfprintf(file, format, vararg);
fclose(file);
}
#endif
}
void trace(bool traceFileDebugOnly, const char *format, ...)
{
va_list vararg;
va_start(vararg, format);
output(traceFileDebugOnly, D3DPERF_SetMarker, format, vararg);
va_end(vararg);
}
bool perfActive()
{
#if defined(ANGLE_DISABLE_PERF)
return false;
#else
static bool active = D3DPERF_GetStatus() != 0;
return active;
#endif
}
ScopedPerfEventHelper::ScopedPerfEventHelper(const char* format, ...)
{
va_list vararg;
va_start(vararg, format);
output(true, reinterpret_cast<PerfOutputFunction>(D3DPERF_BeginEvent), format, vararg);
va_end(vararg);
}
ScopedPerfEventHelper::~ScopedPerfEventHelper()
{
#if !defined(ANGLE_DISABLE_PERF)
if (perfActive())
{
D3DPERF_EndEvent();
}
#endif
}
}