2018-03-20 04:00:59 +01:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
2019-01-21 20:38:23 +01:00
|
|
|
#include <atomic>
|
2018-03-20 04:00:59 +01:00
|
|
|
#include <cstddef>
|
2018-09-05 11:36:50 +02:00
|
|
|
#include <map>
|
2018-03-20 04:00:59 +01:00
|
|
|
#include <memory>
|
2018-10-30 05:03:25 +01:00
|
|
|
#include <optional>
|
2018-08-10 10:29:37 +02:00
|
|
|
#include <tuple>
|
2018-07-03 23:55:44 +02:00
|
|
|
#include <utility>
|
2018-08-29 00:43:08 +02:00
|
|
|
|
|
|
|
#include <boost/icl/interval_map.hpp>
|
2018-03-20 04:00:59 +01:00
|
|
|
#include <glad/glad.h>
|
2018-08-29 00:43:08 +02:00
|
|
|
|
2018-03-20 04:00:59 +01:00
|
|
|
#include "common/common_types.h"
|
2019-05-31 22:33:21 +02:00
|
|
|
#include "video_core/engines/const_buffer_info.h"
|
2018-04-08 06:00:11 +02:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2018-08-29 00:27:03 +02:00
|
|
|
#include "video_core/rasterizer_cache.h"
|
2018-03-20 04:00:59 +01:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
2018-08-29 00:27:03 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_buffer_cache.h"
|
2019-04-10 20:56:12 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_device.h"
|
2019-01-08 21:30:10 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_global_cache.h"
|
2018-03-20 04:00:59 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
2019-04-02 21:58:08 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_sampler_cache.h"
|
2018-08-23 23:30:27 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_cache.h"
|
2019-05-31 22:33:21 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_decompiler.h"
|
2018-04-07 11:22:08 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
2018-03-20 04:00:59 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_state.h"
|
2019-04-11 22:14:55 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_texture_cache.h"
|
2019-04-05 23:31:24 +02:00
|
|
|
#include "video_core/renderer_opengl/utils.h"
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2019-01-15 20:28:42 +01:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2018-08-12 02:20:19 +02:00
|
|
|
namespace Core::Frontend {
|
|
|
|
class EmuWindow;
|
|
|
|
}
|
|
|
|
|
2019-05-07 16:55:18 +02:00
|
|
|
namespace Tegra {
|
|
|
|
class MemoryManager;
|
|
|
|
}
|
|
|
|
|
2018-08-21 10:18:27 +02:00
|
|
|
namespace OpenGL {
|
|
|
|
|
|
|
|
struct ScreenInfo;
|
2018-10-02 19:47:26 +02:00
|
|
|
struct DrawParameters;
|
2018-11-19 02:20:26 +01:00
|
|
|
struct FramebufferCacheKey;
|
2018-08-21 10:18:27 +02:00
|
|
|
|
2018-03-20 04:00:59 +01:00
|
|
|
class RasterizerOpenGL : public VideoCore::RasterizerInterface {
|
|
|
|
public:
|
2019-04-06 22:59:56 +02:00
|
|
|
explicit RasterizerOpenGL(Core::System& system, Core::Frontend::EmuWindow& emu_window,
|
|
|
|
ScreenInfo& info);
|
2018-03-20 04:00:59 +01:00
|
|
|
~RasterizerOpenGL() override;
|
|
|
|
|
2019-05-07 16:55:18 +02:00
|
|
|
void InitMemoryMananger(Tegra::MemoryManager& memory_manager) override;
|
|
|
|
|
2018-03-25 04:50:21 +02:00
|
|
|
void DrawArrays() override;
|
2018-06-07 06:54:25 +02:00
|
|
|
void Clear() override;
|
2018-03-20 04:00:59 +01:00
|
|
|
void FlushAll() override;
|
2019-02-19 02:58:32 +01:00
|
|
|
void FlushRegion(CacheAddr addr, u64 size) override;
|
|
|
|
void InvalidateRegion(CacheAddr addr, u64 size) override;
|
|
|
|
void FlushAndInvalidateRegion(CacheAddr addr, u64 size) override;
|
2018-10-06 05:39:03 +02:00
|
|
|
bool AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Regs::Surface& src,
|
2018-12-15 06:20:00 +01:00
|
|
|
const Tegra::Engines::Fermi2D::Regs::Surface& dst,
|
2019-02-27 04:47:49 +01:00
|
|
|
const Common::Rectangle<u32>& src_rect,
|
|
|
|
const Common::Rectangle<u32>& dst_rect) override;
|
2018-08-21 01:34:02 +02:00
|
|
|
bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr,
|
|
|
|
u32 pixel_stride) override;
|
2018-03-20 04:00:59 +01:00
|
|
|
bool AccelerateDrawBatch(bool is_indexed) override;
|
2019-02-19 02:58:32 +01:00
|
|
|
void UpdatePagesCachedCount(VAddr addr, u64 size, int delta) override;
|
2019-01-21 20:38:23 +01:00
|
|
|
void LoadDiskResources(const std::atomic_bool& stop_loading,
|
|
|
|
const VideoCore::DiskResourceLoadCallback& callback) override;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2018-06-10 01:02:05 +02:00
|
|
|
/// Maximum supported size that a constbuffer can have in bytes.
|
2018-09-15 15:21:06 +02:00
|
|
|
static constexpr std::size_t MaxConstbufferSize = 0x10000;
|
2018-06-10 01:02:05 +02:00
|
|
|
static_assert(MaxConstbufferSize % sizeof(GLvec4) == 0,
|
|
|
|
"The maximum size of a constbuffer must be a multiple of the size of GLvec4");
|
2018-03-20 04:00:59 +01:00
|
|
|
|
|
|
|
private:
|
2019-01-07 06:22:00 +01:00
|
|
|
struct FramebufferConfigState {
|
|
|
|
bool using_color_fb{};
|
|
|
|
bool using_depth_fb{};
|
|
|
|
bool preserve_contents{};
|
|
|
|
std::optional<std::size_t> single_color_target;
|
|
|
|
|
|
|
|
bool operator==(const FramebufferConfigState& rhs) const {
|
|
|
|
return std::tie(using_color_fb, using_depth_fb, preserve_contents,
|
|
|
|
single_color_target) == std::tie(rhs.using_color_fb, rhs.using_depth_fb,
|
|
|
|
rhs.preserve_contents,
|
|
|
|
rhs.single_color_target);
|
|
|
|
}
|
|
|
|
bool operator!=(const FramebufferConfigState& rhs) const {
|
|
|
|
return !operator==(rhs);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-09-10 06:36:13 +02:00
|
|
|
/**
|
|
|
|
* Configures the color and depth framebuffer states.
|
|
|
|
* @param use_color_fb If true, configure color framebuffers.
|
|
|
|
* @param using_depth_fb If true, configure the depth/stencil framebuffer.
|
|
|
|
* @param preserve_contents If true, tries to preserve data from a previously used framebuffer.
|
|
|
|
* @param single_color_target Specifies if a single color buffer target should be used.
|
2019-01-29 06:01:05 +01:00
|
|
|
* @returns If depth (first) or stencil (second) are being stored in the bound zeta texture
|
|
|
|
* (requires using_depth_fb to be true)
|
2018-09-10 06:36:13 +02:00
|
|
|
*/
|
2019-01-29 06:01:05 +01:00
|
|
|
std::pair<bool, bool> ConfigureFramebuffers(
|
|
|
|
OpenGLState& current_state, bool use_color_fb = true, bool using_depth_fb = true,
|
|
|
|
bool preserve_contents = true, std::optional<std::size_t> single_color_target = {});
|
2018-03-27 02:58:19 +02:00
|
|
|
|
2019-01-05 05:00:06 +01:00
|
|
|
/// Configures the current constbuffers to use for the draw command.
|
2019-05-31 22:33:21 +02:00
|
|
|
void SetupDrawConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage,
|
|
|
|
const Shader& shader);
|
|
|
|
|
|
|
|
/// Configures a constant buffer.
|
|
|
|
void SetupConstBuffer(const Tegra::Engines::ConstBufferInfo& buffer,
|
|
|
|
const GLShader::ConstBufferEntry& entry);
|
2019-01-05 05:00:06 +01:00
|
|
|
|
|
|
|
/// Configures the current global memory entries to use for the draw command.
|
|
|
|
void SetupGlobalRegions(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage,
|
2019-06-08 00:52:16 +02:00
|
|
|
const Shader& shader);
|
2019-01-05 05:00:06 +01:00
|
|
|
|
|
|
|
/// Configures the current textures to use for the draw command.
|
|
|
|
void SetupTextures(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, const Shader& shader,
|
2019-06-08 00:52:16 +02:00
|
|
|
BaseBindings base_bindings);
|
2018-06-06 19:58:16 +02:00
|
|
|
|
2018-11-02 04:21:25 +01:00
|
|
|
/// Syncs the viewport and depth range to match the guest state
|
2018-11-08 02:27:47 +01:00
|
|
|
void SyncViewport(OpenGLState& current_state);
|
2018-03-27 02:45:10 +02:00
|
|
|
|
2018-03-20 04:00:59 +01:00
|
|
|
/// Syncs the clip enabled status to match the guest state
|
2018-11-29 20:13:13 +01:00
|
|
|
void SyncClipEnabled(
|
|
|
|
const std::array<bool, Tegra::Engines::Maxwell3D::Regs::NumClipDistances>& clip_mask);
|
2018-03-20 04:00:59 +01:00
|
|
|
|
|
|
|
/// Syncs the clip coefficients to match the guest state
|
|
|
|
void SyncClipCoef();
|
|
|
|
|
|
|
|
/// Syncs the cull mode to match the guest state
|
|
|
|
void SyncCullMode();
|
|
|
|
|
2018-10-26 01:04:13 +02:00
|
|
|
/// Syncs the primitve restart to match the guest state
|
|
|
|
void SyncPrimitiveRestart();
|
|
|
|
|
2018-07-02 20:33:06 +02:00
|
|
|
/// Syncs the depth test state to match the guest state
|
|
|
|
void SyncDepthTestState();
|
|
|
|
|
2018-08-22 06:35:31 +02:00
|
|
|
/// Syncs the stencil test state to match the guest state
|
|
|
|
void SyncStencilTestState();
|
|
|
|
|
2018-06-09 00:05:52 +02:00
|
|
|
/// Syncs the blend state to match the guest state
|
|
|
|
void SyncBlendState();
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2018-08-21 01:44:47 +02:00
|
|
|
/// Syncs the LogicOp state to match the guest state
|
|
|
|
void SyncLogicOpState();
|
|
|
|
|
2018-11-14 02:09:01 +01:00
|
|
|
/// Syncs the the color clamp state
|
|
|
|
void SyncFragmentColorClampState();
|
|
|
|
|
2018-11-14 04:02:54 +01:00
|
|
|
/// Syncs the alpha coverage and alpha to one
|
|
|
|
void SyncMultiSampleState();
|
|
|
|
|
2018-10-09 02:49:36 +02:00
|
|
|
/// Syncs the scissor test state to match the guest state
|
2018-11-21 04:40:32 +01:00
|
|
|
void SyncScissorTest(OpenGLState& current_state);
|
2018-10-09 02:49:36 +02:00
|
|
|
|
2018-09-26 00:41:21 +02:00
|
|
|
/// Syncs the transform feedback state to match the guest state
|
|
|
|
void SyncTransformFeedback();
|
|
|
|
|
2018-09-28 06:31:01 +02:00
|
|
|
/// Syncs the point state to match the guest state
|
|
|
|
void SyncPointState();
|
|
|
|
|
2018-11-05 03:46:06 +01:00
|
|
|
/// Syncs Color Mask
|
|
|
|
void SyncColorMask();
|
|
|
|
|
2018-11-27 00:31:44 +01:00
|
|
|
/// Syncs the polygon offsets
|
|
|
|
void SyncPolygonOffset();
|
|
|
|
|
2019-05-22 01:28:09 +02:00
|
|
|
/// Syncs the alpha test state to match the guest state
|
|
|
|
void SyncAlphaTest();
|
2018-10-12 02:29:11 +02:00
|
|
|
|
2018-11-23 16:11:21 +01:00
|
|
|
/// Check for extension that are not strictly required
|
|
|
|
/// but are needed for correct emulation
|
|
|
|
void CheckExtensions();
|
|
|
|
|
2019-04-10 23:03:52 +02:00
|
|
|
const Device device;
|
2018-03-20 04:00:59 +01:00
|
|
|
OpenGLState state;
|
|
|
|
|
2019-04-11 22:14:55 +02:00
|
|
|
TextureCacheOpenGL texture_cache;
|
2018-08-23 23:30:27 +02:00
|
|
|
ShaderCacheOpenGL shader_cache;
|
2019-01-08 21:30:10 +01:00
|
|
|
GlobalRegionCacheOpenGL global_cache;
|
2019-04-02 21:58:08 +02:00
|
|
|
SamplerCacheOpenGL sampler_cache;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2019-03-09 07:25:11 +01:00
|
|
|
Core::System& system;
|
2018-08-21 01:34:02 +02:00
|
|
|
ScreenInfo& screen_info;
|
|
|
|
|
2018-04-07 11:22:08 +02:00
|
|
|
std::unique_ptr<GLShader::ProgramManager> shader_program_manager;
|
2018-09-05 11:36:50 +02:00
|
|
|
std::map<std::array<Tegra::Engines::Maxwell3D::Regs::VertexAttribute,
|
|
|
|
Tegra::Engines::Maxwell3D::Regs::NumVertexAttributes>,
|
|
|
|
OGLVertexArray>
|
|
|
|
vertex_array_cache;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2018-11-19 02:20:26 +01:00
|
|
|
std::map<FramebufferCacheKey, OGLFramebuffer> framebuffer_cache;
|
2019-01-07 06:22:00 +01:00
|
|
|
FramebufferConfigState current_framebuffer_config_state;
|
2019-01-29 06:01:05 +01:00
|
|
|
std::pair<bool, bool> current_depth_stencil_usage{};
|
2018-11-19 02:20:26 +01:00
|
|
|
|
2018-09-15 15:21:06 +02:00
|
|
|
static constexpr std::size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024;
|
2018-08-29 00:27:03 +02:00
|
|
|
OGLBufferCache buffer_cache;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2019-04-24 23:47:59 +02:00
|
|
|
SurfaceBlitter blitter;
|
2019-04-05 23:31:24 +02:00
|
|
|
BindBuffersRangePushBuffer bind_ubo_pushbuffer{GL_UNIFORM_BUFFER};
|
2019-04-05 08:50:26 +02:00
|
|
|
BindBuffersRangePushBuffer bind_ssbo_pushbuffer{GL_SHADER_STORAGE_BUFFER};
|
2019-04-05 23:31:24 +02:00
|
|
|
|
2018-09-15 15:21:06 +02:00
|
|
|
std::size_t CalculateVertexArraysSize() const;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2018-10-02 19:47:26 +02:00
|
|
|
std::size_t CalculateIndexBufferSize() const;
|
|
|
|
|
2019-01-06 05:53:27 +01:00
|
|
|
/// Updates and returns a vertex array object representing current vertex format
|
|
|
|
GLuint SetupVertexFormat();
|
|
|
|
|
|
|
|
void SetupVertexBuffer(GLuint vao);
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2018-10-02 19:47:26 +02:00
|
|
|
DrawParameters SetupDraw();
|
|
|
|
|
2018-10-07 04:17:31 +02:00
|
|
|
void SetupShaders(GLenum primitive_mode);
|
2018-08-10 19:11:12 +02:00
|
|
|
|
2018-11-19 02:20:26 +01:00
|
|
|
void SetupCachedFramebuffer(const FramebufferCacheKey& fbkey, OpenGLState& current_state);
|
|
|
|
|
2018-03-20 04:00:59 +01:00
|
|
|
enum class AccelDraw { Disabled, Arrays, Indexed };
|
2018-07-24 18:08:10 +02:00
|
|
|
AccelDraw accelerate_draw = AccelDraw::Disabled;
|
2018-08-29 00:43:08 +02:00
|
|
|
|
|
|
|
using CachedPageMap = boost::icl::interval_map<u64, int>;
|
|
|
|
CachedPageMap cached_pages;
|
2018-03-20 04:00:59 +01:00
|
|
|
};
|
2018-08-21 10:18:27 +02:00
|
|
|
|
|
|
|
} // namespace OpenGL
|