Skip to content

engine: override spec constants on instance-basis#9774

Open
elizagamedev wants to merge 7 commits intomainfrom
exv/mi-sc
Open

engine: override spec constants on instance-basis#9774
elizagamedev wants to merge 7 commits intomainfrom
exv/mi-sc

Conversation

@elizagamedev
Copy link
Contributor

This commit adds getConstant() and setConstant() methods to MaterialInstance.

When a material instance is created, it doesn't create or manage any spec constants on its own, but instead relies on Material. The client can change constants at any time, after which the necessary resources are copied and maintained by MaterialInstance.

As part of this change, most internal rendering methods which depended on Material have been refactored to instead depend on MaterialInstance.

Copy link
Collaborator

@pixelflinger pixelflinger left a comment

Choose a reason for hiding this comment

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

This looks good, but scares the hell out of me :-)

It would be really hard to guard this change with a feature flag; but do we have high confidence that NOT using the new feature should essentially not change anything?

loadMaterial(engine);
}
mMaterial->prepareProgram(driver, Variant{ variant }, CompilerPriorityQueue::CRITICAL);
mMaterial->getDefaultInstance()->prepareProgram(driver, Variant{ variant },
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you have a comment that explains why it's okay to use the default instance? What if it's not the one the user ends-up using?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, I think it'd probably be best to inline the prepareProgram() call here at all the call sites of getMaterial(); will do that.

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 had to do quite a lot of refactoring to address this properly, please review.


void FMaterial::compile(CompilerPriorityQueue const priority, UserVariantFilterMask variantSpec,
CallbackHandler* handler, Invocable<void(Material*)>&& callback) noexcept {
FMaterialInstance* mi = getDefaultInstance();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is Material::compile() essentially deprecated?

I feel like at least its documentation needs to change. If I understand correctly, as long as you don't set a constant on a material instance; this works like before. But if you do, this basically doesn't help you.

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, that's correct. I can update the documentation.

Copy link
Contributor

@poweifeng poweifeng left a comment

Choose a reason for hiding this comment

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

some nits

@elizagamedev elizagamedev force-pushed the exv/mi-sc branch 2 times, most recently from 5c24e43 to 03d26cc Compare March 11, 2026 02:21
This commit adds `getConstant()` and `setConstant()` methods to
`MaterialInstance`.

When a material instance is created, it doesn't create or manage any spec
constants on its own, but instead relies on `Material`. The client can change
constants at any time, after which the necessary resources are copied and
maintained by `MaterialInstance`.

As part of this change, most internal rendering methods which depended on
`Material` have been refactored to instead depend on `MaterialInstance`.
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.

4 participants