Skip to content

Commit 7c5eb07

Browse files
committed
assert image-buffer copy alignment in OpenGL
1 parent fdcf172 commit 7c5eb07

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/nbl/video/COpenGLCommandBuffer.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,16 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
138138

139139
const auto bpp = asset::getBytesPerPixel(format);
140140
const auto blockDims = asset::getBlockDimensions(format);
141+
const auto blockByteSize = asset::getTexelOrBlockBytesize(format);
141142

142143
ctxlocal->nextState.pixelUnpack.buffer = core::smart_refctd_ptr<const COpenGLBuffer>(static_cast<const COpenGLBuffer*>(srcBuffer));
143144
for (auto it = c.regions; it != c.regions + c.regionCount; it++)
144145
{
145-
// TODO: check it->bufferOffset is aligned to data type of E_FORMAT
146-
//assert(?);
146+
if(it->bufferOffset != core::alignUp(it->bufferOffset, blockByteSize))
147+
{
148+
assert(false && "bufferOffset should be aligned to block/texel byte size.");
149+
continue;
150+
}
147151

148152
uint32_t pitch = ((it->bufferRowLength ? it->bufferRowLength : it->imageExtent.width) * bpp).getIntegerApprox();
149153
int32_t alignment = 0x1 << core::min(core::min<uint32_t>(core::findLSB(it->bufferOffset),core::findLSB(pitch)), 3u);
@@ -233,6 +237,7 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
233237

234238
const auto bpp = asset::getBytesPerPixel(format);
235239
const auto blockDims = asset::getBlockDimensions(format);
240+
const auto blockByteSize = asset::getTexelOrBlockBytesize(format);
236241

237242
const bool usingGetTexSubImage = (gl->features->Version >= 450 || gl->features->FeatureAvailable[gl->features->EOpenGLFeatures::NBL_ARB_get_texture_sub_image]);
238243

@@ -243,8 +248,11 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
243248
ctxlocal->nextState.pixelPack.buffer = core::smart_refctd_ptr<const COpenGLBuffer>(static_cast<COpenGLBuffer*>(dstBuffer));
244249
for (auto it = c.regions; it != c.regions + c.regionCount; it++)
245250
{
246-
// TODO: check it->bufferOffset is aligned to data type of E_FORMAT
247-
//assert(?);
251+
if(it->bufferOffset != core::alignUp(it->bufferOffset, blockByteSize))
252+
{
253+
assert(false && "bufferOffset should be aligned to block/texel byte size.");
254+
continue;
255+
}
248256

249257
uint32_t pitch = ((it->bufferRowLength ? it->bufferRowLength : it->imageExtent.width) * bpp).getIntegerApprox();
250258
int32_t alignment = 0x1 << core::min(core::max(core::findLSB(it->bufferOffset), core::findLSB(pitch)), 3u);

0 commit comments

Comments
 (0)