GPU/HW: Use GSVector instead of Rectangle
This commit is contained in:
@@ -14,7 +14,6 @@
|
||||
#include "common/file_system.h"
|
||||
#include "common/log.h"
|
||||
#include "common/path.h"
|
||||
#include "common/rectangle.h"
|
||||
#include "common/string_util.h"
|
||||
|
||||
#include "fmt/format.h"
|
||||
@@ -1086,17 +1085,18 @@ void D3D11Device::UnbindTexture(D3D11Texture* tex)
|
||||
}
|
||||
}
|
||||
|
||||
void D3D11Device::SetViewport(s32 x, s32 y, s32 width, s32 height)
|
||||
void D3D11Device::SetViewport(const GSVector4i rc)
|
||||
{
|
||||
const CD3D11_VIEWPORT vp(static_cast<float>(x), static_cast<float>(y), static_cast<float>(width),
|
||||
static_cast<float>(height), 0.0f, 1.0f);
|
||||
const CD3D11_VIEWPORT vp(static_cast<float>(rc.left), static_cast<float>(rc.top), static_cast<float>(rc.width()),
|
||||
static_cast<float>(rc.height()), 0.0f, 1.0f);
|
||||
m_context->RSSetViewports(1, &vp);
|
||||
}
|
||||
|
||||
void D3D11Device::SetScissor(s32 x, s32 y, s32 width, s32 height)
|
||||
void D3D11Device::SetScissor(const GSVector4i rc)
|
||||
{
|
||||
const CD3D11_RECT rc(x, y, x + width, y + height);
|
||||
m_context->RSSetScissorRects(1, &rc);
|
||||
alignas(16) D3D11_RECT drc;
|
||||
GSVector4i::store<true>(&drc, rc);
|
||||
m_context->RSSetScissorRects(1, &drc);
|
||||
}
|
||||
|
||||
void D3D11Device::Draw(u32 vertex_count, u32 base_vertex)
|
||||
|
||||
@@ -92,8 +92,8 @@ public:
|
||||
void SetPipeline(GPUPipeline* pipeline) override;
|
||||
void SetTextureSampler(u32 slot, GPUTexture* texture, GPUSampler* sampler) override;
|
||||
void SetTextureBuffer(u32 slot, GPUTextureBuffer* buffer) override;
|
||||
void SetViewport(s32 x, s32 y, s32 width, s32 height) override;
|
||||
void SetScissor(s32 x, s32 y, s32 width, s32 height) override;
|
||||
void SetViewport(const GSVector4i rc) override;
|
||||
void SetScissor(const GSVector4i rc) override;
|
||||
void Draw(u32 vertex_count, u32 base_vertex) override;
|
||||
void DrawIndexed(u32 index_count, u32 base_index, u32 base_vertex) override;
|
||||
void DrawIndexedWithBarrier(u32 index_count, u32 base_index, u32 base_vertex, DrawBarrier type) override;
|
||||
|
||||
@@ -1927,8 +1927,8 @@ void D3D12Device::SetViewport(ID3D12GraphicsCommandList4* cmdlist)
|
||||
{
|
||||
const D3D12_VIEWPORT vp = {static_cast<float>(m_current_viewport.left),
|
||||
static_cast<float>(m_current_viewport.top),
|
||||
static_cast<float>(m_current_viewport.GetWidth()),
|
||||
static_cast<float>(m_current_viewport.GetHeight()),
|
||||
static_cast<float>(m_current_viewport.width()),
|
||||
static_cast<float>(m_current_viewport.height()),
|
||||
0.0f,
|
||||
1.0f};
|
||||
cmdlist->RSSetViewports(1, &vp);
|
||||
@@ -1936,9 +1936,8 @@ void D3D12Device::SetViewport(ID3D12GraphicsCommandList4* cmdlist)
|
||||
|
||||
void D3D12Device::SetScissor(ID3D12GraphicsCommandList4* cmdlist)
|
||||
{
|
||||
const D3D12_RECT rc = {static_cast<LONG>(m_current_scissor.left), static_cast<LONG>(m_current_scissor.top),
|
||||
static_cast<LONG>(m_current_scissor.right), static_cast<LONG>(m_current_scissor.bottom)};
|
||||
cmdlist->RSSetScissorRects(1, &rc);
|
||||
static_assert(sizeof(GSVector4i) == sizeof(D3D12_RECT));
|
||||
cmdlist->RSSetScissorRects(1, reinterpret_cast<const D3D12_RECT*>(&m_current_scissor));
|
||||
}
|
||||
|
||||
void D3D12Device::SetTextureSampler(u32 slot, GPUTexture* texture, GPUSampler* sampler)
|
||||
@@ -2027,10 +2026,9 @@ void D3D12Device::UnbindTextureBuffer(D3D12TextureBuffer* buf)
|
||||
m_dirty_flags |= DIRTY_FLAG_TEXTURES;
|
||||
}
|
||||
|
||||
void D3D12Device::SetViewport(s32 x, s32 y, s32 width, s32 height)
|
||||
void D3D12Device::SetViewport(const GSVector4i rc)
|
||||
{
|
||||
const Common::Rectangle<s32> rc = Common::Rectangle<s32>::FromExtents(x, y, width, height);
|
||||
if (m_current_viewport == rc)
|
||||
if (m_current_viewport.eq(rc))
|
||||
return;
|
||||
|
||||
m_current_viewport = rc;
|
||||
@@ -2041,10 +2039,9 @@ void D3D12Device::SetViewport(s32 x, s32 y, s32 width, s32 height)
|
||||
SetViewport(GetCommandList());
|
||||
}
|
||||
|
||||
void D3D12Device::SetScissor(s32 x, s32 y, s32 width, s32 height)
|
||||
void D3D12Device::SetScissor(const GSVector4i rc)
|
||||
{
|
||||
const Common::Rectangle<s32> rc = Common::Rectangle<s32>::FromExtents(x, y, width, height);
|
||||
if (m_current_scissor == rc)
|
||||
if (m_current_scissor.eq(rc))
|
||||
return;
|
||||
|
||||
m_current_scissor = rc;
|
||||
|
||||
@@ -114,8 +114,8 @@ public:
|
||||
void SetPipeline(GPUPipeline* pipeline) override;
|
||||
void SetTextureSampler(u32 slot, GPUTexture* texture, GPUSampler* sampler) override;
|
||||
void SetTextureBuffer(u32 slot, GPUTextureBuffer* buffer) override;
|
||||
void SetViewport(s32 x, s32 y, s32 width, s32 height) override;
|
||||
void SetScissor(s32 x, s32 y, s32 width, s32 height) override;
|
||||
void SetViewport(const GSVector4i rc) override;
|
||||
void SetScissor(const GSVector4i rc) override;
|
||||
void Draw(u32 vertex_count, u32 base_vertex) override;
|
||||
void DrawIndexed(u32 index_count, u32 base_index, u32 base_vertex) override;
|
||||
void DrawIndexedWithBarrier(u32 index_count, u32 base_index, u32 base_vertex, DrawBarrier type) override;
|
||||
@@ -344,6 +344,6 @@ private:
|
||||
std::array<D3D12Texture*, MAX_TEXTURE_SAMPLERS> m_current_textures = {};
|
||||
std::array<D3D12DescriptorHandle, MAX_TEXTURE_SAMPLERS> m_current_samplers = {};
|
||||
D3D12TextureBuffer* m_current_texture_buffer = nullptr;
|
||||
Common::Rectangle<s32> m_current_viewport{0, 0, 1, 1};
|
||||
Common::Rectangle<s32> m_current_scissor{0, 0, 1, 1};
|
||||
GSVector4i m_current_viewport = GSVector4i::cxpr(0, 0, 1, 1);
|
||||
GSVector4i m_current_scissor = {};
|
||||
};
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
#include "common/assert.h"
|
||||
#include "common/error.h"
|
||||
#include "common/file_system.h"
|
||||
#include "common/gsvector.h"
|
||||
#include "common/log.h"
|
||||
#include "common/rectangle.h"
|
||||
#include "common/string_util.h"
|
||||
|
||||
#include "fmt/format.h"
|
||||
@@ -179,7 +179,7 @@ bool D3DCommon::GetRequestedExclusiveFullscreenModeDesc(IDXGIFactory5* factory,
|
||||
DXGI_MODE_DESC* fullscreen_mode, IDXGIOutput** output)
|
||||
{
|
||||
// We need to find which monitor the window is located on.
|
||||
const Common::Rectangle<s32> client_rc_vec(window_rect.left, window_rect.top, window_rect.right, window_rect.bottom);
|
||||
const GSVector4i client_rc_vec(window_rect.left, window_rect.top, window_rect.right, window_rect.bottom);
|
||||
|
||||
// The window might be on a different adapter to which we are rendering.. so we have to enumerate them all.
|
||||
HRESULT hr;
|
||||
@@ -204,10 +204,9 @@ bool D3DCommon::GetRequestedExclusiveFullscreenModeDesc(IDXGIFactory5* factory,
|
||||
else if (FAILED(hr) || FAILED(this_output->GetDesc(&output_desc)))
|
||||
continue;
|
||||
|
||||
const Common::Rectangle<s32> output_rc(output_desc.DesktopCoordinates.left, output_desc.DesktopCoordinates.top,
|
||||
output_desc.DesktopCoordinates.right,
|
||||
output_desc.DesktopCoordinates.bottom);
|
||||
if (!client_rc_vec.Intersects(output_rc))
|
||||
const GSVector4i output_rc(output_desc.DesktopCoordinates.left, output_desc.DesktopCoordinates.top,
|
||||
output_desc.DesktopCoordinates.right, output_desc.DesktopCoordinates.bottom);
|
||||
if (!client_rc_vec.rintersects(output_rc))
|
||||
{
|
||||
intersecting_output = std::move(this_output);
|
||||
break;
|
||||
|
||||
@@ -643,10 +643,25 @@ void GPUDevice::SetRenderTarget(GPUTexture* rt, GPUTexture* ds, GPUPipeline::Ren
|
||||
SetRenderTargets(rt ? &rt : nullptr, rt ? 1 : 0, ds, render_pass_flags);
|
||||
}
|
||||
|
||||
void GPUDevice::SetViewport(s32 x, s32 y, s32 width, s32 height)
|
||||
{
|
||||
SetViewport(GSVector4i(x, y, x + width, y + height));
|
||||
}
|
||||
|
||||
void GPUDevice::SetScissor(s32 x, s32 y, s32 width, s32 height)
|
||||
{
|
||||
SetScissor(GSVector4i(x, y, x + width, y + height));
|
||||
}
|
||||
|
||||
void GPUDevice::SetViewportAndScissor(s32 x, s32 y, s32 width, s32 height)
|
||||
{
|
||||
SetViewport(x, y, width, height);
|
||||
SetScissor(x, y, width, height);
|
||||
SetViewportAndScissor(GSVector4i(x, y, x + width, y + height));
|
||||
}
|
||||
|
||||
void GPUDevice::SetViewportAndScissor(const GSVector4i rc)
|
||||
{
|
||||
SetViewport(rc);
|
||||
SetScissor(rc);
|
||||
}
|
||||
|
||||
void GPUDevice::ClearRenderTarget(GPUTexture* t, u32 c)
|
||||
@@ -818,11 +833,13 @@ bool GPUDevice::UsesLowerLeftOrigin() const
|
||||
return (api == RenderAPI::OpenGL || api == RenderAPI::OpenGLES);
|
||||
}
|
||||
|
||||
Common::Rectangle<s32> GPUDevice::FlipToLowerLeft(const Common::Rectangle<s32>& rc, s32 target_height)
|
||||
GSVector4i GPUDevice::FlipToLowerLeft(GSVector4i rc, s32 target_height)
|
||||
{
|
||||
const s32 height = rc.GetHeight();
|
||||
const s32 height = rc.height();
|
||||
const s32 flipped_y = target_height - rc.top - height;
|
||||
return Common::Rectangle<s32>(rc.left, flipped_y, rc.right, flipped_y + height);
|
||||
rc.top = flipped_y;
|
||||
rc.bottom = flipped_y + height;
|
||||
return rc;
|
||||
}
|
||||
|
||||
bool GPUDevice::IsTexturePoolType(GPUTexture::Type type)
|
||||
|
||||
@@ -8,8 +8,8 @@
|
||||
#include "window_info.h"
|
||||
|
||||
#include "common/bitfield.h"
|
||||
#include "common/gsvector.h"
|
||||
#include "common/heap_array.h"
|
||||
#include "common/rectangle.h"
|
||||
#include "common/small_string.h"
|
||||
#include "common/types.h"
|
||||
|
||||
@@ -676,11 +676,14 @@ public:
|
||||
virtual void SetPipeline(GPUPipeline* pipeline) = 0;
|
||||
virtual void SetTextureSampler(u32 slot, GPUTexture* texture, GPUSampler* sampler) = 0;
|
||||
virtual void SetTextureBuffer(u32 slot, GPUTextureBuffer* buffer) = 0;
|
||||
virtual void SetViewport(s32 x, s32 y, s32 width, s32 height) = 0; // TODO: Rectangle
|
||||
virtual void SetScissor(s32 x, s32 y, s32 width, s32 height) = 0;
|
||||
virtual void SetViewport(const GSVector4i rc) = 0;
|
||||
virtual void SetScissor(const GSVector4i rc) = 0;
|
||||
void SetRenderTarget(GPUTexture* rt, GPUTexture* ds = nullptr,
|
||||
GPUPipeline::RenderPassFlag render_pass_flags = GPUPipeline::NoRenderPassFlags);
|
||||
void SetViewport(s32 x, s32 y, s32 width, s32 height);
|
||||
void SetScissor(s32 x, s32 y, s32 width, s32 height);
|
||||
void SetViewportAndScissor(s32 x, s32 y, s32 width, s32 height);
|
||||
void SetViewportAndScissor(const GSVector4i rc);
|
||||
|
||||
// Drawing abstraction.
|
||||
virtual void Draw(u32 vertex_count, u32 base_vertex) = 0;
|
||||
@@ -704,7 +707,7 @@ public:
|
||||
|
||||
bool UpdateImGuiFontTexture();
|
||||
bool UsesLowerLeftOrigin() const;
|
||||
static Common::Rectangle<s32> FlipToLowerLeft(const Common::Rectangle<s32>& rc, s32 target_height);
|
||||
static GSVector4i FlipToLowerLeft(GSVector4i rc, s32 target_height);
|
||||
bool ResizeTexture(std::unique_ptr<GPUTexture>* tex, u32 new_width, u32 new_height, GPUTexture::Type type,
|
||||
GPUTexture::Format format, bool preserve = true);
|
||||
bool ShouldSkipPresentingFrame();
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
// SPDX-FileCopyrightText: 2019-2023 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-FileCopyrightText: 2019-2024 Connor McLaughlin <stenzek@gmail.com>
|
||||
// SPDX-License-Identifier: (GPL-3.0 OR CC-BY-NC-ND-4.0)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "common/gsvector.h"
|
||||
#include "common/types.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -103,6 +104,10 @@ public:
|
||||
ALWAYS_INLINE u32 GetSamples() const { return m_samples; }
|
||||
ALWAYS_INLINE Type GetType() const { return m_type; }
|
||||
ALWAYS_INLINE Format GetFormat() const { return m_format; }
|
||||
ALWAYS_INLINE GSVector4i GetRect() const
|
||||
{
|
||||
return GSVector4i(0, 0, static_cast<s32>(m_width), static_cast<s32>(m_height));
|
||||
}
|
||||
|
||||
ALWAYS_INLINE bool IsTextureArray() const { return m_layers > 1; }
|
||||
ALWAYS_INLINE bool IsMultisampled() const { return m_samples > 1; }
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "metal_stream_buffer.h"
|
||||
#include "window_info.h"
|
||||
|
||||
#include "common/rectangle.h"
|
||||
#include "common/timer.h"
|
||||
|
||||
#include <atomic>
|
||||
@@ -255,8 +254,8 @@ public:
|
||||
void SetPipeline(GPUPipeline* pipeline) override;
|
||||
void SetTextureSampler(u32 slot, GPUTexture* texture, GPUSampler* sampler) override;
|
||||
void SetTextureBuffer(u32 slot, GPUTextureBuffer* buffer) override;
|
||||
void SetViewport(s32 x, s32 y, s32 width, s32 height) override;
|
||||
void SetScissor(s32 x, s32 y, s32 width, s32 height) override;
|
||||
void SetViewport(const GSVector4i rc) override;
|
||||
void SetScissor(const GSVector4i rc) override;
|
||||
void Draw(u32 vertex_count, u32 base_vertex) override;
|
||||
void DrawIndexed(u32 index_count, u32 base_index, u32 base_vertex) override;
|
||||
void DrawIndexedWithBarrier(u32 index_count, u32 base_index, u32 base_vertex, DrawBarrier type) override;
|
||||
@@ -404,8 +403,8 @@ private:
|
||||
std::array<id<MTLTexture>, MAX_TEXTURE_SAMPLERS> m_current_textures = {};
|
||||
std::array<id<MTLSamplerState>, MAX_TEXTURE_SAMPLERS> m_current_samplers = {};
|
||||
id<MTLBuffer> m_current_ssbo = nil;
|
||||
Common::Rectangle<s32> m_current_viewport = {};
|
||||
Common::Rectangle<s32> m_current_scissor = {};
|
||||
GSVector4i m_current_viewport = {};
|
||||
GSVector4i m_current_scissor = {};
|
||||
|
||||
bool m_vsync_enabled = false;
|
||||
|
||||
|
||||
@@ -766,14 +766,12 @@ bool OpenGLDevice::BeginPresent(bool skip_present)
|
||||
m_last_blend_state.write_a);
|
||||
glEnable(GL_SCISSOR_TEST);
|
||||
|
||||
const Common::Rectangle<s32> window_rc =
|
||||
Common::Rectangle<s32>::FromExtents(0, 0, m_window_info.surface_width, m_window_info.surface_height);
|
||||
|
||||
m_current_fbo = 0;
|
||||
m_num_current_render_targets = 0;
|
||||
std::memset(m_current_render_targets.data(), 0, sizeof(m_current_render_targets));
|
||||
m_current_depth_target = nullptr;
|
||||
|
||||
const GSVector4i window_rc = GSVector4i(0, 0, m_window_info.surface_width, m_window_info.surface_height);
|
||||
m_last_viewport = window_rc;
|
||||
m_last_scissor = window_rc;
|
||||
UpdateViewport();
|
||||
@@ -1220,20 +1218,18 @@ void OpenGLDevice::SetTextureBuffer(u32 slot, GPUTextureBuffer* buffer)
|
||||
}
|
||||
}
|
||||
|
||||
void OpenGLDevice::SetViewport(s32 x, s32 y, s32 width, s32 height)
|
||||
void OpenGLDevice::SetViewport(const GSVector4i rc)
|
||||
{
|
||||
const Common::Rectangle<s32> rc = Common::Rectangle<s32>::FromExtents(x, y, width, height);
|
||||
if (m_last_viewport == rc)
|
||||
if (m_last_viewport.eq(rc))
|
||||
return;
|
||||
|
||||
m_last_viewport = rc;
|
||||
UpdateViewport();
|
||||
}
|
||||
|
||||
void OpenGLDevice::SetScissor(s32 x, s32 y, s32 width, s32 height)
|
||||
void OpenGLDevice::SetScissor(const GSVector4i rc)
|
||||
{
|
||||
const Common::Rectangle<s32> rc = Common::Rectangle<s32>::FromExtents(x, y, width, height);
|
||||
if (m_last_scissor == rc)
|
||||
if (m_last_scissor.eq(rc))
|
||||
return;
|
||||
|
||||
m_last_scissor = rc;
|
||||
@@ -1242,10 +1238,10 @@ void OpenGLDevice::SetScissor(s32 x, s32 y, s32 width, s32 height)
|
||||
|
||||
void OpenGLDevice::UpdateViewport()
|
||||
{
|
||||
glViewport(m_last_viewport.left, m_last_viewport.top, m_last_viewport.GetWidth(), m_last_viewport.GetHeight());
|
||||
glViewport(m_last_viewport.left, m_last_viewport.top, m_last_viewport.width(), m_last_viewport.height());
|
||||
}
|
||||
|
||||
void OpenGLDevice::UpdateScissor()
|
||||
{
|
||||
glScissor(m_last_scissor.left, m_last_scissor.top, m_last_scissor.GetWidth(), m_last_scissor.GetHeight());
|
||||
glScissor(m_last_scissor.left, m_last_scissor.top, m_last_scissor.width(), m_last_scissor.height());
|
||||
}
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
#include "opengl_pipeline.h"
|
||||
#include "opengl_texture.h"
|
||||
|
||||
#include "common/rectangle.h"
|
||||
|
||||
#include <cstdio>
|
||||
#include <memory>
|
||||
#include <tuple>
|
||||
@@ -96,8 +94,8 @@ public:
|
||||
void SetPipeline(GPUPipeline* pipeline) override;
|
||||
void SetTextureSampler(u32 slot, GPUTexture* texture, GPUSampler* sampler) override;
|
||||
void SetTextureBuffer(u32 slot, GPUTextureBuffer* buffer) override;
|
||||
void SetViewport(s32 x, s32 y, s32 width, s32 height) override;
|
||||
void SetScissor(s32 x, s32 y, s32 width, s32 height) override;
|
||||
void SetViewport(const GSVector4i rc) override;
|
||||
void SetScissor(const GSVector4i rc) override;
|
||||
void Draw(u32 vertex_count, u32 base_vertex) override;
|
||||
void DrawIndexed(u32 index_count, u32 base_index, u32 base_vertex) override;
|
||||
void DrawIndexedWithBarrier(u32 index_count, u32 base_index, u32 base_vertex, DrawBarrier type) override;
|
||||
@@ -203,8 +201,8 @@ private:
|
||||
u32 m_last_texture_unit = 0;
|
||||
std::array<std::pair<GLuint, GLuint>, MAX_TEXTURE_SAMPLERS> m_last_samplers = {};
|
||||
GLuint m_last_ssbo = 0;
|
||||
Common::Rectangle<s32> m_last_viewport{0, 0, 1, 1};
|
||||
Common::Rectangle<s32> m_last_scissor{0, 0, 1, 1};
|
||||
GSVector4i m_last_viewport = {};
|
||||
GSVector4i m_last_scissor = GSVector4i::cxpr(0, 0, 1, 1);
|
||||
|
||||
// Misc framebuffers
|
||||
GLuint m_read_fbo = 0;
|
||||
|
||||
@@ -620,8 +620,8 @@ void PostProcessing::Chain::DestroyTextures()
|
||||
}
|
||||
|
||||
bool PostProcessing::Chain::Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target,
|
||||
s32 final_left, s32 final_top, s32 final_width, s32 final_height, s32 orig_width,
|
||||
s32 orig_height, s32 native_width, s32 native_height)
|
||||
GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width,
|
||||
s32 native_height)
|
||||
{
|
||||
GL_SCOPE_FMT("{} Apply", m_section);
|
||||
|
||||
@@ -634,9 +634,8 @@ bool PostProcessing::Chain::Apply(GPUTexture* input_color, GPUTexture* input_dep
|
||||
{
|
||||
const bool is_final = (stage.get() == m_stages.back().get());
|
||||
|
||||
if (!stage->Apply(input_color, input_depth, is_final ? final_target : output, final_left, final_top, final_width,
|
||||
final_height, orig_width, orig_height, native_width, native_height, m_target_width,
|
||||
m_target_height))
|
||||
if (!stage->Apply(input_color, input_depth, is_final ? final_target : output, final_rect, orig_width, orig_height,
|
||||
native_width, native_height, m_target_width, m_target_height))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -134,8 +134,8 @@ public:
|
||||
bool CheckTargets(GPUTexture::Format target_format, u32 target_width, u32 target_height,
|
||||
ProgressCallback* progress = nullptr);
|
||||
|
||||
bool Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, s32 final_left, s32 final_top,
|
||||
s32 final_width, s32 final_height, s32 orig_width, s32 orig_height, s32 native_width, s32 native_height);
|
||||
bool Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, const GSVector4i final_rect,
|
||||
s32 orig_width, s32 orig_height, s32 native_width, s32 native_height);
|
||||
|
||||
private:
|
||||
void ClearStagesWithError(const Error& error);
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
#include "gpu_texture.h"
|
||||
|
||||
#include "common/rectangle.h"
|
||||
#include "common/gsvector.h"
|
||||
#include "common/settings_interface.h"
|
||||
#include "common/timer.h"
|
||||
#include "common/types.h"
|
||||
@@ -49,9 +49,9 @@ public:
|
||||
|
||||
virtual bool CompilePipeline(GPUTexture::Format format, u32 width, u32 height, ProgressCallback* progress) = 0;
|
||||
|
||||
virtual bool Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, s32 final_left,
|
||||
s32 final_top, s32 final_width, s32 final_height, s32 orig_width, s32 orig_height,
|
||||
s32 native_width, s32 native_height, u32 target_width, u32 target_height) = 0;
|
||||
virtual bool Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GSVector4i final_rect,
|
||||
s32 orig_width, s32 orig_height, s32 native_width, s32 native_height, u32 target_width,
|
||||
u32 target_height) = 0;
|
||||
|
||||
protected:
|
||||
static void ParseKeyValue(std::string_view line, std::string_view* key, std::string_view* value);
|
||||
|
||||
@@ -1490,16 +1490,15 @@ bool PostProcessing::ReShadeFXShader::ResizeOutput(GPUTexture::Format format, u3
|
||||
}
|
||||
|
||||
bool PostProcessing::ReShadeFXShader::Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target,
|
||||
s32 final_left, s32 final_top, s32 final_width, s32 final_height,
|
||||
s32 orig_width, s32 orig_height, s32 native_width, s32 native_height,
|
||||
u32 target_width, u32 target_height)
|
||||
GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width,
|
||||
s32 native_height, u32 target_width, u32 target_height)
|
||||
{
|
||||
GL_PUSH_FMT("PostProcessingShaderFX {}", m_name);
|
||||
|
||||
m_frame_count++;
|
||||
|
||||
// Reshade always draws at full size.
|
||||
g_gpu_device->SetViewportAndScissor(0, 0, target_width, target_height);
|
||||
g_gpu_device->SetViewportAndScissor(final_rect);
|
||||
|
||||
if (m_uniforms_size > 0)
|
||||
{
|
||||
@@ -1675,84 +1674,85 @@ bool PostProcessing::ReShadeFXShader::Apply(GPUTexture* input_color, GPUTexture*
|
||||
|
||||
case SourceOptionType::ViewportX:
|
||||
{
|
||||
const float value = static_cast<float>(final_left);
|
||||
const float value = static_cast<float>(final_rect.left);
|
||||
std::memcpy(dst, &value, sizeof(value));
|
||||
}
|
||||
break;
|
||||
|
||||
case SourceOptionType::ViewportY:
|
||||
{
|
||||
const float value = static_cast<float>(final_top);
|
||||
const float value = static_cast<float>(final_rect.top);
|
||||
std::memcpy(dst, &value, sizeof(value));
|
||||
}
|
||||
break;
|
||||
|
||||
case SourceOptionType::ViewportWidth:
|
||||
{
|
||||
const float value = static_cast<float>(final_width);
|
||||
const float value = static_cast<float>(final_rect.width());
|
||||
std::memcpy(dst, &value, sizeof(value));
|
||||
}
|
||||
break;
|
||||
|
||||
case SourceOptionType::ViewportHeight:
|
||||
{
|
||||
const float value = static_cast<float>(final_height);
|
||||
const float value = static_cast<float>(final_rect.height());
|
||||
std::memcpy(dst, &value, sizeof(value));
|
||||
}
|
||||
break;
|
||||
|
||||
case SourceOptionType::ViewportOffset:
|
||||
{
|
||||
const float value[2] = {static_cast<float>(final_left), static_cast<float>(final_top)};
|
||||
std::memcpy(dst, &value, sizeof(value));
|
||||
GSVector4::storel(dst, GSVector4(final_rect));
|
||||
}
|
||||
break;
|
||||
|
||||
case SourceOptionType::ViewportSize:
|
||||
{
|
||||
const float value[2] = {static_cast<float>(final_width), static_cast<float>(final_height)};
|
||||
const float value[2] = {static_cast<float>(final_rect.width()), static_cast<float>(final_rect.height())};
|
||||
std::memcpy(dst, &value, sizeof(value));
|
||||
}
|
||||
break;
|
||||
|
||||
case SourceOptionType::InternalPixelSize:
|
||||
{
|
||||
const float value[2] = {static_cast<float>(final_width) / static_cast<float>(orig_width),
|
||||
static_cast<float>(final_height) / static_cast<float>(orig_height)};
|
||||
const float value[2] = {static_cast<float>(final_rect.width()) / static_cast<float>(orig_width),
|
||||
static_cast<float>(final_rect.height()) / static_cast<float>(orig_height)};
|
||||
std::memcpy(dst, value, sizeof(value));
|
||||
}
|
||||
break;
|
||||
|
||||
case SourceOptionType::InternalNormPixelSize:
|
||||
{
|
||||
const float value[2] = {
|
||||
(static_cast<float>(final_width) / static_cast<float>(orig_width)) / static_cast<float>(target_width),
|
||||
(static_cast<float>(final_height) / static_cast<float>(orig_height)) / static_cast<float>(target_height)};
|
||||
const float value[2] = {(static_cast<float>(final_rect.width()) / static_cast<float>(orig_width)) /
|
||||
static_cast<float>(target_width),
|
||||
(static_cast<float>(final_rect.height()) / static_cast<float>(orig_height)) /
|
||||
static_cast<float>(target_height)};
|
||||
std::memcpy(dst, value, sizeof(value));
|
||||
}
|
||||
break;
|
||||
|
||||
case SourceOptionType::NativePixelSize:
|
||||
{
|
||||
const float value[2] = {static_cast<float>(final_width) / static_cast<float>(native_width),
|
||||
static_cast<float>(final_height) / static_cast<float>(native_height)};
|
||||
const float value[2] = {static_cast<float>(final_rect.width()) / static_cast<float>(native_width),
|
||||
static_cast<float>(final_rect.height()) / static_cast<float>(native_height)};
|
||||
std::memcpy(dst, value, sizeof(value));
|
||||
}
|
||||
break;
|
||||
|
||||
case SourceOptionType::NativeNormPixelSize:
|
||||
{
|
||||
const float value[2] = {
|
||||
(static_cast<float>(final_width) / static_cast<float>(native_width)) / static_cast<float>(target_width),
|
||||
(static_cast<float>(final_height) / static_cast<float>(native_height)) / static_cast<float>(target_height)};
|
||||
const float value[2] = {(static_cast<float>(final_rect.width()) / static_cast<float>(native_width)) /
|
||||
static_cast<float>(target_width),
|
||||
(static_cast<float>(final_rect.height()) / static_cast<float>(native_height)) /
|
||||
static_cast<float>(target_height)};
|
||||
std::memcpy(dst, value, sizeof(value));
|
||||
}
|
||||
break;
|
||||
|
||||
case SourceOptionType::BufferToViewportRatio:
|
||||
{
|
||||
const float value[2] = {static_cast<float>(target_width) / static_cast<float>(final_width),
|
||||
static_cast<float>(target_height) / static_cast<float>(final_height)};
|
||||
const float value[2] = {static_cast<float>(target_width) / static_cast<float>(final_rect.width()),
|
||||
static_cast<float>(target_height) / static_cast<float>(final_rect.height())};
|
||||
std::memcpy(dst, value, sizeof(value));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -31,9 +31,9 @@ public:
|
||||
|
||||
bool ResizeOutput(GPUTexture::Format format, u32 width, u32 height) override;
|
||||
bool CompilePipeline(GPUTexture::Format format, u32 width, u32 height, ProgressCallback* progress) override;
|
||||
bool Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, s32 final_left, s32 final_top,
|
||||
s32 final_width, s32 final_height, s32 orig_width, s32 orig_height, s32 native_width, s32 native_height,
|
||||
u32 target_width, u32 target_height) override;
|
||||
bool Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GSVector4i final_rect,
|
||||
s32 orig_width, s32 orig_height, s32 native_width, s32 native_height, u32 target_width,
|
||||
u32 target_height) override;
|
||||
|
||||
private:
|
||||
using TextureID = s32;
|
||||
|
||||
@@ -168,9 +168,8 @@ bool PostProcessing::GLSLShader::CompilePipeline(GPUTexture::Format format, u32
|
||||
}
|
||||
|
||||
bool PostProcessing::GLSLShader::Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target,
|
||||
s32 final_left, s32 final_top, s32 final_width, s32 final_height, s32 orig_width,
|
||||
s32 orig_height, s32 native_width, s32 native_height, u32 target_width,
|
||||
u32 target_height)
|
||||
GSVector4i final_rect, s32 orig_width, s32 orig_height, s32 native_width,
|
||||
s32 native_height, u32 target_width, u32 target_height)
|
||||
{
|
||||
GL_SCOPE_FMT("GLSL Shader {}", m_name);
|
||||
|
||||
@@ -188,12 +187,12 @@ bool PostProcessing::GLSLShader::Apply(GPUTexture* input_color, GPUTexture* inpu
|
||||
|
||||
g_gpu_device->SetPipeline(m_pipeline.get());
|
||||
g_gpu_device->SetTextureSampler(0, input_color, m_sampler.get());
|
||||
g_gpu_device->SetViewportAndScissor(final_left, final_top, final_width, final_height);
|
||||
g_gpu_device->SetViewportAndScissor(final_rect);
|
||||
|
||||
const u32 uniforms_size = GetUniformsSize();
|
||||
void* uniforms = g_gpu_device->MapUniformBuffer(uniforms_size);
|
||||
FillUniformBuffer(uniforms, final_left, final_top, final_width, final_height, target_width, target_height, orig_width,
|
||||
orig_height, native_width, native_height,
|
||||
FillUniformBuffer(uniforms, final_rect.left, final_rect.top, final_rect.width(), final_rect.height(), target_width,
|
||||
target_height, orig_width, orig_height, native_width, native_height,
|
||||
static_cast<float>(PostProcessing::GetTimer().GetTimeSeconds()));
|
||||
g_gpu_device->UnmapUniformBuffer(uniforms_size);
|
||||
g_gpu_device->Draw(3, 0);
|
||||
|
||||
@@ -24,9 +24,9 @@ public:
|
||||
|
||||
bool ResizeOutput(GPUTexture::Format format, u32 width, u32 height) override;
|
||||
bool CompilePipeline(GPUTexture::Format format, u32 width, u32 height, ProgressCallback* progress) override;
|
||||
bool Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, s32 final_left, s32 final_top,
|
||||
s32 final_width, s32 final_height, s32 orig_width, s32 orig_height, s32 native_width, s32 native_height,
|
||||
u32 target_width, u32 target_height) override;
|
||||
bool Apply(GPUTexture* input_color, GPUTexture* input_depth, GPUTexture* final_target, GSVector4i final_rect,
|
||||
s32 orig_width, s32 orig_height, s32 native_width, s32 native_height, u32 target_width,
|
||||
u32 target_height) override;
|
||||
|
||||
private:
|
||||
struct CommonUniforms
|
||||
|
||||
@@ -3611,15 +3611,14 @@ void VulkanDevice::SetInitialPipelineState()
|
||||
|
||||
const VkViewport vp = {static_cast<float>(m_current_viewport.left),
|
||||
static_cast<float>(m_current_viewport.top),
|
||||
static_cast<float>(m_current_viewport.GetWidth()),
|
||||
static_cast<float>(m_current_viewport.GetHeight()),
|
||||
static_cast<float>(m_current_viewport.width()),
|
||||
static_cast<float>(m_current_viewport.height()),
|
||||
0.0f,
|
||||
1.0f};
|
||||
vkCmdSetViewport(GetCurrentCommandBuffer(), 0, 1, &vp);
|
||||
|
||||
const VkRect2D vrc = {
|
||||
{m_current_scissor.left, m_current_scissor.top},
|
||||
{static_cast<u32>(m_current_scissor.GetWidth()), static_cast<u32>(m_current_scissor.GetHeight())}};
|
||||
const VkRect2D vrc = {{m_current_scissor.left, m_current_scissor.top},
|
||||
{static_cast<u32>(m_current_scissor.width()), static_cast<u32>(m_current_scissor.height())}};
|
||||
vkCmdSetScissor(GetCurrentCommandBuffer(), 0, 1, &vrc);
|
||||
}
|
||||
|
||||
@@ -3706,10 +3705,9 @@ void VulkanDevice::UnbindTextureBuffer(VulkanTextureBuffer* buf)
|
||||
m_dirty_flags |= DIRTY_FLAG_TEXTURES_OR_SAMPLERS;
|
||||
}
|
||||
|
||||
void VulkanDevice::SetViewport(s32 x, s32 y, s32 width, s32 height)
|
||||
void VulkanDevice::SetViewport(const GSVector4i rc)
|
||||
{
|
||||
const Common::Rectangle<s32> rc = Common::Rectangle<s32>::FromExtents(x, y, width, height);
|
||||
if (m_current_viewport == rc)
|
||||
if (m_current_viewport.eq(rc))
|
||||
return;
|
||||
|
||||
m_current_viewport = rc;
|
||||
@@ -3717,15 +3715,18 @@ void VulkanDevice::SetViewport(s32 x, s32 y, s32 width, s32 height)
|
||||
if (m_dirty_flags & DIRTY_FLAG_INITIAL)
|
||||
return;
|
||||
|
||||
const VkViewport vp = {
|
||||
static_cast<float>(x), static_cast<float>(y), static_cast<float>(width), static_cast<float>(height), 0.0f, 1.0f};
|
||||
const VkViewport vp = {static_cast<float>(rc.x),
|
||||
static_cast<float>(rc.y),
|
||||
static_cast<float>(rc.width()),
|
||||
static_cast<float>(rc.height()),
|
||||
0.0f,
|
||||
1.0f};
|
||||
vkCmdSetViewport(GetCurrentCommandBuffer(), 0, 1, &vp);
|
||||
}
|
||||
|
||||
void VulkanDevice::SetScissor(s32 x, s32 y, s32 width, s32 height)
|
||||
void VulkanDevice::SetScissor(const GSVector4i rc)
|
||||
{
|
||||
const Common::Rectangle<s32> rc = Common::Rectangle<s32>::FromExtents(x, y, width, height);
|
||||
if (m_current_scissor == rc)
|
||||
if (m_current_scissor.eq(rc))
|
||||
return;
|
||||
|
||||
m_current_scissor = rc;
|
||||
@@ -3733,7 +3734,7 @@ void VulkanDevice::SetScissor(s32 x, s32 y, s32 width, s32 height)
|
||||
if (m_dirty_flags & DIRTY_FLAG_INITIAL)
|
||||
return;
|
||||
|
||||
const VkRect2D vrc = {{x, y}, {static_cast<u32>(width), static_cast<u32>(height)}};
|
||||
const VkRect2D vrc = {{rc.x, rc.y}, {static_cast<u32>(rc.width()), static_cast<u32>(rc.height())}};
|
||||
vkCmdSetScissor(GetCurrentCommandBuffer(), 0, 1, &vrc);
|
||||
}
|
||||
|
||||
|
||||
@@ -122,8 +122,8 @@ public:
|
||||
void SetPipeline(GPUPipeline* pipeline) override;
|
||||
void SetTextureSampler(u32 slot, GPUTexture* texture, GPUSampler* sampler) override;
|
||||
void SetTextureBuffer(u32 slot, GPUTextureBuffer* buffer) override;
|
||||
void SetViewport(s32 x, s32 y, s32 width, s32 height) override;
|
||||
void SetScissor(s32 x, s32 y, s32 width, s32 height) override;
|
||||
void SetViewport(const GSVector4i rc) override;
|
||||
void SetScissor(const GSVector4i rc) override;
|
||||
void Draw(u32 vertex_count, u32 base_vertex) override;
|
||||
void DrawIndexed(u32 index_count, u32 base_index, u32 base_vertex) override;
|
||||
void DrawIndexedWithBarrier(u32 index_count, u32 base_index, u32 base_vertex, DrawBarrier type) override;
|
||||
@@ -477,6 +477,6 @@ private:
|
||||
std::array<VulkanTexture*, MAX_TEXTURE_SAMPLERS> m_current_textures = {};
|
||||
std::array<VkSampler, MAX_TEXTURE_SAMPLERS> m_current_samplers = {};
|
||||
VulkanTextureBuffer* m_current_texture_buffer = nullptr;
|
||||
Common::Rectangle<s32> m_current_viewport{0, 0, 1, 1};
|
||||
Common::Rectangle<s32> m_current_scissor{0, 0, 1, 1};
|
||||
GSVector4i m_current_viewport = {};
|
||||
GSVector4i m_current_scissor = GSVector4i::cxpr(0, 0, 1, 1);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user