glsl_decompiler.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include <string>
  7. #include <utility>
  8. #include <vector>
  9. #include "common/common_types.h"
  10. #include "video_core/engines/maxwell_3d.h"
  11. #include "video_core/shader/shader_ir.h"
  12. namespace VideoCommon::Shader {
  13. class ShaderIR;
  14. }
  15. namespace OpenGL::GLShader {
  16. using Maxwell = Tegra::Engines::Maxwell3D::Regs;
  17. class ConstBufferEntry : public VideoCommon::Shader::ConstBuffer {
  18. public:
  19. explicit ConstBufferEntry(const VideoCommon::Shader::ConstBuffer& entry,
  20. Maxwell::ShaderStage stage, const std::string& name, u32 index)
  21. : VideoCommon::Shader::ConstBuffer{entry}, stage{stage}, name{name}, index{index} {}
  22. const std::string& GetName() const {
  23. return name;
  24. }
  25. Maxwell::ShaderStage GetStage() const {
  26. return stage;
  27. }
  28. u32 GetIndex() const {
  29. return index;
  30. }
  31. u32 GetHash() const {
  32. return (static_cast<u32>(stage) << 16) | index;
  33. }
  34. private:
  35. std::string name;
  36. Maxwell::ShaderStage stage{};
  37. u32 index{};
  38. };
  39. class SamplerEntry : public VideoCommon::Shader::Sampler {
  40. public:
  41. explicit SamplerEntry(const VideoCommon::Shader::Sampler& entry, Maxwell::ShaderStage stage,
  42. const std::string& name)
  43. : VideoCommon::Shader::Sampler{entry}, stage{stage}, name{name} {}
  44. const std::string& GetName() const {
  45. return name;
  46. }
  47. Maxwell::ShaderStage GetStage() const {
  48. return stage;
  49. }
  50. u32 GetHash() const {
  51. return (static_cast<u32>(stage) << 16) | GetIndex();
  52. }
  53. private:
  54. std::string name;
  55. Maxwell::ShaderStage stage{};
  56. };
  57. struct ShaderEntries {
  58. std::vector<ConstBufferEntry> const_buffers;
  59. std::vector<SamplerEntry> samplers;
  60. std::array<bool, Maxwell::NumClipDistances> clip_distances{};
  61. std::size_t shader_length{};
  62. };
  63. using ProgramResult = std::pair<std::string, ShaderEntries>;
  64. std::string GetCommonDeclarations();
  65. ProgramResult Decompile(const VideoCommon::Shader::ShaderIR& ir, Maxwell::ShaderStage stage,
  66. const std::string& suffix);
  67. } // namespace OpenGL::GLShader