diff options
| author | 2018-03-24 00:49:32 -0400 | |
|---|---|---|
| committer | 2018-03-26 21:16:51 -0400 | |
| commit | 8041d72a1ff403a4773bfccebdb7e3162061efd4 (patch) | |
| tree | 073391f4f81807be039852b07a7df8edf13e6326 /src | |
| parent | gl_rasterizer_cache: Implement GetFramebufferSurfaces. (diff) | |
| download | yuzu-8041d72a1ff403a4773bfccebdb7e3162061efd4.tar.gz yuzu-8041d72a1ff403a4773bfccebdb7e3162061efd4.tar.xz yuzu-8041d72a1ff403a4773bfccebdb7e3162061efd4.zip | |
gl_rasterizer_cache: MortonCopy Switch-style.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | 104 |
1 files changed, 32 insertions, 72 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp index 81b4a64a7..f556dbc41 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer_cache.cpp | |||
| @@ -113,65 +113,26 @@ static void MortonCopyTile(u32 stride, u8* tile_buffer, u8* gl_buffer) { | |||
| 113 | template <bool morton_to_gl, PixelFormat format> | 113 | template <bool morton_to_gl, PixelFormat format> |
| 114 | static void MortonCopy(u32 stride, u32 height, u8* gl_buffer, VAddr base, VAddr start, VAddr end) { | 114 | static void MortonCopy(u32 stride, u32 height, u8* gl_buffer, VAddr base, VAddr start, VAddr end) { |
| 115 | constexpr u32 bytes_per_pixel = SurfaceParams::GetFormatBpp(format) / 8; | 115 | constexpr u32 bytes_per_pixel = SurfaceParams::GetFormatBpp(format) / 8; |
| 116 | constexpr u32 tile_size = bytes_per_pixel * 64; | ||
| 117 | |||
| 118 | constexpr u32 gl_bytes_per_pixel = CachedSurface::GetGLBytesPerPixel(format); | 116 | constexpr u32 gl_bytes_per_pixel = CachedSurface::GetGLBytesPerPixel(format); |
| 119 | static_assert(gl_bytes_per_pixel >= bytes_per_pixel, ""); | ||
| 120 | gl_buffer += gl_bytes_per_pixel - bytes_per_pixel; | ||
| 121 | |||
| 122 | const VAddr aligned_down_start = base + Common::AlignDown(start - base, tile_size); | ||
| 123 | const VAddr aligned_start = base + Common::AlignUp(start - base, tile_size); | ||
| 124 | const VAddr aligned_end = base + Common::AlignDown(end - base, tile_size); | ||
| 125 | |||
| 126 | ASSERT(!morton_to_gl || (aligned_start == start && aligned_end == end)); | ||
| 127 | |||
| 128 | const u64 begin_pixel_index = (aligned_down_start - base) / bytes_per_pixel; | ||
| 129 | u32 x = static_cast<u32>((begin_pixel_index % (stride * 8)) / 8); | ||
| 130 | u32 y = static_cast<u32>((begin_pixel_index / (stride * 8)) * 8); | ||
| 131 | |||
| 132 | gl_buffer += ((height - 8 - y) * stride + x) * gl_bytes_per_pixel; | ||
| 133 | |||
| 134 | auto glbuf_next_tile = [&] { | ||
| 135 | x = (x + 8) % stride; | ||
| 136 | gl_buffer += 8 * gl_bytes_per_pixel; | ||
| 137 | if (!x) { | ||
| 138 | y += 8; | ||
| 139 | gl_buffer -= stride * 9 * gl_bytes_per_pixel; | ||
| 140 | } | ||
| 141 | }; | ||
| 142 | |||
| 143 | u8* tile_buffer = Memory::GetPointer(start); | ||
| 144 | |||
| 145 | if (start < aligned_start && !morton_to_gl) { | ||
| 146 | std::array<u8, tile_size> tmp_buf; | ||
| 147 | MortonCopyTile<morton_to_gl, format>(stride, &tmp_buf[0], gl_buffer); | ||
| 148 | std::memcpy(tile_buffer, &tmp_buf[start - aligned_down_start], | ||
| 149 | std::min(aligned_start, end) - start); | ||
| 150 | 117 | ||
| 151 | tile_buffer += aligned_start - start; | 118 | // TODO(bunnei): Assumes the default rendering GOB size of 16 (128 lines). We should check the |
| 152 | glbuf_next_tile(); | 119 | // configuration for this and perform more generic un/swizzle |
| 153 | } | 120 | LOG_WARNING(Render_OpenGL, "need to use correct swizzle/GOB parameters!"); |
| 154 | 121 | VideoCore::MortonCopyPixels128(stride, height, bytes_per_pixel, gl_bytes_per_pixel, | |
| 155 | const u8* const buffer_end = tile_buffer + aligned_end - aligned_start; | 122 | Memory::GetPointer(base), gl_buffer, morton_to_gl); |
| 156 | while (tile_buffer < buffer_end) { | ||
| 157 | MortonCopyTile<morton_to_gl, format>(stride, tile_buffer, gl_buffer); | ||
| 158 | tile_buffer += tile_size; | ||
| 159 | glbuf_next_tile(); | ||
| 160 | } | ||
| 161 | |||
| 162 | if (end > std::max(aligned_start, aligned_end) && !morton_to_gl) { | ||
| 163 | std::array<u8, tile_size> tmp_buf; | ||
| 164 | MortonCopyTile<morton_to_gl, format>(stride, &tmp_buf[0], gl_buffer); | ||
| 165 | std::memcpy(tile_buffer, &tmp_buf[0], end - aligned_end); | ||
| 166 | } | ||
| 167 | } | 123 | } |
| 168 | 124 | ||
| 169 | static constexpr std::array<void (*)(u32, u32, u8*, VAddr, VAddr, VAddr), 18> morton_to_gl_fns = { | 125 | static constexpr std::array<void (*)(u32, u32, u8*, VAddr, VAddr, VAddr), 18> morton_to_gl_fns = { |
| 170 | MortonCopy<true, PixelFormat::RGBA8>, // 0 | 126 | MortonCopy<true, PixelFormat::RGBA8>, |
| 171 | MortonCopy<true, PixelFormat::RGB8>, // 1 | 127 | nullptr, |
| 172 | MortonCopy<true, PixelFormat::RGB5A1>, // 2 | 128 | nullptr, |
| 173 | MortonCopy<true, PixelFormat::RGB565>, // 3 | 129 | nullptr, |
| 174 | MortonCopy<true, PixelFormat::RGBA4>, // 4 | 130 | nullptr, |
| 131 | nullptr, | ||
| 132 | nullptr, | ||
| 133 | nullptr, | ||
| 134 | nullptr, | ||
| 135 | nullptr, | ||
| 175 | nullptr, | 136 | nullptr, |
| 176 | nullptr, | 137 | nullptr, |
| 177 | nullptr, | 138 | nullptr, |
| @@ -180,19 +141,19 @@ static constexpr std::array<void (*)(u32, u32, u8*, VAddr, VAddr, VAddr), 18> mo | |||
| 180 | nullptr, | 141 | nullptr, |
| 181 | nullptr, | 142 | nullptr, |
| 182 | nullptr, | 143 | nullptr, |
| 183 | nullptr, // 5 - 13 | ||
| 184 | MortonCopy<true, PixelFormat::D16>, // 14 | ||
| 185 | nullptr, // 15 | ||
| 186 | MortonCopy<true, PixelFormat::D24>, // 16 | ||
| 187 | MortonCopy<true, PixelFormat::D24S8> // 17 | ||
| 188 | }; | 144 | }; |
| 189 | 145 | ||
| 190 | static constexpr std::array<void (*)(u32, u32, u8*, VAddr, VAddr, VAddr), 18> gl_to_morton_fns = { | 146 | static constexpr std::array<void (*)(u32, u32, u8*, VAddr, VAddr, VAddr), 18> gl_to_morton_fns = { |
| 191 | MortonCopy<false, PixelFormat::RGBA8>, // 0 | 147 | MortonCopy<false, PixelFormat::RGBA8>, |
| 192 | MortonCopy<false, PixelFormat::RGB8>, // 1 | 148 | nullptr, |
| 193 | MortonCopy<false, PixelFormat::RGB5A1>, // 2 | 149 | nullptr, |
| 194 | MortonCopy<false, PixelFormat::RGB565>, // 3 | 150 | nullptr, |
| 195 | MortonCopy<false, PixelFormat::RGBA4>, // 4 | 151 | nullptr, |
| 152 | nullptr, | ||
| 153 | nullptr, | ||
| 154 | nullptr, | ||
| 155 | nullptr, | ||
| 156 | nullptr, | ||
| 196 | nullptr, | 157 | nullptr, |
| 197 | nullptr, | 158 | nullptr, |
| 198 | nullptr, | 159 | nullptr, |
| @@ -201,11 +162,6 @@ static constexpr std::array<void (*)(u32, u32, u8*, VAddr, VAddr, VAddr), 18> gl | |||
| 201 | nullptr, | 162 | nullptr, |
| 202 | nullptr, | 163 | nullptr, |
| 203 | nullptr, | 164 | nullptr, |
| 204 | nullptr, // 5 - 13 | ||
| 205 | MortonCopy<false, PixelFormat::D16>, // 14 | ||
| 206 | nullptr, // 15 | ||
| 207 | MortonCopy<false, PixelFormat::D24>, // 16 | ||
| 208 | MortonCopy<false, PixelFormat::D24S8> // 17 | ||
| 209 | }; | 165 | }; |
| 210 | 166 | ||
| 211 | // Allocate an uninitialized texture of appropriate size and format for the surface | 167 | // Allocate an uninitialized texture of appropriate size and format for the surface |
| @@ -535,8 +491,7 @@ void CachedSurface::LoadGLBuffer(VAddr load_start, VAddr load_end) { | |||
| 535 | ASSERT(type != SurfaceType::Fill); | 491 | ASSERT(type != SurfaceType::Fill); |
| 536 | 492 | ||
| 537 | u8* texture_src_data = Memory::GetPointer(addr); | 493 | u8* texture_src_data = Memory::GetPointer(addr); |
| 538 | if (texture_src_data == nullptr) | 494 | ASSERT(texture_src_data); |
| 539 | return; | ||
| 540 | 495 | ||
| 541 | if (gl_buffer == nullptr) { | 496 | if (gl_buffer == nullptr) { |
| 542 | gl_buffer_size = width * height * GetGLBytesPerPixel(pixel_format); | 497 | gl_buffer_size = width * height * GetGLBytesPerPixel(pixel_format); |
| @@ -551,11 +506,16 @@ void CachedSurface::LoadGLBuffer(VAddr load_start, VAddr load_end) { | |||
| 551 | if (!is_tiled) { | 506 | if (!is_tiled) { |
| 552 | ASSERT(type == SurfaceType::Color); | 507 | ASSERT(type == SurfaceType::Color); |
| 553 | const u32 bytes_per_pixel{GetFormatBpp() >> 3}; | 508 | const u32 bytes_per_pixel{GetFormatBpp() >> 3}; |
| 509 | |||
| 510 | // TODO(bunnei): Assumes the default rendering GOB size of 16 (128 lines). We should check | ||
| 511 | // the configuration for this and perform more generic un/swizzle | ||
| 512 | LOG_WARNING(Render_OpenGL, "need to use correct swizzle/GOB parameters!"); | ||
| 554 | VideoCore::MortonCopyPixels128(width, height, bytes_per_pixel, 4, | 513 | VideoCore::MortonCopyPixels128(width, height, bytes_per_pixel, 4, |
| 555 | texture_src_data + start_offset, &gl_buffer[start_offset], | 514 | texture_src_data + start_offset, &gl_buffer[start_offset], |
| 556 | true); | 515 | true); |
| 557 | } else { | 516 | } else { |
| 558 | ASSERT_MSG(false, "Unimplemented"); | 517 | morton_to_gl_fns[static_cast<size_t>(pixel_format)](stride, height, &gl_buffer[0], addr, |
| 518 | load_start, load_end); | ||
| 559 | } | 519 | } |
| 560 | } | 520 | } |
| 561 | 521 | ||