vertex_loader.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #pragma once
  2. #include "video_core/pica.h"
  3. #include "video_core/shader/shader.h"
  4. namespace Pica {
  5. class MemoryAccesses {
  6. /// Combine overlapping and close ranges
  7. void SimplifyRanges() {
  8. for (auto it = ranges.begin(); it != ranges.end(); ++it) {
  9. // NOTE: We add 32 to the range end address to make sure "close" ranges are combined, too
  10. auto it2 = std::next(it);
  11. while (it2 != ranges.end() && it->first + it->second + 32 >= it2->first) {
  12. it->second = std::max(it->second, it2->first + it2->second - it->first);
  13. it2 = ranges.erase(it2);
  14. }
  15. }
  16. }
  17. public:
  18. /// Record a particular memory access in the list
  19. void AddAccess(u32 paddr, u32 size) {
  20. // Create new range or extend existing one
  21. ranges[paddr] = std::max(ranges[paddr], size);
  22. // Simplify ranges...
  23. SimplifyRanges();
  24. }
  25. /// Map of accessed ranges (mapping start address to range size)
  26. std::map<u32, u32> ranges;
  27. };
  28. class VertexLoader {
  29. public:
  30. void Setup(const Pica::Regs &regs);
  31. void LoadVertex(int index, int vertex, Shader::InputVertex &input, MemoryAccesses &memory_accesses);
  32. u32 GetPhysicalBaseAddress() const { return base_address; }
  33. int GetNumTotalAttributes() const { return num_total_attributes; }
  34. private:
  35. u32 vertex_attribute_sources[16];
  36. u32 vertex_attribute_strides[16] = {};
  37. Regs::VertexAttributeFormat vertex_attribute_formats[16] = {};
  38. u32 vertex_attribute_elements[16] = {};
  39. u32 vertex_attribute_element_size[16] = {};
  40. bool vertex_attribute_is_default[16];
  41. u32 base_address;
  42. int num_total_attributes;
  43. };
  44. } // namespace Pica