Skip to content

Commit

Permalink
feat(ue-dx11): add dx12 support
Browse files Browse the repository at this point in the history
  • Loading branch information
clshortfuse committed Dec 26, 2024
1 parent dc68399 commit 9050779
Show file tree
Hide file tree
Showing 11 changed files with 3,808 additions and 54 deletions.
99 changes: 63 additions & 36 deletions src/games/ue-dx11/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
namespace {

renodx::mods::shader::CustomShaders custom_shaders = {
CustomSwapchainShader(0xAC791084), // fmv
// Crisis Core FF7 Reunion
CustomShaderEntry(0xAC791084), // fmv

// Kingdom Hearts 3
CustomShaderEntry(0x00E9C5FE),
CustomShaderEntry(0xE9343033),

// SM5 LUT Builder
CustomShaderEntry(0x2569985B),
Expand Down Expand Up @@ -301,7 +306,10 @@ void OnPresetOff() {
bool applied_dx12 = false;
void OnInitDevice(reshade::api::device* device) {
if (applied_dx12) return;

if (device->get_api() != reshade::api::device_api::d3d12) return;

reshade::log::message(reshade::log::level::info, "Switching to DX12...");
// Switch over to DX12
renodx::mods::shader::expected_constant_buffer_space = 50;
renodx::mods::swapchain::expected_constant_buffer_space = 50;
Expand All @@ -310,30 +318,44 @@ void OnInitDevice(reshade::api::device* device) {
return device->get_api() == reshade::api::device_api::d3d12;
};

renodx::mods::swapchain::swap_chain_proxy_vertex_shader = __swap_chain_proxy_vertex_shader_dx12;
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};
// renodx::mods::shader::custom_shaders doesn't use the shader data, just hashes
// Update on utils::shaders instead

renodx::utils::shader::UpdateReplacements({
// Kingdom Hearts 3
{0x00E9C5FE, __lutbuilder_0x00E9C5FE_dx12},
{0xE9343033, __lutbuilder_0xE9343033_dx12},
// SM5 LUT Builder
{0x2569985B, __lutbuilder_0x2569985B_dx12},
{0x31FE4421, __lutbuilder_0x31FE4421_dx12},
{0x36E3A438, __lutbuilder_0x36E3A438_dx12},
{0x5CAE0013, __lutbuilder_0x5CAE0013_dx12},
{0x61C2EA30, __lutbuilder_0x61C2EA30_dx12},
{0x73B2BA54, __lutbuilder_0x73B2BA54_dx12},
{0x7570E7B1, __lutbuilder_0x7570E7B1_dx12},
{0x80CD76B6, __lutbuilder_0x80CD76B6_dx12},
{0xA918F0C8, __lutbuilder_0xA918F0C8_dx12},
{0xB1614732, __lutbuilder_0xB1614732_dx12},
{0xBEB7EB31, __lutbuilder_0xBEB7EB31_dx12},
{0xC130BE2D, __lutbuilder_0xC130BE2D_dx12},
{0xC1BCC6B5, __lutbuilder_0xC1BCC6B5_dx12},
{0xC2A711CC, __lutbuilder_0xC2A711CC_dx12},
{0xCA383248, __lutbuilder_0xCA383248_dx12},
{0xCC8FD0FF, __lutbuilder_0xCC8FD0FF_dx12},
{0xD4A45A02, __lutbuilder_0xD4A45A02_dx12},
{0xE6EB2840, __lutbuilder_0xE6EB2840_dx12},
{0xF6AA7756, __lutbuilder_0xF6AA7756_dx12},
});

reshade::log::message(reshade::log::level::info, "Added replacements.");

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 Down Expand Up @@ -406,35 +428,40 @@ void AddGamePatches() {
}
}

bool initialized = false;

} // namespace

extern "C" __declspec(dllexport) constexpr const char* NAME = "RenoDX";
extern "C" __declspec(dllexport) constexpr const char* DESCRIPTION = "RenoDX for Unreal Engine (DirectX 11)";
extern "C" __declspec(dllexport) constexpr const char* DESCRIPTION = "RenoDX for Unreal Engine";

BOOL APIENTRY DllMain(HMODULE h_module, DWORD fdw_reason, LPVOID lpv_reserved) {
switch (fdw_reason) {
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;
if (!reshade::register_addon(h_module)) return FALSE;
reshade::register_event<reshade::addon_event::init_device>(OnInitDevice);
reshade::register_event<reshade::addon_event::init_swapchain>(OnInitSwapchain);

renodx::mods::swapchain::expected_constant_buffer_index = 13;
if (!initialized) {
renodx::mods::shader::expected_constant_buffer_index = 13;
renodx::mods::shader::allow_multiple_push_constants = true;

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;
renodx::mods::swapchain::expected_constant_buffer_index = 13;

renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({
.old_format = reshade::api::format::r10g10b10a2_unorm,
.new_format = reshade::api::format::r16g16b16a16_float,
.dimensions = {.width = 32, .height = 32, .depth = 32},
});
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;

AddGamePatches();
renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({
.old_format = reshade::api::format::r10g10b10a2_unorm,
.new_format = reshade::api::format::r16g16b16a16_float,
.dimensions = {.width = 32, .height = 32, .depth = 32},
});

reshade::register_event<reshade::addon_event::init_device>(OnInitDevice);
reshade::register_event<reshade::addon_event::init_swapchain>(OnInitSwapchain);
AddGamePatches();
initialized = true;
}

break;
case DLL_PROCESS_DETACH:
Expand Down
8 changes: 6 additions & 2 deletions src/games/ue-dx11/common.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ float3 ToneMap(float3 bt709) {
return output_color;
}

float4 LutBuilderToneMap(float3 untonemapped_ap1, float3 tonemapped_bt709) {
float3 UpgradeToneMapAP1(float3 untonemapped_ap1, float3 tonemapped_bt709) {
float3 untonemapped_bt709 = renodx::color::bt709::from::AP1(untonemapped_ap1);

float3 neutral_sdr_color = RenoDRTSmoothClamp(untonemapped_bt709);
Expand All @@ -154,7 +154,11 @@ float4 LutBuilderToneMap(float3 untonemapped_ap1, float3 tonemapped_bt709) {
tonemapped_bt709,
1);

float3 color = ToneMap(untonemapped_graded);
return ToneMap(untonemapped_graded);
}

float4 LutBuilderToneMap(float3 untonemapped_ap1, float3 tonemapped_bt709) {
float3 color = UpgradeToneMapAP1(untonemapped_ap1, tonemapped_bt709);

color = PostToneMapScale(color);
color *= 1.f / 1.05f;
Expand Down
Loading

0 comments on commit 9050779

Please sign in to comment.