From 531498c40182f6b8f3c1b080924f1e86f51f1c50 Mon Sep 17 00:00:00 2001 From: nchalkley2 Date: Mon, 19 Aug 2024 16:04:20 -0400 Subject: [PATCH] Removing mesh compile code, double buffering is still fucked up --- .../egg-ps2-graphics-lib.hpp | 9 ++- .../src/egg-ps2-graphics-lib.cc | 25 ++++---- dependencies/egg-ps2-graphics-lib/src/mesh.cc | 64 +++++++------------ include/objects/mesh_object.hpp | 1 - include/renderer/mesh.hpp | 3 - src/Makefile | 1 - src/Makefile.vuprogs | 14 ---- src/objects/mesh_object.cpp | 8 --- src/renderer/mesh.cc | 30 --------- 9 files changed, 43 insertions(+), 112 deletions(-) delete mode 100644 src/Makefile.vuprogs diff --git a/dependencies/egg-ps2-graphics-lib/include/egg-ps2-graphics-lib/egg-ps2-graphics-lib.hpp b/dependencies/egg-ps2-graphics-lib/include/egg-ps2-graphics-lib/egg-ps2-graphics-lib.hpp index fe9566d..7ec4284 100644 --- a/dependencies/egg-ps2-graphics-lib/include/egg-ps2-graphics-lib/egg-ps2-graphics-lib.hpp +++ b/dependencies/egg-ps2-graphics-lib/include/egg-ps2-graphics-lib/egg-ps2-graphics-lib.hpp @@ -9,8 +9,6 @@ struct Vector; namespace egg::ps2::graphics { -using vif_packet_t = utils::inline_packet2<1024>; - void init(); // Uploads a VU program, returns the address of the loaded program @@ -23,9 +21,16 @@ void wait_vsync(); void start_draw(); void end_draw(); + +using vif_packet_t = utils::inline_packet2<1024>; + // Returns the two vif packets in use std::array& get_vif_packets(); + packet2_t* get_current_vif_packet(); + u8 get_vif_packet_context(); + void flip_vip_packet_context(); + } // namespace egg::ps2::graphics \ No newline at end of file diff --git a/dependencies/egg-ps2-graphics-lib/src/egg-ps2-graphics-lib.cc b/dependencies/egg-ps2-graphics-lib/src/egg-ps2-graphics-lib.cc index e4e5bab..0d8f7bd 100644 --- a/dependencies/egg-ps2-graphics-lib/src/egg-ps2-graphics-lib.cc +++ b/dependencies/egg-ps2-graphics-lib/src/egg-ps2-graphics-lib.cc @@ -78,27 +78,29 @@ void init_drawing_environment(framebuffer_t* t_frame, zbuffer_t* t_z) // Now send the packet, no need to wait since it's the first. dma_channel_send_packet2(packet2, DMA_CHANNEL_GIF, 1); - dma_wait_fast(); + dma_channel_wait(DMA_CHANNEL_GIF, 0); } void vu1_set_double_buffer_settings() { printf("egg-ps2-graphics-lib: vu1_set_double_buffer_settings\n"); - utils::inline_packet2<2> packet2(P2_TYPE_NORMAL, P2_MODE_CHAIN, 1); - //packet2_utils_vu_add_double_buffer(packet2, 0, 512); - packet2_utils_vu_add_end_tag(packet2); - dma_channel_send_packet2(packet2, DMA_CHANNEL_VIF1, 1); + utils::inline_packet2<2> double_buffer_pkt(P2_TYPE_NORMAL, P2_MODE_CHAIN, 1); + packet2_utils_vu_add_double_buffer(double_buffer_pkt, 8, 496); + packet2_utils_vu_add_end_tag(double_buffer_pkt); + + dma_channel_send_packet2(double_buffer_pkt, DMA_CHANNEL_VIF1, 1); dma_channel_wait(DMA_CHANNEL_VIF1, 0); } void flip_buffers(framebuffer_t* t_frame) { - utils::inline_packet2<3> flip(P2_TYPE_NORMAL, P2_MODE_NORMAL, 0); + static utils::inline_packet2<8> flip(P2_TYPE_UNCACHED_ACCL, P2_MODE_NORMAL, 0); + packet2_reset(flip, 0); packet2_update(flip, draw_framebuffer(flip->next, 0, t_frame)); packet2_update(flip, draw_finish(flip->next)); - dma_wait_fast(); - dma_channel_send_packet2(flip, DMA_CHANNEL_GIF, 1); + dma_channel_wait(DMA_CHANNEL_GIF, 0); + dma_channel_send_packet2(flip, DMA_CHANNEL_GIF, 0); draw_wait_finish(); } @@ -166,7 +168,7 @@ void init() init_drawing_environment(frame, &z); - init_draw_finish(); + //init_draw_finish(); current_frame = frame; @@ -212,16 +214,13 @@ void clear_screen(int r, int g, int b) packet2_update(clear, draw_finish(clear->next)); // Now send our current dma chain. - dma_wait_fast(); dma_channel_send_packet2(clear, DMA_CHANNEL_GIF, 1); - - // Wait for scene to finish drawing - draw_wait_finish(); } void wait_vsync() { //printf("waiting vsync.........\n"); + draw_wait_finish(); graph_wait_vsync(); graph_set_framebuffer_filtered(current_frame->address, current_frame->width, current_frame->psm, 0, 0); diff --git a/dependencies/egg-ps2-graphics-lib/src/mesh.cc b/dependencies/egg-ps2-graphics-lib/src/mesh.cc index 1be4b79..9dde31b 100644 --- a/dependencies/egg-ps2-graphics-lib/src/mesh.cc +++ b/dependencies/egg-ps2-graphics-lib/src/mesh.cc @@ -20,41 +20,23 @@ namespace /** Set GS primitive type of drawing. */ prim_t prim; -/** - * Color look up table. - * Needed for texture. - */ -clutbuffer_t clut; - -/** - * Level of details. - * Needed for texture. - */ -lod_t lod; - void draw_strip(const Matrix& mesh_to_screen_matrix, const mesh_descriptor& mesh) { - static bool initialized = false; + assert(mesh.is_valid()); - if (!initialized) - { - // Define the triangle primitive we want to use. - prim.type = PRIM_TRIANGLE_STRIP; - prim.shading = PRIM_SHADE_GOURAUD; - prim.mapping = DRAW_DISABLE; - prim.fogging = DRAW_DISABLE; - prim.blending = DRAW_DISABLE; - prim.antialiasing = DRAW_DISABLE; - prim.mapping_type = PRIM_MAP_ST; - prim.colorfix = PRIM_UNFIXED; - - initialized = true; - printf("Initialized\n"); - } + // Define the triangle primitive we want to use. + prim.type = PRIM_TRIANGLE_STRIP; + prim.shading = PRIM_SHADE_GOURAUD; + prim.mapping = DRAW_DISABLE; + prim.fogging = DRAW_DISABLE; + prim.blending = DRAW_DISABLE; + prim.antialiasing = DRAW_DISABLE; + prim.mapping_type = PRIM_MAP_ST; + prim.colorfix = PRIM_UNFIXED; packet2_reset(get_current_vif_packet(), 0); - packet2_utils_vu_open_unpack(get_current_vif_packet(), 0, true); + packet2_utils_vu_open_unpack(get_current_vif_packet(), 0, 1); { // 0 for (int i = 0; i < 4; ++i) @@ -78,18 +60,20 @@ void draw_strip(const Matrix& mesh_to_screen_matrix, const mesh_descriptor& mesh } packet2_utils_vu_close_unpack(get_current_vif_packet()); - packet2_utils_vu_add_unpack_data(get_current_vif_packet(), 8, (void*)mesh.pos, mesh.num_verts, true); + // Position data + packet2_utils_vu_add_unpack_data(get_current_vif_packet(), 8, (void*)mesh.pos, mesh.num_verts, 1); - assert(mesh.color != nullptr); - { - packet2_utils_vu_add_unpack_data(get_current_vif_packet(), 8 + mesh.num_verts, (void*)mesh.color, mesh.num_verts, true); - } + // Color data + packet2_utils_vu_add_unpack_data(get_current_vif_packet(), 8 + mesh.num_verts, (void*)mesh.color, mesh.num_verts, 1); + + //assert((8 + (mesh.num_verts * 4)) < 496); packet2_utils_vu_add_start_program(get_current_vif_packet(), mesh.vu_program_addr); packet2_utils_vu_add_end_tag(get_current_vif_packet()); + dma_channel_wait(DMA_CHANNEL_VIF1, 0); dma_channel_send_packet2(get_current_vif_packet(), DMA_CHANNEL_VIF1, 1); - dma_wait_fast(); + dma_channel_wait(DMA_CHANNEL_VIF1, 0); flip_vip_packet_context(); } @@ -103,7 +87,7 @@ void draw_mesh(const Matrix& mesh_to_screen_matrix, const mesh_descriptor& mesh) assert(mesh.is_valid()); // TODO: calculate this dynamically based on how much stuff is being put into vu mem - static constexpr s32 verts_per_call = 50; + static constexpr s32 verts_per_call = 96; for (u32 i = 0;;) { @@ -142,20 +126,20 @@ void draw_mesh(const Matrix& mesh_to_screen_matrix, const mesh_descriptor& mesh) bool mesh_descriptor::is_valid(bool print_why_invalid) const { bool all_valid = true; - if (!__is_aligned(pos, 16)) + if ((__uintptr_t)pos == 0) { if (print_why_invalid) { - printf("Mesh invalid! Pos pointer not aligned to a 16 byte address!\n"); + printf("Mesh invalid! Pos pointer is nullptr!\n"); } all_valid &= false; } - if ((__uintptr_t)pos == 0) + if (!__is_aligned(pos, 16)) { if (print_why_invalid) { - printf("Mesh invalid! Pos pointer is nullptr!\n"); + printf("Mesh invalid! Pos pointer not aligned to a 16 byte address!\n"); } all_valid &= false; } diff --git a/include/objects/mesh_object.hpp b/include/objects/mesh_object.hpp index a4aaadf..65792fe 100644 --- a/include/objects/mesh_object.hpp +++ b/include/objects/mesh_object.hpp @@ -12,7 +12,6 @@ class MeshObject: public Renderable, public Debuggable, public RootComponentInte MeshObject(); MeshObject(const Filesystem::Path& mesh_path); MeshObject(Asset::Reference mesh_reference); - virtual void on_gs_init() override; virtual void render(const GS::GSState& gs_state) override; TransformComponent transform; class Mesh* mesh; diff --git a/include/renderer/mesh.hpp b/include/renderer/mesh.hpp index 72fea59..f46bba0 100644 --- a/include/renderer/mesh.hpp +++ b/include/renderer/mesh.hpp @@ -22,14 +22,11 @@ class Mesh: public Renderable, public Debuggable std::unique_ptr mesh_bytes; size_t mesh_size; - void compile(); void draw(const Matrix& render_matrix, bool flush = false); bool is_valid() const { return mesh != nullptr && list >= 0; } int get_triangle_count() const; - virtual void on_gs_init() override; - // for debug const Filesystem::Path* path; bool auto_compile; diff --git a/src/Makefile b/src/Makefile index 7c5e2c0..133516c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -17,7 +17,6 @@ OUTPUT_DIR = build ISO_FOLDER_DIR = build/iso include src/Makefile.iso -# include src/Makefile.vuprogs .PHONY: compile cleancompile compile: $(EE_BIN) diff --git a/src/Makefile.vuprogs b/src/Makefile.vuprogs deleted file mode 100644 index 6b09c02..0000000 --- a/src/Makefile.vuprogs +++ /dev/null @@ -1,14 +0,0 @@ -EE_DVP = dvp-as -VCL = openvcl - -RENDERERS = \ - vertex_color_renderer - -EE_OBJS += $(addsuffix .vo, $(addprefix vu1/, $(RENDERERS))) -VSM_SOURCES = $(addsuffix _vcl.vsm, $(addprefix vu1/, $(RENDERERS))) - -%.vo: %.vsm - $(EE_DVP) $< -o $@ - -%.vsm: %.vcl - $(VCL) -g --gasp masp -o $@ $< \ No newline at end of file diff --git a/src/objects/mesh_object.cpp b/src/objects/mesh_object.cpp index 291e247..e1c53fa 100644 --- a/src/objects/mesh_object.cpp +++ b/src/objects/mesh_object.cpp @@ -17,14 +17,6 @@ MeshObject::MeshObject(Asset::Reference mesh_reference) { } -void MeshObject::on_gs_init() -{ - if (mesh) - { - mesh->compile(); - } -} - void MeshObject::render(const GS::GSState& gs_state) { if (mesh) diff --git a/src/renderer/mesh.cc b/src/renderer/mesh.cc index 679be2e..96a0ec6 100644 --- a/src/renderer/mesh.cc +++ b/src/renderer/mesh.cc @@ -28,12 +28,6 @@ Mesh::Mesh(const Filesystem::Path& in_path, bool in_auto_compile) checkf(Filesystem::load_file(in_path, mesh_bytes, mesh_size, 16), in_path.data()); debug_name = in_path.data(); mesh = reinterpret_cast(mesh_bytes.get()); - - auto_compile = in_auto_compile; - if (auto_compile && GS::has_gs_initialized()) - { - compile(); - } } Mesh::Mesh(Asset::Reference mesh_asset, bool in_auto_compile) @@ -41,30 +35,6 @@ Mesh::Mesh(Asset::Reference mesh_asset, bool in_auto_compile) { } -void Mesh::on_gs_init() -{ - if (auto_compile) - { - compile(); - } -} - -void Mesh::compile() -{ - if (is_valid()) - { - printf("Trying to compile already compiled mesh!\nMesh list: %d\n", list); - return; - } - - check(!is_valid()); - - if (mesh == nullptr) - { - printf("Trying to compile null mesh!\n"); - return; - } -} void Mesh::draw(const Matrix& render_matrix, bool flush) {