Skip to content

Commit 0147b74

Browse files
committed
GameObjectsDisplay: Slight perf improvement + flicker reduction
fix
1 parent fe305ee commit 0147b74

File tree

3 files changed

+13
-10
lines changed

3 files changed

+13
-10
lines changed

src/mods/BackBufferRenderer.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ void BackBufferRenderer::render_d3d12() {
122122
{
123123
std::scoped_lock _{m_d3d12.render_work_mtx};
124124
works = m_d3d12.render_work;
125-
m_d3d12.render_work.clear();
126125
}
127126

128127
const RenderWorkData data{
@@ -153,4 +152,12 @@ void BackBufferRenderer::on_present() {
153152
} else {
154153
render_d3d11();
155154
}
155+
}
156+
157+
void BackBufferRenderer::on_frame() {
158+
// Clearing this here instead of every time whenever we present fixes flickering in some games
159+
if (g_framework->is_dx12() && !m_d3d12.render_work.empty()) {
160+
std::scoped_lock _{m_d3d12.render_work_mtx};
161+
m_d3d12.render_work.clear();
162+
}
156163
}

src/mods/BackBufferRenderer.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class BackBufferRenderer : public Mod {
2727

2828
std::optional<std::string> on_initialize_d3d_thread() override;
2929
void on_present() override;
30+
void on_frame() override;
3031
void on_device_reset() override;
3132

3233
public:

src/mods/tools/GameObjectsDisplay.cpp

+4-9
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ void GameObjectsDisplay::on_frame() {
152152
static auto get_gameobject_method = transform_def->get_method("get_GameObject");
153153
static auto get_position_method = transform_def->get_method("get_Position");
154154
static auto get_axisz_method = transform_def->get_method("get_AxisZ");
155+
static auto get_world_matrix_method = transform_def->get_method("get_WorldMatrix");
155156

156157
auto math = sdk::get_native_singleton("via.math");
157158
auto math_t = sdk::find_type_definition("via.math");
@@ -229,6 +230,8 @@ void GameObjectsDisplay::on_frame() {
229230
});
230231
}
231232

233+
__declspec(align(16)) Matrix4x4f world_matrix{};
234+
232235
for (auto transform = first_transform;
233236
transform != nullptr;
234237
transform = next_transform_method->call<RETransform*>(context, transform))
@@ -264,15 +267,7 @@ void GameObjectsDisplay::on_frame() {
264267
}
265268

266269
if (is_d3d12) {
267-
// Billboard rotation to make the quad face the camera
268-
/*DirectX::SimpleMath::Matrix rotation = DirectX::SimpleMath::Matrix::CreateBillboard(
269-
DirectX::SimpleMath::Vector3(pos.x, pos.y, pos.z),
270-
DirectX::SimpleMath::Vector3(camera_origin.x, camera_origin.y, camera_origin.z),
271-
DirectX::SimpleMath::Vector3::Up
272-
);*/
273-
274-
Matrix4x4f world_matrix{};
275-
sdk::call_object_func<void*>(transform, "get_WorldMatrix", &world_matrix, context, transform);
270+
get_world_matrix_method->call<void*>(&world_matrix, context, transform);
276271

277272
DirectX::SimpleMath::Matrix world =
278273
DirectX::SimpleMath::Matrix{&world_matrix[0][0]};

0 commit comments

Comments
 (0)