Document unsafe versions and add BlockCopyUnsafe
This commit is contained in:
parent
6fc562a9aa
commit
06d1c5a991
|
@ -199,7 +199,7 @@ const u8* MemoryManager::GetPointer(GPUVAddr addr) const {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryManager::ReadBlock(GPUVAddr src_addr, void* dest_buffer, std::size_t size) const {
|
void MemoryManager::ReadBlock(GPUVAddr src_addr, void* dest_buffer, const std::size_t size) const {
|
||||||
std::size_t remaining_size{size};
|
std::size_t remaining_size{size};
|
||||||
std::size_t page_index{src_addr >> page_bits};
|
std::size_t page_index{src_addr >> page_bits};
|
||||||
std::size_t page_offset{src_addr & page_mask};
|
std::size_t page_offset{src_addr & page_mask};
|
||||||
|
@ -226,7 +226,8 @@ void MemoryManager::ReadBlock(GPUVAddr src_addr, void* dest_buffer, std::size_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryManager::ReadBlockUnsafe(GPUVAddr src_addr, void* dest_buffer, std::size_t size) const {
|
void MemoryManager::ReadBlockUnsafe(GPUVAddr src_addr, void* dest_buffer,
|
||||||
|
const std::size_t size) const {
|
||||||
std::size_t remaining_size{size};
|
std::size_t remaining_size{size};
|
||||||
std::size_t page_index{src_addr >> page_bits};
|
std::size_t page_index{src_addr >> page_bits};
|
||||||
std::size_t page_offset{src_addr & page_mask};
|
std::size_t page_offset{src_addr & page_mask};
|
||||||
|
@ -243,7 +244,7 @@ void MemoryManager::ReadBlockUnsafe(GPUVAddr src_addr, void* dest_buffer, std::s
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryManager::WriteBlock(GPUVAddr dest_addr, const void* src_buffer, std::size_t size) {
|
void MemoryManager::WriteBlock(GPUVAddr dest_addr, const void* src_buffer, const std::size_t size) {
|
||||||
std::size_t remaining_size{size};
|
std::size_t remaining_size{size};
|
||||||
std::size_t page_index{dest_addr >> page_bits};
|
std::size_t page_index{dest_addr >> page_bits};
|
||||||
std::size_t page_offset{dest_addr & page_mask};
|
std::size_t page_offset{dest_addr & page_mask};
|
||||||
|
@ -270,7 +271,8 @@ void MemoryManager::WriteBlock(GPUVAddr dest_addr, const void* src_buffer, std::
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryManager::WriteBlockUnsafe(GPUVAddr dest_addr, const void* src_buffer, std::size_t size) {
|
void MemoryManager::WriteBlockUnsafe(GPUVAddr dest_addr, const void* src_buffer,
|
||||||
|
const std::size_t size) {
|
||||||
std::size_t remaining_size{size};
|
std::size_t remaining_size{size};
|
||||||
std::size_t page_index{dest_addr >> page_bits};
|
std::size_t page_index{dest_addr >> page_bits};
|
||||||
std::size_t page_offset{dest_addr & page_mask};
|
std::size_t page_offset{dest_addr & page_mask};
|
||||||
|
@ -287,7 +289,7 @@ void MemoryManager::WriteBlockUnsafe(GPUVAddr dest_addr, const void* src_buffer,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MemoryManager::CopyBlock(GPUVAddr dest_addr, GPUVAddr src_addr, std::size_t size) {
|
void MemoryManager::CopyBlock(GPUVAddr dest_addr, GPUVAddr src_addr, const std::size_t size) {
|
||||||
std::size_t remaining_size{size};
|
std::size_t remaining_size{size};
|
||||||
std::size_t page_index{src_addr >> page_bits};
|
std::size_t page_index{src_addr >> page_bits};
|
||||||
std::size_t page_offset{src_addr & page_mask};
|
std::size_t page_offset{src_addr & page_mask};
|
||||||
|
@ -315,6 +317,12 @@ void MemoryManager::CopyBlock(GPUVAddr dest_addr, GPUVAddr src_addr, std::size_t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MemoryManager::CopyBlockUnsafe(GPUVAddr dest_addr, GPUVAddr src_addr, const std::size_t size) {
|
||||||
|
std::vector<u8> tmp_buffer(size);
|
||||||
|
ReadBlockUnsafe(src_addr, tmp_buffer.data(), size);
|
||||||
|
WriteBlockUnsafe(dest_addr, tmp_buffer.data(), size);
|
||||||
|
}
|
||||||
|
|
||||||
void MemoryManager::MapPages(GPUVAddr base, u64 size, u8* memory, Common::PageType type,
|
void MemoryManager::MapPages(GPUVAddr base, u64 size, u8* memory, Common::PageType type,
|
||||||
VAddr backing_addr) {
|
VAddr backing_addr) {
|
||||||
LOG_DEBUG(HW_GPU, "Mapping {} onto {:016X}-{:016X}", fmt::ptr(memory), base * page_size,
|
LOG_DEBUG(HW_GPU, "Mapping {} onto {:016X}-{:016X}", fmt::ptr(memory), base * page_size,
|
||||||
|
|
|
@ -65,11 +65,31 @@ public:
|
||||||
u8* GetPointer(GPUVAddr addr);
|
u8* GetPointer(GPUVAddr addr);
|
||||||
const u8* GetPointer(GPUVAddr addr) const;
|
const u8* GetPointer(GPUVAddr addr) const;
|
||||||
|
|
||||||
void ReadBlock(GPUVAddr src_addr, void* dest_buffer, std::size_t size) const;
|
|
||||||
void WriteBlock(GPUVAddr dest_addr, const void* src_buffer, std::size_t size);
|
/*
|
||||||
void ReadBlockUnsafe(GPUVAddr src_addr, void* dest_buffer, std::size_t size) const;
|
* ReadBlock and WriteBlock are full read and write operations over virtual
|
||||||
void WriteBlockUnsafe(GPUVAddr dest_addr, const void* src_buffer, std::size_t size);
|
* GPU Memory. It's important to use these when GPU memory may not be continous
|
||||||
void CopyBlock(GPUVAddr dest_addr, GPUVAddr src_addr, std::size_t size);
|
* in the Host Memory counterpart. Note: This functions cause Host GPU Memory
|
||||||
|
* Flushes and Invalidations, respectively to each operation.
|
||||||
|
*/
|
||||||
|
void ReadBlock(GPUVAddr src_addr, void* dest_buffer, const std::size_t size) const;
|
||||||
|
void WriteBlock(GPUVAddr dest_addr, const void* src_buffer, const std::size_t size);
|
||||||
|
void CopyBlock(GPUVAddr dest_addr, GPUVAddr src_addr, const std::size_t size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ReadBlockUnsafe and WriteBlockUnsafe are special versions of ReadBlock and
|
||||||
|
* WriteBlock respectively. In this versions, no flushing or invalidation is actually
|
||||||
|
* done and their performance is similar to a memcpy. This functions can be used
|
||||||
|
* on either of this 2 scenarios instead of their safe counterpart:
|
||||||
|
* - Memory which is sure to never be represented in the Host GPU.
|
||||||
|
* - Memory Managed by a Cache Manager. Example: Texture Flushing should use
|
||||||
|
* WriteBlockUnsafe instead of WriteBlock since it shouldn't invalidate the texture
|
||||||
|
* being flushed.
|
||||||
|
*/
|
||||||
|
void ReadBlockUnsafe(GPUVAddr src_addr, void* dest_buffer, const std::size_t size) const;
|
||||||
|
void WriteBlockUnsafe(GPUVAddr dest_addr, const void* src_buffer, const std::size_t size);
|
||||||
|
void CopyBlockUnsafe(GPUVAddr dest_addr, GPUVAddr src_addr, const std::size_t size);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using VMAMap = std::map<GPUVAddr, VirtualMemoryArea>;
|
using VMAMap = std::map<GPUVAddr, VirtualMemoryArea>;
|
||||||
|
|
|
@ -38,14 +38,15 @@ GPUVAddr GetShaderAddress(Maxwell::ShaderProgram program) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the shader program code from memory for the specified address
|
/// Gets the shader program code from memory for the specified address
|
||||||
ProgramCode GetShaderCode(const GPUVAddr gpu_addr, const u8* host_ptr) {
|
ProgramCode GetShaderCode(Tegra::MemoryManager& memory_manager, const GPUVAddr gpu_addr,
|
||||||
auto& memory_manager{Core::System::GetInstance().GPU().MemoryManager()};
|
const u8* host_ptr) {
|
||||||
ProgramCode program_code(VideoCommon::Shader::MAX_PROGRAM_LENGTH);
|
ProgramCode program_code(VideoCommon::Shader::MAX_PROGRAM_LENGTH);
|
||||||
ASSERT_OR_EXECUTE(host_ptr != nullptr, {
|
ASSERT_OR_EXECUTE(host_ptr != nullptr, {
|
||||||
std::fill(program_code.begin(), program_code.end(), 0);
|
std::fill(program_code.begin(), program_code.end(), 0);
|
||||||
return program_code;
|
return program_code;
|
||||||
});
|
});
|
||||||
memory_manager.ReadBlockUnsafe(gpu_addr, program_code.data(), program_code.size() * sizeof(u64));
|
memory_manager.ReadBlockUnsafe(gpu_addr, program_code.data(),
|
||||||
|
program_code.size() * sizeof(u64));
|
||||||
return program_code;
|
return program_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -498,12 +499,12 @@ Shader ShaderCacheOpenGL::GetStageProgram(Maxwell::ShaderProgram program) {
|
||||||
|
|
||||||
if (!shader) {
|
if (!shader) {
|
||||||
// No shader found - create a new one
|
// No shader found - create a new one
|
||||||
ProgramCode program_code{GetShaderCode(program_addr, host_ptr)};
|
ProgramCode program_code{GetShaderCode(memory_manager, program_addr, host_ptr)};
|
||||||
ProgramCode program_code_b;
|
ProgramCode program_code_b;
|
||||||
if (program == Maxwell::ShaderProgram::VertexA) {
|
if (program == Maxwell::ShaderProgram::VertexA) {
|
||||||
const GPUVAddr program_addr_b{GetShaderAddress(Maxwell::ShaderProgram::VertexB)};
|
const GPUVAddr program_addr_b{GetShaderAddress(Maxwell::ShaderProgram::VertexB)};
|
||||||
program_code_b =
|
program_code_b = GetShaderCode(memory_manager, program_addr_b,
|
||||||
GetShaderCode(program_addr_b, memory_manager.GetPointer(program_addr_b));
|
memory_manager.GetPointer(program_addr_b));
|
||||||
}
|
}
|
||||||
const u64 unique_identifier = GetUniqueIdentifier(program, program_code, program_code_b);
|
const u64 unique_identifier = GetUniqueIdentifier(program, program_code, program_code_b);
|
||||||
const VAddr cpu_addr{*memory_manager.GpuToCpuAddress(program_addr)};
|
const VAddr cpu_addr{*memory_manager.GpuToCpuAddress(program_addr)};
|
||||||
|
|
Reference in New Issue