diff options
| author | 2019-07-05 23:11:58 -0300 | |
|---|---|---|
| committer | 2019-07-06 00:37:55 -0300 | |
| commit | 7ecf64257aef13dcd86b01ae0c66389dc78f70bc (patch) | |
| tree | 4de7ac1f8b5ec89e52d9cd1c5be886d2f1236b52 | |
| parent | gl_rasterizer: Fix vertex and index data invalidations (diff) | |
| download | yuzu-7ecf64257aef13dcd86b01ae0c66389dc78f70bc.tar.gz yuzu-7ecf64257aef13dcd86b01ae0c66389dc78f70bc.tar.xz yuzu-7ecf64257aef13dcd86b01ae0c66389dc78f70bc.zip | |
gl_rasterizer: Minor style changes
| -rw-r--r-- | src/video_core/engines/maxwell_3d.h | 1 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 46 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 5 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_decompiler.cpp | 2 |
4 files changed, 22 insertions, 32 deletions
diff --git a/src/video_core/engines/maxwell_3d.h b/src/video_core/engines/maxwell_3d.h index 13e314944..8d15c8a48 100644 --- a/src/video_core/engines/maxwell_3d.h +++ b/src/video_core/engines/maxwell_3d.h | |||
| @@ -67,6 +67,7 @@ public: | |||
| 67 | static constexpr std::size_t MaxShaderStage = 5; | 67 | static constexpr std::size_t MaxShaderStage = 5; |
| 68 | // Maximum number of const buffers per shader stage. | 68 | // Maximum number of const buffers per shader stage. |
| 69 | static constexpr std::size_t MaxConstBuffers = 18; | 69 | static constexpr std::size_t MaxConstBuffers = 18; |
| 70 | static constexpr std::size_t MaxConstBufferSize = 0x10000; | ||
| 70 | 71 | ||
| 71 | enum class QueryMode : u32 { | 72 | enum class QueryMode : u32 { |
| 72 | Write = 0, | 73 | Write = 0, |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index f3527d65b..b8430f16d 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -81,6 +81,21 @@ struct DrawParameters { | |||
| 81 | } | 81 | } |
| 82 | }; | 82 | }; |
| 83 | 83 | ||
| 84 | static std::size_t GetConstBufferSize(const Tegra::Engines::ConstBufferInfo& buffer, | ||
| 85 | const GLShader::ConstBufferEntry& entry) { | ||
| 86 | if (!entry.IsIndirect()) { | ||
| 87 | return entry.GetSize(); | ||
| 88 | } | ||
| 89 | |||
| 90 | if (buffer.size > Maxwell::MaxConstBufferSize) { | ||
| 91 | LOG_WARNING(Render_OpenGL, "Indirect constbuffer size {} exceeds maximum {}", buffer.size, | ||
| 92 | Maxwell::MaxConstBufferSize); | ||
| 93 | return Maxwell::MaxConstBufferSize; | ||
| 94 | } | ||
| 95 | |||
| 96 | return buffer.size; | ||
| 97 | } | ||
| 98 | |||
| 84 | RasterizerOpenGL::RasterizerOpenGL(Core::System& system, Core::Frontend::EmuWindow& emu_window, | 99 | RasterizerOpenGL::RasterizerOpenGL(Core::System& system, Core::Frontend::EmuWindow& emu_window, |
| 85 | ScreenInfo& info) | 100 | ScreenInfo& info) |
| 86 | : texture_cache{system, *this, device}, shader_cache{*this, system, emu_window, device}, | 101 | : texture_cache{system, *this, device}, shader_cache{*this, system, emu_window, device}, |
| @@ -634,8 +649,8 @@ void RasterizerOpenGL::DrawArrays() { | |||
| 634 | Maxwell::MaxShaderStage; | 649 | Maxwell::MaxShaderStage; |
| 635 | 650 | ||
| 636 | // Add space for at least 18 constant buffers | 651 | // Add space for at least 18 constant buffers |
| 637 | buffer_size += | 652 | buffer_size += Maxwell::MaxConstBuffers * |
| 638 | Maxwell::MaxConstBuffers * (MaxConstbufferSize + device.GetUniformBufferAlignment()); | 653 | (Maxwell::MaxConstBufferSize + device.GetUniformBufferAlignment()); |
| 639 | 654 | ||
| 640 | // Prepare the vertex array. | 655 | // Prepare the vertex array. |
| 641 | buffer_cache.Map(buffer_size); | 656 | buffer_cache.Map(buffer_size); |
| @@ -762,11 +777,9 @@ void RasterizerOpenGL::SetupDrawConstBuffers(Tegra::Engines::Maxwell3D::Regs::Sh | |||
| 762 | MICROPROFILE_SCOPE(OpenGL_UBO); | 777 | MICROPROFILE_SCOPE(OpenGL_UBO); |
| 763 | const auto stage_index = static_cast<std::size_t>(stage); | 778 | const auto stage_index = static_cast<std::size_t>(stage); |
| 764 | const auto& shader_stage = system.GPU().Maxwell3D().state.shader_stages[stage_index]; | 779 | const auto& shader_stage = system.GPU().Maxwell3D().state.shader_stages[stage_index]; |
| 765 | const auto& entries = shader->GetShaderEntries().const_buffers; | ||
| 766 | 780 | ||
| 767 | // Upload only the enabled buffers from the 16 constbuffers of each shader stage | 781 | // Upload only the enabled buffers from the 16 constbuffers of each shader stage |
| 768 | for (u32 bindpoint = 0; bindpoint < entries.size(); ++bindpoint) { | 782 | for (const auto& entry : shader->GetShaderEntries().const_buffers) { |
| 769 | const auto& entry = entries[bindpoint]; | ||
| 770 | SetupConstBuffer(shader_stage.const_buffers[entry.GetIndex()], entry); | 783 | SetupConstBuffer(shader_stage.const_buffers[entry.GetIndex()], entry); |
| 771 | } | 784 | } |
| 772 | } | 785 | } |
| @@ -779,25 +792,9 @@ void RasterizerOpenGL::SetupConstBuffer(const Tegra::Engines::ConstBufferInfo& b | |||
| 779 | return; | 792 | return; |
| 780 | } | 793 | } |
| 781 | 794 | ||
| 782 | std::size_t size; | ||
| 783 | if (entry.IsIndirect()) { | ||
| 784 | // Buffer is accessed indirectly, so upload the entire thing | ||
| 785 | size = buffer.size; | ||
| 786 | |||
| 787 | if (size > MaxConstbufferSize) { | ||
| 788 | LOG_WARNING(Render_OpenGL, "Indirect constbuffer size {} exceeds maximum {}", size, | ||
| 789 | MaxConstbufferSize); | ||
| 790 | size = MaxConstbufferSize; | ||
| 791 | } | ||
| 792 | } else { | ||
| 793 | // Buffer is accessed directly, upload just what we use | ||
| 794 | size = entry.GetSize(); | ||
| 795 | } | ||
| 796 | |||
| 797 | // Align the actual size so it ends up being a multiple of vec4 to meet the OpenGL std140 | 795 | // Align the actual size so it ends up being a multiple of vec4 to meet the OpenGL std140 |
| 798 | // UBO alignment requirements. | 796 | // UBO alignment requirements. |
| 799 | size = Common::AlignUp(size, sizeof(GLvec4)); | 797 | const std::size_t size = Common::AlignUp(GetConstBufferSize(buffer, entry), sizeof(GLvec4)); |
| 800 | ASSERT_MSG(size <= MaxConstbufferSize, "Constant buffer is too big"); | ||
| 801 | 798 | ||
| 802 | const auto alignment = device.GetUniformBufferAlignment(); | 799 | const auto alignment = device.GetUniformBufferAlignment(); |
| 803 | const auto [cbuf, offset] = buffer_cache.UploadMemory(buffer.address, size, alignment); | 800 | const auto [cbuf, offset] = buffer_cache.UploadMemory(buffer.address, size, alignment); |
| @@ -811,10 +808,7 @@ void RasterizerOpenGL::SetupGlobalRegions(Tegra::Engines::Maxwell3D::Regs::Shade | |||
| 811 | const auto cbufs{gpu.Maxwell3D().state.shader_stages[static_cast<std::size_t>(stage)]}; | 808 | const auto cbufs{gpu.Maxwell3D().state.shader_stages[static_cast<std::size_t>(stage)]}; |
| 812 | const auto alignment{device.GetShaderStorageBufferAlignment()}; | 809 | const auto alignment{device.GetShaderStorageBufferAlignment()}; |
| 813 | 810 | ||
| 814 | const auto& entries = shader->GetShaderEntries().global_memory_entries; | 811 | for (const auto& entry : shader->GetShaderEntries().global_memory_entries) { |
| 815 | for (std::size_t bindpoint = 0; bindpoint < entries.size(); ++bindpoint) { | ||
| 816 | const auto& entry{entries[bindpoint]}; | ||
| 817 | |||
| 818 | const auto addr{cbufs.const_buffers[entry.GetCbufIndex()].address + entry.GetCbufOffset()}; | 812 | const auto addr{cbufs.const_buffers[entry.GetCbufIndex()].address + entry.GetCbufOffset()}; |
| 819 | const auto actual_addr{memory_manager.Read<u64>(addr)}; | 813 | const auto actual_addr{memory_manager.Read<u64>(addr)}; |
| 820 | const auto size{memory_manager.Read<u32>(addr + 8)}; | 814 | const auto size{memory_manager.Read<u32>(addr + 8)}; |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 1c915fd7f..172cfe8f6 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -73,11 +73,6 @@ public: | |||
| 73 | void LoadDiskResources(const std::atomic_bool& stop_loading, | 73 | void LoadDiskResources(const std::atomic_bool& stop_loading, |
| 74 | const VideoCore::DiskResourceLoadCallback& callback) override; | 74 | const VideoCore::DiskResourceLoadCallback& callback) override; |
| 75 | 75 | ||
| 76 | /// Maximum supported size that a constbuffer can have in bytes. | ||
| 77 | static constexpr std::size_t MaxConstbufferSize = 0x10000; | ||
| 78 | static_assert(MaxConstbufferSize % sizeof(GLvec4) == 0, | ||
| 79 | "The maximum size of a constbuffer must be a multiple of the size of GLvec4"); | ||
| 80 | |||
| 81 | private: | 76 | private: |
| 82 | struct FramebufferConfigState { | 77 | struct FramebufferConfigState { |
| 83 | bool using_color_fb{}; | 78 | bool using_color_fb{}; |
diff --git a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp index 5f2f1510c..592525d11 100644 --- a/src/video_core/renderer_opengl/gl_shader_decompiler.cpp +++ b/src/video_core/renderer_opengl/gl_shader_decompiler.cpp | |||
| @@ -46,7 +46,7 @@ using TextureArgument = std::pair<Type, Node>; | |||
| 46 | using TextureIR = std::variant<TextureAoffi, TextureArgument>; | 46 | using TextureIR = std::variant<TextureAoffi, TextureArgument>; |
| 47 | 47 | ||
| 48 | constexpr u32 MAX_CONSTBUFFER_ELEMENTS = | 48 | constexpr u32 MAX_CONSTBUFFER_ELEMENTS = |
| 49 | static_cast<u32>(RasterizerOpenGL::MaxConstbufferSize) / (4 * sizeof(float)); | 49 | static_cast<u32>(Maxwell::MaxConstBufferSize) / (4 * sizeof(float)); |
| 50 | 50 | ||
| 51 | class ShaderWriter { | 51 | class ShaderWriter { |
| 52 | public: | 52 | public: |