some bugfixes

This commit is contained in:
h4570
2022-07-28 20:44:21 +02:00
parent 960f4dd0c4
commit 4366d6d6fb
14 changed files with 177 additions and 48 deletions
@@ -63,7 +63,7 @@ class BlockizerProgramsManager {
private: private:
McpipProgramsRepository repo; McpipProgramsRepository repo;
Renderer* renderer; RendererCore* rendererCore;
McpipSingleTexBlockData singleTexBlockData; McpipSingleTexBlockData singleTexBlockData;
McpipMultiTexBlockData multiTexBlockData; McpipMultiTexBlockData multiTexBlockData;
McpipProgramName lastProgramName; McpipProgramName lastProgramName;
@@ -24,13 +24,22 @@ class Path1 {
u32 uploadProgram(VU1Program* program, const u32& address); u32 uploadProgram(VU1Program* program, const u32& address);
void sendDrawFinishTag();
void addDrawFinishTag(packet2_t* packet);
packet2_t* createProgramsCache(VU1Program** programs, const u32& count, packet2_t* createProgramsCache(VU1Program** programs, const u32& count,
const u32& address); const u32& address);
void setDoubleBuffer(const u16& startingAddress, const u16& bufferSize); void setDoubleBuffer(const u16& startingAddress, const u16& bufferSize);
private: private:
void uploadDrawFinishProgram();
void prepareDrawFinishPacket();
packet2_t* doubleBufferPacket; packet2_t* doubleBufferPacket;
packet2_t* drawFinishPacket;
u32 drawFinishAddr;
}; };
} // namespace Tyra } // namespace Tyra
@@ -27,7 +27,7 @@ class Path3 {
void init(RendererSettings* settings); void init(RendererSettings* settings);
void addDrawFinishTag(); void sendDrawFinishTag();
void clearScreen(zbuffer_t* z, const Color& color); void clearScreen(zbuffer_t* z, const Color& color);
void sendTexture(Texture* texture, void sendTexture(Texture* texture,
const RendererCoreTextureBuffers& texBuffers); const RendererCoreTextureBuffers& texBuffers);
@@ -13,6 +13,7 @@
#include <draw.h> #include <draw.h>
#include <gs_privileged.h> #include <gs_privileged.h>
#include "./paths/path3/path3.hpp" #include "./paths/path3/path3.hpp"
#include "./paths/path1/path1.hpp"
namespace Tyra { namespace Tyra {
@@ -29,22 +30,29 @@ class RendererCoreSync {
RendererCoreSync(); 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(); u8 check();
/** Clear finish tag flag. */
void clear(); void clear();
/** Wait for finish flag and clear it. */
void waitAndClear(); void waitAndClear();
void sendPath1Req();
void sendPath3Req();
/** Clear() -> Add() -> waitAndClear() */ void addPath1Req(packet2_t* packet);
void align();
private: private:
Path3* path3; Path3* path3;
Path1* path1;
}; };
} // namespace Tyra } // namespace Tyra
@@ -125,10 +125,10 @@ void DynPipRenderer::sendObjectData(
packet2_utils_gs_add_lod(objectDataPacket, &rendererCore->gs.lod); packet2_utils_gs_add_lod(objectDataPacket, &rendererCore->gs.lod);
if (texBuffers != nullptr) { if (texBuffers != nullptr) {
rendererCore->texture.updateClutBuffer(texBuffers->clut);
packet2_utils_gs_add_texbuff_clut(objectDataPacket, texBuffers->core, packet2_utils_gs_add_texbuff_clut(objectDataPacket, texBuffers->core,
&rendererCore->texture.clut); &rendererCore->texture.clut);
rendererCore->texture.updateClutBuffer(texBuffers->clut);
} }
} }
packet2_utils_vu_close_unpack(objectDataPacket); packet2_utils_vu_close_unpack(objectDataPacket);
@@ -37,6 +37,7 @@ BlockizerProgramsManager::~BlockizerProgramsManager() {
} }
void BlockizerProgramsManager::init(RendererCore* core) { void BlockizerProgramsManager::init(RendererCore* core) {
rendererCore = core;
culler.init(core, &singleTexBlockData); culler.init(core, &singleTexBlockData);
clipper.init(core, &singleTexBlockData, &multiTexBlockData); clipper.init(core, &singleTexBlockData, &multiTexBlockData);
} }
@@ -46,7 +47,7 @@ void BlockizerProgramsManager::setProgramsCache() {
programs[0] = repo.getProgram(McpipProgramName::McPipCull); programs[0] = repo.getProgram(McpipProgramName::McPipCull);
programs[1] = repo.getProgram(McpipProgramName::McPipAsIs); programs[1] = repo.getProgram(McpipProgramName::McPipAsIs);
programsPacket = programsPacket =
renderer->core.getPath1()->createProgramsCache(programs, 2, 0); rendererCore->getPath1()->createProgramsCache(programs, 2, 0);
delete[] programs; delete[] programs;
} }
@@ -139,10 +139,10 @@ void StaPipQBufferRenderer::sendObjectData(
packet2_utils_gs_add_lod(objectDataPacket, &rendererCore->gs.lod); packet2_utils_gs_add_lod(objectDataPacket, &rendererCore->gs.lod);
if (texBuffers != nullptr) { if (texBuffers != nullptr) {
rendererCore->texture.updateClutBuffer(texBuffers->clut);
packet2_utils_gs_add_texbuff_clut(objectDataPacket, texBuffers->core, packet2_utils_gs_add_texbuff_clut(objectDataPacket, texBuffers->core,
&rendererCore->texture.clut); &rendererCore->texture.clut);
rendererCore->texture.updateClutBuffer(texBuffers->clut);
} }
} }
packet2_utils_vu_close_unpack(objectDataPacket); 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
+60 -2
View File
@@ -10,12 +10,70 @@
#include "renderer/core/paths/path1/path1.hpp" #include "renderer/core/paths/path1/path1.hpp"
extern u32 VU1DrawFinish_CodeStart __attribute__((section(".vudata")));
extern u32 VU1DrawFinish_CodeEnd __attribute__((section(".vudata")));
namespace Tyra { namespace Tyra {
Path1::Path1() { Path1::Path1() {
doubleBufferPacket = packet2_create(2, P2_TYPE_NORMAL, P2_MODE_CHAIN, true); 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) { u32 Path1::uploadProgram(VU1Program* program, const u32& address) {
// TYRA_LOG("Uploading VU1 program. Size: ", program->getProgramSize(), // 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 auto packetSize = program->getPacketSize() + 1; // + end tag
packet2_t* packet2 = 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(), packet2_vif_add_micro_program(packet2, address, program->getStart(),
program->getEnd()); program->getEnd());
@@ -36,7 +36,7 @@ void Path3::init(RendererSettings* t_settings) {
TYRA_LOG("Path3 initialized"); TYRA_LOG("Path3 initialized");
} }
void Path3::addDrawFinishTag() { void Path3::sendDrawFinishTag() {
dma_channel_wait(DMA_CHANNEL_GIF, 0); dma_channel_wait(DMA_CHANNEL_GIF, 0);
dma_channel_send_packet2(drawFinishPacket, DMA_CHANNEL_GIF, true); dma_channel_send_packet2(drawFinishPacket, DMA_CHANNEL_GIF, true);
} }
+1 -1
View File
@@ -22,7 +22,7 @@ void RendererCore::init() {
path3.init(&settings); path3.init(&settings);
renderer3D.init(&settings, &path1); renderer3D.init(&settings, &path1);
renderer2D.init(&settings, &texture.clut); renderer2D.init(&settings, &texture.clut);
sync.init(&path3); sync.init(&path3, &path1);
} }
void RendererCore::setClearScreenColor(const Color& color) { bgColor = color; } void RendererCore::setClearScreenColor(const Color& color) { bgColor = color; }
@@ -15,15 +15,30 @@ namespace Tyra {
RendererCoreSync::RendererCoreSync() {} RendererCoreSync::RendererCoreSync() {}
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(); clear();
add(); sendPath1Req();
waitAndClear(); 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; } 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) { void RendererCoreTexture::updateClutBuffer(texbuffer_t* clutBuffer) {
if (clutBuffer == nullptr) { if (clutBuffer == nullptr || clutBuffer->width == 0) {
clut.psm = 0; clut.psm = 0;
clut.load_method = CLUT_NO_LOAD; clut.load_method = CLUT_NO_LOAD;
clut.address = 0; clut.address = 0;
@@ -44,14 +44,22 @@ RendererCoreTextureBuffers RendererCoreTexture::useTexture(Texture* t_tex) {
auto allocated = getAllocatedBuffersByTextureId(t_tex->getId()); auto allocated = getAllocatedBuffersByTextureId(t_tex->getId());
if (allocated.id != 0) return allocated; if (allocated.id != 0) return allocated;
while ((t_tex->getSizeInMB()) > sender.getFreeVRamInMB()) { // 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 = // auto idToDealloc =
// cacheManager.getTextureIdToDealloc(currentAllocations); // cacheManager.getTextureIdToDealloc(currentAllocations);
auto idToDealloc = currentAllocations.back().id; // auto buffToDealloc = getAllocatedBuffersByTextureId(idToDealloc);
auto buffToDealloc = getAllocatedBuffersByTextureId(idToDealloc); // TYRA_LOG("Deallocate(", buffToDealloc.id, ")");
sender.deallocate(buffToDealloc); // sender.deallocate(buffToDealloc);
unregisterAllocation(idToDealloc); // unregisterAllocation(idToDealloc);
} // }
auto newTexBuffer = sender.allocate(t_tex); auto newTexBuffer = sender.allocate(t_tex);
path3->sendTexture(t_tex, newTexBuffer); path3->sendTexture(t_tex, newTexBuffer);
+17 -17
View File
@@ -92,7 +92,7 @@ void Tutorial01 ::init() {
dynpip.setRenderer(&engine->renderer.core); dynpip.setRenderer(&engine->renderer.core);
stapip.setRenderer(&engine->renderer.core); stapip.setRenderer(&engine->renderer.core);
picturesCount = 1; picturesCount = 3;
pictures = new Sprite*[picturesCount]; pictures = new Sprite*[picturesCount];
for (u32 i = 0; i < picturesCount; i++) for (u32 i = 0; i < picturesCount; i++)
pictures[i] = get2DPicture(&engine->renderer); pictures[i] = get2DPicture(&engine->renderer);
@@ -159,23 +159,23 @@ void Tutorial01 ::loop() {
for (u32 i = 0; i < picturesCount; i++) for (u32 i = 0; i < picturesCount; i++)
engine->renderer.renderer2D.render(pictures[i]); engine->renderer.renderer2D.render(pictures[i]);
// engine->renderer.renderer3D.usePipeline(&stapip); engine->renderer.renderer3D.usePipeline(&stapip);
// { {
// stapip.render(staticMesh, staOptions); stapip.render(staticMesh, staOptions);
// stapip.render(skybox, skyboxOptions); stapip.render(skybox, skyboxOptions);
// } }
// engine->renderer.renderer3D.usePipeline(&dynpip); engine->renderer.renderer3D.usePipeline(&dynpip);
// { {
// dynpip.render(cube); dynpip.render(cube);
// Threading::switchThread(); Threading::switchThread();
// for (u8 i = 0; i < warriorsCount; i++) { for (u8 i = 0; i < warriorsCount; i++) {
// dynpip.render(warriors[i], dynOptions); dynpip.render(warriors[i], dynOptions);
// if (i == 5) Threading::switchThread(); if (i == 5) Threading::switchThread();
// if (i == 10) Threading::switchThread(); if (i == 10) Threading::switchThread();
// if (i == 15) Threading::switchThread(); if (i == 15) Threading::switchThread();
// } }
// } }
engine->renderer.renderer3D.usePipeline(&mcPip); engine->renderer.renderer3D.usePipeline(&mcPip);
{ mcPip.render(blocks, blocksCount, blocksTex2, true); } { mcPip.render(blocks, blocksCount, blocksTex2, true); }