Skip to content

Commit

Permalink
Merge pull request JoeyAnthony#18 from JoeyAnthony/feature/GB-212-res…
Browse files Browse the repository at this point in the history
…olution-change-crash-fix-directx9

Invalidating and restoring weaver device objects on resize event
  • Loading branch information
JoeyAnthony authored Feb 9, 2024
2 parents a499df2 + 7c0439d commit 5594ab0
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 19 deletions.
13 changes: 6 additions & 7 deletions gamebridge_reshade/src/directx9weaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,19 @@ void DirectX9Weaver::on_reshade_finish_effects(reshade::api::effect_runtime* run

//Check texture size
if (desc.texture.width != effect_frame_copy_x || desc.texture.height != effect_frame_copy_y) {
// Invalidate weaver device objects before resizing the resource.
weaver->invalidateDeviceObjects();

//TODO Might have to get the buffer from the create_effect_copy_buffer function and only swap them when creation suceeds
d3d9_device->destroy_resource(effect_frame_copy);
if (!create_effect_copy_buffer(desc) && !resize_buffer_failed) {
reshade::log_message(reshade::log_level::warning, "Couldn't create effect copy buffer, trying again next frame");
resize_buffer_failed = true;
}

// Restore weaver device objects after resizing the resource.
weaver->restoreDeviceObjects();

// Set newly create buffer as input
weaver->setInputFrameBuffer((IDirect3DTexture9*)effect_frame_copy.handle);
reshade::log_message(reshade::log_level::info, "Buffer size changed");
Expand Down Expand Up @@ -181,13 +187,6 @@ void DirectX9Weaver::do_weave(bool doWeave)
weaving_enabled = doWeave;
}

// Called before IDirect3DDevice9::Reset
void DirectX9Weaver::on_destroy_swapchain(reshade::api::swapchain *swapchain) {
if (weaver) {
weaver->invalidateDeviceObjects();
}
}

bool DirectX9Weaver::set_latency_in_frames(int32_t numberOfFrames) {
if (weaver_initialized) {
if (numberOfFrames < 0) {
Expand Down
2 changes: 0 additions & 2 deletions gamebridge_reshade/src/directx9weaver.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,12 @@ class DirectX9Weaver: public IGraphicsApi {
bool init_weaver(reshade::api::effect_runtime* runtime, reshade::api::resource rtv, reshade::api::command_list* cmd_list);
bool create_effect_copy_buffer(const reshade::api::resource_desc& effect_resource_desc);


// Inherited via IGraphicsApi
void draw_debug_overlay(reshade::api::effect_runtime* runtime) override;
void draw_sr_settings_overlay(reshade::api::effect_runtime* runtime) override;
void draw_settings_overlay(reshade::api::effect_runtime* runtime) override;
void on_reshade_finish_effects(reshade::api::effect_runtime* runtime, reshade::api::command_list* cmd_list, reshade::api::resource_view rtv, reshade::api::resource_view rtv_srgb) override;
void on_init_effect_runtime(reshade::api::effect_runtime* runtime) override;
void on_destroy_swapchain(reshade::api::swapchain *swapchain) override;
void do_weave(bool doWeave) override;
bool set_latency_in_frames(int32_t numberOfFrames) override;
bool set_latency_framerate_adaptive(uint32_t frametimeInMicroseconds) override;
Expand Down
7 changes: 0 additions & 7 deletions gamebridge_reshade/src/dllmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,6 @@ static void on_render_technique(reshade::api::effect_runtime *runtime, reshade::
effects_are_active = true;
}

static void on_destroy_swapchain(reshade::api::swapchain *swapchain) {
if(weaver_implementation != nullptr) {
weaver_implementation->on_destroy_swapchain(swapchain);
}
}

BOOL APIENTRY DllMain( HMODULE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
Expand All @@ -348,7 +342,6 @@ BOOL APIENTRY DllMain( HMODULE hModule,
reshade::register_event<reshade::addon_event::reshade_render_technique>(&on_render_technique);
reshade::register_event<reshade::addon_event::reshade_finish_effects>(&on_reshade_finish_effects);
reshade::register_event<reshade::addon_event::reshade_reloaded_effects>(&on_reshade_reload_effects);
reshade::register_event<reshade::addon_event::destroy_swapchain>(&on_destroy_swapchain);

reshade::register_overlay(nullptr, &draw_status_overlay);

Expand Down
3 changes: 0 additions & 3 deletions gamebridge_reshade/src/igraphicsapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ class IGraphicsApi {
virtual void do_weave(bool doWeave) = 0;
virtual ~IGraphicsApi() = default;

// Only used for dx9
virtual void on_destroy_swapchain(reshade::api::swapchain *swapchain) {};

virtual LatencyModes get_latency_mode() = 0;

// The two methods below return true if the latency was succesfully set, they return false if their current latency mode does not permit them to set the latency.
Expand Down

0 comments on commit 5594ab0

Please sign in to comment.