shader_header.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. // Documentation in:
  15. // http://download.nvidia.com/open-gpu-doc/Shader-Program-Header/1/Shader-Program-Header.html#ImapTexture
  16. struct Header {
  17. union {
  18. BitField<0, 5, u32> sph_type;
  19. BitField<5, 5, u32> version;
  20. BitField<10, 4, u32> shader_type;
  21. BitField<14, 1, u32> mrt_enable;
  22. BitField<15, 1, u32> kills_pixels;
  23. BitField<16, 1, u32> does_global_store;
  24. BitField<17, 4, u32> sass_version;
  25. BitField<21, 5, u32> reserved;
  26. BitField<26, 1, u32> does_load_or_store;
  27. BitField<27, 1, u32> does_fp64;
  28. BitField<28, 4, u32> stream_out_mask;
  29. } common0;
  30. union {
  31. BitField<0, 24, u32> shader_local_memory_low_size;
  32. BitField<24, 8, u32> per_patch_attribute_count;
  33. } common1;
  34. union {
  35. BitField<0, 24, u32> shader_local_memory_high_size;
  36. BitField<24, 8, u32> threads_per_input_primitive;
  37. } common2;
  38. union {
  39. BitField<0, 24, u32> shader_local_memory_crs_size;
  40. BitField<24, 4, OutputTopology> output_topology;
  41. BitField<28, 4, u32> reserved;
  42. } common3;
  43. union {
  44. BitField<0, 12, u32> max_output_vertices;
  45. BitField<12, 8, u32> store_req_start; // NOTE: not used by geometry shaders.
  46. BitField<24, 4, u32> reserved;
  47. BitField<12, 8, u32> store_req_end; // NOTE: not used by geometry shaders.
  48. } common4;
  49. union {
  50. struct {
  51. INSERT_PADDING_BYTES(3); // ImapSystemValuesA
  52. INSERT_PADDING_BYTES(1); // ImapSystemValuesB
  53. INSERT_PADDING_BYTES(16); // ImapGenericVector[32]
  54. INSERT_PADDING_BYTES(2); // ImapColor
  55. union {
  56. BitField<0, 8, u16> clip_distances;
  57. BitField<8, 1, u16> point_sprite_s;
  58. BitField<9, 1, u16> point_sprite_t;
  59. BitField<10, 1, u16> fog_coordinate;
  60. BitField<12, 1, u16> tessellation_eval_point_u;
  61. BitField<13, 1, u16> tessellation_eval_point_v;
  62. BitField<14, 1, u16> instance_id;
  63. BitField<15, 1, u16> vertex_id;
  64. };
  65. INSERT_PADDING_BYTES(5); // ImapFixedFncTexture[10]
  66. INSERT_PADDING_BYTES(1); // ImapReserved
  67. INSERT_PADDING_BYTES(3); // OmapSystemValuesA
  68. INSERT_PADDING_BYTES(1); // OmapSystemValuesB
  69. INSERT_PADDING_BYTES(16); // OmapGenericVector[32]
  70. INSERT_PADDING_BYTES(2); // OmapColor
  71. INSERT_PADDING_BYTES(2); // OmapSystemValuesC
  72. INSERT_PADDING_BYTES(5); // OmapFixedFncTexture[10]
  73. INSERT_PADDING_BYTES(1); // OmapReserved
  74. } vtg;
  75. struct {
  76. INSERT_PADDING_BYTES(3); // ImapSystemValuesA
  77. INSERT_PADDING_BYTES(1); // ImapSystemValuesB
  78. INSERT_PADDING_BYTES(32); // ImapGenericVector[32]
  79. INSERT_PADDING_BYTES(2); // ImapColor
  80. INSERT_PADDING_BYTES(2); // ImapSystemValuesC
  81. INSERT_PADDING_BYTES(10); // ImapFixedFncTexture[10]
  82. INSERT_PADDING_BYTES(2); // ImapReserved
  83. struct {
  84. u32 target;
  85. union {
  86. BitField<0, 1, u32> sample_mask;
  87. BitField<1, 1, u32> depth;
  88. BitField<2, 30, u32> reserved;
  89. };
  90. } omap;
  91. bool IsColorComponentOutputEnabled(u32 render_target, u32 component) const {
  92. const u32 bit = render_target * 4 + component;
  93. return omap.target & (1 << bit);
  94. }
  95. } ps;
  96. };
  97. u64 GetLocalMemorySize() {
  98. return (common1.shader_local_memory_low_size |
  99. (common2.shader_local_memory_high_size << 24));
  100. }
  101. };
  102. static_assert(sizeof(Header) == 0x50, "Incorrect structure size");
  103. } // namespace Tegra::Shader