shader_header.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 "common/bit_field.h"
  6. #include "common/common_funcs.h"
  7. #include "common/common_types.h"
  8. namespace Tegra::Shader {
  9. enum class OutputTopology : u32 {
  10. PointList = 1,
  11. LineStrip = 6,
  12. TriangleStrip = 7,
  13. };
  14. enum class AttributeUse : u8 {
  15. Unused = 0,
  16. Constant = 1,
  17. Perspective = 2,
  18. ScreenLinear = 3,
  19. };
  20. // Documentation in:
  21. // http://download.nvidia.com/open-gpu-doc/Shader-Program-Header/1/Shader-Program-Header.html#ImapTexture
  22. struct Header {
  23. union {
  24. BitField<0, 5, u32> sph_type;
  25. BitField<5, 5, u32> version;
  26. BitField<10, 4, u32> shader_type;
  27. BitField<14, 1, u32> mrt_enable;
  28. BitField<15, 1, u32> kills_pixels;
  29. BitField<16, 1, u32> does_global_store;
  30. BitField<17, 4, u32> sass_version;
  31. BitField<21, 5, u32> reserved;
  32. BitField<26, 1, u32> does_load_or_store;
  33. BitField<27, 1, u32> does_fp64;
  34. BitField<28, 4, u32> stream_out_mask;
  35. } common0{};
  36. union {
  37. BitField<0, 24, u32> shader_local_memory_low_size;
  38. BitField<24, 8, u32> per_patch_attribute_count;
  39. } common1{};
  40. union {
  41. BitField<0, 24, u32> shader_local_memory_high_size;
  42. BitField<24, 8, u32> threads_per_input_primitive;
  43. } common2{};
  44. union {
  45. BitField<0, 24, u32> shader_local_memory_crs_size;
  46. BitField<24, 4, OutputTopology> output_topology;
  47. BitField<28, 4, u32> reserved;
  48. } common3{};
  49. union {
  50. BitField<0, 12, u32> max_output_vertices;
  51. BitField<12, 8, u32> store_req_start; // NOTE: not used by geometry shaders.
  52. BitField<24, 4, u32> reserved;
  53. BitField<12, 8, u32> store_req_end; // NOTE: not used by geometry shaders.
  54. } common4{};
  55. union {
  56. struct {
  57. INSERT_UNION_PADDING_BYTES(3); // ImapSystemValuesA
  58. INSERT_UNION_PADDING_BYTES(1); // ImapSystemValuesB
  59. INSERT_UNION_PADDING_BYTES(16); // ImapGenericVector[32]
  60. INSERT_UNION_PADDING_BYTES(2); // ImapColor
  61. union {
  62. BitField<0, 8, u16> clip_distances;
  63. BitField<8, 1, u16> point_sprite_s;
  64. BitField<9, 1, u16> point_sprite_t;
  65. BitField<10, 1, u16> fog_coordinate;
  66. BitField<12, 1, u16> tessellation_eval_point_u;
  67. BitField<13, 1, u16> tessellation_eval_point_v;
  68. BitField<14, 1, u16> instance_id;
  69. BitField<15, 1, u16> vertex_id;
  70. };
  71. INSERT_UNION_PADDING_BYTES(5); // ImapFixedFncTexture[10]
  72. INSERT_UNION_PADDING_BYTES(1); // ImapReserved
  73. INSERT_UNION_PADDING_BYTES(3); // OmapSystemValuesA
  74. INSERT_UNION_PADDING_BYTES(1); // OmapSystemValuesB
  75. INSERT_UNION_PADDING_BYTES(16); // OmapGenericVector[32]
  76. INSERT_UNION_PADDING_BYTES(2); // OmapColor
  77. INSERT_UNION_PADDING_BYTES(2); // OmapSystemValuesC
  78. INSERT_UNION_PADDING_BYTES(5); // OmapFixedFncTexture[10]
  79. INSERT_UNION_PADDING_BYTES(1); // OmapReserved
  80. } vtg;
  81. struct {
  82. INSERT_UNION_PADDING_BYTES(3); // ImapSystemValuesA
  83. INSERT_UNION_PADDING_BYTES(1); // ImapSystemValuesB
  84. union {
  85. BitField<0, 2, AttributeUse> x;
  86. BitField<2, 2, AttributeUse> y;
  87. BitField<4, 2, AttributeUse> w;
  88. BitField<6, 2, AttributeUse> z;
  89. u8 raw;
  90. } imap_generic_vector[32];
  91. INSERT_UNION_PADDING_BYTES(2); // ImapColor
  92. INSERT_UNION_PADDING_BYTES(2); // ImapSystemValuesC
  93. INSERT_UNION_PADDING_BYTES(10); // ImapFixedFncTexture[10]
  94. INSERT_UNION_PADDING_BYTES(2); // ImapReserved
  95. struct {
  96. u32 target;
  97. union {
  98. BitField<0, 1, u32> sample_mask;
  99. BitField<1, 1, u32> depth;
  100. BitField<2, 30, u32> reserved;
  101. };
  102. } omap;
  103. bool IsColorComponentOutputEnabled(u32 render_target, u32 component) const {
  104. const u32 bit = render_target * 4 + component;
  105. return omap.target & (1 << bit);
  106. }
  107. AttributeUse GetAttributeIndexUse(u32 attribute, u32 index) const {
  108. return static_cast<AttributeUse>(
  109. (imap_generic_vector[attribute].raw >> (index * 2)) & 0x03);
  110. }
  111. AttributeUse GetAttributeUse(u32 attribute) const {
  112. AttributeUse result = AttributeUse::Unused;
  113. for (u32 i = 0; i < 4; i++) {
  114. const auto index = GetAttributeIndexUse(attribute, i);
  115. if (index == AttributeUse::Unused) {
  116. continue;
  117. }
  118. if (result == AttributeUse::Unused || result == index) {
  119. result = index;
  120. continue;
  121. }
  122. LOG_CRITICAL(HW_GPU, "Generic Attribute Conflict in Interpolation Mode");
  123. if (index == AttributeUse::Perspective) {
  124. result = index;
  125. }
  126. }
  127. return result;
  128. }
  129. } ps;
  130. std::array<u32, 0xF> raw{};
  131. };
  132. u64 GetLocalMemorySize() const {
  133. return (common1.shader_local_memory_low_size |
  134. (common2.shader_local_memory_high_size << 24));
  135. }
  136. };
  137. static_assert(sizeof(Header) == 0x50, "Incorrect structure size");
  138. } // namespace Tegra::Shader