summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Fernando Sahmkow2019-06-01 23:03:22 -0400
committerGravatar ReinUsesLisp2019-06-20 21:38:34 -0300
commit9f755218a1359cbd004e6c287f5fead0897c1d11 (patch)
tree9a0e4187602f3c650b7367d268b46e22892b5a5c /src
parenttexture_cache: Optimize GetSurface and use references on functions that don't... (diff)
downloadyuzu-9f755218a1359cbd004e6c287f5fead0897c1d11.tar.gz
yuzu-9f755218a1359cbd004e6c287f5fead0897c1d11.tar.xz
yuzu-9f755218a1359cbd004e6c287f5fead0897c1d11.zip
texture_cache: move some large methods to cpp files
Diffstat (limited to 'src')
-rw-r--r--src/video_core/texture_cache/surface_base.cpp103
-rw-r--r--src/video_core/texture_cache/surface_base.h106
-rw-r--r--src/video_core/texture_cache/surface_params.cpp33
-rw-r--r--src/video_core/texture_cache/surface_params.h32
4 files changed, 135 insertions, 139 deletions
diff --git a/src/video_core/texture_cache/surface_base.cpp b/src/video_core/texture_cache/surface_base.cpp
index 7e90960f7..8c6edb04f 100644
--- a/src/video_core/texture_cache/surface_base.cpp
+++ b/src/video_core/texture_cache/surface_base.cpp
@@ -42,6 +42,109 @@ SurfaceBaseImpl::SurfaceBaseImpl(GPUVAddr gpu_addr, const SurfaceParams& params)
42 } 42 }
43} 43}
44 44
45MatchTopologyResult SurfaceBaseImpl::MatchesTopology(const SurfaceParams& rhs) const {
46 const u32 src_bpp{params.GetBytesPerPixel()};
47 const u32 dst_bpp{rhs.GetBytesPerPixel()};
48 const bool ib1 = params.IsBuffer();
49 const bool ib2 = rhs.IsBuffer();
50 if (std::tie(src_bpp, params.is_tiled, ib1) == std::tie(dst_bpp, rhs.is_tiled, ib2)) {
51 const bool cb1 = params.IsCompressed();
52 const bool cb2 = rhs.IsCompressed();
53 if (cb1 == cb2) {
54 return MatchTopologyResult::FullMatch;
55 }
56 return MatchTopologyResult::CompressUnmatch;
57 }
58 return MatchTopologyResult::None;
59}
60
61MatchStructureResult SurfaceBaseImpl::MatchesStructure(const SurfaceParams& rhs) const {
62 // Buffer surface Check
63 if (params.IsBuffer()) {
64 const std::size_t wd1 = params.width * params.GetBytesPerPixel();
65 const std::size_t wd2 = rhs.width * rhs.GetBytesPerPixel();
66 if (wd1 == wd2) {
67 return MatchStructureResult::FullMatch;
68 }
69 return MatchStructureResult::None;
70 }
71
72 // Linear Surface check
73 if (!params.is_tiled) {
74 if (std::tie(params.width, params.height, params.pitch) ==
75 std::tie(rhs.width, rhs.height, rhs.pitch)) {
76 return MatchStructureResult::FullMatch;
77 }
78 return MatchStructureResult::None;
79 }
80
81 // Tiled Surface check
82 if (std::tie(params.depth, params.block_width, params.block_height, params.block_depth,
83 params.tile_width_spacing, params.num_levels) ==
84 std::tie(rhs.depth, rhs.block_width, rhs.block_height, rhs.block_depth,
85 rhs.tile_width_spacing, rhs.num_levels)) {
86 if (std::tie(params.width, params.height) == std::tie(rhs.width, rhs.height)) {
87 return MatchStructureResult::FullMatch;
88 }
89 const u32 ws = SurfaceParams::ConvertWidth(rhs.GetBlockAlignedWidth(), params.pixel_format,
90 rhs.pixel_format);
91 const u32 hs =
92 SurfaceParams::ConvertHeight(rhs.height, params.pixel_format, rhs.pixel_format);
93 const u32 w1 = params.GetBlockAlignedWidth();
94 if (std::tie(w1, params.height) == std::tie(ws, hs)) {
95 return MatchStructureResult::SemiMatch;
96 }
97 }
98 return MatchStructureResult::None;
99}
100
101std::optional<std::pair<u32, u32>> SurfaceBaseImpl::GetLayerMipmap(
102 const GPUVAddr candidate_gpu_addr) const {
103 if (candidate_gpu_addr < gpu_addr) {
104 return {};
105 }
106 const auto relative_address{static_cast<GPUVAddr>(candidate_gpu_addr - gpu_addr)};
107 const auto layer{static_cast<u32>(relative_address / layer_size)};
108 const GPUVAddr mipmap_address = relative_address - layer_size * layer;
109 const auto mipmap_it =
110 Common::BinaryFind(mipmap_offsets.begin(), mipmap_offsets.end(), mipmap_address);
111 if (mipmap_it == mipmap_offsets.end()) {
112 return {};
113 }
114 const auto level{static_cast<u32>(std::distance(mipmap_offsets.begin(), mipmap_it))};
115 return std::make_pair(layer, level);
116}
117
118std::vector<CopyParams> SurfaceBaseImpl::BreakDownLayered(const SurfaceParams& in_params) const {
119 const u32 layers{params.depth};
120 const u32 mipmaps{params.num_levels};
121 std::vector<CopyParams> result;
122 result.reserve(static_cast<std::size_t>(layers) * static_cast<std::size_t>(mipmaps));
123
124 for (u32 layer = 0; layer < layers; layer++) {
125 for (u32 level = 0; level < mipmaps; level++) {
126 const u32 width = SurfaceParams::IntersectWidth(params, in_params, level, level);
127 const u32 height = SurfaceParams::IntersectHeight(params, in_params, level, level);
128 result.emplace_back(width, height, layer, level);
129 }
130 }
131 return result;
132}
133
134std::vector<CopyParams> SurfaceBaseImpl::BreakDownNonLayered(const SurfaceParams& in_params) const {
135 const u32 mipmaps{params.num_levels};
136 std::vector<CopyParams> result;
137 result.reserve(mipmaps);
138
139 for (u32 level = 0; level < mipmaps; level++) {
140 const u32 width = SurfaceParams::IntersectWidth(params, in_params, level, level);
141 const u32 height = SurfaceParams::IntersectHeight(params, in_params, level, level);
142 const u32 depth{std::min(params.GetMipDepth(level), in_params.GetMipDepth(level))};
143 result.emplace_back(width, height, depth, level);
144 }
145 return result;
146}
147
45void SurfaceBaseImpl::SwizzleFunc(MortonSwizzleMode mode, u8* memory, const SurfaceParams& params, 148void SurfaceBaseImpl::SwizzleFunc(MortonSwizzleMode mode, u8* memory, const SurfaceParams& params,
46 u8* buffer, u32 level) { 149 u8* buffer, u32 level) {
47 const u32 width{params.GetMipWidth(level)}; 150 const u32 width{params.GetMipWidth(level)};
diff --git a/src/video_core/texture_cache/surface_base.h b/src/video_core/texture_cache/surface_base.h
index 70b5258c9..9d19ecd5f 100644
--- a/src/video_core/texture_cache/surface_base.h
+++ b/src/video_core/texture_cache/surface_base.h
@@ -136,83 +136,17 @@ public:
136 return params.target == target; 136 return params.target == target;
137 } 137 }
138 138
139 MatchTopologyResult MatchesTopology(const SurfaceParams& rhs) const;
140
141 MatchStructureResult MatchesStructure(const SurfaceParams& rhs) const;
142
139 bool MatchesSubTexture(const SurfaceParams& rhs, const GPUVAddr other_gpu_addr) const { 143 bool MatchesSubTexture(const SurfaceParams& rhs, const GPUVAddr other_gpu_addr) const {
140 return std::tie(gpu_addr, params.target, params.num_levels) == 144 return std::tie(gpu_addr, params.target, params.num_levels) ==
141 std::tie(other_gpu_addr, rhs.target, rhs.num_levels) && 145 std::tie(other_gpu_addr, rhs.target, rhs.num_levels) &&
142 params.target == SurfaceTarget::Texture2D && params.num_levels == 1; 146 params.target == SurfaceTarget::Texture2D && params.num_levels == 1;
143 } 147 }
144 148
145 MatchTopologyResult MatchesTopology(const SurfaceParams& rhs) const { 149 std::optional<std::pair<u32, u32>> GetLayerMipmap(const GPUVAddr candidate_gpu_addr) const;
146 const u32 src_bpp{params.GetBytesPerPixel()};
147 const u32 dst_bpp{rhs.GetBytesPerPixel()};
148 const bool ib1 = params.IsBuffer();
149 const bool ib2 = rhs.IsBuffer();
150 if (std::tie(src_bpp, params.is_tiled, ib1) == std::tie(dst_bpp, rhs.is_tiled, ib2)) {
151 const bool cb1 = params.IsCompressed();
152 const bool cb2 = rhs.IsCompressed();
153 if (cb1 == cb2) {
154 return MatchTopologyResult::FullMatch;
155 }
156 return MatchTopologyResult::CompressUnmatch;
157 }
158 return MatchTopologyResult::None;
159 }
160
161 MatchStructureResult MatchesStructure(const SurfaceParams& rhs) const {
162 // Buffer surface Check
163 if (params.IsBuffer()) {
164 const std::size_t wd1 = params.width * params.GetBytesPerPixel();
165 const std::size_t wd2 = rhs.width * rhs.GetBytesPerPixel();
166 if (wd1 == wd2) {
167 return MatchStructureResult::FullMatch;
168 }
169 return MatchStructureResult::None;
170 }
171
172 // Linear Surface check
173 if (!params.is_tiled) {
174 if (std::tie(params.width, params.height, params.pitch) ==
175 std::tie(rhs.width, rhs.height, rhs.pitch)) {
176 return MatchStructureResult::FullMatch;
177 }
178 return MatchStructureResult::None;
179 }
180
181 // Tiled Surface check
182 if (std::tie(params.depth, params.block_width, params.block_height, params.block_depth,
183 params.tile_width_spacing, params.num_levels) ==
184 std::tie(rhs.depth, rhs.block_width, rhs.block_height, rhs.block_depth,
185 rhs.tile_width_spacing, rhs.num_levels)) {
186 if (std::tie(params.width, params.height) == std::tie(rhs.width, rhs.height)) {
187 return MatchStructureResult::FullMatch;
188 }
189 const u32 ws = SurfaceParams::ConvertWidth(rhs.GetBlockAlignedWidth(),
190 params.pixel_format, rhs.pixel_format);
191 const u32 hs =
192 SurfaceParams::ConvertHeight(rhs.height, params.pixel_format, rhs.pixel_format);
193 const u32 w1 = params.GetBlockAlignedWidth();
194 if (std::tie(w1, params.height) == std::tie(ws, hs)) {
195 return MatchStructureResult::SemiMatch;
196 }
197 }
198 return MatchStructureResult::None;
199 }
200
201 std::optional<std::pair<u32, u32>> GetLayerMipmap(const GPUVAddr candidate_gpu_addr) const {
202 if (candidate_gpu_addr < gpu_addr) {
203 return {};
204 }
205 const auto relative_address{static_cast<GPUVAddr>(candidate_gpu_addr - gpu_addr)};
206 const auto layer{static_cast<u32>(relative_address / layer_size)};
207 const GPUVAddr mipmap_address = relative_address - layer_size * layer;
208 const auto mipmap_it =
209 Common::BinaryFind(mipmap_offsets.begin(), mipmap_offsets.end(), mipmap_address);
210 if (mipmap_it == mipmap_offsets.end()) {
211 return {};
212 }
213 const auto level{static_cast<u32>(std::distance(mipmap_offsets.begin(), mipmap_it))};
214 return std::make_pair(layer, level);
215 }
216 150
217 std::vector<CopyParams> BreakDown(const SurfaceParams& in_params) const { 151 std::vector<CopyParams> BreakDown(const SurfaceParams& in_params) const {
218 return params.is_layered ? BreakDownLayered(in_params) : BreakDownNonLayered(in_params); 152 return params.is_layered ? BreakDownLayered(in_params) : BreakDownNonLayered(in_params);
@@ -241,35 +175,9 @@ private:
241 void SwizzleFunc(MortonSwizzleMode mode, u8* memory, const SurfaceParams& params, u8* buffer, 175 void SwizzleFunc(MortonSwizzleMode mode, u8* memory, const SurfaceParams& params, u8* buffer,
242 u32 level); 176 u32 level);
243 177
244 std::vector<CopyParams> BreakDownLayered(const SurfaceParams& in_params) const { 178 std::vector<CopyParams> BreakDownLayered(const SurfaceParams& in_params) const;
245 const u32 layers{params.depth};
246 const u32 mipmaps{params.num_levels};
247 std::vector<CopyParams> result;
248 result.reserve(static_cast<std::size_t>(layers) * static_cast<std::size_t>(mipmaps));
249
250 for (u32 layer = 0; layer < layers; layer++) {
251 for (u32 level = 0; level < mipmaps; level++) {
252 const u32 width = SurfaceParams::IntersectWidth(params, in_params, level, level);
253 const u32 height = SurfaceParams::IntersectHeight(params, in_params, level, level);
254 result.emplace_back(width, height, layer, level);
255 }
256 }
257 return result;
258 }
259
260 std::vector<CopyParams> BreakDownNonLayered(const SurfaceParams& in_params) const {
261 const u32 mipmaps{params.num_levels};
262 std::vector<CopyParams> result;
263 result.reserve(mipmaps);
264 179
265 for (u32 level = 0; level < mipmaps; level++) { 180 std::vector<CopyParams> BreakDownNonLayered(const SurfaceParams& in_params) const;
266 const u32 width = SurfaceParams::IntersectWidth(params, in_params, level, level);
267 const u32 height = SurfaceParams::IntersectHeight(params, in_params, level, level);
268 const u32 depth{std::min(params.GetMipDepth(level), in_params.GetMipDepth(level))};
269 result.emplace_back(width, height, depth, level);
270 }
271 return result;
272 }
273}; 181};
274 182
275template <typename TView> 183template <typename TView>
diff --git a/src/video_core/texture_cache/surface_params.cpp b/src/video_core/texture_cache/surface_params.cpp
index 77c09264a..60a7356bb 100644
--- a/src/video_core/texture_cache/surface_params.cpp
+++ b/src/video_core/texture_cache/surface_params.cpp
@@ -6,7 +6,6 @@
6 6
7#include "common/alignment.h" 7#include "common/alignment.h"
8#include "common/bit_util.h" 8#include "common/bit_util.h"
9#include "common/cityhash.h"
10#include "core/core.h" 9#include "core/core.h"
11#include "video_core/engines/shader_bytecode.h" 10#include "video_core/engines/shader_bytecode.h"
12#include "video_core/surface.h" 11#include "video_core/surface.h"
@@ -237,14 +236,6 @@ std::size_t SurfaceParams::GetConvertedMipmapOffset(u32 level) const {
237 return offset; 236 return offset;
238} 237}
239 238
240std::size_t SurfaceParams::GetGuestMipmapSize(u32 level) const {
241 return GetInnerMipmapMemorySize(level, false, false);
242}
243
244std::size_t SurfaceParams::GetHostMipmapSize(u32 level) const {
245 return GetInnerMipmapMemorySize(level, true, false) * GetNumLayers();
246}
247
248std::size_t SurfaceParams::GetConvertedMipmapSize(u32 level) const { 239std::size_t SurfaceParams::GetConvertedMipmapSize(u32 level) const {
249 constexpr std::size_t rgb8_bpp = 4ULL; 240 constexpr std::size_t rgb8_bpp = 4ULL;
250 const std::size_t width_t = GetMipWidth(level); 241 const std::size_t width_t = GetMipWidth(level);
@@ -253,10 +244,6 @@ std::size_t SurfaceParams::GetConvertedMipmapSize(u32 level) const {
253 return width_t * height_t * depth_t * rgb8_bpp; 244 return width_t * height_t * depth_t * rgb8_bpp;
254} 245}
255 246
256std::size_t SurfaceParams::GetGuestLayerSize() const {
257 return GetLayerSize(false, false);
258}
259
260std::size_t SurfaceParams::GetLayerSize(bool as_host_size, bool uncompressed) const { 247std::size_t SurfaceParams::GetLayerSize(bool as_host_size, bool uncompressed) const {
261 std::size_t size = 0; 248 std::size_t size = 0;
262 for (u32 level = 0; level < num_levels; ++level) { 249 for (u32 level = 0; level < num_levels; ++level) {
@@ -269,16 +256,6 @@ std::size_t SurfaceParams::GetLayerSize(bool as_host_size, bool uncompressed) co
269 return size; 256 return size;
270} 257}
271 258
272std::size_t SurfaceParams::GetHostLayerSize(u32 level) const {
273 ASSERT(target != SurfaceTarget::Texture3D);
274 return GetInnerMipmapMemorySize(level, true, false);
275}
276
277bool SurfaceParams::IsPixelFormatZeta() const {
278 return pixel_format >= VideoCore::Surface::PixelFormat::MaxColorFormat &&
279 pixel_format < VideoCore::Surface::PixelFormat::MaxDepthStencilFormat;
280}
281
282std::size_t SurfaceParams::GetInnerMipmapMemorySize(u32 level, bool as_host_size, 259std::size_t SurfaceParams::GetInnerMipmapMemorySize(u32 level, bool as_host_size,
283 bool uncompressed) const { 260 bool uncompressed) const {
284 const bool tiled{as_host_size ? false : is_tiled}; 261 const bool tiled{as_host_size ? false : is_tiled};
@@ -289,16 +266,6 @@ std::size_t SurfaceParams::GetInnerMipmapMemorySize(u32 level, bool as_host_size
289 GetMipBlockHeight(level), GetMipBlockDepth(level)); 266 GetMipBlockHeight(level), GetMipBlockDepth(level));
290} 267}
291 268
292std::size_t SurfaceParams::GetInnerMemorySize(bool as_host_size, bool layer_only,
293 bool uncompressed) const {
294 return GetLayerSize(as_host_size, uncompressed) * (layer_only ? 1U : depth);
295}
296
297std::size_t SurfaceParams::Hash() const {
298 return static_cast<std::size_t>(
299 Common::CityHash64(reinterpret_cast<const char*>(this), sizeof(*this)));
300}
301
302bool SurfaceParams::operator==(const SurfaceParams& rhs) const { 269bool SurfaceParams::operator==(const SurfaceParams& rhs) const {
303 return std::tie(is_tiled, block_width, block_height, block_depth, tile_width_spacing, width, 270 return std::tie(is_tiled, block_width, block_height, block_depth, tile_width_spacing, width,
304 height, depth, pitch, num_levels, pixel_format, component_type, type, target) == 271 height, depth, pitch, num_levels, pixel_format, component_type, type, target) ==
diff --git a/src/video_core/texture_cache/surface_params.h b/src/video_core/texture_cache/surface_params.h
index 5fde695b6..c51e174cd 100644
--- a/src/video_core/texture_cache/surface_params.h
+++ b/src/video_core/texture_cache/surface_params.h
@@ -8,6 +8,7 @@
8 8
9#include "common/alignment.h" 9#include "common/alignment.h"
10#include "common/bit_util.h" 10#include "common/bit_util.h"
11#include "common/cityhash.h"
11#include "common/common_types.h" 12#include "common/common_types.h"
12#include "video_core/engines/fermi_2d.h" 13#include "video_core/engines/fermi_2d.h"
13#include "video_core/engines/maxwell_3d.h" 14#include "video_core/engines/maxwell_3d.h"
@@ -39,7 +40,10 @@ public:
39 static SurfaceParams CreateForFermiCopySurface( 40 static SurfaceParams CreateForFermiCopySurface(
40 const Tegra::Engines::Fermi2D::Regs::Surface& config); 41 const Tegra::Engines::Fermi2D::Regs::Surface& config);
41 42
42 std::size_t Hash() const; 43 std::size_t Hash() const {
44 return static_cast<std::size_t>(
45 Common::CityHash64(reinterpret_cast<const char*>(this), sizeof(*this)));
46 }
43 47
44 bool operator==(const SurfaceParams& rhs) const; 48 bool operator==(const SurfaceParams& rhs) const;
45 49
@@ -113,18 +117,27 @@ public:
113 std::size_t GetConvertedMipmapOffset(u32 level) const; 117 std::size_t GetConvertedMipmapOffset(u32 level) const;
114 118
115 /// Returns the size in bytes in guest memory of a given mipmap level. 119 /// Returns the size in bytes in guest memory of a given mipmap level.
116 std::size_t GetGuestMipmapSize(u32 level) const; 120 std::size_t GetGuestMipmapSize(u32 level) const {
121 return GetInnerMipmapMemorySize(level, false, false);
122 }
117 123
118 /// Returns the size in bytes in host memory (linear) of a given mipmap level. 124 /// Returns the size in bytes in host memory (linear) of a given mipmap level.
119 std::size_t GetHostMipmapSize(u32 level) const; 125 std::size_t GetHostMipmapSize(u32 level) const {
126 return GetInnerMipmapMemorySize(level, true, false) * GetNumLayers();
127 }
120 128
121 std::size_t GetConvertedMipmapSize(u32 level) const; 129 std::size_t GetConvertedMipmapSize(u32 level) const;
122 130
123 /// Returns the size of a layer in bytes in guest memory. 131 /// Returns the size of a layer in bytes in guest memory.
124 std::size_t GetGuestLayerSize() const; 132 std::size_t GetGuestLayerSize() const {
133 return GetLayerSize(false, false);
134 }
125 135
126 /// Returns the size of a layer in bytes in host memory for a given mipmap level. 136 /// Returns the size of a layer in bytes in host memory for a given mipmap level.
127 std::size_t GetHostLayerSize(u32 level) const; 137 std::size_t GetHostLayerSize(u32 level) const {
138 ASSERT(target != VideoCore::Surface::SurfaceTarget::Texture3D);
139 return GetInnerMipmapMemorySize(level, true, false);
140 }
128 141
129 static u32 ConvertWidth(u32 width, VideoCore::Surface::PixelFormat pixel_format_from, 142 static u32 ConvertWidth(u32 width, VideoCore::Surface::PixelFormat pixel_format_from,
130 VideoCore::Surface::PixelFormat pixel_format_to) { 143 VideoCore::Surface::PixelFormat pixel_format_to) {
@@ -194,7 +207,10 @@ public:
194 } 207 }
195 208
196 /// Returns true if the pixel format is a depth and/or stencil format. 209 /// Returns true if the pixel format is a depth and/or stencil format.
197 bool IsPixelFormatZeta() const; 210 bool IsPixelFormatZeta() const {
211 return pixel_format >= VideoCore::Surface::PixelFormat::MaxColorFormat &&
212 pixel_format < VideoCore::Surface::PixelFormat::MaxDepthStencilFormat;
213 }
198 214
199 SurfaceCompression GetCompressionType() const { 215 SurfaceCompression GetCompressionType() const {
200 return VideoCore::Surface::GetFormatCompressionType(pixel_format); 216 return VideoCore::Surface::GetFormatCompressionType(pixel_format);
@@ -229,7 +245,9 @@ private:
229 std::size_t GetInnerMipmapMemorySize(u32 level, bool as_host_size, bool uncompressed) const; 245 std::size_t GetInnerMipmapMemorySize(u32 level, bool as_host_size, bool uncompressed) const;
230 246
231 /// Returns the size of all mipmap levels and aligns as needed. 247 /// Returns the size of all mipmap levels and aligns as needed.
232 std::size_t GetInnerMemorySize(bool as_host_size, bool layer_only, bool uncompressed) const; 248 std::size_t GetInnerMemorySize(bool as_host_size, bool layer_only, bool uncompressed) const {
249 return GetLayerSize(as_host_size, uncompressed) * (layer_only ? 1U : depth);
250 }
233 251
234 /// Returns the size of a layer 252 /// Returns the size of a layer
235 std::size_t GetLayerSize(bool as_host_size, bool uncompressed) const; 253 std::size_t GetLayerSize(bool as_host_size, bool uncompressed) const;