Skip to content

Instantly share code, notes, and snippets.

@Subv
Last active August 29, 2015 14:15
Show Gist options
  • Save Subv/ae2dedc1236b21f9fdbe to your computer and use it in GitHub Desktop.
Save Subv/ae2dedc1236b21f9fdbe to your computer and use it in GitHub Desktop.
#include <limits>
#include <string.h>
#include "output.h"
#include "common/scope_exit.h"
#include "common/string_funcs.h"
#include "tests/test.h"
#include "tests/gpu/displaytransfer.h"
namespace GPU {
namespace DisplayTransfer {
static const u32 RAW_COPY_FLAG = 0;
enum PixelFormat {
IN_RGBA8 = 0 << 8,
IN_RGB8 = 1 << 8,
IN_RGB565 = 2 << 8,
IN_RGB5A1 = 3 << 8,
IN_RGBA4 = 4 << 8,
OUT_RGBA8 = 0 << 12,
OUT_RGB8 = 1 << 12,
OUT_RGB565 = 2 << 12,
OUT_RGB5A1 = 3 << 12,
OUT_RGBA4 = 4 << 12,
};
template<typename T1, typename T2>
static void DisplayTransferAndWait(T1* input, T2* output, u32 input_dimensions, u32 output_dimensions, u32 flags) {
GSPGPU_FlushDataCache(NULL, (u8*)input, 0x400 * sizeof(T1));
GSPGPU_InvalidateDataCache(NULL, (u8*)output, 0x400 * sizeof(T2));
GX_SetDisplayTransfer(NULL, (u32*)input, input_dimensions, (u32*)output, output_dimensions, flags | RAW_COPY_FLAG);
gspWaitForPPF();
//svcSleepThread(1000 * 1000 * 1000); // 1 second
}
static bool RGB5A1_To_RGBA4() {
u16* input = (u16*)linearAlloc(0x400 * 2);
u16* output = (u16*)linearAlloc(0x400 * 2);
memset(output, 0, 0x400 * 2);
memset(input, 0, 0x400 * 2);
SCOPE_EXIT({
linearFree(input);
linearFree(output);
});
// Test Red Input
*input = 0xF800; //Input
*output = 0; //Output
DisplayTransferAndWait(input, output, 0x00200020, 0x00200020, IN_RGB5A1 | OUT_RGBA4);
TestEquals(*output, (u16)0xF000);
// Test Green Input
*input = 0x07C0; //Input
*output = 0; //Output
DisplayTransferAndWait(input, output, 0x00200020, 0x00200020, IN_RGB5A1 | OUT_RGBA4);
TestEquals(*output, (u16)0x0F00);
// Test Red Input
*input = 0x003E; //Input
*output = 0; //Output
DisplayTransferAndWait(input, output, 0x00200020, 0x00200020, IN_RGB5A1 | OUT_RGBA4);
TestEquals(*output, (u16)0x00F0);
// Test Red Input
*input = 0x0001; //Input
*output = 0; //Output
DisplayTransferAndWait(input, output, 0x00200020, 0x00200020, IN_RGB5A1 | OUT_RGBA4);
TestEquals(*output, (u16)0x000F);
return true;
}
static bool RGBA8_To_RGB5A1() {
/*u32* input = (u32*)linearAlloc(0x400 * 4);
u16* output = (u16*)linearAlloc(0x400 * 2);
memset(output, 0, 0x400 * 4);
memset(input, 0, 0x400 * 2);
SCOPE_EXIT({
linearFree(input);
linearFree(output);
});
// Test Red Input
*input = 0xFF000000; //Input
*output = 0; //Output
DisplayTransferAndWait(input, output, 0x00200020, 0x00200020, IN_RGBA8 | OUT_RGB5A1);
//TestEquals(*output, (u16)0xF800);
// Test Red Input
*input = 0x00FF0000; //Input
*output = 0; //Output
DisplayTransferAndWait(input, output, 0x00200020, 0x00200020, IN_RGBA8 | OUT_RGB5A1);
//TestEquals(*output, (u16)0xF800);
// Test Red Input
*input = 0x0000FF00; //Input
*output = 0; //Output
DisplayTransferAndWait(input, output, 0x00200020, 0x00200020, IN_RGBA8 | OUT_RGB5A1);
TestEquals(*output, (u16)0xFF00);
// Test Red Input
*input = 0x000000FF; //Input
*output = 0; //Output
DisplayTransferAndWait(input, output, 0x00200020, 0x00200020, IN_RGBA8 | OUT_RGB5A1);
TestEquals(*output, (u16)0x00FF);*/
return true;
}
static bool RGBA8_To_RGB8() {
u32* input = (u32*)linearAlloc(0x400 * 4);
u32* output = (u32*)linearAlloc(0x400 * 4);
memset(output, 0, 0x400 * 4);
memset(input, 0, 0x400 * 4);
SCOPE_EXIT({
linearFree(input);
linearFree(output);
});
//Test Red Input
*input = 0xFF000000; //Input
*output = 0; //Output
DisplayTransferAndWait(input, output, 0x00200020, 0x00200020, IN_RGBA8 | OUT_RGB8);
TestEquals(*output, (u32)0x00FF0000u);
//Test Green Input
*input = 0x00FF0000; //Input
*output = 0; //Output
DisplayTransferAndWait(input, output, 0x00200020, 0x00200020, IN_RGBA8 | OUT_RGB8);
TestEquals(*output, (u32)0x0000FF00u);
//Test Blue Input
*input = 0x0000FF00; //Input
*output = 0; //Output
DisplayTransferAndWait(input, output, 0x00200020, 0x00200020, IN_RGBA8 | OUT_RGB8);
TestEquals(*output, (u32)0x000000FFu);
//Test Alpha Input
*input = 0x000000FF; //Input
*output = 0; //Output
DisplayTransferAndWait(input, output, 0x00200020, 0x00200020, IN_RGBA8 | OUT_RGB8);
TestEquals(*output, (u32)0x00000000u);
return true;
}
void TestAll() {
const std::string tag = "DisplayTransfer";
Test(tag, "RGBA8_To_RGB8", RGBA8_To_RGB8(), true);
Test(tag, "RGBA8_To_RGB5A1", RGBA8_To_RGB5A1(), true);
Test(tag, "RGB5A1_To_RGBA4", RGB5A1_To_RGBA4(), true);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment