-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtestOutlineManager.cpp
More file actions
2070 lines (1699 loc) · 88.8 KB
/
Copy pathtestOutlineManager.cpp
File metadata and controls
2070 lines (1699 loc) · 88.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2026 Autodesk, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#define _SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING
#ifdef __APPLE__
#include "TargetConditionals.h"
#endif
#include <RenderingFramework/TestContextCreator.h>
#include <RenderingFramework/TestFlags.h>
#include <hvt/engine/framePass.h>
#include <hvt/engine/taskManager.h>
#include <hvt/engine/viewportEngine.h>
#include <hvt/tasks/outline/outlineManager.h>
#include <hvt/tasks/outline/outlineMaskTask.h>
#include <hvt/tasks/outline/outlineOverlayTask.h>
#include <hvt/tasks/outline/outlinePrimIdsTask.h>
#include <pxr/base/gf/frustum.h>
#include <pxr/base/gf/matrix4d.h>
#include <pxr/base/gf/vec4f.h>
#include <pxr/base/tf/errorMark.h>
#include <pxr/base/vt/value.h>
#include <pxr/imaging/hd/retainedSceneIndex.h>
#include <pxr/imaging/hd/tokens.h>
#include <pxr/imaging/hdx/tokens.h>
#include <pxr/pxr.h>
#include <pxr/usd/sdf/path.h>
#include <pxr/usd/usdGeom/cube.h>
#include <pxr/usd/usdGeom/sphere.h>
#include <pxr/usd/usdGeom/xformCommonAPI.h>
#include <gtest/gtest.h>
#include <algorithm>
PXR_NAMESPACE_USING_DIRECTIVE
namespace
{
// Raw token strings for the five outline tasks. Used by parameter-propagation
// tests that look up tasks by name in the TaskManager directly.
TF_DEFINE_PRIVATE_TOKENS(
_tokens,
((outlineBasePrimIdsTask, "outlineBasePrimIdsTask"))
((outlineOverlayPrimIdsTask, "outlineOverlayPrimIdsTask"))
((outlineDefaultPrimIdsTask, "outlineDefaultPrimIdsTask"))
((outlineMaskTask, "outlineMaskTask"))
((outlineOverlayTask, "outlineOverlayTask"))
);
// Minimal fixture: a FramePass without a scene index.
// Sufficient for install, cache, and style-dedup tests.
struct OutlineFixture
{
std::shared_ptr<TestHelpers::TestContext> testContext;
hvt::RenderIndexProxyPtr renderIndexProxy;
hvt::FramePassPtr framePass;
OutlineFixture()
{
testContext = TestHelpers::CreateTestContext();
hvt::RendererDescriptor rendererDesc;
rendererDesc.hgiDriver = &testContext->_backend->hgiDriver();
rendererDesc.rendererName = "HdStormRendererPlugin";
hvt::ViewportEngine::CreateRenderer(renderIndexProxy, rendererDesc);
hvt::FramePassDescriptor passDesc;
passDesc.renderIndex = renderIndexProxy->RenderIndex();
passDesc.uid = SdfPath("/TestOutlineManager");
framePass = hvt::ViewportEngine::CreateFramePass(passDesc);
}
};
// Fixture with a retained scene index wired into the render index.
// Required by parameter-propagation tests that call CommitTaskValues() to
// read back committed hvt::Outline::OutlineMaskTaskParams or OutlinePrimIdsTaskParams.
struct OutlineSceneFixture
{
std::shared_ptr<TestHelpers::TestContext> testContext;
hvt::RenderIndexProxyPtr renderIndexProxy;
hvt::FramePassPtr framePass;
OutlineSceneFixture()
{
testContext = TestHelpers::CreateTestContext();
hvt::RendererDescriptor rendererDesc;
rendererDesc.hgiDriver = &testContext->_backend->hgiDriver();
rendererDesc.rendererName = "HdStormRendererPlugin";
hvt::ViewportEngine::CreateRenderer(renderIndexProxy, rendererDesc);
HdRetainedSceneIndexRefPtr retainedSceneIndex = HdRetainedSceneIndex::New();
renderIndexProxy->RenderIndex()->InsertSceneIndex(
retainedSceneIndex, SdfPath::AbsoluteRootPath());
hvt::FramePassDescriptor passDesc;
passDesc.renderIndex = renderIndexProxy->RenderIndex();
passDesc.uid = SdfPath("/TestOutlineScene");
framePass = hvt::ViewportEngine::CreateFramePass(passDesc);
}
};
// Helper: reads back the committed hvt::Outline::OutlineMaskTaskParams from a TaskManager.
hvt::Outline::OutlineMaskTaskParams _GetMaskParams(hvt::TaskManager& taskManager)
{
SdfPath const maskPath = taskManager.GetTaskPath(_tokens->outlineMaskTask);
VtValue const value = taskManager.GetTaskValue(maskPath, HdTokens->params);
return value.Get<hvt::Outline::OutlineMaskTaskParams>();
}
// Helper: reads back the committed hvt::Outline::OutlinePrimIdsTaskParams for a named
// prim-IDs task (Base / Overlay / Default) from a TaskManager.
hvt::Outline::OutlinePrimIdsTaskParams _GetPrimIdsParams(
hvt::TaskManager& taskManager, TfToken const& token)
{
SdfPath const path = taskManager.GetTaskPath(token);
VtValue const value = taskManager.GetTaskValue(path, HdTokens->params);
return value.Get<hvt::Outline::OutlinePrimIdsTaskParams>();
}
// Helper: reads back the hvt::Outline::OutlineOverlayTaskParams from a TaskManager.
hvt::Outline::OutlineOverlayTaskParams _GetOverlayParams(hvt::TaskManager& taskManager)
{
SdfPath const path = taskManager.GetTaskPath(_tokens->outlineOverlayTask);
VtValue const value = taskManager.GetTaskValue(path, HdTokens->params);
return value.Get<hvt::Outline::OutlineOverlayTaskParams>();
}
// Helper: commits the task values and reads back the Base collection roots, sorted so the
// comparison is order-independent.
SdfPathVector _GetSortedBaseRoots(hvt::FramePass& framePass)
{
framePass.GetTaskManager()->CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
SdfPathVector roots =
_GetPrimIdsParams(*framePass.GetTaskManager(), _tokens->outlineBasePrimIdsTask)
.collection.GetRootPaths();
std::sort(roots.begin(), roots.end());
return roots;
}
} // namespace
// =====================================================================
// OutlineStyle -- equality and default value tests
// (no GPU required)
// =====================================================================
/// Test: Verifies OutlineStyle equality detects differences in each field.
HVT_TEST(TestOutlineManager, outline_styleEquality)
{
hvt::Outline::OutlineStyle a;
hvt::Outline::OutlineStyle b;
ASSERT_EQ(a, b);
ASSERT_FALSE(a != b);
b.selectedColor = GfVec4f(1.0f, 0.0f, 0.0f, 1.0f);
ASSERT_NE(a, b);
b = {};
b.selectionLeadColor = GfVec4f(0.0f, 1.0f, 0.0f, 1.0f);
ASSERT_NE(a, b);
b = {};
b.overlayColor = GfVec4f(0.0f, 0.0f, 1.0f, 0.5f);
ASSERT_NE(a, b);
b = {};
b.enableDefaultOutlines = true;
ASSERT_NE(a, b);
b = {};
b.softnessStrength = 0.5f;
ASSERT_NE(a, b);
b = {};
b.softnessFalloff = 0.8f;
ASSERT_NE(a, b);
b = {};
b.blurMode = hvt::Outline::BlurMode::Blur5x5;
ASSERT_NE(a, b);
b = {};
b.blurMode = hvt::Outline::BlurMode::None;
ASSERT_NE(a, b);
b = {};
b.blurIntensity = 2.0f;
ASSERT_NE(a, b);
b = {};
b.maskVisualizationMode = hvt::Outline::VisualizationMode::VISUALIZE_DEPTH;
ASSERT_NE(a, b);
}
/// Test: Verifies default OutlineStyle field values match the documented defaults.
HVT_TEST(TestOutlineManager, outline_styleDefaultValues)
{
hvt::Outline::OutlineStyle style;
ASSERT_EQ(style.selectedColor, GfVec4f(1.0f, 1.0f, 1.0f, 1.0f));
ASSERT_EQ(style.selectedHoverColor, GfVec4f(1.0f, 0.84f, 0.0f, 1.0f));
ASSERT_EQ(style.selectionLeadColor, GfVec4f(0.0f, 0.8f, 1.0f, 1.0f));
ASSERT_EQ(style.selectionLeadHoverColor, GfVec4f(1.0f, 0.84f, 0.0f, 1.0f));
ASSERT_EQ(style.overlayColor, GfVec4f(1.0f, 1.0f, 1.0f, 0.7f));
ASSERT_EQ(style.overlayHoverColor, GfVec4f(1.0f, 0.84f, 0.0f, 1.0f));
ASSERT_EQ(style.unselectedHoverColor, GfVec4f(1.0f, 0.84f, 0.0f, 1.0f));
ASSERT_EQ(style.defaultColor, GfVec4f(0.5f, 0.5f, 0.5f, 1.0f));
ASSERT_FALSE(style.enableDefaultOutlines);
ASSERT_FLOAT_EQ(style.softnessStrength, 1.0f);
ASSERT_FLOAT_EQ(style.softnessFalloff, 0.4f);
ASSERT_EQ(style.blurMode, hvt::Outline::BlurMode::Blur3x3);
ASSERT_FLOAT_EQ(style.blurIntensity, 1.0f);
ASSERT_EQ(style.maskVisualizationMode, hvt::Outline::VisualizationMode::VISUALIZE_MASK_3x3);
}
// =====================================================================
// Outline::Install -- task lifecycle tests
// (requires GPU via TestContext and FramePass)
// =====================================================================
/// Test: Verifies Install() registers all five outline tasks in the frame pass.
HVT_TEST(TestOutlineManager, outline_install)
{
OutlineFixture f;
hvt::Outline::OutlineManager outline;
auto& taskManager = f.framePass->GetTaskManager();
ASSERT_FALSE(taskManager->HasTask(hvt::Outline::OutlinePrimIdsTask ::GetToken("Base")));
ASSERT_FALSE(taskManager->HasTask(hvt::Outline::OutlinePrimIdsTask ::GetToken("Overlay")));
ASSERT_FALSE(taskManager->HasTask(hvt::Outline::OutlinePrimIdsTask ::GetToken("Default")));
ASSERT_FALSE(taskManager->HasTask(hvt::Outline::OutlineMaskTask::GetToken()));
ASSERT_FALSE(taskManager->HasTask(hvt::Outline::OutlineOverlayTask::GetToken()));
outline.Install(*f.framePass);
ASSERT_TRUE(taskManager->HasTask(hvt::Outline::OutlinePrimIdsTask ::GetToken("Base")));
ASSERT_TRUE(taskManager->HasTask(hvt::Outline::OutlinePrimIdsTask ::GetToken("Overlay")));
ASSERT_TRUE(taskManager->HasTask(hvt::Outline::OutlinePrimIdsTask ::GetToken("Default")));
ASSERT_TRUE(taskManager->HasTask(hvt::Outline::OutlineMaskTask::GetToken()));
ASSERT_TRUE(taskManager->HasTask(hvt::Outline::OutlineOverlayTask::GetToken()));
}
/// Test: Verifies that calling Install() a second time is silently ignored
/// and does not duplicate tasks in the frame pass.
HVT_TEST(TestOutlineManager, outline_installTwiceIsNoop)
{
OutlineFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
outline.Install(*f.framePass); // second call emits TF_WARN and returns early
auto& taskManager = f.framePass->GetTaskManager();
ASSERT_TRUE(taskManager->HasTask(hvt::Outline::OutlinePrimIdsTask ::GetToken("Base")));
ASSERT_TRUE(taskManager->HasTask(hvt::Outline::OutlinePrimIdsTask ::GetToken("Overlay")));
ASSERT_TRUE(taskManager->HasTask(hvt::Outline::OutlinePrimIdsTask ::GetToken("Default")));
ASSERT_TRUE(taskManager->HasTask(hvt::Outline::OutlineMaskTask::GetToken()));
ASSERT_TRUE(taskManager->HasTask(hvt::Outline::OutlineOverlayTask::GetToken()));
}
/// Test: Verifies that a second OutlineManager installing into a pass that already has outline
/// tasks is refused and leaves the pass untouched. The task names carry no per-instance suffix, so
/// an accepted second install would fail every AddTask yet still record itself as installed, and
/// its SetInputs() / SetStyle() would silently go nowhere.
HVT_TEST(TestOutlineManager, outline_installSecondManagerOnSamePassIsRefused)
{
OutlineSceneFixture f;
auto& taskManager = *f.framePass->GetTaskManager();
hvt::Outline::OutlineManager first;
first.Install(*f.framePass);
{
hvt::Outline::OutlineManager second;
// Install() must refuse before reaching AddTask, which would post a TF_CODING_ERROR per
// task. The harness only prints those, so assert on the error list instead: the mark is
// clean only if nothing was posted while it was in scope.
TfErrorMark mark;
second.Install(*f.framePass); // emits TF_WARN and returns early
EXPECT_TRUE(mark.IsClean());
mark.Clear(); // on failure, keep the errors from surfacing again at teardown
hvt::Outline::OutlineInputs ignored;
ignored.overlayPaths = { SdfPath("/Root/Other") };
second.SetInputs(ignored);
}
EXPECT_TRUE(taskManager.HasTask(hvt::Outline::OutlineMaskTask::GetToken()));
// Only the first manager's inputs reach the tasks.
hvt::Outline::OutlineInputs inputs;
inputs.overlayPaths = { SdfPath("/Root/Cube") };
first.SetInputs(inputs);
taskManager.CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
EXPECT_EQ(_GetMaskParams(taskManager).overlayPaths, inputs.overlayPaths);
}
/// Test: Verifies that all three prim-IDs tasks execute before the mask task,
/// and the mask task executes before the overlay task.
HVT_TEST(TestOutlineManager, outline_taskOrderPrimIdsBeforeMaskBeforeOverlay)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
auto& taskManager = f.framePass->GetTaskManager();
outline.Install(*f.framePass);
SdfPath const basePath = taskManager->GetTaskPath(_tokens->outlineBasePrimIdsTask);
SdfPath const overlayPrimIdsPath = taskManager->GetTaskPath(_tokens->outlineOverlayPrimIdsTask);
SdfPath const defaultPath = taskManager->GetTaskPath(_tokens->outlineDefaultPrimIdsTask);
SdfPath const maskPath = taskManager->GetTaskPath(_tokens->outlineMaskTask);
SdfPath const overlayPath = taskManager->GetTaskPath(_tokens->outlineOverlayTask);
SdfPathVector taskPaths;
taskManager->GetTaskPaths(hvt::TaskFlagsBits::kExecutableBit, false, taskPaths);
auto indexOf = [&taskPaths](SdfPath const& path) {
auto it = std::find(taskPaths.begin(), taskPaths.end(), path);
EXPECT_NE(it, taskPaths.end());
return static_cast<size_t>(std::distance(taskPaths.begin(), it));
};
size_t const baseIdx = indexOf(basePath);
size_t const overlayPrimIdsIdx = indexOf(overlayPrimIdsPath);
size_t const defaultIdx = indexOf(defaultPath);
size_t const maskIdx = indexOf(maskPath);
size_t const overlayIdx = indexOf(overlayPath);
EXPECT_LT(baseIdx, maskIdx);
EXPECT_LT(overlayPrimIdsIdx, maskIdx);
EXPECT_LT(defaultIdx, maskIdx);
EXPECT_LT(maskIdx, overlayIdx);
}
// =====================================================================
// Outline::SetInputs -- cache behavior tests
// (no GPU required; SetInputs() / GetCacheStats() work standalone)
// =====================================================================
/// Test: Verifies that calling SetInputs() with all-empty inputs (identical
/// to the default-constructed state) counts as a cache hit.
HVT_TEST(TestOutlineManager, outline_cacheFirstEmptyCallIsHit)
{
hvt::Outline::OutlineManager outline;
outline.SetInputs(hvt::Outline::OutlineInputs{}); // same as default state -> hit
auto stats = outline.GetCacheStats();
ASSERT_EQ(stats.totalQueries, 1u);
ASSERT_EQ(stats.hits, 1u);
ASSERT_EQ(stats.misses, 0u);
}
/// Test: Verifies that calling SetInputs() with non-empty paths counts
/// as a cache miss (changed from default empty state).
HVT_TEST(TestOutlineManager, outline_cacheFirstNonEmptyCallIsMiss)
{
hvt::Outline::OutlineManager outline;
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/world/cube") };
outline.SetInputs(inputs);
auto stats = outline.GetCacheStats();
ASSERT_EQ(stats.totalQueries, 1u);
ASSERT_EQ(stats.hits, 0u);
ASSERT_EQ(stats.misses, 1u);
}
/// Test: Verifies that calling SetInputs() twice with identical inputs
/// counts the second call as a cache hit.
HVT_TEST(TestOutlineManager, outline_cacheHitOnIdenticalInputs)
{
hvt::Outline::OutlineManager outline;
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/world/cube") };
outline.SetInputs(inputs); // miss
outline.SetInputs(inputs); // hit -- inputs unchanged
auto stats = outline.GetCacheStats();
ASSERT_EQ(stats.totalQueries, 2u);
ASSERT_EQ(stats.hits, 1u);
ASSERT_EQ(stats.misses, 1u);
}
/// Test: Verifies that changing any input field triggers a cache miss.
HVT_TEST(TestOutlineManager, outline_cacheMissOnChangedInputs)
{
hvt::Outline::OutlineManager outline;
hvt::Outline::OutlineInputs a;
a.selectedPaths = { SdfPath("/world/cube") };
hvt::Outline::OutlineInputs b;
b.selectedPaths = { SdfPath("/world/sphere") };
outline.SetInputs(a); // miss
outline.SetInputs(b); // miss -- selectedPaths changed
auto stats = outline.GetCacheStats();
ASSERT_EQ(stats.totalQueries, 2u);
ASSERT_EQ(stats.hits, 0u);
ASSERT_EQ(stats.misses, 2u);
}
/// Test: Verifies that cache statistics accumulate correctly across
/// a sequence of hit and miss calls.
HVT_TEST(TestOutlineManager, outline_cacheStatsAccumulate)
{
hvt::Outline::OutlineManager outline;
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/world/cube") };
outline.SetInputs(inputs); // miss
outline.SetInputs(inputs); // hit
outline.SetInputs(inputs); // hit
inputs.leadPath = SdfPath("/world/cube");
outline.SetInputs(inputs); // miss -- leadPath changed
outline.SetInputs(inputs); // hit
auto stats = outline.GetCacheStats();
ASSERT_EQ(stats.totalQueries, 5u);
ASSERT_EQ(stats.hits, 3u);
ASSERT_EQ(stats.misses, 2u);
}
/// Test: Verifies that maxInputPathCount tracks the largest number of
/// paths seen across all SetInputs() calls.
HVT_TEST(TestOutlineManager, outline_cacheMaxCollectionSize)
{
hvt::Outline::OutlineManager outline;
hvt::Outline::OutlineInputs smallInputs;
smallInputs.selectedPaths = { SdfPath("/a") };
outline.SetInputs(smallInputs); // miss, size=1
hvt::Outline::OutlineInputs largeInputs;
largeInputs.selectedPaths = { SdfPath("/b"), SdfPath("/c"), SdfPath("/d") };
outline.SetInputs(largeInputs); // miss, size=3
hvt::Outline::OutlineInputs mediumInputs;
mediumInputs.selectedPaths = { SdfPath("/e"), SdfPath("/f") };
outline.SetInputs(mediumInputs); // miss, size=2
auto stats = outline.GetCacheStats();
ASSERT_EQ(stats.maxInputPathCount, 3u);
}
/// Test: Verifies that changing overlayPaths, excludePaths, or isHoverSelected each
/// independently triggers a cache miss. Complements outline_cacheMissOnChangedInputs
/// (selectedPaths) and outline_cacheStatsAccumulate (leadPath) so every field the
/// SetInputs() dedup compares is exercised.
HVT_TEST(TestOutlineManager, outline_cacheMissOnEachRemainingField)
{
hvt::Outline::OutlineManager outline;
hvt::Outline::OutlineInputs inputs;
outline.SetInputs(inputs); // identical to default state -> hit
inputs.overlayPaths = { SdfPath("/Root/Gizmo") };
outline.SetInputs(inputs); // miss -- overlayPaths changed
inputs.excludePaths = { SdfPath("/Root/Transient") };
outline.SetInputs(inputs); // miss -- excludePaths changed
inputs.isHoverSelected = true;
outline.SetInputs(inputs); // miss -- isHoverSelected changed
auto stats = outline.GetCacheStats();
ASSERT_EQ(stats.totalQueries, 4u);
ASSERT_EQ(stats.hits, 1u);
ASSERT_EQ(stats.misses, 3u);
}
/// Test: Verifies that changing selectedPaths and hoverPaths independently
/// each produce a cache miss, and that identical calls in between produce hits.
HVT_TEST(TestOutlineManager, outline_cacheSetInputsDedupWithHoverPaths)
{
OutlineFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/Root/Cube") };
outline.SetInputs(inputs);
hvt::Outline::OutlineManager::CacheStats afterFirst = outline.GetCacheStats();
ASSERT_EQ(afterFirst.totalQueries, 1u);
ASSERT_EQ(afterFirst.misses, 1u);
ASSERT_EQ(afterFirst.hits, 0u);
outline.SetInputs(inputs);
hvt::Outline::OutlineManager::CacheStats afterSecond = outline.GetCacheStats();
ASSERT_EQ(afterSecond.totalQueries, 2u);
ASSERT_EQ(afterSecond.misses, 1u);
ASSERT_EQ(afterSecond.hits, 1u);
inputs.hoverPaths = { SdfPath("/Root/Sphere") };
outline.SetInputs(inputs);
hvt::Outline::OutlineManager::CacheStats afterThird = outline.GetCacheStats();
ASSERT_EQ(afterThird.totalQueries, 3u);
ASSERT_EQ(afterThird.misses, 2u);
ASSERT_EQ(afterThird.hits, 1u);
}
// =====================================================================
// Outline::SetStyle -- dedup behavior tests
// (no GPU required)
// =====================================================================
/// Test: Exercises both branches of SetStyle()'s equality guard through the observable
/// commit->readback contract. A repeated identical SetStyle() (guard fires, early return)
/// must leave the committed style intact; a SetStyle() with a changed field (guard falls
/// through, re-assigns) must propagate. The dedup early-return is a CPU optimization with no
/// directly observable effect, so this guards the behavior it must preserve, not the branch.
HVT_TEST(TestOutlineManager, outline_setStyleDedup)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
auto& taskManager = *f.framePass->GetTaskManager();
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/Root/Cube") };
outline.SetInputs(inputs);
// Default style, applied twice. The second (identical) call hits the dedup early return;
// the committed params must still carry the default softness.
hvt::Outline::OutlineStyle style;
outline.SetStyle(style);
outline.SetStyle(style);
taskManager.CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
EXPECT_FLOAT_EQ(_GetMaskParams(taskManager).style.softnessStrength, 1.0f);
// Changed field -- guard falls through, re-assigns, propagates on commit.
hvt::Outline::OutlineStyle changed = style;
changed.softnessStrength = 0.5f;
outline.SetStyle(changed);
taskManager.CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
EXPECT_FLOAT_EQ(_GetMaskParams(taskManager).style.softnessStrength, 0.5f);
// Repeat the changed style (dedup again) -- committed value stays 0.5.
outline.SetStyle(changed);
taskManager.CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
EXPECT_FLOAT_EQ(_GetMaskParams(taskManager).style.softnessStrength, 0.5f);
}
// =====================================================================
// Outline internals -- task ordering and parameter propagation
// (requires FramePass with scene index; no full GPU render)
// =====================================================================
/// Test: Verifies that when enableDefaultOutlines is false, the mask task's
/// default texture inputs fall back to the base prim-IDs textures rather than
/// the separate default-pass textures. OutlineMaskTask::Execute() derives
/// hasDistinctDefault from these names, so they are the committed contract.
HVT_TEST(TestOutlineManager, outline_maskTextureFallbackWhenDefaultDisabled)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
hvt::Outline::OutlineStyle style;
style.enableDefaultOutlines = false;
outline.SetStyle(style);
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/Root/Cube") };
outline.SetInputs(inputs);
f.framePass->GetTaskManager()->CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
hvt::Outline::OutlineMaskTaskParams maskParams = _GetMaskParams(*f.framePass->GetTaskManager());
EXPECT_EQ(maskParams.defaultPrimIdsTexture, "outlineBasePrimIdsTexture");
EXPECT_EQ(maskParams.defaultDepthTexture, "outlineBaseDepthTexture");
EXPECT_EQ(maskParams.defaultPrimIdsTexture, maskParams.basePrimIdsTexture);
EXPECT_EQ(maskParams.defaultDepthTexture, maskParams.baseDepthTexture);
}
/// Test: Verifies that when overlayPaths is empty, the mask task's overlay
/// texture inputs fall back to the base prim-IDs textures. That aliasing is what makes
/// OutlineMaskTask::Execute() clear hasDistinctOverlay, so the shader skips the overlay lookup.
HVT_TEST(TestOutlineManager, outline_maskTextureFallbackWhenOverlayEmpty)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/Root/Cube") };
outline.SetInputs(inputs); // no overlayPaths set
f.framePass->GetTaskManager()->CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
hvt::Outline::OutlineMaskTaskParams maskParams = _GetMaskParams(*f.framePass->GetTaskManager());
EXPECT_EQ(maskParams.overlayPrimIdsTexture, "outlineBasePrimIdsTexture");
EXPECT_EQ(maskParams.overlayDepthTexture, "outlineBaseDepthTexture");
EXPECT_EQ(maskParams.overlayPrimIdsTexture, maskParams.basePrimIdsTexture);
EXPECT_EQ(maskParams.overlayDepthTexture, maskParams.baseDepthTexture);
}
/// Test: Verifies that excludePaths are applied only to the Default prim-IDs
/// collection and do not affect the selected or overlay buckets.
HVT_TEST(TestOutlineManager, outline_excludePathsAppliedToDefaultCollection)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
hvt::Outline::OutlineStyle style;
style.enableDefaultOutlines = true;
outline.SetStyle(style);
hvt::Outline::OutlineInputs inputs;
inputs.excludePaths = { SdfPath("/Root/Transient") };
outline.SetInputs(inputs);
f.framePass->GetTaskManager()->CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
SdfPath const defaultPath = f.framePass->GetTaskManager()->GetTaskPath(
_tokens->outlineDefaultPrimIdsTask);
VtValue const value = f.framePass->GetTaskManager()->GetTaskValue(
defaultPath, HdTokens->params);
hvt::Outline::OutlinePrimIdsTaskParams primIdsParams =
value.Get<hvt::Outline::OutlinePrimIdsTaskParams>();
EXPECT_TRUE(primIdsParams.enabled);
EXPECT_EQ(primIdsParams.collection.GetExcludePaths(),
SdfPathVector{ SdfPath("/Root/Transient") });
}
/// Test: The positive complement of the two fallback tests above. When overlayPaths is
/// non-empty AND enableDefaultOutlines is true, the mask task must reference the dedicated
/// overlay and default textures rather than the base aliases, which is what makes
/// OutlineMaskTask::Execute() set hasDistinctOverlay / hasDistinctDefault for both lookups.
HVT_TEST(TestOutlineManager, outline_maskTextureDistinctWhenOverlayAndDefaultPresent)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
hvt::Outline::OutlineStyle style;
style.enableDefaultOutlines = true;
outline.SetStyle(style);
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/Root/Cube") };
inputs.overlayPaths = { SdfPath("/Root/Gizmo") };
outline.SetInputs(inputs);
f.framePass->GetTaskManager()->CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
hvt::Outline::OutlineMaskTaskParams maskParams = _GetMaskParams(*f.framePass->GetTaskManager());
EXPECT_EQ(maskParams.overlayPrimIdsTexture, "outlineOverlayPrimIdsTexture");
EXPECT_EQ(maskParams.overlayDepthTexture, "outlineOverlayDepthTexture");
EXPECT_NE(maskParams.overlayPrimIdsTexture, maskParams.basePrimIdsTexture);
EXPECT_NE(maskParams.overlayDepthTexture, maskParams.baseDepthTexture);
EXPECT_EQ(maskParams.defaultPrimIdsTexture, "outlineDefaultPrimIdsTexture");
EXPECT_EQ(maskParams.defaultDepthTexture, "outlineDefaultDepthTexture");
EXPECT_NE(maskParams.defaultPrimIdsTexture, maskParams.basePrimIdsTexture);
EXPECT_NE(maskParams.defaultDepthTexture, maskParams.baseDepthTexture);
}
/// Test: Verifies that every OutlineStyle field SetStyle() owns propagates into the
/// committed mask task parameters (colors, softness, visualization mode). SetStyle() is
/// the manager's sole path for theme changes, so a dropped field is a silent regression.
HVT_TEST(TestOutlineManager, outline_stylePropagatesToMaskParams)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
hvt::Outline::OutlineStyle style;
style.selectedColor = GfVec4f(0.10f, 0.20f, 0.30f, 0.40f);
style.selectedHoverColor = GfVec4f(0.50f, 0.60f, 0.70f, 0.80f);
style.selectionLeadColor = GfVec4f(0.11f, 0.22f, 0.33f, 0.44f);
style.selectionLeadHoverColor = GfVec4f(0.90f, 0.80f, 0.70f, 0.60f);
style.overlayColor = GfVec4f(0.15f, 0.25f, 0.35f, 0.45f);
style.overlayHoverColor = GfVec4f(0.55f, 0.65f, 0.75f, 0.85f);
style.unselectedHoverColor = GfVec4f(0.12f, 0.13f, 0.14f, 0.15f);
style.defaultColor = GfVec4f(0.21f, 0.22f, 0.23f, 0.24f);
style.softnessStrength = 0.33f;
style.softnessFalloff = 0.66f;
style.maskVisualizationMode = hvt::Outline::VisualizationMode::VISUALIZE_PRIM_IDS;
outline.SetStyle(style);
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/Root/Cube") };
outline.SetInputs(inputs);
f.framePass->GetTaskManager()->CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
hvt::Outline::OutlineMaskTaskParams maskParams = _GetMaskParams(*f.framePass->GetTaskManager());
EXPECT_EQ(maskParams.style.selectedColor, style.selectedColor);
EXPECT_EQ(maskParams.style.selectedHoverColor, style.selectedHoverColor);
EXPECT_EQ(maskParams.style.selectionLeadColor, style.selectionLeadColor);
EXPECT_EQ(maskParams.style.selectionLeadHoverColor, style.selectionLeadHoverColor);
EXPECT_EQ(maskParams.style.overlayColor, style.overlayColor);
EXPECT_EQ(maskParams.style.overlayHoverColor, style.overlayHoverColor);
EXPECT_EQ(maskParams.style.unselectedHoverColor, style.unselectedHoverColor);
EXPECT_EQ(maskParams.style.defaultColor, style.defaultColor);
EXPECT_FLOAT_EQ(maskParams.style.softnessStrength, style.softnessStrength);
EXPECT_FLOAT_EQ(maskParams.style.softnessFalloff, style.softnessFalloff);
EXPECT_EQ(maskParams.maskVisualizationMode, style.maskVisualizationMode);
}
/// Test: Verifies that the SetInputs() path buckets and the isHoverSelected flag pass
/// through to the mask task parameters. The lead / hover / overlay ID counts are NOT
/// asserted here: the manager leaves them for OutlineMaskTask::_Sync() to resolve from the
/// render index (a path expands to a subtree of prim IDs), so they are only meaningful after
/// a render, not after a bare CommitTaskValues(). End-to-end count behavior is covered by the
/// render baseline tests and by the task's own tests in testOutlineTasks.cpp.
HVT_TEST(TestOutlineManager, outline_inputsPropagateToMaskParams)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/Root/Cube"), SdfPath("/Root/Sphere") };
inputs.leadPath = SdfPath("/Root/Cube");
inputs.hoverPaths = { SdfPath("/Root/Sphere") };
inputs.overlayPaths = { SdfPath("/Root/Gizmo"), SdfPath("/Root/Grid") };
inputs.isHoverSelected = true;
outline.SetInputs(inputs);
f.framePass->GetTaskManager()->CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
hvt::Outline::OutlineMaskTaskParams maskParams = _GetMaskParams(*f.framePass->GetTaskManager());
EXPECT_EQ(maskParams.leadPath, inputs.leadPath);
EXPECT_EQ(maskParams.hoverPaths, inputs.hoverPaths);
EXPECT_EQ(maskParams.overlayPaths, inputs.overlayPaths);
EXPECT_EQ(maskParams.style.isHoverSelected, 1);
}
/// Test: Verifies that the Base prim-IDs collection is built from the union of
/// selectedPaths and hoverPaths. leadPath is intentionally NOT added to the roots
/// (it only recolors prim IDs already rasterized there) -- see OutlineManager.cpp.
HVT_TEST(TestOutlineManager, outline_baseCollectionUnionsSelectedAndHover)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/Root/Cube") };
inputs.hoverPaths = { SdfPath("/Root/Sphere") };
outline.SetInputs(inputs);
f.framePass->GetTaskManager()->CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
hvt::Outline::OutlinePrimIdsTaskParams baseParams =
_GetPrimIdsParams(*f.framePass->GetTaskManager(), _tokens->outlineBasePrimIdsTask);
EXPECT_TRUE(baseParams.enabled);
SdfPathVector roots = baseParams.collection.GetRootPaths();
std::sort(roots.begin(), roots.end());
SdfPathVector expected = { SdfPath("/Root/Cube"), SdfPath("/Root/Sphere") };
std::sort(expected.begin(), expected.end());
EXPECT_EQ(roots, expected);
}
/// Test: A hovered path that is already selected (the isHoverSelected state) appears in both
/// buckets but collapses to a single Base collection root, so the roots vector stays stable.
HVT_TEST(TestOutlineManager, outline_baseCollectionPrunesDuplicateHoverRoot)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/Root/Cube") };
inputs.hoverPaths = { SdfPath("/Root/Cube") }; // same path in both buckets
inputs.isHoverSelected = true;
outline.SetInputs(inputs);
EXPECT_EQ(_GetSortedBaseRoots(*f.framePass), SdfPathVector { SdfPath("/Root/Cube") });
}
/// Test: A hovered path nested under a selected root is pruned from the Base collection roots --
/// the selected ancestor already selects that subtree, so hovering within a selection leaves the
/// roots vector unchanged rather than dirtying the collection.
HVT_TEST(TestOutlineManager, outline_baseCollectionPrunesNestedHoverRoot)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/Root/Cube") };
inputs.hoverPaths = { SdfPath("/Root/Cube/Child") }; // nested under the selected root
outline.SetInputs(inputs);
EXPECT_EQ(_GetSortedBaseRoots(*f.framePass), SdfPathVector { SdfPath("/Root/Cube") });
}
/// Test: Pruning is path-prefix aware, not string-prefix aware. "/Root/CubeExtra" shares a
/// string prefix with "/Root/Cube" but is a sibling, not a descendant, so both roots survive.
HVT_TEST(TestOutlineManager, outline_baseCollectionKeepsStringPrefixSiblingRoot)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/Root/Cube") };
inputs.hoverPaths = { SdfPath("/Root/CubeExtra") };
outline.SetInputs(inputs);
SdfPathVector expected = { SdfPath("/Root/Cube"), SdfPath("/Root/CubeExtra") };
std::sort(expected.begin(), expected.end());
EXPECT_EQ(_GetSortedBaseRoots(*f.framePass), expected);
}
/// Test: Verifies the per-bucket enabled logic. With only selectedPaths set and
/// enableDefaultOutlines disabled: Base is enabled (has selection), Overlay is
/// disabled (no overlayPaths), and Default is disabled (default outlines off).
HVT_TEST(TestOutlineManager, outline_perBucketEnabledFlags)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
hvt::Outline::OutlineStyle style;
style.enableDefaultOutlines = false;
outline.SetStyle(style);
hvt::Outline::OutlineInputs inputs;
inputs.selectedPaths = { SdfPath("/Root/Cube") };
outline.SetInputs(inputs);
f.framePass->GetTaskManager()->CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
auto& taskManager = *f.framePass->GetTaskManager();
EXPECT_TRUE(_GetPrimIdsParams(taskManager, _tokens->outlineBasePrimIdsTask).enabled);
EXPECT_FALSE(_GetPrimIdsParams(taskManager, _tokens->outlineOverlayPrimIdsTask).enabled);
EXPECT_FALSE(_GetPrimIdsParams(taskManager, _tokens->outlineDefaultPrimIdsTask).enabled);
}
/// Test: Exercises the per-task derived-collection cache (keyed on inputsGeneration in
/// OutlineManager.cpp). This cache is the one piece of the manager's caching that host-side
/// caching (dirty flags, cached selection state) does NOT subsume: the task commit callbacks
/// run on every frame regardless of how the host gates SetInputs(), and the cache stops each
/// commit from rebuilding the HdRprimCollection when the inputs are unchanged.
///
/// A "rebuild happened" event is an internal CPU detail and is not directly observable
/// through the public API (a rebuilt collection is value-equal to a reused one). What IS
/// observable -- and what this test guards -- is the contract the generation cache must
/// uphold: the committed Base collection stays stable across repeated commits with unchanged
/// inputs (the cache is reused, never going stale or empty) AND is rebuilt to reflect the
/// new paths once SetInputs() bumps the generation. The main regression this catches is a
/// cache that never invalidates: it would leave the stale collection in the final step.
HVT_TEST(TestOutlineManager, outline_collectionCacheStableAcrossCommitsAndInvalidatesOnChange)
{
OutlineSceneFixture f;
hvt::Outline::OutlineManager outline;
outline.Install(*f.framePass);
auto& taskManager = *f.framePass->GetTaskManager();
auto baseRoots = [&taskManager]() {
SdfPathVector roots = _GetPrimIdsParams(taskManager, _tokens->outlineBasePrimIdsTask)
.collection.GetRootPaths();
std::sort(roots.begin(), roots.end());
return roots;
};
// First (non-empty) inputs -> miss. Commit, then commit again without touching inputs:
// the second commit must reuse the cached collection and stay value-stable.
hvt::Outline::OutlineInputs first;
first.selectedPaths = { SdfPath("/Root/Cube") };
outline.SetInputs(first);
taskManager.CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
EXPECT_EQ(baseRoots(), SdfPathVector{ SdfPath("/Root/Cube") });
taskManager.CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
EXPECT_EQ(baseRoots(), SdfPathVector{ SdfPath("/Root/Cube") });
// A no-op SetInputs (identical) is a cache hit and must not disturb the committed roots.
outline.SetInputs(first);
taskManager.CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
EXPECT_EQ(baseRoots(), SdfPathVector{ SdfPath("/Root/Cube") });
// Changed inputs -> miss -> generation bump. The next commit MUST rebuild the collection
// so it reflects the new paths (proves the cache invalidates rather than going stale).
hvt::Outline::OutlineInputs second;
second.selectedPaths = { SdfPath("/Root/Sphere") };
outline.SetInputs(second);
taskManager.CommitTaskValues(hvt::TaskFlagsBits::kExecutableBit);
EXPECT_EQ(baseRoots(), SdfPathVector{ SdfPath("/Root/Sphere") });
// Sanity-check the stats reflect the exercised path: 3 queries, 1 hit (the repeat), 2 misses.
auto stats = outline.GetCacheStats();
EXPECT_EQ(stats.totalQueries, 3u);
EXPECT_EQ(stats.hits, 1u);
EXPECT_EQ(stats.misses, 2u);
}
// =====================================================================
// Outline::Install -- atPos / order anchor placement
// (the atPos + order parameters are otherwise never exercised)
// =====================================================================
/// Test: Verifies that when Install() is given an explicit anchor (atPos) with
/// insertBefore, the whole outline group lands before that anchor task while the
/// three tasks keep their fixed internal order (prim-IDs -> mask -> overlay).
HVT_TEST(TestOutlineManager, outline_installAnchorInsertBefore)
{
OutlineFixture f;
hvt::Outline::OutlineManager outline;
auto& taskManager = *f.framePass->GetTaskManager();
// colorCorrectionTask is one of the default frame-pass tasks; use it as anchor.
SdfPath const anchorPath = taskManager.GetTaskPath(HdxPrimitiveTokens->colorCorrectionTask);
ASSERT_FALSE(anchorPath.IsEmpty());
outline.Install(*f.framePass, anchorPath, hvt::TaskManager::InsertionOrder::insertBefore);
SdfPathVector taskPaths;
taskManager.GetTaskPaths(hvt::TaskFlagsBits::kExecutableBit, false, taskPaths);
auto indexOf = [&taskPaths](SdfPath const& path) {
auto it = std::find(taskPaths.begin(), taskPaths.end(), path);
EXPECT_NE(it, taskPaths.end());
return static_cast<size_t>(std::distance(taskPaths.begin(), it));
};
size_t const anchorIdx = indexOf(anchorPath);
size_t const baseIdx = indexOf(taskManager.GetTaskPath(_tokens->outlineBasePrimIdsTask));
size_t const overlayPIdx =
indexOf(taskManager.GetTaskPath(_tokens->outlineOverlayPrimIdsTask));
size_t const defaultIdx = indexOf(taskManager.GetTaskPath(_tokens->outlineDefaultPrimIdsTask));
size_t const maskIdx = indexOf(taskManager.GetTaskPath(_tokens->outlineMaskTask));
size_t const overlayIdx = indexOf(taskManager.GetTaskPath(_tokens->outlineOverlayTask));
// Whole group precedes the anchor.
EXPECT_LT(baseIdx, anchorIdx);
EXPECT_LT(overlayPIdx, anchorIdx);
EXPECT_LT(defaultIdx, anchorIdx);
EXPECT_LT(maskIdx, anchorIdx);
EXPECT_LT(overlayIdx, anchorIdx);
// Fixed internal order is preserved regardless of the anchor.
EXPECT_LT(baseIdx, maskIdx);
EXPECT_LT(overlayPIdx, maskIdx);
EXPECT_LT(defaultIdx, maskIdx);
EXPECT_LT(maskIdx, overlayIdx);
}
/// Test: Verifies that Install() with an anchor and insertAfter places the whole
/// outline group after that anchor task, internal order still preserved.
HVT_TEST(TestOutlineManager, outline_installAnchorInsertAfter)
{
OutlineFixture f;
hvt::Outline::OutlineManager outline;
auto& taskManager = *f.framePass->GetTaskManager();
SdfPath const anchorPath = taskManager.GetTaskPath(HdxPrimitiveTokens->colorCorrectionTask);
ASSERT_FALSE(anchorPath.IsEmpty());
outline.Install(*f.framePass, anchorPath, hvt::TaskManager::InsertionOrder::insertAfter);
SdfPathVector taskPaths;
taskManager.GetTaskPaths(hvt::TaskFlagsBits::kExecutableBit, false, taskPaths);