#define GR_CACHE_STATS 0
#endif
+#if !defined(GR_GPU_STATS)
+#define GR_GPU_STATS 0
+#endif
+
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
void printCacheStats() const;
#endif
+ class GPUStats {
+ public:
+#if GR_GPU_STATS
+ GPUStats() { this->reset(); }
+
+ void reset() { fRenderTargetBinds = 0; fShaderCompilations = 0; }
+
+ int renderTargetBinds() const { return fRenderTargetBinds; }
+ void incRenderTargetBinds() { fRenderTargetBinds++; }
+ int shaderCompilations() const { return fShaderCompilations; }
+ void incShaderCompilations() { fShaderCompilations++; }
+ private:
+ int fRenderTargetBinds;
+ int fShaderCompilations;
+#else
+ void incRenderTargetBinds() {}
+ void incShaderCompilations() {}
+#endif
+ };
+
+#if GR_GPU_STATS
+ const GPUStats* gpuStats() const;
+#endif
+
private:
// Used to indicate whether a draw should be performed immediately or queued in fDrawBuffer.
enum BufferedDraw {
fResourceCache->printStats();
}
#endif
+
+#if GR_GPU_STATS
+const GrContext::GPUStats* GrContext::gpuStats() const {
+ return fGpu->gpuStats();
+}
+#endif
+
return kDrawPath_DrawType == type || kDrawPaths_DrawType == type;
}
+ GrContext::GPUStats* gpuStats() { return &fGPUStats; }
+
protected:
DrawType PrimTypeToDrawType(GrPrimitiveType type) {
switch (type) {
GrClipMaskManager fClipMaskManager;
+ GrContext::GPUStats fGPUStats;
+
struct GeometryPoolState {
const GrVertexBuffer* fPoolVertexBuffer;
int fPoolStartVertex;
width, height)) {
goto FAILED;
}
+ fGPUStats.incRenderTargetBinds();
GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fRTFBOID));
GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
GR_GL_COLOR_ATTACHMENT0,
fGLContext.caps()->markConfigAsValidColorAttachment(desc->fConfig);
}
}
+ fGPUStats.incRenderTargetBinds();
GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, desc->fTexFBOID));
if (this->glCaps().usesImplicitMSAAResolve() && desc->fSampleCnt > 0) {
GrGLuint rb = glsb->renderbufferID();
fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
+ fGPUStats.incRenderTargetBinds();
GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, fbo));
GL_CALL(FramebufferRenderbuffer(GR_GL_FRAMEBUFFER,
GR_GL_STENCIL_ATTACHMENT,
GrGLRenderTarget* glRT = static_cast<GrGLRenderTarget*>(renderTarget);
if (renderTarget->getUniqueID() != fHWBoundRenderTargetUniqueID) {
fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
+ fGPUStats.incRenderTargetBinds();
GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, glRT->renderFBOID()));
}
switch (this->glCaps().invalidateFBType()) {
case GrGLRenderTarget::kCanResolve_ResolveType:
this->onResolveRenderTarget(tgt);
// we don't track the state of the READ FBO ID.
+ fGPUStats.incRenderTargetBinds();
GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER,
tgt->textureFBOID()));
break;
uint32_t rtID = target->getUniqueID();
if (fHWBoundRenderTargetUniqueID != rtID) {
+ fGPUStats.incRenderTargetBinds();
GL_CALL(BindFramebuffer(GR_GL_FRAMEBUFFER, target->renderFBOID()));
#ifdef SK_DEBUG
// don't do this check in Chromium -- this is causing
// Some extensions automatically resolves the texture when it is read.
if (this->glCaps().usesMSAARenderBuffers()) {
SkASSERT(rt->textureFBOID() != rt->renderFBOID());
+ fGPUStats.incRenderTargetBinds();
+ fGPUStats.incRenderTargetBinds();
GL_CALL(BindFramebuffer(GR_GL_READ_FRAMEBUFFER, rt->renderFBOID()));
GL_CALL(BindFramebuffer(GR_GL_DRAW_FRAMEBUFFER, rt->textureFBOID()));
// make sure we go through flushRenderTarget() since we've modified
}
}
+}
+
// If a temporary FBO was created, its non-zero ID is returned. The viewport that the copy rect is
// relative to is output.
-inline GrGLuint bind_surface_as_fbo(const GrGLInterface* gl,
- GrSurface* surface,
- GrGLenum fboTarget,
- GrGLIRect* viewport) {
+GrGLuint GrGpuGL::bindSurfaceAsFBO(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport) {
GrGLRenderTarget* rt = static_cast<GrGLRenderTarget*>(surface->asRenderTarget());
GrGLuint tempFBOID;
if (NULL == rt) {
SkASSERT(surface->asTexture());
GrGLuint texID = static_cast<GrGLTexture*>(surface->asTexture())->textureID();
- GR_GL_CALL(gl, GenFramebuffers(1, &tempFBOID));
- GR_GL_CALL(gl, BindFramebuffer(fboTarget, tempFBOID));
- GR_GL_CALL(gl, FramebufferTexture2D(fboTarget,
- GR_GL_COLOR_ATTACHMENT0,
- GR_GL_TEXTURE_2D,
- texID,
- 0));
+ GR_GL_CALL(this->glInterface(), GenFramebuffers(1, &tempFBOID));
+ fGPUStats.incRenderTargetBinds();
+ GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, tempFBOID));
+ GR_GL_CALL(this->glInterface(), FramebufferTexture2D(fboTarget,
+ GR_GL_COLOR_ATTACHMENT0,
+ GR_GL_TEXTURE_2D,
+ texID,
+ 0));
viewport->fLeft = 0;
viewport->fBottom = 0;
viewport->fWidth = surface->width();
viewport->fHeight = surface->height();
} else {
tempFBOID = 0;
- GR_GL_CALL(gl, BindFramebuffer(fboTarget, rt->renderFBOID()));
+ fGPUStats.incRenderTargetBinds();
+ GR_GL_CALL(this->glInterface(), BindFramebuffer(fboTarget, rt->renderFBOID()));
*viewport = rt->getViewport();
}
return tempFBOID;
}
-}
-
void GrGpuGL::initCopySurfaceDstDesc(const GrSurface* src, GrTextureDesc* desc) {
// Check for format issues with glCopyTexSubImage2D
if (kGLES_GrGLStandard == this->glStandard() && this->glCaps().bgraIsInternalFormat() &&
(!wouldNeedTempFBO || !inheritedCouldCopy)) {
GrGLuint srcFBO;
GrGLIRect srcVP;
- srcFBO = bind_surface_as_fbo(this->glInterface(), src, GR_GL_FRAMEBUFFER, &srcVP);
+ srcFBO = this->bindSurfaceAsFBO(src, GR_GL_FRAMEBUFFER, &srcVP);
GrGLTexture* dstTex = static_cast<GrGLTexture*>(dst->asTexture());
SkASSERT(dstTex);
// We modified the bound FBO
GrGLuint srcFBO;
GrGLIRect dstVP;
GrGLIRect srcVP;
- dstFBO = bind_surface_as_fbo(this->glInterface(), dst, GR_GL_DRAW_FRAMEBUFFER, &dstVP);
- srcFBO = bind_surface_as_fbo(this->glInterface(), src, GR_GL_READ_FRAMEBUFFER, &srcVP);
+ dstFBO = this->bindSurfaceAsFBO(dst, GR_GL_DRAW_FRAMEBUFFER, &dstVP);
+ srcFBO = this->bindSurfaceAsFBO(src, GR_GL_READ_FRAMEBUFFER, &srcVP);
// We modified the bound FBO
fHWBoundRenderTargetUniqueID = SK_InvalidUniqueID;
GrGLIRect srcGLRect;
bool insideClip) SK_OVERRIDE;
virtual bool flushGraphicsState(DrawType, const GrDeviceCoordTexture* dstCopy) SK_OVERRIDE;
- // GrDrawTarget ovverides
+ // GrDrawTarget overrides
virtual void didAddGpuTraceMarker() SK_OVERRIDE;
virtual void didRemoveGpuTraceMarker() SK_OVERRIDE;
GrGLuint texID,
GrGLRenderTarget::Desc* desc);
+ GrGLuint bindSurfaceAsFBO(GrSurface* surface, GrGLenum fboTarget, GrGLIRect* viewport);
+
GrGLContext fGLContext;
// GL program-related state
fragShaderSrc.append(fCode);
fragShaderSrc.append("}\n");
- GrGLuint fragShaderId = GrGLCompileAndAttachShader(gpu->glContext(),
- programId, GR_GL_FRAGMENT_SHADER, fragShaderSrc);
+ GrGLuint fragShaderId = GrGLCompileAndAttachShader(gpu->glContext(), programId,
+ GR_GL_FRAGMENT_SHADER, fragShaderSrc,
+ gpu->gpuStats());
if (!fragShaderId) {
return false;
}
"\tEndPrimitive();\n");
geomShaderSrc.append("}\n");
GrGLuint geomShaderId =
- GrGLCompileAndAttachShader(glCtx, programId, GR_GL_GEOMETRY_SHADER, geomShaderSrc);
+ GrGLCompileAndAttachShader(glCtx, programId,
+ GR_GL_GEOMETRY_SHADER, geomShaderSrc,
+ fProgramBuilder->gpu()->gpuStats());
if (!geomShaderId) {
return false;
}
GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
GrGLuint programId,
GrGLenum type,
- const SkString& shaderSrc) {
+ const SkString& shaderSrc,
+ GrContext::GPUStats* gpuStats) {
const GrGLInterface* gli = glCtx.interface();
- GrGLuint shaderId;
- GR_GL_CALL_RET(gli, shaderId, CreateShader(type));
- if (0 == shaderId) {
- return 0;
- }
+ GrGLuint shaderId;
+ GR_GL_CALL_RET(gli, shaderId, CreateShader(type));
+ if (0 == shaderId) {
+ return 0;
+ }
- #ifdef SK_DEBUG
- SkString prettySource = GrGLSLPrettyPrint::PrettyPrintGLSL(shaderSrc, false);
- const GrGLchar* sourceStr = prettySource.c_str();
- GrGLint sourceLength = static_cast<GrGLint>(prettySource.size());
- #else
- GrGLint sourceLength = static_cast<GrGLint>(shaderSrc.size());
- const GrGLchar* sourceStr = shaderSrc.c_str();
- #endif
- GR_GL_CALL(gli, ShaderSource(shaderId, 1, &sourceStr, &sourceLength));
- GR_GL_CALL(gli, CompileShader(shaderId));
+#ifdef SK_DEBUG
+ SkString prettySource = GrGLSLPrettyPrint::PrettyPrintGLSL(shaderSrc, false);
+ const GrGLchar* sourceStr = prettySource.c_str();
+ GrGLint sourceLength = static_cast<GrGLint>(prettySource.size());
+#else
+ GrGLint sourceLength = static_cast<GrGLint>(shaderSrc.size());
+ const GrGLchar* sourceStr = shaderSrc.c_str();
+#endif
+ GR_GL_CALL(gli, ShaderSource(shaderId, 1, &sourceStr, &sourceLength));
+ gpuStats->incShaderCompilations();
+ GR_GL_CALL(gli, CompileShader(shaderId));
- // Calling GetShaderiv in Chromium is quite expensive. Assume success in release builds.
- bool checkCompiled = !glCtx.isChromium();
- #ifdef SK_DEBUG
- checkCompiled = true;
- #endif
- if (checkCompiled) {
- GrGLint compiled = GR_GL_INIT_ZERO;
- GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_COMPILE_STATUS, &compiled));
+ // Calling GetShaderiv in Chromium is quite expensive. Assume success in release builds.
+ bool checkCompiled = !glCtx.isChromium();
+#ifdef SK_DEBUG
+ checkCompiled = true;
+#endif
+ if (checkCompiled) {
+ GrGLint compiled = GR_GL_INIT_ZERO;
+ GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_COMPILE_STATUS, &compiled));
- if (!compiled) {
- GrGLint infoLen = GR_GL_INIT_ZERO;
- GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_INFO_LOG_LENGTH, &infoLen));
- SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
- if (infoLen > 0) {
- // retrieve length even though we don't need it to workaround bug in Chromium cmd
- // buffer param validation.
- GrGLsizei length = GR_GL_INIT_ZERO;
- GR_GL_CALL(gli, GetShaderInfoLog(shaderId, infoLen+1,
- &length, (char*)log.get()));
- GrPrintf(GrGLSLPrettyPrint::PrettyPrintGLSL(shaderSrc, true).c_str());
- GrPrintf("\n%s", log.get());
- }
- SkDEBUGFAIL("Shader compilation failed!");
- GR_GL_CALL(gli, DeleteShader(shaderId));
- return 0;
- }
- }
+ if (!compiled) {
+ GrGLint infoLen = GR_GL_INIT_ZERO;
+ GR_GL_CALL(gli, GetShaderiv(shaderId, GR_GL_INFO_LOG_LENGTH, &infoLen));
+ SkAutoMalloc log(sizeof(char)*(infoLen+1)); // outside if for debugger
+ if (infoLen > 0) {
+ // retrieve length even though we don't need it to workaround bug in Chromium cmd
+ // buffer param validation.
+ GrGLsizei length = GR_GL_INIT_ZERO;
+ GR_GL_CALL(gli, GetShaderInfoLog(shaderId, infoLen+1,
+ &length, (char*)log.get()));
+ GrPrintf(GrGLSLPrettyPrint::PrettyPrintGLSL(shaderSrc, true).c_str());
+ GrPrintf("\n%s", log.get());
+ }
+ SkDEBUGFAIL("Shader compilation failed!");
+ GR_GL_CALL(gli, DeleteShader(shaderId));
+ return 0;
+ }
+ }
- TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "skia_gpu::GLShader",
- TRACE_EVENT_SCOPE_THREAD, "shader", TRACE_STR_COPY(shaderSrc.c_str()));
- if (c_PrintShaders) {
- GrPrintf(GrGLSLPrettyPrint::PrettyPrintGLSL(shaderSrc, true).c_str());
- GrPrintf("\n");
- }
+ TRACE_EVENT_INSTANT1(TRACE_DISABLED_BY_DEFAULT("skia.gpu"), "skia_gpu::GLShader",
+ TRACE_EVENT_SCOPE_THREAD, "shader", TRACE_STR_COPY(shaderSrc.c_str()));
+ if (c_PrintShaders) {
+ GrPrintf(GrGLSLPrettyPrint::PrettyPrintGLSL(shaderSrc, true).c_str());
+ GrPrintf("\n");
+ }
- // Attach the shader, but defer deletion until after we have linked the program.
- // This works around a bug in the Android emulator's GLES2 wrapper which
- // will immediately delete the shader object and free its memory even though it's
- // attached to a program, which then causes glLinkProgram to fail.
- GR_GL_CALL(gli, AttachShader(programId, shaderId));
+ // Attach the shader, but defer deletion until after we have linked the program.
+ // This works around a bug in the Android emulator's GLES2 wrapper which
+ // will immediately delete the shader object and free its memory even though it's
+ // attached to a program, which then causes glLinkProgram to fail.
+ GR_GL_CALL(gli, AttachShader(programId, shaderId));
- return shaderId;
+ return shaderId;
}
#define GrGLShaderStringBuilder_DEFINED
#include "GrAllocator.h"
+#include "GrContext.h"
#include "gl/GrGLContext.h"
#include "SkTypes.h"
GrGLuint GrGLCompileAndAttachShader(const GrGLContext& glCtx,
GrGLuint programId,
GrGLenum type,
- const SkString& shaderSrc);
+ const SkString& shaderSrc,
+ GrContext::GPUStats* gpuStats);
#endif
fProgramBuilder->appendDecls(fOutputs, &vertShaderSrc);
vertShaderSrc.append("void main() {");
vertShaderSrc.append(fCode);
- vertShaderSrc.append("}");
+ vertShaderSrc.append("}\n");
GrGLuint vertShaderId = GrGLCompileAndAttachShader(glCtx, programId,
- GR_GL_VERTEX_SHADER, vertShaderSrc);
+ GR_GL_VERTEX_SHADER, vertShaderSrc,
+ gpu->gpuStats());
if (!vertShaderId) {
return false;
}
bool preprocess() const { return fPreprocess; }
PictureRenderer* setRenderer(PictureRenderer*);
+ PictureRenderer* renderer() { return fRenderer; }
void setTimerResultType(TimerData::Result resultType) { fTimerResult = resultType; }
"SK_LAZY_CACHE_STATS set to true. Report percentage of cache hits when using "
"deferred image decoding.");
+#if GR_GPU_STATS
+DEFINE_bool(gpuStats, false, "Only meaningful with gpu configurations. "
+ "Report some GPU call statistics.");
+#endif
+
DEFINE_bool(preprocess, false, "If true, perform device specific preprocessing before timing.");
// Buildbot-specific parameters
(double) gTotalCacheHits / (gTotalCacheHits + gTotalCacheMisses));
}
#endif
+
+#if GR_GPU_STATS
+ if (FLAGS_gpuStats && benchmark.renderer()->isUsingGpuDevice()) {
+ GrContext* ctx = benchmark.renderer()->getGrContext();
+ SkDebugf("RenderTarget Binds: %d\n", ctx->gpuStats()->renderTargetBinds());
+ SkDebugf("Shader Compilations: %d\n", ctx->gpuStats()->shaderCompilations());
+ }
+#endif
+
gWriter.end();
return 0;
}
"Requires --validate.");
DEFINE_string(mismatchPath, "", "Write images for tests that failed due to "
"pixel mismatches into this directory.");
+#if GR_GPU_STATS
+DEFINE_bool(gpuStats, false, "Only meaningful with gpu configurations. "
+ "Report some GPU call statistics.");
+#endif
DEFINE_bool(preprocess, false, "If true, perform device specific preprocessing before rendering.");
DEFINE_string(readJsonSummaryPath, "", "JSON file to read image expectations from.");
DECLARE_string(readPath);
#endif
}
#endif
+#if GR_GPU_STATS
+ if (FLAGS_gpuStats && renderer->isUsingGpuDevice()) {
+ GrContext* ctx = renderer->getGrContext();
+ SkDebugf("RenderTarget Binds: %d\n", ctx->gpuStats()->renderTargetBinds());
+ SkDebugf("Shader Compilations: %d\n", ctx->gpuStats()->shaderCompilations());
+ }
+#endif
#endif
if (FLAGS_writeJsonSummaryPath.count() == 1) {
// If there were any descriptions on the command line, insert them now.