Skip to content
This repository has been archived by the owner on Apr 18, 2022. It is now read-only.

Commit

Permalink
Fixed Basic MSAA x4 Support
Browse files Browse the repository at this point in the history
  • Loading branch information
SonicMastr committed Dec 8, 2020
1 parent 6e833aa commit 35e2220
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 10 deletions.
3 changes: 2 additions & 1 deletion include/hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@
#include "../include/pib.h"
#include <taihen.h>

#define NUM_HOOKS 19
#define NUM_HOOKS 20

extern tai_hook_ref_t hookRef[NUM_HOOKS];
extern SceUID hook[NUM_HOOKS];
extern int customResolutionMode;
extern tai_module_info_t modInfo;
extern int systemMode;
extern int isCreatingSurface;

void loadHooks(PibOptions options);
void releaseHooks(void);
Expand Down
7 changes: 7 additions & 0 deletions include/patches.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,11 @@ SceGxmErrorCode sceGxmDepthStencilSurfaceInit_msaaPatch(SceGxmDepthStencilSurfac
uint32_t strideInSamples,
void *depthData,
void *stencilData);
SceGxmErrorCode sceGxmShaderPatcherCreateFragmentProgram_msaaPatch(SceGxmShaderPatcher *shaderPatcher,
SceGxmShaderPatcherId programId,
SceGxmOutputRegisterFormat outputFormat,
SceGxmMultisampleMode multisampleMode,
const SceGxmBlendInfo *blendInfo,
const SceGxmProgram *vertexProgram,
SceGxmFragmentProgram **fragmentProgram);
#endif /* PATCHES_H_ */
9 changes: 5 additions & 4 deletions src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,10 @@ void loadHooks(PibOptions options)
hook[6] = taiHookFunctionOffset(&hookRef[6], modInfo.modid, 0, 0x158F8, 1, pglDisplaySetSwapInterval_intervalPatch);
hook[7] = taiHookFunctionImport(&hookRef[7], modInfo.name, 0x5ED8F994, 0x5795E898, sceDisplayWaitVblankStart_intervalPatch);
LOG("Swap interval Patch: 0x%08x\nWaitVblankStart Patch: 0x%08X\n", hook[5], hook[6]);
if ((options & PIB_SYSTEM_MODE) || (options & PIB_ENABLE_MSAA))
if ((options & PIB_SYSTEM_MODE) || (options & PIB_ENABLE_MSAA)) {
hook[8] = taiHookFunctionOffset(&hookRef[8], modInfo.modid, 0, 0x17d24, 1, pglMemoryAllocAlign_patch);
LOG("pglMemoryAllocAlign Patch: 0x%08x\n", hook[8]);
hook[10] = taiHookFunctionOffset(&hookRef[10], modInfo.modid, 0, 0x33074, 1, pglPlatformSurfaceCreateWindow_detect);
}
if (options & PIB_SYSTEM_MODE) {
systemMode = 1;
uint8_t cbnz_opcode = 0xB9;
Expand All @@ -67,7 +68,6 @@ void loadHooks(PibOptions options)
taiInjectData(modInfo.modid, 0, 0x2D2C0, &mem_mode_two, sizeof(mem_mode_two)); // Patch pglVitaMemoryAlloc to always use MAIN memblock
taiInjectData(modInfo.modid, 0, 0x2D1DC, &mem_mode_two, sizeof(mem_mode_two)); //
hook[9] = taiHookFunctionImport(&hookRef[9], modInfo.name, 0xF76B66BD, 0xB0F1E4EC, sceGxmInitialize_patch);
hook[10] = taiHookFunctionOffset(&hookRef[10], modInfo.modid, 0, 0x33074, 1, pglPlatformSurfaceCreateWindow_detect);
hook[11] = taiHookFunctionImport(&hookRef[11], modInfo.name, 0xF76B66BD, 0x6A6013E1, sceGxmSyncObjectCreate_patch);
hook[12] = taiHookFunctionOffset(&hookRef[12], modInfo.modid, 0, 0x2A85A, 1, pglPlatformContextBeginFrame_patch);
hook[13] = taiHookFunctionOffset(&hookRef[13], modInfo.modid, 0, 0x33902, 1, pglPlatformSurfaceSwap_patch);
Expand All @@ -77,7 +77,8 @@ void loadHooks(PibOptions options)
if (options & PIB_ENABLE_MSAA) {
hook[16] = taiHookFunctionImport(&hookRef[16], modInfo.name, 0xF76B66BD, 0xED0F6E25, sceGxmColorSurfaceInit_msaaPatch);
hook[17] = taiHookFunctionImport(&hookRef[17], modInfo.name, 0xF76B66BD, 0x207AF96B, sceGxmCreateRenderTarget_msaaPatch);
hook[18] = taiHookFunctionImport(&hookRef[18], modInfo.name, 0xF76B66BD, 0xCA9D41D1, sceGxmCreateRenderTarget_msaaPatch);
hook[18] = taiHookFunctionImport(&hookRef[18], modInfo.name, 0xF76B66BD, 0xCA9D41D1, sceGxmDepthStencilSurfaceInit_msaaPatch);
hook[19] = taiHookFunctionImport(&hookRef[19], modInfo.name, 0xF76B66BD, 0x4ED2E49D, sceGxmShaderPatcherCreateFragmentProgram_msaaPatch);
LOG("MSAA ENABLED!\n");
}
}
Expand Down
19 changes: 16 additions & 3 deletions src/patches.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ SceGxmErrorCode sceGxmCreateRenderTarget_msaaPatch(const SceGxmRenderTargetParam
renderTargetParams.flags = 0;
renderTargetParams.width = params->width;
renderTargetParams.height = params->height;
renderTargetParams.multisampleMode = SCE_GXM_MULTISAMPLE_4X;
renderTargetParams.multisampleMode = isCreatingSurface ? SCE_GXM_MULTISAMPLE_4X : SCE_GXM_MULTISAMPLE_NONE;
renderTargetParams.scenesPerFrame = 1;
renderTargetParams.multisampleLocations = 0;
renderTargetParams.driverMemBlock = -1;
Expand All @@ -193,6 +193,19 @@ SceGxmErrorCode sceGxmDepthStencilSurfaceInit_msaaPatch(SceGxmDepthStencilSurfac
void *depthData,
void *stencilData)
{
strideInSamples *= 2;
if (isCreatingSurface)
strideInSamples *= 2;
return TAI_CONTINUE(SceGxmErrorCode, hookRef[18], surface, depthStencilFormat, surfaceType, strideInSamples, depthData, stencilData);
}
}

SceGxmErrorCode sceGxmShaderPatcherCreateFragmentProgram_msaaPatch(SceGxmShaderPatcher *shaderPatcher,
SceGxmShaderPatcherId programId,
SceGxmOutputRegisterFormat outputFormat,
SceGxmMultisampleMode multisampleMode,
const SceGxmBlendInfo *blendInfo,
const SceGxmProgram *vertexProgram,
SceGxmFragmentProgram **fragmentProgram)
{
multisampleMode = SCE_GXM_MULTISAMPLE_4X;
return TAI_CONTINUE(SceGxmErrorCode, hookRef[19], shaderPatcher, programId, outputFormat, multisampleMode, blendInfo, vertexProgram, fragmentProgram);
}
5 changes: 3 additions & 2 deletions src/sysmodepatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ typedef struct SceSharedFbInfo { // size is 0x58
static SceSharedFbInfo info;
static SceUID shfb_id;
static void *displayBufferData[2];
static int isCreatingSurface, isDestroyingSurface, currentContext, framebegun = 0;
static int isDestroyingSurface, currentContext, framebegun = 0;
static unsigned int bufferDataIndex;
int isCreatingSurface;

SceGxmErrorCode sceGxmInitialize_patch(const SceGxmInitializeParams *params)
{
Expand Down Expand Up @@ -96,7 +97,7 @@ unsigned int pglMemoryAllocAlign_patch(int memoryType, int size, int unused, int
memory[0] = displayBufferData[bufferDataIndex];
return 0;
}
if (!systemMode && memoryType == 5)
if (!systemMode && memoryType == 5 && isCreatingSurface)
{
size *= 4; // For MSAA
}
Expand Down

0 comments on commit 35e2220

Please sign in to comment.