node_helper.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2019 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <memory>
  6. #include <string>
  7. #include <tuple>
  8. #include <type_traits>
  9. #include <utility>
  10. #include <vector>
  11. #include "common/common_types.h"
  12. #include "video_core/shader/node.h"
  13. namespace VideoCommon::Shader {
  14. /// This arithmetic operation cannot be constraint
  15. inline constexpr MetaArithmetic PRECISE = {true};
  16. /// This arithmetic operation can be optimized away
  17. inline constexpr MetaArithmetic NO_PRECISE = {false};
  18. /// Creates a conditional node
  19. Node Conditional(Node condition, std::vector<Node> code);
  20. /// Creates a commentary node
  21. Node Comment(std::string text);
  22. /// Creates an u32 immediate
  23. Node Immediate(u32 value);
  24. /// Creates a s32 immediate
  25. Node Immediate(s32 value);
  26. /// Creates a f32 immediate
  27. Node Immediate(f32 value);
  28. /// Converts an signed operation code to an unsigned operation code
  29. OperationCode SignedToUnsignedCode(OperationCode operation_code, bool is_signed);
  30. template <typename T, typename... Args>
  31. Node MakeNode(Args&&... args) {
  32. static_assert(std::is_convertible_v<T, NodeData>);
  33. return std::make_shared<NodeData>(T(std::forward<Args>(args)...));
  34. }
  35. template <typename T, typename... Args>
  36. TrackSampler MakeTrackSampler(Args&&... args) {
  37. static_assert(std::is_convertible_v<T, TrackSamplerData>);
  38. return std::make_shared<TrackSamplerData>(T{std::forward<Args>(args)...});
  39. }
  40. template <typename... Args>
  41. Node Operation(OperationCode code, Args&&... args) {
  42. if constexpr (sizeof...(args) == 0) {
  43. return MakeNode<OperationNode>(code);
  44. } else if constexpr (std::is_convertible_v<std::tuple_element_t<0, std::tuple<Args...>>,
  45. Meta>) {
  46. return MakeNode<OperationNode>(code, std::forward<Args>(args)...);
  47. } else {
  48. return MakeNode<OperationNode>(code, Meta{}, std::forward<Args>(args)...);
  49. }
  50. }
  51. template <typename... Args>
  52. Node SignedOperation(OperationCode code, bool is_signed, Args&&... args) {
  53. return Operation(SignedToUnsignedCode(code, is_signed), std::forward<Args>(args)...);
  54. }
  55. } // namespace VideoCommon::Shader