Textures are fetched! Dynamic exchange is real!

This commit is contained in:
jndean
2023-10-26 14:16:13 +00:00
parent 4746082583
commit fb9e404485
5 changed files with 61 additions and 26 deletions

View File

@@ -3,6 +3,7 @@
#include <poplar/Vertex.hpp>
#include "doomtype.h"
#include "r_data.h"
#include "ipu_interface.h"
#include "ipu_utils.h"
@@ -18,6 +19,7 @@ const int* tileLocalTextureRange;
const int* tileLocalTextureOffsets;
// -------- Components for the tiles that serve textures ------------ //
extern "C"
@@ -75,17 +77,26 @@ void IPU_R_FulfilColumnRequest(unsigned* progBuf, unsigned char* textureBuf, uns
auto recvProgram = &progBuf[progBuf[0]];
auto sendProgram = &progBuf[progBuf[1]];
auto aggrProgram = &progBuf[progBuf[2]];
// for(; textureFetchCount < tmpRepeatCount; textureFetchCount++) {
while (1) {
XCOM_Execute(recvProgram, NULL, textureBuf);
// Unpack received data
unsigned textureNum = ((IPUColRequest_t*) textureBuf)->texture;
unsigned colNum = ((IPUColRequest_t*) textureBuf)->column;
unsigned columnOffset = ((IPUColRequest_t*) textureBuf)->columnOffset;
byte c1 = (textureNum * 9) % 256;
byte* col = textureBuf;
if (textureNum != 0xffffffff &&
textureNum >= tileLocalTextureRange[0] &&
textureNum < tileLocalTextureRange[1]) {
col = &textureBuf[tileLocalTextureOffsets[textureNum] + columnOffset];
// if (firstPrint && tileID >= 32 && tileID < 36) printf("Accepted texture %d\n", (int)textureNum);
} else {
// if (firstPrint && tileID >= 32 && tileID < 36) printf("Rejected texture %d\n", (int)textureNum);
}
byte c1 = (17 * 9) % 256;
byte c2 = (c1 + 1) % 256;
byte c3 = (c1 + 2) % 256;
byte c4 = (c1 + 1) % 256;
@@ -93,10 +104,9 @@ void IPU_R_FulfilColumnRequest(unsigned* progBuf, unsigned char* textureBuf, uns
for (int i = 0; i < IPUTEXTURECACHELINESIZE; i++) {
((unsigned*)textureBuf)[i] = colour;
}
XCOM_Execute(sendProgram, textureBuf, NULL);
XCOM_Execute(sendProgram, col, NULL);
XCOM_Execute(aggrProgram, NULL, commsBuf);
// if (tileID == 35) printf ("Texture flag: %d\n", commsBuf[0]);
if (commsBuf[0])
return;
}
@@ -190,7 +200,7 @@ byte* IPU_R_RequestColumn(int texture, int column) {
// Populate buffer with data to be exchanged
IPUColRequest_t *request = (IPUColRequest_t*) tileLocalTextureBuf;
request->texture = texture;
request->column = column;
request->columnOffset = (column & texturewidthmask[texture]) * (textureheight[texture] >> FRACBITS);
*((unsigned*) &request[1]) = 0; // The Done Flag
XCOM_Execute(
@@ -204,7 +214,14 @@ byte* IPU_R_RequestColumn(int texture, int column) {
tileLocalCommsBuf[0] = 0;
}
int textureSourceTile = 0;
int textureSourceTile;
for (textureSourceTile = 0; textureSourceTile < IPUTEXTURETILESPERRENDERTILE; ++textureSourceTile) {
if (texture >= tileLocalTextureRange[textureSourceTile] &&
texture < tileLocalTextureRange[textureSourceTile + 1]) {
break;
}
}
XCOM_PatchMuxAndExecute(
receiveProg, // Prog
NULL, // Read offset
@@ -234,7 +251,7 @@ void IPU_R_RenderTileDone() {
// Populate buffer with data to be exchanged
IPUColRequest_t *request = (IPUColRequest_t*) tileLocalTextureBuf;
request->texture = 0xffffffff;
request->column = 0xffffffff;
request->columnOffset = 0xffffffff;
*((unsigned*) &request[1]) = 1; // The `done` Flag
XCOM_Execute(

View File

@@ -12,7 +12,7 @@ extern "C" {
typedef struct {
int texture, column;
unsigned texture, columnOffset;
} IPUColRequest_t;
@@ -23,6 +23,7 @@ extern const int* tileLocalTextureRange;
extern const int* tileLocalTextureOffsets;
__SUPER__ void IPU_R_InitTextureTile(unsigned* progBuf, int progBufSize);
__SUPER__ void IPU_R_InitColumnRequester(unsigned* progBuf, int progBufSize);

View File

@@ -65,7 +65,7 @@ struct
poplar::constraint("region(*nonExecutableDummy) != region(*progBuf)"),
poplar::constraint("elem(*textureCache) != elem(*progBuf)"),
poplar::constraint("elem(*textureCache) != elem(*commsBuf)"),
poplar::constraint("elem(*progBuf) != elem(*commsBuf)"),
poplar::constraint("elem(*progBuf) != elem(*commsBuf)"),
]]
R_RenderPlayerView_Vertex : public poplar::SupervisorVertex {
poplar::Input<poplar::Vector<unsigned char>> miscValues;
@@ -75,12 +75,14 @@ R_RenderPlayerView_Vertex : public poplar::SupervisorVertex {
poplar::InOut<poplar::Vector<unsigned>> progBuf;
poplar::InOut<poplar::Vector<unsigned>> commsBuf;
poplar::InOut<poplar::Vector<unsigned>> textureCache;
poplar::Input<poplar::Vector<int>> textureRange;
__SUPER__ void compute() {
assert(&frame[0] == I_VideoBuffer);
tileLocalProgBuf = &progBuf[0];
tileLocalCommsBuf = &commsBuf[0];
tileLocalTextureBuf = &textureCache[0];
tileLocalTextureRange = &textureRange[0];
IPU_R_RenderPlayerView_UnpackMiscValues(
(R_RenderPlayerView_MiscValues_t*) &miscValues[0]
@@ -113,13 +115,13 @@ R_FulfilColumnRequests_Vertex : public poplar::SupervisorVertex {
poplar::InOut<poplar::Vector<unsigned>> progBuf;
poplar::InOut<poplar::Vector<unsigned>> commsBuf;
poplar::Output<poplar::Vector<unsigned char>> textureBuf;
// poplar::Input<poplar::Vector<int>> textureOffsets;
// poplar::Input<poplar::Vector<int>> textureRange;
poplar::Input<poplar::Vector<int>> textureOffsets;
poplar::Input<poplar::Vector<int>> textureRange;
__SUPER__ void compute() {
// tileLocalTextureRange = &textureRange[0];
// tileLocalTextureOffsets = &textureOffsets[0];
tileLocalTextureRange = &textureRange[0];
tileLocalTextureOffsets = &textureOffsets[0];
IPU_R_FulfilColumnRequest(&progBuf[0], &textureBuf[0], &commsBuf[0]);
}
};

View File

@@ -21,8 +21,14 @@
#define __R_DATA__
#include "doomtype.h"
#include "m_fixed.h"
#include "ipu_utils.h"
extern int* texturewidthmask;
extern fixed_t* textureheight;
// Retrieve column data for span blitting.
__SUPER__ byte *R_GetColumn(int tex, int col);

View File

@@ -167,6 +167,13 @@ void IpuDoom::buildIpuGraph() {
"textureBuf-stream",
poplar::UNSIGNED_CHAR,
IPUTEXTURETILESPERRENDERTILE * IPUTEXTURETILEBUFSIZE);
poplar::Tensor textureOffsets = m_ipuGraph.addVariable(poplar::INT, {IPUMAXNUMTEXTURES}, "textureOffsets");
poplar::Tensor textureRanges = m_ipuGraph.addVariable(poplar::INT, {IPUTEXTURETILESPERRENDERTILE + 1}, "textureRanges");
auto textureOffsetStream = m_ipuGraph.addHostToDeviceFIFO("textureOffsets-stream", poplar::INT, IPUMAXNUMTEXTURES);
auto textureRangeStream = m_ipuGraph.addHostToDeviceFIFO("textureRanges-stream", poplar::INT, IPUTEXTURETILESPERRENDERTILE + 1);
m_ipuGraph.setTileMapping(textureOffsets, IPUFIRSTTEXTURETILE);
m_ipuGraph.setTileMapping(textureRanges, IPUFIRSTRENDERTILE);
poplar::ComputeSet R_Init_CS = m_ipuGraph.addComputeSet("R_Init_CS");
for (int renderTile = 0; renderTile < IPUNUMRENDERTILES; ++renderTile) {
@@ -206,12 +213,20 @@ void IpuDoom::buildIpuGraph() {
poplar::program::Sequence R_Init_prog({
poplar::program::Copy(miscValuesStream, m_miscValuesBuf),
poplar::program::Copy(textureBufStream, textureBuf.slice(0, IPUTEXTURETILESPERRENDERTILE)),
poplar::program::Copy(textureOffsetStream, textureOffsets),
poplar::program::Copy(textureRangeStream, textureRanges),
poplar::program::Execute(R_InitTextureAndSans_CS),
poplar::program::Repeat(2, poplar::program::Sequence({ // <- number of R_Init_CS steps
poplar::program::Execute(R_Init_CS),
poplar::program::Call(requestLumpFromHost, {m_lumpNum[0]}, {lumpBuf}),
})),
});
for (int i = IPUTEXTURETILESPERRENDERTILE; i < IPUNUMTEXTURETILES; i += IPUTEXTURETILESPERRENDERTILE) {
R_Init_prog.add(poplar::program::Copy(
textureBuf.slice(0, IPUTEXTURETILESPERRENDERTILE),
textureBuf.slice(i, i + IPUTEXTURETILESPERRENDERTILE)
));
}
// ---------------- G_Ticker --------------//
@@ -297,19 +312,13 @@ void IpuDoom::buildIpuGraph() {
IPUNUMTEXTURECACHELINES * IPUTEXTURECACHELINESIZE},
"textureCache");
poplar::Tensor textureOffsets = m_ipuGraph.addVariable(poplar::INT, {IPUMAXNUMTEXTURES}, "textureOffsets");
poplar::Tensor textureRanges = m_ipuGraph.addVariable(poplar::INT, {IPUTEXTURETILESPERRENDERTILE + 1}, "textureRanges");
auto textureOffsetStream = m_ipuGraph.addHostToDeviceFIFO("textureOffsets-stream", poplar::INT, IPUMAXNUMTEXTURES);
auto textureRangeStream = m_ipuGraph.addHostToDeviceFIFO("textureRanges-stream", poplar::INT, IPUTEXTURETILESPERRENDERTILE + 1);
m_ipuGraph.setTileMapping(textureOffsets, IPUFIRSTTEXTURETILE);
m_ipuGraph.setTileMapping(textureRanges, IPUFIRSTTEXTURETILE);
poplar::ComputeSet R_RenderPlayerView_CS = m_ipuGraph.addComputeSet("R_RenderPlayerView_CS");
for (int renderTile = 0; renderTile < IPUNUMRENDERTILES; ++renderTile) {
int logicalTile = IPUFIRSTRENDERTILE + renderTile;
vtx = m_ipuGraph.addVertex(R_RenderPlayerView_CS, "R_RenderPlayerView_Vertex", {
{"frame", ipuFrameSlices[renderTile]},
{"textureCache", textureCache[renderTile]},
{"textureRange", textureRanges},
{"progBuf", progBuf[logicalTile]},
{"commsBuf", commsBuf[logicalTile]},
{"nonExecutableDummy", nonExecutableDummy[logicalTile]},
@@ -321,14 +330,14 @@ void IpuDoom::buildIpuGraph() {
}
for (int textureTile = 0; textureTile < IPUNUMTEXTURETILES; ++textureTile) {
int logicalTile = IPUFIRSTTEXTURETILE + textureTile;
// int textureStripeIdx = textureTile % IPUTEXTURETILESPERRENDERTILE;
int textureStripeIdx = textureTile % IPUTEXTURETILESPERRENDERTILE;
vtx = m_ipuGraph.addVertex(R_RenderPlayerView_CS, "R_FulfilColumnRequests_Vertex", {
{"dummy", nonExecutableDummy[logicalTile]},
{"progBuf", progBuf[logicalTile]},
{"commsBuf", commsBuf[logicalTile]},
{"textureBuf", textureBuf[textureTile]},
// {"textureOffsets", textureOffsets},
// {"textureRange", textureRanges.slice(textureStripeIdx, textureStripeIdx + 2)},
{"textureOffsets", textureOffsets},
{"textureRange", textureRanges.slice(textureStripeIdx, textureStripeIdx + 2)},
});
m_ipuGraph.setTileMapping(vtx, logicalTile);
m_ipuGraph.setPerfEstimate(vtx, 1000);