diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_texture_cache.cpp | 24 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_texture_cache.h | 6 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_rasterizer.cpp | 248 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_rasterizer.h | 5 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.cpp | 22 | ||||
| -rw-r--r-- | src/video_core/renderer_vulkan/vk_texture_cache.h | 6 | ||||
| -rw-r--r-- | src/video_core/texture_cache/texture_cache.h | 86 | ||||
| -rw-r--r-- | src/video_core/texture_cache/texture_cache_base.h | 10 |
8 files changed, 156 insertions, 251 deletions
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.cpp b/src/video_core/renderer_opengl/gl_texture_cache.cpp index b047e7b3d..4b13e807d 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.cpp +++ b/src/video_core/renderer_opengl/gl_texture_cache.cpp | |||
| @@ -762,14 +762,14 @@ Image::Image(const VideoCommon::NullImageParams& params) : VideoCommon::ImageBas | |||
| 762 | 762 | ||
| 763 | Image::~Image() = default; | 763 | Image::~Image() = default; |
| 764 | 764 | ||
| 765 | void Image::UploadMemory(const ImageBufferMap& map, | 765 | void Image::UploadMemory(GLuint buffer_handle, size_t buffer_offset, |
| 766 | std::span<const VideoCommon::BufferImageCopy> copies) { | 766 | std::span<const VideoCommon::BufferImageCopy> copies) { |
| 767 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); | 767 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); |
| 768 | if (is_rescaled) { | 768 | if (is_rescaled) { |
| 769 | ScaleDown(true); | 769 | ScaleDown(true); |
| 770 | } | 770 | } |
| 771 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, map.buffer); | 771 | glBindBuffer(GL_PIXEL_UNPACK_BUFFER, buffer_handle); |
| 772 | glFlushMappedBufferRange(GL_PIXEL_UNPACK_BUFFER, map.offset, unswizzled_size_bytes); | 772 | glFlushMappedBufferRange(GL_PIXEL_UNPACK_BUFFER, buffer_offset, unswizzled_size_bytes); |
| 773 | 773 | ||
| 774 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); | 774 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 775 | 775 | ||
| @@ -788,21 +788,26 @@ void Image::UploadMemory(const ImageBufferMap& map, | |||
| 788 | current_image_height = copy.buffer_image_height; | 788 | current_image_height = copy.buffer_image_height; |
| 789 | glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, current_image_height); | 789 | glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, current_image_height); |
| 790 | } | 790 | } |
| 791 | CopyBufferToImage(copy, map.offset); | 791 | CopyBufferToImage(copy, buffer_offset); |
| 792 | } | 792 | } |
| 793 | if (is_rescaled) { | 793 | if (is_rescaled) { |
| 794 | ScaleUp(); | 794 | ScaleUp(); |
| 795 | } | 795 | } |
| 796 | } | 796 | } |
| 797 | 797 | ||
| 798 | void Image::DownloadMemory(ImageBufferMap& map, | 798 | void Image::UploadMemory(const ImageBufferMap& map, |
| 799 | std::span<const VideoCommon::BufferImageCopy> copies) { | ||
| 800 | UploadMemory(map.buffer, map.offset, copies); | ||
| 801 | } | ||
| 802 | |||
| 803 | void Image::DownloadMemory(GLuint buffer_handle, size_t buffer_offset, | ||
| 799 | std::span<const VideoCommon::BufferImageCopy> copies) { | 804 | std::span<const VideoCommon::BufferImageCopy> copies) { |
| 800 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); | 805 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); |
| 801 | if (is_rescaled) { | 806 | if (is_rescaled) { |
| 802 | ScaleDown(); | 807 | ScaleDown(); |
| 803 | } | 808 | } |
| 804 | glMemoryBarrier(GL_PIXEL_BUFFER_BARRIER_BIT); // TODO: Move this to its own API | 809 | glMemoryBarrier(GL_PIXEL_BUFFER_BARRIER_BIT); // TODO: Move this to its own API |
| 805 | glBindBuffer(GL_PIXEL_PACK_BUFFER, map.buffer); | 810 | glBindBuffer(GL_PIXEL_PACK_BUFFER, buffer_handle); |
| 806 | glPixelStorei(GL_PACK_ALIGNMENT, 1); | 811 | glPixelStorei(GL_PACK_ALIGNMENT, 1); |
| 807 | 812 | ||
| 808 | u32 current_row_length = std::numeric_limits<u32>::max(); | 813 | u32 current_row_length = std::numeric_limits<u32>::max(); |
| @@ -820,13 +825,18 @@ void Image::DownloadMemory(ImageBufferMap& map, | |||
| 820 | current_image_height = copy.buffer_image_height; | 825 | current_image_height = copy.buffer_image_height; |
| 821 | glPixelStorei(GL_PACK_IMAGE_HEIGHT, current_image_height); | 826 | glPixelStorei(GL_PACK_IMAGE_HEIGHT, current_image_height); |
| 822 | } | 827 | } |
| 823 | CopyImageToBuffer(copy, map.offset); | 828 | CopyImageToBuffer(copy, buffer_offset); |
| 824 | } | 829 | } |
| 825 | if (is_rescaled) { | 830 | if (is_rescaled) { |
| 826 | ScaleUp(true); | 831 | ScaleUp(true); |
| 827 | } | 832 | } |
| 828 | } | 833 | } |
| 829 | 834 | ||
| 835 | void Image::DownloadMemory(ImageBufferMap& map, | ||
| 836 | std::span<const VideoCommon::BufferImageCopy> copies) { | ||
| 837 | DownloadMemory(map.buffer, map.offset, copies); | ||
| 838 | } | ||
| 839 | |||
| 830 | GLuint Image::StorageHandle() noexcept { | 840 | GLuint Image::StorageHandle() noexcept { |
| 831 | switch (info.format) { | 841 | switch (info.format) { |
| 832 | case PixelFormat::A8B8G8R8_SRGB: | 842 | case PixelFormat::A8B8G8R8_SRGB: |
diff --git a/src/video_core/renderer_opengl/gl_texture_cache.h b/src/video_core/renderer_opengl/gl_texture_cache.h index e30875496..911e4607a 100644 --- a/src/video_core/renderer_opengl/gl_texture_cache.h +++ b/src/video_core/renderer_opengl/gl_texture_cache.h | |||
| @@ -206,9 +206,15 @@ public: | |||
| 206 | Image(Image&&) = default; | 206 | Image(Image&&) = default; |
| 207 | Image& operator=(Image&&) = default; | 207 | Image& operator=(Image&&) = default; |
| 208 | 208 | ||
| 209 | void UploadMemory(GLuint buffer_handle, size_t buffer_offset, | ||
| 210 | std::span<const VideoCommon::BufferImageCopy> copies); | ||
| 211 | |||
| 209 | void UploadMemory(const ImageBufferMap& map, | 212 | void UploadMemory(const ImageBufferMap& map, |
| 210 | std::span<const VideoCommon::BufferImageCopy> copies); | 213 | std::span<const VideoCommon::BufferImageCopy> copies); |
| 211 | 214 | ||
| 215 | void DownloadMemory(GLuint buffer_handle, size_t buffer_offset, | ||
| 216 | std::span<const VideoCommon::BufferImageCopy> copies); | ||
| 217 | |||
| 212 | void DownloadMemory(ImageBufferMap& map, std::span<const VideoCommon::BufferImageCopy> copies); | 218 | void DownloadMemory(ImageBufferMap& map, std::span<const VideoCommon::BufferImageCopy> copies); |
| 213 | 219 | ||
| 214 | GLuint StorageHandle() noexcept; | 220 | GLuint StorageHandle() noexcept; |
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.cpp b/src/video_core/renderer_vulkan/vk_rasterizer.cpp index f085d53a1..a00cf1569 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.cpp +++ b/src/video_core/renderer_vulkan/vk_rasterizer.cpp | |||
| @@ -770,232 +770,44 @@ bool AccelerateDMA::BufferCopy(GPUVAddr src_address, GPUVAddr dest_address, u64 | |||
| 770 | return buffer_cache.DMACopy(src_address, dest_address, amount); | 770 | return buffer_cache.DMACopy(src_address, dest_address, amount); |
| 771 | } | 771 | } |
| 772 | 772 | ||
| 773 | bool AccelerateDMA::ImageToBuffer(const Tegra::DMA::ImageCopy& copy_info, | 773 | template <bool IS_IMAGE_UPLOAD> |
| 774 | const Tegra::DMA::ImageOperand& src, | 774 | bool AccelerateDMA::DmaBufferImageCopy(const Tegra::DMA::ImageCopy& copy_info, |
| 775 | const Tegra::DMA::BufferOperand& dst) { | 775 | const Tegra::DMA::BufferOperand& buffer_operand, |
| 776 | const Tegra::DMA::ImageOperand& image_operand) { | ||
| 776 | std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex}; | 777 | std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex}; |
| 777 | auto query_image = texture_cache.ObtainImage(src, false); | 778 | const auto image_id = texture_cache.DmaImageId(image_operand); |
| 778 | if (!query_image) { | 779 | if (image_id == VideoCommon::NULL_IMAGE_ID) { |
| 779 | return false; | 780 | return false; |
| 780 | } | 781 | } |
| 781 | auto* image = query_image->first; | 782 | const u32 buffer_size = static_cast<u32>(buffer_operand.pitch * buffer_operand.height); |
| 782 | auto [level, base] = query_image->second; | 783 | static constexpr auto sync_info = VideoCommon::ObtainBufferSynchronize::FullSynchronize; |
| 783 | const u32 buffer_size = static_cast<u32>(dst.pitch * dst.height); | 784 | const auto post_op = IS_IMAGE_UPLOAD ? VideoCommon::ObtainBufferOperation::DoNothing |
| 784 | const auto [buffer, offset] = buffer_cache.ObtainBuffer( | 785 | : VideoCommon::ObtainBufferOperation::MarkAsWritten; |
| 785 | dst.address, buffer_size, VideoCommon::ObtainBufferSynchronize::FullSynchronize, | 786 | const auto [buffer, offset] = |
| 786 | VideoCommon::ObtainBufferOperation::MarkAsWritten); | 787 | buffer_cache.ObtainBuffer(buffer_operand.address, buffer_size, sync_info, post_op); |
| 787 | 788 | ||
| 788 | const bool is_rescaled = image->IsRescaled(); | 789 | const auto [image, copy] = texture_cache.DmaBufferImageCopy( |
| 789 | if (is_rescaled) { | 790 | copy_info, buffer_operand, image_operand, image_id, IS_IMAGE_UPLOAD); |
| 790 | image->ScaleDown(); | 791 | const std::span copy_span{©, 1}; |
| 791 | } | 792 | |
| 792 | VkImageSubresourceLayers subresources{ | 793 | if constexpr (IS_IMAGE_UPLOAD) { |
| 793 | .aspectMask = image->AspectMask(), | 794 | image->UploadMemory(buffer->Handle(), offset, copy_span); |
| 794 | .mipLevel = level, | 795 | } else { |
| 795 | .baseArrayLayer = base, | 796 | image->DownloadMemory(buffer->Handle(), offset, copy_span); |
| 796 | .layerCount = 1, | ||
| 797 | }; | ||
| 798 | const u32 bpp = VideoCore::Surface::BytesPerBlock(image->info.format); | ||
| 799 | const auto convert = [old_bpp = src.bytes_per_pixel, bpp](u32 value) { | ||
| 800 | return (old_bpp * value) / bpp; | ||
| 801 | }; | ||
| 802 | const u32 base_x = convert(src.params.origin.x.Value()); | ||
| 803 | const u32 base_y = src.params.origin.y.Value(); | ||
| 804 | const u32 length_x = convert(copy_info.length_x); | ||
| 805 | const u32 length_y = copy_info.length_y; | ||
| 806 | VkOffset3D image_offset{ | ||
| 807 | .x = static_cast<s32>(base_x), | ||
| 808 | .y = static_cast<s32>(base_y), | ||
| 809 | .z = 0, | ||
| 810 | }; | ||
| 811 | VkExtent3D image_extent{ | ||
| 812 | .width = length_x, | ||
| 813 | .height = length_y, | ||
| 814 | .depth = 1, | ||
| 815 | }; | ||
| 816 | auto buff_info(dst); | ||
| 817 | buff_info.pitch = convert(dst.pitch); | ||
| 818 | scheduler.RequestOutsideRenderPassOperationContext(); | ||
| 819 | scheduler.Record([src_image = image->Handle(), dst_buffer = buffer->Handle(), | ||
| 820 | buffer_offset = offset, subresources, image_offset, image_extent, | ||
| 821 | buff_info](vk::CommandBuffer cmdbuf) { | ||
| 822 | const std::array buffer_copy_info{ | ||
| 823 | VkBufferImageCopy{ | ||
| 824 | .bufferOffset = buffer_offset, | ||
| 825 | .bufferRowLength = buff_info.pitch, | ||
| 826 | .bufferImageHeight = buff_info.height, | ||
| 827 | .imageSubresource = subresources, | ||
| 828 | .imageOffset = image_offset, | ||
| 829 | .imageExtent = image_extent, | ||
| 830 | }, | ||
| 831 | }; | ||
| 832 | const VkImageSubresourceRange range{ | ||
| 833 | .aspectMask = subresources.aspectMask, | ||
| 834 | .baseMipLevel = subresources.mipLevel, | ||
| 835 | .levelCount = 1, | ||
| 836 | .baseArrayLayer = subresources.baseArrayLayer, | ||
| 837 | .layerCount = 1, | ||
| 838 | }; | ||
| 839 | static constexpr VkMemoryBarrier WRITE_BARRIER{ | ||
| 840 | .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, | ||
| 841 | .pNext = nullptr, | ||
| 842 | .srcAccessMask = VK_ACCESS_TRANSFER_WRITE_BIT, | ||
| 843 | .dstAccessMask = VK_ACCESS_MEMORY_READ_BIT | VK_ACCESS_MEMORY_WRITE_BIT, | ||
| 844 | }; | ||
| 845 | const std::array pre_barriers{ | ||
| 846 | VkImageMemoryBarrier{ | ||
| 847 | .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, | ||
| 848 | .pNext = nullptr, | ||
| 849 | .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | | ||
| 850 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | | ||
| 851 | VK_ACCESS_TRANSFER_WRITE_BIT, | ||
| 852 | .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT, | ||
| 853 | .oldLayout = VK_IMAGE_LAYOUT_GENERAL, | ||
| 854 | .newLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, | ||
| 855 | .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 856 | .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 857 | .image = src_image, | ||
| 858 | .subresourceRange = range, | ||
| 859 | }, | ||
| 860 | }; | ||
| 861 | const std::array post_barriers{ | ||
| 862 | VkImageMemoryBarrier{ | ||
| 863 | .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, | ||
| 864 | .pNext = nullptr, | ||
| 865 | .srcAccessMask = 0, | ||
| 866 | .dstAccessMask = 0, | ||
| 867 | .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, | ||
| 868 | .newLayout = VK_IMAGE_LAYOUT_GENERAL, | ||
| 869 | .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 870 | .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 871 | .image = src_image, | ||
| 872 | .subresourceRange = range, | ||
| 873 | }, | ||
| 874 | }; | ||
| 875 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, | ||
| 876 | 0, {}, {}, pre_barriers); | ||
| 877 | cmdbuf.CopyImageToBuffer(src_image, VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL, dst_buffer, | ||
| 878 | buffer_copy_info); | ||
| 879 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, | ||
| 880 | 0, WRITE_BARRIER, nullptr, post_barriers); | ||
| 881 | }); | ||
| 882 | if (is_rescaled) { | ||
| 883 | image->ScaleUp(true); | ||
| 884 | } | 797 | } |
| 885 | return true; | 798 | return true; |
| 886 | } | 799 | } |
| 887 | 800 | ||
| 801 | bool AccelerateDMA::ImageToBuffer(const Tegra::DMA::ImageCopy& copy_info, | ||
| 802 | const Tegra::DMA::ImageOperand& image_operand, | ||
| 803 | const Tegra::DMA::BufferOperand& buffer_operand) { | ||
| 804 | return DmaBufferImageCopy<false>(copy_info, buffer_operand, image_operand); | ||
| 805 | } | ||
| 806 | |||
| 888 | bool AccelerateDMA::BufferToImage(const Tegra::DMA::ImageCopy& copy_info, | 807 | bool AccelerateDMA::BufferToImage(const Tegra::DMA::ImageCopy& copy_info, |
| 889 | const Tegra::DMA::BufferOperand& src, | 808 | const Tegra::DMA::BufferOperand& buffer_operand, |
| 890 | const Tegra::DMA::ImageOperand& dst) { | 809 | const Tegra::DMA::ImageOperand& image_operand) { |
| 891 | std::scoped_lock lock{buffer_cache.mutex, texture_cache.mutex}; | 810 | return DmaBufferImageCopy<true>(copy_info, buffer_operand, image_operand); |
| 892 | auto query_image = texture_cache.ObtainImage(dst, true); | ||
| 893 | if (!query_image) { | ||
| 894 | return false; | ||
| 895 | } | ||
| 896 | auto* image = query_image->first; | ||
| 897 | auto [level, base] = query_image->second; | ||
| 898 | const u32 buffer_size = static_cast<u32>(src.pitch * src.height); | ||
| 899 | const auto [buffer, offset] = buffer_cache.ObtainBuffer( | ||
| 900 | src.address, buffer_size, VideoCommon::ObtainBufferSynchronize::FullSynchronize, | ||
| 901 | VideoCommon::ObtainBufferOperation::DoNothing); | ||
| 902 | const bool is_rescaled = image->IsRescaled(); | ||
| 903 | if (is_rescaled) { | ||
| 904 | image->ScaleDown(true); | ||
| 905 | } | ||
| 906 | VkImageSubresourceLayers subresources{ | ||
| 907 | .aspectMask = image->AspectMask(), | ||
| 908 | .mipLevel = level, | ||
| 909 | .baseArrayLayer = base, | ||
| 910 | .layerCount = 1, | ||
| 911 | }; | ||
| 912 | const u32 bpp = VideoCore::Surface::BytesPerBlock(image->info.format); | ||
| 913 | const auto convert = [old_bpp = dst.bytes_per_pixel, bpp](u32 value) { | ||
| 914 | return (old_bpp * value) / bpp; | ||
| 915 | }; | ||
| 916 | const u32 base_x = convert(dst.params.origin.x.Value()); | ||
| 917 | const u32 base_y = dst.params.origin.y.Value(); | ||
| 918 | const u32 length_x = convert(copy_info.length_x); | ||
| 919 | const u32 length_y = copy_info.length_y; | ||
| 920 | VkOffset3D image_offset{ | ||
| 921 | .x = static_cast<s32>(base_x), | ||
| 922 | .y = static_cast<s32>(base_y), | ||
| 923 | .z = 0, | ||
| 924 | }; | ||
| 925 | VkExtent3D image_extent{ | ||
| 926 | .width = length_x, | ||
| 927 | .height = length_y, | ||
| 928 | .depth = 1, | ||
| 929 | }; | ||
| 930 | auto buff_info(src); | ||
| 931 | buff_info.pitch = convert(src.pitch); | ||
| 932 | scheduler.RequestOutsideRenderPassOperationContext(); | ||
| 933 | scheduler.Record([dst_image = image->Handle(), src_buffer = buffer->Handle(), | ||
| 934 | buffer_offset = offset, subresources, image_offset, image_extent, | ||
| 935 | buff_info](vk::CommandBuffer cmdbuf) { | ||
| 936 | const std::array buffer_copy_info{ | ||
| 937 | VkBufferImageCopy{ | ||
| 938 | .bufferOffset = buffer_offset, | ||
| 939 | .bufferRowLength = buff_info.pitch, | ||
| 940 | .bufferImageHeight = buff_info.height, | ||
| 941 | .imageSubresource = subresources, | ||
| 942 | .imageOffset = image_offset, | ||
| 943 | .imageExtent = image_extent, | ||
| 944 | }, | ||
| 945 | }; | ||
| 946 | const VkImageSubresourceRange range{ | ||
| 947 | .aspectMask = subresources.aspectMask, | ||
| 948 | .baseMipLevel = subresources.mipLevel, | ||
| 949 | .levelCount = 1, | ||
| 950 | .baseArrayLayer = subresources.baseArrayLayer, | ||
| 951 | .layerCount = 1, | ||
| 952 | }; | ||
| 953 | static constexpr VkMemoryBarrier READ_BARRIER{ | ||
| 954 | .sType = VK_STRUCTURE_TYPE_MEMORY_BARRIER, | ||
| 955 | .pNext = nullptr, | ||
| 956 | .srcAccessMask = VK_ACCESS_MEMORY_WRITE_BIT, | ||
| 957 | .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT | VK_ACCESS_TRANSFER_WRITE_BIT, | ||
| 958 | }; | ||
| 959 | const std::array pre_barriers{ | ||
| 960 | VkImageMemoryBarrier{ | ||
| 961 | .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, | ||
| 962 | .pNext = nullptr, | ||
| 963 | .srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT | VK_ACCESS_COLOR_ATTACHMENT_WRITE_BIT | | ||
| 964 | VK_ACCESS_DEPTH_STENCIL_ATTACHMENT_WRITE_BIT | | ||
| 965 | VK_ACCESS_TRANSFER_WRITE_BIT, | ||
| 966 | .dstAccessMask = VK_ACCESS_TRANSFER_READ_BIT, | ||
| 967 | .oldLayout = VK_IMAGE_LAYOUT_GENERAL, | ||
| 968 | .newLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, | ||
| 969 | .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 970 | .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 971 | .image = dst_image, | ||
| 972 | .subresourceRange = range, | ||
| 973 | }, | ||
| 974 | }; | ||
| 975 | const std::array post_barriers{ | ||
| 976 | VkImageMemoryBarrier{ | ||
| 977 | .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, | ||
| 978 | .pNext = nullptr, | ||
| 979 | .srcAccessMask = 0, | ||
| 980 | .dstAccessMask = 0, | ||
| 981 | .oldLayout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL, | ||
| 982 | .newLayout = VK_IMAGE_LAYOUT_GENERAL, | ||
| 983 | .srcQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 984 | .dstQueueFamilyIndex = VK_QUEUE_FAMILY_IGNORED, | ||
| 985 | .image = dst_image, | ||
| 986 | .subresourceRange = range, | ||
| 987 | }, | ||
| 988 | }; | ||
| 989 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, VK_PIPELINE_STAGE_TRANSFER_BIT, | ||
| 990 | 0, READ_BARRIER, {}, pre_barriers); | ||
| 991 | cmdbuf.CopyBufferToImage(src_buffer, dst_image, VK_IMAGE_LAYOUT_GENERAL, buffer_copy_info); | ||
| 992 | cmdbuf.PipelineBarrier(VK_PIPELINE_STAGE_TRANSFER_BIT, VK_PIPELINE_STAGE_ALL_COMMANDS_BIT, | ||
| 993 | 0, nullptr, nullptr, post_barriers); | ||
| 994 | }); | ||
| 995 | if (is_rescaled) { | ||
| 996 | image->ScaleUp(); | ||
| 997 | } | ||
| 998 | return true; | ||
| 999 | } | 811 | } |
| 1000 | 812 | ||
| 1001 | void RasterizerVulkan::UpdateDynamicStates() { | 813 | void RasterizerVulkan::UpdateDynamicStates() { |
diff --git a/src/video_core/renderer_vulkan/vk_rasterizer.h b/src/video_core/renderer_vulkan/vk_rasterizer.h index 7746c5434..1659fbc13 100644 --- a/src/video_core/renderer_vulkan/vk_rasterizer.h +++ b/src/video_core/renderer_vulkan/vk_rasterizer.h | |||
| @@ -59,6 +59,11 @@ public: | |||
| 59 | const Tegra::DMA::ImageOperand& dst) override; | 59 | const Tegra::DMA::ImageOperand& dst) override; |
| 60 | 60 | ||
| 61 | private: | 61 | private: |
| 62 | template <bool IS_IMAGE_UPLOAD> | ||
| 63 | bool DmaBufferImageCopy(const Tegra::DMA::ImageCopy& copy_info, | ||
| 64 | const Tegra::DMA::BufferOperand& src, | ||
| 65 | const Tegra::DMA::ImageOperand& dst); | ||
| 66 | |||
| 62 | BufferCache& buffer_cache; | 67 | BufferCache& buffer_cache; |
| 63 | TextureCache& texture_cache; | 68 | TextureCache& texture_cache; |
| 64 | Scheduler& scheduler; | 69 | Scheduler& scheduler; |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.cpp b/src/video_core/renderer_vulkan/vk_texture_cache.cpp index 8a204f93f..bf6389ff1 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.cpp +++ b/src/video_core/renderer_vulkan/vk_texture_cache.cpp | |||
| @@ -1312,15 +1312,16 @@ Image::Image(const VideoCommon::NullImageParams& params) : VideoCommon::ImageBas | |||
| 1312 | 1312 | ||
| 1313 | Image::~Image() = default; | 1313 | Image::~Image() = default; |
| 1314 | 1314 | ||
| 1315 | void Image::UploadMemory(const StagingBufferRef& map, std::span<const BufferImageCopy> copies) { | 1315 | void Image::UploadMemory(VkBuffer buffer, VkDeviceSize offset, |
| 1316 | std::span<const VideoCommon::BufferImageCopy> copies) { | ||
| 1316 | // TODO: Move this to another API | 1317 | // TODO: Move this to another API |
| 1317 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); | 1318 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); |
| 1318 | if (is_rescaled) { | 1319 | if (is_rescaled) { |
| 1319 | ScaleDown(true); | 1320 | ScaleDown(true); |
| 1320 | } | 1321 | } |
| 1321 | scheduler->RequestOutsideRenderPassOperationContext(); | 1322 | scheduler->RequestOutsideRenderPassOperationContext(); |
| 1322 | std::vector vk_copies = TransformBufferImageCopies(copies, map.offset, aspect_mask); | 1323 | std::vector vk_copies = TransformBufferImageCopies(copies, offset, aspect_mask); |
| 1323 | const VkBuffer src_buffer = map.buffer; | 1324 | const VkBuffer src_buffer = buffer; |
| 1324 | const VkImage vk_image = *original_image; | 1325 | const VkImage vk_image = *original_image; |
| 1325 | const VkImageAspectFlags vk_aspect_mask = aspect_mask; | 1326 | const VkImageAspectFlags vk_aspect_mask = aspect_mask; |
| 1326 | const bool is_initialized = std::exchange(initialized, true); | 1327 | const bool is_initialized = std::exchange(initialized, true); |
| @@ -1333,14 +1334,19 @@ void Image::UploadMemory(const StagingBufferRef& map, std::span<const BufferImag | |||
| 1333 | } | 1334 | } |
| 1334 | } | 1335 | } |
| 1335 | 1336 | ||
| 1336 | void Image::DownloadMemory(const StagingBufferRef& map, std::span<const BufferImageCopy> copies) { | 1337 | void Image::UploadMemory(const StagingBufferRef& map, std::span<const BufferImageCopy> copies) { |
| 1338 | UploadMemory(map.buffer, map.offset, copies); | ||
| 1339 | } | ||
| 1340 | |||
| 1341 | void Image::DownloadMemory(VkBuffer buffer, VkDeviceSize offset, | ||
| 1342 | std::span<const VideoCommon::BufferImageCopy> copies) { | ||
| 1337 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); | 1343 | const bool is_rescaled = True(flags & ImageFlagBits::Rescaled); |
| 1338 | if (is_rescaled) { | 1344 | if (is_rescaled) { |
| 1339 | ScaleDown(); | 1345 | ScaleDown(); |
| 1340 | } | 1346 | } |
| 1341 | std::vector vk_copies = TransformBufferImageCopies(copies, map.offset, aspect_mask); | 1347 | std::vector vk_copies = TransformBufferImageCopies(copies, offset, aspect_mask); |
| 1342 | scheduler->RequestOutsideRenderPassOperationContext(); | 1348 | scheduler->RequestOutsideRenderPassOperationContext(); |
| 1343 | scheduler->Record([buffer = map.buffer, image = *original_image, aspect_mask = aspect_mask, | 1349 | scheduler->Record([buffer, image = *original_image, aspect_mask = aspect_mask, |
| 1344 | vk_copies](vk::CommandBuffer cmdbuf) { | 1350 | vk_copies](vk::CommandBuffer cmdbuf) { |
| 1345 | const VkImageMemoryBarrier read_barrier{ | 1351 | const VkImageMemoryBarrier read_barrier{ |
| 1346 | .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, | 1352 | .sType = VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER, |
| @@ -1395,6 +1401,10 @@ void Image::DownloadMemory(const StagingBufferRef& map, std::span<const BufferIm | |||
| 1395 | } | 1401 | } |
| 1396 | } | 1402 | } |
| 1397 | 1403 | ||
| 1404 | void Image::DownloadMemory(const StagingBufferRef& map, std::span<const BufferImageCopy> copies) { | ||
| 1405 | DownloadMemory(map.buffer, map.offset, copies); | ||
| 1406 | } | ||
| 1407 | |||
| 1398 | bool Image::IsRescaled() const noexcept { | 1408 | bool Image::IsRescaled() const noexcept { |
| 1399 | return True(flags & ImageFlagBits::Rescaled); | 1409 | return True(flags & ImageFlagBits::Rescaled); |
| 1400 | } | 1410 | } |
diff --git a/src/video_core/renderer_vulkan/vk_texture_cache.h b/src/video_core/renderer_vulkan/vk_texture_cache.h index 0ce39616f..d5ee23f8d 100644 --- a/src/video_core/renderer_vulkan/vk_texture_cache.h +++ b/src/video_core/renderer_vulkan/vk_texture_cache.h | |||
| @@ -132,9 +132,15 @@ public: | |||
| 132 | Image(Image&&) = default; | 132 | Image(Image&&) = default; |
| 133 | Image& operator=(Image&&) = default; | 133 | Image& operator=(Image&&) = default; |
| 134 | 134 | ||
| 135 | void UploadMemory(VkBuffer buffer, VkDeviceSize offset, | ||
| 136 | std::span<const VideoCommon::BufferImageCopy> copies); | ||
| 137 | |||
| 135 | void UploadMemory(const StagingBufferRef& map, | 138 | void UploadMemory(const StagingBufferRef& map, |
| 136 | std::span<const VideoCommon::BufferImageCopy> copies); | 139 | std::span<const VideoCommon::BufferImageCopy> copies); |
| 137 | 140 | ||
| 141 | void DownloadMemory(VkBuffer buffer, VkDeviceSize offset, | ||
| 142 | std::span<const VideoCommon::BufferImageCopy> copies); | ||
| 143 | |||
| 138 | void DownloadMemory(const StagingBufferRef& map, | 144 | void DownloadMemory(const StagingBufferRef& map, |
| 139 | std::span<const VideoCommon::BufferImageCopy> copies); | 145 | std::span<const VideoCommon::BufferImageCopy> copies); |
| 140 | 146 | ||
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h index 335338434..8e8b9a5e6 100644 --- a/src/video_core/texture_cache/texture_cache.h +++ b/src/video_core/texture_cache/texture_cache.h | |||
| @@ -745,6 +745,25 @@ void TextureCache<P>::PopAsyncFlushes() { | |||
| 745 | } | 745 | } |
| 746 | 746 | ||
| 747 | template <class P> | 747 | template <class P> |
| 748 | ImageId TextureCache<P>::DmaImageId(const Tegra::DMA::ImageOperand& operand) { | ||
| 749 | const ImageInfo dst_info(operand); | ||
| 750 | const ImageId dst_id = FindDMAImage(dst_info, operand.address); | ||
| 751 | if (!dst_id) { | ||
| 752 | return NULL_IMAGE_ID; | ||
| 753 | } | ||
| 754 | const auto& image = slot_images[dst_id]; | ||
| 755 | if (False(image.flags & ImageFlagBits::GpuModified)) { | ||
| 756 | // No need to waste time on an image that's synced with guest | ||
| 757 | return NULL_IMAGE_ID; | ||
| 758 | } | ||
| 759 | const auto base = image.TryFindBase(operand.address); | ||
| 760 | if (!base) { | ||
| 761 | return NULL_IMAGE_ID; | ||
| 762 | } | ||
| 763 | return dst_id; | ||
| 764 | } | ||
| 765 | |||
| 766 | template <class P> | ||
| 748 | bool TextureCache<P>::IsRescaling() const noexcept { | 767 | bool TextureCache<P>::IsRescaling() const noexcept { |
| 749 | return is_rescaling; | 768 | return is_rescaling; |
| 750 | } | 769 | } |
| @@ -772,6 +791,49 @@ bool TextureCache<P>::IsRegionGpuModified(VAddr addr, size_t size) { | |||
| 772 | } | 791 | } |
| 773 | 792 | ||
| 774 | template <class P> | 793 | template <class P> |
| 794 | std::pair<typename TextureCache<P>::Image*, BufferImageCopy> TextureCache<P>::DmaBufferImageCopy( | ||
| 795 | const Tegra::DMA::ImageCopy& copy_info, const Tegra::DMA::BufferOperand& buffer_operand, | ||
| 796 | const Tegra::DMA::ImageOperand& image_operand, ImageId image_id, bool modifies_image) { | ||
| 797 | const auto [level, base] = PrepareDmaImage(image_id, image_operand.address, modifies_image); | ||
| 798 | auto* image = &slot_images[image_id]; | ||
| 799 | const u32 buffer_size = static_cast<u32>(buffer_operand.pitch * buffer_operand.height); | ||
| 800 | const u32 bpp = VideoCore::Surface::BytesPerBlock(image->info.format); | ||
| 801 | const auto convert = [old_bpp = image_operand.bytes_per_pixel, bpp](u32 value) { | ||
| 802 | return (old_bpp * value) / bpp; | ||
| 803 | }; | ||
| 804 | const u32 base_x = convert(image_operand.params.origin.x.Value()); | ||
| 805 | const u32 base_y = image_operand.params.origin.y.Value(); | ||
| 806 | const u32 length_x = convert(copy_info.length_x); | ||
| 807 | const u32 length_y = copy_info.length_y; | ||
| 808 | |||
| 809 | const BufferImageCopy copy{ | ||
| 810 | .buffer_offset = 0, | ||
| 811 | .buffer_size = buffer_size, | ||
| 812 | .buffer_row_length = convert(buffer_operand.pitch), | ||
| 813 | .buffer_image_height = buffer_operand.height, | ||
| 814 | .image_subresource = | ||
| 815 | { | ||
| 816 | .base_level = static_cast<s32>(level), | ||
| 817 | .base_layer = static_cast<s32>(base), | ||
| 818 | .num_layers = 1, | ||
| 819 | }, | ||
| 820 | .image_offset = | ||
| 821 | { | ||
| 822 | .x = static_cast<s32>(base_x), | ||
| 823 | .y = static_cast<s32>(base_y), | ||
| 824 | .z = 0, | ||
| 825 | }, | ||
| 826 | .image_extent = | ||
| 827 | { | ||
| 828 | .width = length_x, | ||
| 829 | .height = length_y, | ||
| 830 | .depth = 1, | ||
| 831 | }, | ||
| 832 | }; | ||
| 833 | return {image, copy}; | ||
| 834 | } | ||
| 835 | |||
| 836 | template <class P> | ||
| 775 | void TextureCache<P>::RefreshContents(Image& image, ImageId image_id) { | 837 | void TextureCache<P>::RefreshContents(Image& image, ImageId image_id) { |
| 776 | if (False(image.flags & ImageFlagBits::CpuModified)) { | 838 | if (False(image.flags & ImageFlagBits::CpuModified)) { |
| 777 | // Only upload modified images | 839 | // Only upload modified images |
| @@ -1405,26 +1467,14 @@ ImageId TextureCache<P>::FindDMAImage(const ImageInfo& info, GPUVAddr gpu_addr) | |||
| 1405 | } | 1467 | } |
| 1406 | 1468 | ||
| 1407 | template <class P> | 1469 | template <class P> |
| 1408 | std::optional<std::pair<typename TextureCache<P>::Image*, std::pair<u32, u32>>> | 1470 | std::pair<u32, u32> TextureCache<P>::PrepareDmaImage(ImageId dst_id, GPUVAddr base_addr, |
| 1409 | TextureCache<P>::ObtainImage(const Tegra::DMA::ImageOperand& operand, bool mark_as_modified) { | 1471 | bool mark_as_modified) { |
| 1410 | ImageInfo dst_info(operand); | 1472 | const auto& image = slot_images[dst_id]; |
| 1411 | ImageId dst_id = FindDMAImage(dst_info, operand.address); | 1473 | const auto base = image.TryFindBase(base_addr); |
| 1412 | if (!dst_id) { | ||
| 1413 | return std::nullopt; | ||
| 1414 | } | ||
| 1415 | auto& image = slot_images[dst_id]; | ||
| 1416 | auto base = image.TryFindBase(operand.address); | ||
| 1417 | if (!base) { | ||
| 1418 | return std::nullopt; | ||
| 1419 | } | ||
| 1420 | if (False(image.flags & ImageFlagBits::GpuModified)) { | ||
| 1421 | // No need to waste time on an image that's synced with guest | ||
| 1422 | return std::nullopt; | ||
| 1423 | } | ||
| 1424 | PrepareImage(dst_id, mark_as_modified, false); | 1474 | PrepareImage(dst_id, mark_as_modified, false); |
| 1425 | auto& new_image = slot_images[dst_id]; | 1475 | const auto& new_image = slot_images[dst_id]; |
| 1426 | lru_cache.Touch(new_image.lru_index, frame_tick); | 1476 | lru_cache.Touch(new_image.lru_index, frame_tick); |
| 1427 | return std::make_pair(&new_image, std::make_pair(base->level, base->layer)); | 1477 | return std::make_pair(base->level, base->layer); |
| 1428 | } | 1478 | } |
| 1429 | 1479 | ||
| 1430 | template <class P> | 1480 | template <class P> |
diff --git a/src/video_core/texture_cache/texture_cache_base.h b/src/video_core/texture_cache/texture_cache_base.h index 848a5d9ea..5a5b4179c 100644 --- a/src/video_core/texture_cache/texture_cache_base.h +++ b/src/video_core/texture_cache/texture_cache_base.h | |||
| @@ -209,8 +209,11 @@ public: | |||
| 209 | /// Pop asynchronous downloads | 209 | /// Pop asynchronous downloads |
| 210 | void PopAsyncFlushes(); | 210 | void PopAsyncFlushes(); |
| 211 | 211 | ||
| 212 | [[nodiscard]] std::optional<std::pair<Image*, std::pair<u32, u32>>> ObtainImage( | 212 | [[nodiscard]] ImageId DmaImageId(const Tegra::DMA::ImageOperand& operand); |
| 213 | const Tegra::DMA::ImageOperand& operand, bool mark_as_modified); | 213 | |
| 214 | [[nodiscard]] std::pair<Image*, BufferImageCopy> DmaBufferImageCopy( | ||
| 215 | const Tegra::DMA::ImageCopy& copy_info, const Tegra::DMA::BufferOperand& buffer_operand, | ||
| 216 | const Tegra::DMA::ImageOperand& image_operand, ImageId image_id, bool modifies_image); | ||
| 214 | 217 | ||
| 215 | /// Return true when a CPU region is modified from the GPU | 218 | /// Return true when a CPU region is modified from the GPU |
| 216 | [[nodiscard]] bool IsRegionGpuModified(VAddr addr, size_t size); | 219 | [[nodiscard]] bool IsRegionGpuModified(VAddr addr, size_t size); |
| @@ -386,6 +389,9 @@ private: | |||
| 386 | /// Returns true if the current clear parameters clear the whole image of a given image view | 389 | /// Returns true if the current clear parameters clear the whole image of a given image view |
| 387 | [[nodiscard]] bool IsFullClear(ImageViewId id); | 390 | [[nodiscard]] bool IsFullClear(ImageViewId id); |
| 388 | 391 | ||
| 392 | [[nodiscard]] std::pair<u32, u32> PrepareDmaImage(ImageId dst_id, GPUVAddr base_addr, | ||
| 393 | bool mark_as_modified); | ||
| 394 | |||
| 389 | bool ImageCanRescale(ImageBase& image); | 395 | bool ImageCanRescale(ImageBase& image); |
| 390 | void InvalidateScale(Image& image); | 396 | void InvalidateScale(Image& image); |
| 391 | bool ScaleUp(Image& image); | 397 | bool ScaleUp(Image& image); |