aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Tony Wasserka <NeoBrainX@gmail.com>2014-07-27 14:58:30 +0200
committerGravatar Tony Wasserka <NeoBrainX@gmail.com>2014-08-12 13:48:56 +0200
commit9a76a2d0611fc0c35b665fb886d437e8f4d5b4df (patch)
tree3dc2277e820070ef0d13769c10892f1fd2460d13
parentc52651261916b136f2ea4ff022fb9cead5a73a93 (diff)
Pica: Add primitive assembly stage.
-rw-r--r--src/video_core/CMakeLists.txt2
-rw-r--r--src/video_core/command_processor.cpp3
-rw-r--r--src/video_core/pica.h15
-rw-r--r--src/video_core/primitive_assembly.cpp52
-rw-r--r--src/video_core/primitive_assembly.h21
-rw-r--r--src/video_core/video_core.vcxproj2
-rw-r--r--src/video_core/video_core.vcxproj.filters2
7 files changed, 95 insertions, 2 deletions
diff --git a/src/video_core/CMakeLists.txt b/src/video_core/CMakeLists.txt
index 74304ee4..b06f14db 100644
--- a/src/video_core/CMakeLists.txt
+++ b/src/video_core/CMakeLists.txt
@@ -1,4 +1,5 @@
set(SRCS command_processor.cpp
+ primitive_assembly.cpp
utils.cpp
vertex_shader.cpp
video_core.cpp
@@ -6,6 +7,7 @@ set(SRCS command_processor.cpp
set(HEADERS command_processor.h
math.h
+ primitive_assembly.h
utils.h
video_core.h
renderer_base.h
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp
index 339fa772..020a4da3 100644
--- a/src/video_core/command_processor.cpp
+++ b/src/video_core/command_processor.cpp
@@ -5,6 +5,7 @@
#include "command_processor.h"
#include "math.h"
#include "pica.h"
+#include "primitive_assembly.h"
#include "vertex_shader.h"
@@ -100,7 +101,7 @@ static inline void WritePicaReg(u32 id, u32 value) {
// TODO: Add processed vertex to vertex cache!
}
- // TODO: Submit vertex to primitive assembly
+ PrimitiveAssembly::SubmitVertex(output);
}
break;
}
diff --git a/src/video_core/pica.h b/src/video_core/pica.h
index 42303a58..6bbd3ce3 100644
--- a/src/video_core/pica.h
+++ b/src/video_core/pica.h
@@ -221,7 +221,18 @@ struct Regs {
u32 trigger_draw;
u32 trigger_draw_indexed;
- INSERT_PADDING_WORDS(0x8a);
+ INSERT_PADDING_WORDS(0x2e);
+
+ enum class TriangleTopology : u32 {
+ List = 0,
+ Strip = 1,
+ Fan = 2,
+ ListIndexed = 3, // TODO: No idea if this is correct
+ };
+
+ BitField<8, 2, TriangleTopology> triangle_topology;
+
+ INSERT_PADDING_WORDS(0x5b);
// Offset to shader program entry point (in words)
BitField<0, 16, u32> vs_main_offset;
@@ -334,6 +345,7 @@ struct Regs {
ADD_FIELD(num_vertices);
ADD_FIELD(trigger_draw);
ADD_FIELD(trigger_draw_indexed);
+ ADD_FIELD(triangle_topology);
ADD_FIELD(vs_main_offset);
ADD_FIELD(vs_input_register_map);
ADD_FIELD(vs_uniform_setup);
@@ -386,6 +398,7 @@ ASSERT_REG_POSITION(index_array, 0x227);
ASSERT_REG_POSITION(num_vertices, 0x228);
ASSERT_REG_POSITION(trigger_draw, 0x22e);
ASSERT_REG_POSITION(trigger_draw_indexed, 0x22f);
+ASSERT_REG_POSITION(triangle_topology, 0x25e);
ASSERT_REG_POSITION(vs_main_offset, 0x2ba);
ASSERT_REG_POSITION(vs_input_register_map, 0x2bb);
ASSERT_REG_POSITION(vs_uniform_setup, 0x2c0);
diff --git a/src/video_core/primitive_assembly.cpp b/src/video_core/primitive_assembly.cpp
new file mode 100644
index 00000000..b2196d13
--- /dev/null
+++ b/src/video_core/primitive_assembly.cpp
@@ -0,0 +1,52 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#include "pica.h"
+#include "primitive_assembly.h"
+#include "vertex_shader.h"
+
+namespace Pica {
+
+namespace PrimitiveAssembly {
+
+static OutputVertex buffer[2];
+static int buffer_index = 0; // TODO: reset this on emulation restart
+
+void SubmitVertex(OutputVertex& vtx)
+{
+ switch (registers.triangle_topology) {
+ case Regs::TriangleTopology::List:
+ case Regs::TriangleTopology::ListIndexed:
+ if (buffer_index < 2) {
+ buffer[buffer_index++] = vtx;
+ } else {
+ buffer_index = 0;
+
+ // TODO
+ // Clipper::ProcessTriangle(buffer[0], buffer[1], vtx);
+ }
+ break;
+
+ case Regs::TriangleTopology::Fan:
+ if (buffer_index == 2) {
+ buffer_index = 0;
+
+ // TODO
+ // Clipper::ProcessTriangle(buffer[0], buffer[1], vtx);
+
+ buffer[1] = vtx;
+ } else {
+ buffer[buffer_index++] = vtx;
+ }
+ break;
+
+ default:
+ ERROR_LOG(GPU, "Unknown triangle mode %x:", (int)registers.triangle_topology.Value());
+ break;
+ }
+}
+
+} // namespace
+
+} // namespace
diff --git a/src/video_core/primitive_assembly.h b/src/video_core/primitive_assembly.h
new file mode 100644
index 00000000..2a2b0c17
--- /dev/null
+++ b/src/video_core/primitive_assembly.h
@@ -0,0 +1,21 @@
+// Copyright 2014 Citra Emulator Project
+// Licensed under GPLv2
+// Refer to the license.txt file included.
+
+#pragma once
+
+namespace Pica {
+
+namespace VertexShader {
+ struct OutputVertex;
+}
+
+namespace PrimitiveAssembly {
+
+using VertexShader::OutputVertex;
+
+void SubmitVertex(OutputVertex& vtx);
+
+} // namespace
+
+} // namespace
diff --git a/src/video_core/video_core.vcxproj b/src/video_core/video_core.vcxproj
index 56729dc0..9cf3b085 100644
--- a/src/video_core/video_core.vcxproj
+++ b/src/video_core/video_core.vcxproj
@@ -21,6 +21,7 @@
<ItemGroup>
<ClCompile Include="renderer_opengl\renderer_opengl.cpp" />
<ClCompile Include="command_processor.cpp" />
+ <ClCompile Include="primitive_assembly.cpp" />
<ClCompile Include="utils.cpp" />
<ClCompile Include="vertex_shader.cpp" />
<ClCompile Include="video_core.cpp" />
@@ -30,6 +31,7 @@
<ClInclude Include="gpu_debugger.h" />
<ClInclude Include="math.h" />
<ClInclude Include="pica.h" />
+ <ClInclude Include="primitive_assembly.h" />
<ClInclude Include="renderer_base.h" />
<ClInclude Include="utils.h" />
<ClInclude Include="vertex_shader.h" />
diff --git a/src/video_core/video_core.vcxproj.filters b/src/video_core/video_core.vcxproj.filters
index db0b3701..9da20b28 100644
--- a/src/video_core/video_core.vcxproj.filters
+++ b/src/video_core/video_core.vcxproj.filters
@@ -10,6 +10,7 @@
<Filter>renderer_opengl</Filter>
</ClCompile>
<ClCompile Include="command_processor.cpp" />
+ <ClCompile Include="primitive_assembly.cpp" />
<ClCompile Include="utils.cpp" />
<ClCompile Include="vertex_shader.cpp" />
<ClCompile Include="video_core.cpp" />
@@ -22,6 +23,7 @@
<ClInclude Include="gpu_debugger.h" />
<ClInclude Include="math.h" />
<ClInclude Include="pica.h" />
+ <ClInclude Include="primitive_assembly.h" />
<ClInclude Include="renderer_base.h" />
<ClInclude Include="utils.h" />
<ClInclude Include="vertex_shader.h" />