Skip to content

Commit

Permalink
finished Overclock
Browse files Browse the repository at this point in the history
  • Loading branch information
darkxex committed Feb 5, 2022
1 parent 86f41f7 commit c815492
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 127 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/
build-win32/
nxmp/
nxmp.*
compile.bat
126 changes: 15 additions & 111 deletions include/SwitchSys.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@

//
// Created by cpasjuste on 26/11/18.
//

#ifndef CROSS2D_SWITCH_CLOCKS_H
#define CROSS2D_SWITCH_CLOCKS_H
#include <stdio.h>
class SwitchSys {
#include <switch.h>

namespace c2d {

class SwitchSys {

public:

Expand Down Expand Up @@ -29,7 +40,8 @@ class SwitchSys {
Gpu = PcvModule_GPU,
Emc = PcvModule_EMC
};

static void maxClock();
static void defaultClock(int stock_cpu_clock_temp,int stock_gpu_clock_temp,int stock_emc_clock_temp);
static int getClock(const Module &module, bool stockClocks = false);

static bool setClock(const Module &module, int hz);
Expand All @@ -38,114 +50,6 @@ class SwitchSys {
static int stock_gpu_clock;
static int stock_emc_clock;
};

int SwitchSys::stock_cpu_clock = 0;
int SwitchSys::stock_gpu_clock = 0;
int SwitchSys::stock_emc_clock = 0;

int stock_cpu_clock_temp = 0;
int stock_gpu_clock_temp = 0;
int stock_emc_clock_temp = 0;



bool SwitchSys::setClock(const SwitchSys::Module &module, int hz) {

int new_hz = hz;
int bus_id = (int) module;
bool is_old = hosversionBefore(8, 0, 0);

switch (module) {
case SwitchSys::Module::Cpu:
new_hz = new_hz <= 0 ? stock_cpu_clock : new_hz;
bus_id = is_old ? (int) module : (int) PcvModuleId_CpuBus;
break;
case SwitchSys::Module::Gpu:
new_hz = new_hz <= 0 ? stock_gpu_clock : new_hz;
bus_id = is_old ? (int) module : (int) PcvModuleId_GPU;
break;
case SwitchSys::Module::Emc:
new_hz = new_hz <= 0 ? stock_emc_clock : new_hz;
bus_id = is_old ? (int) module : (int) PcvModuleId_EMC;
break;
default:
break;
}

if (is_old) {
if (R_SUCCEEDED(pcvSetClockRate((PcvModule) bus_id, (u32) new_hz))) {
return true;
}
} else {
ClkrstSession session = {0};
clkrstOpenSession(&session, (PcvModuleId) bus_id, 3);
clkrstSetClockRate(&session, hz);
clkrstCloseSession(&session);
}


return false;
}
int SwitchSys::getClock(const SwitchSys::Module &module, bool stockClocks) {

u32 hz = 0;
int bus_id = 0;
bool is_old = hosversionBefore(8, 0, 0);

if (stockClocks) {
switch (module) {
case SwitchSys::Module::Cpu:
return stock_cpu_clock;
case SwitchSys::Module::Gpu:
return stock_gpu_clock;
case SwitchSys::Module::Emc:
return stock_emc_clock;
default:
return 0;
}
}

switch (module) {
case SwitchSys::Module::Cpu:
bus_id = is_old ? (int) module : (int) PcvModuleId_CpuBus;
break;
case SwitchSys::Module::Gpu:
bus_id = is_old ? (int) module : (int) PcvModuleId_GPU;
break;
case SwitchSys::Module::Emc:
bus_id = is_old ? (int) module : (int) PcvModuleId_EMC;
break;
default:
break;
}

if (hosversionBefore(8, 0, 0)) {
pcvGetClockRate((PcvModule) bus_id, &hz);
} else {
ClkrstSession session = {0};
clkrstOpenSession(&session, (PcvModuleId) bus_id, 3);
clkrstGetClockRate(&session, &hz);
clkrstCloseSession(&session);
}


return (int) hz;
}

void maxClock()
{ int clock_old = SwitchSys::getClock(SwitchSys::Module::Cpu);
SwitchSys::setClock(SwitchSys::Module::Cpu, (int) SwitchSys::CPUClock::Max);
SwitchSys::setClock(SwitchSys::Module::Gpu, (int) SwitchSys::GPUClock::Max);
SwitchSys::setClock(SwitchSys::Module::Emc, (int) SwitchSys::EMCClock::Max);
printf("setting max cpu speed (old: %i, new: %i)\n",
clock_old, SwitchSys::getClock(SwitchSys::Module::Cpu));}

void defaultClock(int stock_cpu_clock_temp,int stock_gpu_clock_temp,int stock_emc_clock_temp)
{
int clock_old = SwitchSys::getClock(SwitchSys::Module::Cpu);
SwitchSys::setClock(SwitchSys::Module::Cpu, (int) stock_cpu_clock_temp);
SwitchSys::setClock(SwitchSys::Module::Gpu, (int) stock_gpu_clock_temp);
SwitchSys::setClock(SwitchSys::Module::Emc, (int) stock_emc_clock_temp);
printf("restoring cpu speed (old: %i, new: %i)\n",
clock_old, SwitchSys::getClock(SwitchSys::Module::Cpu));
}
#endif //CROSS2D_SWITCH_CLOCKS_H
2 changes: 1 addition & 1 deletion include/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ typedef struct {
int playershowcontrols = false;
int playershowstats = false;
bool masterlock = false;

bool clockoc = false;
bool first_item;
bool focus;
int fileHoveredidx = 0;
Expand Down
119 changes: 119 additions & 0 deletions source/SwitchSys.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
//
// Created by cpasjuste on 26/11/18.
//

#include "SwitchSys.h"

using namespace c2d;

int SwitchSys::stock_cpu_clock = 0;
int SwitchSys::stock_gpu_clock = 0;
int SwitchSys::stock_emc_clock = 0;

int SwitchSys::getClock(const SwitchSys::Module &module, bool stockClocks) {

u32 hz = 0;


int bus_id = 0;
bool is_old = hosversionBefore(8, 0, 0);

if (stockClocks) {
switch (module) {
case SwitchSys::Module::Cpu:
return stock_cpu_clock;
case SwitchSys::Module::Gpu:
return stock_gpu_clock;
case SwitchSys::Module::Emc:
return stock_emc_clock;
default:
return 0;
}
}

switch (module) {
case SwitchSys::Module::Cpu:
bus_id = is_old ? (int) module : (int) PcvModuleId_CpuBus;
break;
case SwitchSys::Module::Gpu:
bus_id = is_old ? (int) module : (int) PcvModuleId_GPU;
break;
case SwitchSys::Module::Emc:
bus_id = is_old ? (int) module : (int) PcvModuleId_EMC;
break;
default:
break;
}

if (hosversionBefore(8, 0, 0)) {
pcvGetClockRate((PcvModule) bus_id, &hz);
} else {
ClkrstSession session = {0};
clkrstOpenSession(&session, (PcvModuleId) bus_id, 3);
clkrstGetClockRate(&session, &hz);
clkrstCloseSession(&session);
}


return (int) hz;
}




bool SwitchSys::setClock(const SwitchSys::Module &module, int hz) {


int new_hz = hz;
int bus_id = (int) module;
bool is_old = hosversionBefore(8, 0, 0);

switch (module) {
case SwitchSys::Module::Cpu:
new_hz = new_hz <= 0 ? stock_cpu_clock : new_hz;
bus_id = is_old ? (int) module : (int) PcvModuleId_CpuBus;
break;
case SwitchSys::Module::Gpu:
new_hz = new_hz <= 0 ? stock_gpu_clock : new_hz;
bus_id = is_old ? (int) module : (int) PcvModuleId_GPU;
break;
case SwitchSys::Module::Emc:
new_hz = new_hz <= 0 ? stock_emc_clock : new_hz;
bus_id = is_old ? (int) module : (int) PcvModuleId_EMC;
break;
default:
break;
}

if (is_old) {
if (R_SUCCEEDED(pcvSetClockRate((PcvModule) bus_id, (u32) new_hz))) {
return true;
}
} else {
ClkrstSession session = {0};
clkrstOpenSession(&session, (PcvModuleId) bus_id, 3);
clkrstSetClockRate(&session, hz);
clkrstCloseSession(&session);
}


return false;
}

void SwitchSys::maxClock()
{ int clock_old = SwitchSys::getClock(SwitchSys::Module::Cpu);
SwitchSys::setClock(SwitchSys::Module::Cpu, (int) SwitchSys::CPUClock::Max);
SwitchSys::setClock(SwitchSys::Module::Gpu, (int) SwitchSys::GPUClock::Max);
SwitchSys::setClock(SwitchSys::Module::Emc, (int) SwitchSys::EMCClock::Max);
printf("setting max cpu speed (old: %i, new: %i)\n",
clock_old, SwitchSys::getClock(SwitchSys::Module::Cpu));}

void SwitchSys::defaultClock(int stock_cpu_clock_temp,int stock_gpu_clock_temp,int stock_emc_clock_temp)
{
int clock_old = SwitchSys::getClock(SwitchSys::Module::Cpu);
SwitchSys::setClock(SwitchSys::Module::Cpu, (int) stock_cpu_clock_temp);
SwitchSys::setClock(SwitchSys::Module::Gpu, (int) stock_gpu_clock_temp);
SwitchSys::setClock(SwitchSys::Module::Emc, (int) stock_emc_clock_temp);
printf("restoring cpu speed (old: %i, new: %i)\n",
clock_old, SwitchSys::getClock(SwitchSys::Module::Cpu));
}
14 changes: 9 additions & 5 deletions source/UI/playerWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
#include "imgui.h"
#include "utils.h"
#include "imgui_internal.h"
#include "SwitchSys.h"

using namespace c2d;

namespace playerWindows{

Expand Down Expand Up @@ -262,32 +264,34 @@ namespace playerWindows{
if (ImGui::Selectable(topmenu[n].c_str(), selected == n)){
if(n==0){
mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Restore_CNN_M.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode A (Fast)\"");
SwitchSys::maxClock();
}
if(n==1){
mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Restore_CNN_Soft_M.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode B (Fast)\"");

SwitchSys::maxClock();
}
if(n==2){
mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Upscale_Denoise_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode C (Fast)\"");

SwitchSys::maxClock();
}
if(n==3){
mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Restore_CNN_M.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_Restore_CNN_S.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode A+A (Fast)\"");

SwitchSys::maxClock();
}
if(n==4){
mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Restore_CNN_Soft_M.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Restore_CNN_Soft_S.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode B+B (Fast)\"");

SwitchSys::maxClock();
}
if(n==5){
mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders set \"./mpv/anime4k/Anime4K_Clamp_Highlights.glsl:./mpv/anime4k/Anime4K_Upscale_Denoise_CNN_x2_M.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x2.glsl:./mpv/anime4k/Anime4K_AutoDownscalePre_x4.glsl:./mpv/anime4k/Anime4K_Restore_CNN_S.glsl:./mpv/anime4k/Anime4K_Upscale_CNN_x2_S.glsl\"; show-text \"Anime4K: Mode C+A (Fast)\"");

SwitchSys::maxClock();
}
if(n==6){
mpv_command_string(libmpv->getHandle(), "show-text \"Shaders: ${glsl-shaders}\"");
}
if(n==7){
mpv_command_string(libmpv->getHandle(), "no-osd change-list glsl-shaders clr \"\"; show-text \"Anime4K Disabled\"");
SwitchSys::defaultClock(SwitchSys::stock_cpu_clock, SwitchSys::stock_gpu_clock, SwitchSys::stock_emc_clock);
}
}
}
Expand Down
23 changes: 22 additions & 1 deletion source/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

#include "gui.h"
#include "localfiles.h"

#include "imgui.h"
#include "imgui_internal.h"
#include "imgui_impl_sdl.h"
#include "imgui_impl_opengl3.h"
#include "SwitchSys.h"

using namespace c2d;

MenuItem item;

Expand Down Expand Up @@ -47,6 +49,20 @@ namespace GUI {
}

}

void toggleOC(){
item.clockoc = !item.clockoc;
if(item.clockoc){
const char *cmd[] = {"show-text", "Overclock Enabled","2000", NULL};
mpv_command_async(libmpv->getHandle(), 0, cmd);
SwitchSys::maxClock();
}else{
const char *cmd[] = {"show-text", "Overclock Disabled","2000", NULL};
mpv_command_async(libmpv->getHandle(), 0, cmd);
SwitchSys::defaultClock(SwitchSys::stock_cpu_clock, SwitchSys::stock_gpu_clock, SwitchSys::stock_emc_clock);
}

}


void HandleEvents(){
Expand Down Expand Up @@ -345,6 +361,11 @@ namespace GUI {
toggleMasterLock();
}
}
if (button == SDL_KEY_LSTICK){
if(item.state == MENU_STATE_PLAYER && !item.masterlock){
toggleOC();
}
}
if (button == SDL_KEY_MINUS){
if(item.state == MENU_STATE_PLAYER && !item.masterlock){
item.state = item.laststate;
Expand Down
Loading

0 comments on commit c815492

Please sign in to comment.