From b4846f0491b1c9986bc25c4278af191c3a347346 Mon Sep 17 00:00:00 2001 From: water Date: Sun, 8 Aug 2021 21:50:34 -0400 Subject: [PATCH] hook up profiler --- common/math/Vector.h | 16 ++++++ .../opengl_renderer/DirectRenderer.cpp | 52 ++++++++++++++----- .../opengl_renderer/OpenGLRenderer.cpp | 4 ++ game/kernel/kmachine.cpp | 15 ++++++ game/kernel/kmachine.h | 5 +- goal_src/engine/gfx/hw/display.gc | 14 +++++ 6 files changed, 90 insertions(+), 16 deletions(-) diff --git a/common/math/Vector.h b/common/math/Vector.h index cd4a8cd84b..250c2561e0 100644 --- a/common/math/Vector.h +++ b/common/math/Vector.h @@ -114,6 +114,13 @@ class Vector { return result; } + Vector cross(const Vector& other) const { + static_assert(Size == 3, "Size for cross"); + Vector result = {y() * other.z() - z() * other.y(), z() * other.x() - x() * other.z(), + x() * other.y() - y() * other.x()}; + return result; + } + Vector normalized(const T& norm = T(1)) const { return (*this) * (norm / length()); } void normalize(const T& norm = T(1)) { *this = normalized(norm); } @@ -130,6 +137,15 @@ class Vector { T* data() { return m_data; } const T* data() const { return m_data; } + template + Vector cast() { + Vector result; + for (int i = 0; i < Size; i++) { + result[i] = (U)m_data[i]; + } + return result; + } + private: T m_data[Size]; }; diff --git a/game/graphics/opengl_renderer/DirectRenderer.cpp b/game/graphics/opengl_renderer/DirectRenderer.cpp index b3b2413c4a..f7b11a8e9f 100644 --- a/game/graphics/opengl_renderer/DirectRenderer.cpp +++ b/game/graphics/opengl_renderer/DirectRenderer.cpp @@ -33,7 +33,7 @@ DirectRenderer::~DirectRenderer() { * Render from a DMA bucket. */ void DirectRenderer::render(DmaFollower& dma, SharedRenderState* render_state) { - fmt::print("direct: {}\n", m_my_id); + // fmt::print("direct: {}\n", m_my_id); // if we're rendering from a bucket, we should start off we a totally reset state: reset_state(); setup_common_state(render_state); @@ -53,7 +53,6 @@ void DirectRenderer::render(DmaFollower& dma, SharedRenderState* render_state) { } } - fmt::print("update from end {}\n", m_prim_gl_state.texture_enable); flush_pending(render_state); } @@ -62,7 +61,7 @@ void DirectRenderer::flush_pending(SharedRenderState* render_state) { return; } - lg::warn("DirectRenderer flush with {} triangles.\n", m_prim_buffer.vert_count / 3); + // lg::warn("DirectRenderer flush with {} triangles.", m_prim_buffer.vert_count / 3); // update opengl state if (m_prim_gl_state_needs_gl_update) { update_gl_prim(render_state); @@ -92,9 +91,6 @@ void DirectRenderer::flush_pending(SharedRenderState* render_state) { if (m_prim_gl_state.texture_enable) { glBindBuffer(GL_ARRAY_BUFFER, m_ogl.st_buffer); glBufferSubData(GL_ARRAY_BUFFER, 0, m_ogl.st_buffer_bytes, m_prim_buffer.sts.data()); - for (int i = 0; i < 10; i++) { - fmt::print("{}: {} {}\n", i, m_prim_buffer.sts[i].x(), m_prim_buffer.sts[i].y()); - } } // setup attributes: @@ -119,7 +115,6 @@ void DirectRenderer::flush_pending(SharedRenderState* render_state) { 0); if (m_prim_gl_state.texture_enable) { - fmt::print("DO TEXTURE!\n"); glBindBuffer(GL_ARRAY_BUFFER, m_ogl.st_buffer); glEnableVertexAttribArray(2); glVertexAttribPointer(2, // location 0 in the shader @@ -176,7 +171,7 @@ void DirectRenderer::upload_texture(TextureRecord* tex) { void DirectRenderer::update_gl_texture(SharedRenderState* render_state) { auto tex = render_state->texture_pool->lookup(m_texture_state.texture_base_ptr); assert(tex); - fmt::print("Successful texture lookup! {} {}\n", tex->page_name, tex->name); + // fmt::print("Successful texture lookup! {} {}\n", tex->page_name, tex->name); // first: do we need to load the texture? if (!tex->on_gpu) { @@ -365,7 +360,8 @@ void DirectRenderer::render_gif(const u8* data, u32 size, SharedRenderState* ren for (u32 reg = 0; reg < nreg; reg++) { u64 register_data; memcpy(®ister_data, data + offset, 8); -// fmt::print("loop: {} reg: {} {}\n", loop, reg, reg_descriptor_name(reg_desc[reg])); + // fmt::print("loop: {} reg: {} {}\n", loop, reg, + // reg_descriptor_name(reg_desc[reg])); switch (reg_desc[reg]) { case GifTag::RegisterDescriptor::PRIM: handle_prim(register_data, render_state); @@ -393,7 +389,7 @@ void DirectRenderer::render_gif(const u8* data, u32 size, SharedRenderState* ren assert(offset == size); -// fmt::print("{}\n", GifTag(data).print()); + // fmt::print("{}\n", GifTag(data).print()); } void DirectRenderer::handle_ad(const u8* data, SharedRenderState* render_state) { @@ -461,7 +457,7 @@ void DirectRenderer::handle_tex1_1(u64 val) { void DirectRenderer::handle_tex0_1(u64 val, SharedRenderState* render_state) { GsTex0 reg(val); -// fmt::print("{}\n", reg.print()); + // fmt::print("{}\n", reg.print()); // update tbp if (m_texture_state.current_register != reg) { @@ -648,6 +644,39 @@ void DirectRenderer::handle_xyzf2_common(u32 x, u32 y, u32 z, u8 f) { } } break; + // case GsPrim::Kind::LINE: { + // if (m_prim_building.building_idx == 1) { + // math::Vector pt0 = m_prim_building.building_vert[0].cast(); + // math::Vector pt1 = m_prim_building.building_vert[1].cast(); + // auto normal = (pt1 - pt0).normalized().cross({0, 0, 1}); + // + // double line_width = (1 << 28); + // fmt::print("Line:\n "); + // fmt::print(" {} {} {} {}\n", m_prim_building.building_vert[0].x(), + // m_prim_building.building_vert[0].y(), + // m_prim_building.building_vert[1].x(), + // m_prim_building.building_vert[1].y()); + // // debug_print_vtx(m_prim_building.building_vert[0]); + // // debug_print_vtx(m_prim_building.building_vert[1]); + // + // math::Vector a = pt0 + normal * line_width; + // math::Vector b = pt1 + normal * line_width; + // math::Vector c = pt0 - normal * line_width; + // math::Vector d = pt1 - normal * line_width; + // + // // ACB: + // m_prim_buffer.push(m_prim_building.building_rgba[0], a.cast(), {}); + // m_prim_buffer.push(m_prim_building.building_rgba[0], c.cast(), {}); + // m_prim_buffer.push(m_prim_building.building_rgba[1], b.cast(), {}); + // // b c d + // m_prim_buffer.push(m_prim_building.building_rgba[1], b.cast(), {}); + // m_prim_buffer.push(m_prim_building.building_rgba[0], c.cast(), {}); + // m_prim_buffer.push(m_prim_building.building_rgba[1], d.cast(), {}); + // // + // + // m_prim_building.building_idx = 0; + // } + // } break; default: fmt::print("prim type {} is unsupported.\n", (int)m_prim_building.kind); assert(false); @@ -719,7 +748,6 @@ void DirectRenderer::PrimGlState::from_register(GsPrim reg) { current_register = reg; gouraud_enable = reg.gouraud(); texture_enable = reg.tme(); - fmt::print("set tex en: {}\n", texture_enable); fogging_enable = reg.fge(); aa_enable = reg.aa1(); use_uv = reg.fst(); diff --git a/game/graphics/opengl_renderer/OpenGLRenderer.cpp b/game/graphics/opengl_renderer/OpenGLRenderer.cpp index 183ebb0a3c..474ddcb7a7 100644 --- a/game/graphics/opengl_renderer/OpenGLRenderer.cpp +++ b/game/graphics/opengl_renderer/OpenGLRenderer.cpp @@ -4,6 +4,9 @@ #include "game/graphics/opengl.h" #include "game/graphics/opengl_renderer/DirectRenderer.h" +// for the vif callback +#include "game/kernel/kmachine.h" + /*! * OpenGL Error callback. If we do something invalid, this will be called. */ @@ -108,6 +111,7 @@ void OpenGLRenderer::dispatch_buckets(DmaFollower dma) { // should have ended at the start of the next chain assert(dma.current_tag_offset() == m_render_state.next_bucket); m_render_state.next_bucket += 16; + vif_interrupt_callback(); } // TODO ending data. diff --git a/game/kernel/kmachine.cpp b/game/kernel/kmachine.cpp index db85513030..55ac8b48bb 100644 --- a/game/kernel/kmachine.cpp +++ b/game/kernel/kmachine.cpp @@ -55,12 +55,16 @@ const char* init_types[] = {"fakeiso", "deviso", "iso_cd"}; Timer ee_clock_timer; +// added +bool machine_booted = false; + void kmachine_init_globals() { isodrv = iso_cd; modsrc = 1; reboot = 1; memset(pad_dma_buf, 0, sizeof(pad_dma_buf)); ee_clock_timer = Timer(); + machine_booted = false; } /*! @@ -612,6 +616,16 @@ void InitMachine_PCPort() { make_function_symbol_from_c("__pc-texture-relocate", (void*)pc_texture_relocate); } +void vif_interrupt_callback() { + // added for the PC port for faking VIF interrupts from the graphics system. + if (machine_booted) { + auto sym = intern_from_c("vif1-handler-debug"); + if (sym->value) { + call_goal(Ptr(sym->value), 0, 0, 0, s7.offset, g_ee_main_mem); + } + } +} + /*! * Final initialization of the system after the kernel is loaded. * This is called from InitHeapAndSymbol at the very end. @@ -684,4 +698,5 @@ void InitMachineScheme() { lg::info("calling fake play~"); call_goal_function_by_name("play"); } + machine_booted = true; } diff --git a/game/kernel/kmachine.h b/game/kernel/kmachine.h index ba63aad244..6056c95e1f 100644 --- a/game/kernel/kmachine.h +++ b/game/kernel/kmachine.h @@ -5,9 +5,6 @@ * GOAL Machine. Contains low-level hardware interfaces for GOAL. */ -#ifndef RUNTIME_KMACHINE_H -#define RUNTIME_KMACHINE_H - #include "common/common_types.h" #include "Ptr.h" @@ -118,4 +115,4 @@ struct FileStream { // static_assert(offsetof(CpadInfo, new_pad) == 76, "cpad type offset"); -#endif // RUNTIME_KMACHINE_H +void vif_interrupt_callback(); diff --git a/goal_src/engine/gfx/hw/display.gc b/goal_src/engine/gfx/hw/display.gc index 1e5d5036dd..1da5135320 100644 --- a/goal_src/engine/gfx/hw/display.gc +++ b/goal_src/engine/gfx/hw/display.gc @@ -532,6 +532,20 @@ ;; There was also a vblank hanlder that incremented *vblank-counter*, but it is disabled. +(defun vif1-handler-debug () + (let ((c0 (/ (* 128 (-> *display* frames (-> *display* on-screen) frame profile-bar 1 profile-frame-count)) 69)) + (c1 (* 64 (logand (-> *display* frames (-> *display* on-screen) frame profile-bar 1 profile-frame-count) 3))) + ) + (add-frame + (-> *display* frames (-> *display* on-screen) frame profile-bar 1) + 'end-calc + (new 'static 'rgba + :r c0 + :b (- 128 c0) + :g c1 + :a #x80))) + ) + (define *oddeven* 0)