2022-08-21 01:22:57 +02:00
|
|
|
// Copyright 2022 Citra Emulator Project
|
2015-05-19 06:21:33 +02:00
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
2023-03-27 13:29:17 +02:00
|
|
|
|
2016-04-30 17:34:51 +02:00
|
|
|
#include "core/hw/gpu.h"
|
2023-03-27 13:29:17 +02:00
|
|
|
#include "video_core/rasterizer_accelerated.h"
|
2015-12-07 04:06:12 +01:00
|
|
|
#include "video_core/rasterizer_interface.h"
|
2017-01-29 00:12:09 +01:00
|
|
|
#include "video_core/regs_texturing.h"
|
2018-04-09 23:31:11 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_shader_manager.h"
|
2015-09-11 13:20:02 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_state.h"
|
2018-03-14 23:36:54 +01:00
|
|
|
#include "video_core/renderer_opengl/gl_stream_buffer.h"
|
2023-04-21 09:14:55 +02:00
|
|
|
#include "video_core/renderer_opengl/gl_texture_runtime.h"
|
2016-04-30 17:34:51 +02:00
|
|
|
|
2023-03-30 13:24:49 +02:00
|
|
|
namespace VideoCore {
|
|
|
|
class RendererBase;
|
2018-08-12 02:20:19 +02:00
|
|
|
}
|
|
|
|
|
2023-04-27 06:38:28 +02:00
|
|
|
namespace VideoCore {
|
|
|
|
class CustomTexManager;
|
|
|
|
}
|
|
|
|
|
2018-11-17 08:29:10 +01:00
|
|
|
namespace OpenGL {
|
2023-03-27 13:29:17 +02:00
|
|
|
|
2023-08-02 00:40:39 +02:00
|
|
|
struct ScreenInfo;
|
|
|
|
|
2023-03-27 13:29:17 +02:00
|
|
|
class Driver;
|
2020-04-19 02:12:20 +02:00
|
|
|
class ShaderProgramManager;
|
2018-11-17 08:29:10 +01:00
|
|
|
|
2023-03-27 13:29:17 +02:00
|
|
|
class RasterizerOpenGL : public VideoCore::RasterizerAccelerated {
|
2015-05-19 06:21:33 +02:00
|
|
|
public:
|
2023-04-27 06:38:28 +02:00
|
|
|
explicit RasterizerOpenGL(Memory::MemorySystem& memory,
|
|
|
|
VideoCore::CustomTexManager& custom_tex_manager,
|
|
|
|
VideoCore::RendererBase& renderer, Driver& driver);
|
2015-05-19 06:21:33 +02:00
|
|
|
~RasterizerOpenGL() override;
|
|
|
|
|
2023-04-27 06:38:28 +02:00
|
|
|
void TickFrame();
|
2019-09-08 00:11:09 +02:00
|
|
|
void LoadDiskResources(const std::atomic_bool& stop_loading,
|
|
|
|
const VideoCore::DiskResourceLoadCallback& callback) override;
|
|
|
|
|
2015-05-19 06:21:33 +02:00
|
|
|
void DrawTriangles() override;
|
2016-04-17 00:57:57 +02:00
|
|
|
void FlushAll() override;
|
2015-12-07 02:56:45 +01:00
|
|
|
void FlushRegion(PAddr addr, u32 size) override;
|
2017-12-12 18:21:55 +01:00
|
|
|
void InvalidateRegion(PAddr addr, u32 size) override;
|
2016-04-17 00:57:57 +02:00
|
|
|
void FlushAndInvalidateRegion(PAddr addr, u32 size) override;
|
2020-01-17 07:17:55 +01:00
|
|
|
void ClearAll(bool flush) override;
|
2016-04-17 00:57:57 +02:00
|
|
|
bool AccelerateDisplayTransfer(const GPU::Regs::DisplayTransferConfig& config) override;
|
2016-09-27 12:09:53 +02:00
|
|
|
bool AccelerateTextureCopy(const GPU::Regs::DisplayTransferConfig& config) override;
|
2016-04-17 00:57:57 +02:00
|
|
|
bool AccelerateFill(const GPU::Regs::MemoryFillConfig& config) override;
|
2016-09-18 02:38:01 +02:00
|
|
|
bool AccelerateDisplay(const GPU::Regs::FramebufferConfig& config, PAddr framebuffer_addr,
|
2023-08-02 00:40:39 +02:00
|
|
|
u32 pixel_stride, ScreenInfo& screen_info);
|
2018-05-11 15:41:26 +02:00
|
|
|
bool AccelerateDrawBatch(bool is_indexed) override;
|
2015-05-19 06:21:33 +02:00
|
|
|
|
2015-10-10 01:32:38 +02:00
|
|
|
private:
|
2023-03-27 13:29:17 +02:00
|
|
|
void SyncFixedState() override;
|
|
|
|
void NotifyFixedFunctionPicaRegisterChanged(u32 id) override;
|
|
|
|
|
2017-08-22 08:49:53 +02:00
|
|
|
/// Syncs the clip enabled status to match the PICA register
|
|
|
|
void SyncClipEnabled();
|
|
|
|
|
2015-05-19 06:21:33 +02:00
|
|
|
/// Syncs the cull mode to match the PICA register
|
|
|
|
void SyncCullMode();
|
|
|
|
|
|
|
|
/// Syncs the blend enabled status to match the PICA register
|
|
|
|
void SyncBlendEnabled();
|
|
|
|
|
|
|
|
/// Syncs the blend functions to match the PICA register
|
|
|
|
void SyncBlendFuncs();
|
|
|
|
|
|
|
|
/// Syncs the blend color to match the PICA register
|
|
|
|
void SyncBlendColor();
|
|
|
|
|
2015-05-26 00:39:03 +02:00
|
|
|
/// Syncs the logic op states to match the PICA register
|
|
|
|
void SyncLogicOp();
|
|
|
|
|
2016-03-31 15:36:00 +02:00
|
|
|
/// Syncs the color write mask to match the PICA register state
|
|
|
|
void SyncColorWriteMask();
|
|
|
|
|
|
|
|
/// Syncs the stencil write mask to match the PICA register state
|
|
|
|
void SyncStencilWriteMask();
|
|
|
|
|
|
|
|
/// Syncs the depth write mask to match the PICA register state
|
|
|
|
void SyncDepthWriteMask();
|
|
|
|
|
2015-05-19 06:21:33 +02:00
|
|
|
/// Syncs the stencil test states to match the PICA register
|
|
|
|
void SyncStencilTest();
|
|
|
|
|
|
|
|
/// Syncs the depth test states to match the PICA register
|
|
|
|
void SyncDepthTest();
|
|
|
|
|
2018-05-19 11:12:51 +02:00
|
|
|
/// Syncs and uploads the lighting, fog and proctex LUTs
|
|
|
|
void SyncAndUploadLUTs();
|
2020-06-04 16:34:00 +02:00
|
|
|
void SyncAndUploadLUTsLF();
|
2018-05-19 11:12:51 +02:00
|
|
|
|
2023-04-21 09:14:55 +02:00
|
|
|
/// Syncs all enabled PICA texture units
|
2023-08-01 02:35:41 +02:00
|
|
|
void SyncTextureUnits(const Framebuffer* framebuffer);
|
2023-04-21 09:14:55 +02:00
|
|
|
|
|
|
|
/// Binds the PICA shadow cube required for shadow mapping
|
|
|
|
void BindShadowCube(const Pica::TexturingRegs::FullTextureConfig& texture);
|
|
|
|
|
|
|
|
/// Binds a texture cube to texture unit 0
|
|
|
|
void BindTextureCube(const Pica::TexturingRegs::FullTextureConfig& texture);
|
|
|
|
|
|
|
|
/// Makes a temporary copy of the framebuffer if a feedback loop is detected
|
2023-08-01 02:35:41 +02:00
|
|
|
bool IsFeedbackLoop(u32 texture_index, const Framebuffer* framebuffer, Surface& surface);
|
2023-04-21 09:14:55 +02:00
|
|
|
|
|
|
|
/// Unbinds all special texture unit 0 texture configurations
|
|
|
|
void UnbindSpecial();
|
|
|
|
|
2023-04-27 06:38:28 +02:00
|
|
|
/// Binds the custom material referenced by surface if it exists.
|
|
|
|
void BindMaterial(u32 texture_index, Surface& surface);
|
|
|
|
|
2018-05-02 09:34:36 +02:00
|
|
|
/// Upload the uniform blocks to the uniform buffer object
|
2019-08-19 02:07:50 +02:00
|
|
|
void UploadUniforms(bool accelerate_draw);
|
2018-05-11 15:41:26 +02:00
|
|
|
|
|
|
|
/// Generic draw function for DrawTriangles and AccelerateDrawBatch
|
2018-05-18 12:55:19 +02:00
|
|
|
bool Draw(bool accelerate, bool is_indexed);
|
2018-05-11 15:41:26 +02:00
|
|
|
|
|
|
|
/// Internal implementation for AccelerateDrawBatch
|
2019-08-19 02:07:50 +02:00
|
|
|
bool AccelerateDrawBatchInternal(bool is_indexed);
|
2018-05-11 15:41:26 +02:00
|
|
|
|
|
|
|
/// Setup vertex array for AccelerateDrawBatch
|
|
|
|
void SetupVertexArray(u8* array_ptr, GLintptr buffer_offset, GLuint vs_input_index_min,
|
|
|
|
GLuint vs_input_index_max);
|
|
|
|
|
|
|
|
/// Setup vertex shader for AccelerateDrawBatch
|
|
|
|
bool SetupVertexShader();
|
|
|
|
|
|
|
|
/// Setup geometry shader for AccelerateDrawBatch
|
|
|
|
bool SetupGeometryShader();
|
2018-05-02 09:34:36 +02:00
|
|
|
|
2023-03-27 13:29:17 +02:00
|
|
|
private:
|
|
|
|
Driver& driver;
|
2016-04-17 00:57:57 +02:00
|
|
|
OpenGLState state;
|
2023-08-02 00:40:39 +02:00
|
|
|
ShaderProgramManager shader_manager;
|
2023-04-21 09:14:55 +02:00
|
|
|
TextureRuntime runtime;
|
2023-05-07 01:34:28 +02:00
|
|
|
RasterizerCache res_cache;
|
2018-04-09 23:31:11 +02:00
|
|
|
|
2018-05-11 15:41:26 +02:00
|
|
|
OGLVertexArray sw_vao; // VAO for software shader draw
|
|
|
|
OGLVertexArray hw_vao; // VAO for hardware shader / accelerate draw
|
|
|
|
std::array<bool, 16> hw_vao_enabled_attributes{};
|
|
|
|
|
2023-04-21 09:14:55 +02:00
|
|
|
GLsizeiptr texture_buffer_size;
|
2018-03-22 22:16:23 +01:00
|
|
|
OGLStreamBuffer vertex_buffer;
|
2018-05-02 09:34:36 +02:00
|
|
|
OGLStreamBuffer uniform_buffer;
|
2018-05-11 15:41:26 +02:00
|
|
|
OGLStreamBuffer index_buffer;
|
2018-05-19 12:54:50 +02:00
|
|
|
OGLStreamBuffer texture_buffer;
|
2020-06-04 16:34:00 +02:00
|
|
|
OGLStreamBuffer texture_lf_buffer;
|
2018-05-02 09:34:36 +02:00
|
|
|
GLint uniform_buffer_alignment;
|
2023-09-30 11:06:06 +02:00
|
|
|
std::size_t uniform_size_aligned_vs_pica;
|
2018-09-06 22:03:28 +02:00
|
|
|
std::size_t uniform_size_aligned_vs;
|
|
|
|
std::size_t uniform_size_aligned_fs;
|
2015-11-15 23:43:01 +01:00
|
|
|
|
2020-06-04 16:34:00 +02:00
|
|
|
OGLTexture texture_buffer_lut_lf;
|
2018-05-19 12:54:50 +02:00
|
|
|
OGLTexture texture_buffer_lut_rg;
|
|
|
|
OGLTexture texture_buffer_lut_rgba;
|
2023-04-27 06:38:28 +02:00
|
|
|
bool use_custom_normal{};
|
2023-08-30 20:26:28 +02:00
|
|
|
bool emulate_minmax_blend{};
|
2015-05-19 06:21:33 +02:00
|
|
|
};
|
2018-11-17 08:29:10 +01:00
|
|
|
|
|
|
|
} // namespace OpenGL
|