diff options
| author | 2014-07-16 11:27:58 +0200 | |
|---|---|---|
| committer | 2014-07-23 00:33:08 +0200 | |
| commit | 246cb75584af281596b938f898e8a3aedbcdb62a (patch) | |
| tree | e87322b8dbcf7e7d2975bc6874f0fd3487a46eb7 /src/core/hw/gpu.h | |
| parent | GPU: Make use of RegisterSet. (diff) | |
| download | yuzu-246cb75584af281596b938f898e8a3aedbcdb62a.tar.gz yuzu-246cb75584af281596b938f898e8a3aedbcdb62a.tar.xz yuzu-246cb75584af281596b938f898e8a3aedbcdb62a.zip | |
RegisterSet: Simplify code by using structs for register definition instead of unions.
Diffstat (limited to 'src/core/hw/gpu.h')
| -rw-r--r-- | src/core/hw/gpu.h | 154 |
1 files changed, 72 insertions, 82 deletions
diff --git a/src/core/hw/gpu.h b/src/core/hw/gpu.h index ce524bd02..4ef0a047f 100644 --- a/src/core/hw/gpu.h +++ b/src/core/hw/gpu.h | |||
| @@ -29,7 +29,7 @@ struct Regs { | |||
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| 31 | template<Id id> | 31 | template<Id id> |
| 32 | union Struct; | 32 | struct Struct; |
| 33 | 33 | ||
| 34 | enum class FramebufferFormat : u32 { | 34 | enum class FramebufferFormat : u32 { |
| 35 | RGBA8 = 0, | 35 | RGBA8 = 0, |
| @@ -38,128 +38,118 @@ struct Regs { | |||
| 38 | RGB5A1 = 3, | 38 | RGB5A1 = 3, |
| 39 | RGBA4 = 4, | 39 | RGBA4 = 4, |
| 40 | }; | 40 | }; |
| 41 | |||
| 42 | }; | 41 | }; |
| 43 | 42 | ||
| 44 | template<> | 43 | template<> |
| 45 | union Regs::Struct<Regs::MemoryFill> { | 44 | struct Regs::Struct<Regs::MemoryFill> { |
| 46 | struct { | 45 | u32 address_start; |
| 47 | u32 address_start; | 46 | u32 address_end; // ? |
| 48 | u32 address_end; // ? | 47 | u32 size; |
| 49 | u32 size; | 48 | u32 value; // ? |
| 50 | u32 value; // ? | 49 | |
| 51 | 50 | inline u32 GetStartAddress() const { | |
| 52 | inline u32 GetStartAddress() const { | 51 | return address_start * 8; |
| 53 | return address_start * 8; | 52 | } |
| 54 | } | 53 | |
| 55 | 54 | inline u32 GetEndAddress() const { | |
| 56 | inline u32 GetEndAddress() const { | 55 | return address_end * 8; |
| 57 | return address_end * 8; | 56 | } |
| 58 | } | ||
| 59 | } data; | ||
| 60 | }; | 57 | }; |
| 61 | static_assert(sizeof(Regs::Struct<Regs::MemoryFill>) == 0x10, "Structure size and register block length don't match"); | 58 | static_assert(sizeof(Regs::Struct<Regs::MemoryFill>) == 0x10, "Structure size and register block length don't match"); |
| 62 | 59 | ||
| 63 | template<> | 60 | template<> |
| 64 | union Regs::Struct<Regs::FramebufferTop> { | 61 | struct Regs::Struct<Regs::FramebufferTop> { |
| 65 | using Format = Regs::FramebufferFormat; | 62 | using Format = Regs::FramebufferFormat; |
| 66 | 63 | ||
| 67 | struct { | 64 | union { |
| 68 | union { | 65 | u32 size; |
| 69 | u32 size; | ||
| 70 | 66 | ||
| 71 | BitField< 0, 16, u32> width; | 67 | BitField< 0, 16, u32> width; |
| 72 | BitField<16, 16, u32> height; | 68 | BitField<16, 16, u32> height; |
| 73 | }; | 69 | }; |
| 74 | 70 | ||
| 75 | u32 pad0[2]; | 71 | u32 pad0[2]; |
| 76 | 72 | ||
| 77 | u32 address_left1; | 73 | u32 address_left1; |
| 78 | u32 address_left2; | 74 | u32 address_left2; |
| 79 | 75 | ||
| 80 | union { | 76 | union { |
| 81 | u32 format; | 77 | u32 format; |
| 82 | 78 | ||
| 83 | BitField< 0, 3, Format> color_format; | 79 | BitField< 0, 3, Format> color_format; |
| 84 | }; | 80 | }; |
| 85 | 81 | ||
| 86 | u32 pad1; | 82 | u32 pad1; |
| 87 | 83 | ||
| 88 | union { | 84 | union { |
| 89 | u32 active_fb; | 85 | u32 active_fb; |
| 90 | 86 | ||
| 91 | BitField<0, 1, u32> second_fb_active; | 87 | BitField<0, 1, u32> second_fb_active; |
| 92 | }; | 88 | }; |
| 93 | 89 | ||
| 94 | u32 pad2[5]; | 90 | u32 pad2[5]; |
| 95 | 91 | ||
| 96 | u32 stride; | 92 | u32 stride; |
| 97 | 93 | ||
| 98 | u32 address_right1; | 94 | u32 address_right1; |
| 99 | u32 address_right2; | 95 | u32 address_right2; |
| 100 | } data; | ||
| 101 | }; | 96 | }; |
| 97 | |||
| 102 | template<> | 98 | template<> |
| 103 | union Regs::Struct<Regs::FramebufferBottom> { | 99 | struct Regs::Struct<Regs::FramebufferBottom> : public Regs::Struct<Regs::FramebufferTop> { |
| 104 | using Type = decltype(Regs::Struct<Regs::FramebufferTop>::data); | ||
| 105 | Type data; | ||
| 106 | }; | 100 | }; |
| 107 | static_assert(sizeof(Regs::Struct<Regs::FramebufferTop>) == 0x40, "Structure size and register block length don't match"); | 101 | static_assert(sizeof(Regs::Struct<Regs::FramebufferTop>) == 0x40, "Structure size and register block length don't match"); |
| 108 | 102 | ||
| 109 | template<> | 103 | template<> |
| 110 | union Regs::Struct<Regs::DisplayTransfer> { | 104 | struct Regs::Struct<Regs::DisplayTransfer> { |
| 111 | using Format = Regs::FramebufferFormat; | 105 | using Format = Regs::FramebufferFormat; |
| 112 | 106 | ||
| 113 | struct { | 107 | u32 input_address; |
| 114 | u32 input_address; | 108 | u32 output_address; |
| 115 | u32 output_address; | ||
| 116 | 109 | ||
| 117 | inline u32 GetPhysicalInputAddress() const { | 110 | inline u32 GetPhysicalInputAddress() const { |
| 118 | return input_address * 8; | 111 | return input_address * 8; |
| 119 | } | 112 | } |
| 120 | 113 | ||
| 121 | inline u32 GetPhysicalOutputAddress() const { | 114 | inline u32 GetPhysicalOutputAddress() const { |
| 122 | return output_address * 8; | 115 | return output_address * 8; |
| 123 | } | 116 | } |
| 124 | 117 | ||
| 125 | union { | 118 | union { |
| 126 | u32 output_size; | 119 | u32 output_size; |
| 127 | 120 | ||
| 128 | BitField< 0, 16, u32> output_width; | 121 | BitField< 0, 16, u32> output_width; |
| 129 | BitField<16, 16, u32> output_height; | 122 | BitField<16, 16, u32> output_height; |
| 130 | }; | 123 | }; |
| 131 | 124 | ||
| 132 | union { | 125 | union { |
| 133 | u32 input_size; | 126 | u32 input_size; |
| 134 | 127 | ||
| 135 | BitField< 0, 16, u32> input_width; | 128 | BitField< 0, 16, u32> input_width; |
| 136 | BitField<16, 16, u32> input_height; | 129 | BitField<16, 16, u32> input_height; |
| 137 | }; | 130 | }; |
| 138 | 131 | ||
| 139 | union { | 132 | union { |
| 140 | u32 flags; | 133 | u32 flags; |
| 141 | 134 | ||
| 142 | BitField< 0, 1, u32> flip_data; | 135 | BitField< 0, 1, u32> flip_data; |
| 143 | BitField< 8, 3, Format> input_format; | 136 | BitField< 8, 3, Format> input_format; |
| 144 | BitField<12, 3, Format> output_format; | 137 | BitField<12, 3, Format> output_format; |
| 145 | BitField<16, 1, u32> output_tiled; | 138 | BitField<16, 1, u32> output_tiled; |
| 146 | }; | 139 | }; |
| 147 | 140 | ||
| 148 | u32 unknown; | 141 | u32 unknown; |
| 149 | u32 trigger; | 142 | u32 trigger; |
| 150 | } data; | ||
| 151 | }; | 143 | }; |
| 152 | static_assert(sizeof(Regs::Struct<Regs::DisplayTransfer>) == 0x1C, "Structure size and register block length don't match"); | 144 | static_assert(sizeof(Regs::Struct<Regs::DisplayTransfer>) == 0x1C, "Structure size and register block length don't match"); |
| 153 | 145 | ||
| 154 | template<> | 146 | template<> |
| 155 | union Regs::Struct<Regs::CommandProcessor> { | 147 | struct Regs::Struct<Regs::CommandProcessor> { |
| 156 | struct { | 148 | u32 size; |
| 157 | u32 size; | 149 | u32 pad0; |
| 158 | u32 pad0; | 150 | u32 address; |
| 159 | u32 address; | 151 | u32 pad1; |
| 160 | u32 pad1; | 152 | u32 trigger; |
| 161 | u32 trigger; | ||
| 162 | } data; | ||
| 163 | }; | 153 | }; |
| 164 | static_assert(sizeof(Regs::Struct<Regs::CommandProcessor>) == 0x14, "Structure size and register block length don't match"); | 154 | static_assert(sizeof(Regs::Struct<Regs::CommandProcessor>) == 0x14, "Structure size and register block length don't match"); |
| 165 | 155 | ||