summaryrefslogtreecommitdiff
path: root/src/video_core/texture_cache
diff options
context:
space:
mode:
authorGravatar bunnei2021-07-25 11:39:04 -0700
committerGravatar GitHub2021-07-25 11:39:04 -0700
commit98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f (patch)
tree816faa96c2c4d291825063433331a8ea4b3d08f1 /src/video_core/texture_cache
parentMerge pull request #6699 from lat9nq/common-threads (diff)
parentshader: Support out of bound local memory reads and immediate writes (diff)
downloadyuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.tar.gz
yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.tar.xz
yuzu-98b26b6e126d4775fdf3f773fe8a8ac808a8ff8f.zip
Merge pull request #6585 from ameerj/hades
Shader Decompiler Rewrite
Diffstat (limited to 'src/video_core/texture_cache')
-rw-r--r--src/video_core/texture_cache/formatter.cpp4
-rw-r--r--src/video_core/texture_cache/formatter.h3
-rw-r--r--src/video_core/texture_cache/image_view_base.cpp9
-rw-r--r--src/video_core/texture_cache/image_view_base.h1
-rw-r--r--src/video_core/texture_cache/texture_cache.h35
5 files changed, 37 insertions, 15 deletions
diff --git a/src/video_core/texture_cache/formatter.cpp b/src/video_core/texture_cache/formatter.cpp
index d10ba4ccd..249cc4d0f 100644
--- a/src/video_core/texture_cache/formatter.cpp
+++ b/src/video_core/texture_cache/formatter.cpp
@@ -43,7 +43,7 @@ std::string Name(const ImageBase& image) {
43 return "Invalid"; 43 return "Invalid";
44} 44}
45 45
46std::string Name(const ImageViewBase& image_view, std::optional<ImageViewType> type) { 46std::string Name(const ImageViewBase& image_view) {
47 const u32 width = image_view.size.width; 47 const u32 width = image_view.size.width;
48 const u32 height = image_view.size.height; 48 const u32 height = image_view.size.height;
49 const u32 depth = image_view.size.depth; 49 const u32 depth = image_view.size.depth;
@@ -51,7 +51,7 @@ std::string Name(const ImageViewBase& image_view, std::optional<ImageViewType> t
51 const u32 num_layers = image_view.range.extent.layers; 51 const u32 num_layers = image_view.range.extent.layers;
52 52
53 const std::string level = num_levels > 1 ? fmt::format(":{}", num_levels) : ""; 53 const std::string level = num_levels > 1 ? fmt::format(":{}", num_levels) : "";
54 switch (type.value_or(image_view.type)) { 54 switch (image_view.type) {
55 case ImageViewType::e1D: 55 case ImageViewType::e1D:
56 return fmt::format("ImageView 1D {}{}", width, level); 56 return fmt::format("ImageView 1D {}{}", width, level);
57 case ImageViewType::e2D: 57 case ImageViewType::e2D:
diff --git a/src/video_core/texture_cache/formatter.h b/src/video_core/texture_cache/formatter.h
index a48413983..c6cf0583f 100644
--- a/src/video_core/texture_cache/formatter.h
+++ b/src/video_core/texture_cache/formatter.h
@@ -255,8 +255,7 @@ struct RenderTargets;
255 255
256[[nodiscard]] std::string Name(const ImageBase& image); 256[[nodiscard]] std::string Name(const ImageBase& image);
257 257
258[[nodiscard]] std::string Name(const ImageViewBase& image_view, 258[[nodiscard]] std::string Name(const ImageViewBase& image_view);
259 std::optional<ImageViewType> type = std::nullopt);
260 259
261[[nodiscard]] std::string Name(const RenderTargets& render_targets); 260[[nodiscard]] std::string Name(const RenderTargets& render_targets);
262 261
diff --git a/src/video_core/texture_cache/image_view_base.cpp b/src/video_core/texture_cache/image_view_base.cpp
index e8d632f9e..450becbeb 100644
--- a/src/video_core/texture_cache/image_view_base.cpp
+++ b/src/video_core/texture_cache/image_view_base.cpp
@@ -36,6 +36,15 @@ ImageViewBase::ImageViewBase(const ImageViewInfo& info, const ImageInfo& image_i
36 } 36 }
37} 37}
38 38
39ImageViewBase::ImageViewBase(const ImageInfo& info, const ImageViewInfo& view_info)
40 : format{info.format}, type{ImageViewType::Buffer}, size{
41 .width = info.size.width,
42 .height = 1,
43 .depth = 1,
44 } {
45 ASSERT_MSG(view_info.type == ImageViewType::Buffer, "Expected texture buffer");
46}
47
39ImageViewBase::ImageViewBase(const NullImageParams&) {} 48ImageViewBase::ImageViewBase(const NullImageParams&) {}
40 49
41} // namespace VideoCommon 50} // namespace VideoCommon
diff --git a/src/video_core/texture_cache/image_view_base.h b/src/video_core/texture_cache/image_view_base.h
index 73954167e..903f715c5 100644
--- a/src/video_core/texture_cache/image_view_base.h
+++ b/src/video_core/texture_cache/image_view_base.h
@@ -27,6 +27,7 @@ DECLARE_ENUM_FLAG_OPERATORS(ImageViewFlagBits)
27struct ImageViewBase { 27struct ImageViewBase {
28 explicit ImageViewBase(const ImageViewInfo& info, const ImageInfo& image_info, 28 explicit ImageViewBase(const ImageViewInfo& info, const ImageInfo& image_info,
29 ImageId image_id); 29 ImageId image_id);
30 explicit ImageViewBase(const ImageInfo& info, const ImageViewInfo& view_info);
30 explicit ImageViewBase(const NullImageParams&); 31 explicit ImageViewBase(const NullImageParams&);
31 32
32 [[nodiscard]] bool IsBuffer() const noexcept { 33 [[nodiscard]] bool IsBuffer() const noexcept {
diff --git a/src/video_core/texture_cache/texture_cache.h b/src/video_core/texture_cache/texture_cache.h
index 85ce06d56..f34c9d9ca 100644
--- a/src/video_core/texture_cache/texture_cache.h
+++ b/src/video_core/texture_cache/texture_cache.h
@@ -117,6 +117,9 @@ public:
117 /// Return a reference to the given image view id 117 /// Return a reference to the given image view id
118 [[nodiscard]] ImageView& GetImageView(ImageViewId id) noexcept; 118 [[nodiscard]] ImageView& GetImageView(ImageViewId id) noexcept;
119 119
120 /// Mark an image as modified from the GPU
121 void MarkModification(ImageId id) noexcept;
122
120 /// Fill image_view_ids with the graphics images in indices 123 /// Fill image_view_ids with the graphics images in indices
121 void FillGraphicsImageViews(std::span<const u32> indices, 124 void FillGraphicsImageViews(std::span<const u32> indices,
122 std::span<ImageViewId> image_view_ids); 125 std::span<ImageViewId> image_view_ids);
@@ -527,6 +530,11 @@ typename P::ImageView& TextureCache<P>::GetImageView(ImageViewId id) noexcept {
527} 530}
528 531
529template <class P> 532template <class P>
533void TextureCache<P>::MarkModification(ImageId id) noexcept {
534 MarkModification(slot_images[id]);
535}
536
537template <class P>
530void TextureCache<P>::FillGraphicsImageViews(std::span<const u32> indices, 538void TextureCache<P>::FillGraphicsImageViews(std::span<const u32> indices,
531 std::span<ImageViewId> image_view_ids) { 539 std::span<ImageViewId> image_view_ids) {
532 FillImageViews(graphics_image_table, graphics_image_view_ids, indices, image_view_ids); 540 FillImageViews(graphics_image_table, graphics_image_view_ids, indices, image_view_ids);
@@ -540,13 +548,13 @@ void TextureCache<P>::FillComputeImageViews(std::span<const u32> indices,
540 548
541template <class P> 549template <class P>
542typename P::Sampler* TextureCache<P>::GetGraphicsSampler(u32 index) { 550typename P::Sampler* TextureCache<P>::GetGraphicsSampler(u32 index) {
543 [[unlikely]] if (index > graphics_sampler_table.Limit()) { 551 if (index > graphics_sampler_table.Limit()) {
544 LOG_ERROR(HW_GPU, "Invalid sampler index={}", index); 552 LOG_DEBUG(HW_GPU, "Invalid sampler index={}", index);
545 return &slot_samplers[NULL_SAMPLER_ID]; 553 return &slot_samplers[NULL_SAMPLER_ID];
546 } 554 }
547 const auto [descriptor, is_new] = graphics_sampler_table.Read(index); 555 const auto [descriptor, is_new] = graphics_sampler_table.Read(index);
548 SamplerId& id = graphics_sampler_ids[index]; 556 SamplerId& id = graphics_sampler_ids[index];
549 [[unlikely]] if (is_new) { 557 if (is_new) {
550 id = FindSampler(descriptor); 558 id = FindSampler(descriptor);
551 } 559 }
552 return &slot_samplers[id]; 560 return &slot_samplers[id];
@@ -554,13 +562,13 @@ typename P::Sampler* TextureCache<P>::GetGraphicsSampler(u32 index) {
554 562
555template <class P> 563template <class P>
556typename P::Sampler* TextureCache<P>::GetComputeSampler(u32 index) { 564typename P::Sampler* TextureCache<P>::GetComputeSampler(u32 index) {
557 [[unlikely]] if (index > compute_sampler_table.Limit()) { 565 if (index > compute_sampler_table.Limit()) {
558 LOG_ERROR(HW_GPU, "Invalid sampler index={}", index); 566 LOG_DEBUG(HW_GPU, "Invalid sampler index={}", index);
559 return &slot_samplers[NULL_SAMPLER_ID]; 567 return &slot_samplers[NULL_SAMPLER_ID];
560 } 568 }
561 const auto [descriptor, is_new] = compute_sampler_table.Read(index); 569 const auto [descriptor, is_new] = compute_sampler_table.Read(index);
562 SamplerId& id = compute_sampler_ids[index]; 570 SamplerId& id = compute_sampler_ids[index];
563 [[unlikely]] if (is_new) { 571 if (is_new) {
564 id = FindSampler(descriptor); 572 id = FindSampler(descriptor);
565 } 573 }
566 return &slot_samplers[id]; 574 return &slot_samplers[id];
@@ -661,7 +669,7 @@ ImageViewId TextureCache<P>::VisitImageView(DescriptorTable<TICEntry>& table,
661 std::span<ImageViewId> cached_image_view_ids, 669 std::span<ImageViewId> cached_image_view_ids,
662 u32 index) { 670 u32 index) {
663 if (index > table.Limit()) { 671 if (index > table.Limit()) {
664 LOG_ERROR(HW_GPU, "Invalid image view index={}", index); 672 LOG_DEBUG(HW_GPU, "Invalid image view index={}", index);
665 return NULL_IMAGE_VIEW_ID; 673 return NULL_IMAGE_VIEW_ID;
666 } 674 }
667 const auto [descriptor, is_new] = table.Read(index); 675 const auto [descriptor, is_new] = table.Read(index);
@@ -968,9 +976,6 @@ void TextureCache<P>::UploadImageContents(Image& image, StagingBuffer& staging)
968 auto copies = UnswizzleImage(gpu_memory, gpu_addr, image.info, unswizzled_data); 976 auto copies = UnswizzleImage(gpu_memory, gpu_addr, image.info, unswizzled_data);
969 ConvertImage(unswizzled_data, image.info, mapped_span, copies); 977 ConvertImage(unswizzled_data, image.info, mapped_span, copies);
970 image.UploadMemory(staging, copies); 978 image.UploadMemory(staging, copies);
971 } else if (image.info.type == ImageType::Buffer) {
972 const std::array copies{UploadBufferCopy(gpu_memory, gpu_addr, image, mapped_span)};
973 image.UploadMemory(staging, copies);
974 } else { 979 } else {
975 const auto copies = UnswizzleImage(gpu_memory, gpu_addr, image.info, mapped_span); 980 const auto copies = UnswizzleImage(gpu_memory, gpu_addr, image.info, mapped_span);
976 image.UploadMemory(staging, copies); 981 image.UploadMemory(staging, copies);
@@ -993,7 +998,12 @@ ImageViewId TextureCache<P>::FindImageView(const TICEntry& config) {
993template <class P> 998template <class P>
994ImageViewId TextureCache<P>::CreateImageView(const TICEntry& config) { 999ImageViewId TextureCache<P>::CreateImageView(const TICEntry& config) {
995 const ImageInfo info(config); 1000 const ImageInfo info(config);
996 const GPUVAddr image_gpu_addr = config.Address() - config.BaseLayer() * info.layer_stride; 1001 if (info.type == ImageType::Buffer) {
1002 const ImageViewInfo view_info(config, 0);
1003 return slot_image_views.insert(runtime, info, view_info, config.Address());
1004 }
1005 const u32 layer_offset = config.BaseLayer() * info.layer_stride;
1006 const GPUVAddr image_gpu_addr = config.Address() - layer_offset;
997 const ImageId image_id = FindOrInsertImage(info, image_gpu_addr); 1007 const ImageId image_id = FindOrInsertImage(info, image_gpu_addr);
998 if (!image_id) { 1008 if (!image_id) {
999 return NULL_IMAGE_VIEW_ID; 1009 return NULL_IMAGE_VIEW_ID;
@@ -1801,6 +1811,9 @@ void TextureCache<P>::PrepareImageView(ImageViewId image_view_id, bool is_modifi
1801 return; 1811 return;
1802 } 1812 }
1803 const ImageViewBase& image_view = slot_image_views[image_view_id]; 1813 const ImageViewBase& image_view = slot_image_views[image_view_id];
1814 if (image_view.IsBuffer()) {
1815 return;
1816 }
1804 PrepareImage(image_view.image_id, is_modification, invalidate); 1817 PrepareImage(image_view.image_id, is_modification, invalidate);
1805} 1818}
1806 1819