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>
|
|
|
|
#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;
|
|
|
|
|
|
|
|
class RasterizerOpenGL : public VideoCore::RasterizerInterface {
|
|
|
|
public:
|
|
|
|
RasterizerOpenGL();
|
|
|
|
~RasterizerOpenGL() override;
|
|
|
|
|
2018-03-25 04:50:21 +02:00
|
|
|
void DrawArrays() 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-03-23 02:13:46 +01:00
|
|
|
bool AccelerateDisplay(const Tegra::FramebufferConfig& framebuffer, VAddr framebuffer_addr,
|
2018-03-23 02:04:30 +01:00
|
|
|
u32 pixel_stride, ScreenInfo& screen_info) 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
u32 border_color_r;
|
|
|
|
u32 border_color_g;
|
|
|
|
u32 border_color_b;
|
|
|
|
u32 border_color_a;
|
|
|
|
};
|
2018-03-20 04:00:59 +01: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-03-27 04:54:16 +02:00
|
|
|
/// Binds the required textures to OpenGL before drawing a batch.
|
|
|
|
void BindTextures();
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
u32 SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, GLuint program,
|
2018-04-15 21:42:23 +02:00
|
|
|
u32 current_bindpoint,
|
|
|
|
const std::vector<GLShader::ConstBufferEntry>& entries);
|
2018-04-14 18:50:15 +02:00
|
|
|
|
2018-03-27 02:45:10 +02:00
|
|
|
/// Syncs the viewport to match the guest state
|
|
|
|
void SyncViewport(const MathUtil::Rectangle<u32>& surfaces_rect, u16 res_scale);
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
/// Syncs the blend enabled status to match the guest state
|
|
|
|
void SyncBlendEnabled();
|
|
|
|
|
|
|
|
/// Syncs the blend functions to match the guest state
|
|
|
|
void SyncBlendFuncs();
|
|
|
|
|
|
|
|
/// Syncs the blend color to match the guest state
|
|
|
|
void SyncBlendColor();
|
|
|
|
|
|
|
|
bool has_ARB_buffer_storage;
|
|
|
|
bool has_ARB_direct_state_access;
|
|
|
|
bool has_ARB_separate_shader_objects;
|
|
|
|
bool has_ARB_vertex_attrib_binding;
|
|
|
|
|
|
|
|
OpenGLState state;
|
|
|
|
|
|
|
|
RasterizerCacheOpenGL res_cache;
|
|
|
|
|
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:50:15 +02:00
|
|
|
std::array<std::array<OGLBuffer, Tegra::Engines::Maxwell3D::Regs::MaxConstBuffers>,
|
|
|
|
Tegra::Engines::Maxwell3D::Regs::MaxShaderStage>
|
|
|
|
ssbos;
|
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;
|
|
|
|
std::unique_ptr<OGLStreamBuffer> stream_buffer;
|
2018-03-20 04:00:59 +01:00
|
|
|
OGLBuffer uniform_buffer;
|
|
|
|
OGLFramebuffer framebuffer;
|
|
|
|
|
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-04-08 06:00:11 +02:00
|
|
|
std::array<OGLBuffer, Tegra::Engines::Maxwell3D::Regs::MaxShaderStage> uniform_buffers;
|
2018-03-20 04:00:59 +01:00
|
|
|
|
2018-04-22 02:19:33 +02:00
|
|
|
void SetupShaders(u8* buffer_ptr, GLintptr buffer_offset);
|
2018-03-20 04:00:59 +01:00
|
|
|
|
|
|
|
enum class AccelDraw { Disabled, Arrays, Indexed };
|
|
|
|
AccelDraw accelerate_draw;
|
|
|
|
};
|