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

GafferOSL : expand indexed primitive variables before shading. #2655

Merged
merged 1 commit into from
Jul 24, 2018

Conversation

donboie
Copy link
Contributor

@donboie donboie commented Jul 12, 2018

Bit of a bodge to fix a crash bug when processing indexed primvars in OSLObject.

Copy link
Member

@johnhaddon johnhaddon left a 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?

// 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();
Copy link
Member

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?

@@ -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() );
Copy link
Member

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().

}
else
{
// cast is ok - we're only using it to be able to reference the data from the shadingPoints,
Copy link
Member

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.

Copy link
Member

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?

Copy link
Contributor Author

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.

Copy link
Member

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...

Copy link
Contributor Author

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.

@donboie
Copy link
Contributor Author

donboie commented Jul 16, 2018

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?

Much better. I don't know why I was so quick to discount this approach - updates squashed into
eb7ffe3

@donboie donboie force-pushed the OSLObjectIndexPrimVars branch 3 times, most recently from 4986baa to eb21320 Compare July 19, 2018 23:47
@@ -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" )
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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...

Copy link
Contributor Author

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about 78cff01 ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - thanks Don!

- removed 'scope' parameter from needsAttribute as it always an empty string.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants