Skip to content

Commit

Permalink
ImageGadget : Fix unnecessary texture updates
Browse files Browse the repository at this point in the history
When an image tile doesn't need updating, `Tile::computeUpdate()` still returns an `Update` struct, but with `channelData == null`. When processing that in `Tile::applyUpdates()`, we were zeroing out `Tile::m_channelDataHash`, which would cause the next update to do completely unnecessary work. Now we don't do that.
  • Loading branch information
johnhaddon committed Sep 18, 2024
1 parent 57c6df9 commit f15eb9f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Improvements
Fixes
-----

- Viewer, ImageGadget : Fixed unnecessary texture updates when specific image tiles don't change.
- Constraint : The `target` browser now shows locations from the `targetScene` if it has an input connection. Before it always showed locations from the main input.
- ImageInspector : Fixed broken UI caused by double-clicking in the Image tab.

Expand Down
26 changes: 26 additions & 0 deletions python/GafferImageUITest/ImageGadgetTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#
##########################################################################

import time
import unittest
import imath

Expand Down Expand Up @@ -120,5 +121,30 @@ def testStateChangedSignal( self ) :
self.assertEqual( len( cs ), 2 )
self.assertNotEqual( gadget.state(), gadget.State.Paused )

def testNoUnecessaryUpdates( self ) :

script = Gaffer.ScriptNode()
script["image"] = GafferImage.Checkerboard()
script["image"]["format"].setValue( GafferImage.Format( GafferImage.ImagePlug.tileSize(), GafferImage.ImagePlug.tileSize() ) )

gadget = GafferImageUI.ImageGadget()
gadget.setImage( script["image"]["out"] )
gadget.setContext( script.context() )

with GafferUI.Window() as window :
GafferUI.GadgetWidget( gadget )

window.setVisible( True )
while gadget.tileUpdateCount() < 4 :
self.waitForIdle()

for frame in range( 2, 4 ) :
script.context().setFrame( frame )
t = time.time() + 0.5
while time.time() < t :
self.waitForIdle()

self.assertEqual( gadget.tileUpdateCount(), 4 )

if __name__ == "__main__":
unittest.main()
2 changes: 1 addition & 1 deletion src/GafferImageUI/ImageGadget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ void ImageGadget::Tile::applyUpdates( const std::vector<Update> &updates )

for( const auto &u : updates )
{
if( u.tile )
if( u.channelData )
{
u.tile->m_channelDataToConvert = u.channelData;
u.tile->m_channelDataHash = u.channelDataHash;
Expand Down

0 comments on commit f15eb9f

Please sign in to comment.