Skip to content

Commit

Permalink
Merge pull request #6117 from johnhaddon/shadingEngineInt64
Browse files Browse the repository at this point in the history
ShadingEngine : Support 64 bit ints in `RendererServices::get_userdata()`
  • Loading branch information
johnhaddon authored Nov 21, 2024
2 parents 5aa13b8 + ed0cc23 commit 0e3ec4a
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main/installDependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

# Determine default archive URL.

defaultURL = "https://github.com/GafferHQ/dependencies/releases/download/9.0.0/gafferDependencies-9.0.0-{platform}{buildEnvironment}.{extension}"
defaultURL = "https://github.com/GafferHQ/dependencies/releases/download/9.1.0/gafferDependencies-9.1.0-{platform}{buildEnvironment}.{extension}"

# Parse command line arguments.

Expand Down
7 changes: 7 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ Fixes
- `gaffer view` : Fixed default OpenColorIO display transform.
- AnimationEditor : Fixed changing of the current frame by dragging the frame indicator or clicking on the time axis.
- ImageWriter : Matched view metadata to Nuke when using the Nuke options for `layout`. This should address an issue where EXRs written from Gaffer using Nuke layouts sometimes did not load correctly in Nuke (#6120). In the unlikely situation that you were relying on the old behaviour, you can set the env var `GAFFERIMAGE_IMAGEWRITER_OMIT_DEFAULT_NUKE_VIEW = 1` in order to keep the old behaviour.
- OSLObject : Fixed `getattribute()` to support 64 bit integer data, such as an `instanceId` primitive variable loaded from USD. Since OSL doesn't provide a 64 bit integer type, values are truncated to 32 bits.
- MeshSplit : Vertex order is now preserved.

API
---
Expand All @@ -54,6 +56,11 @@ API
- SceneEditor : Added `editScope()` method.
- Image : Added optional `image` argument to `createSwatch()` static method.

Build
-----

- Cortex : Updated to version 10.5.11.0.

1.5.0.1 (relative to 1.5.0.0)
=======

Expand Down
27 changes: 27 additions & 0 deletions python/GafferOSLTest/ShadingEngineTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,33 @@ def testDoubleAsIntViaGetAttribute( self ) :
for i, c in enumerate( p["Ci"] ) :
self.assertEqual( c[0], float(i) )

def testInt64GetAttribute( self ) :

shader = self.compileShader( pathlib.Path( __file__ ).parent / "shaders" / "intAttribute.osl" )

for dataType in ( IECore.Int64VectorData, IECore.UInt64VectorData ) :

with self.subTest( dataType = dataType ) :

points = IECore.CompoundData( {
"P" : IECore.V3fVectorData( [ imath.V3f( i ) for i in range( 0, 10 ) ] ),
"int64Data" : dataType( range( 0, 10 ) )
} )

engine = GafferOSL.ShadingEngine( IECoreScene.ShaderNetwork(
shaders = {
"output" : IECoreScene.Shader( shader, "osl:surface", { "name" : "int64Data" } ),
},
output = "output"
) )

self.assertTrue( engine.needsAttribute( "int64Data" ) )

points = engine.shade( points )

for i, c in enumerate( points["Ci"] ) :
self.assertEqual( c[0], float( i ) )

def testUserDataViaGetAttribute( self ) :

shader = self.compileShader( pathlib.Path( __file__ ).parent / "shaders" / "attribute.osl" )
Expand Down
50 changes: 32 additions & 18 deletions src/GafferOSL/ShadingEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,29 @@ DataPtr dataFromTypeDesc( TypeDesc type, void *&basePointer )
return nullptr;
}

template<typename SourceType>
bool convertScalar( void *dst, TypeDesc dstType, const void *src )
{
const SourceType *typedSrc = reinterpret_cast<const SourceType *>( src );
if( dstType == TypeDesc::FLOAT )
{
if( typedSrc && dst )
{
*((float*)dst) = static_cast<float>( *typedSrc );
}
return true;
}
else if( dstType == TypeDesc::INT )
{
if( typedSrc && dst )
{
*((int*)dst) = static_cast<int>( *typedSrc );
}
return true;
}
return false;
}

// Equivalent to `OSL::ShadingSystem:convert_value()`, but with support for
// additional conversions.
bool convertValue( void *dst, TypeDesc dstType, const void *src, TypeDesc srcType )
Expand Down Expand Up @@ -254,24 +277,15 @@ bool convertValue( void *dst, TypeDesc dstType, const void *src, TypeDesc srcTyp
}
else if( srcType.basetype == TypeDesc::DOUBLE && srcType.aggregate == TypeDesc::SCALAR )
{
const double *doubleCast = reinterpret_cast<const double *>( src );
if( dstType == TypeDesc::FLOAT )
{
if( doubleCast && dst )
{
*((float*)dst) = static_cast<float>( *doubleCast );
}
return true;
}
else if( dstType == TypeDesc::INT )
{
if( doubleCast && dst )
{
*((int*)dst) = static_cast<int>( *doubleCast );
}
return true;
}
return false;
return convertScalar<double>( dst, dstType, src );
}
else if( srcType.basetype == TypeDesc::INT64 && srcType.aggregate == TypeDesc::SCALAR )
{
return convertScalar<int64_t>( dst, dstType, src );
}
else if( srcType.basetype == TypeDesc::UINT64 && srcType.aggregate == TypeDesc::SCALAR )
{
return convertScalar<uint64_t>( dst, dstType, src );
}

return false;
Expand Down

0 comments on commit 0e3ec4a

Please sign in to comment.