- Implemented device detection and automatic selection of KREngine memory management parameters

- Now detecting iPad 3 and adjusting parameters to utilize the greater RAM capacity

--HG--
extra : convert_revision : svn%3A7752d6cf-9f14-4ad2-affc-04f1e67b81a5/trunk%40135
This commit is contained in:
kearwood
2012-10-19 23:17:43 +00:00
parent 9e96e765c4
commit 2097664c0a
12 changed files with 67 additions and 21 deletions

View File

@@ -40,7 +40,7 @@
#import "KRShader.h" #import "KRShader.h"
#import "KRContextObject.h" #import "KRContextObject.h"
#import "KRTexture.h" #import "KRTexture.h"
#import "KRContext.h"
#define KRENGINE_MAX_SHADOW_BUFFERS 3 #define KRENGINE_MAX_SHADOW_BUFFERS 3
#define KRENGINE_SHADOW_MAP_WIDTH 2048 #define KRENGINE_SHADOW_MAP_WIDTH 2048
@@ -48,7 +48,6 @@
class KRInstance; class KRInstance;
class KRScene; class KRScene;
class KRContext;
class KRCamera : public KRContextObject { class KRCamera : public KRContextObject {
public: public:

View File

@@ -11,6 +11,16 @@
#include "KRContext.h" #include "KRContext.h"
#include "KRCamera.h" #include "KRCamera.h"
int KRContext::KRENGINE_MAX_VBO_HANDLES;
int KRContext::KRENGINE_MAX_VBO_MEM;
int KRContext::KRENGINE_MAX_SHADER_HANDLES;
int KRContext::KRENGINE_MAX_TEXTURE_HANDLES;
int KRContext::KRENGINE_MAX_TEXTURE_MEM;
int KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX;
int KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN;
int KRContext::KRENGINE_MAX_TEXTURE_DIM;
int KRContext::KRENGINE_MIN_TEXTURE_DIM;
KRContext::KRContext() { KRContext::KRContext() {
m_pBundleManager = new KRBundleManager(*this); m_pBundleManager = new KRBundleManager(*this);
m_pShaderManager = new KRShaderManager(*this); m_pShaderManager = new KRShaderManager(*this);

View File

@@ -9,14 +9,27 @@
#ifndef KREngine_KRContext_h #ifndef KREngine_KRContext_h
#define KREngine_KRContext_h #define KREngine_KRContext_h
#import "KREngine-common.h"
#import "KRBundleManager.h" #import "KRBundleManager.h"
#import "KRSceneManager.h" #import "KRSceneManager.h"
#import "KRTextureManager.h" #import "KRTextureManager.h"
#import "KRMaterialManager.h" #import "KRMaterialManager.h"
#import "KRShaderManager.h" #import "KRShaderManager.h"
#import "KRModelManager.h" #import "KRModelManager.h"
class KRContext { class KRContext {
public: public:
static int KRENGINE_MAX_VBO_HANDLES;
static int KRENGINE_MAX_VBO_MEM;
static int KRENGINE_MAX_SHADER_HANDLES;
static int KRENGINE_MAX_TEXTURE_HANDLES;
static int KRENGINE_MAX_TEXTURE_MEM;
static int KRENGINE_TARGET_TEXTURE_MEM_MAX;
static int KRENGINE_TARGET_TEXTURE_MEM_MIN;
static int KRENGINE_MAX_TEXTURE_DIM;
static int KRENGINE_MIN_TEXTURE_DIM;
KRContext(); KRContext();
~KRContext(); ~KRContext();

View File

@@ -11,6 +11,8 @@
#ifndef KREngine_KREngine_common_h #ifndef KREngine_KREngine_common_h
#define KREngine_KREngine_common_h #define KREngine_KREngine_common_h
#define KRENGINE_MAX_TEXTURE_UNITS 8
#import <stdint.h> #import <stdint.h>
#import <vector> #import <vector>
#import <string> #import <string>

View File

@@ -29,6 +29,8 @@
// or implied, of Kearwood Gilbert. // or implied, of Kearwood Gilbert.
// //
#import <UIKit/UIKit.h>
#import "KREngine.h" #import "KREngine.h"
#import "KRVector3.h" #import "KRVector3.h"
#import "KRScene.h" #import "KRScene.h"
@@ -64,6 +66,31 @@ double const PI = 3.141592653589793f;
- (id)init - (id)init
{ {
BOOL isIpad = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad;
BOOL isRetina = [[UIScreen mainScreen] scale] >= 2.0;
if(isIpad && isRetina) {
KRContext::KRENGINE_MAX_VBO_HANDLES = 10000;
KRContext::KRENGINE_MAX_VBO_MEM = 128000000 * 2;
KRContext::KRENGINE_MAX_SHADER_HANDLES = 100;
KRContext::KRENGINE_MAX_TEXTURE_HANDLES = 10000;
KRContext::KRENGINE_MAX_TEXTURE_MEM = 64000000 * 2;
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX = 48000000 * 2;
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN = 32000000 * 2;
KRContext::KRENGINE_MAX_TEXTURE_DIM = 2048;
KRContext::KRENGINE_MIN_TEXTURE_DIM = 64;
} else {
KRContext::KRENGINE_MAX_VBO_HANDLES = 10000;
KRContext::KRENGINE_MAX_VBO_MEM = 128000000;
KRContext::KRENGINE_MAX_SHADER_HANDLES = 100;
KRContext::KRENGINE_MAX_TEXTURE_HANDLES = 10000;
KRContext::KRENGINE_MAX_TEXTURE_MEM = 64000000;
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX = 48000000;
KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN = 32000000;
KRContext::KRENGINE_MAX_TEXTURE_DIM = 2048;
KRContext::KRENGINE_MIN_TEXTURE_DIM = 64;
}
_camera = NULL; _camera = NULL;
_context = NULL; _context = NULL;
if ((self = [super init])) { if ((self = [super init])) {

View File

@@ -54,6 +54,8 @@ using std::list;
#import "KRCamera.h" #import "KRCamera.h"
class KRMaterial; class KRMaterial;
class KRNode;
class KRModel : public KRResource { class KRModel : public KRResource {

View File

@@ -120,7 +120,7 @@ void KRModelManager::bindVBO(GLvoid *data, GLsizeiptr size, bool enable_vertex,
} else { } else {
m_vboMemUsed += size; m_vboMemUsed += size;
while(m_vbosPool.size() + m_vbosActive.size() >= KRENGINE_MAX_VBO_HANDLES || m_vboMemUsed >= KRENGINE_MAX_VBO_MEM) { while(m_vbosPool.size() + m_vbosActive.size() >= KRContext::KRENGINE_MAX_VBO_HANDLES || m_vboMemUsed >= KRContext::KRENGINE_MAX_VBO_MEM) {
if(m_vbosPool.empty()) { if(m_vbosPool.empty()) {
fprintf(stderr, "flushBuffers due to VBO exhaustion...\n"); fprintf(stderr, "flushBuffers due to VBO exhaustion...\n");
m_pContext->rotateBuffers(false); m_pContext->rotateBuffers(false);

View File

@@ -32,9 +32,6 @@
#ifndef KRMODELMANAGER_H #ifndef KRMODELMANAGER_H
#define KRMODELMANAGER_H #define KRMODELMANAGER_H
#define KRENGINE_MAX_VBO_HANDLES 10000
#define KRENGINE_MAX_VBO_MEM 128000000
#import "KREngine-common.h" #import "KREngine-common.h"
#import "KRContextObject.h" #import "KRContextObject.h"
#import "KRDataBlock.h" #import "KRDataBlock.h"

View File

@@ -53,7 +53,7 @@ KRShader *KRShaderManager::getShader(std::string shader_name, KRCamera *pCamera,
KRShader *pShader = m_shaders[szKey]; KRShader *pShader = m_shaders[szKey];
if(pShader == NULL) { if(pShader == NULL) {
if(m_shaders.size() > KRENGINE_MAX_SHADER_HANDLES) { if(m_shaders.size() > KRContext::KRENGINE_MAX_SHADER_HANDLES) {
// Keep the size of the shader cache reasonable // Keep the size of the shader cache reasonable
std::map<std::string, KRShader *>::iterator itr = m_shaders.begin(); std::map<std::string, KRShader *>::iterator itr = m_shaders.begin();
delete (*itr).second; delete (*itr).second;

View File

@@ -35,6 +35,7 @@
#import <string> #import <string>
#import "KRCamera.h" #import "KRCamera.h"
#import "KRDataBlock.h" #import "KRDataBlock.h"
#import "KRNode.h"
using std::map; using std::map;
using std::vector; using std::vector;
@@ -44,7 +45,8 @@ using std::vector;
#ifndef KRSHADERMANAGER_H #ifndef KRSHADERMANAGER_H
#define KRSHADERMANAGER_H #define KRSHADERMANAGER_H
#define KRENGINE_MAX_SHADER_HANDLES 100 class KRShader;
class KRCamera;
class KRShaderManager : public KRContextObject { class KRShaderManager : public KRContextObject {
public: public:

View File

@@ -33,6 +33,7 @@
#include "KRContext.h" #include "KRContext.h"
#include "KRTexture2D.h" #include "KRTexture2D.h"
#include "KRTextureCube.h" #include "KRTextureCube.h"
#include "KRContext.h"
#include <string.h> #include <string.h>
KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context) { KRTextureManager::KRTextureManager(KRContext &context) : KRContextObject(context) {
@@ -119,7 +120,7 @@ void KRTextureManager::selectTexture(int iTextureUnit, KRTexture *pTexture, int
GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0)); GLDEBUG(glBindTexture(GL_TEXTURE_2D, 0));
} }
m_boundTextures[iTextureUnit] = pTexture; m_boundTextures[iTextureUnit] = pTexture;
while(m_activeTextures.size() + m_poolTextures.size() > KRENGINE_MAX_TEXTURE_HANDLES || m_textureMemUsed > KRENGINE_MAX_TEXTURE_MEM) { while(m_activeTextures.size() + m_poolTextures.size() > KRContext::KRENGINE_MAX_TEXTURE_HANDLES || m_textureMemUsed > KRContext::KRContext::KRENGINE_MAX_TEXTURE_MEM) {
if(m_poolTextures.empty()) { if(m_poolTextures.empty()) {
fprintf(stderr, "Kraken - Texture swapping...\n"); fprintf(stderr, "Kraken - Texture swapping...\n");
decreaseLODCap(); decreaseLODCap();
@@ -150,10 +151,10 @@ size_t KRTextureManager::getActiveMemUsed() {
void KRTextureManager::rotateBuffers(bool new_frame) void KRTextureManager::rotateBuffers(bool new_frame)
{ {
if(new_frame && m_activeTextureMemUsed < KRENGINE_TARGET_TEXTURE_MEM_MIN && m_activeTextureMemUsed * 4 < KRENGINE_TARGET_TEXTURE_MEM_MAX) { if(new_frame && m_activeTextureMemUsed < KRContext::KRENGINE_TARGET_TEXTURE_MEM_MIN && m_activeTextureMemUsed * 4 < KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX) {
// Increasing the LOD level will generally increase active texture memory usage by 4 times, don't increase the texture level until we can ensure that the LOD won't immediately be dropped back to the current level // Increasing the LOD level will generally increase active texture memory usage by 4 times, don't increase the texture level until we can ensure that the LOD won't immediately be dropped back to the current level
increaseLODCap(); increaseLODCap();
} else if(new_frame && m_activeTextureMemUsed > KRENGINE_TARGET_TEXTURE_MEM_MAX) { } else if(new_frame && m_activeTextureMemUsed > KRContext::KRENGINE_TARGET_TEXTURE_MEM_MAX) {
decreaseLODCap(); decreaseLODCap();
} }
m_poolTextures.insert(m_activeTextures.begin(), m_activeTextures.end()); m_poolTextures.insert(m_activeTextures.begin(), m_activeTextures.end());
@@ -174,14 +175,14 @@ void KRTextureManager::rotateBuffers(bool new_frame)
void KRTextureManager::decreaseLODCap() void KRTextureManager::decreaseLODCap()
{ {
if(m_lod_max_dim_cap > KRENGINE_MIN_TEXTURE_DIM) { if(m_lod_max_dim_cap > KRContext::KRENGINE_MIN_TEXTURE_DIM) {
m_lod_max_dim_cap = m_lod_max_dim_cap >> 1; m_lod_max_dim_cap = m_lod_max_dim_cap >> 1;
} }
} }
void KRTextureManager::increaseLODCap() void KRTextureManager::increaseLODCap()
{ {
if(m_lod_max_dim_cap < KRENGINE_MAX_TEXTURE_DIM) { if(m_lod_max_dim_cap < KRContext::KRENGINE_MAX_TEXTURE_DIM) {
m_lod_max_dim_cap = m_lod_max_dim_cap << 1; m_lod_max_dim_cap = m_lod_max_dim_cap << 1;
} }
} }

View File

@@ -29,14 +29,6 @@
// or implied, of Kearwood Gilbert. // or implied, of Kearwood Gilbert.
// //
#define KRENGINE_MAX_TEXTURE_UNITS 8
#define KRENGINE_MAX_TEXTURE_HANDLES 10000
#define KRENGINE_MAX_TEXTURE_MEM 64000000
#define KRENGINE_TARGET_TEXTURE_MEM_MAX 48000000
#define KRENGINE_TARGET_TEXTURE_MEM_MIN 32000000
#define KRENGINE_MAX_TEXTURE_DIM 2048
#define KRENGINE_MIN_TEXTURE_DIM 64
#ifndef KRTEXTUREMANAGER_H #ifndef KRTEXTUREMANAGER_H
#define KRTEXTUREMANAGER_H #define KRTEXTUREMANAGER_H
@@ -44,6 +36,7 @@
#include "KRContextObject.h" #include "KRContextObject.h"
#include "KREngine-common.h" #include "KREngine-common.h"
#include "KRDataBlock.h" #include "KRDataBlock.h"
#include "KRContext.h"
#include <map> #include <map>
#include <set> #include <set>