Add comments (speedup plans for GLES) and reformat a bit (no changes)

This commit is contained in:
Henrik Rydgård committed 2013-10-09 11:56:46 +02:00
1 parent ab759a9350
commit 6d6ea77df2
3 files changed
+133 -99

No files matched your search

+79 -85
View File
@@ -101,10 +101,8 @@ inline u16 RGBA8888toRGBA5551(u32 px) {
void ConvertFromRGBA8888(u8 *dst, 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)
{
if (g_Config.bStretchToDisplay)
{
float origW, float origH, float frameW, float frameH) {
if (g_Config.bStretchToDisplay) {
*x = 0;
*y = 0;
*w = frameW;
@@ -115,8 +113,7 @@ void CenterRect(float *x, float *y, float *w, float *h,
float origRatio = origW/origH;
float frameRatio = frameW/frameH;
if (origRatio > frameRatio)
{
if (origRatio > frameRatio) {
// Image is wider than frame. Center vertically.
float scale = origW / frameW;
*x = 0.0f;
@@ -128,9 +125,7 @@ void CenterRect(float *x, float *y, float *w, float *h,
*h = (frameH + *h) / 2.0f; // (408 + 720) / 2 = 564
#endif
*y = (frameH - *h) / 2.0f;
}
else
{
} else {
// Image is taller than frame. Center horizontally.
float scale = origH / frameH;
*y = 0.0f;
@@ -237,31 +232,32 @@ FramebufferManager::FramebufferManager() :
// Check vendor string to try and guess GPU
const char *cvendor = (char *)glGetString(GL_VENDOR);
if(cvendor) {
if (cvendor) {
const std::string vendor(cvendor);
if(vendor == "NVIDIA Corporation"
if (vendor == "NVIDIA Corporation"
|| vendor == "Nouveau"
|| vendor == "nouveau") {
gpuVendor = GPU_VENDOR_NVIDIA;
} else if(vendor == "Advanced Micro Devices, Inc."
} else if (vendor == "Advanced Micro Devices, Inc."
|| vendor == "ATI Technologies Inc.") {
gpuVendor = GPU_VENDOR_AMD;
} else if(vendor == "Intel"
} else if (vendor == "Intel"
|| vendor == "Intel Inc."
|| vendor == "Intel Corporation"
|| vendor == "Tungsten Graphics, Inc") { // We'll assume this last one means Intel
gpuVendor = GPU_VENDOR_INTEL;
} else if(vendor == "ARM")
} else if (vendor == "ARM") {
gpuVendor = GPU_VENDOR_ARM;
else if(vendor == "Imagination Technologies")
} else if (vendor == "Imagination Technologies") {
gpuVendor = GPU_VENDOR_POWERVR;
else if(vendor == "Qualcomm")
} else if (vendor == "Qualcomm") {
gpuVendor = GPU_VENDOR_ADRENO;
else
} else {
gpuVendor = GPU_VENDOR_UNKNOWN;
} else
}
} else {
gpuVendor = GPU_VENDOR_UNKNOWN;
}
gstate_c.gpuVendor = gpuVendor;
NOTICE_LOG(SCEGE, "GPU Vendor : %s", cvendor);
}
@@ -789,6 +785,9 @@ void FramebufferManager::CopyDisplayToOutput() {
GLuint colorTexture = fbo_get_color_texture(vfb->fbo);
// TODO ES3: Use glInvalidateFramebuffer to discard depth/stencil data at the end of frame.
// and to discard extraFBOs_ after using them.
if (useFXAA_ && extraFBOs_.size() == 1) {
glBindTexture(GL_TEXTURE_2D, colorTexture);
@@ -810,12 +809,13 @@ void FramebufferManager::CopyDisplayToOutput() {
// These are in the output display coordinates
float x, y, w, h;
CenterRect(&x, &y, &w, &h, 480.0f, 272.0f, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight);
#if defined(USING_GLES2) && !defined(__SYMBIAN32__) && !defined(MEEGO_EDITION_HARMATTAN) && !defined(IOS)
if (gl_extensions.NV_draw_texture) {
// Fast path for Tegra. TODO: Make this path work on desktop nvidia, seems glew doesn't have a clue.
glDrawTextureNV(colorTexture, 0,
x, y, w, h, 0.0f,
// Actually, on Desktop we should just use glBlitFramebuffer.
glDrawTextureNV(colorTexture, 0,
x, y, w, h, 0.0f,
0, 0, 480.0f / (float)vfb->width, 272.0f / (float)vfb->height);
return;
}
@@ -829,12 +829,12 @@ void FramebufferManager::CopyDisplayToOutput() {
void FramebufferManager::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool sync) {
#ifndef USING_GLES2
if(sync) {
if (sync) {
PackFramebufferAsync_(NULL); // flush async just in case when we go for synchronous update
}
#endif
#endif
if(vfb) {
if (vfb) {
// We'll pseudo-blit framebuffers here to get a resized and flipped version of vfb.
// For now we'll keep these on the same struct as the ones that can get displayed
// (and blatantly copy work already done above while at it).
@@ -855,7 +855,7 @@ void FramebufferManager::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool s
}
// Create a new fbo if none was found for the size
if(!nvfb) {
if (!nvfb) {
nvfb = new VirtualFramebuffer();
nvfb->fbo = 0;
nvfb->fb_address = vfb->fb_address;
@@ -927,8 +927,8 @@ void FramebufferManager::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool s
#ifdef USING_GLES2
PackFramebufferSync_(nvfb); // synchronous glReadPixels
#else
if(gl_extensions.PBO_ARB || !gl_extensions.ATIClampBug) {
if(!sync) {
if (gl_extensions.PBO_ARB || !gl_extensions.ATIClampBug) {
if (!sync) {
PackFramebufferAsync_(nvfb); // asynchronous glReadPixels using PBOs
} else {
PackFramebufferSync_(nvfb); // synchronous glReadPixels
@@ -939,7 +939,6 @@ void FramebufferManager::ReadFramebufferToMemory(VirtualFramebuffer *vfb, bool s
}
void FramebufferManager::BlitFramebuffer_(VirtualFramebuffer *src, VirtualFramebuffer *dst, bool flip, float upscale, float vscale) {
if (dst->fbo) {
fbo_bind_as_render_target(dst->fbo);
} else {
@@ -947,13 +946,13 @@ void FramebufferManager::BlitFramebuffer_(VirtualFramebuffer *src, VirtualFrameb
fbo_unbind();
return;
}
if(glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
if (glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
ERROR_LOG(SCEGE, "Incomplete target framebuffer, aborting blit");
fbo_unbind();
return;
}
glstate.viewport.set(0, 0, dst->width, dst->height);
DisableState();
@@ -971,15 +970,15 @@ void FramebufferManager::BlitFramebuffer_(VirtualFramebuffer *src, VirtualFrameb
CompileDraw2DProgram();
DrawActiveTexture(x, y, w, h, (float)PSP_CoreParameter().pixelWidth, (float)PSP_CoreParameter().pixelHeight, flip, upscale, vscale, draw2dprogram_);
glBindTexture(GL_TEXTURE_2D, 0);
fbo_unbind();
}
// TODO: SSE/NEON
void ConvertFromRGBA8888(u8 *dst, u8 *src, u32 stride, u32 height, GEBufferFormat format) {
if(format == GE_FORMAT_8888) {
if(src == dst) {
if (format == GE_FORMAT_8888) {
if (src == dst) {
return;
} else { // Here lets assume they don't intersect
memcpy(dst, src, stride * height * 4);
@@ -990,18 +989,17 @@ 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++) {
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++) {
for (int i = 0; i < size; i++) {
dst16[i] = RGBA8888toRGBA5551(src32[i]);
}
break;
case GE_FORMAT_4444: // ABGR 4444
for(int i = 0; i < size; i++) {
for (int i = 0; i < size; i++) {
dst16[i] = RGBA8888toRGBA4444(src32[i]);
}
break;
@@ -1024,35 +1022,32 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) {
bool useCPU = g_Config.iRenderingMode == FB_READFBOMEMORY_CPU;
// We'll prepare two PBOs to switch between readying and reading
if(!pixelBufObj_) {
if (!pixelBufObj_) {
GLuint pbos[MAX_PBO];
glGenBuffers(MAX_PBO, pbos);
pixelBufObj_ = new AsyncPBO[MAX_PBO];
for(int i = 0; i < MAX_PBO; i++) {
for (int i = 0; i < MAX_PBO; i++) {
pixelBufObj_[i].handle = pbos[i];
pixelBufObj_[i].maxSize = 0;
pixelBufObj_[i].reading = false;
}
}
// Receive previously requested data from a PBO
if(pixelBufObj_[nextPBO].reading) {
if (pixelBufObj_[nextPBO].reading) {
glBindBuffer(GL_PIXEL_PACK_BUFFER, pixelBufObj_[nextPBO].handle);
packed = (GLubyte *)glMapBuffer(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY);
if(packed) {
DEBUG_LOG(SCEGE, "Reading PBO to memory , bufSize = %u, packed = %08x, fb_address = %08x, stride = %u, pbo = %u",
if (packed) {
DEBUG_LOG(SCEGE, "Reading PBO to memory , bufSize = %u, packed = %08x, fb_address = %08x, stride = %u, pbo = %u",
pixelBufObj_[nextPBO].size, packed, pixelBufObj_[nextPBO].fb_address, pixelBufObj_[nextPBO].stride, nextPBO);
if(useCPU) {
ConvertFromRGBA8888(Memory::GetPointer(pixelBufObj_[nextPBO].fb_address), packed,
pixelBufObj_[nextPBO].stride, pixelBufObj_[nextPBO].height,
if (useCPU) {
ConvertFromRGBA8888(Memory::GetPointer(pixelBufObj_[nextPBO].fb_address), packed,
pixelBufObj_[nextPBO].stride, pixelBufObj_[nextPBO].height,
pixelBufObj_[nextPBO].format);
} else {
} else {
// We don't need to convert, GPU already did (or should have)
Memory::Memcpy(pixelBufObj_[nextPBO].fb_address, packed, pixelBufObj_[nextPBO].size);
}
@@ -1061,12 +1056,11 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) {
}
glUnmapBuffer(GL_PIXEL_PACK_BUFFER);
unbind = true;
}
// Order packing/readback of the framebuffer
if(vfb) {
if (vfb) {
int pixelType, pixelSize, pixelFormat, align;
bool reverseOrder = (gpuVendor == GPU_VENDOR_NVIDIA) || (gpuVendor == GPU_VENDOR_AMD);
@@ -1108,16 +1102,16 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) {
fbo_bind_for_read(vfb->fbo);
} else {
fbo_unbind();
if(gl_extensions.FBO_ARB) {
if (gl_extensions.FBO_ARB) {
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
}
return;
}
if(glCheckFramebufferStatus(GL_READ_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
if (glCheckFramebufferStatus(GL_READ_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
ERROR_LOG(SCEGE, "Incomplete source framebuffer, aborting read");
fbo_unbind();
if(gl_extensions.FBO_ARB) {
if (gl_extensions.FBO_ARB) {
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
}
return;
@@ -1125,9 +1119,9 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) {
glBindBuffer(GL_PIXEL_PACK_BUFFER, pixelBufObj_[currentPBO_].handle);
if(pixelBufObj_[currentPBO_].maxSize < bufSize) {
if (pixelBufObj_[currentPBO_].maxSize < bufSize) {
// We reserve a buffer big enough to fit all those pixels
if(useCPU && pixelType != GL_UNSIGNED_BYTE) {
if (useCPU && pixelType != GL_UNSIGNED_BYTE) {
// Wnd result may be 16-bit but we are reading 32-bit, so we need double the space on the buffer
glBufferData(GL_PIXEL_PACK_BUFFER, bufSize*2, NULL, GL_DYNAMIC_READ);
} else {
@@ -1136,7 +1130,7 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) {
pixelBufObj_[currentPBO_].maxSize = bufSize;
}
if(useCPU) {
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);
@@ -1150,21 +1144,21 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) {
switch(error) {
case 0:
break;
case GL_INVALID_ENUM:
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_ENUM");
case GL_INVALID_ENUM:
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_ENUM");
break;
case GL_INVALID_VALUE:
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_VALUE");
case GL_INVALID_VALUE:
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_VALUE");
break;
case GL_INVALID_OPERATION:
// GL_INVALID_OPERATION will happen sometimes midframe but everything
// seems to work out when actually mapping buffers?
// GL_SAMPLE_BUFFERS, GL_READ_BUFFER, GL_BUFFER_SIZE/MAPPED,
case GL_INVALID_OPERATION:
// GL_INVALID_OPERATION will happen sometimes midframe but everything
// seems to work out when actually mapping buffers?
// GL_SAMPLE_BUFFERS, GL_READ_BUFFER, GL_BUFFER_SIZE/MAPPED,
// GL_PIXEL_PACK_BUFFER_BINDING, all have the expected values.
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_OPERATION");
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_OPERATION");
break;
case GL_INVALID_FRAMEBUFFER_OPERATION:
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_FRAMEBUFFER_OPERATION");
case GL_INVALID_FRAMEBUFFER_OPERATION:
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_FRAMEBUFFER_OPERATION");
break;
default:
ERROR_LOG(SCEGE, "glReadPixels: UNKNOWN OPENGL ERROR %u", error);
@@ -1172,7 +1166,7 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) {
}
fbo_unbind();
if(gl_extensions.FBO_ARB) {
if (gl_extensions.FBO_ARB) {
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
}
@@ -1188,7 +1182,7 @@ void FramebufferManager::PackFramebufferAsync_(VirtualFramebuffer *vfb) {
currentPBO_ = nextPBO;
if(unbind) {
if (unbind) {
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
}
}
@@ -1209,13 +1203,13 @@ void FramebufferManager::PackFramebufferSync_(VirtualFramebuffer *vfb) {
u32 fb_address = (0x04000000) | vfb->fb_address;
GLubyte *packed = 0;
if(vfb->format == GE_FORMAT_8888) {
if (vfb->format == GE_FORMAT_8888) {
packed = (GLubyte *)Memory::GetPointer(fb_address);
} else { // End result may be 16-bit but we are reading 32-bit, so there may not be enough space at fb_address
packed = (GLubyte *)malloc(bufSize * sizeof(GLubyte));
}
if(packed) {
if (packed) {
DEBUG_LOG(SCEGE, "Reading framebuffer to mem, bufSize = %u, packed = %p, fb_address = %08x",
(u32)bufSize, packed, fb_address);
@@ -1225,26 +1219,26 @@ void FramebufferManager::PackFramebufferSync_(VirtualFramebuffer *vfb) {
switch(error) {
case 0:
break;
case GL_INVALID_ENUM:
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_ENUM");
case GL_INVALID_ENUM:
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_ENUM");
break;
case GL_INVALID_VALUE:
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_VALUE");
case GL_INVALID_VALUE:
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_VALUE");
break;
case GL_INVALID_OPERATION:
// GL_INVALID_OPERATION will happen sometimes midframe but everything
// seems to work out when actually reading?
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_OPERATION");
// GL_INVALID_OPERATION will happen sometimes midframe but everything
// seems to work out when actually reading?
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_OPERATION");
break;
case GL_INVALID_FRAMEBUFFER_OPERATION:
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_FRAMEBUFFER_OPERATION");
case GL_INVALID_FRAMEBUFFER_OPERATION:
ERROR_LOG(SCEGE, "glReadPixels: GL_INVALID_FRAMEBUFFER_OPERATION");
break;
default:
ERROR_LOG(SCEGE, "glReadPixels: UNKNOWN OPENGL ERROR %u", error);
break;
}
if(vfb->format != GE_FORMAT_8888) { // If not RGBA 8888 we need to convert
if (vfb->format != GE_FORMAT_8888) { // If not RGBA 8888 we need to convert
ConvertFromRGBA8888(Memory::GetPointer(fb_address), packed, vfb->fb_stride, vfb->height, vfb->format);
free(packed);
}
@@ -1323,7 +1317,7 @@ void FramebufferManager::DecimateFBOs() {
VirtualFramebuffer *vfb = vfbs_[i];
int age = frameLastFramebufUsed - std::max(vfb->last_frame_render, vfb->last_frame_used);
if(updateVram && age == 0 && !vfb->memoryUpdated && vfb == displayFramebuf_)
if (updateVram && age == 0 && !vfb->memoryUpdated && vfb == displayFramebuf_)
ReadFramebufferToMemory(vfb);
if (vfb == displayFramebuf_ || vfb == prevDisplayFramebuf_ || vfb == prevPrevDisplayFramebuf_) {