summaryrefslogtreecommitdiff
path: root/src/video_core/texture_cache
diff options
context:
space:
mode:
authorGravatar ReinUsesLisp2020-05-27 17:31:12 -0300
committerGravatar ReinUsesLisp2020-05-27 17:31:14 -0300
commitd2b25575426b9b52049b88d8d6d9ae83c81da312 (patch)
tree05237fb71e694ded6151dfed72bf9fa587cb7b21 /src/video_core/texture_cache
parentMerge pull request #3981 from ReinUsesLisp/bar (diff)
downloadyuzu-d2b25575426b9b52049b88d8d6d9ae83c81da312.tar.gz
yuzu-d2b25575426b9b52049b88d8d6d9ae83c81da312.tar.xz
yuzu-d2b25575426b9b52049b88d8d6d9ae83c81da312.zip
texture_cache: Use small vector for surface vectors
This avoids most heap allocations when collecting surfaces into a vector.
Diffstat (limited to 'src/video_core/texture_cache')
-rw-r--r--src/video_core/texture_cache/texture_cache.h19
1 files changed, 10 insertions, 9 deletions
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index d6efc34b2..d7e42697d 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -14,6 +14,7 @@
14#include <unordered_map> 14#include <unordered_map>
15#include <vector> 15#include <vector>
16 16
17#include <boost/container/small_vector.hpp>
17#include <boost/icl/interval_map.hpp> 18#include <boost/icl/interval_map.hpp>
18#include <boost/range/iterator_range.hpp> 19#include <boost/range/iterator_range.hpp>
19 20
@@ -53,6 +54,7 @@ using RenderTargetConfig = Tegra::Engines::Maxwell3D::Regs::RenderTargetConfig;
53 54
54template <typename TSurface, typename TView> 55template <typename TSurface, typename TView>
55class TextureCache { 56class TextureCache {
57 using VectorSurface = boost::container::small_vector<TSurface, 1>;
56 58
57public: 59public:
58 void InvalidateRegion(VAddr addr, std::size_t size) { 60 void InvalidateRegion(VAddr addr, std::size_t size) {
@@ -498,7 +500,7 @@ private:
498 * @param untopological Indicates to the recycler that the texture has no way 500 * @param untopological Indicates to the recycler that the texture has no way
499 * to match the overlaps due to topological reasons. 501 * to match the overlaps due to topological reasons.
500 **/ 502 **/
501 RecycleStrategy PickStrategy(std::vector<TSurface>& overlaps, const SurfaceParams& params, 503 RecycleStrategy PickStrategy(VectorSurface& overlaps, const SurfaceParams& params,
502 const GPUVAddr gpu_addr, const MatchTopologyResult untopological) { 504 const GPUVAddr gpu_addr, const MatchTopologyResult untopological) {
503 if (Settings::IsGPULevelExtreme()) { 505 if (Settings::IsGPULevelExtreme()) {
504 return RecycleStrategy::Flush; 506 return RecycleStrategy::Flush;
@@ -538,9 +540,8 @@ private:
538 * @param untopological Indicates to the recycler that the texture has no way to match the 540 * @param untopological Indicates to the recycler that the texture has no way to match the
539 * overlaps due to topological reasons. 541 * overlaps due to topological reasons.
540 **/ 542 **/
541 std::pair<TSurface, TView> RecycleSurface(std::vector<TSurface>& overlaps, 543 std::pair<TSurface, TView> RecycleSurface(VectorSurface& overlaps, const SurfaceParams& params,
542 const SurfaceParams& params, const GPUVAddr gpu_addr, 544 const GPUVAddr gpu_addr, const bool preserve_contents,
543 const bool preserve_contents,
544 const MatchTopologyResult untopological) { 545 const MatchTopologyResult untopological) {
545 const bool do_load = preserve_contents && Settings::IsGPULevelExtreme(); 546 const bool do_load = preserve_contents && Settings::IsGPULevelExtreme();
546 for (auto& surface : overlaps) { 547 for (auto& surface : overlaps) {
@@ -650,7 +651,7 @@ private:
650 * @param params The parameters on the new surface. 651 * @param params The parameters on the new surface.
651 * @param gpu_addr The starting address of the new surface. 652 * @param gpu_addr The starting address of the new surface.
652 **/ 653 **/
653 std::optional<std::pair<TSurface, TView>> TryReconstructSurface(std::vector<TSurface>& overlaps, 654 std::optional<std::pair<TSurface, TView>> TryReconstructSurface(VectorSurface& overlaps,
654 const SurfaceParams& params, 655 const SurfaceParams& params,
655 const GPUVAddr gpu_addr) { 656 const GPUVAddr gpu_addr) {
656 if (params.target == SurfaceTarget::Texture3D) { 657 if (params.target == SurfaceTarget::Texture3D) {
@@ -708,7 +709,7 @@ private:
708 * @param preserve_contents Indicates that the new surface should be loaded from memory or 709 * @param preserve_contents Indicates that the new surface should be loaded from memory or
709 * left blank. 710 * left blank.
710 */ 711 */
711 std::optional<std::pair<TSurface, TView>> Manage3DSurfaces(std::vector<TSurface>& overlaps, 712 std::optional<std::pair<TSurface, TView>> Manage3DSurfaces(VectorSurface& overlaps,
712 const SurfaceParams& params, 713 const SurfaceParams& params,
713 const GPUVAddr gpu_addr, 714 const GPUVAddr gpu_addr,
714 const VAddr cpu_addr, 715 const VAddr cpu_addr,
@@ -810,7 +811,7 @@ private:
810 TSurface& current_surface = iter->second; 811 TSurface& current_surface = iter->second;
811 const auto topological_result = current_surface->MatchesTopology(params); 812 const auto topological_result = current_surface->MatchesTopology(params);
812 if (topological_result != MatchTopologyResult::FullMatch) { 813 if (topological_result != MatchTopologyResult::FullMatch) {
813 std::vector<TSurface> overlaps{current_surface}; 814 VectorSurface overlaps{current_surface};
814 return RecycleSurface(overlaps, params, gpu_addr, preserve_contents, 815 return RecycleSurface(overlaps, params, gpu_addr, preserve_contents,
815 topological_result); 816 topological_result);
816 } 817 }
@@ -1124,14 +1125,14 @@ private:
1124 } 1125 }
1125 } 1126 }
1126 1127
1127 std::vector<TSurface> GetSurfacesInRegion(const VAddr cpu_addr, const std::size_t size) { 1128 VectorSurface GetSurfacesInRegion(const VAddr cpu_addr, const std::size_t size) {
1128 if (size == 0) { 1129 if (size == 0) {
1129 return {}; 1130 return {};
1130 } 1131 }
1131 const VAddr cpu_addr_end = cpu_addr + size; 1132 const VAddr cpu_addr_end = cpu_addr + size;
1132 VAddr start = cpu_addr >> registry_page_bits; 1133 VAddr start = cpu_addr >> registry_page_bits;
1133 const VAddr end = (cpu_addr_end - 1) >> registry_page_bits; 1134 const VAddr end = (cpu_addr_end - 1) >> registry_page_bits;
1134 std::vector<TSurface> surfaces; 1135 VectorSurface surfaces;
1135 while (start <= end) { 1136 while (start <= end) {
1136 std::vector<TSurface>& list = registry[start]; 1137 std::vector<TSurface>& list = registry[start];
1137 for (auto& surface : list) { 1138 for (auto& surface : list) {