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>
|
|
|
|
#include <cstddef>
|
2018-09-05 11:36:50 +02:00
|
|
|
#include <map>
|
2018-03-20 04:00:59 +01:00
|
|
|
#include <memory>
|
2018-08-10 10:29:37 +02:00
|
|
|
#include <tuple>
|
2018-07-03 23:55:44 +02:00
|
|
|
#include <utility>
|
2018-03-20 04:00:59 +01:00
|
|
|
#include <vector>
|
2018-08-29 00:43:08 +02:00
|
|
|
|
|
|
|
#include <boost/icl/interval_map.hpp>
|
2018-09-10 06:36:13 +02:00
|
|
|
#include <boost/optional.hpp>
|
2018-08-29 00:43:08 +02:00
|
|
|
#include <boost/range/iterator_range.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"
|
2018-04-08 06:00:11 +02:00
|
|
|
#include "video_core/engines/maxwell_3d.h"
|
2018-04-24 06:19:36 +02:00
|
|
|
#include "video_core/memory_manager.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"
|
2018-10-02 19:47:26 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_primitive_assembler.h"
|
2018-03-20 04:00:59 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_rasterizer_cache.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
2018-08-23 23:30:27 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_cache.h"
|
2018-03-20 04:00:59 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_gen.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"
|
|
|
|
#include "video_core/renderer_opengl/gl_stream_buffer.h"
|
|
|
|
|
2018-08-12 02:20:19 +02:00
|
|
|
namespace Core::Frontend {
|
|
|
|
class EmuWindow;
|
|
|
|
}
|
|
|
|
|
2018-08-21 10:18:27 +02:00
|
|
|
namespace OpenGL {
|
|
|
|
|
|
|
|
struct ScreenInfo;
|
2018-10-02 19:47:26 +02:00
|
|
|
struct DrawParameters;
|
2018-08-21 10:18:27 +02:00
|
|
|
|
2018-03-20 04:00:59 +01:00
|
|
|
class RasterizerOpenGL : public VideoCore::RasterizerInterface {
|
|
|
|
public:
|
2018-08-21 01:34:02 +02:00
|
|
|
explicit RasterizerOpenGL(Core::Frontend::EmuWindow& renderer, ScreenInfo& info);
|
2018-03-20 04:00:59 +01:00
|
|
|
~RasterizerOpenGL() 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;
|
2018-08-28 03:35:15 +02:00
|
|
|
void FlushRegion(VAddr addr, u64 size) override;
|
|
|
|
void InvalidateRegion(VAddr addr, u64 size) override;
|
|
|
|
void FlushAndInvalidateRegion(VAddr addr, u64 size) override;
|
2018-10-06 05:39:03 +02:00
|
|
|
bool AccelerateSurfaceCopy(const Tegra::Engines::Fermi2D::Regs::Surface& src,
|
|
|
|
const Tegra::Engines::Fermi2D::Regs::Surface& dst) override;
|
2018-03-20 04:00:59 +01:00
|
|
|
bool AccelerateFill(const void* config) 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;
|
2018-08-29 00:43:08 +02:00
|
|
|
void UpdatePagesCachedCount(Tegra::GPUVAddr addr, u64 size, int delta) override;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2018-03-23 01:00:41 +01:00
|
|
|
/// OpenGL shader generated for a given Maxwell register state
|
|
|
|
struct MaxwellShader {
|
|
|
|
/// OpenGL shader resource
|
2018-04-07 05:56:42 +02:00
|
|
|
OGLProgram shader;
|
2018-03-23 01:00:41 +01:00
|
|
|
};
|
|
|
|
|
2018-03-20 04:00:59 +01:00
|
|
|
struct VertexShader {
|
|
|
|
OGLShader shader;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FragmentShader {
|
|
|
|
OGLShader shader;
|
|
|
|
};
|
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:
|
2018-03-27 04:42:54 +02:00
|
|
|
class SamplerInfo {
|
|
|
|
public:
|
|
|
|
OGLSampler sampler;
|
|
|
|
|
|
|
|
/// Creates the sampler object, initializing its state so that it's in sync with the
|
|
|
|
/// SamplerInfo struct.
|
|
|
|
void Create();
|
|
|
|
/// Syncs the sampler object with the config, updating any necessary state.
|
|
|
|
void SyncWithConfig(const Tegra::Texture::TSCEntry& config);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Tegra::Texture::TextureFilter mag_filter;
|
|
|
|
Tegra::Texture::TextureFilter min_filter;
|
|
|
|
Tegra::Texture::WrapMode wrap_u;
|
|
|
|
Tegra::Texture::WrapMode wrap_v;
|
2018-09-06 05:25:06 +02:00
|
|
|
Tegra::Texture::WrapMode wrap_p;
|
2018-09-19 07:18:20 +02:00
|
|
|
bool uses_depth_compare;
|
|
|
|
Tegra::Texture::DepthCompareFunc depth_compare_func;
|
2018-07-24 05:26:48 +02:00
|
|
|
GLvec4 border_color;
|
2018-03-27 04:42:54 +02:00
|
|
|
};
|
2018-03-20 04:00:59 +01:00
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
void ConfigureFramebuffers(bool use_color_fb = true, bool using_depth_fb = true,
|
|
|
|
bool preserve_contents = true,
|
2018-09-15 15:21:06 +02:00
|
|
|
boost::optional<std::size_t> single_color_target = {});
|
2018-03-27 02:58:19 +02:00
|
|
|
|
2018-04-15 21:14:57 +02:00
|
|
|
/*
|
|
|
|
* Configures the current constbuffers to use for the draw command.
|
|
|
|
* @param stage The shader stage to configure buffers for.
|
2018-08-23 23:30:27 +02:00
|
|
|
* @param shader The shader object that contains the specified stage.
|
2018-04-15 21:14:57 +02:00
|
|
|
* @param current_bindpoint The offset at which to start counting new buffer bindpoints.
|
|
|
|
* @returns The next available bindpoint for use in the next shader stage.
|
|
|
|
*/
|
2018-08-29 00:27:03 +02:00
|
|
|
u32 SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, Shader& shader,
|
2018-10-07 04:17:31 +02:00
|
|
|
GLenum primitive_mode, u32 current_bindpoint);
|
2018-04-14 18:50:15 +02:00
|
|
|
|
2018-06-06 19:58:16 +02:00
|
|
|
/*
|
|
|
|
* Configures the current textures to use for the draw command.
|
|
|
|
* @param stage The shader stage to configure textures for.
|
2018-08-23 23:30:27 +02:00
|
|
|
* @param shader The shader object that contains the specified stage.
|
2018-06-06 19:58:16 +02:00
|
|
|
* @param current_unit The offset at which to start counting unused texture units.
|
|
|
|
* @returns The next available bindpoint for use in the next shader stage.
|
|
|
|
*/
|
2018-08-23 23:30:27 +02:00
|
|
|
u32 SetupTextures(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, Shader& shader,
|
2018-10-07 04:17:31 +02:00
|
|
|
GLenum primitive_mode, u32 current_unit);
|
2018-06-06 19:58:16 +02:00
|
|
|
|
2018-03-27 02:45:10 +02:00
|
|
|
/// Syncs the viewport to match the guest state
|
2018-09-10 01:01:21 +02:00
|
|
|
void SyncViewport();
|
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
|
|
|
|
void SyncClipEnabled();
|
|
|
|
|
|
|
|
/// Syncs the clip coefficients to match the guest state
|
|
|
|
void SyncClipCoef();
|
|
|
|
|
|
|
|
/// Syncs the cull mode to match the guest state
|
|
|
|
void SyncCullMode();
|
|
|
|
|
|
|
|
/// Syncs the depth scale to match the guest state
|
|
|
|
void SyncDepthScale();
|
|
|
|
|
|
|
|
/// Syncs the depth offset to match the guest state
|
|
|
|
void SyncDepthOffset();
|
|
|
|
|
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-10-09 02:49:36 +02:00
|
|
|
/// Syncs the scissor test state to match the guest state
|
|
|
|
void SyncScissorTest();
|
|
|
|
|
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-07-24 18:08:10 +02:00
|
|
|
bool has_ARB_direct_state_access = false;
|
2018-09-13 02:27:43 +02:00
|
|
|
bool has_ARB_multi_bind = false;
|
2018-07-24 18:08:10 +02:00
|
|
|
bool has_ARB_separate_shader_objects = false;
|
|
|
|
bool has_ARB_vertex_attrib_binding = false;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
|
|
|
OpenGLState state;
|
|
|
|
|
|
|
|
RasterizerCacheOpenGL res_cache;
|
2018-08-23 23:30:27 +02:00
|
|
|
ShaderCacheOpenGL shader_cache;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2018-08-12 02:20:19 +02:00
|
|
|
Core::Frontend::EmuWindow& emu_window;
|
2018-08-02 02:59:42 +02:00
|
|
|
|
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-09-27 02:52:31 +02:00
|
|
|
std::array<SamplerInfo, Tegra::Engines::Maxwell3D::Regs::NumTextureSamplers> texture_samplers;
|
2018-04-14 18:45:23 +02: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
|
|
|
OGLFramebuffer framebuffer;
|
2018-10-02 19:47:26 +02:00
|
|
|
PrimitiveAssembler primitive_assembler{buffer_cache};
|
2018-08-10 09:45:38 +02:00
|
|
|
GLint uniform_buffer_alignment;
|
2018-03-20 04:00:59 +01: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;
|
|
|
|
|
2018-08-29 00:27:03 +02:00
|
|
|
void SetupVertexArrays();
|
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-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
|