diff options
| author | 2018-08-20 15:19:59 -0500 | |
|---|---|---|
| committer | 2018-08-20 15:20:35 -0500 | |
| commit | d7c68fbb120c8881b874b4c65efa9ad63a332304 (patch) | |
| tree | 933125eb3faf7f077dd7fcecec30f001a474c1aa /src | |
| parent | Rasterizer: Don't attempt to copy over the old texture's data when doing a fo... (diff) | |
| download | yuzu-d7c68fbb120c8881b874b4c65efa9ad63a332304.tar.gz yuzu-d7c68fbb120c8881b874b4c65efa9ad63a332304.tar.xz yuzu-d7c68fbb120c8881b874b4c65efa9ad63a332304.zip | |
Rasterizer: Reinterpret the raw texture bytes instead of blitting (and thus doing format conversion) to a new texture when a game requests an old texture address with a different format.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 52 |
1 files changed, 49 insertions, 3 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 27bf9ece7..817fa07a8 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | |||
| @@ -798,12 +798,58 @@ Surface RasterizerCacheOpenGL::RecreateSurface(const Surface& surface, | |||
| 798 | // Verify surface is compatible for blitting | 798 | // Verify surface is compatible for blitting |
| 799 | const auto& params{surface->GetSurfaceParams()}; | 799 | const auto& params{surface->GetSurfaceParams()}; |
| 800 | ASSERT(params.type == new_params.type); | 800 | ASSERT(params.type == new_params.type); |
| 801 | ASSERT_MSG(params.GetCompressionFactor(params.pixel_format) == 1, | ||
| 802 | "Compressed texture reinterpretation is not supported"); | ||
| 801 | 803 | ||
| 802 | // Create a new surface with the new parameters, and blit the previous surface to it | 804 | // Create a new surface with the new parameters, and blit the previous surface to it |
| 803 | Surface new_surface{std::make_shared<CachedSurface>(new_params)}; | 805 | Surface new_surface{std::make_shared<CachedSurface>(new_params)}; |
| 804 | BlitTextures(surface->Texture().handle, params.GetRect(), new_surface->Texture().handle, | 806 | |
| 805 | new_surface->GetSurfaceParams().GetRect(), params.type, read_framebuffer.handle, | 807 | auto source_format = GetFormatTuple(params.pixel_format, params.component_type); |
| 806 | draw_framebuffer.handle); | 808 | auto dest_format = GetFormatTuple(new_params.pixel_format, new_params.component_type); |
| 809 | |||
| 810 | size_t buffer_size = std::max(params.SizeInBytes(), new_params.SizeInBytes()); | ||
| 811 | |||
| 812 | // Use a Pixel Buffer Object to download the previous texture and then upload it to the new one | ||
| 813 | // using the new format. | ||
| 814 | OGLBuffer pbo; | ||
| 815 | pbo.Create(); | ||
| 816 | |||
| 817 | glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo.handle); | ||
| 818 | glBufferData(GL_PIXEL_PACK_BUFFER, buffer_size, nullptr, GL_STREAM_DRAW_ARB); | ||
| 819 | glGetTextureImage(surface->Texture().handle, 0, source_format.format, source_format.type, | ||
| 820 | params.SizeInBytes(), nullptr); | ||
| 821 | |||
| 822 | // If the new texture is bigger than the previous one, we need to fill in the rest with data | ||
| 823 | // from the CPU. | ||
| 824 | if (params.SizeInBytes() < new_params.SizeInBytes()) { | ||
| 825 | // Upload the rest of the memory. | ||
| 826 | if (new_params.is_tiled) { | ||
| 827 | // TODO(Subv): We might have to de-tile the subtexture and re-tile it with the rest of | ||
| 828 | // the data in this case. Games like Super Mario Odyssey seem to hit this case when | ||
| 829 | // drawing, it re-uses the memory of a previous texture as a bigger framebuffer but it | ||
| 830 | // doesn't clear it beforehand, the texture is already full of zeros. | ||
| 831 | LOG_CRITICAL(HW_GPU, "Trying to upload extra texture data from the CPU during " | ||
| 832 | "reinterpretation but the texture is tiled."); | ||
| 833 | } | ||
| 834 | size_t remaining_size = new_params.SizeInBytes() - params.SizeInBytes(); | ||
| 835 | auto address = Core::System::GetInstance().GPU().memory_manager->GpuToCpuAddress( | ||
| 836 | new_params.addr + params.SizeInBytes()); | ||
| 837 | std::vector<u8> data(remaining_size); | ||
| 838 | Memory::ReadBlock(*address, data.data(), data.size()); | ||
| 839 | glBufferSubData(GL_PIXEL_PACK_BUFFER, params.SizeInBytes(), remaining_size, data.data()); | ||
| 840 | } | ||
| 841 | |||
| 842 | glBindBuffer(GL_PIXEL_PACK_BUFFER, 0); | ||
| 843 | |||
| 844 | const auto& dest_rect{new_params.GetRect()}; | ||
| 845 | |||
| 846 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo.handle); | ||
| 847 | glTextureSubImage2D( | ||
| 848 | new_surface->Texture().handle, 0, 0, 0, static_cast<GLsizei>(dest_rect.GetWidth()), | ||
| 849 | static_cast<GLsizei>(dest_rect.GetHeight()), dest_format.format, dest_format.type, nullptr); | ||
| 850 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0); | ||
| 851 | |||
| 852 | pbo.Release(); | ||
| 807 | 853 | ||
| 808 | // Update cache accordingly | 854 | // Update cache accordingly |
| 809 | UnregisterSurface(surface); | 855 | UnregisterSurface(surface); |