From 1ecd0218da5a402dd06e87a1c1112d4fbeba059c Mon Sep 17 00:00:00 2001 From: water Date: Tue, 8 Mar 2022 21:28:31 -0500 Subject: [PATCH 1/6] add ocean-vu0 mips2c and decomp ocean-texture --- decompiler/config/all-types.gc | 4 +- .../config/jak1_ntsc_black_label/hacks.jsonc | 4 +- .../jak1_ntsc_black_label/type_casts.jsonc | 103 +++ decompiler/level_extractor/extract_level.cpp | 5 + game/CMakeLists.txt | 1 + game/common/vu.h | 8 + game/mips2c/functions/ocean_vu0.cpp | 646 ++++++++++++++++++ game/mips2c/mips2c_table.cpp | 10 +- goal_src/engine/gfx/ocean/ocean-h.gc | 4 +- goal_src/engine/gfx/ocean/ocean-texture.gc | 595 ++++++++++++++++ goal_src/engine/gfx/ocean/ocean.gc | 28 +- .../reference/engine/gfx/ocean/ocean-h_REF.gc | 4 +- .../engine/gfx/ocean/ocean-texture_REF.gc | 597 ++++++++++++++++ 13 files changed, 1992 insertions(+), 17 deletions(-) create mode 100644 game/mips2c/functions/ocean_vu0.cpp create mode 100644 test/decompiler/reference/engine/gfx/ocean/ocean-texture_REF.gc diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index acb7074e29..fa228c52e8 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -7370,7 +7370,7 @@ (define-extern *ocean-mid-off* symbol) (define-extern *ocean-near-off* symbol) (define-extern *ocean-heights* ocean-wave-info) ;; guess -(define-extern *ocean-verts* (pointer vector)) ;; ret from ocean-generate-verts +(define-extern *ocean-verts* (inline-array vector)) ;; ret from ocean-generate-verts ;; ---------------------- @@ -21702,7 +21702,7 @@ ;; - Functions (define-extern ocean-interp-wave (function ocean-wave-info uint none)) ;; unconfirmed -(define-extern ocean-generate-verts (function (pointer vector) ocean-wave-info none)) ;; unconfirmed - pointer is *ocean-verts* +(define-extern ocean-generate-verts (function (inline-array vector) ocean-wave-info none)) ;; unconfirmed - pointer is *ocean-verts* (define-extern draw-ocean-texture (function dma-buffer (pointer vector) symbol none)) ;; unconfirmed - pointer is *ocean-verts* (define-extern ocean-init-buffer (function dma-buffer pointer)) (define-extern draw-ocean-far (function dma-buffer profile-frame)) diff --git a/decompiler/config/jak1_ntsc_black_label/hacks.jsonc b/decompiler/config/jak1_ntsc_black_label/hacks.jsonc index 9b178babfa..2a495b5cba 100644 --- a/decompiler/config/jak1_ntsc_black_label/hacks.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/hacks.jsonc @@ -594,7 +594,9 @@ // ocean "init-ocean-far-regs", "draw-large-polygon-ocean", - "render-ocean-quad" + "render-ocean-quad", + "ocean-generate-verts", + "ocean-interp-wave" ], "mips2c_jump_table_functions": { diff --git a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc index 08ae852c68..a8fc488b5d 100644 --- a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc @@ -7425,5 +7425,108 @@ [[114, 117], "v1", "dma-packet"] ], + "ocean-texture-add-constants": [ + [[8, 16], "a0", "dma-packet"] + ], + + "ocean-texture-add-envmap": [ + [[1, 8], "v1", "(pointer uint128)"] + ], + + "ocean-texture-add-verts": [ + [[6, 11], "a0", "dma-packet"] + ], + + "ocean-texture-add-verts-last": [ + [[6, 11], "a3", "dma-packet"], + [[19, 24], "a0", "dma-packet"] + ], + + "ocean-texture-add-call-start": [ + [[3, 8], "a0", "dma-packet"] + ], + + "ocean-texture-add-call-rest": [ + [[3, 8], "a0", "dma-packet"] + ], + + "ocean-texture-add-call-done": [ + [[3, 8], "a0", "dma-packet"] + ], + + "draw-ocean-texture": [ + [[24, 29], "a0", "dma-packet"], + [[92, 96], "a0", "dma-packet"], + [[102, 105], "a0", "gs-gif-tag"], + [110, "s0", "(pointer gs-test)"], + [112, "s0", "(pointer gs-reg64)"], + [114, "s0", "(pointer gs-alpha)"], + [116, "s0", "(pointer gs-reg64)"], + [133, "s0", "(pointer gs-tex0)"], + [135, "s0", "(pointer gs-reg64)"], + [137, "s0", "(pointer gs-tex1)"], + [139, "s0", "(pointer gs-reg64)"], + [140, "s0", "(pointer gs-clamp)"], + [142, "s0", "(pointer gs-reg64)"], + [143, "s0", "(pointer uint64)"], + [145, "s0", "(pointer gs-reg64)"], + [[151, 155], "v1", "(pointer uint128)"], + [[156, 164], "a0", "vector4w"], + [[165, 169], "a0", "vector4w"], + [[170, 175], "a0", "vector4w"], + [[176, 182], "a0", "vector4w"], + [[183, 191], "v1", "vector4w"], + [[204, 208], "a0", "dma-packet"], + [[214, 217], "a0", "gs-gif-tag"], + [237, "s2", "(pointer gs-tex0)"], + [239, "s2", "(pointer gs-reg64)"], + [240, "s2", "(pointer uint64)"], + [242, "s2", "(pointer gs-reg64)"], + [251, "v1", "(pointer uint128)"], + [[253, 260], "a0", "vector4w"], + [[261, 265], "a0", "vector4w"], + [[266, 271], "a0", "vector4w"], + [[272, 278], "a0", "vector4w"], + [[279, 286], "v1", "vector4w"], + [[292, 296], "a0", "dma-packet"], + [[302, 305], "a0", "gs-gif-tag"], + [325, "s3", "(pointer gs-tex0)"], + [327, "s3", "(pointer gs-reg64)"], + [328, "s3", "(pointer uint64)"], + [330, "s3", "(pointer gs-reg64)"], + [339, "v1", "(pointer uint128)"], + [[341, 348], "a0", "vector4w"], + [[349, 367], "a0", "vector4w"], + [[368, 375], "v1", "vector4w"], + [[381, 385], "a0", "dma-packet"], + [[391, 394], "a0", "gs-gif-tag"], + [415, "s3", "(pointer gs-tex0)"], + [417, "s3", "(pointer gs-reg64)"], + [418, "s3", "(pointer uint64)"], + [420, "s3", "(pointer gs-reg64)"], + [429, "v1", "(pointer uint128)"], + [[431, 457], "a0", "vector4w"], + [[458, 466], "v1", "vector4w"], + [[471, 475], "a0", "dma-packet"], + [[481, 484], "a0", "gs-gif-tag"], + [505, "s3", "(pointer gs-tex0)"], + [507, "s3", "(pointer gs-reg64)"], + [508, "s3", "(pointer uint64)"], + [510, "s3", "(pointer gs-reg64)"], + [519, "v1", "(pointer uint128)"], + [[521, 547], "a0", "vector4w"], + [[548, 555], "v1", "vector4w"], + [[561, 565], "a0", "dma-packet"], + [[571, 574], "a0", "gs-gif-tag"], + [595, "s3", "(pointer gs-tex0)"], + [597, "s3", "(pointer gs-reg64)"], + [598, "s3", "(pointer uint64)"], + [600, "s3", "(pointer gs-reg64)"], + [609, "v1", "(pointer uint128)"], + [[611, 638], "a0", "vector4w"], + [[639, 646], "v1", "vector4w"], + [[652, 656], "a0", "dma-packet"] + ], + "placeholder-do-not-add-below": [] } diff --git a/decompiler/level_extractor/extract_level.cpp b/decompiler/level_extractor/extract_level.cpp index a1efe74b3f..84165e828f 100644 --- a/decompiler/level_extractor/extract_level.cpp +++ b/decompiler/level_extractor/extract_level.cpp @@ -133,6 +133,11 @@ void extract_common(ObjectFileDB& db, TextureDB& tex_db, const std::string& dgo_ return; } + if (tex_db.textures.size() == 0) { + lg::warn("Skipping common extract because there were no textures in the input"); + return; + } + confirm_textures_identical(tex_db); tfrag3::Level tfrag_level; diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 53cf90f164..5dd600b009 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -50,6 +50,7 @@ set(RUNTIME_SOURCE mips2c/functions/joint.cpp mips2c/functions/merc_blend_shape.cpp mips2c/functions/ocean.cpp + mips2c/functions/ocean_vu0.cpp mips2c/functions/ripple.cpp mips2c/functions/sky_tng.cpp mips2c/functions/sparticle.cpp diff --git a/game/common/vu.h b/game/common/vu.h index 9c8e0bedff..3d0631180d 100644 --- a/game/common/vu.h +++ b/game/common/vu.h @@ -471,6 +471,14 @@ struct alignas(16) Accumulator { } } + void msub(Mask mask, Vf& dest, const Vf& a, float b) { + for (int i = 0; i < 4; i++) { + if ((u64)mask & (1 << i)) { + dest[i] = data[i] - a[i] * b; + } + } + } + u16 madd_flag(Mask mask, Vf& dest, const Vf& a, float b) { u16 result = 0; for (int i = 0; i < 4; i++) { diff --git a/game/mips2c/functions/ocean_vu0.cpp b/game/mips2c/functions/ocean_vu0.cpp new file mode 100644 index 0000000000..f6578f8a53 --- /dev/null +++ b/game/mips2c/functions/ocean_vu0.cpp @@ -0,0 +1,646 @@ +// clang-format off +//--------------------------MIPS2C--------------------- +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/kscheme.h" +namespace Mips2C { +namespace ocean_interp_wave { +struct Cache { + void* ocean_wave_frames; // *ocean-wave-frames* + void* ocean_work; // *ocean-work* +} cache; + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->daddiu(sp, sp, -16); // daddiu sp, sp, -16 + c->sd(fp, 8, sp); // sd fp, 8(sp) + c->mov64(fp, t9); // or fp, t9, r0 + c->dsra(a2, a1, 5); // dsra a2, a1, 5 + c->andi(v1, a2, 63); // andi v1, a2, 63 + c->dsll(v1, v1, 10); // dsll v1, v1, 10 + c->daddu(v1, r0, v1); // daddu v1, r0, v1 + c->load_symbol(a3, cache.ocean_wave_frames); // lw a3, *ocean-wave-frames*(s7) + c->daddu(v1, v1, a3); // daddu v1, v1, a3 + c->daddiu(a2, a2, 1); // daddiu a2, a2, 1 + c->andi(a2, a2, 63); // andi a2, a2, 63 + c->dsll(a2, a2, 10); // dsll a2, a2, 10 + c->daddu(a2, r0, a2); // daddu a2, r0, a2 + c->load_symbol(a3, cache.ocean_wave_frames); // lw a3, *ocean-wave-frames*(s7) + c->daddu(a2, a2, a3); // daddu a2, a2, a3 + c->fprs[f0] = 0.03125; // lwc1 f0, L12(fp) + c->andi(a1, a1, 31); // andi a1, a1, 31 + c->mtc1(f1, a1); // mtc1 f1, a1 + c->cvtsw(f1, f1); // cvt.s.w f1, f1 + c->muls(f0, f0, f1); // mul.s f0, f0, f1 + c->load_symbol(a1, cache.ocean_work); // lw a1, *ocean-work*(s7) + c->swc1(f0, 64, a1); // swc1 f0, 64(a1) + c->fprs[f0] = 1.0; // lwc1 f0, L11(fp) + c->load_symbol(a1, cache.ocean_work); // lw a1, *ocean-work*(s7) + c->lwc1(f1, 64, a1); // lwc1 f1, 64(a1) + c->subs(f0, f0, f1); // sub.s f0, f0, f1 + c->load_symbol(a1, cache.ocean_work); // lw a1, *ocean-work*(s7) + c->swc1(f0, 60, a1); // swc1 f0, 60(a1) + c->fprs[f0] = 0.333; // lwc1 f0, L10(fp) + c->load_symbol(a1, cache.ocean_work); // lw a1, *ocean-work*(s7) + c->lwc1(f1, 60, a1); // lwc1 f1, 60(a1) + c->muls(f0, f0, f1); // mul.s f0, f0, f1 + c->load_symbol(a1, cache.ocean_work); // lw a1, *ocean-work*(s7) + c->swc1(f0, 60, a1); // swc1 f0, 60(a1) + c->fprs[f0] = 0.333; // lwc1 f0, L10(fp) + c->load_symbol(a1, cache.ocean_work); // lw a1, *ocean-work*(s7) + c->lwc1(f1, 64, a1); // lwc1 f1, 64(a1) + c->muls(f0, f0, f1); // mul.s f0, f0, f1 + c->load_symbol(a1, cache.ocean_work); // lw a1, *ocean-work*(s7) + c->swc1(f0, 64, a1); // swc1 f0, 64(a1) + c->load_symbol(a3, cache.ocean_work); // lw a3, *ocean-work*(s7) + c->addiu(a1, r0, 32); // addiu a1, r0, 32 + c->lqc2(vf1, 60, a3); // lqc2 vf1, 60(a3) + // nop // sll r0, r0, 0 + c->lw(a3, 0, v1); // lw a3, 0(v1) + // nop // sll r0, r0, 0 + c->lw(t0, 0, a2); // lw t0, 0(a2) + + block_1: + c->pextlb(t1, a3, r0); // pextlb t1, a3, r0 + c->lw(a3, 4, v1); // lw a3, 4(v1) + c->pextlb(t2, t0, r0); // pextlb t2, t0, r0 + c->lw(t0, 4, a2); // lw t0, 4(a2) + c->pextlb(t3, a3, r0); // pextlb t3, a3, r0 + c->lw(a3, 8, v1); // lw a3, 8(v1) + c->pextlb(t4, t0, r0); // pextlb t4, t0, r0 + c->lw(t0, 8, a2); // lw t0, 8(a2) + c->pextlh(t5, t1, r0); // pextlh t5, t1, r0 + c->lw(t1, 12, v1); // lw t1, 12(v1) + c->pextlh(t6, t2, r0); // pextlh t6, t2, r0 + c->lw(t2, 12, a2); // lw t2, 12(a2) + c->pextlh(t3, t3, r0); // pextlh t3, t3, r0 + c->mov128_vf_gpr(vf2, t5); // qmtc2.i vf2, t5 + c->pextlh(t4, t4, r0); // pextlh t4, t4, r0 + c->mov128_vf_gpr(vf10, t6); // qmtc2.i vf10, t6 + c->pextlb(a3, a3, r0); // pextlb a3, a3, r0 + c->mov128_vf_gpr(vf3, t3); // qmtc2.i vf3, t3 + c->pextlb(t0, t0, r0); // pextlb t0, t0, r0 + c->mov128_vf_gpr(vf11, t4); // qmtc2.i vf11, t4 + c->pextlb(t4, t1, r0); // pextlb t4, t1, r0 + c->vitof15(DEST::xyzw, vf2, vf2); // vitof15.xyzw vf2, vf2 + c->pextlb(t3, t2, r0); // pextlb t3, t2, r0 + c->vitof15(DEST::xyzw, vf10, vf10); // vitof15.xyzw vf10, vf10 + c->pextlh(a3, a3, r0); // pextlh a3, a3, r0 + c->vitof15(DEST::xyzw, vf3, vf3); // vitof15.xyzw vf3, vf3 + c->pextlh(t1, t0, r0); // pextlh t1, t0, r0 + c->vitof15(DEST::xyzw, vf11, vf11); // vitof15.xyzw vf11, vf11 + c->pextlh(t2, t4, r0); // pextlh t2, t4, r0 + c->lw(t5, 16, v1); // lw t5, 16(v1) + c->pextlh(t3, t3, r0); // pextlh t3, t3, r0 + c->lw(t6, 16, a2); // lw t6, 16(a2) + c->vmula_bc(DEST::xyzw, BC::x, vf2, vf1); // vmulax.xyzw acc, vf2, vf1 + c->lw(t4, 20, v1); // lw t4, 20(v1) + c->vmadd_bc(DEST::xyzw, BC::y, vf2, vf10, vf1); // vmaddy.xyzw vf2, vf10, vf1 + c->lw(t0, 20, a2); // lw t0, 20(a2) + c->vmula_bc(DEST::xyzw, BC::x, vf3, vf1); // vmulax.xyzw acc, vf3, vf1 + c->mov128_vf_gpr(vf4, a3); // qmtc2.i vf4, a3 + c->vmadd_bc(DEST::xyzw, BC::y, vf3, vf11, vf1); // vmaddy.xyzw vf3, vf11, vf1 + c->mov128_vf_gpr(vf12, t1); // qmtc2.i vf12, t1 + c->pextlb(a3, t5, r0); // pextlb a3, t5, r0 + c->mov128_vf_gpr(vf5, t2); // qmtc2.i vf5, t2 + c->pextlb(t1, t6, r0); // pextlb t1, t6, r0 + c->mov128_vf_gpr(vf13, t3); // qmtc2.i vf13, t3 + c->pextlb(t2, t4, r0); // pextlb t2, t4, r0 + c->vitof15(DEST::xyzw, vf4, vf4); // vitof15.xyzw vf4, vf4 + c->pextlb(t0, t0, r0); // pextlb t0, t0, r0 + c->vitof15(DEST::xyzw, vf12, vf12); // vitof15.xyzw vf12, vf12 + c->pextlh(a3, a3, r0); // pextlh a3, a3, r0 + c->vitof15(DEST::xyzw, vf5, vf5); // vitof15.xyzw vf5, vf5 + c->pextlh(t1, t1, r0); // pextlh t1, t1, r0 + c->vitof15(DEST::xyzw, vf13, vf13); // vitof15.xyzw vf13, vf13 + c->pextlh(t2, t2, r0); // pextlh t2, t2, r0 + c->lw(t5, 24, v1); // lw t5, 24(v1) + c->pextlh(t3, t0, r0); // pextlh t3, t0, r0 + c->lw(t6, 24, a2); // lw t6, 24(a2) + c->vmula_bc(DEST::xyzw, BC::x, vf4, vf1); // vmulax.xyzw acc, vf4, vf1 + c->lw(t4, 28, v1); // lw t4, 28(v1) + c->vmadd_bc(DEST::xyzw, BC::y, vf4, vf12, vf1); // vmaddy.xyzw vf4, vf12, vf1 + c->lw(t0, 28, a2); // lw t0, 28(a2) + c->vmula_bc(DEST::xyzw, BC::x, vf5, vf1); // vmulax.xyzw acc, vf5, vf1 + c->mov128_vf_gpr(vf6, a3); // qmtc2.i vf6, a3 + c->vmadd_bc(DEST::xyzw, BC::y, vf5, vf13, vf1); // vmaddy.xyzw vf5, vf13, vf1 + c->mov128_vf_gpr(vf14, t1); // qmtc2.i vf14, t1 + c->pextlb(a3, t5, r0); // pextlb a3, t5, r0 + c->mov128_vf_gpr(vf7, t2); // qmtc2.i vf7, t2 + c->pextlb(t1, t6, r0); // pextlb t1, t6, r0 + c->mov128_vf_gpr(vf15, t3); // qmtc2.i vf15, t3 + c->pextlb(t2, t4, r0); // pextlb t2, t4, r0 + c->vitof15(DEST::xyzw, vf6, vf6); // vitof15.xyzw vf6, vf6 + c->pextlb(t0, t0, r0); // pextlb t0, t0, r0 + c->vitof15(DEST::xyzw, vf14, vf14); // vitof15.xyzw vf14, vf14 + c->pextlh(a3, a3, r0); // pextlh a3, a3, r0 + c->vitof15(DEST::xyzw, vf7, vf7); // vitof15.xyzw vf7, vf7 + c->pextlh(t1, t1, r0); // pextlh t1, t1, r0 + c->vitof15(DEST::xyzw, vf15, vf15); // vitof15.xyzw vf15, vf15 + c->pextlh(t2, t2, r0); // pextlh t2, t2, r0 + c->sqc2(vf2, 0, a0); // sqc2 vf2, 0(a0) + c->pextlh(t0, t0, r0); // pextlh t0, t0, r0 + c->sqc2(vf3, 16, a0); // sqc2 vf3, 16(a0) + c->vmula_bc(DEST::xyzw, BC::x, vf6, vf1); // vmulax.xyzw acc, vf6, vf1 + c->sqc2(vf4, 32, a0); // sqc2 vf4, 32(a0) + c->vmadd_bc(DEST::xyzw, BC::y, vf6, vf14, vf1); // vmaddy.xyzw vf6, vf14, vf1 + c->sqc2(vf5, 48, a0); // sqc2 vf5, 48(a0) + c->vmula_bc(DEST::xyzw, BC::x, vf7, vf1); // vmulax.xyzw acc, vf7, vf1 + c->mov128_vf_gpr(vf8, a3); // qmtc2.i vf8, a3 + c->vmadd_bc(DEST::xyzw, BC::y, vf7, vf15, vf1); // vmaddy.xyzw vf7, vf15, vf1 + c->mov128_vf_gpr(vf16, t1); // qmtc2.i vf16, t1 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf9, t2); // qmtc2.i vf9, t2 + // nop // sll r0, r0, 0 + c->mov128_vf_gpr(vf17, t0); // qmtc2.i vf17, t0 + // nop // sll r0, r0, 0 + c->vitof15(DEST::xyzw, vf8, vf8); // vitof15.xyzw vf8, vf8 + c->daddiu(a0, a0, 128); // daddiu a0, a0, 128 + c->vitof15(DEST::xyzw, vf16, vf16); // vitof15.xyzw vf16, vf16 + c->lw(a3, 32, v1); // lw a3, 32(v1) + c->vitof15(DEST::xyzw, vf9, vf9); // vitof15.xyzw vf9, vf9 + c->lw(t0, 32, a2); // lw t0, 32(a2) + c->vitof15(DEST::xyzw, vf17, vf17); // vitof15.xyzw vf17, vf17 + c->vmula_bc(DEST::xyzw, BC::x, vf8, vf1); // vmulax.xyzw acc, vf8, vf1 + c->sqc2(vf6, -64, a0); // sqc2 vf6, -64(a0) + c->vmadd_bc(DEST::xyzw, BC::y, vf8, vf16, vf1); // vmaddy.xyzw vf8, vf16, vf1 + c->sqc2(vf7, -48, a0); // sqc2 vf7, -48(a0) + c->vmula_bc(DEST::xyzw, BC::x, vf9, vf1); // vmulax.xyzw acc, vf9, vf1 + c->daddiu(a1, a1, -1); // daddiu a1, a1, -1 + c->vmadd_bc(DEST::xyzw, BC::y, vf9, vf17, vf1); // vmaddy.xyzw vf9, vf17, vf1 + c->daddiu(v1, v1, 32); // daddiu v1, v1, 32 + // nop // sll r0, r0, 0 + c->daddiu(a2, a2, 32); // daddiu a2, a2, 32 + // nop // sll r0, r0, 0 + c->sqc2(vf8, -32, a0); // sqc2 vf8, -32(a0) + bc = ((s64)c->sgpr64(a1)) > 0; // bgtz a1, L5 + c->sqc2(vf9, -16, a0); // sqc2 vf9, -16(a0) + if (bc) {goto block_1;} // branch non-likely + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + c->gprs[v1].du64[0] = 0; // or v1, r0, r0 + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + c->ld(fp, 8, sp); // ld fp, 8(sp) + //jr ra // jr ra + c->daddiu(sp, sp, 16); // daddiu sp, sp, 16 + goto end_of_function; // return + + end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.ocean_wave_frames = intern_from_c("*ocean-wave-frames*").c(); + cache.ocean_work = intern_from_c("*ocean-work*").c(); + gLinkedFunctionTable.reg("ocean-interp-wave", execute, 256); +} + +} // namespace ocean_interp_wave +} // namespace Mips2C + + +//--------------------------MIPS2C--------------------- +#include "game/mips2c/mips2c_private.h" +#include "game/kernel/kscheme.h" +namespace Mips2C { +namespace ocean_generate_verts { +struct Cache { + void* ocean_vu0_work; // *ocean-vu0-work* + void* time_of_day_context; // *time-of-day-context* + void* ocean_vu0_block; // ocean-vu0-block + void* upload_vu0_program; // upload-vu0-program + void* vector; // vector*! + void* vu_lights_light_group; // vu-lights<-light-group! + void* ocean_generate_verts_vector; +} cache; + +void vcallms0(ExecutionContext* c) { + float Q = 0; + // nop | mulay.x ACC, vf12, vf02 0 + c->acc.vf.mula(Mask::x, c->vf_src(vf12).vf, c->vf_src(vf02).vf.y()); + // nop | mulax.z ACC, vf12, vf03 1 + c->acc.vf.mula(Mask::z, c->vf_src(vf12).vf, c->vf_src(vf03).vf.x()); + // nop | msubx.xz vf24, vf12, vf02 2 + // ASSERT(false); + c->acc.vf.msub(Mask::xz, c->vfs[vf24].vf, c->vf_src(vf12).vf, c->vf_src(vf02).vf.x()); + // nop | mulaz.x ACC, vf12, vf02 3 + c->acc.vf.mula(Mask::x, c->vf_src(vf12).vf, c->vf_src(vf02).vf.z()); + // nop | mulay.z ACC, vf12, vf03 4 + c->acc.vf.mula(Mask::z, c->vf_src(vf12).vf, c->vf_src(vf03).vf.y()); + // nop | msuby.xz vf25, vf12, vf02 5 + // ASSERT(false); + c->acc.vf.msub(Mask::xz, c->vfs[vf25].vf, c->vf_src(vf12).vf, c->vf_src(vf02).vf.y()); + // nop | mulaw.x ACC, vf12, vf02 6 + c->acc.vf.mula(Mask::x, c->vf_src(vf12).vf, c->vf_src(vf02).vf.w()); + // nop | mulaz.z ACC, vf12, vf03 7 + c->acc.vf.mula(Mask::z, c->vf_src(vf12).vf, c->vf_src(vf03).vf.z()); + // nop | msubz.xz vf26, vf12, vf02 8 + // ASSERT(false); + c->acc.vf.msub(Mask::xz, c->vfs[vf26].vf, c->vf_src(vf12).vf, c->vf_src(vf02).vf.z()); + // nop | mulax.x ACC, vf12, vf04 9 + c->acc.vf.mula(Mask::x, c->vf_src(vf12).vf, c->vf_src(vf04).vf.x()); + // nop | mulaw.z ACC, vf12, vf03 10 + c->acc.vf.mula(Mask::z, c->vf_src(vf12).vf, c->vf_src(vf03).vf.w()); + // nop | msubw.xz vf27, vf12, vf02 11 + // ASSERT(false); + c->acc.vf.msub(Mask::xz, c->vfs[vf27].vf, c->vf_src(vf12).vf, c->vf_src(vf02).vf.w()); + // nop | mul.xz vf28, vf24, vf24 12 + c->vfs[vf28].vf.mul(Mask::xz, c->vf_src(vf24).vf, c->vf_src(vf24).vf); + // nop | mul.xz vf29, vf25, vf25 13 + c->vfs[vf29].vf.mul(Mask::xz, c->vf_src(vf25).vf, c->vf_src(vf25).vf); + // nop | mul.xz vf30, vf26, vf26 14 + c->vfs[vf30].vf.mul(Mask::xz, c->vf_src(vf26).vf, c->vf_src(vf26).vf); + // nop | mul.xz vf31, vf27, vf27 15 + c->vfs[vf31].vf.mul(Mask::xz, c->vf_src(vf27).vf, c->vf_src(vf27).vf); + // nop | subx.y vf24, vf01, vf28 16 + c->vfs[vf24].vf.sub(Mask::y, c->vf_src(vf01).vf, c->vf_src(vf28).vf.x()); + // nop | subx.y vf25, vf01, vf29 17 + c->vfs[vf25].vf.sub(Mask::y, c->vf_src(vf01).vf, c->vf_src(vf29).vf.x()); + // nop | subx.y vf26, vf01, vf30 18 + c->vfs[vf26].vf.sub(Mask::y, c->vf_src(vf01).vf, c->vf_src(vf30).vf.x()); + // nop | subx.y vf27, vf01, vf31 19 + c->vfs[vf27].vf.sub(Mask::y, c->vf_src(vf01).vf, c->vf_src(vf31).vf.x()); + // nop | subz.y vf24, vf24, vf28 20 + c->vfs[vf24].vf.sub(Mask::y, c->vf_src(vf24).vf, c->vf_src(vf28).vf.z()); + // nop | subz.y vf25, vf25, vf29 21 + c->vfs[vf25].vf.sub(Mask::y, c->vf_src(vf25).vf, c->vf_src(vf29).vf.z()); + // nop | subz.y vf26, vf26, vf30 22 + c->vfs[vf26].vf.sub(Mask::y, c->vf_src(vf26).vf, c->vf_src(vf30).vf.z()); + // nop | subz.y vf27, vf27, vf31 23 + c->vfs[vf27].vf.sub(Mask::y, c->vf_src(vf27).vf, c->vf_src(vf31).vf.z()); + // nop | mulx.w vf24, vf01, vf02 24 + c->vfs[vf24].vf.mul(Mask::w, c->vf_src(vf01).vf, c->vf_src(vf02).vf.x()); + // nop | muly.w vf25, vf01, vf02 25 + c->vfs[vf25].vf.mul(Mask::w, c->vf_src(vf01).vf, c->vf_src(vf02).vf.y()); + // nop | mulz.w vf26, vf01, vf02 26 + c->vfs[vf26].vf.mul(Mask::w, c->vf_src(vf01).vf, c->vf_src(vf02).vf.z()); + // nop | mulw.w vf27, vf01, vf02 27 + c->vfs[vf27].vf.mul(Mask::w, c->vf_src(vf01).vf, c->vf_src(vf02).vf.w()); + // nop | mulax.xyzw ACC, vf05, vf24 28 + c->acc.vf.mula(Mask::xyzw, c->vf_src(vf05).vf, c->vf_src(vf24).vf.x()); + // nop | madday.xyzw ACC, vf06, vf24 29 + c->acc.vf.madda(Mask::xyzw, c->vfs[vf06].vf, c->vfs[vf24].vf.y()); + // nop | maddz.xyz vf16, vf07, vf24 30 + c->acc.vf.madd(Mask::xyz, c->vfs[vf16].vf, c->vf_src(vf07).vf, c->vf_src(vf24).vf.z()); + // nop | subw.z vf24, vf24, vf00 31 + c->vfs[vf24].vf.sub(Mask::z, c->vf_src(vf24).vf, c->vf_src(vf00).vf.w()); + // nop | mulax.xyzw ACC, vf05, vf25 32 + c->acc.vf.mula(Mask::xyzw, c->vf_src(vf05).vf, c->vf_src(vf25).vf.x()); + // nop | madday.xyzw ACC, vf06, vf25 33 + c->acc.vf.madda(Mask::xyzw, c->vfs[vf06].vf, c->vfs[vf25].vf.y()); + // nop | maddz.xyz vf17, vf07, vf25 34 + c->acc.vf.madd(Mask::xyz, c->vfs[vf17].vf, c->vf_src(vf07).vf, c->vf_src(vf25).vf.z()); + // div Q, vf00.w, vf24.z | subw.z vf25, vf25, vf00 35 + c->vfs[vf25].vf.sub(Mask::z, c->vf_src(vf25).vf, c->vf_src(vf00).vf.w()); Q = 1.f / c->vf_src(vf24).vf.z(); + // nop | mulax.xyzw ACC, vf05, vf26 36 + c->acc.vf.mula(Mask::xyzw, c->vf_src(vf05).vf, c->vf_src(vf26).vf.x()); + // nop | madday.xyzw ACC, vf06, vf26 37 + c->acc.vf.madda(Mask::xyzw, c->vfs[vf06].vf, c->vfs[vf26].vf.y()); + // nop | maddz.xyz vf18, vf07, vf26 38 + c->acc.vf.madd(Mask::xyz, c->vfs[vf18].vf, c->vf_src(vf07).vf, c->vf_src(vf26).vf.z()); + // nop | subw.z vf26, vf26, vf00 39 + c->vfs[vf26].vf.sub(Mask::z, c->vf_src(vf26).vf, c->vf_src(vf00).vf.w()); + // nop | mulax.xyzw ACC, vf05, vf27 40 + c->acc.vf.mula(Mask::xyzw, c->vf_src(vf05).vf, c->vf_src(vf27).vf.x()); + // nop | madday.xyzw ACC, vf06, vf27 41 + c->acc.vf.madda(Mask::xyzw, c->vfs[vf06].vf, c->vfs[vf27].vf.y()); + // nop | mul.w vf20, vf00, Q 42 + c->vfs[vf20].vf.mul(Mask::w, c->vf_src(vf00).vf, c->Q); + // div Q, vf00.w, vf25.z | maddz.xyz vf19, vf07, vf27 43 + c->acc.vf.madd(Mask::xyz, c->vfs[vf19].vf, c->vf_src(vf07).vf, c->vf_src(vf27).vf.z()); Q = 1.f / c->vf_src(vf25).vf.z(); + // nop | subw.z vf27, vf27, vf00 44 + c->vfs[vf27].vf.sub(Mask::z, c->vf_src(vf27).vf, c->vf_src(vf00).vf.w()); + // nop | maxx.xyz vf16, vf16, vf00 45 + c->vfs[vf16].vf.max(Mask::xyz, c->vf_src(vf16).vf, c->vf_src(vf00).vf.x()); + // nop | maxx.xyz vf17, vf17, vf00 46 + c->vfs[vf17].vf.max(Mask::xyz, c->vf_src(vf17).vf, c->vf_src(vf00).vf.x()); + // nop | maxx.xyz vf18, vf18, vf00 47 + c->vfs[vf18].vf.max(Mask::xyz, c->vf_src(vf18).vf, c->vf_src(vf00).vf.x()); + // nop | maxx.xyz vf19, vf19, vf00 48 + c->vfs[vf19].vf.max(Mask::xyz, c->vf_src(vf19).vf, c->vf_src(vf00).vf.x()); + // nop | mul.w vf21, vf00, Q 49 + c->vfs[vf21].vf.mul(Mask::w, c->vf_src(vf00).vf, c->Q); + // div Q, vf00.w, vf26.z | mula.xyzw ACC, vf01, vf11 50 + c->acc.vf.mula(Mask::xyzw, c->vf_src(vf01).vf, c->vf_src(vf11).vf); Q = 1.f / c->vf_src(vf26).vf.z(); + // nop | maddax.xyz ACC, vf08, vf16 51 + c->acc.vf.madda(Mask::xyz, c->vfs[vf08].vf, c->vfs[vf16].vf.x()); + // nop | madday.xyz ACC, vf09, vf16 52 + c->acc.vf.madda(Mask::xyz, c->vfs[vf09].vf, c->vfs[vf16].vf.y()); + // nop | maddz.xyz vf20, vf10, vf16 53 + c->acc.vf.madd(Mask::xyz, c->vfs[vf20].vf, c->vf_src(vf10).vf, c->vf_src(vf16).vf.z()); + // nop | mula.xyzw ACC, vf01, vf11 54 + // vu.acc.mula(Mask::xyzw, vu.vf01, vu.vf11); + c->acc.vf.mula(Mask::xyzw, c->vf_src(vf01).vf, c->vf_src(vf11).vf); + // nop | maddax.xyz ACC, vf08, vf17 55 + c->acc.vf.madda(Mask::xyz, c->vfs[vf08].vf, c->vfs[vf17].vf.x()); + // nop | madday.xyz ACC, vf09, vf17 56 + c->acc.vf.madda(Mask::xyz, c->vfs[vf09].vf, c->vfs[vf17].vf.y()); + // nop | mul.w vf22, vf00, Q 57 + c->vfs[vf22].vf.mul(Mask::w, c->vf_src(vf00).vf, c->Q); + // nop | maddz.xyz vf21, vf10, vf17 58 + c->acc.vf.madd(Mask::xyz, c->vfs[vf21].vf, c->vf_src(vf10).vf, c->vf_src(vf17).vf.z()); + // div Q, vf00.w, vf27.z | mula.xyzw ACC, vf01, vf11 59 + // vu.acc.mula(Mask::xyzw, vu.vf01, vu.vf11); + c->acc.vf.mula(Mask::xyzw, c->vf_src(vf01).vf, c->vf_src(vf11).vf); + Q = 1.f / c->vf_src(vf27).vf.z(); + // nop | maddax.xyz ACC, vf08, vf18 60 + c->acc.vf.madda(Mask::xyz, c->vfs[vf08].vf, c->vfs[vf18].vf.x()); + // nop | madday.xyz ACC, vf09, vf18 61 + c->acc.vf.madda(Mask::xyz, c->vfs[vf09].vf, c->vfs[vf18].vf.y()); + // nop | maddz.xyz vf22, vf10, vf18 62 + c->acc.vf.madd(Mask::xyz, c->vfs[vf22].vf, c->vf_src(vf10).vf, c->vf_src(vf18).vf.z()); + // nop | mula.xyzw ACC, vf01, vf11 63 + // vu.acc.mula(Mask::xyzw, vu.vf01, vu.vf11); + c->acc.vf.mula(Mask::xyzw, c->vf_src(vf01).vf, c->vf_src(vf11).vf); + // nop | maddax.xyz ACC, vf08, vf19 64 + c->acc.vf.madda(Mask::xyz, c->vfs[vf08].vf, c->vfs[vf19].vf.x()); + // nop | madday.xyz ACC, vf09, vf19 65 + c->acc.vf.madda(Mask::xyz, c->vfs[vf09].vf, c->vfs[vf19].vf.y()); + // nop | maddz.xyz vf23, vf10, vf19 66 + c->acc.vf.madd(Mask::xyz, c->vfs[vf23].vf, c->vf_src(vf10).vf, c->vf_src(vf19).vf.z()); + // nop | mul.w vf23, vf00, Q 67 + c->vfs[vf23].vf.mul(Mask::w, c->vf_src(vf00).vf, c->Q); + // nop | miniy.xyz vf20, vf20, vf12 68 + c->vfs[vf20].vf.mini(Mask::xyz, c->vf_src(vf20).vf, c->vf_src(vf12).vf.y()); + // nop | miniy.xyz vf21, vf21, vf12 69 + c->vfs[vf21].vf.mini(Mask::xyz, c->vf_src(vf21).vf, c->vf_src(vf12).vf.y()); + // nop | miniy.xyz vf22, vf22, vf12 :e 70 + c->vfs[vf22].vf.mini(Mask::xyz, c->vf_src(vf22).vf, c->vf_src(vf12).vf.y()); + // nop | miniy.xyz vf23, vf23, vf12 71 + c->vfs[vf23].vf.mini(Mask::xyz, c->vf_src(vf23).vf, c->vf_src(vf12).vf.y()); +} + +u64 execute(void* ctxt) { + auto* c = (ExecutionContext*)ctxt; + bool bc = false; + u32 call_addr = 0; + c->daddiu(sp, sp, -64); // daddiu sp, sp, -64 + c->sd(ra, 0, sp); // sd ra, 0(sp) + c->sd(fp, 8, sp); // sd fp, 8(sp) + c->mov64(fp, t9); // or fp, t9, r0 + c->sq(s4, 16, sp); // sq s4, 16(sp) + c->sq(s5, 32, sp); // sq s5, 32(sp) + c->sq(gp, 48, sp); // sq gp, 48(sp) + c->mov64(s5, a0); // or s5, a0, r0 + c->mov64(gp, a1); // or gp, a1, r0 + c->load_symbol(t9, cache.upload_vu0_program); // lw t9, upload-vu0-program(s7) + c->load_symbol(a0, cache.ocean_vu0_block); // lw a0, ocean-vu0-block(s7) + c->load_symbol(v1, cache.ocean_vu0_work); // lw v1, *ocean-vu0-work*(s7) + c->daddiu(a1, v1, 160); // daddiu a1, v1, 160 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->load_symbol(t9, cache.vu_lights_light_group); // lw t9, vu-lights<-light-group!(s7) + c->load_symbol(v1, cache.ocean_vu0_work); // lw v1, *ocean-vu0-work*(s7) + c->daddiu(a0, v1, 48); // daddiu a0, v1, 48 + c->load_symbol(v1, cache.time_of_day_context); // lw v1, *time-of-day-context*(s7) + c->daddiu(a1, v1, 156); // daddiu a1, v1, 156 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + // daddiu s4, fp, L7 // daddiu s4, fp, L7 TODO + c->load_symbol(s4, cache.ocean_generate_verts_vector); // HACK + c->load_symbol(t9, cache.vector); // lw t9, vector*!(s7) + c->load_symbol(v1, cache.ocean_vu0_work); // lw v1, *ocean-vu0-work*(s7) + c->daddiu(a0, v1, 96); // daddiu a0, v1, 96 + c->load_symbol(v1, cache.ocean_vu0_work); // lw v1, *ocean-vu0-work*(s7) + c->daddiu(a1, v1, 96); // daddiu a1, v1, 96 + c->mov64(a2, s4); // or a2, s4, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->load_symbol(t9, cache.vector); // lw t9, vector*!(s7) + c->load_symbol(v1, cache.ocean_vu0_work); // lw v1, *ocean-vu0-work*(s7) + c->daddiu(a0, v1, 112); // daddiu a0, v1, 112 + c->load_symbol(v1, cache.ocean_vu0_work); // lw v1, *ocean-vu0-work*(s7) + c->daddiu(a1, v1, 112); // daddiu a1, v1, 112 + c->mov64(a2, s4); // or a2, s4, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->load_symbol(t9, cache.vector); // lw t9, vector*!(s7) + c->load_symbol(v1, cache.ocean_vu0_work); // lw v1, *ocean-vu0-work*(s7) + c->daddiu(a0, v1, 128); // daddiu a0, v1, 128 + c->load_symbol(v1, cache.ocean_vu0_work); // lw v1, *ocean-vu0-work*(s7) + c->daddiu(a1, v1, 128); // daddiu a1, v1, 128 + c->mov64(a2, s4); // or a2, s4, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->load_symbol(t9, cache.vector); // lw t9, vector*!(s7) + c->load_symbol(v1, cache.ocean_vu0_work); // lw v1, *ocean-vu0-work*(s7) + c->daddiu(a0, v1, 144); // daddiu a0, v1, 144 + c->load_symbol(v1, cache.ocean_vu0_work); // lw v1, *ocean-vu0-work*(s7) + c->daddiu(a1, v1, 144); // daddiu a1, v1, 144 + c->mov64(a2, s4); // or a2, s4, r0 + call_addr = c->gprs[t9].du32[0]; // function call: + c->sll(v0, ra, 0); // sll v0, ra, 0 + c->jalr(call_addr); // jalr ra, t9 + c->mov64(v1, v0); // or v1, v0, r0 + c->load_symbol(v1, cache.ocean_vu0_work); // lw v1, *ocean-vu0-work*(s7) + c->vmax_bc(DEST::xyzw, BC::w, vf1, vf0, vf0); // vmaxw.xyzw vf1, vf0, vf0 + c->lqc2(vf12, 0, v1); // lqc2 vf12, 0(v1) + c->lqc2(vf5, 48, v1); // lqc2 vf5, 48(v1) + c->lqc2(vf6, 64, v1); // lqc2 vf6, 64(v1) + c->lqc2(vf7, 80, v1); // lqc2 vf7, 80(v1) + c->lqc2(vf8, 96, v1); // lqc2 vf8, 96(v1) + c->lqc2(vf9, 112, v1); // lqc2 vf9, 112(v1) + c->lqc2(vf10, 128, v1); // lqc2 vf10, 128(v1) + c->lqc2(vf11, 144, v1); // lqc2 vf11, 144(v1) + c->addiu(v1, r0, 31); // addiu v1, r0, 31 + c->mov64(a0, gp); // or a0, gp, r0 + c->daddiu(a1, gp, 128); // daddiu a1, gp, 128 + + block_1: + c->lqc2(vf2, 0, gp); // lqc2 vf2, 0(gp) + c->addiu(t2, r0, 6); // addiu t2, r0, 6 + c->lqc2(vf3, 16, gp); // lqc2 vf3, 16(gp) + c->daddiu(t5, gp, 16); // daddiu t5, gp, 16 + c->lqc2(vf4, 0, a1); // lqc2 vf4, 0(a1) + c->daddiu(a1, a1, 16); // daddiu a1, a1, 16 + // Unknown instr: vcallms 0 + vcallms0(c); + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t1, vf20); // qmfc2.i t1, vf20 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t0, vf21); // qmfc2.i t0, vf21 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a3, vf22); // qmfc2.i a3, vf22 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a2, vf23); // qmfc2.i a2, vf23 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t6, vf24); // qmfc2.i t6, vf24 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t7, vf25); // qmfc2.i t7, vf25 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t3, vf26); // qmfc2.i t3, vf26 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t4, vf27); // qmfc2.i t4, vf27 + // nop // sll r0, r0, 0 + c->lqc2(vf2, 0, t5); // lqc2 vf2, 0(t5) + // nop // sll r0, r0, 0 + c->lqc2(vf3, 16, t5); // lqc2 vf3, 16(t5) + c->daddiu(gp, t5, 16); // daddiu gp, t5, 16 + c->lqc2(vf4, 0, a1); // lqc2 vf4, 0(a1) + c->daddiu(a1, a1, 16); // daddiu a1, a1, 16 + + block_2: + // Unknown instr: vcallms 0 + vcallms0(c); + // nop // sll r0, r0, 0 + c->pextlw(t5, t7, t6); // pextlw t5, t7, t6 + // nop // sll r0, r0, 0 + c->pextuw(t6, t7, t6); // pextuw t6, t7, t6 + // nop // sll r0, r0, 0 + c->pextlw(t7, t4, t3); // pextlw t7, t4, t3 + // nop // sll r0, r0, 0 + c->pextuw(t4, t4, t3); // pextuw t4, t4, t3 + // nop // sll r0, r0, 0 + c->pcpyld(t3, t7, t5); // pcpyld t3, t7, t5 + c->sq(t1, 0, s5); // sq t1, 0(s5) + c->pcpyud(t1, t5, t7); // pcpyud t1, t5, t7 + c->sq(t0, 32, s5); // sq t0, 32(s5) + c->pcpyld(t0, t4, t6); // pcpyld t0, t4, t6 + c->sq(a3, 64, s5); // sq a3, 64(s5) + c->pcpyud(a3, t6, t4); // pcpyud a3, t6, t4 + c->sq(a2, 96, s5); // sq a2, 96(s5) + c->sq(t3, 16, s5); // sq t3, 16(s5) + // nop // sll r0, r0, 0 + c->sq(t1, 48, s5); // sq t1, 48(s5) + // nop // sll r0, r0, 0 + c->sq(t0, 80, s5); // sq t0, 80(s5) + // nop // sll r0, r0, 0 + c->sq(a3, 112, s5); // sq a3, 112(s5) + c->daddiu(s5, s5, 128); // daddiu s5, s5, 128 + c->mov128_gpr_vf(t1, vf20); // qmfc2.i t1, vf20 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t0, vf21); // qmfc2.i t0, vf21 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a3, vf22); // qmfc2.i a3, vf22 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a2, vf23); // qmfc2.i a2, vf23 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t6, vf24); // qmfc2.i t6, vf24 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t7, vf25); // qmfc2.i t7, vf25 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t3, vf26); // qmfc2.i t3, vf26 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t4, vf27); // qmfc2.i t4, vf27 + c->daddiu(t2, t2, -1); // daddiu t2, t2, -1 + c->lqc2(vf2, 0, gp); // lqc2 vf2, 0(gp) + c->daddiu(a1, a1, 16); // daddiu a1, a1, 16 + c->lqc2(vf3, 16, gp); // lqc2 vf3, 16(gp) + c->daddiu(gp, gp, 16); // daddiu gp, gp, 16 + bc = ((s64)c->sgpr64(t2)) > 0; // bgtz t2, L3 + c->lqc2(vf4, -16, a1); // lqc2 vf4, -16(a1) + if (bc) {goto block_2;} // branch non-likely + + c->lqc2(vf3, -128, gp); // lqc2 vf3, -128(gp) + // nop // sll r0, r0, 0 + // Unknown instr: vcallms 0 + vcallms0(c); + // nop // sll r0, r0, 0 + c->pextlw(t2, t7, t6); // pextlw t2, t7, t6 + // nop // sll r0, r0, 0 + c->pextuw(t5, t7, t6); // pextuw t5, t7, t6 + // nop // sll r0, r0, 0 + c->pextlw(t6, t4, t3); // pextlw t6, t4, t3 + // nop // sll r0, r0, 0 + c->pextuw(t4, t4, t3); // pextuw t4, t4, t3 + // nop // sll r0, r0, 0 + c->pcpyld(t3, t6, t2); // pcpyld t3, t6, t2 + c->sq(t1, 0, s5); // sq t1, 0(s5) + c->pcpyud(t1, t2, t6); // pcpyud t1, t2, t6 + c->sq(t0, 32, s5); // sq t0, 32(s5) + c->pcpyld(t0, t4, t5); // pcpyld t0, t4, t5 + c->sq(a3, 64, s5); // sq a3, 64(s5) + c->pcpyud(a3, t5, t4); // pcpyud a3, t5, t4 + c->sq(a2, 96, s5); // sq a2, 96(s5) + c->sq(t3, 16, s5); // sq t3, 16(s5) + // nop // sll r0, r0, 0 + c->sq(t1, 48, s5); // sq t1, 48(s5) + // nop // sll r0, r0, 0 + c->sq(t0, 80, s5); // sq t0, 80(s5) + // nop // sll r0, r0, 0 + c->sq(a3, 112, s5); // sq a3, 112(s5) + c->daddiu(a2, s5, 128); // daddiu a2, s5, 128 + c->mov128_gpr_vf(t2, vf20); // qmfc2.i t2, vf20 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t1, vf21); // qmfc2.i t1, vf21 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t0, vf22); // qmfc2.i t0, vf22 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(a3, vf23); // qmfc2.i a3, vf23 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t4, vf24); // qmfc2.i t4, vf24 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t7, vf25); // qmfc2.i t7, vf25 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t5, vf26); // qmfc2.i t5, vf26 + // nop // sll r0, r0, 0 + c->mov128_gpr_vf(t6, vf27); // qmfc2.i t6, vf27 + c->daddiu(v1, v1, -1); // daddiu v1, v1, -1 + c->pextlw(t3, t7, t4); // pextlw t3, t7, t4 + // nop // sll r0, r0, 0 + c->pextuw(t4, t7, t4); // pextuw t4, t7, t4 + // nop // sll r0, r0, 0 + c->pextlw(t7, t6, t5); // pextlw t7, t6, t5 + // nop // sll r0, r0, 0 + c->pextuw(t6, t6, t5); // pextuw t6, t6, t5 + // nop // sll r0, r0, 0 + c->pcpyld(t5, t7, t3); // pcpyld t5, t7, t3 + c->sq(t2, 0, a2); // sq t2, 0(a2) + c->pcpyud(t2, t3, t7); // pcpyud t2, t3, t7 + c->sq(t1, 32, a2); // sq t1, 32(a2) + c->pcpyld(t1, t6, t4); // pcpyld t1, t6, t4 + c->sq(t0, 64, a2); // sq t0, 64(a2) + c->pcpyud(t0, t4, t6); // pcpyud t0, t4, t6 + c->sq(a3, 96, a2); // sq a3, 96(a2) + c->sq(t5, 16, a2); // sq t5, 16(a2) + // nop // sll r0, r0, 0 + c->sq(t2, 48, a2); // sq t2, 48(a2) + // nop // sll r0, r0, 0 + c->sq(t1, 80, a2); // sq t1, 80(a2) + // nop // sll r0, r0, 0 + c->sq(t0, 112, a2); // sq t0, 112(a2) + c->daddiu(s5, a2, 128); // daddiu s5, a2, 128 + bc = ((s64)c->sgpr64(v1)) > 0; // bgtz v1, L2 + // nop // sll r0, r0, 0 + if (bc) {goto block_1;} // branch non-likely + + bc = c->sgpr64(v1) == 0; // beq v1, r0, L2 + c->mov64(a1, a0); // or a1, a0, r0 + if (bc) {goto block_1;} // branch non-likely + + c->gprs[v0].du64[0] = 0; // or v0, r0, r0 + c->ld(ra, 0, sp); // ld ra, 0(sp) + c->ld(fp, 8, sp); // ld fp, 8(sp) + c->lq(gp, 48, sp); // lq gp, 48(sp) + c->lq(s5, 32, sp); // lq s5, 32(sp) + c->lq(s4, 16, sp); // lq s4, 16(sp) + //jr ra // jr ra + c->daddiu(sp, sp, 64); // daddiu sp, sp, 64 + goto end_of_function; // return + + // nop // sll r0, r0, 0 + // nop // sll r0, r0, 0 + end_of_function: + return c->gprs[v0].du64[0]; +} + +void link() { + cache.ocean_vu0_work = intern_from_c("*ocean-vu0-work*").c(); + cache.time_of_day_context = intern_from_c("*time-of-day-context*").c(); + cache.ocean_vu0_block = intern_from_c("ocean-vu0-block").c(); + cache.upload_vu0_program = intern_from_c("upload-vu0-program").c(); + cache.vector = intern_from_c("vector*!").c(); + cache.vu_lights_light_group = intern_from_c("vu-lights<-light-group!").c(); + cache.ocean_generate_verts_vector = intern_from_c("*ocean-generate-verts-vector*").c(); + gLinkedFunctionTable.reg("ocean-generate-verts", execute, 128); +} + +} // namespace ocean_generate_verts +} // namespace Mips2C diff --git a/game/mips2c/mips2c_table.cpp b/game/mips2c/mips2c_table.cpp index dcc576595a..4f14491227 100644 --- a/game/mips2c/mips2c_table.cpp +++ b/game/mips2c/mips2c_table.cpp @@ -269,6 +269,12 @@ extern void link(); namespace draw_large_polygon_ocean { extern void link(); } +namespace ocean_interp_wave { +extern void link(); +} +namespace ocean_generate_verts { +extern void link(); +} LinkedFunctionTable gLinkedFunctionTable; Rng gRng; std::unordered_map> gMips2CLinkCallbacks = { @@ -314,8 +320,8 @@ std::unordered_map> gMips2CLinkCallbacks = {"ripple", {ripple_execute_init::link, ripple_create_wave_table::link, ripple_apply_wave_table::link, ripple_matrix_scale::link}}, - {"ocean", - {init_ocean_far_regs::link, render_ocean_quad::link, draw_large_polygon_ocean::link}}}; + {"ocean", {init_ocean_far_regs::link, render_ocean_quad::link, draw_large_polygon_ocean::link}}, + {"ocean-vu0", {ocean_interp_wave::link, ocean_generate_verts::link}}}; void LinkedFunctionTable::reg(const std::string& name, u64 (*exec)(void*), u32 stack_size) { const auto& it = m_executes.insert({name, {exec, Ptr()}}); diff --git a/goal_src/engine/gfx/ocean/ocean-h.gc b/goal_src/engine/gfx/ocean/ocean-h.gc index d25e934a8f..e323484cfb 100644 --- a/goal_src/engine/gfx/ocean/ocean-h.gc +++ b/goal_src/engine/gfx/ocean/ocean-h.gc @@ -233,7 +233,7 @@ (define *ocean-mid-off* #f) (define *ocean-near-off* #f) (define *ocean-heights* (the-as ocean-wave-info #f)) -(define *ocean-verts* (the-as (pointer vector) #f)) +(define *ocean-verts* (the-as (inline-array vector) #f)) (deftype ocean-vu0-work (structure) ((scales vector :inline :offset-assert 0) @@ -419,3 +419,5 @@ ) (define-extern *ocean-trans-corner-table* (inline-array vector4w-2)) +(define-extern ocean-interp-wave (function ocean-wave-info uint none)) +(define-extern ocean-generate-verts (function (inline-array vector) ocean-wave-info none)) \ No newline at end of file diff --git a/goal_src/engine/gfx/ocean/ocean-texture.gc b/goal_src/engine/gfx/ocean/ocean-texture.gc index 88357ca0dd..b700671ea7 100644 --- a/goal_src/engine/gfx/ocean/ocean-texture.gc +++ b/goal_src/engine/gfx/ocean/ocean-texture.gc @@ -5,3 +5,598 @@ ;; name in dgo: ocean-texture ;; dgos: GAME, ENGINE + +;; definition for symbol *ocean-texture-work*, type ocean-texture-work +(define *ocean-texture-work* (new 'static 'ocean-texture-work + :sprite-tmpl + (new 'static 'dma-gif-packet + :dma-vif + (new 'static 'dma-packet + :dma + (new 'static 'dma-tag :qwc #x6 :id (dma-tag-id cnt)) + :vif1 + (new 'static 'vif-tag :imm #x6 :cmd (vif-cmd direct) :msk #x1) + ) + :gif + (new 'static 'array uint64 2 #x508b400000008001 #x53531) + ) + :sprite-tmpl2 + (new 'static 'dma-gif-packet + :dma-vif + (new 'static 'dma-packet + :dma + (new 'static 'dma-tag :qwc #x4 :id (dma-tag-id cnt)) + :vif1 + (new 'static 'vif-tag :imm #x4 :cmd (vif-cmd direct) :msk #x1) + ) + :gif + (new 'static 'array uint64 2 #x3023400000008001 #x551) + ) + :adgif-tmpl + (new 'static 'dma-gif-packet + :dma-vif + (new 'static 'dma-packet + :dma + (new 'static 'dma-tag :qwc #x6 :id (dma-tag-id cnt)) + :vif1 + (new 'static 'vif-tag :imm #x6 :cmd (vif-cmd direct) :msk #x1) + ) + :gif + (new 'static 'array uint64 2 #x1000000000008005 #xe) + ) + ) + ) + +;; definition for symbol ocean-texture-vu1-block, type vu-function +(define ocean-texture-vu1-block (new 'static 'vu-function :length #x92 :qlength 73)) + +;; definition for function ocean-texture-setup-constants +;; INFO: Return type mismatch int vs none. +(defun ocean-texture-setup-constants ((arg0 ocean-texture-constants)) + (set! (-> arg0 giftag dword 0) (make-u128 0 (the-as uint #x300e400000008042))) + (set! (-> arg0 giftag dword 1) (the-as uint 1298)) + (set-vector! (-> arg0 buffers) 384 583 384 583) + (set-vector! (-> arg0 dests) 782 881 782 881) + (set-vector! (-> arg0 start) 0.0 0.0 1048575.94 0.0) + (set-vector! (-> arg0 offsets) 4.0 8.0 12.0 16.0) + (set-vector! (-> arg0 constants) 0.5 0.5 0.0 0.0) + (set! (-> arg0 cam-nrm x) (- (-> *math-camera* inv-camera-rot vector 2 x))) + (set! (-> arg0 cam-nrm y) (- (-> *math-camera* inv-camera-rot vector 2 y))) + (set! (-> arg0 cam-nrm z) (- (-> *math-camera* inv-camera-rot vector 2 z))) + (set! (-> arg0 cam-nrm w) 0.0) + 0 + (none) + ) + +;; definition for function ocean-texture-add-constants +(defun ocean-texture-add-constants ((arg0 dma-buffer)) + (let* ((a1-0 7) + (v1-0 arg0) + (a0-1 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a0-1) dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc a1-0)) + (set! (-> (the-as dma-packet a0-1) vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> (the-as dma-packet a0-1) vif1) + (new 'static 'vif-tag :imm #x3d9 :cmd (vif-cmd unpack-v4-32) :num a1-0) + ) + (set! (-> v1-0 base) (&+ (the-as pointer a0-1) 16)) + ) + (ocean-texture-setup-constants (the-as ocean-texture-constants (-> arg0 base))) + (let ((v0-1 (&+ (-> arg0 base) 112))) + (set! (-> arg0 base) v0-1) + v0-1 + ) + ) + +;; definition for function ocean-texture-add-envmap +;; Used lq/sq +(defun ocean-texture-add-envmap ((arg0 dma-buffer)) + (let ((v1-0 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-0) 0) (-> *ocean-texture-work* adgif-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-0) 1) (-> *ocean-texture-work* adgif-tmpl quad 1)) + (let ((s4-0 (&+ v1-0 32))) + (adgif-shader<-texture-simple! + (the-as adgif-shader s4-0) + (lookup-texture-by-id (new 'static 'texture-id :index #x1 :page #x100)) + ) + ) + ) + (let ((v0-2 (&+ (-> arg0 base) 112))) + (set! (-> arg0 base) v0-2) + v0-2 + ) + ) + +;; definition for function ocean-texture-add-verts +(defun ocean-texture-add-verts ((arg0 dma-buffer) (arg1 (pointer vector))) + (let* ((v1-0 arg0) + (a0-1 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a0-1) dma) + (new 'static 'dma-tag :qwc #xc0 :id (dma-tag-id ref) :addr (the-as int arg1)) + ) + (set! (-> (the-as dma-packet a0-1) vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> (the-as dma-packet a0-1) vif1) + (new 'static 'vif-tag :imm #x8000 :num #xc0 :cmd (vif-cmd unpack-v4-32)) + ) + (let ((v0-0 (&+ (the-as pointer a0-1) 16))) + (set! (-> v1-0 base) v0-0) + v0-0 + ) + ) + ) + +;; definition for function ocean-texture-add-verts-last +(defun ocean-texture-add-verts-last ((arg0 dma-buffer) (arg1 (pointer vector)) (arg2 (pointer vector))) + (let* ((v1-0 arg0) + (a3-0 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a3-0) dma) + (new 'static 'dma-tag :qwc #x80 :id (dma-tag-id ref) :addr (the-as int arg1)) + ) + (set! (-> (the-as dma-packet a3-0) vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> (the-as dma-packet a3-0) vif1) + (new 'static 'vif-tag :imm #x8000 :num #x80 :cmd (vif-cmd unpack-v4-32)) + ) + (set! (-> v1-0 base) (&+ (the-as pointer a3-0) 16)) + ) + (let* ((v1-1 arg0) + (a0-1 (the-as object (-> v1-1 base))) + ) + (set! (-> (the-as dma-packet a0-1) dma) + (new 'static 'dma-tag :qwc #x40 :id (dma-tag-id ref) :addr (the-as int arg2)) + ) + (set! (-> (the-as dma-packet a0-1) vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> (the-as dma-packet a0-1) vif1) + (new 'static 'vif-tag :imm #x8080 :num #x40 :cmd (vif-cmd unpack-v4-32)) + ) + (let ((v0-0 (&+ (the-as pointer a0-1) 16))) + (set! (-> v1-1 base) v0-0) + v0-0 + ) + ) + ) + +;; definition for function ocean-texture-add-call-start +;; INFO: Return type mismatch pointer vs none. +(defun ocean-texture-add-call-start ((arg0 dma-buffer)) + (let* ((v1-0 arg0) + (a0-1 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a0-1) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-1) vif0) (new 'static 'vif-tag :cmd (vif-cmd mscalf) :msk #x1)) + (set! (-> (the-as dma-packet a0-1) vif1) (new 'static 'vif-tag :cmd (vif-cmd stmod))) + (set! (-> v1-0 base) (&+ (the-as pointer a0-1) 16)) + ) + (none) + ) + +;; definition for function ocean-texture-add-call-rest +;; INFO: Return type mismatch pointer vs none. +(defun ocean-texture-add-call-rest ((arg0 dma-buffer)) + (let* ((v1-0 arg0) + (a0-1 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a0-1) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-1) vif0) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd mscalf) :msk #x1)) + (set! (-> (the-as dma-packet a0-1) vif1) (new 'static 'vif-tag :cmd (vif-cmd stmod))) + (set! (-> v1-0 base) (&+ (the-as pointer a0-1) 16)) + ) + (none) + ) + +;; definition for function ocean-texture-add-call-done +;; INFO: Return type mismatch pointer vs none. +(defun ocean-texture-add-call-done ((arg0 dma-buffer)) + (let* ((v1-0 arg0) + (a0-1 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a0-1) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-1) vif0) (new 'static 'vif-tag :imm #x4 :cmd (vif-cmd mscalf) :msk #x1)) + (set! (-> (the-as dma-packet a0-1) vif1) (new 'static 'vif-tag :cmd (vif-cmd stmod))) + (set! (-> v1-0 base) (&+ (the-as pointer a0-1) 16)) + ) + (none) + ) + +;; definition for function draw-ocean-texture +;; INFO: Return type mismatch int vs none. +;; Used lq/sq +(defun draw-ocean-texture ((arg0 dma-buffer) (arg1 (pointer vector)) (arg2 symbol)) + (local-vars (sv-16 (pointer vector)) (sv-32 int) (sv-48 (pointer vector)) (sv-64 (pointer vector))) + (set! sv-64 arg1) + (let* ((s0-0 arg2) + (a1-1 *ocean-base-page*) + (s2-0 *ocean-base-block*) + (s1-0 (+ a1-1 8)) + (s4-0 (* s1-0 32)) + (s3-0 (+ a1-1 10)) + (s5-0 (* s3-0 32)) + ) + (set-display-gs-state arg0 a1-1 128 128 0 0) + (dma-buffer-add-vu-function arg0 ocean-texture-vu1-block 1) + (let* ((v1-0 arg0) + (a0-3 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a0-3) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-3) vif0) (new 'static 'vif-tag :cmd (vif-cmd base))) + (set! (-> (the-as dma-packet a0-3) vif1) (new 'static 'vif-tag :imm #xc0 :cmd (vif-cmd offset))) + (set! (-> v1-0 base) (&+ (the-as pointer a0-3) 16)) + ) + (ocean-texture-add-constants arg0) + (ocean-texture-add-envmap arg0) + (set! sv-16 sv-64) + (ocean-texture-add-verts arg0 sv-16) + (set! sv-48 (&-> sv-16 768)) + (ocean-texture-add-call-start arg0) + (set! sv-32 0) + (while (< sv-32 9) + (ocean-texture-add-verts arg0 sv-48) + (set! sv-48 (&-> sv-48 768)) + (ocean-texture-add-call-rest arg0) + (set! sv-32 (+ sv-32 1)) + ) + (ocean-texture-add-verts-last arg0 sv-48 sv-64) + (ocean-texture-add-call-rest arg0) + (ocean-texture-add-call-done arg0) + (when s0-0 + (set-display-gs-state arg0 s1-0 64 64 0 0) + (let* ((v1-13 arg0) + (a0-15 (the-as object (-> v1-13 base))) + ) + (set! (-> (the-as dma-packet a0-15) dma) (new 'static 'dma-tag :qwc #x7 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-15) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-15) vif1) (new 'static 'vif-tag :imm #x7 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-13 base) (&+ (the-as pointer a0-15) 16)) + ) + (let* ((v1-14 arg0) + (a0-17 (the-as object (-> v1-14 base))) + ) + (set! (-> (the-as gs-gif-tag a0-17) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x6)) + (set! (-> (the-as gs-gif-tag a0-17) regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + :regs5 (gif-reg-id a+d) + :regs6 (gif-reg-id a+d) + :regs7 (gif-reg-id a+d) + :regs8 (gif-reg-id a+d) + :regs9 (gif-reg-id a+d) + :regs10 (gif-reg-id a+d) + :regs11 (gif-reg-id a+d) + :regs12 (gif-reg-id a+d) + :regs13 (gif-reg-id a+d) + :regs14 (gif-reg-id a+d) + :regs15 (gif-reg-id a+d) + ) + ) + (set! (-> v1-14 base) (&+ (the-as pointer a0-17) 16)) + ) + (let* ((s1-1 arg0) + (s0-1 (-> s1-1 base)) + ) + (set! (-> (the-as (pointer gs-test) s0-1) 0) + (new 'static 'gs-test :ate #x1 :atst (gs-atest always) :zte #x1 :ztst (gs-ztest always)) + ) + (set! (-> (the-as (pointer gs-reg64) s0-1) 1) (gs-reg64 test-1)) + (set! (-> (the-as (pointer gs-alpha) s0-1) 2) (new 'static 'gs-alpha :b #x1 :d #x1)) + (set! (-> (the-as (pointer gs-reg64) s0-1) 3) (gs-reg64 alpha-1)) + (set! (-> (the-as (pointer gs-tex0) s0-1) 4) + (new 'static 'gs-tex0 :tbw #x2 :tcc #x1 :th (log2 128) :tw (log2 128) :tbp0 s2-0) + ) + (set! (-> (the-as (pointer gs-reg64) s0-1) 5) (gs-reg64 tex0-1)) + (set! (-> (the-as (pointer gs-tex1) s0-1) 6) (new 'static 'gs-tex1 :mmag #x1 :mmin #x1)) + (set! (-> (the-as (pointer gs-reg64) s0-1) 7) (gs-reg64 tex1-1)) + (set! (-> (the-as (pointer gs-clamp) s0-1) 8) (new 'static 'gs-clamp)) + (set! (-> (the-as (pointer gs-reg64) s0-1) 9) (gs-reg64 clamp-1)) + (set! (-> (the-as (pointer uint64) s0-1) 10) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) s0-1) 11) (gs-reg64 texflush)) + (set! (-> s1-1 base) (&+ s0-1 96)) + ) + (let ((v1-31 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-31) 0) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-31) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-31 32)) 128 128 128 64) + (set-vector! (the-as vector4w (&+ v1-31 48)) 0 0 0 0) + (set-vector! (the-as vector4w (&+ v1-31 64)) 0 0 #xffffff 0) + (set-vector! (the-as vector4w (&+ v1-31 80)) 2048 2048 0 0) + (set-vector! (the-as vector4w (&+ v1-31 96)) 1024 1024 #xffffff 0) + ) + (&+! (-> arg0 base) 112) + (set-display-gs-state arg0 s3-0 64 32 0 0) + (let* ((v1-35 arg0) + (a0-35 (the-as object (-> v1-35 base))) + ) + (set! (-> (the-as dma-packet a0-35) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-35) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-35) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-35 base) (&+ (the-as pointer a0-35) 16)) + ) + (let* ((v1-36 arg0) + (a0-37 (the-as object (-> v1-36 base))) + ) + (set! (-> (the-as gs-gif-tag a0-37) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + (set! (-> (the-as gs-gif-tag a0-37) regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + :regs5 (gif-reg-id a+d) + :regs6 (gif-reg-id a+d) + :regs7 (gif-reg-id a+d) + :regs8 (gif-reg-id a+d) + :regs9 (gif-reg-id a+d) + :regs10 (gif-reg-id a+d) + :regs11 (gif-reg-id a+d) + :regs12 (gif-reg-id a+d) + :regs13 (gif-reg-id a+d) + :regs14 (gif-reg-id a+d) + :regs15 (gif-reg-id a+d) + ) + ) + (set! (-> v1-36 base) (&+ (the-as pointer a0-37) 16)) + ) + (let* ((s3-1 arg0) + (s2-3 (-> s3-1 base)) + ) + (set! (-> (the-as (pointer gs-tex0) s2-3) 0) + (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 64) :tw (log2 64) :tbp0 s4-0) + ) + (set! (-> (the-as (pointer gs-reg64) s2-3) 1) (gs-reg64 tex0-1)) + (set! (-> (the-as (pointer uint64) s2-3) 2) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) s2-3) 3) (gs-reg64 texflush)) + (set! (-> s3-1 base) (&+ s2-3 32)) + ) + (let ((v1-46 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-46)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-46) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-46 32)) 128 128 128 0) + (set-vector! (the-as vector4w (&+ v1-46 48)) 0 0 0 0) + (set-vector! (the-as vector4w (&+ v1-46 64)) 0 0 #xffffff 0) + (set-vector! (the-as vector4w (&+ v1-46 80)) 1024 1024 0 0) + (set-vector! (the-as vector4w (&+ v1-46 96)) 512 512 #xffffff 0) + ) + (&+! (-> arg0 base) 112) + (let* ((v1-50 arg0) + (a0-54 (the-as object (-> v1-50 base))) + ) + (set! (-> (the-as dma-packet a0-54) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-54) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-54) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-50 base) (&+ (the-as pointer a0-54) 16)) + ) + (let* ((v1-51 arg0) + (a0-56 (the-as object (-> v1-51 base))) + ) + (set! (-> (the-as gs-gif-tag a0-56) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + (set! (-> (the-as gs-gif-tag a0-56) regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + :regs5 (gif-reg-id a+d) + :regs6 (gif-reg-id a+d) + :regs7 (gif-reg-id a+d) + :regs8 (gif-reg-id a+d) + :regs9 (gif-reg-id a+d) + :regs10 (gif-reg-id a+d) + :regs11 (gif-reg-id a+d) + :regs12 (gif-reg-id a+d) + :regs13 (gif-reg-id a+d) + :regs14 (gif-reg-id a+d) + :regs15 (gif-reg-id a+d) + ) + ) + (set! (-> v1-51 base) (&+ (the-as pointer a0-56) 16)) + ) + (let* ((s4-3 arg0) + (s3-2 (-> s4-3 base)) + ) + (set! (-> (the-as (pointer gs-tex0) s3-2) 0) + (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 32) :tw (log2 32) :tbp0 s5-0) + ) + (set! (-> (the-as (pointer gs-reg64) s3-2) 1) (gs-reg64 tex0-1)) + (set! (-> (the-as (pointer uint64) s3-2) 2) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) s3-2) 3) (gs-reg64 texflush)) + (set! (-> s4-3 base) (&+ s3-2 32)) + ) + (let ((v1-61 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-61)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-61) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-61 32)) 128 128 128 0) + (set-vector! (the-as vector4w (&+ v1-61 48)) 0 0 0 0) + (set-vector! (the-as vector4w (&+ v1-61 64)) 512 0 #xffffff 0) + (set-vector! (the-as vector4w (&+ v1-61 80)) 512 512 0 0) + (set-vector! (the-as vector4w (&+ v1-61 96)) 768 256 #xffffff 0) + ) + (&+! (-> arg0 base) 112) + (let* ((v1-65 arg0) + (a0-73 (the-as object (-> v1-65 base))) + ) + (set! (-> (the-as dma-packet a0-73) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-73) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-73) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-65 base) (&+ (the-as pointer a0-73) 16)) + ) + (let* ((v1-66 arg0) + (a0-75 (the-as object (-> v1-66 base))) + ) + (set! (-> (the-as gs-gif-tag a0-75) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + (set! (-> (the-as gs-gif-tag a0-75) regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + :regs5 (gif-reg-id a+d) + :regs6 (gif-reg-id a+d) + :regs7 (gif-reg-id a+d) + :regs8 (gif-reg-id a+d) + :regs9 (gif-reg-id a+d) + :regs10 (gif-reg-id a+d) + :regs11 (gif-reg-id a+d) + :regs12 (gif-reg-id a+d) + :regs13 (gif-reg-id a+d) + :regs14 (gif-reg-id a+d) + :regs15 (gif-reg-id a+d) + ) + ) + (set! (-> v1-66 base) (&+ (the-as pointer a0-75) 16)) + ) + (let* ((s4-4 arg0) + (s3-3 (-> s4-4 base)) + ) + (set! (-> (the-as (pointer gs-tex0) s3-3) 0) + (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 16) :tw (log2 16) :tbp0 (+ s5-0 16)) + ) + (set! (-> (the-as (pointer gs-reg64) s3-3) 1) (gs-reg64 tex0-1)) + (set! (-> (the-as (pointer uint64) s3-3) 2) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) s3-3) 3) (gs-reg64 texflush)) + (set! (-> s4-4 base) (&+ s3-3 32)) + ) + (let ((v1-76 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-76)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-76) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-76 32)) 128 128 128 0) + (set-vector! (the-as vector4w (&+ v1-76 48)) 0 0 0 0) + (set-vector! (the-as vector4w (&+ v1-76 64)) 768 0 #xffffff 0) + (set-vector! (the-as vector4w (&+ v1-76 80)) 256 256 0 0) + (set-vector! (the-as vector4w (&+ v1-76 96)) 896 128 #xffffff 0) + ) + (&+! (-> arg0 base) 112) + (let* ((v1-80 arg0) + (a0-93 (the-as object (-> v1-80 base))) + ) + (set! (-> (the-as dma-packet a0-93) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-93) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-93) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-80 base) (&+ (the-as pointer a0-93) 16)) + ) + (let* ((v1-81 arg0) + (a0-95 (the-as object (-> v1-81 base))) + ) + (set! (-> (the-as gs-gif-tag a0-95) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + (set! (-> (the-as gs-gif-tag a0-95) regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + :regs5 (gif-reg-id a+d) + :regs6 (gif-reg-id a+d) + :regs7 (gif-reg-id a+d) + :regs8 (gif-reg-id a+d) + :regs9 (gif-reg-id a+d) + :regs10 (gif-reg-id a+d) + :regs11 (gif-reg-id a+d) + :regs12 (gif-reg-id a+d) + :regs13 (gif-reg-id a+d) + :regs14 (gif-reg-id a+d) + :regs15 (gif-reg-id a+d) + ) + ) + (set! (-> v1-81 base) (&+ (the-as pointer a0-95) 16)) + ) + (let* ((s4-5 arg0) + (s3-4 (-> s4-5 base)) + ) + (set! (-> (the-as (pointer gs-tex0) s3-4) 0) + (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 8) :tw (log2 8) :tbp0 (+ s5-0 20)) + ) + (set! (-> (the-as (pointer gs-reg64) s3-4) 1) (gs-reg64 tex0-1)) + (set! (-> (the-as (pointer uint64) s3-4) 2) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) s3-4) 3) (gs-reg64 texflush)) + (set! (-> s4-5 base) (&+ s3-4 32)) + ) + (let ((v1-91 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-91)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-91) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-91 32)) 128 128 128 0) + (set-vector! (the-as vector4w (&+ v1-91 48)) 0 0 0 0) + (set-vector! (the-as vector4w (&+ v1-91 64)) 896 0 #xffffff 0) + (set-vector! (the-as vector4w (&+ v1-91 80)) 256 256 0 0) + (set-vector! (the-as vector4w (&+ v1-91 96)) 1024 128 #xffffff 0) + ) + (&+! (-> arg0 base) 112) + (let* ((v1-95 arg0) + (a0-113 (the-as object (-> v1-95 base))) + ) + (set! (-> (the-as dma-packet a0-113) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-113) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-113) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-95 base) (&+ (the-as pointer a0-113) 16)) + ) + (let* ((v1-96 arg0) + (a0-115 (the-as object (-> v1-96 base))) + ) + (set! (-> (the-as gs-gif-tag a0-115) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + (set! (-> (the-as gs-gif-tag a0-115) regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + :regs5 (gif-reg-id a+d) + :regs6 (gif-reg-id a+d) + :regs7 (gif-reg-id a+d) + :regs8 (gif-reg-id a+d) + :regs9 (gif-reg-id a+d) + :regs10 (gif-reg-id a+d) + :regs11 (gif-reg-id a+d) + :regs12 (gif-reg-id a+d) + :regs13 (gif-reg-id a+d) + :regs14 (gif-reg-id a+d) + :regs15 (gif-reg-id a+d) + ) + ) + (set! (-> v1-96 base) (&+ (the-as pointer a0-115) 16)) + ) + (let* ((s4-6 arg0) + (s3-5 (-> s4-6 base)) + ) + (set! (-> (the-as (pointer gs-tex0) s3-5) 0) + (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 4) :tw (log2 4) :tbp0 (+ s5-0 21)) + ) + (set! (-> (the-as (pointer gs-reg64) s3-5) 1) (gs-reg64 tex0-1)) + (set! (-> (the-as (pointer uint64) s3-5) 2) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) s3-5) 3) (gs-reg64 texflush)) + (set! (-> s4-6 base) (&+ s3-5 32)) + ) + (let ((v1-106 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-106)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-106) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-106 32)) 128 128 128 0) + (set-vector! (the-as vector4w (&+ v1-106 48)) 0 0 0 0) + (set-vector! (the-as vector4w (&+ v1-106 64)) 768 128 #xffffff 0) + (set-vector! (the-as vector4w (&+ v1-106 80)) 512 512 0 0) + (set-vector! (the-as vector4w (&+ v1-106 96)) 896 256 #xffffff 0) + ) + (&+! (-> arg0 base) 112) + (let* ((v1-110 arg0) + (a0-133 (the-as object (-> v1-110 base))) + ) + (set! (-> (the-as dma-packet a0-133) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-133) vif0) (new 'static 'vif-tag :cmd (vif-cmd flush) :msk #x1)) + (set! (-> (the-as dma-packet a0-133) vif1) (new 'static 'vif-tag)) + (set! (-> v1-110 base) (&+ (the-as pointer a0-133) 16)) + ) + ) + ) + (reset-display-gs-state *display* arg0 *oddeven*) + 0 + (none) + ) + + + + diff --git a/goal_src/engine/gfx/ocean/ocean.gc b/goal_src/engine/gfx/ocean/ocean.gc index 3f543b243a..a07f5e4e7f 100644 --- a/goal_src/engine/gfx/ocean/ocean.gc +++ b/goal_src/engine/gfx/ocean/ocean.gc @@ -600,17 +600,27 @@ ) ) +;; PC Port hack +(define *ocean-generate-verts-vector* (new 'global 'vector)) + +(set-vector! *ocean-generate-verts-vector* + (the-as float #x42800000) + (the-as float #x43000000) + (the-as float #x43000000) + (the-as float #x43000000) + ) + (defun draw-ocean () (set! *ocean-heights* #f) - (set! *ocean-verts* (the-as (pointer vector) #f)) - ; (let ((gp-0 (-> *display* frames (-> *display* on-screen) frame global-buf))) - ; (set! *ocean-heights* (the-as ocean-wave-info (-> gp-0 base))) - ; (ocean-interp-wave *ocean-heights* (the-as uint (-> *display* integral-frame-counter))) - ; (&+! (-> gp-0 base) 4096) - ; (set! *ocean-verts* (the-as (pointer vector) (-> gp-0 base))) - ; (ocean-generate-verts *ocean-verts* *ocean-heights*) - ; (&+! (-> gp-0 base) #x8000) - ; ) + (set! *ocean-verts* (the-as (inline-array vector) #f)) + (let ((gp-0 (-> *display* frames (-> *display* on-screen) frame global-buf))) + (set! *ocean-heights* (the-as ocean-wave-info (-> gp-0 base))) + (ocean-interp-wave *ocean-heights* (the-as uint (-> *display* integral-frame-counter))) + (&+! (-> gp-0 base) 4096) + (set! *ocean-verts* (the-as (inline-array vector) (-> gp-0 base))) + (ocean-generate-verts *ocean-verts* *ocean-heights*) + (&+! (-> gp-0 base) #x8000) + ) (when *ocean-map* (let* ((v1-12 (camera-pos)) (a0-6 *swamp-low-ocean-marker*) diff --git a/test/decompiler/reference/engine/gfx/ocean/ocean-h_REF.gc b/test/decompiler/reference/engine/gfx/ocean/ocean-h_REF.gc index a339139d0e..a55e9bd494 100644 --- a/test/decompiler/reference/engine/gfx/ocean/ocean-h_REF.gc +++ b/test/decompiler/reference/engine/gfx/ocean/ocean-h_REF.gc @@ -443,8 +443,8 @@ ;; definition for symbol *ocean-heights*, type ocean-wave-info (define *ocean-heights* (the-as ocean-wave-info #f)) -;; definition for symbol *ocean-verts*, type (pointer vector) -(define *ocean-verts* (the-as (pointer vector) #f)) +;; definition for symbol *ocean-verts*, type (inline-array vector) +(define *ocean-verts* (the-as (inline-array vector) #f)) ;; definition of type ocean-vu0-work (deftype ocean-vu0-work (structure) diff --git a/test/decompiler/reference/engine/gfx/ocean/ocean-texture_REF.gc b/test/decompiler/reference/engine/gfx/ocean/ocean-texture_REF.gc new file mode 100644 index 0000000000..0bd449b5f2 --- /dev/null +++ b/test/decompiler/reference/engine/gfx/ocean/ocean-texture_REF.gc @@ -0,0 +1,597 @@ +;;-*-Lisp-*- +(in-package goal) + +;; definition for symbol *ocean-texture-work*, type ocean-texture-work +(define *ocean-texture-work* (new 'static 'ocean-texture-work + :sprite-tmpl + (new 'static 'dma-gif-packet + :dma-vif + (new 'static 'dma-packet + :dma + (new 'static 'dma-tag :qwc #x6 :id (dma-tag-id cnt)) + :vif1 + (new 'static 'vif-tag :imm #x6 :cmd (vif-cmd direct) :msk #x1) + ) + :gif + (new 'static 'array uint64 2 #x508b400000008001 #x53531) + ) + :sprite-tmpl2 + (new 'static 'dma-gif-packet + :dma-vif + (new 'static 'dma-packet + :dma + (new 'static 'dma-tag :qwc #x4 :id (dma-tag-id cnt)) + :vif1 + (new 'static 'vif-tag :imm #x4 :cmd (vif-cmd direct) :msk #x1) + ) + :gif + (new 'static 'array uint64 2 #x3023400000008001 #x551) + ) + :adgif-tmpl + (new 'static 'dma-gif-packet + :dma-vif + (new 'static 'dma-packet + :dma + (new 'static 'dma-tag :qwc #x6 :id (dma-tag-id cnt)) + :vif1 + (new 'static 'vif-tag :imm #x6 :cmd (vif-cmd direct) :msk #x1) + ) + :gif + (new 'static 'array uint64 2 #x1000000000008005 #xe) + ) + ) + ) + +;; definition for symbol ocean-texture-vu1-block, type vu-function +(define ocean-texture-vu1-block (new 'static 'vu-function :length #x92 :qlength 73)) + +;; definition for function ocean-texture-setup-constants +;; INFO: Return type mismatch int vs none. +(defun ocean-texture-setup-constants ((arg0 ocean-texture-constants)) + (set! (-> arg0 giftag dword 0) (make-u128 0 (the-as uint #x300e400000008042))) + (set! (-> arg0 giftag dword 1) (the-as uint 1298)) + (set-vector! (-> arg0 buffers) 384 583 384 583) + (set-vector! (-> arg0 dests) 782 881 782 881) + (set-vector! (-> arg0 start) 0.0 0.0 1048575.94 0.0) + (set-vector! (-> arg0 offsets) 4.0 8.0 12.0 16.0) + (set-vector! (-> arg0 constants) 0.5 0.5 0.0 0.0) + (set! (-> arg0 cam-nrm x) (- (-> *math-camera* inv-camera-rot vector 2 x))) + (set! (-> arg0 cam-nrm y) (- (-> *math-camera* inv-camera-rot vector 2 y))) + (set! (-> arg0 cam-nrm z) (- (-> *math-camera* inv-camera-rot vector 2 z))) + (set! (-> arg0 cam-nrm w) 0.0) + 0 + (none) + ) + +;; definition for function ocean-texture-add-constants +(defun ocean-texture-add-constants ((arg0 dma-buffer)) + (let* ((a1-0 7) + (v1-0 arg0) + (a0-1 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a0-1) dma) (new 'static 'dma-tag :id (dma-tag-id cnt) :qwc a1-0)) + (set! (-> (the-as dma-packet a0-1) vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> (the-as dma-packet a0-1) vif1) + (new 'static 'vif-tag :imm #x3d9 :cmd (vif-cmd unpack-v4-32) :num a1-0) + ) + (set! (-> v1-0 base) (&+ (the-as pointer a0-1) 16)) + ) + (ocean-texture-setup-constants (the-as ocean-texture-constants (-> arg0 base))) + (let ((v0-1 (&+ (-> arg0 base) 112))) + (set! (-> arg0 base) v0-1) + v0-1 + ) + ) + +;; definition for function ocean-texture-add-envmap +;; Used lq/sq +(defun ocean-texture-add-envmap ((arg0 dma-buffer)) + (let ((v1-0 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-0) 0) (-> *ocean-texture-work* adgif-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-0) 1) (-> *ocean-texture-work* adgif-tmpl quad 1)) + (let ((s4-0 (&+ v1-0 32))) + (adgif-shader<-texture-simple! + (the-as adgif-shader s4-0) + (lookup-texture-by-id (new 'static 'texture-id :index #x1 :page #x100)) + ) + ) + ) + (let ((v0-2 (&+ (-> arg0 base) 112))) + (set! (-> arg0 base) v0-2) + v0-2 + ) + ) + +;; definition for function ocean-texture-add-verts +(defun ocean-texture-add-verts ((arg0 dma-buffer) (arg1 (pointer vector))) + (let* ((v1-0 arg0) + (a0-1 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a0-1) dma) + (new 'static 'dma-tag :qwc #xc0 :id (dma-tag-id ref) :addr (the-as int arg1)) + ) + (set! (-> (the-as dma-packet a0-1) vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> (the-as dma-packet a0-1) vif1) + (new 'static 'vif-tag :imm #x8000 :num #xc0 :cmd (vif-cmd unpack-v4-32)) + ) + (let ((v0-0 (&+ (the-as pointer a0-1) 16))) + (set! (-> v1-0 base) v0-0) + v0-0 + ) + ) + ) + +;; definition for function ocean-texture-add-verts-last +(defun ocean-texture-add-verts-last ((arg0 dma-buffer) (arg1 (pointer vector)) (arg2 (pointer vector))) + (let* ((v1-0 arg0) + (a3-0 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a3-0) dma) + (new 'static 'dma-tag :qwc #x80 :id (dma-tag-id ref) :addr (the-as int arg1)) + ) + (set! (-> (the-as dma-packet a3-0) vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> (the-as dma-packet a3-0) vif1) + (new 'static 'vif-tag :imm #x8000 :num #x80 :cmd (vif-cmd unpack-v4-32)) + ) + (set! (-> v1-0 base) (&+ (the-as pointer a3-0) 16)) + ) + (let* ((v1-1 arg0) + (a0-1 (the-as object (-> v1-1 base))) + ) + (set! (-> (the-as dma-packet a0-1) dma) + (new 'static 'dma-tag :qwc #x40 :id (dma-tag-id ref) :addr (the-as int arg2)) + ) + (set! (-> (the-as dma-packet a0-1) vif0) (new 'static 'vif-tag :imm #x404 :cmd (vif-cmd stcycl))) + (set! (-> (the-as dma-packet a0-1) vif1) + (new 'static 'vif-tag :imm #x8080 :num #x40 :cmd (vif-cmd unpack-v4-32)) + ) + (let ((v0-0 (&+ (the-as pointer a0-1) 16))) + (set! (-> v1-1 base) v0-0) + v0-0 + ) + ) + ) + +;; definition for function ocean-texture-add-call-start +;; INFO: Return type mismatch pointer vs none. +(defun ocean-texture-add-call-start ((arg0 dma-buffer)) + (let* ((v1-0 arg0) + (a0-1 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a0-1) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-1) vif0) (new 'static 'vif-tag :cmd (vif-cmd mscalf) :msk #x1)) + (set! (-> (the-as dma-packet a0-1) vif1) (new 'static 'vif-tag :cmd (vif-cmd stmod))) + (set! (-> v1-0 base) (&+ (the-as pointer a0-1) 16)) + ) + (none) + ) + +;; definition for function ocean-texture-add-call-rest +;; INFO: Return type mismatch pointer vs none. +(defun ocean-texture-add-call-rest ((arg0 dma-buffer)) + (let* ((v1-0 arg0) + (a0-1 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a0-1) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-1) vif0) (new 'static 'vif-tag :imm #x2 :cmd (vif-cmd mscalf) :msk #x1)) + (set! (-> (the-as dma-packet a0-1) vif1) (new 'static 'vif-tag :cmd (vif-cmd stmod))) + (set! (-> v1-0 base) (&+ (the-as pointer a0-1) 16)) + ) + (none) + ) + +;; definition for function ocean-texture-add-call-done +;; INFO: Return type mismatch pointer vs none. +(defun ocean-texture-add-call-done ((arg0 dma-buffer)) + (let* ((v1-0 arg0) + (a0-1 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a0-1) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-1) vif0) (new 'static 'vif-tag :imm #x4 :cmd (vif-cmd mscalf) :msk #x1)) + (set! (-> (the-as dma-packet a0-1) vif1) (new 'static 'vif-tag :cmd (vif-cmd stmod))) + (set! (-> v1-0 base) (&+ (the-as pointer a0-1) 16)) + ) + (none) + ) + +;; definition for function draw-ocean-texture +;; INFO: Return type mismatch int vs none. +;; Used lq/sq +(defun draw-ocean-texture ((arg0 dma-buffer) (arg1 (pointer vector)) (arg2 symbol)) + (local-vars (sv-16 (pointer vector)) (sv-32 int) (sv-48 (pointer vector)) (sv-64 (pointer vector))) + (set! sv-64 arg1) + (let* ((s0-0 arg2) + (a1-1 *ocean-base-page*) + (s2-0 *ocean-base-block*) + (s1-0 (+ a1-1 8)) + (s4-0 (* s1-0 32)) + (s3-0 (+ a1-1 10)) + (s5-0 (* s3-0 32)) + ) + (set-display-gs-state arg0 a1-1 128 128 0 0) + (dma-buffer-add-vu-function arg0 ocean-texture-vu1-block 1) + (let* ((v1-0 arg0) + (a0-3 (the-as object (-> v1-0 base))) + ) + (set! (-> (the-as dma-packet a0-3) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-3) vif0) (new 'static 'vif-tag :cmd (vif-cmd base))) + (set! (-> (the-as dma-packet a0-3) vif1) (new 'static 'vif-tag :imm #xc0 :cmd (vif-cmd offset))) + (set! (-> v1-0 base) (&+ (the-as pointer a0-3) 16)) + ) + (ocean-texture-add-constants arg0) + (ocean-texture-add-envmap arg0) + (set! sv-16 sv-64) + (ocean-texture-add-verts arg0 sv-16) + (set! sv-48 (&-> sv-16 768)) + (ocean-texture-add-call-start arg0) + (set! sv-32 0) + (while (< sv-32 9) + (ocean-texture-add-verts arg0 sv-48) + (set! sv-48 (&-> sv-48 768)) + (ocean-texture-add-call-rest arg0) + (set! sv-32 (+ sv-32 1)) + ) + (ocean-texture-add-verts-last arg0 sv-48 sv-64) + (ocean-texture-add-call-rest arg0) + (ocean-texture-add-call-done arg0) + (when s0-0 + (set-display-gs-state arg0 s1-0 64 64 0 0) + (let* ((v1-13 arg0) + (a0-15 (the-as object (-> v1-13 base))) + ) + (set! (-> (the-as dma-packet a0-15) dma) (new 'static 'dma-tag :qwc #x7 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-15) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-15) vif1) (new 'static 'vif-tag :imm #x7 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-13 base) (&+ (the-as pointer a0-15) 16)) + ) + (let* ((v1-14 arg0) + (a0-17 (the-as object (-> v1-14 base))) + ) + (set! (-> (the-as gs-gif-tag a0-17) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x6)) + (set! (-> (the-as gs-gif-tag a0-17) regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + :regs5 (gif-reg-id a+d) + :regs6 (gif-reg-id a+d) + :regs7 (gif-reg-id a+d) + :regs8 (gif-reg-id a+d) + :regs9 (gif-reg-id a+d) + :regs10 (gif-reg-id a+d) + :regs11 (gif-reg-id a+d) + :regs12 (gif-reg-id a+d) + :regs13 (gif-reg-id a+d) + :regs14 (gif-reg-id a+d) + :regs15 (gif-reg-id a+d) + ) + ) + (set! (-> v1-14 base) (&+ (the-as pointer a0-17) 16)) + ) + (let* ((s1-1 arg0) + (s0-1 (-> s1-1 base)) + ) + (set! (-> (the-as (pointer gs-test) s0-1) 0) + (new 'static 'gs-test :ate #x1 :atst (gs-atest always) :zte #x1 :ztst (gs-ztest always)) + ) + (set! (-> (the-as (pointer gs-reg64) s0-1) 1) (gs-reg64 test-1)) + (set! (-> (the-as (pointer gs-alpha) s0-1) 2) (new 'static 'gs-alpha :b #x1 :d #x1)) + (set! (-> (the-as (pointer gs-reg64) s0-1) 3) (gs-reg64 alpha-1)) + (set! (-> (the-as (pointer gs-tex0) s0-1) 4) + (new 'static 'gs-tex0 :tbw #x2 :tcc #x1 :th (log2 128) :tw (log2 128) :tbp0 s2-0) + ) + (set! (-> (the-as (pointer gs-reg64) s0-1) 5) (gs-reg64 tex0-1)) + (set! (-> (the-as (pointer gs-tex1) s0-1) 6) (new 'static 'gs-tex1 :mmag #x1 :mmin #x1)) + (set! (-> (the-as (pointer gs-reg64) s0-1) 7) (gs-reg64 tex1-1)) + (set! (-> (the-as (pointer gs-clamp) s0-1) 8) (new 'static 'gs-clamp)) + (set! (-> (the-as (pointer gs-reg64) s0-1) 9) (gs-reg64 clamp-1)) + (set! (-> (the-as (pointer uint64) s0-1) 10) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) s0-1) 11) (gs-reg64 texflush)) + (set! (-> s1-1 base) (&+ s0-1 96)) + ) + (let ((v1-31 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-31) 0) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-31) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-31 32)) 128 128 128 64) + (set-vector! (the-as vector4w (&+ v1-31 48)) 0 0 0 0) + (set-vector! (the-as vector4w (&+ v1-31 64)) 0 0 #xffffff 0) + (set-vector! (the-as vector4w (&+ v1-31 80)) 2048 2048 0 0) + (set-vector! (the-as vector4w (&+ v1-31 96)) 1024 1024 #xffffff 0) + ) + (&+! (-> arg0 base) 112) + (set-display-gs-state arg0 s3-0 64 32 0 0) + (let* ((v1-35 arg0) + (a0-35 (the-as object (-> v1-35 base))) + ) + (set! (-> (the-as dma-packet a0-35) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-35) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-35) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-35 base) (&+ (the-as pointer a0-35) 16)) + ) + (let* ((v1-36 arg0) + (a0-37 (the-as object (-> v1-36 base))) + ) + (set! (-> (the-as gs-gif-tag a0-37) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + (set! (-> (the-as gs-gif-tag a0-37) regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + :regs5 (gif-reg-id a+d) + :regs6 (gif-reg-id a+d) + :regs7 (gif-reg-id a+d) + :regs8 (gif-reg-id a+d) + :regs9 (gif-reg-id a+d) + :regs10 (gif-reg-id a+d) + :regs11 (gif-reg-id a+d) + :regs12 (gif-reg-id a+d) + :regs13 (gif-reg-id a+d) + :regs14 (gif-reg-id a+d) + :regs15 (gif-reg-id a+d) + ) + ) + (set! (-> v1-36 base) (&+ (the-as pointer a0-37) 16)) + ) + (let* ((s3-1 arg0) + (s2-3 (-> s3-1 base)) + ) + (set! (-> (the-as (pointer gs-tex0) s2-3) 0) + (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 64) :tw (log2 64) :tbp0 s4-0) + ) + (set! (-> (the-as (pointer gs-reg64) s2-3) 1) (gs-reg64 tex0-1)) + (set! (-> (the-as (pointer uint64) s2-3) 2) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) s2-3) 3) (gs-reg64 texflush)) + (set! (-> s3-1 base) (&+ s2-3 32)) + ) + (let ((v1-46 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-46)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-46) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-46 32)) 128 128 128 0) + (set-vector! (the-as vector4w (&+ v1-46 48)) 0 0 0 0) + (set-vector! (the-as vector4w (&+ v1-46 64)) 0 0 #xffffff 0) + (set-vector! (the-as vector4w (&+ v1-46 80)) 1024 1024 0 0) + (set-vector! (the-as vector4w (&+ v1-46 96)) 512 512 #xffffff 0) + ) + (&+! (-> arg0 base) 112) + (let* ((v1-50 arg0) + (a0-54 (the-as object (-> v1-50 base))) + ) + (set! (-> (the-as dma-packet a0-54) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-54) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-54) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-50 base) (&+ (the-as pointer a0-54) 16)) + ) + (let* ((v1-51 arg0) + (a0-56 (the-as object (-> v1-51 base))) + ) + (set! (-> (the-as gs-gif-tag a0-56) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + (set! (-> (the-as gs-gif-tag a0-56) regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + :regs5 (gif-reg-id a+d) + :regs6 (gif-reg-id a+d) + :regs7 (gif-reg-id a+d) + :regs8 (gif-reg-id a+d) + :regs9 (gif-reg-id a+d) + :regs10 (gif-reg-id a+d) + :regs11 (gif-reg-id a+d) + :regs12 (gif-reg-id a+d) + :regs13 (gif-reg-id a+d) + :regs14 (gif-reg-id a+d) + :regs15 (gif-reg-id a+d) + ) + ) + (set! (-> v1-51 base) (&+ (the-as pointer a0-56) 16)) + ) + (let* ((s4-3 arg0) + (s3-2 (-> s4-3 base)) + ) + (set! (-> (the-as (pointer gs-tex0) s3-2) 0) + (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 32) :tw (log2 32) :tbp0 s5-0) + ) + (set! (-> (the-as (pointer gs-reg64) s3-2) 1) (gs-reg64 tex0-1)) + (set! (-> (the-as (pointer uint64) s3-2) 2) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) s3-2) 3) (gs-reg64 texflush)) + (set! (-> s4-3 base) (&+ s3-2 32)) + ) + (let ((v1-61 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-61)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-61) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-61 32)) 128 128 128 0) + (set-vector! (the-as vector4w (&+ v1-61 48)) 0 0 0 0) + (set-vector! (the-as vector4w (&+ v1-61 64)) 512 0 #xffffff 0) + (set-vector! (the-as vector4w (&+ v1-61 80)) 512 512 0 0) + (set-vector! (the-as vector4w (&+ v1-61 96)) 768 256 #xffffff 0) + ) + (&+! (-> arg0 base) 112) + (let* ((v1-65 arg0) + (a0-73 (the-as object (-> v1-65 base))) + ) + (set! (-> (the-as dma-packet a0-73) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-73) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-73) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-65 base) (&+ (the-as pointer a0-73) 16)) + ) + (let* ((v1-66 arg0) + (a0-75 (the-as object (-> v1-66 base))) + ) + (set! (-> (the-as gs-gif-tag a0-75) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + (set! (-> (the-as gs-gif-tag a0-75) regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + :regs5 (gif-reg-id a+d) + :regs6 (gif-reg-id a+d) + :regs7 (gif-reg-id a+d) + :regs8 (gif-reg-id a+d) + :regs9 (gif-reg-id a+d) + :regs10 (gif-reg-id a+d) + :regs11 (gif-reg-id a+d) + :regs12 (gif-reg-id a+d) + :regs13 (gif-reg-id a+d) + :regs14 (gif-reg-id a+d) + :regs15 (gif-reg-id a+d) + ) + ) + (set! (-> v1-66 base) (&+ (the-as pointer a0-75) 16)) + ) + (let* ((s4-4 arg0) + (s3-3 (-> s4-4 base)) + ) + (set! (-> (the-as (pointer gs-tex0) s3-3) 0) + (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 16) :tw (log2 16) :tbp0 (+ s5-0 16)) + ) + (set! (-> (the-as (pointer gs-reg64) s3-3) 1) (gs-reg64 tex0-1)) + (set! (-> (the-as (pointer uint64) s3-3) 2) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) s3-3) 3) (gs-reg64 texflush)) + (set! (-> s4-4 base) (&+ s3-3 32)) + ) + (let ((v1-76 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-76)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-76) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-76 32)) 128 128 128 0) + (set-vector! (the-as vector4w (&+ v1-76 48)) 0 0 0 0) + (set-vector! (the-as vector4w (&+ v1-76 64)) 768 0 #xffffff 0) + (set-vector! (the-as vector4w (&+ v1-76 80)) 256 256 0 0) + (set-vector! (the-as vector4w (&+ v1-76 96)) 896 128 #xffffff 0) + ) + (&+! (-> arg0 base) 112) + (let* ((v1-80 arg0) + (a0-93 (the-as object (-> v1-80 base))) + ) + (set! (-> (the-as dma-packet a0-93) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-93) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-93) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-80 base) (&+ (the-as pointer a0-93) 16)) + ) + (let* ((v1-81 arg0) + (a0-95 (the-as object (-> v1-81 base))) + ) + (set! (-> (the-as gs-gif-tag a0-95) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + (set! (-> (the-as gs-gif-tag a0-95) regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + :regs5 (gif-reg-id a+d) + :regs6 (gif-reg-id a+d) + :regs7 (gif-reg-id a+d) + :regs8 (gif-reg-id a+d) + :regs9 (gif-reg-id a+d) + :regs10 (gif-reg-id a+d) + :regs11 (gif-reg-id a+d) + :regs12 (gif-reg-id a+d) + :regs13 (gif-reg-id a+d) + :regs14 (gif-reg-id a+d) + :regs15 (gif-reg-id a+d) + ) + ) + (set! (-> v1-81 base) (&+ (the-as pointer a0-95) 16)) + ) + (let* ((s4-5 arg0) + (s3-4 (-> s4-5 base)) + ) + (set! (-> (the-as (pointer gs-tex0) s3-4) 0) + (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 8) :tw (log2 8) :tbp0 (+ s5-0 20)) + ) + (set! (-> (the-as (pointer gs-reg64) s3-4) 1) (gs-reg64 tex0-1)) + (set! (-> (the-as (pointer uint64) s3-4) 2) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) s3-4) 3) (gs-reg64 texflush)) + (set! (-> s4-5 base) (&+ s3-4 32)) + ) + (let ((v1-91 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-91)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-91) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-91 32)) 128 128 128 0) + (set-vector! (the-as vector4w (&+ v1-91 48)) 0 0 0 0) + (set-vector! (the-as vector4w (&+ v1-91 64)) 896 0 #xffffff 0) + (set-vector! (the-as vector4w (&+ v1-91 80)) 256 256 0 0) + (set-vector! (the-as vector4w (&+ v1-91 96)) 1024 128 #xffffff 0) + ) + (&+! (-> arg0 base) 112) + (let* ((v1-95 arg0) + (a0-113 (the-as object (-> v1-95 base))) + ) + (set! (-> (the-as dma-packet a0-113) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-113) vif0) (new 'static 'vif-tag)) + (set! (-> (the-as dma-packet a0-113) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + (set! (-> v1-95 base) (&+ (the-as pointer a0-113) 16)) + ) + (let* ((v1-96 arg0) + (a0-115 (the-as object (-> v1-96 base))) + ) + (set! (-> (the-as gs-gif-tag a0-115) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + (set! (-> (the-as gs-gif-tag a0-115) regs) + (new 'static 'gif-tag-regs + :regs0 (gif-reg-id a+d) + :regs1 (gif-reg-id a+d) + :regs2 (gif-reg-id a+d) + :regs3 (gif-reg-id a+d) + :regs4 (gif-reg-id a+d) + :regs5 (gif-reg-id a+d) + :regs6 (gif-reg-id a+d) + :regs7 (gif-reg-id a+d) + :regs8 (gif-reg-id a+d) + :regs9 (gif-reg-id a+d) + :regs10 (gif-reg-id a+d) + :regs11 (gif-reg-id a+d) + :regs12 (gif-reg-id a+d) + :regs13 (gif-reg-id a+d) + :regs14 (gif-reg-id a+d) + :regs15 (gif-reg-id a+d) + ) + ) + (set! (-> v1-96 base) (&+ (the-as pointer a0-115) 16)) + ) + (let* ((s4-6 arg0) + (s3-5 (-> s4-6 base)) + ) + (set! (-> (the-as (pointer gs-tex0) s3-5) 0) + (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 4) :tw (log2 4) :tbp0 (+ s5-0 21)) + ) + (set! (-> (the-as (pointer gs-reg64) s3-5) 1) (gs-reg64 tex0-1)) + (set! (-> (the-as (pointer uint64) s3-5) 2) (the-as uint 0)) + (set! (-> (the-as (pointer gs-reg64) s3-5) 3) (gs-reg64 texflush)) + (set! (-> s4-6 base) (&+ s3-5 32)) + ) + (let ((v1-106 (-> arg0 base))) + (set! (-> (the-as (pointer uint128) v1-106)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + (set! (-> (the-as (pointer uint128) v1-106) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + (set-vector! (the-as vector4w (&+ v1-106 32)) 128 128 128 0) + (set-vector! (the-as vector4w (&+ v1-106 48)) 0 0 0 0) + (set-vector! (the-as vector4w (&+ v1-106 64)) 768 128 #xffffff 0) + (set-vector! (the-as vector4w (&+ v1-106 80)) 512 512 0 0) + (set-vector! (the-as vector4w (&+ v1-106 96)) 896 256 #xffffff 0) + ) + (&+! (-> arg0 base) 112) + (let* ((v1-110 arg0) + (a0-133 (the-as object (-> v1-110 base))) + ) + (set! (-> (the-as dma-packet a0-133) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + (set! (-> (the-as dma-packet a0-133) vif0) (new 'static 'vif-tag :cmd (vif-cmd flush) :msk #x1)) + (set! (-> (the-as dma-packet a0-133) vif1) (new 'static 'vif-tag)) + (set! (-> v1-110 base) (&+ (the-as pointer a0-133) 16)) + ) + ) + ) + (reset-display-gs-state *display* arg0 *oddeven*) + 0 + (none) + ) + + + + From 6c0450c47e9e51ea9917c27b13e02db066011c36 Mon Sep 17 00:00:00 2001 From: water Date: Wed, 9 Mar 2022 20:55:29 -0500 Subject: [PATCH 2/6] vu1 texture setup --- decompiler/config/all-types.gc | 6 +- .../jak1_ntsc_black_label/type_casts.jsonc | 3 +- game/CMakeLists.txt | 3 +- .../opengl_renderer/OpenGLRenderer.cpp | 2 +- .../{ => ocean}/OceanMidAndFar.cpp | 38 +- .../{ => ocean}/OceanMidAndFar.h | 12 + .../opengl_renderer/ocean/OceanTexture.cpp | 282 +++++++ .../opengl_renderer/ocean/OceanTexture.h | 120 +++ goal_src/engine/draw/drawable.gc | 2 +- goal_src/engine/gfx/ocean/ocean-h.gc | 1 + goal_src/engine/gfx/ocean/ocean-texture.gc | 755 +++++++++--------- goal_src/engine/gfx/ocean/ocean-vu0.gc | 4 +- goal_src/engine/gfx/ocean/ocean.gc | 2 +- 13 files changed, 832 insertions(+), 398 deletions(-) rename game/graphics/opengl_renderer/{ => ocean}/OceanMidAndFar.cpp (80%) rename game/graphics/opengl_renderer/{ => ocean}/OceanMidAndFar.h (52%) create mode 100644 game/graphics/opengl_renderer/ocean/OceanTexture.cpp create mode 100644 game/graphics/opengl_renderer/ocean/OceanTexture.h diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index fa228c52e8..71eb766ae5 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -21703,7 +21703,7 @@ (define-extern ocean-interp-wave (function ocean-wave-info uint none)) ;; unconfirmed (define-extern ocean-generate-verts (function (inline-array vector) ocean-wave-info none)) ;; unconfirmed - pointer is *ocean-verts* -(define-extern draw-ocean-texture (function dma-buffer (pointer vector) symbol none)) ;; unconfirmed - pointer is *ocean-verts* +(define-extern draw-ocean-texture (function dma-buffer (inline-array vector) symbol none)) ;; unconfirmed - pointer is *ocean-verts* (define-extern ocean-init-buffer (function dma-buffer pointer)) (define-extern draw-ocean-far (function dma-buffer profile-frame)) (define-extern draw-ocean-mid (function dma-buffer none)) ; not confirmed @@ -21747,10 +21747,10 @@ (define-extern ocean-texture-add-constants (function dma-buffer pointer)) (define-extern ocean-texture-add-envmap (function dma-buffer pointer)) -(define-extern ocean-texture-add-verts (function dma-buffer (pointer vector) pointer)) ;; pointer is *ocean-verts* +(define-extern ocean-texture-add-verts (function dma-buffer (inline-array vector) pointer)) ;; pointer is *ocean-verts* (define-extern ocean-texture-add-call-start (function dma-buffer none)) ;; unconfirmed (define-extern ocean-texture-add-call-rest (function dma-buffer none)) ;; unconfirmed -(define-extern ocean-texture-add-verts-last (function dma-buffer (pointer vector) (pointer vector) pointer)) ;; pointer is *ocean-verts* and unconfirmed +(define-extern ocean-texture-add-verts-last (function dma-buffer (inline-array vector) (inline-array vector) pointer)) ;; pointer is *ocean-verts* and unconfirmed (define-extern ocean-texture-add-call-done (function dma-buffer none)) ;; unconfirmed (define-extern ocean-texture-setup-constants (function ocean-texture-constants none)) diff --git a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc index a8fc488b5d..52132596f0 100644 --- a/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc +++ b/decompiler/config/jak1_ntsc_black_label/type_casts.jsonc @@ -7525,7 +7525,8 @@ [609, "v1", "(pointer uint128)"], [[611, 638], "a0", "vector4w"], [[639, 646], "v1", "vector4w"], - [[652, 656], "a0", "dma-packet"] + [[652, 656], "a0", "dma-packet"], + [57, "v1", "(inline-array vector)"] ], "placeholder-do-not-add-below": [] diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 5dd600b009..3f6b31847f 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -84,6 +84,8 @@ set(RUNTIME_SOURCE graphics/opengl_renderer/foreground/Generic2_DMA.cpp graphics/opengl_renderer/foreground/Generic2_Build.cpp graphics/opengl_renderer/foreground/Generic2_OpenGL.cpp + graphics/opengl_renderer/ocean/OceanMidAndFar.cpp + graphics/opengl_renderer/ocean/OceanTexture.cpp graphics/opengl_renderer/BucketRenderer.cpp graphics/opengl_renderer/debug_gui.cpp graphics/opengl_renderer/DirectRenderer.cpp @@ -95,7 +97,6 @@ set(RUNTIME_SOURCE graphics/opengl_renderer/Loader.cpp graphics/opengl_renderer/MercProgram.cpp graphics/opengl_renderer/MercRenderer.cpp - graphics/opengl_renderer/OceanMidAndFar.cpp graphics/opengl_renderer/opengl_utils.cpp graphics/opengl_renderer/OpenGLRenderer.cpp graphics/opengl_renderer/Profiler.cpp diff --git a/game/graphics/opengl_renderer/OpenGLRenderer.cpp b/game/graphics/opengl_renderer/OpenGLRenderer.cpp index 9a28a7b2d2..bd2b435975 100644 --- a/game/graphics/opengl_renderer/OpenGLRenderer.cpp +++ b/game/graphics/opengl_renderer/OpenGLRenderer.cpp @@ -14,7 +14,7 @@ #include "game/graphics/opengl_renderer/MercRenderer.h" #include "game/graphics/opengl_renderer/EyeRenderer.h" #include "game/graphics/opengl_renderer/GenericRenderer.h" -#include "game/graphics/opengl_renderer/OceanMidAndFar.h" +#include "game/graphics/opengl_renderer/ocean/OceanMidAndFar.h" // for the vif callback #include "game/kernel/kmachine.h" diff --git a/game/graphics/opengl_renderer/OceanMidAndFar.cpp b/game/graphics/opengl_renderer/ocean/OceanMidAndFar.cpp similarity index 80% rename from game/graphics/opengl_renderer/OceanMidAndFar.cpp rename to game/graphics/opengl_renderer/ocean/OceanMidAndFar.cpp index 471236914a..4f5a3452ab 100644 --- a/game/graphics/opengl_renderer/OceanMidAndFar.cpp +++ b/game/graphics/opengl_renderer/ocean/OceanMidAndFar.cpp @@ -1,7 +1,9 @@ #include "OceanMidAndFar.h" OceanMidAndFar::OceanMidAndFar(const std::string& name, BucketId my_id) - : BucketRenderer(name, my_id), m_direct(name, my_id, 4096) {} + : BucketRenderer(name, my_id), + m_direct(name, my_id, 4096) + {} void OceanMidAndFar::draw_debug_window() { m_direct.draw_debug_window(); @@ -35,6 +37,29 @@ void OceanMidAndFar::render(DmaFollower& dma, } m_direct.reset_state(); + { + auto p = prof.make_scoped_child("texture"); + m_texture_renderer.handle_ocean_texture(dma, render_state, p); + } + + handle_ocean_far(dma, render_state, prof); + + auto final_next = dma.read_and_advance(); + ASSERT(final_next.vifcode0().kind == VifCode::Kind::NOP && + final_next.vifcode1().kind == VifCode::Kind::NOP && final_next.size_bytes == 0); + for (int i = 0; i < 4; i++) { + dma.read_and_advance(); + } + ASSERT(dma.current_tag_offset() == render_state->next_bucket); + + m_direct.flush_pending(render_state, prof); +} + + + +void OceanMidAndFar::handle_ocean_far(DmaFollower& dma, + SharedRenderState* render_state, + ScopedProfilerNode& prof) { auto init_data = dma.read_and_advance(); ASSERT(init_data.size_bytes == 160); u8 init_data_buffer[160]; @@ -42,6 +67,7 @@ void OceanMidAndFar::render(DmaFollower& dma, // this is a bit of a hack, but it patches the ta0 to 0 in // (set! (-> (the-as (pointer gs-texa) s4-0) 8) (new 'static 'gs-texa :ta0 #x80 :ta1 #x80)) + // TODO figure out if we actually have do something here. u8 val = 0; memcpy(init_data_buffer + 80, &val, 1); m_direct.render_gif(init_data_buffer, 160, render_state, prof); @@ -53,14 +79,4 @@ void OceanMidAndFar::render(DmaFollower& dma, ASSERT(data.size_bytes / 16 == data.vifcode1().immediate); m_direct.render_gif(data.data, data.size_bytes, render_state, prof); } - - auto final_next = dma.read_and_advance(); - ASSERT(final_next.vifcode0().kind == VifCode::Kind::NOP && - final_next.vifcode1().kind == VifCode::Kind::NOP && final_next.size_bytes == 0); - for (int i = 0; i < 4; i++) { - dma.read_and_advance(); - } - ASSERT(dma.current_tag_offset() == render_state->next_bucket); - - m_direct.flush_pending(render_state, prof); } \ No newline at end of file diff --git a/game/graphics/opengl_renderer/OceanMidAndFar.h b/game/graphics/opengl_renderer/ocean/OceanMidAndFar.h similarity index 52% rename from game/graphics/opengl_renderer/OceanMidAndFar.h rename to game/graphics/opengl_renderer/ocean/OceanMidAndFar.h index 6e9b124d29..4dd740638a 100644 --- a/game/graphics/opengl_renderer/OceanMidAndFar.h +++ b/game/graphics/opengl_renderer/ocean/OceanMidAndFar.h @@ -2,7 +2,13 @@ #include "game/graphics/opengl_renderer/BucketRenderer.h" #include "game/graphics/opengl_renderer/DirectRenderer.h" +#include "game/graphics/opengl_renderer/opengl_utils.h" +#include "game/graphics/opengl_renderer/ocean/OceanTexture.h" +/*! + * OceanMidAndFar is the handler for the first ocean bucket. + * + */ class OceanMidAndFar : public BucketRenderer { public: OceanMidAndFar(const std::string& name, BucketId my_id); @@ -10,5 +16,11 @@ class OceanMidAndFar : public BucketRenderer { void draw_debug_window() override; private: + + void handle_ocean_far(DmaFollower& dma, + SharedRenderState* render_state, + ScopedProfilerNode& prof); + DirectRenderer m_direct; + OceanTexture m_texture_renderer; }; diff --git a/game/graphics/opengl_renderer/ocean/OceanTexture.cpp b/game/graphics/opengl_renderer/ocean/OceanTexture.cpp new file mode 100644 index 0000000000..8bc813ba46 --- /dev/null +++ b/game/graphics/opengl_renderer/ocean/OceanTexture.cpp @@ -0,0 +1,282 @@ +#include "OceanTexture.h" + +OceanTexture::OceanTexture() : m_tex0(TEX0_SIZE, TEX0_SIZE, GL_UNSIGNED_INT_8_8_8_8_REV) { + m_dbuf_x = m_dbuf_a; + m_dbuf_y = m_dbuf_b; + + m_tbuf_x = m_tbuf_a; + m_tbuf_y = m_tbuf_b; +} + +void OceanTexture::handle_tex_call_start(DmaFollower& dma, + SharedRenderState* render_state, + ScopedProfilerNode& prof) { + // L1: + // lq.xyzw vf14_startx, 988(vi00) | maxw.xyzw vf01_ones, vf00, vf00 + vu.startx = Vf(m_texture_constants.start); + // lq.xyzw vf02_offset, 989(vi00) + // lq.xyzw vf03_tbuf, 986(vi00) + // lq.xyzw vf04_dbuf, 987(vi00) + // lq.xyzw vf05_giftag, 985(vi00) + // lq.xyzw vf06_cam_nrm, 991(vi00) + // lq.xyzw vf07_constants, 990(vi00) + // iaddiu vi11_0x80, vi00, 0x80 + // mtir vi08_tptr, vf03_tbuf.x + vu.tptr = get_tbuf(); + // mtir vi09_tbase, vf03_tbuf.x + vu.tbase = get_tbuf(); + // mr32.xyzw vf03_tbuf, vf03_tbuf + swap_tbuf(); + // xtop vi05_in_ptr + vu.in_ptr = swap_vu_upload_buffers(); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3(); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5(); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5(); + + // nop :e + // nop +} + +void OceanTexture::handle_tex_call_rest(DmaFollower& dma, + SharedRenderState* render_state, + ScopedProfilerNode& prof) { + // L2: + // xtop vi05_in_ptr + vu.in_ptr = swap_vu_upload_buffers(); + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5(); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5(); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5(); + + // nop :e + // nop +} + +void OceanTexture::run_L3() { + +} + +void OceanTexture::run_L5() { + +} + +void OceanTexture::handle_tex_call_done(DmaFollower& dma, + SharedRenderState* render_state, + ScopedProfilerNode& prof) { + // this program does nothing. +} + +void OceanTexture::handle_ocean_texture(DmaFollower& dma, + SharedRenderState* render_state, + ScopedProfilerNode& prof) { + // render to the first texture + { + // (set-display-gs-state arg0 ocean-tex-page-0 128 128 0 0) + auto data = dma.read_and_advance(); + } + + // set up VIF + { + // (new 'static 'vif-tag :cmd (vif-cmd base)) + // (new 'static 'vif-tag :imm #xc0 :cmd (vif-cmd offset)) + auto data = dma.read_and_advance(); + ASSERT(data.size_bytes == 0); + ASSERT(data.vifcode0().kind == VifCode::Kind::BASE); + ASSERT(data.vifcode1().kind == VifCode::Kind::OFFSET); + ASSERT(data.vifcode0().immediate == 0); + ASSERT(data.vifcode1().immediate == 0xc0); + } + + // load texture constants + { + // (ocean-texture-add-constants arg0) + auto data = dma.read_and_advance(); + ASSERT(data.size_bytes == sizeof(OceanTextureConstants)); + ASSERT(data.vifcode0().kind == VifCode::Kind::STCYCL); + ASSERT(data.vifcode0().immediate == 0x404); + ASSERT(data.vifcode1().kind == VifCode::Kind::UNPACK_V4_32); + ASSERT(data.vifcode1().num == data.size_bytes / 16); + ASSERT(data.vifcode1().immediate == TexVu1Data::CONSTANTS); + memcpy(&m_texture_constants, data.data, sizeof(OceanTextureConstants)); + } + + // set up GS for envmap texture drawing + { + // (ocean-texture-add-envmap arg0) + auto data = dma.read_and_advance(); + ASSERT(data.size_bytes == sizeof(AdGifData) + 16); // 16 for the giftag. + ASSERT(data.vifcode0().kind == VifCode::Kind::NOP); + ASSERT(data.vifcode1().kind == VifCode::Kind::DIRECT); + memcpy(&m_envmap_adgif, data.data + 16, sizeof(AdGifData)); + } + + // vertices are uploaded double buffered + m_texture_vertices_loading = m_texture_vertices_a; + m_texture_vertices_drawing = m_texture_vertices_b; + + // add first group of vertices + { + // (ocean-texture-add-verts arg0 sv-16) + auto data = dma.read_and_advance(); + ASSERT(data.size_bytes == sizeof(m_texture_vertices_a)); + ASSERT(data.vifcode0().kind == VifCode::Kind::STCYCL); + ASSERT(data.vifcode0().immediate == 0x404); + ASSERT(data.vifcode1().kind == VifCode::Kind::UNPACK_V4_32); + ASSERT(data.vifcode1().num == data.size_bytes / 16); + VifCodeUnpack up(data.vifcode1()); + ASSERT(up.addr_qw == 0); + ASSERT(up.use_tops_flag == true); + memcpy(m_texture_vertices_loading, data.data, sizeof(m_texture_vertices_a)); + } + + // first call + { + auto data = dma.read_and_advance(); + ASSERT(data.size_bytes == 0); + ASSERT(data.vifcode0().kind == VifCode::Kind::MSCALF); + ASSERT(data.vifcode0().immediate == TexVu1Prog::START); + ASSERT(data.vifcode1().kind == VifCode::Kind::STMOD); // not sure why... + handle_tex_call_start(dma, render_state, prof); + // TODO handle call and swapping buffer + } + + // loop over vertex groups + for (int i = 0; i < NUM_FRAG_LOOPS; i++) { + auto verts = dma.read_and_advance(); + ASSERT(verts.size_bytes == sizeof(m_texture_vertices_a)); + ASSERT(verts.vifcode0().kind == VifCode::Kind::STCYCL); + ASSERT(verts.vifcode0().immediate == 0x404); + ASSERT(verts.vifcode1().kind == VifCode::Kind::UNPACK_V4_32); + ASSERT(verts.vifcode1().num == verts.size_bytes / 16); + VifCodeUnpack up(verts.vifcode1()); + ASSERT(up.addr_qw == 0); + ASSERT(up.use_tops_flag == true); + memcpy(m_texture_vertices_loading, verts.data, sizeof(m_texture_vertices_a)); + + auto call = dma.read_and_advance(); + ASSERT(call.size_bytes == 0); + ASSERT(call.vifcode0().kind == VifCode::Kind::MSCALF); + ASSERT(call.vifcode0().immediate == TexVu1Prog::REST); + ASSERT(call.vifcode1().kind == VifCode::Kind::STMOD); // not sure why... + handle_tex_call_rest(dma, render_state, prof); + + // TODO handle call and swapping buffer + } + + // last upload does something weird... + { + // (ocean-texture-add-verts-last arg0 (the-as (inline-array vector) sv-48) sv-64) + auto data0 = dma.read_and_advance(); + ASSERT(data0.size_bytes == 128 * 16); + ASSERT(data0.vifcode0().kind == VifCode::Kind::STCYCL); + ASSERT(data0.vifcode0().immediate == 0x404); + ASSERT(data0.vifcode1().kind == VifCode::Kind::UNPACK_V4_32); + ASSERT(data0.vifcode1().num == data0.size_bytes / 16); + VifCodeUnpack up0(data0.vifcode1()); + ASSERT(up0.addr_qw == 0); + ASSERT(up0.use_tops_flag == true); + memcpy(m_texture_vertices_loading, data0.data, 128 * 16); + + auto data1 = dma.read_and_advance(); + ASSERT(data1.size_bytes == 64 * 16); + ASSERT(data1.vifcode0().kind == VifCode::Kind::STCYCL); + ASSERT(data1.vifcode0().immediate == 0x404); + ASSERT(data1.vifcode1().kind == VifCode::Kind::UNPACK_V4_32); + ASSERT(data1.vifcode1().num == data1.size_bytes / 16); + VifCodeUnpack up1(data1.vifcode1()); + ASSERT(up1.addr_qw == 128); + ASSERT(up1.use_tops_flag == true); + memcpy(m_texture_vertices_loading + 128, data1.data, 64 * 16); + } + + // last rest call + { + auto data = dma.read_and_advance(); + ASSERT(data.size_bytes == 0); + ASSERT(data.vifcode0().kind == VifCode::Kind::MSCALF); + ASSERT(data.vifcode0().immediate == TexVu1Prog::REST); + ASSERT(data.vifcode1().kind == VifCode::Kind::STMOD); // not sure why... + handle_tex_call_rest(dma, render_state, prof); + // TODO handle call and swapping buffer + } + + // last call + { + auto data = dma.read_and_advance(); + ASSERT(data.size_bytes == 0); + ASSERT(data.vifcode0().kind == VifCode::Kind::MSCALF); + ASSERT(data.vifcode0().immediate == TexVu1Prog::DONE); + ASSERT(data.vifcode1().kind == VifCode::Kind::STMOD); // not sure why... + handle_tex_call_done(dma, render_state, prof); + // TODO handle call and swapping buffer + } +} \ No newline at end of file diff --git a/game/graphics/opengl_renderer/ocean/OceanTexture.h b/game/graphics/opengl_renderer/ocean/OceanTexture.h new file mode 100644 index 0000000000..8e270107e2 --- /dev/null +++ b/game/graphics/opengl_renderer/ocean/OceanTexture.h @@ -0,0 +1,120 @@ +#pragma once + +#include "game/graphics/opengl_renderer/BucketRenderer.h" +#include "game/graphics/opengl_renderer/DirectRenderer.h" +#include "game/graphics/opengl_renderer/opengl_utils.h" +#include "game/common/vu.h" + +class OceanTexture { + public: + OceanTexture(); + void handle_ocean_texture(DmaFollower& dma, + SharedRenderState* render_state, + ScopedProfilerNode& prof); + + private: + void handle_tex_call_start(DmaFollower& dma, + SharedRenderState* render_state, + ScopedProfilerNode& prof); + void handle_tex_call_rest(DmaFollower& dma, + SharedRenderState* render_state, + ScopedProfilerNode& prof); + void handle_tex_call_done(DmaFollower& dma, + SharedRenderState* render_state, + ScopedProfilerNode& prof); + + void run_L3(); + void run_L5(); + + static constexpr int TEX0_SIZE = 128; + FramebufferTexturePair m_tex0; + + // (deftype ocean-texture-constants (structure) + struct OceanTextureConstants { + // ((giftag qword :inline :offset-assert 0) 985 + u8 giftag[16]; + // (buffers vector4w :inline :offset-assert 16) 986 + math::Vector buffers; + // (dests vector4w :inline :offset-assert 32) 987 + math::Vector dests; + // (start vector :inline :offset-assert 48) 988 + math::Vector4f start; + // (offsets vector :inline :offset-assert 64) 989 + math::Vector4f offsets; + // (constants vector :inline :offset-assert 80) 990 + math::Vector4f constants; + // (cam-nrm vector :inline :offset-assert 96) 991 + math::Vector4f cam_nrm; + // ) + } m_texture_constants; + static_assert(sizeof(OceanTextureConstants) == 112); + + AdGifData m_envmap_adgif; + + Vf m_texture_vertices_a[192]; + Vf m_texture_vertices_b[192]; + + static constexpr int DBUF_SIZE = 99; + Vf m_dbuf_a[DBUF_SIZE]; + Vf m_dbuf_b[DBUF_SIZE]; + + Vf* m_dbuf_x; + Vf* m_dbuf_y; + + static constexpr int TBUF_SIZE = 199; + Vf m_tbuf_a[TBUF_SIZE]; + Vf m_tbuf_b[TBUF_SIZE]; + + Vf* m_tbuf_x; + Vf* m_tbuf_y; + + Vf* m_texture_vertices_loading = nullptr; + Vf* m_texture_vertices_drawing = nullptr; + + Vf* swap_vu_upload_buffers() { + std::swap(m_texture_vertices_drawing, m_texture_vertices_loading); + return m_texture_vertices_drawing; + } + + void swap_dbuf() { + std::swap(m_dbuf_x, m_dbuf_y); + } + + void swap_tbuf() { + std::swap(m_tbuf_x, m_tbuf_y); + } + + Vf* get_dbuf() { + return m_dbuf_x; + } + + Vf* get_dbuf_other() { + return m_dbuf_y; + } + + Vf* get_tbuf() { + return m_tbuf_x; + } + + struct { + Vf startx; // vf14 + Vf* dbuf_read_a; // vi03 + Vf* dbuf_read_b; // vi04 + Vf* in_ptr; // vi05 + Vf* dbuf_write; // vi06 + Vf* tptr; // vi08 + Vf* tbase; // vi09 + } vu; + + enum TexVu1Data { + BUF0 = 384, + BUF1 = 583, + DEST0 = 782, + DEST1 = 881, + CONSTANTS = 985, + }; + + enum TexVu1Prog { START = 0, REST = 2, DONE = 4 }; + + static constexpr int NUM_FRAG_LOOPS = 9; +}; diff --git a/goal_src/engine/draw/drawable.gc b/goal_src/engine/draw/drawable.gc index d4c16a3878..0a4ecf9b9a 100644 --- a/goal_src/engine/draw/drawable.gc +++ b/goal_src/engine/draw/drawable.gc @@ -1048,7 +1048,7 @@ (update-time-of-day *time-of-day-context*) ;; closest (update-ocean) - ;; (draw-ocean) + (draw-ocean) (set! (-> *merc-global-array* count) (the-as uint 0)) (set! *merc-globals* (the-as merc-globals (-> *merc-global-array* globals))) (set! (-> *shadow-queue* cur-run) (the-as uint 0)) diff --git a/goal_src/engine/gfx/ocean/ocean-h.gc b/goal_src/engine/gfx/ocean/ocean-h.gc index e323484cfb..b0e69e38f0 100644 --- a/goal_src/engine/gfx/ocean/ocean-h.gc +++ b/goal_src/engine/gfx/ocean/ocean-h.gc @@ -9,6 +9,7 @@ (define-extern ocean-get-height (function vector float)) (define-extern update-ocean (function none)) (define-extern draw-ocean (function none)) +(define-extern draw-ocean-texture (function dma-buffer (inline-array vector) symbol none)) ;; The "ocean" renderer is used to render the infinite water. ;; It doesn't draw the rivers in FJ or the water near the farmer. diff --git a/goal_src/engine/gfx/ocean/ocean-texture.gc b/goal_src/engine/gfx/ocean/ocean-texture.gc index b700671ea7..693499ca51 100644 --- a/goal_src/engine/gfx/ocean/ocean-texture.gc +++ b/goal_src/engine/gfx/ocean/ocean-texture.gc @@ -48,15 +48,17 @@ ) ;; definition for symbol ocean-texture-vu1-block, type vu-function -(define ocean-texture-vu1-block (new 'static 'vu-function :length #x92 :qlength 73)) +(define ocean-texture-vu1-block (new 'static 'vu-function #|:length #x92 :qlength 73|#)) -;; definition for function ocean-texture-setup-constants -;; INFO: Return type mismatch int vs none. (defun ocean-texture-setup-constants ((arg0 ocean-texture-constants)) + "Set the constant values used in Ocean Texture VU1 program." (set! (-> arg0 giftag dword 0) (make-u128 0 (the-as uint #x300e400000008042))) (set! (-> arg0 giftag dword 1) (the-as uint 1298)) + + ;; these are VU1 data addresses (set-vector! (-> arg0 buffers) 384 583 384 583) (set-vector! (-> arg0 dests) 782 881 782 881) + (set-vector! (-> arg0 start) 0.0 0.0 1048575.94 0.0) (set-vector! (-> arg0 offsets) 4.0 8.0 12.0 16.0) (set-vector! (-> arg0 constants) 0.5 0.5 0.0 0.0) @@ -68,8 +70,8 @@ (none) ) -;; definition for function ocean-texture-add-constants (defun ocean-texture-add-constants ((arg0 dma-buffer)) + "Add DMA packet to upload ocean constants. The constants are stored in the DMA buffer." (let* ((a1-0 7) (v1-0 arg0) (a0-1 (the-as object (-> v1-0 base))) @@ -91,10 +93,13 @@ ;; definition for function ocean-texture-add-envmap ;; Used lq/sq (defun ocean-texture-add-envmap ((arg0 dma-buffer)) + "Add DMA packet to set up the GS with the env map texture's ADGIF shader." (let ((v1-0 (-> arg0 base))) + ;; DMA template for ADGIF setup. (set! (-> (the-as (pointer uint128) v1-0) 0) (-> *ocean-texture-work* adgif-tmpl dma-vif quad)) (set! (-> (the-as (pointer uint128) v1-0) 1) (-> *ocean-texture-work* adgif-tmpl quad 1)) (let ((s4-0 (&+ v1-0 32))) + ;; this just stores the adgif directly in the DMA buffer (adgif-shader<-texture-simple! (the-as adgif-shader s4-0) (lookup-texture-by-id (new 'static 'texture-id :index #x1 :page #x100)) @@ -108,7 +113,7 @@ ) ;; definition for function ocean-texture-add-verts -(defun ocean-texture-add-verts ((arg0 dma-buffer) (arg1 (pointer vector))) +(defun ocean-texture-add-verts ((arg0 dma-buffer) (arg1 (inline-array vector))) (let* ((v1-0 arg0) (a0-1 (the-as object (-> v1-0 base))) ) @@ -127,7 +132,7 @@ ) ;; definition for function ocean-texture-add-verts-last -(defun ocean-texture-add-verts-last ((arg0 dma-buffer) (arg1 (pointer vector)) (arg2 (pointer vector))) +(defun ocean-texture-add-verts-last ((arg0 dma-buffer) (arg1 (inline-array vector)) (arg2 (inline-array vector))) (let* ((v1-0 arg0) (a3-0 (the-as object (-> v1-0 base))) ) @@ -202,18 +207,18 @@ ;; definition for function draw-ocean-texture ;; INFO: Return type mismatch int vs none. ;; Used lq/sq -(defun draw-ocean-texture ((arg0 dma-buffer) (arg1 (pointer vector)) (arg2 symbol)) - (local-vars (sv-16 (pointer vector)) (sv-32 int) (sv-48 (pointer vector)) (sv-64 (pointer vector))) +(defun draw-ocean-texture ((arg0 dma-buffer) (arg1 (inline-array vector)) (arg2 symbol)) + (local-vars (sv-16 (inline-array vector)) (sv-32 int) (sv-48 vector) (sv-64 (inline-array vector))) (set! sv-64 arg1) (let* ((s0-0 arg2) - (a1-1 *ocean-base-page*) - (s2-0 *ocean-base-block*) - (s1-0 (+ a1-1 8)) - (s4-0 (* s1-0 32)) - (s3-0 (+ a1-1 10)) - (s5-0 (* s3-0 32)) + (ocean-tex-page-0 *ocean-base-page*) + (ocean-tex-block-0 *ocean-base-block*) + (ocean-tex-page-1 (+ ocean-tex-page-0 8)) + (ocean-tex-block-1 (* ocean-tex-page-1 32)) + (ocean-tex-page-2 (+ ocean-tex-page-0 10)) + (ocean-tex-block-2 (* ocean-tex-page-2 32)) ) - (set-display-gs-state arg0 a1-1 128 128 0 0) + (set-display-gs-state arg0 ocean-tex-page-0 128 128 0 0) (dma-buffer-add-vu-function arg0 ocean-texture-vu1-block 1) (let* ((v1-0 arg0) (a0-3 (the-as object (-> v1-0 base))) @@ -227,376 +232,372 @@ (ocean-texture-add-envmap arg0) (set! sv-16 sv-64) (ocean-texture-add-verts arg0 sv-16) - (set! sv-48 (&-> sv-16 768)) + (set! sv-48 (-> sv-16 192)) (ocean-texture-add-call-start arg0) (set! sv-32 0) (while (< sv-32 9) - (ocean-texture-add-verts arg0 sv-48) - (set! sv-48 (&-> sv-48 768)) + (ocean-texture-add-verts arg0 (the-as (inline-array vector) sv-48)) + (set! sv-48 (-> (the-as (inline-array vector) sv-48) 192)) (ocean-texture-add-call-rest arg0) (set! sv-32 (+ sv-32 1)) ) - (ocean-texture-add-verts-last arg0 sv-48 sv-64) + (ocean-texture-add-verts-last arg0 (the-as (inline-array vector) sv-48) sv-64) (ocean-texture-add-call-rest arg0) (ocean-texture-add-call-done arg0) - (when s0-0 - (set-display-gs-state arg0 s1-0 64 64 0 0) - (let* ((v1-13 arg0) - (a0-15 (the-as object (-> v1-13 base))) - ) - (set! (-> (the-as dma-packet a0-15) dma) (new 'static 'dma-tag :qwc #x7 :id (dma-tag-id cnt))) - (set! (-> (the-as dma-packet a0-15) vif0) (new 'static 'vif-tag)) - (set! (-> (the-as dma-packet a0-15) vif1) (new 'static 'vif-tag :imm #x7 :cmd (vif-cmd direct) :msk #x1)) - (set! (-> v1-13 base) (&+ (the-as pointer a0-15) 16)) - ) - (let* ((v1-14 arg0) - (a0-17 (the-as object (-> v1-14 base))) - ) - (set! (-> (the-as gs-gif-tag a0-17) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x6)) - (set! (-> (the-as gs-gif-tag a0-17) regs) - (new 'static 'gif-tag-regs - :regs0 (gif-reg-id a+d) - :regs1 (gif-reg-id a+d) - :regs2 (gif-reg-id a+d) - :regs3 (gif-reg-id a+d) - :regs4 (gif-reg-id a+d) - :regs5 (gif-reg-id a+d) - :regs6 (gif-reg-id a+d) - :regs7 (gif-reg-id a+d) - :regs8 (gif-reg-id a+d) - :regs9 (gif-reg-id a+d) - :regs10 (gif-reg-id a+d) - :regs11 (gif-reg-id a+d) - :regs12 (gif-reg-id a+d) - :regs13 (gif-reg-id a+d) - :regs14 (gif-reg-id a+d) - :regs15 (gif-reg-id a+d) - ) - ) - (set! (-> v1-14 base) (&+ (the-as pointer a0-17) 16)) - ) - (let* ((s1-1 arg0) - (s0-1 (-> s1-1 base)) - ) - (set! (-> (the-as (pointer gs-test) s0-1) 0) - (new 'static 'gs-test :ate #x1 :atst (gs-atest always) :zte #x1 :ztst (gs-ztest always)) - ) - (set! (-> (the-as (pointer gs-reg64) s0-1) 1) (gs-reg64 test-1)) - (set! (-> (the-as (pointer gs-alpha) s0-1) 2) (new 'static 'gs-alpha :b #x1 :d #x1)) - (set! (-> (the-as (pointer gs-reg64) s0-1) 3) (gs-reg64 alpha-1)) - (set! (-> (the-as (pointer gs-tex0) s0-1) 4) - (new 'static 'gs-tex0 :tbw #x2 :tcc #x1 :th (log2 128) :tw (log2 128) :tbp0 s2-0) - ) - (set! (-> (the-as (pointer gs-reg64) s0-1) 5) (gs-reg64 tex0-1)) - (set! (-> (the-as (pointer gs-tex1) s0-1) 6) (new 'static 'gs-tex1 :mmag #x1 :mmin #x1)) - (set! (-> (the-as (pointer gs-reg64) s0-1) 7) (gs-reg64 tex1-1)) - (set! (-> (the-as (pointer gs-clamp) s0-1) 8) (new 'static 'gs-clamp)) - (set! (-> (the-as (pointer gs-reg64) s0-1) 9) (gs-reg64 clamp-1)) - (set! (-> (the-as (pointer uint64) s0-1) 10) (the-as uint 0)) - (set! (-> (the-as (pointer gs-reg64) s0-1) 11) (gs-reg64 texflush)) - (set! (-> s1-1 base) (&+ s0-1 96)) - ) - (let ((v1-31 (-> arg0 base))) - (set! (-> (the-as (pointer uint128) v1-31) 0) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) - (set! (-> (the-as (pointer uint128) v1-31) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) - (set-vector! (the-as vector4w (&+ v1-31 32)) 128 128 128 64) - (set-vector! (the-as vector4w (&+ v1-31 48)) 0 0 0 0) - (set-vector! (the-as vector4w (&+ v1-31 64)) 0 0 #xffffff 0) - (set-vector! (the-as vector4w (&+ v1-31 80)) 2048 2048 0 0) - (set-vector! (the-as vector4w (&+ v1-31 96)) 1024 1024 #xffffff 0) - ) - (&+! (-> arg0 base) 112) - (set-display-gs-state arg0 s3-0 64 32 0 0) - (let* ((v1-35 arg0) - (a0-35 (the-as object (-> v1-35 base))) - ) - (set! (-> (the-as dma-packet a0-35) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) - (set! (-> (the-as dma-packet a0-35) vif0) (new 'static 'vif-tag)) - (set! (-> (the-as dma-packet a0-35) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) - (set! (-> v1-35 base) (&+ (the-as pointer a0-35) 16)) - ) - (let* ((v1-36 arg0) - (a0-37 (the-as object (-> v1-36 base))) - ) - (set! (-> (the-as gs-gif-tag a0-37) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) - (set! (-> (the-as gs-gif-tag a0-37) regs) - (new 'static 'gif-tag-regs - :regs0 (gif-reg-id a+d) - :regs1 (gif-reg-id a+d) - :regs2 (gif-reg-id a+d) - :regs3 (gif-reg-id a+d) - :regs4 (gif-reg-id a+d) - :regs5 (gif-reg-id a+d) - :regs6 (gif-reg-id a+d) - :regs7 (gif-reg-id a+d) - :regs8 (gif-reg-id a+d) - :regs9 (gif-reg-id a+d) - :regs10 (gif-reg-id a+d) - :regs11 (gif-reg-id a+d) - :regs12 (gif-reg-id a+d) - :regs13 (gif-reg-id a+d) - :regs14 (gif-reg-id a+d) - :regs15 (gif-reg-id a+d) - ) - ) - (set! (-> v1-36 base) (&+ (the-as pointer a0-37) 16)) - ) - (let* ((s3-1 arg0) - (s2-3 (-> s3-1 base)) - ) - (set! (-> (the-as (pointer gs-tex0) s2-3) 0) - (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 64) :tw (log2 64) :tbp0 s4-0) - ) - (set! (-> (the-as (pointer gs-reg64) s2-3) 1) (gs-reg64 tex0-1)) - (set! (-> (the-as (pointer uint64) s2-3) 2) (the-as uint 0)) - (set! (-> (the-as (pointer gs-reg64) s2-3) 3) (gs-reg64 texflush)) - (set! (-> s3-1 base) (&+ s2-3 32)) - ) - (let ((v1-46 (-> arg0 base))) - (set! (-> (the-as (pointer uint128) v1-46)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) - (set! (-> (the-as (pointer uint128) v1-46) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) - (set-vector! (the-as vector4w (&+ v1-46 32)) 128 128 128 0) - (set-vector! (the-as vector4w (&+ v1-46 48)) 0 0 0 0) - (set-vector! (the-as vector4w (&+ v1-46 64)) 0 0 #xffffff 0) - (set-vector! (the-as vector4w (&+ v1-46 80)) 1024 1024 0 0) - (set-vector! (the-as vector4w (&+ v1-46 96)) 512 512 #xffffff 0) - ) - (&+! (-> arg0 base) 112) - (let* ((v1-50 arg0) - (a0-54 (the-as object (-> v1-50 base))) - ) - (set! (-> (the-as dma-packet a0-54) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) - (set! (-> (the-as dma-packet a0-54) vif0) (new 'static 'vif-tag)) - (set! (-> (the-as dma-packet a0-54) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) - (set! (-> v1-50 base) (&+ (the-as pointer a0-54) 16)) - ) - (let* ((v1-51 arg0) - (a0-56 (the-as object (-> v1-51 base))) - ) - (set! (-> (the-as gs-gif-tag a0-56) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) - (set! (-> (the-as gs-gif-tag a0-56) regs) - (new 'static 'gif-tag-regs - :regs0 (gif-reg-id a+d) - :regs1 (gif-reg-id a+d) - :regs2 (gif-reg-id a+d) - :regs3 (gif-reg-id a+d) - :regs4 (gif-reg-id a+d) - :regs5 (gif-reg-id a+d) - :regs6 (gif-reg-id a+d) - :regs7 (gif-reg-id a+d) - :regs8 (gif-reg-id a+d) - :regs9 (gif-reg-id a+d) - :regs10 (gif-reg-id a+d) - :regs11 (gif-reg-id a+d) - :regs12 (gif-reg-id a+d) - :regs13 (gif-reg-id a+d) - :regs14 (gif-reg-id a+d) - :regs15 (gif-reg-id a+d) - ) - ) - (set! (-> v1-51 base) (&+ (the-as pointer a0-56) 16)) - ) - (let* ((s4-3 arg0) - (s3-2 (-> s4-3 base)) - ) - (set! (-> (the-as (pointer gs-tex0) s3-2) 0) - (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 32) :tw (log2 32) :tbp0 s5-0) - ) - (set! (-> (the-as (pointer gs-reg64) s3-2) 1) (gs-reg64 tex0-1)) - (set! (-> (the-as (pointer uint64) s3-2) 2) (the-as uint 0)) - (set! (-> (the-as (pointer gs-reg64) s3-2) 3) (gs-reg64 texflush)) - (set! (-> s4-3 base) (&+ s3-2 32)) - ) - (let ((v1-61 (-> arg0 base))) - (set! (-> (the-as (pointer uint128) v1-61)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) - (set! (-> (the-as (pointer uint128) v1-61) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) - (set-vector! (the-as vector4w (&+ v1-61 32)) 128 128 128 0) - (set-vector! (the-as vector4w (&+ v1-61 48)) 0 0 0 0) - (set-vector! (the-as vector4w (&+ v1-61 64)) 512 0 #xffffff 0) - (set-vector! (the-as vector4w (&+ v1-61 80)) 512 512 0 0) - (set-vector! (the-as vector4w (&+ v1-61 96)) 768 256 #xffffff 0) - ) - (&+! (-> arg0 base) 112) - (let* ((v1-65 arg0) - (a0-73 (the-as object (-> v1-65 base))) - ) - (set! (-> (the-as dma-packet a0-73) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) - (set! (-> (the-as dma-packet a0-73) vif0) (new 'static 'vif-tag)) - (set! (-> (the-as dma-packet a0-73) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) - (set! (-> v1-65 base) (&+ (the-as pointer a0-73) 16)) - ) - (let* ((v1-66 arg0) - (a0-75 (the-as object (-> v1-66 base))) - ) - (set! (-> (the-as gs-gif-tag a0-75) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) - (set! (-> (the-as gs-gif-tag a0-75) regs) - (new 'static 'gif-tag-regs - :regs0 (gif-reg-id a+d) - :regs1 (gif-reg-id a+d) - :regs2 (gif-reg-id a+d) - :regs3 (gif-reg-id a+d) - :regs4 (gif-reg-id a+d) - :regs5 (gif-reg-id a+d) - :regs6 (gif-reg-id a+d) - :regs7 (gif-reg-id a+d) - :regs8 (gif-reg-id a+d) - :regs9 (gif-reg-id a+d) - :regs10 (gif-reg-id a+d) - :regs11 (gif-reg-id a+d) - :regs12 (gif-reg-id a+d) - :regs13 (gif-reg-id a+d) - :regs14 (gif-reg-id a+d) - :regs15 (gif-reg-id a+d) - ) - ) - (set! (-> v1-66 base) (&+ (the-as pointer a0-75) 16)) - ) - (let* ((s4-4 arg0) - (s3-3 (-> s4-4 base)) - ) - (set! (-> (the-as (pointer gs-tex0) s3-3) 0) - (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 16) :tw (log2 16) :tbp0 (+ s5-0 16)) - ) - (set! (-> (the-as (pointer gs-reg64) s3-3) 1) (gs-reg64 tex0-1)) - (set! (-> (the-as (pointer uint64) s3-3) 2) (the-as uint 0)) - (set! (-> (the-as (pointer gs-reg64) s3-3) 3) (gs-reg64 texflush)) - (set! (-> s4-4 base) (&+ s3-3 32)) - ) - (let ((v1-76 (-> arg0 base))) - (set! (-> (the-as (pointer uint128) v1-76)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) - (set! (-> (the-as (pointer uint128) v1-76) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) - (set-vector! (the-as vector4w (&+ v1-76 32)) 128 128 128 0) - (set-vector! (the-as vector4w (&+ v1-76 48)) 0 0 0 0) - (set-vector! (the-as vector4w (&+ v1-76 64)) 768 0 #xffffff 0) - (set-vector! (the-as vector4w (&+ v1-76 80)) 256 256 0 0) - (set-vector! (the-as vector4w (&+ v1-76 96)) 896 128 #xffffff 0) - ) - (&+! (-> arg0 base) 112) - (let* ((v1-80 arg0) - (a0-93 (the-as object (-> v1-80 base))) - ) - (set! (-> (the-as dma-packet a0-93) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) - (set! (-> (the-as dma-packet a0-93) vif0) (new 'static 'vif-tag)) - (set! (-> (the-as dma-packet a0-93) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) - (set! (-> v1-80 base) (&+ (the-as pointer a0-93) 16)) - ) - (let* ((v1-81 arg0) - (a0-95 (the-as object (-> v1-81 base))) - ) - (set! (-> (the-as gs-gif-tag a0-95) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) - (set! (-> (the-as gs-gif-tag a0-95) regs) - (new 'static 'gif-tag-regs - :regs0 (gif-reg-id a+d) - :regs1 (gif-reg-id a+d) - :regs2 (gif-reg-id a+d) - :regs3 (gif-reg-id a+d) - :regs4 (gif-reg-id a+d) - :regs5 (gif-reg-id a+d) - :regs6 (gif-reg-id a+d) - :regs7 (gif-reg-id a+d) - :regs8 (gif-reg-id a+d) - :regs9 (gif-reg-id a+d) - :regs10 (gif-reg-id a+d) - :regs11 (gif-reg-id a+d) - :regs12 (gif-reg-id a+d) - :regs13 (gif-reg-id a+d) - :regs14 (gif-reg-id a+d) - :regs15 (gif-reg-id a+d) - ) - ) - (set! (-> v1-81 base) (&+ (the-as pointer a0-95) 16)) - ) - (let* ((s4-5 arg0) - (s3-4 (-> s4-5 base)) - ) - (set! (-> (the-as (pointer gs-tex0) s3-4) 0) - (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 8) :tw (log2 8) :tbp0 (+ s5-0 20)) - ) - (set! (-> (the-as (pointer gs-reg64) s3-4) 1) (gs-reg64 tex0-1)) - (set! (-> (the-as (pointer uint64) s3-4) 2) (the-as uint 0)) - (set! (-> (the-as (pointer gs-reg64) s3-4) 3) (gs-reg64 texflush)) - (set! (-> s4-5 base) (&+ s3-4 32)) - ) - (let ((v1-91 (-> arg0 base))) - (set! (-> (the-as (pointer uint128) v1-91)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) - (set! (-> (the-as (pointer uint128) v1-91) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) - (set-vector! (the-as vector4w (&+ v1-91 32)) 128 128 128 0) - (set-vector! (the-as vector4w (&+ v1-91 48)) 0 0 0 0) - (set-vector! (the-as vector4w (&+ v1-91 64)) 896 0 #xffffff 0) - (set-vector! (the-as vector4w (&+ v1-91 80)) 256 256 0 0) - (set-vector! (the-as vector4w (&+ v1-91 96)) 1024 128 #xffffff 0) - ) - (&+! (-> arg0 base) 112) - (let* ((v1-95 arg0) - (a0-113 (the-as object (-> v1-95 base))) - ) - (set! (-> (the-as dma-packet a0-113) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) - (set! (-> (the-as dma-packet a0-113) vif0) (new 'static 'vif-tag)) - (set! (-> (the-as dma-packet a0-113) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) - (set! (-> v1-95 base) (&+ (the-as pointer a0-113) 16)) - ) - (let* ((v1-96 arg0) - (a0-115 (the-as object (-> v1-96 base))) - ) - (set! (-> (the-as gs-gif-tag a0-115) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) - (set! (-> (the-as gs-gif-tag a0-115) regs) - (new 'static 'gif-tag-regs - :regs0 (gif-reg-id a+d) - :regs1 (gif-reg-id a+d) - :regs2 (gif-reg-id a+d) - :regs3 (gif-reg-id a+d) - :regs4 (gif-reg-id a+d) - :regs5 (gif-reg-id a+d) - :regs6 (gif-reg-id a+d) - :regs7 (gif-reg-id a+d) - :regs8 (gif-reg-id a+d) - :regs9 (gif-reg-id a+d) - :regs10 (gif-reg-id a+d) - :regs11 (gif-reg-id a+d) - :regs12 (gif-reg-id a+d) - :regs13 (gif-reg-id a+d) - :regs14 (gif-reg-id a+d) - :regs15 (gif-reg-id a+d) - ) - ) - (set! (-> v1-96 base) (&+ (the-as pointer a0-115) 16)) - ) - (let* ((s4-6 arg0) - (s3-5 (-> s4-6 base)) - ) - (set! (-> (the-as (pointer gs-tex0) s3-5) 0) - (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 4) :tw (log2 4) :tbp0 (+ s5-0 21)) - ) - (set! (-> (the-as (pointer gs-reg64) s3-5) 1) (gs-reg64 tex0-1)) - (set! (-> (the-as (pointer uint64) s3-5) 2) (the-as uint 0)) - (set! (-> (the-as (pointer gs-reg64) s3-5) 3) (gs-reg64 texflush)) - (set! (-> s4-6 base) (&+ s3-5 32)) - ) - (let ((v1-106 (-> arg0 base))) - (set! (-> (the-as (pointer uint128) v1-106)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) - (set! (-> (the-as (pointer uint128) v1-106) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) - (set-vector! (the-as vector4w (&+ v1-106 32)) 128 128 128 0) - (set-vector! (the-as vector4w (&+ v1-106 48)) 0 0 0 0) - (set-vector! (the-as vector4w (&+ v1-106 64)) 768 128 #xffffff 0) - (set-vector! (the-as vector4w (&+ v1-106 80)) 512 512 0 0) - (set-vector! (the-as vector4w (&+ v1-106 96)) 896 256 #xffffff 0) - ) - (&+! (-> arg0 base) 112) - (let* ((v1-110 arg0) - (a0-133 (the-as object (-> v1-110 base))) - ) - (set! (-> (the-as dma-packet a0-133) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) - (set! (-> (the-as dma-packet a0-133) vif0) (new 'static 'vif-tag :cmd (vif-cmd flush) :msk #x1)) - (set! (-> (the-as dma-packet a0-133) vif1) (new 'static 'vif-tag)) - (set! (-> v1-110 base) (&+ (the-as pointer a0-133) 16)) - ) - ) + ; (when s0-0 + ; (set-display-gs-state arg0 ocean-tex-page-1 64 64 0 0) + ; (let* ((v1-13 arg0) + ; (a0-15 (the-as object (-> v1-13 base))) + ; ) + ; (set! (-> (the-as dma-packet a0-15) dma) (new 'static 'dma-tag :qwc #x7 :id (dma-tag-id cnt))) + ; (set! (-> (the-as dma-packet a0-15) vif0) (new 'static 'vif-tag)) + ; (set! (-> (the-as dma-packet a0-15) vif1) (new 'static 'vif-tag :imm #x7 :cmd (vif-cmd direct) :msk #x1)) + ; (set! (-> v1-13 base) (&+ (the-as pointer a0-15) 16)) + ; ) + ; (let* ((v1-14 arg0) + ; (a0-17 (the-as object (-> v1-14 base))) + ; ) + ; (set! (-> (the-as gs-gif-tag a0-17) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x6)) + ; (set! (-> (the-as gs-gif-tag a0-17) regs) + ; (new 'static 'gif-tag-regs + ; :regs0 (gif-reg-id a+d) + ; :regs1 (gif-reg-id a+d) + ; :regs2 (gif-reg-id a+d) + ; :regs3 (gif-reg-id a+d) + ; :regs4 (gif-reg-id a+d) + ; :regs5 (gif-reg-id a+d) + ; :regs6 (gif-reg-id a+d) + ; :regs7 (gif-reg-id a+d) + ; :regs8 (gif-reg-id a+d) + ; :regs9 (gif-reg-id a+d) + ; :regs10 (gif-reg-id a+d) + ; :regs11 (gif-reg-id a+d) + ; :regs12 (gif-reg-id a+d) + ; :regs13 (gif-reg-id a+d) + ; :regs14 (gif-reg-id a+d) + ; :regs15 (gif-reg-id a+d) + ; ) + ; ) + ; (set! (-> v1-14 base) (&+ (the-as pointer a0-17) 16)) + ; ) + ; (let* ((s1-1 arg0) + ; (s0-1 (-> s1-1 base)) + ; ) + ; (set! (-> (the-as (pointer gs-test) s0-1) 0) + ; (new 'static 'gs-test :ate #x1 :atst (gs-atest always) :zte #x1 :ztst (gs-ztest always)) + ; ) + ; (set! (-> (the-as (pointer gs-reg64) s0-1) 1) (gs-reg64 test-1)) + ; (set! (-> (the-as (pointer gs-alpha) s0-1) 2) (new 'static 'gs-alpha :b #x1 :d #x1)) + ; (set! (-> (the-as (pointer gs-reg64) s0-1) 3) (gs-reg64 alpha-1)) + ; (set! (-> (the-as (pointer gs-tex0) s0-1) 4) + ; (new 'static 'gs-tex0 :tbw #x2 :tcc #x1 :th (log2 128) :tw (log2 128) :tbp0 ocean-tex-block-0) + ; ) + ; (set! (-> (the-as (pointer gs-reg64) s0-1) 5) (gs-reg64 tex0-1)) + ; (set! (-> (the-as (pointer gs-tex1) s0-1) 6) (new 'static 'gs-tex1 :mmag #x1 :mmin #x1)) + ; (set! (-> (the-as (pointer gs-reg64) s0-1) 7) (gs-reg64 tex1-1)) + ; (set! (-> (the-as (pointer gs-clamp) s0-1) 8) (new 'static 'gs-clamp)) + ; (set! (-> (the-as (pointer gs-reg64) s0-1) 9) (gs-reg64 clamp-1)) + ; (set! (-> (the-as (pointer uint64) s0-1) 10) (the-as uint 0)) + ; (set! (-> (the-as (pointer gs-reg64) s0-1) 11) (gs-reg64 texflush)) + ; (set! (-> s1-1 base) (&+ s0-1 96)) + ; ) + ; (let ((v1-31 (-> arg0 base))) + ; (set! (-> (the-as (pointer uint128) v1-31) 0) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + ; (set! (-> (the-as (pointer uint128) v1-31) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + ; (set-vector! (the-as vector4w (&+ v1-31 32)) 128 128 128 64) + ; (set-vector! (the-as vector4w (&+ v1-31 48)) 0 0 0 0) + ; (set-vector! (the-as vector4w (&+ v1-31 64)) 0 0 #xffffff 0) + ; (set-vector! (the-as vector4w (&+ v1-31 80)) 2048 2048 0 0) + ; (set-vector! (the-as vector4w (&+ v1-31 96)) 1024 1024 #xffffff 0) + ; ) + ; (&+! (-> arg0 base) 112) + ; (set-display-gs-state arg0 ocean-tex-page-2 64 32 0 0) + ; (let* ((v1-35 arg0) + ; (a0-35 (the-as object (-> v1-35 base))) + ; ) + ; (set! (-> (the-as dma-packet a0-35) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + ; (set! (-> (the-as dma-packet a0-35) vif0) (new 'static 'vif-tag)) + ; (set! (-> (the-as dma-packet a0-35) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + ; (set! (-> v1-35 base) (&+ (the-as pointer a0-35) 16)) + ; ) + ; (let* ((v1-36 arg0) + ; (a0-37 (the-as object (-> v1-36 base))) + ; ) + ; (set! (-> (the-as gs-gif-tag a0-37) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + ; (set! (-> (the-as gs-gif-tag a0-37) regs) + ; (new 'static 'gif-tag-regs + ; :regs0 (gif-reg-id a+d) + ; :regs1 (gif-reg-id a+d) + ; :regs2 (gif-reg-id a+d) + ; :regs3 (gif-reg-id a+d) + ; :regs4 (gif-reg-id a+d) + ; :regs5 (gif-reg-id a+d) + ; :regs6 (gif-reg-id a+d) + ; :regs7 (gif-reg-id a+d) + ; :regs8 (gif-reg-id a+d) + ; :regs9 (gif-reg-id a+d) + ; :regs10 (gif-reg-id a+d) + ; :regs11 (gif-reg-id a+d) + ; :regs12 (gif-reg-id a+d) + ; :regs13 (gif-reg-id a+d) + ; :regs14 (gif-reg-id a+d) + ; :regs15 (gif-reg-id a+d) + ; ) + ; ) + ; (set! (-> v1-36 base) (&+ (the-as pointer a0-37) 16)) + ; ) + ; (let* ((s3-1 arg0) + ; (s2-3 (-> s3-1 base)) + ; ) + ; (set! (-> (the-as (pointer gs-tex0) s2-3) 0) + ; (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 64) :tw (log2 64) :tbp0 ocean-tex-block-1) + ; ) + ; (set! (-> (the-as (pointer gs-reg64) s2-3) 1) (gs-reg64 tex0-1)) + ; (set! (-> (the-as (pointer uint64) s2-3) 2) (the-as uint 0)) + ; (set! (-> (the-as (pointer gs-reg64) s2-3) 3) (gs-reg64 texflush)) + ; (set! (-> s3-1 base) (&+ s2-3 32)) + ; ) + ; (let ((v1-46 (-> arg0 base))) + ; (set! (-> (the-as (pointer uint128) v1-46)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + ; (set! (-> (the-as (pointer uint128) v1-46) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + ; (set-vector! (the-as vector4w (&+ v1-46 32)) 128 128 128 0) + ; (set-vector! (the-as vector4w (&+ v1-46 48)) 0 0 0 0) + ; (set-vector! (the-as vector4w (&+ v1-46 64)) 0 0 #xffffff 0) + ; (set-vector! (the-as vector4w (&+ v1-46 80)) 1024 1024 0 0) + ; (set-vector! (the-as vector4w (&+ v1-46 96)) 512 512 #xffffff 0) + ; ) + ; (&+! (-> arg0 base) 112) + ; (let* ((v1-50 arg0) + ; (a0-54 (the-as object (-> v1-50 base))) + ; ) + ; (set! (-> (the-as dma-packet a0-54) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + ; (set! (-> (the-as dma-packet a0-54) vif0) (new 'static 'vif-tag)) + ; (set! (-> (the-as dma-packet a0-54) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + ; (set! (-> v1-50 base) (&+ (the-as pointer a0-54) 16)) + ; ) + ; (let* ((v1-51 arg0) + ; (a0-56 (the-as object (-> v1-51 base))) + ; ) + ; (set! (-> (the-as gs-gif-tag a0-56) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + ; (set! (-> (the-as gs-gif-tag a0-56) regs) + ; (new 'static 'gif-tag-regs + ; :regs0 (gif-reg-id a+d) + ; :regs1 (gif-reg-id a+d) + ; :regs2 (gif-reg-id a+d) + ; :regs3 (gif-reg-id a+d) + ; :regs4 (gif-reg-id a+d) + ; :regs5 (gif-reg-id a+d) + ; :regs6 (gif-reg-id a+d) + ; :regs7 (gif-reg-id a+d) + ; :regs8 (gif-reg-id a+d) + ; :regs9 (gif-reg-id a+d) + ; :regs10 (gif-reg-id a+d) + ; :regs11 (gif-reg-id a+d) + ; :regs12 (gif-reg-id a+d) + ; :regs13 (gif-reg-id a+d) + ; :regs14 (gif-reg-id a+d) + ; :regs15 (gif-reg-id a+d) + ; ) + ; ) + ; (set! (-> v1-51 base) (&+ (the-as pointer a0-56) 16)) + ; ) + ; (let* ((s4-3 arg0) + ; (s3-2 (-> s4-3 base)) + ; ) + ; (set! (-> (the-as (pointer gs-tex0) s3-2) 0) + ; (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 32) :tw (log2 32) :tbp0 ocean-tex-block-2) + ; ) + ; (set! (-> (the-as (pointer gs-reg64) s3-2) 1) (gs-reg64 tex0-1)) + ; (set! (-> (the-as (pointer uint64) s3-2) 2) (the-as uint 0)) + ; (set! (-> (the-as (pointer gs-reg64) s3-2) 3) (gs-reg64 texflush)) + ; (set! (-> s4-3 base) (&+ s3-2 32)) + ; ) + ; (let ((v1-61 (-> arg0 base))) + ; (set! (-> (the-as (pointer uint128) v1-61)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + ; (set! (-> (the-as (pointer uint128) v1-61) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + ; (set-vector! (the-as vector4w (&+ v1-61 32)) 128 128 128 0) + ; (set-vector! (the-as vector4w (&+ v1-61 48)) 0 0 0 0) + ; (set-vector! (the-as vector4w (&+ v1-61 64)) 512 0 #xffffff 0) + ; (set-vector! (the-as vector4w (&+ v1-61 80)) 512 512 0 0) + ; (set-vector! (the-as vector4w (&+ v1-61 96)) 768 256 #xffffff 0) + ; ) + ; (&+! (-> arg0 base) 112) + ; (let* ((v1-65 arg0) + ; (a0-73 (the-as object (-> v1-65 base))) + ; ) + ; (set! (-> (the-as dma-packet a0-73) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + ; (set! (-> (the-as dma-packet a0-73) vif0) (new 'static 'vif-tag)) + ; (set! (-> (the-as dma-packet a0-73) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + ; (set! (-> v1-65 base) (&+ (the-as pointer a0-73) 16)) + ; ) + ; (let* ((v1-66 arg0) + ; (a0-75 (the-as object (-> v1-66 base))) + ; ) + ; (set! (-> (the-as gs-gif-tag a0-75) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + ; (set! (-> (the-as gs-gif-tag a0-75) regs) + ; (new 'static 'gif-tag-regs + ; :regs0 (gif-reg-id a+d) + ; :regs1 (gif-reg-id a+d) + ; :regs2 (gif-reg-id a+d) + ; :regs3 (gif-reg-id a+d) + ; :regs4 (gif-reg-id a+d) + ; :regs5 (gif-reg-id a+d) + ; :regs6 (gif-reg-id a+d) + ; :regs7 (gif-reg-id a+d) + ; :regs8 (gif-reg-id a+d) + ; :regs9 (gif-reg-id a+d) + ; :regs10 (gif-reg-id a+d) + ; :regs11 (gif-reg-id a+d) + ; :regs12 (gif-reg-id a+d) + ; :regs13 (gif-reg-id a+d) + ; :regs14 (gif-reg-id a+d) + ; :regs15 (gif-reg-id a+d) + ; ) + ; ) + ; (set! (-> v1-66 base) (&+ (the-as pointer a0-75) 16)) + ; ) + ; (let* ((s4-4 arg0) + ; (s3-3 (-> s4-4 base)) + ; ) + ; (set! (-> (the-as (pointer gs-tex0) s3-3) 0) + ; (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 16) :tw (log2 16) :tbp0 (+ ocean-tex-block-2 16)) + ; ) + ; (set! (-> (the-as (pointer gs-reg64) s3-3) 1) (gs-reg64 tex0-1)) + ; (set! (-> (the-as (pointer uint64) s3-3) 2) (the-as uint 0)) + ; (set! (-> (the-as (pointer gs-reg64) s3-3) 3) (gs-reg64 texflush)) + ; (set! (-> s4-4 base) (&+ s3-3 32)) + ; ) + ; (let ((v1-76 (-> arg0 base))) + ; (set! (-> (the-as (pointer uint128) v1-76)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + ; (set! (-> (the-as (pointer uint128) v1-76) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + ; (set-vector! (the-as vector4w (&+ v1-76 32)) 128 128 128 0) + ; (set-vector! (the-as vector4w (&+ v1-76 48)) 0 0 0 0) + ; (set-vector! (the-as vector4w (&+ v1-76 64)) 768 0 #xffffff 0) + ; (set-vector! (the-as vector4w (&+ v1-76 80)) 256 256 0 0) + ; (set-vector! (the-as vector4w (&+ v1-76 96)) 896 128 #xffffff 0) + ; ) + ; (&+! (-> arg0 base) 112) + ; (let* ((v1-80 arg0) + ; (a0-93 (the-as object (-> v1-80 base))) + ; ) + ; (set! (-> (the-as dma-packet a0-93) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + ; (set! (-> (the-as dma-packet a0-93) vif0) (new 'static 'vif-tag)) + ; (set! (-> (the-as dma-packet a0-93) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + ; (set! (-> v1-80 base) (&+ (the-as pointer a0-93) 16)) + ; ) + ; (let* ((v1-81 arg0) + ; (a0-95 (the-as object (-> v1-81 base))) + ; ) + ; (set! (-> (the-as gs-gif-tag a0-95) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + ; (set! (-> (the-as gs-gif-tag a0-95) regs) + ; (new 'static 'gif-tag-regs + ; :regs0 (gif-reg-id a+d) + ; :regs1 (gif-reg-id a+d) + ; :regs2 (gif-reg-id a+d) + ; :regs3 (gif-reg-id a+d) + ; :regs4 (gif-reg-id a+d) + ; :regs5 (gif-reg-id a+d) + ; :regs6 (gif-reg-id a+d) + ; :regs7 (gif-reg-id a+d) + ; :regs8 (gif-reg-id a+d) + ; :regs9 (gif-reg-id a+d) + ; :regs10 (gif-reg-id a+d) + ; :regs11 (gif-reg-id a+d) + ; :regs12 (gif-reg-id a+d) + ; :regs13 (gif-reg-id a+d) + ; :regs14 (gif-reg-id a+d) + ; :regs15 (gif-reg-id a+d) + ; ) + ; ) + ; (set! (-> v1-81 base) (&+ (the-as pointer a0-95) 16)) + ; ) + ; (let* ((s4-5 arg0) + ; (s3-4 (-> s4-5 base)) + ; ) + ; (set! (-> (the-as (pointer gs-tex0) s3-4) 0) + ; (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 8) :tw (log2 8) :tbp0 (+ ocean-tex-block-2 20)) + ; ) + ; (set! (-> (the-as (pointer gs-reg64) s3-4) 1) (gs-reg64 tex0-1)) + ; (set! (-> (the-as (pointer uint64) s3-4) 2) (the-as uint 0)) + ; (set! (-> (the-as (pointer gs-reg64) s3-4) 3) (gs-reg64 texflush)) + ; (set! (-> s4-5 base) (&+ s3-4 32)) + ; ) + ; (let ((v1-91 (-> arg0 base))) + ; (set! (-> (the-as (pointer uint128) v1-91)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + ; (set! (-> (the-as (pointer uint128) v1-91) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + ; (set-vector! (the-as vector4w (&+ v1-91 32)) 128 128 128 0) + ; (set-vector! (the-as vector4w (&+ v1-91 48)) 0 0 0 0) + ; (set-vector! (the-as vector4w (&+ v1-91 64)) 896 0 #xffffff 0) + ; (set-vector! (the-as vector4w (&+ v1-91 80)) 256 256 0 0) + ; (set-vector! (the-as vector4w (&+ v1-91 96)) 1024 128 #xffffff 0) + ; ) + ; (&+! (-> arg0 base) 112) + ; (let* ((v1-95 arg0) + ; (a0-113 (the-as object (-> v1-95 base))) + ; ) + ; (set! (-> (the-as dma-packet a0-113) dma) (new 'static 'dma-tag :qwc #x3 :id (dma-tag-id cnt))) + ; (set! (-> (the-as dma-packet a0-113) vif0) (new 'static 'vif-tag)) + ; (set! (-> (the-as dma-packet a0-113) vif1) (new 'static 'vif-tag :imm #x3 :cmd (vif-cmd direct) :msk #x1)) + ; (set! (-> v1-95 base) (&+ (the-as pointer a0-113) 16)) + ; ) + ; (let* ((v1-96 arg0) + ; (a0-115 (the-as object (-> v1-96 base))) + ; ) + ; (set! (-> (the-as gs-gif-tag a0-115) tag) (new 'static 'gif-tag64 :nloop #x1 :eop #x1 :nreg #x2)) + ; (set! (-> (the-as gs-gif-tag a0-115) regs) + ; (new 'static 'gif-tag-regs + ; :regs0 (gif-reg-id a+d) + ; :regs1 (gif-reg-id a+d) + ; :regs2 (gif-reg-id a+d) + ; :regs3 (gif-reg-id a+d) + ; :regs4 (gif-reg-id a+d) + ; :regs5 (gif-reg-id a+d) + ; :regs6 (gif-reg-id a+d) + ; :regs7 (gif-reg-id a+d) + ; :regs8 (gif-reg-id a+d) + ; :regs9 (gif-reg-id a+d) + ; :regs10 (gif-reg-id a+d) + ; :regs11 (gif-reg-id a+d) + ; :regs12 (gif-reg-id a+d) + ; :regs13 (gif-reg-id a+d) + ; :regs14 (gif-reg-id a+d) + ; :regs15 (gif-reg-id a+d) + ; ) + ; ) + ; (set! (-> v1-96 base) (&+ (the-as pointer a0-115) 16)) + ; ) + ; (let* ((s4-6 arg0) + ; (s3-5 (-> s4-6 base)) + ; ) + ; (set! (-> (the-as (pointer gs-tex0) s3-5) 0) + ; (new 'static 'gs-tex0 :tbw #x1 :tcc #x1 :th (log2 4) :tw (log2 4) :tbp0 (+ ocean-tex-block-2 21)) + ; ) + ; (set! (-> (the-as (pointer gs-reg64) s3-5) 1) (gs-reg64 tex0-1)) + ; (set! (-> (the-as (pointer uint64) s3-5) 2) (the-as uint 0)) + ; (set! (-> (the-as (pointer gs-reg64) s3-5) 3) (gs-reg64 texflush)) + ; (set! (-> s4-6 base) (&+ s3-5 32)) + ; ) + ; (let ((v1-106 (-> arg0 base))) + ; (set! (-> (the-as (pointer uint128) v1-106)) (-> *ocean-texture-work* sprite-tmpl dma-vif quad)) + ; (set! (-> (the-as (pointer uint128) v1-106) 1) (-> *ocean-texture-work* sprite-tmpl quad 1)) + ; (set-vector! (the-as vector4w (&+ v1-106 32)) 128 128 128 0) + ; (set-vector! (the-as vector4w (&+ v1-106 48)) 0 0 0 0) + ; (set-vector! (the-as vector4w (&+ v1-106 64)) 768 128 #xffffff 0) + ; (set-vector! (the-as vector4w (&+ v1-106 80)) 512 512 0 0) + ; (set-vector! (the-as vector4w (&+ v1-106 96)) 896 256 #xffffff 0) + ; ) + ; (&+! (-> arg0 base) 112) + ; (let* ((v1-110 arg0) + ; (a0-133 (the-as object (-> v1-110 base))) + ; ) + ; (set! (-> (the-as dma-packet a0-133) dma) (new 'static 'dma-tag :id (dma-tag-id cnt))) + ; (set! (-> (the-as dma-packet a0-133) vif0) (new 'static 'vif-tag :cmd (vif-cmd flush) :msk #x1)) + ; (set! (-> (the-as dma-packet a0-133) vif1) (new 'static 'vif-tag)) + ; (set! (-> v1-110 base) (&+ (the-as pointer a0-133) 16)) + ; ) + ; ) ) - (reset-display-gs-state *display* arg0 *oddeven*) + ; (reset-display-gs-state *display* arg0 *oddeven*) 0 (none) - ) - - - - + ) \ No newline at end of file diff --git a/goal_src/engine/gfx/ocean/ocean-vu0.gc b/goal_src/engine/gfx/ocean/ocean-vu0.gc index 2730ba812c..471ebf3adf 100644 --- a/goal_src/engine/gfx/ocean/ocean-vu0.gc +++ b/goal_src/engine/gfx/ocean/ocean-vu0.gc @@ -15,8 +15,8 @@ ) ) -;; (def-mips2c ocean-interp-wave (function ocean-wave-info uint none)) ;; TODO mips2c +(def-mips2c ocean-interp-wave (function ocean-wave-info uint none)) ;; TODO mips2c (define ocean-vu0-block (new 'static 'vu-function :length #x0 :qlength #x0)) -;; (def-mips2c ocean-generate-verts (function (pointer vector) ocean-wave-info none)) ;; TODO mips2c \ No newline at end of file +(def-mips2c ocean-generate-verts (function (inline-array vector) ocean-wave-info none)) ;; TODO mips2c \ No newline at end of file diff --git a/goal_src/engine/gfx/ocean/ocean.gc b/goal_src/engine/gfx/ocean/ocean.gc index a07f5e4e7f..39016c3118 100644 --- a/goal_src/engine/gfx/ocean/ocean.gc +++ b/goal_src/engine/gfx/ocean/ocean.gc @@ -645,7 +645,7 @@ (let* ((s5-0 (-> *display* frames (-> *display* on-screen) frame global-buf)) (gp-1 (-> s5-0 base)) ) - ;; (draw-ocean-texture s5-0 *ocean-verts* #t) + (draw-ocean-texture s5-0 *ocean-verts* #t) (ocean-init-buffer s5-0) (draw-ocean-far s5-0) ; (if (not *ocean-mid-off*) From a7bf920bfb65da6c4056fc9c44f55f07b6601877 Mon Sep 17 00:00:00 2001 From: water Date: Thu, 10 Mar 2022 19:22:27 -0500 Subject: [PATCH 3/6] temp --- .../opengl_renderer/ocean/OceanTexture.cpp | 262 +++++++++++++++++- .../opengl_renderer/ocean/OceanTexture.h | 39 ++- 2 files changed, 277 insertions(+), 24 deletions(-) diff --git a/game/graphics/opengl_renderer/ocean/OceanTexture.cpp b/game/graphics/opengl_renderer/ocean/OceanTexture.cpp index 8bc813ba46..295e0cac39 100644 --- a/game/graphics/opengl_renderer/ocean/OceanTexture.cpp +++ b/game/graphics/opengl_renderer/ocean/OceanTexture.cpp @@ -121,12 +121,270 @@ void OceanTexture::handle_tex_call_rest(DmaFollower& dma, // nop } -void OceanTexture::run_L3() { +namespace { +void lq_buffer(Mask mask, Vf& dest, Vf* src) { + for (int i = 0; i < 4; i++) { + if ((u64)mask & (1 << i)) { + dest.data[i] = src->data[i]; + } + } +} + +void sq_buffer(Mask mask, const Vf& src, Vf* dest) { + for (int i = 0; i < 4; i++) { + if ((u64)mask & (1 << i)) { + dest->data[i] = src.data[i]; + } + } +} + +void sq_buffer_giftag(const u8* src, Vf* dest) { + memcpy(dest, src, 16); +} +} // namespace +void OceanTexture::run_L3() { + Vf base_pos; // vf15 + u16 loop_idx; + + Vf vtx0; // vf16 + Vf vtx1; // vf17 + Vf vtx2; // vf18 + Vf vtx3; // vf19 + + Vf res0; // vf20 + Vf res1; // vf21 + Vf res2; // vf22 + Vf res3; // vf23 + + Vf nrm0; // vf24 + Vf nrm1; // vf25 + Vf nrm2; // vf26 + + Vf reflect; // vf27 + + Vf cout0; // vf28 + Vf cout1; // vf29 + Vf cout2; // vf30 + Vf cout3; // vf31 + + Accumulator acc; + const Vf ones(1, 1, 1, 1); + const Vf vf00(0, 0, 0, 1); + const u16 vi11 = 0x80; + bool bc; + +// clang-format off + L3: + // ior vi07, vi06, vi00 | nop 56 + vu.dbuf_write_base = vu.dbuf_write; + // move.xyzw vf15, vf14 | nop 57 + base_pos.move(Mask::xyzw, vu.startx); + // iaddi vi01, vi00, 0x8 | nop 58 + loop_idx = 8; + // lq.xyzw vf24, 1(vi05) | mulw.xyzw vf20, vf15, vf00 59 (?? what are they doing here) + res0.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm0, vu.in_ptr + 1); + // lq.xyzw vf25, 3(vi05) | mulw.xyzw vf21, vf15, vf00 60 + res1.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm1, vu.in_ptr + 3); + // lq.xyzw vf26, 5(vi05) | mulw.xyzw vf22, vf15, vf00 61 + res2.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm2, vu.in_ptr + 5); + // nop | mulw.xyzw vf23, vf15, vf00 62 + res3.mul(Mask::xyzw, base_pos, 1.f); + // nop | mulax.xyzw ACC, vf24, vf06 63 + acc.mula(Mask::xyzw, nrm0, m_texture_constants.cam_nrm.x()); + // nop | madday.xyzw ACC, vf25, vf06 64 + acc.madda(Mask::xyzw, nrm1, m_texture_constants.cam_nrm.y()); + // nop | maddz.xyzw vf27, vf26, vf06 65 + acc.madd(Mask::xyzw, reflect, nrm2, m_texture_constants.cam_nrm.z()); + // nop | addx.x vf21, vf21, vf02 66 + res1.add(Mask::x, res1, m_texture_constants.offsets.x()); + // nop | addy.x vf22, vf22, vf02 67 + res2.add(Mask::x, res2, m_texture_constants.offsets.y()); + L4: + // nop | addz.x vf23, vf23, vf02 68 + res3.add(Mask::x, res3, m_texture_constants.offsets.z()); + // nop | addw.x vf15, vf15, vf02 69 + base_pos.add(Mask::x, base_pos, m_texture_constants.offsets.w()); + // sq.xyzw vf20, 2(vi06) | mulx.x vf28, vf01, vf24 70 + cout0.mul(Mask::x, ones, nrm0.x()); sq_buffer(Mask::xyzw, res0, vu.dbuf_write + 2); + // sq.xyzw vf21, 5(vi06) | muly.x vf29, vf01, vf24 71 + cout1.mul(Mask::x, ones, nrm0.y()); sq_buffer(Mask::xyzw, res1, vu.dbuf_write + 5); + // sq.xyzw vf22, 8(vi06) | mulz.x vf30, vf01, vf24 72 + cout2.mul(Mask::x, ones, nrm0.z()); sq_buffer(Mask::xyzw, res2, vu.dbuf_write + 8); + // sq.xyzw vf23, 11(vi06) | mulw.x vf31, vf01, vf24 73 + cout3.mul(Mask::x, ones, nrm0.w()); sq_buffer(Mask::xyzw, res3, vu.dbuf_write + 11); + // lq.xyzw vf16, 0(vi05) | mulx.y vf28, vf01, vf25 74 + cout0.mul(Mask::y, ones, nrm1.x()); lq_buffer(Mask::xyzw, vtx0, vu.in_ptr); + // lq.xyzw vf17, 2(vi05) | muly.y vf29, vf01, vf25 75 + cout1.mul(Mask::y, ones, nrm1.y()); lq_buffer(Mask::xyzw, vtx1, vu.in_ptr + 2); + // lq.xyzw vf18, 4(vi05) | mulz.y vf30, vf01, vf25 76 + cout2.mul(Mask::y, ones, nrm1.z()); lq_buffer(Mask::xyzw, vtx2, vu.in_ptr + 4); + // lq.xyzw vf19, 6(vi05) | mulw.y vf31, vf01, vf25 77 + cout3.mul(Mask::y, ones, nrm1.w()); lq_buffer(Mask::xyzw, vtx3, vu.in_ptr + 6); + // iaddi vi05, vi05, 0x8 | mulx.xy vf28, vf28, vf27 78 + cout0.mul(Mask::xy, cout0, reflect.x()); vu.in_ptr = vu.in_ptr + 8; + // nop | muly.xy vf29, vf29, vf27 79 + cout1.mul(Mask::xy, cout1, reflect.y()); + // nop | mulz.xy vf30, vf30, vf27 80 + cout2.mul(Mask::xy, cout2, reflect.z()); + // nop | mulw.xy vf31, vf31, vf27 81 + cout3.mul(Mask::xy, cout3, reflect.w()); + // nop | mulw.xy vf28, vf28, vf16 82 + cout0.mul(Mask::xy, cout0, vtx0.w()); + // nop | mulw.xy vf29, vf29, vf17 83 + cout1.mul(Mask::xy, cout1, vtx1.w()); + // nop | mulw.xy vf30, vf30, vf18 84 + cout2.mul(Mask::xy, cout2, vtx2.w()); + // nop | mulw.xy vf31, vf31, vf19 85 + cout3.mul(Mask::xy, cout3, vtx3.w()); + // nop | ftoi0.xyzw vf16, vf16 86 + vtx0.ftoi0(Mask::xyzw, vtx0); + // nop | ftoi0.xyzw vf17, vf17 87 + vtx1.ftoi0(Mask::xyzw, vtx1); + // nop | ftoi0.xyzw vf18, vf18 88 + vtx2.ftoi0(Mask::xyzw, vtx2); + // iaddi vi01, vi01, -0x1 | ftoi0.xyzw vf19, vf19 89 + vtx3.ftoi0(Mask::xyzw, vtx3); loop_idx = loop_idx + -1; + // mfir.w vf16, vi11 | add.xyzw vf28, vf28, vf06 90 + cout0.add(Mask::xyzw, cout0, m_texture_constants.cam_nrm); vtx0.mfir(Mask::w, vi11); + // mfir.w vf17, vi11 | add.xyzw vf29, vf29, vf06 91 + cout1.add(Mask::xyzw, cout1, m_texture_constants.cam_nrm); vtx1.mfir(Mask::w, vi11); + // mfir.w vf18, vi11 | add.xyzw vf30, vf30, vf06 92 + cout2.add(Mask::xyzw, cout2, m_texture_constants.cam_nrm); vtx2.mfir(Mask::w, vi11); + // mfir.w vf19, vi11 | add.xyzw vf31, vf31, vf06 93 + cout3.add(Mask::xyzw, cout3, m_texture_constants.cam_nrm); vtx3.mfir(Mask::w, vi11); + // nop | mulx.xyzw vf28, vf28, vf07 94 + cout0.mul(Mask::xyzw, cout0, m_texture_constants.constants.x()); + // nop | mulx.xyzw vf29, vf29, vf07 95 + cout1.mul(Mask::xyzw, cout1, m_texture_constants.constants.x()); + // nop | mulx.xyzw vf30, vf30, vf07 96 + cout2.mul(Mask::xyzw, cout2, m_texture_constants.constants.x()); + // nop | mulx.xyzw vf31, vf31, vf07 97 + cout3.mul(Mask::xyzw, cout3, m_texture_constants.constants.x()); + // nop | addy.xyzw vf28, vf28, vf07 98 + cout0.add(Mask::xyzw, cout0, m_texture_constants.constants.y()); + // nop | addy.xyzw vf29, vf29, vf07 99 + cout1.add(Mask::xyzw, cout1, m_texture_constants.constants.y()); + // nop | addy.xyzw vf30, vf30, vf07 100 + cout2.add(Mask::xyzw, cout2, m_texture_constants.constants.y()); + // nop | addy.xyzw vf31, vf31, vf07 101 + cout3.add(Mask::xyzw, cout3, m_texture_constants.constants.y()); + // sq.xyzw vf16, 1(vi06) | sub.zw vf28, vf01, vf00 102 + cout0.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx0, vu.dbuf_write + 1); + // sq.xyzw vf17, 4(vi06) | sub.zw vf29, vf01, vf00 103 + cout1.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx1, vu.dbuf_write + 4); + // sq.xyzw vf18, 7(vi06) | sub.zw vf30, vf01, vf00 104 + cout2.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx2, vu.dbuf_write + 7); + // sq.xyzw vf19, 10(vi06) | sub.zw vf31, vf01, vf00 105 + cout3.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx3, vu.dbuf_write + 10); + // lq.xyzw vf24, 1(vi05) | mulw.xyzw vf20, vf15, vf00 106 + res0.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm0, vu.in_ptr + 1); + // lq.xyzw vf25, 3(vi05) | mulw.xyzw vf21, vf15, vf00 107 + res1.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm1, vu.in_ptr + 3); + // lq.xyzw vf26, 5(vi05) | mulw.xyzw vf22, vf15, vf00 108 + res2.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm2, vu.in_ptr + 5); + // sq.xyzw vf28, 0(vi06) | mulw.xyzw vf23, vf15, vf00 109 + res3.mul(Mask::xyzw, base_pos, 1.f); sq_buffer(Mask::xyzw, cout0, vu.dbuf_write); + // sq.xyzw vf29, 3(vi06) | mulax.xyzw ACC, vf24, vf06 110 + acc.mula(Mask::xyzw, nrm0, m_texture_constants.cam_nrm.x()); sq_buffer(Mask::xyzw, cout1, vu.dbuf_write + 3); + // sq.xyzw vf30, 6(vi06) | madday.xyzw ACC, vf25, vf06 111 + acc.madda(Mask::xyzw, nrm1, m_texture_constants.cam_nrm.y()); sq_buffer(Mask::xyzw, cout2, vu.dbuf_write + 6); + // sq.xyzw vf31, 9(vi06) | maddz.xyzw vf27, vf26, vf06 112 + acc.madd(Mask::xyzw, reflect, nrm2, m_texture_constants.cam_nrm.z()); sq_buffer(Mask::xyzw, cout3, vu.dbuf_write + 9); + // BRANCH! + // ibgtz vi01, L4 | addx.x vf21, vf21, vf02 113 + res1.add(Mask::x, res1, m_texture_constants.offsets.x()); bc = ((s16)loop_idx) > 0; + // iaddi vi06, vi06, 0xc | addy.x vf22, vf22, vf02 114 + res2.add(Mask::x, res2, m_texture_constants.offsets.y()); vu.dbuf_write = vu.dbuf_write + 12; + if (bc) { goto L4; } + + // lq.xyzw vf28, 0(vi07) | addx.y vf14, vf14, vf02 115 + vu.startx.add(Mask::y, vu.startx, m_texture_constants.offsets.x()); lq_buffer(Mask::xyzw, cout0, vu.dbuf_write_base); + // lq.xyzw vf16, 1(vi07) | nop 116 + lq_buffer(Mask::xyzw, vtx0, vu.dbuf_write_base + 1); + // sq.xyzw vf20, 2(vi06) | nop 117 + sq_buffer(Mask::xyzw, res0, vu.dbuf_write + 2); + // sq.xyzw vf28, 0(vi06) | nop 118 + sq_buffer(Mask::xyzw, cout0, vu.dbuf_write); + // jr vi12 | nop 119 + // sq.xyzw vf16, 1(vi06) | nop 120 + sq_buffer(Mask::xyzw, vtx0, vu.dbuf_write + 1); + // clang-format on } void OceanTexture::run_L5() { - + // clang-format off + u16 loop_idx; + Vf res0; + Vf res1; + Vf cout0; + Vf cout1; + Vf vtx0; + Vf vtx1; + bool bc; + L5: + // iaddiu vi01, vi00, 0x21 | nop 121 + loop_idx = 0x21; /* 33 */ + // sq.xyzw vf05, 0(vi08) | nop 122 + sq_buffer_giftag(m_texture_constants.giftag, vu.tptr); + // iaddi vi08, vi08, 0x1 | nop 123 + vu.tptr = vu.tptr + 1; + L6: + // iaddi vi01, vi01, -0x1 | nop 124 + loop_idx = loop_idx + -1; + // lq.xyzw vf20, 2(vi03) | nop 125 + lq_buffer(Mask::xyzw, res0, vu.dbuf_read_a + 2); + // lq.xyzw vf21, 2(vi04) | nop 126 + lq_buffer(Mask::xyzw, res1, vu.dbuf_read_b + 2); + // lq.xyzw vf28, 0(vi03) | nop 127 + lq_buffer(Mask::xyzw, cout0, vu.dbuf_read_a); + // lq.xyzw vf16, 1(vi03) | nop 128 + lq_buffer(Mask::xyzw, vtx0, vu.dbuf_read_a + 1); + // lq.xyzw vf29, 0(vi04) | ftoi4.xyzw vf20, vf20 129 + res0.ftoi4(Mask::xyzw, res0); lq_buffer(Mask::xyzw, cout1, vu.dbuf_read_b); + // lq.xyzw vf17, 1(vi04) | ftoi4.xyzw vf21, vf21 130 + res1.ftoi4(Mask::xyzw, res1); lq_buffer(Mask::xyzw, vtx1, vu.dbuf_read_b + 1); + // sq.xyzw vf28, 0(vi08) | nop 131 + sq_buffer(Mask::xyzw, cout0, vu.tptr); + // sq.xyzw vf16, 1(vi08) | nop 132 + sq_buffer(Mask::xyzw, vtx0, vu.tptr + 1); + // sq.xyzw vf20, 2(vi08) | nop 133 + sq_buffer(Mask::xyzw, res0, vu.tptr + 2); + // sq.xyzw vf29, 3(vi08) | nop 134 + sq_buffer(Mask::xyzw, cout1, vu.tptr + 3); + // sq.xyzw vf17, 4(vi08) | nop 135 + sq_buffer(Mask::xyzw, vtx1, vu.tptr + 4); + // sq.xyzw vf21, 5(vi08) | nop 136 + sq_buffer(Mask::xyzw, res1, vu.tptr + 5); + // iaddi vi03, vi03, 0x3 | nop 137 + vu.dbuf_read_a = vu.dbuf_read_a + 3; + // iaddi vi04, vi04, 0x3 | nop 138 + vu.dbuf_read_b = vu.dbuf_read_b + 3; + // BRANCH! + // ibgtz vi01, L6 | nop 139 + bc = ((s16)loop_idx) > 0; + // iaddi vi08, vi08, 0x6 | nop 140 + vu.tptr = vu.tptr + 6; + if (bc) { goto L6; } + + // xgkick vi09 | nop 141 + xgkick(vu.tbase); + // mtir vi08, vf03.x | nop 142 + // vu.tptr = vu.vf03.x_as_u16(); + vu.tptr = get_tbuf(); + // mtir vi09, vf03.x | nop 143 + // vu.vi09 = vu.vf03.x_as_u16(); + vu.tbase = get_tbuf(); + // jr vi12 | nop 144 + // ASSERT(false); + // mr32.xyzw vf03, vf03 | nop 145 + // vu.vf03.mr32(Mask::xyzw, vu.vf03); + swap_tbuf(); + // clang-format on +} + +void OceanTexture::xgkick(Vf* src) { + // KICK } void OceanTexture::handle_tex_call_done(DmaFollower& dma, diff --git a/game/graphics/opengl_renderer/ocean/OceanTexture.h b/game/graphics/opengl_renderer/ocean/OceanTexture.h index 8e270107e2..1db215d3b5 100644 --- a/game/graphics/opengl_renderer/ocean/OceanTexture.h +++ b/game/graphics/opengl_renderer/ocean/OceanTexture.h @@ -26,6 +26,8 @@ class OceanTexture { void run_L3(); void run_L5(); + void xgkick(Vf* src); + static constexpr int TEX0_SIZE = 128; FramebufferTexturePair m_tex0; @@ -76,34 +78,27 @@ class OceanTexture { return m_texture_vertices_drawing; } - void swap_dbuf() { - std::swap(m_dbuf_x, m_dbuf_y); - } + void swap_dbuf() { std::swap(m_dbuf_x, m_dbuf_y); } - void swap_tbuf() { - std::swap(m_tbuf_x, m_tbuf_y); - } + void swap_tbuf() { std::swap(m_tbuf_x, m_tbuf_y); } - Vf* get_dbuf() { - return m_dbuf_x; - } + Vf* get_dbuf() { return m_dbuf_x; } - Vf* get_dbuf_other() { - return m_dbuf_y; - } + Vf* get_dbuf_other() { return m_dbuf_y; } - Vf* get_tbuf() { - return m_tbuf_x; - } + Vf* get_tbuf() { return m_tbuf_x; } struct { - Vf startx; // vf14 - Vf* dbuf_read_a; // vi03 - Vf* dbuf_read_b; // vi04 - Vf* in_ptr; // vi05 - Vf* dbuf_write; // vi06 - Vf* tptr; // vi08 - Vf* tbase; // vi09 + Vf startx; // vf14 + // Vf base_pos; vf15 + // Vf nrm0; vf24 + Vf* dbuf_read_a; // vi03 + Vf* dbuf_read_b; // vi04 + Vf* in_ptr; // vi05 + Vf* dbuf_write; // vi06 + Vf* dbuf_write_base; // vi07 + Vf* tptr; // vi08 + Vf* tbase; // vi09 } vu; enum TexVu1Data { From 09f043e3fc8edd690a7d370f83c7012b731409eb Mon Sep 17 00:00:00 2001 From: water Date: Fri, 11 Mar 2022 19:10:38 -0500 Subject: [PATCH 4/6] unoptimized version working --- decompiler/config/all-types.gc | 2 +- .../opengl_renderer/DirectRenderer.cpp | 30 ++++- .../graphics/opengl_renderer/DirectRenderer.h | 3 + .../opengl_renderer/OpenGLRenderer.cpp | 2 +- game/graphics/opengl_renderer/Profiler.cpp | 2 +- game/graphics/opengl_renderer/buckets.h | 3 +- .../opengl_renderer/ocean/OceanMidAndFar.cpp | 12 +- .../opengl_renderer/ocean/OceanMidAndFar.h | 1 + .../opengl_renderer/ocean/OceanTexture.cpp | 122 +++++++++++++----- .../opengl_renderer/ocean/OceanTexture.h | 26 ++-- goal_src/engine/gfx/ocean/ocean-h.gc | 14 +- goal_src/engine/gfx/ocean/ocean-texture.gc | 103 +++++++++------ 12 files changed, 213 insertions(+), 107 deletions(-) diff --git a/decompiler/config/all-types.gc b/decompiler/config/all-types.gc index 2868683fea..95047f0871 100644 --- a/decompiler/config/all-types.gc +++ b/decompiler/config/all-types.gc @@ -7193,7 +7193,7 @@ ) (deftype ocean-texture-constants (structure) - ((giftag qword :inline :offset-assert 0) + ((giftag gs-gif-tag :inline :offset-assert 0) (buffers vector4w :inline :offset-assert 16) (dests vector4w :inline :offset-assert 32) (start vector :inline :offset-assert 48) diff --git a/game/graphics/opengl_renderer/DirectRenderer.cpp b/game/graphics/opengl_renderer/DirectRenderer.cpp index ed77c83598..82647feb2d 100644 --- a/game/graphics/opengl_renderer/DirectRenderer.cpp +++ b/game/graphics/opengl_renderer/DirectRenderer.cpp @@ -568,6 +568,9 @@ void DirectRenderer::render_gif(const u8* data, case GifTag::RegisterDescriptor::TEX0_1: handle_tex0_1_packed(data + offset); break; + case GifTag::RegisterDescriptor::XYZ2: + handle_xyz2_packed(data + offset, render_state, prof); + break; default: fmt::print("Register {} is not supported in packed mode yet\n", reg_descriptor_name(reg_desc[reg])); @@ -770,7 +773,25 @@ void DirectRenderer::handle_xyzf2_packed(const u8* data, u8 f = (upper >> 36); bool adc = upper & (1ull << 47); - handle_xyzf2_common(x, y, z, f, render_state, prof, !adc); + handle_xyzf2_common(x << 16, y << 16, z << 8, f, render_state, prof, !adc); +} + +void DirectRenderer::handle_xyz2_packed(const u8* data, + SharedRenderState* render_state, + ScopedProfilerNode& prof) { + u32 x, y, z; + memcpy(&x, data, 4); + memcpy(&y, data + 4, 4); + memcpy(&z, data + 8, 4); + + u64 upper; + memcpy(&upper, data + 8, 8); + bool adc = upper & (1ull << 47); + float un_mess_up = 448.f / 512.f; + // TODO total hack + s32 yy = (((s32)y - 1024) << 17) * un_mess_up; + handle_xyzf2_common(((x << 2) + 32768 - 2048 * 2) << 16, ((32768) << 16) - yy, z, 0, + render_state, prof, !adc); } void DirectRenderer::handle_zbuf1(u64 val, @@ -906,9 +927,6 @@ void DirectRenderer::handle_xyzf2_common(u32 x, SharedRenderState* render_state, ScopedProfilerNode& prof, bool advance) { - ASSERT(z < (1 << 24)); - (void)f; // TODO: do something with this. - if (m_my_id == BucketId::MERC_TFRAG_TEX_LEVEL0) { // fmt::print("0x{:x}, 0x{:x}, 0x{:x}\n", x, y, z); } @@ -922,7 +940,7 @@ void DirectRenderer::handle_xyzf2_common(u32 x, m_prim_building.st_reg.x(), m_prim_building.st_reg.y(), m_prim_building.Q); m_prim_building.building_rgba.at(m_prim_building.building_idx) = m_prim_building.rgba_reg; m_prim_building.building_vert.at(m_prim_building.building_idx) = - math::Vector{x << 16, y << 16, z << 8, f}; + math::Vector{x, y, z, f}; m_prim_building.building_idx++; @@ -1050,7 +1068,7 @@ void DirectRenderer::handle_xyzf2(u64 val, u32 z = (val >> 32) & 0xffffff; u32 f = (val >> 56) & 0xff; - handle_xyzf2_common(x, y, z, f, render_state, prof, true); + handle_xyzf2_common(x << 16, y << 16, z << 8, f, render_state, prof, true); } void DirectRenderer::TestState::from_register(GsTest reg) { diff --git a/game/graphics/opengl_renderer/DirectRenderer.h b/game/graphics/opengl_renderer/DirectRenderer.h index 7c617e2bb9..a068b6b5a4 100644 --- a/game/graphics/opengl_renderer/DirectRenderer.h +++ b/game/graphics/opengl_renderer/DirectRenderer.h @@ -82,6 +82,9 @@ class DirectRenderer : public BucketRenderer { void handle_xyzf2_packed(const u8* data, SharedRenderState* render_state, ScopedProfilerNode& prof); + void handle_xyz2_packed(const u8* data, + SharedRenderState* render_state, + ScopedProfilerNode& prof); void handle_tex0_1_packed(const u8* data); void handle_tex0_1(u64 val); void handle_tex1_1(u64 val); diff --git a/game/graphics/opengl_renderer/OpenGLRenderer.cpp b/game/graphics/opengl_renderer/OpenGLRenderer.cpp index bd2b435975..432c47dde8 100644 --- a/game/graphics/opengl_renderer/OpenGLRenderer.cpp +++ b/game/graphics/opengl_renderer/OpenGLRenderer.cpp @@ -85,7 +85,7 @@ void OpenGLRenderer::init_bucket_renderers() { // 1 // 2 init_bucket_renderer("sky", BucketCategory::OTHER, BucketId::SKY_DRAW); // 3 - init_bucket_renderer("ocean-mid-far", BucketCategory::OTHER, + init_bucket_renderer("ocean-mid-far", BucketCategory::OCEAN, BucketId::OCEAN_MID_AND_FAR); // 4 //----------------------- diff --git a/game/graphics/opengl_renderer/Profiler.cpp b/game/graphics/opengl_renderer/Profiler.cpp index 2f99eb480c..3a6d1d82d3 100644 --- a/game/graphics/opengl_renderer/Profiler.cpp +++ b/game/graphics/opengl_renderer/Profiler.cpp @@ -215,7 +215,7 @@ void SmallProfiler::draw(const std::string& status, const SmallProfilerStats& st for (int i = 0; i < (int)BucketCategory::MAX_CATEGORIES; i++) { m_plots[i].push(stats.time_per_category[i] * 1000.f); ImGui::Text("%6s", BUCKET_CATEGORY_NAMES[i]); - m_plots[i].draw(5.f); + m_plots[i].draw(3.f); } } ImGui::End(); diff --git a/game/graphics/opengl_renderer/buckets.h b/game/graphics/opengl_renderer/buckets.h index d7f49fdc49..2e054a86ac 100644 --- a/game/graphics/opengl_renderer/buckets.h +++ b/game/graphics/opengl_renderer/buckets.h @@ -82,10 +82,11 @@ enum class BucketCategory { MERC, GENERIC_MERC, SPRITE, + OCEAN, DEBUG_DRAW, OTHER, MAX_CATEGORIES }; constexpr const char* BUCKET_CATEGORY_NAMES[(int)BucketCategory::MAX_CATEGORIES] = { - "tfrag", "tie", "tex", "merc", "mercneric", "sprite", "debug", "other"}; \ No newline at end of file + "tfrag", "tie", "tex", "merc", "mercneric", "sprite", "ocean", "debug", "other"}; \ No newline at end of file diff --git a/game/graphics/opengl_renderer/ocean/OceanMidAndFar.cpp b/game/graphics/opengl_renderer/ocean/OceanMidAndFar.cpp index 4f5a3452ab..deb0b7ee94 100644 --- a/game/graphics/opengl_renderer/ocean/OceanMidAndFar.cpp +++ b/game/graphics/opengl_renderer/ocean/OceanMidAndFar.cpp @@ -1,14 +1,18 @@ #include "OceanMidAndFar.h" +#include "third-party/imgui/imgui.h" OceanMidAndFar::OceanMidAndFar(const std::string& name, BucketId my_id) - : BucketRenderer(name, my_id), - m_direct(name, my_id, 4096) - {} + : BucketRenderer(name, my_id), m_direct(name, my_id, 4096) {} void OceanMidAndFar::draw_debug_window() { + m_texture_renderer.draw_debug_window(); m_direct.draw_debug_window(); } +void OceanMidAndFar::init_textures(TexturePool& pool) { + m_texture_renderer.init_textures(pool); +} + void OceanMidAndFar::render(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof) { @@ -55,8 +59,6 @@ void OceanMidAndFar::render(DmaFollower& dma, m_direct.flush_pending(render_state, prof); } - - void OceanMidAndFar::handle_ocean_far(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof) { diff --git a/game/graphics/opengl_renderer/ocean/OceanMidAndFar.h b/game/graphics/opengl_renderer/ocean/OceanMidAndFar.h index 4dd740638a..3897b80f75 100644 --- a/game/graphics/opengl_renderer/ocean/OceanMidAndFar.h +++ b/game/graphics/opengl_renderer/ocean/OceanMidAndFar.h @@ -14,6 +14,7 @@ class OceanMidAndFar : public BucketRenderer { OceanMidAndFar(const std::string& name, BucketId my_id); void render(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof) override; void draw_debug_window() override; + void init_textures(TexturePool& pool) override; private: diff --git a/game/graphics/opengl_renderer/ocean/OceanTexture.cpp b/game/graphics/opengl_renderer/ocean/OceanTexture.cpp index 295e0cac39..cd347d6110 100644 --- a/game/graphics/opengl_renderer/ocean/OceanTexture.cpp +++ b/game/graphics/opengl_renderer/ocean/OceanTexture.cpp @@ -1,6 +1,11 @@ #include "OceanTexture.h" +#include "game/graphics/opengl_renderer/AdgifHandler.h" +#include "third-party/imgui/imgui.h" -OceanTexture::OceanTexture() : m_tex0(TEX0_SIZE, TEX0_SIZE, GL_UNSIGNED_INT_8_8_8_8_REV) { +constexpr int OCEAN_TEX_TBP = 8160; // todo +OceanTexture::OceanTexture() + : m_tex0(TEX0_SIZE, TEX0_SIZE, GL_UNSIGNED_INT_8_8_8_8_REV), + m_hack_renderer("burp", BucketId::BUCKET0, 0x8000) { m_dbuf_x = m_dbuf_a; m_dbuf_y = m_dbuf_b; @@ -8,8 +13,50 @@ OceanTexture::OceanTexture() : m_tex0(TEX0_SIZE, TEX0_SIZE, GL_UNSIGNED_INT_8_8_ m_tbuf_y = m_tbuf_b; } -void OceanTexture::handle_tex_call_start(DmaFollower& dma, - SharedRenderState* render_state, +void OceanTexture::init_textures(TexturePool& pool) { + TextureInput in; + in.gpu_texture = m_tex0.texture(); + constexpr int boost = 2; + in.w = 128 * boost; + in.h = 128 * boost; + in.page_name = "PC-OCEAN"; + in.name = "pc-ocean"; + m_tex0_gpu = pool.give_texture_and_load_to_vram(in, OCEAN_TEX_TBP); +} + +void OceanTexture::draw_debug_window() { + if (m_tex0_gpu) { + ImGui::Image((void*)m_tex0_gpu->gpu_textures.at(0).gl, ImVec2(m_tex0_gpu->w, m_tex0_gpu->h)); + } + ImGui::Checkbox("Optimized Version", &m_use_ocean_specific); +} + +void OceanTexture::flush(SharedRenderState* render_state, ScopedProfilerNode& prof) { + if (m_use_ocean_specific) { + // todo + } else { + m_hack_renderer.flush_pending(render_state, prof); + } +} + +void OceanTexture::setup_renderer() { + if (m_use_ocean_specific) { + // todo + } else { + m_hack_renderer.reset_state(); + } +} + +void OceanTexture::xgkick(Vf* src, SharedRenderState* render_state, ScopedProfilerNode& prof) { + // KICK + if (m_use_ocean_specific) { + // todo + } else { + m_hack_renderer.render_gif((const u8*)src, UINT32_MAX, render_state, prof); + } +} + +void OceanTexture::handle_tex_call_start(SharedRenderState* render_state, ScopedProfilerNode& prof) { // L1: // lq.xyzw vf14_startx, 988(vi00) | maxw.xyzw vf01_ones, vf00, vf00 @@ -49,7 +96,7 @@ void OceanTexture::handle_tex_call_start(DmaFollower& dma, // bal vi12_ra, L5 // mtir vi04_dbuf_read_b, vf04_dbuf.y vu.dbuf_read_b = get_dbuf_other(); - run_L5(); + run_L5(render_state, prof); // mtir vi06_dbuf_write, vf04_dbuf.x vu.dbuf_write = get_dbuf(); @@ -63,15 +110,13 @@ void OceanTexture::handle_tex_call_start(DmaFollower& dma, // bal vi12_ra, L5 // mtir vi04_dbuf_read_b, vf04_dbuf.y vu.dbuf_read_b = get_dbuf_other(); - run_L5(); + run_L5(render_state, prof); // nop :e // nop } -void OceanTexture::handle_tex_call_rest(DmaFollower& dma, - SharedRenderState* render_state, - ScopedProfilerNode& prof) { +void OceanTexture::handle_tex_call_rest(SharedRenderState* render_state, ScopedProfilerNode& prof) { // L2: // xtop vi05_in_ptr vu.in_ptr = swap_vu_upload_buffers(); @@ -87,7 +132,7 @@ void OceanTexture::handle_tex_call_rest(DmaFollower& dma, // bal vi12_ra, L5 // mtir vi04_dbuf_read_b, vf04_dbuf.y vu.dbuf_read_b = get_dbuf_other(); - run_L5(); + run_L5(render_state, prof); // mtir vi06_dbuf_write, vf04_dbuf.x vu.dbuf_write = get_dbuf(); @@ -101,7 +146,7 @@ void OceanTexture::handle_tex_call_rest(DmaFollower& dma, // bal vi12_ra, L5 // mtir vi04_dbuf_read_b, vf04_dbuf.y vu.dbuf_read_b = get_dbuf_other(); - run_L5(); + run_L5(render_state, prof); // mtir vi06_dbuf_write, vf04_dbuf.x vu.dbuf_write = get_dbuf(); @@ -115,7 +160,7 @@ void OceanTexture::handle_tex_call_rest(DmaFollower& dma, // bal vi12_ra, L5 // mtir vi04_dbuf_read_b, vf04_dbuf.y vu.dbuf_read_b = get_dbuf_other(); - run_L5(); + run_L5(render_state, prof); // nop :e // nop @@ -174,7 +219,7 @@ void OceanTexture::run_L3() { const u16 vi11 = 0x80; bool bc; -// clang-format off + // clang-format off L3: // ior vi07, vi06, vi00 | nop 56 vu.dbuf_write_base = vu.dbuf_write; @@ -312,7 +357,7 @@ void OceanTexture::run_L3() { // clang-format on } -void OceanTexture::run_L5() { +void OceanTexture::run_L5(SharedRenderState* render_state, ScopedProfilerNode& prof) { // clang-format off u16 loop_idx; Vf res0; @@ -356,6 +401,7 @@ void OceanTexture::run_L5() { sq_buffer(Mask::xyzw, vtx1, vu.tptr + 4); // sq.xyzw vf21, 5(vi08) | nop 136 sq_buffer(Mask::xyzw, res1, vu.tptr + 5); + // iaddi vi03, vi03, 0x3 | nop 137 vu.dbuf_read_a = vu.dbuf_read_a + 3; // iaddi vi04, vi04, 0x3 | nop 138 @@ -368,7 +414,7 @@ void OceanTexture::run_L5() { if (bc) { goto L6; } // xgkick vi09 | nop 141 - xgkick(vu.tbase); + xgkick(vu.tbase, render_state, prof); // mtir vi08, vf03.x | nop 142 // vu.tptr = vu.vf03.x_as_u16(); vu.tptr = get_tbuf(); @@ -383,19 +429,10 @@ void OceanTexture::run_L5() { // clang-format on } -void OceanTexture::xgkick(Vf* src) { - // KICK -} - -void OceanTexture::handle_tex_call_done(DmaFollower& dma, - SharedRenderState* render_state, - ScopedProfilerNode& prof) { - // this program does nothing. -} - void OceanTexture::handle_ocean_texture(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof) { + FramebufferTexturePairContext ctxt(m_tex0); // render to the first texture { // (set-display-gs-state arg0 ocean-tex-page-0 128 128 0 0) @@ -435,6 +472,27 @@ void OceanTexture::handle_ocean_texture(DmaFollower& dma, ASSERT(data.vifcode0().kind == VifCode::Kind::NOP); ASSERT(data.vifcode1().kind == VifCode::Kind::DIRECT); memcpy(&m_envmap_adgif, data.data + 16, sizeof(AdGifData)); + + // fmt::print("adgif is:\n{}\n\n", AdgifHelper(m_envmap_adgif).print()); + /* + * adgif is: +[0] TEX0_1 + tbp0: 10010 tbw: 2 psm: 19 tw: 6 th: 6 tcc: 1 tfx: 0 cbp: 10046 cpsm: 0 csm: 0 +[1] TEX1_1 + lcm: false mxl: 0 mmag: true mmin: 4 mtba: false l: 0 k: 0 +[2] MIPTBP1_1 +[3] CLAMP_1 + 0x5 +[4] ALPHA_1 + (Cs - Cd) * As / 128.0 + Cd + + */ + + // HACK + setup_renderer(); + if (!m_use_ocean_specific) { + m_hack_renderer.render_gif(data.data, UINT32_MAX, render_state, prof); + } } // vertices are uploaded double buffered @@ -463,8 +521,7 @@ void OceanTexture::handle_ocean_texture(DmaFollower& dma, ASSERT(data.vifcode0().kind == VifCode::Kind::MSCALF); ASSERT(data.vifcode0().immediate == TexVu1Prog::START); ASSERT(data.vifcode1().kind == VifCode::Kind::STMOD); // not sure why... - handle_tex_call_start(dma, render_state, prof); - // TODO handle call and swapping buffer + handle_tex_call_start(render_state, prof); } // loop over vertex groups @@ -485,9 +542,7 @@ void OceanTexture::handle_ocean_texture(DmaFollower& dma, ASSERT(call.vifcode0().kind == VifCode::Kind::MSCALF); ASSERT(call.vifcode0().immediate == TexVu1Prog::REST); ASSERT(call.vifcode1().kind == VifCode::Kind::STMOD); // not sure why... - handle_tex_call_rest(dma, render_state, prof); - - // TODO handle call and swapping buffer + handle_tex_call_rest(render_state, prof); } // last upload does something weird... @@ -523,8 +578,7 @@ void OceanTexture::handle_ocean_texture(DmaFollower& dma, ASSERT(data.vifcode0().kind == VifCode::Kind::MSCALF); ASSERT(data.vifcode0().immediate == TexVu1Prog::REST); ASSERT(data.vifcode1().kind == VifCode::Kind::STMOD); // not sure why... - handle_tex_call_rest(dma, render_state, prof); - // TODO handle call and swapping buffer + handle_tex_call_rest(render_state, prof); } // last call @@ -534,7 +588,9 @@ void OceanTexture::handle_ocean_texture(DmaFollower& dma, ASSERT(data.vifcode0().kind == VifCode::Kind::MSCALF); ASSERT(data.vifcode0().immediate == TexVu1Prog::DONE); ASSERT(data.vifcode1().kind == VifCode::Kind::STMOD); // not sure why... - handle_tex_call_done(dma, render_state, prof); - // TODO handle call and swapping buffer + // this program does nothing. } + + flush(render_state, prof); + render_state->texture_pool->move_existing_to_vram(m_tex0_gpu, 8160); } \ No newline at end of file diff --git a/game/graphics/opengl_renderer/ocean/OceanTexture.h b/game/graphics/opengl_renderer/ocean/OceanTexture.h index 1db215d3b5..e71c9be763 100644 --- a/game/graphics/opengl_renderer/ocean/OceanTexture.h +++ b/game/graphics/opengl_renderer/ocean/OceanTexture.h @@ -11,25 +11,25 @@ class OceanTexture { void handle_ocean_texture(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof); + void init_textures(TexturePool& pool); + void draw_debug_window(); private: - void handle_tex_call_start(DmaFollower& dma, - SharedRenderState* render_state, - ScopedProfilerNode& prof); - void handle_tex_call_rest(DmaFollower& dma, - SharedRenderState* render_state, - ScopedProfilerNode& prof); - void handle_tex_call_done(DmaFollower& dma, - SharedRenderState* render_state, - ScopedProfilerNode& prof); + void handle_tex_call_start(SharedRenderState* render_state, ScopedProfilerNode& prof); + void handle_tex_call_rest(SharedRenderState* render_state, ScopedProfilerNode& prof); void run_L3(); - void run_L5(); + void run_L5(SharedRenderState* render_state, ScopedProfilerNode& prof); + + void xgkick(Vf* src, SharedRenderState* render_state, ScopedProfilerNode& prof); + void setup_renderer(); + void flush(SharedRenderState* render_state, ScopedProfilerNode& prof); - void xgkick(Vf* src); + bool m_use_ocean_specific = false; - static constexpr int TEX0_SIZE = 128; + static constexpr int TEX0_SIZE = 256; // TODO actually 128 FramebufferTexturePair m_tex0; + GpuTexture* m_tex0_gpu = nullptr; // (deftype ocean-texture-constants (structure) struct OceanTextureConstants { @@ -112,4 +112,6 @@ class OceanTexture { enum TexVu1Prog { START = 0, REST = 2, DONE = 4 }; static constexpr int NUM_FRAG_LOOPS = 9; + + DirectRenderer m_hack_renderer; }; diff --git a/goal_src/engine/gfx/ocean/ocean-h.gc b/goal_src/engine/gfx/ocean/ocean-h.gc index b0e69e38f0..43f2bbf8b2 100644 --- a/goal_src/engine/gfx/ocean/ocean-h.gc +++ b/goal_src/engine/gfx/ocean/ocean-h.gc @@ -249,13 +249,13 @@ ) (deftype ocean-texture-constants (structure) - ((giftag qword :inline :offset-assert 0) - (buffers vector4w :inline :offset-assert 16) - (dests vector4w :inline :offset-assert 32) - (start vector :inline :offset-assert 48) - (offsets vector :inline :offset-assert 64) - (constants vector :inline :offset-assert 80) - (cam-nrm vector :inline :offset-assert 96) + ((giftag gs-gif-tag :inline :offset-assert 0) + (buffers vector4w :inline :offset-assert 16) + (dests vector4w :inline :offset-assert 32) + (start vector :inline :offset-assert 48) + (offsets vector :inline :offset-assert 64) + (constants vector :inline :offset-assert 80) + (cam-nrm vector :inline :offset-assert 96) ) :method-count-assert 9 :size-assert #x70 diff --git a/goal_src/engine/gfx/ocean/ocean-texture.gc b/goal_src/engine/gfx/ocean/ocean-texture.gc index 693499ca51..16661171fd 100644 --- a/goal_src/engine/gfx/ocean/ocean-texture.gc +++ b/goal_src/engine/gfx/ocean/ocean-texture.gc @@ -7,44 +7,57 @@ ;; definition for symbol *ocean-texture-work*, type ocean-texture-work -(define *ocean-texture-work* (new 'static 'ocean-texture-work - :sprite-tmpl - (new 'static 'dma-gif-packet - :dma-vif - (new 'static 'dma-packet - :dma - (new 'static 'dma-tag :qwc #x6 :id (dma-tag-id cnt)) - :vif1 - (new 'static 'vif-tag :imm #x6 :cmd (vif-cmd direct) :msk #x1) - ) - :gif - (new 'static 'array uint64 2 #x508b400000008001 #x53531) - ) - :sprite-tmpl2 - (new 'static 'dma-gif-packet - :dma-vif - (new 'static 'dma-packet - :dma - (new 'static 'dma-tag :qwc #x4 :id (dma-tag-id cnt)) - :vif1 - (new 'static 'vif-tag :imm #x4 :cmd (vif-cmd direct) :msk #x1) - ) - :gif - (new 'static 'array uint64 2 #x3023400000008001 #x551) - ) - :adgif-tmpl - (new 'static 'dma-gif-packet - :dma-vif - (new 'static 'dma-packet - :dma - (new 'static 'dma-tag :qwc #x6 :id (dma-tag-id cnt)) - :vif1 - (new 'static 'vif-tag :imm #x6 :cmd (vif-cmd direct) :msk #x1) - ) - :gif - (new 'static 'array uint64 2 #x1000000000008005 #xe) - ) - ) +(define *ocean-texture-work* + (new 'static 'ocean-texture-work + :sprite-tmpl + (new 'static 'dma-gif-packet + :dma-vif + (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x6 :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :imm #x6 :cmd (vif-cmd direct) :msk #x1) + ) + :gif0 (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type sprite) :tme #x1 :fst #x1) + :nreg #x5 + ) + :gif1 (new 'static 'gif-tag-regs + :regs0 (gif-reg-id rgbaq) + :regs1 (gif-reg-id uv) + :regs2 (gif-reg-id xyz2) + :regs3 (gif-reg-id uv) + :regs4 (gif-reg-id xyz2) + ) + ) + :sprite-tmpl2 + (new 'static 'dma-gif-packet + :dma-vif + (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x4 :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :imm #x4 :cmd (vif-cmd direct) :msk #x1) + ) + :gif0 (new 'static 'gif-tag64 + :nloop #x1 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type sprite) :abe #x1) + :nreg #x3 + ) + :gif1 (new 'static 'gif-tag-regs :regs0 (gif-reg-id rgbaq) :regs1 (gif-reg-id xyz2) :regs2 (gif-reg-id xyz2)) + ) + :adgif-tmpl + (new 'static 'dma-gif-packet + :dma-vif + (new 'static 'dma-packet + :dma (new 'static 'dma-tag :qwc #x6 :id (dma-tag-id cnt)) + :vif1 (new 'static 'vif-tag :imm #x6 :cmd (vif-cmd direct) :msk #x1) + ) + :gif0 (new 'static 'gif-tag64 :nloop #x5 :eop #x1 :nreg #x1) + :gif1 (new 'static 'gif-tag-regs :regs0 (gif-reg-id a+d)) + ) + ) ) ;; definition for symbol ocean-texture-vu1-block, type vu-function @@ -52,8 +65,18 @@ (defun ocean-texture-setup-constants ((arg0 ocean-texture-constants)) "Set the constant values used in Ocean Texture VU1 program." - (set! (-> arg0 giftag dword 0) (make-u128 0 (the-as uint #x300e400000008042))) - (set! (-> arg0 giftag dword 1) (the-as uint 1298)) + (set! (-> arg0 giftag tag) + (new 'static 'gif-tag64 + :nloop #x42 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1) + :nreg #x3 + ) + ) + (set! (-> arg0 giftag regs) + (new 'static 'gif-tag-regs :regs0 (gif-reg-id st) :regs1 (gif-reg-id rgbaq) :regs2 (gif-reg-id xyz2)) + ) ;; these are VU1 data addresses (set-vector! (-> arg0 buffers) 384 583 384 583) From ce7a20db09560305fe404cd3fc6daad0b63d9ebd Mon Sep 17 00:00:00 2001 From: water Date: Fri, 11 Mar 2022 21:54:44 -0500 Subject: [PATCH 5/6] optimized version by default --- decompiler/data/game_text.cpp | 4 +- game/CMakeLists.txt | 2 + .../opengl_renderer/DirectRenderer.cpp | 7 +- game/graphics/opengl_renderer/Shader.cpp | 1 + game/graphics/opengl_renderer/Shader.h | 1 + game/graphics/opengl_renderer/debug_gui.cpp | 2 +- .../opengl_renderer/ocean/OceanMidAndFar.h | 1 - .../opengl_renderer/ocean/OceanTexture.cpp | 392 +------------- .../opengl_renderer/ocean/OceanTexture.h | 39 +- .../opengl_renderer/ocean/OceanTexture_PC.cpp | 501 ++++++++++++++++++ .../ocean/OceanTexture_PS2.cpp | 378 +++++++++++++ .../shaders/ocean_texture.frag | 12 + .../shaders/ocean_texture.vert | 15 + game/kernel/kmemcard.cpp | 6 +- game/mips2c/functions/ocean.cpp | 4 - game/mips2c/functions/ocean_vu0.cpp | 10 +- 16 files changed, 977 insertions(+), 398 deletions(-) create mode 100644 game/graphics/opengl_renderer/ocean/OceanTexture_PC.cpp create mode 100644 game/graphics/opengl_renderer/ocean/OceanTexture_PS2.cpp create mode 100644 game/graphics/opengl_renderer/shaders/ocean_texture.frag create mode 100644 game/graphics/opengl_renderer/shaders/ocean_texture.vert diff --git a/decompiler/data/game_text.cpp b/decompiler/data/game_text.cpp index 195f20514e..7883c1c9a6 100644 --- a/decompiler/data/game_text.cpp +++ b/decompiler/data/game_text.cpp @@ -167,7 +167,7 @@ std::string write_game_text( // - first add the strings that are the same across all languages for (auto const& [key, val] : cfg.new_strings_same_across_langs) { result += fmt::format("(#x{}\n ", key); - for (int i = 0; i < languages.size(); i++) { + for (u32 i = 0; i < languages.size(); i++) { result += fmt::format("\"{}\"\n ", val); } result += ")\n\n"; @@ -179,7 +179,7 @@ std::string write_game_text( for (auto const& str : val) { result += fmt::format("\"{}\"\n ", str); } - for (int i = 0; i < languages.size() - val.size(); i++) { + for (u32 i = 0; i < languages.size() - val.size(); i++) { result += fmt::format("\"{}\"\n ", "TODO"); } result += ")\n\n"; diff --git a/game/CMakeLists.txt b/game/CMakeLists.txt index 3f6b31847f..5350bd91e8 100644 --- a/game/CMakeLists.txt +++ b/game/CMakeLists.txt @@ -86,6 +86,8 @@ set(RUNTIME_SOURCE graphics/opengl_renderer/foreground/Generic2_OpenGL.cpp graphics/opengl_renderer/ocean/OceanMidAndFar.cpp graphics/opengl_renderer/ocean/OceanTexture.cpp + graphics/opengl_renderer/ocean/OceanTexture_PC.cpp + graphics/opengl_renderer/ocean/OceanTexture_PS2.cpp graphics/opengl_renderer/BucketRenderer.cpp graphics/opengl_renderer/debug_gui.cpp graphics/opengl_renderer/DirectRenderer.cpp diff --git a/game/graphics/opengl_renderer/DirectRenderer.cpp b/game/graphics/opengl_renderer/DirectRenderer.cpp index 82647feb2d..b18d695cce 100644 --- a/game/graphics/opengl_renderer/DirectRenderer.cpp +++ b/game/graphics/opengl_renderer/DirectRenderer.cpp @@ -790,8 +790,8 @@ void DirectRenderer::handle_xyz2_packed(const u8* data, float un_mess_up = 448.f / 512.f; // TODO total hack s32 yy = (((s32)y - 1024) << 17) * un_mess_up; - handle_xyzf2_common(((x << 2) + 32768 - 2048 * 2) << 16, ((32768) << 16) - yy, z, 0, - render_state, prof, !adc); + handle_xyzf2_common(((x << 2) + 32768 - 2048 * 2) << 16, ((32768) << 16) - yy, z, 0, render_state, + prof, !adc); } void DirectRenderer::handle_zbuf1(u64 val, @@ -939,8 +939,7 @@ void DirectRenderer::handle_xyzf2_common(u32 x, m_prim_building.building_stq.at(m_prim_building.building_idx) = math::Vector( m_prim_building.st_reg.x(), m_prim_building.st_reg.y(), m_prim_building.Q); m_prim_building.building_rgba.at(m_prim_building.building_idx) = m_prim_building.rgba_reg; - m_prim_building.building_vert.at(m_prim_building.building_idx) = - math::Vector{x, y, z, f}; + m_prim_building.building_vert.at(m_prim_building.building_idx) = math::Vector{x, y, z, f}; m_prim_building.building_idx++; diff --git a/game/graphics/opengl_renderer/Shader.cpp b/game/graphics/opengl_renderer/Shader.cpp index 5c4d21bfe5..4f124e39d0 100644 --- a/game/graphics/opengl_renderer/Shader.cpp +++ b/game/graphics/opengl_renderer/Shader.cpp @@ -78,4 +78,5 @@ ShaderLibrary::ShaderLibrary() { at(ShaderId::DIRECT2) = {"direct2"}; at(ShaderId::EYE) = {"eye"}; at(ShaderId::GENERIC) = {"generic"}; + at(ShaderId::OCEAN_TEXTURE) = {"ocean_texture"}; } diff --git a/game/graphics/opengl_renderer/Shader.h b/game/graphics/opengl_renderer/Shader.h index 1a0f01740f..a7bbc5e612 100644 --- a/game/graphics/opengl_renderer/Shader.h +++ b/game/graphics/opengl_renderer/Shader.h @@ -35,6 +35,7 @@ enum class ShaderId { DIRECT2 = 10, EYE = 11, GENERIC = 12, + OCEAN_TEXTURE = 13, MAX_SHADERS }; diff --git a/game/graphics/opengl_renderer/debug_gui.cpp b/game/graphics/opengl_renderer/debug_gui.cpp index b7965a1703..5f07ae118e 100644 --- a/game/graphics/opengl_renderer/debug_gui.cpp +++ b/game/graphics/opengl_renderer/debug_gui.cpp @@ -17,7 +17,7 @@ void FrameTimeRecorder::start_frame() { m_fps_timer.start(); } -void FrameTimeRecorder::draw_window(const DmaStats& dma_stats) { +void FrameTimeRecorder::draw_window(const DmaStats& /*dma_stats*/) { auto* p_open = &m_open; ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | diff --git a/game/graphics/opengl_renderer/ocean/OceanMidAndFar.h b/game/graphics/opengl_renderer/ocean/OceanMidAndFar.h index 3897b80f75..55f6e1eb25 100644 --- a/game/graphics/opengl_renderer/ocean/OceanMidAndFar.h +++ b/game/graphics/opengl_renderer/ocean/OceanMidAndFar.h @@ -17,7 +17,6 @@ class OceanMidAndFar : public BucketRenderer { void init_textures(TexturePool& pool) override; private: - void handle_ocean_far(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof); diff --git a/game/graphics/opengl_renderer/ocean/OceanTexture.cpp b/game/graphics/opengl_renderer/ocean/OceanTexture.cpp index cd347d6110..0378f35ef1 100644 --- a/game/graphics/opengl_renderer/ocean/OceanTexture.cpp +++ b/game/graphics/opengl_renderer/ocean/OceanTexture.cpp @@ -11,6 +11,12 @@ OceanTexture::OceanTexture() m_tbuf_x = m_tbuf_a; m_tbuf_y = m_tbuf_b; + + init_pc(); +} + +OceanTexture::~OceanTexture() { + destroy_pc(); } void OceanTexture::init_textures(TexturePool& pool) { @@ -33,7 +39,7 @@ void OceanTexture::draw_debug_window() { void OceanTexture::flush(SharedRenderState* render_state, ScopedProfilerNode& prof) { if (m_use_ocean_specific) { - // todo + flush_pc(render_state, prof); } else { m_hack_renderer.flush_pending(render_state, prof); } @@ -41,394 +47,29 @@ void OceanTexture::flush(SharedRenderState* render_state, ScopedProfilerNode& pr void OceanTexture::setup_renderer() { if (m_use_ocean_specific) { - // todo + setup_pc(); } else { m_hack_renderer.reset_state(); } } -void OceanTexture::xgkick(Vf* src, SharedRenderState* render_state, ScopedProfilerNode& prof) { - // KICK +void OceanTexture::handle_tex_call_start(SharedRenderState* render_state, + ScopedProfilerNode& prof) { if (m_use_ocean_specific) { - // todo + run_L1_PC(); } else { - m_hack_renderer.render_gif((const u8*)src, UINT32_MAX, render_state, prof); + run_L1(render_state, prof); } } -void OceanTexture::handle_tex_call_start(SharedRenderState* render_state, - ScopedProfilerNode& prof) { - // L1: - // lq.xyzw vf14_startx, 988(vi00) | maxw.xyzw vf01_ones, vf00, vf00 - vu.startx = Vf(m_texture_constants.start); - // lq.xyzw vf02_offset, 989(vi00) - // lq.xyzw vf03_tbuf, 986(vi00) - // lq.xyzw vf04_dbuf, 987(vi00) - // lq.xyzw vf05_giftag, 985(vi00) - // lq.xyzw vf06_cam_nrm, 991(vi00) - // lq.xyzw vf07_constants, 990(vi00) - // iaddiu vi11_0x80, vi00, 0x80 - // mtir vi08_tptr, vf03_tbuf.x - vu.tptr = get_tbuf(); - // mtir vi09_tbase, vf03_tbuf.x - vu.tbase = get_tbuf(); - // mr32.xyzw vf03_tbuf, vf03_tbuf - swap_tbuf(); - // xtop vi05_in_ptr - vu.in_ptr = swap_vu_upload_buffers(); - - // mtir vi06_dbuf_write, vf04_dbuf.x - vu.dbuf_write = get_dbuf(); - // bal vi12_ra, L3 - // mr32.xyzw vf04_dbuf, vf04_dbuf - swap_dbuf(); - run_L3(); - - // mtir vi06_dbuf_write, vf04_dbuf.x - vu.dbuf_write = get_dbuf(); - // bal vi12_ra, L3 - // mr32.xyzw vf04_dbuf, vf04_dbuf - swap_dbuf(); - run_L3(); - - // mtir vi03_dbuf_read_a, vf04_dbuf.x - vu.dbuf_read_a = get_dbuf(); - // bal vi12_ra, L5 - // mtir vi04_dbuf_read_b, vf04_dbuf.y - vu.dbuf_read_b = get_dbuf_other(); - run_L5(render_state, prof); - - // mtir vi06_dbuf_write, vf04_dbuf.x - vu.dbuf_write = get_dbuf(); - // bal vi12_ra, L3 - // mr32.xyzw vf04_dbuf, vf04_dbuf - swap_dbuf(); - run_L3(); - - // mtir vi03_dbuf_read_a, vf04_dbuf.x - vu.dbuf_read_a = get_dbuf(); - // bal vi12_ra, L5 - // mtir vi04_dbuf_read_b, vf04_dbuf.y - vu.dbuf_read_b = get_dbuf_other(); - run_L5(render_state, prof); - - // nop :e - // nop -} - void OceanTexture::handle_tex_call_rest(SharedRenderState* render_state, ScopedProfilerNode& prof) { - // L2: - // xtop vi05_in_ptr - vu.in_ptr = swap_vu_upload_buffers(); - // mtir vi06_dbuf_write, vf04_dbuf.x - vu.dbuf_write = get_dbuf(); - // bal vi12_ra, L3 - // mr32.xyzw vf04_dbuf, vf04_dbuf - swap_dbuf(); - run_L3(); - - // mtir vi03_dbuf_read_a, vf04_dbuf.x - vu.dbuf_read_a = get_dbuf(); - // bal vi12_ra, L5 - // mtir vi04_dbuf_read_b, vf04_dbuf.y - vu.dbuf_read_b = get_dbuf_other(); - run_L5(render_state, prof); - - // mtir vi06_dbuf_write, vf04_dbuf.x - vu.dbuf_write = get_dbuf(); - // bal vi12_ra, L3 - // mr32.xyzw vf04_dbuf, vf04_dbuf - swap_dbuf(); - run_L3(); - - // mtir vi03_dbuf_read_a, vf04_dbuf.x - vu.dbuf_read_a = get_dbuf(); - // bal vi12_ra, L5 - // mtir vi04_dbuf_read_b, vf04_dbuf.y - vu.dbuf_read_b = get_dbuf_other(); - run_L5(render_state, prof); - - // mtir vi06_dbuf_write, vf04_dbuf.x - vu.dbuf_write = get_dbuf(); - // bal vi12_ra, L3 - // mr32.xyzw vf04_dbuf, vf04_dbuf - swap_dbuf(); - run_L3(); - - // mtir vi03_dbuf_read_a, vf04_dbuf.x - vu.dbuf_read_a = get_dbuf(); - // bal vi12_ra, L5 - // mtir vi04_dbuf_read_b, vf04_dbuf.y - vu.dbuf_read_b = get_dbuf_other(); - run_L5(render_state, prof); - - // nop :e - // nop -} - -namespace { -void lq_buffer(Mask mask, Vf& dest, Vf* src) { - for (int i = 0; i < 4; i++) { - if ((u64)mask & (1 << i)) { - dest.data[i] = src->data[i]; - } - } -} - -void sq_buffer(Mask mask, const Vf& src, Vf* dest) { - for (int i = 0; i < 4; i++) { - if ((u64)mask & (1 << i)) { - dest->data[i] = src.data[i]; - } + if (m_use_ocean_specific) { + run_L2_PC(); + } else { + run_L2(render_state, prof); } } -void sq_buffer_giftag(const u8* src, Vf* dest) { - memcpy(dest, src, 16); -} -} // namespace - -void OceanTexture::run_L3() { - Vf base_pos; // vf15 - u16 loop_idx; - - Vf vtx0; // vf16 - Vf vtx1; // vf17 - Vf vtx2; // vf18 - Vf vtx3; // vf19 - - Vf res0; // vf20 - Vf res1; // vf21 - Vf res2; // vf22 - Vf res3; // vf23 - - Vf nrm0; // vf24 - Vf nrm1; // vf25 - Vf nrm2; // vf26 - - Vf reflect; // vf27 - - Vf cout0; // vf28 - Vf cout1; // vf29 - Vf cout2; // vf30 - Vf cout3; // vf31 - - Accumulator acc; - const Vf ones(1, 1, 1, 1); - const Vf vf00(0, 0, 0, 1); - const u16 vi11 = 0x80; - bool bc; - - // clang-format off - L3: - // ior vi07, vi06, vi00 | nop 56 - vu.dbuf_write_base = vu.dbuf_write; - // move.xyzw vf15, vf14 | nop 57 - base_pos.move(Mask::xyzw, vu.startx); - // iaddi vi01, vi00, 0x8 | nop 58 - loop_idx = 8; - // lq.xyzw vf24, 1(vi05) | mulw.xyzw vf20, vf15, vf00 59 (?? what are they doing here) - res0.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm0, vu.in_ptr + 1); - // lq.xyzw vf25, 3(vi05) | mulw.xyzw vf21, vf15, vf00 60 - res1.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm1, vu.in_ptr + 3); - // lq.xyzw vf26, 5(vi05) | mulw.xyzw vf22, vf15, vf00 61 - res2.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm2, vu.in_ptr + 5); - // nop | mulw.xyzw vf23, vf15, vf00 62 - res3.mul(Mask::xyzw, base_pos, 1.f); - // nop | mulax.xyzw ACC, vf24, vf06 63 - acc.mula(Mask::xyzw, nrm0, m_texture_constants.cam_nrm.x()); - // nop | madday.xyzw ACC, vf25, vf06 64 - acc.madda(Mask::xyzw, nrm1, m_texture_constants.cam_nrm.y()); - // nop | maddz.xyzw vf27, vf26, vf06 65 - acc.madd(Mask::xyzw, reflect, nrm2, m_texture_constants.cam_nrm.z()); - // nop | addx.x vf21, vf21, vf02 66 - res1.add(Mask::x, res1, m_texture_constants.offsets.x()); - // nop | addy.x vf22, vf22, vf02 67 - res2.add(Mask::x, res2, m_texture_constants.offsets.y()); - L4: - // nop | addz.x vf23, vf23, vf02 68 - res3.add(Mask::x, res3, m_texture_constants.offsets.z()); - // nop | addw.x vf15, vf15, vf02 69 - base_pos.add(Mask::x, base_pos, m_texture_constants.offsets.w()); - // sq.xyzw vf20, 2(vi06) | mulx.x vf28, vf01, vf24 70 - cout0.mul(Mask::x, ones, nrm0.x()); sq_buffer(Mask::xyzw, res0, vu.dbuf_write + 2); - // sq.xyzw vf21, 5(vi06) | muly.x vf29, vf01, vf24 71 - cout1.mul(Mask::x, ones, nrm0.y()); sq_buffer(Mask::xyzw, res1, vu.dbuf_write + 5); - // sq.xyzw vf22, 8(vi06) | mulz.x vf30, vf01, vf24 72 - cout2.mul(Mask::x, ones, nrm0.z()); sq_buffer(Mask::xyzw, res2, vu.dbuf_write + 8); - // sq.xyzw vf23, 11(vi06) | mulw.x vf31, vf01, vf24 73 - cout3.mul(Mask::x, ones, nrm0.w()); sq_buffer(Mask::xyzw, res3, vu.dbuf_write + 11); - // lq.xyzw vf16, 0(vi05) | mulx.y vf28, vf01, vf25 74 - cout0.mul(Mask::y, ones, nrm1.x()); lq_buffer(Mask::xyzw, vtx0, vu.in_ptr); - // lq.xyzw vf17, 2(vi05) | muly.y vf29, vf01, vf25 75 - cout1.mul(Mask::y, ones, nrm1.y()); lq_buffer(Mask::xyzw, vtx1, vu.in_ptr + 2); - // lq.xyzw vf18, 4(vi05) | mulz.y vf30, vf01, vf25 76 - cout2.mul(Mask::y, ones, nrm1.z()); lq_buffer(Mask::xyzw, vtx2, vu.in_ptr + 4); - // lq.xyzw vf19, 6(vi05) | mulw.y vf31, vf01, vf25 77 - cout3.mul(Mask::y, ones, nrm1.w()); lq_buffer(Mask::xyzw, vtx3, vu.in_ptr + 6); - // iaddi vi05, vi05, 0x8 | mulx.xy vf28, vf28, vf27 78 - cout0.mul(Mask::xy, cout0, reflect.x()); vu.in_ptr = vu.in_ptr + 8; - // nop | muly.xy vf29, vf29, vf27 79 - cout1.mul(Mask::xy, cout1, reflect.y()); - // nop | mulz.xy vf30, vf30, vf27 80 - cout2.mul(Mask::xy, cout2, reflect.z()); - // nop | mulw.xy vf31, vf31, vf27 81 - cout3.mul(Mask::xy, cout3, reflect.w()); - // nop | mulw.xy vf28, vf28, vf16 82 - cout0.mul(Mask::xy, cout0, vtx0.w()); - // nop | mulw.xy vf29, vf29, vf17 83 - cout1.mul(Mask::xy, cout1, vtx1.w()); - // nop | mulw.xy vf30, vf30, vf18 84 - cout2.mul(Mask::xy, cout2, vtx2.w()); - // nop | mulw.xy vf31, vf31, vf19 85 - cout3.mul(Mask::xy, cout3, vtx3.w()); - // nop | ftoi0.xyzw vf16, vf16 86 - vtx0.ftoi0(Mask::xyzw, vtx0); - // nop | ftoi0.xyzw vf17, vf17 87 - vtx1.ftoi0(Mask::xyzw, vtx1); - // nop | ftoi0.xyzw vf18, vf18 88 - vtx2.ftoi0(Mask::xyzw, vtx2); - // iaddi vi01, vi01, -0x1 | ftoi0.xyzw vf19, vf19 89 - vtx3.ftoi0(Mask::xyzw, vtx3); loop_idx = loop_idx + -1; - // mfir.w vf16, vi11 | add.xyzw vf28, vf28, vf06 90 - cout0.add(Mask::xyzw, cout0, m_texture_constants.cam_nrm); vtx0.mfir(Mask::w, vi11); - // mfir.w vf17, vi11 | add.xyzw vf29, vf29, vf06 91 - cout1.add(Mask::xyzw, cout1, m_texture_constants.cam_nrm); vtx1.mfir(Mask::w, vi11); - // mfir.w vf18, vi11 | add.xyzw vf30, vf30, vf06 92 - cout2.add(Mask::xyzw, cout2, m_texture_constants.cam_nrm); vtx2.mfir(Mask::w, vi11); - // mfir.w vf19, vi11 | add.xyzw vf31, vf31, vf06 93 - cout3.add(Mask::xyzw, cout3, m_texture_constants.cam_nrm); vtx3.mfir(Mask::w, vi11); - // nop | mulx.xyzw vf28, vf28, vf07 94 - cout0.mul(Mask::xyzw, cout0, m_texture_constants.constants.x()); - // nop | mulx.xyzw vf29, vf29, vf07 95 - cout1.mul(Mask::xyzw, cout1, m_texture_constants.constants.x()); - // nop | mulx.xyzw vf30, vf30, vf07 96 - cout2.mul(Mask::xyzw, cout2, m_texture_constants.constants.x()); - // nop | mulx.xyzw vf31, vf31, vf07 97 - cout3.mul(Mask::xyzw, cout3, m_texture_constants.constants.x()); - // nop | addy.xyzw vf28, vf28, vf07 98 - cout0.add(Mask::xyzw, cout0, m_texture_constants.constants.y()); - // nop | addy.xyzw vf29, vf29, vf07 99 - cout1.add(Mask::xyzw, cout1, m_texture_constants.constants.y()); - // nop | addy.xyzw vf30, vf30, vf07 100 - cout2.add(Mask::xyzw, cout2, m_texture_constants.constants.y()); - // nop | addy.xyzw vf31, vf31, vf07 101 - cout3.add(Mask::xyzw, cout3, m_texture_constants.constants.y()); - // sq.xyzw vf16, 1(vi06) | sub.zw vf28, vf01, vf00 102 - cout0.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx0, vu.dbuf_write + 1); - // sq.xyzw vf17, 4(vi06) | sub.zw vf29, vf01, vf00 103 - cout1.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx1, vu.dbuf_write + 4); - // sq.xyzw vf18, 7(vi06) | sub.zw vf30, vf01, vf00 104 - cout2.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx2, vu.dbuf_write + 7); - // sq.xyzw vf19, 10(vi06) | sub.zw vf31, vf01, vf00 105 - cout3.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx3, vu.dbuf_write + 10); - // lq.xyzw vf24, 1(vi05) | mulw.xyzw vf20, vf15, vf00 106 - res0.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm0, vu.in_ptr + 1); - // lq.xyzw vf25, 3(vi05) | mulw.xyzw vf21, vf15, vf00 107 - res1.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm1, vu.in_ptr + 3); - // lq.xyzw vf26, 5(vi05) | mulw.xyzw vf22, vf15, vf00 108 - res2.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm2, vu.in_ptr + 5); - // sq.xyzw vf28, 0(vi06) | mulw.xyzw vf23, vf15, vf00 109 - res3.mul(Mask::xyzw, base_pos, 1.f); sq_buffer(Mask::xyzw, cout0, vu.dbuf_write); - // sq.xyzw vf29, 3(vi06) | mulax.xyzw ACC, vf24, vf06 110 - acc.mula(Mask::xyzw, nrm0, m_texture_constants.cam_nrm.x()); sq_buffer(Mask::xyzw, cout1, vu.dbuf_write + 3); - // sq.xyzw vf30, 6(vi06) | madday.xyzw ACC, vf25, vf06 111 - acc.madda(Mask::xyzw, nrm1, m_texture_constants.cam_nrm.y()); sq_buffer(Mask::xyzw, cout2, vu.dbuf_write + 6); - // sq.xyzw vf31, 9(vi06) | maddz.xyzw vf27, vf26, vf06 112 - acc.madd(Mask::xyzw, reflect, nrm2, m_texture_constants.cam_nrm.z()); sq_buffer(Mask::xyzw, cout3, vu.dbuf_write + 9); - // BRANCH! - // ibgtz vi01, L4 | addx.x vf21, vf21, vf02 113 - res1.add(Mask::x, res1, m_texture_constants.offsets.x()); bc = ((s16)loop_idx) > 0; - // iaddi vi06, vi06, 0xc | addy.x vf22, vf22, vf02 114 - res2.add(Mask::x, res2, m_texture_constants.offsets.y()); vu.dbuf_write = vu.dbuf_write + 12; - if (bc) { goto L4; } - - // lq.xyzw vf28, 0(vi07) | addx.y vf14, vf14, vf02 115 - vu.startx.add(Mask::y, vu.startx, m_texture_constants.offsets.x()); lq_buffer(Mask::xyzw, cout0, vu.dbuf_write_base); - // lq.xyzw vf16, 1(vi07) | nop 116 - lq_buffer(Mask::xyzw, vtx0, vu.dbuf_write_base + 1); - // sq.xyzw vf20, 2(vi06) | nop 117 - sq_buffer(Mask::xyzw, res0, vu.dbuf_write + 2); - // sq.xyzw vf28, 0(vi06) | nop 118 - sq_buffer(Mask::xyzw, cout0, vu.dbuf_write); - // jr vi12 | nop 119 - // sq.xyzw vf16, 1(vi06) | nop 120 - sq_buffer(Mask::xyzw, vtx0, vu.dbuf_write + 1); - // clang-format on -} - -void OceanTexture::run_L5(SharedRenderState* render_state, ScopedProfilerNode& prof) { - // clang-format off - u16 loop_idx; - Vf res0; - Vf res1; - Vf cout0; - Vf cout1; - Vf vtx0; - Vf vtx1; - bool bc; - L5: - // iaddiu vi01, vi00, 0x21 | nop 121 - loop_idx = 0x21; /* 33 */ - // sq.xyzw vf05, 0(vi08) | nop 122 - sq_buffer_giftag(m_texture_constants.giftag, vu.tptr); - // iaddi vi08, vi08, 0x1 | nop 123 - vu.tptr = vu.tptr + 1; - L6: - // iaddi vi01, vi01, -0x1 | nop 124 - loop_idx = loop_idx + -1; - // lq.xyzw vf20, 2(vi03) | nop 125 - lq_buffer(Mask::xyzw, res0, vu.dbuf_read_a + 2); - // lq.xyzw vf21, 2(vi04) | nop 126 - lq_buffer(Mask::xyzw, res1, vu.dbuf_read_b + 2); - // lq.xyzw vf28, 0(vi03) | nop 127 - lq_buffer(Mask::xyzw, cout0, vu.dbuf_read_a); - // lq.xyzw vf16, 1(vi03) | nop 128 - lq_buffer(Mask::xyzw, vtx0, vu.dbuf_read_a + 1); - // lq.xyzw vf29, 0(vi04) | ftoi4.xyzw vf20, vf20 129 - res0.ftoi4(Mask::xyzw, res0); lq_buffer(Mask::xyzw, cout1, vu.dbuf_read_b); - // lq.xyzw vf17, 1(vi04) | ftoi4.xyzw vf21, vf21 130 - res1.ftoi4(Mask::xyzw, res1); lq_buffer(Mask::xyzw, vtx1, vu.dbuf_read_b + 1); - // sq.xyzw vf28, 0(vi08) | nop 131 - sq_buffer(Mask::xyzw, cout0, vu.tptr); - // sq.xyzw vf16, 1(vi08) | nop 132 - sq_buffer(Mask::xyzw, vtx0, vu.tptr + 1); - // sq.xyzw vf20, 2(vi08) | nop 133 - sq_buffer(Mask::xyzw, res0, vu.tptr + 2); - // sq.xyzw vf29, 3(vi08) | nop 134 - sq_buffer(Mask::xyzw, cout1, vu.tptr + 3); - // sq.xyzw vf17, 4(vi08) | nop 135 - sq_buffer(Mask::xyzw, vtx1, vu.tptr + 4); - // sq.xyzw vf21, 5(vi08) | nop 136 - sq_buffer(Mask::xyzw, res1, vu.tptr + 5); - - // iaddi vi03, vi03, 0x3 | nop 137 - vu.dbuf_read_a = vu.dbuf_read_a + 3; - // iaddi vi04, vi04, 0x3 | nop 138 - vu.dbuf_read_b = vu.dbuf_read_b + 3; - // BRANCH! - // ibgtz vi01, L6 | nop 139 - bc = ((s16)loop_idx) > 0; - // iaddi vi08, vi08, 0x6 | nop 140 - vu.tptr = vu.tptr + 6; - if (bc) { goto L6; } - - // xgkick vi09 | nop 141 - xgkick(vu.tbase, render_state, prof); - // mtir vi08, vf03.x | nop 142 - // vu.tptr = vu.vf03.x_as_u16(); - vu.tptr = get_tbuf(); - // mtir vi09, vf03.x | nop 143 - // vu.vi09 = vu.vf03.x_as_u16(); - vu.tbase = get_tbuf(); - // jr vi12 | nop 144 - // ASSERT(false); - // mr32.xyzw vf03, vf03 | nop 145 - // vu.vf03.mr32(Mask::xyzw, vu.vf03); - swap_tbuf(); - // clang-format on -} - void OceanTexture::handle_ocean_texture(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof) { @@ -437,6 +78,7 @@ void OceanTexture::handle_ocean_texture(DmaFollower& dma, { // (set-display-gs-state arg0 ocean-tex-page-0 128 128 0 0) auto data = dma.read_and_advance(); + (void)data; } // set up VIF diff --git a/game/graphics/opengl_renderer/ocean/OceanTexture.h b/game/graphics/opengl_renderer/ocean/OceanTexture.h index e71c9be763..86aa68faa4 100644 --- a/game/graphics/opengl_renderer/ocean/OceanTexture.h +++ b/game/graphics/opengl_renderer/ocean/OceanTexture.h @@ -13,19 +13,33 @@ class OceanTexture { ScopedProfilerNode& prof); void init_textures(TexturePool& pool); void draw_debug_window(); + ~OceanTexture(); private: void handle_tex_call_start(SharedRenderState* render_state, ScopedProfilerNode& prof); void handle_tex_call_rest(SharedRenderState* render_state, ScopedProfilerNode& prof); + void run_L1(SharedRenderState* render_state, ScopedProfilerNode& prof); + void run_L2(SharedRenderState* render_state, ScopedProfilerNode& prof); void run_L3(); void run_L5(SharedRenderState* render_state, ScopedProfilerNode& prof); - void xgkick(Vf* src, SharedRenderState* render_state, ScopedProfilerNode& prof); + + void run_L1_PC(); + void run_L2_PC(); + void run_L3_PC(); + void run_L5_PC(); + void xgkick_PC(Vf* src); + void setup_renderer(); void flush(SharedRenderState* render_state, ScopedProfilerNode& prof); - bool m_use_ocean_specific = false; + void setup_pc(); + void flush_pc(SharedRenderState* render_state, ScopedProfilerNode& prof); + void init_pc(); + void destroy_pc(); + + bool m_use_ocean_specific = true; static constexpr int TEX0_SIZE = 256; // TODO actually 128 FramebufferTexturePair m_tex0; @@ -101,6 +115,27 @@ class OceanTexture { Vf* tbase; // vi09 } vu; + static constexpr u32 NUM_STRIPS = 32; + static constexpr u32 NUM_VERTS_PER_STRIP = 66; + static constexpr u32 NUM_VERTS = NUM_STRIPS * NUM_VERTS_PER_STRIP; + + // note: if we used u16's for s/t, we could make this 8 bytes, but I'm afraid that some GPUs + // will be unhappy with that format. + struct Vertex { + float s, t; + math::Vector rgba; + u32 pad; + }; + static_assert(sizeof(Vertex) == 16); + struct { + std::vector vertex_positions; + std::vector vertex_dynamic; + std::vector index_buffer; + u32 vtx_idx = 0; + + GLuint vao, static_vertex_buffer, dynamic_vertex_buffer, gl_index_buffer; + } m_pc; + enum TexVu1Data { BUF0 = 384, BUF1 = 583, diff --git a/game/graphics/opengl_renderer/ocean/OceanTexture_PC.cpp b/game/graphics/opengl_renderer/ocean/OceanTexture_PC.cpp new file mode 100644 index 0000000000..2d510a3be7 --- /dev/null +++ b/game/graphics/opengl_renderer/ocean/OceanTexture_PC.cpp @@ -0,0 +1,501 @@ +#include "OceanTexture.h" + +void OceanTexture::run_L1_PC() { + // L1: + // lq.xyzw vf14_startx, 988(vi00) | maxw.xyzw vf01_ones, vf00, vf00 + vu.startx = Vf(m_texture_constants.start); + // lq.xyzw vf02_offset, 989(vi00) + // lq.xyzw vf03_tbuf, 986(vi00) + // lq.xyzw vf04_dbuf, 987(vi00) + // lq.xyzw vf05_giftag, 985(vi00) + // lq.xyzw vf06_cam_nrm, 991(vi00) + // lq.xyzw vf07_constants, 990(vi00) + // iaddiu vi11_0x80, vi00, 0x80 + // mtir vi08_tptr, vf03_tbuf.x + vu.tptr = get_tbuf(); + // mtir vi09_tbase, vf03_tbuf.x + vu.tbase = get_tbuf(); + // mr32.xyzw vf03_tbuf, vf03_tbuf + swap_tbuf(); + // xtop vi05_in_ptr + vu.in_ptr = swap_vu_upload_buffers(); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3_PC(); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3_PC(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5_PC(); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3_PC(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5_PC(); + + // nop :e + // nop +} + +void OceanTexture::run_L2_PC() { + // L2: + // xtop vi05_in_ptr + vu.in_ptr = swap_vu_upload_buffers(); + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3_PC(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5_PC(); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3_PC(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5_PC(); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3_PC(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5_PC(); + + // nop :e + // nop +} + +namespace { +void lq_buffer(Mask mask, Vf& dest, Vf* src) { + for (int i = 0; i < 4; i++) { + if ((u64)mask & (1 << i)) { + dest.data[i] = src->data[i]; + } + } +} + +void sq_buffer(Mask mask, const Vf& src, Vf* dest) { + for (int i = 0; i < 4; i++) { + if ((u64)mask & (1 << i)) { + dest->data[i] = src.data[i]; + } + } +} + +void sq_buffer_giftag(const u8* src, Vf* dest) { + memcpy(dest, src, 16); +} +} // namespace + +void OceanTexture::run_L3_PC() { + Vf base_pos; // vf15 + u16 loop_idx; + + Vf vtx0; // vf16 + Vf vtx1; // vf17 + Vf vtx2; // vf18 + Vf vtx3; // vf19 + + Vf res0; // vf20 + Vf res1; // vf21 + Vf res2; // vf22 + Vf res3; // vf23 + + Vf nrm0; // vf24 + Vf nrm1; // vf25 + Vf nrm2; // vf26 + + Vf reflect; // vf27 + + Vf cout0; // vf28 + Vf cout1; // vf29 + Vf cout2; // vf30 + Vf cout3; // vf31 + + Accumulator acc; + const Vf ones(1, 1, 1, 1); + const Vf vf00(0, 0, 0, 1); + const u16 vi11 = 0x80; + bool bc; + + // clang-format off + // L3: + // ior vi07, vi06, vi00 | nop 56 + vu.dbuf_write_base = vu.dbuf_write; + // move.xyzw vf15, vf14 | nop 57 + base_pos.move(Mask::xyzw, vu.startx); + // iaddi vi01, vi00, 0x8 | nop 58 + loop_idx = 8; + // lq.xyzw vf24, 1(vi05) | mulw.xyzw vf20, vf15, vf00 59 (?? what are they doing here) + res0.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm0, vu.in_ptr + 1); + // lq.xyzw vf25, 3(vi05) | mulw.xyzw vf21, vf15, vf00 60 + res1.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm1, vu.in_ptr + 3); + // lq.xyzw vf26, 5(vi05) | mulw.xyzw vf22, vf15, vf00 61 + res2.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm2, vu.in_ptr + 5); + // nop | mulw.xyzw vf23, vf15, vf00 62 + res3.mul(Mask::xyzw, base_pos, 1.f); + // nop | mulax.xyzw ACC, vf24, vf06 63 + acc.mula(Mask::xyzw, nrm0, m_texture_constants.cam_nrm.x()); + // nop | madday.xyzw ACC, vf25, vf06 64 + acc.madda(Mask::xyzw, nrm1, m_texture_constants.cam_nrm.y()); + // nop | maddz.xyzw vf27, vf26, vf06 65 + acc.madd(Mask::xyzw, reflect, nrm2, m_texture_constants.cam_nrm.z()); + // nop | addx.x vf21, vf21, vf02 66 + res1.add(Mask::x, res1, m_texture_constants.offsets.x()); + // nop | addy.x vf22, vf22, vf02 67 + res2.add(Mask::x, res2, m_texture_constants.offsets.y()); + L4: + // nop | addz.x vf23, vf23, vf02 68 + res3.add(Mask::x, res3, m_texture_constants.offsets.z()); + // nop | addw.x vf15, vf15, vf02 69 + base_pos.add(Mask::x, base_pos, m_texture_constants.offsets.w()); + // sq.xyzw vf20, 2(vi06) | mulx.x vf28, vf01, vf24 70 + cout0.mul(Mask::x, ones, nrm0.x()); sq_buffer(Mask::xyzw, res0, vu.dbuf_write + 2); + // sq.xyzw vf21, 5(vi06) | muly.x vf29, vf01, vf24 71 + cout1.mul(Mask::x, ones, nrm0.y()); sq_buffer(Mask::xyzw, res1, vu.dbuf_write + 5); + // sq.xyzw vf22, 8(vi06) | mulz.x vf30, vf01, vf24 72 + cout2.mul(Mask::x, ones, nrm0.z()); sq_buffer(Mask::xyzw, res2, vu.dbuf_write + 8); + // sq.xyzw vf23, 11(vi06) | mulw.x vf31, vf01, vf24 73 + cout3.mul(Mask::x, ones, nrm0.w()); sq_buffer(Mask::xyzw, res3, vu.dbuf_write + 11); + // lq.xyzw vf16, 0(vi05) | mulx.y vf28, vf01, vf25 74 + cout0.mul(Mask::y, ones, nrm1.x()); lq_buffer(Mask::xyzw, vtx0, vu.in_ptr); + // lq.xyzw vf17, 2(vi05) | muly.y vf29, vf01, vf25 75 + cout1.mul(Mask::y, ones, nrm1.y()); lq_buffer(Mask::xyzw, vtx1, vu.in_ptr + 2); + // lq.xyzw vf18, 4(vi05) | mulz.y vf30, vf01, vf25 76 + cout2.mul(Mask::y, ones, nrm1.z()); lq_buffer(Mask::xyzw, vtx2, vu.in_ptr + 4); + // lq.xyzw vf19, 6(vi05) | mulw.y vf31, vf01, vf25 77 + cout3.mul(Mask::y, ones, nrm1.w()); lq_buffer(Mask::xyzw, vtx3, vu.in_ptr + 6); + // iaddi vi05, vi05, 0x8 | mulx.xy vf28, vf28, vf27 78 + cout0.mul(Mask::xy, cout0, reflect.x()); vu.in_ptr = vu.in_ptr + 8; + // nop | muly.xy vf29, vf29, vf27 79 + cout1.mul(Mask::xy, cout1, reflect.y()); + // nop | mulz.xy vf30, vf30, vf27 80 + cout2.mul(Mask::xy, cout2, reflect.z()); + // nop | mulw.xy vf31, vf31, vf27 81 + cout3.mul(Mask::xy, cout3, reflect.w()); + // nop | mulw.xy vf28, vf28, vf16 82 + cout0.mul(Mask::xy, cout0, vtx0.w()); + // nop | mulw.xy vf29, vf29, vf17 83 + cout1.mul(Mask::xy, cout1, vtx1.w()); + // nop | mulw.xy vf30, vf30, vf18 84 + cout2.mul(Mask::xy, cout2, vtx2.w()); + // nop | mulw.xy vf31, vf31, vf19 85 + cout3.mul(Mask::xy, cout3, vtx3.w()); + // nop | ftoi0.xyzw vf16, vf16 86 + vtx0.ftoi0(Mask::xyzw, vtx0); + // nop | ftoi0.xyzw vf17, vf17 87 + vtx1.ftoi0(Mask::xyzw, vtx1); + // nop | ftoi0.xyzw vf18, vf18 88 + vtx2.ftoi0(Mask::xyzw, vtx2); + // iaddi vi01, vi01, -0x1 | ftoi0.xyzw vf19, vf19 89 + vtx3.ftoi0(Mask::xyzw, vtx3); loop_idx = loop_idx + -1; + // mfir.w vf16, vi11 | add.xyzw vf28, vf28, vf06 90 + cout0.add(Mask::xyzw, cout0, m_texture_constants.cam_nrm); vtx0.mfir(Mask::w, vi11); + // mfir.w vf17, vi11 | add.xyzw vf29, vf29, vf06 91 + cout1.add(Mask::xyzw, cout1, m_texture_constants.cam_nrm); vtx1.mfir(Mask::w, vi11); + // mfir.w vf18, vi11 | add.xyzw vf30, vf30, vf06 92 + cout2.add(Mask::xyzw, cout2, m_texture_constants.cam_nrm); vtx2.mfir(Mask::w, vi11); + // mfir.w vf19, vi11 | add.xyzw vf31, vf31, vf06 93 + cout3.add(Mask::xyzw, cout3, m_texture_constants.cam_nrm); vtx3.mfir(Mask::w, vi11); + // nop | mulx.xyzw vf28, vf28, vf07 94 + cout0.mul(Mask::xyzw, cout0, m_texture_constants.constants.x()); + // nop | mulx.xyzw vf29, vf29, vf07 95 + cout1.mul(Mask::xyzw, cout1, m_texture_constants.constants.x()); + // nop | mulx.xyzw vf30, vf30, vf07 96 + cout2.mul(Mask::xyzw, cout2, m_texture_constants.constants.x()); + // nop | mulx.xyzw vf31, vf31, vf07 97 + cout3.mul(Mask::xyzw, cout3, m_texture_constants.constants.x()); + // nop | addy.xyzw vf28, vf28, vf07 98 + cout0.add(Mask::xyzw, cout0, m_texture_constants.constants.y()); + // nop | addy.xyzw vf29, vf29, vf07 99 + cout1.add(Mask::xyzw, cout1, m_texture_constants.constants.y()); + // nop | addy.xyzw vf30, vf30, vf07 100 + cout2.add(Mask::xyzw, cout2, m_texture_constants.constants.y()); + // nop | addy.xyzw vf31, vf31, vf07 101 + cout3.add(Mask::xyzw, cout3, m_texture_constants.constants.y()); + // sq.xyzw vf16, 1(vi06) | sub.zw vf28, vf01, vf00 102 + cout0.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx0, vu.dbuf_write + 1); + // sq.xyzw vf17, 4(vi06) | sub.zw vf29, vf01, vf00 103 + cout1.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx1, vu.dbuf_write + 4); + // sq.xyzw vf18, 7(vi06) | sub.zw vf30, vf01, vf00 104 + cout2.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx2, vu.dbuf_write + 7); + // sq.xyzw vf19, 10(vi06) | sub.zw vf31, vf01, vf00 105 + cout3.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx3, vu.dbuf_write + 10); + // lq.xyzw vf24, 1(vi05) | mulw.xyzw vf20, vf15, vf00 106 + res0.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm0, vu.in_ptr + 1); + // lq.xyzw vf25, 3(vi05) | mulw.xyzw vf21, vf15, vf00 107 + res1.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm1, vu.in_ptr + 3); + // lq.xyzw vf26, 5(vi05) | mulw.xyzw vf22, vf15, vf00 108 + res2.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm2, vu.in_ptr + 5); + // sq.xyzw vf28, 0(vi06) | mulw.xyzw vf23, vf15, vf00 109 + res3.mul(Mask::xyzw, base_pos, 1.f); sq_buffer(Mask::xyzw, cout0, vu.dbuf_write); + + // sq.xyzw vf29, 3(vi06) | mulax.xyzw ACC, vf24, vf06 110 + acc.mula(Mask::xyzw, nrm0, m_texture_constants.cam_nrm.x()); sq_buffer(Mask::xyzw, cout1, vu.dbuf_write + 3); + // sq.xyzw vf30, 6(vi06) | madday.xyzw ACC, vf25, vf06 111 + acc.madda(Mask::xyzw, nrm1, m_texture_constants.cam_nrm.y()); sq_buffer(Mask::xyzw, cout2, vu.dbuf_write + 6); + // sq.xyzw vf31, 9(vi06) | maddz.xyzw vf27, vf26, vf06 112 + acc.madd(Mask::xyzw, reflect, nrm2, m_texture_constants.cam_nrm.z()); sq_buffer(Mask::xyzw, cout3, vu.dbuf_write + 9); + // BRANCH! + // ibgtz vi01, L4 | addx.x vf21, vf21, vf02 113 + res1.add(Mask::x, res1, m_texture_constants.offsets.x()); bc = ((s16)loop_idx) > 0; + // iaddi vi06, vi06, 0xc | addy.x vf22, vf22, vf02 114 + res2.add(Mask::x, res2, m_texture_constants.offsets.y()); vu.dbuf_write = vu.dbuf_write + 12; + if (bc) { goto L4; } + + // lq.xyzw vf28, 0(vi07) | addx.y vf14, vf14, vf02 115 + vu.startx.add(Mask::y, vu.startx, m_texture_constants.offsets.x()); lq_buffer(Mask::xyzw, cout0, vu.dbuf_write_base); + // lq.xyzw vf16, 1(vi07) | nop 116 + lq_buffer(Mask::xyzw, vtx0, vu.dbuf_write_base + 1); + // sq.xyzw vf20, 2(vi06) | nop 117 + sq_buffer(Mask::xyzw, res0, vu.dbuf_write + 2); + // sq.xyzw vf28, 0(vi06) | nop 118 + sq_buffer(Mask::xyzw, cout0, vu.dbuf_write); + // jr vi12 | nop 119 + // sq.xyzw vf16, 1(vi06) | nop 120 + sq_buffer(Mask::xyzw, vtx0, vu.dbuf_write + 1); + // clang-format on +} + +void OceanTexture::run_L5_PC() { + // clang-format off + u16 loop_idx; + Vf res0; + Vf res1; + Vf cout0; + Vf cout1; + Vf vtx0; + Vf vtx1; + bool bc; + // L5: + // iaddiu vi01, vi00, 0x21 | nop 121 + loop_idx = 0x21; /* 33 */ + // sq.xyzw vf05, 0(vi08) | nop 122 + sq_buffer_giftag(m_texture_constants.giftag, vu.tptr); + // iaddi vi08, vi08, 0x1 | nop 123 + vu.tptr = vu.tptr + 1; + L6: + // iaddi vi01, vi01, -0x1 | nop 124 + loop_idx = loop_idx + -1; + // lq.xyzw vf20, 2(vi03) | nop 125 + lq_buffer(Mask::xyzw, res0, vu.dbuf_read_a + 2); + // lq.xyzw vf21, 2(vi04) | nop 126 + lq_buffer(Mask::xyzw, res1, vu.dbuf_read_b + 2); + // lq.xyzw vf28, 0(vi03) | nop 127 + lq_buffer(Mask::xyzw, cout0, vu.dbuf_read_a); + // lq.xyzw vf16, 1(vi03) | nop 128 + lq_buffer(Mask::xyzw, vtx0, vu.dbuf_read_a + 1); + // lq.xyzw vf29, 0(vi04) | ftoi4.xyzw vf20, vf20 129 + res0.ftoi4(Mask::xyzw, res0); lq_buffer(Mask::xyzw, cout1, vu.dbuf_read_b); + // lq.xyzw vf17, 1(vi04) | ftoi4.xyzw vf21, vf21 130 + res1.ftoi4(Mask::xyzw, res1); lq_buffer(Mask::xyzw, vtx1, vu.dbuf_read_b + 1); + // sq.xyzw vf28, 0(vi08) | nop 131 + sq_buffer(Mask::xyzw, cout0, vu.tptr); + // sq.xyzw vf16, 1(vi08) | nop 132 + sq_buffer(Mask::xyzw, vtx0, vu.tptr + 1); + // sq.xyzw vf20, 2(vi08) | nop 133 + sq_buffer(Mask::xyzw, res0, vu.tptr + 2); + // sq.xyzw vf29, 3(vi08) | nop 134 + sq_buffer(Mask::xyzw, cout1, vu.tptr + 3); + // sq.xyzw vf17, 4(vi08) | nop 135 + sq_buffer(Mask::xyzw, vtx1, vu.tptr + 4); + // sq.xyzw vf21, 5(vi08) | nop 136 + sq_buffer(Mask::xyzw, res1, vu.tptr + 5); + + // iaddi vi03, vi03, 0x3 | nop 137 + vu.dbuf_read_a = vu.dbuf_read_a + 3; + // iaddi vi04, vi04, 0x3 | nop 138 + vu.dbuf_read_b = vu.dbuf_read_b + 3; + // BRANCH! + // ibgtz vi01, L6 | nop 139 + bc = ((s16)loop_idx) > 0; + // iaddi vi08, vi08, 0x6 | nop 140 + vu.tptr = vu.tptr + 6; + if (bc) { goto L6; } + + // xgkick vi09 | nop 141 + xgkick_PC(vu.tbase); + // mtir vi08, vf03.x | nop 142 + // vu.tptr = vu.vf03.x_as_u16(); + vu.tptr = get_tbuf(); + // mtir vi09, vf03.x | nop 143 + // vu.vi09 = vu.vf03.x_as_u16(); + vu.tbase = get_tbuf(); + // jr vi12 | nop 144 + // ASSERT(false); + // mr32.xyzw vf03, vf03 | nop 145 + // vu.vf03.mr32(Mask::xyzw, vu.vf03); + swap_tbuf(); + // clang-format on +} + +void OceanTexture::xgkick_PC(Vf* src) { + // we're going to rely on the data being the exact layout we expect here. + u32 offset = 16; + const u8* data = (const u8*)src; + + for (u32 i = 0; i < NUM_VERTS_PER_STRIP; i++) { + auto& v = m_pc.vertex_dynamic[m_pc.vtx_idx]; + // st + memcpy(&v.s, data + offset, sizeof(float) * 2); + // rgbaq + v.rgba.x() = data[offset + 16]; + v.rgba.y() = data[offset + 20]; + v.rgba.z() = data[offset + 24]; + v.rgba.w() = data[offset + 28]; // we don't actually need it, it's always 0x80 + + // xyz2 + offset += 48; + m_pc.vtx_idx++; + } +} + +void OceanTexture::setup_pc() { + m_pc.vtx_idx = 0; +} + +void OceanTexture::flush_pc(SharedRenderState* render_state, ScopedProfilerNode& prof) { + ASSERT(m_pc.vtx_idx == 2112); + glBindVertexArray(m_pc.vao); + glBindBuffer(GL_ARRAY_BUFFER, m_pc.dynamic_vertex_buffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * NUM_VERTS, m_pc.vertex_dynamic.data(), + GL_DYNAMIC_DRAW); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pc.gl_index_buffer); + + render_state->shaders[ShaderId::OCEAN_TEXTURE].activate(); + + GsTex0 tex0(m_envmap_adgif.tex0_data); + auto lookup = render_state->texture_pool->lookup(tex0.tbp0()); + if (!lookup) { + lookup = render_state->texture_pool->get_placeholder_texture(); + } + // no decal + // yes tcc + glActiveTexture(GL_TEXTURE0); + glBindTexture(GL_TEXTURE_2D, *lookup); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + + glUniform1i(glGetUniformLocation(render_state->shaders[ShaderId::OCEAN_TEXTURE].id(), "tex_T0"), + 0); + + glDisable(GL_DEPTH_TEST); + glDisable(GL_BLEND); + // glDrawArrays(GL_TRIANGLE_STRIP, 0, NUM_VERTS); + glEnable(GL_PRIMITIVE_RESTART); + glPrimitiveRestartIndex(UINT32_MAX); + glDrawElements(GL_TRIANGLE_STRIP, m_pc.index_buffer.size(), GL_UNSIGNED_INT, (void*)0); + prof.add_draw_call(); + prof.add_tri(NUM_STRIPS * NUM_STRIPS * 2); + + glBindVertexArray(0); +} + +void OceanTexture::init_pc() { + int i = 0; + m_pc.vertex_positions.resize(NUM_VERTS); + m_pc.vertex_dynamic.resize(NUM_VERTS); + m_pc.index_buffer.clear(); + for (u32 strip = 0; strip < NUM_STRIPS; strip++) { + u32 lo = 64 * strip; + u32 hi = 64 * (strip + 1); + for (u32 vert_pair = 0; vert_pair < NUM_VERTS_PER_STRIP / 2; vert_pair++) { + m_pc.index_buffer.push_back(i); + auto& v0 = m_pc.vertex_positions[i++]; + v0 = math::Vector2f(vert_pair * 64, lo); + m_pc.index_buffer.push_back(i); + auto& v1 = m_pc.vertex_positions[i++]; + v1 = math::Vector2f(vert_pair * 64, hi); + } + m_pc.index_buffer.push_back(UINT32_MAX); + } + + glGenVertexArrays(1, &m_pc.vao); + glBindVertexArray(m_pc.vao); + + glGenBuffers(1, &m_pc.gl_index_buffer); + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pc.gl_index_buffer); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(u32) * m_pc.index_buffer.size(), + m_pc.index_buffer.data(), GL_STATIC_DRAW); + + glGenBuffers(1, &m_pc.static_vertex_buffer); + glBindBuffer(GL_ARRAY_BUFFER, m_pc.static_vertex_buffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(math::Vector4f) * NUM_VERTS, m_pc.vertex_positions.data(), + GL_STATIC_DRAW); + glEnableVertexAttribArray(0); + glEnableVertexAttribArray(1); + glEnableVertexAttribArray(2); + + glVertexAttribPointer(0, // location 0 in the shader + 2, // 3 floats per vert + GL_FLOAT, // floats + GL_TRUE, // normalized, ignored, + 0, // tightly packed + 0 + + ); + + glGenBuffers(1, &m_pc.dynamic_vertex_buffer); + glBindBuffer(GL_ARRAY_BUFFER, m_pc.dynamic_vertex_buffer); + glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * NUM_VERTS, nullptr, GL_DYNAMIC_DRAW); + glVertexAttribPointer(1, // location 0 in the shader + 4, // 4 color components + GL_UNSIGNED_BYTE, // floats + GL_TRUE, // normalized, ignored, + sizeof(Vertex), // + (void*)offsetof(Vertex, rgba) // offset in array (why is this a pointer...) + ); + glVertexAttribPointer(2, // location 0 in the shader + 2, // 2 floats per vert + GL_FLOAT, // floats + GL_FALSE, // normalized, ignored, + sizeof(Vertex), // + (void*)offsetof(Vertex, s) // offset in array (why is this a pointer...) + ); +} + +void OceanTexture::destroy_pc() {} \ No newline at end of file diff --git a/game/graphics/opengl_renderer/ocean/OceanTexture_PS2.cpp b/game/graphics/opengl_renderer/ocean/OceanTexture_PS2.cpp new file mode 100644 index 0000000000..c5f76903a1 --- /dev/null +++ b/game/graphics/opengl_renderer/ocean/OceanTexture_PS2.cpp @@ -0,0 +1,378 @@ +#include "OceanTexture.h" + +void OceanTexture::run_L1(SharedRenderState* render_state, ScopedProfilerNode& prof) { + // L1: + // lq.xyzw vf14_startx, 988(vi00) | maxw.xyzw vf01_ones, vf00, vf00 + vu.startx = Vf(m_texture_constants.start); + // lq.xyzw vf02_offset, 989(vi00) + // lq.xyzw vf03_tbuf, 986(vi00) + // lq.xyzw vf04_dbuf, 987(vi00) + // lq.xyzw vf05_giftag, 985(vi00) + // lq.xyzw vf06_cam_nrm, 991(vi00) + // lq.xyzw vf07_constants, 990(vi00) + // iaddiu vi11_0x80, vi00, 0x80 + // mtir vi08_tptr, vf03_tbuf.x + vu.tptr = get_tbuf(); + // mtir vi09_tbase, vf03_tbuf.x + vu.tbase = get_tbuf(); + // mr32.xyzw vf03_tbuf, vf03_tbuf + swap_tbuf(); + // xtop vi05_in_ptr + vu.in_ptr = swap_vu_upload_buffers(); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3(); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5(render_state, prof); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5(render_state, prof); + + // nop :e + // nop +} + +void OceanTexture::run_L2(SharedRenderState* render_state, ScopedProfilerNode& prof) { + // L2: + // xtop vi05_in_ptr + vu.in_ptr = swap_vu_upload_buffers(); + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5(render_state, prof); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5(render_state, prof); + + // mtir vi06_dbuf_write, vf04_dbuf.x + vu.dbuf_write = get_dbuf(); + // bal vi12_ra, L3 + // mr32.xyzw vf04_dbuf, vf04_dbuf + swap_dbuf(); + run_L3(); + + // mtir vi03_dbuf_read_a, vf04_dbuf.x + vu.dbuf_read_a = get_dbuf(); + // bal vi12_ra, L5 + // mtir vi04_dbuf_read_b, vf04_dbuf.y + vu.dbuf_read_b = get_dbuf_other(); + run_L5(render_state, prof); + + // nop :e + // nop +} + +namespace { +void lq_buffer(Mask mask, Vf& dest, Vf* src) { + for (int i = 0; i < 4; i++) { + if ((u64)mask & (1 << i)) { + dest.data[i] = src->data[i]; + } + } +} + +void sq_buffer(Mask mask, const Vf& src, Vf* dest) { + for (int i = 0; i < 4; i++) { + if ((u64)mask & (1 << i)) { + dest->data[i] = src.data[i]; + } + } +} + +void sq_buffer_giftag(const u8* src, Vf* dest) { + memcpy(dest, src, 16); +} +} // namespace + +void OceanTexture::run_L3() { + Vf base_pos; // vf15 + u16 loop_idx; + + Vf vtx0; // vf16 + Vf vtx1; // vf17 + Vf vtx2; // vf18 + Vf vtx3; // vf19 + + Vf res0; // vf20 + Vf res1; // vf21 + Vf res2; // vf22 + Vf res3; // vf23 + + Vf nrm0; // vf24 + Vf nrm1; // vf25 + Vf nrm2; // vf26 + + Vf reflect; // vf27 + + Vf cout0; // vf28 + Vf cout1; // vf29 + Vf cout2; // vf30 + Vf cout3; // vf31 + + Accumulator acc; + const Vf ones(1, 1, 1, 1); + const Vf vf00(0, 0, 0, 1); + const u16 vi11 = 0x80; + bool bc; + + // clang-format off + // L3: + // ior vi07, vi06, vi00 | nop 56 + vu.dbuf_write_base = vu.dbuf_write; + // move.xyzw vf15, vf14 | nop 57 + base_pos.move(Mask::xyzw, vu.startx); + // iaddi vi01, vi00, 0x8 | nop 58 + loop_idx = 8; + // lq.xyzw vf24, 1(vi05) | mulw.xyzw vf20, vf15, vf00 59 (?? what are they doing here) + res0.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm0, vu.in_ptr + 1); + // lq.xyzw vf25, 3(vi05) | mulw.xyzw vf21, vf15, vf00 60 + res1.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm1, vu.in_ptr + 3); + // lq.xyzw vf26, 5(vi05) | mulw.xyzw vf22, vf15, vf00 61 + res2.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm2, vu.in_ptr + 5); + // nop | mulw.xyzw vf23, vf15, vf00 62 + res3.mul(Mask::xyzw, base_pos, 1.f); + // nop | mulax.xyzw ACC, vf24, vf06 63 + acc.mula(Mask::xyzw, nrm0, m_texture_constants.cam_nrm.x()); + // nop | madday.xyzw ACC, vf25, vf06 64 + acc.madda(Mask::xyzw, nrm1, m_texture_constants.cam_nrm.y()); + // nop | maddz.xyzw vf27, vf26, vf06 65 + acc.madd(Mask::xyzw, reflect, nrm2, m_texture_constants.cam_nrm.z()); + // nop | addx.x vf21, vf21, vf02 66 + res1.add(Mask::x, res1, m_texture_constants.offsets.x()); + // nop | addy.x vf22, vf22, vf02 67 + res2.add(Mask::x, res2, m_texture_constants.offsets.y()); + L4: + // nop | addz.x vf23, vf23, vf02 68 + res3.add(Mask::x, res3, m_texture_constants.offsets.z()); + // nop | addw.x vf15, vf15, vf02 69 + base_pos.add(Mask::x, base_pos, m_texture_constants.offsets.w()); + // sq.xyzw vf20, 2(vi06) | mulx.x vf28, vf01, vf24 70 + cout0.mul(Mask::x, ones, nrm0.x()); sq_buffer(Mask::xyzw, res0, vu.dbuf_write + 2); + // sq.xyzw vf21, 5(vi06) | muly.x vf29, vf01, vf24 71 + cout1.mul(Mask::x, ones, nrm0.y()); sq_buffer(Mask::xyzw, res1, vu.dbuf_write + 5); + // sq.xyzw vf22, 8(vi06) | mulz.x vf30, vf01, vf24 72 + cout2.mul(Mask::x, ones, nrm0.z()); sq_buffer(Mask::xyzw, res2, vu.dbuf_write + 8); + // sq.xyzw vf23, 11(vi06) | mulw.x vf31, vf01, vf24 73 + cout3.mul(Mask::x, ones, nrm0.w()); sq_buffer(Mask::xyzw, res3, vu.dbuf_write + 11); + // lq.xyzw vf16, 0(vi05) | mulx.y vf28, vf01, vf25 74 + cout0.mul(Mask::y, ones, nrm1.x()); lq_buffer(Mask::xyzw, vtx0, vu.in_ptr); + // lq.xyzw vf17, 2(vi05) | muly.y vf29, vf01, vf25 75 + cout1.mul(Mask::y, ones, nrm1.y()); lq_buffer(Mask::xyzw, vtx1, vu.in_ptr + 2); + // lq.xyzw vf18, 4(vi05) | mulz.y vf30, vf01, vf25 76 + cout2.mul(Mask::y, ones, nrm1.z()); lq_buffer(Mask::xyzw, vtx2, vu.in_ptr + 4); + // lq.xyzw vf19, 6(vi05) | mulw.y vf31, vf01, vf25 77 + cout3.mul(Mask::y, ones, nrm1.w()); lq_buffer(Mask::xyzw, vtx3, vu.in_ptr + 6); + // iaddi vi05, vi05, 0x8 | mulx.xy vf28, vf28, vf27 78 + cout0.mul(Mask::xy, cout0, reflect.x()); vu.in_ptr = vu.in_ptr + 8; + // nop | muly.xy vf29, vf29, vf27 79 + cout1.mul(Mask::xy, cout1, reflect.y()); + // nop | mulz.xy vf30, vf30, vf27 80 + cout2.mul(Mask::xy, cout2, reflect.z()); + // nop | mulw.xy vf31, vf31, vf27 81 + cout3.mul(Mask::xy, cout3, reflect.w()); + // nop | mulw.xy vf28, vf28, vf16 82 + cout0.mul(Mask::xy, cout0, vtx0.w()); + // nop | mulw.xy vf29, vf29, vf17 83 + cout1.mul(Mask::xy, cout1, vtx1.w()); + // nop | mulw.xy vf30, vf30, vf18 84 + cout2.mul(Mask::xy, cout2, vtx2.w()); + // nop | mulw.xy vf31, vf31, vf19 85 + cout3.mul(Mask::xy, cout3, vtx3.w()); + // nop | ftoi0.xyzw vf16, vf16 86 + vtx0.ftoi0(Mask::xyzw, vtx0); + // nop | ftoi0.xyzw vf17, vf17 87 + vtx1.ftoi0(Mask::xyzw, vtx1); + // nop | ftoi0.xyzw vf18, vf18 88 + vtx2.ftoi0(Mask::xyzw, vtx2); + // iaddi vi01, vi01, -0x1 | ftoi0.xyzw vf19, vf19 89 + vtx3.ftoi0(Mask::xyzw, vtx3); loop_idx = loop_idx + -1; + // mfir.w vf16, vi11 | add.xyzw vf28, vf28, vf06 90 + cout0.add(Mask::xyzw, cout0, m_texture_constants.cam_nrm); vtx0.mfir(Mask::w, vi11); + // mfir.w vf17, vi11 | add.xyzw vf29, vf29, vf06 91 + cout1.add(Mask::xyzw, cout1, m_texture_constants.cam_nrm); vtx1.mfir(Mask::w, vi11); + // mfir.w vf18, vi11 | add.xyzw vf30, vf30, vf06 92 + cout2.add(Mask::xyzw, cout2, m_texture_constants.cam_nrm); vtx2.mfir(Mask::w, vi11); + // mfir.w vf19, vi11 | add.xyzw vf31, vf31, vf06 93 + cout3.add(Mask::xyzw, cout3, m_texture_constants.cam_nrm); vtx3.mfir(Mask::w, vi11); + // nop | mulx.xyzw vf28, vf28, vf07 94 + cout0.mul(Mask::xyzw, cout0, m_texture_constants.constants.x()); + // nop | mulx.xyzw vf29, vf29, vf07 95 + cout1.mul(Mask::xyzw, cout1, m_texture_constants.constants.x()); + // nop | mulx.xyzw vf30, vf30, vf07 96 + cout2.mul(Mask::xyzw, cout2, m_texture_constants.constants.x()); + // nop | mulx.xyzw vf31, vf31, vf07 97 + cout3.mul(Mask::xyzw, cout3, m_texture_constants.constants.x()); + // nop | addy.xyzw vf28, vf28, vf07 98 + cout0.add(Mask::xyzw, cout0, m_texture_constants.constants.y()); + // nop | addy.xyzw vf29, vf29, vf07 99 + cout1.add(Mask::xyzw, cout1, m_texture_constants.constants.y()); + // nop | addy.xyzw vf30, vf30, vf07 100 + cout2.add(Mask::xyzw, cout2, m_texture_constants.constants.y()); + // nop | addy.xyzw vf31, vf31, vf07 101 + cout3.add(Mask::xyzw, cout3, m_texture_constants.constants.y()); + // sq.xyzw vf16, 1(vi06) | sub.zw vf28, vf01, vf00 102 + cout0.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx0, vu.dbuf_write + 1); + // sq.xyzw vf17, 4(vi06) | sub.zw vf29, vf01, vf00 103 + cout1.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx1, vu.dbuf_write + 4); + // sq.xyzw vf18, 7(vi06) | sub.zw vf30, vf01, vf00 104 + cout2.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx2, vu.dbuf_write + 7); + // sq.xyzw vf19, 10(vi06) | sub.zw vf31, vf01, vf00 105 + cout3.sub(Mask::zw, ones, vf00); sq_buffer(Mask::xyzw, vtx3, vu.dbuf_write + 10); + // lq.xyzw vf24, 1(vi05) | mulw.xyzw vf20, vf15, vf00 106 + res0.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm0, vu.in_ptr + 1); + // lq.xyzw vf25, 3(vi05) | mulw.xyzw vf21, vf15, vf00 107 + res1.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm1, vu.in_ptr + 3); + // lq.xyzw vf26, 5(vi05) | mulw.xyzw vf22, vf15, vf00 108 + res2.mul(Mask::xyzw, base_pos, 1.f); lq_buffer(Mask::xyzw, nrm2, vu.in_ptr + 5); + // sq.xyzw vf28, 0(vi06) | mulw.xyzw vf23, vf15, vf00 109 + res3.mul(Mask::xyzw, base_pos, 1.f); sq_buffer(Mask::xyzw, cout0, vu.dbuf_write); + // sq.xyzw vf29, 3(vi06) | mulax.xyzw ACC, vf24, vf06 110 + acc.mula(Mask::xyzw, nrm0, m_texture_constants.cam_nrm.x()); sq_buffer(Mask::xyzw, cout1, vu.dbuf_write + 3); + // sq.xyzw vf30, 6(vi06) | madday.xyzw ACC, vf25, vf06 111 + acc.madda(Mask::xyzw, nrm1, m_texture_constants.cam_nrm.y()); sq_buffer(Mask::xyzw, cout2, vu.dbuf_write + 6); + // sq.xyzw vf31, 9(vi06) | maddz.xyzw vf27, vf26, vf06 112 + acc.madd(Mask::xyzw, reflect, nrm2, m_texture_constants.cam_nrm.z()); sq_buffer(Mask::xyzw, cout3, vu.dbuf_write + 9); + // BRANCH! + // ibgtz vi01, L4 | addx.x vf21, vf21, vf02 113 + res1.add(Mask::x, res1, m_texture_constants.offsets.x()); bc = ((s16)loop_idx) > 0; + // iaddi vi06, vi06, 0xc | addy.x vf22, vf22, vf02 114 + res2.add(Mask::x, res2, m_texture_constants.offsets.y()); vu.dbuf_write = vu.dbuf_write + 12; + if (bc) { goto L4; } + + // lq.xyzw vf28, 0(vi07) | addx.y vf14, vf14, vf02 115 + vu.startx.add(Mask::y, vu.startx, m_texture_constants.offsets.x()); lq_buffer(Mask::xyzw, cout0, vu.dbuf_write_base); + // lq.xyzw vf16, 1(vi07) | nop 116 + lq_buffer(Mask::xyzw, vtx0, vu.dbuf_write_base + 1); + // sq.xyzw vf20, 2(vi06) | nop 117 + sq_buffer(Mask::xyzw, res0, vu.dbuf_write + 2); + // sq.xyzw vf28, 0(vi06) | nop 118 + sq_buffer(Mask::xyzw, cout0, vu.dbuf_write); + // jr vi12 | nop 119 + // sq.xyzw vf16, 1(vi06) | nop 120 + sq_buffer(Mask::xyzw, vtx0, vu.dbuf_write + 1); + // clang-format on +} + +void OceanTexture::run_L5(SharedRenderState* render_state, ScopedProfilerNode& prof) { + // clang-format off + u16 loop_idx; + Vf res0; + Vf res1; + Vf cout0; + Vf cout1; + Vf vtx0; + Vf vtx1; + bool bc; + // L5: + // iaddiu vi01, vi00, 0x21 | nop 121 + loop_idx = 0x21; /* 33 */ + // sq.xyzw vf05, 0(vi08) | nop 122 + sq_buffer_giftag(m_texture_constants.giftag, vu.tptr); + // iaddi vi08, vi08, 0x1 | nop 123 + vu.tptr = vu.tptr + 1; + L6: + // iaddi vi01, vi01, -0x1 | nop 124 + loop_idx = loop_idx + -1; + // lq.xyzw vf20, 2(vi03) | nop 125 + lq_buffer(Mask::xyzw, res0, vu.dbuf_read_a + 2); + // lq.xyzw vf21, 2(vi04) | nop 126 + lq_buffer(Mask::xyzw, res1, vu.dbuf_read_b + 2); + // lq.xyzw vf28, 0(vi03) | nop 127 + lq_buffer(Mask::xyzw, cout0, vu.dbuf_read_a); + // lq.xyzw vf16, 1(vi03) | nop 128 + lq_buffer(Mask::xyzw, vtx0, vu.dbuf_read_a + 1); + // lq.xyzw vf29, 0(vi04) | ftoi4.xyzw vf20, vf20 129 + res0.ftoi4(Mask::xyzw, res0); lq_buffer(Mask::xyzw, cout1, vu.dbuf_read_b); + // lq.xyzw vf17, 1(vi04) | ftoi4.xyzw vf21, vf21 130 + res1.ftoi4(Mask::xyzw, res1); lq_buffer(Mask::xyzw, vtx1, vu.dbuf_read_b + 1); + // sq.xyzw vf28, 0(vi08) | nop 131 + sq_buffer(Mask::xyzw, cout0, vu.tptr); + // sq.xyzw vf16, 1(vi08) | nop 132 + sq_buffer(Mask::xyzw, vtx0, vu.tptr + 1); + // sq.xyzw vf20, 2(vi08) | nop 133 + sq_buffer(Mask::xyzw, res0, vu.tptr + 2); + // sq.xyzw vf29, 3(vi08) | nop 134 + sq_buffer(Mask::xyzw, cout1, vu.tptr + 3); + // sq.xyzw vf17, 4(vi08) | nop 135 + sq_buffer(Mask::xyzw, vtx1, vu.tptr + 4); + // sq.xyzw vf21, 5(vi08) | nop 136 + sq_buffer(Mask::xyzw, res1, vu.tptr + 5); + + // iaddi vi03, vi03, 0x3 | nop 137 + vu.dbuf_read_a = vu.dbuf_read_a + 3; + // iaddi vi04, vi04, 0x3 | nop 138 + vu.dbuf_read_b = vu.dbuf_read_b + 3; + // BRANCH! + // ibgtz vi01, L6 | nop 139 + bc = ((s16)loop_idx) > 0; + // iaddi vi08, vi08, 0x6 | nop 140 + vu.tptr = vu.tptr + 6; + if (bc) { goto L6; } + + // xgkick vi09 | nop 141 + xgkick(vu.tbase, render_state, prof); + // mtir vi08, vf03.x | nop 142 + // vu.tptr = vu.vf03.x_as_u16(); + vu.tptr = get_tbuf(); + // mtir vi09, vf03.x | nop 143 + // vu.vi09 = vu.vf03.x_as_u16(); + vu.tbase = get_tbuf(); + // jr vi12 | nop 144 + // ASSERT(false); + // mr32.xyzw vf03, vf03 | nop 145 + // vu.vf03.mr32(Mask::xyzw, vu.vf03); + swap_tbuf(); + // clang-format on +} + +void OceanTexture::xgkick(Vf* src, SharedRenderState* render_state, ScopedProfilerNode& prof) { + // KICK + m_hack_renderer.render_gif((const u8*)src, UINT32_MAX, render_state, prof); +} \ No newline at end of file diff --git a/game/graphics/opengl_renderer/shaders/ocean_texture.frag b/game/graphics/opengl_renderer/shaders/ocean_texture.frag new file mode 100644 index 0000000000..20fe614b9d --- /dev/null +++ b/game/graphics/opengl_renderer/shaders/ocean_texture.frag @@ -0,0 +1,12 @@ +#version 430 core + +out vec4 color; +in vec2 tex_coord; +in vec4 fragment_color; + +uniform sampler2D tex_T0; + +void main() { + vec4 tex = texture(tex_T0, tex_coord); + color = fragment_color * tex * 2; +} \ No newline at end of file diff --git a/game/graphics/opengl_renderer/shaders/ocean_texture.vert b/game/graphics/opengl_renderer/shaders/ocean_texture.vert new file mode 100644 index 0000000000..c1de212665 --- /dev/null +++ b/game/graphics/opengl_renderer/shaders/ocean_texture.vert @@ -0,0 +1,15 @@ +#version 430 core + +layout (location = 0) in vec2 position_in; +layout (location = 1) in vec4 rgba_in; +layout (location = 2) in vec2 tex_coord_in; + +out vec4 fragment_color; +out vec2 tex_coord; + +void main() { + // inputs are 0 - 2048. + gl_Position = vec4((position_in.x - 1024) / 1024, (position_in.y - 1024) / 1024, 0.5, 1.0); + fragment_color = vec4(rgba_in.x, rgba_in.y, rgba_in.z, 1); + tex_coord = tex_coord_in; +} diff --git a/game/kernel/kmemcard.cpp b/game/kernel/kmemcard.cpp index e89a8b3b4c..da1f1ed3a1 100644 --- a/game/kernel/kmemcard.cpp +++ b/game/kernel/kmemcard.cpp @@ -714,7 +714,7 @@ void MC_set_language(s32 l) { * Set the current memory card operation to FORMAT the given card. * Doesn't do anything in the port because we don't use memory cards. */ -u64 MC_format(s32 card_idx) { +u64 MC_format(s32 /*card_idx*/) { return u64(McStatusCode::OK); // u64 can_add = op.operation == MemoryCardOperationKind::NO_OP; // mc_print("requested format"); @@ -732,7 +732,7 @@ u64 MC_format(s32 card_idx) { * Set the current memory card operation to UNFORMAT the given card. * You get the idea. */ -u64 MC_unformat(s32 card_idx) { +u64 MC_unformat(s32 /*card_idx*/) { return u64(McStatusCode::OK); // u64 can_add = op.operation == MemoryCardOperationKind::NO_OP; // mc_print("requested unformat"); @@ -750,7 +750,7 @@ u64 MC_unformat(s32 card_idx) { * Set the current memory card operation to create the save file. * The data I believe is just an empty buffer used as temporary storage. */ -u64 MC_createfile(s32 param, Ptr data) { +u64 MC_createfile(s32 /*param*/, Ptr /*data*/) { return u64(McStatusCode::OK); // u64 can_add = op.operation == MemoryCardOperationKind::NO_OP; // mc_print("requested createfile"); diff --git a/game/mips2c/functions/ocean.cpp b/game/mips2c/functions/ocean.cpp index e4c5019ce5..3df9501262 100644 --- a/game/mips2c/functions/ocean.cpp +++ b/game/mips2c/functions/ocean.cpp @@ -14,8 +14,6 @@ struct Cache { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; - bool bc = false; - u32 call_addr = 0; c->daddiu(sp, sp, -16); // daddiu sp, sp, -16 c->sd(fp, 8, sp); // sd fp, 8(sp) c->mov64(fp, t9); // or fp, t9, r0 @@ -280,8 +278,6 @@ struct Cache { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; c->copy_vfs_from_other(&ocean_regs_vfs); - bool bc = false; - u32 call_addr = 0; c->mov64(v1, a0); // or v1, a0, r0 get_fake_spad_addr(t4, cache.fake_scratchpad_data, 0, c);// lui t4, 28672 c->ori(t4, t4, 12288); // ori t4, t4, 12288 diff --git a/game/mips2c/functions/ocean_vu0.cpp b/game/mips2c/functions/ocean_vu0.cpp index f6578f8a53..1500153372 100644 --- a/game/mips2c/functions/ocean_vu0.cpp +++ b/game/mips2c/functions/ocean_vu0.cpp @@ -12,7 +12,6 @@ struct Cache { u64 execute(void* ctxt) { auto* c = (ExecutionContext*)ctxt; bool bc = false; - u32 call_addr = 0; c->daddiu(sp, sp, -16); // daddiu sp, sp, -16 c->sd(fp, 8, sp); // sd fp, 8(sp) c->mov64(fp, t9); // or fp, t9, r0 @@ -217,7 +216,6 @@ struct Cache { } cache; void vcallms0(ExecutionContext* c) { - float Q = 0; // nop | mulay.x ACC, vf12, vf02 0 c->acc.vf.mula(Mask::x, c->vf_src(vf12).vf, c->vf_src(vf02).vf.y()); // nop | mulax.z ACC, vf12, vf03 1 @@ -293,7 +291,7 @@ void vcallms0(ExecutionContext* c) { // nop | maddz.xyz vf17, vf07, vf25 34 c->acc.vf.madd(Mask::xyz, c->vfs[vf17].vf, c->vf_src(vf07).vf, c->vf_src(vf25).vf.z()); // div Q, vf00.w, vf24.z | subw.z vf25, vf25, vf00 35 - c->vfs[vf25].vf.sub(Mask::z, c->vf_src(vf25).vf, c->vf_src(vf00).vf.w()); Q = 1.f / c->vf_src(vf24).vf.z(); + c->vfs[vf25].vf.sub(Mask::z, c->vf_src(vf25).vf, c->vf_src(vf00).vf.w()); c->Q = 1.f / c->vf_src(vf24).vf.z(); // nop | mulax.xyzw ACC, vf05, vf26 36 c->acc.vf.mula(Mask::xyzw, c->vf_src(vf05).vf, c->vf_src(vf26).vf.x()); // nop | madday.xyzw ACC, vf06, vf26 37 @@ -309,7 +307,7 @@ void vcallms0(ExecutionContext* c) { // nop | mul.w vf20, vf00, Q 42 c->vfs[vf20].vf.mul(Mask::w, c->vf_src(vf00).vf, c->Q); // div Q, vf00.w, vf25.z | maddz.xyz vf19, vf07, vf27 43 - c->acc.vf.madd(Mask::xyz, c->vfs[vf19].vf, c->vf_src(vf07).vf, c->vf_src(vf27).vf.z()); Q = 1.f / c->vf_src(vf25).vf.z(); + c->acc.vf.madd(Mask::xyz, c->vfs[vf19].vf, c->vf_src(vf07).vf, c->vf_src(vf27).vf.z()); c->Q = 1.f / c->vf_src(vf25).vf.z(); // nop | subw.z vf27, vf27, vf00 44 c->vfs[vf27].vf.sub(Mask::z, c->vf_src(vf27).vf, c->vf_src(vf00).vf.w()); // nop | maxx.xyz vf16, vf16, vf00 45 @@ -323,7 +321,7 @@ void vcallms0(ExecutionContext* c) { // nop | mul.w vf21, vf00, Q 49 c->vfs[vf21].vf.mul(Mask::w, c->vf_src(vf00).vf, c->Q); // div Q, vf00.w, vf26.z | mula.xyzw ACC, vf01, vf11 50 - c->acc.vf.mula(Mask::xyzw, c->vf_src(vf01).vf, c->vf_src(vf11).vf); Q = 1.f / c->vf_src(vf26).vf.z(); + c->acc.vf.mula(Mask::xyzw, c->vf_src(vf01).vf, c->vf_src(vf11).vf); c->Q = 1.f / c->vf_src(vf26).vf.z(); // nop | maddax.xyz ACC, vf08, vf16 51 c->acc.vf.madda(Mask::xyz, c->vfs[vf08].vf, c->vfs[vf16].vf.x()); // nop | madday.xyz ACC, vf09, vf16 52 @@ -344,7 +342,7 @@ void vcallms0(ExecutionContext* c) { // div Q, vf00.w, vf27.z | mula.xyzw ACC, vf01, vf11 59 // vu.acc.mula(Mask::xyzw, vu.vf01, vu.vf11); c->acc.vf.mula(Mask::xyzw, c->vf_src(vf01).vf, c->vf_src(vf11).vf); - Q = 1.f / c->vf_src(vf27).vf.z(); + c->Q = 1.f / c->vf_src(vf27).vf.z(); // nop | maddax.xyz ACC, vf08, vf18 60 c->acc.vf.madda(Mask::xyz, c->vfs[vf08].vf, c->vfs[vf18].vf.x()); // nop | madday.xyz ACC, vf09, vf18 61 From 2ee5b37a3e6c62f31700e9edbcb52e49ec9f57a1 Mon Sep 17 00:00:00 2001 From: water Date: Fri, 11 Mar 2022 21:59:14 -0500 Subject: [PATCH 6/6] update ref test --- .../reference/engine/gfx/ocean/ocean-h_REF.gc | 14 ++++---- .../engine/gfx/ocean/ocean-texture_REF.gc | 34 +++++++++++-------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/test/decompiler/reference/engine/gfx/ocean/ocean-h_REF.gc b/test/decompiler/reference/engine/gfx/ocean/ocean-h_REF.gc index a55e9bd494..a8291999ae 100644 --- a/test/decompiler/reference/engine/gfx/ocean/ocean-h_REF.gc +++ b/test/decompiler/reference/engine/gfx/ocean/ocean-h_REF.gc @@ -472,13 +472,13 @@ ;; definition of type ocean-texture-constants (deftype ocean-texture-constants (structure) - ((giftag qword :inline :offset-assert 0) - (buffers vector4w :inline :offset-assert 16) - (dests vector4w :inline :offset-assert 32) - (start vector :inline :offset-assert 48) - (offsets vector :inline :offset-assert 64) - (constants vector :inline :offset-assert 80) - (cam-nrm vector :inline :offset-assert 96) + ((giftag gs-gif-tag :inline :offset-assert 0) + (buffers vector4w :inline :offset-assert 16) + (dests vector4w :inline :offset-assert 32) + (start vector :inline :offset-assert 48) + (offsets vector :inline :offset-assert 64) + (constants vector :inline :offset-assert 80) + (cam-nrm vector :inline :offset-assert 96) ) :method-count-assert 9 :size-assert #x70 diff --git a/test/decompiler/reference/engine/gfx/ocean/ocean-texture_REF.gc b/test/decompiler/reference/engine/gfx/ocean/ocean-texture_REF.gc index 0bd449b5f2..fb4b80657c 100644 --- a/test/decompiler/reference/engine/gfx/ocean/ocean-texture_REF.gc +++ b/test/decompiler/reference/engine/gfx/ocean/ocean-texture_REF.gc @@ -48,8 +48,18 @@ ;; definition for function ocean-texture-setup-constants ;; INFO: Return type mismatch int vs none. (defun ocean-texture-setup-constants ((arg0 ocean-texture-constants)) - (set! (-> arg0 giftag dword 0) (make-u128 0 (the-as uint #x300e400000008042))) - (set! (-> arg0 giftag dword 1) (the-as uint 1298)) + (set! (-> arg0 giftag tag) + (new 'static 'gif-tag64 + :nloop #x42 + :eop #x1 + :pre #x1 + :prim (new 'static 'gs-prim :prim (gs-prim-type tri-strip) :iip #x1 :tme #x1) + :nreg #x3 + ) + ) + (set! (-> arg0 giftag regs) + (new 'static 'gif-tag-regs :regs0 (gif-reg-id st) :regs1 (gif-reg-id rgbaq) :regs2 (gif-reg-id xyz2)) + ) (set-vector! (-> arg0 buffers) 384 583 384 583) (set-vector! (-> arg0 dests) 782 881 782 881) (set-vector! (-> arg0 start) 0.0 0.0 1048575.94 0.0) @@ -103,7 +113,7 @@ ) ;; definition for function ocean-texture-add-verts -(defun ocean-texture-add-verts ((arg0 dma-buffer) (arg1 (pointer vector))) +(defun ocean-texture-add-verts ((arg0 dma-buffer) (arg1 (inline-array vector))) (let* ((v1-0 arg0) (a0-1 (the-as object (-> v1-0 base))) ) @@ -122,7 +132,7 @@ ) ;; definition for function ocean-texture-add-verts-last -(defun ocean-texture-add-verts-last ((arg0 dma-buffer) (arg1 (pointer vector)) (arg2 (pointer vector))) +(defun ocean-texture-add-verts-last ((arg0 dma-buffer) (arg1 (inline-array vector)) (arg2 (inline-array vector))) (let* ((v1-0 arg0) (a3-0 (the-as object (-> v1-0 base))) ) @@ -197,8 +207,8 @@ ;; definition for function draw-ocean-texture ;; INFO: Return type mismatch int vs none. ;; Used lq/sq -(defun draw-ocean-texture ((arg0 dma-buffer) (arg1 (pointer vector)) (arg2 symbol)) - (local-vars (sv-16 (pointer vector)) (sv-32 int) (sv-48 (pointer vector)) (sv-64 (pointer vector))) +(defun draw-ocean-texture ((arg0 dma-buffer) (arg1 (inline-array vector)) (arg2 symbol)) + (local-vars (sv-16 (inline-array vector)) (sv-32 int) (sv-48 vector) (sv-64 (inline-array vector))) (set! sv-64 arg1) (let* ((s0-0 arg2) (a1-1 *ocean-base-page*) @@ -222,16 +232,16 @@ (ocean-texture-add-envmap arg0) (set! sv-16 sv-64) (ocean-texture-add-verts arg0 sv-16) - (set! sv-48 (&-> sv-16 768)) + (set! sv-48 (-> sv-16 192)) (ocean-texture-add-call-start arg0) (set! sv-32 0) (while (< sv-32 9) - (ocean-texture-add-verts arg0 sv-48) - (set! sv-48 (&-> sv-48 768)) + (ocean-texture-add-verts arg0 (the-as (inline-array vector) sv-48)) + (set! sv-48 (-> (the-as (inline-array vector) sv-48) 192)) (ocean-texture-add-call-rest arg0) (set! sv-32 (+ sv-32 1)) ) - (ocean-texture-add-verts-last arg0 sv-48 sv-64) + (ocean-texture-add-verts-last arg0 (the-as (inline-array vector) sv-48) sv-64) (ocean-texture-add-call-rest arg0) (ocean-texture-add-call-done arg0) (when s0-0 @@ -591,7 +601,3 @@ 0 (none) ) - - - -