Skip to content

Commit

Permalink
VR/TemporalUpscaler: Slight bottleneck reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
praydog committed Sep 5, 2023
1 parent 055707f commit f7560a0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
21 changes: 13 additions & 8 deletions src/mods/TemporalUpscaler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,8 @@ void TemporalUpscaler::on_early_present() {
const auto is_vr_multipass = vr_enabled && vr->is_using_multipass();
const auto frame = vr->get_render_frame_count();

m_copier.wait(INFINITE);
auto& copier = m_copiers[swapchain->GetCurrentBackBufferIndex() % m_copiers.size()];
copier.wait(INFINITE);

if (vr_enabled && is_vr_multipass) {
for (auto& state : m_eye_states) {
Expand Down Expand Up @@ -410,12 +411,12 @@ void TemporalUpscaler::on_early_present() {
//params.renderSizeX, params.renderSizeY, params.sharpness, params.jitterOffsetX, params.jitterOffsetY, params.motionScaleX, params.motionScaleY, params.reset, params.nearPlane, params.farPlane, params.verticalFOV, params.execute);

if (i == 0) {
m_copier.copy((ID3D12Resource*)m_upscaled_textures[evaluate_index], backbuffer.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_PRESENT);
copier.copy((ID3D12Resource*)m_upscaled_textures[evaluate_index], backbuffer.Get(), D3D12_RESOURCE_STATE_UNORDERED_ACCESS, D3D12_RESOURCE_STATE_PRESENT);
}
}
}

m_copier.execute();
copier.execute();

static bool once = true;

Expand Down Expand Up @@ -498,8 +499,9 @@ bool TemporalUpscaler::init_upscale_features() {
out_h = bb_desc.Height;
out_format = bb_desc.Format;

m_copier.setup();
m_big_copier.setup();
for (auto& copier : m_copiers) {
copier.setup();
}
} else {
auto& hook = g_framework->get_d3d11_hook();

Expand Down Expand Up @@ -575,7 +577,9 @@ void TemporalUpscaler::release_upscale_features() {
return;
}

m_copier.wait(2000);
for (auto& copier : m_copiers) {
copier.wait(2000);
}

if (m_upscaled_textures[0] != nullptr) {
ReleaseUpscaleFeature(get_evaluate_id(0));
Expand All @@ -588,8 +592,9 @@ void TemporalUpscaler::release_upscale_features() {
}

m_wants_reinitialize = true;
m_copier.reset();
m_big_copier.reset();
for (auto& copier : m_copiers) {
copier.reset();
}

for (auto& state : m_eye_states) {
state.color.Reset();
Expand Down
3 changes: 1 addition & 2 deletions src/mods/TemporalUpscaler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ class TemporalUpscaler : public Mod {
float m_motion_scale[2]{-1.0f, 1.0f};
float m_jitter_evaluate_scale{1.0f};

d3d12::CommandContext m_copier{};
d3d12::CommandContext m_big_copier{};
std::array<d3d12::CommandContext, 3> m_copiers{};
ComPtr<ID3D12Resource> m_old_backbuffer{};

std::array<std::array<Matrix4x4f, 6>, 2> m_old_projection_matrix{};
Expand Down
17 changes: 13 additions & 4 deletions src/mods/vr/D3D12Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,17 @@ vr::EVRCompositorError D3D12Component::on_frame(VR* vr) {

// TODO: Correct this for the upscaler...?
if (!m_backbuffer_is_8bit) {
auto command_list = m_backbuffer_copy.commands.cmd_list.Get();
m_backbuffer_copy.commands.wait(INFINITE);
auto& commands = m_backbuffer_copy_commands[backbuffer_index % m_backbuffer_copy_commands.size()];
auto command_list = commands.cmd_list.Get();
commands.wait(INFINITE);

// Copy current backbuffer into our copy so we can use it as an SRV.
m_backbuffer_copy.commands.copy(backbuffer.Get(), m_backbuffer_copy.texture.Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_PRESENT);
commands.copy(backbuffer.Get(), m_backbuffer_copy.texture.Get(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_PRESENT);

// Convert the backbuffer to 8-bit.
render_srv_to_rtv(command_list, m_backbuffer_copy, m_converted_eye_tex, D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_PIXEL_SHADER_RESOURCE);

m_backbuffer_copy.commands.execute();
commands.execute();
}

auto eye_texture = m_backbuffer_is_8bit ? backbuffer : m_converted_eye_tex.texture;
Expand Down Expand Up @@ -296,6 +297,10 @@ void D3D12Component::on_reset(VR* vr) {
for (auto& copier : m_generic_copiers) {
copier.reset();
}

for (auto& commands : m_backbuffer_copy_commands) {
commands.reset();
}

m_prev_backbuffer.Reset();
m_backbuffer_copy.reset();
Expand Down Expand Up @@ -484,6 +489,10 @@ void D3D12Component::setup() {
for (auto& copier : m_generic_copiers) {
copier.setup(L"Generic Copier");
}

for (auto& commands : m_backbuffer_copy_commands) {
commands.setup(L"Backbuffer Copy Commands");
}

setup_sprite_batch_pso(rt_desc.Format);

Expand Down
5 changes: 3 additions & 2 deletions src/mods/vr/D3D12Component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <../../directxtk12-src/Inc/GraphicsMemory.h>
#include <../../directxtk12-src/Inc/SpriteBatch.h>

#include "d3d12/ResourceCopier.hpp"
#include "d3d12/CommandContext.hpp"
#include "d3d12/TextureContext.hpp"

#define XR_USE_PLATFORM_WIN32
Expand Down Expand Up @@ -55,7 +55,8 @@ class D3D12Component {
ComPtr<ID3D12Resource> m_prev_backbuffer{};
d3d12::TextureContext m_backbuffer_copy{};
d3d12::TextureContext m_converted_eye_tex{};
std::array<d3d12::ResourceCopier, 3> m_generic_copiers{};
std::array<d3d12::CommandContext, 3> m_generic_copiers{};
std::array<d3d12::CommandContext, 3> m_backbuffer_copy_commands{};

std::unique_ptr<DirectX::DX12::SpriteBatch> m_sprite_batch{};

Expand Down

0 comments on commit f7560a0

Please sign in to comment.