profiler; rsf, makefile and image loading tweaks; pngcrush'd largest images; removed leftover debug text from asset loading

This commit is contained in:
zetaPRIME 2017-05-09 05:21:52 -04:00
parent f852ec8134
commit c667c1b0d1
12 changed files with 87 additions and 17 deletions

View File

@ -25,6 +25,10 @@
#include "starlight/util/JsonConversions.h" #include "starlight/util/JsonConversions.h"
#include "starlight/util/Profiler.h"
using starlight::util::Profiler;
#include <sstream>
using std::string; using std::string;
using std::shared_ptr; using std::shared_ptr;
using std::make_shared; using std::make_shared;
@ -75,40 +79,48 @@ namespace {
} }
CTexture* LoadPNG(const std::string& path, bool isPremult = false) { CTexture* LoadPNG(const std::string& path, bool isPremult = false) {
//Profiler::TaskStart();
unsigned char* imgbuf; unsigned char* imgbuf;
unsigned width, height; unsigned width, height;
lodepng::State state;
lodepng_decode32_file(&imgbuf, &width, &height, path.c_str()); lodepng_decode32_file(&imgbuf, &width, &height, path.c_str());
if (state.info_png.color.colortype != 6) isPremult = true; // expect no alpha if not rgba
/*{
std::stringstream ss; ss << "loaded png, ";
ss << width; ss << "x"; ss << height;
Profiler::TaskFinish(ss.str());
}*/
unsigned bw = NextPow2(width), bh = NextPow2(height); unsigned bw = NextPow2(width), bh = NextPow2(height);
u8* gpubuf = static_cast<u8*>(linearAlloc(bw*bh*4)); u8* gpubuf = static_cast<u8*>(linearAlloc(bw*bh*4));
//Profiler::TaskStart();
//memset(gpubuf, 0, bw*bh*4);
//Profiler::TaskFinish("cleared canvas");
u8* src = static_cast<u8*>(imgbuf); u8* dst = static_cast<u8*>(gpubuf);
//Profiler::TaskStart();
if (isPremult) { if (isPremult) {
u32* src = reinterpret_cast<u32*>(imgbuf); u32* dst = reinterpret_cast<u32*>(gpubuf);
// just convert endianness // just convert endianness
for(unsigned iy = 0; iy < height; iy++) { for(unsigned iy = 0; iy < height; iy++) {
for (unsigned ix = 0; ix < width; ix++) { for (unsigned ix = 0; ix < width; ix++) {
int r = *src++; u32 clr = *src;
int g = *src++; *dst = __builtin_bswap32(clr);
int b = *src++;
int a = *src++;
*dst++ = a; src+=4; dst+=4;
*dst++ = b;
*dst++ = g;
*dst++ = r;
} }
dst += (bw - width) * 4; // skip the difference dst += (bw - width) * 4; // skip the difference
} }
} else { } else {
u8* src = static_cast<u8*>(imgbuf); u8* dst = static_cast<u8*>(gpubuf);
// convert and premultiply // convert and premultiply
for(unsigned iy = 0; iy < height; iy++) { for(unsigned iy = 0; iy < height; iy++) {
for (unsigned ix = 0; ix < width; ix++) { for (unsigned ix = 0; ix < width; ix++) {
int r = *src++; u8 r = *src++;
int g = *src++; u8 g = *src++;
int b = *src++; u8 b = *src++;
int a = *src++; u8 a = *src++;
float aa = (1.0f / 255.0f) * a; float aa = (1.0f / 255.0f) * a;
@ -120,11 +132,14 @@ namespace {
dst += (bw - width) * 4; // skip the difference dst += (bw - width) * 4; // skip the difference
} }
} }
//Profiler::TaskFinish("made into canvas, flipped and premult");
// completely skipping over the difference instead of erasing might eventually lead to garbage outside of frame, // completely skipping over the difference instead of erasing might eventually lead to garbage outside of frame,
// but meh; that'll only be visible if you intentionally push the UVs outside the image proper // but meh; that'll only be visible if you intentionally push the UVs outside the image proper
//Profiler::TaskStart();
CTexture* tx = RenderCore::LoadTexture(static_cast<void*>(gpubuf), bw, bh); CTexture* tx = RenderCore::LoadTexture(static_cast<void*>(gpubuf), bw, bh);
tx->size = Vector2(width, height); // and for now just fix the size after the fact tx->size = Vector2(width, height); // and for now just fix the size after the fact
//Profiler::TaskFinish("copied into linear");
std::free(imgbuf); std::free(imgbuf);
linearFree(gpubuf); linearFree(gpubuf);
@ -216,7 +231,7 @@ shared_ptr<Drawable> ThemeManager::LoadAsset(string& path, ThemeRefContainer<Dra
static shared_ptr<Drawable> nulldrw = make_shared<starlight::gfx::DrawableTest>(); static shared_ptr<Drawable> nulldrw = make_shared<starlight::gfx::DrawableTest>();
string ext = FindExtension(path); string ext = FindExtension(path);
printf("load: %s (%s)\n", path.c_str(), ext.c_str()); //printf("load: %s (%s)\n", path.c_str(), ext.c_str());
/**/ if (ext == "png") { /**/ if (ext == "png") {
return make_shared<DrawableImage>(LoadPNG(path)); return make_shared<DrawableImage>(LoadPNG(path));
} }
@ -227,7 +242,7 @@ shared_ptr<Drawable> ThemeManager::LoadAsset(string& path, ThemeRefContainer<Dra
fs >> j; fs >> j;
} }
auto st = j.dump(); auto st = j.dump();
printf("file contents: %s\n", st.c_str()); //printf("file contents: %s\n", st.c_str());
string type = j["assetType"]; string type = j["assetType"];
/**/ if (type == "ninepatch") { /**/ if (type == "ninepatch") {

View File

@ -264,7 +264,7 @@ CTexture* RenderCore::LoadTexture(void* src, int width, int height) {
C3D_TexBind(0, tex->texture); C3D_TexBind(0, tex->texture);
printf("loaded image w %i (%i) h %i (%i)\n", width, owidth, height, oheight); //printf("loaded image w %i (%i) h %i (%i)\n", width, owidth, height, oheight);
return tex; return tex;
} }

View File

@ -88,6 +88,7 @@ void DebugConsole::PreDraw() {
if (!buffer) buffer = std::make_unique<gfx::DrawContextCanvas>(rect.size + Vector2(0, 8)); if (!buffer) buffer = std::make_unique<gfx::DrawContextCanvas>(rect.size + Vector2(0, 8));
buffer->Clear(); buffer->Clear();
GFXManager::PushContext(buffer.get()); GFXManager::PushContext(buffer.get());
GFXManager::PrepareForDrawing(); // force clear even if nothing to write
textConfig.Print(buffer->rect, text); textConfig.Print(buffer->rect, text);
GFXManager::PopContext(); GFXManager::PopContext();
} }

View File

@ -53,6 +53,7 @@ void Label::PreDraw() {
buffer = std::make_unique<gfx::DrawContextCanvas>(rect.size + Vector2(0, 8)); buffer = std::make_unique<gfx::DrawContextCanvas>(rect.size + Vector2(0, 8));
buffer->Clear(); buffer->Clear();
GFXManager::PushContext(buffer.get()); GFXManager::PushContext(buffer.get());
GFXManager::PrepareForDrawing(); // force clear even if nothing to write
textConfig.ROGet().Print(buffer->rect, text); textConfig.ROGet().Print(buffer->rect, text);
GFXManager::PopContext(); GFXManager::PopContext();
} }

View File

@ -0,0 +1,19 @@
#include "Profiler.h"
#include <cstdio>
#include "3ds.h"
using starlight::util::Profiler;
Profiler::TickCount Profiler::tc = Profiler::TickCount();
void Profiler::TaskStart() {
osTickCounterUpdate(reinterpret_cast<TickCounter*>(&tc));
}
void Profiler::TaskFinish(const std::string& msg) {
osTickCounterUpdate(reinterpret_cast<TickCounter*>(&tc));
double tm = osTickCounterRead(reinterpret_cast<TickCounter*>(&tc));
printf("T:%f - %s\n", tm, msg.c_str());
}

View File

@ -0,0 +1,22 @@
#pragma once
#include "starlight/_global.h"
#include <string>
namespace starlight {
namespace util {
class Profiler {
private:
struct TickCount {
unsigned long long int elapsed;
unsigned long long int ref;
};
static TickCount tc;
Profiler() {};
public:
static void TaskStart();
static void TaskFinish(const std::string& msg);
};
}
}

View File

@ -13,6 +13,9 @@ roadmap to v0.5.1 {
- libctru console as ui element - libctru console as ui element
pngcrush the biggest assets (default and osk backdrops etc.)
- profile image loading (for large images, loading the png and spanned copy/premult take about the same time; memset to preclear is only ~2ms with a 512x512)
- fix the hang on osk when pressing (L|R)+up+left - fix the hang on osk when pressing (L|R)+up+left
figure out what (else) to put on the left side of the keyboard (opposite backspace and enter) figure out what (else) to put on the left side of the keyboard (opposite backspace and enter)
temporary drawable loading, local themeref, discard etc. temporary drawable loading, local themeref, discard etc.
@ -28,6 +31,7 @@ roadmap to v0.5.1 {
...and some mechanism for allowing it to opt out of the rest of the cycle ...and some mechanism for allowing it to opt out of the rest of the cycle
Trackable sideclass for threads; float progress 0..1, etc. Trackable sideclass for threads; float progress 0..1, etc.
^ make progress bar and use it for a progress/"please wait" dialog
- MAKE THREADS END CLEANLY - MAKE THREADS END CLEANLY
^ observed a single instance of being stalled on redscreen, not really sure what that was about ^ observed a single instance of being stalled on redscreen, not really sure what that was about
lambda task thread lambda task thread

View File

@ -173,7 +173,7 @@ send: $(BUILD)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
send-cia: $(TARGET)-strip.elf send-cia: $(TARGET)-strip.elf
@makerom -f cia -o $(TARGET).cia -elf $(TARGET)-strip.elf -rsf resources/$(TARGET).rsf -icon resources/icon.icn -banner resources/banner.bnr -exefslogo -target t @makerom -f cia -o $(TARGET).cia -elf $(TARGET)-strip.elf -rsf resources/$(TARGET).rsf -icon resources/icon.icn -banner resources/banner.bnr -exefslogo -target t
@sockme $(TARGET).cia $(3DSIP) @sockme $(TARGET).cia $(3DSIP) || sockme $(TARGET).cia $(3DSIP) || sockme $(TARGET).cia $(3DSIP)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
run: $(BUILD) run: $(BUILD)
@citra $(TARGET).3dsx @citra $(TARGET).3dsx

View File

@ -91,6 +91,12 @@ AccessControlInfo:
Priority : 16 Priority : 16
MaxCpu : 0x9E # Default MaxCpu : 0x9E # Default
# New3DS Exclusive Process Settings
SystemModeExt : Legacy # Legacy(Default)/124MB/178MB Legacy:Use Old3DS SystemMode
CpuSpeed : 804MHz # 268MHz(Default)/804MHz
EnableL2Cache : true # false(default)/true
CanAccessCore2 : true
DisableDebug : true DisableDebug : true
EnableForceDebug : false EnableForceDebug : false

View File

@ -11,6 +11,7 @@
#include "starlight/gfx/RenderCore.h" #include "starlight/gfx/RenderCore.h"
#include "starlight/util/Path.h" #include "starlight/util/Path.h"
#include "starlight/util/Profiler.h"
#include "starlight/ui/ParallaxLayer.h" #include "starlight/ui/ParallaxLayer.h"
#include "starlight/ui/ScrollField.h" #include "starlight/ui/ScrollField.h"
@ -36,6 +37,7 @@ using starlight::GFXManager;
using starlight::gfx::RenderCore; using starlight::gfx::RenderCore;
using starlight::util::Path; using starlight::util::Path;
using starlight::util::Profiler;
using starlight::Application; using starlight::Application;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.2 KiB

After

Width:  |  Height:  |  Size: 2.5 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.8 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB