Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reintroduce single cache for successive scanline reads #1899

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 29 additions & 6 deletions src/lib/OpenEXR/ImfScanLineInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,27 @@ struct ScanLineInputFile::Data

void readPixels (const FrameBuffer &fb, int scanLine1, int scanLine2);

// only keep a single stash of a scanline for things which
// are reading one-scanline at a time. if we try to keep a
// multi-threaded stash of scanlines, memory grows too rapidly
std::unique_ptr<ScanLineProcess> singleScan;
std::unique_ptr<ScanLineProcess> checkoutScan ()
{
#if ILMTHREAD_THREADING_ENABLED
std::lock_guard<std::mutex> lock (_mx);
#endif
if (singleScan)
return std::move (singleScan);
return std::make_unique<ScanLineProcess> ();
}
void checkinScan (std::unique_ptr<ScanLineProcess> &sp)
{
#if ILMTHREAD_THREADING_ENABLED
std::lock_guard<std::mutex> lock (_mx);
#endif
singleScan = std::move (sp);
}

FrameBuffer frameBuffer;
std::vector<Slice> fill_list;

Expand Down Expand Up @@ -451,7 +472,7 @@ void ScanLineInputFile::Data::readPixels (
else
#endif
{
ScanLineProcess sp;
std::unique_ptr<ScanLineProcess> sp = checkoutScan ();

for (int y = scanLine1; y <= scanLine2; )
{
Expand All @@ -461,10 +482,10 @@ void ScanLineInputFile::Data::readPixels (
// check if we have the same chunk where we can just
// re-run the unpack (i.e. people reading 1 scan at a time
// in a multi-scanline chunk)
if (!sp.first && sp.cinfo.idx == cinfo.idx &&
sp.last_decode_err == EXR_ERR_SUCCESS)
if (!sp->first && sp->cinfo.idx == cinfo.idx &&
sp->last_decode_err == EXR_ERR_SUCCESS)
{
sp.run_unpack (
sp->run_unpack (
*_ctxt,
partNumber,
&fb,
Expand All @@ -474,8 +495,8 @@ void ScanLineInputFile::Data::readPixels (
}
else
{
sp.cinfo = cinfo;
sp.run_decode (
sp->cinfo = cinfo;
sp->run_decode (
*_ctxt,
partNumber,
&fb,
Expand All @@ -486,6 +507,8 @@ void ScanLineInputFile::Data::readPixels (

y += scansperchunk - (y - cinfo.start_y);
}

checkinScan (sp);
}
}

Expand Down
Loading