aboutsummaryrefslogtreecommitdiff
path: root/src/video_core/shader/shader.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/shader/shader.h')
-rw-r--r--src/video_core/shader/shader.h120
1 files changed, 49 insertions, 71 deletions
diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h
index 2b07759b9..b188d3edf 100644
--- a/src/video_core/shader/shader.h
+++ b/src/video_core/shader/shader.h
@@ -6,7 +6,6 @@
#include <array>
#include <cstddef>
-#include <memory>
#include <type_traits>
#include <nihstro/shader_bytecode.h>
#include "common/assert.h"
@@ -15,7 +14,6 @@
#include "common/vector_math.h"
#include "video_core/pica.h"
#include "video_core/pica_types.h"
-#include "video_core/shader/debug_data.h"
using nihstro::RegisterType;
using nihstro::SourceRegister;
@@ -25,14 +23,11 @@ namespace Pica {
namespace Shader {
-struct InputVertex {
+struct AttributeBuffer {
alignas(16) Math::Vec4<float24> attr[16];
};
struct OutputVertex {
- OutputVertex() = default;
-
- // VS output attributes
Math::Vec4<float24> pos;
Math::Vec4<float24> quat;
Math::Vec4<float24> color;
@@ -44,49 +39,22 @@ struct OutputVertex {
INSERT_PADDING_WORDS(1);
Math::Vec2<float24> tc2;
- // Padding for optimal alignment
- INSERT_PADDING_WORDS(4);
-
- // Attributes used to store intermediate results
-
- // position after perspective divide
- Math::Vec3<float24> screenpos;
- INSERT_PADDING_WORDS(1);
-
- // Linear interpolation
- // factor: 0=this, 1=vtx
- void Lerp(float24 factor, const OutputVertex& vtx) {
- pos = pos * factor + vtx.pos * (float24::FromFloat32(1) - factor);
-
- // TODO: Should perform perspective correct interpolation here...
- tc0 = tc0 * factor + vtx.tc0 * (float24::FromFloat32(1) - factor);
- tc1 = tc1 * factor + vtx.tc1 * (float24::FromFloat32(1) - factor);
- tc2 = tc2 * factor + vtx.tc2 * (float24::FromFloat32(1) - factor);
-
- screenpos = screenpos * factor + vtx.screenpos * (float24::FromFloat32(1) - factor);
-
- color = color * factor + vtx.color * (float24::FromFloat32(1) - factor);
- }
-
- // Linear interpolation
- // factor: 0=v0, 1=v1
- static OutputVertex Lerp(float24 factor, const OutputVertex& v0, const OutputVertex& v1) {
- OutputVertex ret = v0;
- ret.Lerp(factor, v1);
- return ret;
- }
+ static OutputVertex FromAttributeBuffer(const Regs& regs, AttributeBuffer& output);
};
+#define ASSERT_POS(var, pos) \
+ static_assert(offsetof(OutputVertex, var) == pos * sizeof(float24), "Semantic at wrong " \
+ "offset.")
+ASSERT_POS(pos, Regs::VSOutputAttributes::POSITION_X);
+ASSERT_POS(quat, Regs::VSOutputAttributes::QUATERNION_X);
+ASSERT_POS(color, Regs::VSOutputAttributes::COLOR_R);
+ASSERT_POS(tc0, Regs::VSOutputAttributes::TEXCOORD0_U);
+ASSERT_POS(tc1, Regs::VSOutputAttributes::TEXCOORD1_U);
+ASSERT_POS(tc0_w, Regs::VSOutputAttributes::TEXCOORD0_W);
+ASSERT_POS(view, Regs::VSOutputAttributes::VIEW_X);
+ASSERT_POS(tc2, Regs::VSOutputAttributes::TEXCOORD2_U);
+#undef ASSERT_POS
static_assert(std::is_pod<OutputVertex>::value, "Structure is not POD");
-static_assert(sizeof(OutputVertex) == 32 * sizeof(float), "OutputVertex has invalid size");
-
-struct OutputRegisters {
- OutputRegisters() = default;
-
- alignas(16) Math::Vec4<float24> value[16];
-
- OutputVertex ToVertex(const Regs::ShaderConfig& config) const;
-};
-static_assert(std::is_pod<OutputRegisters>::value, "Structure is not POD");
+static_assert(sizeof(OutputVertex) == 24 * sizeof(float), "OutputVertex has invalid size");
/**
* This structure contains the state information that needs to be unique for a shader unit. The 3DS
@@ -100,11 +68,10 @@ struct UnitState {
// required to be 16-byte aligned.
alignas(16) Math::Vec4<float24> input[16];
alignas(16) Math::Vec4<float24> temporary[16];
+ alignas(16) Math::Vec4<float24> output[16];
} registers;
static_assert(std::is_pod<Registers>::value, "Structure is not POD");
- OutputRegisters output_registers;
-
bool conditional_code[2];
// Two Address registers and one loop counter
@@ -130,7 +97,7 @@ struct UnitState {
static size_t OutputOffset(const DestRegister& reg) {
switch (reg.GetRegisterType()) {
case RegisterType::Output:
- return offsetof(UnitState, output_registers.value) +
+ return offsetof(UnitState, registers.output) +
reg.GetIndex() * sizeof(Math::Vec4<float24>);
case RegisterType::Temporary:
@@ -142,13 +109,19 @@ struct UnitState {
return 0;
}
}
-};
-/// Clears the shader cache
-void ClearCache();
+ /**
+ * Loads the unit state with an input vertex.
+ *
+ * @param config Shader configuration registers corresponding to the unit.
+ * @param input Attribute buffer to load into the input registers.
+ */
+ void LoadInput(const Regs::ShaderConfig& config, const AttributeBuffer& input);
-struct ShaderSetup {
+ void WriteOutput(const Regs::ShaderConfig& config, AttributeBuffer& output);
+};
+struct ShaderSetup {
struct {
// The float uniforms are accessed by the shader JIT using SSE instructions, and are
// therefore required to be 16-byte aligned.
@@ -173,32 +146,37 @@ struct ShaderSetup {
std::array<u32, 1024> program_code;
std::array<u32, 1024> swizzle_data;
+ /// Data private to ShaderEngines
+ struct EngineData {
+ unsigned int entry_point;
+ /// Used by the JIT, points to a compiled shader object.
+ const void* cached_shader = nullptr;
+ } engine_data;
+};
+
+class ShaderEngine {
+public:
+ virtual ~ShaderEngine() = default;
+
/**
* Performs any shader unit setup that only needs to happen once per shader (as opposed to once
* per vertex, which would happen within the `Run` function).
*/
- void Setup();
+ virtual void SetupBatch(ShaderSetup& setup, unsigned int entry_point) = 0;
/**
- * Runs the currently setup shader
- * @param state Shader unit state, must be setup per shader and per shader unit
- * @param input Input vertex into the shader
- * @param num_attributes The number of vertex shader attributes
+ * Runs the currently setup shader.
+ *
+ * @param setup Shader engine state, must be setup with SetupBatch on each shader change.
+ * @param state Shader unit state, must be setup with input data before each shader invocation.
*/
- void Run(UnitState& state, const InputVertex& input, int num_attributes);
-
- /**
- * Produce debug information based on the given shader and input vertex
- * @param input Input vertex into the shader
- * @param num_attributes The number of vertex shader attributes
- * @param config Configuration object for the shader pipeline
- * @param setup Setup object for the shader pipeline
- * @return Debug information for this shader with regards to the given vertex
- */
- DebugData<true> ProduceDebugInfo(const InputVertex& input, int num_attributes,
- const Regs::ShaderConfig& config, const ShaderSetup& setup);
+ virtual void Run(const ShaderSetup& setup, UnitState& state) const = 0;
};
+// TODO(yuriks): Remove and make it non-global state somewhere
+ShaderEngine* GetEngine();
+void Shutdown();
+
} // namespace Shader
} // namespace Pica