| 60 | } |
| 61 | |
| 62 | HRESULT STDMETHODCALLTYPE D3D12CommandQueueDownlevel::Present(ID3D12GraphicsCommandList *pOpenCommandList, ID3D12Resource *pSourceTex2D, HWND hWindow, D3D12_DOWNLEVEL_PRESENT_FLAGS Flags) |
| 63 | { |
| 64 | assert(pSourceTex2D != nullptr); |
| 65 | |
| 66 | // Synchronize access to this command queue while events are invoked and the immediate command list may be accessed |
| 67 | std::unique_lock<std::recursive_mutex> lock(_parent_queue->_mutex); |
| 68 | |
| 69 | _hwnd = hWindow; |
| 70 | _swap_index = (_swap_index + 1) % static_cast<UINT>(_back_buffers.size()); |
| 71 | |
| 72 | // Update source texture render target view |
| 73 | if (_back_buffers[_swap_index] != pSourceTex2D) |
| 74 | { |
| 75 | reshade::reset_effect_runtime(this); |
| 76 | |
| 77 | #if RESHADE_ADDON |
| 78 | const bool resize = (_back_buffers[0] != nullptr); |
| 79 | if (resize) |
| 80 | reshade::invoke_addon_event<reshade::addon_event::destroy_swapchain>(this, resize); |
| 81 | #endif |
| 82 | |
| 83 | // Reduce number of back buffers if less are used than predicted |
| 84 | if (const auto it = std::find(_back_buffers.begin(), _back_buffers.end(), pSourceTex2D); it != _back_buffers.end()) |
| 85 | _back_buffers.erase(it); |
| 86 | else |
| 87 | _back_buffers[_swap_index] = pSourceTex2D; |
| 88 | |
| 89 | // Do not initialize before all back buffers have been set |
| 90 | // The first to be set is at index 1 due to the addition above, so it is sufficient to check the last to be set, which will be at index 0 |
| 91 | if (_back_buffers[0] != nullptr) |
| 92 | { |
| 93 | #if RESHADE_ADDON |
| 94 | reshade::invoke_addon_event<reshade::addon_event::init_swapchain>(this, resize); |
| 95 | #endif |
| 96 | |
| 97 | reshade::init_effect_runtime(this); |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | // Do not call 'present' event before 'init_swapchain' event |
| 102 | if (_back_buffers[0] != nullptr) |
| 103 | { |
| 104 | #if RESHADE_ADDON |
| 105 | reshade::invoke_addon_event<reshade::addon_event::present>(_parent_queue, this, nullptr, nullptr, 0, nullptr); |
| 106 | #endif |
| 107 | |
| 108 | reshade::present_effect_runtime(this); |
| 109 | |
| 110 | _parent_queue->flush_immediate_command_list(); |
| 111 | } |
| 112 | |
| 113 | lock.unlock(); |
| 114 | |
| 115 | // Get original command list pointer from proxy object |
| 116 | if (com_ptr<D3D12GraphicsCommandList> command_list_proxy; |
| 117 | SUCCEEDED(pOpenCommandList->QueryInterface(&command_list_proxy))) |
| 118 | pOpenCommandList = command_list_proxy->_orig; |
| 119 |
nothing calls this directly
no test coverage detected