diff options
Diffstat (limited to 'src/video_core/renderer_opengl/gl_rasterizer.h')
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 148 |
1 files changed, 42 insertions, 106 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 390349a0c..82fa61742 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -4,22 +4,33 @@ #pragma once +#include <array> #include <cstddef> #include <cstring> #include <memory> #include <vector> #include <unordered_map> +#include <glad/glad.h> + +#include "common/bit_field.h" #include "common/common_types.h" #include "common/hash.h" +#include "common/vector_math.h" + +#include "core/hw/gpu.h" #include "video_core/pica.h" #include "video_core/pica_state.h" +#include "video_core/pica_types.h" #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_state.h" #include "video_core/renderer_opengl/pica_to_gl.h" -#include "video_core/shader/shader_interpreter.h" +#include "video_core/shader/shader.h" + +struct ScreenInfo; /** * This struct contains all state used to generate the GLSL shader program that emulates the current @@ -38,36 +49,18 @@ struct PicaShaderConfig { res.alpha_test_func = regs.output_merger.alpha_test.enable ? regs.output_merger.alpha_test.func.Value() : Pica::Regs::CompareFunc::Always; - // Copy relevant TevStageConfig fields only. We're doing this manually (instead of calling - // the GetTevStages() function) because BitField explicitly disables copies. - - res.tev_stages[0].sources_raw = regs.tev_stage0.sources_raw; - res.tev_stages[1].sources_raw = regs.tev_stage1.sources_raw; - res.tev_stages[2].sources_raw = regs.tev_stage2.sources_raw; - res.tev_stages[3].sources_raw = regs.tev_stage3.sources_raw; - res.tev_stages[4].sources_raw = regs.tev_stage4.sources_raw; - res.tev_stages[5].sources_raw = regs.tev_stage5.sources_raw; - - res.tev_stages[0].modifiers_raw = regs.tev_stage0.modifiers_raw; - res.tev_stages[1].modifiers_raw = regs.tev_stage1.modifiers_raw; - res.tev_stages[2].modifiers_raw = regs.tev_stage2.modifiers_raw; - res.tev_stages[3].modifiers_raw = regs.tev_stage3.modifiers_raw; - res.tev_stages[4].modifiers_raw = regs.tev_stage4.modifiers_raw; - res.tev_stages[5].modifiers_raw = regs.tev_stage5.modifiers_raw; - - res.tev_stages[0].ops_raw = regs.tev_stage0.ops_raw; - res.tev_stages[1].ops_raw = regs.tev_stage1.ops_raw; - res.tev_stages[2].ops_raw = regs.tev_stage2.ops_raw; - res.tev_stages[3].ops_raw = regs.tev_stage3.ops_raw; - res.tev_stages[4].ops_raw = regs.tev_stage4.ops_raw; - res.tev_stages[5].ops_raw = regs.tev_stage5.ops_raw; - - res.tev_stages[0].scales_raw = regs.tev_stage0.scales_raw; - res.tev_stages[1].scales_raw = regs.tev_stage1.scales_raw; - res.tev_stages[2].scales_raw = regs.tev_stage2.scales_raw; - res.tev_stages[3].scales_raw = regs.tev_stage3.scales_raw; - res.tev_stages[4].scales_raw = regs.tev_stage4.scales_raw; - res.tev_stages[5].scales_raw = regs.tev_stage5.scales_raw; + // Copy relevant tev stages fields. + // We don't sync const_color here because of the high variance, it is a + // shader uniform instead. + const auto& tev_stages = regs.GetTevStages(); + DEBUG_ASSERT(res.tev_stages.size() == tev_stages.size()); + for (size_t i = 0; i < tev_stages.size(); i++) { + const auto& tev_stage = tev_stages[i]; + res.tev_stages[i].sources_raw = tev_stage.sources_raw; + res.tev_stages[i].modifiers_raw = tev_stage.modifiers_raw; + res.tev_stages[i].ops_raw = tev_stage.ops_raw; + res.tev_stages[i].scales_raw = tev_stage.scales_raw; + } res.combiner_buffer_input = regs.tev_combiner_buffer_input.update_mask_rgb.Value() | @@ -191,16 +184,17 @@ public: RasterizerOpenGL(); ~RasterizerOpenGL() override; - void InitObjects() override; - void Reset() override; void AddTriangle(const Pica::Shader::OutputVertex& v0, const Pica::Shader::OutputVertex& v1, const Pica::Shader::OutputVertex& v2) override; void DrawTriangles() override; - void FlushFramebuffer() override; void NotifyPicaRegisterChanged(u32 id) override; + void FlushAll() override; void FlushRegion(PAddr addr, u32 size) override; - void InvalidateRegion(PAddr addr, u32 size) override; + void FlushAndInvalidateRegion(PAddr addr, u32 size) override; + bool AccelerateDisplayTransfer(const GPU::Regs::DisplayTransferConfig& config) override; + bool AccelerateFill(const GPU::Regs::MemoryFillConfig& config) override; + bool AccelerateDisplay(const GPU::Regs::FramebufferConfig& config, PAddr framebuffer_addr, u32 pixel_stride, ScreenInfo& screen_info) override; /// OpenGL shader generated for a given Pica register state struct PicaShader { @@ -210,26 +204,6 @@ public: private: - /// Structure used for storing information about color textures - struct TextureInfo { - OGLTexture texture; - GLsizei width; - GLsizei height; - Pica::Regs::ColorFormat format; - GLenum gl_format; - GLenum gl_type; - }; - - /// Structure used for storing information about depth textures - struct DepthTextureInfo { - OGLTexture texture; - GLsizei width; - GLsizei height; - Pica::Regs::DepthFormat format; - GLenum gl_format; - GLenum gl_type; - }; - struct SamplerInfo { using TextureConfig = Pica::Regs::TextureConfig; @@ -311,18 +285,9 @@ private: static_assert(sizeof(UniformData) == 0x310, "The size of the UniformData structure has changed, update the structure in the shader"); static_assert(sizeof(UniformData) < 16384, "UniformData structure must be less than 16kb as per the OpenGL spec"); - /// Reconfigure the OpenGL color texture to use the given format and dimensions - void ReconfigureColorTexture(TextureInfo& texture, Pica::Regs::ColorFormat format, u32 width, u32 height); - - /// Reconfigure the OpenGL depth texture to use the given format and dimensions - void ReconfigureDepthTexture(DepthTextureInfo& texture, Pica::Regs::DepthFormat format, u32 width, u32 height); - /// Sets the OpenGL shader in accordance with the current PICA register state void SetShader(); - /// Syncs the state and contents of the OpenGL framebuffer to match the current PICA framebuffer - void SyncFramebuffer(); - /// Syncs the cull mode to match the PICA register void SyncCullMode(); @@ -359,72 +324,42 @@ private: /// Syncs the depth test states to match the PICA register void SyncDepthTest(); - /// Syncs the TEV constant color to match the PICA register - void SyncTevConstColor(int tev_index, const Pica::Regs::TevStageConfig& tev_stage); - /// Syncs the TEV combiner color buffer to match the PICA register void SyncCombinerColor(); + /// Syncs the TEV constant color to match the PICA register + void SyncTevConstColor(int tev_index, const Pica::Regs::TevStageConfig& tev_stage); + /// Syncs the lighting global ambient color to match the PICA register void SyncGlobalAmbient(); /// Syncs the lighting lookup tables void SyncLightingLUT(unsigned index); - /// Syncs the specified light's diffuse color to match the PICA register - void SyncLightDiffuse(int light_index); - - /// Syncs the specified light's ambient color to match the PICA register - void SyncLightAmbient(int light_index); - - /// Syncs the specified light's position to match the PICA register - void SyncLightPosition(int light_index); - /// Syncs the specified light's specular 0 color to match the PICA register void SyncLightSpecular0(int light_index); /// Syncs the specified light's specular 1 color to match the PICA register void SyncLightSpecular1(int light_index); - /// Syncs the remaining OpenGL drawing state to match the current PICA state - void SyncDrawState(); - - /// Copies the 3DS color framebuffer into the OpenGL color framebuffer texture - void ReloadColorBuffer(); + /// Syncs the specified light's diffuse color to match the PICA register + void SyncLightDiffuse(int light_index); - /// Copies the 3DS depth framebuffer into the OpenGL depth framebuffer texture - void ReloadDepthBuffer(); + /// Syncs the specified light's ambient color to match the PICA register + void SyncLightAmbient(int light_index); - /** - * Save the current OpenGL color framebuffer to the current PICA framebuffer in 3DS memory - * Loads the OpenGL framebuffer textures into temporary buffers - * Then copies into the 3DS framebuffer using proper Morton order - */ - void CommitColorBuffer(); + /// Syncs the specified light's position to match the PICA register + void SyncLightPosition(int light_index); - /** - * Save the current OpenGL depth framebuffer to the current PICA framebuffer in 3DS memory - * Loads the OpenGL framebuffer textures into temporary buffers - * Then copies into the 3DS framebuffer using proper Morton order - */ - void CommitDepthBuffer(); + OpenGLState state; RasterizerCacheOpenGL res_cache; std::vector<HardwareVertex> vertex_batch; - OpenGLState state; - - PAddr cached_fb_color_addr; - PAddr cached_fb_depth_addr; - - // Hardware rasterizer - std::array<SamplerInfo, 3> texture_samplers; - TextureInfo fb_color_texture; - DepthTextureInfo fb_depth_texture; - std::unordered_map<PicaShaderConfig, std::unique_ptr<PicaShader>> shader_cache; const PicaShader* current_shader = nullptr; + bool shader_dirty; struct { UniformData data; @@ -432,11 +367,12 @@ private: bool dirty; } uniform_block_data; + std::array<SamplerInfo, 3> texture_samplers; OGLVertexArray vertex_array; OGLBuffer vertex_buffer; OGLBuffer uniform_buffer; OGLFramebuffer framebuffer; - std::array<OGLTexture, 6> lighting_lut; + std::array<OGLTexture, 6> lighting_luts; std::array<std::array<GLvec4, 256>, 6> lighting_lut_data; }; |