PixelQuad.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * Copyright (c) 2021, Stephan Unverwerth <s.unverwerth@serenityos.org>
  3. * Copyright (c) 2022, Jelle Raaijmakers <jelle@gmta.nl>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/SIMD.h>
  9. #include <AK/SIMDExtras.h>
  10. #include <LibGfx/Vector2.h>
  11. #include <LibGfx/Vector3.h>
  12. #include <LibGfx/Vector4.h>
  13. #include <LibSoftGPU/Config.h>
  14. namespace SoftGPU {
  15. using AK::SIMD::expand4;
  16. using AK::SIMD::f32x4;
  17. using AK::SIMD::i32x4;
  18. struct PixelQuad final {
  19. void set_input(int index, f32x4 value) { inputs[index] = value; }
  20. f32x4 get_input_float(int index) const { return inputs[index]; }
  21. void set_input(int index, Vector4<f32x4> const& value)
  22. {
  23. inputs[index] = value.x();
  24. inputs[index + 1] = value.y();
  25. inputs[index + 2] = value.z();
  26. inputs[index + 3] = value.w();
  27. }
  28. Vector4<f32x4> get_input_vector4(int index) const
  29. {
  30. return Vector4<f32x4>(
  31. inputs[index],
  32. inputs[index + 1],
  33. inputs[index + 2],
  34. inputs[index + 3]);
  35. }
  36. void set_output(int index, f32x4 value) { outputs[index] = value; }
  37. f32x4 get_output_float(int index) const { return outputs[index]; }
  38. void set_output(int index, Vector4<f32x4> const& value)
  39. {
  40. outputs[index] = value.x();
  41. outputs[index + 1] = value.y();
  42. outputs[index + 2] = value.z();
  43. outputs[index + 3] = value.w();
  44. }
  45. Vector4<f32x4> get_output_vector4(int index) const
  46. {
  47. return Vector4<f32x4>(
  48. outputs[index],
  49. outputs[index + 1],
  50. outputs[index + 2],
  51. outputs[index + 3]);
  52. }
  53. Vector2<i32x4> screen_coordinates;
  54. Vector3<f32x4> barycentrics;
  55. f32x4 depth;
  56. Array<f32x4, NUM_SHADER_INPUTS> inputs;
  57. Array<f32x4, NUM_SHADER_OUTPUTS> outputs;
  58. f32x4 fog_depth;
  59. i32x4 mask;
  60. f32x4 coverage { expand4(1.f) };
  61. };
  62. }