diff options
| author | 2014-08-14 14:30:38 +0200 | |
|---|---|---|
| committer | 2014-08-25 22:03:18 +0200 | |
| commit | f37e39deb9abe88b4874ebc2889ed52e02ed9c13 (patch) | |
| tree | bbced32a26ee671ffb69de1c42492fc13b8f6724 /src/video_core/debug_utils | |
| parent | Pica: Add debug utility functions for dumping geometry data. (diff) | |
| download | yuzu-f37e39deb9abe88b4874ebc2889ed52e02ed9c13.tar.gz yuzu-f37e39deb9abe88b4874ebc2889ed52e02ed9c13.tar.xz yuzu-f37e39deb9abe88b4874ebc2889ed52e02ed9c13.zip | |
Pica: Add debug utilities for dumping shaders.
Diffstat (limited to 'src/video_core/debug_utils')
| -rw-r--r-- | src/video_core/debug_utils/debug_utils.cpp | 205 | ||||
| -rw-r--r-- | src/video_core/debug_utils/debug_utils.h | 3 |
2 files changed, 208 insertions, 0 deletions
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp index ac895ec3a..f41249eac 100644 --- a/src/video_core/debug_utils/debug_utils.cpp +++ b/src/video_core/debug_utils/debug_utils.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 | 2 | // Licensed under GPLv2 |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <algorithm> | ||
| 5 | #include <fstream> | 6 | #include <fstream> |
| 6 | #include <string> | 7 | #include <string> |
| 7 | 8 | ||
| @@ -55,6 +56,210 @@ void GeometryDumper::Dump() { | |||
| 55 | } | 56 | } |
| 56 | } | 57 | } |
| 57 | 58 | ||
| 59 | #pragma pack(1) | ||
| 60 | struct DVLBHeader { | ||
| 61 | enum : u32 { | ||
| 62 | MAGIC_WORD = 0x424C5644, // "DVLB" | ||
| 63 | }; | ||
| 64 | |||
| 65 | u32 magic_word; | ||
| 66 | u32 num_programs; | ||
| 67 | // u32 dvle_offset_table[]; | ||
| 68 | }; | ||
| 69 | static_assert(sizeof(DVLBHeader) == 0x8, "Incorrect structure size"); | ||
| 70 | |||
| 71 | struct DVLPHeader { | ||
| 72 | enum : u32 { | ||
| 73 | MAGIC_WORD = 0x504C5644, // "DVLP" | ||
| 74 | }; | ||
| 75 | |||
| 76 | u32 magic_word; | ||
| 77 | u32 version; | ||
| 78 | u32 binary_offset; // relative to DVLP start | ||
| 79 | u32 binary_size_words; | ||
| 80 | u32 swizzle_patterns_offset; | ||
| 81 | u32 swizzle_patterns_num_entries; | ||
| 82 | u32 unk2; | ||
| 83 | }; | ||
| 84 | static_assert(sizeof(DVLPHeader) == 0x1C, "Incorrect structure size"); | ||
| 85 | |||
| 86 | struct DVLEHeader { | ||
| 87 | enum : u32 { | ||
| 88 | MAGIC_WORD = 0x454c5644, // "DVLE" | ||
| 89 | }; | ||
| 90 | |||
| 91 | enum class ShaderType : u8 { | ||
| 92 | VERTEX = 0, | ||
| 93 | GEOMETRY = 1, | ||
| 94 | }; | ||
| 95 | |||
| 96 | u32 magic_word; | ||
| 97 | u16 pad1; | ||
| 98 | ShaderType type; | ||
| 99 | u8 pad2; | ||
| 100 | u32 main_offset_words; // offset within binary blob | ||
| 101 | u32 endmain_offset_words; | ||
| 102 | u32 pad3; | ||
| 103 | u32 pad4; | ||
| 104 | u32 constant_table_offset; | ||
| 105 | u32 constant_table_size; // number of entries | ||
| 106 | u32 label_table_offset; | ||
| 107 | u32 label_table_size; | ||
| 108 | u32 output_register_table_offset; | ||
| 109 | u32 output_register_table_size; | ||
| 110 | u32 uniform_table_offset; | ||
| 111 | u32 uniform_table_size; | ||
| 112 | u32 symbol_table_offset; | ||
| 113 | u32 symbol_table_size; | ||
| 114 | |||
| 115 | }; | ||
| 116 | static_assert(sizeof(DVLEHeader) == 0x40, "Incorrect structure size"); | ||
| 117 | #pragma pack() | ||
| 118 | |||
| 119 | void DumpShader(const u32* binary_data, u32 binary_size, const u32* swizzle_data, u32 swizzle_size, | ||
| 120 | u32 main_offset, const Regs::VSOutputAttributes* output_attributes) | ||
| 121 | { | ||
| 122 | // NOTE: Permanently enabling this just trashes hard disks for no reason. | ||
| 123 | // Hence, this is currently disabled. | ||
| 124 | return; | ||
| 125 | |||
| 126 | struct StuffToWrite { | ||
| 127 | u8* pointer; | ||
| 128 | u32 size; | ||
| 129 | }; | ||
| 130 | std::vector<StuffToWrite> writing_queue; | ||
| 131 | u32 write_offset = 0; | ||
| 132 | |||
| 133 | auto QueueForWriting = [&writing_queue,&write_offset](u8* pointer, u32 size) { | ||
| 134 | writing_queue.push_back({pointer, size}); | ||
| 135 | u32 old_write_offset = write_offset; | ||
| 136 | write_offset += size; | ||
| 137 | return old_write_offset; | ||
| 138 | }; | ||
| 139 | |||
| 140 | // First off, try to translate Pica state (one enum for output attribute type and component) | ||
| 141 | // into shbin format (separate type and component mask). | ||
| 142 | union OutputRegisterInfo { | ||
| 143 | enum Type : u64 { | ||
| 144 | POSITION = 0, | ||
| 145 | COLOR = 2, | ||
| 146 | TEXCOORD0 = 3, | ||
| 147 | TEXCOORD1 = 5, | ||
| 148 | TEXCOORD2 = 6, | ||
| 149 | }; | ||
| 150 | |||
| 151 | BitField< 0, 64, u64> hex; | ||
| 152 | |||
| 153 | BitField< 0, 16, Type> type; | ||
| 154 | BitField<16, 16, u64> id; | ||
| 155 | BitField<32, 4, u64> component_mask; | ||
| 156 | }; | ||
| 157 | |||
| 158 | // This is put into a try-catch block to make sure we notice unknown configurations. | ||
| 159 | std::vector<OutputRegisterInfo> output_info_table; | ||
| 160 | for (int i = 0; i < 7; ++i) { | ||
| 161 | using OutputAttributes = Pica::Regs::VSOutputAttributes; | ||
| 162 | |||
| 163 | // TODO: It's still unclear how the attribute components map to the register! | ||
| 164 | // Once we know that, this code probably will not make much sense anymore. | ||
| 165 | std::map<OutputAttributes::Semantic, std::pair<OutputRegisterInfo::Type, u32> > map = { | ||
| 166 | { OutputAttributes::POSITION_X, { OutputRegisterInfo::POSITION, 1} }, | ||
| 167 | { OutputAttributes::POSITION_Y, { OutputRegisterInfo::POSITION, 2} }, | ||
| 168 | { OutputAttributes::POSITION_Z, { OutputRegisterInfo::POSITION, 4} }, | ||
| 169 | { OutputAttributes::POSITION_W, { OutputRegisterInfo::POSITION, 8} }, | ||
| 170 | { OutputAttributes::COLOR_R, { OutputRegisterInfo::COLOR, 1} }, | ||
| 171 | { OutputAttributes::COLOR_G, { OutputRegisterInfo::COLOR, 2} }, | ||
| 172 | { OutputAttributes::COLOR_B, { OutputRegisterInfo::COLOR, 4} }, | ||
| 173 | { OutputAttributes::COLOR_A, { OutputRegisterInfo::COLOR, 8} }, | ||
| 174 | { OutputAttributes::TEXCOORD0_U, { OutputRegisterInfo::TEXCOORD0, 1} }, | ||
| 175 | { OutputAttributes::TEXCOORD0_V, { OutputRegisterInfo::TEXCOORD0, 2} }, | ||
| 176 | { OutputAttributes::TEXCOORD1_U, { OutputRegisterInfo::TEXCOORD1, 1} }, | ||
| 177 | { OutputAttributes::TEXCOORD1_V, { OutputRegisterInfo::TEXCOORD1, 2} }, | ||
| 178 | { OutputAttributes::TEXCOORD2_U, { OutputRegisterInfo::TEXCOORD2, 1} }, | ||
| 179 | { OutputAttributes::TEXCOORD2_V, { OutputRegisterInfo::TEXCOORD2, 2} } | ||
| 180 | }; | ||
| 181 | |||
| 182 | for (const auto& semantic : std::vector<OutputAttributes::Semantic>{ | ||
| 183 | output_attributes[i].map_x, | ||
| 184 | output_attributes[i].map_y, | ||
| 185 | output_attributes[i].map_z, | ||
| 186 | output_attributes[i].map_w }) { | ||
| 187 | if (semantic == OutputAttributes::INVALID) | ||
| 188 | continue; | ||
| 189 | |||
| 190 | try { | ||
| 191 | OutputRegisterInfo::Type type = map.at(semantic).first; | ||
| 192 | u32 component_mask = map.at(semantic).second; | ||
| 193 | |||
| 194 | auto it = std::find_if(output_info_table.begin(), output_info_table.end(), | ||
| 195 | [&i, &type](const OutputRegisterInfo& info) { | ||
| 196 | return info.id == i && info.type == type; | ||
| 197 | } | ||
| 198 | ); | ||
| 199 | |||
| 200 | if (it == output_info_table.end()) { | ||
| 201 | output_info_table.push_back({}); | ||
| 202 | output_info_table.back().type = type; | ||
| 203 | output_info_table.back().component_mask = component_mask; | ||
| 204 | output_info_table.back().id = i; | ||
| 205 | } else { | ||
| 206 | it->component_mask = it->component_mask | component_mask; | ||
| 207 | } | ||
| 208 | } catch (const std::out_of_range& oor) { | ||
| 209 | _dbg_assert_msg_(GPU, 0, "Unknown output attribute mapping"); | ||
| 210 | ERROR_LOG(GPU, "Unknown output attribute mapping: %03x, %03x, %03x, %03x", | ||
| 211 | (int)output_attributes[i].map_x.Value(), | ||
| 212 | (int)output_attributes[i].map_y.Value(), | ||
| 213 | (int)output_attributes[i].map_z.Value(), | ||
| 214 | (int)output_attributes[i].map_w.Value()); | ||
| 215 | } | ||
| 216 | } | ||
| 217 | } | ||
| 218 | |||
| 219 | |||
| 220 | struct { | ||
| 221 | DVLBHeader header; | ||
| 222 | u32 dvle_offset; | ||
| 223 | } dvlb{ {DVLBHeader::MAGIC_WORD, 1 } }; // 1 DVLE | ||
| 224 | |||
| 225 | DVLPHeader dvlp{ DVLPHeader::MAGIC_WORD }; | ||
| 226 | DVLEHeader dvle{ DVLEHeader::MAGIC_WORD }; | ||
| 227 | |||
| 228 | QueueForWriting((u8*)&dvlb, sizeof(dvlb)); | ||
| 229 | u32 dvlp_offset = QueueForWriting((u8*)&dvlp, sizeof(dvlp)); | ||
| 230 | dvlb.dvle_offset = QueueForWriting((u8*)&dvle, sizeof(dvle)); | ||
| 231 | |||
| 232 | // TODO: Reduce the amount of binary code written to relevant portions | ||
| 233 | dvlp.binary_offset = write_offset - dvlp_offset; | ||
| 234 | dvlp.binary_size_words = binary_size; | ||
| 235 | QueueForWriting((u8*)binary_data, binary_size * sizeof(u32)); | ||
| 236 | |||
| 237 | dvlp.swizzle_patterns_offset = write_offset - dvlp_offset; | ||
| 238 | dvlp.swizzle_patterns_num_entries = swizzle_size; | ||
| 239 | u32 dummy = 0; | ||
| 240 | for (int i = 0; i < swizzle_size; ++i) { | ||
| 241 | QueueForWriting((u8*)&swizzle_data[i], sizeof(swizzle_data[i])); | ||
| 242 | QueueForWriting((u8*)&dummy, sizeof(dummy)); | ||
| 243 | } | ||
| 244 | |||
| 245 | dvle.main_offset_words = main_offset; | ||
| 246 | dvle.output_register_table_offset = write_offset - dvlb.dvle_offset; | ||
| 247 | dvle.output_register_table_size = output_info_table.size(); | ||
| 248 | QueueForWriting((u8*)output_info_table.data(), output_info_table.size() * sizeof(OutputRegisterInfo)); | ||
| 249 | |||
| 250 | // TODO: Create a label table for "main" | ||
| 251 | |||
| 252 | |||
| 253 | // Write data to file | ||
| 254 | static int dump_index = 0; | ||
| 255 | std::string filename = std::string("shader_dump") + std::to_string(++dump_index) + std::string(".shbin"); | ||
| 256 | std::ofstream file(filename, std::ios_base::out | std::ios_base::binary); | ||
| 257 | |||
| 258 | for (auto& chunk : writing_queue) { | ||
| 259 | file.write((char*)chunk.pointer, chunk.size); | ||
| 260 | } | ||
| 261 | } | ||
| 262 | |||
| 58 | } // namespace | 263 | } // namespace |
| 59 | 264 | ||
| 60 | } // namespace | 265 | } // namespace |
diff --git a/src/video_core/debug_utils/debug_utils.h b/src/video_core/debug_utils/debug_utils.h index 9b4dce539..bd7a0a89b 100644 --- a/src/video_core/debug_utils/debug_utils.h +++ b/src/video_core/debug_utils/debug_utils.h | |||
| @@ -35,6 +35,9 @@ private: | |||
| 35 | std::vector<Face> faces; | 35 | std::vector<Face> faces; |
| 36 | }; | 36 | }; |
| 37 | 37 | ||
| 38 | void DumpShader(const u32* binary_data, u32 binary_size, const u32* swizzle_data, u32 swizzle_size, | ||
| 39 | u32 main_offset, const Regs::VSOutputAttributes* output_attributes); | ||
| 40 | |||
| 38 | } // namespace | 41 | } // namespace |
| 39 | 42 | ||
| 40 | } // namespace | 43 | } // namespace |