99
1010#include < cage-core/concurrent.h>
1111#include < cage-core/debug.h>
12+ #include < cage-core/profiling.h>
1213#include < cage-engine/graphicsDevice.h>
1314#include < cage-engine/texture.h>
1415#include < cage-engine/window.h>
@@ -59,13 +60,13 @@ namespace cage
5960
6061 void lostFromDevice (const wgpu::Device &device, wgpu::DeviceLostReason reason, wgpu::StringView message)
6162 {
62- CAGE_LOG (SeverityEnum::Info, " graphics" , " device lost" );
63+ CAGE_LOG (SeverityEnum::Info, " graphics" , " wgpu device lost: " );
6364 CAGE_LOG (SeverityEnum::Note, " wgpu" , conv (message));
6465 }
6566
6667 void errorFromDevice (const wgpu::Device &device, wgpu::ErrorType error, wgpu::StringView message)
6768 {
68- CAGE_LOG (SeverityEnum::Error, " graphics" , " device error" );
69+ CAGE_LOG (SeverityEnum::Error, " graphics" , " wgpu device error: " );
6970 CAGE_LOG (SeverityEnum::Error, " wgpu" , conv (message));
7071 detail::debugBreakpoint ();
7172 }
@@ -81,6 +82,7 @@ namespace cage
8182 GraphicsDeviceImpl (const GraphicsDeviceCreateConfig &config)
8283 {
8384 {
85+ CAGE_LOG (SeverityEnum::Info, " graphics" , " initializing wgpu instance" );
8486 dawn::native::DawnInstanceDescriptor ex = {};
8587 ex.SetLoggingCallback (logFromInstance);
8688 wgpu::InstanceDescriptor desc = {};
@@ -96,8 +98,8 @@ namespace cage
9698
9799 wgpu::Adapter adapter;
98100 {
101+ CAGE_LOG (SeverityEnum::Info, " graphics" , " initializing wgpu adapter" );
99102 wgpu::RequestAdapterOptions opts = {};
100- // opts.backendType = wgpu::BackendType::Vulkan;
101103 opts.powerPreference = wgpu::PowerPreference::HighPerformance;
102104 if (config.compatibility )
103105 opts.compatibleSurface = getContext (config.compatibility )->surface ;
@@ -120,6 +122,7 @@ namespace cage
120122 }
121123
122124 {
125+ CAGE_LOG (SeverityEnum::Info, " graphics" , " initializing wgpu device" );
123126 wgpu::DeviceDescriptor desc = {};
124127 desc.SetDeviceLostCallback (wgpu::CallbackMode::AllowProcessEvents, lostFromDevice);
125128 desc.SetUncapturedErrorCallback (errorFromDevice);
@@ -130,10 +133,13 @@ namespace cage
130133 }
131134
132135 {
136+ CAGE_LOG (SeverityEnum::Info, " graphics" , " initializing wgpu queue" );
133137 queue = device.GetQueue ();
134138 if (!queue)
135139 CAGE_THROW_ERROR (Exception, " failed to create wgpu queue" );
136140 }
141+
142+ CAGE_LOG (SeverityEnum::Info, " graphics" , " wgpu initialized" );
137143 }
138144
139145 GraphicsContext *getContext (Window *window)
@@ -143,17 +149,24 @@ namespace cage
143149 context = systemMemory ().createHolder <GraphicsContext>();
144150 if (!context->surface )
145151 {
152+ CAGE_LOG (SeverityEnum::Info, " graphics" , " initializing wgpu surface" );
146153 context->surface = wgpu::glfw::CreateSurfaceForWindow (instance, getGlfwWindow (window));
147154 if (!context->surface )
148155 CAGE_THROW_ERROR (Exception, " failed to create wgpu surface from window" );
149156 }
150157 return +context;
151158 }
152159
153- void processEvents () { device.Tick (); }
160+ void processEvents ()
161+ {
162+ const ProfilingScope profiling (" graphics process events" );
163+ device.Tick ();
164+ }
154165
155166 Holder<Texture> nextFrame (Window *window)
156167 {
168+ const ProfilingScope profiling (" graphics next frame" );
169+
157170 GraphicsContext *context = getContext (window);
158171
159172 const Vec2i res = window->resolution ();
@@ -169,9 +182,7 @@ namespace cage
169182 cfg.width = res[0 ];
170183 cfg.height = res[1 ];
171184 cfg.presentMode = wgpu::PresentMode::Mailbox;
172- // cfg.format = wgpu::TextureFormat::RGBA8Unorm;
173- cfg.format = wgpu::TextureFormat::BGRA8Unorm;
174- // cfg.usage = wgpu::TextureUsage::RenderAttachment;
185+ cfg.format = wgpu::TextureFormat::BGRA8Unorm; // this should be guaranteed to work everywhere
175186 context->surface .Configure (&cfg);
176187 context->resolution = res;
177188 }
0 commit comments