MCPcopy Create free account
hub / github.com/defold/defold / requestDeviceCallback

Function requestDeviceCallback

engine/graphics/src/webgpu/graphics_webgpu.cpp:1087–1139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1085static void requestDeviceCallback(WGPURequestDeviceStatus status, WGPUDevice device, WGPUStringView message, void* userdata, void *)
1086#else
1087static void requestDeviceCallback(WGPURequestDeviceStatus status, WGPUDevice device, const char* message, void* userdata)
1088#endif
1089{
1090 TRACE_CALL;
1091 WebGPUContext* context = (WebGPUContext*)userdata;
1092 if (device)
1093 {
1094 context->m_Device = device;
1095 wgpuDeviceGetLimits(context->m_Device, &context->m_DeviceLimits);
1096 context->m_Queue = wgpuDeviceGetQueue(context->m_Device);
1097 {
1098#if defined(DM_GRAPHICS_WEBGPU2)
1099 WGPUSurfaceDescriptor surface_desc = WGPU_SURFACE_DESCRIPTOR_INIT;
1100#if defined(__EMSCRIPTEN__)
1101 WGPUEmscriptenSurfaceSourceCanvasHTMLSelector selector = WGPU_EMSCRIPTEN_SURFACE_SOURCE_CANVAS_HTML_SELECTOR_INIT;
1102 selector.selector.data = "#canvas";
1103 selector.selector.length = 7;
1104 surface_desc.nextInChain = (WGPUChainedStruct*)&selector;
1105#endif
1106#else
1107 WGPUSurfaceDescriptor surface_desc = {};
1108#if defined(__EMSCRIPTEN__)
1109 WGPUSurfaceDescriptorFromCanvasHTMLSelector selector = { { surface_desc.nextInChain, WGPUSType_SurfaceDescriptorFromCanvasHTMLSelector }, "#canvas" };
1110 surface_desc.nextInChain = (WGPUChainedStruct*)&selector;
1111#endif
1112#endif
1113 context->m_Surface = wgpuInstanceCreateSurface(context->m_Instance, &surface_desc);
1114 }
1115#if defined(DM_GRAPHICS_WEBGPU2)
1116 {
1117 WGPUSurfaceCapabilities capabilities = WGPU_SURFACE_CAPABILITIES_INIT;
1118 wgpuSurfaceGetCapabilities(context->m_Surface, context->m_Adapter, &capabilities);
1119 assert(capabilities.formatCount > 0);
1120 context->m_Format = capabilities.formats[0];
1121 wgpuSurfaceCapabilitiesFreeMembers(capabilities);
1122 }
1123#else
1124 context->m_Format = wgpuSurfaceGetPreferredFormat(context->m_Surface, context->m_Adapter);
1125#endif
1126 WebGPUConfigure(context, context->m_OriginalWidth, context->m_OriginalHeight);
1127
1128 dmLogInfo("WebGPU: Created device");
1129 }
1130 else
1131 {
1132#if defined(DM_GRAPHICS_WEBGPU2)
1133 dmLogError("WebGPU: Unable to create device %s", message.data ? message.data : "unknown");
1134#else
1135 dmLogError("WebGPU: Unable to create device %s", message);
1136#endif
1137 }
1138 context->m_InitComplete = true;
1139}
1140
1141#if defined(DM_GRAPHICS_WEBGPU2)
1142static void instanceRequestAdapterCallback(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void* userdata, void *)

Callers

nothing calls this directly

Calls 2

WebGPUConfigureFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected