[cleanup] memory bugs, memory usage reduction, delete merc1 (#1515)

* [cleanup] remove merc1, fix memory bugs, reduce memory usage

* change compiler log to see actual info from build_level

* save file

* editing text is hard
This commit is contained in:
water111 2022-06-21 21:26:11 -04:00 committed by GitHub
parent 78b6ba3d27
commit 90a049dcc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 56 additions and 5939 deletions

View File

@ -107,8 +107,6 @@ set(RUNTIME_SOURCE
graphics/opengl_renderer/DirectRenderer2.cpp
graphics/opengl_renderer/EyeRenderer.cpp
graphics/opengl_renderer/dma_helpers.cpp
graphics/opengl_renderer/MercProgram.cpp
graphics/opengl_renderer/MercRenderer.cpp
graphics/opengl_renderer/opengl_utils.cpp
graphics/opengl_renderer/OpenGLRenderer.cpp
graphics/opengl_renderer/Profiler.cpp

View File

@ -37,11 +37,9 @@ struct SharedRenderState {
bool use_sky_cpu = true;
bool use_occlusion_culling = true;
bool enable_merc_xgkick = true;
bool use_direct2 = true;
math::Vector<u8, 4> fog_color;
float fog_intensity = 1.f;
bool no_multidraw = false;
bool merc2 = true;
void reset();
bool has_pc_data = false;

File diff suppressed because it is too large Load Diff

View File

@ -1,367 +0,0 @@
#include "MercRenderer.h"
#include "third-party/imgui/imgui.h"
MercRenderer::MercRenderer(const std::string& name, BucketId my_id)
: BucketRenderer(name, my_id),
m_direct(fmt::format("{}-dir", name), my_id, 0x30000),
m_direct2(20000, 40000, 1000, name, false) {
memset(m_buffer.data, 0, sizeof(m_buffer.data));
}
void MercRenderer::init_shaders(ShaderLibrary& shaders) {
m_direct2.init_shaders(shaders);
}
void MercRenderer::render(DmaFollower& dma,
SharedRenderState* render_state,
ScopedProfilerNode& prof) {
m_stats = Stats();
// skip if disabled
if (!m_enabled) {
while (dma.current_tag_offset() != render_state->next_bucket) {
dma.read_and_advance();
}
return;
}
// process the first tag. this is just jumping to the merc-specific dma.
auto data0 = dma.read_and_advance();
ASSERT(data0.vif1() == 0);
ASSERT(data0.vif0() == 0);
ASSERT(data0.size_bytes == 0);
if (dma.current_tag().kind == DmaTag::Kind::CALL) {
// renderer didn't run, let's just get out of here.
for (int i = 0; i < 4; i++) {
dma.read_and_advance();
}
ASSERT(dma.current_tag_offset() == render_state->next_bucket);
return;
}
m_stats.had_data = true;
ASSERT(data0.size_bytes == 0);
ASSERT(data0.vif0() == 0);
ASSERT(data0.vif1() == 0);
// if we reach here, there's stuff to draw
handle_setup(dma, render_state, prof);
m_direct2.reset_state();
m_direct.reset_state();
while (dma.current_tag_offset() != render_state->next_bucket) {
handle_merc_chain(dma, render_state, prof);
}
ASSERT(dma.current_tag_offset() == render_state->next_bucket);
m_direct2.flush_pending(render_state, prof);
m_direct.flush_pending(render_state, prof);
}
namespace {
bool tag_is_nothing_next(const DmaFollower& dma) {
return dma.current_tag().kind == DmaTag::Kind::NEXT && dma.current_tag().qwc == 0 &&
dma.current_tag_vif0() == 0 && dma.current_tag_vif1() == 0;
}
} // namespace
void MercRenderer::unpack32(const VifCodeUnpack& up, const u8* data, u32 imm) {
ASSERT(!up.is_unsigned);
u32 addr = up.addr_qw;
ASSERT(imm != 0);
ASSERT(!m_vif.stmod);
if (up.use_tops_flag) {
addr += xitop();
}
u32 start_in_buff = (addr)*16;
u32 end_in_buff = start_in_buff + imm * 16;
ASSERT(start_in_buff < sizeof(m_buffer.data));
ASSERT(end_in_buff <= sizeof(m_buffer.data));
memcpy(m_buffer.data + start_in_buff, data, imm * 16);
}
void MercRenderer::unpack8(const VifCodeUnpack& up, const u8* data, u32 imm) {
// ASSERT(m_vif.stmod);
ASSERT(up.is_unsigned);
u32 addr = up.addr_qw;
if (up.use_tops_flag) {
addr += xitop();
}
ASSERT(imm != 0);
u32 start_in_buff = (addr)*16;
u32 end_in_buff = start_in_buff + imm * 16;
ASSERT(start_in_buff < sizeof(m_buffer.data));
ASSERT(end_in_buff <= sizeof(m_buffer.data));
u8* out_ptr = m_buffer.data + start_in_buff;
if (m_vif.stmod) {
// use row
auto row = _mm_loadu_si128((const __m128i*)m_vif.row);
for (u32 qw = 0; qw < imm; qw++) {
_mm_storeu_si128((__m128i*)out_ptr,
_mm_add_epi32(row, _mm_cvtepu8_epi32(_mm_loadu_si64(data))));
data += 4;
out_ptr += 16;
}
} else {
// no row
for (u32 qw = 0; qw < imm; qw++) {
_mm_storeu_si128((__m128i*)out_ptr, _mm_cvtepu8_epi32(_mm_loadu_si64(data)));
data += 4;
out_ptr += 16;
}
}
/*
u32 row[4];
if (m_vif.stmod) {
memcpy(row, m_vif.row, 16);
} else {
memset(row, 0, 16);
}
u32 temp[4];
for (u32 i = 0; i < imm; i++) {
for (u32 j = 0; j < 4; j++) {
temp[j] = row[j] + data[4 * i + j];
}
memcpy(m_buffer.data + start_in_buff + i * 16, temp, 16);
}
*/
}
void MercRenderer::handle_merc_chain(DmaFollower& dma,
SharedRenderState* render_state,
ScopedProfilerNode& prof) {
// fmt::print("DMA: {}\n", dma.current_tag().print());
while (tag_is_nothing_next(dma)) {
auto nothing = dma.read_and_advance();
ASSERT(nothing.size_bytes == 0);
}
if (dma.current_tag().kind == DmaTag::Kind::CALL) {
for (int i = 0; i < 4; i++) {
dma.read_and_advance();
}
return;
}
auto init = dma.read_and_advance();
// skip pc port stuff
if (init.vifcode1().kind == VifCode::Kind::PC_PORT) {
dma.read_and_advance();
init = dma.read_and_advance();
}
ASSERT(init.vifcode0().kind == VifCode::Kind::STROW);
ASSERT(init.size_bytes == 16);
m_vif.row[0] = init.vif1();
memcpy(m_vif.row + 1, init.data, 12);
// now used in pc renderer.
// u32 extra;
// memcpy(&extra, init.data + 12, 4);
// ASSERT(extra == 0);
DmaTransfer next;
bool setting_up = true;
u32 mscal_addr = -1;
while (setting_up) {
next = dma.read_and_advance();
u32 offset_in_data = 0;
// fmt::print("START {} : {} {}\n", next.size_bytes, next.vifcode0().print(),
// next.vifcode1().print());
auto vif0 = next.vifcode0();
switch (vif0.kind) {
case VifCode::Kind::NOP:
case VifCode::Kind::FLUSHE:
break;
case VifCode::Kind::STMOD:
ASSERT(vif0.immediate == 0 || vif0.immediate == 1);
m_vif.stmod = vif0.immediate;
break;
default:
ASSERT(false);
}
auto vif1 = next.vifcode1();
switch (vif1.kind) {
case VifCode::Kind::UNPACK_V4_8: {
// todo unpack
m_stats.unpack_count++;
m_stats.unpack_bytes += vif1.num * 4;
VifCodeUnpack up(vif1);
unpack8(up, next.data, vif1.num);
offset_in_data += 4 * vif1.num;
} break;
case VifCode::Kind::UNPACK_V4_32: {
// todo unpack
VifCodeUnpack up(vif1);
unpack32(up, next.data, vif1.num);
m_stats.unpack_bytes += vif1.num * 16;
offset_in_data += 16 * vif1.num;
} break;
case VifCode::Kind::MSCAL:
mscal_addr = vif1.immediate;
ASSERT(next.size_bytes == 0);
setting_up = false;
break;
default:
ASSERT(false);
}
ASSERT(offset_in_data <= next.size_bytes);
if (offset_in_data < next.size_bytes) {
ASSERT((offset_in_data % 4) == 0);
u32 leftover = next.size_bytes - offset_in_data;
if (leftover < 16) {
for (u32 i = 0; i < leftover; i++) {
ASSERT(next.data[offset_in_data + i] == 0);
}
} else {
ASSERT(false);
}
}
}
m_dbf = !m_dbf;
switch (mscal_addr) {
case 17:
m_stats.mscal_17++;
if (m_enable_prime_mscals) {
mscal(17, render_state, prof);
}
break;
case 32:
m_stats.mscal_32++;
if (m_enable_prime_mscals) {
mscal(32, render_state, prof);
}
break;
case 20:
m_stats.mscal_20++;
if (m_enable_normal_mscals) {
mscal(20, render_state, prof);
}
break;
case 35:
m_stats.mscal_35++;
if (m_enable_normal_mscals) {
mscal(35, render_state, prof);
}
break;
default:
ASSERT_MSG(false, fmt::format("unknown mscal: {}", mscal_addr));
}
// while (true) {
// next = dma.read_and_advance();
// if (next.vif0() == 0 && next.vifcode1().kind == VifCode::Kind::UNPACK_V4_8) {
//
// } else {
// fmt::print("{} : {} {}\n", next.size_bytes, next.vifcode0().print(),
// next.vifcode1().print()); ASSERT(false);
// }
// }
}
/*!
* Handle the setup DMA data prepared by merc-vu1-init-buffer in GOAL
*/
void MercRenderer::handle_setup(DmaFollower& dma,
SharedRenderState* render_state,
ScopedProfilerNode& prof) {
auto first = dma.read_and_advance();
// 10 quadword setup packet
ASSERT(first.size_bytes == 10 * 16);
// m_stats.str += fmt::format("Setup 0: {} {} {}", first.size_bytes / 16,
// first.vifcode0().print(), first.vifcode1().print());
// transferred vifcodes
{
auto vif0 = first.vifcode0();
auto vif1 = first.vifcode1();
// STCYCL 4, 4
ASSERT(vif0.kind == VifCode::Kind::STCYCL);
auto vif0_st = VifCodeStcycl(vif0);
ASSERT(vif0_st.cl == 4 && vif0_st.wl == 4);
// STMOD
ASSERT(vif1.kind == VifCode::Kind::STMOD);
ASSERT(vif1.immediate == 0);
}
// 1 qw with 4 vifcodes.
u32 vifcode_data[4];
memcpy(vifcode_data, first.data, 16);
{
auto vif0 = VifCode(vifcode_data[0]);
ASSERT(vif0.kind == VifCode::Kind::BASE);
ASSERT(vif0.immediate == MercDataMemory::BUFFER_BASE);
auto vif1 = VifCode(vifcode_data[1]);
ASSERT(vif1.kind == VifCode::Kind::OFFSET);
ASSERT((s16)vif1.immediate == MercDataMemory::BUFFER_OFFSET);
auto vif2 = VifCode(vifcode_data[2]);
ASSERT(vif2.kind == VifCode::Kind::NOP);
auto vif3 = VifCode(vifcode_data[3]);
ASSERT(vif3.kind == VifCode::Kind::UNPACK_V4_32);
VifCodeUnpack up(vif3);
ASSERT(up.addr_qw == MercDataMemory::LOW_MEMORY);
ASSERT(!up.use_tops_flag);
ASSERT(vif3.num == 8);
}
// 8 qw's of low memory data
memcpy(&m_low_memory, first.data + 16, sizeof(LowMemory));
m_stats.str += fmt::format("Fog: {}\n", m_low_memory.fog.to_string_aligned());
// 1 qw with another 4 vifcodes.
u32 vifcode_final_data[4];
memcpy(vifcode_final_data, first.data + 16 + sizeof(LowMemory), 16);
{
ASSERT(VifCode(vifcode_final_data[0]).kind == VifCode::Kind::FLUSHE);
ASSERT(vifcode_final_data[1] == 0);
ASSERT(vifcode_final_data[2] == 0);
VifCode mscal(vifcode_final_data[3]);
ASSERT(mscal.kind == VifCode::Kind::MSCAL);
ASSERT(mscal.immediate == 0);
}
// copy low memory into the VU "emulation" RAM.
memcpy(m_buffer.data, &m_low_memory, sizeof(LowMemory));
mscal(0, render_state, prof);
auto second = dma.read_and_advance();
ASSERT(second.size_bytes == 32); // setting up test register.
m_direct.render_gif(second.data, 32, render_state, prof);
auto nothing = dma.read_and_advance();
ASSERT(nothing.size_bytes == 0);
ASSERT(nothing.vif0() == 0);
ASSERT(nothing.vif1() == 0);
}
void MercRenderer::draw_debug_window() {
ImGui::Text("Ran? %d\n", m_stats.had_data);
ImGui::Text("%d unpacks, %d bytes\n", m_stats.unpack_count, m_stats.unpack_bytes);
ImGui::Text("MSCAL: [17] %d [20] %d [32] %d [35] %d \n", m_stats.mscal_17, m_stats.mscal_20,
m_stats.mscal_32, m_stats.mscal_35);
ImGui::Text("Debug:\n%s\n", m_stats.str.c_str());
ImGui::Checkbox("Normal MSCAL enable", &m_enable_normal_mscals);
ImGui::Checkbox("Prime MSCAL enable", &m_enable_prime_mscals);
ImGui::Checkbox("Send to direct", &m_enable_send_to_direct);
m_direct2.draw_debug_window();
}
void MercRenderer::xgkick(u16 addr, SharedRenderState* render_state, ScopedProfilerNode& prof) {
if (m_enable_send_to_direct && render_state->enable_merc_xgkick) {
if (render_state->use_direct2) {
m_direct2.render_gif_data(m_buffer.data + (16 * addr), render_state, prof);
} else {
m_direct.render_gif(m_buffer.data + (16 * addr), UINT32_MAX, render_state, prof);
}
}
}

View File

@ -1,124 +0,0 @@
#pragma once
#include "game/graphics/opengl_renderer/BucketRenderer.h"
#include "common/math/Vector.h"
#include "game/graphics/opengl_renderer/DirectRenderer.h"
#include "game/common/vu.h"
#include "game/graphics/opengl_renderer/DirectRenderer2.h"
class MercRenderer : public BucketRenderer {
public:
MercRenderer(const std::string& name, BucketId my_id);
void init_shaders(ShaderLibrary& shaders) override;
void render(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof) override;
void draw_debug_window() override;
private:
void handle_setup(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof);
void handle_merc_chain(DmaFollower& dma,
SharedRenderState* render_state,
ScopedProfilerNode& prof);
void unpack8(const VifCodeUnpack& up, const u8* data, u32 imm);
void unpack32(const VifCodeUnpack& up, const u8* data, u32 imm);
void mscal(int enter_address, SharedRenderState* render_state, ScopedProfilerNode& prof);
template <bool DEBUG>
void mscal_impl(int enter_address, SharedRenderState* render_state, ScopedProfilerNode& prof);
void xgkick(u16 addr, SharedRenderState* render_state, ScopedProfilerNode& prof);
enum MercDataMemory {
LOW_MEMORY = 0,
BUFFER_BASE = 442,
// this negative offset is what broke jak graphics in Dobiestation for a long time.
BUFFER_OFFSET = -442
};
struct LowMemory {
u8 tri_strip_tag[16];
u8 ad_gif_tag[16];
math::Vector4f hvdf_offset;
math::Vector4f perspective[4];
math::Vector4f fog;
} m_low_memory;
static_assert(sizeof(LowMemory) == 0x80);
struct alignas(16) BufferMemory {
u8 data[1024 * 16];
} m_buffer;
void sq_buffer(Mask mask, const Vf& data, u32 qw) {
// if (data.x_as_u32() == 0x80000000 && data.y_as_u32() == 0x80000000) {
// fmt::print("big store line {}: {} : {} {} {} {}\n", line_number, qw, data.x(), data.y(),
// data.z(), data.w());
// }
// sketchy...
// qw &= 1023;
ASSERT(qw * 16 < sizeof(m_buffer.data));
for (int i = 0; i < 4; i++) {
if ((u64)mask & (1 << i)) {
memcpy(m_buffer.data + qw * 16 + i * 4, data.data + i, 4);
}
}
}
void lq_buffer(Mask mask, Vf& dest, u16 addr);
template <bool DEBUG>
void lq_buffer_xyzw(Vf& dest, u16 addr);
template <bool DEBUG>
void lq_buffer_xyz(Vf& dest, u16 addr);
template <bool DEBUG>
void sq_buffer_xyzw(const Vf& src, u16 addr);
void isw_buffer(Mask mask, u16 val, u16 addr);
void ilw_buffer(Mask mask, u16& dest, u16 addr);
u16 xtop();
u16 xitop();
DirectRenderer m_direct;
DirectRenderer2 m_direct2;
struct {
u32 row[4] = {0, 0, 0, 0};
bool stmod = false;
} m_vif;
struct Stats {
int unpack_count = 0;
int unpack_bytes = 0;
int mscal_35 = 0;
int mscal_20 = 0;
int mscal_17 = 0;
int mscal_32 = 0;
bool had_data = false;
std::string str;
} m_stats;
bool m_dbf = false;
bool m_enable_prime_mscals = true;
bool m_enable_normal_mscals = true;
bool m_enable_send_to_direct = true;
struct Vu {
Vf vf01, vf02, vf03, vf04, vf05, vf06, vf07, vf08, vf09, vf10, vf11, vf12, vf13, vf14, vf15,
vf16, vf17, vf18, vf19, vf20, vf21, vf22, vf23, vf24, vf25, vf26, vf27, vf28, vf29, vf30,
vf31;
const Vf vf00;
u16 vi01, vi02, vi03, vi04, vi05, vi06, vi07, vi09, vi08, vi11, vi12, vi13, vi10, vi14, vi15;
float I, P, Q;
Accumulator acc;
const u16 vi00 = 0;
u16 hack_old_vi15 = 0;
Vu() : vf00(0, 0, 0, 1) {}
} vu;
};

View File

@ -12,7 +12,6 @@
#include "game/graphics/opengl_renderer/background/TFragment.h"
#include "game/graphics/opengl_renderer/background/Tie3.h"
#include "game/graphics/opengl_renderer/background/Shrub.h"
#include "game/graphics/opengl_renderer/MercRenderer.h"
#include "game/graphics/opengl_renderer/EyeRenderer.h"
#include "game/graphics/opengl_renderer/ShadowRenderer.h"
#include "game/graphics/opengl_renderer/foreground/Generic2.h"
@ -69,15 +68,6 @@ OpenGLRenderer::OpenGLRenderer(std::shared_ptr<TexturePool> texture_pool,
init_bucket_renderers();
}
void OpenGLRenderer::init_merc_renderer(const std::string& name, BucketId id) {
std::vector<std::unique_ptr<BucketRenderer>> merc_renderers;
merc_renderers.push_back(std::make_unique<MercRenderer>(name, id));
merc_renderers.push_back(std::make_unique<Merc2>(name, id));
m_mercs.push_back(
init_bucket_renderer<RenderMux>(name, BucketCategory::MERC, id, std::move(merc_renderers)));
}
/*!
* Construct bucket renderers. We can specify different renderers for different buckets
*/
@ -116,7 +106,8 @@ void OpenGLRenderer::init_bucket_renderers() {
// 9 : TIE_LEVEL0
init_bucket_renderer<Tie3>("l0-tfrag-tie", BucketCategory::TIE, BucketId::TIE_LEVEL0, 0);
// 10 : MERC_TFRAG_TEX_LEVEL0
init_merc_renderer("l0-tfrag-merc", BucketId::MERC_TFRAG_TEX_LEVEL0);
init_bucket_renderer<Merc2>("l0-tfrag-merc", BucketCategory::MERC,
BucketId::MERC_TFRAG_TEX_LEVEL0);
// 11 : GMERC_TFRAG_TEX_LEVEL0
init_bucket_renderer<Generic2>("l0-tfrag-generic", BucketCategory::GENERIC,
BucketId::GENERIC_TFRAG_TEX_LEVEL0, 1500000, 10000, 10000, 800);
@ -135,7 +126,8 @@ void OpenGLRenderer::init_bucket_renderers() {
// 16 : TIE_LEVEL1
init_bucket_renderer<Tie3>("l1-tfrag-tie", BucketCategory::TIE, BucketId::TIE_LEVEL1, 1);
// 17 : MERC_TFRAG_TEX_LEVEL1
init_merc_renderer("l1-tfrag-merc", BucketId::MERC_TFRAG_TEX_LEVEL1);
init_bucket_renderer<Merc2>("l1-tfrag-merc", BucketCategory::MERC,
BucketId::MERC_TFRAG_TEX_LEVEL1);
// 18 : GMERC_TFRAG_TEX_LEVEL1
init_bucket_renderer<Generic2>("l1-tfrag-generic", BucketCategory::GENERIC,
BucketId::GENERIC_TFRAG_TEX_LEVEL1, 1500000, 10000, 10000, 800);
@ -202,7 +194,8 @@ void OpenGLRenderer::init_bucket_renderers() {
BucketId::TFRAG_ICE_LEVEL1, ice_tfrags, false, 1);
// 44
init_merc_renderer("common-alpha-merc", BucketId::MERC_AFTER_ALPHA);
init_bucket_renderer<Merc2>("common-alpha-merc", BucketCategory::MERC,
BucketId::MERC_AFTER_ALPHA);
init_bucket_renderer<Generic2>("common-alpha-generic", BucketCategory::GENERIC,
BucketId::GENERIC_ALPHA); // 46
@ -213,7 +206,8 @@ void OpenGLRenderer::init_bucket_renderers() {
//-----------------------
init_bucket_renderer<TextureUploadHandler>("l0-pris-tex", BucketCategory::TEX,
BucketId::PRIS_TEX_LEVEL0); // 48
init_merc_renderer("l0-pris-merc", BucketId::MERC_PRIS_LEVEL0); // 49
init_bucket_renderer<Merc2>("l0-pris-merc", BucketCategory::MERC,
BucketId::MERC_PRIS_LEVEL0); // 49
init_bucket_renderer<Generic2>("l0-pris-generic", BucketCategory::GENERIC,
BucketId::GENERIC_PRIS_LEVEL0); // 50
@ -222,7 +216,8 @@ void OpenGLRenderer::init_bucket_renderers() {
//-----------------------
init_bucket_renderer<TextureUploadHandler>("l1-pris-tex", BucketCategory::TEX,
BucketId::PRIS_TEX_LEVEL1); // 51
init_merc_renderer("l1-pris-merc", BucketId::MERC_PRIS_LEVEL1); // 52
init_bucket_renderer<Merc2>("l1-pris-merc", BucketCategory::MERC,
BucketId::MERC_PRIS_LEVEL1); // 52
init_bucket_renderer<Generic2>("l1-pris-generic", BucketCategory::GENERIC,
BucketId::GENERIC_PRIS_LEVEL1); // 53
@ -231,7 +226,8 @@ void OpenGLRenderer::init_bucket_renderers() {
"common-pris-eyes", BucketCategory::OTHER, BucketId::MERC_EYES_AFTER_PRIS); // 54
// hack: set to merc2 for debugging
init_merc_renderer("common-pris-merc", BucketId::MERC_AFTER_PRIS); // 55
init_bucket_renderer<Merc2>("common-pris-merc", BucketCategory::MERC,
BucketId::MERC_AFTER_PRIS); // 55
init_bucket_renderer<Generic2>("common-pris-generic", BucketCategory::GENERIC,
BucketId::GENERIC_PRIS); // 56
@ -240,7 +236,8 @@ void OpenGLRenderer::init_bucket_renderers() {
//-----------------------
init_bucket_renderer<TextureUploadHandler>("l0-water-tex", BucketCategory::TEX,
BucketId::WATER_TEX_LEVEL0); // 57
init_merc_renderer("l0-water-merc", BucketId::MERC_WATER_LEVEL0); // 58
init_bucket_renderer<Merc2>("l0-water-merc", BucketCategory::MERC,
BucketId::MERC_WATER_LEVEL0); // 58
init_bucket_renderer<Generic2>("l0-water-generic", BucketCategory::GENERIC,
BucketId::GENERIC_WATER_LEVEL0); // 59
@ -249,7 +246,8 @@ void OpenGLRenderer::init_bucket_renderers() {
//-----------------------
init_bucket_renderer<TextureUploadHandler>("l1-water-tex", BucketCategory::TEX,
BucketId::WATER_TEX_LEVEL1); // 60
init_merc_renderer("l1-water-merc", BucketId::MERC_WATER_LEVEL1); // 61
init_bucket_renderer<Merc2>("l1-water-merc", BucketCategory::MERC,
BucketId::MERC_WATER_LEVEL1); // 61
init_bucket_renderer<Generic2>("l1-water-generic", BucketCategory::GENERIC,
BucketId::GENERIC_WATER_LEVEL1); // 62
@ -299,11 +297,6 @@ void OpenGLRenderer::render(DmaFollower dma, const RenderOptions& settings) {
m_render_state.ee_main_memory = g_ee_main_mem;
m_render_state.offset_of_s7 = offset_of_s7();
// hack to toggle all mercs, todo remove once we finish merc2
for (auto merc : m_mercs) {
merc->set_idx(m_render_state.merc2 ? 1 : 0);
}
{
auto prof = m_profiler.root()->make_scoped_child("frame-setup");
setup_frame(settings.window_width_px, settings.window_height_px, settings.lbox_width_px,
@ -378,14 +371,12 @@ void OpenGLRenderer::render(DmaFollower dma, const RenderOptions& settings) {
void OpenGLRenderer::draw_renderer_selection_window() {
ImGui::Begin("Renderer Debug");
ImGui::Checkbox("Merc2", &m_render_state.merc2);
ImGui::Checkbox("Use old single-draw", &m_render_state.no_multidraw);
ImGui::SliderFloat("Fog Adjust", &m_render_state.fog_intensity, 0, 10);
ImGui::Checkbox("Sky CPU", &m_render_state.use_sky_cpu);
ImGui::Checkbox("Occlusion Cull", &m_render_state.use_occlusion_culling);
ImGui::Checkbox("Merc XGKICK", &m_render_state.enable_merc_xgkick);
ImGui::Checkbox("Blackout Loads", &m_enable_fast_blackout_loads);
ImGui::Checkbox("Direct 2", &m_render_state.use_direct2);
for (size_t i = 0; i < m_bucket_renderers.size(); i++) {
auto renderer = m_bucket_renderers[i].get();

View File

@ -49,9 +49,6 @@ class OpenGLRenderer {
void init_bucket_renderers();
void draw_renderer_selection_window();
void finish_screenshot(const std::string& output_name, int px, int py, int x, int y);
void init_merc_renderer(const std::string& name, BucketId id);
template <typename T, class... Args>
T* init_bucket_renderer(const std::string& name,
BucketCategory cat,
@ -72,8 +69,6 @@ class OpenGLRenderer {
std::array<std::unique_ptr<BucketRenderer>, (int)BucketId::MAX_BUCKETS> m_bucket_renderers;
std::array<BucketCategory, (int)BucketId::MAX_BUCKETS> m_bucket_categories;
std::vector<RenderMux*> m_mercs;
std::array<float, (int)BucketCategory::MAX_CATEGORIES> m_category_times;
FullScreenDraw m_blackout_renderer;
CollideMeshRenderer m_collide_renderer;

View File

@ -30,6 +30,18 @@ void Generic2::draw_debug_window() {
ImGui::Checkbox("Alpha 4", &m_alpha_draw_enable[3]);
ImGui::Checkbox("Alpha 5", &m_alpha_draw_enable[4]);
ImGui::Checkbox("Alpha 6", &m_alpha_draw_enable[5]);
ImGui::Text("Max Seen:");
ImGui::Text(" frag: %d/%d %.1f%%", m_max_frags_seen, (int)m_fragments.size(),
100.f * m_max_frags_seen / (float)m_fragments.size());
ImGui::Text(" vert: %d/%d %.1f%%", m_max_verts_seen, (int)m_verts.size(),
100.f * m_max_verts_seen / (float)m_verts.size());
ImGui::Text(" adgif: %d/%d %.1f%%", m_max_frags_seen, (int)m_adgifs.size(),
100.f * m_max_adgifs_seen / (float)m_adgifs.size());
ImGui::Text(" idx: %d/%d %.1f%%", m_max_frags_seen, (int)m_indices.size(),
100.f * m_max_indices_seen / (float)m_indices.size());
ImGui::Text(" bucket: %d/%d %.1f%%", m_max_frags_seen, (int)m_fragments.size(),
100.f * m_max_frags_seen / (float)m_fragments.size());
}
/*!

View File

@ -6,8 +6,8 @@ class Generic2 : public BucketRenderer {
public:
Generic2(const std::string& name,
BucketId my_id,
u32 num_verts = 1500000,
u32 num_frags = 10000,
u32 num_verts = 200000,
u32 num_frags = 2000,
u32 num_adgif = 3000,
u32 num_buckets = 800);
~Generic2();
@ -150,18 +150,23 @@ class Generic2 : public BucketRenderer {
u32 m_next_free_frag = 0;
std::vector<Fragment> m_fragments;
u32 m_max_frags_seen = 0;
u32 m_next_free_vert = 0;
std::vector<Vertex> m_verts;
u32 m_max_verts_seen = 0;
u32 m_next_free_adgif = 0;
std::vector<Adgif> m_adgifs;
u32 m_max_adgifs_seen = 0;
u32 m_next_free_bucket = 0;
std::vector<Bucket> m_buckets;
u32 m_max_buckets_seen = 0;
u32 m_next_free_idx = 0;
std::vector<u32> m_indices;
u32 m_max_indices_seen = 0;
Fragment& next_frag() {
ASSERT(m_next_free_frag < m_fragments.size());

View File

@ -100,6 +100,12 @@ bool Generic2::handle_bucket_setup_dma(DmaFollower& dma, u32 next_bucket) {
}
void Generic2::reset_buffers() {
m_max_frags_seen = std::max(m_next_free_frag, m_max_frags_seen);
m_max_verts_seen = std::max(m_next_free_vert, m_max_verts_seen);
m_max_adgifs_seen = std::max(m_next_free_adgif, m_max_adgifs_seen);
m_max_buckets_seen = std::max(m_next_free_bucket, m_max_buckets_seen);
m_max_indices_seen = std::max(m_next_free_idx, m_max_indices_seen);
m_next_free_frag = 0;
m_next_free_vert = 0;
m_next_free_adgif = 0;

View File

@ -63,6 +63,8 @@ struct GraphicsData {
double last_engine_time = 1. / 60.;
float pmode_alp = 0.f;
std::string imgui_log_filename, imgui_filename;
GraphicsData()
: dma_copier(EE_MAIN_MEM_SIZE),
texture_pool(std::make_shared<TexturePool>()),
@ -236,9 +238,11 @@ static std::shared_ptr<GfxDisplay> gl_make_display(int width,
ImGui::CreateContext();
// Init ImGui settings
g_gfx_data->imgui_filename = file_util::get_file_path({"imgui.ini"});
g_gfx_data->imgui_log_filename = file_util::get_file_path({"imgui_log.txt"});
ImGuiIO& io = ImGui::GetIO();
io.IniFilename = file_util::get_file_path({"imgui.ini"}).c_str();
io.LogFilename = file_util::get_file_path({"imgui_log.txt"}).c_str();
io.IniFilename = g_gfx_data->imgui_filename.c_str();
io.LogFilename = g_gfx_data->imgui_log_filename.c_str();
// set up to get inputs for this window
ImGui_ImplGlfw_InitForOpenGL(window, true);
@ -260,6 +264,9 @@ GLDisplay::GLDisplay(GLFWwindow* window, bool is_main) : m_window(window) {
}
GLDisplay::~GLDisplay() {
ImGuiIO& io = ImGui::GetIO();
io.IniFilename = nullptr;
io.LogFilename = nullptr;
glfwSetWindowUserPointer(m_window, nullptr);
ImGui_ImplOpenGL3_Shutdown();
ImGui_ImplGlfw_Shutdown();

View File

@ -169,8 +169,6 @@ void ee_runner(SystemThreadInterface& iface) {
// // kill the IOP todo
iop::LIBRARY_kill();
munmap(g_ee_main_mem, EE_MAIN_MEM_SIZE);
// after main returns, trigger a shutdown.
iface.trigger_shutdown();
}
@ -341,5 +339,6 @@ RuntimeExitStatus exec_runtime(int argc, char** argv) {
// join and exit
tm.join();
lg::info("GOAL Runtime Shutdown (code {})", MasterExit);
munmap(g_ee_main_mem, EE_MAIN_MEM_SIZE);
return MasterExit;
}

View File

@ -12,17 +12,11 @@
#include <regex>
#include "common/nrepl/ReplServer.h"
void setup_logging(bool verbose) {
void setup_logging() {
lg::set_file(file_util::get_file_path({"log/compiler.txt"}));
if (verbose) {
lg::set_file_level(lg::level::info);
lg::set_stdout_level(lg::level::info);
lg::set_flush_level(lg::level::info);
} else {
lg::set_file_level(lg::level::warn);
lg::set_stdout_level(lg::level::warn);
lg::set_flush_level(lg::level::warn);
}
lg::initialize();
}
@ -40,7 +34,6 @@ int main(int argc, char** argv) {
app.add_option("-u,--user", username,
"Specify the username to use for your user profile in 'goal_src/user/'");
app.add_option("-p,--port", nrepl_port, "Specify the nREPL port. Defaults to 8181");
app.add_flag("-v,--verbose", verbose, "Enable verbose output");
app.add_flag("--auto-lt", auto_listen,
"Attempt to automatically connect to the listener on startup");
app.add_flag("--auto-dbg", auto_debug,
@ -78,7 +71,7 @@ int main(int argc, char** argv) {
}
}
setup_logging(verbose);
setup_logging();
lg::info("OpenGOAL Compiler {}.{}", versions::GOAL_VERSION_MAJOR, versions::GOAL_VERSION_MINOR);