mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-18 03:44:32 +01:00
Use SSE some in framebuffers to memory.
Since people are using it (even though it seems dangerous), might as well make it faster. 6% better in Tales of Phantasia X.
This commit is contained in:
1 parent
4475c99426
commit
e8d5866e5a
3 files changed
+184
-23
No files matched your search
+52
-23
@@ -35,6 +35,7 @@
|
||||
#include "GPU/GPUState.h"
|
||||
|
||||
#include "GPU/Common/PostShader.h"
|
||||
#include "GPU/Common/TextureDecoder.h"
|
||||
#include "GPU/GLES/Framebuffer.h"
|
||||
#include "GPU/GLES/TextureCache.h"
|
||||
#include "GPU/GLES/ShaderManager.h"
|
||||
@@ -111,11 +112,15 @@ inline u16 RGBA8888toRGBA4444(u32 px) {
|
||||
return ((px >> 4) & 0x000F) | ((px >> 8) & 0x00F0) | ((px >> 12) & 0x0F00) | ((px >> 16) & 0xF000);
|
||||
}
|
||||
|
||||
inline u16 RGBA8888toRGBA5551(u32 px) {
|
||||
return ((px >> 3) & 0x001F) | ((px >> 6) & 0x03E0) | ((px >> 9) & 0x7C00) | ((px >> 16) & 0x8000);
|
||||
inline u16 BGRA8888toRGB565(u32 px) {
|
||||
return ((px >> 19) & 0x001F) | ((px >> 5) & 0x07E0) | ((px << 8) & 0xF800);
|
||||
}
|
||||
|
||||
void ConvertFromRGBA8888(u8 *dst, u8 *src, u32 stride, u32 height, GEBufferFormat format);
|
||||
inline u16 BGRA8888toRGBA4444(u32 px) {
|
||||
return ((px >> 20) & 0x000F) | ((px >> 8) & 0x00F0) | ((px << 4) & 0x0F00) | ((px >> 16) & 0xF000);
|
||||
}
|
||||
|
||||
void ConvertFromRGBA8888(u8 *dst, const u8 *src, u32 stride, u32 height, GEBufferFormat format);
|
||||
|
||||
void CenterRect(float *x, float *y, float *w, float *h,
|
||||
float origW, float origH, float frameW, float frameH) {
|
||||
@@ -1256,12 +1261,23 @@ void FramebufferManager::BlitFramebuffer_(VirtualFramebuffer *src, VirtualFrameb
|
||||
fbo_unbind();
|
||||
}
|
||||
|
||||
static inline bool UseBGRA8888() {
|
||||
// TODO: Other platforms? May depend on vendor which is faster?
|
||||
#ifdef _WIN32
|
||||
return gl_extensions.EXT_bgra;
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO: SSE/NEON
|
||||
// Could also make C fake-simd for 64-bit, two 8888 pixels fit in a register :)
|
||||
void ConvertFromRGBA8888(u8 *dst, u8 *src, u32 stride, u32 height, GEBufferFormat format) {
|
||||
void ConvertFromRGBA8888(u8 *dst, const u8 *src, u32 stride, u32 height, GEBufferFormat format) {
|
||||
if (format == GE_FORMAT_8888) {
|
||||
if (src == dst) {
|
||||
return;
|
||||
} else if (UseBGRA8888()) {
|
||||
u32 numPixels = height * stride;
|
||||
ConvertBGRA8888ToRGBA8888((u32 *)dst, (const u32 *)src, numPixels);
|
||||
} else { // Here lets assume they don't intersect
|
||||
memcpy(dst, src, stride * height * 4);
|
||||
}
|
||||
@@ -1271,25 +1287,38 @@ void ConvertFromRGBA8888(u8 *dst, u8 *src, u32 stride, u32 height, GEBufferForma
|
||||
u16 *dst16 = (u16 *)dst;
|
||||
switch (format) {
|
||||
case GE_FORMAT_565: // BGR 565
|
||||
for (int i = 0; i < size; i++) {
|
||||
dst16[i] = RGBA8888toRGB565(src32[i]);
|
||||
if (UseBGRA8888()) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
dst16[i] = BGRA8888toRGB565(src32[i]);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < size; i++) {
|
||||
dst16[i] = RGBA8888toRGB565(src32[i]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GE_FORMAT_5551: // ABGR 1555
|
||||
for (int i = 0; i < size; i++) {
|
||||
dst16[i] = RGBA8888toRGBA5551(src32[i]);
|
||||
if (UseBGRA8888()) {
|
||||
ConvertBGRA8888ToRGBA5551(dst16, src32, size);
|
||||
} else {
|
||||
ConvertRGBA8888ToRGBA5551(dst16, src32, size);
|
||||
}
|
||||
break;
|
||||
case GE_FORMAT_4444: // ABGR 4444
|
||||
for (int i = 0; i < size; i++) {
|
||||
dst16[i] = RGBA8888toRGBA4444(src32[i]);
|
||||
if (UseBGRA8888()) {
|
||||
for (int i = 0; i < size; i++) {
|
||||
dst16[i] = BGRA8888toRGBA4444(src32[i]);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < size; i++) {
|
||||
dst16[i] = RGBA8888toRGBA4444(src32[i]);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case GE_FORMAT_8888:
|
||||
case GE_FORMAT_INVALID:
|
||||
// Not possible.
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1317,24 +1346,24 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) {
|
||||
}
|
||||
|
||||
// Receive previously requested data from a PBO
|
||||
if (pixelBufObj_[nextPBO].reading) {
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, pixelBufObj_[nextPBO].handle);
|
||||
AsyncPBO &pbo = pixelBufObj_[nextPBO];
|
||||
if (pbo.reading) {
|
||||
glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo.handle);
|
||||
packed = (GLubyte *)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
|
||||
|
||||
if (packed) {
|
||||
DEBUG_LOG(SCEGE, "Reading PBO to memory , bufSize = %u, packed = %p, fb_address = %08x, stride = %u, pbo = %u",
|
||||
pixelBufObj_[nextPBO].size, packed, pixelBufObj_[nextPBO].fb_address, pixelBufObj_[nextPBO].stride, nextPBO);
|
||||
pbo.size, packed, pbo.fb_address, pbo.stride, nextPBO);
|
||||
|
||||
if (useCPU) {
|
||||
ConvertFromRGBA8888(Memory::GetPointer(pixelBufObj_[nextPBO].fb_address), packed,
|
||||
pixelBufObj_[nextPBO].stride, pixelBufObj_[nextPBO].height,
|
||||
pixelBufObj_[nextPBO].format);
|
||||
if (useCPU || (UseBGRA8888() && pbo.format == GE_FORMAT_8888)) {
|
||||
u8 *dst = Memory::GetPointer(pbo.fb_address);
|
||||
ConvertFromRGBA8888(dst, packed, pbo.stride, pbo.height, pbo.format);
|
||||
} else {
|
||||
// We don't need to convert, GPU already did (or should have)
|
||||
Memory::Memcpy(pixelBufObj_[nextPBO].fb_address, packed, pixelBufObj_[nextPBO].size);
|
||||
Memory::Memcpy(pbo.fb_address, packed, pbo.size);
|
||||
}
|
||||
|
||||
pixelBufObj_[nextPBO].reading = false;
|
||||
pbo.reading = false;
|
||||
}
|
||||
|
||||
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
|
||||
@@ -1371,7 +1400,7 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) {
|
||||
case GE_FORMAT_8888: // 32 bit RGBA
|
||||
default:
|
||||
pixelType = GL_UNSIGNED_BYTE;
|
||||
pixelFormat = GL_RGBA;
|
||||
pixelFormat = UseBGRA8888() ? GL_BGRA_EXT : GL_RGBA;
|
||||
pixelSize = 4;
|
||||
align = 4;
|
||||
break;
|
||||
@@ -1412,7 +1441,7 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) {
|
||||
if (useCPU) {
|
||||
// If converting pixel formats on the CPU we'll always request RGBA8888
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, 4);
|
||||
glReadPixels(0, 0, vfb->fb_stride, vfb->height, GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
glReadPixels(0, 0, vfb->fb_stride, vfb->height, UseBGRA8888() ? GL_BGRA_EXT : GL_RGBA, GL_UNSIGNED_BYTE, 0);
|
||||
} else {
|
||||
// Otherwise we'll directly request the format we need and let the GPU sort it out
|
||||
glPixelStorei(GL_PACK_ALIGNMENT, align);
|
||||
|
||||
Reference in new issue
Block a user