renderer_opengl: Replace Memory::GetPointer with Read/WriteBlock.

Only trivial usages are rewritten.
This commit is contained in:
Markus Wick
2018-11-07 10:40:15 +01:00
parent 65bd03d74c
commit 6a21beabb2
3 changed files with 11 additions and 12 deletions

View File

@@ -47,12 +47,13 @@ GLintptr PrimitiveAssembler::MakeQuadIndexed(Tegra::GPUVAddr gpu_addr, std::size
auto& memory_manager = Core::System::GetInstance().GPU().MemoryManager(); auto& memory_manager = Core::System::GetInstance().GPU().MemoryManager();
const std::optional<VAddr> cpu_addr{memory_manager.GpuToCpuAddress(gpu_addr)}; const std::optional<VAddr> cpu_addr{memory_manager.GpuToCpuAddress(gpu_addr)};
const u8* source{Memory::GetPointer(*cpu_addr)}; index_cache.resize(count);
Memory::ReadBlock(*cpu_addr, index_cache.data(), count);
for (u32 primitive = 0; primitive < count / 4; ++primitive) { for (u32 primitive = 0; primitive < count / 4; ++primitive) {
for (std::size_t i = 0; i < TRIANGLES_PER_QUAD; ++i) { for (std::size_t i = 0; i < TRIANGLES_PER_QUAD; ++i) {
const u32 index = primitive * 4 + QUAD_MAP[i]; const u32 index = primitive * 4 + QUAD_MAP[i];
const u8* src_offset = source + (index * index_size); const u8* src_offset = index_cache.data() + (index * index_size);
std::memcpy(dst_pointer, src_offset, index_size); std::memcpy(dst_pointer, src_offset, index_size);
dst_pointer += index_size; dst_pointer += index_size;
@@ -62,4 +63,4 @@ GLintptr PrimitiveAssembler::MakeQuadIndexed(Tegra::GPUVAddr gpu_addr, std::size
return index_offset; return index_offset;
} }
} // namespace OpenGL } // namespace OpenGL

View File

@@ -28,6 +28,7 @@ public:
private: private:
OGLBufferCache& buffer_cache; OGLBufferCache& buffer_cache;
std::vector<u8> index_cache;
}; };
} // namespace OpenGL } // namespace OpenGL

View File

@@ -752,8 +752,7 @@ static void CopySurface(const Surface& src_surface, const Surface& dst_surface,
} }
std::size_t remaining_size = dst_params.size_in_bytes - src_params.size_in_bytes; std::size_t remaining_size = dst_params.size_in_bytes - src_params.size_in_bytes;
std::vector<u8> data(remaining_size); std::vector<u8> data(remaining_size);
std::memcpy(data.data(), Memory::GetPointer(dst_params.addr + src_params.size_in_bytes), Memory::ReadBlock(dst_params.addr + src_params.size_in_bytes, data.data(), data.size());
data.size());
glBufferSubData(GL_PIXEL_PACK_BUFFER, src_params.size_in_bytes, remaining_size, glBufferSubData(GL_PIXEL_PACK_BUFFER, src_params.size_in_bytes, remaining_size,
data.data()); data.data());
@@ -1004,9 +1003,8 @@ void CachedSurface::LoadGLBuffer() {
for (u32 i = 0; i < params.max_mip_level; i++) for (u32 i = 0; i < params.max_mip_level; i++)
SwizzleFunc(morton_to_gl_fns, params, gl_buffer[i], i); SwizzleFunc(morton_to_gl_fns, params, gl_buffer[i], i);
} else { } else {
const auto texture_src_data{Memory::GetPointer(params.addr)}; gl_buffer[0].resize(params.size_in_bytes_gl);
const auto texture_src_data_end{texture_src_data + params.size_in_bytes_gl}; Memory::ReadBlock(params.addr, gl_buffer[0].data(), gl_buffer[0].size());
gl_buffer[0].assign(texture_src_data, texture_src_data_end);
} }
for (u32 i = 0; i < params.max_mip_level; i++) for (u32 i = 0; i < params.max_mip_level; i++)
ConvertFormatAsNeeded_LoadGLBuffer(gl_buffer[i], params.pixel_format, params.MipWidth(i), ConvertFormatAsNeeded_LoadGLBuffer(gl_buffer[i], params.pixel_format, params.MipWidth(i),
@@ -1035,15 +1033,14 @@ void CachedSurface::FlushGLBuffer() {
ConvertFormatAsNeeded_FlushGLBuffer(gl_buffer[0], params.pixel_format, params.width, ConvertFormatAsNeeded_FlushGLBuffer(gl_buffer[0], params.pixel_format, params.width,
params.height); params.height);
ASSERT(params.type != SurfaceType::Fill); ASSERT(params.type != SurfaceType::Fill);
const u8* const texture_src_data = Memory::GetPointer(params.addr); ASSERT(/*texture_src_data*/ Memory::GetPointer(params.addr));
ASSERT(texture_src_data);
if (params.is_tiled) { if (params.is_tiled) {
ASSERT_MSG(params.block_width == 1, "Block width is defined as {} on texture type {}", ASSERT_MSG(params.block_width == 1, "Block width is defined as {} on texture type {}",
params.block_width, static_cast<u32>(params.target)); params.block_width, static_cast<u32>(params.target));
SwizzleFunc(gl_to_morton_fns, params, gl_buffer[0], 0); SwizzleFunc(gl_to_morton_fns, params, gl_buffer[0], 0);
} else { } else {
std::memcpy(Memory::GetPointer(GetAddr()), gl_buffer[0].data(), GetSizeInBytes()); Memory::WriteBlock(GetAddr(), gl_buffer[0].data(), GetSizeInBytes());
} }
} }