diff options
| author | 2019-04-11 17:14:55 -0300 | |
|---|---|---|
| committer | 2019-06-20 21:36:11 -0300 | |
| commit | bab21e8cb3df9c06e3c0a37a8fc68fed676f5d6e (patch) | |
| tree | 860ce1a40373ff6002506bef72f78022de7d022c /src/video_core/texture_cache.h | |
| parent | Merge pull request #2596 from FernandoS27/revert-2590 (diff) | |
| download | yuzu-bab21e8cb3df9c06e3c0a37a8fc68fed676f5d6e.tar.gz yuzu-bab21e8cb3df9c06e3c0a37a8fc68fed676f5d6e.tar.xz yuzu-bab21e8cb3df9c06e3c0a37a8fc68fed676f5d6e.zip | |
gl_texture_cache: Initial implementation
Diffstat (limited to 'src/video_core/texture_cache.h')
| -rw-r--r-- | src/video_core/texture_cache.h | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/video_core/texture_cache.h b/src/video_core/texture_cache.h index 041551691..9fd5f074e 100644 --- a/src/video_core/texture_cache.h +++ b/src/video_core/texture_cache.h | |||
| @@ -20,6 +20,7 @@ | |||
| 20 | #include "video_core/engines/fermi_2d.h" | 20 | #include "video_core/engines/fermi_2d.h" |
| 21 | #include "video_core/engines/maxwell_3d.h" | 21 | #include "video_core/engines/maxwell_3d.h" |
| 22 | #include "video_core/gpu.h" | 22 | #include "video_core/gpu.h" |
| 23 | #include "video_core/memory_manager.h" | ||
| 23 | #include "video_core/rasterizer_interface.h" | 24 | #include "video_core/rasterizer_interface.h" |
| 24 | #include "video_core/surface.h" | 25 | #include "video_core/surface.h" |
| 25 | 26 | ||
| @@ -43,6 +44,10 @@ public: | |||
| 43 | 44 | ||
| 44 | bool operator==(const HasheableSurfaceParams& rhs) const; | 45 | bool operator==(const HasheableSurfaceParams& rhs) const; |
| 45 | 46 | ||
| 47 | bool operator!=(const HasheableSurfaceParams& rhs) const { | ||
| 48 | return !operator==(rhs); | ||
| 49 | } | ||
| 50 | |||
| 46 | protected: | 51 | protected: |
| 47 | // Avoid creation outside of a managed environment. | 52 | // Avoid creation outside of a managed environment. |
| 48 | HasheableSurfaceParams() = default; | 53 | HasheableSurfaceParams() = default; |
| @@ -167,12 +172,27 @@ public: | |||
| 167 | /// Returns the offset in bytes in host memory (linear) of a given mipmap level. | 172 | /// Returns the offset in bytes in host memory (linear) of a given mipmap level. |
| 168 | std::size_t GetHostMipmapLevelOffset(u32 level) const; | 173 | std::size_t GetHostMipmapLevelOffset(u32 level) const; |
| 169 | 174 | ||
| 175 | /// Returns the size in bytes in host memory (linear) of a given mipmap level. | ||
| 176 | std::size_t GetHostMipmapSize(u32 level) const; | ||
| 177 | |||
| 170 | /// Returns the size of a layer in bytes in guest memory. | 178 | /// Returns the size of a layer in bytes in guest memory. |
| 171 | std::size_t GetGuestLayerSize() const; | 179 | std::size_t GetGuestLayerSize() const; |
| 172 | 180 | ||
| 173 | /// Returns the size of a layer in bytes in host memory for a given mipmap level. | 181 | /// Returns the size of a layer in bytes in host memory for a given mipmap level. |
| 174 | std::size_t GetHostLayerSize(u32 level) const; | 182 | std::size_t GetHostLayerSize(u32 level) const; |
| 175 | 183 | ||
| 184 | /// Returns the default block width. | ||
| 185 | u32 GetDefaultBlockWidth() const; | ||
| 186 | |||
| 187 | /// Returns the default block height. | ||
| 188 | u32 GetDefaultBlockHeight() const; | ||
| 189 | |||
| 190 | /// Returns the bits per pixel. | ||
| 191 | u32 GetBitsPerPixel() const; | ||
| 192 | |||
| 193 | /// Returns the bytes per pixel. | ||
| 194 | u32 GetBytesPerPixel() const; | ||
| 195 | |||
| 176 | /// Returns true if another surface can be familiar with this. This is a loosely defined term | 196 | /// Returns true if another surface can be familiar with this. This is a loosely defined term |
| 177 | /// that reflects the possibility of these two surface parameters potentially being part of a | 197 | /// that reflects the possibility of these two surface parameters potentially being part of a |
| 178 | /// bigger superset. | 198 | /// bigger superset. |
| @@ -370,6 +390,7 @@ private: | |||
| 370 | template <typename TSurface, typename TView, typename TExecutionContext> | 390 | template <typename TSurface, typename TView, typename TExecutionContext> |
| 371 | class TextureCache { | 391 | class TextureCache { |
| 372 | static_assert(std::is_trivially_copyable_v<TExecutionContext>); | 392 | static_assert(std::is_trivially_copyable_v<TExecutionContext>); |
| 393 | |||
| 373 | using ResultType = std::tuple<TView*, TExecutionContext>; | 394 | using ResultType = std::tuple<TView*, TExecutionContext>; |
| 374 | using IntervalMap = boost::icl::interval_map<CacheAddr, std::set<TSurface*>>; | 395 | using IntervalMap = boost::icl::interval_map<CacheAddr, std::set<TSurface*>>; |
| 375 | using IntervalType = typename IntervalMap::interval_type; | 396 | using IntervalType = typename IntervalMap::interval_type; |
| @@ -583,4 +604,79 @@ private: | |||
| 583 | std::unordered_map<SurfaceParams, std::list<std::unique_ptr<TSurface>>> surface_reserve; | 604 | std::unordered_map<SurfaceParams, std::list<std::unique_ptr<TSurface>>> surface_reserve; |
| 584 | }; | 605 | }; |
| 585 | 606 | ||
| 607 | struct DummyExecutionContext {}; | ||
| 608 | |||
| 609 | template <typename TSurface, typename TView> | ||
| 610 | class TextureCacheContextless : protected TextureCache<TSurface, TView, DummyExecutionContext> { | ||
| 611 | using Base = TextureCache<TSurface, TView, DummyExecutionContext>; | ||
| 612 | |||
| 613 | public: | ||
| 614 | void InvalidateRegion(CacheAddr addr, std::size_t size) { | ||
| 615 | Base::InvalidateRegion(addr, size); | ||
| 616 | } | ||
| 617 | |||
| 618 | TView* GetTextureSurface(const Tegra::Texture::FullTextureInfo& config) { | ||
| 619 | return RemoveContext(Base::GetTextureSurface({}, config)); | ||
| 620 | } | ||
| 621 | |||
| 622 | TView* GetDepthBufferSurface(bool preserve_contents) { | ||
| 623 | return RemoveContext(Base::GetDepthBufferSurface({}, preserve_contents)); | ||
| 624 | } | ||
| 625 | |||
| 626 | TView* GetColorBufferSurface(std::size_t index, bool preserve_contents) { | ||
| 627 | return RemoveContext(Base::GetColorBufferSurface({}, index, preserve_contents)); | ||
| 628 | } | ||
| 629 | |||
| 630 | TView* GetFermiSurface(const Tegra::Engines::Fermi2D::Regs::Surface& config) { | ||
| 631 | return RemoveContext(Base::GetFermiSurface({}, config)); | ||
| 632 | } | ||
| 633 | |||
| 634 | TSurface* TryFindFramebufferSurface(const u8* host_ptr) const { | ||
| 635 | return Base::TryFindFramebufferSurface(host_ptr); | ||
| 636 | } | ||
| 637 | |||
| 638 | protected: | ||
| 639 | explicit TextureCacheContextless(Core::System& system, | ||
| 640 | VideoCore::RasterizerInterface& rasterizer) | ||
| 641 | : TextureCache<TSurface, TView, DummyExecutionContext>{system, rasterizer} {} | ||
| 642 | |||
| 643 | virtual TView* TryFastGetSurfaceView(VAddr cpu_addr, u8* host_ptr, const SurfaceParams& params, | ||
| 644 | bool preserve_contents, | ||
| 645 | const std::vector<TSurface*>& overlaps) = 0; | ||
| 646 | |||
| 647 | private: | ||
| 648 | std::tuple<TView*, DummyExecutionContext> TryFastGetSurfaceView( | ||
| 649 | DummyExecutionContext, VAddr cpu_addr, u8* host_ptr, const SurfaceParams& params, | ||
| 650 | bool preserve_contents, const std::vector<TSurface*>& overlaps) { | ||
| 651 | return {TryFastGetSurfaceView(cpu_addr, host_ptr, params, preserve_contents, overlaps), {}}; | ||
| 652 | } | ||
| 653 | |||
| 654 | TView* RemoveContext(std::tuple<TView*, DummyExecutionContext> return_value) { | ||
| 655 | const auto [view, exctx] = return_value; | ||
| 656 | return view; | ||
| 657 | } | ||
| 658 | }; | ||
| 659 | |||
| 660 | template <typename TView> | ||
| 661 | class SurfaceBaseContextless : public SurfaceBase<TView, DummyExecutionContext> { | ||
| 662 | public: | ||
| 663 | DummyExecutionContext FlushBuffer(DummyExecutionContext) { | ||
| 664 | FlushBufferImpl(); | ||
| 665 | return {}; | ||
| 666 | } | ||
| 667 | |||
| 668 | DummyExecutionContext UploadTexture(DummyExecutionContext) { | ||
| 669 | UploadTextureImpl(); | ||
| 670 | return {}; | ||
| 671 | } | ||
| 672 | |||
| 673 | protected: | ||
| 674 | explicit SurfaceBaseContextless(const SurfaceParams& params) | ||
| 675 | : SurfaceBase<TView, DummyExecutionContext>{params} {} | ||
| 676 | |||
| 677 | virtual void FlushBufferImpl() = 0; | ||
| 678 | |||
| 679 | virtual void UploadTextureImpl() = 0; | ||
| 680 | }; | ||
| 681 | |||
| 586 | } // namespace VideoCommon | 682 | } // namespace VideoCommon |