From 7505112f1d984e1ca9cae1e9c4909de66542b314 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 19 Nov 2022 13:05:27 +0100 Subject: [PATCH 1/7] shader: Fix compiler warning --- panda/src/gobj/shader.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panda/src/gobj/shader.cxx b/panda/src/gobj/shader.cxx index fc458ccaef..e01c123c66 100644 --- a/panda/src/gobj/shader.cxx +++ b/panda/src/gobj/shader.cxx @@ -2876,7 +2876,7 @@ r_preprocess_source(ostream &out, istream &in, const Filename &fn, source_dir = full_fn.get_dirname(); incfn = incfile; - } else if (sscanf(line.c_str(), " # pragma%*[ \t]include <%2047[^\>]> %zn", incfile, &nread) == 1 + } else if (sscanf(line.c_str(), " # pragma%*[ \t]include <%2047[^>]> %zn", incfile, &nread) == 1 && nread == line.size()) { // Angled includes are also OK, but we don't search in the directory // of the source file. From d893b21f2b6876f3a9902b145bab2bc696908699 Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 19 Nov 2022 13:12:14 +0100 Subject: [PATCH 2/7] assimp: Fix assert loading meshes with multiple primitive types --- pandatool/src/assimp/assimpLoader.cxx | 46 +++++++++++++++++++-------- pandatool/src/assimp/assimpLoader.h | 10 ++++-- 2 files changed, 40 insertions(+), 16 deletions(-) diff --git a/pandatool/src/assimp/assimpLoader.cxx b/pandatool/src/assimp/assimpLoader.cxx index 377a59b1c5..7c2691cb0a 100644 --- a/pandatool/src/assimp/assimpLoader.cxx +++ b/pandatool/src/assimp/assimpLoader.cxx @@ -215,8 +215,7 @@ build_graph() { } // And then the meshes. - _geoms = new PT(Geom)[_scene->mNumMeshes]; - _geom_matindices = new unsigned int[_scene->mNumMeshes]; + _geoms = new Geoms[_scene->mNumMeshes]; for (size_t i = 0; i < _scene->mNumMeshes; ++i) { load_mesh(i); } @@ -234,7 +233,6 @@ build_graph() { delete[] _textures; delete[] _mat_states; delete[] _geoms; - delete[] _geom_matindices; } /** @@ -1019,20 +1017,22 @@ load_mesh(size_t index) { } // Create a geom and add the primitives to it. - PT(Geom) geom = new Geom(vdata); + Geoms &geoms = _geoms[index]; + geoms._mat_index = mesh.mMaterialIndex; + if (points->get_num_primitives() > 0) { - geom->add_primitive(points); + geoms._points = new Geom(vdata); + geoms._points->add_primitive(points); } if (lines->get_num_primitives() > 0) { - geom->add_primitive(lines); + geoms._lines = new Geom(vdata); + geoms._lines->add_primitive(lines); } if (triangles->get_num_primitives() > 0) { - geom->add_primitive(triangles); + geoms._triangles = new Geom(vdata); + geoms._triangles->add_primitive(triangles); } - _geoms[index] = geom; - _geom_matindices[index] = mesh.mMaterialIndex; - if (character) { _charmap[mesh.mName.C_Str()] = character; } @@ -1138,13 +1138,31 @@ load_node(const aiNode &node, PandaNode *parent) { // If there's only mesh, don't bother using a per-geom state. if (node.mNumMeshes == 1) { meshIndex = node.mMeshes[0]; - gnode->add_geom(_geoms[meshIndex]); - gnode->set_state(_mat_states[_geom_matindices[meshIndex]]); + const Geoms &geoms = _geoms[meshIndex]; + if (geoms._points != nullptr) { + gnode->add_geom(geoms._points); + } + if (geoms._lines != nullptr) { + gnode->add_geom(geoms._lines); + } + if (geoms._triangles != nullptr) { + gnode->add_geom(geoms._triangles); + } + gnode->set_state(_mat_states[geoms._mat_index]); } else { for (size_t i = 0; i < node.mNumMeshes; ++i) { meshIndex = node.mMeshes[i]; - gnode->add_geom(_geoms[node.mMeshes[i]], - _mat_states[_geom_matindices[meshIndex]]); + const Geoms &geoms = _geoms[meshIndex]; + const RenderState *state = _mat_states[geoms._mat_index]; + if (geoms._points != nullptr) { + gnode->add_geom(geoms._points, state); + } + if (geoms._lines != nullptr) { + gnode->add_geom(geoms._lines, state); + } + if (geoms._triangles != nullptr) { + gnode->add_geom(geoms._triangles, state); + } } } diff --git a/pandatool/src/assimp/assimpLoader.h b/pandatool/src/assimp/assimpLoader.h index 3b4854451d..5e4446f762 100644 --- a/pandatool/src/assimp/assimpLoader.h +++ b/pandatool/src/assimp/assimpLoader.h @@ -62,11 +62,17 @@ private: Assimp::Importer _importer; const aiScene *_scene; + struct Geoms { + PT(Geom) _points; + PT(Geom) _lines; + PT(Geom) _triangles; + unsigned int _mat_index = 0; + }; + // These arrays are temporarily used during the build_graph run. PT(Texture) *_textures; CPT(RenderState) *_mat_states; - PT(Geom) *_geoms; - unsigned int *_geom_matindices; + Geoms *_geoms; BoneMap _bonemap; CharacterMap _charmap; From 03d411c937b65a5c695791f00789a633baab39ce Mon Sep 17 00:00:00 2001 From: rdb Date: Sat, 19 Nov 2022 13:14:18 +0100 Subject: [PATCH 3/7] dist: Workaround to disable autodiscovery in setuptools>=61.0.0 See #1394 - creates a new finalize_distribution_options entry point that makes sure that either `py_modules` or `packages` is present, otherwise setuptools will activate its new auto-discovery system, even for custom commands that don't need setuptools' discovery system. However, this is not a great solution, because it applies when running all setuptools commands, not just build_apps. --- direct/src/dist/commands.py | 11 +++++++++++ makepanda/makepanda.py | 3 +++ makepanda/makewheel.py | 2 ++ 3 files changed, 16 insertions(+) diff --git a/direct/src/dist/commands.py b/direct/src/dist/commands.py index e55ed8a2cd..02e2285606 100644 --- a/direct/src/dist/commands.py +++ b/direct/src/dist/commands.py @@ -1685,3 +1685,14 @@ class bdist_apps(setuptools.Command): else: self.announce('\tUnknown installer: {}'.format(installer), distutils.log.ERROR) + + +def finalize_distribution_options(dist): + """Entry point for compatibility with setuptools>=61, see #1394.""" + + options = dist.get_option_dict('build_apps') + if options.get('gui_apps') or options.get('console_apps'): + # Make sure this is set to avoid auto-discovery taking place. + if getattr(dist.metadata, 'py_modules', None) is None and \ + getattr(dist.metadata, 'packages', None) is None: + dist.py_modules = [] diff --git a/makepanda/makepanda.py b/makepanda/makepanda.py index e348702d7e..49d0d74283 100755 --- a/makepanda/makepanda.py +++ b/makepanda/makepanda.py @@ -3259,6 +3259,9 @@ Author-email: etc-panda3d@lists.andrew.cmu.edu ENTRY_POINTS = """[distutils.commands] build_apps = direct.dist.commands:build_apps bdist_apps = direct.dist.commands:bdist_apps + +[setuptools.finalize_distribution_options] +build_apps = direct.dist.commands:finalize_distribution_options """ if not PkgSkip("DIRECT"): diff --git a/makepanda/makewheel.py b/makepanda/makewheel.py index fbcace6b56..f7ab00a0f9 100644 --- a/makepanda/makewheel.py +++ b/makepanda/makewheel.py @@ -765,6 +765,8 @@ __version__ = '{0}' entry_points += '[distutils.commands]\n' entry_points += 'build_apps = direct.dist.commands:build_apps\n' entry_points += 'bdist_apps = direct.dist.commands:bdist_apps\n' + entry_points += '[setuptools.finalize_distribution_options]\n' + entry_points += 'build_apps = direct.dist.commands:finalize_distribution_options\n' whl.write_file_data('panda3d_tools/__init__.py', PANDA3D_TOOLS_INIT.format(tools_init)) From fcfa1d2c99331f94efcefc9da9ec508eaf9fc1f5 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 21 Nov 2022 18:25:46 +0100 Subject: [PATCH 4/7] gobj: Fix `ShaderBuffer.prepare()` not actually doing anything --- panda/src/gobj/preparedGraphicsObjects.cxx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/panda/src/gobj/preparedGraphicsObjects.cxx b/panda/src/gobj/preparedGraphicsObjects.cxx index 099b40c899..c26fb7735f 100644 --- a/panda/src/gobj/preparedGraphicsObjects.cxx +++ b/panda/src/gobj/preparedGraphicsObjects.cxx @@ -1658,6 +1658,12 @@ begin_frame(GraphicsStateGuardianBase *gsg, Thread *current_thread) { } _enqueued_index_buffers.clear(); + + for (ShaderBuffer *buffer : _enqueued_shader_buffers) { + buffer->prepare_now(this, gsg); + } + + _enqueued_shader_buffers.clear(); } /** From 8a48c3b7114fd94807afa301cf0ea0646a38d791 Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 21 Nov 2022 18:26:19 +0100 Subject: [PATCH 5/7] pgraph: Remove recursive lock grab in `Light.set_color()` Harmless, but unnecessary --- panda/src/pgraph/light.I | 2 +- panda/src/pgraph/light.cxx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/panda/src/pgraph/light.I b/panda/src/pgraph/light.I index 6dd0428836..d173740607 100644 --- a/panda/src/pgraph/light.I +++ b/panda/src/pgraph/light.I @@ -71,8 +71,8 @@ INLINE void Light:: set_color(const LColor &color) { CDWriter cdata(_cycler); cdata->_color = color; + cdata->_viz_geom_stale = true; _has_color_temperature = false; - mark_viz_stale(); } /** diff --git a/panda/src/pgraph/light.cxx b/panda/src/pgraph/light.cxx index 8631cb5b0b..d70a83c195 100644 --- a/panda/src/pgraph/light.cxx +++ b/panda/src/pgraph/light.cxx @@ -125,7 +125,7 @@ set_color_temperature(PN_stdfloat temperature) { CDWriter cdata(_cycler); cdata->_color = color; - mark_viz_stale(); + cdata->_viz_geom_stale = true; } /** From 09f8634433a782040a6fea75fc8ac52a39052e5b Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 21 Nov 2022 18:29:51 +0100 Subject: [PATCH 6/7] pipeline: Minor optimizations in cycler copy constructor When copying a dirty cycler, don't use two separate lock-grabbing calls to add to the clean set, then remove from clean set and move to dirty set Short-cut the cdata copy loop for the common case of only 1 stage --- panda/src/pipeline/pipeline.cxx | 36 +++++++++++++++++++ panda/src/pipeline/pipeline.h | 1 + panda/src/pipeline/pipelineCyclerTrueImpl.cxx | 30 ++++++++-------- 3 files changed, 53 insertions(+), 14 deletions(-) diff --git a/panda/src/pipeline/pipeline.cxx b/panda/src/pipeline/pipeline.cxx index a3633226bc..ae2d88b512 100644 --- a/panda/src/pipeline/pipeline.cxx +++ b/panda/src/pipeline/pipeline.cxx @@ -357,6 +357,42 @@ add_cycler(PipelineCyclerTrueImpl *cycler) { } #endif // THREADED_PIPELINE +#ifdef THREADED_PIPELINE +/** + * Adds the indicated cycler to the list of cyclers associated with the + * pipeline. This method only exists when true pipelining is configured on. + * + * If the dirty flag is true, it will be marked as dirty in addition, as though + * add_dirty_cycler() were called immediately afterward. + */ +void Pipeline:: +add_cycler(PipelineCyclerTrueImpl *cycler, bool dirty) { + // It's safe to add it to the list while cycling, since the _clean list is + // not touched during the cycle loop. + MutexHolder holder(_lock); + nassertv(!cycler->_dirty); + + if (!dirty) { + cycler->insert_before(&_clean); + } + else { + nassertv(_num_stages != 1); + cycler->insert_before(&_dirty); + cycler->_dirty = _next_cycle_seq; + ++_num_dirty_cyclers; + +#ifdef DEBUG_THREADS + inc_cycler_type(_dirty_cycler_types, cycler->get_parent_type(), 1); +#endif + } + ++_num_cyclers; + +#ifdef DEBUG_THREADS + inc_cycler_type(_all_cycler_types, cycler->get_parent_type(), 1); +#endif +} +#endif // THREADED_PIPELINE + #ifdef THREADED_PIPELINE /** * Marks the indicated cycler as "dirty", meaning it will need to be cycled diff --git a/panda/src/pipeline/pipeline.h b/panda/src/pipeline/pipeline.h index c06bb2ffef..10fec52b60 100644 --- a/panda/src/pipeline/pipeline.h +++ b/panda/src/pipeline/pipeline.h @@ -50,6 +50,7 @@ public: #ifdef THREADED_PIPELINE void add_cycler(PipelineCyclerTrueImpl *cycler); + void add_cycler(PipelineCyclerTrueImpl *cycler, bool dirty); void add_dirty_cycler(PipelineCyclerTrueImpl *cycler); void remove_cycler(PipelineCyclerTrueImpl *cycler); diff --git a/panda/src/pipeline/pipelineCyclerTrueImpl.cxx b/panda/src/pipeline/pipelineCyclerTrueImpl.cxx index 714e61c0e4..3378b479e2 100644 --- a/panda/src/pipeline/pipelineCyclerTrueImpl.cxx +++ b/panda/src/pipeline/pipelineCyclerTrueImpl.cxx @@ -56,24 +56,26 @@ PipelineCyclerTrueImpl(const PipelineCyclerTrueImpl ©) : nassertv(_num_stages == copy._num_stages); _data = new CycleDataNode[_num_stages]; - // It's no longer critically important that we preserve pointerwise - // equivalence between different stages in the copy, but it doesn't cost - // much and might be a little more efficient, so we do it anyway. - typedef pmap Pointers; - Pointers pointers; + if (_num_stages == 1) { + _data[0]._cdata = copy._data[0]._cdata->make_copy(); + } + else { + // It's no longer critically important that we preserve pointerwise + // equivalence between different stages in the copy, but it doesn't cost + // much and might be a little more efficient, so we do it anyway. + typedef pmap Pointers; + Pointers pointers; - for (int i = 0; i < _num_stages; ++i) { - PT(CycleData) &new_pt = pointers[copy._data[i]._cdata]; - if (new_pt == nullptr) { - new_pt = copy._data[i]._cdata->make_copy(); + for (int i = 0; i < _num_stages; ++i) { + PT(CycleData) &new_pt = pointers[copy._data[i]._cdata]; + if (new_pt == nullptr) { + new_pt = copy._data[i]._cdata->make_copy(); + } + _data[i]._cdata = new_pt.p(); } - _data[i]._cdata = new_pt.p(); } - _pipeline->add_cycler(this); - if (copy._dirty) { - _pipeline->add_dirty_cycler(this); - } + _pipeline->add_cycler(this, copy._dirty != 0); } /** From 1f9f6a618ffdb4e2c253b6327b82f467a5d4dd5d Mon Sep 17 00:00:00 2001 From: rdb Date: Mon, 21 Nov 2022 18:33:35 +0100 Subject: [PATCH 7/7] vision: Fix use of wrong delete operator in ARToolKit code --- panda/src/vision/arToolKit.cxx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/panda/src/vision/arToolKit.cxx b/panda/src/vision/arToolKit.cxx index 4208ba6eee..ed7d019680 100644 --- a/panda/src/vision/arToolKit.cxx +++ b/panda/src/vision/arToolKit.cxx @@ -423,7 +423,7 @@ analyze(Texture *tex, bool do_flip_texture) { if (arDetectMarker(data, _threshold * 256, &marker_info, &marker_num) < 0) { vision_cat.error() << "ARToolKit detection error.\n"; - delete data; + delete[] data; return; }