Skip to content

Commit

Permalink
Change "get_back_buffer" to use return value instead of output parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
crosire committed Sep 9, 2021
1 parent e045a1b commit 988c806
Show file tree
Hide file tree
Showing 16 changed files with 59 additions and 61 deletions.
13 changes: 5 additions & 8 deletions include/reshade_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -887,19 +887,16 @@ namespace reshade { namespace api
/// Gets the back buffer resource at the specified <paramref name="index"/> in this swap chain.
/// </summary>
/// <param name="index">Index of the back buffer. This has to be between zero and the value returned by <see cref="get_back_buffer_count"/>.</param>
/// <param name="out_handle">Pointer to a variable that is set to the handle of the back buffer resource.</param>
virtual void get_back_buffer(uint32_t index, resource *out_handle) = 0;
/// <summary>
/// Gets the current back buffer resource.
/// </summary>
/// <param name="out_handle">Pointer to a variable that is set to the handle of the back buffer resource.</param>
inline void get_current_back_buffer(resource *out_handle) { get_back_buffer(get_current_back_buffer_index(), out_handle); }

virtual resource get_back_buffer(uint32_t index) = 0;
/// <summary>
/// Gets the number of back buffer resources in this swap chain.
/// </summary>
virtual uint32_t get_back_buffer_count() const = 0;

/// <summary>
/// Gets the current back buffer resource.
/// </summary>
inline resource get_current_back_buffer() { return get_back_buffer(get_current_back_buffer_index()); }
/// <summary>
/// Gets the index of the back buffer resource that can currently be rendered into.
/// </summary>
Expand Down
10 changes: 5 additions & 5 deletions source/d3d10/d3d10_impl_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ reshade::d3d10::swapchain_impl::~swapchain_impl()
on_reset();
}

void reshade::d3d10::swapchain_impl::get_back_buffer(uint32_t index, api::resource *out)
reshade::api::resource reshade::d3d10::swapchain_impl::get_back_buffer(uint32_t index)
{
assert(index == 0);

*out = { reinterpret_cast<uintptr_t>(_backbuffer.get()) };
return { reinterpret_cast<uintptr_t>(_backbuffer.get()) };
}
void reshade::d3d10::swapchain_impl::get_back_buffer_resolved(uint32_t index, api::resource *out)
reshade::api::resource reshade::d3d10::swapchain_impl::get_back_buffer_resolved(uint32_t index)
{
assert(index == 0);

*out = { reinterpret_cast<uintptr_t>(_backbuffer_resolved.get()) };
return { reinterpret_cast<uintptr_t>(_backbuffer_resolved.get()) };
}

bool reshade::d3d10::swapchain_impl::on_init()
Expand Down Expand Up @@ -201,7 +201,7 @@ bool reshade::d3d10::swapchain_impl::on_layer_submit(UINT eye, ID3D10Texture2D *
{
on_reset();

source_desc.Width = target_width;
source_desc.Width = target_width;
source_desc.Height = region_height;
source_desc.MipLevels = 1;
source_desc.ArraySize = 1;
Expand Down
5 changes: 3 additions & 2 deletions source/d3d10/d3d10_impl_swapchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ namespace reshade::d3d10
swapchain_impl(device_impl *device, IDXGISwapChain *swapchain);
~swapchain_impl();

void get_back_buffer(uint32_t index, api::resource *out) final;
void get_back_buffer_resolved(uint32_t index, api::resource *out) final;
api::resource get_back_buffer(uint32_t index) final;
api::resource get_back_buffer_resolved(uint32_t index) final;

uint32_t get_back_buffer_count() const final { return 1; }
uint32_t get_current_back_buffer_index() const final { return 0; }

bool on_init();
void on_reset();

void on_present();
bool on_layer_submit(UINT eye, ID3D10Texture2D *source, const float bounds[4], ID3D10Texture2D **target);

Expand Down
8 changes: 4 additions & 4 deletions source/d3d11/d3d11_impl_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,17 @@ reshade::d3d11::swapchain_impl::~swapchain_impl()
on_reset();
}

void reshade::d3d11::swapchain_impl::get_back_buffer(uint32_t index, api::resource *out)
reshade::api::resource reshade::d3d11::swapchain_impl::get_back_buffer(uint32_t index)
{
assert(index == 0);

*out = { reinterpret_cast<uintptr_t>(_backbuffer.get()) };
return { reinterpret_cast<uintptr_t>(_backbuffer.get()) };
}
void reshade::d3d11::swapchain_impl::get_back_buffer_resolved(uint32_t index, api::resource *out)
reshade::api::resource reshade::d3d11::swapchain_impl::get_back_buffer_resolved(uint32_t index)
{
assert(index == 0);

*out = { reinterpret_cast<uintptr_t>(_backbuffer_resolved.get()) };
return { reinterpret_cast<uintptr_t>(_backbuffer_resolved.get()) };
}

bool reshade::d3d11::swapchain_impl::on_init()
Expand Down
5 changes: 3 additions & 2 deletions source/d3d11/d3d11_impl_swapchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ namespace reshade::d3d11
swapchain_impl(device_impl *device, device_context_impl *immediate_context, IDXGISwapChain *swapchain);
~swapchain_impl();

void get_back_buffer(uint32_t index, api::resource *out) final;
void get_back_buffer_resolved(uint32_t index, api::resource *out) final;
api::resource get_back_buffer(uint32_t index) final;
api::resource get_back_buffer_resolved(uint32_t index) final;

uint32_t get_back_buffer_count() const final { return 1; }
uint32_t get_current_back_buffer_index() const final { return 0; }

bool on_init();
void on_reset();

void on_present();
bool on_layer_submit(UINT eye, ID3D11Texture2D *source, const float bounds[4], ID3D11Texture2D **target);

Expand Down
8 changes: 4 additions & 4 deletions source/d3d12/d3d12_impl_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ reshade::d3d12::swapchain_impl::~swapchain_impl()
on_reset();
}

void reshade::d3d12::swapchain_impl::get_back_buffer(uint32_t index, api::resource *out)
reshade::api::resource reshade::d3d12::swapchain_impl::get_back_buffer(uint32_t index)
{
*out = { reinterpret_cast<uintptr_t>(_backbuffers[index].get()) };
return { reinterpret_cast<uintptr_t>(_backbuffers[index].get()) };
}
void reshade::d3d12::swapchain_impl::get_back_buffer_resolved(uint32_t index, api::resource *out)
reshade::api::resource reshade::d3d12::swapchain_impl::get_back_buffer_resolved(uint32_t index)
{
*out = { reinterpret_cast<uintptr_t>(_backbuffers[index].get()) };
return { reinterpret_cast<uintptr_t>(_backbuffers[index].get()) };
}

uint32_t reshade::d3d12::swapchain_impl::get_back_buffer_count() const
Expand Down
4 changes: 2 additions & 2 deletions source/d3d12/d3d12_impl_swapchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ namespace reshade::d3d12
swapchain_impl(device_impl *device, command_queue_impl *queue, IDXGISwapChain3 *swapchain);
~swapchain_impl();

void get_back_buffer(uint32_t index, api::resource *out) final;
void get_back_buffer_resolved(uint32_t index, api::resource *out) final;
api::resource get_back_buffer(uint32_t index) final;
api::resource get_back_buffer_resolved(uint32_t index) final;

uint32_t get_back_buffer_count() const final;
uint32_t get_current_back_buffer_index() const final;
Expand Down
8 changes: 4 additions & 4 deletions source/d3d9/d3d9_impl_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,17 @@ reshade::d3d9::swapchain_impl::~swapchain_impl()
on_reset();
}

void reshade::d3d9::swapchain_impl::get_back_buffer(uint32_t index, api::resource *out)
reshade::api::resource reshade::d3d9::swapchain_impl::get_back_buffer(uint32_t index)
{
assert(index == 0);

*out = { reinterpret_cast<uintptr_t>(_backbuffer.get()) };
return { reinterpret_cast<uintptr_t>(_backbuffer.get()) };
}
void reshade::d3d9::swapchain_impl::get_back_buffer_resolved(uint32_t index, api::resource *out)
reshade::api::resource reshade::d3d9::swapchain_impl::get_back_buffer_resolved(uint32_t index)
{
assert(index == 0);

*out = { reinterpret_cast<uintptr_t>(_backbuffer_resolved.get()) };
return { reinterpret_cast<uintptr_t>(_backbuffer_resolved.get()) };
}

bool reshade::d3d9::swapchain_impl::on_init(const D3DPRESENT_PARAMETERS &pp)
Expand Down
5 changes: 3 additions & 2 deletions source/d3d9/d3d9_impl_swapchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ namespace reshade::d3d9
swapchain_impl(device_impl *device, IDirect3DSwapChain9 *swapchain);
~swapchain_impl();

void get_back_buffer(uint32_t index, api::resource *out) final;
void get_back_buffer_resolved(uint32_t index, api::resource *out) final;
api::resource get_back_buffer(uint32_t index) final;
api::resource get_back_buffer_resolved(uint32_t index) final;

uint32_t get_back_buffer_count() const final { return 1; }
uint32_t get_current_back_buffer_index() const final { return 0; }

bool on_init(const D3DPRESENT_PARAMETERS &pp);
void on_reset();

void on_present();

private:
Expand Down
11 changes: 7 additions & 4 deletions source/opengl/opengl_impl_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,20 @@ reshade::opengl::swapchain_impl::~swapchain_impl()
on_reset();
}

void reshade::opengl::swapchain_impl::get_back_buffer(uint32_t index, api::resource *out)
reshade::api::resource reshade::opengl::swapchain_impl::get_back_buffer(uint32_t index)
{
assert(index == 0);

*out = make_resource_handle(GL_FRAMEBUFFER_DEFAULT, GL_BACK);
if (_is_vr)
return make_resource_handle(GL_RENDERBUFFER, _rbo);
else
return make_resource_handle(GL_FRAMEBUFFER_DEFAULT, GL_BACK);
}
void reshade::opengl::swapchain_impl::get_back_buffer_resolved(uint32_t index, api::resource *out)
reshade::api::resource reshade::opengl::swapchain_impl::get_back_buffer_resolved(uint32_t index)
{
assert(index == 0);

*out = make_resource_handle(GL_RENDERBUFFER, _rbo);
return make_resource_handle(GL_RENDERBUFFER, _rbo);
}

bool reshade::opengl::swapchain_impl::on_init(HWND hwnd, unsigned int width, unsigned int height)
Expand Down
4 changes: 2 additions & 2 deletions source/opengl/opengl_impl_swapchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ namespace reshade::opengl

uint64_t get_native_object() const final { return reinterpret_cast<uintptr_t>(*_hdcs.begin()); } // Simply return the first device context

void get_back_buffer(uint32_t index, api::resource *out) final;
void get_back_buffer_resolved(uint32_t index, api::resource *out) final;
api::resource get_back_buffer(uint32_t index) final;
api::resource get_back_buffer_resolved(uint32_t index) final;

uint32_t get_back_buffer_count() const final { return 1; }
uint32_t get_current_back_buffer_index() const final { return 0; }
Expand Down
13 changes: 5 additions & 8 deletions source/runtime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,6 @@ bool reshade::runtime::on_init(input::window_handle window)
// Create render passes for the back buffer
for (uint32_t i = 0; i < get_back_buffer_count(); ++i)
{
api::resource backbuffer;
get_back_buffer_resolved(i, &backbuffer);

api::render_pass_desc pass_desc = {};
pass_desc.depth_stencil_format = _effect_stencil_format;
pass_desc.render_targets_format[0] = api::format_to_default_typed(_backbuffer_format, 0);
Expand All @@ -230,6 +227,8 @@ bool reshade::runtime::on_init(input::window_handle window)
goto exit_failure;
}

const api::resource backbuffer = get_back_buffer_resolved(i);

if (!_device->create_resource_view(backbuffer, api::resource_usage::render_target, api::resource_view_desc(pass_desc.render_targets_format[0]), &_backbuffer_targets.emplace_back()) ||
!_device->create_resource_view(backbuffer, api::resource_usage::render_target, api::resource_view_desc(pass_desc_srgb.render_targets_format[0]), &_backbuffer_targets.emplace_back()))
{
Expand Down Expand Up @@ -3148,8 +3147,7 @@ void reshade::runtime::update_and_render_effects()
}
}

api::resource backbuffer;
get_current_back_buffer_resolved(&backbuffer);
const api::resource backbuffer = get_current_back_buffer_resolved();

api::command_list *const cmd_list = _graphics_queue->get_immediate_command_list();
cmd_list->barrier(backbuffer, api::resource_usage::present, api::resource_usage::render_target);
Expand Down Expand Up @@ -3199,10 +3197,9 @@ void reshade::runtime::render_technique(technique &tech)
{
const effect &effect = _effects[tech.effect_index];

api::command_list *const cmd_list = _graphics_queue->get_immediate_command_list();
const api::resource backbuffer = get_current_back_buffer_resolved();

api::resource backbuffer;
get_current_back_buffer_resolved(&backbuffer);
api::command_list *const cmd_list = _graphics_queue->get_immediate_command_list();

#if RESHADE_GUI
if (_gather_gpu_statistics)
Expand Down
8 changes: 3 additions & 5 deletions source/runtime.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ namespace reshade
/// <param name="pixels">Pointer to an array of <c>width * height * 4</c> bytes the image data is written to.</param>
bool capture_screenshot(uint8_t *pixels) final
{
api::resource resource;
get_current_back_buffer_resolved(&resource);
return get_texture_data(resource, api::resource_usage::present, pixels);
return get_texture_data(get_current_back_buffer_resolved(), api::resource_usage::present, pixels);
}

/// <summary>
Expand Down Expand Up @@ -141,8 +139,8 @@ namespace reshade
api::device *get_device() final { return _device; }
api::command_queue *get_command_queue() final { return _graphics_queue; }

virtual void get_back_buffer_resolved(uint32_t index, api::resource *out) = 0;
inline void get_current_back_buffer_resolved(api::resource *out) { get_back_buffer_resolved(get_current_back_buffer_index(), out); }
virtual api::resource get_back_buffer_resolved(uint32_t index) = 0;
api::resource get_current_back_buffer_resolved() { return get_back_buffer_resolved(get_current_back_buffer_index()); }

bool on_init(void *window);
void on_reset();
Expand Down
5 changes: 2 additions & 3 deletions source/runtime_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -935,10 +935,9 @@ void reshade::runtime::draw_gui()
if (ImDrawData *const draw_data = ImGui::GetDrawData();
draw_data != nullptr && draw_data->CmdListsCount != 0 && draw_data->TotalVtxCount != 0)
{
api::command_list *const cmd_list = _graphics_queue->get_immediate_command_list();
const api::resource backbuffer = get_current_back_buffer_resolved();

api::resource backbuffer;
get_current_back_buffer_resolved(&backbuffer);
api::command_list *const cmd_list = _graphics_queue->get_immediate_command_list();
cmd_list->barrier(backbuffer, api::resource_usage::present, api::resource_usage::render_target);

render_imgui_draw_data(draw_data, _backbuffer_passes[get_current_back_buffer_index() * 2], _backbuffer_fbos[get_current_back_buffer_index() * 2]);
Expand Down
8 changes: 4 additions & 4 deletions source/vulkan/vulkan_impl_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ reshade::vulkan::swapchain_impl::~swapchain_impl()
on_reset();
}

void reshade::vulkan::swapchain_impl::get_back_buffer(uint32_t index, api::resource *out)
reshade::api::resource reshade::vulkan::swapchain_impl::get_back_buffer(uint32_t index)
{
*out = { (uint64_t)_swapchain_images[index] };
return { (uint64_t)_swapchain_images[index] };
}
void reshade::vulkan::swapchain_impl::get_back_buffer_resolved(uint32_t index, api::resource *out)
reshade::api::resource reshade::vulkan::swapchain_impl::get_back_buffer_resolved(uint32_t index)
{
*out = { (uint64_t)_swapchain_images[index] };
return { (uint64_t)_swapchain_images[index] };
}

uint32_t reshade::vulkan::swapchain_impl::get_back_buffer_count() const
Expand Down
5 changes: 3 additions & 2 deletions source/vulkan/vulkan_impl_swapchain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ namespace reshade::vulkan
swapchain_impl(device_impl *device, command_queue_impl *graphics_queue);
~swapchain_impl();

void get_back_buffer(uint32_t index, api::resource *out) final;
void get_back_buffer_resolved(uint32_t index, api::resource *out) final;
api::resource get_back_buffer(uint32_t index) final;
api::resource get_back_buffer_resolved(uint32_t index) final;

uint32_t get_back_buffer_count() const final;
uint32_t get_current_back_buffer_index() const final;

bool on_init(VkSwapchainKHR swapchain, const VkSwapchainCreateInfoKHR &desc, HWND hwnd);
void on_reset();

void on_present(VkQueue queue, const uint32_t swapchain_image_index, std::vector<VkSemaphore> &wait);
bool on_layer_submit(uint32_t eye, VkImage source, const VkExtent2D &source_extent, VkFormat source_format, VkSampleCountFlags source_samples, uint32_t source_layer_index, const float bounds[4], VkImage *target_image);

Expand Down

0 comments on commit 988c806

Please sign in to comment.