Skip to content

Commit

Permalink
gpu/vram-to-vram-overlap investigate srcX < dstX case
Browse files Browse the repository at this point in the history
  • Loading branch information
JaCzekanski committed Mar 29, 2020
1 parent 047db80 commit 93568c5
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 57 deletions.
2 changes: 1 addition & 1 deletion common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LIBDIRS := -L$(PSN00BSDK)/libpsn00b
GCC_VERSION = 7.4.0
GCC_BASE = /usr/local/mipsel-unknown-elf

CFLAGS ?= -g -msoft-float -O3 -fno-builtin -fdata-sections -ffunction-sections -Wall -Wextra -Wno-strict-aliasing -Wno-sign-compare
CFLAGS ?= -g -msoft-float -O3 -D__PLAYSTATION__ -fno-builtin -fdata-sections -ffunction-sections -Wall -Wextra -Wno-strict-aliasing -Wno-sign-compare
CPPFLAGS ?= $(CFLAGS) -fno-exceptions -std=c++1z
AFLAGS ?= -g -msoft-float
LDFLAGS ?= -g -Ttext=0x80010000 -gc-sections -T $(GCC_BASE)/mipsel-unknown-elf/lib/ldscripts/elf32elmip.x
Expand Down
7 changes: 6 additions & 1 deletion common/gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ void setResolution(int w, int h) {
SetDefDispEnv(&disp, 0, 0, w, h);
SetDefDrawEnv(&draw, 0, 0, 1024, 512);

if (h == 480) {
disp.isinter = true; // Interlace mode
draw.dfe = true; // Drawing to display area (odd and even lines)
}

PutDispEnv(&disp);
PutDrawEnv(&draw);
}
Expand Down Expand Up @@ -89,7 +94,7 @@ void vramPut(int x, int y, uint16_t pixel) {

uint32_t vramGet(int x, int y) {
VRAM2CPU buf = {0};
setcode(&buf, 0xC0); // CPU -> VRAM
setcode(&buf, 0xC0); // VRAM -> CPU
setlen(&buf, 3);

buf.x0 = x; // VRAM position
Expand Down
100 changes: 45 additions & 55 deletions gpu/vram-to-vram-overlap/main.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
#include <common.h>
#include "font.h"

// 24 bit to 15 bit value
constexpr uint16_t rgb(uint8_t r, uint8_t g, uint8_t b) {
uint16_t c = 0;
c |= ((r >> 3) & 0x1f);
c |= ((g >> 3) & 0x1f) << 5;
c |= ((b >> 3) & 0x1f) << 10;
return c;
}

constexpr uint16_t randomColor(int c) {
return rgb(64+(c*432)%192, 64+(c*127)%192, 64+(c*941)%192);
}

// Write sizexsize rect to vram
void writeRect(int dstX, int dstY, int size) {
for (int y = 0; y<size; y++) {
for (int x = 0; x<size; x++) {
vramPut(dstX + x, dstY + y, randomColor(y * 32 + x));
vramPut(dstX + x, dstY + y, y*2 * 32 + x*2);
}
}
}
Expand All @@ -31,53 +18,56 @@ void line(int sx, int sy, int ex, int ey) {
l.x0 = sx;
l.y0 = sy;
l.x1 = ex;
l.y1 = ey;

l.y1 = ey;
DrawPrim(&l);
}

constexpr int SIZES = 6 + 3;
constexpr int sizes[SIZES] = {
2, 8, 15, 16, 31, 32,
32, // x + 1
32, // y + 1
32, // x + 1, y + 1
constexpr int testCases[] = {
2, 8, 15, 16,
16, // x + 1
16, // y + 1
16, // x + 1, y + 1
};
template<class T, size_t N>
constexpr size_t count(T (&)[N]) { return N; }

const int COLS = 10;
const int CELL_SIZE = 48;
constexpr int TEST_W = 3; // Test x from -3 to 3
constexpr int TEST_H = 1; // Test y from -1 to 1
const int COLS = (TEST_W*2 + 1) * (TEST_H*2 + 1);
const int CELL_SIZE = 42;
const int MARGIN = 4;

void drawDebugInfo() {
// Draw grid, vertical lines
for (int size = 0; size < SIZES + 1; size++) {
for (int size = 0; size < count(testCases) + 1; size++) {
line(
0, size * CELL_SIZE,
CELL_SIZE * COLS, size * CELL_SIZE
CELL_SIZE * (COLS+1), size * CELL_SIZE
);
}
// Horizontal
for (int i = 0; i<COLS + 1; i++) {
for (int i = 0; i <= COLS + 1; i++) {
line(
i * CELL_SIZE, 0,
i * CELL_SIZE, SIZES * CELL_SIZE
i * CELL_SIZE, count(testCases) * CELL_SIZE
);
}

// Labels
for (int testCase = 0; testCase < SIZES; testCase++) {
for (int i = 0; i<COLS; i++) {
if (i == 0) {
FntPos(i * CELL_SIZE + 4, testCase * CELL_SIZE + 12);
FntPrintf("BLOCK\n\n %2d\n ", sizes[testCase]);
if (testCase == 6) FntPrintf("x+1");
if (testCase == 7) FntPrintf("y+1");
if (testCase == 8) FntPrintf("xy+1");
} else {
int x = (i-1)%3 - 1;
int y = (i-1)/3 - 1;
FntPos(i * CELL_SIZE + 4, (testCase + 1) * CELL_SIZE - 10);
for (int t = 0; t < count(testCases); t++) {
FntPos(2, t * CELL_SIZE + 12);
FntPrintf("BLOCK\n %2d\n ", testCases[t]);
if (t == 4) FntPrintf("x+1");
if (t == 5) FntPrintf("y+1");
if (t == 6) FntPrintf("xy+1");

int i = 1;
for (int y = -TEST_H; y <= TEST_H; y++) {
for (int x = -TEST_W; x <= TEST_W; x++) {
FntPos(i * CELL_SIZE + 4, (t + 1) * CELL_SIZE - 10);
FntPrintf("%2d:%d", x, y);
i++;
}
}
}
Expand All @@ -86,7 +76,7 @@ void drawDebugInfo() {
#define DRAW_DEBUG

int main() {
initVideo(320, 240);
initVideo(640, 480);
printf("\ngpu/vram-to-vram-overlap\n");

setMaskBitSetting(false, false);
Expand All @@ -98,30 +88,30 @@ int main() {
#endif

// Draw test data
for (int testCase = 0; testCase < SIZES; testCase++) {
for (int i = 1; i<COLS; i++) {
writeRect(i * CELL_SIZE + MARGIN, testCase * CELL_SIZE + MARGIN, sizes[testCase]);
for (int t = 0; t < count(testCases); t++) {
for (int i = 0; i<COLS; i++) {
writeRect((i+1) * CELL_SIZE + MARGIN, t * CELL_SIZE + MARGIN, testCases[t]);
writeGP0(1, 0);
}
}

// Run test itself - copy data in different configurations
for (int testCase = 0; testCase < SIZES; testCase++) {
int size = sizes[testCase];
for (int t = 0; t < count(testCases); t++) {
int size = testCases[t];
int xOffset = 0;
int yOffset = 0;

if (testCase == 6) {xOffset += 1;}
if (testCase == 7) {yOffset += 1;}
if (testCase == 8) {xOffset += 1; yOffset += 1;}
if (t == 4) {xOffset += 1;}
if (t == 5) {yOffset += 1;}
if (t == 6) {xOffset += 1; yOffset += 1;}

int i = 1;
for (int y = -1; y <= 1; y++) {
for (int x = -1; x <= 1; x++) {
int srcX = xOffset + i * CELL_SIZE + MARGIN;
int srcY = yOffset + testCase * CELL_SIZE + MARGIN;
int dstX = xOffset + i * CELL_SIZE + MARGIN + x;
int dstY = yOffset + testCase * CELL_SIZE + MARGIN + y;
for (int y = -TEST_H; y <= TEST_H; y++) {
for (int x = -TEST_W; x <= TEST_W; x++) {
int srcX = xOffset + i * CELL_SIZE + MARGIN;
int srcY = yOffset + t * CELL_SIZE + MARGIN;
int dstX = xOffset + i * CELL_SIZE + MARGIN + x;
int dstY = yOffset + t * CELL_SIZE + MARGIN + y;

vramToVramCopy(srcX, srcY, dstX, dstY, size, size);
writeGP0(1, 0);
Expand Down
Binary file modified gpu/vram-to-vram-overlap/vram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 93568c5

Please sign in to comment.