diff options
| author | 2019-06-25 18:03:25 -0400 | |
|---|---|---|
| committer | 2019-06-25 18:03:25 -0400 | |
| commit | c0abc7124d6ecd17f9da5ee5b3de9cb3dbf3ce1f (patch) | |
| tree | 809b703bbf7b86782cf1247d650e9ce13392ab6d /src | |
| parent | copy_params: use constexpr for constructor (diff) | |
| download | yuzu-c0abc7124d6ecd17f9da5ee5b3de9cb3dbf3ce1f.tar.gz yuzu-c0abc7124d6ecd17f9da5ee5b3de9cb3dbf3ce1f.tar.xz yuzu-c0abc7124d6ecd17f9da5ee5b3de9cb3dbf3ce1f.zip | |
surface_params: Corrections, asserts and documentation.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/texture_cache/surface_params.cpp | 4 | ||||
| -rw-r--r-- | src/video_core/texture_cache/surface_params.h | 97 |
2 files changed, 58 insertions, 43 deletions
diff --git a/src/video_core/texture_cache/surface_params.cpp b/src/video_core/texture_cache/surface_params.cpp index a670fc1a9..340ed2ca0 100644 --- a/src/video_core/texture_cache/surface_params.cpp +++ b/src/video_core/texture_cache/surface_params.cpp | |||
| @@ -269,11 +269,11 @@ std::size_t SurfaceParams::GetConvertedMipmapOffset(u32 level) const { | |||
| 269 | } | 269 | } |
| 270 | 270 | ||
| 271 | std::size_t SurfaceParams::GetConvertedMipmapSize(u32 level) const { | 271 | std::size_t SurfaceParams::GetConvertedMipmapSize(u32 level) const { |
| 272 | constexpr std::size_t rgb8_bpp = 4ULL; | 272 | constexpr std::size_t rgba8_bpp = 4ULL; |
| 273 | const std::size_t width_t = GetMipWidth(level); | 273 | const std::size_t width_t = GetMipWidth(level); |
| 274 | const std::size_t height_t = GetMipHeight(level); | 274 | const std::size_t height_t = GetMipHeight(level); |
| 275 | const std::size_t depth_t = is_layered ? depth : GetMipDepth(level); | 275 | const std::size_t depth_t = is_layered ? depth : GetMipDepth(level); |
| 276 | return width_t * height_t * depth_t * rgb8_bpp; | 276 | return width_t * height_t * depth_t * rgba8_bpp; |
| 277 | } | 277 | } |
| 278 | 278 | ||
| 279 | std::size_t SurfaceParams::GetLayerSize(bool as_host_size, bool uncompressed) const { | 279 | std::size_t SurfaceParams::GetLayerSize(bool as_host_size, bool uncompressed) const { |
diff --git a/src/video_core/texture_cache/surface_params.h b/src/video_core/texture_cache/surface_params.h index c51e174cd..4dfb882f0 100644 --- a/src/video_core/texture_cache/surface_params.h +++ b/src/video_core/texture_cache/surface_params.h | |||
| @@ -95,25 +95,21 @@ public: | |||
| 95 | /// Returns the block depth of a given mipmap level. | 95 | /// Returns the block depth of a given mipmap level. |
| 96 | u32 GetMipBlockDepth(u32 level) const; | 96 | u32 GetMipBlockDepth(u32 level) const; |
| 97 | 97 | ||
| 98 | /// returns the best possible row/pitch alignment for the surface. | ||
| 98 | u32 GetRowAlignment(u32 level) const { | 99 | u32 GetRowAlignment(u32 level) const { |
| 99 | const u32 bpp = | 100 | const u32 bpp = |
| 100 | GetCompressionType() == SurfaceCompression::Converted ? 4 : GetBytesPerPixel(); | 101 | GetCompressionType() == SurfaceCompression::Converted ? 4 : GetBytesPerPixel(); |
| 101 | return 1U << Common::CountTrailingZeroes32(GetMipWidth(level) * bpp); | 102 | return 1U << Common::CountTrailingZeroes32(GetMipWidth(level) * bpp); |
| 102 | } | 103 | } |
| 103 | 104 | ||
| 104 | // Helper used for out of class size calculations | ||
| 105 | static std::size_t AlignLayered(const std::size_t out_size, const u32 block_height, | ||
| 106 | const u32 block_depth) { | ||
| 107 | return Common::AlignBits(out_size, | ||
| 108 | Tegra::Texture::GetGOBSizeShift() + block_height + block_depth); | ||
| 109 | } | ||
| 110 | |||
| 111 | /// Returns the offset in bytes in guest memory of a given mipmap level. | 105 | /// Returns the offset in bytes in guest memory of a given mipmap level. |
| 112 | std::size_t GetGuestMipmapLevelOffset(u32 level) const; | 106 | std::size_t GetGuestMipmapLevelOffset(u32 level) const; |
| 113 | 107 | ||
| 114 | /// Returns the offset in bytes in host memory (linear) of a given mipmap level. | 108 | /// Returns the offset in bytes in host memory (linear) of a given mipmap level. |
| 115 | std::size_t GetHostMipmapLevelOffset(u32 level) const; | 109 | std::size_t GetHostMipmapLevelOffset(u32 level) const; |
| 116 | 110 | ||
| 111 | /// Returns the offset in bytes in host memory (linear) of a given mipmap level | ||
| 112 | // for a texture that is converted in host gpu. | ||
| 117 | std::size_t GetConvertedMipmapOffset(u32 level) const; | 113 | std::size_t GetConvertedMipmapOffset(u32 level) const; |
| 118 | 114 | ||
| 119 | /// Returns the size in bytes in guest memory of a given mipmap level. | 115 | /// Returns the size in bytes in guest memory of a given mipmap level. |
| @@ -139,40 +135,7 @@ public: | |||
| 139 | return GetInnerMipmapMemorySize(level, true, false); | 135 | return GetInnerMipmapMemorySize(level, true, false); |
| 140 | } | 136 | } |
| 141 | 137 | ||
| 142 | static u32 ConvertWidth(u32 width, VideoCore::Surface::PixelFormat pixel_format_from, | 138 | /// Returns the max possible mipmap that the texture can have in host gpu |
| 143 | VideoCore::Surface::PixelFormat pixel_format_to) { | ||
| 144 | const u32 bw1 = VideoCore::Surface::GetDefaultBlockWidth(pixel_format_from); | ||
| 145 | const u32 bw2 = VideoCore::Surface::GetDefaultBlockWidth(pixel_format_to); | ||
| 146 | return (width * bw2 + bw1 - 1) / bw1; | ||
| 147 | } | ||
| 148 | |||
| 149 | static u32 ConvertHeight(u32 height, VideoCore::Surface::PixelFormat pixel_format_from, | ||
| 150 | VideoCore::Surface::PixelFormat pixel_format_to) { | ||
| 151 | const u32 bh1 = VideoCore::Surface::GetDefaultBlockHeight(pixel_format_from); | ||
| 152 | const u32 bh2 = VideoCore::Surface::GetDefaultBlockHeight(pixel_format_to); | ||
| 153 | return (height * bh2 + bh1 - 1) / bh1; | ||
| 154 | } | ||
| 155 | |||
| 156 | // this finds the maximun possible width between 2 2D layers of different formats | ||
| 157 | static u32 IntersectWidth(const SurfaceParams& src_params, const SurfaceParams& dst_params, | ||
| 158 | const u32 src_level, const u32 dst_level) { | ||
| 159 | const u32 bw1 = src_params.GetDefaultBlockWidth(); | ||
| 160 | const u32 bw2 = dst_params.GetDefaultBlockWidth(); | ||
| 161 | const u32 t_src_width = (src_params.GetMipWidth(src_level) * bw2 + bw1 - 1) / bw1; | ||
| 162 | const u32 t_dst_width = (dst_params.GetMipWidth(dst_level) * bw1 + bw2 - 1) / bw2; | ||
| 163 | return std::min(t_src_width, t_dst_width); | ||
| 164 | } | ||
| 165 | |||
| 166 | // this finds the maximun possible height between 2 2D layers of different formats | ||
| 167 | static u32 IntersectHeight(const SurfaceParams& src_params, const SurfaceParams& dst_params, | ||
| 168 | const u32 src_level, const u32 dst_level) { | ||
| 169 | const u32 bh1 = src_params.GetDefaultBlockHeight(); | ||
| 170 | const u32 bh2 = dst_params.GetDefaultBlockHeight(); | ||
| 171 | const u32 t_src_height = (src_params.GetMipHeight(src_level) * bh2 + bh1 - 1) / bh1; | ||
| 172 | const u32 t_dst_height = (dst_params.GetMipHeight(dst_level) * bh1 + bh2 - 1) / bh2; | ||
| 173 | return std::min(t_src_height, t_dst_height); | ||
| 174 | } | ||
| 175 | |||
| 176 | u32 MaxPossibleMipmap() const { | 139 | u32 MaxPossibleMipmap() const { |
| 177 | const u32 max_mipmap_w = Common::Log2Ceil32(width) + 1U; | 140 | const u32 max_mipmap_w = Common::Log2Ceil32(width) + 1U; |
| 178 | const u32 max_mipmap_h = Common::Log2Ceil32(height) + 1U; | 141 | const u32 max_mipmap_h = Common::Log2Ceil32(height) + 1U; |
| @@ -182,6 +145,7 @@ public: | |||
| 182 | return std::max(max_mipmap, Common::Log2Ceil32(depth) + 1U); | 145 | return std::max(max_mipmap, Common::Log2Ceil32(depth) + 1U); |
| 183 | } | 146 | } |
| 184 | 147 | ||
| 148 | /// Returns if the guest surface is a compressed surface. | ||
| 185 | bool IsCompressed() const { | 149 | bool IsCompressed() const { |
| 186 | return GetDefaultBlockHeight() > 1 || GetDefaultBlockWidth() > 1; | 150 | return GetDefaultBlockHeight() > 1 || GetDefaultBlockWidth() > 1; |
| 187 | } | 151 | } |
| @@ -212,16 +176,67 @@ public: | |||
| 212 | pixel_format < VideoCore::Surface::PixelFormat::MaxDepthStencilFormat; | 176 | pixel_format < VideoCore::Surface::PixelFormat::MaxDepthStencilFormat; |
| 213 | } | 177 | } |
| 214 | 178 | ||
| 179 | /// Returns how the compression should be handled for this texture. Values | ||
| 180 | /// are: None(no compression), Compressed(texture is compressed), | ||
| 181 | /// Converted(texture is converted before upload/ after download), | ||
| 182 | /// Rearranged(texture is swizzled before upload/after download). | ||
| 215 | SurfaceCompression GetCompressionType() const { | 183 | SurfaceCompression GetCompressionType() const { |
| 216 | return VideoCore::Surface::GetFormatCompressionType(pixel_format); | 184 | return VideoCore::Surface::GetFormatCompressionType(pixel_format); |
| 217 | } | 185 | } |
| 218 | 186 | ||
| 187 | /// Returns is the surface is a TextureBuffer type of surface. | ||
| 219 | bool IsBuffer() const { | 188 | bool IsBuffer() const { |
| 220 | return target == VideoCore::Surface::SurfaceTarget::TextureBuffer; | 189 | return target == VideoCore::Surface::SurfaceTarget::TextureBuffer; |
| 221 | } | 190 | } |
| 222 | 191 | ||
| 192 | /// Returns the debug name of the texture for use in graphic debuggers. | ||
| 223 | std::string TargetName() const; | 193 | std::string TargetName() const; |
| 224 | 194 | ||
| 195 | // Helper used for out of class size calculations | ||
| 196 | static std::size_t AlignLayered(const std::size_t out_size, const u32 block_height, | ||
| 197 | const u32 block_depth) { | ||
| 198 | return Common::AlignBits(out_size, | ||
| 199 | Tegra::Texture::GetGOBSizeShift() + block_height + block_depth); | ||
| 200 | } | ||
| 201 | |||
| 202 | /// Converts a width from a type of surface into another. This helps represent the | ||
| 203 | /// equivalent value between compressed/non-compressed textures. | ||
| 204 | static u32 ConvertWidth(u32 width, VideoCore::Surface::PixelFormat pixel_format_from, | ||
| 205 | VideoCore::Surface::PixelFormat pixel_format_to) { | ||
| 206 | const u32 bw1 = VideoCore::Surface::GetDefaultBlockWidth(pixel_format_from); | ||
| 207 | const u32 bw2 = VideoCore::Surface::GetDefaultBlockWidth(pixel_format_to); | ||
| 208 | return (width * bw2 + bw1 - 1) / bw1; | ||
| 209 | } | ||
| 210 | |||
| 211 | /// Converts a height from a type of surface into another. This helps represent the | ||
| 212 | /// equivalent value between compressed/non-compressed textures. | ||
| 213 | static u32 ConvertHeight(u32 height, VideoCore::Surface::PixelFormat pixel_format_from, | ||
| 214 | VideoCore::Surface::PixelFormat pixel_format_to) { | ||
| 215 | const u32 bh1 = VideoCore::Surface::GetDefaultBlockHeight(pixel_format_from); | ||
| 216 | const u32 bh2 = VideoCore::Surface::GetDefaultBlockHeight(pixel_format_to); | ||
| 217 | return (height * bh2 + bh1 - 1) / bh1; | ||
| 218 | } | ||
| 219 | |||
| 220 | // Finds the maximun possible width between 2 2D layers of different formats | ||
| 221 | static u32 IntersectWidth(const SurfaceParams& src_params, const SurfaceParams& dst_params, | ||
| 222 | const u32 src_level, const u32 dst_level) { | ||
| 223 | const u32 bw1 = src_params.GetDefaultBlockWidth(); | ||
| 224 | const u32 bw2 = dst_params.GetDefaultBlockWidth(); | ||
| 225 | const u32 t_src_width = (src_params.GetMipWidth(src_level) * bw2 + bw1 - 1) / bw1; | ||
| 226 | const u32 t_dst_width = (dst_params.GetMipWidth(dst_level) * bw1 + bw2 - 1) / bw2; | ||
| 227 | return std::min(t_src_width, t_dst_width); | ||
| 228 | } | ||
| 229 | |||
| 230 | // Finds the maximun possible height between 2 2D layers of different formats | ||
| 231 | static u32 IntersectHeight(const SurfaceParams& src_params, const SurfaceParams& dst_params, | ||
| 232 | const u32 src_level, const u32 dst_level) { | ||
| 233 | const u32 bh1 = src_params.GetDefaultBlockHeight(); | ||
| 234 | const u32 bh2 = dst_params.GetDefaultBlockHeight(); | ||
| 235 | const u32 t_src_height = (src_params.GetMipHeight(src_level) * bh2 + bh1 - 1) / bh1; | ||
| 236 | const u32 t_dst_height = (dst_params.GetMipHeight(dst_level) * bh1 + bh2 - 1) / bh2; | ||
| 237 | return std::min(t_src_height, t_dst_height); | ||
| 238 | } | ||
| 239 | |||
| 225 | bool is_tiled; | 240 | bool is_tiled; |
| 226 | bool srgb_conversion; | 241 | bool srgb_conversion; |
| 227 | bool is_layered; | 242 | bool is_layered; |