-
Notifications
You must be signed in to change notification settings - Fork 419
Refactor runRenderer to use structured types #2869
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
97cae93
1904ded
56aacf1
ad7a4af
1c17ae3
d5e0b55
ac55117
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,6 +53,19 @@ class LanguageProfileTimes | |
| output << "\tI/O: " << ioTime << " seconds" << std::endl; | ||
| output << "\tImage save: " << imageSaveTime << " seconds" << std::endl; | ||
| } | ||
|
|
||
| void accumulate(const LanguageProfileTimes& other) | ||
| { | ||
| totalTime += other.totalTime; | ||
| setupTime += other.setupTime; | ||
| transparencyTime += other.transparencyTime; | ||
| generationTime += other.generationTime; | ||
| compileTime += other.compileTime; | ||
| renderTime += other.renderTime; | ||
| ioTime += other.ioTime; | ||
| imageSaveTime += other.imageSaveTime; | ||
| } | ||
|
|
||
| double totalTime = 0.0; | ||
| double setupTime = 0.0; | ||
| double transparencyTime = 0.0; | ||
|
|
@@ -104,8 +117,6 @@ struct DocumentInfo | |
| class TestRunLogger | ||
| { | ||
| public: | ||
| ~TestRunLogger(); | ||
|
|
||
| void start(const std::string& target, const GenShaderUtil::TestSuiteOptions& options); | ||
|
|
||
| std::ostream& renderLog() { return _renderLog ? *_renderLog : std::cout; } | ||
|
|
@@ -124,7 +135,7 @@ class TestRunLogger | |
| class TestRunProfiler | ||
| { | ||
| public: | ||
| ~TestRunProfiler() { _totalTimer.reset(); } | ||
| ~TestRunProfiler() = default; | ||
|
|
||
| void start(); | ||
| void printSummary(const GenShaderUtil::TestSuiteOptions& options, | ||
|
|
@@ -161,6 +172,59 @@ struct TestRunState | |
| std::unique_ptr<mx::GenContext> context; | ||
| }; | ||
|
|
||
| // Read-only test configuration for the entire validate() run. | ||
| // Note: the log stream requires synchronization for concurrent use. | ||
| struct RenderSession | ||
| { | ||
| const GenShaderUtil::TestSuiteOptions& testOptions; | ||
| std::ostream& log; | ||
| }; | ||
|
|
||
| // Per-element data passed to each runRenderer call. | ||
| struct RenderItem | ||
| { | ||
| RenderItem(mx::TypedElementPtr elem, | ||
| mx::FileSearchPath searchPath, | ||
| mx::FilePath outPath, | ||
| mx::ImageVec* images = nullptr) | ||
| : element(std::move(elem)), | ||
| imageSearchPath(std::move(searchPath)), | ||
| outputPath(std::move(outPath)), | ||
| imageVec(images) {} | ||
|
|
||
| mx::TypedElementPtr element; | ||
| mx::FileSearchPath imageSearchPath; | ||
| mx::FilePath outputPath; | ||
| mx::ImageVec* imageVec = nullptr; | ||
|
|
||
| const std::string& shaderName() const | ||
| { | ||
| if (_cachedShaderName.empty()) | ||
| { | ||
| mx::StringMap pathMap; | ||
| pathMap["/"] = "_"; | ||
| pathMap[":"] = "_"; | ||
| _cachedShaderName = mx::createValidName( | ||
| mx::replaceSubstrings(element->getNamePath(), pathMap)); | ||
| } | ||
| return _cachedShaderName; | ||
| } | ||
|
||
|
|
||
| mx::DocumentPtr doc() const { return element->getDocument(); } | ||
|
|
||
| private: | ||
| mutable std::string _cachedShaderName; | ||
| }; | ||
|
|
||
| // Returned by runRenderer — each call produces its own isolated profiling data. | ||
| // The caller accumulates results, making future parallelism straightforward. | ||
| struct RenderProfileResult | ||
| { | ||
| LanguageProfileTimes languageTimes; | ||
| unsigned int elementsTested = 0; | ||
| bool success = true; | ||
| }; | ||
|
|
||
| // Base class used for performing compilation and render tests for a given | ||
| // shading language and target. | ||
| // | ||
|
|
@@ -209,17 +273,13 @@ class ShaderRenderTester | |
| // Create a renderer for the generated code | ||
| virtual void createRenderer(std::ostream& log) = 0; | ||
|
|
||
| // Run the renderer | ||
| virtual bool runRenderer(const std::string& shaderName, | ||
| mx::TypedElementPtr element, | ||
| mx::GenContext& context, | ||
| mx::DocumentPtr doc, | ||
| std::ostream& log, | ||
| const GenShaderUtil::TestSuiteOptions& testOptions, | ||
| RenderProfileTimes& profileTimes, | ||
| const mx::FileSearchPath& imageSearchPath, | ||
| const std::string& outputPath = ".", | ||
| mx::ImageVec* imageVec = nullptr) = 0; | ||
| // Run the renderer. | ||
| // GenContext is a separate argument because it is mutable (written per-element) | ||
| // and must be cloned per-thread for future parallel execution. | ||
| virtual RenderProfileResult runRenderer( | ||
| const RenderSession& session, | ||
| const RenderItem& item, | ||
| mx::GenContext& context) = 0; | ||
|
|
||
| // Save an image | ||
| virtual bool saveImage(const mx::FilePath&, mx::ConstImagePtr, bool) const { return 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.
runRenderernow returns aRenderProfileResultwith asuccessflag, butvalidate()ignores it and always returnstrueafter printing the summary. This makes the new success reporting ineffective and could hide failures ifCHECK/REQUIREbehavior changes or if this utility is reused outside Catch2. Consider propagatingresult.successinto an overallallSuccessand returningfalse(and/or skipping accumulation) when a renderer run fails, or remove thesuccessfield if it’s intentionally unused.