diff options
| author | 2019-05-07 21:48:02 -0300 | |
|---|---|---|
| committer | 2019-06-20 21:36:12 -0300 | |
| commit | 2b30000a1ed1972e0701a8525182104b4544caa4 (patch) | |
| tree | e66b712f76e6ebedf1da25a233736cf6765a3b38 /src/video_core/texture_cache | |
| parent | copy_params: Use constructor instead of C-like initialization (diff) | |
| download | yuzu-2b30000a1ed1972e0701a8525182104b4544caa4.tar.gz yuzu-2b30000a1ed1972e0701a8525182104b4544caa4.tar.xz yuzu-2b30000a1ed1972e0701a8525182104b4544caa4.zip | |
surface_base: Silence truncation warnings and minor renames and reordering
Diffstat (limited to 'src/video_core/texture_cache')
| -rw-r--r-- | src/video_core/texture_cache/surface_base.cpp | 34 | ||||
| -rw-r--r-- | src/video_core/texture_cache/surface_base.h | 35 |
2 files changed, 37 insertions, 32 deletions
diff --git a/src/video_core/texture_cache/surface_base.cpp b/src/video_core/texture_cache/surface_base.cpp index 0de0bc656..5e994cf08 100644 --- a/src/video_core/texture_cache/surface_base.cpp +++ b/src/video_core/texture_cache/surface_base.cpp | |||
| @@ -18,17 +18,19 @@ MICROPROFILE_DEFINE(GPU_Flush_Texture, "GPU", "Texture Flush", MP_RGB(128, 192, | |||
| 18 | using Tegra::Texture::ConvertFromGuestToHost; | 18 | using Tegra::Texture::ConvertFromGuestToHost; |
| 19 | using VideoCore::MortonSwizzleMode; | 19 | using VideoCore::MortonSwizzleMode; |
| 20 | 20 | ||
| 21 | SurfaceBaseImpl::SurfaceBaseImpl(const GPUVAddr gpu_vaddr, const SurfaceParams& params) | 21 | SurfaceBaseImpl::SurfaceBaseImpl(GPUVAddr gpu_addr, const SurfaceParams& params) |
| 22 | : gpu_addr{gpu_vaddr}, params{params}, mipmap_sizes{params.num_levels}, | 22 | : params{params}, gpu_addr{gpu_addr}, layer_size{params.GetGuestLayerSize()}, |
| 23 | mipmap_offsets{params.num_levels}, layer_size{params.GetGuestLayerSize()}, | 23 | guest_memory_size{params.GetGuestSizeInBytes()}, host_memory_size{ |
| 24 | memory_size{params.GetGuestSizeInBytes()}, host_memory_size{params.GetHostSizeInBytes()} { | 24 | params.GetHostSizeInBytes()} { |
| 25 | u32 offset = 0; | 25 | mipmap_offsets.reserve(params.num_levels); |
| 26 | mipmap_offsets.resize(params.num_levels); | 26 | mipmap_sizes.reserve(params.num_levels); |
| 27 | mipmap_sizes.resize(params.num_levels); | 27 | |
| 28 | for (u32 i = 0; i < params.num_levels; i++) { | 28 | std::size_t offset = 0; |
| 29 | mipmap_offsets[i] = offset; | 29 | for (u32 level = 0; level < params.num_levels; ++level) { |
| 30 | mipmap_sizes[i] = params.GetGuestMipmapSize(i); | 30 | const std::size_t mipmap_size{params.GetGuestMipmapSize(level)}; |
| 31 | offset += mipmap_sizes[i]; | 31 | mipmap_sizes.push_back(mipmap_size); |
| 32 | mipmap_offsets.push_back(offset); | ||
| 33 | offset += mipmap_size; | ||
| 32 | } | 34 | } |
| 33 | } | 35 | } |
| 34 | 36 | ||
| @@ -44,7 +46,7 @@ void SurfaceBaseImpl::SwizzleFunc(MortonSwizzleMode mode, u8* memory, const Surf | |||
| 44 | std::size_t host_offset{0}; | 46 | std::size_t host_offset{0}; |
| 45 | const std::size_t guest_stride = layer_size; | 47 | const std::size_t guest_stride = layer_size; |
| 46 | const std::size_t host_stride = params.GetHostLayerSize(level); | 48 | const std::size_t host_stride = params.GetHostLayerSize(level); |
| 47 | for (u32 layer = 0; layer < params.depth; layer++) { | 49 | for (u32 layer = 0; layer < params.depth; ++layer) { |
| 48 | MortonSwizzle(mode, params.pixel_format, width, block_height, height, block_depth, 1, | 50 | MortonSwizzle(mode, params.pixel_format, width, block_height, height, block_depth, 1, |
| 49 | params.tile_width_spacing, buffer + host_offset, memory + guest_offset); | 51 | params.tile_width_spacing, buffer + host_offset, memory + guest_offset); |
| 50 | guest_offset += guest_stride; | 52 | guest_offset += guest_stride; |
| @@ -60,12 +62,12 @@ void SurfaceBaseImpl::SwizzleFunc(MortonSwizzleMode mode, u8* memory, const Surf | |||
| 60 | void SurfaceBaseImpl::LoadBuffer(Tegra::MemoryManager& memory_manager, | 62 | void SurfaceBaseImpl::LoadBuffer(Tegra::MemoryManager& memory_manager, |
| 61 | std::vector<u8>& staging_buffer) { | 63 | std::vector<u8>& staging_buffer) { |
| 62 | MICROPROFILE_SCOPE(GPU_Load_Texture); | 64 | MICROPROFILE_SCOPE(GPU_Load_Texture); |
| 63 | auto host_ptr = memory_manager.GetPointer(gpu_addr); | 65 | const auto host_ptr{memory_manager.GetPointer(gpu_addr)}; |
| 64 | if (params.is_tiled) { | 66 | if (params.is_tiled) { |
| 65 | ASSERT_MSG(params.block_width == 1, "Block width is defined as {} on texture target {}", | 67 | ASSERT_MSG(params.block_width == 1, "Block width is defined as {} on texture target {}", |
| 66 | params.block_width, static_cast<u32>(params.target)); | 68 | params.block_width, static_cast<u32>(params.target)); |
| 67 | for (u32 level = 0; level < params.num_levels; ++level) { | 69 | for (u32 level = 0; level < params.num_levels; ++level) { |
| 68 | const u32 host_offset = params.GetHostMipmapLevelOffset(level); | 70 | const std::size_t host_offset{params.GetHostMipmapLevelOffset(level)}; |
| 69 | SwizzleFunc(MortonSwizzleMode::MortonToLinear, host_ptr, params, | 71 | SwizzleFunc(MortonSwizzleMode::MortonToLinear, host_ptr, params, |
| 70 | staging_buffer.data() + host_offset, level); | 72 | staging_buffer.data() + host_offset, level); |
| 71 | } | 73 | } |
| @@ -91,7 +93,7 @@ void SurfaceBaseImpl::LoadBuffer(Tegra::MemoryManager& memory_manager, | |||
| 91 | } | 93 | } |
| 92 | 94 | ||
| 93 | for (u32 level = 0; level < params.num_levels; ++level) { | 95 | for (u32 level = 0; level < params.num_levels; ++level) { |
| 94 | const u32 host_offset = params.GetHostMipmapLevelOffset(level); | 96 | const std::size_t host_offset{params.GetHostMipmapLevelOffset(level)}; |
| 95 | ConvertFromGuestToHost(staging_buffer.data() + host_offset, params.pixel_format, | 97 | ConvertFromGuestToHost(staging_buffer.data() + host_offset, params.pixel_format, |
| 96 | params.GetMipWidth(level), params.GetMipHeight(level), | 98 | params.GetMipWidth(level), params.GetMipHeight(level), |
| 97 | params.GetMipDepth(level), true, true); | 99 | params.GetMipDepth(level), true, true); |
| @@ -105,7 +107,7 @@ void SurfaceBaseImpl::FlushBuffer(Tegra::MemoryManager& memory_manager, | |||
| 105 | if (params.is_tiled) { | 107 | if (params.is_tiled) { |
| 106 | ASSERT_MSG(params.block_width == 1, "Block width is defined as {}", params.block_width); | 108 | ASSERT_MSG(params.block_width == 1, "Block width is defined as {}", params.block_width); |
| 107 | for (u32 level = 0; level < params.num_levels; ++level) { | 109 | for (u32 level = 0; level < params.num_levels; ++level) { |
| 108 | const u32 host_offset = params.GetHostMipmapLevelOffset(level); | 110 | const std::size_t host_offset{params.GetHostMipmapLevelOffset(level)}; |
| 109 | SwizzleFunc(MortonSwizzleMode::LinearToMorton, host_ptr, params, | 111 | SwizzleFunc(MortonSwizzleMode::LinearToMorton, host_ptr, params, |
| 110 | staging_buffer.data() + host_offset, level); | 112 | staging_buffer.data() + host_offset, level); |
| 111 | } | 113 | } |
diff --git a/src/video_core/texture_cache/surface_base.h b/src/video_core/texture_cache/surface_base.h index 029cfb055..7cc122158 100644 --- a/src/video_core/texture_cache/surface_base.h +++ b/src/video_core/texture_cache/surface_base.h | |||
| @@ -78,7 +78,7 @@ public: | |||
| 78 | 78 | ||
| 79 | void SetCacheAddr(const CacheAddr new_addr) { | 79 | void SetCacheAddr(const CacheAddr new_addr) { |
| 80 | cache_addr = new_addr; | 80 | cache_addr = new_addr; |
| 81 | cache_addr_end = new_addr + memory_size; | 81 | cache_addr_end = new_addr + guest_memory_size; |
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | const SurfaceParams& GetSurfaceParams() const { | 84 | const SurfaceParams& GetSurfaceParams() const { |
| @@ -86,7 +86,7 @@ public: | |||
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | std::size_t GetSizeInBytes() const { | 88 | std::size_t GetSizeInBytes() const { |
| 89 | return memory_size; | 89 | return guest_memory_size; |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | std::size_t GetHostSizeInBytes() const { | 92 | std::size_t GetHostSizeInBytes() const { |
| @@ -135,17 +135,19 @@ public: | |||
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | std::optional<std::pair<u32, u32>> GetLayerMipmap(const GPUVAddr candidate_gpu_addr) const { | 137 | std::optional<std::pair<u32, u32>> GetLayerMipmap(const GPUVAddr candidate_gpu_addr) const { |
| 138 | if (candidate_gpu_addr < gpu_addr) | 138 | if (candidate_gpu_addr < gpu_addr) { |
| 139 | return {}; | 139 | return {}; |
| 140 | const GPUVAddr relative_address = candidate_gpu_addr - gpu_addr; | 140 | } |
| 141 | const u32 layer = relative_address / layer_size; | 141 | const auto relative_address{static_cast<GPUVAddr>(candidate_gpu_addr - gpu_addr)}; |
| 142 | const auto layer{static_cast<u32>(relative_address / layer_size)}; | ||
| 142 | const GPUVAddr mipmap_address = relative_address - layer_size * layer; | 143 | const GPUVAddr mipmap_address = relative_address - layer_size * layer; |
| 143 | const auto mipmap_it = | 144 | const auto mipmap_it = |
| 144 | binary_find(mipmap_offsets.begin(), mipmap_offsets.end(), mipmap_address); | 145 | binary_find(mipmap_offsets.begin(), mipmap_offsets.end(), mipmap_address); |
| 145 | if (mipmap_it != mipmap_offsets.end()) { | 146 | if (mipmap_it == mipmap_offsets.end()) { |
| 146 | return {{layer, std::distance(mipmap_offsets.begin(), mipmap_it)}}; | 147 | return {}; |
| 147 | } | 148 | } |
| 148 | return {}; | 149 | const auto level{static_cast<u32>(std::distance(mipmap_offsets.begin(), mipmap_it))}; |
| 150 | return std::make_pair(layer, level); | ||
| 149 | } | 151 | } |
| 150 | 152 | ||
| 151 | std::vector<CopyParams> BreakDown(const SurfaceParams& in_params) const { | 153 | std::vector<CopyParams> BreakDown(const SurfaceParams& in_params) const { |
| @@ -169,7 +171,7 @@ public: | |||
| 169 | 171 | ||
| 170 | } else { | 172 | } else { |
| 171 | result.reserve(mipmaps); | 173 | result.reserve(mipmaps); |
| 172 | for (std::size_t level = 0; level < mipmaps; level++) { | 174 | for (u32 level = 0; level < mipmaps; level++) { |
| 173 | const u32 width{std::min(params.GetMipWidth(level), in_params.GetMipWidth(level))}; | 175 | const u32 width{std::min(params.GetMipWidth(level), in_params.GetMipWidth(level))}; |
| 174 | const u32 height{ | 176 | const u32 height{ |
| 175 | std::min(params.GetMipHeight(level), in_params.GetMipHeight(level))}; | 177 | std::min(params.GetMipHeight(level), in_params.GetMipHeight(level))}; |
| @@ -181,21 +183,22 @@ public: | |||
| 181 | } | 183 | } |
| 182 | 184 | ||
| 183 | protected: | 185 | protected: |
| 184 | explicit SurfaceBaseImpl(const GPUVAddr gpu_vaddr, const SurfaceParams& params); | 186 | explicit SurfaceBaseImpl(GPUVAddr gpu_addr, const SurfaceParams& params); |
| 185 | ~SurfaceBaseImpl() = default; | 187 | ~SurfaceBaseImpl() = default; |
| 186 | 188 | ||
| 187 | virtual void DecorateSurfaceName() = 0; | 189 | virtual void DecorateSurfaceName() = 0; |
| 188 | 190 | ||
| 189 | const SurfaceParams params; | 191 | const SurfaceParams params; |
| 190 | GPUVAddr gpu_addr{}; | ||
| 191 | std::vector<u32> mipmap_sizes; | ||
| 192 | std::vector<u32> mipmap_offsets; | ||
| 193 | const std::size_t layer_size; | 192 | const std::size_t layer_size; |
| 194 | const std::size_t memory_size; | 193 | const std::size_t guest_memory_size; |
| 195 | const std::size_t host_memory_size; | 194 | const std::size_t host_memory_size; |
| 196 | CacheAddr cache_addr; | 195 | GPUVAddr gpu_addr{}; |
| 196 | CacheAddr cache_addr{}; | ||
| 197 | CacheAddr cache_addr_end{}; | 197 | CacheAddr cache_addr_end{}; |
| 198 | VAddr cpu_addr; | 198 | VAddr cpu_addr{}; |
| 199 | |||
| 200 | std::vector<std::size_t> mipmap_sizes; | ||
| 201 | std::vector<std::size_t> mipmap_offsets; | ||
| 199 | 202 | ||
| 200 | private: | 203 | private: |
| 201 | void SwizzleFunc(MortonSwizzleMode mode, u8* memory, const SurfaceParams& params, u8* buffer, | 204 | void SwizzleFunc(MortonSwizzleMode mode, u8* memory, const SurfaceParams& params, u8* buffer, |