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>
|
|
|
|
#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>
|
|
|
|
#include <glad/glad.h>
|
|
|
|
#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-03-20 04:00:59 +01:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_rasterizer_cache.h"
|
|
|
|
#include "video_core/renderer_opengl/gl_resource_manager.h"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
struct ScreenInfo;
|
|
|
|
|
2018-08-12 02:20:19 +02:00
|
|
|
namespace Core::Frontend {
|
|
|
|
class EmuWindow;
|
|
|
|
}
|
|
|
|
|
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-04-14 05:13:47 +02:00
|
|
|
void NotifyMaxwellRegisterChanged(u32 method) override;
|
2018-03-20 04:00:59 +01:00
|
|
|
void FlushAll() override;
|
2018-04-24 06:19:36 +02:00
|
|
|
void FlushRegion(Tegra::GPUVAddr addr, u64 size) override;
|
|
|
|
void InvalidateRegion(Tegra::GPUVAddr addr, u64 size) override;
|
|
|
|
void FlushAndInvalidateRegion(Tegra::GPUVAddr addr, u64 size) override;
|
2018-03-20 04:00:59 +01:00
|
|
|
bool AccelerateDisplayTransfer(const void* config) override;
|
|
|
|
bool AccelerateTextureCopy(const void* config) override;
|
|
|
|
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-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-06-27 05:07:34 +02:00
|
|
|
static constexpr 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-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-07-03 23:55:44 +02:00
|
|
|
/// Configures the color and depth framebuffer states and returns the dirty <Color, Depth>
|
|
|
|
/// surfaces if writing was enabled.
|
2018-08-20 22:18:51 +02:00
|
|
|
std::pair<Surface, Surface> ConfigureFramebuffers(bool using_color_fb, bool using_depth_fb,
|
|
|
|
bool preserve_contents);
|
2018-07-03 23:55:44 +02:00
|
|
|
|
2018-03-27 02:58:19 +02:00
|
|
|
/// Binds the framebuffer color and depth surface
|
|
|
|
void BindFramebufferSurfaces(const Surface& color_surface, const Surface& depth_surface,
|
|
|
|
bool has_stencil);
|
|
|
|
|
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.
|
|
|
|
* @param program The OpenGL program object that contains the specified stage.
|
|
|
|
* @param current_bindpoint The offset at which to start counting new buffer bindpoints.
|
|
|
|
* @param entries Vector describing the buffers that are actually used in the guest shader.
|
|
|
|
* @returns The next available bindpoint for use in the next shader stage.
|
|
|
|
*/
|
2018-08-10 10:29:37 +02:00
|
|
|
std::tuple<u8*, GLintptr, u32> SetupConstBuffers(
|
|
|
|
u8* buffer_ptr, GLintptr buffer_offset, Tegra::Engines::Maxwell3D::Regs::ShaderStage stage,
|
|
|
|
GLuint program, u32 current_bindpoint,
|
|
|
|
const std::vector<GLShader::ConstBufferEntry>& entries);
|
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.
|
|
|
|
* @param program The OpenGL program object that contains the specified stage.
|
|
|
|
* @param current_unit The offset at which to start counting unused texture units.
|
|
|
|
* @param entries Vector describing the textures that are actually used in the guest shader.
|
|
|
|
* @returns The next available bindpoint for use in the next shader stage.
|
|
|
|
*/
|
|
|
|
u32 SetupTextures(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, GLuint program,
|
|
|
|
u32 current_unit, const std::vector<GLShader::SamplerEntry>& entries);
|
|
|
|
|
2018-03-27 02:45:10 +02:00
|
|
|
/// Syncs the viewport to match the guest state
|
2018-06-22 01:36:01 +02:00
|
|
|
void SyncViewport(const MathUtil::Rectangle<u32>& surfaces_rect);
|
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-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-07-24 18:08:10 +02:00
|
|
|
bool has_ARB_direct_state_access = false;
|
|
|
|
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-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-03-20 04:00:59 +01:00
|
|
|
OGLVertexArray sw_vao;
|
|
|
|
OGLVertexArray hw_vao;
|
|
|
|
|
2018-04-15 00:50:06 +02:00
|
|
|
std::array<SamplerInfo, GLShader::NumTextureSamplers> texture_samplers;
|
2018-04-14 18:45:23 +02:00
|
|
|
|
2018-05-19 18:36:09 +02:00
|
|
|
static constexpr size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024;
|
2018-08-09 21:31:46 +02:00
|
|
|
OGLStreamBuffer stream_buffer;
|
2018-03-20 04:00:59 +01:00
|
|
|
OGLBuffer uniform_buffer;
|
|
|
|
OGLFramebuffer framebuffer;
|
2018-08-10 09:45:38 +02:00
|
|
|
GLint uniform_buffer_alignment;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2018-04-22 02:19:33 +02:00
|
|
|
size_t CalculateVertexArraysSize() const;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2018-04-22 02:19:33 +02:00
|
|
|
std::pair<u8*, GLintptr> SetupVertexArrays(u8* array_ptr, GLintptr buffer_offset);
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2018-08-10 09:30:35 +02:00
|
|
|
std::pair<u8*, GLintptr> SetupShaders(u8* buffer_ptr, GLintptr buffer_offset);
|
|
|
|
|
|
|
|
std::pair<u8*, GLintptr> AlignBuffer(u8* buffer_ptr, GLintptr buffer_offset, size_t alignment);
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2018-08-10 19:11:12 +02:00
|
|
|
std::tuple<u8*, GLintptr, GLintptr> UploadMemory(u8* buffer_ptr, GLintptr buffer_offset,
|
|
|
|
Tegra::GPUVAddr gpu_addr, size_t size,
|
|
|
|
size_t alignment = 4);
|
|
|
|
|
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-03-20 04:00:59 +01:00
|
|
|
};
|