From 6ff7906ddc89d8f970702d320f29317831de7975 Mon Sep 17 00:00:00 2001 From: Markus Wick Date: Fri, 10 Aug 2018 10:29:37 +0200 Subject: gl_rasterizer: Use the stream buffer for constant buffers. --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 39 ++++++++++++------------ src/video_core/renderer_opengl/gl_rasterizer.h | 11 +++---- src/video_core/renderer_opengl/gl_state.cpp | 9 ++++-- src/video_core/renderer_opengl/gl_state.h | 2 ++ 4 files changed, 32 insertions(+), 29 deletions(-) (limited to 'src/video_core') diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 5a0e337a5..fd4731d80 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -44,14 +44,6 @@ RasterizerOpenGL::RasterizerOpenGL(Core::Frontend::EmuWindow& window) state.texture_units[i].sampler = texture_samplers[i].sampler.handle; } - // Create SSBOs - for (size_t stage = 0; stage < ssbos.size(); ++stage) { - for (size_t buffer = 0; buffer < ssbos[stage].size(); ++buffer) { - ssbos[stage][buffer].Create(); - state.draw.const_buffers[stage][buffer].ssbo = ssbos[stage][buffer].handle; - } - } - GLint ext_num; glGetIntegerv(GL_NUM_EXTENSIONS, &ext_num); for (GLint i = 0; i < ext_num; i++) { @@ -255,9 +247,9 @@ std::pair RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr static_cast(stage)); // Configure the const buffers for this shader stage. - current_constbuffer_bindpoint = - SetupConstBuffers(static_cast(stage), gl_stage_program, - current_constbuffer_bindpoint, shader_resources.const_buffer_entries); + std::tie(buffer_ptr, buffer_offset, current_constbuffer_bindpoint) = SetupConstBuffers( + buffer_ptr, buffer_offset, static_cast(stage), gl_stage_program, + current_constbuffer_bindpoint, shader_resources.const_buffer_entries); // Configure the textures for this shader stage. current_texture_bindpoint = @@ -453,6 +445,9 @@ void RasterizerOpenGL::DrawArrays() { Common::AlignUp(buffer_size, 4) + (sizeof(GLShader::MaxwellUniformData) + uniform_buffer_alignment) * Maxwell::MaxShaderStage; + // Add space for at least 18 constant buffers + buffer_size += Maxwell::MaxConstBuffers * (MaxConstbufferSize + uniform_buffer_alignment); + u8* buffer_ptr; GLintptr buffer_offset; std::tie(buffer_ptr, buffer_offset, std::ignore) = @@ -627,9 +622,9 @@ void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::TSCEntr } } -u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint program, - u32 current_bindpoint, - const std::vector& entries) { +std::tuple RasterizerOpenGL::SetupConstBuffers( + u8* buffer_ptr, GLintptr buffer_offset, Maxwell::ShaderStage stage, GLuint program, + u32 current_bindpoint, const std::vector& entries) { const auto& gpu = Core::System::GetInstance().GPU(); const auto& maxwell3d = gpu.Maxwell3D(); @@ -678,12 +673,16 @@ u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint progr size = Common::AlignUp(size, sizeof(GLvec4)); ASSERT_MSG(size <= MaxConstbufferSize, "Constbuffer too big"); - std::vector data(size); - Memory::ReadBlock(*addr, data.data(), data.size()); + std::tie(buffer_ptr, buffer_offset) = + AlignBuffer(buffer_ptr, buffer_offset, static_cast(uniform_buffer_alignment)); - glBindBuffer(GL_UNIFORM_BUFFER, buffer_draw_state.ssbo); - glBufferData(GL_UNIFORM_BUFFER, data.size(), data.data(), GL_DYNAMIC_DRAW); - glBindBuffer(GL_UNIFORM_BUFFER, 0); + buffer_draw_state.size = size; + buffer_draw_state.offset = buffer_offset; + buffer_draw_state.ssbo = stream_buffer.GetHandle(); + + Memory::ReadBlock(*addr, buffer_ptr, size); + buffer_ptr += size; + buffer_offset += size; // Now configure the bindpoint of the buffer inside the shader const std::string buffer_name = used_buffer.GetName(); @@ -696,7 +695,7 @@ u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint progr state.Apply(); - return current_bindpoint + static_cast(entries.size()); + return {buffer_ptr, buffer_offset, current_bindpoint + static_cast(entries.size())}; } u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, GLuint program, u32 current_unit, diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 6f8503703..aa6afc1de 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -100,9 +101,10 @@ private: * @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, - u32 current_bindpoint, - const std::vector& entries); + std::tuple SetupConstBuffers( + u8* buffer_ptr, GLintptr buffer_offset, Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, + GLuint program, u32 current_bindpoint, + const std::vector& entries); /* * Configures the current textures to use for the draw command. @@ -154,9 +156,6 @@ private: OGLVertexArray hw_vao; std::array texture_samplers; - std::array, - Tegra::Engines::Maxwell3D::Regs::MaxShaderStage> - ssbos; static constexpr size_t STREAM_BUFFER_SIZE = 128 * 1024 * 1024; OGLStreamBuffer stream_buffer; diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp index 68bacd4c5..212c87e0c 100644 --- a/src/video_core/renderer_opengl/gl_state.cpp +++ b/src/video_core/renderer_opengl/gl_state.cpp @@ -209,10 +209,13 @@ void OpenGLState::Apply() const { const auto& current = cur_state.draw.const_buffers[stage][buffer_id]; const auto& new_state = draw.const_buffers[stage][buffer_id]; - if (current.enabled != new_state.enabled || current.bindpoint != new_state.bindpoint || - current.ssbo != new_state.ssbo) { + if (std::tie(current.enabled, current.bindpoint, current.ssbo, current.size, + current.offset) != std::tie(new_state.enabled, new_state.bindpoint, + new_state.ssbo, new_state.size, + new_state.offset)) { if (new_state.enabled) { - glBindBufferBase(GL_UNIFORM_BUFFER, new_state.bindpoint, new_state.ssbo); + glBindBufferRange(GL_UNIFORM_BUFFER, new_state.bindpoint, new_state.ssbo, + new_state.offset, new_state.size); } } } diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h index 5c7b636e4..26e5460e5 100644 --- a/src/video_core/renderer_opengl/gl_state.h +++ b/src/video_core/renderer_opengl/gl_state.h @@ -123,6 +123,8 @@ public: bool enabled = false; GLuint bindpoint; GLuint ssbo; + GLsizeiptr size; + GLintptr offset; }; std::array, 5> const_buffers; } draw; -- cgit v1.2.3