Skip to content

Commit

Permalink
[F3D] Pipe Sync Optimization (#337)
Browse files Browse the repository at this point in the history
* made SP gbi cmds export before PipeSync, added bleed function to remove unneeded syncs after bleeding

* changed gsDPSetTexture and gsSPSetOtherMode to not skip syncs

* added DPSetPrimDepth to sync exclusion in mat bleed

---------

Co-authored-by: scut <scut>
  • Loading branch information
jesusyoshi54 committed May 12, 2024
1 parent 4589b8b commit b0b752f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
20 changes: 20 additions & 0 deletions fast64_internal/f3d/f3d_bleed.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ def bleed_mat(self, cur_fmat: FMaterial, last_mat: FMaterial, bleed_state: int):
commands_bled.commands.remove(None)
else:
commands_bled = self.bleed_cmd_list(cur_fmat.mat_only_DL, bleed_state)
# some syncs may become redundant after bleeding
self.optimize_syncs(commands_bled, bleed_state)
# remove SPEndDisplayList
while SPEndDisplayList() in commands_bled.commands:
commands_bled.commands.remove(SPEndDisplayList())
Expand Down Expand Up @@ -353,6 +355,24 @@ def on_bleed_end(
cmd_list.commands.append(SPEndDisplayList())
self.bled_gfx_lists[cmd_list] = last_mat

# remove syncs if first material, or if no gsDP cmds in material
def optimize_syncs(self, cmd_list: GfxList, bleed_state: int):
no_syncs_needed = {"DPSetPrimColor", "DPSetPrimDepth"} # will not affect rdp
syncs_needed = {"SPSetOtherMode"} # will affect rdp
if bleed_state == self.bleed_start:
while DPPipeSync() in cmd_list.commands:
cmd_list.commands.remove(DPPipeSync())
for cmd in cmd_list.commands:
cmd_name = type(cmd).__name__
if cmd == DPPipeSync():
continue
if "DP" in cmd_name and cmd_name not in no_syncs_needed:
return
if cmd_name in syncs_needed:
return
while DPPipeSync() in cmd_list.commands:
cmd_list.commands.remove(DPPipeSync())

def create_reset_cmds(self, reset_cmd_dict: dict[GbiMacro], default_render_mode: list[str]):
reset_cmds = []
for cmd_type, cmd_use in reset_cmd_dict.items():
Expand Down
34 changes: 17 additions & 17 deletions fast64_internal/f3d/f3d_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1315,12 +1315,26 @@ def saveOrGetF3DMaterial(material, fModel, obj, drawLayer, convertTextureData):
+ (("_layer" + str(drawLayer)) if f3dMat.rdp_settings.set_rendermode and drawLayer is not None else "")
+ (("_area" + str(areaIndex)) if f3dMat.set_fog and f3dMat.use_global_fog and areaKey is not None else "")
)
fMaterial = fModel.addMaterial(materialName)
fMaterial.mat_only_DL.commands.append(DPPipeSync())
fMaterial.revert.commands.append(DPPipeSync())

if not material.is_f3d:
raise PluginError("Material named " + material.name + " is not an F3D material.")
fMaterial = fModel.addMaterial(materialName)
useDict = all_combiner_uses(f3dMat)

defaults = bpy.context.scene.world.rdp_defaults
if fModel.f3d.F3DEX_GBI_2:
saveGeoModeDefinitionF3DEX2(fMaterial, f3dMat.rdp_settings, defaults, fModel.matWriteMethod)
else:
saveGeoModeDefinition(fMaterial, f3dMat.rdp_settings, defaults, fModel.matWriteMethod)

# Checking for f3dMat.rdp_settings.g_lighting here will prevent accidental exports,
# There may be some edge case where this isn't desired.
if useDict["Shade"] and f3dMat.rdp_settings.g_lighting and f3dMat.set_lights:
fLights = saveLightsDefinition(fModel, fMaterial, f3dMat, materialName + "_lights")
fMaterial.mat_only_DL.commands.extend([SPSetLights(fLights)])

fMaterial.mat_only_DL.commands.append(DPPipeSync())
fMaterial.revert.commands.append(DPPipeSync())

fMaterial.getScrollData(material, getMaterialScrollDimensions(f3dMat))

Expand Down Expand Up @@ -1412,20 +1426,12 @@ def saveOrGetF3DMaterial(material, fModel, obj, drawLayer, convertTextureData):
]
)

useDict = all_combiner_uses(f3dMat)
multitexManager = MultitexManager(material, fMaterial, fModel)

# Set othermode
if drawLayer is not None:
defaultRM = fModel.getRenderMode(drawLayer)
else:
defaultRM = None

defaults = bpy.context.scene.world.rdp_defaults
if fModel.f3d.F3DEX_GBI_2:
saveGeoModeDefinitionF3DEX2(fMaterial, f3dMat.rdp_settings, defaults, fModel.matWriteMethod)
else:
saveGeoModeDefinition(fMaterial, f3dMat.rdp_settings, defaults, fModel.matWriteMethod)
saveOtherModeHDefinition(
fMaterial,
f3dMat.rdp_settings,
Expand Down Expand Up @@ -1462,12 +1468,6 @@ def saveOrGetF3DMaterial(material, fModel, obj, drawLayer, convertTextureData):
color = exportColor(f3dMat.env_color[0:3]) + [scaleToU8(f3dMat.env_color[3])]
fMaterial.mat_only_DL.commands.append(DPSetEnvColor(*color))

# Checking for f3dMat.rdp_settings.g_lighting here will prevent accidental exports,
# There may be some edge case where this isn't desired.
if useDict["Shade"] and f3dMat.set_lights and f3dMat.rdp_settings.g_lighting:
fLights = saveLightsDefinition(fModel, fMaterial, f3dMat, materialName + "_lights")
fMaterial.mat_only_DL.commands.extend([SPSetLights(fLights)]) # TODO: handle synching: NO NEED?

if useDict["Key"] and f3dMat.set_key:
if material.mat_ver >= 4:
center = f3dMat.key_center
Expand Down

0 comments on commit b0b752f

Please sign in to comment.