@@ -263,17 +263,20 @@ namespace Baikal
263
263
{
264
264
// Evaluate data size
265
265
size_t datasize = 0 ;
266
+ int alignment = 16 ;
266
267
for (auto iter = scene.textures_ .cbegin (); iter != scene.textures_ .cend (); ++iter)
267
268
{
269
+ if (datasize % alignment != 0 )
270
+ datasize += alignment - datasize % alignment;
268
271
datasize += iter->size ;
269
272
}
270
-
271
273
// Texture descriptors
272
274
out.textures = m_context.CreateBuffer <Scene::Texture>(scene.textures_ .size (), CL_MEM_READ_ONLY);
273
275
m_vidmem_usage += scene.textures_ .size () * sizeof (Scene::Texture);
274
276
275
277
// Texture data
276
278
out.texturedata = m_context.CreateBuffer <char >(datasize, CL_MEM_READ_ONLY);
279
+ m_vidmem_usage += datasize;
277
280
278
281
// Map both buffers
279
282
Scene::Texture* mappeddesc = nullptr ;
@@ -297,7 +300,6 @@ namespace Baikal
297
300
298
301
// Write data into the buffer
299
302
memcpy (mappeddata, scene.texturedata_ [texture.dataoffset ].get (), texture.size );
300
- m_vidmem_usage += texture.size ;
301
303
302
304
// Adjust offset in the texture
303
305
texture.dataoffset = current_offset;
@@ -313,6 +315,14 @@ namespace Baikal
313
315
314
316
// Adjust descriptor pointer
315
317
++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
+ }
316
326
}
317
327
318
328
m_context.UnmapBuffer (0 , out.textures , mappeddesc_orig).Wait ();
0 commit comments