diff options
Diffstat (limited to '')
| -rw-r--r-- | src/video_core/pica.h | 161 |
1 files changed, 128 insertions, 33 deletions
diff --git a/src/video_core/pica.h b/src/video_core/pica.h index 0e231c6c9..5bd7f416e 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h | |||
| @@ -11,6 +11,8 @@ | |||
| 11 | #include "common/bit_field.h" | 11 | #include "common/bit_field.h" |
| 12 | #include "common/common_types.h" | 12 | #include "common/common_types.h" |
| 13 | 13 | ||
| 14 | #include "core/mem_map.h" | ||
| 15 | |||
| 14 | namespace Pica { | 16 | namespace Pica { |
| 15 | 17 | ||
| 16 | // Returns index corresponding to the Regs member labeled by field_name | 18 | // Returns index corresponding to the Regs member labeled by field_name |
| @@ -50,7 +52,7 @@ struct Regs { | |||
| 50 | 52 | ||
| 51 | INSERT_PADDING_WORDS(0x1bc); | 53 | INSERT_PADDING_WORDS(0x1bc); |
| 52 | 54 | ||
| 53 | union { | 55 | struct { |
| 54 | enum class Format : u64 { | 56 | enum class Format : u64 { |
| 55 | BYTE = 0, | 57 | BYTE = 0, |
| 56 | UBYTE = 1, | 58 | UBYTE = 1, |
| @@ -58,36 +60,127 @@ struct Regs { | |||
| 58 | FLOAT = 3, | 60 | FLOAT = 3, |
| 59 | }; | 61 | }; |
| 60 | 62 | ||
| 61 | BitField< 0, 2, Format> format0; | 63 | BitField<0, 29, u32> base_address; |
| 62 | BitField< 2, 2, u64> size0; // number of elements minus 1 | 64 | |
| 63 | BitField< 4, 2, Format> format1; | 65 | inline u32 GetBaseAddress() const { |
| 64 | BitField< 6, 2, u64> size1; | 66 | // TODO: Ugly, should fix PhysicalToVirtualAddress instead |
| 65 | BitField< 8, 2, Format> format2; | 67 | return (base_address * 8) - Memory::FCRAM_PADDR + Memory::HEAP_GSP_VADDR; |
| 66 | BitField<10, 2, u64> size2; | 68 | } |
| 67 | BitField<12, 2, Format> format3; | 69 | |
| 68 | BitField<14, 2, u64> size3; | 70 | // Descriptor for internal vertex attributes |
| 69 | BitField<16, 2, Format> format4; | 71 | union { |
| 70 | BitField<18, 2, u64> size4; | 72 | BitField< 0, 2, Format> format0; // size of one element |
| 71 | BitField<20, 2, Format> format5; | 73 | BitField< 2, 2, u64> size0; // number of elements minus 1 |
| 72 | BitField<22, 2, u64> size5; | 74 | BitField< 4, 2, Format> format1; |
| 73 | BitField<24, 2, Format> format6; | 75 | BitField< 6, 2, u64> size1; |
| 74 | BitField<26, 2, u64> size6; | 76 | BitField< 8, 2, Format> format2; |
| 75 | BitField<28, 2, Format> format7; | 77 | BitField<10, 2, u64> size2; |
| 76 | BitField<30, 2, u64> size7; | 78 | BitField<12, 2, Format> format3; |
| 77 | BitField<32, 2, Format> format8; | 79 | BitField<14, 2, u64> size3; |
| 78 | BitField<34, 2, u64> size8; | 80 | BitField<16, 2, Format> format4; |
| 79 | BitField<36, 2, Format> format9; | 81 | BitField<18, 2, u64> size4; |
| 80 | BitField<38, 2, u64> size9; | 82 | BitField<20, 2, Format> format5; |
| 81 | BitField<40, 2, Format> format10; | 83 | BitField<22, 2, u64> size5; |
| 82 | BitField<42, 2, u64> size10; | 84 | BitField<24, 2, Format> format6; |
| 83 | BitField<44, 2, Format> format11; | 85 | BitField<26, 2, u64> size6; |
| 84 | BitField<46, 2, u64> size11; | 86 | BitField<28, 2, Format> format7; |
| 85 | 87 | BitField<30, 2, u64> size7; | |
| 86 | BitField<48, 12, u64> attribute_mask; | 88 | BitField<32, 2, Format> format8; |
| 87 | BitField<60, 4, u64> num_attributes; // number of total attributes minus 1 | 89 | BitField<34, 2, u64> size8; |
| 88 | } vertex_descriptor; | 90 | BitField<36, 2, Format> format9; |
| 89 | 91 | BitField<38, 2, u64> size9; | |
| 90 | INSERT_PADDING_WORDS(0xfe); | 92 | BitField<40, 2, Format> format10; |
| 93 | BitField<42, 2, u64> size10; | ||
| 94 | BitField<44, 2, Format> format11; | ||
| 95 | BitField<46, 2, u64> size11; | ||
| 96 | |||
| 97 | BitField<48, 12, u64> attribute_mask; | ||
| 98 | |||
| 99 | // number of total attributes minus 1 | ||
| 100 | BitField<60, 4, u64> num_extra_attributes; | ||
| 101 | }; | ||
| 102 | |||
| 103 | inline Format GetFormat(int n) const { | ||
| 104 | Format formats[] = { | ||
| 105 | format0, format1, format2, format3, | ||
| 106 | format4, format5, format6, format7, | ||
| 107 | format8, format9, format10, format11 | ||
| 108 | }; | ||
| 109 | return formats[n]; | ||
| 110 | } | ||
| 111 | |||
| 112 | inline int GetNumElements(int n) const { | ||
| 113 | int sizes[] = { | ||
| 114 | size0, size1, size2, size3, | ||
| 115 | size4, size5, size6, size7, | ||
| 116 | size8, size9, size10, size11 | ||
| 117 | }; | ||
| 118 | return sizes[n]+1; | ||
| 119 | } | ||
| 120 | |||
| 121 | inline int GetElementSizeInBytes(int n) const { | ||
| 122 | return (GetFormat(n) == Format::FLOAT) ? 4 : | ||
| 123 | (GetFormat(n) == Format::SHORT) ? 2 : 1; | ||
| 124 | } | ||
| 125 | |||
| 126 | inline int GetStride(int n) const { | ||
| 127 | return GetNumElements(n) * GetElementSizeInBytes(n); | ||
| 128 | } | ||
| 129 | |||
| 130 | inline int GetNumTotalAttributes() const { | ||
| 131 | return num_extra_attributes+1; | ||
| 132 | } | ||
| 133 | |||
| 134 | // Attribute loaders map the source vertex data to input attributes | ||
| 135 | // This e.g. allows to load different attributes from different memory locations | ||
| 136 | struct Loader { | ||
| 137 | // Source attribute data offset from the base address | ||
| 138 | u32 data_offset; | ||
| 139 | |||
| 140 | union { | ||
| 141 | BitField< 0, 4, u64> comp0; | ||
| 142 | BitField< 4, 4, u64> comp1; | ||
| 143 | BitField< 8, 4, u64> comp2; | ||
| 144 | BitField<12, 4, u64> comp3; | ||
| 145 | BitField<16, 4, u64> comp4; | ||
| 146 | BitField<20, 4, u64> comp5; | ||
| 147 | BitField<24, 4, u64> comp6; | ||
| 148 | BitField<28, 4, u64> comp7; | ||
| 149 | BitField<32, 4, u64> comp8; | ||
| 150 | BitField<36, 4, u64> comp9; | ||
| 151 | BitField<40, 4, u64> comp10; | ||
| 152 | BitField<44, 4, u64> comp11; | ||
| 153 | |||
| 154 | // bytes for a single vertex in this loader | ||
| 155 | BitField<48, 8, u64> byte_count; | ||
| 156 | |||
| 157 | BitField<60, 4, u64> component_count; | ||
| 158 | }; | ||
| 159 | |||
| 160 | inline int GetComponent(int n) const { | ||
| 161 | int components[] = { | ||
| 162 | comp0, comp1, comp2, comp3, | ||
| 163 | comp4, comp5, comp6, comp7, | ||
| 164 | comp8, comp9, comp10, comp11 | ||
| 165 | }; | ||
| 166 | return components[n]; | ||
| 167 | } | ||
| 168 | } attribute_loaders[12]; | ||
| 169 | } vertex_attributes; | ||
| 170 | |||
| 171 | struct { | ||
| 172 | enum IndexFormat : u32 { | ||
| 173 | BYTE = 0, | ||
| 174 | SHORT = 1, | ||
| 175 | }; | ||
| 176 | |||
| 177 | union { | ||
| 178 | BitField<0, 31, u32> offset; // relative to base attribute address | ||
| 179 | BitField<31, 1, IndexFormat> format; | ||
| 180 | }; | ||
| 181 | } index_array; | ||
| 182 | |||
| 183 | INSERT_PADDING_WORDS(0xd8); | ||
| 91 | 184 | ||
| 92 | #undef INSERT_PADDING_WORDS_HELPER1 | 185 | #undef INSERT_PADDING_WORDS_HELPER1 |
| 93 | #undef INSERT_PADDING_WORDS_HELPER2 | 186 | #undef INSERT_PADDING_WORDS_HELPER2 |
| @@ -112,7 +205,8 @@ struct Regs { | |||
| 112 | 205 | ||
| 113 | ADD_FIELD(viewport_size_x); | 206 | ADD_FIELD(viewport_size_x); |
| 114 | ADD_FIELD(viewport_size_y); | 207 | ADD_FIELD(viewport_size_y); |
| 115 | ADD_FIELD(vertex_descriptor); | 208 | ADD_FIELD(vertex_attributes); |
| 209 | ADD_FIELD(index_array); | ||
| 116 | 210 | ||
| 117 | #undef ADD_FIELD | 211 | #undef ADD_FIELD |
| 118 | #endif // _MSC_VER | 212 | #endif // _MSC_VER |
| @@ -153,7 +247,8 @@ private: | |||
| 153 | 247 | ||
| 154 | ASSERT_REG_POSITION(viewport_size_x, 0x41); | 248 | ASSERT_REG_POSITION(viewport_size_x, 0x41); |
| 155 | ASSERT_REG_POSITION(viewport_size_y, 0x43); | 249 | ASSERT_REG_POSITION(viewport_size_y, 0x43); |
| 156 | ASSERT_REG_POSITION(vertex_descriptor, 0x200); | 250 | ASSERT_REG_POSITION(vertex_attributes, 0x200); |
| 251 | ASSERT_REG_POSITION(index_array, 0x227); | ||
| 157 | 252 | ||
| 158 | #undef ASSERT_REG_POSITION | 253 | #undef ASSERT_REG_POSITION |
| 159 | #endif // !defined(_MSC_VER) | 254 | #endif // !defined(_MSC_VER) |