Skip to content

Refactor ShaderRenderTester::validate() into focused helper methods#2825

Open
ashwinbhat wants to merge 5 commits intoAcademySoftwareFoundation:mainfrom
autodesk-forks:bhata/renderutil-refactor
Open

Refactor ShaderRenderTester::validate() into focused helper methods#2825
ashwinbhat wants to merge 5 commits intoAcademySoftwareFoundation:mainfrom
autodesk-forks:bhata/renderutil-refactor

Conversation

@ashwinbhat
Copy link
Contributor

Break up the monolithic validate() into
initializeLogging(),
collectTestFiles(),
initializeGeneratorContext(), and
loadAndValidateDocument()

Refactoring was AI Assisted: Claude 4.6 Opus
Verfied Render test run and log contents are consistent except for timestamps.

genglsl_render_log_BEFORE.txt
genglsl_render_profiling_log_BEFORE.txt

genglsl_render_log.txt
genglsl_render_profiling_log.txt

Break up the monolithic validate() into
 initializeLogging(),
 collectTestFiles(),
 initializeGeneratorContext(), and
 loadAndValidateDocument()

Refactoring was AI Assisted: Claude 4.6 Opus
Verfied Render test run and log contents are consistent except for timestamps.
@ashwinbhat ashwinbhat self-assigned this Mar 13, 2026
@ashwinbhat ashwinbhat requested a review from kwokcb March 13, 2026 22:20
@ashwinbhat ashwinbhat marked this pull request as ready for review March 14, 2026 00:55
@ashwinbhat
Copy link
Contributor Author

@jstone-lucasfilm @bernardkwok @ppenenko The ShaderRenderTester::validate was getting too long. Refactoring it for ease of read.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors ShaderRenderTester::validate() in the MaterialX render test utilities into smaller helper methods to improve readability and separation of concerns, while keeping test behavior/logging consistent.

Changes:

  • Extracted logging setup into initializeLogging() and introduced LogStreams to manage file-backed streams.
  • Extracted test discovery into collectTestFiles() and per-document work into loadAndValidateDocument() with a DocumentInfo return struct.
  • Extracted generator/context initialization into initializeGeneratorContext().

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
source/MaterialXTest/MaterialXRender/RenderUtil.h Adds LogStreams / DocumentInfo structs and declares new helper methods used to break up validate().
source/MaterialXTest/MaterialXRender/RenderUtil.cpp Implements the new helper methods and rewires validate() to use them.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

ashwinbhat and others added 2 commits March 17, 2026 10:06
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Ashwin Bhat <1727158+ashwinbhat@users.noreply.github.com>
Copy link
Member

@jstone-lucasfilm jstone-lucasfilm left a comment

Choose a reason for hiding this comment

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

Thanks for putting this proposal together, @ashwinbhat, and I've written up two initial thoughts.

std::unique_ptr<std::ofstream> docValidLogFile;
std::unique_ptr<std::ofstream> profilingLogFile;

std::ostream& log;
Copy link
Member

Choose a reason for hiding this comment

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

This seems like a very unusual pattern, where we're storing both unique pointers and direct references to the same objects.

Would it perhaps be better to provide accessors to these unique pointers, rather than storing them a second time?

RenderProfileTimes& profileTimes);

// Load a single .mtlx document, validate it, and find its renderable elements.
DocumentInfo loadAndValidateDocument(const mx::FilePath& filename,
Copy link
Member

Choose a reason for hiding this comment

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

Although I like the idea of making each of these steps separable and focused, I feel that a helper method taking nine arguments is reducing the clarity of the separation, since it's so tightly coupled to the original monolithic design.

Could this perhaps be refactored further, either using a clearer split of the new helper methods, or context objects that wrap associated state variables in an intuitive way?

Copy link
Contributor

Choose a reason for hiding this comment

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

Bit hard to follow all the changes, but I think it would be easier to store state on the class instance vs passing arguments around. It would also help to isolate the new perfecto code as utility methods.

Something like: instance::startLogging(), logResult(), endLogging(), startPerf(), logPerf(), endPerf(). You could make it scoped to avoid missing closing "ends".

@kwokcb
Copy link
Contributor

kwokcb commented Mar 18, 2026

I noticed "AI gen" code tends to remove comments in code. Would be good to set a rule to prioritize not do so, and restore any ones removed currently.

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