77
88#include " ../window/private.h"
99
10+ #include < cage-core/concurrent.h>
1011#include < cage-core/debug.h>
1112#include < cage-engine/graphicsDevice.h>
13+ #include < cage-engine/texture.h>
1214#include < cage-engine/window.h>
1315
1416namespace cage
1517{
16- Holder<Texture> adaptWgpuTexture (wgpu::Texture texture);
17-
1818 struct GraphicsContext
1919 {
2020 wgpu::Surface surface;
@@ -73,16 +73,17 @@ namespace cage
7373 class GraphicsDeviceImpl : public GraphicsDevice
7474 {
7575 public:
76+ Holder<Mutex> mutex = newMutex();
7677 wgpu::Instance instance;
7778 wgpu::Device device;
7879 wgpu::Queue queue;
7980
8081 GraphicsDeviceImpl (const GraphicsDeviceCreateConfig &config)
8182 {
8283 {
83- dawn::native::DawnInstanceDescriptor ex;
84+ dawn::native::DawnInstanceDescriptor ex = {} ;
8485 ex.SetLoggingCallback (logFromInstance);
85- wgpu::InstanceDescriptor desc;
86+ wgpu::InstanceDescriptor desc = {} ;
8687 desc.nextInChain = &ex;
8788 std::array<wgpu::InstanceFeatureName, 2 > features = { wgpu::InstanceFeatureName::TimedWaitAny, wgpu::InstanceFeatureName::ShaderSourceSPIRV };
8889 desc.requiredFeatureCount = features.size ();
@@ -95,7 +96,7 @@ namespace cage
9596
9697 wgpu::Adapter adapter;
9798 {
98- wgpu::RequestAdapterOptions opts;
99+ wgpu::RequestAdapterOptions opts = {} ;
99100 opts.backendType = wgpu::BackendType::Vulkan;
100101 opts.powerPreference = wgpu::PowerPreference::HighPerformance;
101102 if (config.compatibility )
@@ -111,15 +112,15 @@ namespace cage
111112 if (!adapter)
112113 CAGE_THROW_ERROR (Exception, " failed to create wgpu adapter" );
113114
114- wgpu::AdapterInfo info;
115+ wgpu::AdapterInfo info = {} ;
115116 adapter.GetInfo (&info);
116117 CAGE_LOG (SeverityEnum::Info, " graphics" , Stringizer () + " adapter vendor: " + conv (info.vendor ));
117118 CAGE_LOG (SeverityEnum::Info, " graphics" , Stringizer () + " adapter device: " + conv (info.device ));
118119 CAGE_LOG (SeverityEnum::Info, " graphics" , Stringizer () + " adapter description: " + conv (info.description ));
119120 }
120121
121122 {
122- wgpu::DeviceDescriptor desc;
123+ wgpu::DeviceDescriptor desc = {} ;
123124 desc.SetDeviceLostCallback (wgpu::CallbackMode::AllowProcessEvents, lostFromDevice);
124125 desc.SetUncapturedErrorCallback (errorFromDevice);
125126
@@ -163,7 +164,7 @@ namespace cage
163164 if (res != context->resolution )
164165 {
165166 context->presentable = false ;
166- wgpu::SurfaceConfiguration cfg;
167+ wgpu::SurfaceConfiguration cfg = {} ;
167168 cfg.device = device;
168169 cfg.width = res[0 ];
169170 cfg.height = res[1 ];
@@ -177,7 +178,7 @@ namespace cage
177178 if (context->presentable )
178179 context->surface .Present ();
179180
180- wgpu::SurfaceTexture tex;
181+ wgpu::SurfaceTexture tex = {} ;
181182 context->surface .GetCurrentTexture (&tex);
182183 switch (tex.status )
183184 {
@@ -192,7 +193,7 @@ namespace cage
192193
193194 CAGE_ASSERT (tex.texture );
194195 context->presentable = true ;
195- return adaptWgpuTexture (tex.texture );
196+ return newTexture (tex.texture );
196197 }
197198 };
198199 }
@@ -220,9 +221,17 @@ namespace cage
220221 return impl->device ;
221222 }
222223
223- wgpu::Queue GraphicsDevice::nativeQueue ()
224+ Holder< wgpu::Queue> GraphicsDevice::nativeQueue ()
224225 {
225226 GraphicsDeviceImpl *impl = (GraphicsDeviceImpl *)this ;
226- return impl->queue ;
227+ struct LockedQueue : private Noncopyable
228+ {
229+ ScopeLock<Mutex> lock;
230+ wgpu::Queue queue;
231+
232+ LockedQueue (ScopeLock<Mutex> &&l, wgpu::Queue &&q) : lock(std::move(l)), queue(std::move(q)) {}
233+ };
234+ Holder<LockedQueue> l = systemMemory ().createHolder <LockedQueue>(ScopeLock (impl->mutex ), impl->queue );
235+ return Holder<wgpu::Queue>(&l->queue , std::move (l));
227236 }
228237}
0 commit comments