Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pathfinder2 #62

Merged
merged 3 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 90 additions & 4 deletions src/devkit/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <crc32_hash.hpp>
#include "../mods/swapchain.hpp"
#include "../utils/descriptor.hpp"
#include "../utils/pipeline_layout.hpp"
#include "../utils/shader.hpp"
#include "../utils/shader_compiler_directx.hpp"
#include "../utils/shader_compiler_watcher.hpp"
Expand Down Expand Up @@ -81,9 +82,9 @@ struct ShaderDetails {
};

struct ResourceViewDetails {
reshade::api::resource_view resource_view;
reshade::api::resource_view resource_view = {0};
reshade::api::resource_view_desc resource_view_desc;
reshade::api::resource resource;
reshade::api::resource resource = {0};
reshade::api::resource_desc resource_desc;
std::string resource_tag;
std::string resource_view_tag;
Expand All @@ -98,10 +99,10 @@ struct ResourceViewDetails {
if (swapchain_mod_data == nullptr) return false;
const std::shared_lock lock(swapchain_mod_data->mutex);
this->is_rtv_upgraded = swapchain_mod_data->upgraded_resource_views.contains(resource_view.handle);
this->is_rtv_cloned = swapchain_mod_data->resource_views_cloned.contains(resource_view.handle);
this->is_rtv_cloned = swapchain_mod_data->resource_clones.contains(resource_view.handle);

this->is_res_upgraded = this->resource.handle != 0u && swapchain_mod_data->upgraded_resources.contains(this->resource.handle);
this->is_res_cloned = this->resource.handle != 0u && swapchain_mod_data->cloned_resources.contains(this->resource.handle);
this->is_res_cloned = this->resource.handle != 0u && swapchain_mod_data->resource_clones.contains(this->resource.handle);
return true;
}
};
Expand Down Expand Up @@ -452,6 +453,7 @@ void OnPushDescriptors(
auto srv_index = update.binding + index + starting_index;
destination[srv_index] = (device_data.GetResourceViewDetails(view, device));
};

for (uint32_t i = 0; i < update.count; i++) {
switch (update.type) {
case reshade::api::descriptor_type::sampler:
Expand Down Expand Up @@ -480,6 +482,85 @@ void OnPushDescriptors(
}
}

void OnBindDescriptorTables(
reshade::api::command_list* cmd_list,
reshade::api::shader_stage stages,
reshade::api::pipeline_layout layout,
uint32_t first,
uint32_t count,
const reshade::api::descriptor_table* tables) {
if (!is_snapshotting) return;
auto& data = cmd_list->get_private_data<CommandListData>();
auto& details = data.GetCurrentDrawDetails();

auto* device = cmd_list->get_device();
auto& device_data = device->get_private_data<DeviceData>();

auto& layout_data = device->get_private_data<renodx::utils::pipeline_layout::DeviceData>();
const std::shared_lock layout_lock(layout_data.mutex);

auto& descriptor_data = device->get_private_data<renodx::utils::descriptor::DeviceData>();

for (uint32_t i = 0; i < count; ++i) {
const auto& info = layout_data.pipeline_layout_data[layout.handle];
const auto& param = info.params.at(first + i);

for (uint32_t k = 0; k < param.descriptor_table.count; ++k) {
const auto& range = param.descriptor_table.ranges[k];

// Skip unbounded ranges
if (range.count == UINT32_MAX) continue;

if (range.type != reshade::api::descriptor_type::shader_resource_view
&& range.type != reshade::api::descriptor_type::sampler_with_resource_view) {
continue;
}

uint32_t base_offset = 0;
reshade::api::descriptor_heap heap = {0};
device->get_descriptor_heap_offset(tables[i], range.binding, 0, &heap, &base_offset);

const std::shared_lock descriptor_lock(descriptor_data.mutex);

for (uint32_t j = 0; j < range.count; ++j) {
const auto& heap_data = descriptor_data.heaps[heap.handle];
auto offset = base_offset + j;
if (offset >= heap_data.size()) continue;
const auto& [descriptor_type, descriptor_data] = heap_data[offset];
reshade::api::resource_view resource_view = {0};
bool is_uav = false;
switch (descriptor_type) {
case reshade::api::descriptor_type::sampler_with_resource_view:
resource_view = std::get<reshade::api::sampler_with_resource_view>(descriptor_data).view;
break;
case reshade::api::descriptor_type::buffer_unordered_access_view:
case reshade::api::descriptor_type::texture_unordered_access_view:
is_uav = true;
// fallthrough
case reshade::api::descriptor_type::buffer_shader_resource_view:
case reshade::api::descriptor_type::texture_shader_resource_view:
resource_view = std::get<reshade::api::resource_view>(descriptor_data);
break;
case reshade::api::descriptor_type::constant_buffer:
case reshade::api::descriptor_type::shader_storage_buffer:
case reshade::api::descriptor_type::acceleration_structure:
break;
default:
break;
}
if (resource_view.handle == 0u) continue;
uint32_t texture_index = range.dx_register_index + j;
const std::unique_lock lock(device_data.mutex);
if (is_uav) {
details.uav_binds[texture_index] = (device_data.GetResourceViewDetails(resource_view, device));
} else {
details.srv_binds[texture_index] = (device_data.GetResourceViewDetails(resource_view, device));
}
}
}
}
}

bool OnDraw(reshade::api::command_list* cmd_list, DrawDetails::DrawMethods draw_method) {
bool bypass_draw = false;

Expand Down Expand Up @@ -1583,6 +1664,7 @@ BOOL APIENTRY DllMain(HMODULE h_module, DWORD fdw_reason, LPVOID lpv_reserved) {
reshade::register_event<reshade::addon_event::init_pipeline>(OnInitPipelineTrackAddons);
reshade::register_event<reshade::addon_event::bind_pipeline>(OnBindPipeline);
reshade::register_event<reshade::addon_event::push_descriptors>(OnPushDescriptors);
reshade::register_event<reshade::addon_event::bind_descriptor_tables>(OnBindDescriptorTables);
reshade::register_event<reshade::addon_event::draw>(OnDraw);
reshade::register_event<reshade::addon_event::draw_indexed>(OnDrawIndexed);
reshade::register_event<reshade::addon_event::draw_or_dispatch_indirect>(OnDrawOrDispatchIndirect);
Expand All @@ -1595,6 +1677,10 @@ BOOL APIENTRY DllMain(HMODULE h_module, DWORD fdw_reason, LPVOID lpv_reserved) {
case DLL_PROCESS_DETACH:

renodx::utils::descriptor::Use(fdw_reason);
renodx::utils::shader::Use(fdw_reason);
renodx::utils::shader::dump::Use(fdw_reason);
renodx::utils::trace::Use(fdw_reason);
renodx::utils::swapchain::Use(fdw_reason);

reshade::unregister_event<reshade::addon_event::init_device>(OnInitDevice);
reshade::unregister_event<reshade::addon_event::destroy_device>(OnDestroyDevice);
Expand Down
2 changes: 1 addition & 1 deletion src/games/pathfinder2wotr/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ renodx::utils::settings::Settings settings = {
.key = "toneMapType",
.binding = &shader_injection.toneMapType,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 5.f,
.default_value = 4.f,
.can_reset = false,
.label = "Tone Mapper",
.section = "Tone Mapping",
Expand Down
9 changes: 8 additions & 1 deletion src/games/pathfinder2wotr/tonemapper.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,17 @@ float3 applyUserTonemap(float3 untonemapped, Texture2D lutTexture, SamplerState

// Color, Peak, midgray, midgraynits, exposure, highlights, shadows, contrast, saturation, dechroma, flare, hueCorrectionStrength
float3 sdrColor = renodx::tonemap::renodrt::BT709(outputColor, 100.f, 0.18f, 18.f, 1.f, 1.f, 1.f, 1.f, 1.f, 0.5f, 0.f, 0.f);
outputColor = renodx::tonemap::renodrt::BT709(outputColor, RenoDRTPeak, 0.18f, 18.f, 1.f, 1.f, 1.f, 1.f, 1.f, 0.5f, 0.f, 0.f);

float3 lutColor = renodx::lut::Sample(lutTexture, lut_config, outputColor);
// Normalize the SDR colors to 0-1 range, without clipping them
float lutColorPeak = max(max(max(lutColor.x, lutColor.y), lutColor.z), 1.f);
lutColor /= lutColorPeak;
sdrColor /= lutColorPeak;

outputColor = renodx::tonemap::UpgradeToneMap(outputColor, sdrColor, lutColor, 1.f);
outputColor *= lutColorPeak;

outputColor = renodx::tonemap::renodrt::BT709(outputColor, RenoDRTPeak, 0.18f, 18.f, 1.f, 1.f, 1.f, 1.f, 1.f, 0.5f, 0.f, 0.f);
}

// } else if (injectedData.toneMapType == 6.f) { // test
Expand Down
24 changes: 22 additions & 2 deletions src/games/seaofstars/addon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <embed/0x552A4A60.h>
#include <embed/0x67758842.h>
#include <embed/0x72B31CDE.h>
#include <embed/0x77850945.h>
#include <embed/0xB646820B.h>

#include <deps/imgui/imgui.h>
#include <include/reshade.hpp>
Expand All @@ -25,6 +27,8 @@ renodx::mods::shader::CustomShaders custom_shaders = {
CustomShaderEntry(0x552A4A60),
CustomShaderEntry(0x72B31CDE),
CustomShaderEntry(0x67758842),
CustomShaderEntry(0x77850945),
CustomShaderEntry(0xB646820B),
};

ShaderInjectData shader_injection;
Expand Down Expand Up @@ -174,6 +178,16 @@ renodx::utils::settings::Settings settings = {
.max = 100.f,
.parse = [](float value) { return value * 0.01f; },
},
new renodx::utils::settings::Setting{
.key = "processingInternalSampling",
.binding = &shader_injection.processingInternalSampling,
.value_type = renodx::utils::settings::SettingValueType::INTEGER,
.default_value = 1.f,
.label = "Internal Sampling",
.section = "Processing",
.tooltip = "Selects whether to use the vanilla sampling or PQ for the game's internal rendering LUT.",
.labels = {"Vanilla", "PQ"},
},
};

void OnPresetOff() {
Expand All @@ -190,6 +204,9 @@ void OnPresetOff() {
renodx::utils::settings::UpdateSetting("colorGradeLUTStrength", 100.f);
renodx::utils::settings::UpdateSetting("colorGradeLUTScaling", 0.f);
renodx::utils::settings::UpdateSetting("fxBloom", 50.f);
renodx::utils::settings::UpdateSetting("fxHeroLight", 100.f);
renodx::utils::settings::UpdateSetting("processingInternalSampling", 0.f);

}

} // namespace
Expand All @@ -200,9 +217,12 @@ extern "C" __declspec(dllexport) constexpr const char* DESCRIPTION = "RenoDX for
BOOL APIENTRY DllMain(HMODULE h_module, DWORD fdw_reason, LPVOID lpv_reserved) {
switch (fdw_reason) {
case DLL_PROCESS_ATTACH:

renodx::mods::shader::force_pipeline_cloning = true;
if (!reshade::register_addon(h_module)) return FALSE;

renodx::mods::swapchain::swap_chain_upgrade_targets.push_back({
.old_format = reshade::api::format::r8g8b8a8_typeless,
.new_format = reshade::api::format::r16g16b16a16_float,
});
break;
case DLL_PROCESS_DETACH:
reshade::unregister_addon(h_module);
Expand Down
4 changes: 2 additions & 2 deletions src/games/seaofstars/lutbuilder_0x67758842.ps_4_0.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cbuffer cb0 : register(b0) {
// 3Dmigoto declarations
#define cmp -

void main(float4 v0 : SV_POSITION0, float2 v1 : TEXCOORD0, out float4 o0 : SV_Target0) {
void main(float4 v0: SV_POSITION0, float2 v1: TEXCOORD0, out float4 o0: SV_Target0) {
float4 r0, r1, r2, r3, r4, r5, r6;
uint4 bitmask, uiDest;
float4 fDest;
Expand All @@ -36,7 +36,7 @@ void main(float4 v0 : SV_POSITION0, float2 v1 : TEXCOORD0, out float4 o0 : SV_Ta
// r0.xyz = r0.xzw * cb0[128].www + float3(-0.386036009, -0.386036009, -0.386036009);
r0.xyz = r0.xzw * cb0[128].www;

// LogCToLinear
// ARRI_C1000_NO_CUT
r0.xyz += float3(-0.386036009, -0.386036009, -0.386036009);
r0.xyz = float3(13.6054821, 13.6054821, 13.6054821) * r0.xyz;
r0.xyz = exp2(r0.xyz);
Expand Down
Loading
Loading