summaryrefslogtreecommitdiff
path: root/src/video_core/vertex_loader.cpp
diff options
context:
space:
mode:
authorGravatar Emmanuel Gil Peyrot2016-09-18 09:38:01 +0900
committerGravatar Emmanuel Gil Peyrot2016-09-18 09:38:01 +0900
commitdc8479928c5aee4c6ad6fe4f59006fb604cee701 (patch)
tree569a7f13128450bbab973236615587ff00bced5f /src/video_core/vertex_loader.cpp
parentTravis: Import Dolphin’s clang-format hook. (diff)
downloadyuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.gz
yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.tar.xz
yuzu-dc8479928c5aee4c6ad6fe4f59006fb604cee701.zip
Sources: Run clang-format on everything.
Diffstat (limited to 'src/video_core/vertex_loader.cpp')
-rw-r--r--src/video_core/vertex_loader.cpp88
1 files changed, 52 insertions, 36 deletions
diff --git a/src/video_core/vertex_loader.cpp b/src/video_core/vertex_loader.cpp
index e40f0f1ee..9dcd9d748 100644
--- a/src/video_core/vertex_loader.cpp
+++ b/src/video_core/vertex_loader.cpp
@@ -41,24 +41,32 @@ void VertexLoader::Setup(const Pica::Regs& regs) {
41 // TODO: What happens if a loader overwrites a previous one's data? 41 // TODO: What happens if a loader overwrites a previous one's data?
42 for (unsigned component = 0; component < loader_config.component_count; ++component) { 42 for (unsigned component = 0; component < loader_config.component_count; ++component) {
43 if (component >= 12) { 43 if (component >= 12) {
44 LOG_ERROR(HW_GPU, "Overflow in the vertex attribute loader %u trying to load component %u", loader, component); 44 LOG_ERROR(HW_GPU,
45 "Overflow in the vertex attribute loader %u trying to load component %u",
46 loader, component);
45 continue; 47 continue;
46 } 48 }
47 49
48 u32 attribute_index = loader_config.GetComponent(component); 50 u32 attribute_index = loader_config.GetComponent(component);
49 if (attribute_index < 12) { 51 if (attribute_index < 12) {
50 offset = Common::AlignUp(offset, attribute_config.GetElementSizeInBytes(attribute_index)); 52 offset = Common::AlignUp(offset,
53 attribute_config.GetElementSizeInBytes(attribute_index));
51 vertex_attribute_sources[attribute_index] = loader_config.data_offset + offset; 54 vertex_attribute_sources[attribute_index] = loader_config.data_offset + offset;
52 vertex_attribute_strides[attribute_index] = static_cast<u32>(loader_config.byte_count); 55 vertex_attribute_strides[attribute_index] =
53 vertex_attribute_formats[attribute_index] = attribute_config.GetFormat(attribute_index); 56 static_cast<u32>(loader_config.byte_count);
54 vertex_attribute_elements[attribute_index] = attribute_config.GetNumElements(attribute_index); 57 vertex_attribute_formats[attribute_index] =
58 attribute_config.GetFormat(attribute_index);
59 vertex_attribute_elements[attribute_index] =
60 attribute_config.GetNumElements(attribute_index);
55 offset += attribute_config.GetStride(attribute_index); 61 offset += attribute_config.GetStride(attribute_index);
56 } else if (attribute_index < 16) { 62 } else if (attribute_index < 16) {
57 // Attribute ids 12, 13, 14 and 15 signify 4, 8, 12 and 16-byte paddings, respectively 63 // Attribute ids 12, 13, 14 and 15 signify 4, 8, 12 and 16-byte paddings,
64 // respectively
58 offset = Common::AlignUp(offset, 4); 65 offset = Common::AlignUp(offset, 4);
59 offset += (attribute_index - 11) * 4; 66 offset += (attribute_index - 11) * 4;
60 } else { 67 } else {
61 UNREACHABLE(); // This is truly unreachable due to the number of bits for each component 68 UNREACHABLE(); // This is truly unreachable due to the number of bits for each
69 // component
62 } 70 }
63 } 71 }
64 } 72 }
@@ -66,48 +74,55 @@ void VertexLoader::Setup(const Pica::Regs& regs) {
66 is_setup = true; 74 is_setup = true;
67} 75}
68 76
69void VertexLoader::LoadVertex(u32 base_address, int index, int vertex, Shader::InputVertex& input, DebugUtils::MemoryAccessTracker& memory_accesses) { 77void VertexLoader::LoadVertex(u32 base_address, int index, int vertex, Shader::InputVertex& input,
78 DebugUtils::MemoryAccessTracker& memory_accesses) {
70 ASSERT_MSG(is_setup, "A VertexLoader needs to be setup before loading vertices."); 79 ASSERT_MSG(is_setup, "A VertexLoader needs to be setup before loading vertices.");
71 80
72 for (int i = 0; i < num_total_attributes; ++i) { 81 for (int i = 0; i < num_total_attributes; ++i) {
73 if (vertex_attribute_elements[i] != 0) { 82 if (vertex_attribute_elements[i] != 0) {
74 // Load per-vertex data from the loader arrays 83 // Load per-vertex data from the loader arrays
75 u32 source_addr = base_address + vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex; 84 u32 source_addr =
85 base_address + vertex_attribute_sources[i] + vertex_attribute_strides[i] * vertex;
76 86
77 if (g_debug_context && Pica::g_debug_context->recorder) { 87 if (g_debug_context && Pica::g_debug_context->recorder) {
78 memory_accesses.AddAccess(source_addr, vertex_attribute_elements[i] * ( 88 memory_accesses.AddAccess(
79 (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::FLOAT) ? 4 89 source_addr,
80 : (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::SHORT) ? 2 : 1)); 90 vertex_attribute_elements[i] *
91 ((vertex_attribute_formats[i] == Regs::VertexAttributeFormat::FLOAT)
92 ? 4
93 : (vertex_attribute_formats[i] == Regs::VertexAttributeFormat::SHORT)
94 ? 2
95 : 1));
81 } 96 }
82 97
83 switch (vertex_attribute_formats[i]) { 98 switch (vertex_attribute_formats[i]) {
84 case Regs::VertexAttributeFormat::BYTE: 99 case Regs::VertexAttributeFormat::BYTE: {
85 { 100 const s8* srcdata =
86 const s8* srcdata = reinterpret_cast<const s8*>(Memory::GetPhysicalPointer(source_addr)); 101 reinterpret_cast<const s8*>(Memory::GetPhysicalPointer(source_addr));
87 for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { 102 for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
88 input.attr[i][comp] = float24::FromFloat32(srcdata[comp]); 103 input.attr[i][comp] = float24::FromFloat32(srcdata[comp]);
89 } 104 }
90 break; 105 break;
91 } 106 }
92 case Regs::VertexAttributeFormat::UBYTE: 107 case Regs::VertexAttributeFormat::UBYTE: {
93 { 108 const u8* srcdata =
94 const u8* srcdata = reinterpret_cast<const u8*>(Memory::GetPhysicalPointer(source_addr)); 109 reinterpret_cast<const u8*>(Memory::GetPhysicalPointer(source_addr));
95 for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { 110 for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
96 input.attr[i][comp] = float24::FromFloat32(srcdata[comp]); 111 input.attr[i][comp] = float24::FromFloat32(srcdata[comp]);
97 } 112 }
98 break; 113 break;
99 } 114 }
100 case Regs::VertexAttributeFormat::SHORT: 115 case Regs::VertexAttributeFormat::SHORT: {
101 { 116 const s16* srcdata =
102 const s16* srcdata = reinterpret_cast<const s16*>(Memory::GetPhysicalPointer(source_addr)); 117 reinterpret_cast<const s16*>(Memory::GetPhysicalPointer(source_addr));
103 for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { 118 for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
104 input.attr[i][comp] = float24::FromFloat32(srcdata[comp]); 119 input.attr[i][comp] = float24::FromFloat32(srcdata[comp]);
105 } 120 }
106 break; 121 break;
107 } 122 }
108 case Regs::VertexAttributeFormat::FLOAT: 123 case Regs::VertexAttributeFormat::FLOAT: {
109 { 124 const float* srcdata =
110 const float* srcdata = reinterpret_cast<const float*>(Memory::GetPhysicalPointer(source_addr)); 125 reinterpret_cast<const float*>(Memory::GetPhysicalPointer(source_addr));
111 for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) { 126 for (unsigned int comp = 0; comp < vertex_attribute_elements[i]; ++comp) {
112 input.attr[i][comp] = float24::FromFloat32(srcdata[comp]); 127 input.attr[i][comp] = float24::FromFloat32(srcdata[comp]);
113 } 128 }
@@ -119,22 +134,23 @@ void VertexLoader::LoadVertex(u32 base_address, int index, int vertex, Shader::I
119 // is *not* carried over from the default attribute settings even if they're 134 // is *not* carried over from the default attribute settings even if they're
120 // enabled for this attribute. 135 // enabled for this attribute.
121 for (unsigned int comp = vertex_attribute_elements[i]; comp < 4; ++comp) { 136 for (unsigned int comp = vertex_attribute_elements[i]; comp < 4; ++comp) {
122 input.attr[i][comp] = comp == 3 ? float24::FromFloat32(1.0f) : float24::FromFloat32(0.0f); 137 input.attr[i][comp] =
138 comp == 3 ? float24::FromFloat32(1.0f) : float24::FromFloat32(0.0f);
123 } 139 }
124 140
125 LOG_TRACE(HW_GPU, "Loaded %d components of attribute %x for vertex %x (index %x) from 0x%08x + 0x%08x + 0x%04x: %f %f %f %f", 141 LOG_TRACE(HW_GPU, "Loaded %d components of attribute %x for vertex %x (index %x) from "
126 vertex_attribute_elements[i], i, vertex, index, 142 "0x%08x + 0x%08x + 0x%04x: %f %f %f %f",
127 base_address, 143 vertex_attribute_elements[i], i, vertex, index, base_address,
128 vertex_attribute_sources[i], 144 vertex_attribute_sources[i], vertex_attribute_strides[i] * vertex,
129 vertex_attribute_strides[i] * vertex, 145 input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(),
130 input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(), input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32()); 146 input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32());
131 } else if (vertex_attribute_is_default[i]) { 147 } else if (vertex_attribute_is_default[i]) {
132 // Load the default attribute if we're configured to do so 148 // Load the default attribute if we're configured to do so
133 input.attr[i] = g_state.vs_default_attributes[i]; 149 input.attr[i] = g_state.vs_default_attributes[i];
134 LOG_TRACE(HW_GPU, "Loaded default attribute %x for vertex %x (index %x): (%f, %f, %f, %f)", 150 LOG_TRACE(HW_GPU,
135 i, vertex, index, 151 "Loaded default attribute %x for vertex %x (index %x): (%f, %f, %f, %f)", i,
136 input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(), 152 vertex, index, input.attr[i][0].ToFloat32(), input.attr[i][1].ToFloat32(),
137 input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32()); 153 input.attr[i][2].ToFloat32(), input.attr[i][3].ToFloat32());
138 } else { 154 } else {
139 // TODO(yuriks): In this case, no data gets loaded and the vertex 155 // TODO(yuriks): In this case, no data gets loaded and the vertex
140 // remains with the last value it had. This isn't currently maintained 156 // remains with the last value it had. This isn't currently maintained
@@ -143,4 +159,4 @@ void VertexLoader::LoadVertex(u32 base_address, int index, int vertex, Shader::I
143 } 159 }
144} 160}
145 161
146} // namespace Pica 162} // namespace Pica