Skip to content

Commit 9a8223c

Browse files
authored
Merge pull request #122 from beasterio/master
Added alignment for textures.
2 parents 586e1de + 31d2b38 commit 9a8223c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

App/Scene/scene_tracker.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,17 +263,20 @@ namespace Baikal
263263
{
264264
// Evaluate data size
265265
size_t datasize = 0;
266+
int alignment = 16;
266267
for (auto iter = scene.textures_.cbegin(); iter != scene.textures_.cend(); ++iter)
267268
{
269+
if (datasize % alignment != 0)
270+
datasize += alignment - datasize % alignment;
268271
datasize += iter->size;
269272
}
270-
271273
// Texture descriptors
272274
out.textures = m_context.CreateBuffer<Scene::Texture>(scene.textures_.size(), CL_MEM_READ_ONLY);
273275
m_vidmem_usage += scene.textures_.size() * sizeof(Scene::Texture);
274276

275277
// Texture data
276278
out.texturedata = m_context.CreateBuffer<char>(datasize, CL_MEM_READ_ONLY);
279+
m_vidmem_usage += datasize;
277280

278281
// Map both buffers
279282
Scene::Texture* mappeddesc = nullptr;
@@ -297,7 +300,6 @@ namespace Baikal
297300

298301
// Write data into the buffer
299302
memcpy(mappeddata, scene.texturedata_[texture.dataoffset].get(), texture.size);
300-
m_vidmem_usage += texture.size;
301303

302304
// Adjust offset in the texture
303305
texture.dataoffset = current_offset;
@@ -313,6 +315,14 @@ namespace Baikal
313315

314316
// Adjust descriptor pointer
315317
++mappeddesc;
318+
319+
//alignment
320+
uintptr_t shift = alignment - (uintptr_t)mappeddata % alignment;
321+
if (shift != alignment)
322+
{
323+
mappeddata += shift;
324+
current_offset += shift;
325+
}
316326
}
317327

318328
m_context.UnmapBuffer(0, out.textures, mappeddesc_orig).Wait();

0 commit comments

Comments
 (0)