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

[graphics] port generic VU1 to OpenGL #1221

Merged
merged 13 commits into from
Mar 7, 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
11 changes: 11 additions & 0 deletions common/dma/gs.h
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,19 @@ struct AdGifData {
u64 clamp_addr;
u64 alpha_data;
u64 alpha_addr;

bool is_normal_adgif() const {
return (u8)tex0_addr == (u32)GsRegisterAddress::TEX0_1 &&
(u8)tex1_addr == (u32)GsRegisterAddress::TEX1_1 &&
(u8)mip_addr == (u32)GsRegisterAddress::MIPTBP1_1 &&
(u8)clamp_addr == (u32)GsRegisterAddress::CLAMP_1 &&
((u8)alpha_addr == (u32)GsRegisterAddress::ALPHA_1 ||
(u8)alpha_addr == (u32)GsRegisterAddress::MIPTBP2_1);
}
};

static_assert(sizeof(AdGifData) == 5 * 16);

// this represents all of the drawing state, stored as an integer.
// it can also represent "invalid".
class DrawMode {
Expand Down
15 changes: 15 additions & 0 deletions common/math/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,15 @@ class Vector {
return result + "]";
}

std::string to_string_hex_byte() const {
std::string result = "[";
for (auto x : m_data) {
result.append(fmt::format("0x{:02x} ", x));
}
result.pop_back();
return result + "]";
}

T* data() { return m_data; }
const T* data() const { return m_data; }

Expand All @@ -207,6 +216,12 @@ class Vector {
Vector<T, 3> xyz() const { return head<3>(); }
Vector<T, 3> xy() const { return head<2>(); }

void fill(const T& val) {
for (auto& x : m_data) {
x = val;
}
}

private:
T m_data[Size];
};
Expand Down
4 changes: 2 additions & 2 deletions common/util/Timer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define NS_PER_HNS (100ULL) // NS = nanoseconds
#define NS_PER_SEC (MS_PER_SEC * US_PER_MS * NS_PER_US)

int Timer::clock_gettime_monotonic(struct timespec* tv) {
int Timer::clock_gettime_monotonic(struct timespec* tv) const {
static LARGE_INTEGER ticksPerSec;
LARGE_INTEGER ticks;
double seconds;
Expand Down Expand Up @@ -42,7 +42,7 @@ void Timer::start() {
#endif
}

int64_t Timer::getNs() {
int64_t Timer::getNs() const {
struct timespec now = {};
#ifdef __linux__
clock_gettime(CLOCK_MONOTONIC, &now);
Expand Down
10 changes: 5 additions & 5 deletions common/util/Timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Timer {
explicit Timer() { start(); }

#ifdef _WIN32
int clock_gettime_monotonic(struct timespec* tv);
int clock_gettime_monotonic(struct timespec* tv) const;
#endif

/*!
Expand All @@ -26,19 +26,19 @@ class Timer {
/*!
* Get milliseconds elapsed
*/
double getMs() { return (double)getNs() / 1.e6; }
double getMs() const { return (double)getNs() / 1.e6; }

double getUs() { return (double)getNs() / 1.e3; }
double getUs() const { return (double)getNs() / 1.e3; }

/*!
* Get nanoseconds elapsed
*/
int64_t getNs();
int64_t getNs() const;

/*!
* Get seconds elapsed
*/
double getSeconds() { return (double)getNs() / 1.e9; }
double getSeconds() const { return (double)getNs() / 1.e9; }

struct timespec _startTime = {};
};
12 changes: 8 additions & 4 deletions game/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ set(RUNTIME_SOURCE
graphics/gfx.cpp
graphics/display.cpp
graphics/sceGraphicsInterface.cpp
graphics/opengl_renderer/background/background_common.cpp
graphics/opengl_renderer/background/Tfrag3.cpp
graphics/opengl_renderer/background/TFragment.cpp
graphics/opengl_renderer/background/Tie3.cpp
graphics/opengl_renderer/foreground/Generic2.cpp
graphics/opengl_renderer/foreground/Generic2_DMA.cpp
graphics/opengl_renderer/foreground/Generic2_Build.cpp
graphics/opengl_renderer/foreground/Generic2_OpenGL.cpp
graphics/opengl_renderer/BucketRenderer.cpp
graphics/opengl_renderer/debug_gui.cpp
graphics/opengl_renderer/DirectRenderer.cpp
Expand All @@ -95,10 +103,6 @@ set(RUNTIME_SOURCE
graphics/opengl_renderer/Sprite3.cpp
graphics/opengl_renderer/SpriteRenderer.cpp
graphics/opengl_renderer/TextureUploadHandler.cpp
graphics/opengl_renderer/tfrag/Tfrag3.cpp
graphics/opengl_renderer/tfrag/tfrag_common.cpp
graphics/opengl_renderer/tfrag/TFragment.cpp
graphics/opengl_renderer/tfrag/Tie3.cpp
graphics/texture/TextureConverter.cpp
graphics/texture/TexturePool.cpp
graphics/pipelines/opengl.cpp
Expand Down
23 changes: 23 additions & 0 deletions game/common/vu.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,17 @@ struct alignas(16) Vf {
}
}

void ftoi4_check(Mask /*mask*/, const Vf& a) {
for (int i = 0; i < 3; i++) {
data[i] = a.data[i];
}

for (int i = 3; i < 4; i++) {
s32 val = a.data[i] * 16.f;
memcpy(&data[i], &val, 4);
}
}

void ftoi12(Mask mask, const Vf& a) {
for (int i = 0; i < 4; i++) {
if ((u64)mask & (1 << i)) {
Expand All @@ -365,6 +376,18 @@ struct alignas(16) Vf {
}
}

void ftoi12_check(Mask mask, const Vf& a) {
for (int i = 0; i < 4; i++) {
if ((u64)mask & (1 << i)) {
if (std::isnan(a.data[i])) {
ASSERT(false);
}
s32 val = a.data[i] * 4096.f;
memcpy(&data[i], &val, 4);
}
}
}

void ftoi0(Mask mask, const Vf& a) {
for (int i = 0; i < 4; i++) {
if ((u64)mask & (1 << i)) {
Expand Down
6 changes: 6 additions & 0 deletions game/graphics/opengl_renderer/AdgifHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class AdgifHelper {
m_alpha = GsAlpha(m_data.alpha_data);
}

explicit AdgifHelper(const AdGifData& data) : m_data(data) {
m_tex0 = GsTex0(m_data.tex0_data);
m_tex1 = GsTex1(m_data.tex1_data);
m_alpha = GsAlpha(m_data.alpha_data);
}

bool is_normal_adgif() const {
return (u8)m_data.tex0_addr == (u32)GsRegisterAddress::TEX0_1 &&
(u8)m_data.tex1_addr == (u32)GsRegisterAddress::TEX1_1 &&
Expand Down
55 changes: 2 additions & 53 deletions game/graphics/opengl_renderer/BucketRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,59 +7,7 @@
#include "game/graphics/texture/TexturePool.h"
#include "game/graphics/opengl_renderer/Profiler.h"
#include "game/graphics/opengl_renderer/Loader.h"

/*!
* Matches the bucket-id enum in GOAL
*/
enum class BucketId {
BUCKET0 = 0,
BUCKET1 = 1,
SKY_DRAW = 3,
TFRAG_TEX_LEVEL0 = 5,
TFRAG_LEVEL0 = 6,
TIE_LEVEL0 = 9,
MERC_TFRAG_TEX_LEVEL0 = 10,
GMERC_TFRAG_TEX_LEVEL0 = 11,
TFRAG_TEX_LEVEL1 = 12,
TFRAG_LEVEL1 = 13,
TIE_LEVEL1 = 16,
MERC_TFRAG_TEX_LEVEL1 = 17,
GMERC_TFRAG_TEX_LEVEL1 = 18,
SHRUB_TEX_LEVEL0 = 19,
SHRUB_TEX_LEVEL1 = 25,
GENERIC_SHRUB = 30,
ALPHA_TEX_LEVEL0 = 31,
TFRAG_TRANS0_AND_SKY_BLEND_LEVEL0 = 32,
TFRAG_DIRT_LEVEL0 = 34,
TFRAG_ICE_LEVEL0 = 36,
ALPHA_TEX_LEVEL1 = 38,
TFRAG_TRANS1_AND_SKY_BLEND_LEVEL1 = 39,
TFRAG_DIRT_LEVEL1 = 41,
TFRAG_ICE_LEVEL1 = 43,
MERC_AFTER_ALPHA = 45,
GENERIC_ALPHA = 46,
PRIS_TEX_LEVEL0 = 48,
MERC_PRIS_LEVEL0 = 49,
GENERIC_PRIS_LEVEL0 = 50,
PRIS_TEX_LEVEL1 = 51,
MERC_PRIS_LEVEL1 = 52,
GENERIC_PRIS_LEVEL1 = 53,
MERC_EYES_AFTER_PRIS = 54,
MERC_AFTER_PRIS = 55,
GENERIC_PRIS = 56,
WATER_TEX_LEVEL0 = 57,
MERC_WATER_LEVEL0 = 58,
GENERIC_WATER_LEVEL0 = 59,
WATER_TEX_LEVEL1 = 60,
MERC_WATER_LEVEL1 = 61,
GENERIC_WATER_LEVEL1 = 62,
// ...
PRE_SPRITE_TEX = 65, // maybe it's just common textures?
SPRITE = 66,
DEBUG_DRAW_0 = 67,
DEBUG_DRAW_1 = 68,
MAX_BUCKETS = 69
};
#include "game/graphics/opengl_renderer/buckets.h"

struct LevelVis {
bool valid = false;
Expand Down Expand Up @@ -92,6 +40,7 @@ struct SharedRenderState {
bool enable_merc_xgkick = true;
bool enable_generic_xgkick = true;
bool use_direct2 = true;
bool use_generic2 = true;
math::Vector<u8, 4> fog_color;
float fog_intensity = 1.f;

Expand Down
Loading