Skip to content

Commit de5031a

Browse files
committed
gl-dump-compiled-shaders, pstats collector for compute-dispatch call, a few minor other things
1 parent 0a8b35b commit de5031a

File tree

5 files changed

+76
-3
lines changed

5 files changed

+76
-3
lines changed

panda/src/glstuff/glGraphicsStateGuardian_src.cxx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ PStatCollector CLP(GraphicsStateGuardian)::_load_display_list_pcollector("Draw:T
7777
PStatCollector CLP(GraphicsStateGuardian)::_primitive_batches_display_list_pcollector("Primitive batches:Display lists");
7878
PStatCollector CLP(GraphicsStateGuardian)::_vertices_display_list_pcollector("Vertices:Display lists");
7979
PStatCollector CLP(GraphicsStateGuardian)::_vertices_immediate_pcollector("Vertices:Immediate mode");
80+
PStatCollector CLP(GraphicsStateGuardian)::_compute_dispatch_pcollector("Draw:Compute dispatch");
8081

8182
#ifdef OPENGLES_2
8283
PT(Shader) CLP(GraphicsStateGuardian)::_default_shader = NULL;
@@ -480,9 +481,9 @@ reset() {
480481
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
481482
}
482483

483-
GLCAT.error() << "gl-debug enabled.\n";
484+
GLCAT.debug() << "gl-debug enabled.\n";
484485
} else {
485-
GLCAT.error() << "gl-debug enabled, but NOT supported.\n";
486+
GLCAT.debug() << "gl-debug enabled, but NOT supported.\n";
486487
}
487488
} else {
488489
GLCAT.debug() << "gl-debug NOT enabled.\n";
@@ -1705,12 +1706,16 @@ reset() {
17051706
if (is_at_least_gl_version(4, 2) || has_extension("GL_ARB_shader_image_load_store")) {
17061707
_glBindImageTexture = (PFNGLBINDIMAGETEXTUREPROC)
17071708
get_extension_func("glBindImageTexture");
1709+
_glMemoryBarrier = (PFNGLMEMORYBARRIERPROC)
1710+
get_extension_func("glMemoryBarrier");
17081711

17091712
glGetIntegerv(GL_MAX_IMAGE_UNITS, &_max_image_units);
17101713

17111714
} else if (has_extension("GL_EXT_shader_image_load_store")) {
17121715
_glBindImageTexture = (PFNGLBINDIMAGETEXTUREPROC)
17131716
get_extension_func("glBindImageTextureEXT");
1717+
_glMemoryBarrier = (PFNGLMEMORYBARRIERPROC)
1718+
get_extension_func("glMemoryBarrierEXT");
17141719

17151720
glGetIntegerv(GL_MAX_IMAGE_UNITS_EXT, &_max_image_units);
17161721
}
@@ -1730,6 +1735,19 @@ reset() {
17301735
}
17311736
#endif
17321737

1738+
#ifndef OPENGLES
1739+
_supports_get_program_binary = false;
1740+
1741+
if (is_at_least_gl_version(4, 1) || has_extension("GL_ARB_get_program_binary")) {
1742+
_glGetProgramBinary = (PFNGLGETPROGRAMBINARYPROC)
1743+
get_extension_func("glGetProgramBinary");
1744+
1745+
if (_glGetProgramBinary != NULL) {
1746+
_supports_get_program_binary = true;
1747+
}
1748+
}
1749+
#endif
1750+
17331751
report_my_gl_errors();
17341752

17351753
if (support_stencil) {
@@ -4333,9 +4351,12 @@ end_occlusion_query() {
43334351
////////////////////////////////////////////////////////////////////
43344352
void CLP(GraphicsStateGuardian)::
43354353
dispatch_compute(int num_groups_x, int num_groups_y, int num_groups_z) {
4354+
PStatTimer timer(_compute_dispatch_pcollector);
43364355
nassertv(_supports_compute_shaders);
43374356
nassertv(_current_shader_context != NULL);
43384357
_glDispatchCompute(num_groups_x, num_groups_y, num_groups_z);
4358+
4359+
maybe_gl_finish();
43394360
}
43404361

43414362
////////////////////////////////////////////////////////////////////
@@ -8987,6 +9008,11 @@ specify_texture(CLP(TextureContext) *gtc) {
89879008
glTexParameteri(target, GL_TEXTURE_MAG_FILTER,
89889009
get_texture_filter_type(magfilter, true));
89899010

9011+
if (!uses_mipmaps) {
9012+
// NVIDIA drivers complain if we don't do this.
9013+
glTexParameteri(target, GL_TEXTURE_MAX_LEVEL, 0);
9014+
}
9015+
89909016
// Set anisotropic filtering.
89919017
if (_supports_anisotropy) {
89929018
PN_stdfloat anisotropy = tex->get_effective_anisotropic_degree();

panda/src/glstuff/glGraphicsStateGuardian_src.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ typedef void (APIENTRYP PFNGLDRAWELEMENTSINSTANCEDPROC) (GLenum mode, GLsizei co
176176
typedef void (APIENTRYP PFNGLBINDIMAGETEXTUREPROC) (GLuint unit, GLuint texture, GLint level, GLboolean layered, GLint layer, GLenum access, GLenum format);
177177
typedef void (APIENTRYP PFNGLBINDIMAGETEXTURESPROC) (GLuint first, GLsizei count, const GLuint *textures);
178178
typedef void (APIENTRYP PFNGLDISPATCHCOMPUTEPROC) (GLuint num_groups_x, GLuint num_groups_y, GLuint num_groups_z);
179+
typedef void (APIENTRYP PFNGLMEMORYBARRIERPROC) (GLbitfield barriers);
180+
typedef void (APIENTRYP PFNGLGETPROGRAMBINARYPROC) (GLuint program, GLsizei bufsize, GLsizei *length, GLenum *binaryFormat, void *binary);
179181
#endif // OPENGLES
180182
#endif // __EDG__
181183

@@ -534,6 +536,7 @@ class EXPCL_GL CLP(GraphicsStateGuardian) : public GraphicsStateGuardian {
534536
bool _supports_anisotropy;
535537
GLint _max_image_units;
536538
bool _supports_multi_bind;
539+
bool _supports_get_program_binary;
537540

538541
#ifdef OPENGLES
539542
bool _supports_depth24;
@@ -702,6 +705,8 @@ class EXPCL_GL CLP(GraphicsStateGuardian) : public GraphicsStateGuardian {
702705
PFNGLBINDIMAGETEXTUREPROC _glBindImageTexture;
703706
PFNGLBINDIMAGETEXTURESPROC _glBindImageTextures;
704707
PFNGLDISPATCHCOMPUTEPROC _glDispatchCompute;
708+
PFNGLMEMORYBARRIERPROC _glMemoryBarrier;
709+
PFNGLGETPROGRAMBINARYPROC _glGetProgramBinary;
705710
#endif // OPENGLES
706711

707712
GLenum _edge_clamp;
@@ -745,6 +750,7 @@ class EXPCL_GL CLP(GraphicsStateGuardian) : public GraphicsStateGuardian {
745750
static PStatCollector _primitive_batches_display_list_pcollector;
746751
static PStatCollector _vertices_display_list_pcollector;
747752
static PStatCollector _vertices_immediate_pcollector;
753+
static PStatCollector _compute_dispatch_pcollector;
748754

749755
public:
750756
virtual TypeHandle get_type() const {

panda/src/glstuff/glShaderContext_src.cxx

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1750,6 +1750,13 @@ glsl_compile_shader(GSG *gsg) {
17501750
glsl_report_shader_errors(gsg, _glsl_teshader);
17511751
}
17521752

1753+
// If we requested to retrieve the shader, we should indicate that before linking.
1754+
#if !defined(NDEBUG) && !defined(OPENGLES)
1755+
if (gl_dump_compiled_shaders && gsg->_supports_get_program_binary) {
1756+
gsg->_glProgramParameteri(_glsl_program, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
1757+
}
1758+
#endif
1759+
17531760
gsg->_glLinkProgram(_glsl_program);
17541761

17551762
GLint status;
@@ -1760,9 +1767,36 @@ glsl_compile_shader(GSG *gsg) {
17601767
return false;
17611768
}
17621769

1770+
// Dump the binary if requested.
1771+
#if !defined(NDEBUG) && !defined(OPENGLES)
1772+
if (gl_dump_compiled_shaders && gsg->_supports_get_program_binary) {
1773+
GLint length = 0;
1774+
gsg->_glGetProgramiv(_glsl_program, GL_PROGRAM_BINARY_LENGTH, &length);
1775+
length += 2;
1776+
1777+
char filename[64];
1778+
static int gl_dump_count = 0;
1779+
sprintf(filename, "glsl_program%d.dump", gl_dump_count++);
1780+
1781+
char *binary = new char[length];
1782+
GLenum format;
1783+
GLsizei num_bytes;
1784+
gsg->_glGetProgramBinary(_glsl_program, length, &num_bytes, &format, (void*)binary);
1785+
1786+
pofstream s;
1787+
s.open(filename, ios::out | ios::binary);
1788+
s.write(binary, num_bytes);
1789+
s.close();
1790+
1791+
GLCAT.info()
1792+
<< "Dumped " << num_bytes << " bytes of program binary with format 0x"
1793+
<< hex << format << dec << " to " << filename << "\n";
1794+
delete[] binary;
1795+
}
1796+
#endif // NDEBUG
1797+
17631798
gsg->report_my_gl_errors();
17641799
return true;
17651800
}
17661801

17671802
#endif // OPENGLES_1
1768-

panda/src/glstuff/glmisc_src.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,12 @@ ConfigVariableBool gl_cube_map_seamless
198198
"this is causing problems or if you simply don't need the "
199199
"functionality."));
200200

201+
ConfigVariableBool gl_dump_compiled_shaders
202+
("gl-dump-compiled-shaders", false,
203+
PRC_DESC("This configures Panda to dump the binary content of GLSL "
204+
"programs to disk with a filename like glsl_program0.dump "
205+
"into the current directory."));
206+
201207
extern ConfigVariableBool gl_parallel_arrays;
202208

203209
void CLP(init_classes)() {

panda/src/glstuff/glmisc_src.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ extern ConfigVariableBool gl_force_no_error;
6666
extern ConfigVariableBool gl_force_no_flush;
6767
extern ConfigVariableBool gl_separate_specular_color;
6868
extern ConfigVariableBool gl_cube_map_seamless;
69+
extern ConfigVariableBool gl_dump_compiled_shaders;
6970

7071
extern EXPCL_GL void CLP(init_classes)();
7172

0 commit comments

Comments
 (0)