2015-05-14 05:29:27 +02:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
2015-07-25 23:26:34 +02:00
|
|
|
#include <cstring>
|
pica/command_processor: build geometry pipeline and run geometry shader
The geometry pipeline manages data transfer between VS, GS and primitive assembler. It has known four modes:
- no GS mode: sends VS output directly to the primitive assembler (what citra currently does)
- GS mode 0: sends VS output to GS input registers, and sends GS output to primitive assembler
- GS mode 1: sends VS output to GS uniform registers, and sends GS output to primitive assembler. It also takes an index from the index buffer at the beginning of each primitive for determine the primitive size.
- GS mode 2: similar to mode 1, but doesn't take the index and uses a fixed primitive size.
hwtest shows that immediate mode also supports GS (at least for mode 0), so the geometry pipeline gets refactored into its own class for supporting both drawing mode.
In the immediate mode, some games don't set the pipeline registers to a valid value until the first attribute input, so a geometry pipeline reset flag is set in `pipeline.vs_default_attributes_setup.index` trigger, and the actual pipeline reconfigure is triggered in the first attribute input.
In the normal drawing mode with index buffer, the vertex cache is a little bit modified to support the geometry pipeline. Instead of OutputVertex, it now holds AttributeBuffer, which is the input to the geometry pipeline. The AttributeBuffer->OutputVertex conversion is done inside the pipeline vertex handler. The actual hardware vertex cache is believed to be implemented in a similar way (because this is the only way that makes sense).
Both geometry pipeline and GS unit rely on states preservation across drawing call, so they are put into the global state. In the future, the other three vertex shader units should be also placed in the global state, and a scheduler should be implemented on top of the four units. Note that the current gs_unit already allows running VS on it in the future.
2017-08-04 16:03:17 +02:00
|
|
|
#include "video_core/geometry_pipeline.h"
|
2016-09-21 08:52:38 +02:00
|
|
|
#include "video_core/pica.h"
|
2016-03-03 04:16:38 +01:00
|
|
|
#include "video_core/pica_state.h"
|
pica/command_processor: build geometry pipeline and run geometry shader
The geometry pipeline manages data transfer between VS, GS and primitive assembler. It has known four modes:
- no GS mode: sends VS output directly to the primitive assembler (what citra currently does)
- GS mode 0: sends VS output to GS input registers, and sends GS output to primitive assembler
- GS mode 1: sends VS output to GS uniform registers, and sends GS output to primitive assembler. It also takes an index from the index buffer at the beginning of each primitive for determine the primitive size.
- GS mode 2: similar to mode 1, but doesn't take the index and uses a fixed primitive size.
hwtest shows that immediate mode also supports GS (at least for mode 0), so the geometry pipeline gets refactored into its own class for supporting both drawing mode.
In the immediate mode, some games don't set the pipeline registers to a valid value until the first attribute input, so a geometry pipeline reset flag is set in `pipeline.vs_default_attributes_setup.index` trigger, and the actual pipeline reconfigure is triggered in the first attribute input.
In the normal drawing mode with index buffer, the vertex cache is a little bit modified to support the geometry pipeline. Instead of OutputVertex, it now holds AttributeBuffer, which is the input to the geometry pipeline. The AttributeBuffer->OutputVertex conversion is done inside the pipeline vertex handler. The actual hardware vertex cache is believed to be implemented in a similar way (because this is the only way that makes sense).
Both geometry pipeline and GS unit rely on states preservation across drawing call, so they are put into the global state. In the future, the other three vertex shader units should be also placed in the global state, and a scheduler should be implemented on top of the four units. Note that the current gs_unit already allows running VS on it in the future.
2017-08-04 16:03:17 +02:00
|
|
|
#include "video_core/renderer_base.h"
|
|
|
|
#include "video_core/video_core.h"
|
2015-05-14 05:29:27 +02:00
|
|
|
|
|
|
|
namespace Pica {
|
|
|
|
|
|
|
|
State g_state;
|
|
|
|
|
|
|
|
void Init() {
|
2016-03-05 23:49:23 +01:00
|
|
|
g_state.Reset();
|
2015-05-14 05:29:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Shutdown() {
|
2016-12-17 10:21:16 +01:00
|
|
|
Shader::Shutdown();
|
2016-03-05 23:49:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void Zero(T& o) {
|
|
|
|
memset(&o, 0, sizeof(o));
|
|
|
|
}
|
2015-07-23 05:25:30 +02:00
|
|
|
|
pica/command_processor: build geometry pipeline and run geometry shader
The geometry pipeline manages data transfer between VS, GS and primitive assembler. It has known four modes:
- no GS mode: sends VS output directly to the primitive assembler (what citra currently does)
- GS mode 0: sends VS output to GS input registers, and sends GS output to primitive assembler
- GS mode 1: sends VS output to GS uniform registers, and sends GS output to primitive assembler. It also takes an index from the index buffer at the beginning of each primitive for determine the primitive size.
- GS mode 2: similar to mode 1, but doesn't take the index and uses a fixed primitive size.
hwtest shows that immediate mode also supports GS (at least for mode 0), so the geometry pipeline gets refactored into its own class for supporting both drawing mode.
In the immediate mode, some games don't set the pipeline registers to a valid value until the first attribute input, so a geometry pipeline reset flag is set in `pipeline.vs_default_attributes_setup.index` trigger, and the actual pipeline reconfigure is triggered in the first attribute input.
In the normal drawing mode with index buffer, the vertex cache is a little bit modified to support the geometry pipeline. Instead of OutputVertex, it now holds AttributeBuffer, which is the input to the geometry pipeline. The AttributeBuffer->OutputVertex conversion is done inside the pipeline vertex handler. The actual hardware vertex cache is believed to be implemented in a similar way (because this is the only way that makes sense).
Both geometry pipeline and GS unit rely on states preservation across drawing call, so they are put into the global state. In the future, the other three vertex shader units should be also placed in the global state, and a scheduler should be implemented on top of the four units. Note that the current gs_unit already allows running VS on it in the future.
2017-08-04 16:03:17 +02:00
|
|
|
State::State() : geometry_pipeline(*this) {
|
|
|
|
auto SubmitVertex = [this](const Shader::AttributeBuffer& vertex) {
|
|
|
|
using Pica::Shader::OutputVertex;
|
|
|
|
auto AddTriangle = [this](const OutputVertex& v0, const OutputVertex& v1,
|
|
|
|
const OutputVertex& v2) {
|
|
|
|
VideoCore::g_renderer->Rasterizer()->AddTriangle(v0, v1, v2);
|
|
|
|
};
|
|
|
|
primitive_assembler.SubmitVertex(
|
|
|
|
Shader::OutputVertex::FromAttributeBuffer(regs.rasterizer, vertex), AddTriangle);
|
|
|
|
};
|
|
|
|
|
|
|
|
auto SetWinding = [this]() { primitive_assembler.SetWinding(); };
|
|
|
|
|
|
|
|
g_state.gs_unit.SetVertexHandler(SubmitVertex, SetWinding);
|
|
|
|
g_state.geometry_pipeline.SetVertexHandler(SubmitVertex);
|
|
|
|
}
|
|
|
|
|
2016-03-05 23:49:23 +01:00
|
|
|
void State::Reset() {
|
|
|
|
Zero(regs);
|
|
|
|
Zero(vs);
|
|
|
|
Zero(gs);
|
|
|
|
Zero(cmd_list);
|
|
|
|
Zero(immediate);
|
2017-01-28 21:34:31 +01:00
|
|
|
primitive_assembler.Reconfigure(PipelineRegs::TriangleTopology::List);
|
2015-05-14 05:29:27 +02:00
|
|
|
}
|
2018-03-09 18:54:43 +01:00
|
|
|
} // namespace Pica
|