diff options
| author | 2021-07-09 02:06:09 +0800 | |
|---|---|---|
| committer | 2021-07-08 11:06:09 -0700 | |
| commit | c7ad195fd3eeea380465be48264f4e69165178c7 (patch) | |
| tree | 77a348320c12feaca4248d090c6d686de7bde39a /src/video_core/texture_cache | |
| parent | Merge pull request #6564 from Kelebek1/Audio (diff) | |
| download | yuzu-c7ad195fd3eeea380465be48264f4e69165178c7.tar.gz yuzu-c7ad195fd3eeea380465be48264f4e69165178c7.tar.xz yuzu-c7ad195fd3eeea380465be48264f4e69165178c7.zip | |
Out of bound blit (#6531)
* Fix out of bound blit error
* Fix code read
* Fix ci error
Co-authored-by: Feng Chen <chen.feng@gloritysolutions.com>
Diffstat (limited to 'src/video_core/texture_cache')
| -rw-r--r-- | src/video_core/texture_cache/texture_cache.h | 71 |
1 files changed, 15 insertions, 56 deletions
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index e3542301e..01de2d498 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -159,9 +159,7 @@ public: | |||
| 159 | /// Blit an image with the given parameters | 159 | /// Blit an image with the given parameters |
| 160 | void BlitImage(const Tegra::Engines::Fermi2D::Surface& dst, | 160 | void BlitImage(const Tegra::Engines::Fermi2D::Surface& dst, |
| 161 | const Tegra::Engines::Fermi2D::Surface& src, | 161 | const Tegra::Engines::Fermi2D::Surface& src, |
| 162 | const Tegra::Engines::Fermi2D::Config& copy, | 162 | const Tegra::Engines::Fermi2D::Config& copy); |
| 163 | std::optional<Region2D> src_region_override = {}, | ||
| 164 | std::optional<Region2D> dst_region_override = {}); | ||
| 165 | 163 | ||
| 166 | /// Invalidate the contents of the color buffer index | 164 | /// Invalidate the contents of the color buffer index |
| 167 | /// These contents become unspecified, the cache can assume aggressive optimizations. | 165 | /// These contents become unspecified, the cache can assume aggressive optimizations. |
| @@ -760,9 +758,7 @@ void TextureCache<P>::UnmapGPUMemory(GPUVAddr gpu_addr, size_t size) { | |||
| 760 | template <class P> | 758 | template <class P> |
| 761 | void TextureCache<P>::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst, | 759 | void TextureCache<P>::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst, |
| 762 | const Tegra::Engines::Fermi2D::Surface& src, | 760 | const Tegra::Engines::Fermi2D::Surface& src, |
| 763 | const Tegra::Engines::Fermi2D::Config& copy, | 761 | const Tegra::Engines::Fermi2D::Config& copy) { |
| 764 | std::optional<Region2D> src_override, | ||
| 765 | std::optional<Region2D> dst_override) { | ||
| 766 | const BlitImages images = GetBlitImages(dst, src); | 762 | const BlitImages images = GetBlitImages(dst, src); |
| 767 | const ImageId dst_id = images.dst_id; | 763 | const ImageId dst_id = images.dst_id; |
| 768 | const ImageId src_id = images.src_id; | 764 | const ImageId src_id = images.src_id; |
| @@ -773,47 +769,25 @@ void TextureCache<P>::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst, | |||
| 773 | const ImageBase& src_image = slot_images[src_id]; | 769 | const ImageBase& src_image = slot_images[src_id]; |
| 774 | 770 | ||
| 775 | // TODO: Deduplicate | 771 | // TODO: Deduplicate |
| 776 | const std::optional dst_base = dst_image.TryFindBase(dst.Address()); | ||
| 777 | const SubresourceRange dst_range{.base = dst_base.value(), .extent = {1, 1}}; | ||
| 778 | const ImageViewInfo dst_view_info(ImageViewType::e2D, images.dst_format, dst_range); | ||
| 779 | const auto [dst_framebuffer_id, dst_view_id] = RenderTargetFromImage(dst_id, dst_view_info); | ||
| 780 | const auto [src_samples_x, src_samples_y] = SamplesLog2(src_image.info.num_samples); | ||
| 781 | |||
| 782 | // out of bounds texture blit checking | ||
| 783 | const bool use_override = src_override.has_value(); | ||
| 784 | const s32 src_x0 = copy.src_x0 >> src_samples_x; | ||
| 785 | s32 src_x1 = use_override ? src_override->end.x : copy.src_x1 >> src_samples_x; | ||
| 786 | const s32 src_y0 = copy.src_y0 >> src_samples_y; | ||
| 787 | const s32 src_y1 = copy.src_y1 >> src_samples_y; | ||
| 788 | |||
| 789 | const auto src_width = static_cast<s32>(src_image.info.size.width); | ||
| 790 | const bool width_oob = src_x1 > src_width; | ||
| 791 | const auto width_diff = width_oob ? src_x1 - src_width : 0; | ||
| 792 | if (width_oob) { | ||
| 793 | src_x1 = src_width; | ||
| 794 | } | ||
| 795 | |||
| 796 | const Region2D src_dimensions{ | ||
| 797 | Offset2D{.x = src_x0, .y = src_y0}, | ||
| 798 | Offset2D{.x = src_x1, .y = src_y1}, | ||
| 799 | }; | ||
| 800 | const auto src_region = use_override ? *src_override : src_dimensions; | ||
| 801 | |||
| 802 | const std::optional src_base = src_image.TryFindBase(src.Address()); | 772 | const std::optional src_base = src_image.TryFindBase(src.Address()); |
| 803 | const SubresourceRange src_range{.base = src_base.value(), .extent = {1, 1}}; | 773 | const SubresourceRange src_range{.base = src_base.value(), .extent = {1, 1}}; |
| 804 | const ImageViewInfo src_view_info(ImageViewType::e2D, images.src_format, src_range); | 774 | const ImageViewInfo src_view_info(ImageViewType::e2D, images.src_format, src_range); |
| 805 | const auto [src_framebuffer_id, src_view_id] = RenderTargetFromImage(src_id, src_view_info); | 775 | const auto [src_framebuffer_id, src_view_id] = RenderTargetFromImage(src_id, src_view_info); |
| 806 | const auto [dst_samples_x, dst_samples_y] = SamplesLog2(dst_image.info.num_samples); | 776 | const auto [src_samples_x, src_samples_y] = SamplesLog2(src_image.info.num_samples); |
| 777 | const Region2D src_region{ | ||
| 778 | Offset2D{.x = copy.src_x0 >> src_samples_x, .y = copy.src_y0 >> src_samples_y}, | ||
| 779 | Offset2D{.x = copy.src_x1 >> src_samples_x, .y = copy.src_y1 >> src_samples_y}, | ||
| 780 | }; | ||
| 807 | 781 | ||
| 808 | const s32 dst_x0 = copy.dst_x0 >> dst_samples_x; | 782 | const std::optional dst_base = dst_image.TryFindBase(dst.Address()); |
| 809 | const s32 dst_x1 = copy.dst_x1 >> dst_samples_x; | 783 | const SubresourceRange dst_range{.base = dst_base.value(), .extent = {1, 1}}; |
| 810 | const s32 dst_y0 = copy.dst_y0 >> dst_samples_y; | 784 | const ImageViewInfo dst_view_info(ImageViewType::e2D, images.dst_format, dst_range); |
| 811 | const s32 dst_y1 = copy.dst_y1 >> dst_samples_y; | 785 | const auto [dst_framebuffer_id, dst_view_id] = RenderTargetFromImage(dst_id, dst_view_info); |
| 812 | const Region2D dst_dimensions{ | 786 | const auto [dst_samples_x, dst_samples_y] = SamplesLog2(dst_image.info.num_samples); |
| 813 | Offset2D{.x = dst_x0, .y = dst_y0}, | 787 | const Region2D dst_region{ |
| 814 | Offset2D{.x = dst_x1 - width_diff, .y = dst_y1}, | 788 | Offset2D{.x = copy.dst_x0 >> dst_samples_x, .y = copy.dst_y0 >> dst_samples_y}, |
| 789 | Offset2D{.x = copy.dst_x1 >> dst_samples_x, .y = copy.dst_y1 >> dst_samples_y}, | ||
| 815 | }; | 790 | }; |
| 816 | const auto dst_region = use_override ? *dst_override : dst_dimensions; | ||
| 817 | 791 | ||
| 818 | // Always call this after src_framebuffer_id was queried, as the address might be invalidated. | 792 | // Always call this after src_framebuffer_id was queried, as the address might be invalidated. |
| 819 | Framebuffer* const dst_framebuffer = &slot_framebuffers[dst_framebuffer_id]; | 793 | Framebuffer* const dst_framebuffer = &slot_framebuffers[dst_framebuffer_id]; |
| @@ -830,21 +804,6 @@ void TextureCache<P>::BlitImage(const Tegra::Engines::Fermi2D::Surface& dst, | |||
| 830 | runtime.BlitImage(dst_framebuffer, dst_view, src_view, dst_region, src_region, copy.filter, | 804 | runtime.BlitImage(dst_framebuffer, dst_view, src_view, dst_region, src_region, copy.filter, |
| 831 | copy.operation); | 805 | copy.operation); |
| 832 | } | 806 | } |
| 833 | |||
| 834 | if (width_oob) { | ||
| 835 | // Continue copy of the oob region of the texture on the next row | ||
| 836 | auto oob_src = src; | ||
| 837 | oob_src.height++; | ||
| 838 | const Region2D src_region_override{ | ||
| 839 | Offset2D{.x = 0, .y = src_y0 + 1}, | ||
| 840 | Offset2D{.x = width_diff, .y = src_y1 + 1}, | ||
| 841 | }; | ||
| 842 | const Region2D dst_region_override{ | ||
| 843 | Offset2D{.x = dst_x1 - width_diff, .y = dst_y0}, | ||
| 844 | Offset2D{.x = dst_x1, .y = dst_y1}, | ||
| 845 | }; | ||
| 846 | BlitImage(dst, oob_src, copy, src_region_override, dst_region_override); | ||
| 847 | } | ||
| 848 | } | 807 | } |
| 849 | 808 | ||
| 850 | template <class P> | 809 | template <class P> |