summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Tony Wasserka2014-08-17 14:06:58 +0200
committerGravatar Tony Wasserka2014-08-25 22:03:18 +0200
commit6ea003c7b5ec97d0a754197654cdf6e7fccdba24 (patch)
treeb565322792f592bc2708a969cb395bc0679fe018 /src
parentGSP: Update framebuffer information when necessary. (diff)
downloadyuzu-6ea003c7b5ec97d0a754197654cdf6e7fccdba24.tar.gz
yuzu-6ea003c7b5ec97d0a754197654cdf6e7fccdba24.tar.xz
yuzu-6ea003c7b5ec97d0a754197654cdf6e7fccdba24.zip
Pica: Add debug utility functions for dumping geometry data.
Diffstat (limited to 'src')
-rw-r--r--src/video_core/CMakeLists.txt2
-rw-r--r--src/video_core/command_processor.cpp8
-rw-r--r--src/video_core/debug_utils/debug_utils.cpp60
-rw-r--r--src/video_core/debug_utils/debug_utils.h40
-rw-r--r--src/video_core/video_core.vcxproj2
-rw-r--r--src/video_core/video_core.vcxproj.filters15
6 files changed, 123 insertions, 4 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
index 8e7b93acb..71a1b5ecc 100644
--- a/src/video_core/CMakeLists.txt
+++ b/src/video_core/CMakeLists.txt
@@ -5,6 +5,7 @@ set(SRCS clipper.cpp
5 utils.cpp 5 utils.cpp
6 vertex_shader.cpp 6 vertex_shader.cpp
7 video_core.cpp 7 video_core.cpp
8 debug_utils/debug_utils.cpp
8 renderer_opengl/renderer_opengl.cpp) 9 renderer_opengl/renderer_opengl.cpp)
9 10
10set(HEADERS clipper.h 11set(HEADERS clipper.h
@@ -17,6 +18,7 @@ set(HEADERS clipper.h
17 renderer_base.h 18 renderer_base.h
18 vertex_shader.h 19 vertex_shader.h
19 video_core.h 20 video_core.h
21 debug_utils/debug_utils.h
20 renderer_opengl/renderer_opengl.h) 22 renderer_opengl/renderer_opengl.h)
21 23
22add_library(video_core STATIC ${SRCS} ${HEADERS}) 24add_library(video_core STATIC ${SRCS} ${HEADERS})
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp
index 020a4da3f..2027e58d9 100644
--- a/src/video_core/command_processor.cpp
+++ b/src/video_core/command_processor.cpp
@@ -8,6 +8,7 @@
8#include "primitive_assembly.h" 8#include "primitive_assembly.h"
9#include "vertex_shader.h" 9#include "vertex_shader.h"
10 10
11#include "debug_utils/debug_utils.h"
11 12
12namespace Pica { 13namespace Pica {
13 14
@@ -68,6 +69,8 @@ static inline void WritePicaReg(u32 id, u32 value) {
68 const u16* index_address_16 = (u16*)index_address_8; 69 const u16* index_address_16 = (u16*)index_address_8;
69 bool index_u16 = (bool)index_info.format; 70 bool index_u16 = (bool)index_info.format;
70 71
72 DebugUtils::GeometryDumper geometry_dumper;
73
71 for (int index = 0; index < registers.num_vertices; ++index) 74 for (int index = 0; index < registers.num_vertices; ++index)
72 { 75 {
73 int vertex = is_indexed ? (index_u16 ? index_address_16[index] : index_address_8[index]) : index; 76 int vertex = is_indexed ? (index_u16 ? index_address_16[index] : index_address_8[index]) : index;
@@ -95,6 +98,10 @@ static inline void WritePicaReg(u32 id, u32 value) {
95 input.attr[i][comp].ToFloat32()); 98 input.attr[i][comp].ToFloat32());
96 } 99 }
97 } 100 }
101
102 // NOTE: For now, we simply assume that the first input attribute corresponds to the position.
103 geometry_dumper.AddVertex({input.attr[0][0].ToFloat32(), input.attr[0][1].ToFloat32(), input.attr[0][2].ToFloat32()}, registers.triangle_topology);
104
98 VertexShader::OutputVertex output = VertexShader::RunShader(input, attribute_config.GetNumTotalAttributes()); 105 VertexShader::OutputVertex output = VertexShader::RunShader(input, attribute_config.GetNumTotalAttributes());
99 106
100 if (is_indexed) { 107 if (is_indexed) {
@@ -103,6 +110,7 @@ static inline void WritePicaReg(u32 id, u32 value) {
103 110
104 PrimitiveAssembly::SubmitVertex(output); 111 PrimitiveAssembly::SubmitVertex(output);
105 } 112 }
113 geometry_dumper.Dump();
106 break; 114 break;
107 } 115 }
108 116
diff --git a/src/video_core/debug_utils/debug_utils.cpp b/src/video_core/debug_utils/debug_utils.cpp
new file mode 100644
index 000000000..ac895ec3a
--- /dev/null
+++ b/src/video_core/debug_utils/debug_utils.cpp
@@ -0,0 +1,60 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include <fstream>
6#include <string>
7
8#include "video_core/pica.h"
9
10#include "debug_utils.h"
11
12namespace Pica {
13
14namespace DebugUtils {
15
16void GeometryDumper::AddVertex(std::array<float,3> pos, TriangleTopology topology) {
17 vertices.push_back({pos[0], pos[1], pos[2]});
18
19 int num_vertices = vertices.size();
20
21 switch (topology) {
22 case TriangleTopology::List:
23 case TriangleTopology::ListIndexed:
24 if (0 == (num_vertices % 3))
25 faces.push_back({ num_vertices-3, num_vertices-2, num_vertices-1 });
26 break;
27
28 default:
29 ERROR_LOG(GPU, "Unknown triangle topology %x", (int)topology);
30 exit(0);
31 break;
32 }
33}
34
35void GeometryDumper::Dump() {
36 // NOTE: Permanently enabling this just trashes hard disks for no reason.
37 // Hence, this is currently disabled.
38 return;
39
40 static int index = 0;
41 std::string filename = std::string("geometry_dump") + std::to_string(++index) + ".obj";
42
43 std::ofstream file(filename);
44
45 for (const auto& vertex : vertices) {
46 file << "v " << vertex.pos[0]
47 << " " << vertex.pos[1]
48 << " " << vertex.pos[2] << std::endl;
49 }
50
51 for (const Face& face : faces) {
52 file << "f " << 1+face.index[0]
53 << " " << 1+face.index[1]
54 << " " << 1+face.index[2] << std::endl;
55 }
56}
57
58} // namespace
59
60} // namespace
diff --git a/src/video_core/debug_utils/debug_utils.h b/src/video_core/debug_utils/debug_utils.h
new file mode 100644
index 000000000..9b4dce539
--- /dev/null
+++ b/src/video_core/debug_utils/debug_utils.h
@@ -0,0 +1,40 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8#include <vector>
9
10#include "video_core/pica.h"
11
12namespace Pica {
13
14namespace DebugUtils {
15
16using TriangleTopology = Regs::TriangleTopology;
17
18// Simple utility class for dumping geometry data to an OBJ file
19class GeometryDumper {
20public:
21 void AddVertex(std::array<float,3> pos, TriangleTopology topology);
22
23 void Dump();
24
25private:
26 struct Vertex {
27 std::array<float,3> pos;
28 };
29
30 struct Face {
31 int index[3];
32 };
33
34 std::vector<Vertex> vertices;
35 std::vector<Face> faces;
36};
37
38} // namespace
39
40} // namespace
diff --git a/src/video_core/video_core.vcxproj b/src/video_core/video_core.vcxproj
index 48d77cdc4..4e129fbe7 100644
--- a/src/video_core/video_core.vcxproj
+++ b/src/video_core/video_core.vcxproj
@@ -19,6 +19,7 @@
19 </ProjectConfiguration> 19 </ProjectConfiguration>
20 </ItemGroup> 20 </ItemGroup>
21 <ItemGroup> 21 <ItemGroup>
22 <ClCompile Include="debug_utils\debug_utils.cpp" />
22 <ClCompile Include="renderer_opengl\renderer_opengl.cpp" /> 23 <ClCompile Include="renderer_opengl\renderer_opengl.cpp" />
23 <ClCompile Include="clipper.cpp" /> 24 <ClCompile Include="clipper.cpp" />
24 <ClCompile Include="command_processor.cpp" /> 25 <ClCompile Include="command_processor.cpp" />
@@ -40,6 +41,7 @@
40 <ClInclude Include="utils.h" /> 41 <ClInclude Include="utils.h" />
41 <ClInclude Include="vertex_shader.h" /> 42 <ClInclude Include="vertex_shader.h" />
42 <ClInclude Include="video_core.h" /> 43 <ClInclude Include="video_core.h" />
44 <ClInclude Include="debug_utils\debug_utils.h" />
43 <ClInclude Include="renderer_opengl\renderer_opengl.h" /> 45 <ClInclude Include="renderer_opengl\renderer_opengl.h" />
44 </ItemGroup> 46 </ItemGroup>
45 <ItemGroup> 47 <ItemGroup>
diff --git a/src/video_core/video_core.vcxproj.filters b/src/video_core/video_core.vcxproj.filters
index 31af4f1df..90541aca0 100644
--- a/src/video_core/video_core.vcxproj.filters
+++ b/src/video_core/video_core.vcxproj.filters
@@ -4,6 +4,9 @@
4 <Filter Include="renderer_opengl"> 4 <Filter Include="renderer_opengl">
5 <UniqueIdentifier>{e0245557-dbd4-423e-9399-513d5e99f1e4}</UniqueIdentifier> 5 <UniqueIdentifier>{e0245557-dbd4-423e-9399-513d5e99f1e4}</UniqueIdentifier>
6 </Filter> 6 </Filter>
7 <Filter Include="debug_utils">
8 <UniqueIdentifier>{0ac498e6-bbd8-46e3-9d5f-e816546ab90e}</UniqueIdentifier>
9 </Filter>
7 </ItemGroup> 10 </ItemGroup>
8 <ItemGroup> 11 <ItemGroup>
9 <ClCompile Include="renderer_opengl\renderer_opengl.cpp"> 12 <ClCompile Include="renderer_opengl\renderer_opengl.cpp">
@@ -16,11 +19,11 @@
16 <ClCompile Include="utils.cpp" /> 19 <ClCompile Include="utils.cpp" />
17 <ClCompile Include="vertex_shader.cpp" /> 20 <ClCompile Include="vertex_shader.cpp" />
18 <ClCompile Include="video_core.cpp" /> 21 <ClCompile Include="video_core.cpp" />
22 <ClCompile Include="debug_utils\debug_utils.cpp">
23 <Filter>debug_utils</Filter>
24 </ClCompile>
19 </ItemGroup> 25 </ItemGroup>
20 <ItemGroup> 26 <ItemGroup>
21 <ClInclude Include="renderer_opengl\renderer_opengl.h">
22 <Filter>renderer_opengl</Filter>
23 </ClInclude>
24 <ClInclude Include="clipper.h" /> 27 <ClInclude Include="clipper.h" />
25 <ClInclude Include="command_processor.h" /> 28 <ClInclude Include="command_processor.h" />
26 <ClInclude Include="gpu_debugger.h" /> 29 <ClInclude Include="gpu_debugger.h" />
@@ -32,8 +35,12 @@
32 <ClInclude Include="utils.h" /> 35 <ClInclude Include="utils.h" />
33 <ClInclude Include="vertex_shader.h" /> 36 <ClInclude Include="vertex_shader.h" />
34 <ClInclude Include="video_core.h" /> 37 <ClInclude Include="video_core.h" />
38 <ClInclude Include="renderer_opengl\renderer_opengl.h" />
39 <ClInclude Include="debug_utils\debug_utils.h">
40 <Filter>debug_utils</Filter>
41 </ClInclude>
35 </ItemGroup> 42 </ItemGroup>
36 <ItemGroup> 43 <ItemGroup>
37 <Text Include="CMakeLists.txt" /> 44 <Text Include="CMakeLists.txt" />
38 </ItemGroup> 45 </ItemGroup>
39</Project> 46</Project> \ No newline at end of file