gpu: Move GPUVAddr definition to common_types.
This commit is contained in:
		
							parent
							
								
									43b83d6b6a
								
							
						
					
					
						commit
						241563d15c
					
				| @ -40,10 +40,9 @@ using s64 = std::int64_t; ///< 64-bit signed int | ||||
| using f32 = float;  ///< 32-bit floating point
 | ||||
| using f64 = double; ///< 64-bit floating point
 | ||||
| 
 | ||||
| // TODO: It would be nice to eventually replace these with strong types that prevent accidental
 | ||||
| // conversion between each other.
 | ||||
| using VAddr = u64; ///< Represents a pointer in the userspace virtual address space.
 | ||||
| using PAddr = u64; ///< Represents a pointer in the ARM11 physical address space.
 | ||||
| using VAddr = u64;    ///< Represents a pointer in the userspace virtual address space.
 | ||||
| using PAddr = u64;    ///< Represents a pointer in the ARM11 physical address space.
 | ||||
| using GPUVAddr = u64; ///< Represents a pointer in the GPU virtual address space.
 | ||||
| 
 | ||||
| using u128 = std::array<std::uint64_t, 2>; | ||||
| static_assert(sizeof(u128) == 16, "u128 must be 128 bits wide"); | ||||
|  | ||||
| @ -89,7 +89,7 @@ u32 nvhost_as_gpu::Remap(const std::vector<u8>& input, std::vector<u8>& output) | ||||
|     for (const auto& entry : entries) { | ||||
|         LOG_WARNING(Service_NVDRV, "remap entry, offset=0x{:X} handle=0x{:X} pages=0x{:X}", | ||||
|                     entry.offset, entry.nvmap_handle, entry.pages); | ||||
|         Tegra::GPUVAddr offset = static_cast<Tegra::GPUVAddr>(entry.offset) << 0x10; | ||||
|         GPUVAddr offset = static_cast<GPUVAddr>(entry.offset) << 0x10; | ||||
|         auto object = nvmap_dev->GetObject(entry.nvmap_handle); | ||||
|         if (!object) { | ||||
|             LOG_CRITICAL(Service_NVDRV, "nvmap {} is an invalid handle!", entry.nvmap_handle); | ||||
| @ -102,7 +102,7 @@ u32 nvhost_as_gpu::Remap(const std::vector<u8>& input, std::vector<u8>& output) | ||||
|         u64 size = static_cast<u64>(entry.pages) << 0x10; | ||||
|         ASSERT(size <= object->size); | ||||
| 
 | ||||
|         Tegra::GPUVAddr returned = gpu.MemoryManager().MapBufferEx(object->addr, offset, size); | ||||
|         GPUVAddr returned = gpu.MemoryManager().MapBufferEx(object->addr, offset, size); | ||||
|         ASSERT(returned == offset); | ||||
|     } | ||||
|     std::memcpy(output.data(), entries.data(), output.size()); | ||||
|  | ||||
| @ -13,9 +13,6 @@ | ||||
| 
 | ||||
| namespace Tegra { | ||||
| 
 | ||||
| /// Virtual addresses in the GPU's memory map are 64 bit.
 | ||||
| using GPUVAddr = u64; | ||||
| 
 | ||||
| class MemoryManager final { | ||||
| public: | ||||
|     MemoryManager(); | ||||
|  | ||||
| @ -21,8 +21,8 @@ CachedBufferEntry::CachedBufferEntry(VAddr cpu_addr, std::size_t size, GLintptr | ||||
| OGLBufferCache::OGLBufferCache(RasterizerOpenGL& rasterizer, std::size_t size) | ||||
|     : RasterizerCache{rasterizer}, stream_buffer(size, true) {} | ||||
| 
 | ||||
| GLintptr OGLBufferCache::UploadMemory(Tegra::GPUVAddr gpu_addr, std::size_t size, | ||||
|                                       std::size_t alignment, bool cache) { | ||||
| GLintptr OGLBufferCache::UploadMemory(GPUVAddr gpu_addr, std::size_t size, std::size_t alignment, | ||||
|                                       bool cache) { | ||||
|     auto& memory_manager = Core::System::GetInstance().GPU().MemoryManager(); | ||||
| 
 | ||||
|     // Cache management is a big overhead, so only cache entries with a given size.
 | ||||
|  | ||||
| @ -58,7 +58,7 @@ public: | ||||
| 
 | ||||
|     /// Uploads data from a guest GPU address. Returns host's buffer offset where it's been
 | ||||
|     /// allocated.
 | ||||
|     GLintptr UploadMemory(Tegra::GPUVAddr gpu_addr, std::size_t size, std::size_t alignment = 4, | ||||
|     GLintptr UploadMemory(GPUVAddr gpu_addr, std::size_t size, std::size_t alignment = 4, | ||||
|                           bool cache = true); | ||||
| 
 | ||||
|     /// Uploads from a host memory. Returns host's buffer offset where it's been allocated.
 | ||||
|  | ||||
| @ -46,7 +46,7 @@ GlobalRegion GlobalRegionCacheOpenGL::TryGetReservedGlobalRegion(CacheAddr addr, | ||||
|     return search->second; | ||||
| } | ||||
| 
 | ||||
| GlobalRegion GlobalRegionCacheOpenGL::GetUncachedGlobalRegion(Tegra::GPUVAddr addr, u32 size, | ||||
| GlobalRegion GlobalRegionCacheOpenGL::GetUncachedGlobalRegion(GPUVAddr addr, u32 size, | ||||
|                                                               u8* host_ptr) { | ||||
|     GlobalRegion region{TryGetReservedGlobalRegion(ToCacheAddr(host_ptr), size)}; | ||||
|     if (!region) { | ||||
|  | ||||
| @ -66,7 +66,7 @@ public: | ||||
| 
 | ||||
| private: | ||||
|     GlobalRegion TryGetReservedGlobalRegion(CacheAddr addr, u32 size) const; | ||||
|     GlobalRegion GetUncachedGlobalRegion(Tegra::GPUVAddr addr, u32 size, u8* host_ptr); | ||||
|     GlobalRegion GetUncachedGlobalRegion(GPUVAddr addr, u32 size, u8* host_ptr); | ||||
|     void ReserveGlobalRegion(GlobalRegion region); | ||||
| 
 | ||||
|     std::unordered_map<CacheAddr, GlobalRegion> reserve; | ||||
|  | ||||
| @ -40,8 +40,7 @@ GLintptr PrimitiveAssembler::MakeQuadArray(u32 first, u32 count) { | ||||
|     return index_offset; | ||||
| } | ||||
| 
 | ||||
| GLintptr PrimitiveAssembler::MakeQuadIndexed(Tegra::GPUVAddr gpu_addr, std::size_t index_size, | ||||
|                                              u32 count) { | ||||
| GLintptr PrimitiveAssembler::MakeQuadIndexed(GPUVAddr gpu_addr, std::size_t index_size, u32 count) { | ||||
|     const std::size_t map_size{CalculateQuadSize(count)}; | ||||
|     auto [dst_pointer, index_offset] = buffer_cache.ReserveMemory(map_size); | ||||
| 
 | ||||
|  | ||||
| @ -24,7 +24,7 @@ public: | ||||
| 
 | ||||
|     GLintptr MakeQuadArray(u32 first, u32 count); | ||||
| 
 | ||||
|     GLintptr MakeQuadIndexed(Tegra::GPUVAddr gpu_addr, std::size_t index_size, u32 count); | ||||
|     GLintptr MakeQuadIndexed(GPUVAddr gpu_addr, std::size_t index_size, u32 count); | ||||
| 
 | ||||
| private: | ||||
|     OGLBufferCache& buffer_cache; | ||||
|  | ||||
| @ -225,8 +225,8 @@ void RasterizerOpenGL::SetupVertexBuffer(GLuint vao) { | ||||
|         if (!vertex_array.IsEnabled()) | ||||
|             continue; | ||||
| 
 | ||||
|         const Tegra::GPUVAddr start = vertex_array.StartAddress(); | ||||
|         const Tegra::GPUVAddr end = regs.vertex_array_limit[index].LimitAddress(); | ||||
|         const GPUVAddr start = vertex_array.StartAddress(); | ||||
|         const GPUVAddr end = regs.vertex_array_limit[index].LimitAddress(); | ||||
| 
 | ||||
|         ASSERT(end > start); | ||||
|         const u64 size = end - start + 1; | ||||
| @ -421,8 +421,8 @@ std::size_t RasterizerOpenGL::CalculateVertexArraysSize() const { | ||||
|         if (!regs.vertex_array[index].IsEnabled()) | ||||
|             continue; | ||||
| 
 | ||||
|         const Tegra::GPUVAddr start = regs.vertex_array[index].StartAddress(); | ||||
|         const Tegra::GPUVAddr end = regs.vertex_array_limit[index].LimitAddress(); | ||||
|         const GPUVAddr start = regs.vertex_array[index].StartAddress(); | ||||
|         const GPUVAddr end = regs.vertex_array_limit[index].LimitAddress(); | ||||
| 
 | ||||
|         ASSERT(end > start); | ||||
|         size += end - start + 1; | ||||
|  | ||||
| @ -55,7 +55,7 @@ static void ApplyTextureDefaults(GLuint texture, u32 max_mip_level) { | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void SurfaceParams::InitCacheParameters(Tegra::GPUVAddr gpu_addr_) { | ||||
| void SurfaceParams::InitCacheParameters(GPUVAddr gpu_addr_) { | ||||
|     auto& memory_manager{Core::System::GetInstance().GPU().MemoryManager()}; | ||||
| 
 | ||||
|     gpu_addr = gpu_addr_; | ||||
| @ -222,7 +222,7 @@ std::size_t SurfaceParams::InnerMemorySize(bool force_gl, bool layer_only, | ||||
| } | ||||
| 
 | ||||
| /*static*/ SurfaceParams SurfaceParams::CreateForDepthBuffer( | ||||
|     u32 zeta_width, u32 zeta_height, Tegra::GPUVAddr zeta_address, Tegra::DepthFormat format, | ||||
|     u32 zeta_width, u32 zeta_height, GPUVAddr zeta_address, Tegra::DepthFormat format, | ||||
|     u32 block_width, u32 block_height, u32 block_depth, | ||||
|     Tegra::Engines::Maxwell3D::Regs::InvMemoryLayout type) { | ||||
|     SurfaceParams params{}; | ||||
| @ -980,11 +980,11 @@ void RasterizerCacheOpenGL::FastLayeredCopySurface(const Surface& src_surface, | ||||
|     const auto& init_params{src_surface->GetSurfaceParams()}; | ||||
|     const auto& dst_params{dst_surface->GetSurfaceParams()}; | ||||
|     auto& memory_manager{Core::System::GetInstance().GPU().MemoryManager()}; | ||||
|     Tegra::GPUVAddr address{init_params.gpu_addr}; | ||||
|     GPUVAddr address{init_params.gpu_addr}; | ||||
|     const std::size_t layer_size{dst_params.LayerMemorySize()}; | ||||
|     for (u32 layer = 0; layer < dst_params.depth; layer++) { | ||||
|         for (u32 mipmap = 0; mipmap < dst_params.max_mip_level; mipmap++) { | ||||
|             const Tegra::GPUVAddr sub_address{address + dst_params.GetMipmapLevelOffset(mipmap)}; | ||||
|             const GPUVAddr sub_address{address + dst_params.GetMipmapLevelOffset(mipmap)}; | ||||
|             const Surface& copy{TryGet(memory_manager.GetPointer(sub_address))}; | ||||
|             if (!copy) { | ||||
|                 continue; | ||||
| @ -1244,10 +1244,9 @@ static std::optional<u32> TryFindBestMipMap(std::size_t memory, const SurfacePar | ||||
|     return {}; | ||||
| } | ||||
| 
 | ||||
| static std::optional<u32> TryFindBestLayer(Tegra::GPUVAddr addr, const SurfaceParams params, | ||||
|                                            u32 mipmap) { | ||||
| static std::optional<u32> TryFindBestLayer(GPUVAddr addr, const SurfaceParams params, u32 mipmap) { | ||||
|     const std::size_t size{params.LayerMemorySize()}; | ||||
|     Tegra::GPUVAddr start{params.gpu_addr + params.GetMipmapLevelOffset(mipmap)}; | ||||
|     GPUVAddr start{params.gpu_addr + params.GetMipmapLevelOffset(mipmap)}; | ||||
|     for (u32 i = 0; i < params.depth; i++) { | ||||
|         if (start == addr) { | ||||
|             return {i}; | ||||
|  | ||||
| @ -210,7 +210,7 @@ struct SurfaceParams { | ||||
| 
 | ||||
|     /// Creates SurfaceParams for a depth buffer configuration
 | ||||
|     static SurfaceParams CreateForDepthBuffer( | ||||
|         u32 zeta_width, u32 zeta_height, Tegra::GPUVAddr zeta_address, Tegra::DepthFormat format, | ||||
|         u32 zeta_width, u32 zeta_height, GPUVAddr zeta_address, Tegra::DepthFormat format, | ||||
|         u32 block_width, u32 block_height, u32 block_depth, | ||||
|         Tegra::Engines::Maxwell3D::Regs::InvMemoryLayout type); | ||||
| 
 | ||||
| @ -232,7 +232,7 @@ struct SurfaceParams { | ||||
|     } | ||||
| 
 | ||||
|     /// Initializes parameters for caching, should be called after everything has been initialized
 | ||||
|     void InitCacheParameters(Tegra::GPUVAddr gpu_addr); | ||||
|     void InitCacheParameters(GPUVAddr gpu_addr); | ||||
| 
 | ||||
|     std::string TargetName() const { | ||||
|         switch (target) { | ||||
| @ -297,7 +297,7 @@ struct SurfaceParams { | ||||
|     bool srgb_conversion; | ||||
|     // Parameters used for caching
 | ||||
|     u8* host_ptr; | ||||
|     Tegra::GPUVAddr gpu_addr; | ||||
|     GPUVAddr gpu_addr; | ||||
|     std::size_t size_in_bytes; | ||||
|     std::size_t size_in_bytes_gl; | ||||
| 
 | ||||
|  | ||||
| @ -32,7 +32,7 @@ struct UnspecializedShader { | ||||
| namespace { | ||||
| 
 | ||||
| /// Gets the address for the specified shader stage program
 | ||||
| Tegra::GPUVAddr GetShaderAddress(Maxwell::ShaderProgram program) { | ||||
| GPUVAddr GetShaderAddress(Maxwell::ShaderProgram program) { | ||||
|     const auto& gpu{Core::System::GetInstance().GPU().Maxwell3D()}; | ||||
|     const auto& shader_config{gpu.regs.shader_config[static_cast<std::size_t>(program)]}; | ||||
|     return gpu.regs.code_address.CodeAddress() + shader_config.offset; | ||||
| @ -486,7 +486,7 @@ Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) { | ||||
|     } | ||||
| 
 | ||||
|     auto& memory_manager{Core::System::GetInstance().GPU().MemoryManager()}; | ||||
|     const Tegra::GPUVAddr program_addr{GetShaderAddress(program)}; | ||||
|     const GPUVAddr program_addr{GetShaderAddress(program)}; | ||||
| 
 | ||||
|     // Look up shader in the cache based on address
 | ||||
|     const auto& host_ptr{memory_manager.GetPointer(program_addr)}; | ||||
|  | ||||
| @ -39,8 +39,7 @@ VKBufferCache::VKBufferCache(Tegra::MemoryManager& tegra_memory_manager, | ||||
| 
 | ||||
| VKBufferCache::~VKBufferCache() = default; | ||||
| 
 | ||||
| u64 VKBufferCache::UploadMemory(Tegra::GPUVAddr gpu_addr, std::size_t size, u64 alignment, | ||||
|                                 bool cache) { | ||||
| u64 VKBufferCache::UploadMemory(GPUVAddr gpu_addr, std::size_t size, u64 alignment, bool cache) { | ||||
|     const auto cpu_addr{tegra_memory_manager.GpuToCpuAddress(gpu_addr)}; | ||||
|     ASSERT_MSG(cpu_addr, "Invalid GPU address"); | ||||
| 
 | ||||
|  | ||||
| @ -68,8 +68,7 @@ public: | ||||
| 
 | ||||
|     /// Uploads data from a guest GPU address. Returns host's buffer offset where it's been
 | ||||
|     /// allocated.
 | ||||
|     u64 UploadMemory(Tegra::GPUVAddr gpu_addr, std::size_t size, u64 alignment = 4, | ||||
|                      bool cache = true); | ||||
|     u64 UploadMemory(GPUVAddr gpu_addr, std::size_t size, u64 alignment = 4, bool cache = true); | ||||
| 
 | ||||
|     /// Uploads from a host memory. Returns host's buffer offset where it's been allocated.
 | ||||
|     u64 UploadHostMemory(const u8* raw_pointer, std::size_t size, u64 alignment = 4); | ||||
|  | ||||
| @ -261,7 +261,7 @@ void GraphicsSurfaceWidget::OnSurfaceSourceChanged(int new_value) { | ||||
| 
 | ||||
| void GraphicsSurfaceWidget::OnSurfaceAddressChanged(qint64 new_value) { | ||||
|     if (surface_address != new_value) { | ||||
|         surface_address = static_cast<Tegra::GPUVAddr>(new_value); | ||||
|         surface_address = static_cast<GPUVAddr>(new_value); | ||||
| 
 | ||||
|         surface_source_list->setCurrentIndex(static_cast<int>(Source::Custom)); | ||||
|         emit Update(); | ||||
|  | ||||
| @ -87,7 +87,7 @@ private: | ||||
|     QPushButton* save_surface; | ||||
| 
 | ||||
|     Source surface_source; | ||||
|     Tegra::GPUVAddr surface_address; | ||||
|     GPUVAddr surface_address; | ||||
|     unsigned surface_width; | ||||
|     unsigned surface_height; | ||||
|     Tegra::Texture::TextureFormat surface_format; | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 bunnei
						bunnei