Advertisement
Guest User

3DS linear alloc changes for TinyGL in ScummVM

a guest
May 5th, 2023
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.67 KB | None | 0 0
  1. diff --git a/backends/platform/3ds/app/scummvm.rsf b/backends/platform/3ds/app/scummvm.rsf
  2. index 133341c7590..c877ade30c7 100644
  3. --- a/backends/platform/3ds/app/scummvm.rsf
  4. +++ b/backends/platform/3ds/app/scummvm.rsf
  5. @@ -16,7 +16,7 @@ Option:
  6.    FreeProductCode         : true # Removes limitations on ProductCode
  7.    MediaFootPadding        : false # If true CCI files are created with padding
  8.    EnableCrypt             : false # Enables encryption for NCCH and CIA
  9. -  EnableCompress          : false # Compresses where applicable (currently only exefs:/.code)
  10. +  EnableCompress          : true # Compresses where applicable (currently only exefs:/.code)
  11.  
  12.  AccessControlInfo:
  13.    CoreVersion                   : 2
  14. @@ -38,7 +38,7 @@ AccessControlInfo:
  15.     #- CategorySystemApplication
  16.     #- CategoryHardwareCheck
  17.     #- CategoryFileSystemTool
  18. -   #- Debug
  19. +   - Debug
  20.     #- TwlCardBackup
  21.     #- TwlNandData
  22.     #- Boss
  23. @@ -59,7 +59,7 @@ AccessControlInfo:
  24.  
  25.    # Process Settings
  26.    MemoryType                    : Application # Application/System/Base
  27. -  SystemMode                    : 64MB # 64MB(Default)/96MB/80MB/72MB/32MB
  28. +  SystemMode                    : 96MB # 64MB(Default)/96MB/80MB/72MB/32MB
  29.    IdealProcessor                : 0
  30.    AffinityMask                  : 1
  31.    Priority                      : 16
  32. @@ -76,7 +76,7 @@ AccessControlInfo:
  33.    SpecialMemoryArrange          : true
  34.  
  35.    # New3DS Exclusive Process Settings
  36. -  SystemModeExt                 : 124MB # Legacy(Default)/124MB/178MB  Legacy:Use Old3DS SystemMode
  37. +  SystemModeExt                 : 178MB # Legacy(Default)/124MB/178MB  Legacy:Use Old3DS SystemMode
  38.    CpuSpeed                      : 804MHz # 268MHz(Default)/804MHz
  39.    EnableL2Cache                 : true # false(default)/true
  40.    CanAccessCore2                : true
  41. @@ -180,7 +180,7 @@ AccessControlInfo:
  42.  SystemControlInfo:
  43.    SaveDataSize: 0K
  44.    RemasterVersion: 0
  45. -  StackSize: 0x40000
  46. +  StackSize: 0x400000
  47.  
  48.    # Modules that run services listed above should be included below
  49.    # Maximum 48 dependencies
  50. diff --git a/backends/platform/3ds/main.cpp b/backends/platform/3ds/main.cpp
  51. index beaf214a6a9..d4c18b832fd 100644
  52. --- a/backends/platform/3ds/main.cpp
  53. +++ b/backends/platform/3ds/main.cpp
  54. @@ -29,8 +29,12 @@ enum {
  55.     SYSTEM_MODEL_2DS = 3
  56.  };
  57.  
  58. +// Max regular heap size is 96 MiB, but that is also the max available memory on O3DS
  59. +// Set slightly lower to make room for backend buffers in linear heap on O3DS
  60. +u32 __ctru_heap_size = 84 << 20; // 84 MiB
  61.  // Set the size of the stack.
  62. -u32 __stacksize__ = 64 * 1024;
  63. +//u32 __stacksize__ = 64 * 1024;
  64. +u32 __stacksize__ = 4 << 20; // 4 MiB
  65.  
  66.  int main(int argc, char *argv[]) {
  67.     // Initialize basic libctru stuff
  68. diff --git a/graphics/tinygl/memory.cpp b/graphics/tinygl/memory.cpp
  69. index 280d90070da..27d246f115c 100644
  70. --- a/graphics/tinygl/memory.cpp
  71. +++ b/graphics/tinygl/memory.cpp
  72. @@ -27,26 +27,66 @@
  73.  
  74.  // Memory allocator for TinyGL
  75.  
  76. -#include "graphics/tinygl/zgl.h"
  77. +#ifdef __3DS__
  78. +#include <3ds.h>
  79. +#define FORBIDDEN_SYMBOL_EXCEPTION_time_h
  80. +#include "common/util.h"
  81. +#endif#include "graphics/tinygl/zgl.h"
  82.  
  83.  namespace TinyGL {
  84.  
  85.  // modify these functions so that they suit your needs
  86.  
  87.  void gl_free(void *p) {
  88. +#ifdef __3DS__
  89. +   linearFree(p);
  90. +#else
  91.     free(p);
  92. +#endif
  93.  }
  94.  
  95.  void *gl_malloc(int size) {
  96. +#ifdef __3DS__
  97. +   return linearAlloc(size);
  98. +#else
  99.     return malloc(size);
  100. +#endif
  101.  }
  102.  
  103.  void *gl_zalloc(int size) {
  104. +#ifdef __3DS__
  105. +   return linearAlloc(size);
  106. +#else
  107.     return calloc(1, size);
  108. +#endif
  109.  }
  110.  
  111.  void *gl_realloc(void *p, int size) {
  112. +#ifdef __3DS__
  113. +// Ctrulib's linearRealloc() is in TODO phase and returns NULL
  114. +// In the meantime, make our own.
  115. +// TODO: Pester DevKitPro to make linearRealloc functional
  116. +   size_t oldSize = linearGetSize(p);
  117. +   assert (oldSize != 0);
  118. +   u32 uint32NewSize = (u32)size;
  119. +// https://github.com/devkitPro/libctru/blob/master/libctru/source/allocator/linear.cpp#L56
  120. +// https://github.com/devkitPro/libctru/blob/master/libctru/source/allocator/mem_pool.h#L5
  121. +   int align = __builtin_ffs(0x80) - 1;
  122. +// https://github.com/devkitPro/libctru/blob/master/libctru/source/allocator/mem_pool.cpp#L43
  123. +   u32 alignMask = (1 << align) -1;
  124. +// https://github.com/devkitPro/libctru/blob/master/libctru/source/allocator/mem_pool.cpp#L53
  125. +   u32 newSizeAlign = (uint32NewSize + alignMask) &~ alignMask;
  126. +   if (newSizeAlign == oldSize) {
  127. +       return p; // do nothing
  128. +   } else {
  129. +       void *newAlloc = linearAlloc(size);
  130. +       memcpy(newAlloc, p, MIN(oldSize, linearGetSize(newAlloc)));
  131. +       linearFree(p);
  132. +       return newAlloc;
  133. +   }
  134. +#else
  135.     return realloc(p, size);
  136. +#endif
  137.  }
  138.  
  139.  } // end of namespace TinyGL
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement