diff options
| author | 2014-07-22 19:20:57 -0400 | |
|---|---|---|
| committer | 2014-07-22 19:20:57 -0400 | |
| commit | daa924b906ff3a6f54d00c5d19874c2f839af0a3 (patch) | |
| tree | 127b4998ece87140690b7e74853215522d57ecaa /src/core/hw/gpu.h | |
| parent | Merge pull request #32 from yuriks/master (diff) | |
| parent | Use uniform formatting when printing hexadecimal numbers. (diff) | |
| download | yuzu-daa924b906ff3a6f54d00c5d19874c2f839af0a3.tar.gz yuzu-daa924b906ff3a6f54d00c5d19874c2f839af0a3.tar.xz yuzu-daa924b906ff3a6f54d00c5d19874c2f839af0a3.zip | |
Merge pull request #31 from neobrain/gpu_framebuffer
GPU framebuffer emulation improvements
Diffstat (limited to 'src/core/hw/gpu.h')
| -rw-r--r-- | src/core/hw/gpu.h | 219 |
1 files changed, 179 insertions, 40 deletions
diff --git a/src/core/hw/gpu.h b/src/core/hw/gpu.h index 3314ba989..42f18a0e7 100644 --- a/src/core/hw/gpu.h +++ b/src/core/hw/gpu.h | |||
| @@ -5,43 +5,168 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include "common/common_types.h" | 7 | #include "common/common_types.h" |
| 8 | #include "common/bit_field.h" | ||
| 9 | #include "common/register_set.h" | ||
| 8 | 10 | ||
| 9 | namespace GPU { | 11 | namespace GPU { |
| 10 | 12 | ||
| 11 | static const u32 kFrameCycles = 268123480 / 60; ///< 268MHz / 60 frames per second | 13 | static const u32 kFrameCycles = 268123480 / 60; ///< 268MHz / 60 frames per second |
| 12 | static const u32 kFrameTicks = kFrameCycles / 3; ///< Approximate number of instructions/frame | 14 | static const u32 kFrameTicks = kFrameCycles / 3; ///< Approximate number of instructions/frame |
| 13 | 15 | ||
| 14 | struct Registers { | 16 | // MMIO region 0x1EFxxxxx |
| 17 | struct Regs { | ||
| 15 | enum Id : u32 { | 18 | enum Id : u32 { |
| 16 | FramebufferTopLeft1 = 0x1EF00468, // Main LCD, first framebuffer for 3D left | 19 | MemoryFill = 0x00004, // + 5,6,7; second block at 8-11 |
| 17 | FramebufferTopLeft2 = 0x1EF0046C, // Main LCD, second framebuffer for 3D left | 20 | |
| 18 | FramebufferTopRight1 = 0x1EF00494, // Main LCD, first framebuffer for 3D right | 21 | FramebufferTop = 0x00117, // + 11a,11b,11c,11d(?),11e...126 |
| 19 | FramebufferTopRight2 = 0x1EF00498, // Main LCD, second framebuffer for 3D right | 22 | FramebufferBottom = 0x00157, // + 15a,15b,15c,15d(?),15e...166 |
| 20 | FramebufferSubLeft1 = 0x1EF00568, // Sub LCD, first framebuffer | 23 | |
| 21 | FramebufferSubLeft2 = 0x1EF0056C, // Sub LCD, second framebuffer | 24 | DisplayTransfer = 0x00300, // + 301,302,303,304,305,306 |
| 22 | FramebufferSubRight1 = 0x1EF00594, // Sub LCD, unused first framebuffer | 25 | |
| 23 | FramebufferSubRight2 = 0x1EF00598, // Sub LCD, unused second framebuffer | 26 | CommandProcessor = 0x00638, // + 63a,63c |
| 24 | 27 | ||
| 25 | CommandListSize = 0x1EF018E0, | 28 | NumIds = 0x01000 |
| 26 | CommandListAddress = 0x1EF018E8, | 29 | }; |
| 27 | ProcessCommandList = 0x1EF018F0, | 30 | |
| 31 | template<Id id> | ||
| 32 | struct Struct; | ||
| 33 | |||
| 34 | enum class FramebufferFormat : u32 { | ||
| 35 | RGBA8 = 0, | ||
| 36 | RGB8 = 1, | ||
| 37 | RGB565 = 2, | ||
| 38 | RGB5A1 = 3, | ||
| 39 | RGBA4 = 4, | ||
| 40 | }; | ||
| 41 | }; | ||
| 42 | |||
| 43 | template<> | ||
| 44 | struct Regs::Struct<Regs::MemoryFill> { | ||
| 45 | u32 address_start; | ||
| 46 | u32 address_end; // ? | ||
| 47 | u32 size; | ||
| 48 | u32 value; // ? | ||
| 49 | |||
| 50 | inline u32 GetStartAddress() const { | ||
| 51 | return address_start * 8; | ||
| 52 | } | ||
| 53 | |||
| 54 | inline u32 GetEndAddress() const { | ||
| 55 | return address_end * 8; | ||
| 56 | } | ||
| 57 | }; | ||
| 58 | static_assert(sizeof(Regs::Struct<Regs::MemoryFill>) == 0x10, "Structure size and register block length don't match"); | ||
| 59 | |||
| 60 | template<> | ||
| 61 | struct Regs::Struct<Regs::FramebufferTop> { | ||
| 62 | using Format = Regs::FramebufferFormat; | ||
| 63 | |||
| 64 | union { | ||
| 65 | u32 size; | ||
| 66 | |||
| 67 | BitField< 0, 16, u32> width; | ||
| 68 | BitField<16, 16, u32> height; | ||
| 69 | }; | ||
| 70 | |||
| 71 | u32 pad0[2]; | ||
| 72 | |||
| 73 | u32 address_left1; | ||
| 74 | u32 address_left2; | ||
| 75 | |||
| 76 | union { | ||
| 77 | u32 format; | ||
| 78 | |||
| 79 | BitField< 0, 3, Format> color_format; | ||
| 80 | }; | ||
| 81 | |||
| 82 | u32 pad1; | ||
| 83 | |||
| 84 | union { | ||
| 85 | u32 active_fb; | ||
| 86 | |||
| 87 | // 0: Use parameters ending with "1" | ||
| 88 | // 1: Use parameters ending with "2" | ||
| 89 | BitField<0, 1, u32> second_fb_active; | ||
| 90 | }; | ||
| 91 | |||
| 92 | u32 pad2[5]; | ||
| 93 | |||
| 94 | // Distance between two pixel rows, in bytes | ||
| 95 | u32 stride; | ||
| 96 | |||
| 97 | u32 address_right1; | ||
| 98 | u32 address_right2; | ||
| 99 | }; | ||
| 100 | |||
| 101 | template<> | ||
| 102 | struct Regs::Struct<Regs::FramebufferBottom> : public Regs::Struct<Regs::FramebufferTop> { | ||
| 103 | }; | ||
| 104 | static_assert(sizeof(Regs::Struct<Regs::FramebufferTop>) == 0x40, "Structure size and register block length don't match"); | ||
| 105 | |||
| 106 | template<> | ||
| 107 | struct Regs::Struct<Regs::DisplayTransfer> { | ||
| 108 | using Format = Regs::FramebufferFormat; | ||
| 109 | |||
| 110 | u32 input_address; | ||
| 111 | u32 output_address; | ||
| 112 | |||
| 113 | inline u32 GetPhysicalInputAddress() const { | ||
| 114 | return input_address * 8; | ||
| 115 | } | ||
| 116 | |||
| 117 | inline u32 GetPhysicalOutputAddress() const { | ||
| 118 | return output_address * 8; | ||
| 119 | } | ||
| 120 | |||
| 121 | union { | ||
| 122 | u32 output_size; | ||
| 123 | |||
| 124 | BitField< 0, 16, u32> output_width; | ||
| 125 | BitField<16, 16, u32> output_height; | ||
| 126 | }; | ||
| 127 | |||
| 128 | union { | ||
| 129 | u32 input_size; | ||
| 130 | |||
| 131 | BitField< 0, 16, u32> input_width; | ||
| 132 | BitField<16, 16, u32> input_height; | ||
| 28 | }; | 133 | }; |
| 29 | 134 | ||
| 30 | u32 framebuffer_top_left_1; | 135 | union { |
| 31 | u32 framebuffer_top_left_2; | 136 | u32 flags; |
| 32 | u32 framebuffer_top_right_1; | 137 | |
| 33 | u32 framebuffer_top_right_2; | 138 | BitField< 0, 1, u32> flip_data; // flips input data horizontally (TODO) if true |
| 34 | u32 framebuffer_sub_left_1; | 139 | BitField< 8, 3, Format> input_format; |
| 35 | u32 framebuffer_sub_left_2; | 140 | BitField<12, 3, Format> output_format; |
| 36 | u32 framebuffer_sub_right_1; | 141 | BitField<16, 1, u32> output_tiled; // stores output in a tiled format |
| 37 | u32 framebuffer_sub_right_2; | 142 | }; |
| 38 | 143 | ||
| 39 | u32 command_list_size; | 144 | u32 unknown; |
| 40 | u32 command_list_address; | 145 | |
| 41 | u32 command_processing_enabled; | 146 | // it seems that writing to this field triggers the display transfer |
| 147 | u32 trigger; | ||
| 42 | }; | 148 | }; |
| 149 | static_assert(sizeof(Regs::Struct<Regs::DisplayTransfer>) == 0x1C, "Structure size and register block length don't match"); | ||
| 150 | |||
| 151 | template<> | ||
| 152 | struct Regs::Struct<Regs::CommandProcessor> { | ||
| 153 | // command list size | ||
| 154 | u32 size; | ||
| 155 | |||
| 156 | u32 pad0; | ||
| 157 | |||
| 158 | // command list address | ||
| 159 | u32 address; | ||
| 43 | 160 | ||
| 44 | extern Registers g_regs; | 161 | u32 pad1; |
| 162 | |||
| 163 | // it seems that writing to this field triggers command list processing | ||
| 164 | u32 trigger; | ||
| 165 | }; | ||
| 166 | static_assert(sizeof(Regs::Struct<Regs::CommandProcessor>) == 0x14, "Structure size and register block length don't match"); | ||
| 167 | |||
| 168 | |||
| 169 | extern RegisterSet<u32, Regs> g_regs; | ||
| 45 | 170 | ||
| 46 | enum { | 171 | enum { |
| 47 | TOP_ASPECT_X = 0x5, | 172 | TOP_ASPECT_X = 0x5, |
| @@ -51,23 +176,35 @@ enum { | |||
| 51 | TOP_WIDTH = 400, | 176 | TOP_WIDTH = 400, |
| 52 | BOTTOM_WIDTH = 320, | 177 | BOTTOM_WIDTH = 320, |
| 53 | 178 | ||
| 54 | // Physical addresses in FCRAM used by ARM9 applications - these are correct for real hardware | 179 | // Physical addresses in FCRAM (chosen arbitrarily) |
| 55 | PADDR_FRAMEBUFFER_SEL = 0x20184E59, | 180 | PADDR_TOP_LEFT_FRAME1 = 0x201D4C00, |
| 56 | PADDR_TOP_LEFT_FRAME1 = 0x20184E60, | 181 | PADDR_TOP_LEFT_FRAME2 = 0x202D4C00, |
| 182 | PADDR_TOP_RIGHT_FRAME1 = 0x203D4C00, | ||
| 183 | PADDR_TOP_RIGHT_FRAME2 = 0x204D4C00, | ||
| 184 | PADDR_SUB_FRAME1 = 0x205D4C00, | ||
| 185 | PADDR_SUB_FRAME2 = 0x206D4C00, | ||
| 186 | // Physical addresses in FCRAM used by ARM9 applications | ||
| 187 | /* PADDR_TOP_LEFT_FRAME1 = 0x20184E60, | ||
| 57 | PADDR_TOP_LEFT_FRAME2 = 0x201CB370, | 188 | PADDR_TOP_LEFT_FRAME2 = 0x201CB370, |
| 58 | PADDR_TOP_RIGHT_FRAME1 = 0x20282160, | 189 | PADDR_TOP_RIGHT_FRAME1 = 0x20282160, |
| 59 | PADDR_TOP_RIGHT_FRAME2 = 0x202C8670, | 190 | PADDR_TOP_RIGHT_FRAME2 = 0x202C8670, |
| 60 | PADDR_SUB_FRAME1 = 0x202118E0, | 191 | PADDR_SUB_FRAME1 = 0x202118E0, |
| 61 | PADDR_SUB_FRAME2 = 0x20249CF0, | 192 | PADDR_SUB_FRAME2 = 0x20249CF0,*/ |
| 62 | 193 | ||
| 63 | // Physical addresses in VRAM - I'm not sure how these are actually allocated (so not real) | 194 | // Physical addresses in VRAM |
| 64 | PADDR_VRAM_FRAMEBUFFER_SEL = 0x18184E59, | 195 | // TODO: These should just be deduced from the ones above |
| 65 | PADDR_VRAM_TOP_LEFT_FRAME1 = 0x18184E60, | 196 | PADDR_VRAM_TOP_LEFT_FRAME1 = 0x181D4C00, |
| 66 | PADDR_VRAM_TOP_LEFT_FRAME2 = 0x181CB370, | 197 | PADDR_VRAM_TOP_LEFT_FRAME2 = 0x182D4C00, |
| 198 | PADDR_VRAM_TOP_RIGHT_FRAME1 = 0x183D4C00, | ||
| 199 | PADDR_VRAM_TOP_RIGHT_FRAME2 = 0x184D4C00, | ||
| 200 | PADDR_VRAM_SUB_FRAME1 = 0x185D4C00, | ||
| 201 | PADDR_VRAM_SUB_FRAME2 = 0x186D4C00, | ||
| 202 | // Physical addresses in VRAM used by ARM9 applications | ||
| 203 | /* PADDR_VRAM_TOP_LEFT_FRAME2 = 0x181CB370, | ||
| 67 | PADDR_VRAM_TOP_RIGHT_FRAME1 = 0x18282160, | 204 | PADDR_VRAM_TOP_RIGHT_FRAME1 = 0x18282160, |
| 68 | PADDR_VRAM_TOP_RIGHT_FRAME2 = 0x182C8670, | 205 | PADDR_VRAM_TOP_RIGHT_FRAME2 = 0x182C8670, |
| 69 | PADDR_VRAM_SUB_FRAME1 = 0x182118E0, | 206 | PADDR_VRAM_SUB_FRAME1 = 0x182118E0, |
| 70 | PADDR_VRAM_SUB_FRAME2 = 0x18249CF0, | 207 | PADDR_VRAM_SUB_FRAME2 = 0x18249CF0,*/ |
| 71 | }; | 208 | }; |
| 72 | 209 | ||
| 73 | /// Framebuffer location | 210 | /// Framebuffer location |
| @@ -79,7 +216,7 @@ enum FramebufferLocation { | |||
| 79 | 216 | ||
| 80 | /** | 217 | /** |
| 81 | * Sets whether the framebuffers are in the GSP heap (FCRAM) or VRAM | 218 | * Sets whether the framebuffers are in the GSP heap (FCRAM) or VRAM |
| 82 | * @param | 219 | * @param |
| 83 | */ | 220 | */ |
| 84 | void SetFramebufferLocation(const FramebufferLocation mode); | 221 | void SetFramebufferLocation(const FramebufferLocation mode); |
| 85 | 222 | ||
| @@ -90,16 +227,18 @@ void SetFramebufferLocation(const FramebufferLocation mode); | |||
| 90 | */ | 227 | */ |
| 91 | const u8* GetFramebufferPointer(const u32 address); | 228 | const u8* GetFramebufferPointer(const u32 address); |
| 92 | 229 | ||
| 230 | u32 GetFramebufferAddr(const u32 address); | ||
| 231 | |||
| 93 | /** | 232 | /** |
| 94 | * Gets the location of the framebuffers | 233 | * Gets the location of the framebuffers |
| 95 | */ | 234 | */ |
| 96 | const FramebufferLocation GetFramebufferLocation(); | 235 | FramebufferLocation GetFramebufferLocation(u32 address); |
| 97 | 236 | ||
| 98 | template <typename T> | 237 | template <typename T> |
| 99 | inline void Read(T &var, const u32 addr); | 238 | void Read(T &var, const u32 addr); |
| 100 | 239 | ||
| 101 | template <typename T> | 240 | template <typename T> |
| 102 | inline void Write(u32 addr, const T data); | 241 | void Write(u32 addr, const T data); |
| 103 | 242 | ||
| 104 | /// Update hardware | 243 | /// Update hardware |
| 105 | void Update(); | 244 | void Update(); |