From 5005772243463e6b35e48256244835c89025c86f Mon Sep 17 00:00:00 2001 From: olebeck <31539311+olebeck@users.noreply.github.com> Date: Sun, 29 Jun 2025 16:30:20 +0200 Subject: [PATCH] correct texture address mode, use tlsf instead of sceClibMspace --- miniwin/CMakeLists.txt | 2 + .../backends/gxm/{memory.h => gxm_memory.h} | 2 - .../backends/gxm/libSceRazorCapture_stub.a | Bin 9578 -> 0 bytes miniwin/src/d3drm/backends/gxm/memory.cpp | 52 +- miniwin/src/d3drm/backends/gxm/razor.h | 12 + miniwin/src/d3drm/backends/gxm/renderer.cpp | 374 +++-- .../backends/gxm/{ => shaders}/.gitignore | 0 miniwin/src/d3drm/backends/gxm/tlsf.c | 1264 +++++++++++++++++ miniwin/src/d3drm/backends/gxm/tlsf.h | 90 ++ miniwin/src/internal/d3drmrenderer_gxm.h | 14 +- 10 files changed, 1639 insertions(+), 171 deletions(-) rename miniwin/src/d3drm/backends/gxm/{memory.h => gxm_memory.h} (92%) delete mode 100644 miniwin/src/d3drm/backends/gxm/libSceRazorCapture_stub.a create mode 100644 miniwin/src/d3drm/backends/gxm/razor.h rename miniwin/src/d3drm/backends/gxm/{ => shaders}/.gitignore (100%) create mode 100644 miniwin/src/d3drm/backends/gxm/tlsf.c create mode 100644 miniwin/src/d3drm/backends/gxm/tlsf.h diff --git a/miniwin/CMakeLists.txt b/miniwin/CMakeLists.txt index 4ea5d68d..50638bb2 100644 --- a/miniwin/CMakeLists.txt +++ b/miniwin/CMakeLists.txt @@ -61,10 +61,12 @@ if(VITA) target_sources(miniwin PRIVATE src/d3drm/backends/gxm/renderer.cpp src/d3drm/backends/gxm/memory.cpp + src/d3drm/backends/gxm/tlsf.c ) target_link_libraries(miniwin PRIVATE SceGxm_stub SceRazorCapture_stub + SceRazorHud_stub ) list(APPEND GRAPHICS_BACKENDS USE_GXM) list(REMOVE_ITEM GRAPHICS_BACKENDS USE_SOFTWARE_RENDER USE_SDL_GPU) diff --git a/miniwin/src/d3drm/backends/gxm/memory.h b/miniwin/src/d3drm/backends/gxm/gxm_memory.h similarity index 92% rename from miniwin/src/d3drm/backends/gxm/memory.h rename to miniwin/src/d3drm/backends/gxm/gxm_memory.h index 346b947e..1dd31bf0 100644 --- a/miniwin/src/d3drm/backends/gxm/memory.h +++ b/miniwin/src/d3drm/backends/gxm/gxm_memory.h @@ -16,5 +16,3 @@ void vita_mem_vertex_usse_free(SceUID uid); void* vita_mem_fragment_usse_alloc(unsigned int size, SceUID* uid, unsigned int* usse_offset); void vita_mem_fragment_usse_free(SceUID uid); -bool cdramPool_init(); -SceClibMspace cdramPool_get(); diff --git a/miniwin/src/d3drm/backends/gxm/libSceRazorCapture_stub.a b/miniwin/src/d3drm/backends/gxm/libSceRazorCapture_stub.a deleted file mode 100644 index 4030b429887d5bc1634069eda4287d939a9066ea..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9578 zcmeI2%}*0S6u@6C2(82jeuM-=3L#32Zs~W83REl&mLj1fdNHttrBq5wwp${aVB*!p zM9!Er#)I*$p8O9?Ogwn-;=x4YO|N>;w{&M`cj>xID{*6Yl4ZW$eC)jW&6|Ct?;^`D zEDyWA9(C|V0)db}6h0sHc!qYWlz%;*KqM?Rn0EsJJ}plG+CBpuIt6gJ0MPjo;Mfm< z?s0&gEr8zl0R8=?1#X7DQ{>0kHKELN6Qzm5G+)f}T&V<_x-=)u^0{o5%N2>L`}ar?}N3zfoflDs`D#D)L-1x3E%M zO#3dXk)+B$y-r$Sc|m%cRB@35@M@K&R^hH(IO>;mmR9RwPMg>0Lb+B<(d*WVYxA1s zRFw@imX~KQz0h@5ZHW51sCOOcB-g9_4aadA3sZ}s4j zceC;DAA(Ie`oS<&*#1dt2 zLJM>$3ow5i^BrqG{o zw6Q9%8H@$K8ZVQSfJZMdi>$x`lfl!QSyQ6CNAz<;_03}q zh;aYd905d4aCAkFBY)UODKc}Pquv@LdsH!LkA6M~y=xwhlpp@qz{q9@AYy`{F+GL? z{>YvfiW1Xhe5ZS6lA&|=UALNtA?mS`U0>Ef$+kzhUx!VwbXAX~py-FA!T4VH_gQ*1 z_2pqRvP8YV)_}>jO8_G#SW4=$6d`cz0A #include +#include + + static SceUID cdramPoolUID = -1; static SceClibMspace cdramPool = NULL; @@ -117,50 +120,3 @@ void vita_mem_fragment_usse_free(SceUID uid) sceGxmUnmapFragmentUsseMemory(mem); sceKernelFreeMemBlock(uid); } - -bool cdramPool_init() -{ - if (cdramPool) { - return true; - } - int poolsize; - int ret; - void* mem; - SceKernelFreeMemorySizeInfo info; - info.size = sizeof(SceKernelFreeMemorySizeInfo); - sceKernelGetFreeMemorySize(&info); - - poolsize = ALIGN(info.size_cdram, 256 * 1024); - if (poolsize > info.size_cdram) { - poolsize = ALIGN(info.size_cdram - 256 * 1024, 256 * 1024); - } - poolsize -= 16 * 1024 * 1024; - cdramPoolUID = sceKernelAllocMemBlock("gpu_cdram_pool", SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, poolsize, NULL); - if (cdramPool < 0) { - return false; - } - - ret = sceKernelGetMemBlockBase(cdramPoolUID, &mem); - if (ret < 0) { - return false; - } - cdramPool = sceClibMspaceCreate(mem, poolsize); - - if (!cdramPool) { - return false; - } - ret = sceGxmMapMemory( - mem, - poolsize, - (SceGxmMemoryAttribFlags) (SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE) - ); - if (ret < 0) { - return false; - } - return true; -} - -SceClibMspace cdramPool_get() -{ - return cdramPool; -} diff --git a/miniwin/src/d3drm/backends/gxm/razor.h b/miniwin/src/d3drm/backends/gxm/razor.h new file mode 100644 index 00000000..b14ba0f6 --- /dev/null +++ b/miniwin/src/d3drm/backends/gxm/razor.h @@ -0,0 +1,12 @@ +#pragma once + +#include +#include + +extern "C" { + extern int sceRazorGpuCaptureSetTrigger(int frames, const char* path); + + extern int sceRazorGpuTraceTrigger(); + extern int sceRazorGpuTraceSetFilename(const char* filename, int counter); + extern int sceRazorHudSetDisplayEnabled(bool enable); +} diff --git a/miniwin/src/d3drm/backends/gxm/renderer.cpp b/miniwin/src/d3drm/backends/gxm/renderer.cpp index 193b9c24..eb8da497 100644 --- a/miniwin/src/d3drm/backends/gxm/renderer.cpp +++ b/miniwin/src/d3drm/backends/gxm/renderer.cpp @@ -1,7 +1,9 @@ #include "d3drmrenderer_gxm.h" -#include "memory.h" +#include "gxm_memory.h" #include "meshutils.h" #include "utils.h" +#include "razor.h" +#include "tlsf.h" #include #include @@ -14,6 +16,7 @@ #include "incbin.h" bool with_razor = false; +bool with_razor_hud = false; #define VITA_GXM_SCREEN_WIDTH 960 #define VITA_GXM_SCREEN_HEIGHT 544 @@ -23,6 +26,9 @@ bool with_razor = false; #define VITA_GXM_COLOR_FORMAT SCE_GXM_COLOR_FORMAT_A8B8G8R8 #define VITA_GXM_PIXEL_FORMAT SCE_DISPLAY_PIXELFORMAT_A8B8G8R8 +#define CDRAM_POOL_SIZE 64*1024*1024 + + INCBIN(main_vert_gxp, "shaders/main.vert.gxp"); INCBIN(main_frag_gxp, "shaders/main.frag.gxp"); INCBIN(color_frag_gxp, "shaders/color.frag.gxp"); @@ -53,9 +59,6 @@ static const SceGxmBlendInfo blendInfoTransparent = { .alphaDst = SCE_GXM_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA, }; -extern "C" int sceRazorGpuCaptureSetTrigger(int frames, const char* path); -extern "C" int sceRazorGpuCaptureEnableSalvage(const char* path); -extern "C" int sceRazorGpuCaptureSetTriggerNextFrame(const char* path); static GXMRendererContext gxm_renderer_context; @@ -77,12 +80,19 @@ static void display_callback(const void* callback_data) static void load_razor() { - int mod_id = _sceKernelLoadModule("app0:librazorcapture_es4.suprx", 0, nullptr); int status; + int mod_id = _sceKernelLoadModule("app0:librazorcapture_es4.suprx", 0, nullptr); if (!SCE_ERR(sceKernelStartModule, mod_id, 0, nullptr, 0, nullptr, &status)) { with_razor = true; } + /* + int mod_id_hud = _sceKernelLoadModule("app0:librazorhud_es4.suprx", 0, nullptr); + if (!SCE_ERR(sceKernelStartModule, mod_id_hud, 0, nullptr, 0, nullptr, &status)) { + with_razor_hud = true; + } + */ + if (with_razor) { sceRazorGpuCaptureEnableSalvage("ux0:data/gpu_crash.sgx"); } @@ -111,8 +121,64 @@ bool gxm_init() return err; } gxm_initialized = true; + return true; +} - return cdramPool_init(); +static SceUID cdramAllocatorUID = -1; +static tlsf_t cdramAllocator = nullptr; + +bool cdram_allocator_create() { + int ret; + + ret = sceKernelAllocMemBlock( + "gpu_cdram_pool", + SCE_KERNEL_MEMBLOCK_TYPE_USER_CDRAM_RW, + CDRAM_POOL_SIZE, + NULL + ); + if (ret < 0) { + sceClibPrintf("sceKernelAllocMemBlock failed: %08x\n", ret); + return false; + } + cdramAllocatorUID = ret; + + void* mem; + ret = sceKernelGetMemBlockBase(cdramAllocatorUID, &mem); + if (ret < 0) { + sceClibPrintf("sceKernelGetMemBlockBase failed: %08x\n", ret); + return false; + } + + ret = sceGxmMapMemory( + mem, + CDRAM_POOL_SIZE, + (SceGxmMemoryAttribFlags) (SCE_GXM_MEMORY_ATTRIB_READ | SCE_GXM_MEMORY_ATTRIB_WRITE) + ); + if (ret < 0) { + sceClibPrintf("sceGxmMapMemory failed: %08x\n", ret); + return false; + } + + cdramAllocator = SDL_malloc(tlsf_size()); + tlsf_create(cdramAllocator); + tlsf_add_pool(cdramAllocator, mem, CDRAM_POOL_SIZE); + return true; +} + +int inuse_mem = 0; + +inline void* cdram_alloc(size_t size, size_t align) { + sceClibPrintf("cdram_alloc(%d, %d) inuse=%d ", size, align, inuse_mem); + void* ptr = tlsf_memalign(cdramAllocator, align, size); + sceClibPrintf("ptr=%p\n", ptr); + inuse_mem += tlsf_block_size(ptr); + return ptr; +} + +inline void cdram_free(void* ptr) { + inuse_mem -= tlsf_block_size(ptr); + sceClibPrintf("cdram_free(%p)\n", ptr); + tlsf_free(cdramAllocator, ptr); } static bool create_gxm_context() @@ -130,12 +196,6 @@ static bool create_gxm_context() const unsigned int patcherVertexUsseSize = 64 * 1024; const unsigned int patcherFragmentUsseSize = 64 * 1024; - data->cdramPool = cdramPool_get(); - if (!data->cdramPool) { - SDL_Log("failed to allocate cdramPool"); - return false; - } - // allocate buffers data->vdmRingBuffer = vita_mem_alloc( SCE_KERNEL_MEMBLOCK_TYPE_USER_RW_UNCACHE, @@ -242,14 +302,13 @@ static void destroy_gxm_context() SDL_free(gxm_renderer_context.contextHostMem); } -bool get_gxm_context(SceGxmContext** context, SceGxmShaderPatcher** shaderPatcher, SceClibMspace* cdramPool) +bool get_gxm_context(SceGxmContext** context, SceGxmShaderPatcher** shaderPatcher) { if (!create_gxm_context()) { return false; } *context = gxm_renderer_context.context; *shaderPatcher = gxm_renderer_context.shaderPatcher; - *cdramPool = gxm_renderer_context.cdramPool; return true; } @@ -284,8 +343,6 @@ static void CreateOrthoMatrix(float left, float right, float bottom, float top, Direct3DRMRenderer* GXMRenderer::Create(DWORD width, DWORD height) { - SDL_Log("GXMRenderer::Create width=%d height=%d", width, height); - bool success = gxm_init(); if (!success) { return nullptr; @@ -306,7 +363,12 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) const unsigned int sampleCount = alignedWidth * alignedHeight; const unsigned int depthStrideInSamples = alignedWidth; - if (!get_gxm_context(&this->context, &this->shaderPatcher, &this->cdramPool)) { + if (!get_gxm_context(&this->context, &this->shaderPatcher)) { + return; + } + + if(!cdram_allocator_create()) { + sceClibPrintf("failed to create cdram allocator"); return; } @@ -533,11 +595,11 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) // clear uniforms this->colorShader_uColor = sceGxmProgramFindParameterByName(colorFragmentProgramGxp, "uColor"); // vec4 - this->lights = static_castlights)>(sceClibMspaceMalloc(this->cdramPool, sizeof(*this->lights))); + this->lights = static_castlights)>(cdram_alloc(sizeof(*this->lights), 4)); for (int i = 0; i < VITA_GXM_UNIFORM_BUFFER_COUNT; i++) { - this->quadVertices[i] = (Vertex*) sceClibMspaceMalloc(this->cdramPool, sizeof(Vertex) * 4 * 50); + this->quadVertices[i] = static_cast(cdram_alloc(sizeof(Vertex) * 4 * 50, 4)); } - this->quadIndices = (uint16_t*) sceClibMspaceMalloc(this->cdramPool, sizeof(uint16_t) * 4); + this->quadIndices = static_cast(cdram_alloc(sizeof(uint16_t) * 4, 4)); this->quadIndices[0] = 0; this->quadIndices[1] = 1; this->quadIndices[2] = 2; @@ -551,6 +613,21 @@ GXMRenderer::GXMRenderer(DWORD width, DWORD height) this->vertexNotifications[i].value = 0; } + int count; + auto ids = SDL_GetGamepads(&count); + for(int i = 0; i < count; i++) { + auto id = ids[i]; + auto gamepad = SDL_OpenGamepad(id); + if(gamepad != nullptr) { + this->gamepad = gamepad; + break; + } + } + + if(with_razor_hud) { + sceRazorGpuTraceSetFilename("ux0:data/gpu_trace", 3); + } + m_initialized = true; } @@ -600,7 +677,9 @@ void GXMRenderer::AddTextureDestroyCallback(Uint32 id, IDirect3DRMTexture* textu auto* ctx = static_cast(arg); auto& cache = ctx->renderer->m_textures[ctx->textureId]; void* textureData = sceGxmTextureGetData(&cache.gxmTexture); - sceClibMspaceFree(ctx->renderer->cdramPool, textureData); + cdram_free(textureData); + cache.texture = nullptr; + memset(&cache.gxmTexture, 0, sizeof(cache.gxmTexture)); delete ctx; }, ctx @@ -610,72 +689,121 @@ void GXMRenderer::AddTextureDestroyCallback(Uint32 id, IDirect3DRMTexture* textu static void convertTextureMetadata( SDL_Surface* surface, bool* supportedFormat, - SceGxmTextureFormat* textureFormat, - size_t* textureSize, - size_t* textureAlignment, - size_t* textureStride + SceGxmTextureFormat* gxmTextureFormat, + size_t* textureSize, // size in bytes + size_t* textureAlignment, // alignment in bytes + size_t* textureStride, // stride in bytes + size_t* paletteOffset // offset from textureData in bytes ) { - *supportedFormat = true; - *textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT; + int bytesPerPixel; + size_t extraDataSize = 0; switch (surface->format) { - case SDL_PIXELFORMAT_ABGR8888: { - *textureFormat = SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR; - *textureSize = surface->h * surface->pitch; - *textureStride = surface->pitch; - break; - } - /* - case SDL_PIXELFORMAT_INDEX8: { - *textureFormat = SCE_GXM_TEXTURE_FORMAT_P8_ABGR; - int pixelsSize = surface->h * surface->pitch; - int alignBytes = ALIGNMENT(pixelsSize, SCE_GXM_PALETTE_ALIGNMENT); - *textureSize = pixelsSize + alignBytes + 0xff; - *textureAlignment = SCE_GXM_PALETTE_ALIGNMENT; - *textureStride = surface->pitch; - break; - } - */ - default: { - *supportedFormat = false; - } + case SDL_PIXELFORMAT_INDEX8: { + *supportedFormat = true; + *gxmTextureFormat = SCE_GXM_TEXTURE_FORMAT_P8_ABGR; + int pixelsSize = surface->w * surface->h; + int alignBytes = ALIGNMENT(pixelsSize, SCE_GXM_PALETTE_ALIGNMENT); + extraDataSize = alignBytes + 256 * 4; + *textureAlignment = SCE_GXM_PALETTE_ALIGNMENT; + *paletteOffset = pixelsSize + alignBytes; + bytesPerPixel = 1; + break; + } + case SDL_PIXELFORMAT_ABGR8888: { + *supportedFormat = true; + *gxmTextureFormat = SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR; + *textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT; + bytesPerPixel = 4; + break; + } + default: { + *supportedFormat = false; + *gxmTextureFormat = SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR; + *textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT; + bytesPerPixel = 4; + break; + } } + *textureStride = ALIGN(surface->w, 8)*bytesPerPixel; + *textureSize = (*textureStride)*surface->h+extraDataSize; } -void copySurfaceTo(SDL_Surface* src, void* dstData, size_t textureStride) +void copySurfaceToGxm(DirectDrawSurfaceImpl* surface, uint8_t* textureData, size_t dstStride, size_t dstSize) { - SDL_Surface* dst = SDL_CreateSurfaceFrom(src->w, src->h, SDL_PIXELFORMAT_ABGR8888, dstData, textureStride); - SDL_BlitSurface(src, nullptr, dst, nullptr); - SDL_DestroySurface(dst); + SDL_Surface* src = surface->m_surface; + switch(src->format) { + case SDL_PIXELFORMAT_ABGR8888: { + for(int y = 0; y < src->h; y++) { + uint8_t* srcRow = (uint8_t*)src->pixels + (y*src->pitch); + uint8_t* dstRow = textureData + (y*dstStride); + size_t rowSize = src->w*4; + if((dstRow - textureData)+rowSize > dstSize) { + sceClibPrintf("buffer overrun!!! size=%d y=%d rowSize=%d\n", dstSize, y, rowSize); + } + memcpy(dstRow, srcRow, rowSize); + } + break; + } + case SDL_PIXELFORMAT_INDEX8: { + LPDIRECTDRAWPALETTE _palette; + surface->GetPalette(&_palette); + auto palette = static_cast(_palette); + + // copy pixels + for(int y = 0; y < src->h; y++) { + void* srcRow = static_cast(src->pixels) + (y*src->pitch); + void* dstRow = static_cast(textureData) + (y*dstStride); + memcpy(dstRow, srcRow, src->w); + } + + int pixelsSize = src->w * src->h; + int alignBytes = ALIGNMENT(pixelsSize, SCE_GXM_PALETTE_ALIGNMENT); + uint8_t* paletteData = textureData + pixelsSize + alignBytes; + memcpy(paletteData, palette->m_palette->colors, 256 * 4); + if((paletteData-textureData) + 256*4 > dstSize) { + sceClibPrintf("buffer overrun!!! textureData=%p paletteData=%p size=%d\n", textureData, paletteData, dstSize); + } + palette->Release(); + break; + } + default: { + sceClibPrintf("unsupported format %d\n", SDL_GetPixelFormatName(src->format)); + SDL_Surface* dst = SDL_CreateSurfaceFrom(src->w, src->h, SDL_PIXELFORMAT_ABGR8888, textureData, src->w*4); + SDL_BlitSurface(src, nullptr, dst, nullptr); + SDL_DestroySurface(dst); + break; + } + } } Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture) { auto texture = static_cast(iTexture); auto surface = static_cast(texture->m_surface); - + bool supportedFormat; + SceGxmTextureFormat gxmTextureFormat; size_t textureSize; size_t textureAlignment; size_t textureStride; - SceGxmTextureFormat textureFormat; + size_t paletteOffset; + int textureWidth = surface->m_surface->w; int textureHeight = surface->m_surface->h; convertTextureMetadata( surface->m_surface, &supportedFormat, - &textureFormat, + &gxmTextureFormat, &textureSize, &textureAlignment, - &textureStride + &textureStride, + &paletteOffset ); - if (!supportedFormat) { - textureAlignment = SCE_GXM_TEXTURE_ALIGNMENT; - textureStride = textureWidth * 4; - textureSize = textureHeight * textureStride; - textureFormat = SCE_GXM_TEXTURE_FORMAT_U8U8U8U8_ABGR; + if(!supportedFormat) { + return NO_TEXTURE_ID; } for (Uint32 i = 0; i < m_textures.size(); ++i) { @@ -683,69 +811,42 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture) if (tex.texture == texture) { if (tex.version != texture->m_version) { void* textureData = sceGxmTextureGetData(&tex.gxmTexture); - if (!supportedFormat) { - copySurfaceTo(surface->m_surface, textureData, textureStride); - } - else { - memcpy(textureData, surface->m_surface->pixels, textureSize); - } + copySurfaceToGxm(surface, (uint8_t*)textureData, textureStride, textureSize); tex.version = texture->m_version; } return i; } } - SDL_Log( - "Create Texture %s w=%d h=%d s=%d", + sceClibPrintf("Create Texture %s w=%d h=%d s=%d size=%d align=%d\n", SDL_GetPixelFormatName(surface->m_surface->format), textureWidth, textureHeight, - textureStride + textureStride, + textureSize, + textureAlignment ); // allocate gpu memory - void* textureData = sceClibMspaceMemalign(this->cdramPool, textureAlignment, textureSize); - uint8_t* paletteData = nullptr; - - if (!supportedFormat) { - SDL_Log( - "unsupported SDL texture format %s, falling back on SDL_PIXELFORMAT_ABGR8888", - SDL_GetPixelFormatName(surface->m_surface->format) - ); - copySurfaceTo(surface->m_surface, textureData, textureStride); - } - else if (surface->m_surface->format == SDL_PIXELFORMAT_INDEX8) { - LPDIRECTDRAWPALETTE _palette; - surface->GetPalette(&_palette); - auto palette = static_cast(_palette); - - int pixelsSize = surface->m_surface->w * surface->m_surface->h; - int alignBytes = ALIGNMENT(pixelsSize, SCE_GXM_PALETTE_ALIGNMENT); - SDL_Log("copying indexed texture data from=%p to=%p", surface->m_surface->pixels, textureData); - memcpy(textureData, surface->m_surface->pixels, pixelsSize); - - paletteData = (uint8_t*) textureData + pixelsSize + alignBytes; - memcpy(paletteData, palette->m_palette->colors, palette->m_palette->ncolors * sizeof(SDL_Color)); - } - else { - SDL_Log("copying texture data from=%p to=%p", surface->m_surface->pixels, textureData); - memcpy(textureData, surface->m_surface->pixels, textureSize); - } + void* textureData = cdram_alloc(textureSize, textureAlignment); + copySurfaceToGxm(surface, (uint8_t*)textureData, textureStride, textureSize); SceGxmTexture gxmTexture; SCE_ERR( - sceGxmTextureInitLinearStrided, + sceGxmTextureInitLinear, &gxmTexture, textureData, - textureFormat, + gxmTextureFormat, textureWidth, textureHeight, - textureStride + 0 ); - // sceGxmTextureSetMinFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_LINEAR); + sceGxmTextureSetMinFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_LINEAR); sceGxmTextureSetMagFilter(&gxmTexture, SCE_GXM_TEXTURE_FILTER_LINEAR); - if (paletteData) { - sceGxmTextureSetPalette(&gxmTexture, paletteData); + sceGxmTextureSetUAddrMode(&gxmTexture, SCE_GXM_TEXTURE_ADDR_REPEAT); + sceGxmTextureSetVAddrMode(&gxmTexture, SCE_GXM_TEXTURE_ADDR_REPEAT); + if (gxmTextureFormat == SCE_GXM_TEXTURE_FORMAT_P8_ABGR) { + sceGxmTextureSetPalette(&gxmTexture, (uint8_t*)textureData + paletteOffset); } for (Uint32 i = 0; i < m_textures.size(); ++i) { @@ -754,7 +855,6 @@ Uint32 GXMRenderer::GetTextureId(IDirect3DRMTexture* iTexture) tex.texture = texture; tex.version = texture->m_version; tex.gxmTexture = gxmTexture; - tex.textureSize = textureSize; AddTextureDestroyCallback(i, texture); return i; } @@ -795,7 +895,7 @@ GXMMeshCacheEntry GXMRenderer::GXMUploadMesh(const MeshGroup& meshGroup) size_t vertexBufferSize = sizeof(Vertex) * vertices.size(); size_t indexBufferSize = sizeof(uint16_t) * indices.size(); - void* meshData = sceClibMspaceMemalign(this->cdramPool, 4, vertexBufferSize + indexBufferSize); + void* meshData = cdram_alloc(vertexBufferSize + indexBufferSize, 4); Vertex* vertexBuffer = (Vertex*) meshData; uint16_t* indexBuffer = (uint16_t*) ((uint8_t*) meshData + vertexBufferSize); @@ -845,7 +945,11 @@ void GXMRenderer::AddMeshDestroyCallback(Uint32 id, IDirect3DRMMesh* mesh) auto* ctx = static_cast(arg); auto& cache = ctx->renderer->m_meshes[ctx->id]; cache.meshGroup = nullptr; - sceClibMspaceFree(ctx->renderer->cdramPool, cache.meshData); + cdram_free(cache.meshData); + cache.meshData = nullptr; + cache.indexBuffer = nullptr; + cache.vertexBuffer = nullptr; + cache.indexCount = 0; delete ctx; }, ctx @@ -900,12 +1004,59 @@ const char* GXMRenderer::GetName() } bool razor_triggered = false; +bool razor_live_started = false; +bool razor_display_enabled = true; void GXMRenderer::StartScene() { if (sceneStarted) { return; } + + bool dpad_up = SDL_GetGamepadButton(this->gamepad, SDL_GAMEPAD_BUTTON_DPAD_UP); + bool dpad_down = SDL_GetGamepadButton(this->gamepad, SDL_GAMEPAD_BUTTON_DPAD_DOWN); + bool dpad_left = SDL_GetGamepadButton(this->gamepad, SDL_GAMEPAD_BUTTON_DPAD_LEFT); + bool dpad_right = SDL_GetGamepadButton(this->gamepad, SDL_GAMEPAD_BUTTON_DPAD_RIGHT); + + // hud display + if(with_razor_hud && dpad_up != this->button_dpad_up) { + this->button_dpad_up = dpad_up; + if(dpad_up) { + sceRazorHudSetDisplayEnabled(razor_display_enabled); + } + } + + // capture frame + if(with_razor && dpad_down != this->button_dpad_down) { + this->button_dpad_down = dpad_down; + if(dpad_down) { + sceRazorGpuCaptureSetTriggerNextFrame("ux0:/data/capture.sgx"); + SDL_Log("trigger razor"); + } + } + + // toggle live + if(with_razor_hud && dpad_left != this->button_dpad_left) { + this->button_dpad_left = dpad_left; + if(dpad_left) { + if(razor_live_started) { + sceRazorGpuLiveStop(); + razor_live_started = false; + } else { + sceRazorGpuLiveStart(); + razor_live_started = true; + } + } + } + + // trigger trace + if(with_razor_hud && dpad_right != this->button_dpad_right) { + this->button_dpad_right = dpad_right; + if(dpad_right) { + sceRazorGpuTraceTrigger(); + } + } + sceGxmBeginScene( this->context, 0, @@ -922,22 +1073,11 @@ void GXMRenderer::StartScene() // wait for this uniform buffer to become available this->activeUniformBuffer = (this->activeUniformBuffer + 1) % VITA_GXM_UNIFORM_BUFFER_COUNT; sceGxmNotificationWait(&this->fragmentNotifications[this->activeUniformBuffer]); - - // sceClibPrintf("this->activeUniformBuffer: %d notification: %d\n", this->activeUniformBuffer, - // this->fragmentNotifications[this->activeUniformBuffer].value); } -int frames = 0; + HRESULT GXMRenderer::BeginFrame() { - frames++; - if (with_razor) { - if (!razor_triggered && frames == 10) { - SDL_Log("trigger razor"); - sceRazorGpuCaptureSetTriggerNextFrame("ux0:/data/capture.sgx"); - razor_triggered = true; - } - } this->transparencyEnabled = false; this->StartScene(); diff --git a/miniwin/src/d3drm/backends/gxm/.gitignore b/miniwin/src/d3drm/backends/gxm/shaders/.gitignore similarity index 100% rename from miniwin/src/d3drm/backends/gxm/.gitignore rename to miniwin/src/d3drm/backends/gxm/shaders/.gitignore diff --git a/miniwin/src/d3drm/backends/gxm/tlsf.c b/miniwin/src/d3drm/backends/gxm/tlsf.c new file mode 100644 index 00000000..31d25bdc --- /dev/null +++ b/miniwin/src/d3drm/backends/gxm/tlsf.c @@ -0,0 +1,1264 @@ +#include +#include +#include +#include +#include +#include + +#include "tlsf.h" + +#if defined(__cplusplus) +#define tlsf_decl inline +#else +#define tlsf_decl static +#endif + +/* +** Architecture-specific bit manipulation routines. +** +** TLSF achieves O(1) cost for malloc and free operations by limiting +** the search for a free block to a free list of guaranteed size +** adequate to fulfill the request, combined with efficient free list +** queries using bitmasks and architecture-specific bit-manipulation +** routines. +** +** Most modern processors provide instructions to count leading zeroes +** in a word, find the lowest and highest set bit, etc. These +** specific implementations will be used when available, falling back +** to a reasonably efficient generic implementation. +** +** NOTE: TLSF spec relies on ffs/fls returning value 0..31. +** ffs/fls return 1-32 by default, returning 0 for error. +*/ + +/* +** Detect whether or not we are building for a 32- or 64-bit (LP/LLP) +** architecture. There is no reliable portable method at compile-time. +*/ +#if defined (__alpha__) || defined (__ia64__) || defined (__x86_64__) \ + || defined (_WIN64) || defined (__LP64__) || defined (__LLP64__) +#define TLSF_64BIT +#endif + +/* +** gcc 3.4 and above have builtin support, specialized for architecture. +** Some compilers masquerade as gcc; patchlevel test filters them out. +*/ +#if defined (__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) \ + && defined (__GNUC_PATCHLEVEL__) + +#if defined (__SNC__) +/* SNC for Playstation 3. */ + +tlsf_decl int tlsf_ffs(unsigned int word) +{ + const unsigned int reverse = word & (~word + 1); + const int bit = 32 - __builtin_clz(reverse); + return bit - 1; +} + +#else + +tlsf_decl int tlsf_ffs(unsigned int word) +{ + return __builtin_ffs(word) - 1; +} + +#endif + +tlsf_decl int tlsf_fls(unsigned int word) +{ + const int bit = word ? 32 - __builtin_clz(word) : 0; + return bit - 1; +} + +#elif defined (_MSC_VER) && (_MSC_VER >= 1400) && (defined (_M_IX86) || defined (_M_X64)) +/* Microsoft Visual C++ support on x86/X64 architectures. */ + +#include + +#pragma intrinsic(_BitScanReverse) +#pragma intrinsic(_BitScanForward) + +tlsf_decl int tlsf_fls(unsigned int word) +{ + unsigned long index; + return _BitScanReverse(&index, word) ? index : -1; +} + +tlsf_decl int tlsf_ffs(unsigned int word) +{ + unsigned long index; + return _BitScanForward(&index, word) ? index : -1; +} + +#elif defined (_MSC_VER) && defined (_M_PPC) +/* Microsoft Visual C++ support on PowerPC architectures. */ + +#include + +tlsf_decl int tlsf_fls(unsigned int word) +{ + const int bit = 32 - _CountLeadingZeros(word); + return bit - 1; +} + +tlsf_decl int tlsf_ffs(unsigned int word) +{ + const unsigned int reverse = word & (~word + 1); + const int bit = 32 - _CountLeadingZeros(reverse); + return bit - 1; +} + +#elif defined (__ARMCC_VERSION) +/* RealView Compilation Tools for ARM */ + +tlsf_decl int tlsf_ffs(unsigned int word) +{ + const unsigned int reverse = word & (~word + 1); + const int bit = 32 - __clz(reverse); + return bit - 1; +} + +tlsf_decl int tlsf_fls(unsigned int word) +{ + const int bit = word ? 32 - __clz(word) : 0; + return bit - 1; +} + +#elif defined (__ghs__) +/* Green Hills support for PowerPC */ + +#include + +tlsf_decl int tlsf_ffs(unsigned int word) +{ + const unsigned int reverse = word & (~word + 1); + const int bit = 32 - __CLZ32(reverse); + return bit - 1; +} + +tlsf_decl int tlsf_fls(unsigned int word) +{ + const int bit = word ? 32 - __CLZ32(word) : 0; + return bit - 1; +} + +#else +/* Fall back to generic implementation. */ + +tlsf_decl int tlsf_fls_generic(unsigned int word) +{ + int bit = 32; + + if (!word) bit -= 1; + if (!(word & 0xffff0000)) { word <<= 16; bit -= 16; } + if (!(word & 0xff000000)) { word <<= 8; bit -= 8; } + if (!(word & 0xf0000000)) { word <<= 4; bit -= 4; } + if (!(word & 0xc0000000)) { word <<= 2; bit -= 2; } + if (!(word & 0x80000000)) { word <<= 1; bit -= 1; } + + return bit; +} + +/* Implement ffs in terms of fls. */ +tlsf_decl int tlsf_ffs(unsigned int word) +{ + return tlsf_fls_generic(word & (~word + 1)) - 1; +} + +tlsf_decl int tlsf_fls(unsigned int word) +{ + return tlsf_fls_generic(word) - 1; +} + +#endif + +/* Possibly 64-bit version of tlsf_fls. */ +#if defined (TLSF_64BIT) +tlsf_decl int tlsf_fls_sizet(size_t size) +{ + int high = (int)(size >> 32); + int bits = 0; + if (high) + { + bits = 32 + tlsf_fls(high); + } + else + { + bits = tlsf_fls((int)size & 0xffffffff); + + } + return bits; +} +#else +#define tlsf_fls_sizet tlsf_fls +#endif + +#undef tlsf_decl + +/* +** Constants. +*/ + +/* Public constants: may be modified. */ +enum tlsf_public +{ + /* log2 of number of linear subdivisions of block sizes. Larger + ** values require more memory in the control structure. Values of + ** 4 or 5 are typical. + */ + SL_INDEX_COUNT_LOG2 = 5, +}; + +/* Private constants: do not modify. */ +enum tlsf_private +{ +#if defined (TLSF_64BIT) + /* All allocation sizes and addresses are aligned to 8 bytes. */ + ALIGN_SIZE_LOG2 = 3, +#else + /* All allocation sizes and addresses are aligned to 4 bytes. */ + ALIGN_SIZE_LOG2 = 2, +#endif + ALIGN_SIZE = (1 << ALIGN_SIZE_LOG2), + + /* + ** We support allocations of sizes up to (1 << FL_INDEX_MAX) bits. + ** However, because we linearly subdivide the second-level lists, and + ** our minimum size granularity is 4 bytes, it doesn't make sense to + ** create first-level lists for sizes smaller than SL_INDEX_COUNT * 4, + ** or (1 << (SL_INDEX_COUNT_LOG2 + 2)) bytes, as there we will be + ** trying to split size ranges into more slots than we have available. + ** Instead, we calculate the minimum threshold size, and place all + ** blocks below that size into the 0th first-level list. + */ + +#if defined (TLSF_64BIT) + /* + ** TODO: We can increase this to support larger sizes, at the expense + ** of more overhead in the TLSF structure. + */ + FL_INDEX_MAX = 32, +#else + FL_INDEX_MAX = 30, +#endif + SL_INDEX_COUNT = (1 << SL_INDEX_COUNT_LOG2), + FL_INDEX_SHIFT = (SL_INDEX_COUNT_LOG2 + ALIGN_SIZE_LOG2), + FL_INDEX_COUNT = (FL_INDEX_MAX - FL_INDEX_SHIFT + 1), + + SMALL_BLOCK_SIZE = (1 << FL_INDEX_SHIFT), +}; + +/* +** Cast and min/max macros. +*/ + +#define tlsf_cast(t, exp) ((t) (exp)) +#define tlsf_min(a, b) ((a) < (b) ? (a) : (b)) +#define tlsf_max(a, b) ((a) > (b) ? (a) : (b)) + +/* +** Set assert macro, if it has not been provided by the user. +*/ +#if !defined (tlsf_assert) +#define tlsf_assert assert +#endif + +/* +** Static assertion mechanism. +*/ + +#define _tlsf_glue2(x, y) x ## y +#define _tlsf_glue(x, y) _tlsf_glue2(x, y) +#define tlsf_static_assert(exp) \ + typedef char _tlsf_glue(static_assert, __LINE__) [(exp) ? 1 : -1] + +/* This code has been tested on 32- and 64-bit (LP/LLP) architectures. */ +tlsf_static_assert(sizeof(int) * CHAR_BIT == 32); +tlsf_static_assert(sizeof(size_t) * CHAR_BIT >= 32); +tlsf_static_assert(sizeof(size_t) * CHAR_BIT <= 64); + +/* SL_INDEX_COUNT must be <= number of bits in sl_bitmap's storage type. */ +tlsf_static_assert(sizeof(unsigned int) * CHAR_BIT >= SL_INDEX_COUNT); + +/* Ensure we've properly tuned our sizes. */ +tlsf_static_assert(ALIGN_SIZE == SMALL_BLOCK_SIZE / SL_INDEX_COUNT); + +/* +** Data structures and associated constants. +*/ + +/* +** Block header structure. +** +** There are several implementation subtleties involved: +** - The prev_phys_block field is only valid if the previous block is free. +** - The prev_phys_block field is actually stored at the end of the +** previous block. It appears at the beginning of this structure only to +** simplify the implementation. +** - The next_free / prev_free fields are only valid if the block is free. +*/ +typedef struct block_header_t +{ + /* Points to the previous physical block. */ + struct block_header_t* prev_phys_block; + + /* The size of this block, excluding the block header. */ + size_t size; + + /* Next and previous free blocks. */ + struct block_header_t* next_free; + struct block_header_t* prev_free; +} block_header_t; + +/* +** Since block sizes are always at least a multiple of 4, the two least +** significant bits of the size field are used to store the block status: +** - bit 0: whether block is busy or free +** - bit 1: whether previous block is busy or free +*/ +static const size_t block_header_free_bit = 1 << 0; +static const size_t block_header_prev_free_bit = 1 << 1; + +/* +** The size of the block header exposed to used blocks is the size field. +** The prev_phys_block field is stored *inside* the previous free block. +*/ +static const size_t block_header_overhead = sizeof(size_t); + +/* User data starts directly after the size field in a used block. */ +static const size_t block_start_offset = + offsetof(block_header_t, size) + sizeof(size_t); + +/* +** A free block must be large enough to store its header minus the size of +** the prev_phys_block field, and no larger than the number of addressable +** bits for FL_INDEX. +*/ +static const size_t block_size_min = + sizeof(block_header_t) - sizeof(block_header_t*); +static const size_t block_size_max = tlsf_cast(size_t, 1) << FL_INDEX_MAX; + + +/* The TLSF control structure. */ +typedef struct control_t +{ + /* Empty lists point at this block to indicate they are free. */ + block_header_t block_null; + + /* Bitmaps for free lists. */ + unsigned int fl_bitmap; + unsigned int sl_bitmap[FL_INDEX_COUNT]; + + /* Head of free lists. */ + block_header_t* blocks[FL_INDEX_COUNT][SL_INDEX_COUNT]; +} control_t; + +/* A type used for casting when doing pointer arithmetic. */ +typedef ptrdiff_t tlsfptr_t; + +/* +** block_header_t member functions. +*/ + +static size_t block_size(const block_header_t* block) +{ + return block->size & ~(block_header_free_bit | block_header_prev_free_bit); +} + +static void block_set_size(block_header_t* block, size_t size) +{ + const size_t oldsize = block->size; + block->size = size | (oldsize & (block_header_free_bit | block_header_prev_free_bit)); +} + +static int block_is_last(const block_header_t* block) +{ + return block_size(block) == 0; +} + +static int block_is_free(const block_header_t* block) +{ + return tlsf_cast(int, block->size & block_header_free_bit); +} + +static void block_set_free(block_header_t* block) +{ + block->size |= block_header_free_bit; +} + +static void block_set_used(block_header_t* block) +{ + block->size &= ~block_header_free_bit; +} + +static int block_is_prev_free(const block_header_t* block) +{ + return tlsf_cast(int, block->size & block_header_prev_free_bit); +} + +static void block_set_prev_free(block_header_t* block) +{ + block->size |= block_header_prev_free_bit; +} + +static void block_set_prev_used(block_header_t* block) +{ + block->size &= ~block_header_prev_free_bit; +} + +static block_header_t* block_from_ptr(const void* ptr) +{ + return tlsf_cast(block_header_t*, + tlsf_cast(unsigned char*, ptr) - block_start_offset); +} + +static void* block_to_ptr(const block_header_t* block) +{ + return tlsf_cast(void*, + tlsf_cast(unsigned char*, block) + block_start_offset); +} + +/* Return location of next block after block of given size. */ +static block_header_t* offset_to_block(const void* ptr, size_t size) +{ + return tlsf_cast(block_header_t*, tlsf_cast(tlsfptr_t, ptr) + size); +} + +/* Return location of previous block. */ +static block_header_t* block_prev(const block_header_t* block) +{ + tlsf_assert(block_is_prev_free(block) && "previous block must be free"); + return block->prev_phys_block; +} + +/* Return location of next existing block. */ +static block_header_t* block_next(const block_header_t* block) +{ + block_header_t* next = offset_to_block(block_to_ptr(block), + block_size(block) - block_header_overhead); + tlsf_assert(!block_is_last(block)); + return next; +} + +/* Link a new block with its physical neighbor, return the neighbor. */ +static block_header_t* block_link_next(block_header_t* block) +{ + block_header_t* next = block_next(block); + next->prev_phys_block = block; + return next; +} + +static void block_mark_as_free(block_header_t* block) +{ + /* Link the block to the next block, first. */ + block_header_t* next = block_link_next(block); + block_set_prev_free(next); + block_set_free(block); +} + +static void block_mark_as_used(block_header_t* block) +{ + block_header_t* next = block_next(block); + block_set_prev_used(next); + block_set_used(block); +} + +static size_t align_up(size_t x, size_t align) +{ + tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two"); + return (x + (align - 1)) & ~(align - 1); +} + +static size_t align_down(size_t x, size_t align) +{ + tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two"); + return x - (x & (align - 1)); +} + +static void* align_ptr(const void* ptr, size_t align) +{ + const tlsfptr_t aligned = + (tlsf_cast(tlsfptr_t, ptr) + (align - 1)) & ~(align - 1); + tlsf_assert(0 == (align & (align - 1)) && "must align to a power of two"); + return tlsf_cast(void*, aligned); +} + +/* +** Adjust an allocation size to be aligned to word size, and no smaller +** than internal minimum. +*/ +static size_t adjust_request_size(size_t size, size_t align) +{ + size_t adjust = 0; + if (size) + { + const size_t aligned = align_up(size, align); + + /* aligned sized must not exceed block_size_max or we'll go out of bounds on sl_bitmap */ + if (aligned < block_size_max) + { + adjust = tlsf_max(aligned, block_size_min); + } + } + return adjust; +} + +/* +** TLSF utility functions. In most cases, these are direct translations of +** the documentation found in the white paper. +*/ + +static void mapping_insert(size_t size, int* fli, int* sli) +{ + int fl, sl; + if (size < SMALL_BLOCK_SIZE) + { + /* Store small blocks in first list. */ + fl = 0; + sl = tlsf_cast(int, size) / (SMALL_BLOCK_SIZE / SL_INDEX_COUNT); + } + else + { + fl = tlsf_fls_sizet(size); + sl = tlsf_cast(int, size >> (fl - SL_INDEX_COUNT_LOG2)) ^ (1 << SL_INDEX_COUNT_LOG2); + fl -= (FL_INDEX_SHIFT - 1); + } + *fli = fl; + *sli = sl; +} + +/* This version rounds up to the next block size (for allocations) */ +static void mapping_search(size_t size, int* fli, int* sli) +{ + if (size >= SMALL_BLOCK_SIZE) + { + const size_t round = (1 << (tlsf_fls_sizet(size) - SL_INDEX_COUNT_LOG2)) - 1; + size += round; + } + mapping_insert(size, fli, sli); +} + +static block_header_t* search_suitable_block(control_t* control, int* fli, int* sli) +{ + int fl = *fli; + int sl = *sli; + + /* + ** First, search for a block in the list associated with the given + ** fl/sl index. + */ + unsigned int sl_map = control->sl_bitmap[fl] & (~0U << sl); + if (!sl_map) + { + /* No block exists. Search in the next largest first-level list. */ + const unsigned int fl_map = control->fl_bitmap & (~0U << (fl + 1)); + if (!fl_map) + { + /* No free blocks available, memory has been exhausted. */ + return 0; + } + + fl = tlsf_ffs(fl_map); + *fli = fl; + sl_map = control->sl_bitmap[fl]; + } + tlsf_assert(sl_map && "internal error - second level bitmap is null"); + sl = tlsf_ffs(sl_map); + *sli = sl; + + /* Return the first block in the free list. */ + return control->blocks[fl][sl]; +} + +/* Remove a free block from the free list.*/ +static void remove_free_block(control_t* control, block_header_t* block, int fl, int sl) +{ + block_header_t* prev = block->prev_free; + block_header_t* next = block->next_free; + tlsf_assert(prev && "prev_free field can not be null"); + tlsf_assert(next && "next_free field can not be null"); + next->prev_free = prev; + prev->next_free = next; + + /* If this block is the head of the free list, set new head. */ + if (control->blocks[fl][sl] == block) + { + control->blocks[fl][sl] = next; + + /* If the new head is null, clear the bitmap. */ + if (next == &control->block_null) + { + control->sl_bitmap[fl] &= ~(1U << sl); + + /* If the second bitmap is now empty, clear the fl bitmap. */ + if (!control->sl_bitmap[fl]) + { + control->fl_bitmap &= ~(1U << fl); + } + } + } +} + +/* Insert a free block into the free block list. */ +static void insert_free_block(control_t* control, block_header_t* block, int fl, int sl) +{ + block_header_t* current = control->blocks[fl][sl]; + tlsf_assert(current && "free list cannot have a null entry"); + tlsf_assert(block && "cannot insert a null entry into the free list"); + block->next_free = current; + block->prev_free = &control->block_null; + current->prev_free = block; + + tlsf_assert(block_to_ptr(block) == align_ptr(block_to_ptr(block), ALIGN_SIZE) + && "block not aligned properly"); + /* + ** Insert the new block at the head of the list, and mark the first- + ** and second-level bitmaps appropriately. + */ + control->blocks[fl][sl] = block; + control->fl_bitmap |= (1U << fl); + control->sl_bitmap[fl] |= (1U << sl); +} + +/* Remove a given block from the free list. */ +static void block_remove(control_t* control, block_header_t* block) +{ + int fl, sl; + mapping_insert(block_size(block), &fl, &sl); + remove_free_block(control, block, fl, sl); +} + +/* Insert a given block into the free list. */ +static void block_insert(control_t* control, block_header_t* block) +{ + int fl, sl; + mapping_insert(block_size(block), &fl, &sl); + insert_free_block(control, block, fl, sl); +} + +static int block_can_split(block_header_t* block, size_t size) +{ + return block_size(block) >= sizeof(block_header_t) + size; +} + +/* Split a block into two, the second of which is free. */ +static block_header_t* block_split(block_header_t* block, size_t size) +{ + /* Calculate the amount of space left in the remaining block. */ + block_header_t* remaining = + offset_to_block(block_to_ptr(block), size - block_header_overhead); + + const size_t remain_size = block_size(block) - (size + block_header_overhead); + + tlsf_assert(block_to_ptr(remaining) == align_ptr(block_to_ptr(remaining), ALIGN_SIZE) + && "remaining block not aligned properly"); + + tlsf_assert(block_size(block) == remain_size + size + block_header_overhead); + block_set_size(remaining, remain_size); + tlsf_assert(block_size(remaining) >= block_size_min && "block split with invalid size"); + + block_set_size(block, size); + block_mark_as_free(remaining); + + return remaining; +} + +/* Absorb a free block's storage into an adjacent previous free block. */ +static block_header_t* block_absorb(block_header_t* prev, block_header_t* block) +{ + tlsf_assert(!block_is_last(prev) && "previous block can't be last"); + /* Note: Leaves flags untouched. */ + prev->size += block_size(block) + block_header_overhead; + block_link_next(prev); + return prev; +} + +/* Merge a just-freed block with an adjacent previous free block. */ +static block_header_t* block_merge_prev(control_t* control, block_header_t* block) +{ + if (block_is_prev_free(block)) + { + block_header_t* prev = block_prev(block); + tlsf_assert(prev && "prev physical block can't be null"); + tlsf_assert(block_is_free(prev) && "prev block is not free though marked as such"); + block_remove(control, prev); + block = block_absorb(prev, block); + } + + return block; +} + +/* Merge a just-freed block with an adjacent free block. */ +static block_header_t* block_merge_next(control_t* control, block_header_t* block) +{ + block_header_t* next = block_next(block); + tlsf_assert(next && "next physical block can't be null"); + + if (block_is_free(next)) + { + tlsf_assert(!block_is_last(block) && "previous block can't be last"); + block_remove(control, next); + block = block_absorb(block, next); + } + + return block; +} + +/* Trim any trailing block space off the end of a block, return to pool. */ +static void block_trim_free(control_t* control, block_header_t* block, size_t size) +{ + tlsf_assert(block_is_free(block) && "block must be free"); + if (block_can_split(block, size)) + { + block_header_t* remaining_block = block_split(block, size); + block_link_next(block); + block_set_prev_free(remaining_block); + block_insert(control, remaining_block); + } +} + +/* Trim any trailing block space off the end of a used block, return to pool. */ +static void block_trim_used(control_t* control, block_header_t* block, size_t size) +{ + tlsf_assert(!block_is_free(block) && "block must be used"); + if (block_can_split(block, size)) + { + /* If the next block is free, we must coalesce. */ + block_header_t* remaining_block = block_split(block, size); + block_set_prev_used(remaining_block); + + remaining_block = block_merge_next(control, remaining_block); + block_insert(control, remaining_block); + } +} + +static block_header_t* block_trim_free_leading(control_t* control, block_header_t* block, size_t size) +{ + block_header_t* remaining_block = block; + if (block_can_split(block, size)) + { + /* We want the 2nd block. */ + remaining_block = block_split(block, size - block_header_overhead); + block_set_prev_free(remaining_block); + + block_link_next(block); + block_insert(control, block); + } + + return remaining_block; +} + +static block_header_t* block_locate_free(control_t* control, size_t size) +{ + int fl = 0, sl = 0; + block_header_t* block = 0; + + if (size) + { + mapping_search(size, &fl, &sl); + + /* + ** mapping_search can futz with the size, so for excessively large sizes it can sometimes wind up + ** with indices that are off the end of the block array. + ** So, we protect against that here, since this is the only callsite of mapping_search. + ** Note that we don't need to check sl, since it comes from a modulo operation that guarantees it's always in range. + */ + if (fl < FL_INDEX_COUNT) + { + block = search_suitable_block(control, &fl, &sl); + } + } + + if (block) + { + tlsf_assert(block_size(block) >= size); + remove_free_block(control, block, fl, sl); + } + + return block; +} + +static void* block_prepare_used(control_t* control, block_header_t* block, size_t size) +{ + void* p = 0; + if (block) + { + tlsf_assert(size && "size must be non-zero"); + block_trim_free(control, block, size); + block_mark_as_used(block); + p = block_to_ptr(block); + } + return p; +} + +/* Clear structure and point all empty lists at the null block. */ +static void control_construct(control_t* control) +{ + int i, j; + + control->block_null.next_free = &control->block_null; + control->block_null.prev_free = &control->block_null; + + control->fl_bitmap = 0; + for (i = 0; i < FL_INDEX_COUNT; ++i) + { + control->sl_bitmap[i] = 0; + for (j = 0; j < SL_INDEX_COUNT; ++j) + { + control->blocks[i][j] = &control->block_null; + } + } +} + +/* +** Debugging utilities. +*/ + +typedef struct integrity_t +{ + int prev_status; + int status; +} integrity_t; + +#define tlsf_insist(x) { tlsf_assert(x); if (!(x)) { status--; } } + +static void integrity_walker(void* ptr, size_t size, int used, void* user) +{ + block_header_t* block = block_from_ptr(ptr); + integrity_t* integ = tlsf_cast(integrity_t*, user); + const int this_prev_status = block_is_prev_free(block) ? 1 : 0; + const int this_status = block_is_free(block) ? 1 : 0; + const size_t this_block_size = block_size(block); + + int status = 0; + (void)used; + tlsf_insist(integ->prev_status == this_prev_status && "prev status incorrect"); + tlsf_insist(size == this_block_size && "block size incorrect"); + + integ->prev_status = this_status; + integ->status += status; +} + +int tlsf_check(tlsf_t tlsf) +{ + int i, j; + + control_t* control = tlsf_cast(control_t*, tlsf); + int status = 0; + + /* Check that the free lists and bitmaps are accurate. */ + for (i = 0; i < FL_INDEX_COUNT; ++i) + { + for (j = 0; j < SL_INDEX_COUNT; ++j) + { + const int fl_map = control->fl_bitmap & (1U << i); + const int sl_list = control->sl_bitmap[i]; + const int sl_map = sl_list & (1U << j); + const block_header_t* block = control->blocks[i][j]; + + /* Check that first- and second-level lists agree. */ + if (!fl_map) + { + tlsf_insist(!sl_map && "second-level map must be null"); + } + + if (!sl_map) + { + tlsf_insist(block == &control->block_null && "block list must be null"); + continue; + } + + /* Check that there is at least one free block. */ + tlsf_insist(sl_list && "no free blocks in second-level map"); + tlsf_insist(block != &control->block_null && "block should not be null"); + + while (block != &control->block_null) + { + int fli, sli; + tlsf_insist(block_is_free(block) && "block should be free"); + tlsf_insist(!block_is_prev_free(block) && "blocks should have coalesced"); + tlsf_insist(!block_is_free(block_next(block)) && "blocks should have coalesced"); + tlsf_insist(block_is_prev_free(block_next(block)) && "block should be free"); + tlsf_insist(block_size(block) >= block_size_min && "block not minimum size"); + + mapping_insert(block_size(block), &fli, &sli); + tlsf_insist(fli == i && sli == j && "block size indexed in wrong list"); + block = block->next_free; + } + } + } + + return status; +} + +#undef tlsf_insist + +static void default_walker(void* ptr, size_t size, int used, void* user) +{ + (void)user; + printf("\t%p %s size: %x (%p)\n", ptr, used ? "used" : "free", (unsigned int)size, block_from_ptr(ptr)); +} + +void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user) +{ + tlsf_walker pool_walker = walker ? walker : default_walker; + block_header_t* block = + offset_to_block(pool, -(int)block_header_overhead); + + while (block && !block_is_last(block)) + { + pool_walker( + block_to_ptr(block), + block_size(block), + !block_is_free(block), + user); + block = block_next(block); + } +} + +size_t tlsf_block_size(void* ptr) +{ + size_t size = 0; + if (ptr) + { + const block_header_t* block = block_from_ptr(ptr); + size = block_size(block); + } + return size; +} + +int tlsf_check_pool(pool_t pool) +{ + /* Check that the blocks are physically correct. */ + integrity_t integ = { 0, 0 }; + tlsf_walk_pool(pool, integrity_walker, &integ); + + return integ.status; +} + +/* +** Size of the TLSF structures in a given memory block passed to +** tlsf_create, equal to the size of a control_t +*/ +size_t tlsf_size(void) +{ + return sizeof(control_t); +} + +size_t tlsf_align_size(void) +{ + return ALIGN_SIZE; +} + +size_t tlsf_block_size_min(void) +{ + return block_size_min; +} + +size_t tlsf_block_size_max(void) +{ + return block_size_max; +} + +/* +** Overhead of the TLSF structures in a given memory block passed to +** tlsf_add_pool, equal to the overhead of a free block and the +** sentinel block. +*/ +size_t tlsf_pool_overhead(void) +{ + return 2 * block_header_overhead; +} + +size_t tlsf_alloc_overhead(void) +{ + return block_header_overhead; +} + +pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes) +{ + block_header_t* block; + block_header_t* next; + + const size_t pool_overhead = tlsf_pool_overhead(); + const size_t pool_bytes = align_down(bytes - pool_overhead, ALIGN_SIZE); + + if (((ptrdiff_t)mem % ALIGN_SIZE) != 0) + { + printf("tlsf_add_pool: Memory must be aligned by %u bytes.\n", + (unsigned int)ALIGN_SIZE); + return 0; + } + + if (pool_bytes < block_size_min || pool_bytes > block_size_max) + { +#if defined (TLSF_64BIT) + printf("tlsf_add_pool: Memory size must be between 0x%x and 0x%x00 bytes.\n", + (unsigned int)(pool_overhead + block_size_min), + (unsigned int)((pool_overhead + block_size_max) / 256)); +#else + printf("tlsf_add_pool: Memory size must be between %u and %u bytes.\n", + (unsigned int)(pool_overhead + block_size_min), + (unsigned int)(pool_overhead + block_size_max)); +#endif + return 0; + } + + /* + ** Create the main free block. Offset the start of the block slightly + ** so that the prev_phys_block field falls outside of the pool - + ** it will never be used. + */ + block = offset_to_block(mem, -(tlsfptr_t)block_header_overhead); + block_set_size(block, pool_bytes); + block_set_free(block); + block_set_prev_used(block); + block_insert(tlsf_cast(control_t*, tlsf), block); + + /* Split the block to create a zero-size sentinel block. */ + next = block_link_next(block); + block_set_size(next, 0); + block_set_used(next); + block_set_prev_free(next); + + return mem; +} + +void tlsf_remove_pool(tlsf_t tlsf, pool_t pool) +{ + control_t* control = tlsf_cast(control_t*, tlsf); + block_header_t* block = offset_to_block(pool, -(int)block_header_overhead); + + int fl = 0, sl = 0; + + tlsf_assert(block_is_free(block) && "block should be free"); + tlsf_assert(!block_is_free(block_next(block)) && "next block should not be free"); + tlsf_assert(block_size(block_next(block)) == 0 && "next block size should be zero"); + + mapping_insert(block_size(block), &fl, &sl); + remove_free_block(control, block, fl, sl); +} + +/* +** TLSF main interface. +*/ + +#if _DEBUG +int test_ffs_fls() +{ + /* Verify ffs/fls work properly. */ + int rv = 0; + rv += (tlsf_ffs(0) == -1) ? 0 : 0x1; + rv += (tlsf_fls(0) == -1) ? 0 : 0x2; + rv += (tlsf_ffs(1) == 0) ? 0 : 0x4; + rv += (tlsf_fls(1) == 0) ? 0 : 0x8; + rv += (tlsf_ffs(0x80000000) == 31) ? 0 : 0x10; + rv += (tlsf_ffs(0x80008000) == 15) ? 0 : 0x20; + rv += (tlsf_fls(0x80000008) == 31) ? 0 : 0x40; + rv += (tlsf_fls(0x7FFFFFFF) == 30) ? 0 : 0x80; + +#if defined (TLSF_64BIT) + rv += (tlsf_fls_sizet(0x80000000) == 31) ? 0 : 0x100; + rv += (tlsf_fls_sizet(0x100000000) == 32) ? 0 : 0x200; + rv += (tlsf_fls_sizet(0xffffffffffffffff) == 63) ? 0 : 0x400; +#endif + + if (rv) + { + printf("test_ffs_fls: %x ffs/fls tests failed.\n", rv); + } + return rv; +} +#endif + +tlsf_t tlsf_create(void* mem) +{ +#if _DEBUG + if (test_ffs_fls()) + { + return 0; + } +#endif + + if (((tlsfptr_t)mem % ALIGN_SIZE) != 0) + { + printf("tlsf_create: Memory must be aligned to %u bytes.\n", + (unsigned int)ALIGN_SIZE); + return 0; + } + + control_construct(tlsf_cast(control_t*, mem)); + + return tlsf_cast(tlsf_t, mem); +} + +tlsf_t tlsf_create_with_pool(void* mem, size_t bytes) +{ + tlsf_t tlsf = tlsf_create(mem); + tlsf_add_pool(tlsf, (char*)mem + tlsf_size(), bytes - tlsf_size()); + return tlsf; +} + +void tlsf_destroy(tlsf_t tlsf) +{ + /* Nothing to do. */ + (void)tlsf; +} + +pool_t tlsf_get_pool(tlsf_t tlsf) +{ + return tlsf_cast(pool_t, (char*)tlsf + tlsf_size()); +} + +void* tlsf_malloc(tlsf_t tlsf, size_t size) +{ + control_t* control = tlsf_cast(control_t*, tlsf); + const size_t adjust = adjust_request_size(size, ALIGN_SIZE); + block_header_t* block = block_locate_free(control, adjust); + return block_prepare_used(control, block, adjust); +} + +void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t size) +{ + control_t* control = tlsf_cast(control_t*, tlsf); + const size_t adjust = adjust_request_size(size, ALIGN_SIZE); + + /* + ** We must allocate an additional minimum block size bytes so that if + ** our free block will leave an alignment gap which is smaller, we can + ** trim a leading free block and release it back to the pool. We must + ** do this because the previous physical block is in use, therefore + ** the prev_phys_block field is not valid, and we can't simply adjust + ** the size of that block. + */ + const size_t gap_minimum = sizeof(block_header_t); + const size_t size_with_gap = adjust_request_size(adjust + align + gap_minimum, align); + + /* + ** If alignment is less than or equals base alignment, we're done. + ** If we requested 0 bytes, return null, as tlsf_malloc(0) does. + */ + const size_t aligned_size = (adjust && align > ALIGN_SIZE) ? size_with_gap : adjust; + + block_header_t* block = block_locate_free(control, aligned_size); + + /* This can't be a static assert. */ + tlsf_assert(sizeof(block_header_t) == block_size_min + block_header_overhead); + + if (block) + { + void* ptr = block_to_ptr(block); + void* aligned = align_ptr(ptr, align); + size_t gap = tlsf_cast(size_t, + tlsf_cast(tlsfptr_t, aligned) - tlsf_cast(tlsfptr_t, ptr)); + + /* If gap size is too small, offset to next aligned boundary. */ + if (gap && gap < gap_minimum) + { + const size_t gap_remain = gap_minimum - gap; + const size_t offset = tlsf_max(gap_remain, align); + const void* next_aligned = tlsf_cast(void*, + tlsf_cast(tlsfptr_t, aligned) + offset); + + aligned = align_ptr(next_aligned, align); + gap = tlsf_cast(size_t, + tlsf_cast(tlsfptr_t, aligned) - tlsf_cast(tlsfptr_t, ptr)); + } + + if (gap) + { + tlsf_assert(gap >= gap_minimum && "gap size too small"); + block = block_trim_free_leading(control, block, gap); + } + } + + return block_prepare_used(control, block, adjust); +} + +void tlsf_free(tlsf_t tlsf, void* ptr) +{ + /* Don't attempt to free a NULL pointer. */ + if (ptr) + { + control_t* control = tlsf_cast(control_t*, tlsf); + block_header_t* block = block_from_ptr(ptr); + tlsf_assert(!block_is_free(block) && "block already marked as free"); + block_mark_as_free(block); + block = block_merge_prev(control, block); + block = block_merge_next(control, block); + block_insert(control, block); + } +} + +/* +** The TLSF block information provides us with enough information to +** provide a reasonably intelligent implementation of realloc, growing or +** shrinking the currently allocated block as required. +** +** This routine handles the somewhat esoteric edge cases of realloc: +** - a non-zero size with a null pointer will behave like malloc +** - a zero size with a non-null pointer will behave like free +** - a request that cannot be satisfied will leave the original buffer +** untouched +** - an extended buffer size will leave the newly-allocated area with +** contents undefined +*/ +void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size) +{ + control_t* control = tlsf_cast(control_t*, tlsf); + void* p = 0; + + /* Zero-size requests are treated as free. */ + if (ptr && size == 0) + { + tlsf_free(tlsf, ptr); + } + /* Requests with NULL pointers are treated as malloc. */ + else if (!ptr) + { + p = tlsf_malloc(tlsf, size); + } + else + { + block_header_t* block = block_from_ptr(ptr); + block_header_t* next = block_next(block); + + const size_t cursize = block_size(block); + const size_t combined = cursize + block_size(next) + block_header_overhead; + const size_t adjust = adjust_request_size(size, ALIGN_SIZE); + + tlsf_assert(!block_is_free(block) && "block already marked as free"); + + /* + ** If the next block is used, or when combined with the current + ** block, does not offer enough space, we must reallocate and copy. + */ + if (adjust > cursize && (!block_is_free(next) || adjust > combined)) + { + p = tlsf_malloc(tlsf, size); + if (p) + { + const size_t minsize = tlsf_min(cursize, size); + memcpy(p, ptr, minsize); + tlsf_free(tlsf, ptr); + } + } + else + { + /* Do we need to expand to the next block? */ + if (adjust > cursize) + { + block_merge_next(control, block); + block_mark_as_used(block); + } + + /* Trim the resulting block and return the original pointer. */ + block_trim_used(control, block, adjust); + p = ptr; + } + } + + return p; +} \ No newline at end of file diff --git a/miniwin/src/d3drm/backends/gxm/tlsf.h b/miniwin/src/d3drm/backends/gxm/tlsf.h new file mode 100644 index 00000000..7d58f69a --- /dev/null +++ b/miniwin/src/d3drm/backends/gxm/tlsf.h @@ -0,0 +1,90 @@ +#ifndef INCLUDED_tlsf +#define INCLUDED_tlsf + +/* +** Two Level Segregated Fit memory allocator, version 3.1. +** Written by Matthew Conte +** http://tlsf.baisoku.org +** +** Based on the original documentation by Miguel Masmano: +** http://www.gii.upv.es/tlsf/main/docs +** +** This implementation was written to the specification +** of the document, therefore no GPL restrictions apply. +** +** Copyright (c) 2006-2016, Matthew Conte +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** * Neither the name of the copyright holder nor the +** names of its contributors may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL MATTHEW CONTE BE LIABLE FOR ANY +** DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#include + +#if defined(__cplusplus) +extern "C" { +#endif + +/* tlsf_t: a TLSF structure. Can contain 1 to N pools. */ +/* pool_t: a block of memory that TLSF can manage. */ +typedef void* tlsf_t; +typedef void* pool_t; + +/* Create/destroy a memory pool. */ +tlsf_t tlsf_create(void* mem); +tlsf_t tlsf_create_with_pool(void* mem, size_t bytes); +void tlsf_destroy(tlsf_t tlsf); +pool_t tlsf_get_pool(tlsf_t tlsf); + +/* Add/remove memory pools. */ +pool_t tlsf_add_pool(tlsf_t tlsf, void* mem, size_t bytes); +void tlsf_remove_pool(tlsf_t tlsf, pool_t pool); + +/* malloc/memalign/realloc/free replacements. */ +void* tlsf_malloc(tlsf_t tlsf, size_t bytes); +void* tlsf_memalign(tlsf_t tlsf, size_t align, size_t bytes); +void* tlsf_realloc(tlsf_t tlsf, void* ptr, size_t size); +void tlsf_free(tlsf_t tlsf, void* ptr); + +/* Returns internal block size, not original request size */ +size_t tlsf_block_size(void* ptr); + +/* Overheads/limits of internal structures. */ +size_t tlsf_size(void); +size_t tlsf_align_size(void); +size_t tlsf_block_size_min(void); +size_t tlsf_block_size_max(void); +size_t tlsf_pool_overhead(void); +size_t tlsf_alloc_overhead(void); + +/* Debugging. */ +typedef void (*tlsf_walker)(void* ptr, size_t size, int used, void* user); +void tlsf_walk_pool(pool_t pool, tlsf_walker walker, void* user); +/* Returns nonzero if any internal consistency check fails. */ +int tlsf_check(tlsf_t tlsf); +int tlsf_check_pool(pool_t pool); + +#if defined(__cplusplus) +}; +#endif + +#endif \ No newline at end of file diff --git a/miniwin/src/internal/d3drmrenderer_gxm.h b/miniwin/src/internal/d3drmrenderer_gxm.h index ea2110cd..895a839e 100644 --- a/miniwin/src/internal/d3drmrenderer_gxm.h +++ b/miniwin/src/internal/d3drmrenderer_gxm.h @@ -12,6 +12,8 @@ #include #include +#include "gxm_memory.h" + DEFINE_GUID(GXM_GUID, 0x682656F3, 0x0000, 0x0000, 0x00, 0x00, 0x00, 0x00, 0x00, 0x47, 0x58, 0x4D); #define VITA_GXM_DISPLAY_BUFFER_COUNT 3 @@ -21,7 +23,6 @@ struct GXMTextureCacheEntry { IDirect3DRMTexture* texture; Uint32 version; SceGxmTexture gxmTexture; - size_t textureSize; }; struct GXMMeshCacheEntry { @@ -72,8 +73,6 @@ typedef struct GXMRendererContext { void* vertexRingBuffer; void* fragmentRingBuffer; void* fragmentUsseRingBuffer; - - SceClibMspace cdramPool; void* contextHostMem; SceGxmContext* context; @@ -159,7 +158,6 @@ class GXMRenderer : public Direct3DRMRenderer { SceGxmContext* context; SceGxmShaderPatcher* shaderPatcher; - SceClibMspace cdramPool; SceGxmRenderTarget* renderTarget; void* displayBuffers[VITA_GXM_DISPLAY_BUFFER_COUNT]; @@ -212,6 +210,14 @@ class GXMRenderer : public Direct3DRMRenderer { SceGxmNotification vertexNotifications[VITA_GXM_UNIFORM_BUFFER_COUNT]; SceGxmNotification fragmentNotifications[VITA_GXM_UNIFORM_BUFFER_COUNT]; + SDL_Gamepad* gamepad; + + bool button_dpad_up; + bool button_dpad_down; + bool button_dpad_left; + bool button_dpad_right; + + bool m_initialized = false; };