@@ -120,7 +120,7 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
120
120
return IGPUCommandBuffer::reset (_flags);
121
121
}
122
122
123
- void COpenGLCommandBuffer::copyBufferToImage (const SCmd<impl::ECT_COPY_BUFFER_TO_IMAGE>& c, IOpenGL_FunctionTable* gl, SOpenGLContextLocalCache* ctxlocal, uint32_t ctxid)
123
+ void COpenGLCommandBuffer::copyBufferToImage (const SCmd<impl::ECT_COPY_BUFFER_TO_IMAGE>& c, IOpenGL_FunctionTable* gl, SOpenGLContextLocalCache* ctxlocal, uint32_t ctxid, const system::logger_opt_ptr logger )
124
124
{
125
125
IGPUImage* dstImage = c.dstImage .get ();
126
126
const IGPUBuffer* srcBuffer = c.srcBuffer .get ();
@@ -219,7 +219,7 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
219
219
}
220
220
}
221
221
222
- void COpenGLCommandBuffer::copyImageToBuffer (const SCmd<impl::ECT_COPY_IMAGE_TO_BUFFER>& c, IOpenGL_FunctionTable* gl, SOpenGLContextLocalCache* ctxlocal, uint32_t ctxid)
222
+ void COpenGLCommandBuffer::copyImageToBuffer (const SCmd<impl::ECT_COPY_IMAGE_TO_BUFFER>& c, IOpenGL_FunctionTable* gl, SOpenGLContextLocalCache* ctxlocal, uint32_t ctxid, const system::logger_opt_ptr logger )
223
223
{
224
224
const auto * srcImage = c.srcImage .get ();
225
225
auto * dstBuffer = c.dstBuffer .get ();
@@ -234,10 +234,11 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
234
234
GLuint src = static_cast <const COpenGLImage*>(srcImage)->getOpenGLName ();
235
235
GLenum glfmt, gltype;
236
236
getOpenGLFormatAndParametersFromColorFormat (gl, format, glfmt, gltype);
237
-
237
+
238
+ const auto texelBlockInfo = asset::TexelBlockInfo (format);
238
239
const auto bpp = asset::getBytesPerPixel (format);
239
- const auto blockDims = asset::getBlockDimensions (format );
240
- const auto blockByteSize = asset::getTexelOrBlockBytesize (format );
240
+ const auto blockDims = texelBlockInfo. getDimension ( );
241
+ const auto blockByteSize = texelBlockInfo. getBlockByteSize ( );
241
242
242
243
const bool usingGetTexSubImage = (gl->features ->Version >= 450 || gl->features ->FeatureAvailable [gl->features ->EOpenGLFeatures ::NBL_ARB_get_texture_sub_image]);
243
244
@@ -250,9 +251,15 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
250
251
{
251
252
if (it->bufferOffset != core::alignUp (it->bufferOffset , blockByteSize))
252
253
{
253
- assert (false && " bufferOffset should be aligned to block/texel byte size." );
254
+ logger.log (" bufferOffset should be aligned to block/texel byte size." , system::ILogger::ELL_ERROR);
255
+ assert (false );
254
256
continue ;
255
257
}
258
+
259
+ const auto imageExtent = core::vector3du32_SIMD (it->imageExtent .width , it->imageExtent .height , it->imageExtent .depth );
260
+ const auto imageExtentInBlocks = texelBlockInfo.convertTexelsToBlocks (imageExtent);
261
+ const auto imageExtentBlockStridesInBytes = texelBlockInfo.convert3DBlockStridesTo1DByteStrides (imageExtentInBlocks);
262
+ const uint32_t eachLayerNeededMemory = imageExtentBlockStridesInBytes[3 ]; // = blockByteSize * imageExtentInBlocks.x * imageExtentInBlocks.y * imageExtentInBlocks.z
256
263
257
264
uint32_t pitch = ((it->bufferRowLength ? it->bufferRowLength : it->imageExtent .width ) * bpp).getIntegerApprox ();
258
265
int32_t alignment = 0x1 << core::min (core::max (core::findLSB (it->bufferOffset ), core::findLSB (pitch)), 3u );
@@ -291,14 +298,13 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
291
298
{
292
299
ctxlocal->flushStateGraphics (gl, SOpenGLContextLocalCache::GSB_PIXEL_PACK_UNPACK, ctxid);
293
300
294
- // TODO this isnt totally valid right?
295
- const size_t bytesPerLayer = pitch * yRange * (compressed ? nbl::asset::getFormatChannelCount (format) : nbl::asset::getTexelOrBlockBytesize (format)); // all block compressed formats are decoded into 1 byte per channel format
301
+ const size_t bytesPerLayer = eachLayerNeededMemory;
296
302
for (uint32_t z = 0u ; z < zRange; ++z)
297
303
{
298
304
GLuint fbo = ctxlocal->getSingleColorAttachmentFBO (gl, srcImage, it->imageSubresource .mipLevel , it->imageSubresource .baseArrayLayer + z);
299
305
if (!fbo)
300
306
{
301
- // TODO log something
307
+ logger. log ( " Couldn't retrieve attachment to download image to. " , system::ILogger::ELL_ERROR);
302
308
continue ;
303
309
}
304
310
@@ -692,14 +698,14 @@ COpenGLCommandBuffer::~COpenGLCommandBuffer()
692
698
{
693
699
auto & c = cmd.get <impl::ECT_COPY_BUFFER_TO_IMAGE>();
694
700
695
- copyBufferToImage (c, gl, ctxlocal, ctxid);
701
+ copyBufferToImage (c, gl, ctxlocal, ctxid, m_logger. getOptRawPtr () );
696
702
}
697
703
break ;
698
704
case impl::ECT_COPY_IMAGE_TO_BUFFER:
699
705
{
700
706
auto & c = cmd.get <impl::ECT_COPY_IMAGE_TO_BUFFER>();
701
707
702
- copyImageToBuffer (c, gl, ctxlocal, ctxid);
708
+ copyImageToBuffer (c, gl, ctxlocal, ctxid, m_logger. getOptRawPtr () );
703
709
}
704
710
break ;
705
711
case impl::ECT_BLIT_IMAGE:
0 commit comments