regs_shader.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // Copyright 2017 Citra 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 "common/bit_field.h"
  7. #include "common/common_funcs.h"
  8. #include "common/common_types.h"
  9. namespace Pica {
  10. struct ShaderRegs {
  11. BitField<0, 16, u32> bool_uniforms;
  12. union {
  13. BitField<0, 8, u32> x;
  14. BitField<8, 8, u32> y;
  15. BitField<16, 8, u32> z;
  16. BitField<24, 8, u32> w;
  17. } int_uniforms[4];
  18. INSERT_PADDING_WORDS(0x4);
  19. union {
  20. // Number of input attributes to shader unit - 1
  21. BitField<0, 4, u32> max_input_attribute_index;
  22. };
  23. // Offset to shader program entry point (in words)
  24. BitField<0, 16, u32> main_offset;
  25. /// Maps input attributes to registers. 4-bits per attribute, specifying a register index
  26. u32 input_attribute_to_register_map_low;
  27. u32 input_attribute_to_register_map_high;
  28. unsigned int GetRegisterForAttribute(unsigned int attribute_index) const {
  29. u64 map = ((u64)input_attribute_to_register_map_high << 32) |
  30. (u64)input_attribute_to_register_map_low;
  31. return (map >> (attribute_index * 4)) & 0b1111;
  32. }
  33. BitField<0, 16, u32> output_mask;
  34. // 0x28E, CODETRANSFER_END
  35. INSERT_PADDING_WORDS(0x2);
  36. struct {
  37. enum Format : u32 {
  38. FLOAT24 = 0,
  39. FLOAT32 = 1,
  40. };
  41. bool IsFloat32() const {
  42. return format == FLOAT32;
  43. }
  44. union {
  45. // Index of the next uniform to write to
  46. // TODO: ctrulib uses 8 bits for this, however that seems to yield lots of invalid
  47. // indices
  48. // TODO: Maybe the uppermost index is for the geometry shader? Investigate!
  49. BitField<0, 7, u32> index;
  50. BitField<31, 1, Format> format;
  51. };
  52. // Writing to these registers sets the current uniform.
  53. u32 set_value[8];
  54. } uniform_setup;
  55. INSERT_PADDING_WORDS(0x2);
  56. struct {
  57. // Offset of the next instruction to write code to.
  58. // Incremented with each instruction write.
  59. u32 offset;
  60. // Writing to these registers sets the "current" word in the shader program.
  61. u32 set_word[8];
  62. } program;
  63. INSERT_PADDING_WORDS(0x1);
  64. // This register group is used to load an internal table of swizzling patterns,
  65. // which are indexed by each shader instruction to specify vector component swizzling.
  66. struct {
  67. // Offset of the next swizzle pattern to write code to.
  68. // Incremented with each instruction write.
  69. u32 offset;
  70. // Writing to these registers sets the current swizzle pattern in the table.
  71. u32 set_word[8];
  72. } swizzle_patterns;
  73. INSERT_PADDING_WORDS(0x2);
  74. };
  75. static_assert(sizeof(ShaderRegs) == 0x30 * sizeof(u32), "ShaderRegs struct has incorrect size");
  76. } // namespace Pica