summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Subv2018-04-15 14:14:57 -0500
committerGravatar Subv2018-04-15 14:14:57 -0500
commit14ac40436ead929506d5fdf16eb3721940e60956 (patch)
treea3bf955b685822b3931203eb0f075f72010150b0 /src
parentGPU: Don't use GetPointer when uploading the constbuffer data to the GPU. (diff)
downloadyuzu-14ac40436ead929506d5fdf16eb3721940e60956.tar.gz
yuzu-14ac40436ead929506d5fdf16eb3721940e60956.tar.xz
yuzu-14ac40436ead929506d5fdf16eb3721940e60956.zip
GPU: Don't use explicit binding points when uploading the constbuffers to opengl.
The bindpoints will now be dynamically calculated based on the number of buffers used by the previous shader stage.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp30
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h13
-rw-r--r--src/video_core/renderer_opengl/gl_shader_manager.h11
3 files changed, 47 insertions, 7 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index a778dfc64..a80923285 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -193,6 +193,9 @@ void RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr buffer_offset, size
193 auto& gpu = Core::System().GetInstance().GPU().Maxwell3D(); 193 auto& gpu = Core::System().GetInstance().GPU().Maxwell3D();
194 ASSERT_MSG(!gpu.regs.shader_config[0].enable, "VertexA is unsupported!"); 194 ASSERT_MSG(!gpu.regs.shader_config[0].enable, "VertexA is unsupported!");
195 195
196 // Next available bindpoint to use when uploading the const buffers to the GLSL shaders.
197 u32 current_constbuffer_bindpoint = 0;
198
196 for (unsigned index = 1; index < Maxwell::MaxShaderProgram; ++index) { 199 for (unsigned index = 1; index < Maxwell::MaxShaderProgram; ++index) {
197 ptr_pos += sizeof(GLShader::MaxwellUniformData); 200 ptr_pos += sizeof(GLShader::MaxwellUniformData);
198 201
@@ -223,6 +226,10 @@ void RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr buffer_offset, size
223 Memory::ReadBlock(cpu_address, program_code.data(), program_code.size() * sizeof(u64)); 226 Memory::ReadBlock(cpu_address, program_code.data(), program_code.size() * sizeof(u64));
224 GLShader::ShaderSetup setup{std::move(program_code)}; 227 GLShader::ShaderSetup setup{std::move(program_code)};
225 228
229 static constexpr std::array<const char*, Maxwell::MaxShaderStage> base_names = {
230 "buffer_vs_c", "buffer_tessc_c", "buffer_tesse_c", "buffer_gs_c", "buffer_fs_c",
231 };
232
226 GLShader::ShaderEntries shader_resources; 233 GLShader::ShaderEntries shader_resources;
227 234
228 switch (program) { 235 switch (program) {
@@ -244,9 +251,13 @@ void RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr buffer_offset, size
244 UNREACHABLE(); 251 UNREACHABLE();
245 } 252 }
246 253
254 GLuint gl_stage_program = shader_program_manager->GetCurrentProgramStage(
255 static_cast<Maxwell::ShaderStage>(stage));
256
247 // Configure the const buffers for this shader stage. 257 // Configure the const buffers for this shader stage.
248 SetupConstBuffers(static_cast<Maxwell::ShaderStage>(stage), 258 current_constbuffer_bindpoint = SetupConstBuffers(
249 shader_resources.const_buffer_entries); 259 static_cast<Maxwell::ShaderStage>(stage), gl_stage_program, base_names[stage],
260 current_constbuffer_bindpoint, shader_resources.const_buffer_entries);
250 } 261 }
251 262
252 shader_program_manager->UseTrivialGeometryShader(); 263 shader_program_manager->UseTrivialGeometryShader();
@@ -543,8 +554,9 @@ void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::TSCEntr
543 } 554 }
544} 555}
545 556
546void RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, 557u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint program,
547 const std::vector<GLShader::ConstBufferEntry>& entries) { 558 const std::string& base_name, u32 current_bindpoint,
559 const std::vector<GLShader::ConstBufferEntry>& entries) {
548 auto& gpu = Core::System::GetInstance().GPU(); 560 auto& gpu = Core::System::GetInstance().GPU();
549 auto& maxwell3d = gpu.Get3DEngine(); 561 auto& maxwell3d = gpu.Get3DEngine();
550 562
@@ -568,7 +580,7 @@ void RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage,
568 580
569 ASSERT_MSG(buffer.enabled, "Attempted to upload disabled constbuffer"); 581 ASSERT_MSG(buffer.enabled, "Attempted to upload disabled constbuffer");
570 buffer_draw_state.enabled = true; 582 buffer_draw_state.enabled = true;
571 buffer_draw_state.bindpoint = bindpoint; 583 buffer_draw_state.bindpoint = current_bindpoint + bindpoint;
572 584
573 VAddr addr = gpu.memory_manager->PhysicalToVirtualAddress(buffer.address); 585 VAddr addr = gpu.memory_manager->PhysicalToVirtualAddress(buffer.address);
574 std::vector<u8> data(used_buffer.GetSize() * sizeof(float)); 586 std::vector<u8> data(used_buffer.GetSize() * sizeof(float));
@@ -577,9 +589,17 @@ void RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage,
577 glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer_draw_state.ssbo); 589 glBindBuffer(GL_SHADER_STORAGE_BUFFER, buffer_draw_state.ssbo);
578 glBufferData(GL_SHADER_STORAGE_BUFFER, data.size(), data.data(), GL_DYNAMIC_DRAW); 590 glBufferData(GL_SHADER_STORAGE_BUFFER, data.size(), data.data(), GL_DYNAMIC_DRAW);
579 glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); 591 glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);
592
593 // Now configure the bindpoint of the buffer inside the shader
594 std::string buffer_name = base_name + std::to_string(used_buffer.GetIndex());
595 GLuint index =
596 glGetProgramResourceIndex(program, GL_SHADER_STORAGE_BLOCK, buffer_name.c_str());
597 glShaderStorageBlockBinding(program, index, buffer_draw_state.bindpoint);
580 } 598 }
581 599
582 state.Apply(); 600 state.Apply();
601
602 return current_bindpoint + entries.size();
583} 603}
584 604
585void RasterizerOpenGL::BindFramebufferSurfaces(const Surface& color_surface, 605void RasterizerOpenGL::BindFramebufferSurfaces(const Surface& color_surface,
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 1ea0dfa71..32d9598aa 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -87,8 +87,17 @@ private:
87 /// Binds the required textures to OpenGL before drawing a batch. 87 /// Binds the required textures to OpenGL before drawing a batch.
88 void BindTextures(); 88 void BindTextures();
89 89
90 /// Configures the current constbuffers to use for the draw command. 90 /*
91 void SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, 91 * Configures the current constbuffers to use for the draw command.
92 * @param stage The shader stage to configure buffers for.
93 * @param program The OpenGL program object that contains the specified stage.
94 * @param base_name The name prefix of the buffer objects in the GLSL shaders.
95 * @param current_bindpoint The offset at which to start counting new buffer bindpoints.
96 * @param entries Vector describing the buffers that are actually used in the guest shader.
97 * @returns The next available bindpoint for use in the next shader stage.
98 */
99 u32 SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, GLuint program,
100 const std::string& base_name, u32 current_bindpoint,
92 const std::vector<GLShader::ConstBufferEntry>& entries); 101 const std::vector<GLShader::ConstBufferEntry>& entries);
93 102
94 /// Syncs the viewport to match the guest state 103 /// Syncs the viewport to match the guest state
diff --git a/src/video_core/renderer_opengl/gl_shader_manager.h b/src/video_core/renderer_opengl/gl_shader_manager.h
index ecc92d986..be63320e0 100644
--- a/src/video_core/renderer_opengl/gl_shader_manager.h
+++ b/src/video_core/renderer_opengl/gl_shader_manager.h
@@ -121,6 +121,17 @@ public:
121 return result; 121 return result;
122 } 122 }
123 123
124 GLuint GetCurrentProgramStage(Maxwell3D::Regs::ShaderStage stage) {
125 switch (stage) {
126 case Maxwell3D::Regs::ShaderStage::Vertex:
127 return current.vs;
128 case Maxwell3D::Regs::ShaderStage::Fragment:
129 return current.fs;
130 }
131
132 UNREACHABLE();
133 }
134
124 void UseTrivialGeometryShader() { 135 void UseTrivialGeometryShader() {
125 current.gs = 0; 136 current.gs = 0;
126 } 137 }