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
|
|
|
|
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"
|
2019-10-27 07:40:08 +01:00
|
|
|
#include "video_core/rasterizer_accelerated.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-05-11 08:15:49 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_framebuffer_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"
|
2019-07-12 01:09:53 +02:00
|
|
|
#include "video_core/textures/texture.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-08-21 10:18:27 +02:00
|
|
|
|
2019-10-27 07:40:08 +01:00
|
|
|
class RasterizerOpenGL : public VideoCore::RasterizerAccelerated {
|
2018-03-20 04:00:59 +01:00
|
|
|
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-09-19 17:41:07 +02:00
|
|
|
bool DrawBatch(bool is_indexed) override;
|
|
|
|
bool DrawMultiBatch(bool is_indexed) override;
|
2018-06-07 06:54:25 +02:00
|
|
|
void Clear() override;
|
2019-07-15 03:25:13 +02:00
|
|
|
void DispatchCompute(GPUVAddr code_addr) 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;
|
2019-07-26 20:20:43 +02:00
|
|
|
void FlushCommands() override;
|
2019-06-20 08:22:25 +02:00
|
|
|
void TickFrame() 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-05-18 10:57:49 +02:00
|
|
|
const Tegra::Engines::Fermi2D::Config& copy_config) override;
|
2018-08-21 01:34:02 +02:00
|
|
|
bool AccelerateDisplay(const Tegra::FramebufferConfig& config, VAddr framebuffer_addr,
|
|
|
|
u32 pixel_stride) 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
|
|
|
|
|
|
|
private:
|
2019-09-17 07:36:47 +02:00
|
|
|
/// Configures the color and depth framebuffer states.
|
|
|
|
void ConfigureFramebuffers();
|
2018-03-27 02:58:19 +02:00
|
|
|
|
2019-07-14 14:14:27 +02:00
|
|
|
void ConfigureClearFramebuffer(OpenGLState& current_state, bool using_color_fb,
|
|
|
|
bool using_depth_fb, bool using_stencil_fb);
|
|
|
|
|
2019-01-05 05:00:06 +01:00
|
|
|
/// Configures the current constbuffers to use for the draw command.
|
2019-11-18 22:35:21 +01:00
|
|
|
void SetupDrawConstBuffers(std::size_t stage_index, const Shader& shader);
|
2019-05-31 22:33:21 +02:00
|
|
|
|
2019-07-15 03:25:13 +02:00
|
|
|
/// Configures the current constbuffers to use for the kernel invocation.
|
|
|
|
void SetupComputeConstBuffers(const Shader& kernel);
|
|
|
|
|
2019-05-31 22:33:21 +02:00
|
|
|
/// Configures a constant buffer.
|
2019-11-19 01:38:15 +01:00
|
|
|
void SetupConstBuffer(u32 binding, const Tegra::Engines::ConstBufferInfo& buffer,
|
2019-05-31 22:33:21 +02:00
|
|
|
const GLShader::ConstBufferEntry& entry);
|
2019-01-05 05:00:06 +01:00
|
|
|
|
|
|
|
/// Configures the current global memory entries to use for the draw command.
|
2019-11-18 22:35:21 +01:00
|
|
|
void SetupDrawGlobalMemory(std::size_t stage_index, const Shader& shader);
|
2019-07-15 03:25:13 +02:00
|
|
|
|
|
|
|
/// Configures the current global memory entries to use for the kernel invocation.
|
|
|
|
void SetupComputeGlobalMemory(const Shader& kernel);
|
|
|
|
|
|
|
|
/// Configures a constant buffer.
|
2019-11-19 01:38:15 +01:00
|
|
|
void SetupGlobalMemory(u32 binding, const GLShader::GlobalMemoryEntry& entry, GPUVAddr gpu_addr,
|
2019-07-15 03:25:13 +02:00
|
|
|
std::size_t size);
|
2019-01-05 05:00:06 +01:00
|
|
|
|
2019-09-18 13:51:05 +02:00
|
|
|
/// Syncs all the state, shaders, render targets and textures setting before a draw call.
|
2020-01-30 06:08:46 +01:00
|
|
|
void Draw(bool is_indexed, bool is_instanced);
|
2019-09-15 17:48:54 +02:00
|
|
|
|
2019-11-06 08:32:43 +01:00
|
|
|
/// Configures the current textures to use for the draw command.
|
2019-11-19 01:38:15 +01:00
|
|
|
void SetupDrawTextures(std::size_t stage_index, const Shader& shader);
|
2019-07-12 01:09:53 +02:00
|
|
|
|
2019-11-06 08:32:43 +01:00
|
|
|
/// Configures the textures used in a compute shader.
|
|
|
|
void SetupComputeTextures(const Shader& kernel);
|
2019-07-18 02:50:21 +02:00
|
|
|
|
2019-11-06 08:32:43 +01:00
|
|
|
/// Configures a texture.
|
|
|
|
void SetupTexture(u32 binding, const Tegra::Texture::FullTextureInfo& texture,
|
2019-07-12 01:09:53 +02:00
|
|
|
const GLShader::SamplerEntry& entry);
|
2018-06-06 19:58:16 +02:00
|
|
|
|
2019-11-13 04:27:12 +01:00
|
|
|
/// Configures images in a graphics shader.
|
2019-11-19 01:38:15 +01:00
|
|
|
void SetupDrawImages(std::size_t stage_index, const Shader& shader);
|
2019-11-13 04:27:12 +01:00
|
|
|
|
2019-07-12 07:17:18 +02:00
|
|
|
/// Configures images in a compute shader.
|
2019-07-12 02:54:07 +02:00
|
|
|
void SetupComputeImages(const Shader& shader);
|
|
|
|
|
2019-07-12 07:17:18 +02:00
|
|
|
/// Configures an image.
|
|
|
|
void SetupImage(u32 binding, const Tegra::Texture::TICEntry& tic,
|
|
|
|
const GLShader::ImageEntry& entry);
|
|
|
|
|
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();
|
|
|
|
|
2019-12-18 23:26:52 +01:00
|
|
|
/// Syncs the rasterizer enable state to match the guest state
|
|
|
|
void SyncRasterizeEnable(OpenGLState& current_state);
|
|
|
|
|
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-04-02 21:58:08 +02:00
|
|
|
SamplerCacheOpenGL sampler_cache;
|
2019-05-11 08:15:49 +02:00
|
|
|
FramebufferCacheOpenGL framebuffer_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-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-06-20 08:44:06 +02:00
|
|
|
VertexArrayPushBuffer vertex_array_pushbuffer;
|
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);
|
2019-07-10 21:38:31 +02:00
|
|
|
void SetupVertexInstances(GLuint vao);
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2019-06-20 08:44:06 +02:00
|
|
|
GLintptr SetupIndexBuffer();
|
2019-05-28 00:37:46 +02:00
|
|
|
|
2018-10-07 04:17:31 +02:00
|
|
|
void SetupShaders(GLenum primitive_mode);
|
2018-03-20 04:00:59 +01:00
|
|
|
};
|
2018-08-21 10:18:27 +02:00
|
|
|
|
|
|
|
} // namespace OpenGL
|