diff options
| author | 2017-05-30 10:21:05 -0400 | |
|---|---|---|
| committer | 2017-05-30 10:21:05 -0400 | |
| commit | 54ea95cca74f76777aa156f6d750c9d1ba5b6f11 (patch) | |
| tree | be3f5d2d12c7e48293dda7a72699e514326e66e0 /src | |
| parent | Merge pull request #2734 from yuriks/cmake-imported-libs (diff) | |
| parent | swrasterizer: implement TextureCube (diff) | |
| download | yuzu-54ea95cca74f76777aa156f6d750c9d1ba5b6f11.tar.gz yuzu-54ea95cca74f76777aa156f6d750c9d1ba5b6f11.tar.xz yuzu-54ea95cca74f76777aa156f6d750c9d1ba5b6f11.zip | |
Merge pull request #2721 from wwylele/texture-cube
swrasterizer: implemented TextureCube
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/regs_texturing.h | 27 | ||||
| -rw-r--r-- | src/video_core/swrasterizer/rasterizer.cpp | 53 |
2 files changed, 77 insertions, 3 deletions
diff --git a/src/video_core/regs_texturing.h b/src/video_core/regs_texturing.h index e4038b41b..3f5355fa9 100644 --- a/src/video_core/regs_texturing.h +++ b/src/video_core/regs_texturing.h | |||
| @@ -133,7 +133,32 @@ struct TexturingRegs { | |||
| 133 | BitField<16, 1, u32> clear_texture_cache; // TODO: unimplemented | 133 | BitField<16, 1, u32> clear_texture_cache; // TODO: unimplemented |
| 134 | } main_config; | 134 | } main_config; |
| 135 | TextureConfig texture0; | 135 | TextureConfig texture0; |
| 136 | INSERT_PADDING_WORDS(0x8); | 136 | |
| 137 | enum class CubeFace { | ||
| 138 | PositiveX = 0, | ||
| 139 | NegativeX = 1, | ||
| 140 | PositiveY = 2, | ||
| 141 | NegativeY = 3, | ||
| 142 | PositiveZ = 4, | ||
| 143 | NegativeZ = 5, | ||
| 144 | }; | ||
| 145 | |||
| 146 | BitField<0, 22, u32> cube_address[5]; | ||
| 147 | |||
| 148 | PAddr GetCubePhysicalAddress(CubeFace face) const { | ||
| 149 | PAddr address = texture0.address; | ||
| 150 | if (face != CubeFace::PositiveX) { | ||
| 151 | // Bits [22:27] from the main texture address is shared with all cubemap additional | ||
| 152 | // addresses. | ||
| 153 | auto& face_addr = cube_address[static_cast<size_t>(face) - 1]; | ||
| 154 | address &= ~face_addr.mask; | ||
| 155 | address |= face_addr; | ||
| 156 | } | ||
| 157 | // A multiplier of 8 is also needed in the same way as the main address. | ||
| 158 | return address * 8; | ||
| 159 | } | ||
| 160 | |||
| 161 | INSERT_PADDING_WORDS(0x3); | ||
| 137 | BitField<0, 4, TextureFormat> texture0_format; | 162 | BitField<0, 4, TextureFormat> texture0_format; |
| 138 | BitField<0, 1, u32> fragment_lighting_enable; | 163 | BitField<0, 1, u32> fragment_lighting_enable; |
| 139 | INSERT_PADDING_WORDS(0x1); | 164 | INSERT_PADDING_WORDS(0x1); |
diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp index e9edf0360..8b7b1defb 100644 --- a/src/video_core/swrasterizer/rasterizer.cpp +++ b/src/video_core/swrasterizer/rasterizer.cpp | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <cmath> | 7 | #include <cmath> |
| 8 | #include <tuple> | ||
| 8 | #include "common/assert.h" | 9 | #include "common/assert.h" |
| 9 | #include "common/bit_field.h" | 10 | #include "common/bit_field.h" |
| 10 | #include "common/color.h" | 11 | #include "common/color.h" |
| @@ -70,6 +71,49 @@ static int SignedArea(const Math::Vec2<Fix12P4>& vtx1, const Math::Vec2<Fix12P4> | |||
| 70 | return Math::Cross(vec1, vec2).z; | 71 | return Math::Cross(vec1, vec2).z; |
| 71 | }; | 72 | }; |
| 72 | 73 | ||
| 74 | /// Convert a 3D vector for cube map coordinates to 2D texture coordinates along with the face name | ||
| 75 | static std::tuple<float24, float24, PAddr> ConvertCubeCoord(float24 u, float24 v, float24 w, | ||
| 76 | const TexturingRegs& regs) { | ||
| 77 | const float abs_u = std::abs(u.ToFloat32()); | ||
| 78 | const float abs_v = std::abs(v.ToFloat32()); | ||
| 79 | const float abs_w = std::abs(w.ToFloat32()); | ||
| 80 | float24 x, y, z; | ||
| 81 | PAddr addr; | ||
| 82 | if (abs_u > abs_v && abs_u > abs_w) { | ||
| 83 | if (u > float24::FromFloat32(0)) { | ||
| 84 | addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::PositiveX); | ||
| 85 | y = -v; | ||
| 86 | } else { | ||
| 87 | addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::NegativeX); | ||
| 88 | y = v; | ||
| 89 | } | ||
| 90 | x = -w; | ||
| 91 | z = u; | ||
| 92 | } else if (abs_v > abs_w) { | ||
| 93 | if (v > float24::FromFloat32(0)) { | ||
| 94 | addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::PositiveY); | ||
| 95 | x = u; | ||
| 96 | } else { | ||
| 97 | addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::NegativeY); | ||
| 98 | x = -u; | ||
| 99 | } | ||
| 100 | y = w; | ||
| 101 | z = v; | ||
| 102 | } else { | ||
| 103 | if (w > float24::FromFloat32(0)) { | ||
| 104 | addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::PositiveZ); | ||
| 105 | y = -v; | ||
| 106 | } else { | ||
| 107 | addr = regs.GetCubePhysicalAddress(TexturingRegs::CubeFace::NegativeZ); | ||
| 108 | y = v; | ||
| 109 | } | ||
| 110 | x = u; | ||
| 111 | z = w; | ||
| 112 | } | ||
| 113 | const float24 half = float24::FromFloat32(0.5f); | ||
| 114 | return std::make_tuple(x / z * half + half, y / z * half + half, addr); | ||
| 115 | } | ||
| 116 | |||
| 73 | MICROPROFILE_DEFINE(GPU_Rasterization, "GPU", "Rasterization", MP_RGB(50, 50, 240)); | 117 | MICROPROFILE_DEFINE(GPU_Rasterization, "GPU", "Rasterization", MP_RGB(50, 50, 240)); |
| 74 | 118 | ||
| 75 | /** | 119 | /** |
| @@ -284,10 +328,16 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve | |||
| 284 | 328 | ||
| 285 | // Only unit 0 respects the texturing type (according to 3DBrew) | 329 | // Only unit 0 respects the texturing type (according to 3DBrew) |
| 286 | // TODO: Refactor so cubemaps and shadowmaps can be handled | 330 | // TODO: Refactor so cubemaps and shadowmaps can be handled |
| 331 | PAddr texture_address = texture.config.GetPhysicalAddress(); | ||
| 287 | if (i == 0) { | 332 | if (i == 0) { |
| 288 | switch (texture.config.type) { | 333 | switch (texture.config.type) { |
| 289 | case TexturingRegs::TextureConfig::Texture2D: | 334 | case TexturingRegs::TextureConfig::Texture2D: |
| 290 | break; | 335 | break; |
| 336 | case TexturingRegs::TextureConfig::TextureCube: { | ||
| 337 | auto w = GetInterpolatedAttribute(v0.tc0_w, v1.tc0_w, v2.tc0_w); | ||
| 338 | std::tie(u, v, texture_address) = ConvertCubeCoord(u, v, w, regs.texturing); | ||
| 339 | break; | ||
| 340 | } | ||
| 291 | case TexturingRegs::TextureConfig::Projection2D: { | 341 | case TexturingRegs::TextureConfig::Projection2D: { |
| 292 | auto tc0_w = GetInterpolatedAttribute(v0.tc0_w, v1.tc0_w, v2.tc0_w); | 342 | auto tc0_w = GetInterpolatedAttribute(v0.tc0_w, v1.tc0_w, v2.tc0_w); |
| 293 | u /= tc0_w; | 343 | u /= tc0_w; |
| @@ -322,8 +372,7 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve | |||
| 322 | t = texture.config.height - 1 - | 372 | t = texture.config.height - 1 - |
| 323 | GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height); | 373 | GetWrappedTexCoord(texture.config.wrap_t, t, texture.config.height); |
| 324 | 374 | ||
| 325 | u8* texture_data = | 375 | const u8* texture_data = Memory::GetPhysicalPointer(texture_address); |
| 326 | Memory::GetPhysicalPointer(texture.config.GetPhysicalAddress()); | ||
| 327 | auto info = | 376 | auto info = |
| 328 | Texture::TextureInfo::FromPicaRegister(texture.config, texture.format); | 377 | Texture::TextureInfo::FromPicaRegister(texture.config, texture.format); |
| 329 | 378 | ||