diff options
author | Subv <subv2112@gmail.com> | 2018-04-15 18:15:54 +0200 |
---|---|---|
committer | Subv <subv2112@gmail.com> | 2018-04-15 18:15:54 +0200 |
commit | 7da47da66e150e1d5bc1e43a37b3d9d9554b1c5f (patch) | |
tree | 9eb70498adeac6b023d29e48199364e1b6d6279a | |
parent | Merge pull request #333 from bunnei/const-buff-hints (diff) | |
download | yuzu-7da47da66e150e1d5bc1e43a37b3d9d9554b1c5f.tar yuzu-7da47da66e150e1d5bc1e43a37b3d9d9554b1c5f.tar.gz yuzu-7da47da66e150e1d5bc1e43a37b3d9d9554b1c5f.tar.bz2 yuzu-7da47da66e150e1d5bc1e43a37b3d9d9554b1c5f.tar.lz yuzu-7da47da66e150e1d5bc1e43a37b3d9d9554b1c5f.tar.xz yuzu-7da47da66e150e1d5bc1e43a37b3d9d9554b1c5f.tar.zst yuzu-7da47da66e150e1d5bc1e43a37b3d9d9554b1c5f.zip |
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 67 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 3 | ||||
-rw-r--r-- | src/video_core/renderer_opengl/gl_state.h | 2 |
3 files changed, 41 insertions, 31 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 2a2268c20..8709f9fc2 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -223,15 +223,19 @@ void RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr buffer_offset, size Memory::ReadBlock(cpu_address, program_code.data(), program_code.size() * sizeof(u64)); GLShader::ShaderSetup setup{std::move(program_code)}; + GLShader::ShaderEntries shader_resources; + switch (program) { case Maxwell::ShaderProgram::VertexB: { GLShader::MaxwellVSConfig vs_config{setup}; - shader_program_manager->UseProgrammableVertexShader(vs_config, setup); + shader_resources = + shader_program_manager->UseProgrammableVertexShader(vs_config, setup); break; } case Maxwell::ShaderProgram::Fragment: { GLShader::MaxwellFSConfig fs_config{setup}; - shader_program_manager->UseProgrammableFragmentShader(fs_config, setup); + shader_resources = + shader_program_manager->UseProgrammableFragmentShader(fs_config, setup); break; } default: @@ -239,6 +243,10 @@ void RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr buffer_offset, size shader_config.enable.Value(), shader_config.offset); UNREACHABLE(); } + + // Configure the const buffers for this shader stage. + SetupConstBuffers(static_cast<Maxwell::ShaderStage>(stage), + shader_resources.const_buffer_entries); } shader_program_manager->UseTrivialGeometryShader(); @@ -306,8 +314,6 @@ void RasterizerOpenGL::DrawArrays() { // Sync and bind the texture surfaces BindTextures(); - // Configure the constant buffer objects - SetupConstBuffers(); // Viewport can have negative offsets or larger dimensions than our framebuffer sub-rect. Enable // scissor test to prevent drawing outside of the framebuffer region @@ -537,36 +543,39 @@ void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::TSCEntr } } -void RasterizerOpenGL::SetupConstBuffers() { - using Regs = Tegra::Engines::Maxwell3D::Regs; +void RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, + const std::vector<GLShader::ConstBufferEntry>& entries) { auto& gpu = Core::System::GetInstance().GPU(); auto& maxwell3d = gpu.Get3DEngine(); - // Upload only the enabled buffers from the 16 constbuffers of each shader stage - u32 current_bindpoint = 0; - for (u32 stage = 0; stage < Regs::MaxShaderStage; ++stage) { - auto& shader_stage = maxwell3d.state.shader_stages[stage]; - bool stage_enabled = maxwell3d.IsShaderStageEnabled(static_cast<Regs::ShaderStage>(stage)); - - for (u32 buffer_id = 0; buffer_id < Regs::MaxConstBuffers; ++buffer_id) { - const auto& buffer = shader_stage.const_buffers[buffer_id]; + ASSERT_MSG(maxwell3d.IsShaderStageEnabled(stage), + "Attempted to upload constbuffer of disabled shader stage"); - state.draw.const_buffers[stage][buffer_id].enabled = buffer.enabled && stage_enabled; - - if (buffer.enabled && stage_enabled) { - state.draw.const_buffers[stage][buffer_id].bindpoint = current_bindpoint; - current_bindpoint++; + // Reset all buffer draw state for this stage. + for (auto& buffer : state.draw.const_buffers[static_cast<size_t>(stage)]) { + buffer.bindpoint = 0; + buffer.enabled = false; + } - VAddr addr = gpu.memory_manager->PhysicalToVirtualAddress(buffer.address); - const u8* data = Memory::GetPointer(addr); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, - state.draw.const_buffers[stage][buffer_id].ssbo); - glBufferData(GL_SHADER_STORAGE_BUFFER, buffer.size, data, GL_DYNAMIC_DRAW); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); - } else { - state.draw.const_buffers[stage][buffer_id].bindpoint = -1; - } - } + // Upload only the enabled buffers from the 16 constbuffers of each shader stage + auto& shader_stage = maxwell3d.state.shader_stages[static_cast<size_t>(stage)]; + + for (u32 bindpoint = 0; bindpoint < entries.size(); ++bindpoint) { + const auto& used_buffer = entries[bindpoint]; + const auto& buffer = shader_stage.const_buffers[used_buffer.GetIndex()]; + auto& buffer_draw_state = + state.draw.const_buffers[static_cast<size_t>(stage)][used_buffer.GetIndex()]; + + ASSERT_MSG(buffer.enabled, "Attempted to upload disabled constbuffer"); + buffer_draw_state.enabled = true; + buffer_draw_state.bindpoint = bindpoint; + + VAddr addr = gpu.memory_manager->PhysicalToVirtualAddress(buffer.address); + const u8* data = Memory::GetPointer(addr); + glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer_draw_state.ssbo); + glBufferData(GL_SHADER_STORAGE_BUFFER, used_buffer.GetSize() * sizeof(float), data, + GL_DYNAMIC_DRAW); + glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); } state.Apply(); diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index bf3308aef..1ea0dfa71 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -88,7 +88,8 @@ private: void BindTextures(); /// Configures the current constbuffers to use for the draw command. - void SetupConstBuffers(); + void SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, + const std::vector<GLShader::ConstBufferEntry>& entries); /// Syncs the viewport to match the guest state void SyncViewport(const MathUtil::Rectangle<u32>& surfaces_rect, u16 res_scale); diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h index 6a80e6a7d..75c08e645 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h @@ -124,7 +124,7 @@ public: GLuint shader_program; // GL_CURRENT_PROGRAM GLuint program_pipeline; // GL_PROGRAM_PIPELINE_BINDING struct ConstBufferConfig { - bool enabled; + bool enabled = false; GLuint bindpoint; GLuint ssbo; }; |