From 77a305fda501379a245634aa9a003f136f495712 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Mon, 27 Jul 2020 14:15:38 +1000 Subject: [PATCH] use shader_amd.farc for AMD patches (now toggling Novidia changes shaders between original and patched for multi-GPU users) users of old versions need to repatch shaders or rename shader.farc in MAMD to use this option in Novidia. --- source-code/data/amd-tools/patch shaders py.bat | 2 +- source-code/data/amd-tools/patch shaders.bat | 2 +- source-code/source/plugins/Novidia/src/dllmain.cpp | 7 +++++++ source-code/source/plugins/Novidia/src/framework.h | 14 ++++++++++++++ source-code/source/plugins/Novidia/src/glStuff.h | 1 + 5 files changed, 24 insertions(+), 2 deletions(-) diff --git a/source-code/data/amd-tools/patch shaders py.bat b/source-code/data/amd-tools/patch shaders py.bat index 0dee9b4..43b32d0 100644 --- a/source-code/data/amd-tools/patch shaders py.bat +++ b/source-code/data/amd-tools/patch shaders py.bat @@ -3,7 +3,7 @@ FarcPack ..\rom\shader.farc shader_unpacked mkdir ..\mdata\MAMD mkdir ..\mdata\MAMD\rom copy info.txt ..\mdata\MAMD\ -FarcPack -c shader_patched ..\mdata\MAMD\rom\shader.farc +FarcPack -c shader_patched ..\mdata\MAMD\rom\shader_amd.farc del /Q shader_unpacked rmdir shader_unpacked del /Q shader_patched diff --git a/source-code/data/amd-tools/patch shaders.bat b/source-code/data/amd-tools/patch shaders.bat index 4ef129b..7ad267c 100644 --- a/source-code/data/amd-tools/patch shaders.bat +++ b/source-code/data/amd-tools/patch shaders.bat @@ -3,7 +3,7 @@ FarcPack ..\rom\shader.farc shader_unpacked mkdir ..\mdata\MAMD mkdir ..\mdata\MAMD\rom copy info.txt ..\mdata\MAMD\ -FarcPack -c shader_patched ..\mdata\MAMD\rom\shader.farc +FarcPack -c shader_patched ..\mdata\MAMD\rom\shader_amd.farc del /Q shader_unpacked rmdir shader_unpacked del /Q shader_patched diff --git a/source-code/source/plugins/Novidia/src/dllmain.cpp b/source-code/source/plugins/Novidia/src/dllmain.cpp index 7947bb5..155c04d 100644 --- a/source-code/source/plugins/Novidia/src/dllmain.cpp +++ b/source-code/source/plugins/Novidia/src/dllmain.cpp @@ -157,6 +157,12 @@ BOOL APIENTRY DllMain(HMODULE hModule, DWORD ul_reason_for_call, LPVOID lpReserv DetourAttach(&(PVOID&)uploadModelTransformBuf, h_uploadModelTransformBuf_TexImage); DetourTransactionCommit(); + + if (shader_amd_farc) + { + const char* shaderpath = "./rom/shader_amd.farc"; + InjectCode((void*)0x140a41018, std::vector(shaderpath, shaderpath + strlen(shaderpath))); + } } return TRUE; @@ -169,6 +175,7 @@ using namespace PluginConfig; PluginConfigOption config[] = { { CONFIG_BOOLEAN, new PluginConfigBooleanData{ L"use_TexSubImage", L"general", CONFIG_FILE, L"Use glTexSubImage", L"glTexSubImage should offer higher performance, but stuttering has been reported when it is used.\nTry disabling this if you have issues.", true, false } }, { CONFIG_BOOLEAN, new PluginConfigBooleanData{ L"force_BGRA_upload", L"general", CONFIG_FILE, L"Force BGRA Texture Uploads", L"BGRA format uploads seem to run faster (on some hardware), but drivers may suggest RGBA instead.\nUsing this forces uploads to use the BGRA format.\n\nDisabling this may decrease or improve performance.", true, false } }, + { CONFIG_BOOLEAN, new PluginConfigBooleanData{ L"shader_amd_farc", L"general", CONFIG_FILE, L"Load shader_amd.farc", L"Novidia can manage loading of alternate shaders automatically.\nLeave this enabled for current and future versions of AMDPack.", true, false } }, }; extern "C" __declspec(dllexport) LPCWSTR GetPluginName(void) diff --git a/source-code/source/plugins/Novidia/src/framework.h b/source-code/source/plugins/Novidia/src/framework.h index 4747fa4..efa1865 100644 --- a/source-code/source/plugins/Novidia/src/framework.h +++ b/source-code/source/plugins/Novidia/src/framework.h @@ -1,6 +1,7 @@ #pragma once #include "glStuff.h" +#include // use this as a hook to perform initialisation void(__cdecl* glutSetCursor)(int cursor) = *(void(__cdecl**)(int))0x140966068; @@ -27,6 +28,7 @@ int __stdcall stub() { return 1; } bool use_TexSubImage; bool force_BGRA_upload; GLint tex_upload_format; +bool shader_amd_farc; std::wstring ExePath() { WCHAR buffer[MAX_PATH]; @@ -48,4 +50,16 @@ void loadConfig() { use_TexSubImage = GetPrivateProfileIntW(L"general", L"use_TexSubImage", 1, CONFIG_FILE) > 0 ? true : false; force_BGRA_upload = GetPrivateProfileIntW(L"general", L"force_BGRA_upload", 1, CONFIG_FILE) > 0 ? true : false; + shader_amd_farc = GetPrivateProfileIntW(L"general", L"shader_amd_farc", 1, CONFIG_FILE) > 0 ? true : false; +} + + +void InjectCode(void* address, const std::vector data) +{ + const size_t byteCount = data.size() * sizeof(uint8_t); + + DWORD oldProtect; + VirtualProtect(address, byteCount, PAGE_EXECUTE_READWRITE, &oldProtect); + memcpy(address, data.data(), byteCount); + VirtualProtect(address, byteCount, oldProtect, nullptr); } \ No newline at end of file diff --git a/source-code/source/plugins/Novidia/src/glStuff.h b/source-code/source/plugins/Novidia/src/glStuff.h index 061c6ed..d943a2b 100644 --- a/source-code/source/plugins/Novidia/src/glStuff.h +++ b/source-code/source/plugins/Novidia/src/glStuff.h @@ -40,6 +40,7 @@ typedef char GLchar; #define GL_TEXTURE8 0x84c8 #define GL_BUFFER_SIZE 0x8764 #define GL_RGBA32F 0x8814 +#define GL_RGBA16F 0x881a #define GL_ARRAY_BUFFER 0x8892 #define GL_ARRAY_BUFFER_BINDING 0x8894 #define GL_READ_ONLY 0x88b8