some bugfixes
This commit is contained in:
@@ -63,7 +63,7 @@ class BlockizerProgramsManager {
|
||||
|
||||
private:
|
||||
McpipProgramsRepository repo;
|
||||
Renderer* renderer;
|
||||
RendererCore* rendererCore;
|
||||
McpipSingleTexBlockData singleTexBlockData;
|
||||
McpipMultiTexBlockData multiTexBlockData;
|
||||
McpipProgramName lastProgramName;
|
||||
|
||||
@@ -24,13 +24,22 @@ class Path1 {
|
||||
|
||||
u32 uploadProgram(VU1Program* program, const u32& address);
|
||||
|
||||
void sendDrawFinishTag();
|
||||
|
||||
void addDrawFinishTag(packet2_t* packet);
|
||||
|
||||
packet2_t* createProgramsCache(VU1Program** programs, const u32& count,
|
||||
const u32& address);
|
||||
|
||||
void setDoubleBuffer(const u16& startingAddress, const u16& bufferSize);
|
||||
|
||||
private:
|
||||
void uploadDrawFinishProgram();
|
||||
void prepareDrawFinishPacket();
|
||||
|
||||
packet2_t* doubleBufferPacket;
|
||||
packet2_t* drawFinishPacket;
|
||||
u32 drawFinishAddr;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
|
||||
@@ -27,7 +27,7 @@ class Path3 {
|
||||
|
||||
void init(RendererSettings* settings);
|
||||
|
||||
void addDrawFinishTag();
|
||||
void sendDrawFinishTag();
|
||||
void clearScreen(zbuffer_t* z, const Color& color);
|
||||
void sendTexture(Texture* texture,
|
||||
const RendererCoreTextureBuffers& texBuffers);
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include <draw.h>
|
||||
#include <gs_privileged.h>
|
||||
#include "./paths/path3/path3.hpp"
|
||||
#include "./paths/path1/path1.hpp"
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
@@ -29,22 +30,29 @@ class RendererCoreSync {
|
||||
RendererCoreSync();
|
||||
~RendererCoreSync();
|
||||
|
||||
void init(Path3* path3);
|
||||
void init(Path3* path3, Path1* path1);
|
||||
|
||||
// --- Auto
|
||||
|
||||
/** clear() -> sendPath1Req() -> waitAndClear() */
|
||||
void align3D();
|
||||
|
||||
/** clear() -> sendPath3Req() -> waitAndClear() */
|
||||
void align2D();
|
||||
|
||||
// --- Manual
|
||||
|
||||
/** Send draw finish tag via VU1 to GS. */
|
||||
void add();
|
||||
/** Check if finish flag was set by GS. */
|
||||
u8 check();
|
||||
/** Clear finish tag flag. */
|
||||
void clear();
|
||||
/** Wait for finish flag and clear it. */
|
||||
void waitAndClear();
|
||||
void sendPath1Req();
|
||||
void sendPath3Req();
|
||||
|
||||
/** Clear() -> Add() -> waitAndClear() */
|
||||
void align();
|
||||
void addPath1Req(packet2_t* packet);
|
||||
|
||||
private:
|
||||
Path3* path3;
|
||||
Path1* path1;
|
||||
};
|
||||
|
||||
} // namespace Tyra
|
||||
|
||||
@@ -125,10 +125,10 @@ void DynPipRenderer::sendObjectData(
|
||||
packet2_utils_gs_add_lod(objectDataPacket, &rendererCore->gs.lod);
|
||||
|
||||
if (texBuffers != nullptr) {
|
||||
rendererCore->texture.updateClutBuffer(texBuffers->clut);
|
||||
|
||||
packet2_utils_gs_add_texbuff_clut(objectDataPacket, texBuffers->core,
|
||||
&rendererCore->texture.clut);
|
||||
|
||||
rendererCore->texture.updateClutBuffer(texBuffers->clut);
|
||||
}
|
||||
}
|
||||
packet2_utils_vu_close_unpack(objectDataPacket);
|
||||
|
||||
@@ -37,6 +37,7 @@ BlockizerProgramsManager::~BlockizerProgramsManager() {
|
||||
}
|
||||
|
||||
void BlockizerProgramsManager::init(RendererCore* core) {
|
||||
rendererCore = core;
|
||||
culler.init(core, &singleTexBlockData);
|
||||
clipper.init(core, &singleTexBlockData, &multiTexBlockData);
|
||||
}
|
||||
@@ -46,7 +47,7 @@ void BlockizerProgramsManager::setProgramsCache() {
|
||||
programs[0] = repo.getProgram(McpipProgramName::McPipCull);
|
||||
programs[1] = repo.getProgram(McpipProgramName::McPipAsIs);
|
||||
programsPacket =
|
||||
renderer->core.getPath1()->createProgramsCache(programs, 2, 0);
|
||||
rendererCore->getPath1()->createProgramsCache(programs, 2, 0);
|
||||
delete[] programs;
|
||||
}
|
||||
|
||||
|
||||
@@ -139,10 +139,10 @@ void StaPipQBufferRenderer::sendObjectData(
|
||||
packet2_utils_gs_add_lod(objectDataPacket, &rendererCore->gs.lod);
|
||||
|
||||
if (texBuffers != nullptr) {
|
||||
rendererCore->texture.updateClutBuffer(texBuffers->clut);
|
||||
|
||||
packet2_utils_gs_add_texbuff_clut(objectDataPacket, texBuffers->core,
|
||||
&rendererCore->texture.clut);
|
||||
|
||||
rendererCore->texture.updateClutBuffer(texBuffers->clut);
|
||||
}
|
||||
}
|
||||
packet2_utils_vu_close_unpack(objectDataPacket);
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
|
||||
; ______ ____ ___
|
||||
; | \/ ____| |___|
|
||||
; | | | \ | |
|
||||
;---------------------------------------------------------------
|
||||
; Copyright 2022, tyra - https://github.com/h4570/tyra
|
||||
; Licenced under Apache License 2.0
|
||||
; Sandro Sobczyński <sandro.sobczynski@gmail.com>
|
||||
;
|
||||
;---------------------------------------------------------------
|
||||
; Needed for synchronization with draw_wait_finish()
|
||||
;---------------------------------------------------------------
|
||||
|
||||
.syntax new
|
||||
.name VU1DrawFinish
|
||||
.vu
|
||||
.init_vf_all
|
||||
.init_vi_all
|
||||
|
||||
--enter
|
||||
--endenter
|
||||
|
||||
#vuprog VU1DrawFinish
|
||||
xtop buffer
|
||||
iaddiu kickAddress, buffer, 10
|
||||
xgkick kickAddress
|
||||
#endvuprog
|
||||
|
||||
--exit
|
||||
--endexit
|
||||
@@ -10,12 +10,70 @@
|
||||
|
||||
#include "renderer/core/paths/path1/path1.hpp"
|
||||
|
||||
extern u32 VU1DrawFinish_CodeStart __attribute__((section(".vudata")));
|
||||
extern u32 VU1DrawFinish_CodeEnd __attribute__((section(".vudata")));
|
||||
|
||||
namespace Tyra {
|
||||
|
||||
Path1::Path1() {
|
||||
doubleBufferPacket = packet2_create(2, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
|
||||
drawFinishPacket = packet2_create(10, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
|
||||
uploadDrawFinishProgram();
|
||||
prepareDrawFinishPacket();
|
||||
}
|
||||
|
||||
void Path1::uploadDrawFinishProgram() {
|
||||
int count = (&VU1DrawFinish_CodeEnd - &VU1DrawFinish_CodeStart) / 2;
|
||||
if (count & 1) count++;
|
||||
|
||||
drawFinishAddr = 1000 - count;
|
||||
|
||||
packet2_t* packet2 = packet2_create(10, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
|
||||
packet2_vif_add_micro_program(packet2, drawFinishAddr,
|
||||
&VU1DrawFinish_CodeStart,
|
||||
&VU1DrawFinish_CodeEnd);
|
||||
dma_channel_wait(DMA_CHANNEL_VIF1, 0);
|
||||
dma_channel_send_packet2(packet2, DMA_CHANNEL_VIF1, true);
|
||||
packet2_free(packet2);
|
||||
}
|
||||
|
||||
void Path1::addDrawFinishTag(packet2_t* packet) {
|
||||
prim_t prim;
|
||||
prim.type = PRIM_TRIANGLE;
|
||||
prim.shading = PRIM_SHADE_GOURAUD;
|
||||
prim.mapping = 1;
|
||||
prim.fogging = 0;
|
||||
prim.blending = 1;
|
||||
prim.antialiasing = 0;
|
||||
prim.mapping_type = PRIM_MAP_ST;
|
||||
prim.colorfix = PRIM_UNFIXED;
|
||||
|
||||
packet2_utils_vu_open_unpack(packet, 10, true);
|
||||
{
|
||||
packet2_utils_gif_add_set(packet, 1);
|
||||
packet2_utils_gs_add_draw_finish_giftag(packet);
|
||||
packet2_utils_gs_add_prim_giftag(packet, &prim, 0,
|
||||
((u64)GIF_REG_RGBAQ) << 0, 1, 0);
|
||||
}
|
||||
packet2_utils_vu_close_unpack(packet);
|
||||
|
||||
packet2_utils_vu_add_start_program(packet, drawFinishAddr);
|
||||
}
|
||||
|
||||
void Path1::sendDrawFinishTag() {
|
||||
dma_channel_wait(DMA_CHANNEL_VIF1, 0);
|
||||
dma_channel_send_packet2(drawFinishPacket, DMA_CHANNEL_VIF1, true);
|
||||
}
|
||||
|
||||
Path1::~Path1() {
|
||||
packet2_free(doubleBufferPacket);
|
||||
packet2_free(drawFinishPacket);
|
||||
}
|
||||
|
||||
void Path1::prepareDrawFinishPacket() {
|
||||
addDrawFinishTag(drawFinishPacket);
|
||||
packet2_utils_vu_add_end_tag(drawFinishPacket);
|
||||
}
|
||||
Path1::~Path1() { packet2_free(doubleBufferPacket); }
|
||||
|
||||
u32 Path1::uploadProgram(VU1Program* program, const u32& address) {
|
||||
// TYRA_LOG("Uploading VU1 program. Size: ", program->getProgramSize(),
|
||||
@@ -24,7 +82,7 @@ u32 Path1::uploadProgram(VU1Program* program, const u32& address) {
|
||||
auto packetSize = program->getPacketSize() + 1; // + end tag
|
||||
|
||||
packet2_t* packet2 =
|
||||
packet2_create(packetSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, 1);
|
||||
packet2_create(packetSize, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
|
||||
|
||||
packet2_vif_add_micro_program(packet2, address, program->getStart(),
|
||||
program->getEnd());
|
||||
|
||||
@@ -36,7 +36,7 @@ void Path3::init(RendererSettings* t_settings) {
|
||||
TYRA_LOG("Path3 initialized");
|
||||
}
|
||||
|
||||
void Path3::addDrawFinishTag() {
|
||||
void Path3::sendDrawFinishTag() {
|
||||
dma_channel_wait(DMA_CHANNEL_GIF, 0);
|
||||
dma_channel_send_packet2(drawFinishPacket, DMA_CHANNEL_GIF, true);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ void RendererCore::init() {
|
||||
path3.init(&settings);
|
||||
renderer3D.init(&settings, &path1);
|
||||
renderer2D.init(&settings, &texture.clut);
|
||||
sync.init(&path3);
|
||||
sync.init(&path3, &path1);
|
||||
}
|
||||
|
||||
void RendererCore::setClearScreenColor(const Color& color) { bgColor = color; }
|
||||
|
||||
@@ -15,15 +15,30 @@ namespace Tyra {
|
||||
RendererCoreSync::RendererCoreSync() {}
|
||||
RendererCoreSync::~RendererCoreSync() {}
|
||||
|
||||
void RendererCoreSync::init(Path3* t_path3) { path3 = t_path3; }
|
||||
void RendererCoreSync::init(Path3* t_path3, Path1* t_path1) {
|
||||
path3 = t_path3;
|
||||
path1 = t_path1;
|
||||
}
|
||||
|
||||
void RendererCoreSync::align() {
|
||||
void RendererCoreSync::align3D() {
|
||||
clear();
|
||||
add();
|
||||
sendPath1Req();
|
||||
waitAndClear();
|
||||
}
|
||||
|
||||
void RendererCoreSync::add() { path3->addDrawFinishTag(); }
|
||||
void RendererCoreSync::align2D() {
|
||||
clear();
|
||||
sendPath3Req();
|
||||
waitAndClear();
|
||||
}
|
||||
|
||||
void RendererCoreSync::sendPath1Req() { path1->sendDrawFinishTag(); }
|
||||
|
||||
void RendererCoreSync::sendPath3Req() { path3->sendDrawFinishTag(); }
|
||||
|
||||
void RendererCoreSync::addPath1Req(packet2_t* packet) {
|
||||
path1->addDrawFinishTag(packet);
|
||||
}
|
||||
|
||||
u8 RendererCoreSync::check() { return *GS_REG_CSR & 2; }
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ void RendererCoreTexture::init(RendererCoreGS* t_gs, Path3* t_path3) {
|
||||
}
|
||||
|
||||
void RendererCoreTexture::updateClutBuffer(texbuffer_t* clutBuffer) {
|
||||
if (clutBuffer == nullptr) {
|
||||
if (clutBuffer == nullptr || clutBuffer->width == 0) {
|
||||
clut.psm = 0;
|
||||
clut.load_method = CLUT_NO_LOAD;
|
||||
clut.address = 0;
|
||||
@@ -44,15 +44,23 @@ RendererCoreTextureBuffers RendererCoreTexture::useTexture(Texture* t_tex) {
|
||||
auto allocated = getAllocatedBuffersByTextureId(t_tex->getId());
|
||||
if (allocated.id != 0) return allocated;
|
||||
|
||||
while ((t_tex->getSizeInMB()) > sender.getFreeVRamInMB()) {
|
||||
// auto idToDealloc =
|
||||
// cacheManager.getTextureIdToDealloc(currentAllocations);
|
||||
auto idToDealloc = currentAllocations.back().id;
|
||||
auto buffToDealloc = getAllocatedBuffersByTextureId(idToDealloc);
|
||||
sender.deallocate(buffToDealloc);
|
||||
unregisterAllocation(idToDealloc);
|
||||
// TODO: Dont like this..., but it works for now.
|
||||
if (t_tex->getSizeInMB() > sender.getFreeVRamInMB()) {
|
||||
for (int i = currentAllocations.size() - 1; i >= 0; i--) {
|
||||
sender.deallocate(currentAllocations[i]);
|
||||
}
|
||||
currentAllocations.clear();
|
||||
}
|
||||
|
||||
// while (t_tex->getSizeInMB() > sender.getFreeVRamInMB()) {
|
||||
// auto idToDealloc =
|
||||
// cacheManager.getTextureIdToDealloc(currentAllocations);
|
||||
// auto buffToDealloc = getAllocatedBuffersByTextureId(idToDealloc);
|
||||
// TYRA_LOG("Deallocate(", buffToDealloc.id, ")");
|
||||
// sender.deallocate(buffToDealloc);
|
||||
// unregisterAllocation(idToDealloc);
|
||||
// }
|
||||
|
||||
auto newTexBuffer = sender.allocate(t_tex);
|
||||
path3->sendTexture(t_tex, newTexBuffer);
|
||||
registerAllocation(newTexBuffer);
|
||||
|
||||
Reference in New Issue
Block a user