From 9f803299de3a9c512939ede48654fab838343a8a Mon Sep 17 00:00:00 2001 From: ReinUsesLisp Date: Sat, 5 Jan 2019 01:01:38 -0300 Subject: gl_rasterizer: Implement global memory management --- src/video_core/renderer_opengl/gl_rasterizer.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/video_core/renderer_opengl/gl_rasterizer.cpp') diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 71829fee0..ca421ef28 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -300,6 +300,7 @@ void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) { // Next available bindpoints to use when uploading the const buffers and textures to the GLSL // shaders. The constbuffer bindpoint starts after the shader stage configuration bind points. u32 current_constbuffer_bindpoint = Tegra::Engines::Maxwell3D::Regs::MaxShaderStage; + u32 current_gmem_bindpoint = 0; u32 current_texture_bindpoint = 0; std::array clip_distances{}; @@ -358,6 +359,10 @@ void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) { SetupConstBuffers(static_cast(stage), shader, primitive_mode, current_constbuffer_bindpoint); + // Configure global memory regions for this shader stage. + current_gmem_bindpoint = SetupGlobalRegions(static_cast(stage), + shader, primitive_mode, current_gmem_bindpoint); + // Configure the textures for this shader stage. current_texture_bindpoint = SetupTextures(static_cast(stage), shader, primitive_mode, current_texture_bindpoint); @@ -993,6 +998,23 @@ u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, Shader& shad return current_bindpoint + static_cast(entries.size()); } +u32 RasterizerOpenGL::SetupGlobalRegions(Maxwell::ShaderStage stage, Shader& shader, + GLenum primitive_mode, u32 current_bindpoint) { + for (const auto& global_region : shader->GetShaderEntries().global_memory_entries) { + const auto& region = + global_cache.GetGlobalRegion(global_region, static_cast(stage)); + const GLuint block_index{shader->GetProgramResourceIndex(global_region)}; + ASSERT(block_index != GL_INVALID_INDEX); + + glBindBufferBase(GL_SHADER_STORAGE_BUFFER, current_bindpoint, region->GetBufferHandle()); + glShaderStorageBlockBinding(shader->GetProgramHandle(primitive_mode), block_index, + current_bindpoint); + ++current_bindpoint; + } + + return current_bindpoint; +} + u32 RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, Shader& shader, GLenum primitive_mode, u32 current_unit) { MICROPROFILE_SCOPE(OpenGL_Texture); -- cgit v1.2.3