From 1584e9b9673bd3d4085b7bea06dfc58def175fbc Mon Sep 17 00:00:00 2001 From: sercero Date: Mon, 8 Apr 2024 22:26:36 -0300 Subject: [PATCH] Add support for OgreMeshUpgrader '-optvtxcache' option --- io_ogre/config.py | 1 + io_ogre/ui/export.py | 8 +++++++- io_ogre/util.py | 31 ++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/io_ogre/config.py b/io_ogre/config.py index dba34f9..02cf951 100644 --- a/io_ogre/config.py +++ b/io_ogre/config.py @@ -79,6 +79,7 @@ 'GENERATE_TANGENTS' : '0', 'OPTIMISE_ANIMATIONS' : True, 'INTERFACE_TOGGLE': False, + 'OPTIMISE_VERTEX_CACHE' : False, 'OPTIMISE_VERTEX_BUFFERS' : True, 'OPTIMISE_VERTEX_BUFFERS_OPTIONS' : 'puqs', diff --git a/io_ogre/ui/export.py b/io_ogre/ui/export.py index b3a3c6f..ecb27f8 100644 --- a/io_ogre/ui/export.py +++ b/io_ogre/ui/export.py @@ -98,7 +98,7 @@ def draw(self, context): "Materials" : ["EX_MATERIALS", "EX_SEPARATE_MATERIALS", "EX_COPY_SHADER_PROGRAMS", "EX_USE_FFP_PARAMETERS"], "Textures" : ["EX_DDS_MIPS", "EX_FORCE_IMAGE_FORMAT"], "Armature" : ["EX_ARMATURE_ANIMATION", "EX_SHARED_ARMATURE", "EX_ONLY_KEYFRAMES", "EX_ONLY_DEFORMABLE_BONES", "EX_ONLY_KEYFRAMED_BONES", "EX_OGRE_INHERIT_SCALE", "EX_TRIM_BONE_WEIGHTS"], - "Mesh" : ["EX_MESH", "EX_MESH_OVERWRITE", "EX_ARRAY", "EX_V1_EXTREMITY_POINTS", "EX_Vx_GENERATE_EDGE_LISTS", "EX_GENERATE_TANGENTS", "EX_Vx_OPTIMISE_ANIMATIONS", "EX_V2_OPTIMISE_VERTEX_BUFFERS", "EX_V2_OPTIMISE_VERTEX_BUFFERS_OPTIONS"], + "Mesh" : ["EX_MESH", "EX_MESH_OVERWRITE", "EX_ARRAY", "EX_V1_EXTREMITY_POINTS", "EX_Vx_GENERATE_EDGE_LISTS", "EX_GENERATE_TANGENTS", "EX_Vx_OPTIMISE_ANIMATIONS", "EX_Vx_OPTIMISE_VERTEX_CACHE", "EX_V2_OPTIMISE_VERTEX_BUFFERS", "EX_V2_OPTIMISE_VERTEX_BUFFERS_OPTIONS"], "LOD" : ["EX_LOD_GENERATION", "EX_LOD_LEVELS", "EX_LOD_DISTANCE", "EX_LOD_PERCENT"], "Shape Animation" : ["EX_SHAPE_ANIMATIONS", "EX_SHAPE_NORMALS"], "Logging" : ["EX_Vx_ENABLE_LOGGING", "EX_Vx_DEBUG_LOGGING"] @@ -399,6 +399,12 @@ def execute(self, context): name="Optimise Animations", description="DON'T optimise out redundant tracks & keyframes", default=config.get('OPTIMISE_ANIMATIONS')) = {} + EX_Vx_OPTIMISE_VERTEX_CACHE : BoolProperty( + name="Optimise Vertex Cache", + description="""This reorders the index buffer of the mesh such that triangles are rendered in order of proximity. +If enabled, the MeshUpgrader will print the change of the "average cache miss ratio (ACMR)" metric. +It measures the number of cache misses per triangle and thus ranges from 3.0 (all 3 vertices missed) to about 0.5 for an optimized mesh.""", + default=config.get('OPTIMISE_VERTEX_CACHE')) = {} EX_V2_OPTIMISE_VERTEX_BUFFERS : BoolProperty( name="Optimise Vertex Buffers For Shaders", description="Optimise vertex buffers for shaders.\nSee Vertex Buffers Options for more settings", diff --git a/io_ogre/util.py b/io_ogre/util.py index 5cb6821..9c571ec 100644 --- a/io_ogre/util.py +++ b/io_ogre/util.py @@ -88,7 +88,13 @@ def mesh_upgrade_tool(infile): # For Ogre v2.x we will use OgreMeshTool, which can perform the same operations if detect_converter_type() != "OgreXMLConverter": return - + + # Don't run 'OgreMeshUpgrader' unless we really need to + if config.get('LOD_GENERATION') != '0' and \ + config.get('GENERATE_EDGE_LISTS') is False and \ + config.get('OPTIMISE_VERTEX_CACHE') is False: + return + output_path, filename = os.path.split(infile) if not os.path.exists(infile): @@ -100,6 +106,9 @@ def mesh_upgrade_tool(infile): if config.get('GENERATE_EDGE_LISTS') is True: Report.warnings.append("OgreMeshUpgrader failed, Edge Lists will not be generated for this mesh: %s" % filename) + if config.get('OPTIMISE_VERTEX_CACHE') is True: + Report.warnings.append("OgreMeshUpgrader failed, Vertex Cache will not be optimized for this mesh: %s" % filename) + return # Extract converter type from its output @@ -132,6 +141,17 @@ def mesh_upgrade_tool(infile): if config.get('GENERATE_EDGE_LISTS') is False: cmd.append('-e') + # Vertex Cache Optimization + # https://www.ogre3d.org/2024/02/26/ogre-14-2-released#vertex-cache-optimization-in-meshupgrader + + # Check to see if the option is available + if config.get('OPTIMISE_VERTEX_CACHE') is True: + if output.find("-optvtxcache") == -1: + logger.warn("Vertex Cache Optimization requested, but this version of OgreMeshUpgrader does not support it (OGRE >= 14.2)") + Report.warnings.append("Vertex Cache Optimization requested, but this version of OgreMeshUpgrader does not support it (OGRE >= 14.2)") + else: + cmd.append('-optvtxcache') + # Put logfile into output directory use_logger = False logfile = os.path.join(output_path, 'OgreMeshUpgrader.log') @@ -151,6 +171,9 @@ def mesh_upgrade_tool(infile): if config.get('GENERATE_EDGE_LISTS') is True: logger.info("* Generating Edge Lists for mesh: %s" % filename) + if config.get('OPTIMISE_VERTEX_CACHE') is True: + logger.info("* Optimizing Vertex Cache for mesh: %s" % filename) + # First try to execute with the -log option logger.debug("%s" % " ".join(cmd)) proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) @@ -170,6 +193,9 @@ def mesh_upgrade_tool(infile): if config.get('GENERATE_EDGE_LISTS') is True: Report.warnings.append("OgreMeshUpgrader failed, Edge Lists will not be generated for this mesh: %s" % filename) + if config.get('OPTIMISE_VERTEX_CACHE') is True: + Report.warnings.append("OgreMeshUpgrader failed, Vertex Cache will not be optimized for this mesh: %s" % filename) + if error != None: logger.error(error) logger.warn(output) @@ -180,6 +206,9 @@ def mesh_upgrade_tool(infile): if config.get('GENERATE_EDGE_LISTS') is True: logger.info("- Generated Edge Lists for mesh: %s" % filename) + if config.get('OPTIMISE_VERTEX_CACHE') is True and '-optvtxcache' in cmd: + logger.info("- Optimized Vertex Cache for mesh: %s" % filename) + def detect_converter_type(): # todo: executing the same exe twice might not be efficient but will do for now