diff options
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index f6efce818..114d35ce6 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | |||
| @@ -184,35 +184,37 @@ MathUtil::Rectangle<u32> SurfaceParams::GetRect() const { | |||
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | template <bool morton_to_gl, PixelFormat format> | 186 | template <bool morton_to_gl, PixelFormat format> |
| 187 | void MortonCopy(u32 stride, u32 block_height, u32 height, u8* gl_buffer, Tegra::GPUVAddr addr) { | 187 | void MortonCopy(u32 stride, u32 block_height, u32 height, std::vector<u8>& gl_buffer, |
| 188 | Tegra::GPUVAddr addr) { | ||
| 188 | constexpr u32 bytes_per_pixel = SurfaceParams::GetFormatBpp(format) / CHAR_BIT; | 189 | constexpr u32 bytes_per_pixel = SurfaceParams::GetFormatBpp(format) / CHAR_BIT; |
| 189 | constexpr u32 gl_bytes_per_pixel = CachedSurface::GetGLBytesPerPixel(format); | 190 | constexpr u32 gl_bytes_per_pixel = CachedSurface::GetGLBytesPerPixel(format); |
| 190 | const auto& gpu = Core::System::GetInstance().GPU(); | 191 | const auto& gpu = Core::System::GetInstance().GPU(); |
| 191 | 192 | ||
| 192 | if (morton_to_gl) { | 193 | if (morton_to_gl) { |
| 194 | std::vector<u8> data; | ||
| 193 | if (SurfaceParams::GetFormatType(format) == SurfaceType::ColorTexture) { | 195 | if (SurfaceParams::GetFormatType(format) == SurfaceType::ColorTexture) { |
| 194 | auto data = Tegra::Texture::UnswizzleTexture( | 196 | data = Tegra::Texture::UnswizzleTexture( |
| 195 | *gpu.memory_manager->GpuToCpuAddress(addr), | 197 | *gpu.memory_manager->GpuToCpuAddress(addr), |
| 196 | SurfaceParams::TextureFormatFromPixelFormat(format), stride, height, block_height); | 198 | SurfaceParams::TextureFormatFromPixelFormat(format), stride, height, block_height); |
| 197 | std::memcpy(gl_buffer, data.data(), data.size()); | ||
| 198 | } else { | 199 | } else { |
| 199 | auto data = Tegra::Texture::UnswizzleDepthTexture( | 200 | data = Tegra::Texture::UnswizzleDepthTexture( |
| 200 | *gpu.memory_manager->GpuToCpuAddress(addr), | 201 | *gpu.memory_manager->GpuToCpuAddress(addr), |
| 201 | SurfaceParams::DepthFormatFromPixelFormat(format), stride, height, block_height); | 202 | SurfaceParams::DepthFormatFromPixelFormat(format), stride, height, block_height); |
| 202 | std::memcpy(gl_buffer, data.data(), data.size()); | ||
| 203 | } | 203 | } |
| 204 | const size_t size_to_copy{std::min(gl_buffer.size(), data.size())}; | ||
| 205 | gl_buffer.assign(data.begin(), data.begin() + size_to_copy); | ||
| 204 | } else { | 206 | } else { |
| 205 | // TODO(bunnei): Assumes the default rendering GOB size of 16 (128 lines). We should | 207 | // TODO(bunnei): Assumes the default rendering GOB size of 16 (128 lines). We should |
| 206 | // check the configuration for this and perform more generic un/swizzle | 208 | // check the configuration for this and perform more generic un/swizzle |
| 207 | LOG_WARNING(Render_OpenGL, "need to use correct swizzle/GOB parameters!"); | 209 | LOG_WARNING(Render_OpenGL, "need to use correct swizzle/GOB parameters!"); |
| 208 | VideoCore::MortonCopyPixels128( | 210 | VideoCore::MortonCopyPixels128( |
| 209 | stride, height, bytes_per_pixel, gl_bytes_per_pixel, | 211 | stride, height, bytes_per_pixel, gl_bytes_per_pixel, |
| 210 | Memory::GetPointer(*gpu.memory_manager->GpuToCpuAddress(addr)), gl_buffer, | 212 | Memory::GetPointer(*gpu.memory_manager->GpuToCpuAddress(addr)), gl_buffer.data(), |
| 211 | morton_to_gl); | 213 | morton_to_gl); |
| 212 | } | 214 | } |
| 213 | } | 215 | } |
| 214 | 216 | ||
| 215 | static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr), | 217 | static constexpr std::array<void (*)(u32, u32, u32, std::vector<u8>&, Tegra::GPUVAddr), |
| 216 | SurfaceParams::MaxPixelFormat> | 218 | SurfaceParams::MaxPixelFormat> |
| 217 | morton_to_gl_fns = { | 219 | morton_to_gl_fns = { |
| 218 | MortonCopy<true, PixelFormat::ABGR8>, MortonCopy<true, PixelFormat::B5G6R5>, | 220 | MortonCopy<true, PixelFormat::ABGR8>, MortonCopy<true, PixelFormat::B5G6R5>, |
| @@ -235,7 +237,7 @@ static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr), | |||
| 235 | MortonCopy<true, PixelFormat::Z32FS8>, | 237 | MortonCopy<true, PixelFormat::Z32FS8>, |
| 236 | }; | 238 | }; |
| 237 | 239 | ||
| 238 | static constexpr std::array<void (*)(u32, u32, u32, u8*, Tegra::GPUVAddr), | 240 | static constexpr std::array<void (*)(u32, u32, u32, std::vector<u8>&, Tegra::GPUVAddr), |
| 239 | SurfaceParams::MaxPixelFormat> | 241 | SurfaceParams::MaxPixelFormat> |
| 240 | gl_to_morton_fns = { | 242 | gl_to_morton_fns = { |
| 241 | MortonCopy<false, PixelFormat::ABGR8>, | 243 | MortonCopy<false, PixelFormat::ABGR8>, |
| @@ -467,7 +469,7 @@ void CachedSurface::LoadGLBuffer() { | |||
| 467 | gl_buffer.resize(copy_size); | 469 | gl_buffer.resize(copy_size); |
| 468 | 470 | ||
| 469 | morton_to_gl_fns[static_cast<size_t>(params.pixel_format)]( | 471 | morton_to_gl_fns[static_cast<size_t>(params.pixel_format)]( |
| 470 | params.width, params.block_height, params.height, gl_buffer.data(), params.addr); | 472 | params.width, params.block_height, params.height, gl_buffer, params.addr); |
| 471 | } else { | 473 | } else { |
| 472 | const u8* const texture_src_data_end = texture_src_data + copy_size; | 474 | const u8* const texture_src_data_end = texture_src_data + copy_size; |
| 473 | 475 | ||
| @@ -494,7 +496,7 @@ void CachedSurface::FlushGLBuffer() { | |||
| 494 | std::memcpy(dst_buffer, gl_buffer.data(), params.size_in_bytes); | 496 | std::memcpy(dst_buffer, gl_buffer.data(), params.size_in_bytes); |
| 495 | } else { | 497 | } else { |
| 496 | gl_to_morton_fns[static_cast<size_t>(params.pixel_format)]( | 498 | gl_to_morton_fns[static_cast<size_t>(params.pixel_format)]( |
| 497 | params.width, params.block_height, params.height, gl_buffer.data(), params.addr); | 499 | params.width, params.block_height, params.height, gl_buffer, params.addr); |
| 498 | } | 500 | } |
| 499 | } | 501 | } |
| 500 | 502 | ||