common.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541
  1. /* SCE CONFIDENTIAL
  2. * $PSLibId$
  3. * Copyright (C) 2011 Sony Computer Entertainment Inc.
  4. * All Rights Reserved.
  5. */
  6. #include "common.h"
  7. #include <display.h>
  8. #include <ctrl.h>
  9. #include <libdbgfont.h>
  10. #include <libdbg.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13. // Data structure to pass through the display queue
  14. typedef struct DisplayData
  15. {
  16. void *address; ///< Framebuffer address
  17. uint32_t width; ///< Framebuffer width
  18. uint32_t height; ///< Framebuffer height
  19. uint32_t strideInPixels; ///< Framebuffer stride in pixels
  20. uint32_t flipMode; ///< From #FlipMode
  21. } DisplayData;
  22. // heap memblocks
  23. SceUID g_lpddrUid = 0;
  24. SceUID g_cdramUid = 0;
  25. // libgxm context
  26. void *g_contextHostMem = NULL;
  27. void *g_contextVdmMem = NULL;
  28. void *g_contextVertexMem = NULL;
  29. void *g_contextFragmentMem = NULL;
  30. void *g_contextFragmentUsseMem = NULL;
  31. SceGxmContext *g_context = NULL;
  32. // libgxm shader patcher
  33. SceGxmShaderPatcher *g_shaderPatcher = NULL;
  34. // libgxm display queue
  35. void *g_displayBufferData[DISPLAY_BUFFER_COUNT];
  36. SceGxmColorSurface g_displaySurface[DISPLAY_BUFFER_COUNT];
  37. SceGxmSyncObject *g_displayBufferSync[DISPLAY_BUFFER_COUNT];
  38. uint32_t g_displayFrontBufferIndex = DISPLAY_BUFFER_COUNT - 1;
  39. uint32_t g_displayBackBufferIndex = 0;
  40. // Depth buffer for display surface
  41. void *g_mainDepthBufferData = NULL;
  42. SceGxmDepthStencilSurface g_mainDepthSurface;
  43. // libgxm main render target
  44. SceGxmRenderTarget *g_mainRenderTarget = NULL;
  45. // Callback functions to allocate memory for the shader patcher
  46. static void *patcherHostAlloc(void *userData, uint32_t size);
  47. static void patcherHostFree(void *userData, void *mem);
  48. static void *patcherBufferAlloc(void *userData, uint32_t size);
  49. static void *patcherVertexUsseAlloc(void *userData, uint32_t size, uint32_t *usseOffset);
  50. static void *patcherFragmentUsseAlloc(void *userData, uint32_t size, uint32_t *usseOffset);
  51. static void patcherFree(void *userData, void *mem);
  52. int initDbgFont(void)
  53. {
  54. int err = SCE_OK;
  55. UNUSED(err);
  56. #if !defined(DISABLE_DEBUG_FONT)
  57. // initialize structure
  58. SceDbgFontConfig config;
  59. memset(&config, 0, sizeof(SceDbgFontConfig));
  60. config.fontSize = SCE_DBGFONT_FONTSIZE_DEFAULT;
  61. err = sceDbgFontInit(&config);
  62. SCE_DBG_ASSERT(err == SCE_OK);
  63. #endif
  64. // done
  65. return err;
  66. }
  67. int termDbgFont(void)
  68. {
  69. int err = SCE_OK;
  70. UNUSED(err);
  71. #if !defined(DISABLE_DEBUG_FONT)
  72. // exit
  73. err = sceDbgFontExit();
  74. SCE_DBG_ASSERT(err == SCE_OK);
  75. #endif
  76. // done
  77. return err;
  78. }
  79. static void displayCallback(const void *callbackData)
  80. {
  81. int err = SCE_OK;
  82. UNUSED(err);
  83. // Cast the parameters back
  84. const DisplayData *displayData = (const DisplayData *)callbackData;
  85. // Render debug text now GPU rendering has finished
  86. renderDbgFont();
  87. // Render copyright debug text
  88. // sceDbgFontPrint(30, displayData->height - 45, 0xffffffff, (const SceChar8 *)"SCE CONFIDENTIAL");
  89. // sceDbgFontPrint(30, displayData->height - 30, 0xffffffff, (const SceChar8 *)"Copyright(C) 2012 Sony Computer Entertainment Inc.");
  90. // Flush debug text
  91. SceDbgFontFrameBufInfo info;
  92. memset(&info, 0, sizeof(info));
  93. info.frameBufAddr = (SceUChar8 *)displayData->address;
  94. info.frameBufPitch = displayData->strideInPixels;
  95. info.frameBufWidth = displayData->width;
  96. info.frameBufHeight = displayData->height;
  97. info.frameBufPixelformat = DISPLAY_DBGFONT_FORMAT;
  98. #if !defined(DISABLE_DEBUG_FONT)
  99. err = sceDbgFontFlush(&info);
  100. SCE_DBG_ASSERT(err == SCE_OK);
  101. #endif
  102. // Check this buffer has been displayed for the necessary number of VSYNCs
  103. // (Avoids queuing a flip before the second VSYNC has happened)
  104. if (displayData->flipMode == FLIP_MODE_VSYNC_2) {
  105. err = sceDisplayWaitSetFrameBufMulti(2);
  106. }
  107. // Swap to the new buffer
  108. SceDisplayFrameBuf framebuf;
  109. memset(&framebuf, 0x00, sizeof(SceDisplayFrameBuf));
  110. framebuf.size = sizeof(SceDisplayFrameBuf);
  111. framebuf.base = displayData->address;
  112. framebuf.pitch = displayData->strideInPixels;
  113. framebuf.pixelformat = DISPLAY_PIXEL_FORMAT;
  114. framebuf.width = displayData->width;
  115. framebuf.height = displayData->height;
  116. err = sceDisplaySetFrameBuf(&framebuf,
  117. (displayData->flipMode == FLIP_MODE_HSYNC)
  118. ? SCE_DISPLAY_UPDATETIMING_NEXTHSYNC
  119. : SCE_DISPLAY_UPDATETIMING_NEXTVSYNC);
  120. SCE_DBG_ASSERT(err == SCE_OK);
  121. // Block this callback until the swap has occurred and the old buffer
  122. // is no longer displayed
  123. if (displayData->flipMode != FLIP_MODE_HSYNC) {
  124. err = sceDisplayWaitSetFrameBuf();
  125. SCE_DBG_ASSERT(err == SCE_OK);
  126. }
  127. }
  128. static void initGxmLibrary(void)
  129. {
  130. int err = SCE_OK;
  131. UNUSED(err);
  132. // set up parameters
  133. SceGxmInitializeParams initializeParams;
  134. memset(&initializeParams, 0, sizeof(SceGxmInitializeParams));
  135. initializeParams.flags = 0;
  136. initializeParams.displayQueueMaxPendingCount = DISPLAY_MAX_PENDING_SWAPS;
  137. initializeParams.displayQueueCallback = displayCallback;
  138. initializeParams.displayQueueCallbackDataSize = sizeof(DisplayData);
  139. initializeParams.parameterBufferSize = SCE_GXM_DEFAULT_PARAMETER_BUFFER_SIZE;
  140. // start libgxm
  141. err = sceGxmInitialize(&initializeParams);
  142. SCE_DBG_ASSERT(err == SCE_OK);
  143. }
  144. static void initHeaps(void)
  145. {
  146. int err = SCE_OK;
  147. UNUSED(err);
  148. // set up an empty heap
  149. heapInitialize();
  150. // allocate memory blocks
  151. g_lpddrUid = sceKernelAllocMemBlock(
  152. "SampleLpddr",
  153. SCE_KERNEL_MEMBLOCK_TYPE_USER_RWDATA_UNCACHE,
  154. HEAP_SIZE_LPDDR_R + HEAP_SIZE_LPDDR_RW + HEAP_SIZE_VERTEX_USSE + HEAP_SIZE_FRAGMENT_USSE,
  155. NULL);
  156. SCE_DBG_ASSERT(g_lpddrUid >= SCE_OK);
  157. g_cdramUid = sceKernelAllocMemBlock(
  158. "SampleCdram",
  159. SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RWDATA,
  160. HEAP_SIZE_CDRAM_RW,
  161. NULL);
  162. SCE_DBG_ASSERT(g_cdramUid >= SCE_OK);
  163. // grab the base addresses
  164. uint8_t *lpddrMem = NULL;
  165. uint8_t *cdramMem = NULL;
  166. err = sceKernelGetMemBlockBase(g_lpddrUid, (void **)&lpddrMem);
  167. SCE_DBG_ASSERT(err == SCE_OK);
  168. err = sceKernelGetMemBlockBase(g_cdramUid, (void **)&cdramMem);
  169. SCE_DBG_ASSERT(err == SCE_OK);
  170. // map and add each block
  171. uint32_t usseOffset;
  172. err = sceGxmMapMemory(lpddrMem, HEAP_SIZE_LPDDR_R, SCE_GXM_MEMORY_ATTRIB_READ);
  173. SCE_DBG_ASSERT(err == SCE_OK);
  174. heapExtend(HEAP_TYPE_LPDDR_R, lpddrMem, HEAP_SIZE_LPDDR_R);
  175. lpddrMem += HEAP_SIZE_LPDDR_R;
  176. err = sceGxmMapMemory(lpddrMem, HEAP_SIZE_LPDDR_RW, SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE);
  177. SCE_DBG_ASSERT(err == SCE_OK);
  178. heapExtend(HEAP_TYPE_LPDDR_RW, lpddrMem, HEAP_SIZE_LPDDR_RW);
  179. lpddrMem += HEAP_SIZE_LPDDR_RW;
  180. err = sceGxmMapMemory(cdramMem, HEAP_SIZE_CDRAM_RW, SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE);
  181. SCE_DBG_ASSERT(err == SCE_OK);
  182. heapExtend(HEAP_TYPE_CDRAM_RW, cdramMem, HEAP_SIZE_CDRAM_RW);
  183. cdramMem += HEAP_SIZE_CDRAM_RW;
  184. err = sceGxmMapVertexUsseMemory(lpddrMem, HEAP_SIZE_VERTEX_USSE, &usseOffset);
  185. SCE_DBG_ASSERT(err == SCE_OK);
  186. heapExtend(HEAP_TYPE_VERTEX_USSE, lpddrMem, HEAP_SIZE_VERTEX_USSE, usseOffset);
  187. lpddrMem += HEAP_SIZE_VERTEX_USSE;
  188. err = sceGxmMapFragmentUsseMemory(lpddrMem, HEAP_SIZE_FRAGMENT_USSE, &usseOffset);
  189. SCE_DBG_ASSERT(err == SCE_OK);
  190. heapExtend(HEAP_TYPE_FRAGMENT_USSE, lpddrMem, HEAP_SIZE_FRAGMENT_USSE, usseOffset);
  191. lpddrMem += HEAP_SIZE_FRAGMENT_USSE;
  192. }
  193. static void createGxmContext(void)
  194. {
  195. int err = SCE_OK;
  196. UNUSED(err);
  197. // allocate host memory
  198. g_contextHostMem = malloc(SCE_GXM_MINIMUM_CONTEXT_HOST_MEM_SIZE);
  199. // allocate ring buffer memory using default sizes
  200. uint32_t fragmentUsseOffset;
  201. g_contextVdmMem = heapAlloc(HEAP_TYPE_LPDDR_R, SCE_GXM_DEFAULT_VDM_RING_BUFFER_SIZE, 4);
  202. g_contextVertexMem = heapAlloc(HEAP_TYPE_LPDDR_R, SCE_GXM_DEFAULT_VERTEX_RING_BUFFER_SIZE, 4);
  203. g_contextFragmentMem = heapAlloc(HEAP_TYPE_LPDDR_R, SCE_GXM_DEFAULT_FRAGMENT_RING_BUFFER_SIZE, 4);
  204. g_contextFragmentUsseMem = heapAlloc(HEAP_TYPE_FRAGMENT_USSE, SCE_GXM_DEFAULT_FRAGMENT_USSE_RING_BUFFER_SIZE, 4, &fragmentUsseOffset);
  205. // set up parameters
  206. SceGxmContextParams contextParams;
  207. memset(&contextParams, 0, sizeof(SceGxmContextParams));
  208. contextParams.hostMem = g_contextHostMem;
  209. contextParams.hostMemSize = SCE_GXM_MINIMUM_CONTEXT_HOST_MEM_SIZE;
  210. contextParams.vdmRingBufferMem = g_contextVdmMem;
  211. contextParams.vdmRingBufferMemSize = SCE_GXM_DEFAULT_VDM_RING_BUFFER_SIZE;
  212. contextParams.vertexRingBufferMem = g_contextVertexMem;
  213. contextParams.vertexRingBufferMemSize = SCE_GXM_DEFAULT_VERTEX_RING_BUFFER_SIZE;
  214. contextParams.fragmentRingBufferMem = g_contextFragmentMem;
  215. contextParams.fragmentRingBufferMemSize = SCE_GXM_DEFAULT_FRAGMENT_RING_BUFFER_SIZE;
  216. contextParams.fragmentUsseRingBufferMem = g_contextFragmentUsseMem;
  217. contextParams.fragmentUsseRingBufferMemSize = SCE_GXM_DEFAULT_FRAGMENT_USSE_RING_BUFFER_SIZE;
  218. contextParams.fragmentUsseRingBufferOffset = fragmentUsseOffset;
  219. // create the context
  220. err = sceGxmCreateContext(&contextParams, &g_context);
  221. SCE_DBG_ASSERT(err == SCE_OK);
  222. }
  223. static void createGxmShaderPatcher(void)
  224. {
  225. int err = SCE_OK;
  226. UNUSED(err);
  227. // create a shader patcher
  228. SceGxmShaderPatcherParams patcherParams;
  229. memset(&patcherParams, 0, sizeof(SceGxmShaderPatcherParams));
  230. patcherParams.userData = NULL;
  231. patcherParams.hostAllocCallback = &patcherHostAlloc;
  232. patcherParams.hostFreeCallback = &patcherHostFree;
  233. patcherParams.bufferAllocCallback = &patcherBufferAlloc;
  234. patcherParams.bufferFreeCallback = &patcherFree;
  235. patcherParams.bufferMem = NULL;
  236. patcherParams.bufferMemSize = NULL;
  237. patcherParams.vertexUsseAllocCallback = &patcherVertexUsseAlloc;
  238. patcherParams.vertexUsseFreeCallback = &patcherFree;
  239. patcherParams.vertexUsseMem = NULL;
  240. patcherParams.vertexUsseMemSize = NULL;
  241. patcherParams.vertexUsseOffset = NULL;
  242. patcherParams.fragmentUsseAllocCallback = &patcherFragmentUsseAlloc;
  243. patcherParams.fragmentUsseFreeCallback = &patcherFree;
  244. patcherParams.fragmentUsseMem = NULL;
  245. patcherParams.fragmentUsseMemSize = NULL;
  246. patcherParams.fragmentUsseOffset = NULL;
  247. err = sceGxmShaderPatcherCreate(&patcherParams, &g_shaderPatcher);
  248. SCE_DBG_ASSERT(err == SCE_OK);
  249. }
  250. int initGxm(void)
  251. {
  252. int err = SCE_OK;
  253. UNUSED(err);
  254. // initialize libgxm
  255. initGxmLibrary();
  256. // initialize our sample heaps
  257. initHeaps();
  258. // create a rendering context
  259. createGxmContext();
  260. // create a shader patcher
  261. createGxmShaderPatcher();
  262. // allocate memory and sync objects for display buffers
  263. for (uint32_t i = 0; i < DISPLAY_BUFFER_COUNT; ++i) {
  264. // allocate memory for display
  265. g_displayBufferData[i] = heapAlloc(
  266. HEAP_TYPE_CDRAM_RW,
  267. 4*DISPLAY_STRIDE_IN_PIXELS*DISPLAY_HEIGHT,
  268. 256);
  269. // memset the buffer to black
  270. for (uint32_t y = 0; y < DISPLAY_HEIGHT; ++y) {
  271. uint32_t *row = (uint32_t *)g_displayBufferData[i] + y*DISPLAY_STRIDE_IN_PIXELS;
  272. for (uint32_t x = 0; x < DISPLAY_WIDTH; ++x) {
  273. row[x] = 0xff000000;
  274. }
  275. }
  276. // initialize a color surface for this display buffer
  277. err = sceGxmColorSurfaceInit(
  278. &g_displaySurface[i],
  279. DISPLAY_COLOR_FORMAT,
  280. SCE_GXM_COLOR_SURFACE_LINEAR,
  281. (MSAA_MODE == SCE_GXM_MULTISAMPLE_NONE) ? SCE_GXM_COLOR_SURFACE_SCALE_NONE : SCE_GXM_COLOR_SURFACE_SCALE_MSAA_DOWNSCALE,
  282. SCE_GXM_OUTPUT_REGISTER_SIZE_32BIT,
  283. DISPLAY_WIDTH,
  284. DISPLAY_HEIGHT,
  285. DISPLAY_STRIDE_IN_PIXELS,
  286. g_displayBufferData[i]);
  287. SCE_DBG_ASSERT(err == SCE_OK);
  288. // create a sync object that we will associate with this buffer
  289. err = sceGxmSyncObjectCreate(&g_displayBufferSync[i]);
  290. SCE_DBG_ASSERT(err == SCE_OK);
  291. }
  292. // create a depth buffer
  293. const uint32_t alignedWidth = ALIGN(DISPLAY_WIDTH, SCE_GXM_TILE_SIZEX);
  294. const uint32_t alignedHeight = ALIGN(DISPLAY_HEIGHT, SCE_GXM_TILE_SIZEY);
  295. uint32_t sampleCount = alignedWidth*alignedHeight;
  296. uint32_t depthStrideInSamples = alignedWidth;
  297. if (MSAA_MODE == SCE_GXM_MULTISAMPLE_4X) {
  298. // samples increase in X and Y
  299. sampleCount *= 4;
  300. depthStrideInSamples *= 2;
  301. } else if (MSAA_MODE == SCE_GXM_MULTISAMPLE_2X) {
  302. // samples increase in Y only
  303. sampleCount *= 2;
  304. }
  305. g_mainDepthBufferData = heapAlloc(
  306. HEAP_TYPE_LPDDR_RW,
  307. 4*sampleCount,
  308. SCE_GXM_DEPTHSTENCIL_SURFACE_ALIGNMENT);
  309. // initialize depth surface
  310. err = sceGxmDepthStencilSurfaceInit(
  311. &g_mainDepthSurface,
  312. SCE_GXM_DEPTH_STENCIL_FORMAT_S8D24,
  313. SCE_GXM_DEPTH_STENCIL_SURFACE_TILED,
  314. depthStrideInSamples,
  315. g_mainDepthBufferData,
  316. NULL);
  317. // swap to the current front buffer with VSYNC
  318. // (also ensures that future calls with HSYNC are successful)
  319. SceDisplayFrameBuf framebuf;
  320. memset(&framebuf, 0x00, sizeof(SceDisplayFrameBuf));
  321. framebuf.size = sizeof(SceDisplayFrameBuf);
  322. framebuf.base = g_displayBufferData[g_displayFrontBufferIndex];
  323. framebuf.pitch = DISPLAY_STRIDE_IN_PIXELS;
  324. framebuf.pixelformat = DISPLAY_PIXEL_FORMAT;
  325. framebuf.width = DISPLAY_WIDTH;
  326. framebuf.height = DISPLAY_HEIGHT;
  327. err = sceDisplaySetFrameBuf(&framebuf, SCE_DISPLAY_UPDATETIMING_NEXTVSYNC);
  328. SCE_DBG_ASSERT(err == SCE_OK);
  329. err = sceDisplayWaitSetFrameBuf();
  330. SCE_DBG_ASSERT(err == SCE_OK);
  331. // create a render target that describes the tiling setup we want to use
  332. g_mainRenderTarget = createRenderTarget(DISPLAY_WIDTH, DISPLAY_HEIGHT, MSAA_MODE);
  333. // done
  334. return err;
  335. }
  336. int termGxm(void)
  337. {
  338. int err = SCE_OK;
  339. UNUSED(err);
  340. // destroy render target
  341. destroyRenderTarget(g_mainRenderTarget);
  342. // destroy depth buffer
  343. heapFree(g_mainDepthBufferData);
  344. // wait for display processing to finish before deallocating buffers
  345. err = sceGxmDisplayQueueFinish();
  346. SCE_DBG_ASSERT(err == SCE_OK);
  347. // free the display buffers and sync objects
  348. for (uint32_t i = 0; i < DISPLAY_BUFFER_COUNT; ++i) {
  349. // free color surface
  350. heapFree(g_displayBufferData[i]);
  351. // destroy sync object
  352. err = sceGxmSyncObjectDestroy(g_displayBufferSync[i]);
  353. SCE_DBG_ASSERT(err == SCE_OK);
  354. }
  355. // destroy the shader patcher
  356. err = sceGxmShaderPatcherDestroy(g_shaderPatcher);
  357. SCE_DBG_ASSERT(err == SCE_OK);
  358. // destroy the rendering context
  359. err = sceGxmDestroyContext(g_context);
  360. SCE_DBG_ASSERT(err == SCE_OK);
  361. heapFree(g_contextFragmentUsseMem);
  362. heapFree(g_contextFragmentMem);
  363. heapFree(g_contextVertexMem);
  364. heapFree(g_contextVdmMem);
  365. free(g_contextHostMem);
  366. // destroy heaps
  367. heapTerminate();
  368. sceKernelFreeMemBlock(g_lpddrUid);
  369. sceKernelFreeMemBlock(g_cdramUid);
  370. // terminate libgxm
  371. err = sceGxmTerminate();
  372. SCE_DBG_ASSERT(err == SCE_OK);
  373. // done
  374. return err;
  375. }
  376. int cycleDisplayBuffers(FlipMode flipMode, uint32_t width, uint32_t height, uint32_t strideInPixels)
  377. {
  378. int err = SCE_OK;
  379. UNUSED(err);
  380. // queue the display swap for this frame
  381. DisplayData displayData;
  382. displayData.address = g_displayBufferData[g_displayBackBufferIndex];
  383. displayData.width = width;
  384. displayData.height = height;
  385. displayData.strideInPixels = strideInPixels;
  386. displayData.flipMode = flipMode;
  387. err = sceGxmDisplayQueueAddEntry(
  388. g_displayBufferSync[g_displayFrontBufferIndex], // front buffer is OLD buffer
  389. g_displayBufferSync[g_displayBackBufferIndex], // back buffer is NEW buffer
  390. &displayData);
  391. SCE_DBG_ASSERT(err == SCE_OK);
  392. // update buffer indices
  393. g_displayFrontBufferIndex = g_displayBackBufferIndex;
  394. g_displayBackBufferIndex = (g_displayBackBufferIndex + 1) % DISPLAY_BUFFER_COUNT;
  395. // done
  396. return err;
  397. }
  398. SceGxmRenderTarget *createRenderTarget(uint32_t width, uint32_t height, SceGxmMultisampleMode msaaMode)
  399. {
  400. int err = SCE_OK;
  401. UNUSED(err);
  402. // set up parameters
  403. SceGxmRenderTargetParams params;
  404. memset(&params, 0, sizeof(SceGxmRenderTargetParams));
  405. params.flags = 0;
  406. params.width = width;
  407. params.height = height;
  408. params.scenesPerFrame = 1;
  409. params.multisampleMode = msaaMode;
  410. params.multisampleLocations = 0;
  411. params.driverMemBlock = SCE_UID_INVALID_UID;
  412. // create the render target
  413. SceGxmRenderTarget *renderTarget;
  414. err = sceGxmCreateRenderTarget(&params, &renderTarget);
  415. SCE_DBG_ASSERT(err == SCE_OK);
  416. return renderTarget;
  417. }
  418. void destroyRenderTarget(SceGxmRenderTarget *renderTarget)
  419. {
  420. int err = SCE_OK;
  421. UNUSED(err);
  422. // destroy the render target
  423. err = sceGxmDestroyRenderTarget(renderTarget);
  424. SCE_DBG_ASSERT(err == SCE_OK);
  425. }
  426. void *patcherHostAlloc(void *userData, uint32_t size)
  427. {
  428. UNUSED(userData);
  429. return malloc(size);
  430. }
  431. void patcherHostFree(void *userData, void *mem)
  432. {
  433. UNUSED(userData);
  434. free(mem);
  435. }
  436. void *patcherBufferAlloc(void *userData, uint32_t size)
  437. {
  438. UNUSED(userData);
  439. return heapAlloc(HEAP_TYPE_LPDDR_RW, size, 4);
  440. }
  441. void *patcherVertexUsseAlloc(void *userData, uint32_t size, uint32_t *usseOffset)
  442. {
  443. UNUSED(userData);
  444. return heapAlloc(HEAP_TYPE_VERTEX_USSE, size, SCE_GXM_USSE_ALIGNMENT, usseOffset);
  445. }
  446. void *patcherFragmentUsseAlloc(void *userData, uint32_t size, uint32_t *usseOffset)
  447. {
  448. UNUSED(userData);
  449. return heapAlloc(HEAP_TYPE_FRAGMENT_USSE, size, SCE_GXM_USSE_ALIGNMENT, usseOffset);
  450. }
  451. void patcherFree(void *userData, void *mem)
  452. {
  453. UNUSED(userData);
  454. heapFree(mem);
  455. }