dynpip files

This commit is contained in:
h4570
2022-07-18 22:42:14 +02:00
parent 95c01afa01
commit a5e1a28164
38 changed files with 481 additions and 182 deletions
@@ -0,0 +1,37 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "renderer/3d/pipeline/dynamic/dynpip_programs_repository.hpp"
namespace Tyra {
DynPipProgramsRepository::DynPipProgramsRepository() {}
DynPipProgramsRepository::~DynPipProgramsRepository() {}
DynPipVU1Program* DynPipProgramsRepository::getProgram(
const DynPipProgramName& name) {
switch (name) {
case DynPipProgramName::DynPipColor:
return &color;
case DynPipProgramName::DynPipDirLights:
return &dirLights;
case DynPipProgramName::DynPipTextureDirLights:
return &textureDirLights;
case DynPipProgramName::DynPipTextureColor:
return &textureColor;
default:
TYRA_TRAP("Unknown VU1 program name");
return &color;
}
}
} // namespace Tyra
@@ -0,0 +1,21 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "renderer/3d/pipeline/dynamic/dynpip_qbuffer.hpp"
#include <sstream>
#include <iomanip>
namespace Tyra {
DynPipQBuffer::DynPipQBuffer() {}
DynPipQBuffer::~DynPipQBuffer() {}
} // namespace Tyra
@@ -0,0 +1,86 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "renderer/3d/pipeline/dynamic/dynpip_vu1_program.hpp"
namespace Tyra {
DynPipVU1Program::DynPipVU1Program(const DynPipProgramName& t_name,
u32* t_start, u32* t_end,
const u32& t_reglist,
const u8& t_reglistCount,
const u8& t_elementsPerVertex)
: VU1Program(t_start, t_end),
name(t_name),
reglistCount(t_reglistCount),
elementsPerVertex(t_elementsPerVertex),
reglist(t_reglist) {
packetSize = packet2_utils_get_packet_size_for_program(start, end);
programSize = calculateProgramSize();
}
DynPipVU1Program::~DynPipVU1Program() {}
const DynPipProgramName& DynPipVU1Program::getName() const { return name; }
u32& DynPipVU1Program::getReglist() { return reglist; }
void DynPipVU1Program::addBufferDataToPacket(packet2_t* packet,
DynPipQBuffer* buffer,
prim_t* prim) {
addStandardBufferDataToPacket(packet, buffer, prim);
addProgramQBufferDataToPacket(packet, buffer);
}
void DynPipVU1Program::addStandardBufferDataToPacket(packet2_t* packet,
DynPipQBuffer* buffer,
prim_t* prim) {
// if (buffer->bag->texture)
// prim->mapping = 1;
// else
// prim->mapping = 0;
// packet2_utils_vu_open_unpack(packet, 0, true);
// {
// packet2_add_float(packet, 2048.0F); // scale
// packet2_add_float(packet, 2048.0F); // scale
// packet2_add_float(packet,
// static_cast<float>(0xFFFFFF) / 32.0F); // scale
// packet2_add_u32(packet, buffer->size); // vertex count
// packet2_utils_gs_add_prim_giftag(packet, prim, buffer->size, reglist,
// reglistCount, 0);
// }
// packet2_utils_vu_close_unpack(packet);
}
u16 DynPipVU1Program::getMaxVertCount(const bool& singleColorEnabled,
const u16& bufferSize) const {
return 0; // TODO
// u16 res = bufferSize - 4;
// u8 colorElementsPerVertex =
// singleColorEnabled ? (elementsPerVertex - 1) : elementsPerVertex;
// res /= (colorElementsPerVertex + reglistCount);
// // Buffer size = VU1 double buffer size (xtop)
// // res = qbuffer size (directly inside VU1)
// // Must be dividable by 3 and the result also dividable by 3. Why?
// // 1st dividable reason - triangle, and packaging system in 3d rendering
// // 2nd dividable reason - subpackaging system. We are splitting packages
// into
// // 3 subpackages in 3d renderer.
// res = res / 3 / 3;
// res = res * 3 * 3;
// return res;
}
} // namespace Tyra
@@ -21,7 +21,7 @@
.init_vf_all
.init_vi_all
#include "src/renderer/core/paths/path1/programs/vcl_sml.i"
#include "src/renderer/3d/pipeline/shared_macros/vcl_sml.i"
#include "inc/renderer/3d/pipeline/minecraft/programs/as_is/mcpip_vu1_as_is_shared_defines.h"
#include "src/renderer/3d/pipeline/minecraft/programs/as_is/macros.i"
@@ -57,15 +57,15 @@ void McpipClip::initStaticPacket() {
void McpipClip::addData(McpipBlock* block, const bool& isMulti,
RendererCoreTextureBuffers* texBuffers,
packet2_t* packet, const u8& context) {
std::vector<Path1ClipVertex> clippedVertices;
std::vector<EEClipVertex> clippedVertices;
auto mvp = rendererCore->renderer3D.getViewProj() * block->model;
const auto* blockData = isMulti ? multiBlockData : singleBlockData;
for (u32 i = 0; i < blockData->count / 3; i++) {
for (u8 j = 0; j < 3; j++) {
Path1ClipVertex vert = {mvp * blockData->vertices[i * 3 + j], Vec4(),
blockData->textureCoords[i * 3 + j], Vec4()};
EEClipVertex vert = {mvp * blockData->vertices[i * 3 + j], Vec4(),
blockData->textureCoords[i * 3 + j], Vec4()};
inputTriangle.push_back(vert);
}
@@ -93,7 +93,7 @@ void McpipClip::addData(McpipBlock* block, const bool& isMulti,
addDataToPacket(packet, context, block, clippedVertices.size(), texBuffers);
}
void McpipClip::addCorrections(std::vector<Path1ClipVertex>* vertices,
void McpipClip::addCorrections(std::vector<EEClipVertex>* vertices,
McpipBlock* block) {
for (u32 i = 0; i < vertices->size(); i++) {
(*vertices)[i].position /= (*vertices)[i].position.w; // Perspective divide
@@ -101,7 +101,7 @@ void McpipClip::addCorrections(std::vector<Path1ClipVertex>* vertices,
}
}
void McpipClip::moveDataToBuffer(std::vector<Path1ClipVertex>* vertices,
void McpipClip::moveDataToBuffer(std::vector<EEClipVertex>* vertices,
const u8& context) {
for (u32 i = 0; i < vertices->size(); i++) {
vertexBuffers[context][i].set(vertices->at(i).position);
@@ -21,7 +21,7 @@
.init_vf_all
.init_vi_all
#include "src/renderer/core/paths/path1/programs/vcl_sml.i"
#include "src/renderer/3d/pipeline/shared_macros/vcl_sml.i"
#include "inc/renderer/3d/pipeline/minecraft/programs/cull/mcpip_vu1_cull_shared_defines.h"
#include "src/renderer/3d/pipeline/minecraft/programs/cull/macros.i"
@@ -0,0 +1,99 @@
;//--------------------------------------------------------------------------------
;// Tyra's standard macros library
;//--------------------------------------------------------------------------------
;//---------------------------------------------------------
;// LoadTyraStaticData - Load "Set" gif tag
;//---------------------------------------------------------
#macro LoadTyraStaticData: t_gifSetTagName
lq t_gifSetTagName, VU1_SET_GIFTAG_ADDR(vi00)
#endmacro
;//---------------------------------------------------------
;// LoadTyraLightMatrix - Loads single color. Color is placed in 4th slot of Lights matrix
;//---------------------------------------------------------
#macro LoadTyraSingleColor: t_singleColor, t_singleColorEnabled, t_singleColorAddr, t_optionsAddr
lq t_singleColor, t_singleColorAddr(vi00)
ilw.x t_singleColorEnabled, t_optionsAddr(vi00)
#endmacro
;//---------------------------------------------------------
;// LoadTyraTags - Load lod, texture buffer and clut
;// 1 - GIF tag - texture LOD
;// 2 - GIF tag - texture buffer & CLUT
;//---------------------------------------------------------
#macro LoadTyraTags: t_lodGifTag, t_texBufferClutGifTag, t_lodAddr, t_ClutAddr
lq t_lodGifTag, t_lodAddr(vi00)
lq t_texBufferClutGifTag, t_ClutAddr(vi00)
#endmacro
;//---------------------------------------------------------
;// LoadTyraBufferTags - Load scales and prim tag
;// 1 - float : X, Y, Z - scale vector that we will use to scale the verts after projecting them, float : W - vert count.
;// 2 - GIF tag - tell GS how many data we will send
;//---------------------------------------------------------
#macro LoadTyraBufferTags: t_scale, t_primTag, t_buffer
lq.xyz t_scale, 0(t_buffer)
lq t_primTag, 1(t_buffer)
#endmacro
;//---------------------------------------------------------
;// LoadTyraDirectionalLights - Load directions and colors. All are always present
;// - 3 directional lights directions
;// - 3 directional lights colors + ambient color
;//---------------------------------------------------------
#macro LoadTyraDirectionalLights: t_lightMatrix, t_lightDirections, t_lightsColors, t_ambientColor, t_dirOffset, t_colorOffset, t_matrixOffset
lq.xyz t_lightMatrix[0], t_matrixOffset+0(vi00)
lq.xyz t_lightMatrix[1], t_matrixOffset+1(vi00)
lq.xyz t_lightMatrix[2], t_matrixOffset+2(vi00)
lq.xyz t_lightDirections[0], t_dirOffset(vi00)
lq.xyz t_lightDirections[1], t_dirOffset+1(vi00)
lq.xyz t_lightDirections[2], t_dirOffset+2(vi00)
lq.xyz t_lightsColors[0], t_colorOffset(vi00)
lq.xyz t_lightsColors[1], t_colorOffset+1(vi00)
lq.xyz t_lightsColors[2], t_colorOffset+2(vi00)
lq.xyz t_ambientColor, t_colorOffset+3(vi00)
#endmacro
;//---------------------------------------------------------
;// StoreTyraGifTags - Store gif tags.
;// Not using sqi instruction, because VCL cannot optimize it.
;// Primtag contains information about how many polys we will send
;//---------------------------------------------------------
#macro StoreTyraGifTags: t_gifSetTag, t_lodGifTag, t_texBufferClutGifTag, t_primTag, t_destAddress
sq t_gifSetTag, 0(t_destAddress)
sq t_lodGifTag, 1(t_destAddress)
sq t_gifSetTag, 2(t_destAddress)
sq t_texBufferClutGifTag, 3(t_destAddress)
sq t_primTag, 4(t_destAddress)
iaddiu t_destAddress, t_destAddress, 5
#endmacro
;//---------------------------------------------------------
;// CalculateLights - Based on Dr Fortuna's work
;//
;// 1. Transform by the rotation part of the world matrix
;// 2. "Transform" the normal by the light direction matrix
;// 3. Four intensities, one for each light.
;// 4. Clamp the intensity to 0..1
;// 5. Transform the intensities by the light colour matrix
;// 6. Load 128 and put it into the alpha value
;// 7. Clamp result to 0-128 values
;// 8. And write to the output buffer
;//---------------------------------------------------------
#macro CalculateTyraDirectionalLights: t_outputColor, t_normal, t_lightDirections, t_lightColors, t_lightMatrix, t_ambientColor
mul.xyz acc, t_lightMatrix[0], t_normal[x]
madd.xyz acc, t_lightMatrix[1], t_normal[y]
madd.xyz t_normal, t_lightMatrix[2], t_normal[z]
mula.xyz acc, t_lightDirections[0], t_normal[x]
madd.xyz acc, t_lightDirections[1], t_normal[y]
madd.xyz t_outputColor, t_lightDirections[2], t_normal[z]
mini.xyz t_outputColor, t_outputColor, vf00[w]
max.xyz t_outputColor, t_outputColor, vf00[x]
mula.xyz acc, t_lightColors[0], t_outputColor[x]
madda.xyz acc, t_lightColors[1], t_outputColor[y]
madda.xyz acc, t_lightColors[2], t_outputColor[z]
madd.xyz t_outputColor, t_ambientColor, vf00[w]
loi 128
addi.w t_outputColor, vf00, i
#endmacro
File diff suppressed because it is too large Load Diff
@@ -18,8 +18,8 @@
.init_vf_all
.init_vi_all
#include "src/renderer/core/paths/path1/programs/vcl_sml.i"
#include "src/renderer/core/paths/path1/programs/tyra_macros.i"
#include "src/renderer/3d/pipeline/shared_macros/vcl_sml.i"
#include "src/renderer/3d/pipeline/shared_macros/tyra_macros.i"
#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h"
#define RGBA_STORE_OFFSET 0
@@ -18,8 +18,8 @@
.init_vf_all
.init_vi_all
#include "src/renderer/core/paths/path1/programs/vcl_sml.i"
#include "src/renderer/core/paths/path1/programs/tyra_macros.i"
#include "src/renderer/3d/pipeline/shared_macros/vcl_sml.i"
#include "src/renderer/3d/pipeline/shared_macros/tyra_macros.i"
#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h"
#define RGBA_STORE_OFFSET 0
@@ -18,8 +18,8 @@
.init_vf_all
.init_vi_all
#include "src/renderer/core/paths/path1/programs/vcl_sml.i"
#include "src/renderer/core/paths/path1/programs/tyra_macros.i"
#include "src/renderer/3d/pipeline/shared_macros/vcl_sml.i"
#include "src/renderer/3d/pipeline/shared_macros/tyra_macros.i"
#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h"
#define STQ_STORE_OFFSET 0
@@ -18,8 +18,8 @@
.init_vf_all
.init_vi_all
#include "src/renderer/core/paths/path1/programs/vcl_sml.i"
#include "src/renderer/core/paths/path1/programs/tyra_macros.i"
#include "src/renderer/3d/pipeline/shared_macros/vcl_sml.i"
#include "src/renderer/3d/pipeline/shared_macros/tyra_macros.i"
#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h"
#define STQ_STORE_OFFSET 0
@@ -18,8 +18,8 @@
.init_vf_all
.init_vi_all
#include "src/renderer/core/paths/path1/programs/vcl_sml.i"
#include "src/renderer/core/paths/path1/programs/tyra_macros.i"
#include "src/renderer/3d/pipeline/shared_macros/vcl_sml.i"
#include "src/renderer/3d/pipeline/shared_macros/tyra_macros.i"
#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h"
#define RGBA_STORE_OFFSET 0
@@ -18,8 +18,8 @@
.init_vf_all
.init_vi_all
#include "src/renderer/core/paths/path1/programs/vcl_sml.i"
#include "src/renderer/core/paths/path1/programs/tyra_macros.i"
#include "src/renderer/3d/pipeline/shared_macros/vcl_sml.i"
#include "src/renderer/3d/pipeline/shared_macros/tyra_macros.i"
#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h"
#define RGBA_STORE_OFFSET 0
@@ -18,8 +18,8 @@
.init_vf_all
.init_vi_all
#include "src/renderer/core/paths/path1/programs/vcl_sml.i"
#include "src/renderer/core/paths/path1/programs/tyra_macros.i"
#include "src/renderer/3d/pipeline/shared_macros/vcl_sml.i"
#include "src/renderer/3d/pipeline/shared_macros/tyra_macros.i"
#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h"
#define STQ_STORE_OFFSET 0
@@ -18,8 +18,8 @@
.init_vf_all
.init_vi_all
#include "src/renderer/core/paths/path1/programs/vcl_sml.i"
#include "src/renderer/core/paths/path1/programs/tyra_macros.i"
#include "src/renderer/3d/pipeline/shared_macros/vcl_sml.i"
#include "src/renderer/3d/pipeline/shared_macros/tyra_macros.i"
#include "inc/renderer/3d/pipeline/static/core/programs/stapip_vu1_shared_defines.h"
#define STQ_STORE_OFFSET 0
@@ -27,16 +27,16 @@ void StaPipClipper::clip(StaPipQBuffer* buffer) {
TYRA_ASSERT(buffer->size <= maxVertCount / 3, "Buffer should have max ",
maxVertCount / 3, " verts if we want to clip it.");
Path1EEClipAlgorithmSettings algoSettings = {
buffer->bag->lighting != nullptr, buffer->bag->texture != nullptr,
buffer->bag->color->many != nullptr};
EEClipAlgorithmSettings algoSettings = {buffer->bag->lighting != nullptr,
buffer->bag->texture != nullptr,
buffer->bag->color->many != nullptr};
std::vector<Path1ClipVertex> clippedVertices;
std::vector<EEClipVertex> clippedVertices;
for (u32 i = 0; i < buffer->size / 3; i++) {
std::vector<Path1ClipVertex> inputTriangle;
std::vector<EEClipVertex> inputTriangle;
for (u8 j = 0; j < 3; j++) {
Path1ClipVertex vert = {
EEClipVertex vert = {
*mvp * buffer->vertices[i * 3 + j],
buffer->bag->lighting ? buffer->normals[i * 3 + j] : Vec4(),
buffer->bag->texture ? buffer->sts[i * 3 + j] : Vec4(),
@@ -45,7 +45,7 @@ void StaPipClipper::clip(StaPipQBuffer* buffer) {
inputTriangle.push_back(vert);
}
std::vector<Path1ClipVertex> clippedTriangle;
std::vector<EEClipVertex> clippedTriangle;
algorithm.clip(&clippedTriangle, inputTriangle, algoSettings);
if (clippedTriangle.size() == 0) continue;
@@ -64,14 +64,14 @@ void StaPipClipper::clip(StaPipQBuffer* buffer) {
moveDataToBuffer(clippedVertices, buffer);
}
void StaPipClipper::perspectiveDivide(std::vector<Path1ClipVertex>* vertices) {
void StaPipClipper::perspectiveDivide(std::vector<EEClipVertex>* vertices) {
for (u32 i = 0; i < vertices->size(); i++) {
(*vertices)[i].position /= (*vertices)[i].position.w;
}
}
void StaPipClipper::moveDataToBuffer(
const std::vector<Path1ClipVertex>& vertices, StaPipQBuffer* buffer) {
void StaPipClipper::moveDataToBuffer(const std::vector<EEClipVertex>& vertices,
StaPipQBuffer* buffer) {
buffer->reallocateManually(vertices.size());
for (u32 i = 0; i < vertices.size(); i++) {
@@ -25,14 +25,14 @@ StaPipVU1Program* StaPipProgramsRepository::getProgram(
return &cullColor;
case StaPipProgramName::StaPipAsIsDirLights:
return &asIsLightingColor;
return &asIsDirLights;
case StaPipProgramName::StaPipCullDirLights:
return &cullLightingColor;
return &cullDirLights;
case StaPipProgramName::StaPipAsIsTextureDirLights:
return &asIsLightingTextureColor;
return &asIsTextureDirLights;
case StaPipProgramName::StaPipCullTextureDirLights:
return &cullLightingTextureColor;
return &cullTextureDirLights;
case StaPipProgramName::StaPipAsIsTextureColor:
return &asIsTextureColor;
@@ -41,7 +41,7 @@ StaPipVU1Program* StaPipProgramsRepository::getProgram(
default:
TYRA_TRAP("Unknown VU1 program name");
return &cullLightingTextureColor;
return &cullTextureDirLights;
}
}
@@ -36,7 +36,7 @@ namespace Tyra {
StaPipQBufferRenderer::StaPipQBufferRenderer() {
context = 0;
lastProgramName = StdipUndefinedProgram;
lastProgramName = StaPipUndefinedProgram;
staticDataPacket = packet2_create(3, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
objectDataPacket = packet2_create(16, P2_TYPE_NORMAL, P2_MODE_CHAIN, true);
programsPacket = nullptr;
@@ -221,7 +221,7 @@ void StaPipQBufferRenderer::clip(StaPipQBuffer* buffer) {
}
void StaPipQBufferRenderer::clearLastProgramName() {
lastProgramName = StdipUndefinedProgram;
lastProgramName = StaPipUndefinedProgram;
}
void StaPipQBufferRenderer::addBufferDataToPacket(StaPipVU1Program* program,