ALL: fixed video buf alignments

master
Martin Gerhardy 2019-10-20 14:36:24 +02:00
parent 9cbaa548d0
commit 702486967b
6 changed files with 18 additions and 19 deletions

View File

@ -79,8 +79,8 @@ private:
std::vector<RenderMeshData> _meshData;
std::vector<image::ImagePtr> _images;
std::vector<video::TexturePtr> _textures;
Vertices _vertices;
Indices _indices;
alignas(32) Vertices _vertices;
alignas(16) Indices _indices;
video::Buffer _vertexBuffer;
video::Buffer _vertexBufferLines;
int32_t _vertexBufferLinesIndex = -1;

View File

@ -90,7 +90,7 @@ int32_t ShapeRenderer::create(const video::ShapeBuilder& shapeBuilder) {
return -1;
}
std::vector<Vertex> vertices;
alignas(32) std::vector<Vertex> vertices;
vertices.reserve(shapeBuilder.getVertices().size());
shapeBuilder.iterate([&] (const glm::vec3& pos, const glm::vec2& uv, const glm::vec4& color, const glm::vec3& normal) {
vertices.emplace_back(Vertex{glm::vec4(pos, 1.0f), color, uv, normal});
@ -147,7 +147,7 @@ void ShapeRenderer::update(uint32_t meshIndex, const video::ShapeBuilder& shapeB
Log::warn("Invalid mesh index given: %u", meshIndex);
return;
}
std::vector<Vertex> vertices;
alignas(32) std::vector<Vertex> vertices;
vertices.reserve(shapeBuilder.getVertices().size());
shapeBuilder.iterate([&] (const glm::vec3& pos, const glm::vec2& uv, const glm::vec4& color, const glm::vec3& normal) {
vertices.emplace_back(Vertex{glm::vec4(pos, 1.0f), color, uv, normal});

View File

@ -123,9 +123,8 @@ bool Buffer::update(int32_t idx, const void* data, size_t size) {
core_assert(video::boundVertexArray() == InvalidId);
const size_t oldSize = _size[idx];
const size_t newSize = align(size, _targets[idx]);
#if VIDEO_BUFFER_HASH_COMPARE
if (oldSize == newSize) {
if (oldSize == size) {
uint32_t newHash = core::hash(data, size);
if (newHash == _hash[idx]) {
return true;
@ -135,15 +134,15 @@ bool Buffer::update(int32_t idx, const void* data, size_t size) {
_hash[idx] = core::hash(data, size);
}
#endif
_size[idx] = newSize;
_size[idx] = size;
core_assert_16byte_aligned(data);
core_assert_msg((_size[idx] & 15) == 0, "Size is not aligned properly");
//core_assert_msg((_size[idx] & 15) == 0, "Size is not aligned properly: %i", (int)_size[idx]);
const BufferType type = _targets[idx];
const Id id = _handles[idx];
if (oldSize >= size && _modes[idx] != BufferMode::Static) {
video::bufferSubData(id, type, 0, data, _size[idx]);
video::bufferSubData(id, type, 0, data, size);
} else {
video::bufferData(id, type, _modes[idx], data, _size[idx]);
video::bufferData(id, type, _modes[idx], data, size);
}
return true;
@ -160,9 +159,9 @@ int32_t Buffer::create(const void* data, size_t size, BufferType target) {
Log::error("Failed to create buffer (size: %i)", (int)size);
return -1;
}
_size[idx] = align(size, target);
_size[idx] = size;
if (data != nullptr) {
update(idx, data, _size[idx]);
update(idx, data, size);
}
++_handleIdx;
return idx;

View File

@ -32,11 +32,11 @@ public:
typedef std::vector<glm::vec4> Colors;
typedef Colors::const_iterator ColorsIter;
private:
Indices _indices;
Texcoords _texcoords;
Vertices _vertices;
Vertices _normals;
Colors _colors;
alignas(32) Indices _indices;
alignas(32) Texcoords _texcoords;
alignas(32) Vertices _vertices;
alignas(32) Vertices _normals;
alignas(32) Colors _colors;
glm::mat3 _rotation = glm::mat3(1.0f);
Primitive _primitive = Primitive::Triangles;
int _initialSize;

View File

@ -28,7 +28,7 @@ core::AppState TestGLSLGeom::onInit() {
glm::vec4 pos{0, 0, 0, 1};
glm::vec3 color{1, 1, 1};
};
Buf buf;
alignas(32) Buf buf;
const int32_t bufIndex = _buffer.create(&buf, sizeof(buf));
_buffer.setMode(bufIndex, video::BufferMode::Static);

View File

@ -35,7 +35,7 @@ private:
int32_t _itemMesh = -1;
int32_t _frustumMesh = -1;
int32_t _aabbMesh = -1;
std::vector<glm::vec3> _positions;
alignas(32) std::vector<glm::vec3> _positions;
glm::vec3 _pos;
glm::vec3 _lookAt{10.0f, 70.0f, 10.0f};
glm::vec3 _omega{0.0f, 0.1f, 0.0f};