diff options
| author | 2014-12-06 21:52:21 +0100 | |
|---|---|---|
| committer | 2014-12-20 18:05:53 +0100 | |
| commit | 3df88d59b0ba43f1c3360cfdaaccd461cacff72c (patch) | |
| tree | d0377ec9b94ba6bb5f7c02b539eeeba00d7887d5 /src | |
| parent | Pica: Implement texture wrapping. (diff) | |
| download | yuzu-3df88d59b0ba43f1c3360cfdaaccd461cacff72c.tar.gz yuzu-3df88d59b0ba43f1c3360cfdaaccd461cacff72c.tar.xz yuzu-3df88d59b0ba43f1c3360cfdaaccd461cacff72c.zip | |
Pica: Merge texture lookup logic for DebugUtils and Rasterizer.
This effectively adds support for a lot texture formats in the rasterizer.
Diffstat (limited to 'src')
| -rw-r--r-- | src/citra_qt/debugger/graphics_cmdlists.cpp | 2 | ||||
| -rw-r--r-- | src/video_core/debug_utils/debug_utils.cpp | 44 | ||||
| -rw-r--r-- | src/video_core/debug_utils/debug_utils.h | 3 | ||||
| -rw-r--r-- | src/video_core/rasterizer.cpp | 49 |
4 files changed, 42 insertions, 56 deletions
diff --git a/src/citra_qt/debugger/graphics_cmdlists.cpp b/src/citra_qt/debugger/graphics_cmdlists.cpp index bdd676470..01ff31d44 100644 --- a/src/citra_qt/debugger/graphics_cmdlists.cpp +++ b/src/citra_qt/debugger/graphics_cmdlists.cpp | |||
| @@ -24,7 +24,7 @@ QImage LoadTexture(u8* src, const Pica::DebugUtils::TextureInfo& info) { | |||
| 24 | QImage decoded_image(info.width, info.height, QImage::Format_ARGB32); | 24 | QImage decoded_image(info.width, info.height, QImage::Format_ARGB32); |
| 25 | for (int y = 0; y < info.height; ++y) { | 25 | for (int y = 0; y < info.height; ++y) { |
| 26 | for (int x = 0; x < info.width; ++x) { | 26 | for (int x = 0; x < info.width; ++x) { |
| 27 | Math::Vec4<u8> color = Pica::DebugUtils::LookupTexture(src, x, y, info); | 27 | Math::Vec4<u8> color = Pica::DebugUtils::LookupTexture(src, x, y, info, true); |
| 28 | decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a())); | 28 | decoded_image.setPixel(x, y, qRgba(color.r(), color.g(), color.b(), color.a())); |
| 29 | } | 29 | } |
| 30 | } | 30 | } |
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 89bf08b99..6c26138da 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp | |||
| @@ -356,9 +356,29 @@ std::unique_ptr<PicaTrace> FinishPicaTracing() | |||
| 356 | return std::move(ret); | 356 | return std::move(ret); |
| 357 | } | 357 | } |
| 358 | 358 | ||
| 359 | const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info) { | 359 | const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info, bool disable_alpha) { |
| 360 | 360 | ||
| 361 | // Cf. rasterizer code for an explanation of this algorithm. | 361 | // Images are split into 8x8 tiles. Each tile is composed of four 4x4 subtiles each |
| 362 | // of which is composed of four 2x2 subtiles each of which is composed of four texels. | ||
| 363 | // Each structure is embedded into the next-bigger one in a diagonal pattern, e.g. | ||
| 364 | // texels are laid out in a 2x2 subtile like this: | ||
| 365 | // 2 3 | ||
| 366 | // 0 1 | ||
| 367 | // | ||
| 368 | // The full 8x8 tile has the texels arranged like this: | ||
| 369 | // | ||
| 370 | // 42 43 46 47 58 59 62 63 | ||
| 371 | // 40 41 44 45 56 57 60 61 | ||
| 372 | // 34 35 38 39 50 51 54 55 | ||
| 373 | // 32 33 36 37 48 49 52 53 | ||
| 374 | // 10 11 14 15 26 27 30 31 | ||
| 375 | // 08 09 12 13 24 25 28 29 | ||
| 376 | // 02 03 06 07 18 19 22 23 | ||
| 377 | // 00 01 04 05 16 17 20 21 | ||
| 378 | |||
| 379 | // TODO(neobrain): Not sure if this swizzling pattern is used for all textures. | ||
| 380 | // To be flexible in case different but similar patterns are used, we keep this | ||
| 381 | // somewhat inefficient code around for now. | ||
| 362 | int texel_index_within_tile = 0; | 382 | int texel_index_within_tile = 0; |
| 363 | for (int block_size_index = 0; block_size_index < 3; ++block_size_index) { | 383 | for (int block_size_index = 0; block_size_index < 3; ++block_size_index) { |
| 364 | int sub_tile_width = 1 << block_size_index; | 384 | int sub_tile_width = 1 << block_size_index; |
| @@ -379,7 +399,7 @@ const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const Texture | |||
| 379 | case Regs::TextureFormat::RGBA8: | 399 | case Regs::TextureFormat::RGBA8: |
| 380 | { | 400 | { |
| 381 | const u8* source_ptr = source + coarse_x * block_height * 4 + coarse_y * info.stride + texel_index_within_tile * 4; | 401 | const u8* source_ptr = source + coarse_x * block_height * 4 + coarse_y * info.stride + texel_index_within_tile * 4; |
| 382 | return { source_ptr[3], source_ptr[2], source_ptr[1], 255 }; | 402 | return { source_ptr[3], source_ptr[2], source_ptr[1], disable_alpha ? 255 : source_ptr[0] }; |
| 383 | } | 403 | } |
| 384 | 404 | ||
| 385 | case Regs::TextureFormat::RGB8: | 405 | case Regs::TextureFormat::RGB8: |
| @@ -394,8 +414,8 @@ const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const Texture | |||
| 394 | u8 r = (source_ptr >> 11) & 0x1F; | 414 | u8 r = (source_ptr >> 11) & 0x1F; |
| 395 | u8 g = ((source_ptr) >> 6) & 0x1F; | 415 | u8 g = ((source_ptr) >> 6) & 0x1F; |
| 396 | u8 b = (source_ptr >> 1) & 0x1F; | 416 | u8 b = (source_ptr >> 1) & 0x1F; |
| 397 | u8 a = 1; | 417 | u8 a = source_ptr & 1; |
| 398 | return Math::MakeVec<u8>((r << 3) | (r >> 2), (g << 3) | (g >> 2), (b << 3) | (b >> 2), a * 255); | 418 | return Math::MakeVec<u8>((r << 3) | (r >> 2), (g << 3) | (g >> 2), (b << 3) | (b >> 2), disable_alpha ? 255 : (a * 255)); |
| 399 | } | 419 | } |
| 400 | 420 | ||
| 401 | case Regs::TextureFormat::RGBA4: | 421 | case Regs::TextureFormat::RGBA4: |
| @@ -404,16 +424,24 @@ const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const Texture | |||
| 404 | u8 r = source_ptr[1] >> 4; | 424 | u8 r = source_ptr[1] >> 4; |
| 405 | u8 g = source_ptr[1] & 0xFF; | 425 | u8 g = source_ptr[1] & 0xFF; |
| 406 | u8 b = source_ptr[0] >> 4; | 426 | u8 b = source_ptr[0] >> 4; |
| 427 | u8 a = source_ptr[0] & 0xFF; | ||
| 407 | r = (r << 4) | r; | 428 | r = (r << 4) | r; |
| 408 | g = (g << 4) | g; | 429 | g = (g << 4) | g; |
| 409 | b = (b << 4) | b; | 430 | b = (b << 4) | b; |
| 410 | return { r, g, b, 255 }; | 431 | a = (a << 4) | a; |
| 432 | return { r, g, b, disable_alpha ? 255 : a }; | ||
| 411 | } | 433 | } |
| 412 | 434 | ||
| 413 | case Regs::TextureFormat::A8: | 435 | case Regs::TextureFormat::A8: |
| 414 | { | 436 | { |
| 415 | const u8* source_ptr = source + coarse_x * block_height + coarse_y * info.stride + texel_index_within_tile; | 437 | const u8* source_ptr = source + coarse_x * block_height + coarse_y * info.stride + texel_index_within_tile; |
| 416 | return { *source_ptr, *source_ptr, *source_ptr, 255 }; | 438 | |
| 439 | // TODO: Better control this... | ||
| 440 | if (disable_alpha) { | ||
| 441 | return { *source_ptr, *source_ptr, *source_ptr, 255 }; | ||
| 442 | } else { | ||
| 443 | return { 0, 0, 0, *source_ptr }; | ||
| 444 | } | ||
| 417 | } | 445 | } |
| 418 | 446 | ||
| 419 | default: | 447 | default: |
diff --git a/src/video_core/debug_utils/debug_utils.h b/src/video_core/debug_utils/debug_utils.h index 51f14f12f..f950356f3 100644 --- a/src/video_core/debug_utils/debug_utils.h +++ b/src/video_core/debug_utils/debug_utils.h | |||
| @@ -202,7 +202,8 @@ struct TextureInfo { | |||
| 202 | const Pica::Regs::TextureFormat& format); | 202 | const Pica::Regs::TextureFormat& format); |
| 203 | }; | 203 | }; |
| 204 | 204 | ||
| 205 | const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info); | 205 | const Math::Vec4<u8> LookupTexture(const u8* source, int x, int y, const TextureInfo& info, |
| 206 | bool disable_alpha = false); | ||
| 206 | void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data); | 207 | void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data); |
| 207 | 208 | ||
| 208 | void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig,6>& stages); | 209 | void DumpTevStageConfig(const std::array<Pica::Regs::TevStageConfig,6>& stages); |
diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp index e12f68a7f..aa2bc93ec 100644 --- a/src/video_core/rasterizer.cpp +++ b/src/video_core/rasterizer.cpp | |||
| @@ -183,27 +183,6 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0, | |||
| 183 | 183 | ||
| 184 | _dbg_assert_(HW_GPU, 0 != texture.config.address); | 184 | _dbg_assert_(HW_GPU, 0 != texture.config.address); |
| 185 | 185 | ||
| 186 | // Images are split into 8x8 tiles. Each tile is composed of four 4x4 subtiles each | ||
| 187 | // of which is composed of four 2x2 subtiles each of which is composed of four texels. | ||
| 188 | // Each structure is embedded into the next-bigger one in a diagonal pattern, e.g. | ||
| 189 | // texels are laid out in a 2x2 subtile like this: | ||
| 190 | // 2 3 | ||
| 191 | // 0 1 | ||
| 192 | // | ||
| 193 | // The full 8x8 tile has the texels arranged like this: | ||
| 194 | // | ||
| 195 | // 42 43 46 47 58 59 62 63 | ||
| 196 | // 40 41 44 45 56 57 60 61 | ||
| 197 | // 34 35 38 39 50 51 54 55 | ||
| 198 | // 32 33 36 37 48 49 52 53 | ||
| 199 | // 10 11 14 15 26 27 30 31 | ||
| 200 | // 08 09 12 13 24 25 28 29 | ||
| 201 | // 02 03 06 07 18 19 22 23 | ||
| 202 | // 00 01 04 05 16 17 20 21 | ||
| 203 | |||
| 204 | // TODO(neobrain): Not sure if this swizzling pattern is used for all textures. | ||
| 205 | // To be flexible in case different but similar patterns are used, we keep this | ||
| 206 | // somewhat inefficient code around for now. | ||
| 207 | int s = (int)(uv[i].u() * float24::FromFloat32(static_cast<float>(texture.config.width))).ToFloat32(); | 186 | int s = (int)(uv[i].u() * float24::FromFloat32(static_cast<float>(texture.config.width))).ToFloat32(); |
| 208 | int t = (int)(uv[i].v() * float24::FromFloat32(static_cast<float>(texture.config.height))).ToFloat32(); | 187 | int t = (int)(uv[i].v() * float24::FromFloat32(static_cast<float>(texture.config.height))).ToFloat32(); |
| 209 | auto GetWrappedTexCoord = [](Regs::TextureConfig::WrapMode mode, int val, unsigned size) { | 188 | auto GetWrappedTexCoord = [](Regs::TextureConfig::WrapMode mode, int val, unsigned size) { |
| @@ -225,32 +204,10 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0, | |||
| 225 | s = GetWrappedTexCoord(registers.texture0.wrap_s, s, registers.texture0.width); | 204 | s = GetWrappedTexCoord(registers.texture0.wrap_s, s, registers.texture0.width); |
| 226 | t = GetWrappedTexCoord(registers.texture0.wrap_t, t, registers.texture0.height); | 205 | t = GetWrappedTexCoord(registers.texture0.wrap_t, t, registers.texture0.height); |
| 227 | 206 | ||
| 228 | int texel_index_within_tile = 0; | 207 | u8* texture_data = Memory::GetPointer(texture.config.GetPhysicalAddress()); |
| 229 | for (int block_size_index = 0; block_size_index < 3; ++block_size_index) { | 208 | auto info = DebugUtils::TextureInfo::FromPicaRegister(texture.config, texture.format); |
| 230 | int sub_tile_width = 1 << block_size_index; | ||
| 231 | int sub_tile_height = 1 << block_size_index; | ||
| 232 | |||
| 233 | int sub_tile_index = (s & sub_tile_width) << block_size_index; | ||
| 234 | sub_tile_index += 2 * ((t & sub_tile_height) << block_size_index); | ||
| 235 | texel_index_within_tile += sub_tile_index; | ||
| 236 | } | ||
| 237 | |||
| 238 | const int block_width = 8; | ||
| 239 | const int block_height = 8; | ||
| 240 | |||
| 241 | int coarse_s = (s / block_width) * block_width; | ||
| 242 | int coarse_t = (t / block_height) * block_height; | ||
| 243 | |||
| 244 | // TODO: This is currently hardcoded for RGB8 | ||
| 245 | u32* texture_data = (u32*)Memory::GetPointer(texture.config.GetPhysicalAddress()); | ||
| 246 | |||
| 247 | const int row_stride = texture.config.width * 3; | ||
| 248 | u8* source_ptr = (u8*)texture_data + coarse_s * block_height * 3 + coarse_t * row_stride + texel_index_within_tile * 3; | ||
| 249 | texture_color[i].r() = source_ptr[2]; | ||
| 250 | texture_color[i].g() = source_ptr[1]; | ||
| 251 | texture_color[i].b() = source_ptr[0]; | ||
| 252 | texture_color[i].a() = 0xFF; | ||
| 253 | 209 | ||
| 210 | texture_color[i] = DebugUtils::LookupTexture(texture_data, s, t, info); | ||
| 254 | DebugUtils::DumpTexture(texture.config, (u8*)texture_data); | 211 | DebugUtils::DumpTexture(texture.config, (u8*)texture_data); |
| 255 | } | 212 | } |
| 256 | 213 | ||