vertex_shader.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <initializer_list>
  6. #include <common/common_types.h>
  7. #include "math.h"
  8. #include "pica.h"
  9. namespace Pica {
  10. namespace VertexShader {
  11. struct InputVertex {
  12. Math::Vec4<float24> attr[16];
  13. };
  14. struct OutputVertex {
  15. OutputVertex() = default;
  16. // VS output attributes
  17. Math::Vec4<float24> pos;
  18. Math::Vec4<float24> dummy; // quaternions (not implemented, yet)
  19. Math::Vec4<float24> color;
  20. Math::Vec2<float24> tc0;
  21. Math::Vec2<float24> tc1;
  22. float24 pad[6];
  23. Math::Vec2<float24> tc2;
  24. // Padding for optimal alignment
  25. float24 pad2[4];
  26. // Attributes used to store intermediate results
  27. // position after perspective divide
  28. Math::Vec3<float24> screenpos;
  29. float24 pad3;
  30. // Linear interpolation
  31. // factor: 0=this, 1=vtx
  32. void Lerp(float24 factor, const OutputVertex& vtx) {
  33. pos = pos * factor + vtx.pos * (float24::FromFloat32(1) - factor);
  34. // TODO: Should perform perspective correct interpolation here...
  35. tc0 = tc0 * factor + vtx.tc0 * (float24::FromFloat32(1) - factor);
  36. tc1 = tc1 * factor + vtx.tc1 * (float24::FromFloat32(1) - factor);
  37. tc2 = tc2 * factor + vtx.tc2 * (float24::FromFloat32(1) - factor);
  38. screenpos = screenpos * factor + vtx.screenpos * (float24::FromFloat32(1) - factor);
  39. color = color * factor + vtx.color * (float24::FromFloat32(1) - factor);
  40. }
  41. // Linear interpolation
  42. // factor: 0=v0, 1=v1
  43. static OutputVertex Lerp(float24 factor, const OutputVertex& v0, const OutputVertex& v1) {
  44. OutputVertex ret = v0;
  45. ret.Lerp(factor, v1);
  46. return ret;
  47. }
  48. };
  49. static_assert(std::is_pod<OutputVertex>::value, "Structure is not POD");
  50. static_assert(sizeof(OutputVertex) == 32 * sizeof(float), "OutputVertex has invalid size");
  51. void SubmitShaderMemoryChange(u32 addr, u32 value);
  52. void SubmitSwizzleDataChange(u32 addr, u32 value);
  53. OutputVertex RunShader(const InputVertex& input, int num_attributes);
  54. Math::Vec4<float24>& GetFloatUniform(u32 index);
  55. bool& GetBoolUniform(u32 index);
  56. Math::Vec4<u8>& GetIntUniform(u32 index);
  57. Math::Vec4<float24>& GetDefaultAttribute(u32 index);
  58. const std::array<u32, 1024>& GetShaderBinary();
  59. const std::array<u32, 1024>& GetSwizzlePatterns();
  60. } // namespace
  61. } // namespace