Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
move ifdef
  • Loading branch information
jonahwilliams committed Oct 16, 2023
commit 3caf282bc0ac09fbb500c41b75673f10166e2a26
5 changes: 4 additions & 1 deletion impeller/renderer/backend/metal/command_buffer_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@ static bool LogMTLCommandBufferErrorIfPresent(id<MTLCommandBuffer> buffer) {
if (!context) {
return false;
}
#ifdef IMPELLER_DEBUG
ContextMTL::Cast(*context).GetGPUTracer()->RecordCmdBuffer(buffer_);

#endif // IMPELLER_DEBUG
if (callback) {
[buffer_
addCompletedHandler:^(id<MTLCommandBuffer> buffer) {
Expand Down Expand Up @@ -196,7 +197,9 @@ static bool LogMTLCommandBufferErrorIfPresent(id<MTLCommandBuffer> buffer) {
auto buffer = buffer_;
buffer_ = nil;

#ifdef IMPELLER_DEBUG
ContextMTL::Cast(*context).GetGPUTracer()->RecordCmdBuffer(buffer);
#endif // IMPELLER_DEBUG

auto worker_task_runner = ContextMTL::Cast(*context).GetWorkerTaskRunner();
auto mtl_render_pass = static_cast<RenderPassMTL*>(render_pass.get());
Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/backend/metal/context_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ class ContextMTL final : public Context,

std::shared_ptr<const fml::SyncSwitch> GetIsGpuDisabledSyncSwitch() const;

#ifdef IMPELLER_DEBUG
std::shared_ptr<GPUTracerMTL> GetGPUTracer() const;
#endif // IMPELLER_DEBUG

private:
id<MTLDevice> device_ = nullptr;
Expand All @@ -106,7 +108,9 @@ class ContextMTL final : public Context,
std::shared_ptr<const Capabilities> device_capabilities_;
std::shared_ptr<fml::ConcurrentMessageLoop> raster_message_loop_;
std::shared_ptr<const fml::SyncSwitch> is_gpu_disabled_sync_switch_;
#ifdef IMPELLER_DEBUG
std::shared_ptr<GPUTracerMTL> gpu_tracer_;
#endif // IMPELLER_DEBUG
bool is_valid_ = false;

ContextMTL(
Expand Down
4 changes: 4 additions & 0 deletions impeller/renderer/backend/metal/context_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,9 @@ static bool DeviceSupportsComputeSubgroups(id<MTLDevice> device) {

device_capabilities_ =
InferMetalCapabilities(device_, PixelFormat::kB8G8R8A8UNormInt);
#ifdef IMPELLER_DEBUG
gpu_tracer_ = std::make_shared<GPUTracerMTL>();
#endif // IMPELLER_DEBUG
is_valid_ = true;
}

Expand Down Expand Up @@ -327,9 +329,11 @@ new ContextMTL(device, command_queue,
raster_message_loop_.reset();
}

#ifdef IMPELLER_DEBUG
std::shared_ptr<GPUTracerMTL> ContextMTL::GetGPUTracer() const {
return gpu_tracer_;
}
#endif // IMPELLER_DEBUG

const std::shared_ptr<fml::ConcurrentTaskRunner>
ContextMTL::GetWorkerTaskRunner() const {
Expand Down
8 changes: 3 additions & 5 deletions impeller/renderer/backend/metal/gpu_tracer_mtl.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,9 @@ class GPUTracerMTL : public std::enable_shared_from_this<GPUTracerMTL> {
size_t pending_buffers = 0;
};

[[maybe_unused]] mutable Mutex trace_state_mutex_;
[[maybe_unused]] GPUTraceState trace_states_[16] IPLR_GUARDED_BY(
trace_state_mutex_);
[[maybe_unused]] size_t current_state_ IPLR_GUARDED_BY(trace_state_mutex_) =
0u;
mutable Mutex trace_state_mutex_;
GPUTraceState trace_states_[16] IPLR_GUARDED_BY(trace_state_mutex_);
size_t current_state_ IPLR_GUARDED_BY(trace_state_mutex_) = 0u;
};

} // namespace impeller
4 changes: 0 additions & 4 deletions impeller/renderer/backend/metal/gpu_tracer_mtl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,13 @@
namespace impeller {

void GPUTracerMTL::MarkFrameEnd() {
#ifdef IMPELLER_DEBUG
if (@available(ios 10.3, tvos 10.2, macos 10.15, macCatalyst 13.0, *)) {
Lock lock(trace_state_mutex_);
current_state_ = (current_state_ + 1) % 16;
}
#endif // IMPELLER_DEBUG
}

void GPUTracerMTL::RecordCmdBuffer(id<MTLCommandBuffer> buffer) {
#ifdef IMPELLER_DEBUG
if (@available(ios 10.3, tvos 10.2, macos 10.15, macCatalyst 13.0, *)) {
Lock lock(trace_state_mutex_);
auto current_state = current_state_;
Expand Down Expand Up @@ -54,7 +51,6 @@
}
}];
}
#endif // IMPELLER_DEBUG
}

} // namespace impeller