summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/CMakeLists.txt1
-rw-r--r--src/common/alignment.h22
-rw-r--r--src/video_core/command_processor.cpp6
3 files changed, 28 insertions, 1 deletions
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 959084cdf..1c9be718f 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -22,6 +22,7 @@ set(SRCS
22 ) 22 )
23 23
24set(HEADERS 24set(HEADERS
25 alignment.h
25 assert.h 26 assert.h
26 bit_field.h 27 bit_field.h
27 bit_set.h 28 bit_set.h
diff --git a/src/common/alignment.h b/src/common/alignment.h
new file mode 100644
index 000000000..b77da4a92
--- /dev/null
+++ b/src/common/alignment.h
@@ -0,0 +1,22 @@
1// This file is under the public domain.
2
3#pragma once
4
5#include <cstddef>
6#include <type_traits>
7
8namespace Common {
9
10template <typename T>
11constexpr T AlignUp(T value, size_t size) {
12 static_assert(std::is_unsigned<T>::value, "T must be an unsigned value.");
13 return static_cast<T>(value + (size - value % size) % size);
14}
15
16template <typename T>
17constexpr T AlignDown(T value, size_t size) {
18 static_assert(std::is_unsigned<T>::value, "T must be an unsigned value.");
19 return static_cast<T>(value - value % size);
20}
21
22} // namespace Common
diff --git a/src/video_core/command_processor.cpp b/src/video_core/command_processor.cpp
index 2274dfa66..54721561e 100644
--- a/src/video_core/command_processor.cpp
+++ b/src/video_core/command_processor.cpp
@@ -5,6 +5,7 @@
5#include <cmath> 5#include <cmath>
6#include <boost/range/algorithm/fill.hpp> 6#include <boost/range/algorithm/fill.hpp>
7 7
8#include "common/alignment.h"
8#include "common/microprofile.h" 9#include "common/microprofile.h"
9#include "common/profiler.h" 10#include "common/profiler.h"
10 11
@@ -210,14 +211,17 @@ static void WritePicaReg(u32 id, u32 value, u32 mask) {
210 211
211 u32 attribute_index = loader_config.GetComponent(component); 212 u32 attribute_index = loader_config.GetComponent(component);
212 if (attribute_index < 12) { 213 if (attribute_index < 12) {
214 int element_size = attribute_config.GetElementSizeInBytes(attribute_index);
215 load_address = Common::AlignUp(load_address, element_size);
213 vertex_attribute_sources[attribute_index] = load_address; 216 vertex_attribute_sources[attribute_index] = load_address;
214 vertex_attribute_strides[attribute_index] = static_cast<u32>(loader_config.byte_count); 217 vertex_attribute_strides[attribute_index] = static_cast<u32>(loader_config.byte_count);
215 vertex_attribute_formats[attribute_index] = attribute_config.GetFormat(attribute_index); 218 vertex_attribute_formats[attribute_index] = attribute_config.GetFormat(attribute_index);
216 vertex_attribute_elements[attribute_index] = attribute_config.GetNumElements(attribute_index); 219 vertex_attribute_elements[attribute_index] = attribute_config.GetNumElements(attribute_index);
217 vertex_attribute_element_size[attribute_index] = attribute_config.GetElementSizeInBytes(attribute_index); 220 vertex_attribute_element_size[attribute_index] = element_size;
218 load_address += attribute_config.GetStride(attribute_index); 221 load_address += attribute_config.GetStride(attribute_index);
219 } else if (attribute_index < 16) { 222 } else if (attribute_index < 16) {
220 // Attribute ids 12, 13, 14 and 15 signify 4, 8, 12 and 16-byte paddings, respectively 223 // Attribute ids 12, 13, 14 and 15 signify 4, 8, 12 and 16-byte paddings, respectively
224 load_address = Common::AlignUp(load_address, 4);
221 load_address += (attribute_index - 11) * 4; 225 load_address += (attribute_index - 11) * 4;
222 } else { 226 } else {
223 UNREACHABLE(); // This is truly unreachable due to the number of bits for each component 227 UNREACHABLE(); // This is truly unreachable due to the number of bits for each component