Skip to content

Commit

Permalink
feat(ue-dx11): detect dx12
Browse files Browse the repository at this point in the history
  • Loading branch information
clshortfuse committed Dec 26, 2024
1 parent 9dca849 commit f33fbd1
Show file tree
Hide file tree
Showing 54 changed files with 40,573 additions and 22 deletions.
125 changes: 123 additions & 2 deletions src/games/ue-dx11/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace {
renodx::mods::shader::CustomShaders custom_shaders = {
CustomSwapchainShader(0xAC791084), // fmv

// SM5 LUT Builder
CustomShaderEntry(0x2569985B),
CustomShaderEntry(0x31FE4421),
CustomShaderEntry(0x36E3A438),
Expand All @@ -43,6 +44,21 @@ renodx::mods::shader::CustomShaders custom_shaders = {
CustomShaderEntry(0xE6EB2840),
CustomShaderEntry(0xF6AA7756),

// SM6 LUT Builder

CustomShaderEntry(0x269E94C1),
CustomShaderEntry(0x3028EBE7),
CustomShaderEntry(0x33247499),
CustomShaderEntry(0x4CC68F73),
CustomShaderEntry(0x4F3FCE76),
CustomShaderEntry(0x5D760393),
CustomShaderEntry(0x6CFBD4C0),
CustomShaderEntry(0x90BBE81C),
CustomShaderEntry(0x94D26E3A),
CustomShaderEntry(0xB530B36A),
CustomShaderEntry(0xB6CA5FD9),
CustomShaderEntry(0xBAA27141),

};

ShaderInjectData shader_injection;
Expand Down Expand Up @@ -181,7 +197,7 @@ renodx::utils::settings::Settings settings = {
.tooltip = "Controls highlight desaturation due to overexposure.",
.max = 100.f,
.is_enabled = []() { return shader_injection.toneMapType == 1; },
.parse = [](float value) { return value * 0.02f - 1.f; },
.parse = [](float value) { return (value * 0.02f) - 1.f; },
},
new renodx::utils::settings::Setting{
.key = "ColorGradeFlare",
Expand Down Expand Up @@ -282,8 +298,42 @@ void OnPresetOff() {
renodx::utils::settings::UpdateSetting("colorGradeColorSpace", 0.f);
}

bool fired_on_init_swapchain = false;
bool applied_dx12 = false;
void OnInitDevice(reshade::api::device* device) {
if (applied_dx12) return;
if (device->get_api() != reshade::api::device_api::d3d12) return;
// Switch over to DX12
renodx::mods::shader::expected_constant_buffer_space = 50;
renodx::mods::swapchain::expected_constant_buffer_space = 50;

renodx::mods::shader::on_init_pipeline_layout = [](reshade::api::device* device, auto, auto) {
return device->get_api() == reshade::api::device_api::d3d12;
};

renodx::mods::swapchain::swap_chain_proxy_pixel_shader = __swap_chain_proxy_pixel_shader_dx12;
renodx::mods::shader::custom_shaders[0x2569985B] = {.crc32 = 0x2569985B, .code = __lutbuilder_0x2569985B_dx12};
renodx::mods::shader::custom_shaders[0x31FE4421] = {.crc32 = 0x31FE4421, .code = __lutbuilder_0x31FE4421_dx12};
renodx::mods::shader::custom_shaders[0x36E3A438] = {.crc32 = 0x36E3A438, .code = __lutbuilder_0x36E3A438_dx12};
renodx::mods::shader::custom_shaders[0x5CAE0013] = {.crc32 = 0x5CAE0013, .code = __lutbuilder_0x5CAE0013_dx12};
renodx::mods::shader::custom_shaders[0x61C2EA30] = {.crc32 = 0x61C2EA30, .code = __lutbuilder_0x61C2EA30_dx12};
renodx::mods::shader::custom_shaders[0x73B2BA54] = {.crc32 = 0x73B2BA54, .code = __lutbuilder_0x73B2BA54_dx12};
renodx::mods::shader::custom_shaders[0x7570E7B1] = {.crc32 = 0x7570E7B1, .code = __lutbuilder_0x7570E7B1_dx12};
renodx::mods::shader::custom_shaders[0x80CD76B6] = {.crc32 = 0x80CD76B6, .code = __lutbuilder_0x80CD76B6_dx12};
renodx::mods::shader::custom_shaders[0xA918F0C8] = {.crc32 = 0xA918F0C8, .code = __lutbuilder_0xA918F0C8_dx12};
renodx::mods::shader::custom_shaders[0xB1614732] = {.crc32 = 0xB1614732, .code = __lutbuilder_0xB1614732_dx12};
renodx::mods::shader::custom_shaders[0xBEB7EB31] = {.crc32 = 0xBEB7EB31, .code = __lutbuilder_0xBEB7EB31_dx12};
renodx::mods::shader::custom_shaders[0xC130BE2D] = {.crc32 = 0xC130BE2D, .code = __lutbuilder_0xC130BE2D_dx12};
renodx::mods::shader::custom_shaders[0xC1BCC6B5] = {.crc32 = 0xC1BCC6B5, .code = __lutbuilder_0xC1BCC6B5_dx12};
renodx::mods::shader::custom_shaders[0xC2A711CC] = {.crc32 = 0xC2A711CC, .code = __lutbuilder_0xC2A711CC_dx12};
renodx::mods::shader::custom_shaders[0xCA383248] = {.crc32 = 0xCA383248, .code = __lutbuilder_0xCA383248_dx12};
renodx::mods::shader::custom_shaders[0xCC8FD0FF] = {.crc32 = 0xCC8FD0FF, .code = __lutbuilder_0xCC8FD0FF_dx12};
renodx::mods::shader::custom_shaders[0xD4A45A02] = {.crc32 = 0xD4A45A02, .code = __lutbuilder_0xD4A45A02_dx12};
renodx::mods::shader::custom_shaders[0xE6EB2840] = {.crc32 = 0xE6EB2840, .code = __lutbuilder_0xE6EB2840_dx12};
renodx::mods::shader::custom_shaders[0xF6AA7756] = {.crc32 = 0xF6AA7756, .code = __lutbuilder_0xF6AA7756_dx12};
applied_dx12 = true;
}

bool fired_on_init_swapchain = false;
void OnInitSwapchain(reshade::api::swapchain* swapchain) {
if (fired_on_init_swapchain) return;
fired_on_init_swapchain = true;
Expand All @@ -294,6 +344,68 @@ void OnInitSwapchain(reshade::api::swapchain* swapchain) {
}
}

void AddUpgrade(reshade::api::format old_format) {
renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({
.old_format = old_format,
.new_format = reshade::api::format::r16g16b16a16_float,
.usage_include = reshade::api::resource_usage::render_target,
});
}

void AddPsychonauts2Patches() {
renodx::mods::swapchain::force_borderless = false;
renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({
.old_format = reshade::api::format::r10g10b10a2_unorm,
.new_format = reshade::api::format::r16g16b16a16_float,
.ignore_size = true,
.usage_include = reshade::api::resource_usage::render_target,
});
renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({
.old_format = reshade::api::format::r11g11b10_float,
.new_format = reshade::api::format::r16g16b16a16_float,
.ignore_size = true,
.usage_include = reshade::api::resource_usage::render_target,
});
}

void AddHifiRushPatches() {
// for (auto index : {1}) {
// renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({
// .old_format = reshade::api::format::b8g8r8a8_typeless,
// .new_format = reshade::api::format::b8g8r8a8_typeless,
// .index = index,
// .view_upgrades = {},
// .usage_include = reshade::api::resource_usage::render_target,
// });
// }
// renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({
// .old_format = reshade::api::format::b8g8r8a8_typeless,
// .new_format = reshade::api::format::r16g16b16a16_typeless,
// .usage_include = reshade::api::resource_usage::render_target,
// });
}

void AddGamePatches() {
try {
auto process_path = renodx::utils::platform::GetCurrentProcessPath();
auto filename = process_path.filename().string();
if (filename == "Psychonauts2-WinGDK-Shipping.exe") {
AddPsychonauts2Patches();
} else if (filename == "Hi-Fi-RUSH.exe") {
AddHifiRushPatches();
} else if (filename == "TheThaumaturge-Win64-Shipping.exe") {
AddUpgrade(reshade::api::format::r10g10b10a2_unorm);
} else if (filename == "SystemReShock-Win64-Shipping.exe") {
AddUpgrade(reshade::api::format::b8g8r8a8_typeless);
} else {
return;
}
reshade::log::message(reshade::log::level::info, std::format("Applied patches for {}.", filename).c_str());
} catch (...) {
reshade::log::message(reshade::log::level::error, "Could not read process path");
}
}

} // namespace

extern "C" __declspec(dllexport) constexpr const char* NAME = "RenoDX";
Expand All @@ -304,6 +416,11 @@ BOOL APIENTRY DllMain(HMODULE h_module, DWORD fdw_reason, LPVOID lpv_reserved) {
case DLL_PROCESS_ATTACH:
if (!reshade::register_addon(h_module)) return FALSE;

renodx::mods::shader::expected_constant_buffer_index = 13;
renodx::mods::shader::allow_multiple_push_constants = true;

renodx::mods::swapchain::expected_constant_buffer_index = 13;

renodx::mods::swapchain::use_resource_cloning = true;
renodx::mods::swapchain::swap_chain_proxy_vertex_shader = __swap_chain_proxy_vertex_shader;
renodx::mods::swapchain::swap_chain_proxy_pixel_shader = __swap_chain_proxy_pixel_shader;
Expand All @@ -314,10 +431,14 @@ BOOL APIENTRY DllMain(HMODULE h_module, DWORD fdw_reason, LPVOID lpv_reserved) {
.dimensions = {.width = 32, .height = 32, .depth = 32},
});

AddGamePatches();

reshade::register_event<reshade::addon_event::init_device>(OnInitDevice);
reshade::register_event<reshade::addon_event::init_swapchain>(OnInitSwapchain);

break;
case DLL_PROCESS_DETACH:
reshade::unregister_event<reshade::addon_event::init_device>(OnInitDevice);
reshade::unregister_event<reshade::addon_event::init_swapchain>(OnInitSwapchain);
reshade::unregister_addon(h_module);
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ---- Created with 3Dmigoto v1.3.16 on Thu Oct 17 13:24:08 2024
#include "../common.hlsl"
#include "../../common.hlsl"

cbuffer cb1 : register(b1) {
float4 cb1[21];
Expand Down
Loading

0 comments on commit f33fbd1

Please sign in to comment.