7
7
#include " impeller/renderer/backend/metal/render_pass_mtl.h"
8
8
9
9
namespace impeller {
10
-
11
- id <MTLCommandBuffer > CreateCommandBuffer (id <MTLCommandQueue > queue) {
12
- if (@available (iOS 14.0 , macOS 11.0 , *)) {
13
- auto desc = [[MTLCommandBufferDescriptor alloc ] init ];
14
- // Degrades CPU performance slightly but is well worth the cost for typical
15
- // Impeller workloads.
16
- desc.errorOptions = MTLCommandBufferErrorOptionEncoderExecutionStatus;
17
- return [queue commandBufferWithDescriptor: desc];
18
- }
19
- return [queue commandBuffer ];
20
- }
21
-
22
- CommandBufferMTL::CommandBufferMTL (id <MTLCommandQueue > queue)
23
- : buffer_(CreateCommandBuffer(queue)) {
24
- if (!buffer_) {
25
- return ;
26
- }
27
- is_valid_ = true ;
28
- }
29
-
30
- CommandBufferMTL::~CommandBufferMTL () = default ;
31
-
32
- bool CommandBufferMTL::IsValid () const {
33
- return is_valid_;
34
- }
35
-
36
- void CommandBufferMTL::SetLabel (const std::string& label) const {
37
- if (label.empty ()) {
38
- return ;
39
- }
40
-
41
- [buffer_ setLabel: @(label.data ())];
42
- }
43
-
44
- static CommandBuffer::Status ToCommitResult (MTLCommandBufferStatus status) {
45
- switch (status) {
46
- case MTLCommandBufferStatusCompleted :
47
- return CommandBufferMTL::Status::kCompleted ;
48
- case MTLCommandBufferStatusEnqueued :
49
- return CommandBufferMTL::Status::kPending ;
50
- default :
51
- break ;
52
- }
53
- return CommandBufferMTL::Status::kError ;
54
- }
55
-
10
+ namespace {
56
11
// TODO(dnfield): remove this declaration when we no longer need to build on
57
- // machines with lower SDK versions than 11.0.s
58
- #if !defined(MAC_OS_VERSION_11_0) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_VERSION_11_0
12
+ // machines with lower SDK versions than 11.0.
13
+ #if !defined(MAC_OS_VERSION_11_0) || \
14
+ MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_VERSION_11_0
59
15
typedef NS_ENUM (NSInteger , MTLCommandEncoderErrorState) {
60
16
MTLCommandEncoderErrorStateUnknown = 0 ,
61
17
MTLCommandEncoderErrorStateCompleted = 1 ,
@@ -65,12 +21,6 @@ typedef NS_ENUM(NSInteger, MTLCommandEncoderErrorState) {
65
21
} API_AVAILABLE(macos(11.0 ), ios(14.0 ));
66
22
#endif
67
23
68
-
69
- #if !defined(MAC_OS_VERSION_12_0) || MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_VERSION_12_0
70
- constexpr int MTLCommandBufferErrorAccessRevoked = 4 ;
71
- constexpr int MTLCommandBufferErrorStackOverflow = 12 ;
72
- #endif
73
-
74
24
API_AVAILABLE (ios(14.0 ), macos(11.0 ))
75
25
NSString * MTLCommandEncoderErrorStateToString (
76
26
MTLCommandEncoderErrorState state) {
@@ -89,6 +39,14 @@ typedef NS_ENUM(NSInteger, MTLCommandEncoderErrorState) {
89
39
return @" unknown" ;
90
40
}
91
41
42
+ // TODO(dnfield): This can be removed when all bots have been sufficiently
43
+ // upgraded for MAC_OS_VERSION_12_0.
44
+ #if !defined(MAC_OS_VERSION_12_0) || \
45
+ MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_VERSION_12_0
46
+ constexpr int MTLCommandBufferErrorAccessRevoked = 4 ;
47
+ constexpr int MTLCommandBufferErrorStackOverflow = 12 ;
48
+ #endif
49
+
92
50
static NSString * MTLCommandBufferErrorToString (MTLCommandBufferError code) {
93
51
switch (code) {
94
52
case MTLCommandBufferErrorNone :
@@ -173,6 +131,52 @@ static void LogMTLCommandBufferErrorIfPresent(id<MTLCommandBuffer> buffer) {
173
131
stream << " <<<<<<<" ;
174
132
VALIDATION_LOG << stream.str ();
175
133
}
134
+ } // namespace
135
+
136
+ id <MTLCommandBuffer > CreateCommandBuffer (id <MTLCommandQueue > queue) {
137
+ if (@available (iOS 14.0 , macOS 11.0 , *)) {
138
+ auto desc = [[MTLCommandBufferDescriptor alloc ] init ];
139
+ // Degrades CPU performance slightly but is well worth the cost for typical
140
+ // Impeller workloads.
141
+ desc.errorOptions = MTLCommandBufferErrorOptionEncoderExecutionStatus;
142
+ return [queue commandBufferWithDescriptor: desc];
143
+ }
144
+ return [queue commandBuffer ];
145
+ }
146
+
147
+ CommandBufferMTL::CommandBufferMTL (id <MTLCommandQueue > queue)
148
+ : buffer_(CreateCommandBuffer(queue)) {
149
+ if (!buffer_) {
150
+ return ;
151
+ }
152
+ is_valid_ = true ;
153
+ }
154
+
155
+ CommandBufferMTL::~CommandBufferMTL () = default ;
156
+
157
+ bool CommandBufferMTL::IsValid () const {
158
+ return is_valid_;
159
+ }
160
+
161
+ void CommandBufferMTL::SetLabel (const std::string& label) const {
162
+ if (label.empty ()) {
163
+ return ;
164
+ }
165
+
166
+ [buffer_ setLabel: @(label.data ())];
167
+ }
168
+
169
+ static CommandBuffer::Status ToCommitResult (MTLCommandBufferStatus status) {
170
+ switch (status) {
171
+ case MTLCommandBufferStatusCompleted :
172
+ return CommandBufferMTL::Status::kCompleted ;
173
+ case MTLCommandBufferStatusEnqueued :
174
+ return CommandBufferMTL::Status::kPending ;
175
+ default :
176
+ break ;
177
+ }
178
+ return CommandBufferMTL::Status::kError ;
179
+ }
176
180
177
181
bool CommandBufferMTL::SubmitCommands (CompletionCallback callback) {
178
182
if (!buffer_) {
0 commit comments