diff options
Diffstat (limited to 'src/video_core/shader/shader.h')
| -rw-r--r-- | src/video_core/shader/shader.h | 49 |
1 files changed, 13 insertions, 36 deletions
diff --git a/src/video_core/shader/shader.h b/src/video_core/shader/shader.h index 00bd723cf..b188d3edf 100644 --- a/src/video_core/shader/shader.h +++ b/src/video_core/shader/shader.h | |||
| @@ -28,9 +28,6 @@ struct AttributeBuffer { | |||
| 28 | }; | 28 | }; |
| 29 | 29 | ||
| 30 | struct OutputVertex { | 30 | struct OutputVertex { |
| 31 | OutputVertex() = default; | ||
| 32 | |||
| 33 | // VS output attributes | ||
| 34 | Math::Vec4<float24> pos; | 31 | Math::Vec4<float24> pos; |
| 35 | Math::Vec4<float24> quat; | 32 | Math::Vec4<float24> quat; |
| 36 | Math::Vec4<float24> color; | 33 | Math::Vec4<float24> color; |
| @@ -42,42 +39,22 @@ struct OutputVertex { | |||
| 42 | INSERT_PADDING_WORDS(1); | 39 | INSERT_PADDING_WORDS(1); |
| 43 | Math::Vec2<float24> tc2; | 40 | Math::Vec2<float24> tc2; |
| 44 | 41 | ||
| 45 | // Padding for optimal alignment | ||
| 46 | INSERT_PADDING_WORDS(4); | ||
| 47 | |||
| 48 | // Attributes used to store intermediate results | ||
| 49 | |||
| 50 | // position after perspective divide | ||
| 51 | Math::Vec3<float24> screenpos; | ||
| 52 | INSERT_PADDING_WORDS(1); | ||
| 53 | |||
| 54 | // Linear interpolation | ||
| 55 | // factor: 0=this, 1=vtx | ||
| 56 | void Lerp(float24 factor, const OutputVertex& vtx) { | ||
| 57 | pos = pos * factor + vtx.pos * (float24::FromFloat32(1) - factor); | ||
| 58 | |||
| 59 | // TODO: Should perform perspective correct interpolation here... | ||
| 60 | tc0 = tc0 * factor + vtx.tc0 * (float24::FromFloat32(1) - factor); | ||
| 61 | tc1 = tc1 * factor + vtx.tc1 * (float24::FromFloat32(1) - factor); | ||
| 62 | tc2 = tc2 * factor + vtx.tc2 * (float24::FromFloat32(1) - factor); | ||
| 63 | |||
| 64 | screenpos = screenpos * factor + vtx.screenpos * (float24::FromFloat32(1) - factor); | ||
| 65 | |||
| 66 | color = color * factor + vtx.color * (float24::FromFloat32(1) - factor); | ||
| 67 | } | ||
| 68 | |||
| 69 | // Linear interpolation | ||
| 70 | // factor: 0=v0, 1=v1 | ||
| 71 | static OutputVertex Lerp(float24 factor, const OutputVertex& v0, const OutputVertex& v1) { | ||
| 72 | OutputVertex ret = v0; | ||
| 73 | ret.Lerp(factor, v1); | ||
| 74 | return ret; | ||
| 75 | } | ||
| 76 | |||
| 77 | static OutputVertex FromAttributeBuffer(const Regs& regs, AttributeBuffer& output); | 42 | static OutputVertex FromAttributeBuffer(const Regs& regs, AttributeBuffer& output); |
| 78 | }; | 43 | }; |
| 44 | #define ASSERT_POS(var, pos) \ | ||
| 45 | static_assert(offsetof(OutputVertex, var) == pos * sizeof(float24), "Semantic at wrong " \ | ||
| 46 | "offset.") | ||
| 47 | ASSERT_POS(pos, Regs::VSOutputAttributes::POSITION_X); | ||
| 48 | ASSERT_POS(quat, Regs::VSOutputAttributes::QUATERNION_X); | ||
| 49 | ASSERT_POS(color, Regs::VSOutputAttributes::COLOR_R); | ||
| 50 | ASSERT_POS(tc0, Regs::VSOutputAttributes::TEXCOORD0_U); | ||
| 51 | ASSERT_POS(tc1, Regs::VSOutputAttributes::TEXCOORD1_U); | ||
| 52 | ASSERT_POS(tc0_w, Regs::VSOutputAttributes::TEXCOORD0_W); | ||
| 53 | ASSERT_POS(view, Regs::VSOutputAttributes::VIEW_X); | ||
| 54 | ASSERT_POS(tc2, Regs::VSOutputAttributes::TEXCOORD2_U); | ||
| 55 | #undef ASSERT_POS | ||
| 79 | static_assert(std::is_pod<OutputVertex>::value, "Structure is not POD"); | 56 | static_assert(std::is_pod<OutputVertex>::value, "Structure is not POD"); |
| 80 | static_assert(sizeof(OutputVertex) == 32 * sizeof(float), "OutputVertex has invalid size"); | 57 | static_assert(sizeof(OutputVertex) == 24 * sizeof(float), "OutputVertex has invalid size"); |
| 81 | 58 | ||
| 82 | /** | 59 | /** |
| 83 | * This structure contains the state information that needs to be unique for a shader unit. The 3DS | 60 | * This structure contains the state information that needs to be unique for a shader unit. The 3DS |