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

PROTOTYPE WIP: Add thread-safe read functions to input files #1280

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
31 changes: 31 additions & 0 deletions src/lib/OpenEXR/ImfInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -899,12 +899,43 @@ InputFile::readPixels (int scanLine1, int scanLine2)
}
}

void
InputFile::readPixels (const FrameBuffer& frameBuffer, int scanLine1, int scanLine2)
{
if (_data->compositor)
{
#if ILMTHREAD_THREADING_ENABLED
std::lock_guard<std::mutex> lock (*_data);
#endif
setFrameBuffer (frameBuffer);
_data->compositor->readPixels (scanLine1, scanLine2);
}
else if (_data->isTiled)
{
#if ILMTHREAD_THREADING_ENABLED
std::lock_guard<std::mutex> lock (*_data);
#endif
setFrameBuffer (frameBuffer);
bufferedReadPixels (_data, scanLine1, scanLine2);
}
else
{
_data->sFile->readPixels (frameBuffer, scanLine1, scanLine2);
}
}

void
InputFile::readPixels (int scanLine)
{
readPixels (scanLine, scanLine);
}

void
InputFile::readPixels (const FrameBuffer& frameBuffer, int scanLine)
{
readPixels (frameBuffer, scanLine, scanLine);
}

void
InputFile::rawPixelData (
int firstScanLine, const char*& pixelData, int& pixelDataSize)
Expand Down
12 changes: 12 additions & 0 deletions src/lib/OpenEXR/ImfInputFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,25 @@ class IMF_EXPORT_TYPE InputFile : public GenericInputFile
//
// readPixels(s) calls readPixels(s,s).
//
// The readPixels flavors that are passed a `FrameBuffer&` are
// thread-safe when called at the same time as other threads make
// calls to readPixels(fb,...). The reading functions that rely
// on saved state from a prior call to setFrameBuffer() are NOT
// safe to call when multiple threads are using the same InputFile.
//
//---------------------------------------------------------------

IMF_EXPORT
void readPixels (int scanLine1, int scanLine2);
IMF_EXPORT
void readPixels (int scanLine);

IMF_EXPORT
void readPixels (const FrameBuffer& frameBuffer, int scanLine1, int scanLine2);
IMF_EXPORT
void readPixels (const FrameBuffer& frameBuffer, int scanLine);


//----------------------------------------------
// Read a block of raw pixel data from the file,
// without uncompressing it (this function is
Expand Down
4 changes: 4 additions & 0 deletions src/lib/OpenEXR/ImfInputPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ class IMF_EXPORT_TYPE InputPart
IMF_EXPORT
void readPixels (int scanLine);
IMF_EXPORT
void readPixels (const FrameBuffer& frameBuffer, int scanLine1, int scanLine2);
IMF_EXPORT
void readPixels (const FrameBuffer& frameBuffer, int scanLine);
IMF_EXPORT
void rawPixelData (
int firstScanLine, const char*& pixelData, int& pixelDataSize);

Expand Down
19 changes: 19 additions & 0 deletions src/lib/OpenEXR/ImfScanLineInputFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1748,12 +1748,31 @@ ScanLineInputFile::readPixels (int scanLine1, int scanLine2)
}
}

void
ScanLineInputFile::readPixels (const FrameBuffer& frameBuffer, int scanLine1, int scanLine2)
{
// FIXME: For now, this just locks, then calls setFrameBuffer() and
// readPixels(). It would be better to implement this function to avoid
// locking by not needing any saved framebuffer state.
#if ILMTHREAD_THREADING_ENABLED
std::lock_guard<std::mutex> lock (*_data);
#endif
setFrameBuffer(frameBuffer);
readPixels(scanLine1, scanLine2);
}

void
ScanLineInputFile::readPixels (int scanLine)
{
readPixels (scanLine, scanLine);
}

void
ScanLineInputFile::readPixels (const FrameBuffer& frameBuffer, int scanLine)
{
readPixels (frameBuffer, scanLine, scanLine);
}

void
ScanLineInputFile::rawPixelData (
int firstScanLine, const char*& pixelData, int& pixelDataSize)
Expand Down
11 changes: 11 additions & 0 deletions src/lib/OpenEXR/ImfScanLineInputFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,24 @@ class IMF_EXPORT_TYPE ScanLineInputFile : public GenericInputFile
// If threading is enabled, readPixels (s1, s2) tries to perform
// decopmression of multiple scanlines in parallel.
//
// The readPixels flavors that are passed a `FrameBuffer&` are
// thread-safe when called at the same time as other threads make
// calls to readPixels(fb,...). The reading functions that rely
// on saved state from a prior call to setFrameBuffer() are NOT
// safe to call when multiple threads are using the same InputFile.
//
//---------------------------------------------------------------

IMF_EXPORT
void readPixels (int scanLine1, int scanLine2);
IMF_EXPORT
void readPixels (int scanLine);

IMF_EXPORT
void readPixels (const FrameBuffer& frameBuffer, int scanLine1, int scanLine2);
IMF_EXPORT
void readPixels (const FrameBuffer& frameBuffer, int scanLine);

//----------------------------------------------
// Read a block of raw pixel data from the file,
// without uncompressing it (this function is
Expand Down
32 changes: 31 additions & 1 deletion src/lib/OpenEXR/ImfTiledInputFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,13 @@ class IMF_EXPORT_TYPE TiledInputFile : public GenericInputFile
// Attempting to access a tile that is not present in the file
// throws an InputExc exception.
//
// The readTile/readTiles flavors that are passed a `FrameBuffer&`
// are thread-safe when called at the same time as other threads
// make calls to readTiles(fb,...). The reading functions that
// rely on saved state from a prior call to setFrameBuffer() are
// NOT safe to call when multiple threads are using the same
// TiledInputFile.
//
//------------------------------------------------------------

IMF_EXPORT
Expand All @@ -326,10 +333,33 @@ class IMF_EXPORT_TYPE TiledInputFile : public GenericInputFile

IMF_EXPORT
void readTiles (int dx1, int dx2, int dy1, int dy2, int lx, int ly);

IMF_EXPORT
void readTiles (int dx1, int dx2, int dy1, int dy2, int l = 0);

IMF_EXPORT
void readTile (const FrameBuffer& frameBuffer, int dx, int dy, int l = 0);
IMF_EXPORT
void
readTile (const FrameBuffer& frameBuffer, int dx, int dy, int lx, int ly);

IMF_EXPORT
void readTiles (
const FrameBuffer& frameBuffer,
int dx1,
int dx2,
int dy1,
int dy2,
int lx,
int ly);
IMF_EXPORT
void readTiles (
const FrameBuffer& frameBuffer,
int dx1,
int dx2,
int dy1,
int dy2,
int l = 0);

//--------------------------------------------------
// Read a tile of raw pixel data from the file,
// without uncompressing it (this function is
Expand Down
22 changes: 22 additions & 0 deletions src/lib/OpenEXR/ImfTiledInputPart.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ class IMF_EXPORT_TYPE TiledInputPart
IMF_EXPORT
void readTiles (int dx1, int dx2, int dy1, int dy2, int l = 0);
IMF_EXPORT
void readTile (const FrameBuffer& frameBuffer, int dx, int dy, int l = 0);
IMF_EXPORT
void
readTile (const FrameBuffer& frameBuffer, int dx, int dy, int lx, int ly);
IMF_EXPORT
void readTiles (
const FrameBuffer& frameBuffer,
int dx1,
int dx2,
int dy1,
int dy2,
int lx,
int ly);
IMF_EXPORT
void readTiles (
const FrameBuffer& frameBuffer,
int dx1,
int dx2,
int dy1,
int dy2,
int l = 0);
IMF_EXPORT
void rawTileData (
int& dx,
int& dy,
Expand Down