Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[F3D] Pipe Sync Optimization #337

Merged
merged 4 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1313,12 +1313,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 @@ -1410,20 +1424,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 @@ -1460,12 +1466,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
Loading