Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.48 KB | None | 0 0
  1. diff --git a/src/video_core/vertex_loader.cpp b/src/video_core/vertex_loader.cpp
  2. index 37c5224..8f9db2e 100644
  3. --- a/src/video_core/vertex_loader.cpp
  4. +++ b/src/video_core/vertex_loader.cpp
  5. @@ -13,9 +13,37 @@
  6. #include "video_core/regs_pipeline.h"
  7. #include "video_core/shader/shader.h"
  8. #include "video_core/vertex_loader.h"
  9. +#include "common/microprofile.h"
  10.  
  11. namespace Pica {
  12.  
  13. +MICROPROFILE_DEFINE(GPU_VertexLoad, "GPU", "Vertex Load", MP_RGB(50, 50, 240));
  14. +
  15. +template<typename T>
  16. +static void LoadBufferAttr(Math::Vec4<float24>& attr, int index, u32 elements, PAddr address) {
  17. + const T* srcdata =
  18. + reinterpret_cast<const T*>(Memory::GetPhysicalPointer(address));
  19. + for (unsigned int comp = 0; comp < elements; ++comp) {
  20. + attr[comp] = float24::FromFloat32(srcdata[comp]);
  21. + }
  22. +
  23. + // Default attribute values set if array elements have < 4 components. This
  24. + // is *not* carried over from the default attribute settings even if they're
  25. + // enabled for this attribute.
  26. + for (unsigned int comp = elements; comp < 4; ++comp) {
  27. + attr[comp] =
  28. + comp == 3 ? float24::FromFloat32(1.0f) : float24::FromFloat32(0.0f);
  29. + }
  30. +}
  31. +
  32. +void LoadDefaultAttr(Math::Vec4<float24>& attr, int index, u32 elements, PAddr address) {
  33. + // Load the default attribute if we're configured to do so
  34. + attr = g_state.input_default_attributes.attr[index];
  35. +}
  36. +
  37. +void LoadPreviousAttr(Math::Vec4<float24>& attr, int index, u32 elements, PAddr address) {
  38. +}
  39. +
  40. void VertexLoader::Setup(const PipelineRegs& regs) {
  41. ASSERT_MSG(!is_setup, "VertexLoader is not intended to be setup more than once.");
  42.  
  43. @@ -67,94 +95,49 @@ void VertexLoader::Setup(const PipelineRegs& regs) {
  44. }
  45. }
  46.  
  47. - is_setup = true;
  48. -}
  49. -
  50. -void VertexLoader::LoadVertex(u32 base_address, int index, int vertex,
  51. - Shader::AttributeBuffer& input,
  52. - DebugUtils::MemoryAccessTracker& memory_accesses) {
  53. - ASSERT_MSG(is_setup, "A VertexLoader needs to be setup before loading vertices.");
  54. -
  55. for (int i = 0; i < num_total_attributes; ++i) {
  56. if (vertex_attribute_elements[i] != 0) {
  57. - // Load per-vertex data from the loader arrays
  58. - u32 source_addr =
  59. - base_address + vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex;
  60. -
  61. - if (g_debug_context && Pica::g_debug_context->recorder) {
  62. - memory_accesses.AddAccess(
  63. - source_addr,
  64. - vertex_attribute_elements[i] *
  65. - ((vertex_attribute_formats[i] == PipelineRegs::VertexAttributeFormat::FLOAT)
  66. - ? 4
  67. - : (vertex_attribute_formats[i] ==
  68. - PipelineRegs::VertexAttributeFormat::SHORT)
  69. - ? 2
  70. - : 1));
  71. - }
  72. -
  73. switch (vertex_attribute_formats[i]) {
  74. case PipelineRegs::VertexAttributeFormat::BYTE: {
  75. - const s8* srcdata =
  76. - reinterpret_cast<const s8*>(Memory::GetPhysicalPointer(source_addr));
  77. - for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
  78. - input.attr[i][comp] = float24::FromFloat32(srcdata[comp]);
  79. - }
  80. + vertex_attribute_loader_function[i] = LoadBufferAttr<s8>;
  81. break;
  82. }
  83. case PipelineRegs::VertexAttributeFormat::UBYTE: {
  84. - const u8* srcdata =
  85. - reinterpret_cast<const u8*>(Memory::GetPhysicalPointer(source_addr));
  86. - for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
  87. - input.attr[i][comp] = float24::FromFloat32(srcdata[comp]);
  88. - }
  89. + vertex_attribute_loader_function[i] = LoadBufferAttr<u8>;
  90. break;
  91. }
  92. case PipelineRegs::VertexAttributeFormat::SHORT: {
  93. - const s16* srcdata =
  94. - reinterpret_cast<const s16*>(Memory::GetPhysicalPointer(source_addr));
  95. - for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
  96. - input.attr[i][comp] = float24::FromFloat32(srcdata[comp]);
  97. - }
  98. + vertex_attribute_loader_function[i] = LoadBufferAttr<s16>;
  99. break;
  100. }
  101. case PipelineRegs::VertexAttributeFormat::FLOAT: {
  102. - const float* srcdata =
  103. - reinterpret_cast<const float*>(Memory::GetPhysicalPointer(source_addr));
  104. - for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
  105. - input.attr[i][comp] = float24::FromFloat32(srcdata[comp]);
  106. - }
  107. + vertex_attribute_loader_function[i] = LoadBufferAttr<float>;
  108. break;
  109. }
  110. }
  111. -
  112. - // Default attribute values set if array elements have < 4 components. This
  113. - // is *not* carried over from the default attribute settings even if they're
  114. - // enabled for this attribute.
  115. - for (unsigned int comp = vertex_attribute_elements[i]; comp < 4; ++comp) {
  116. - input.attr[i][comp] =
  117. - comp == 3 ? float24::FromFloat32(1.0f) : float24::FromFloat32(0.0f);
  118. - }
  119. -
  120. - LOG_TRACE(HW_GPU, "Loaded %d components of attribute %x for vertex %x (index %x) from "
  121. - "0x%08x + 0x%08x + 0x%04x: %f %f %f %f",
  122. - vertex_attribute_elements[i], i, vertex, index, base_address,
  123. - vertex_attribute_sources[i], vertex_attribute_strides[i] * vertex,
  124. - input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(),
  125. - input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32());
  126. } else if (vertex_attribute_is_default[i]) {
  127. - // Load the default attribute if we're configured to do so
  128. - input.attr[i] = g_state.input_default_attributes.attr[i];
  129. - LOG_TRACE(HW_GPU,
  130. - "Loaded default attribute %x for vertex %x (index %x): (%f, %f, %f, %f)", i,
  131. - vertex, index, input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(),
  132. - input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32());
  133. + vertex_attribute_loader_function[i] = LoadDefaultAttr;
  134. } else {
  135. - // TODO(yuriks): In this case, no data gets loaded and the vertex
  136. - // remains with the last value it had. This isn't currently maintained
  137. - // as global state, however, and so won't work in Citra yet.
  138. + vertex_attribute_loader_function[i] = LoadPreviousAttr;
  139. }
  140. }
  141. +
  142. + is_setup = true;
  143. +}
  144. +
  145. +void VertexLoader::LoadVertex(u32 base_address, int index, int vertex,
  146. + Shader::AttributeBuffer& input,
  147. + DebugUtils::MemoryAccessTracker& memory_accesses) {
  148. + MICROPROFILE_SCOPE(GPU_VertexLoad);
  149. +
  150. + ASSERT_MSG(is_setup, "A VertexLoader needs to be setup before loading vertices.");
  151. +
  152. + for (int i = 0; i < num_total_attributes; ++i) {
  153. + // Load per-vertex data from the loader arrays
  154. + u32 source_addr =
  155. + base_address + vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex;
  156. + vertex_attribute_loader_function[i](input.attr[i], i, vertex_attribute_elements[i], source_addr);
  157. + }
  158. }
  159.  
  160. } // namespace Pica
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement