Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

add ocean-vu0 mips2c and decomp ocean-texture #1230

Merged
merged 7 commits into from
Mar 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions decompiler/config/all-types.gc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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


;; ----------------------
Expand Down Expand Up @@ -21702,8 +21702,8 @@
;; - 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 draw-ocean-texture (function dma-buffer (pointer vector) symbol 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 (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
Expand Down Expand Up @@ -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))

Expand Down
4 changes: 3 additions & 1 deletion decompiler/config/jak1_ntsc_black_label/hacks.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
104 changes: 104 additions & 0 deletions decompiler/config/jak1_ntsc_black_label/type_casts.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -7421,5 +7421,109 @@
[[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"],
[57, "v1", "(inline-array vector)"]
],

"placeholder-do-not-add-below": []
}
4 changes: 2 additions & 2 deletions decompiler/data/game_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
Expand Down
5 changes: 5 additions & 0 deletions decompiler/level_extractor/extract_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion game/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -83,6 +84,10 @@ 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/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
Expand All @@ -94,7 +99,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
Expand Down
8 changes: 8 additions & 0 deletions game/common/vu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
31 changes: 24 additions & 7 deletions game/graphics/opengl_renderer/DirectRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}
Expand All @@ -921,8 +939,7 @@ void DirectRenderer::handle_xyzf2_common(u32 x,
m_prim_building.building_stq.at(m_prim_building.building_idx) = math::Vector<float, 3>(
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<u32, 4>{x << 16, y << 16, z << 8, f};
m_prim_building.building_vert.at(m_prim_building.building_idx) = math::Vector<u32, 4>{x, y, z, f};

m_prim_building.building_idx++;

Expand Down Expand Up @@ -1050,7 +1067,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) {
Expand Down
3 changes: 3 additions & 0 deletions game/graphics/opengl_renderer/DirectRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
14 changes: 0 additions & 14 deletions game/graphics/opengl_renderer/OceanMidAndFar.h

This file was deleted.

4 changes: 2 additions & 2 deletions game/graphics/opengl_renderer/OpenGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -85,7 +85,7 @@ void OpenGLRenderer::init_bucket_renderers() {
// 1
// 2
init_bucket_renderer<SkyRenderer>("sky", BucketCategory::OTHER, BucketId::SKY_DRAW); // 3
init_bucket_renderer<OceanMidAndFar>("ocean-mid-far", BucketCategory::OTHER,
init_bucket_renderer<OceanMidAndFar>("ocean-mid-far", BucketCategory::OCEAN,
BucketId::OCEAN_MID_AND_FAR); // 4

//-----------------------
Expand Down
2 changes: 1 addition & 1 deletion game/graphics/opengl_renderer/Profiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions game/graphics/opengl_renderer/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,5 @@ ShaderLibrary::ShaderLibrary() {
at(ShaderId::DIRECT2) = {"direct2"};
at(ShaderId::EYE) = {"eye"};
at(ShaderId::GENERIC) = {"generic"};
at(ShaderId::OCEAN_TEXTURE) = {"ocean_texture"};
}
1 change: 1 addition & 0 deletions game/graphics/opengl_renderer/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum class ShaderId {
DIRECT2 = 10,
EYE = 11,
GENERIC = 12,
OCEAN_TEXTURE = 13,
MAX_SHADERS
};

Expand Down
3 changes: 2 additions & 1 deletion game/graphics/opengl_renderer/buckets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
"tfrag", "tie", "tex", "merc", "mercneric", "sprite", "ocean", "debug", "other"};
2 changes: 1 addition & 1 deletion game/graphics/opengl_renderer/debug_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
Loading