Support apply_matrix on Vertex type

This commit is contained in:
Jaby 2024-04-03 17:30:37 -05:00
parent 07480c8eba
commit 7d29b27f64
6 changed files with 57 additions and 39 deletions

View File

@ -18,22 +18,19 @@ namespace GTETest {
}
void apply(const GTE::MATRIX& matrix) {
static const auto apply_to = [](const GTE::MATRIX& matrix, GTE::SVECTOR vector) -> GPU::Vertex {
static const auto apply_to = [](const GTE::MATRIX& matrix, GPU::Vertex vertex) -> GPU::Vertex {
GTE::MATRIX move_back = GTE::MATRIX{
GTE::ROTMATRIX::identity(), GTE::TRANSFERVECTOR::translated(-matrix.transfer.x, -matrix.transfer.y, -matrix.transfer.z)
};
GTE::SVECTOR output;
int32_t flag;
GTE::comp_matrix(matrix, move_back, move_back);
return GTE::apply_matrix(move_back, vector, output).to<GPU::Vertex>();
return GTE::apply_matrix(move_back, vertex, vertex);
};
const auto& area = this->area;
this->display.vertex0 = apply_to(matrix, GTE::SVECTOR::from(area.get_top_left()));
this->display.vertex1 = apply_to(matrix, GTE::SVECTOR::from(area.get_top_right()));
this->display.vertex2 = apply_to(matrix, GTE::SVECTOR::from(area.get_bottom_left()));
this->display.vertex3 = apply_to(matrix, GTE::SVECTOR::from(area.get_bottom_right()));
this->display.vertex0 = apply_to(matrix, area.get_top_left());
this->display.vertex1 = apply_to(matrix, area.get_top_right());
this->display.vertex2 = apply_to(matrix, area.get_bottom_left());
this->display.vertex3 = apply_to(matrix, area.get_bottom_right());
}
void render() {

View File

@ -5,6 +5,20 @@ namespace JabyEngine {
namespace GTE {
static constexpr auto StackSize = 16;
/*
matrix: first input
Sets the 3x3 constant rotation matrix and the parallel transfer vector from input
*/
void set_matrix(const MATRIX& matrix);
/*
returns: current matrix
Gets the current 3x3 constant rotation matrix and the parallel transfer vector
*/
MATRIX get_matrix();
/*
RotTrans
@ -99,8 +113,28 @@ namespace JabyEngine {
returns: result
Applies the matrix to the vector
The function destroys the constant rotation matrix and transfer vector
*/
SVECTOR& apply_matrix(const MATRIX& m0, const SVECTOR& v0, SVECTOR& v1);
static SVECTOR& apply_matrix(const MATRIX& m0, const SVECTOR& v0, SVECTOR& v1) {
set_matrix(m0);
JabyEngine::GTE::ldv0(v0);
JabyEngine::GTE::rt();
JabyEngine::GTE::stsv(v1);
return v1;
}
/*
Same as apply_matrix but works on Vertex
*/
static GPU::Vertex& apply_matrix(const MATRIX& m0, const GPU::Vertex& v0, GPU::Vertex& v1) {
set_matrix(m0);
JabyEngine::GTE::ldgv0(v0);
JabyEngine::GTE::rt();
JabyEngine::GTE::stgv(v1);
return v1;
}
/*
MulMatrix0
@ -133,20 +167,6 @@ namespace JabyEngine {
return result;
}
/*
matrix: first input
Sets the 3x3 constant rotation matrix and the parallel transfer vector from input
*/
void set_matrix(const MATRIX& matrix);
/*
returns: current matrix
Gets the current 3x3 constant rotation matrix and the parallel transfer vector
*/
MATRIX get_matrix();
/*
matrix: optional input

View File

@ -29,7 +29,12 @@ namespace JabyEngine {
__asm__ volatile("or $12, $12, $13" :: "r"(&vector) : "$12", "$13");
__asm__ volatile("mtc2 $12, $0" :: "r"(&vector) : "$12", "$13");
__asm__ volatile("lwc2 $1, 8(%0)" :: "r"(&vector) : "$12", "$13");
}
// Loads a GPU VERTEX type
static __always_inline void ldgv0(const GPU::Vertex& vertex) {
__asm__ volatile("lwc2 $0, 0(%0)" :: "r"(&vertex));
__asm__ volatile("lwc2 $1, 0" :: "r"(&vertex));
}
// Load column vector of MATRIX to universal register
@ -77,6 +82,14 @@ namespace JabyEngine {
__asm__ volatile("sh $14, 4(%0)" :: "r"(&out_vector) : "$12", "$13", "$14", "memory");
}
// Stores result into a GPU Vertex type
static __always_inline void stgv(GPU::Vertex& out_vertex) {
__asm__ volatile("mfc2 $12, $9" :: "r"(&out_vertex) : "$12", "$13", "$14", "memory");
__asm__ volatile("mfc2 $13, $10" :: "r"(&out_vertex) : "$12", "$13", "$14", "memory");
__asm__ volatile("sh $12, 0(%0)" :: "r"(&out_vertex) : "$12", "$13", "$14", "memory");
__asm__ volatile("sh $13, 2(%0)" :: "r"(&out_vertex) : "$12", "$13", "$14", "memory");
}
/*
Kernel of RotTrans
(Transfer vector)+(Rotation Matrix)*(vertex register 0)

View File

@ -10,13 +10,14 @@ namespace JabyEngine {
T x;
T y;
T z;
T pad;
static constexpr VECTOR create() {
return VECTOR::create(0, 0, 0);
}
static constexpr VECTOR create(T x, T y, T z) {
return VECTOR{.x = x, .y = y, .z = z};
return VECTOR{.x = x, .y = y, .z = z, .pad = 0};
}
template<typename S>

View File

@ -2,10 +2,7 @@
#include "../../internal-include/GPU/gpu_internal.hpp"
#include <stdio.h>
#include <PSX/GTE/gte.hpp>
#include <PSX/System/syscalls.hpp>
#include "../../reference/inline_n.h"
#include <math.h>
extern "C" uint32_t __heap_start;
extern "C" uint32_t __bss_start;

View File

@ -43,16 +43,6 @@ namespace JabyEngine {
static MATRIX Stack[StackSize];
static MATRIX* FreeStackEntry = Stack;
SVECTOR& apply_matrix(const MATRIX& m0, const SVECTOR& v0, SVECTOR& v1) {
// TODO: Do we want to push here?
set_matrix(m0);
JabyEngine::GTE::ldv0(v0);
JabyEngine::GTE::rt();
JabyEngine::GTE::stsv(v1);
return v1;
}
ROTMATRIX& multiply_matrix(const ROTMATRIX& m0, const ROTMATRIX& m1, ROTMATRIX& result) {
set_rot_matrix(m0);