Remove KProcess Memory Functions

This commit is contained in:
◱ PixelyIon
2020-10-04 23:48:34 +05:30
committed by ◱ PixelyIon
parent 60e82e6af0
commit 02f3e37c4f
25 changed files with 192 additions and 309 deletions

View File

@ -41,7 +41,7 @@ namespace skyline::gpu::vmm {
}
if (extension)
chunks.insert(std::next(chunk), ChunkDescriptor(newChunk.address + newChunk.size, extension, (oldChunk.state == ChunkState::Mapped) ? (oldChunk.cpuAddress + newSize + newChunk.size) : 0, oldChunk.state));
chunks.insert(std::next(chunk), ChunkDescriptor(newChunk.address + newChunk.size, extension, (oldChunk.state == ChunkState::Mapped) ? (oldChunk.pointer + newSize + newChunk.size) : 0, oldChunk.state));
return newChunk.address;
} else if (chunk->address + chunk->size > newChunk.address) {
@ -65,7 +65,7 @@ namespace skyline::gpu::vmm {
tailChunk->address += chunkSliceOffset;
tailChunk->size -= chunkSliceOffset;
if (tailChunk->state == ChunkState::Mapped)
tailChunk->cpuAddress += chunkSliceOffset;
tailChunk->pointer += chunkSliceOffset;
// If the size of the head chunk is zero then we can directly replace it with our new one rather than inserting it
auto headChunk{std::prev(tailChunk)};
@ -103,27 +103,27 @@ namespace skyline::gpu::vmm {
return InsertChunk(ChunkDescriptor(address, size, 0, ChunkState::Reserved));
}
u64 MemoryManager::MapAllocate(u64 address, u64 size) {
u64 MemoryManager::MapAllocate(u8 *pointer, u64 size) {
size = util::AlignUp(size, constant::GpuPageSize);
auto mappedChunk{FindChunk(ChunkState::Unmapped, size)};
if (!mappedChunk)
return 0;
auto chunk{*mappedChunk};
chunk.cpuAddress = address;
chunk.pointer = pointer;
chunk.size = size;
chunk.state = ChunkState::Mapped;
return InsertChunk(chunk);
}
u64 MemoryManager::MapFixed(u64 address, u64 cpuAddress, u64 size) {
if (!util::IsAligned(address, constant::GpuPageSize))
return 0;
u64 MemoryManager::MapFixed(u64 address, u8 *pointer, u64 size) {
if (!util::IsAligned(pointer, constant::GpuPageSize))
return false;
size = util::AlignUp(size, constant::GpuPageSize);
return InsertChunk(ChunkDescriptor(address, size, cpuAddress, ChunkState::Mapped));
return InsertChunk(ChunkDescriptor(address, size, pointer, ChunkState::Mapped));
}
bool MemoryManager::Unmap(u64 address, u64 size) {
@ -151,20 +151,20 @@ namespace skyline::gpu::vmm {
u64 initialSize{size};
u64 chunkOffset{address - chunk->address};
u64 readAddress{chunk->cpuAddress + chunkOffset};
u64 readSize{std::min(chunk->size - chunkOffset, size)};
u8 *source{chunk->pointer + chunkOffset};
u64 sourceSize{std::min(chunk->size - chunkOffset, size)};
// A continuous region in the GPU address space may be made up of several discontinuous regions in physical memory so we have to iterate over all chunks
while (size) {
state.process->ReadMemory(destination + (initialSize - size), readAddress, readSize);
std::memcpy(destination + (initialSize - size), source, sourceSize);
size -= readSize;
size -= sourceSize;
if (size) {
if (++chunk == chunks.end() || chunk->state != ChunkState::Mapped)
throw exception("Failed to read region in GPU address space: Address: 0x{:X}, Size: 0x{:X}", address, size);
readAddress = chunk->cpuAddress;
readSize = std::min(chunk->size, size);
source = chunk->pointer;
sourceSize = std::min(chunk->size, size);
}
}
}
@ -181,20 +181,20 @@ namespace skyline::gpu::vmm {
u64 initialSize{size};
u64 chunkOffset{address - chunk->address};
u64 writeAddress{chunk->cpuAddress + chunkOffset};
u64 writeSize{std::min(chunk->size - chunkOffset, size)};
u8 *destination{chunk->pointer + chunkOffset};
u64 destinationSize{std::min(chunk->size - chunkOffset, size)};
// A continuous region in the GPU address space may be made up of several discontinuous regions in physical memory so we have to iterate over all chunks
while (size) {
state.process->WriteMemory(source + (initialSize - size), writeAddress, writeSize);
std::memcpy(destination, source + (initialSize - size), destinationSize);
size -= writeSize;
size -= destinationSize;
if (size) {
if (++chunk == chunks.end() || chunk->state != ChunkState::Mapped)
throw exception("Failed to write region in GPU address space: Address: 0x{:X}, Size: 0x{:X}", address, size);
writeAddress = chunk->cpuAddress;
writeSize = std::min(chunk->size, size);
destination = chunk->pointer;
destinationSize = std::min(chunk->size, size);
}
}
}

View File

@ -20,10 +20,10 @@ namespace skyline {
struct ChunkDescriptor {
u64 address; //!< The address of the chunk in the GPU address space
u64 size; //!< The size of the chunk in bytes
u64 cpuAddress; //!< The address of the chunk in the CPU address space (if mapped)
u8* pointer; //!< A pointer to the chunk in the CPU address space (if mapped)
ChunkState state;
ChunkDescriptor(u64 address, u64 size, u64 cpuAddress, ChunkState state) : address(address), size(size), cpuAddress(cpuAddress), state(state) {}
ChunkDescriptor(u64 address, u64 size, u8* pointer, ChunkState state) : address(address), size(size), pointer(pointer), state(state) {}
/**
* @return If the given chunk can be contained wholly within this chunk
@ -78,20 +78,20 @@ namespace skyline {
/**
* @brief Maps a physical CPU memory region to an automatically chosen virtual memory region
* @param address The physical CPU address of the region to be mapped into the GPU's address space
* @param pointer A pointer to the region to be mapped into the GPU's address space
* @param size The size of the region to map
* @return The virtual address of the region base
*/
u64 MapAllocate(u64 address, u64 size);
u64 MapAllocate(u8* pointer, 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 cpuAddress The physical CPU address of the region to be mapped into the GPU's address space
* @param pointer A pointer to the region to be mapped into the GPU's address space
* @param size The size of the region to map
* @return The virtual address of the region base
*/
u64 MapFixed(u64 address, u64 cpuAddress, u64 size);
u64 MapFixed(u64 address, u8* pointer, u64 size);
/**
* @brief Unmaps all chunks in the given region from the GPU address space

View File

@ -7,7 +7,7 @@
#include "texture.h"
namespace skyline::gpu {
GuestTexture::GuestTexture(const DeviceState &state, u64 address, texture::Dimensions dimensions, texture::Format format, texture::TileMode tiling, texture::TileConfig layout) : state(state), address(address), dimensions(dimensions), format(format), tileMode(tiling), tileConfig(layout) {}
GuestTexture::GuestTexture(const DeviceState &state, u8* pointer, texture::Dimensions dimensions, texture::Format format, texture::TileMode tiling, texture::TileConfig layout) : state(state), pointer(pointer), dimensions(dimensions), format(format), tileMode(tiling), tileConfig(layout) {}
std::shared_ptr<Texture> GuestTexture::InitializeTexture(std::optional<texture::Format> format, std::optional<texture::Dimensions> dimensions, texture::Swizzle swizzle) {
if (!host.expired())
@ -30,7 +30,7 @@ namespace skyline::gpu {
}
void Texture::SynchronizeHost() {
auto texture{state.process->GetPointer<u8>(guest->address)};
auto pointer{guest->pointer};
auto size{format.GetSize(dimensions)};
backing.resize(size);
auto output{reinterpret_cast<u8 *>(backing.data())};
@ -51,7 +51,7 @@ namespace skyline::gpu {
auto robBytes{robWidthBytes * robHeight}; // The size of a ROB in bytes
auto gobYOffset{robWidthBytes * gobHeight}; // The offset of the next Y-axis GOB from the current one in linear space
auto inputSector{texture}; // The address of the input sector
auto inputSector{pointer}; // The address of the input sector
auto outputRob{output}; // The address of the output block
for (u32 rob{}, y{}, paddingY{}; rob < surfaceHeightRobs; rob++) { // Every Surface contains `surfaceHeightRobs` ROBs
@ -80,7 +80,7 @@ namespace skyline::gpu {
auto sizeLine{guest->format.GetSize(dimensions.width, 1)}; // The size of a single line of pixel data
auto sizeStride{guest->format.GetSize(guest->tileConfig.pitch, 1)}; // The size of a single stride of pixel data
auto inputLine{texture}; // The address of the input line
auto inputLine{pointer}; // The address of the input line
auto outputLine{output}; // The address of the output line
for (u32 line{}; line < dimensions.height; line++) {
@ -89,7 +89,7 @@ namespace skyline::gpu {
outputLine += sizeLine;
}
} else if (guest->tileMode == texture::TileMode::Linear) {
std::memcpy(output, texture, size);
std::memcpy(output, pointer, size);
}
}

View File

@ -124,14 +124,14 @@ namespace skyline {
const DeviceState &state;
public:
u64 address; //!< The address of the texture in guest memory
u8* pointer; //!< The address of the texture in guest memory
std::weak_ptr<Texture> host; //!< A host texture (if any) that was created from this guest texture
texture::Dimensions dimensions;
texture::Format format;
texture::TileMode tileMode;
texture::TileConfig tileConfig;
GuestTexture(const DeviceState &state, u64 address, texture::Dimensions dimensions, texture::Format format, texture::TileMode tileMode = texture::TileMode::Linear, texture::TileConfig tileConfig = {});
GuestTexture(const DeviceState &state, u8* pointer, texture::Dimensions dimensions, texture::Format format, texture::TileMode tileMode = texture::TileMode::Linear, texture::TileConfig tileConfig = {});
constexpr size_t Size() {
return format.GetSize(dimensions);