-
Notifications
You must be signed in to change notification settings - Fork 206
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
GafferOSL : expand indexed primitive variables before shading. #2655
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks Don. I've noted a few potential issues that I think might be addressed by switching prepareShadingPoints
to use ShadingEngine::needsAttribute()
directly instead of requiredPrimvars
. That avoids the linear search, doesn't require changes to hash/affects, and doesn't have any ambiguity around required vs resampled. Is there something I'm missing that would stop that from working?
src/GafferOSL/OSLObject.cpp
Outdated
// cast is ok - we're only using it to be able to reference the data from the shadingPoints, | ||
// but nothing will modify the data itself. | ||
shadingPoints->writable()[it->first] = boost::const_pointer_cast<Data>( it->second.data ); | ||
bool primvarUsed = std::find( primvarNames.begin(), primvarNames.end(), it->first ) != primvarNames.end(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any quadratic complexity concerns here? Do we expect the number of primvars to always be low enough to get away with linear search?
src/GafferOSL/OSLObject.cpp
Outdated
@@ -254,7 +275,7 @@ IECore::ConstObjectPtr OSLObject::computeProcessedObject( const ScenePath &path, | |||
PrimitiveVariable::Interpolation interpolation = static_cast<PrimitiveVariable::Interpolation>( interpolationPlug()->getValue() ); | |||
|
|||
IECoreScene::ConstPrimitivePtr resampledObject = IECore::runTimeCast<const IECoreScene::Primitive>( resampledInPlug()->objectPlug()->getValue() ); | |||
CompoundDataPtr shadingPoints = prepareShadingPoints( resampledObject.get() ); | |||
CompoundDataPtr shadingPoints = prepareShadingPoints( resampledObject.get(), resampledNamesPlug()->getValue() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a plug is pulled on in compute()
, it should also be hashed in hash()
. I suspect we can get away with this here because it is hashed into resampledInPlug()
, but it's best to stick to the rules - it's easy to get things subtly wrong otherwise. The same goes for affects()
.
src/GafferOSL/OSLObject.cpp
Outdated
} | ||
else | ||
{ | ||
// cast is ok - we're only using it to be able to reference the data from the shadingPoints, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're adding the primvar here even if primvarUsed
is false. That seems wrong, but if I understand correctly, is necessary because Constant primvars aren't listed in requiredPrimvars
. In other words, requiredPrimvars
is a misleading name - it's actually resampledPrimVars
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not also omit the non-indexed primvars if needsAttribute()
is false?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I though so also but I got a few test failures which I couldn't explain. Seems like we depend on all the privmars being present in the shadedPoint compound some how. I'll look into it further.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks - I feel like there's either a hole in my understanding here, or a bug somewhere, so it'd be good to get to the bottom of it...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we need to have the "P" primvar to define the number of points to shade. Also I found problems with a unit test which read 'u' so have forced globals to be required to be on the safe side.
53c9cd0
to
eb7ffe3
Compare
Much better. I don't know why I was so quick to discount this approach - updates squashed into |
4986baa
to
eb21320
Compare
src/GafferOSL/ShadingEngine.cpp
Outdated
@@ -1297,5 +1297,11 @@ bool ShadingEngine::needsAttribute( const std::string &scope, const std::string | |||
return true; | |||
} | |||
|
|||
// globals which are always needed | |||
if ( name == "P" || name == "uv" || name == "u" || name == "v" || name == "N" ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I really want to limit the amount of unnecessary resampling and de-indexing we do - it's a major overhead. Can't we use the globals_needed
query we're already using in ShadingEngine::queryContextVariablesAndAttributesNeeded()
to make this more accurate?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is something like 3815e9c better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But I don't think the attribute/global distinction is relevant in terms of the ShadingEngine interface, because everything is passed in via that one container of points to be shaded. As a user of the class there is no distinction at all. I know needsAttribute()
takes both scope
and name
, but actually that's misleading because scope
is unused from the point of view of the client of the ShadingEngine. Likewise, the combined "uv" vs separate "u" and "v" consideration could be totally encapsulated within the ShadingEngine, and so could the requirement for "P". OSLObject just literally just need to call ShadingEngine::needsAttribute( primVarName )
and nothing else.
As a separate thing, I think it'd be good to remove the requirement for "P" by passing in a point count on its own, as it could reduce overhead in a lot of OSLImage cases. But that can wait. Let's just get it working so that we have a single ShadingEngine::needsAttribute( name )
call that encapsulates everything, hiding any distinction between globals and attributes...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. But I don't think the attribute/global distinction is relevant in terms of the ShadingEngine interface, because everything is passed in via that one container of points to be shaded. As a user of the class there is no distinction at all. I know needsAttribute() takes both scope and name, but actually that's misleading because scope is unused from the point of view of the client of the ShadingEngine. Likewise, the combined "uv" vs separate "u" and "v" consideration could be totally encapsulated within the ShadingEngine, and so could the requirement for "P". OSLObject just literally just need to call ShadingEngine::needsAttribute( primVarName ) and nothing else.
right o
As a separate thing, I think it'd be good to remove the requirement for "P" by passing in a point count on its own,
Agreed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about 78cff01 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good - thanks Don!
3815e9c
to
78cff01
Compare
- removed 'scope' parameter from needsAttribute as it always an empty string.
78cff01
to
baa159e
Compare
Bit of a bodge to fix a crash bug when processing indexed primvars in OSLObject.