Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement geometry shaders (Battle-tested Edition) #2

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/citra_qt/debugger/graphics_breakpoints.cpp
Expand Up @@ -36,6 +36,8 @@ QVariant BreakPointModel::data(const QModelIndex& index, int role) const {
{Pica::DebugContext::Event::IncomingPrimitiveBatch, tr("Incoming primitive batch")},
{Pica::DebugContext::Event::FinishedPrimitiveBatch, tr("Finished primitive batch")},
{Pica::DebugContext::Event::VertexShaderInvocation, tr("Vertex shader invocation")},
{Pica::DebugContext::Event::GeometryShaderInvocation,
tr("Geometry shader invocation")},
{Pica::DebugContext::Event::IncomingDisplayTransfer,
tr("Incoming display transfer")},
{Pica::DebugContext::Event::GSPCommandProcessed, tr("GSP command processed")},
Expand Down
3 changes: 1 addition & 2 deletions src/citra_qt/debugger/graphics_vertex_shader.cpp
Expand Up @@ -522,8 +522,7 @@ void GraphicsVertexShaderWidget::Reload(bool replace_vertex_data, void* vertex_d
info.labels.insert({entry_point, "main"});

// Generate debug information
debug_data = Pica::g_state.vs.ProduceDebugInfo(input_vertex, num_attributes, shader_config,
shader_setup);
debug_data = Pica::g_state.vs.ProduceDebugInfo(input_vertex, num_attributes, shader_config);

// Reload widget state
for (int attr = 0; attr < num_attributes; ++attr) {
Expand Down
234 changes: 161 additions & 73 deletions src/video_core/command_processor.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/video_core/debug_utils/debug_utils.h
Expand Up @@ -39,6 +39,7 @@ class DebugContext {
IncomingPrimitiveBatch,
FinishedPrimitiveBatch,
VertexShaderInvocation,
GeometryShaderInvocation,
IncomingDisplayTransfer,
GSPCommandProcessed,
BufferSwapped,
Expand Down
37 changes: 31 additions & 6 deletions src/video_core/pica.h
Expand Up @@ -1128,7 +1128,7 @@ struct Regs {
// Number of vertices to render
u32 num_vertices;

INSERT_PADDING_WORDS(0x1);
BitField<0, 2, u32> using_geometry_shader;

// The index of the first vertex to render
u32 vertex_offset;
Expand Down Expand Up @@ -1176,7 +1176,11 @@ struct Regs {
}
} command_buffer;

INSERT_PADDING_WORDS(0x07);
INSERT_PADDING_WORDS(0x06);

enum class VSComMode : u32 { Shared = 0, Exclusive = 1 };

VSComMode vs_com_mode;

enum class GPUMode : u32 {
Drawing = 0,
Expand All @@ -1185,7 +1189,17 @@ struct Regs {

GPUMode gpu_mode;

INSERT_PADDING_WORDS(0x18);
INSERT_PADDING_WORDS(0x4);

BitField<0, 4, u32> vs_outmap_total1;

INSERT_PADDING_WORDS(0x6);

BitField<0, 4, u32> vs_outmap_total2;

BitField<0, 4, u32> gsh_misc0;

INSERT_PADDING_WORDS(0xB);

enum class TriangleTopology : u32 {
List = 0,
Expand All @@ -1194,7 +1208,10 @@ struct Regs {
Shader = 3, // Programmable setup unit implemented in a geometry shader
};

BitField<8, 2, TriangleTopology> triangle_topology;
union {
BitField<0, 4, u32> vs_outmap_count;
BitField<8, 2, TriangleTopology> triangle_topology;
};

u32 restart_primitive;

Expand All @@ -1213,8 +1230,10 @@ struct Regs {
INSERT_PADDING_WORDS(0x4);

union {
// Number of input attributes to shader unit - 1
BitField<0, 4, u32> num_input_attributes;
BitField<0, 4, u32>
num_input_attributes; // Number of input attributes to shader unit - 1
BitField<8, 4, u32> use_subdivision;
BitField<24, 8, u32> use_geometry_shader;
};

// Offset to shader program entry point (in words)
Expand Down Expand Up @@ -1267,6 +1286,8 @@ struct Regs {
}

union {
u32 setup;

// Index of the next uniform to write to
// TODO: ctrulib uses 8 bits for this, however that seems to yield lots of invalid
// indices
Expand Down Expand Up @@ -1391,7 +1412,11 @@ ASSERT_REG_POSITION(trigger_draw, 0x22e);
ASSERT_REG_POSITION(trigger_draw_indexed, 0x22f);
ASSERT_REG_POSITION(vs_default_attributes_setup, 0x232);
ASSERT_REG_POSITION(command_buffer, 0x238);
ASSERT_REG_POSITION(vs_com_mode, 0x244);
ASSERT_REG_POSITION(gpu_mode, 0x245);
ASSERT_REG_POSITION(vs_outmap_total1, 0x24A);
ASSERT_REG_POSITION(vs_outmap_total2, 0x251);
ASSERT_REG_POSITION(gsh_misc0, 0x252);
ASSERT_REG_POSITION(triangle_topology, 0x25e);
ASSERT_REG_POSITION(restart_primitive, 0x25f);
ASSERT_REG_POSITION(gs, 0x280);
Expand Down
10 changes: 10 additions & 0 deletions src/video_core/pica_state.h
Expand Up @@ -20,6 +20,8 @@ struct State {
/// Pica registers
Regs regs;

Shader::UnitState<false> shader_units[4];

Shader::ShaderSetup vs;
Shader::ShaderSetup gs;

Expand Down Expand Up @@ -73,6 +75,14 @@ struct State {

// This is constructed with a dummy triangle topology
PrimitiveAssembler<Shader::OutputVertex> primitive_assembler;

/// Current geometry shader state
struct GeometryShaderState {
// Buffer used for geometry shader inputs
Shader::InputVertex buffer;
// The current index into the buffer
unsigned int index;
} gs_input_buffer;
};

extern State g_state; ///< Current Pica state
Expand Down
1 change: 0 additions & 1 deletion src/video_core/primitive_assembly.cpp
Expand Up @@ -17,7 +17,6 @@ template <typename VertexType>
void PrimitiveAssembler<VertexType>::SubmitVertex(VertexType& vtx,
TriangleHandler triangle_handler) {
switch (topology) {
// TODO: Figure out what's different with TriangleTopology::Shader.
case Regs::TriangleTopology::List:
case Regs::TriangleTopology::Shader:
if (buffer_index < 2) {
Expand Down