diff options
| author | 2018-04-15 14:42:23 -0500 | |
|---|---|---|
| committer | 2018-04-15 15:02:50 -0500 | |
| commit | 477aab59603825e3cfc5144b784d0fe3df286ae4 (patch) | |
| tree | 4ea684514f99ad3e1718282e01e2d04c6b938f5f /src | |
| parent | GPU: Don't use explicit binding points when uploading the constbuffers to ope... (diff) | |
| download | yuzu-477aab59603825e3cfc5144b784d0fe3df286ae4.tar.gz yuzu-477aab59603825e3cfc5144b784d0fe3df286ae4.tar.xz yuzu-477aab59603825e3cfc5144b784d0fe3df286ae4.zip | |
GPU: Use the same buffer names in the generated GLSL and the buffer uploading code.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 17 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 5 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 5 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.h | 14 |
4 files changed, 24 insertions, 17 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index a80923285..28abc563a 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -226,10 +226,6 @@ void RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr buffer_offset, size | |||
| 226 | 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)); |
| 227 | GLShader::ShaderSetup setup{std::move(program_code)}; | 227 | GLShader::ShaderSetup setup{std::move(program_code)}; |
| 228 | 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 | |||
| 233 | GLShader::ShaderEntries shader_resources; | 229 | GLShader::ShaderEntries shader_resources; |
| 234 | 230 | ||
| 235 | switch (program) { | 231 | switch (program) { |
| @@ -255,9 +251,9 @@ void RasterizerOpenGL::SetupShaders(u8* buffer_ptr, GLintptr buffer_offset, size | |||
| 255 | static_cast<Maxwell::ShaderStage>(stage)); | 251 | static_cast<Maxwell::ShaderStage>(stage)); |
| 256 | 252 | ||
| 257 | // Configure the const buffers for this shader stage. | 253 | // Configure the const buffers for this shader stage. |
| 258 | current_constbuffer_bindpoint = SetupConstBuffers( | 254 | current_constbuffer_bindpoint = |
| 259 | static_cast<Maxwell::ShaderStage>(stage), gl_stage_program, base_names[stage], | 255 | SetupConstBuffers(static_cast<Maxwell::ShaderStage>(stage), gl_stage_program, |
| 260 | current_constbuffer_bindpoint, shader_resources.const_buffer_entries); | 256 | current_constbuffer_bindpoint, shader_resources.const_buffer_entries); |
| 261 | } | 257 | } |
| 262 | 258 | ||
| 263 | shader_program_manager->UseTrivialGeometryShader(); | 259 | shader_program_manager->UseTrivialGeometryShader(); |
| @@ -555,7 +551,7 @@ void RasterizerOpenGL::SamplerInfo::SyncWithConfig(const Tegra::Texture::TSCEntr | |||
| 555 | } | 551 | } |
| 556 | 552 | ||
| 557 | u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint program, | 553 | u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint program, |
| 558 | const std::string& base_name, u32 current_bindpoint, | 554 | u32 current_bindpoint, |
| 559 | const std::vector<GLShader::ConstBufferEntry>& entries) { | 555 | const std::vector<GLShader::ConstBufferEntry>& entries) { |
| 560 | auto& gpu = Core::System::GetInstance().GPU(); | 556 | auto& gpu = Core::System::GetInstance().GPU(); |
| 561 | auto& maxwell3d = gpu.Get3DEngine(); | 557 | auto& maxwell3d = gpu.Get3DEngine(); |
| @@ -591,10 +587,11 @@ u32 RasterizerOpenGL::SetupConstBuffers(Maxwell::ShaderStage stage, GLuint progr | |||
| 591 | glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); | 587 | glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0); |
| 592 | 588 | ||
| 593 | // Now configure the bindpoint of the buffer inside the shader | 589 | // Now configure the bindpoint of the buffer inside the shader |
| 594 | std::string buffer_name = base_name + std::to_string(used_buffer.GetIndex()); | 590 | std::string buffer_name = used_buffer.GetName(); |
| 595 | GLuint index = | 591 | GLuint index = |
| 596 | glGetProgramResourceIndex(program, GL_SHADER_STORAGE_BLOCK, buffer_name.c_str()); | 592 | glGetProgramResourceIndex(program, GL_SHADER_STORAGE_BLOCK, buffer_name.c_str()); |
| 597 | glShaderStorageBlockBinding(program, index, buffer_draw_state.bindpoint); | 593 | if (index != -1) |
| 594 | glShaderStorageBlockBinding(program, index, buffer_draw_state.bindpoint); | ||
| 598 | } | 595 | } |
| 599 | 596 | ||
| 600 | state.Apply(); | 597 | state.Apply(); |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 32d9598aa..548ce0453 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -91,14 +91,13 @@ private: | |||
| 91 | * Configures the current constbuffers to use for the draw command. | 91 | * Configures the current constbuffers to use for the draw command. |
| 92 | * @param stage The shader stage to configure buffers for. | 92 | * @param stage The shader stage to configure buffers for. |
| 93 | * @param program The OpenGL program object that contains the specified stage. | 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. | 94 | * @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. | 95 | * @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. | 96 | * @returns The next available bindpoint for use in the next shader stage. |
| 98 | */ | 97 | */ |
| 99 | u32 SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, GLuint program, | 98 | u32 SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, GLuint program, |
| 100 | const std::string& base_name, u32 current_bindpoint, | 99 | u32 current_bindpoint, |
| 101 | const std::vector<GLShader::ConstBufferEntry>& entries); | 100 | const std::vector<GLShader::ConstBufferEntry>& entries); |
| 102 | 101 | ||
| 103 | /// Syncs the viewport to match the guest state | 102 | /// Syncs the viewport to match the guest state |
| 104 | void SyncViewport(const MathUtil::Rectangle<u32>& surfaces_rect, u16 res_scale); | 103 | void SyncViewport(const MathUtil::Rectangle<u32>& surfaces_rect, u16 res_scale); |
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 9cf2c6a0c..e11711533 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -192,7 +192,7 @@ private: | |||
| 192 | 192 | ||
| 193 | /// Generates code representing a uniform (C buffer) register. | 193 | /// Generates code representing a uniform (C buffer) register. |
| 194 | std::string GetUniform(const Uniform& reg) { | 194 | std::string GetUniform(const Uniform& reg) { |
| 195 | declr_const_buffers[reg.index].MarkAsUsed(reg.index, reg.offset); | 195 | declr_const_buffers[reg.index].MarkAsUsed(reg.index, reg.offset, stage); |
| 196 | return 'c' + std::to_string(reg.index) + '[' + std::to_string(reg.offset) + ']'; | 196 | return 'c' + std::to_string(reg.index) + '[' + std::to_string(reg.offset) + ']'; |
| 197 | } | 197 | } |
| 198 | 198 | ||
| @@ -478,8 +478,7 @@ private: | |||
| 478 | 478 | ||
| 479 | unsigned const_buffer_layout = 0; | 479 | unsigned const_buffer_layout = 0; |
| 480 | for (const auto& entry : GetConstBuffersDeclarations()) { | 480 | for (const auto& entry : GetConstBuffersDeclarations()) { |
| 481 | declarations.AddLine("layout(std430, binding = " + std::to_string(const_buffer_layout) + | 481 | declarations.AddLine("layout(std430) buffer " + entry.GetName()); |
| 482 | ") buffer c" + std::to_string(entry.GetIndex()) + "_buffer"); | ||
| 483 | declarations.AddLine("{"); | 482 | declarations.AddLine("{"); |
| 484 | declarations.AddLine(" float c" + std::to_string(entry.GetIndex()) + "[];"); | 483 | declarations.AddLine(" float c" + std::to_string(entry.GetIndex()) + "[];"); |
| 485 | declarations.AddLine("};"); | 484 | declarations.AddLine("};"); |
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.h b/src/video_core/renderer_opengl/gl_shader_gen.h index 3d9aead74..458032b5c 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.h +++ b/src/video_core/renderer_opengl/gl_shader_gen.h | |||
| @@ -19,10 +19,13 @@ constexpr size_t MAX_PROGRAM_CODE_LENGTH{0x1000}; | |||
| 19 | using ProgramCode = std::array<u64, MAX_PROGRAM_CODE_LENGTH>; | 19 | using ProgramCode = std::array<u64, MAX_PROGRAM_CODE_LENGTH>; |
| 20 | 20 | ||
| 21 | class ConstBufferEntry { | 21 | class ConstBufferEntry { |
| 22 | using Maxwell = Tegra::Engines::Maxwell3D::Regs; | ||
| 23 | |||
| 22 | public: | 24 | public: |
| 23 | void MarkAsUsed(unsigned index, unsigned offset) { | 25 | void MarkAsUsed(unsigned index, unsigned offset, Maxwell::ShaderStage stage) { |
| 24 | is_used = true; | 26 | is_used = true; |
| 25 | this->index = index; | 27 | this->index = index; |
| 28 | this->stage = stage; | ||
| 26 | max_offset = std::max(max_offset, offset); | 29 | max_offset = std::max(max_offset, offset); |
| 27 | } | 30 | } |
| 28 | 31 | ||
| @@ -38,10 +41,19 @@ public: | |||
| 38 | return max_offset + 1; | 41 | return max_offset + 1; |
| 39 | } | 42 | } |
| 40 | 43 | ||
| 44 | std::string GetName() const { | ||
| 45 | return BufferBaseNames[static_cast<size_t>(stage)] + std::to_string(index); | ||
| 46 | } | ||
| 47 | |||
| 41 | private: | 48 | private: |
| 49 | static constexpr std::array<const char*, Maxwell::MaxShaderStage> BufferBaseNames = { | ||
| 50 | "buffer_vs_c", "buffer_tessc_c", "buffer_tesse_c", "buffer_gs_c", "buffer_fs_c", | ||
| 51 | }; | ||
| 52 | |||
| 42 | bool is_used{}; | 53 | bool is_used{}; |
| 43 | unsigned index{}; | 54 | unsigned index{}; |
| 44 | unsigned max_offset{}; | 55 | unsigned max_offset{}; |
| 56 | Maxwell::ShaderStage stage; | ||
| 45 | }; | 57 | }; |
| 46 | 58 | ||
| 47 | struct ShaderEntries { | 59 | struct ShaderEntries { |