diff options
| author | 2014-08-17 12:31:19 +0200 | |
|---|---|---|
| committer | 2014-08-25 22:03:18 +0200 | |
| commit | 9679d231df0bc8fac9e0e596ab78750bb38ef248 (patch) | |
| tree | f80fe9c3396c3c83aacc06c26ddf3643140b20ae /src | |
| parent | Pica/DebugUtils: Add convenient tev setup printer. (diff) | |
| download | yuzu-9679d231df0bc8fac9e0e596ab78750bb38ef248.tar.gz yuzu-9679d231df0bc8fac9e0e596ab78750bb38ef248.tar.xz yuzu-9679d231df0bc8fac9e0e596ab78750bb38ef248.zip | |
Pica/Rasterizer: Add texturing support.
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/debug_utils/debug_utils.cpp | 18 | ||||
| -rw-r--r-- | src/video_core/pica.h | 5 | ||||
| -rw-r--r-- | src/video_core/rasterizer.cpp | 64 |
3 files changed, 69 insertions, 18 deletions
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index 619c0fbe5..f7d9455be 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp | |||
| @@ -387,23 +387,7 @@ void DumpTexture(const Pica::Regs::TextureConfig& texture_config, u8* data) { | |||
| 387 | buf = new u8[row_stride * texture_config.height]; | 387 | buf = new u8[row_stride * texture_config.height]; |
| 388 | for (int y = 0; y < texture_config.height; ++y) { | 388 | for (int y = 0; y < texture_config.height; ++y) { |
| 389 | for (int x = 0; x < texture_config.width; ++x) { | 389 | for (int x = 0; x < texture_config.width; ++x) { |
| 390 | // Images are split into 8x8 tiles. Each tile is composed of four 4x4 subtiles each | 390 | // Cf. rasterizer code for an explanation of this algorithm. |
| 391 | // of which is composed of four 2x2 subtiles each of which is composed of four texels. | ||
| 392 | // Each structure is embedded into the next-bigger one in a diagonal pattern, e.g. | ||
| 393 | // texels are laid out in a 2x2 subtile like this: | ||
| 394 | // 2 3 | ||
| 395 | // 0 1 | ||
| 396 | // | ||
| 397 | // The full 8x8 tile has the texels arranged like this: | ||
| 398 | // | ||
| 399 | // 42 43 46 47 58 59 62 63 | ||
| 400 | // 40 41 44 45 56 57 60 61 | ||
| 401 | // 34 35 38 39 50 51 54 55 | ||
| 402 | // 32 33 36 37 48 49 52 53 | ||
| 403 | // 10 11 14 15 26 27 30 31 | ||
| 404 | // 08 09 12 13 24 25 28 29 | ||
| 405 | // 02 03 06 07 18 19 22 23 | ||
| 406 | // 00 01 04 05 16 17 20 21 | ||
| 407 | int texel_index_within_tile = 0; | 391 | int texel_index_within_tile = 0; |
| 408 | for (int block_size_index = 0; block_size_index < 3; ++block_size_index) { | 392 | for (int block_size_index = 0; block_size_index < 3; ++block_size_index) { |
| 409 | int sub_tile_width = 1 << block_size_index; | 393 | int sub_tile_width = 1 << block_size_index; |
diff --git a/src/video_core/pica.h b/src/video_core/pica.h index 7bd4388b5..cfdc9b934 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h | |||
| @@ -95,7 +95,7 @@ struct Regs { | |||
| 95 | BitField<16, 16, u32> y; | 95 | BitField<16, 16, u32> y; |
| 96 | } viewport_corner; | 96 | } viewport_corner; |
| 97 | 97 | ||
| 98 | INSERT_PADDING_WORDS(0x18); | 98 | INSERT_PADDING_WORDS(0x17); |
| 99 | 99 | ||
| 100 | struct TextureConfig { | 100 | struct TextureConfig { |
| 101 | INSERT_PADDING_WORDS(0x1); | 101 | INSERT_PADDING_WORDS(0x1); |
| @@ -130,6 +130,7 @@ struct Regs { | |||
| 130 | // Seems like they are luminance formats and compressed textures. | 130 | // Seems like they are luminance formats and compressed textures. |
| 131 | }; | 131 | }; |
| 132 | 132 | ||
| 133 | BitField<0, 1, u32> texturing_enable; | ||
| 133 | TextureConfig texture0; | 134 | TextureConfig texture0; |
| 134 | INSERT_PADDING_WORDS(0x8); | 135 | INSERT_PADDING_WORDS(0x8); |
| 135 | BitField<0, 4, TextureFormat> texture0_format; | 136 | BitField<0, 4, TextureFormat> texture0_format; |
| @@ -533,6 +534,7 @@ struct Regs { | |||
| 533 | ADD_FIELD(viewport_depth_range); | 534 | ADD_FIELD(viewport_depth_range); |
| 534 | ADD_FIELD(viewport_depth_far_plane); | 535 | ADD_FIELD(viewport_depth_far_plane); |
| 535 | ADD_FIELD(viewport_corner); | 536 | ADD_FIELD(viewport_corner); |
| 537 | ADD_FIELD(texturing_enable); | ||
| 536 | ADD_FIELD(texture0); | 538 | ADD_FIELD(texture0); |
| 537 | ADD_FIELD(texture0_format); | 539 | ADD_FIELD(texture0_format); |
| 538 | ADD_FIELD(tev_stage0); | 540 | ADD_FIELD(tev_stage0); |
| @@ -598,6 +600,7 @@ ASSERT_REG_POSITION(viewport_depth_far_plane, 0x4e); | |||
| 598 | ASSERT_REG_POSITION(vs_output_attributes[0], 0x50); | 600 | ASSERT_REG_POSITION(vs_output_attributes[0], 0x50); |
| 599 | ASSERT_REG_POSITION(vs_output_attributes[1], 0x51); | 601 | ASSERT_REG_POSITION(vs_output_attributes[1], 0x51); |
| 600 | ASSERT_REG_POSITION(viewport_corner, 0x68); | 602 | ASSERT_REG_POSITION(viewport_corner, 0x68); |
| 603 | ASSERT_REG_POSITION(texturing_enable, 0x80); | ||
| 601 | ASSERT_REG_POSITION(texture0, 0x81); | 604 | ASSERT_REG_POSITION(texture0, 0x81); |
| 602 | ASSERT_REG_POSITION(texture0_format, 0x8e); | 605 | ASSERT_REG_POSITION(texture0_format, 0x8e); |
| 603 | ASSERT_REG_POSITION(tev_stage0, 0xc0); | 606 | ASSERT_REG_POSITION(tev_stage0, 0xc0); |
diff --git a/src/video_core/rasterizer.cpp b/src/video_core/rasterizer.cpp index 5a4155c84..1bd32e8d0 100644 --- a/src/video_core/rasterizer.cpp +++ b/src/video_core/rasterizer.cpp | |||
| @@ -11,6 +11,8 @@ | |||
| 11 | #include "rasterizer.h" | 11 | #include "rasterizer.h" |
| 12 | #include "vertex_shader.h" | 12 | #include "vertex_shader.h" |
| 13 | 13 | ||
| 14 | #include "debug_utils/debug_utils.h" | ||
| 15 | |||
| 14 | namespace Pica { | 16 | namespace Pica { |
| 15 | 17 | ||
| 16 | namespace Rasterizer { | 18 | namespace Rasterizer { |
| @@ -165,6 +167,62 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0, | |||
| 165 | (u8)(GetInterpolatedAttribute(v0.color.a(), v1.color.a(), v2.color.a()).ToFloat32() * 255) | 167 | (u8)(GetInterpolatedAttribute(v0.color.a(), v1.color.a(), v2.color.a()).ToFloat32() * 255) |
| 166 | }; | 168 | }; |
| 167 | 169 | ||
| 170 | Math::Vec4<u8> texture_color{}; | ||
| 171 | float24 u = GetInterpolatedAttribute(v0.tc0.u(), v1.tc0.u(), v2.tc0.u()); | ||
| 172 | float24 v = GetInterpolatedAttribute(v0.tc0.v(), v1.tc0.v(), v2.tc0.v()); | ||
| 173 | if (registers.texturing_enable) { | ||
| 174 | // Images are split into 8x8 tiles. Each tile is composed of four 4x4 subtiles each | ||
| 175 | // of which is composed of four 2x2 subtiles each of which is composed of four texels. | ||
| 176 | // Each structure is embedded into the next-bigger one in a diagonal pattern, e.g. | ||
| 177 | // texels are laid out in a 2x2 subtile like this: | ||
| 178 | // 2 3 | ||
| 179 | // 0 1 | ||
| 180 | // | ||
| 181 | // The full 8x8 tile has the texels arranged like this: | ||
| 182 | // | ||
| 183 | // 42 43 46 47 58 59 62 63 | ||
| 184 | // 40 41 44 45 56 57 60 61 | ||
| 185 | // 34 35 38 39 50 51 54 55 | ||
| 186 | // 32 33 36 37 48 49 52 53 | ||
| 187 | // 10 11 14 15 26 27 30 31 | ||
| 188 | // 08 09 12 13 24 25 28 29 | ||
| 189 | // 02 03 06 07 18 19 22 23 | ||
| 190 | // 00 01 04 05 16 17 20 21 | ||
| 191 | |||
| 192 | // TODO: This is currently hardcoded for RGB8 | ||
| 193 | u32* texture_data = (u32*)Memory::GetPointer(registers.texture0.GetPhysicalAddress()); | ||
| 194 | |||
| 195 | // TODO(neobrain): Not sure if this swizzling pattern is used for all textures. | ||
| 196 | // To be flexible in case different but similar patterns are used, we keep this | ||
| 197 | // somewhat inefficient code around for now. | ||
| 198 | int s = (int)(u * float24::FromFloat32(registers.texture0.width)).ToFloat32(); | ||
| 199 | int t = (int)(v * float24::FromFloat32(registers.texture0.height)).ToFloat32(); | ||
| 200 | int texel_index_within_tile = 0; | ||
| 201 | for (int block_size_index = 0; block_size_index < 3; ++block_size_index) { | ||
| 202 | int sub_tile_width = 1 << block_size_index; | ||
| 203 | int sub_tile_height = 1 << block_size_index; | ||
| 204 | |||
| 205 | int sub_tile_index = (s & sub_tile_width) << block_size_index; | ||
| 206 | sub_tile_index += 2 * ((t & sub_tile_height) << block_size_index); | ||
| 207 | texel_index_within_tile += sub_tile_index; | ||
| 208 | } | ||
| 209 | |||
| 210 | const int block_width = 8; | ||
| 211 | const int block_height = 8; | ||
| 212 | |||
| 213 | int coarse_s = (s / block_width) * block_width; | ||
| 214 | int coarse_t = (t / block_height) * block_height; | ||
| 215 | |||
| 216 | const int row_stride = registers.texture0.width * 3; | ||
| 217 | u8* source_ptr = (u8*)texture_data + coarse_s * block_height * 3 + coarse_t * row_stride + texel_index_within_tile * 3; | ||
| 218 | texture_color.r() = source_ptr[2]; | ||
| 219 | texture_color.g() = source_ptr[1]; | ||
| 220 | texture_color.b() = source_ptr[0]; | ||
| 221 | texture_color.a() = 0xFF; | ||
| 222 | |||
| 223 | DebugUtils::DumpTexture(registers.texture0, (u8*)texture_data); | ||
| 224 | } | ||
| 225 | |||
| 168 | // Texture environment - consists of 6 stages of color and alpha combining. | 226 | // Texture environment - consists of 6 stages of color and alpha combining. |
| 169 | // | 227 | // |
| 170 | // Color combiners take three input color values from some source (e.g. interpolated | 228 | // Color combiners take three input color values from some source (e.g. interpolated |
| @@ -184,6 +242,9 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0, | |||
| 184 | case Source::PrimaryColor: | 242 | case Source::PrimaryColor: |
| 185 | return primary_color.rgb(); | 243 | return primary_color.rgb(); |
| 186 | 244 | ||
| 245 | case Source::Texture0: | ||
| 246 | return texture_color.rgb(); | ||
| 247 | |||
| 187 | case Source::Constant: | 248 | case Source::Constant: |
| 188 | return {tev_stage.const_r, tev_stage.const_g, tev_stage.const_b}; | 249 | return {tev_stage.const_r, tev_stage.const_g, tev_stage.const_b}; |
| 189 | 250 | ||
| @@ -201,6 +262,9 @@ void ProcessTriangle(const VertexShader::OutputVertex& v0, | |||
| 201 | case Source::PrimaryColor: | 262 | case Source::PrimaryColor: |
| 202 | return primary_color.a(); | 263 | return primary_color.a(); |
| 203 | 264 | ||
| 265 | case Source::Texture0: | ||
| 266 | return texture_color.a(); | ||
| 267 | |||
| 204 | case Source::Constant: | 268 | case Source::Constant: |
| 205 | return tev_stage.const_a; | 269 | return tev_stage.const_a; |
| 206 | 270 | ||