diff options
author | bunnei <bunneidev@gmail.com> | 2018-06-26 16:25:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-26 16:25:56 +0200 |
commit | 36dedae842b3bc094f52e46f0e8edc028edeec25 (patch) | |
tree | 79886fcda14b4db11b65e2c2dff338c4e9c2689c /src/video_core/renderer_opengl/gl_rasterizer.cpp | |
parent | Merge pull request #589 from mailwl/fix-crash (diff) | |
parent | Rasterizer: Use UBOs instead of SSBOs for uploading const buffers. (diff) | |
download | yuzu-36dedae842b3bc094f52e46f0e8edc028edeec25.tar yuzu-36dedae842b3bc094f52e46f0e8edc028edeec25.tar.gz yuzu-36dedae842b3bc094f52e46f0e8edc028edeec25.tar.bz2 yuzu-36dedae842b3bc094f52e46f0e8edc028edeec25.tar.lz yuzu-36dedae842b3bc094f52e46f0e8edc028edeec25.tar.xz yuzu-36dedae842b3bc094f52e46f0e8edc028edeec25.tar.zst yuzu-36dedae842b3bc094f52e46f0e8edc028edeec25.zip |
Diffstat (limited to 'src/video_core/renderer_opengl/gl_rasterizer.cpp')
-rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 3ba20f978..0f6dec60b 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp @@ -197,8 +197,8 @@ void RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr buffer_offset) { ASSERT_MSG(!gpu.regs.shader_config[0].enable, "VertexA is unsupported!"); // Next available bindpoints to use when uploading the const buffers and textures to the GLSL - // shaders. - u32 current_constbuffer_bindpoint = 0; + // shaders. The constbuffer bindpoint starts after the shader stage configuration bind points. + u32 current_constbuffer_bindpoint = uniform_buffers.size(); u32 current_texture_bindpoint = 0; for (unsigned index = 1; index < Maxwell::MaxShaderProgram; ++index) { @@ -608,27 +608,33 @@ u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint progr boost::optional<VAddr> addr = gpu.memory_manager->GpuToCpuAddress(buffer.address); - std::vector<u8> data; + size_t size = 0; + if (used_buffer.IsIndirect()) { // Buffer is accessed indirectly, so upload the entire thing - data.resize(buffer.size * sizeof(float)); + size = buffer.size * sizeof(float); } else { // Buffer is accessed directly, upload just what we use - data.resize(used_buffer.GetSize() * sizeof(float)); + size = used_buffer.GetSize() * sizeof(float); } + // Align the actual size so it ends up being a multiple of vec4 to meet the OpenGL std140 + // UBO alignment requirements. + size = Common::AlignUp(size, sizeof(GLvec4)); + ASSERT_MSG(size <= MaxConstbufferSize, "Constbuffer too big"); + + std::vector<u8> data(size); Memory::ReadBlock(*addr, data.data(), data.size()); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer_draw_state.ssbo); - glBufferData(GL_SHADER_STORAGE_BUFFER, data.size(), data.data(), GL_DYNAMIC_DRAW); - glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); + glBindBuffer(GL_UNIFORM_BUFFER, buffer_draw_state.ssbo); + glBufferData(GL_UNIFORM_BUFFER, data.size(), data.data(), GL_DYNAMIC_DRAW); + glBindBuffer(GL_UNIFORM_BUFFER, 0); // Now configure the bindpoint of the buffer inside the shader std::string buffer_name = used_buffer.GetName(); - GLuint index = - glGetProgramResourceIndex(program, GL_SHADER_STORAGE_BLOCK, buffer_name.c_str()); + GLuint index = glGetProgramResourceIndex(program, GL_UNIFORM_BLOCK, buffer_name.c_str()); if (index != -1) - glShaderStorageBlockBinding(program, index, buffer_draw_state.bindpoint); + glUniformBlockBinding(program, index, buffer_draw_state.bindpoint); } state.Apply(); |