perf: SSE spatial culling, inlined ray-tri, clickthrough CC fix

PerformSpatialCulling (0x6B8C60): Zig rewrite with SSE outcode
computation. 1.4x speedup, JMP-patched in weirdperformance.

performCollisionDetection (0x6B88E0): fully inlined SSE Moller-Trumbore
ray-triangle intersection, eliminating 4 SetVector3 calls and the
ray_tri function pointer call per triangle. ~22 cyc/tri in bench.

Both graduated from transform44 A/B testing to production JMP patches.

entity_sse.zig: reimplementations of UpdateEntityAndChunksPositions and
updateEntitiesInBounds (A/B tested, 1.2x bench, not shipped - memory
bound with negligible real-world gain).

clickthrough: fixed CheckObjectTypePermissions hook from fastcall to
thiscall (ECX preservation), fixed ClntObjMgrObjectPtr from fastcall(4)
to fastcall(5) with correct arg count.

bench: added performCollisionDetection bench with synthetic mesh data
and patched FindOrCreateHashEntry stub.
This commit is contained in:
MarcelineVQ
2026-03-25 12:34:57 -07:00
parent 4274729a77
commit 41ca30cfd5
7 changed files with 1219 additions and 56 deletions
+42
View File
@@ -65,6 +65,22 @@ pub fn build(b: *std.Build) void {
.optimize = .ReleaseFast,
}),
});
const cull_sse_obj = b.addObject(.{
.name = "cull_sse",
.root_module = b.createModule(.{
.root_source_file = b.path("src/performance/cull_sse.zig"),
.target = target,
.optimize = .ReleaseFast,
}),
});
const entity_sse_obj = b.addObject(.{
.name = "entity_sse",
.root_module = b.createModule(.{
.root_source_file = b.path("src/performance/entity_sse.zig"),
.target = target,
.optimize = .ReleaseFast,
}),
});
const bone_sse_target = b.resolveTargetQuery(.{
.cpu_arch = .x86,
.os_tag = .windows,
@@ -172,6 +188,8 @@ pub fn build(b: *std.Build) void {
// Called for both the main weirdutils build and each variant.
const ModuleObjects = struct {
clip_sse: *std.Build.Step.Compile,
cull_sse: *std.Build.Step.Compile,
entity_sse: *std.Build.Step.Compile,
bone_sse: *std.Build.Step.Compile,
bone_sse_ref: *std.Build.Step.Compile,
math_sse: *std.Build.Step.Compile,
@@ -184,6 +202,8 @@ pub fn build(b: *std.Build) void {
@setEvalBranchQuota(10000);
if (comptime std.mem.eql(u8, module_name, "weirdperformance")) {
mod.addObject(self.clip_sse);
mod.addObject(self.cull_sse);
mod.addObject(self.entity_sse);
mod.addObject(self.bone_sse);
mod.addObject(self.bone_sse_ref);
mod.addObject(self.silicon_sse);
@@ -193,6 +213,8 @@ pub fn build(b: *std.Build) void {
}
if (comptime std.mem.eql(u8, module_name, "transform44")) {
mod.addObject(self.clip_sse);
mod.addObject(self.cull_sse);
mod.addObject(self.entity_sse);
mod.addObject(self.bone_sse);
mod.addObject(self.bone_sse_ref);
mod.addObject(self.particle_sse);
@@ -208,6 +230,8 @@ pub fn build(b: *std.Build) void {
};
const objs = ModuleObjects{
.clip_sse = clip_sse_obj,
.cull_sse = cull_sse_obj,
.entity_sse = entity_sse_obj,
.bone_sse = bone_sse_obj,
.bone_sse_ref = bone_sse_ref_obj,
.math_sse = math_sse_obj,
@@ -299,11 +323,29 @@ pub fn build(b: *std.Build) void {
.optimize = .ReleaseFast,
}),
});
const bench_cull_sse = b.addObject(.{
.name = "bench_cull_sse",
.root_module = b.createModule(.{
.root_source_file = b.path("src/performance/cull_sse.zig"),
.target = bench_target,
.optimize = .ReleaseFast,
}),
});
bench.root_module.addObject(bench_math_sse);
bench.root_module.addObject(bench_silicon_sse);
bench.root_module.addObject(bench_bone_sse);
bench.root_module.addObject(bench_bone_baseline);
bench.root_module.addObject(bench_particle_sse);
bench.root_module.addObject(bench_cull_sse);
const bench_entity_sse = b.addObject(.{
.name = "bench_entity_sse",
.root_module = b.createModule(.{
.root_source_file = b.path("src/performance/entity_sse.zig"),
.target = bench_target,
.optimize = .ReleaseFast,
}),
});
bench.root_module.addObject(bench_entity_sse);
bench.root_module.linkSystemLibrary("m", .{});
const install_bench = b.addInstallArtifact(bench, .{});
const bench_step = b.step("bench", "Build math_sse benchmark harness (x86 Linux)");