mirror of
https://github.com/Takiiiiiiii/strato.git
synced 2025-07-17 08:46:39 +00:00
Rework GPU VMM variable naming
This commit is contained in:
@ -11,30 +11,30 @@ namespace skyline {
|
||||
}
|
||||
|
||||
namespace gpu::vmm {
|
||||
enum ChunkState {
|
||||
enum class ChunkState {
|
||||
Unmapped, //!< The chunk is unmapped
|
||||
Reserved, //!< The chunk is reserved
|
||||
Mapped //!< The chunk is mapped and a CPU side address is present
|
||||
};
|
||||
|
||||
struct ChunkDescriptor {
|
||||
u64 address; //!< The address of the chunk in the GPU address space
|
||||
u64 virtAddr; //!< The address of the chunk in the virtual address space
|
||||
u64 size; //!< The size of the chunk in bytes
|
||||
u8 *pointer; //!< A pointer to the chunk in the CPU address space (if mapped)
|
||||
u8 *cpuPtr; //!< A pointer to the chunk in the application's address space (if mapped)
|
||||
ChunkState state;
|
||||
|
||||
ChunkDescriptor(u64 address, u64 size, u8 *pointer, ChunkState state) : address(address), size(size), pointer(pointer), state(state) {}
|
||||
ChunkDescriptor(u64 virtAddr, u64 size, u8 *cpuPtr, ChunkState state) : virtAddr(virtAddr), size(size), cpuPtr(cpuPtr), state(state) {}
|
||||
|
||||
/**
|
||||
* @return If the given chunk can be contained wholly within this chunk
|
||||
*/
|
||||
inline bool CanContain(const ChunkDescriptor &chunk) {
|
||||
return (chunk.address >= this->address) && ((this->size + this->address) >= (chunk.size + chunk.address));
|
||||
return (chunk.virtAddr >= this->virtAddr) && ((this->size + this->virtAddr) >= (chunk.size + chunk.virtAddr));
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The MemoryManager class handles the mapping of the GPU address space
|
||||
* @brief The MemoryManager class handles mapping between a virtual address space and an application's address space
|
||||
*/
|
||||
class MemoryManager {
|
||||
private:
|
||||
@ -42,18 +42,18 @@ namespace skyline {
|
||||
std::vector<ChunkDescriptor> chunks;
|
||||
|
||||
/**
|
||||
* @brief Finds a chunk of the specified type in the GPU address space that is larger than the given size
|
||||
* @brief Finds a chunk in the virtual address space that is larger than meets the given requirements
|
||||
* @param state The state of the chunk to find
|
||||
* @param size The minimum size of the chunk to find
|
||||
* @param alignment The alignment of the chunk to find
|
||||
* @return The first unmapped chunk in the GPU address space that fulfils the requested conditions
|
||||
* @param alignment The minimum alignment of the chunk to find
|
||||
* @return The first applicable chunk
|
||||
*/
|
||||
std::optional<ChunkDescriptor> FindChunk(ChunkState state, u64 size, u64 alignment = 0);
|
||||
|
||||
/**
|
||||
* @brief Inserts a chunk into the chunk list, resizing and splitting as necessary
|
||||
* @param newChunk The chunk to insert
|
||||
* @return The base virtual GPU address of the inserted chunk
|
||||
* @return The base virtual address of the inserted chunk
|
||||
*/
|
||||
u64 InsertChunk(const ChunkDescriptor &newChunk);
|
||||
|
||||
@ -61,81 +61,82 @@ namespace skyline {
|
||||
MemoryManager(const DeviceState &state);
|
||||
|
||||
/**
|
||||
* @brief Reserves a region of the GPU address space so it will not be chosen automatically when mapping
|
||||
* @brief Reserves a region of the virtual address space so it will not be chosen automatically when mapping
|
||||
* @param size The size of the region to reserve
|
||||
* @param alignment The alignment of the region to reserve
|
||||
* @return The virtual GPU base address of the region base
|
||||
* @return The base virtual address of the reserved region
|
||||
*/
|
||||
u64 ReserveSpace(u64 size, u64 alignment);
|
||||
|
||||
/**
|
||||
* @brief Reserves a fixed region of the GPU address space so it will not be chosen automatically when mapping
|
||||
* @param address The virtual base address of the region to allocate
|
||||
* @brief Reserves a fixed region of the virtual address space so it will not be chosen automatically when mapping
|
||||
* @param virtAddr The virtual base address of the region to allocate
|
||||
* @param size The size of the region to allocate
|
||||
* @return The virtual address of the region base
|
||||
* @return The base virtual address of the reserved region
|
||||
*/
|
||||
u64 ReserveFixed(u64 address, u64 size);
|
||||
u64 ReserveFixed(u64 virtAddr, u64 size);
|
||||
|
||||
/**
|
||||
* @brief Maps a physical CPU memory region to an automatically chosen virtual memory region
|
||||
* @param pointer A pointer to the region to be mapped into the GPU's address space
|
||||
* @brief Maps a CPU memory region into an automatically chosen region of the virtual address space
|
||||
* @param cpuPtr A pointer to the region to be mapped into the virtual address space
|
||||
* @param size The size of the region to map
|
||||
* @return The virtual address of the region base
|
||||
* @return The base virtual address of the mapped region
|
||||
*/
|
||||
u64 MapAllocate(u8 *pointer, u64 size);
|
||||
u64 MapAllocate(u8 *cpuPtr, u64 size);
|
||||
|
||||
/**
|
||||
* @brief Maps a physical CPU memory region to a fixed virtual memory region
|
||||
* @param address The target virtual address of the region
|
||||
* @param pointer A pointer to the region to be mapped into the GPU's address space
|
||||
* @brief Maps a CPU memory region to a fixed region in the virtual address space
|
||||
* @param virtAddr The target virtual address of the region
|
||||
* @param cpuPtr A pointer to the region to be mapped into the virtual address space
|
||||
* @param size The size of the region to map
|
||||
* @return The virtual address of the region base
|
||||
* @return The base virtual address of the mapped region
|
||||
*/
|
||||
u64 MapFixed(u64 address, u8 *pointer, u64 size);
|
||||
u64 MapFixed(u64 virtAddr, u8 *cpuPtr, u64 size);
|
||||
|
||||
/**
|
||||
* @brief Unmaps all chunks in the given region from the GPU address space
|
||||
* @brief Unmaps all chunks in the given region from the virtual address space
|
||||
* @return Whether the operation succeeded
|
||||
*/
|
||||
bool Unmap(u64 address, u64 size);
|
||||
bool Unmap(u64 virtAddr, u64 size);
|
||||
|
||||
void Read(u8 *destination, u64 address, u64 size) const;
|
||||
|
||||
void Read(u8 *destination, u64 virtAddr, u64 size) const;
|
||||
|
||||
/**
|
||||
* @brief Reads in a span from a region of the GPU virtual address space
|
||||
* @brief Reads in a span from a region of the virtual address space
|
||||
*/
|
||||
template<typename T>
|
||||
void Read(span<T> destination, u64 address) const {
|
||||
Read(reinterpret_cast<u8 *>(destination.data()), address, destination.size_bytes());
|
||||
void Read(span<T> destination, u64 virtAddr) const {
|
||||
Read(reinterpret_cast<u8 *>(destination.data()), virtAddr, destination.size_bytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads in an object from a region of the GPU virtual address space
|
||||
* @brief Reads in an object from a region of the virtual address space
|
||||
* @tparam T The type of object to return
|
||||
*/
|
||||
template<typename T>
|
||||
T Read(u64 address) const {
|
||||
T Read(u64 virtAddr) const {
|
||||
T obj;
|
||||
Read(reinterpret_cast<u8 *>(&obj), address, sizeof(T));
|
||||
Read(reinterpret_cast<u8 *>(&obj), virtAddr, sizeof(T));
|
||||
return obj;
|
||||
}
|
||||
|
||||
void Write(u8 *source, u64 address, u64 size) const;
|
||||
void Write(u8 *source, u64 virtAddr, u64 size) const;
|
||||
|
||||
/**
|
||||
* @brief Writes out a span to a region of the GPU virtual address space
|
||||
* @brief Writes out a span to a region of the virtual address space
|
||||
*/
|
||||
template<typename T>
|
||||
void Write(span<T> source, u64 address) const {
|
||||
Write(reinterpret_cast<u8 *>(source.data()), address, source.size_bytes());
|
||||
void Write(span<T> source, u64 virtAddr) const {
|
||||
Write(reinterpret_cast<u8 *>(source.data()), virtAddr, source.size_bytes());
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Reads in an object from a region of the GPU virtual address space
|
||||
* @brief Reads in an object from a region of the virtual address space
|
||||
*/
|
||||
template<typename T>
|
||||
void Write(T source, u64 address) const {
|
||||
Write(reinterpret_cast<u8 *>(&source), address, sizeof(T));
|
||||
void Write(T source, u64 virtAddr) const {
|
||||
Write(reinterpret_cast<u8 *>(&source), virtAddr, sizeof(T));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user