chore: make yuzu REUSE compliant
[REUSE] is a specification that aims at making file copyright
information consistent, so that it can be both human and machine
readable. It basically requires that all files have a header containing
copyright and licensing information. When this isn't possible, like
when dealing with binary assets, generated files or embedded third-party
dependencies, it is permitted to insert copyright information in the
`.reuse/dep5` file.
Oh, and it also requires that all the licenses used in the project are
present in the `LICENSES` folder, that's why the diff is so huge.
This can be done automatically with `reuse download --all`.
The `reuse` tool also contains a handy subcommand that analyzes the
project and tells whether or not the project is (still) compliant,
`reuse lint`.
Following REUSE has a few advantages over the current approach:
- Copyright information is easy to access for users / downstream
- Files like `dist/license.md` do not need to exist anymore, as
`.reuse/dep5` is used instead
- `reuse lint` makes it easy to ensure that copyright information of
files like binary assets / images is always accurate and up to date
To add copyright information of files that didn't have it I looked up
who committed what and when, for each file. As yuzu contributors do not
have to sign a CLA or similar I couldn't assume that copyright ownership
was of the "yuzu Emulator Project", so I used the name and/or email of
the commit author instead.
[REUSE]: https://reuse.software
Follow-up to 01cf05bc75b1e47beb08937439f3ed9339e7b254
2022-05-15 02:06:02 +02:00
|
|
|
// SPDX-FileCopyrightText: 2014 Citra Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2014-04-06 22:55:39 +02:00
|
|
|
|
2015-06-21 18:47:21 +02:00
|
|
|
#include <algorithm>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdlib>
|
2016-04-30 17:34:51 +02:00
|
|
|
#include <memory>
|
2020-03-25 05:57:36 +01:00
|
|
|
|
2016-04-30 17:34:51 +02:00
|
|
|
#include <glad/glad.h>
|
2020-03-25 05:57:36 +01:00
|
|
|
|
2015-06-21 18:47:21 +02:00
|
|
|
#include "common/assert.h"
|
|
|
|
#include "common/logging/log.h"
|
2020-02-17 20:31:14 +01:00
|
|
|
#include "common/microprofile.h"
|
2021-04-15 01:07:40 +02:00
|
|
|
#include "common/settings.h"
|
2018-08-31 18:21:34 +02:00
|
|
|
#include "common/telemetry.h"
|
2017-02-21 01:31:59 +01:00
|
|
|
#include "core/core_timing.h"
|
2016-12-23 14:37:40 +01:00
|
|
|
#include "core/frontend/emu_window.h"
|
2016-04-30 17:34:51 +02:00
|
|
|
#include "core/memory.h"
|
2018-08-31 18:21:34 +02:00
|
|
|
#include "core/telemetry_session.h"
|
2021-10-21 01:36:06 +02:00
|
|
|
#include "video_core/host_shaders/fxaa_frag.h"
|
|
|
|
#include "video_core/host_shaders/fxaa_vert.h"
|
2020-08-24 02:28:15 +02:00
|
|
|
#include "video_core/host_shaders/opengl_present_frag.h"
|
2021-10-23 06:09:29 +02:00
|
|
|
#include "video_core/host_shaders/opengl_present_scaleforce_frag.h"
|
2020-08-24 02:28:15 +02:00
|
|
|
#include "video_core/host_shaders/opengl_present_vert.h"
|
2022-12-08 22:52:29 +01:00
|
|
|
#include "video_core/host_shaders/opengl_smaa_glsl.h"
|
2021-09-10 05:01:39 +02:00
|
|
|
#include "video_core/host_shaders/present_bicubic_frag.h"
|
2021-10-21 02:05:16 +02:00
|
|
|
#include "video_core/host_shaders/present_gaussian_frag.h"
|
2022-12-08 22:52:29 +01:00
|
|
|
#include "video_core/host_shaders/smaa_blending_weight_calculation_frag.h"
|
|
|
|
#include "video_core/host_shaders/smaa_blending_weight_calculation_vert.h"
|
|
|
|
#include "video_core/host_shaders/smaa_edge_detection_frag.h"
|
|
|
|
#include "video_core/host_shaders/smaa_edge_detection_vert.h"
|
|
|
|
#include "video_core/host_shaders/smaa_neighborhood_blending_frag.h"
|
|
|
|
#include "video_core/host_shaders/smaa_neighborhood_blending_vert.h"
|
2018-08-21 01:22:43 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_rasterizer.h"
|
2019-12-26 20:04:41 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
2021-07-11 07:04:52 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_util.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "video_core/renderer_opengl/renderer_opengl.h"
|
2022-12-08 22:52:29 +01:00
|
|
|
#include "video_core/smaa_area_tex.h"
|
|
|
|
#include "video_core/smaa_search_tex.h"
|
2020-12-30 06:25:23 +01:00
|
|
|
#include "video_core/textures/decoders.h"
|
2015-04-04 12:57:31 +02:00
|
|
|
|
2020-02-27 00:28:50 +01:00
|
|
|
namespace OpenGL {
|
2020-03-16 08:03:16 +01:00
|
|
|
namespace {
|
|
|
|
constexpr GLint PositionLocation = 0;
|
|
|
|
constexpr GLint TexCoordLocation = 1;
|
|
|
|
constexpr GLint ModelViewMatrixLocation = 0;
|
|
|
|
|
|
|
|
struct ScreenRectVertex {
|
|
|
|
constexpr ScreenRectVertex(u32 x, u32 y, GLfloat u, GLfloat v)
|
|
|
|
: position{{static_cast<GLfloat>(x), static_cast<GLfloat>(y)}}, tex_coord{{u, v}} {}
|
|
|
|
|
|
|
|
std::array<GLfloat, 2> position;
|
|
|
|
std::array<GLfloat, 2> tex_coord;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Defines a 1:1 pixel ortographic projection matrix with (0,0) on the top-left
|
|
|
|
* corner and (width, height) on the lower-bottom.
|
|
|
|
*
|
|
|
|
* The projection part of the matrix is trivial, hence these operations are represented
|
|
|
|
* by a 3x2 matrix.
|
|
|
|
*/
|
|
|
|
std::array<GLfloat, 3 * 2> MakeOrthographicMatrix(float width, float height) {
|
|
|
|
std::array<GLfloat, 3 * 2> matrix; // Laid out in column-major order
|
2020-02-17 20:31:14 +01:00
|
|
|
|
2020-03-16 08:03:16 +01:00
|
|
|
// clang-format off
|
|
|
|
matrix[0] = 2.f / width; matrix[2] = 0.f; matrix[4] = -1.f;
|
|
|
|
matrix[1] = 0.f; matrix[3] = -2.f / height; matrix[5] = 1.f;
|
|
|
|
// Last matrix row is implicitly assumed to be [0, 0, 1].
|
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
return matrix;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* GetSource(GLenum source) {
|
|
|
|
switch (source) {
|
|
|
|
case GL_DEBUG_SOURCE_API:
|
|
|
|
return "API";
|
|
|
|
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
|
|
|
|
return "WINDOW_SYSTEM";
|
|
|
|
case GL_DEBUG_SOURCE_SHADER_COMPILER:
|
|
|
|
return "SHADER_COMPILER";
|
|
|
|
case GL_DEBUG_SOURCE_THIRD_PARTY:
|
|
|
|
return "THIRD_PARTY";
|
|
|
|
case GL_DEBUG_SOURCE_APPLICATION:
|
|
|
|
return "APPLICATION";
|
|
|
|
case GL_DEBUG_SOURCE_OTHER:
|
|
|
|
return "OTHER";
|
|
|
|
default:
|
2022-06-07 23:02:29 +02:00
|
|
|
ASSERT(false);
|
2020-03-16 08:03:16 +01:00
|
|
|
return "Unknown source";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* GetType(GLenum type) {
|
|
|
|
switch (type) {
|
|
|
|
case GL_DEBUG_TYPE_ERROR:
|
|
|
|
return "ERROR";
|
|
|
|
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
|
|
|
|
return "DEPRECATED_BEHAVIOR";
|
|
|
|
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
|
|
|
|
return "UNDEFINED_BEHAVIOR";
|
|
|
|
case GL_DEBUG_TYPE_PORTABILITY:
|
|
|
|
return "PORTABILITY";
|
|
|
|
case GL_DEBUG_TYPE_PERFORMANCE:
|
|
|
|
return "PERFORMANCE";
|
|
|
|
case GL_DEBUG_TYPE_OTHER:
|
|
|
|
return "OTHER";
|
|
|
|
case GL_DEBUG_TYPE_MARKER:
|
|
|
|
return "MARKER";
|
|
|
|
default:
|
2022-06-07 23:02:29 +02:00
|
|
|
ASSERT(false);
|
2020-03-16 08:03:16 +01:00
|
|
|
return "Unknown type";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void APIENTRY DebugHandler(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length,
|
|
|
|
const GLchar* message, const void* user_param) {
|
|
|
|
const char format[] = "{} {} {}: {}";
|
|
|
|
const char* const str_source = GetSource(source);
|
|
|
|
const char* const str_type = GetType(type);
|
|
|
|
|
|
|
|
switch (severity) {
|
|
|
|
case GL_DEBUG_SEVERITY_HIGH:
|
|
|
|
LOG_CRITICAL(Render_OpenGL, format, str_source, str_type, id, message);
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_SEVERITY_MEDIUM:
|
|
|
|
LOG_WARNING(Render_OpenGL, format, str_source, str_type, id, message);
|
|
|
|
break;
|
|
|
|
case GL_DEBUG_SEVERITY_NOTIFICATION:
|
|
|
|
case GL_DEBUG_SEVERITY_LOW:
|
|
|
|
LOG_DEBUG(Render_OpenGL, format, str_source, str_type, id, message);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // Anonymous namespace
|
2020-02-17 20:31:14 +01:00
|
|
|
|
2020-06-12 02:24:45 +02:00
|
|
|
RendererOpenGL::RendererOpenGL(Core::TelemetrySession& telemetry_session_,
|
|
|
|
Core::Frontend::EmuWindow& emu_window_,
|
|
|
|
Core::Memory::Memory& cpu_memory_, Tegra::GPU& gpu_,
|
2020-12-05 17:40:14 +01:00
|
|
|
std::unique_ptr<Core::Frontend::GraphicsContext> context_)
|
|
|
|
: RendererBase{emu_window_, std::move(context_)}, telemetry_session{telemetry_session_},
|
2022-12-13 20:39:03 +01:00
|
|
|
emu_window{emu_window_}, cpu_memory{cpu_memory_}, gpu{gpu_}, device{emu_window_},
|
|
|
|
state_tracker{}, program_manager{device},
|
2021-01-18 23:04:27 +01:00
|
|
|
rasterizer(emu_window, gpu, cpu_memory, device, screen_info, program_manager, state_tracker) {
|
2021-01-05 08:09:39 +01:00
|
|
|
if (Settings::values.renderer_debug && GLAD_GL_KHR_debug) {
|
|
|
|
glEnable(GL_DEBUG_OUTPUT);
|
|
|
|
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
|
|
|
|
glDebugMessageCallback(DebugHandler, nullptr);
|
|
|
|
}
|
|
|
|
AddTelemetryFields();
|
|
|
|
InitOpenGLObjects();
|
2021-06-26 06:14:06 +02:00
|
|
|
|
|
|
|
// Initialize default attributes to match hardware's disabled attributes
|
|
|
|
GLint max_attribs{};
|
|
|
|
glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &max_attribs);
|
|
|
|
for (GLint attrib = 0; attrib < max_attribs; ++attrib) {
|
2021-07-17 22:16:23 +02:00
|
|
|
glVertexAttrib4f(attrib, 0.0f, 0.0f, 0.0f, 1.0f);
|
2021-06-26 06:14:06 +02:00
|
|
|
}
|
|
|
|
// Enable seamless cubemaps when per texture parameters are not available
|
|
|
|
if (!GLAD_GL_ARB_seamless_cubemap_per_texture && !GLAD_GL_AMD_seamless_cubemap_per_texture) {
|
|
|
|
glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
|
|
|
|
}
|
|
|
|
// Enable unified vertex attributes and query vertex buffer address when the driver supports it
|
|
|
|
if (device.HasVertexBufferUnifiedMemory()) {
|
|
|
|
glEnableClientState(GL_VERTEX_ATTRIB_ARRAY_UNIFIED_NV);
|
|
|
|
glEnableClientState(GL_ELEMENT_ARRAY_UNIFIED_NV);
|
|
|
|
|
|
|
|
glMakeNamedBufferResidentNV(vertex_buffer.handle, GL_READ_ONLY);
|
|
|
|
glGetNamedBufferParameterui64vNV(vertex_buffer.handle, GL_BUFFER_GPU_ADDRESS_NV,
|
|
|
|
&vertex_buffer_address);
|
|
|
|
}
|
2021-01-05 08:09:39 +01:00
|
|
|
}
|
2018-08-12 02:20:19 +02:00
|
|
|
|
2017-05-28 03:02:46 +02:00
|
|
|
RendererOpenGL::~RendererOpenGL() = default;
|
2014-04-06 22:55:39 +02:00
|
|
|
|
2019-08-21 06:55:25 +02:00
|
|
|
void RendererOpenGL::SwapBuffers(const Tegra::FramebufferConfig* framebuffer) {
|
2020-02-17 20:31:14 +01:00
|
|
|
if (!framebuffer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
PrepareRendertarget(framebuffer);
|
|
|
|
RenderScreenshot();
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
state_tracker.BindFramebuffer(0);
|
2020-09-19 22:15:02 +02:00
|
|
|
DrawScreen(emu_window.GetFramebufferLayout());
|
2020-02-17 20:31:14 +01:00
|
|
|
|
2020-09-19 22:15:02 +02:00
|
|
|
++m_current_frame;
|
2020-02-17 20:31:14 +01:00
|
|
|
|
2021-05-16 02:34:20 +02:00
|
|
|
gpu.RendererFrameEndNotify();
|
2021-01-05 08:09:39 +01:00
|
|
|
rasterizer.TickFrame();
|
2020-03-25 03:58:49 +01:00
|
|
|
|
2020-09-19 22:15:02 +02:00
|
|
|
context->SwapBuffers();
|
Overhaul EmuWindow::PollEvents to fix yuzu-cmd calling SDL_PollEvents off main thread
EmuWindow::PollEvents was called from the GPU thread (or the CPU thread
in sync-GPU mode) when swapping buffers. It had three implementations:
- In GRenderWindow, it didn't actually poll events, just set a flag and
emit a signal to indicate that a frame was displayed.
- In EmuWindow_SDL2_Hide, it did nothing.
- In EmuWindow_SDL2, it did call SDL_PollEvents, but this is wrong
because SDL_PollEvents is supposed to be called on the thread that set
up video - in this case, the main thread, which was sleeping in a
busyloop (regardless of whether sync-GPU was enabled). On macOS this
causes a crash.
To fix this:
- Rename EmuWindow::PollEvents to OnFrameDisplayed, and give it a
default implementation that does nothing.
- In EmuWindow_SDL2, do not override OnFrameDisplayed, but instead have
the main thread call SDL_WaitEvent in a loop.
2020-11-22 22:05:18 +01:00
|
|
|
render_window.OnFrameDisplayed();
|
2020-02-17 20:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void RendererOpenGL::PrepareRendertarget(const Tegra::FramebufferConfig* framebuffer) {
|
2020-09-19 22:15:02 +02:00
|
|
|
if (!framebuffer) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// If framebuffer is provided, reload it from memory to a texture
|
|
|
|
if (screen_info.texture.width != static_cast<GLsizei>(framebuffer->width) ||
|
|
|
|
screen_info.texture.height != static_cast<GLsizei>(framebuffer->height) ||
|
|
|
|
screen_info.texture.pixel_format != framebuffer->pixel_format ||
|
|
|
|
gl_framebuffer_data.empty()) {
|
|
|
|
// Reallocate texture if the framebuffer size has changed.
|
|
|
|
// This is expected to not happen very often and hence should not be a
|
|
|
|
// performance problem.
|
|
|
|
ConfigureFramebufferTexture(screen_info.texture, *framebuffer);
|
2014-08-28 20:21:54 +02:00
|
|
|
}
|
2020-09-19 22:15:02 +02:00
|
|
|
|
|
|
|
// Load the framebuffer from memory, draw it to the screen, and swap buffers
|
|
|
|
LoadFBToScreenInfo(*framebuffer);
|
2014-04-09 00:59:02 +02:00
|
|
|
}
|
2014-04-06 22:55:39 +02:00
|
|
|
|
2018-08-21 01:34:02 +02:00
|
|
|
void RendererOpenGL::LoadFBToScreenInfo(const Tegra::FramebufferConfig& framebuffer) {
|
2018-03-23 19:58:27 +01:00
|
|
|
// Framebuffer orientation handling
|
|
|
|
framebuffer_transform_flags = framebuffer.transform_flags;
|
2018-07-18 02:11:41 +02:00
|
|
|
framebuffer_crop_rect = framebuffer.crop_rect;
|
2022-04-04 18:51:09 +02:00
|
|
|
framebuffer_width = framebuffer.width;
|
|
|
|
framebuffer_height = framebuffer.height;
|
2018-03-23 19:58:27 +01:00
|
|
|
|
2019-08-21 07:17:14 +02:00
|
|
|
const VAddr framebuffer_addr{framebuffer.address + framebuffer.offset};
|
2021-10-21 04:40:02 +02:00
|
|
|
screen_info.was_accelerated =
|
|
|
|
rasterizer.AccelerateDisplay(framebuffer, framebuffer_addr, framebuffer.stride);
|
|
|
|
if (screen_info.was_accelerated) {
|
2019-08-21 07:17:14 +02:00
|
|
|
return;
|
|
|
|
}
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2019-08-21 07:17:14 +02:00
|
|
|
// Reset the screen info's display texture to its own permanent texture
|
|
|
|
screen_info.display_texture = screen_info.texture.resource.handle;
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2019-08-21 07:17:14 +02:00
|
|
|
// TODO(Rodrigo): Read this from HLE
|
|
|
|
constexpr u32 block_height_log2 = 4;
|
2020-12-30 06:25:23 +01:00
|
|
|
const auto pixel_format{
|
|
|
|
VideoCore::Surface::PixelFormatFromGPUPixelFormat(framebuffer.pixel_format)};
|
|
|
|
const u32 bytes_per_pixel{VideoCore::Surface::BytesPerBlock(pixel_format)};
|
|
|
|
const u64 size_in_bytes{Tegra::Texture::CalculateSize(
|
|
|
|
true, bytes_per_pixel, framebuffer.stride, framebuffer.height, 1, block_height_log2, 0)};
|
|
|
|
const u8* const host_ptr{cpu_memory.GetPointer(framebuffer_addr)};
|
|
|
|
const std::span<const u8> input_data(host_ptr, size_in_bytes);
|
|
|
|
Tegra::Texture::UnswizzleTexture(gl_framebuffer_data, input_data, bytes_per_pixel,
|
|
|
|
framebuffer.width, framebuffer.height, 1, block_height_log2,
|
|
|
|
0);
|
|
|
|
|
|
|
|
glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
|
2019-08-21 07:17:14 +02:00
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, static_cast<GLint>(framebuffer.stride));
|
|
|
|
|
|
|
|
// Update existing texture
|
|
|
|
// TODO: Test what happens on hardware when you change the framebuffer dimensions so that
|
|
|
|
// they differ from the LCD resolution.
|
|
|
|
// TODO: Applications could theoretically crash yuzu here by specifying too large
|
|
|
|
// framebuffer sizes. We should make sure that this cannot happen.
|
|
|
|
glTextureSubImage2D(screen_info.texture.resource.handle, 0, 0, 0, framebuffer.width,
|
|
|
|
framebuffer.height, screen_info.texture.gl_format,
|
|
|
|
screen_info.texture.gl_type, gl_framebuffer_data.data());
|
|
|
|
|
|
|
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
2014-10-13 07:40:26 +02:00
|
|
|
}
|
2014-04-07 06:52:34 +02:00
|
|
|
|
2018-01-15 06:20:19 +01:00
|
|
|
void RendererOpenGL::LoadColorToActiveGLTexture(u8 color_r, u8 color_g, u8 color_b, u8 color_a,
|
2014-10-13 07:40:26 +02:00
|
|
|
const TextureInfo& texture) {
|
2019-01-06 22:49:23 +01:00
|
|
|
const u8 framebuffer_data[4] = {color_a, color_b, color_g, color_r};
|
|
|
|
glClearTexImage(texture.resource.handle, 0, GL_RGBA, GL_UNSIGNED_BYTE, framebuffer_data);
|
2014-08-21 09:27:53 +02:00
|
|
|
}
|
2014-04-06 22:55:39 +02:00
|
|
|
|
2014-08-28 11:34:47 +02:00
|
|
|
void RendererOpenGL::InitOpenGLObjects() {
|
2019-12-26 20:04:41 +01:00
|
|
|
// Create shader programs
|
2021-10-21 01:36:06 +02:00
|
|
|
fxaa_vertex = CreateProgram(HostShaders::FXAA_VERT, GL_VERTEX_SHADER);
|
|
|
|
fxaa_fragment = CreateProgram(HostShaders::FXAA_FRAG, GL_FRAGMENT_SHADER);
|
2022-12-08 22:52:29 +01:00
|
|
|
|
|
|
|
const auto SmaaShader = [](std::string_view specialized_source, GLenum stage) {
|
|
|
|
std::string shader_source{specialized_source};
|
|
|
|
constexpr std::string_view include_string = "#include \"opengl_smaa.glsl\"";
|
|
|
|
const std::size_t pos = shader_source.find(include_string);
|
|
|
|
ASSERT(pos != std::string::npos);
|
|
|
|
shader_source.replace(pos, include_string.size(), HostShaders::OPENGL_SMAA_GLSL);
|
|
|
|
return CreateProgram(shader_source, stage);
|
|
|
|
};
|
|
|
|
|
|
|
|
smaa_edge_detection_vert = SmaaShader(HostShaders::SMAA_EDGE_DETECTION_VERT, GL_VERTEX_SHADER);
|
|
|
|
smaa_edge_detection_frag =
|
|
|
|
SmaaShader(HostShaders::SMAA_EDGE_DETECTION_FRAG, GL_FRAGMENT_SHADER);
|
|
|
|
smaa_blending_weight_calculation_vert =
|
|
|
|
SmaaShader(HostShaders::SMAA_BLENDING_WEIGHT_CALCULATION_VERT, GL_VERTEX_SHADER);
|
|
|
|
smaa_blending_weight_calculation_frag =
|
|
|
|
SmaaShader(HostShaders::SMAA_BLENDING_WEIGHT_CALCULATION_FRAG, GL_FRAGMENT_SHADER);
|
|
|
|
smaa_neighborhood_blending_vert =
|
|
|
|
SmaaShader(HostShaders::SMAA_NEIGHBORHOOD_BLENDING_VERT, GL_VERTEX_SHADER);
|
|
|
|
smaa_neighborhood_blending_frag =
|
|
|
|
SmaaShader(HostShaders::SMAA_NEIGHBORHOOD_BLENDING_FRAG, GL_FRAGMENT_SHADER);
|
|
|
|
|
2021-07-14 08:48:30 +02:00
|
|
|
present_vertex = CreateProgram(HostShaders::OPENGL_PRESENT_VERT, GL_VERTEX_SHADER);
|
2021-08-17 00:12:52 +02:00
|
|
|
present_bilinear_fragment = CreateProgram(HostShaders::OPENGL_PRESENT_FRAG, GL_FRAGMENT_SHADER);
|
2021-09-10 05:01:39 +02:00
|
|
|
present_bicubic_fragment = CreateProgram(HostShaders::PRESENT_BICUBIC_FRAG, GL_FRAGMENT_SHADER);
|
2021-10-21 01:27:54 +02:00
|
|
|
present_gaussian_fragment =
|
|
|
|
CreateProgram(HostShaders::PRESENT_GAUSSIAN_FRAG, GL_FRAGMENT_SHADER);
|
2021-08-17 00:12:52 +02:00
|
|
|
present_scaleforce_fragment =
|
2021-10-23 06:09:29 +02:00
|
|
|
CreateProgram(fmt::format("#version 460\n{}", HostShaders::OPENGL_PRESENT_SCALEFORCE_FRAG),
|
|
|
|
GL_FRAGMENT_SHADER);
|
2014-08-28 20:21:54 +02:00
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
// Generate presentation sampler
|
|
|
|
present_sampler.Create();
|
|
|
|
glSamplerParameteri(present_sampler.handle, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
2021-07-27 00:48:22 +02:00
|
|
|
glSamplerParameteri(present_sampler.handle, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
2020-12-30 06:25:23 +01:00
|
|
|
|
2021-10-17 17:22:16 +02:00
|
|
|
present_sampler_nn.Create();
|
|
|
|
glSamplerParameteri(present_sampler_nn.handle, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
glSamplerParameteri(present_sampler_nn.handle, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
2014-08-28 20:21:54 +02:00
|
|
|
// Generate VBO handle for drawing
|
2016-04-17 00:57:57 +02:00
|
|
|
vertex_buffer.Create();
|
2014-08-28 20:21:54 +02:00
|
|
|
|
|
|
|
// Attach vertex data to VAO
|
2019-01-06 05:53:27 +01:00
|
|
|
glNamedBufferData(vertex_buffer.handle, sizeof(ScreenRectVertex) * 4, nullptr, GL_STREAM_DRAW);
|
2014-04-07 06:52:34 +02:00
|
|
|
|
2018-01-11 04:43:17 +01:00
|
|
|
// Allocate textures for the screen
|
2019-01-06 22:49:23 +01:00
|
|
|
screen_info.texture.resource.Create(GL_TEXTURE_2D);
|
2014-04-07 06:52:34 +02:00
|
|
|
|
2019-01-06 22:49:23 +01:00
|
|
|
const GLuint texture = screen_info.texture.resource.handle;
|
|
|
|
glTextureStorage2D(texture, 1, GL_RGBA8, 1, 1);
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2018-01-11 04:43:17 +01:00
|
|
|
screen_info.display_texture = screen_info.texture.resource.handle;
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2018-01-15 06:20:19 +01:00
|
|
|
// Clear screen to black
|
|
|
|
LoadColorToActiveGLTexture(0, 0, 0, 0, screen_info.texture);
|
2021-10-21 01:36:06 +02:00
|
|
|
|
2022-12-08 22:52:29 +01:00
|
|
|
aa_framebuffer.Create();
|
|
|
|
|
|
|
|
smaa_area_tex.Create(GL_TEXTURE_2D);
|
|
|
|
glTextureStorage2D(smaa_area_tex.handle, 1, GL_RG8, AREATEX_WIDTH, AREATEX_HEIGHT);
|
|
|
|
glTextureSubImage2D(smaa_area_tex.handle, 0, 0, 0, AREATEX_WIDTH, AREATEX_HEIGHT, GL_RG,
|
|
|
|
GL_UNSIGNED_BYTE, areaTexBytes);
|
|
|
|
smaa_search_tex.Create(GL_TEXTURE_2D);
|
|
|
|
glTextureStorage2D(smaa_search_tex.handle, 1, GL_R8, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT);
|
|
|
|
glTextureSubImage2D(smaa_search_tex.handle, 0, 0, 0, SEARCHTEX_WIDTH, SEARCHTEX_HEIGHT, GL_RED,
|
|
|
|
GL_UNSIGNED_BYTE, searchTexBytes);
|
2014-04-06 22:55:39 +02:00
|
|
|
}
|
|
|
|
|
2019-03-02 21:08:11 +01:00
|
|
|
void RendererOpenGL::AddTelemetryFields() {
|
|
|
|
const char* const gl_version{reinterpret_cast<char const*>(glGetString(GL_VERSION))};
|
|
|
|
const char* const gpu_vendor{reinterpret_cast<char const*>(glGetString(GL_VENDOR))};
|
|
|
|
const char* const gpu_model{reinterpret_cast<char const*>(glGetString(GL_RENDERER))};
|
|
|
|
|
|
|
|
LOG_INFO(Render_OpenGL, "GL_VERSION: {}", gl_version);
|
|
|
|
LOG_INFO(Render_OpenGL, "GL_VENDOR: {}", gpu_vendor);
|
|
|
|
LOG_INFO(Render_OpenGL, "GL_RENDERER: {}", gpu_model);
|
|
|
|
|
2020-08-18 20:21:50 +02:00
|
|
|
constexpr auto user_system = Common::Telemetry::FieldType::UserSystem;
|
2020-12-05 02:42:50 +01:00
|
|
|
telemetry_session.AddField(user_system, "GPU_Vendor", std::string(gpu_vendor));
|
|
|
|
telemetry_session.AddField(user_system, "GPU_Model", std::string(gpu_model));
|
|
|
|
telemetry_session.AddField(user_system, "GPU_OpenGL_Version", std::string(gl_version));
|
2019-03-02 21:08:11 +01:00
|
|
|
}
|
|
|
|
|
2015-02-05 15:15:42 +01:00
|
|
|
void RendererOpenGL::ConfigureFramebufferTexture(TextureInfo& texture,
|
2018-03-23 02:04:30 +01:00
|
|
|
const Tegra::FramebufferConfig& framebuffer) {
|
|
|
|
texture.width = framebuffer.width;
|
|
|
|
texture.height = framebuffer.height;
|
2019-02-26 07:47:16 +01:00
|
|
|
texture.pixel_format = framebuffer.pixel_format;
|
2015-02-05 15:15:42 +01:00
|
|
|
|
2019-08-21 07:07:56 +02:00
|
|
|
const auto pixel_format{
|
|
|
|
VideoCore::Surface::PixelFormatFromGPUPixelFormat(framebuffer.pixel_format)};
|
2020-12-30 06:25:23 +01:00
|
|
|
const u32 bytes_per_pixel{VideoCore::Surface::BytesPerBlock(pixel_format)};
|
2019-08-21 07:07:56 +02:00
|
|
|
gl_framebuffer_data.resize(texture.width * texture.height * bytes_per_pixel);
|
|
|
|
|
2018-01-11 04:43:17 +01:00
|
|
|
GLint internal_format;
|
2018-03-23 02:04:30 +01:00
|
|
|
switch (framebuffer.pixel_format) {
|
2022-03-20 05:51:16 +01:00
|
|
|
case Service::android::PixelFormat::Rgba8888:
|
2019-01-06 22:49:23 +01:00
|
|
|
internal_format = GL_RGBA8;
|
2015-02-05 15:15:42 +01:00
|
|
|
texture.gl_format = GL_RGBA;
|
2018-04-25 01:44:09 +02:00
|
|
|
texture.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
2019-08-21 07:22:54 +02:00
|
|
|
break;
|
2022-03-20 05:51:16 +01:00
|
|
|
case Service::android::PixelFormat::Rgb565:
|
2019-08-21 07:22:54 +02:00
|
|
|
internal_format = GL_RGB565;
|
|
|
|
texture.gl_format = GL_RGB;
|
|
|
|
texture.gl_type = GL_UNSIGNED_SHORT_5_6_5;
|
2015-02-05 15:15:42 +01:00
|
|
|
break;
|
|
|
|
default:
|
2019-01-06 22:49:23 +01:00
|
|
|
internal_format = GL_RGBA8;
|
2018-11-21 02:27:34 +01:00
|
|
|
texture.gl_format = GL_RGBA;
|
|
|
|
texture.gl_type = GL_UNSIGNED_INT_8_8_8_8_REV;
|
2020-12-30 06:25:23 +01:00
|
|
|
// UNIMPLEMENTED_MSG("Unknown framebuffer pixel format: {}",
|
|
|
|
// static_cast<u32>(framebuffer.pixel_format));
|
2022-11-11 13:12:37 +01:00
|
|
|
break;
|
2015-02-05 15:15:42 +01:00
|
|
|
}
|
|
|
|
|
2019-01-06 22:49:23 +01:00
|
|
|
texture.resource.Release();
|
|
|
|
texture.resource.Create(GL_TEXTURE_2D);
|
|
|
|
glTextureStorage2D(texture.resource.handle, 1, internal_format, texture.width, texture.height);
|
2022-12-08 22:52:29 +01:00
|
|
|
aa_texture.Release();
|
|
|
|
aa_texture.Create(GL_TEXTURE_2D);
|
|
|
|
glTextureStorage2D(aa_texture.handle, 1, GL_RGBA16F,
|
|
|
|
Settings::values.resolution_info.ScaleUp(screen_info.texture.width),
|
|
|
|
Settings::values.resolution_info.ScaleUp(screen_info.texture.height));
|
|
|
|
glNamedFramebufferTexture(aa_framebuffer.handle, GL_COLOR_ATTACHMENT0, aa_texture.handle, 0);
|
|
|
|
smaa_edges_tex.Release();
|
|
|
|
smaa_edges_tex.Create(GL_TEXTURE_2D);
|
|
|
|
glTextureStorage2D(smaa_edges_tex.handle, 1, GL_RG16F,
|
|
|
|
Settings::values.resolution_info.ScaleUp(screen_info.texture.width),
|
|
|
|
Settings::values.resolution_info.ScaleUp(screen_info.texture.height));
|
|
|
|
smaa_blend_tex.Release();
|
|
|
|
smaa_blend_tex.Create(GL_TEXTURE_2D);
|
|
|
|
glTextureStorage2D(smaa_blend_tex.handle, 1, GL_RGBA16F,
|
2021-10-21 04:40:02 +02:00
|
|
|
Settings::values.resolution_info.ScaleUp(screen_info.texture.width),
|
|
|
|
Settings::values.resolution_info.ScaleUp(screen_info.texture.height));
|
2015-02-05 15:15:42 +01:00
|
|
|
}
|
|
|
|
|
2019-12-26 05:50:38 +01:00
|
|
|
void RendererOpenGL::DrawScreen(const Layout::FramebufferLayout& layout) {
|
2021-10-21 01:36:06 +02:00
|
|
|
// TODO: Signal state tracker about these changes
|
|
|
|
state_tracker.NotifyScreenDrawVertexArray();
|
|
|
|
state_tracker.NotifyPolygonModes();
|
|
|
|
state_tracker.NotifyViewport0();
|
|
|
|
state_tracker.NotifyScissor0();
|
|
|
|
state_tracker.NotifyColorMask(0);
|
|
|
|
state_tracker.NotifyBlend0();
|
|
|
|
state_tracker.NotifyFramebuffer();
|
|
|
|
state_tracker.NotifyFrontFace();
|
|
|
|
state_tracker.NotifyCullTest();
|
|
|
|
state_tracker.NotifyDepthTest();
|
|
|
|
state_tracker.NotifyStencilTest();
|
|
|
|
state_tracker.NotifyPolygonOffset();
|
|
|
|
state_tracker.NotifyRasterizeEnable();
|
|
|
|
state_tracker.NotifyFramebufferSRGB();
|
|
|
|
state_tracker.NotifyLogicOp();
|
|
|
|
state_tracker.NotifyClipControl();
|
|
|
|
state_tracker.NotifyAlphaTest();
|
|
|
|
|
|
|
|
state_tracker.ClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE);
|
|
|
|
|
|
|
|
glEnable(GL_CULL_FACE);
|
|
|
|
glDisable(GL_COLOR_LOGIC_OP);
|
|
|
|
glDisable(GL_DEPTH_TEST);
|
|
|
|
glDisable(GL_STENCIL_TEST);
|
|
|
|
glDisable(GL_POLYGON_OFFSET_FILL);
|
|
|
|
glDisable(GL_RASTERIZER_DISCARD);
|
|
|
|
glDisable(GL_ALPHA_TEST);
|
|
|
|
glDisablei(GL_BLEND, 0);
|
|
|
|
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
|
|
|
glCullFace(GL_BACK);
|
|
|
|
glFrontFace(GL_CW);
|
|
|
|
glColorMaski(0, GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
|
2022-12-08 22:52:29 +01:00
|
|
|
glDepthRangeIndexed(0, 0.0, 0.0);
|
2021-10-21 01:36:06 +02:00
|
|
|
|
|
|
|
glBindTextureUnit(0, screen_info.display_texture);
|
|
|
|
|
2022-12-08 22:52:29 +01:00
|
|
|
const auto anti_aliasing = Settings::values.anti_aliasing.GetValue();
|
|
|
|
if (anti_aliasing != Settings::AntiAliasing::None) {
|
2021-10-21 01:36:06 +02:00
|
|
|
glEnablei(GL_SCISSOR_TEST, 0);
|
2021-10-21 04:40:02 +02:00
|
|
|
auto viewport_width = screen_info.texture.width;
|
|
|
|
auto scissor_width = framebuffer_crop_rect.GetWidth();
|
|
|
|
if (scissor_width <= 0) {
|
|
|
|
scissor_width = viewport_width;
|
|
|
|
}
|
|
|
|
auto viewport_height = screen_info.texture.height;
|
|
|
|
auto scissor_height = framebuffer_crop_rect.GetHeight();
|
|
|
|
if (scissor_height <= 0) {
|
|
|
|
scissor_height = viewport_height;
|
|
|
|
}
|
|
|
|
if (screen_info.was_accelerated) {
|
|
|
|
viewport_width = Settings::values.resolution_info.ScaleUp(viewport_width);
|
|
|
|
scissor_width = Settings::values.resolution_info.ScaleUp(scissor_width);
|
|
|
|
viewport_height = Settings::values.resolution_info.ScaleUp(viewport_height);
|
|
|
|
scissor_height = Settings::values.resolution_info.ScaleUp(scissor_height);
|
|
|
|
}
|
|
|
|
glScissorIndexed(0, 0, 0, scissor_width, scissor_height);
|
|
|
|
glViewportIndexedf(0, 0.0f, 0.0f, static_cast<GLfloat>(viewport_width),
|
|
|
|
static_cast<GLfloat>(viewport_height));
|
2021-10-21 01:36:06 +02:00
|
|
|
|
|
|
|
glBindSampler(0, present_sampler.handle);
|
|
|
|
GLint old_read_fb;
|
|
|
|
GLint old_draw_fb;
|
|
|
|
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb);
|
|
|
|
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &old_draw_fb);
|
|
|
|
|
2022-12-08 22:52:29 +01:00
|
|
|
switch (anti_aliasing) {
|
|
|
|
case Settings::AntiAliasing::Fxaa: {
|
|
|
|
program_manager.BindPresentPrograms(fxaa_vertex.handle, fxaa_fragment.handle);
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, aa_framebuffer.handle);
|
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
} break;
|
|
|
|
case Settings::AntiAliasing::Smaa: {
|
|
|
|
glClearColor(0, 0, 0, 0);
|
|
|
|
glFrontFace(GL_CCW);
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, aa_framebuffer.handle);
|
|
|
|
glBindSampler(1, present_sampler.handle);
|
|
|
|
glBindSampler(2, present_sampler.handle);
|
|
|
|
|
|
|
|
glNamedFramebufferTexture(aa_framebuffer.handle, GL_COLOR_ATTACHMENT0,
|
|
|
|
smaa_edges_tex.handle, 0);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
program_manager.BindPresentPrograms(smaa_edge_detection_vert.handle,
|
|
|
|
smaa_edge_detection_frag.handle);
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
|
|
|
|
|
|
|
glBindTextureUnit(0, smaa_edges_tex.handle);
|
|
|
|
glBindTextureUnit(1, smaa_area_tex.handle);
|
|
|
|
glBindTextureUnit(2, smaa_search_tex.handle);
|
|
|
|
glNamedFramebufferTexture(aa_framebuffer.handle, GL_COLOR_ATTACHMENT0,
|
|
|
|
smaa_blend_tex.handle, 0);
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
program_manager.BindPresentPrograms(smaa_blending_weight_calculation_vert.handle,
|
|
|
|
smaa_blending_weight_calculation_frag.handle);
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
|
|
|
|
|
|
|
glBindTextureUnit(0, screen_info.display_texture);
|
|
|
|
glBindTextureUnit(1, smaa_blend_tex.handle);
|
|
|
|
glNamedFramebufferTexture(aa_framebuffer.handle, GL_COLOR_ATTACHMENT0,
|
|
|
|
aa_texture.handle, 0);
|
|
|
|
program_manager.BindPresentPrograms(smaa_neighborhood_blending_vert.handle,
|
|
|
|
smaa_neighborhood_blending_frag.handle);
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 3);
|
|
|
|
glFrontFace(GL_CW);
|
|
|
|
} break;
|
|
|
|
default:
|
|
|
|
UNREACHABLE();
|
|
|
|
}
|
2021-10-21 01:36:06 +02:00
|
|
|
|
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read_fb);
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb);
|
|
|
|
|
2022-12-08 22:52:29 +01:00
|
|
|
glBindTextureUnit(0, aa_texture.handle);
|
2021-10-21 01:36:06 +02:00
|
|
|
}
|
2019-12-26 05:50:38 +01:00
|
|
|
const std::array ortho_matrix =
|
|
|
|
MakeOrthographicMatrix(static_cast<float>(layout.width), static_cast<float>(layout.height));
|
2021-08-17 00:12:52 +02:00
|
|
|
|
2021-11-21 08:33:57 +01:00
|
|
|
const auto fragment_handle = [this]() {
|
|
|
|
switch (Settings::values.scaling_filter.GetValue()) {
|
|
|
|
case Settings::ScalingFilter::NearestNeighbor:
|
|
|
|
case Settings::ScalingFilter::Bilinear:
|
|
|
|
return present_bilinear_fragment.handle;
|
|
|
|
case Settings::ScalingFilter::Bicubic:
|
|
|
|
return present_bicubic_fragment.handle;
|
|
|
|
case Settings::ScalingFilter::Gaussian:
|
|
|
|
return present_gaussian_fragment.handle;
|
|
|
|
case Settings::ScalingFilter::ScaleForce:
|
|
|
|
return present_scaleforce_fragment.handle;
|
|
|
|
case Settings::ScalingFilter::Fsr:
|
|
|
|
LOG_WARNING(
|
|
|
|
Render_OpenGL,
|
|
|
|
"FidelityFX Super Resolution is not supported in OpenGL, changing to ScaleForce");
|
|
|
|
return present_scaleforce_fragment.handle;
|
|
|
|
default:
|
|
|
|
return present_bilinear_fragment.handle;
|
|
|
|
}
|
|
|
|
}();
|
2021-08-17 00:12:52 +02:00
|
|
|
program_manager.BindPresentPrograms(present_vertex.handle, fragment_handle);
|
2021-07-14 08:48:30 +02:00
|
|
|
glProgramUniformMatrix3x2fv(present_vertex.handle, ModelViewMatrixLocation, 1, GL_FALSE,
|
|
|
|
ortho_matrix.data());
|
2019-12-26 05:50:38 +01:00
|
|
|
|
2018-02-12 01:04:27 +01:00
|
|
|
const auto& texcoords = screen_info.display_texcoords;
|
2018-03-23 19:58:27 +01:00
|
|
|
auto left = texcoords.left;
|
|
|
|
auto right = texcoords.right;
|
2022-03-20 05:51:16 +01:00
|
|
|
if (framebuffer_transform_flags != Service::android::BufferTransformFlags::Unset) {
|
|
|
|
if (framebuffer_transform_flags == Service::android::BufferTransformFlags::FlipV) {
|
2018-03-23 19:58:27 +01:00
|
|
|
// Flip the framebuffer vertically
|
|
|
|
left = texcoords.right;
|
|
|
|
right = texcoords.left;
|
|
|
|
} else {
|
|
|
|
// Other transformations are unsupported
|
2018-07-02 18:13:26 +02:00
|
|
|
LOG_CRITICAL(Render_OpenGL, "Unsupported framebuffer_transform_flags={}",
|
2020-12-07 06:41:47 +01:00
|
|
|
framebuffer_transform_flags);
|
2018-03-23 19:58:27 +01:00
|
|
|
UNIMPLEMENTED();
|
|
|
|
}
|
2018-04-24 17:12:11 +02:00
|
|
|
}
|
2016-04-17 00:57:57 +02:00
|
|
|
|
2018-07-18 02:11:41 +02:00
|
|
|
ASSERT_MSG(framebuffer_crop_rect.left == 0, "Unimplemented");
|
|
|
|
|
2022-08-20 10:58:01 +02:00
|
|
|
f32 left_start{};
|
|
|
|
if (framebuffer_crop_rect.Top() > 0) {
|
|
|
|
left_start = static_cast<f32>(framebuffer_crop_rect.Top()) /
|
|
|
|
static_cast<f32>(framebuffer_crop_rect.Bottom());
|
|
|
|
}
|
2022-04-04 18:51:09 +02:00
|
|
|
f32 scale_u = static_cast<f32>(framebuffer_width) / static_cast<f32>(screen_info.texture.width);
|
|
|
|
f32 scale_v =
|
|
|
|
static_cast<f32>(framebuffer_height) / static_cast<f32>(screen_info.texture.height);
|
2018-07-18 02:11:41 +02:00
|
|
|
// Scale the output by the crop width/height. This is commonly used with 1280x720 rendering
|
|
|
|
// (e.g. handheld mode) on a 1920x1080 framebuffer.
|
|
|
|
if (framebuffer_crop_rect.GetWidth() > 0) {
|
2019-11-08 21:08:07 +01:00
|
|
|
scale_u = static_cast<f32>(framebuffer_crop_rect.GetWidth()) /
|
|
|
|
static_cast<f32>(screen_info.texture.width);
|
2018-07-18 02:11:41 +02:00
|
|
|
}
|
|
|
|
if (framebuffer_crop_rect.GetHeight() > 0) {
|
2019-11-08 21:08:07 +01:00
|
|
|
scale_v = static_cast<f32>(framebuffer_crop_rect.GetHeight()) /
|
|
|
|
static_cast<f32>(screen_info.texture.height);
|
2018-07-18 02:11:41 +02:00
|
|
|
}
|
2021-10-21 04:40:02 +02:00
|
|
|
if (Settings::values.anti_aliasing.GetValue() == Settings::AntiAliasing::Fxaa &&
|
|
|
|
!screen_info.was_accelerated) {
|
|
|
|
scale_u /= Settings::values.resolution_info.up_factor;
|
|
|
|
scale_v /= Settings::values.resolution_info.up_factor;
|
|
|
|
}
|
2018-07-18 02:11:41 +02:00
|
|
|
|
2019-12-26 05:50:38 +01:00
|
|
|
const auto& screen = layout.screen;
|
2019-11-29 00:36:02 +01:00
|
|
|
const std::array vertices = {
|
2022-08-20 10:58:01 +02:00
|
|
|
ScreenRectVertex(screen.left, screen.top, texcoords.top * scale_u,
|
|
|
|
left_start + left * scale_v),
|
|
|
|
ScreenRectVertex(screen.right, screen.top, texcoords.bottom * scale_u,
|
|
|
|
left_start + left * scale_v),
|
|
|
|
ScreenRectVertex(screen.left, screen.bottom, texcoords.top * scale_u,
|
|
|
|
left_start + right * scale_v),
|
|
|
|
ScreenRectVertex(screen.right, screen.bottom, texcoords.bottom * scale_u,
|
|
|
|
left_start + right * scale_v),
|
2019-11-29 00:36:02 +01:00
|
|
|
};
|
2019-12-26 05:50:38 +01:00
|
|
|
glNamedBufferSubData(vertex_buffer.handle, 0, sizeof(vertices), std::data(vertices));
|
2014-08-28 20:21:54 +02:00
|
|
|
|
2019-12-26 05:01:41 +01:00
|
|
|
if (screen_info.display_srgb) {
|
|
|
|
glEnable(GL_FRAMEBUFFER_SRGB);
|
|
|
|
} else {
|
|
|
|
glDisable(GL_FRAMEBUFFER_SRGB);
|
|
|
|
}
|
2019-12-26 05:28:17 +01:00
|
|
|
glDisablei(GL_SCISSOR_TEST, 0);
|
2019-12-29 02:12:12 +01:00
|
|
|
glViewportIndexedf(0, 0.0f, 0.0f, static_cast<GLfloat>(layout.width),
|
|
|
|
static_cast<GLfloat>(layout.height));
|
2019-12-25 23:46:04 +01:00
|
|
|
|
2019-12-29 03:08:40 +01:00
|
|
|
glEnableVertexAttribArray(PositionLocation);
|
|
|
|
glEnableVertexAttribArray(TexCoordLocation);
|
2019-12-29 05:28:53 +01:00
|
|
|
glVertexAttribDivisor(PositionLocation, 0);
|
|
|
|
glVertexAttribDivisor(TexCoordLocation, 0);
|
2019-12-26 04:16:52 +01:00
|
|
|
glVertexAttribFormat(PositionLocation, 2, GL_FLOAT, GL_FALSE,
|
|
|
|
offsetof(ScreenRectVertex, position));
|
|
|
|
glVertexAttribFormat(TexCoordLocation, 2, GL_FLOAT, GL_FALSE,
|
|
|
|
offsetof(ScreenRectVertex, tex_coord));
|
|
|
|
glVertexAttribBinding(PositionLocation, 0);
|
|
|
|
glVertexAttribBinding(TexCoordLocation, 0);
|
gl_rasterizer: Use NV_vertex_buffer_unified_memory for vertex buffer robustness
Switch games are allowed to bind less data than what they use in a
vertex buffer, the expected behavior here is that these values are read
as zero. At the moment of writing this only D3D12, OpenGL and NVN through
NV_vertex_buffer_unified_memory support vertex buffer with a size limit.
In theory this could be emulated on Vulkan creating a new VkBuffer for
each (handle, offset, length) tuple and binding the expected data to it.
This is likely going to be slow and memory expensive when used on the
vertex buffer and we have to do it on all draws because we can't know
without analyzing indices when a game is going to read vertex data out
of bounds.
This is not a problem on OpenGL's BufferAddressRangeNV because it takes
a length parameter, unlike Vulkan's CmdBindVertexBuffers that only takes
buffers and offsets (the length is implicit in VkBuffer). It isn't a
problem on D3D12 either, because D3D12_VERTEX_BUFFER_VIEW on
IASetVertexBuffers takes SizeInBytes as a parameter (although I am not
familiar with robustness on D3D12).
Currently this only implements buffer ranges for vertex buffers,
although indices can also be affected. A KHR_robustness profile is not
created, but Nvidia's driver reads out of bound vertex data as zero
anyway, this might have to be changed in the future.
- Fixes SMO random triangles when capturing an enemy, getting hit, or
looking at the environment on certain maps.
2020-06-18 08:56:31 +02:00
|
|
|
if (device.HasVertexBufferUnifiedMemory()) {
|
|
|
|
glBindVertexBuffer(0, 0, 0, sizeof(ScreenRectVertex));
|
|
|
|
glBufferAddressRangeNV(GL_VERTEX_ATTRIB_ARRAY_ADDRESS_NV, 0, vertex_buffer_address,
|
|
|
|
sizeof(vertices));
|
|
|
|
} else {
|
|
|
|
glBindVertexBuffer(0, vertex_buffer.handle, 0, sizeof(ScreenRectVertex));
|
|
|
|
}
|
2019-12-26 04:16:52 +01:00
|
|
|
|
2021-10-17 17:22:16 +02:00
|
|
|
if (Settings::values.scaling_filter.GetValue() != Settings::ScalingFilter::NearestNeighbor) {
|
|
|
|
glBindSampler(0, present_sampler.handle);
|
|
|
|
} else {
|
|
|
|
glBindSampler(0, present_sampler_nn.handle);
|
|
|
|
}
|
2019-12-26 08:01:11 +01:00
|
|
|
|
2022-12-08 22:52:29 +01:00
|
|
|
// Update background color before drawing
|
|
|
|
glClearColor(Settings::values.bg_red.GetValue() / 255.0f,
|
|
|
|
Settings::values.bg_green.GetValue() / 255.0f,
|
|
|
|
Settings::values.bg_blue.GetValue() / 255.0f, 1.0f);
|
|
|
|
|
2019-12-26 05:50:38 +01:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT);
|
2014-08-28 20:21:54 +02:00
|
|
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
2020-05-18 03:32:49 +02:00
|
|
|
|
2021-05-23 09:28:34 +02:00
|
|
|
// TODO
|
|
|
|
// program_manager.RestoreGuestPipeline();
|
2014-08-28 20:21:54 +02:00
|
|
|
}
|
|
|
|
|
2020-02-17 20:31:14 +01:00
|
|
|
void RendererOpenGL::RenderScreenshot() {
|
|
|
|
if (!renderer_settings.screenshot_requested) {
|
|
|
|
return;
|
|
|
|
}
|
2014-04-06 22:55:39 +02:00
|
|
|
|
2019-12-26 09:01:43 +01:00
|
|
|
GLint old_read_fb;
|
|
|
|
GLint old_draw_fb;
|
|
|
|
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &old_read_fb);
|
|
|
|
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &old_draw_fb);
|
|
|
|
|
2018-08-31 08:16:16 +02:00
|
|
|
// Draw the current frame to the screenshot framebuffer
|
|
|
|
screenshot_framebuffer.Create();
|
2019-12-26 09:01:43 +01:00
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, screenshot_framebuffer.handle);
|
2018-08-31 08:16:16 +02:00
|
|
|
|
2020-09-19 22:15:02 +02:00
|
|
|
const Layout::FramebufferLayout layout{renderer_settings.screenshot_framebuffer_layout};
|
2018-08-31 08:16:16 +02:00
|
|
|
|
|
|
|
GLuint renderbuffer;
|
|
|
|
glGenRenderbuffers(1, &renderbuffer);
|
|
|
|
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
|
2019-09-03 06:05:23 +02:00
|
|
|
glRenderbufferStorage(GL_RENDERBUFFER, screen_info.display_srgb ? GL_SRGB8 : GL_RGB8,
|
|
|
|
layout.width, layout.height);
|
2018-08-31 08:16:16 +02:00
|
|
|
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
|
|
|
|
|
|
|
|
DrawScreen(layout);
|
|
|
|
|
2020-12-30 06:25:23 +01:00
|
|
|
glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
|
|
|
|
glPixelStorei(GL_PACK_ROW_LENGTH, 0);
|
2018-08-31 08:16:16 +02:00
|
|
|
glReadPixels(0, 0, layout.width, layout.height, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
|
|
|
|
renderer_settings.screenshot_bits);
|
|
|
|
|
|
|
|
screenshot_framebuffer.Release();
|
|
|
|
glDeleteRenderbuffers(1, &renderbuffer);
|
|
|
|
|
2019-12-26 09:01:43 +01:00
|
|
|
glBindFramebuffer(GL_READ_FRAMEBUFFER, old_read_fb);
|
|
|
|
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, old_draw_fb);
|
|
|
|
|
2021-07-26 07:52:33 +02:00
|
|
|
renderer_settings.screenshot_complete_callback(true);
|
2018-08-31 08:16:16 +02:00
|
|
|
renderer_settings.screenshot_requested = false;
|
|
|
|
}
|
|
|
|
|
2018-08-21 10:18:27 +02:00
|
|
|
} // namespace OpenGL
|