Skip to content

Commit

Permalink
shader: use specific PStatCollector and group markers for shader compile
Browse files Browse the repository at this point in the history
This makes it possible to determine which shader is taking which amount of time to compile.
  • Loading branch information
rdb committed Dec 8, 2019
1 parent 9565d99 commit 406268c
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 4 deletions.
6 changes: 5 additions & 1 deletion panda/src/glstuff/glGraphicsStateGuardian_src.cxx
Expand Up @@ -6206,15 +6206,17 @@ release_geom(GeomContext *gc) {
*/
ShaderContext *CLP(GraphicsStateGuardian)::
prepare_shader(Shader *se) {
PStatGPUTimer timer(this, _prepare_shader_pcollector);
PStatGPUTimer timer(this, se->get_prepare_shader_pcollector());

#ifndef OPENGLES_1
ShaderContext *result = nullptr;

switch (se->get_language()) {
case Shader::SL_GLSL:
if (_supports_glsl) {
push_group_marker(std::string("Prepare Shader ") + se->get_debug_name());
result = new CLP(ShaderContext)(this, se);
pop_group_marker();
break;
} else {
GLCAT.error()
Expand All @@ -6225,7 +6227,9 @@ prepare_shader(Shader *se) {
case Shader::SL_Cg:
#if defined(HAVE_CG) && !defined(OPENGLES)
if (_supports_basic_shaders) {
push_group_marker(std::string("Prepare Shader ") + se->get_debug_name());
result = new CLP(CgShaderContext)(this, se);
pop_group_marker();
break;
} else {
GLCAT.error()
Expand Down
2 changes: 1 addition & 1 deletion panda/src/glstuff/glShaderContext_src.cxx
Expand Up @@ -3142,7 +3142,7 @@ glsl_compile_and_link() {
}

if (_glgsg->_use_object_labels) {
string name = _shader->get_filename();
const std::string &name = _shader->get_debug_name();
_glgsg->_glObjectLabel(GL_PROGRAM, _glsl_program, name.size(), name.data());
}

Expand Down
16 changes: 16 additions & 0 deletions panda/src/gobj/shader.I
Expand Up @@ -789,3 +789,19 @@ operator < (const Shader::ShaderFile &other) const {
}
return false;
}

/**
* Returns a PStatCollector for timing the preparation of just this shader.
*/
INLINE PStatCollector &Shader::
get_prepare_shader_pcollector() {
return _prepare_shader_pcollector;
}

/**
* Returns a name for the shader that is used for debugging.
*/
INLINE const std::string &Shader::
get_debug_name() const {
return _debug_name;
}
16 changes: 14 additions & 2 deletions panda/src/gobj/shader.cxx
Expand Up @@ -2479,6 +2479,8 @@ read(const ShaderFile &sfile, BamCacheRecord *record) {
}
}

_prepare_shader_pcollector = PStatCollector(std::string("Draw:Prepare:Shader:") + _debug_name);

_loaded = true;
return true;
}
Expand Down Expand Up @@ -2569,6 +2571,9 @@ load(const ShaderFile &sbody, BamCacheRecord *record) {
}
}

_debug_name = "created-shader";
_prepare_shader_pcollector = PStatCollector("Draw:Prepare:Shader:created-shader");

_loaded = true;
return true;
}
Expand All @@ -2589,6 +2594,8 @@ do_read_source(string &into, const Filename &fn, BamCacheRecord *record) {
return false;
}

Filename fullpath = vf->get_filename();

if (_language == SL_GLSL && glsl_preprocess) {
istream *source = vf->open_read_file(true);
if (source == nullptr) {
Expand All @@ -2603,7 +2610,7 @@ do_read_source(string &into, const Filename &fn, BamCacheRecord *record) {

std::set<Filename> open_files;
ostringstream sstr;
if (!r_preprocess_source(sstr, *source, fn, vf->get_filename(), open_files, record)) {
if (!r_preprocess_source(sstr, *source, fn, fullpath, open_files, record)) {
vf->close_read_file(source);
return false;
}
Expand All @@ -2625,7 +2632,7 @@ do_read_source(string &into, const Filename &fn, BamCacheRecord *record) {
}

_last_modified = std::max(_last_modified, vf->get_timestamp());
_source_files.push_back(vf->get_filename());
_source_files.push_back(fullpath);

// Strip trailing whitespace.
while (!into.empty() && isspace(into[into.size() - 1])) {
Expand All @@ -2635,6 +2642,11 @@ do_read_source(string &into, const Filename &fn, BamCacheRecord *record) {
// Except add back a newline at the end, which is needed by Intel drivers.
into += "\n";

if (!_debug_name.empty()) {
_debug_name += '/';
}
_debug_name += fullpath.get_basename();

return true;
}

Expand Down
6 changes: 6 additions & 0 deletions panda/src/gobj/shader.h
Expand Up @@ -529,6 +529,9 @@ class EXPCL_PANDA_GOBJ Shader : public TypedWritableReferenceCount {

static void set_default_caps(const ShaderCaps &caps);

INLINE PStatCollector &get_prepare_shader_pcollector();
INLINE const std::string &get_debug_name() const;

private:
#ifdef HAVE_CG
ShaderArgClass cg_parameter_class(CGparameter p);
Expand Down Expand Up @@ -612,6 +615,9 @@ class EXPCL_PANDA_GOBJ Shader : public TypedWritableReferenceCount {
typedef pmap <PreparedGraphicsObjects *, ShaderContext *> Contexts;
Contexts _contexts;

PStatCollector _prepare_shader_pcollector;
std::string _debug_name;

private:
void clear_prepared(PreparedGraphicsObjects *prepared_objects);

Expand Down

0 comments on commit 406268c

Please sign in to comment.