diff options
| author | 2019-09-18 07:51:05 -0400 | |
|---|---|---|
| committer | 2019-09-19 11:41:31 -0400 | |
| commit | c17655ce7465815bb69adf22c2d12f02a93d7d5c (patch) | |
| tree | 07749426e3fd8e5fdd874e4d13c8df74428bca2f | |
| parent | VideoCore: Corrections to the MME Inliner and removal of hacky instance manag... (diff) | |
| download | yuzu-c17655ce7465815bb69adf22c2d12f02a93d7d5c.tar.gz yuzu-c17655ce7465815bb69adf22c2d12f02a93d7d5c.tar.xz yuzu-c17655ce7465815bb69adf22c2d12f02a93d7d5c.zip | |
Rasterizer: Refactor draw calls, remove deadcode and clean up.
| -rw-r--r-- | src/video_core/rasterizer_interface.h | 2 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 169 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 3 |
3 files changed, 68 insertions, 106 deletions
diff --git a/src/video_core/rasterizer_interface.h b/src/video_core/rasterizer_interface.h index a37b84b8c..fe0d82255 100644 --- a/src/video_core/rasterizer_interface.h +++ b/src/video_core/rasterizer_interface.h | |||
| @@ -31,7 +31,7 @@ public: | |||
| 31 | /// Draw the current batch of vertex arrays | 31 | /// Draw the current batch of vertex arrays |
| 32 | virtual void DrawArrays() = 0; | 32 | virtual void DrawArrays() = 0; |
| 33 | 33 | ||
| 34 | /// Draw the current batch of vertex arrays | 34 | /// Draw the current batch of multiple instasnces of vertex arrays |
| 35 | virtual void DrawMultiArrays() = 0; | 35 | virtual void DrawMultiArrays() = 0; |
| 36 | 36 | ||
| 37 | /// Clear the current framebuffer | 37 | /// Clear the current framebuffer |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index f71a22738..9ca832863 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -49,40 +49,6 @@ MICROPROFILE_DEFINE(OpenGL_Blits, "OpenGL", "Blits", MP_RGB(128, 128, 192)); | |||
| 49 | MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100)); | 49 | MICROPROFILE_DEFINE(OpenGL_CacheManagement, "OpenGL", "Cache Mgmt", MP_RGB(100, 255, 100)); |
| 50 | MICROPROFILE_DEFINE(OpenGL_PrimitiveAssembly, "OpenGL", "Prim Asmbl", MP_RGB(255, 100, 100)); | 50 | MICROPROFILE_DEFINE(OpenGL_PrimitiveAssembly, "OpenGL", "Prim Asmbl", MP_RGB(255, 100, 100)); |
| 51 | 51 | ||
| 52 | struct DrawParameters { | ||
| 53 | GLenum primitive_mode; | ||
| 54 | GLsizei count; | ||
| 55 | GLint current_instance; | ||
| 56 | bool use_indexed; | ||
| 57 | |||
| 58 | GLint vertex_first; | ||
| 59 | |||
| 60 | GLenum index_format; | ||
| 61 | GLint base_vertex; | ||
| 62 | GLintptr index_buffer_offset; | ||
| 63 | |||
| 64 | void DispatchDraw() const { | ||
| 65 | if (use_indexed) { | ||
| 66 | const auto index_buffer_ptr = reinterpret_cast<const void*>(index_buffer_offset); | ||
| 67 | if (current_instance > 0) { | ||
| 68 | glDrawElementsInstancedBaseVertexBaseInstance(primitive_mode, count, index_format, | ||
| 69 | index_buffer_ptr, 1, base_vertex, | ||
| 70 | current_instance); | ||
| 71 | } else { | ||
| 72 | glDrawElementsBaseVertex(primitive_mode, count, index_format, index_buffer_ptr, | ||
| 73 | base_vertex); | ||
| 74 | } | ||
| 75 | } else { | ||
| 76 | if (current_instance > 0) { | ||
| 77 | glDrawArraysInstancedBaseInstance(primitive_mode, vertex_first, count, 1, | ||
| 78 | current_instance); | ||
| 79 | } else { | ||
| 80 | glDrawArrays(primitive_mode, vertex_first, count); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | } | ||
| 84 | }; | ||
| 85 | |||
| 86 | static std::size_t GetConstBufferSize(const Tegra::Engines::ConstBufferInfo& buffer, | 52 | static std::size_t GetConstBufferSize(const Tegra::Engines::ConstBufferInfo& buffer, |
| 87 | const GLShader::ConstBufferEntry& entry) { | 53 | const GLShader::ConstBufferEntry& entry) { |
| 88 | if (!entry.IsIndirect()) { | 54 | if (!entry.IsIndirect()) { |
| @@ -270,29 +236,6 @@ GLintptr RasterizerOpenGL::SetupIndexBuffer() { | |||
| 270 | return offset; | 236 | return offset; |
| 271 | } | 237 | } |
| 272 | 238 | ||
| 273 | DrawParameters RasterizerOpenGL::SetupDraw(GLintptr index_buffer_offset) { | ||
| 274 | const auto& gpu = system.GPU().Maxwell3D(); | ||
| 275 | const auto& regs = gpu.regs; | ||
| 276 | const bool is_indexed = accelerate_draw == AccelDraw::Indexed; | ||
| 277 | |||
| 278 | DrawParameters params{}; | ||
| 279 | params.current_instance = gpu.state.current_instance; | ||
| 280 | |||
| 281 | params.use_indexed = is_indexed; | ||
| 282 | params.primitive_mode = MaxwellToGL::PrimitiveTopology(regs.draw.topology); | ||
| 283 | |||
| 284 | if (is_indexed) { | ||
| 285 | params.index_format = MaxwellToGL::IndexFormat(regs.index_array.format); | ||
| 286 | params.count = regs.index_array.count; | ||
| 287 | params.index_buffer_offset = index_buffer_offset; | ||
| 288 | params.base_vertex = static_cast<GLint>(regs.vb_element_base); | ||
| 289 | } else { | ||
| 290 | params.count = regs.vertex_buffer.count; | ||
| 291 | params.vertex_first = regs.vertex_buffer.first; | ||
| 292 | } | ||
| 293 | return params; | ||
| 294 | } | ||
| 295 | |||
| 296 | void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) { | 239 | void RasterizerOpenGL::SetupShaders(GLenum primitive_mode) { |
| 297 | MICROPROFILE_SCOPE(OpenGL_Shader); | 240 | MICROPROFILE_SCOPE(OpenGL_Shader); |
| 298 | auto& gpu = system.GPU().Maxwell3D(); | 241 | auto& gpu = system.GPU().Maxwell3D(); |
| @@ -784,36 +727,65 @@ void RasterizerOpenGL::DrawPrelude() { | |||
| 784 | } | 727 | } |
| 785 | } | 728 | } |
| 786 | 729 | ||
| 730 | struct DrawParams { | ||
| 731 | bool is_indexed; | ||
| 732 | bool is_instanced; | ||
| 733 | GLenum primitive_mode; | ||
| 734 | GLint count; | ||
| 735 | GLint base_vertex; | ||
| 736 | |||
| 737 | // Indexed settings | ||
| 738 | GLenum index_format; | ||
| 739 | GLintptr index_buffer_offset; | ||
| 740 | |||
| 741 | // Instanced setting | ||
| 742 | GLint num_instances; | ||
| 743 | GLint base_instance; | ||
| 744 | |||
| 745 | void DispatchDraw() { | ||
| 746 | if (is_indexed) { | ||
| 747 | const auto index_buffer_ptr = reinterpret_cast<const void*>(index_buffer_offset); | ||
| 748 | if (is_instanced) { | ||
| 749 | glDrawElementsInstancedBaseVertexBaseInstance(primitive_mode, count, index_format, | ||
| 750 | index_buffer_ptr, num_instances, | ||
| 751 | base_vertex, base_instance); | ||
| 752 | } else { | ||
| 753 | glDrawElementsBaseVertex(primitive_mode, count, index_format, index_buffer_ptr, | ||
| 754 | base_vertex); | ||
| 755 | } | ||
| 756 | } else { | ||
| 757 | if (is_instanced) { | ||
| 758 | glDrawArraysInstancedBaseInstance(primitive_mode, base_vertex, count, num_instances, | ||
| 759 | base_instance); | ||
| 760 | } else { | ||
| 761 | glDrawArrays(primitive_mode, base_vertex, count); | ||
| 762 | } | ||
| 763 | } | ||
| 764 | } | ||
| 765 | }; | ||
| 766 | |||
| 787 | void RasterizerOpenGL::DrawArrays() { | 767 | void RasterizerOpenGL::DrawArrays() { |
| 788 | DrawPrelude(); | 768 | DrawPrelude(); |
| 789 | 769 | ||
| 790 | auto& maxwell3d = system.GPU().Maxwell3D(); | 770 | auto& maxwell3d = system.GPU().Maxwell3D(); |
| 791 | const auto& regs = maxwell3d.regs; | 771 | const auto& regs = maxwell3d.regs; |
| 792 | const auto current_instance = maxwell3d.state.current_instance; | 772 | const auto current_instance = maxwell3d.state.current_instance; |
| 793 | const auto primitive_mode = MaxwellToGL::PrimitiveTopology(regs.draw.topology); | 773 | DrawParams draw_call; |
| 794 | if (accelerate_draw == AccelDraw::Indexed) { | 774 | draw_call.is_indexed = accelerate_draw == AccelDraw::Indexed; |
| 795 | const auto index_format = MaxwellToGL::IndexFormat(regs.index_array.format); | 775 | draw_call.num_instances = static_cast<GLint>(1); |
| 796 | const auto count = regs.index_array.count; | 776 | draw_call.base_instance = static_cast<GLint>(current_instance); |
| 797 | const auto base_vertex = static_cast<GLint>(regs.vb_element_base); | 777 | draw_call.is_instanced = current_instance > 0; |
| 798 | const auto index_buffer_ptr = reinterpret_cast<const void*>(index_buffer_offset); | 778 | draw_call.primitive_mode = MaxwellToGL::PrimitiveTopology(regs.draw.topology); |
| 799 | if (current_instance > 0) { | 779 | if (draw_call.is_indexed) { |
| 800 | glDrawElementsInstancedBaseVertexBaseInstance(primitive_mode, count, index_format, | 780 | draw_call.count = static_cast<GLint>(regs.index_array.count); |
| 801 | index_buffer_ptr, 1, base_vertex, | 781 | draw_call.base_vertex = static_cast<GLint>(regs.vb_element_base); |
| 802 | current_instance); | 782 | draw_call.index_format = MaxwellToGL::IndexFormat(regs.index_array.format); |
| 803 | } else { | 783 | draw_call.index_buffer_offset = index_buffer_offset; |
| 804 | glDrawElementsBaseVertex(primitive_mode, count, index_format, index_buffer_ptr, | ||
| 805 | base_vertex); | ||
| 806 | } | ||
| 807 | } else { | 784 | } else { |
| 808 | const auto count = regs.vertex_buffer.count; | 785 | draw_call.count = static_cast<GLint>(regs.vertex_buffer.count); |
| 809 | const auto vertex_first = regs.vertex_buffer.first; | 786 | draw_call.base_vertex = static_cast<GLint>(regs.vertex_buffer.first); |
| 810 | if (current_instance > 0) { | ||
| 811 | glDrawArraysInstancedBaseInstance(primitive_mode, vertex_first, count, 1, | ||
| 812 | current_instance); | ||
| 813 | } else { | ||
| 814 | glDrawArrays(primitive_mode, vertex_first, count); | ||
| 815 | } | ||
| 816 | } | 787 | } |
| 788 | draw_call.DispatchDraw(); | ||
| 817 | 789 | ||
| 818 | accelerate_draw = AccelDraw::Disabled; | 790 | accelerate_draw = AccelDraw::Disabled; |
| 819 | maxwell3d.dirty.memory_general = false; | 791 | maxwell3d.dirty.memory_general = false; |
| @@ -825,32 +797,23 @@ void RasterizerOpenGL::DrawMultiArrays() { | |||
| 825 | auto& maxwell3d = system.GPU().Maxwell3D(); | 797 | auto& maxwell3d = system.GPU().Maxwell3D(); |
| 826 | const auto& regs = maxwell3d.regs; | 798 | const auto& regs = maxwell3d.regs; |
| 827 | const auto& draw_setup = maxwell3d.mme_draw; | 799 | const auto& draw_setup = maxwell3d.mme_draw; |
| 828 | const auto num_instances = draw_setup.instance_count; | 800 | DrawParams draw_call; |
| 829 | const auto base_instance = static_cast<GLint>(regs.vb_base_instance); | 801 | draw_call.is_indexed = |
| 830 | const auto primitive_mode = MaxwellToGL::PrimitiveTopology(regs.draw.topology); | 802 | draw_setup.current_mode == Tegra::Engines::Maxwell3D::MMMEDrawMode::Indexed; |
| 831 | if (draw_setup.current_mode == Tegra::Engines::Maxwell3D::MMMEDrawMode::Indexed) { | 803 | draw_call.num_instances = static_cast<GLint>(draw_setup.instance_count); |
| 832 | const auto index_format = MaxwellToGL::IndexFormat(regs.index_array.format); | 804 | draw_call.base_instance = static_cast<GLint>(regs.vb_base_instance); |
| 833 | const auto count = regs.index_array.count; | 805 | draw_call.is_instanced = draw_setup.instance_count > 1; |
| 834 | const auto base_vertex = static_cast<GLint>(regs.vb_element_base); | 806 | draw_call.primitive_mode = MaxwellToGL::PrimitiveTopology(regs.draw.topology); |
| 835 | const auto index_buffer_ptr = reinterpret_cast<const void*>(index_buffer_offset); | 807 | if (draw_call.is_indexed) { |
| 836 | if (num_instances > 1) { | 808 | draw_call.count = static_cast<GLint>(regs.index_array.count); |
| 837 | glDrawElementsInstancedBaseVertexBaseInstance(primitive_mode, count, index_format, | 809 | draw_call.base_vertex = static_cast<GLint>(regs.vb_element_base); |
| 838 | index_buffer_ptr, num_instances, | 810 | draw_call.index_format = MaxwellToGL::IndexFormat(regs.index_array.format); |
| 839 | base_vertex, base_instance); | 811 | draw_call.index_buffer_offset = index_buffer_offset; |
| 840 | } else { | ||
| 841 | glDrawElementsBaseVertex(primitive_mode, count, index_format, index_buffer_ptr, | ||
| 842 | base_vertex); | ||
| 843 | } | ||
| 844 | } else { | 812 | } else { |
| 845 | const auto count = regs.vertex_buffer.count; | 813 | draw_call.count = static_cast<GLint>(regs.vertex_buffer.count); |
| 846 | const auto vertex_first = regs.vertex_buffer.first; | 814 | draw_call.base_vertex = static_cast<GLint>(regs.vertex_buffer.first); |
| 847 | if (num_instances > 1) { | ||
| 848 | glDrawArraysInstancedBaseInstance(primitive_mode, vertex_first, count, num_instances, | ||
| 849 | base_instance); | ||
| 850 | } else { | ||
| 851 | glDrawArrays(primitive_mode, vertex_first, count); | ||
| 852 | } | ||
| 853 | } | 815 | } |
| 816 | draw_call.DispatchDraw(); | ||
| 854 | 817 | ||
| 855 | accelerate_draw = AccelDraw::Disabled; | 818 | accelerate_draw = AccelDraw::Disabled; |
| 856 | maxwell3d.dirty.memory_general = false; | 819 | maxwell3d.dirty.memory_general = false; |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 63a914ff9..b4e21b9de 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -138,6 +138,7 @@ private: | |||
| 138 | void SetupGlobalMemory(const GLShader::GlobalMemoryEntry& entry, GPUVAddr gpu_addr, | 138 | void SetupGlobalMemory(const GLShader::GlobalMemoryEntry& entry, GPUVAddr gpu_addr, |
| 139 | std::size_t size); | 139 | std::size_t size); |
| 140 | 140 | ||
| 141 | /// Syncs all the state, shaders, render targets and textures setting before a draw call. | ||
| 141 | void DrawPrelude(); | 142 | void DrawPrelude(); |
| 142 | 143 | ||
| 143 | /// Configures the current textures to use for the draw command. Returns shaders texture buffer | 144 | /// Configures the current textures to use for the draw command. Returns shaders texture buffer |
| @@ -254,8 +255,6 @@ private: | |||
| 254 | 255 | ||
| 255 | GLintptr SetupIndexBuffer(); | 256 | GLintptr SetupIndexBuffer(); |
| 256 | 257 | ||
| 257 | DrawParameters SetupDraw(GLintptr index_buffer_offset); | ||
| 258 | |||
| 259 | GLintptr index_buffer_offset; | 258 | GLintptr index_buffer_offset; |
| 260 | 259 | ||
| 261 | void SetupShaders(GLenum primitive_mode); | 260 | void SetupShaders(GLenum primitive_mode); |