Skip to content

Commit

Permalink
add an optional, less-accurate-but-faster sprite render and fix silly…
Browse files Browse the repository at this point in the history
… math bug (#1102)

* also add a new sprite renderer

* claaaang

* goal build fix

* fix tests, add stack singleton option

* make all event-message-blocks the same

* diskboot
  • Loading branch information
water111 authored Jan 22, 2022
1 parent 4648f78 commit 35bdc9b
Show file tree
Hide file tree
Showing 45 changed files with 1,493 additions and 277 deletions.
7 changes: 7 additions & 0 deletions common/dma/gs.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,13 @@ class DrawMode {
bool get_depth_write_enable() const { return m_val & 0b1; }
void enable_depth_write() { m_val = m_val | 0b1; }
void disable_depth_write() { m_val = m_val & ~(0b1); }
void set_depth_write_enable(bool x) {
if (x) {
enable_depth_write();
} else {
disable_depth_write();
}
}

GsTest::ZTest get_depth_test() const { return (GsTest::ZTest)((m_val >> 1) & 0b11); }
void set_depth_test(GsTest::ZTest dt) { m_val = (m_val & ~(0b110)) | ((u32)(dt) << 1); }
Expand Down
17 changes: 12 additions & 5 deletions common/type_system/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -696,9 +696,9 @@ StructureType::StructureType(std::string parent,
std::string StructureType::print() const {
std::string result = fmt::format(
"[StructureType] {}\n parent: {}\n boxed: {}\n dynamic: {}\n size: {}\n pack: {}\n misalign: "
"{}\n heap-base: {}\n fields:\n",
m_name, m_parent, m_is_boxed, m_dynamic, m_size_in_mem, m_pack, m_allow_misalign,
m_heap_base);
"{}\n heap-base: {}\n stack-singleton: {}\n fields:\n",
m_name, m_parent, m_is_boxed, m_dynamic, m_size_in_mem, m_pack, m_allow_misalign, m_heap_base,
m_always_stack_singleton);
for (auto& x : m_fields) {
result += " " + x.print() + "\n";
}
Expand Down Expand Up @@ -727,7 +727,8 @@ bool StructureType::operator==(const Type& other) const {
m_pack == p_other->m_pack &&
m_allow_misalign == p_other->m_allow_misalign &&
m_offset == p_other->m_offset &&
m_idx_of_first_unique_field == p_other->m_idx_of_first_unique_field;
m_idx_of_first_unique_field == p_other->m_idx_of_first_unique_field &&
m_always_stack_singleton == p_other->m_always_stack_singleton;
// clang-format on
}

Expand Down Expand Up @@ -773,6 +774,11 @@ std::string StructureType::diff_structure_common(const StructureType& other) con
result += fmt::format("allow_misalign: {} vs. {}\n", m_allow_misalign, other.m_allow_misalign);
}

if (m_always_stack_singleton != other.m_always_stack_singleton) {
result += fmt::format("always_stack_singleton: {} vs. {}\n", m_always_stack_singleton,
other.m_always_stack_singleton);
}

if (m_offset != other.m_offset) {
result += fmt::format("offset: {} vs. {}\n", m_offset, other.m_offset);
}
Expand Down Expand Up @@ -906,7 +912,8 @@ bool BasicType::operator==(const Type& other) const {
m_allow_misalign == p_other->m_allow_misalign &&
m_offset == p_other->m_offset &&
m_idx_of_first_unique_field == p_other->m_idx_of_first_unique_field &&
m_final == p_other->m_final;
m_final == p_other->m_final &&
m_always_stack_singleton == p_other->m_always_stack_singleton;
// clang-format on
}

Expand Down
3 changes: 3 additions & 0 deletions common/type_system/Type.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,11 @@ class StructureType : public ReferenceType {
bool is_dynamic() const { return m_dynamic; }
~StructureType() = default;
void set_pack(bool pack) { m_pack = pack; }
void set_always_stack_singleton() { m_always_stack_singleton = true; }
void set_heap_base(int hb) { m_heap_base = hb; }
bool is_packed() const { return m_pack; }
bool is_allowed_misalign() const { return m_allow_misalign; };
bool is_always_stack_singleton() const { return m_always_stack_singleton; }
void set_allow_misalign(bool misalign) { m_allow_misalign = misalign; }
void set_gen_inspect(bool gen_inspect) { m_generate_inspect = gen_inspect; }

Expand All @@ -300,6 +302,7 @@ class StructureType : public ReferenceType {
bool m_pack = false;
bool m_allow_misalign = false;
int m_offset = 0;
bool m_always_stack_singleton = false;
size_t m_idx_of_first_unique_field = 0;
};

Expand Down
3 changes: 3 additions & 0 deletions common/type_system/TypeSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1617,6 +1617,9 @@ std::string TypeSystem::generate_deftype_footer(const Type* type) const {
if (as_structure->is_allowed_misalign()) {
result.append(" :allow-misaligned\n");
}
if (as_structure->is_always_stack_singleton()) {
result.append(" :always-stack-singleton\n");
}
}

if (type->heap_base()) {
Expand Down
13 changes: 13 additions & 0 deletions common/type_system/deftype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ struct StructureDefResult {
bool pack_me = false;
bool allow_misaligned = false;
bool final = false;
bool always_stack_singleton = false;
};

StructureDefResult parse_structure_def(StructureType* type,
Expand Down Expand Up @@ -347,6 +348,8 @@ StructureDefResult parse_structure_def(StructureType* type,
result.allow_misaligned = true;
} else if (opt_name == ":final") {
result.final = true;
} else if (opt_name == ":always-stack-singleton") {
result.always_stack_singleton = true;
} else {
throw std::runtime_error("Invalid option in field specification: " + opt_name);
}
Expand Down Expand Up @@ -572,6 +575,13 @@ DeftypeResult parse_deftype(const goos::Object& deftype, TypeSystem* ts) {
name);
throw std::runtime_error("invalid pack option on basic");
}
if (sr.always_stack_singleton) {
fmt::print(
"[TypeSystem] :always-stack-singleton was set on {}, which is a basic and cannot "
"be a stack singleton\n",
name);
throw std::runtime_error("invalid stack singleton option on basic");
}
new_type->set_heap_base(result.flags.heap_base);
if (sr.final) {
new_type->set_final();
Expand All @@ -592,6 +602,9 @@ DeftypeResult parse_deftype(const goos::Object& deftype, TypeSystem* ts) {
if (sr.allow_misaligned) {
new_type->set_allow_misalign(true);
}
if (sr.always_stack_singleton) {
new_type->set_always_stack_singleton();
}
if (sr.final) {
throw std::runtime_error(
fmt::format("[TypeSystem] :final option cannot be used on structure type {}", name));
Expand Down
1 change: 1 addition & 0 deletions decompiler/config/all-types.gc
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,7 @@
:method-count-assert 9
:size-assert #x48
:flag-assert #x900000048
:always-stack-singleton
)

;; - Symbols
Expand Down
3 changes: 2 additions & 1 deletion docs/markdown/progress-notes/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,5 @@
- It is now an error to use a `none`-typed variable in a condition
- Debugger will now correctly track when object files are loaded over previous files
- Asm ops requiring 128-bit inputs will now try harder to convert their inputs when it is appropriate.
- 0's that are constant propagated to the input of a 128-bit instruction will use `vpxor` instruction to generate the value, instead of `xor` and a `mov`.
- 0's that are constant propagated to the input of a 128-bit instruction will use `vpxor` instruction to generate the value, instead of `xor` and a `mov`.
- Add a `stack-singleton-no-clear` stack construction type. It will create a "singleton" inside this function - all other `(new 'stack-singleton` forms with the same type will return the same stack object.
1 change: 1 addition & 0 deletions game/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ set(RUNTIME_SOURCE
graphics/opengl_renderer/SkyBlendCPU.cpp
graphics/opengl_renderer/SkyBlendGPU.cpp
graphics/opengl_renderer/SkyRenderer.cpp
graphics/opengl_renderer/Sprite3.cpp
graphics/opengl_renderer/SpriteRenderer.cpp
graphics/opengl_renderer/TextureUploadHandler.cpp
graphics/opengl_renderer/tfrag/BufferedRenderer.cpp
Expand Down
29 changes: 29 additions & 0 deletions game/graphics/opengl_renderer/BucketRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "BucketRenderer.h"
#include "third-party/imgui/imgui.h"

#include "third-party/fmt/core.h"

Expand Down Expand Up @@ -62,4 +63,32 @@ void SharedRenderState::reset() {
for (auto& x : occlusion_vis) {
x.valid = false;
}
}

RenderMux::RenderMux(const std::string& name,
BucketId my_id,
std::vector<std::unique_ptr<BucketRenderer>> renderers)
: BucketRenderer(name, my_id), m_renderers(std::move(renderers)) {
for (auto& r : m_renderers) {
m_name_strs.push_back(r->name_and_id());
m_name_str_ptrs.push_back(m_name_strs.back().data());
}
}

void RenderMux::render(DmaFollower& dma,
SharedRenderState* render_state,
ScopedProfilerNode& prof) {
m_renderers[m_render_idx]->render(dma, render_state, prof);
}

void RenderMux::serialize(Serializer& ser) {
for (auto& r : m_renderers) {
r->serialize(ser);
}
}

void RenderMux::draw_debug_window() {
ImGui::ListBox("Pick", &m_render_idx, m_name_str_ptrs.data(), m_renderers.size());
ImGui::Separator();
m_renderers[m_render_idx]->draw_debug_window();
}
16 changes: 16 additions & 0 deletions game/graphics/opengl_renderer/BucketRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,22 @@ class BucketRenderer {
bool m_enabled = true;
};

class RenderMux : public BucketRenderer {
public:
RenderMux(const std::string& name,
BucketId my_id,
std::vector<std::unique_ptr<BucketRenderer>> renderers);
void render(DmaFollower& dma, SharedRenderState* render_state, ScopedProfilerNode& prof) override;
void draw_debug_window() override;
void serialize(Serializer& ser) override;

private:
std::vector<std::unique_ptr<BucketRenderer>> m_renderers;
int m_render_idx = 0;
std::vector<std::string> m_name_strs;
std::vector<const char*> m_name_str_ptrs;
};

/*!
* Renderer that makes sure the bucket is empty and ignores it.
*/
Expand Down
7 changes: 6 additions & 1 deletion game/graphics/opengl_renderer/OpenGLRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "third-party/imgui/imgui.h"
#include "common/util/FileUtil.h"
#include "game/graphics/opengl_renderer/SkyRenderer.h"
#include "game/graphics/opengl_renderer/Sprite3.h"
#include "game/graphics/opengl_renderer/tfrag/TFragment.h"
#include "game/graphics/opengl_renderer/tfrag/Tie3.h"

Expand Down Expand Up @@ -100,7 +101,11 @@ void OpenGLRenderer::init_bucket_renderers() {
init_bucket_renderer<TextureUploadHandler>("water-tex-0", BucketId::WATER_TEX_LEVEL0);
init_bucket_renderer<TextureUploadHandler>("water-tex-1", BucketId::WATER_TEX_LEVEL1);
init_bucket_renderer<TextureUploadHandler>("pre-sprite-tex", BucketId::PRE_SPRITE_TEX);
init_bucket_renderer<SpriteRenderer>("sprite", BucketId::SPRITE);
std::vector<std::unique_ptr<BucketRenderer>> sprite_renderers;
sprite_renderers.push_back(std::make_unique<SpriteRenderer>("sprite-renderer", BucketId::SPRITE));
sprite_renderers.push_back(std::make_unique<Sprite3>("sprite-3", BucketId::SPRITE));

init_bucket_renderer<RenderMux>("sprite", BucketId::SPRITE, std::move(sprite_renderers));
init_bucket_renderer<DirectRenderer>("debug-draw-0", BucketId::DEBUG_DRAW_0, 0x8000,
DirectRenderer::Mode::NORMAL);
init_bucket_renderer<DirectRenderer>("debug-draw-1", BucketId::DEBUG_DRAW_1, 0x8000,
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 @@ -77,4 +77,5 @@ ShaderLibrary::ShaderLibrary() {
at(ShaderId::BUFFERED_TCC1) = {"buffered_tcc1"};
at(ShaderId::TFRAG3) = {"tfrag3"};
at(ShaderId::TFRAG3_NO_TEX) = {"tfrag3_no_tex"};
at(ShaderId::SPRITE3) = {"sprite3_3d"};
}
1 change: 1 addition & 0 deletions game/graphics/opengl_renderer/Shader.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ enum class ShaderId {
TFRAG3 = 12,
TFRAG3_NO_TEX = 13,
SPRITE = 14,
SPRITE3 = 15,
MAX_SHADERS
};

Expand Down
Loading

0 comments on commit 35bdc9b

Please sign in to comment.