diff options
| author | 2019-06-17 22:35:04 -0400 | |
|---|---|---|
| committer | 2019-06-17 22:35:04 -0400 | |
| commit | c7b5c245e1e6c8ec27e26cd767a34eeb8531580b (patch) | |
| tree | b0139c242f5a609e73e253e5d717dc5149527bfb /src | |
| parent | Merge pull request #2538 from ReinUsesLisp/ssy-pbk (diff) | |
| parent | gl_rasterizer: Remove unused parameters in descriptor uploads (diff) | |
| download | yuzu-c7b5c245e1e6c8ec27e26cd767a34eeb8531580b.tar.gz yuzu-c7b5c245e1e6c8ec27e26cd767a34eeb8531580b.tar.xz yuzu-c7b5c245e1e6c8ec27e26cd767a34eeb8531580b.zip | |
Merge pull request #2562 from ReinUsesLisp/split-cbuf-upload
video_core/engines: Move ConstBufferInfo out of Maxwell3D
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/CMakeLists.txt | 1 | ||||
| -rw-r--r-- | src/video_core/engines/const_buffer_info.h | 17 | ||||
| -rw-r--r-- | src/video_core/engines/maxwell_3d.cpp | 4 | ||||
| -rw-r--r-- | src/video_core/engines/maxwell_3d.h | 8 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 80 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 15 |
6 files changed, 69 insertions, 56 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt index 2d4caa08d..f8b67cbe1 100644 --- a/src/video_core/CMakeLists.txt +++ b/src/video_core/CMakeLists.txt | |||
| @@ -3,6 +3,7 @@ add_library(video_core STATIC | |||
| 3 | dma_pusher.h | 3 | dma_pusher.h |
| 4 | debug_utils/debug_utils.cpp | 4 | debug_utils/debug_utils.cpp |
| 5 | debug_utils/debug_utils.h | 5 | debug_utils/debug_utils.h |
| 6 | engines/const_buffer_info.h | ||
| 6 | engines/engine_upload.cpp | 7 | engines/engine_upload.cpp |
| 7 | engines/engine_upload.h | 8 | engines/engine_upload.h |
| 8 | engines/fermi_2d.cpp | 9 | engines/fermi_2d.cpp |
diff --git a/src/video_core/engines/const_buffer_info.h b/src/video_core/engines/const_buffer_info.h new file mode 100644 index 000000000..d8f672462 --- /dev/null +++ b/src/video_core/engines/const_buffer_info.h | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include "common/common_types.h" | ||
| 8 | |||
| 9 | namespace Tegra::Engines { | ||
| 10 | |||
| 11 | struct ConstBufferInfo { | ||
| 12 | GPUVAddr address; | ||
| 13 | u32 size; | ||
| 14 | bool enabled; | ||
| 15 | }; | ||
| 16 | |||
| 17 | } // namespace Tegra::Engines | ||
diff --git a/src/video_core/engines/maxwell_3d.cpp b/src/video_core/engines/maxwell_3d.cpp index 39968d403..08d553696 100644 --- a/src/video_core/engines/maxwell_3d.cpp +++ b/src/video_core/engines/maxwell_3d.cpp | |||
| @@ -396,12 +396,10 @@ void Maxwell3D::ProcessCBBind(Regs::ShaderStage stage) { | |||
| 396 | auto& shader = state.shader_stages[static_cast<std::size_t>(stage)]; | 396 | auto& shader = state.shader_stages[static_cast<std::size_t>(stage)]; |
| 397 | auto& bind_data = regs.cb_bind[static_cast<std::size_t>(stage)]; | 397 | auto& bind_data = regs.cb_bind[static_cast<std::size_t>(stage)]; |
| 398 | 398 | ||
| 399 | auto& buffer = shader.const_buffers[bind_data.index]; | ||
| 400 | |||
| 401 | ASSERT(bind_data.index < Regs::MaxConstBuffers); | 399 | ASSERT(bind_data.index < Regs::MaxConstBuffers); |
| 400 | auto& buffer = shader.const_buffers[bind_data.index]; | ||
| 402 | 401 | ||
| 403 | buffer.enabled = bind_data.valid.Value() != 0; | 402 | buffer.enabled = bind_data.valid.Value() != 0; |
| 404 | buffer.index = bind_data.index; | ||
| 405 | buffer.address = regs.const_buffer.BufferAddress(); | 403 | buffer.address = regs.const_buffer.BufferAddress(); |
| 406 | buffer.size = regs.const_buffer.cb_size; | 404 | buffer.size = regs.const_buffer.cb_size; |
| 407 | } | 405 | } |
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index f342c78e6..13e314944 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h | |||
| @@ -15,6 +15,7 @@ | |||
| 15 | #include "common/common_funcs.h" | 15 | #include "common/common_funcs.h" |
| 16 | #include "common/common_types.h" | 16 | #include "common/common_types.h" |
| 17 | #include "common/math_util.h" | 17 | #include "common/math_util.h" |
| 18 | #include "video_core/engines/const_buffer_info.h" | ||
| 18 | #include "video_core/engines/engine_upload.h" | 19 | #include "video_core/engines/engine_upload.h" |
| 19 | #include "video_core/gpu.h" | 20 | #include "video_core/gpu.h" |
| 20 | #include "video_core/macro_interpreter.h" | 21 | #include "video_core/macro_interpreter.h" |
| @@ -1112,13 +1113,6 @@ public: | |||
| 1112 | static_assert(std::is_trivially_copyable_v<Regs>, "Maxwell3D Regs must be trivially copyable"); | 1113 | static_assert(std::is_trivially_copyable_v<Regs>, "Maxwell3D Regs must be trivially copyable"); |
| 1113 | 1114 | ||
| 1114 | struct State { | 1115 | struct State { |
| 1115 | struct ConstBufferInfo { | ||
| 1116 | GPUVAddr address; | ||
| 1117 | u32 index; | ||
| 1118 | u32 size; | ||
| 1119 | bool enabled; | ||
| 1120 | }; | ||
| 1121 | |||
| 1122 | struct ShaderStageInfo { | 1116 | struct ShaderStageInfo { |
| 1123 | std::array<ConstBufferInfo, Regs::MaxConstBuffers> const_buffers; | 1117 | std::array<ConstBufferInfo, Regs::MaxConstBuffers> const_buffers; |
| 1124 | }; | 1118 | }; |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index ca410287a..d77426067 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -322,9 +322,9 @@ void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) { | |||
| 322 | } | 322 | } |
| 323 | 323 | ||
| 324 | const auto stage_enum = static_cast<Maxwell::ShaderStage>(stage); | 324 | const auto stage_enum = static_cast<Maxwell::ShaderStage>(stage); |
| 325 | SetupConstBuffers(stage_enum, shader, program_handle, base_bindings); | 325 | SetupDrawConstBuffers(stage_enum, shader); |
| 326 | SetupGlobalRegions(stage_enum, shader, program_handle, base_bindings); | 326 | SetupGlobalRegions(stage_enum, shader); |
| 327 | SetupTextures(stage_enum, shader, program_handle, base_bindings); | 327 | SetupTextures(stage_enum, shader, base_bindings); |
| 328 | 328 | ||
| 329 | // Workaround for Intel drivers. | 329 | // Workaround for Intel drivers. |
| 330 | // When a clip distance is enabled but not set in the shader it crops parts of the screen | 330 | // When a clip distance is enabled but not set in the shader it crops parts of the screen |
| @@ -776,57 +776,55 @@ bool RasterizerOpenGL::AccelerateDisplay(const Tegra::FramebufferConfig& config, | |||
| 776 | return true; | 776 | return true; |
| 777 | } | 777 | } |
| 778 | 778 | ||
| 779 | void RasterizerOpenGL::SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, | 779 | void RasterizerOpenGL::SetupDrawConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, |
| 780 | const Shader& shader, GLuint program_handle, | 780 | const Shader& shader) { |
| 781 | BaseBindings base_bindings) { | ||
| 782 | MICROPROFILE_SCOPE(OpenGL_UBO); | 781 | MICROPROFILE_SCOPE(OpenGL_UBO); |
| 783 | const auto& gpu = system.GPU(); | 782 | const auto stage_index = static_cast<std::size_t>(stage); |
| 784 | const auto& maxwell3d = gpu.Maxwell3D(); | 783 | const auto& shader_stage = system.GPU().Maxwell3D().state.shader_stages[stage_index]; |
| 785 | const auto& shader_stage = maxwell3d.state.shader_stages[static_cast<std::size_t>(stage)]; | ||
| 786 | const auto& entries = shader->GetShaderEntries().const_buffers; | 784 | const auto& entries = shader->GetShaderEntries().const_buffers; |
| 787 | 785 | ||
| 788 | // Upload only the enabled buffers from the 16 constbuffers of each shader stage | 786 | // Upload only the enabled buffers from the 16 constbuffers of each shader stage |
| 789 | for (u32 bindpoint = 0; bindpoint < entries.size(); ++bindpoint) { | 787 | for (u32 bindpoint = 0; bindpoint < entries.size(); ++bindpoint) { |
| 790 | const auto& used_buffer = entries[bindpoint]; | 788 | const auto& entry = entries[bindpoint]; |
| 791 | const auto& buffer = shader_stage.const_buffers[used_buffer.GetIndex()]; | 789 | SetupConstBuffer(shader_stage.const_buffers[entry.GetIndex()], entry); |
| 792 | 790 | } | |
| 793 | if (!buffer.enabled) { | 791 | } |
| 794 | // Set values to zero to unbind buffers | ||
| 795 | bind_ubo_pushbuffer.Push(0, 0, 0); | ||
| 796 | continue; | ||
| 797 | } | ||
| 798 | 792 | ||
| 799 | std::size_t size = 0; | 793 | void RasterizerOpenGL::SetupConstBuffer(const Tegra::Engines::ConstBufferInfo& buffer, |
| 794 | const GLShader::ConstBufferEntry& entry) { | ||
| 795 | if (!buffer.enabled) { | ||
| 796 | // Set values to zero to unbind buffers | ||
| 797 | bind_ubo_pushbuffer.Push(0, 0, 0); | ||
| 798 | return; | ||
| 799 | } | ||
| 800 | 800 | ||
| 801 | if (used_buffer.IsIndirect()) { | 801 | std::size_t size; |
| 802 | // Buffer is accessed indirectly, so upload the entire thing | 802 | if (entry.IsIndirect()) { |
| 803 | size = buffer.size; | 803 | // Buffer is accessed indirectly, so upload the entire thing |
| 804 | size = buffer.size; | ||
| 804 | 805 | ||
| 805 | if (size > MaxConstbufferSize) { | 806 | if (size > MaxConstbufferSize) { |
| 806 | LOG_WARNING(Render_OpenGL, "Indirect constbuffer size {} exceeds maximum {}", size, | 807 | LOG_WARNING(Render_OpenGL, "Indirect constbuffer size {} exceeds maximum {}", size, |
| 807 | MaxConstbufferSize); | 808 | MaxConstbufferSize); |
| 808 | size = MaxConstbufferSize; | 809 | size = MaxConstbufferSize; |
| 809 | } | ||
| 810 | } else { | ||
| 811 | // Buffer is accessed directly, upload just what we use | ||
| 812 | size = used_buffer.GetSize(); | ||
| 813 | } | 810 | } |
| 811 | } else { | ||
| 812 | // Buffer is accessed directly, upload just what we use | ||
| 813 | size = entry.GetSize(); | ||
| 814 | } | ||
| 814 | 815 | ||
| 815 | // Align the actual size so it ends up being a multiple of vec4 to meet the OpenGL std140 | 816 | // Align the actual size so it ends up being a multiple of vec4 to meet the OpenGL std140 |
| 816 | // UBO alignment requirements. | 817 | // UBO alignment requirements. |
| 817 | size = Common::AlignUp(size, sizeof(GLvec4)); | 818 | size = Common::AlignUp(size, sizeof(GLvec4)); |
| 818 | ASSERT_MSG(size <= MaxConstbufferSize, "Constbuffer too big"); | 819 | ASSERT_MSG(size <= MaxConstbufferSize, "Constant buffer is too big"); |
| 819 | |||
| 820 | const GLintptr const_buffer_offset = | ||
| 821 | buffer_cache.UploadMemory(buffer.address, size, device.GetUniformBufferAlignment()); | ||
| 822 | 820 | ||
| 823 | bind_ubo_pushbuffer.Push(buffer_cache.GetHandle(), const_buffer_offset, size); | 821 | const std::size_t alignment = device.GetUniformBufferAlignment(); |
| 824 | } | 822 | const GLintptr offset = buffer_cache.UploadMemory(buffer.address, size, alignment); |
| 823 | bind_ubo_pushbuffer.Push(buffer_cache.GetHandle(), offset, size); | ||
| 825 | } | 824 | } |
| 826 | 825 | ||
| 827 | void RasterizerOpenGL::SetupGlobalRegions(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, | 826 | void RasterizerOpenGL::SetupGlobalRegions(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, |
| 828 | const Shader& shader, GLenum primitive_mode, | 827 | const Shader& shader) { |
| 829 | BaseBindings base_bindings) { | ||
| 830 | const auto& entries = shader->GetShaderEntries().global_memory_entries; | 828 | const auto& entries = shader->GetShaderEntries().global_memory_entries; |
| 831 | for (std::size_t bindpoint = 0; bindpoint < entries.size(); ++bindpoint) { | 829 | for (std::size_t bindpoint = 0; bindpoint < entries.size(); ++bindpoint) { |
| 832 | const auto& entry{entries[bindpoint]}; | 830 | const auto& entry{entries[bindpoint]}; |
| @@ -840,7 +838,7 @@ void RasterizerOpenGL::SetupGlobalRegions(Tegra::Engines::Maxwell3D::Regs::Shade | |||
| 840 | } | 838 | } |
| 841 | 839 | ||
| 842 | void RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, const Shader& shader, | 840 | void RasterizerOpenGL::SetupTextures(Maxwell::ShaderStage stage, const Shader& shader, |
| 843 | GLuint program_handle, BaseBindings base_bindings) { | 841 | BaseBindings base_bindings) { |
| 844 | MICROPROFILE_SCOPE(OpenGL_Texture); | 842 | MICROPROFILE_SCOPE(OpenGL_Texture); |
| 845 | const auto& gpu = system.GPU(); | 843 | const auto& gpu = system.GPU(); |
| 846 | const auto& maxwell3d = gpu.Maxwell3D(); | 844 | const auto& maxwell3d = gpu.Maxwell3D(); |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 2817f65c9..f7671ff5d 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -17,6 +17,7 @@ | |||
| 17 | #include <glad/glad.h> | 17 | #include <glad/glad.h> |
| 18 | 18 | ||
| 19 | #include "common/common_types.h" | 19 | #include "common/common_types.h" |
| 20 | #include "video_core/engines/const_buffer_info.h" | ||
| 20 | #include "video_core/engines/maxwell_3d.h" | 21 | #include "video_core/engines/maxwell_3d.h" |
| 21 | #include "video_core/rasterizer_cache.h" | 22 | #include "video_core/rasterizer_cache.h" |
| 22 | #include "video_core/rasterizer_interface.h" | 23 | #include "video_core/rasterizer_interface.h" |
| @@ -27,6 +28,7 @@ | |||
| 27 | #include "video_core/renderer_opengl/gl_resource_manager.h" | 28 | #include "video_core/renderer_opengl/gl_resource_manager.h" |
| 28 | #include "video_core/renderer_opengl/gl_sampler_cache.h" | 29 | #include "video_core/renderer_opengl/gl_sampler_cache.h" |
| 29 | #include "video_core/renderer_opengl/gl_shader_cache.h" | 30 | #include "video_core/renderer_opengl/gl_shader_cache.h" |
| 31 | #include "video_core/renderer_opengl/gl_shader_decompiler.h" | ||
| 30 | #include "video_core/renderer_opengl/gl_shader_manager.h" | 32 | #include "video_core/renderer_opengl/gl_shader_manager.h" |
| 31 | #include "video_core/renderer_opengl/gl_state.h" | 33 | #include "video_core/renderer_opengl/gl_state.h" |
| 32 | #include "video_core/renderer_opengl/utils.h" | 34 | #include "video_core/renderer_opengl/utils.h" |
| @@ -105,17 +107,20 @@ private: | |||
| 105 | bool preserve_contents = true, std::optional<std::size_t> single_color_target = {}); | 107 | bool preserve_contents = true, std::optional<std::size_t> single_color_target = {}); |
| 106 | 108 | ||
| 107 | /// Configures the current constbuffers to use for the draw command. | 109 | /// Configures the current constbuffers to use for the draw command. |
| 108 | void SetupConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, const Shader& shader, | 110 | void SetupDrawConstBuffers(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, |
| 109 | GLuint program_handle, BaseBindings base_bindings); | 111 | const Shader& shader); |
| 112 | |||
| 113 | /// Configures a constant buffer. | ||
| 114 | void SetupConstBuffer(const Tegra::Engines::ConstBufferInfo& buffer, | ||
| 115 | const GLShader::ConstBufferEntry& entry); | ||
| 110 | 116 | ||
| 111 | /// Configures the current global memory entries to use for the draw command. | 117 | /// Configures the current global memory entries to use for the draw command. |
| 112 | void SetupGlobalRegions(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, | 118 | void SetupGlobalRegions(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, |
| 113 | const Shader& shader, GLenum primitive_mode, | 119 | const Shader& shader); |
| 114 | BaseBindings base_bindings); | ||
| 115 | 120 | ||
| 116 | /// Configures the current textures to use for the draw command. | 121 | /// Configures the current textures to use for the draw command. |
| 117 | void SetupTextures(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, const Shader& shader, | 122 | void SetupTextures(Tegra::Engines::Maxwell3D::Regs::ShaderStage stage, const Shader& shader, |
| 118 | GLuint program_handle, BaseBindings base_bindings); | 123 | BaseBindings base_bindings); |
| 119 | 124 | ||
| 120 | /// Syncs the viewport and depth range to match the guest state | 125 | /// Syncs the viewport and depth range to match the guest state |
| 121 | void SyncViewport(OpenGLState& current_state); | 126 | void SyncViewport(OpenGLState& current_state); |