diff options
| author | 2014-12-28 00:56:32 -0200 | |
|---|---|---|
| committer | 2014-12-29 02:08:09 -0200 | |
| commit | a320d1a5b4b7ce3b90372697fbe50242b78d082e (patch) | |
| tree | 727b752af17e41adc52006dfe6d8aa33b6894ecf /src/video_core/clipper.cpp | |
| parent | Vertex Shader: Zero OutputVertex to avoid denormals (diff) | |
| download | yuzu-a320d1a5b4b7ce3b90372697fbe50242b78d082e.tar.gz yuzu-a320d1a5b4b7ce3b90372697fbe50242b78d082e.tar.xz yuzu-a320d1a5b4b7ce3b90372697fbe50242b78d082e.zip | |
Clipper: Avoid dynamic allocations
The triangle clipper was allocating its temporary input, output and work
buffers using a std::vector. Since this is a hot path, it's desirable to
use stack allocation instead.
Diffstat (limited to 'src/video_core/clipper.cpp')
| -rw-r--r-- | src/video_core/clipper.cpp | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/src/video_core/clipper.cpp b/src/video_core/clipper.cpp index 0bcd0b895..e89b7a0c0 100644 --- a/src/video_core/clipper.cpp +++ b/src/video_core/clipper.cpp | |||
| @@ -2,7 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <vector> | 5 | #include <boost/container/static_vector.hpp> |
| 6 | 6 | ||
| 7 | #include "clipper.h" | 7 | #include "clipper.h" |
| 8 | #include "pica.h" | 8 | #include "pica.h" |
| @@ -98,18 +98,15 @@ static void InitScreenCoordinates(OutputVertex& vtx) | |||
| 98 | } | 98 | } |
| 99 | 99 | ||
| 100 | void ProcessTriangle(OutputVertex &v0, OutputVertex &v1, OutputVertex &v2) { | 100 | void ProcessTriangle(OutputVertex &v0, OutputVertex &v1, OutputVertex &v2) { |
| 101 | using boost::container::static_vector; | ||
| 101 | 102 | ||
| 102 | // TODO (neobrain): | 103 | // TODO (neobrain): |
| 103 | // The list of output vertices has some fixed maximum size, | 104 | // The list of output vertices has some fixed maximum size, |
| 104 | // however I haven't taken the time to figure out what it is exactly. | 105 | // however I haven't taken the time to figure out what it is exactly. |
| 105 | // For now, we hence just assume a maximal size of 1000 vertices. | 106 | // For now, we hence just assume a maximal size of 256 vertices. |
| 106 | const size_t max_vertices = 1000; | 107 | static const size_t MAX_VERTICES = 256; |
| 107 | std::vector<OutputVertex> buffer_vertices; | 108 | static_vector<OutputVertex, MAX_VERTICES> buffer_vertices; |
| 108 | std::vector<OutputVertex*> output_list{ &v0, &v1, &v2 }; | 109 | static_vector<OutputVertex*, MAX_VERTICES> output_list = { &v0, &v1, &v2 }; |
| 109 | |||
| 110 | // Make sure to reserve space for all vertices. | ||
| 111 | // Without this, buffer reallocation would invalidate references. | ||
| 112 | buffer_vertices.reserve(max_vertices); | ||
| 113 | 110 | ||
| 114 | // Simple implementation of the Sutherland-Hodgman clipping algorithm. | 111 | // Simple implementation of the Sutherland-Hodgman clipping algorithm. |
| 115 | // TODO: Make this less inefficient (currently lots of useless buffering overhead happens here) | 112 | // TODO: Make this less inefficient (currently lots of useless buffering overhead happens here) |
| @@ -120,7 +117,7 @@ void ProcessTriangle(OutputVertex &v0, OutputVertex &v1, OutputVertex &v2) { | |||
| 120 | ClippingEdge(ClippingEdge::POS_Z, float24::FromFloat32(+1.0)), | 117 | ClippingEdge(ClippingEdge::POS_Z, float24::FromFloat32(+1.0)), |
| 121 | ClippingEdge(ClippingEdge::NEG_Z, float24::FromFloat32(-1.0)) }) { | 118 | ClippingEdge(ClippingEdge::NEG_Z, float24::FromFloat32(-1.0)) }) { |
| 122 | 119 | ||
| 123 | const std::vector<OutputVertex*> input_list = output_list; | 120 | const static_vector<OutputVertex*, MAX_VERTICES> input_list = output_list; |
| 124 | output_list.clear(); | 121 | output_list.clear(); |
| 125 | 122 | ||
| 126 | const OutputVertex* reference_vertex = input_list.back(); | 123 | const OutputVertex* reference_vertex = input_list.back(); |