@@ -315,47 +315,27 @@ struct ContentContextOptions {
315
315
bool wireframe = false ;
316
316
bool is_for_rrect_blur_clear = false ;
317
317
318
- struct Hash {
319
- constexpr uint64_t operator ()(const ContentContextOptions& o) const {
320
- static_assert (sizeof (o.sample_count ) == 1 );
321
- static_assert (sizeof (o.blend_mode ) == 1 );
322
- static_assert (sizeof (o.sample_count ) == 1 );
323
- static_assert (sizeof (o.depth_compare ) == 1 );
324
- static_assert (sizeof (o.stencil_mode ) == 1 );
325
- static_assert (sizeof (o.primitive_type ) == 1 );
326
- static_assert (sizeof (o.color_attachment_pixel_format ) == 1 );
327
-
328
- return (o.is_for_rrect_blur_clear ? 1llu : 0llu) << 0 |
329
- (o.wireframe ? 1llu : 0llu) << 1 |
330
- (o.has_depth_stencil_attachments ? 1llu : 0llu) << 2 |
331
- (o.depth_write_enabled ? 1llu : 0llu) << 3 |
332
- // enums
333
- static_cast <uint64_t >(o.color_attachment_pixel_format ) << 8 |
334
- static_cast <uint64_t >(o.primitive_type ) << 16 |
335
- static_cast <uint64_t >(o.stencil_mode ) << 24 |
336
- static_cast <uint64_t >(o.depth_compare ) << 32 |
337
- static_cast <uint64_t >(o.blend_mode ) << 40 |
338
- static_cast <uint64_t >(o.sample_count ) << 48 ;
339
- }
340
- };
341
-
342
- struct Equal {
343
- constexpr bool operator ()(const ContentContextOptions& lhs,
344
- const ContentContextOptions& rhs) const {
345
- return lhs.sample_count == rhs.sample_count &&
346
- lhs.blend_mode == rhs.blend_mode &&
347
- lhs.depth_write_enabled == rhs.depth_write_enabled &&
348
- lhs.depth_compare == rhs.depth_compare &&
349
- lhs.stencil_mode == rhs.stencil_mode &&
350
- lhs.primitive_type == rhs.primitive_type &&
351
- lhs.color_attachment_pixel_format ==
352
- rhs.color_attachment_pixel_format &&
353
- lhs.has_depth_stencil_attachments ==
354
- rhs.has_depth_stencil_attachments &&
355
- lhs.wireframe == rhs.wireframe &&
356
- lhs.is_for_rrect_blur_clear == rhs.is_for_rrect_blur_clear ;
357
- }
358
- };
318
+ constexpr uint64_t ToKey () const {
319
+ static_assert (sizeof (sample_count) == 1 );
320
+ static_assert (sizeof (blend_mode) == 1 );
321
+ static_assert (sizeof (sample_count) == 1 );
322
+ static_assert (sizeof (depth_compare) == 1 );
323
+ static_assert (sizeof (stencil_mode) == 1 );
324
+ static_assert (sizeof (primitive_type) == 1 );
325
+ static_assert (sizeof (color_attachment_pixel_format) == 1 );
326
+
327
+ return (is_for_rrect_blur_clear ? 1llu : 0llu) << 0 |
328
+ (wireframe ? 1llu : 0llu) << 1 |
329
+ (has_depth_stencil_attachments ? 1llu : 0llu) << 2 |
330
+ (depth_write_enabled ? 1llu : 0llu) << 3 |
331
+ // enums
332
+ static_cast <uint64_t >(color_attachment_pixel_format) << 8 |
333
+ static_cast <uint64_t >(primitive_type) << 16 |
334
+ static_cast <uint64_t >(stencil_mode) << 24 |
335
+ static_cast <uint64_t >(depth_compare) << 32 |
336
+ static_cast <uint64_t >(blend_mode) << 40 |
337
+ static_cast <uint64_t >(sample_count) << 48 ;
338
+ }
359
339
360
340
void ApplyToPipelineDescriptor (PipelineDescriptor& desc) const ;
361
341
};
@@ -771,15 +751,15 @@ class ContentContext {
771
751
struct Hash {
772
752
std::size_t operator ()(const RuntimeEffectPipelineKey& key) const {
773
753
return fml::HashCombine (key.unique_entrypoint_name ,
774
- ContentContextOptions::Hash{}( key.options ));
754
+ key.options . ToKey ( ));
775
755
}
776
756
};
777
757
778
758
struct Equal {
779
759
constexpr bool operator ()(const RuntimeEffectPipelineKey& lhs,
780
760
const RuntimeEffectPipelineKey& rhs) const {
781
761
return lhs.unique_entrypoint_name == rhs.unique_entrypoint_name &&
782
- ContentContextOptions::Equal{}( lhs.options , rhs.options );
762
+ lhs.options . ToKey () == rhs.options . ToKey ( );
783
763
}
784
764
};
785
765
};
@@ -810,7 +790,13 @@ class ContentContext {
810
790
811
791
void Set (const ContentContextOptions& options,
812
792
std::unique_ptr<PipelineHandleT> pipeline) {
813
- pipelines_[options] = std::move (pipeline);
793
+ uint64_t p_key = options.ToKey ();
794
+ for (const auto & [key, pipeline] : pipelines_) {
795
+ if (key == p_key) {
796
+ return ;
797
+ }
798
+ }
799
+ pipelines_.push_back (std::make_pair (p_key, std::move (pipeline)));
814
800
}
815
801
816
802
void SetDefault (const ContentContextOptions& options,
@@ -833,8 +819,11 @@ class ContentContext {
833
819
}
834
820
835
821
PipelineHandleT* Get (const ContentContextOptions& options) const {
836
- if (auto found = pipelines_.find (options); found != pipelines_.end ()) {
837
- return found->second .get ();
822
+ uint64_t p_key = options.ToKey ();
823
+ for (const auto & [key, pipeline] : pipelines_) {
824
+ if (key == p_key) {
825
+ return pipeline.get ();
826
+ }
838
827
}
839
828
return nullptr ;
840
829
}
@@ -850,10 +839,7 @@ class ContentContext {
850
839
851
840
private:
852
841
std::optional<ContentContextOptions> default_options_;
853
- std::unordered_map<ContentContextOptions,
854
- std::unique_ptr<PipelineHandleT>,
855
- ContentContextOptions::Hash,
856
- ContentContextOptions::Equal>
842
+ std::vector<std::pair<uint64_t , std::unique_ptr<PipelineHandleT>>>
857
843
pipelines_;
858
844
859
845
Variants (const Variants&) = delete ;
0 commit comments